Skip to content

Commit 70e7983

Browse files
committed
Merge branch 'hns3-add-code-optimization-for-VF-reset-and-some-new-reset-feature'
Huazhong Tan says: ==================== hns3: add code optimization for VF reset and some new reset feature Currently hardware supports below reset: 1. VF reset: triggered by sending cmd to IMP(Integrated Management Processor). Only reset specific VF function and do not affect other PF or VF. 2. PF reset: triggered by sending cmd to IMP. Only reset specific PF and it's VF. 3. PF FLR: triggered by PCIe subsystem. Only reset specific PF and it's VF. 4. VF FLR: triggered by PCIe subsystem. Only reset specific VF function and do not affect other PF or VF. 5. Core reset: triggered by writing to register. Reset most hardware unit, such as SSU, which affects all the PF and VF. 6. Global reset: triggered by writing to register. Reset all hardware unit, which affects all the PF and VF. 7. IMP reset: triggered by IMU(Intelligent Management Unit) when IMP is not longer feeding IMU's watchdog. IMU will reload the IMP firmware and IMP will perform global reset after firmware reloading, which affects all the PF and VF. Current driver only support PF/VF reset, incomplete core and global reset(lacking the vf reset handling). So this patchset adds complete reset support in hns3 driver. Also, this patchset contains some optimization related to reset. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 40c4b1e + 6ff3cf0 commit 70e7983

File tree

12 files changed

+638
-164
lines changed

12 files changed

+638
-164
lines changed

drivers/net/ethernet/hisilicon/hns3/hclge_mbx.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ struct hclge_mbx_pf_to_vf_cmd {
8585
u16 msg[8];
8686
};
8787

88+
struct hclge_vf_rst_cmd {
89+
u8 dest_vfid;
90+
u8 vf_rst;
91+
u8 rsv[22];
92+
};
93+
8894
/* used by VF to store the received Async responses from PF */
8995
struct hclgevf_mbx_arq_ring {
9096
#define HCLGE_MBX_MAX_ARQ_MSG_SIZE 8

drivers/net/ethernet/hisilicon/hns3/hnae3.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,22 @@ enum hnae3_reset_notify_type {
124124

125125
enum hnae3_reset_type {
126126
HNAE3_VF_RESET,
127+
HNAE3_VF_FUNC_RESET,
128+
HNAE3_VF_PF_FUNC_RESET,
127129
HNAE3_VF_FULL_RESET,
130+
HNAE3_FLR_RESET,
128131
HNAE3_FUNC_RESET,
129132
HNAE3_CORE_RESET,
130133
HNAE3_GLOBAL_RESET,
131134
HNAE3_IMP_RESET,
132135
HNAE3_NONE_RESET,
133136
};
134137

138+
enum hnae3_flr_state {
139+
HNAE3_FLR_DOWN,
140+
HNAE3_FLR_DONE,
141+
};
142+
135143
struct hnae3_vector_info {
136144
u8 __iomem *io_addr;
137145
int vector;
@@ -297,7 +305,8 @@ struct hnae3_ae_dev {
297305
struct hnae3_ae_ops {
298306
int (*init_ae_dev)(struct hnae3_ae_dev *ae_dev);
299307
void (*uninit_ae_dev)(struct hnae3_ae_dev *ae_dev);
300-
308+
void (*flr_prepare)(struct hnae3_ae_dev *ae_dev);
309+
void (*flr_done)(struct hnae3_ae_dev *ae_dev);
301310
int (*init_client_instance)(struct hnae3_client *client,
302311
struct hnae3_ae_dev *ae_dev);
303312
void (*uninit_client_instance)(struct hnae3_client *client,

drivers/net/ethernet/hisilicon/hns3/hns3_enet.c

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -415,9 +415,6 @@ static void hns3_nic_net_down(struct net_device *netdev)
415415
const struct hnae3_ae_ops *ops;
416416
int i;
417417

418-
if (test_and_set_bit(HNS3_NIC_STATE_DOWN, &priv->state))
419-
return;
420-
421418
/* disable vectors */
422419
for (i = 0; i < priv->vector_num; i++)
423420
hns3_vector_disable(&priv->tqp_vector[i]);
@@ -439,6 +436,11 @@ static void hns3_nic_net_down(struct net_device *netdev)
439436

440437
static int hns3_nic_net_stop(struct net_device *netdev)
441438
{
439+
struct hns3_nic_priv *priv = netdev_priv(netdev);
440+
441+
if (test_and_set_bit(HNS3_NIC_STATE_DOWN, &priv->state))
442+
return 0;
443+
442444
netif_tx_stop_all_queues(netdev);
443445
netif_carrier_off(netdev);
444446

@@ -1849,9 +1851,29 @@ static pci_ers_result_t hns3_slot_reset(struct pci_dev *pdev)
18491851
return PCI_ERS_RESULT_DISCONNECT;
18501852
}
18511853

1854+
static void hns3_reset_prepare(struct pci_dev *pdev)
1855+
{
1856+
struct hnae3_ae_dev *ae_dev = pci_get_drvdata(pdev);
1857+
1858+
dev_info(&pdev->dev, "hns3 flr prepare\n");
1859+
if (ae_dev && ae_dev->ops && ae_dev->ops->flr_prepare)
1860+
ae_dev->ops->flr_prepare(ae_dev);
1861+
}
1862+
1863+
static void hns3_reset_done(struct pci_dev *pdev)
1864+
{
1865+
struct hnae3_ae_dev *ae_dev = pci_get_drvdata(pdev);
1866+
1867+
dev_info(&pdev->dev, "hns3 flr done\n");
1868+
if (ae_dev && ae_dev->ops && ae_dev->ops->flr_done)
1869+
ae_dev->ops->flr_done(ae_dev);
1870+
}
1871+
18521872
static const struct pci_error_handlers hns3_err_handler = {
18531873
.error_detected = hns3_error_detected,
18541874
.slot_reset = hns3_slot_reset,
1875+
.reset_prepare = hns3_reset_prepare,
1876+
.reset_done = hns3_reset_done,
18551877
};
18561878

18571879
static struct pci_driver hns3_driver = {
@@ -2699,6 +2721,7 @@ static void hns3_update_new_int_gl(struct hns3_enet_tqp_vector *tqp_vector)
26992721

27002722
static int hns3_nic_common_poll(struct napi_struct *napi, int budget)
27012723
{
2724+
struct hns3_nic_priv *priv = netdev_priv(napi->dev);
27022725
struct hns3_enet_ring *ring;
27032726
int rx_pkt_total = 0;
27042727

@@ -2707,6 +2730,11 @@ static int hns3_nic_common_poll(struct napi_struct *napi, int budget)
27072730
bool clean_complete = true;
27082731
int rx_budget;
27092732

2733+
if (unlikely(test_bit(HNS3_NIC_STATE_DOWN, &priv->state))) {
2734+
napi_complete(napi);
2735+
return 0;
2736+
}
2737+
27102738
/* Since the actual Tx work is minimal, we can give the Tx a larger
27112739
* budget and be more aggressive about cleaning up the Tx descriptors.
27122740
*/
@@ -2731,9 +2759,11 @@ static int hns3_nic_common_poll(struct napi_struct *napi, int budget)
27312759
if (!clean_complete)
27322760
return budget;
27332761

2734-
napi_complete(napi);
2735-
hns3_update_new_int_gl(tqp_vector);
2736-
hns3_mask_vector_irq(tqp_vector, 1);
2762+
if (likely(!test_bit(HNS3_NIC_STATE_DOWN, &priv->state)) &&
2763+
napi_complete(napi)) {
2764+
hns3_update_new_int_gl(tqp_vector);
2765+
hns3_mask_vector_irq(tqp_vector, 1);
2766+
}
27372767

27382768
return rx_pkt_total;
27392769
}
@@ -3818,20 +3848,30 @@ static int hns3_reset_notify_init_enet(struct hnae3_handle *handle)
38183848
/* Carrier off reporting is important to ethtool even BEFORE open */
38193849
netif_carrier_off(netdev);
38203850

3851+
ret = hns3_nic_alloc_vector_data(priv);
3852+
if (ret)
3853+
return ret;
3854+
38213855
hns3_restore_coal(priv);
38223856

38233857
ret = hns3_nic_init_vector_data(priv);
38243858
if (ret)
3825-
return ret;
3859+
goto err_dealloc_vector;
38263860

38273861
ret = hns3_init_all_ring(priv);
3828-
if (ret) {
3829-
hns3_nic_uninit_vector_data(priv);
3830-
priv->ring_data = NULL;
3831-
}
3862+
if (ret)
3863+
goto err_uninit_vector;
38323864

38333865
set_bit(HNS3_NIC_STATE_INITED, &priv->state);
38343866

3867+
return ret;
3868+
3869+
err_uninit_vector:
3870+
hns3_nic_uninit_vector_data(priv);
3871+
priv->ring_data = NULL;
3872+
err_dealloc_vector:
3873+
hns3_nic_dealloc_vector_data(priv);
3874+
38353875
return ret;
38363876
}
38373877

@@ -3856,6 +3896,10 @@ static int hns3_reset_notify_uninit_enet(struct hnae3_handle *handle)
38563896

38573897
hns3_store_coal(priv);
38583898

3899+
ret = hns3_nic_dealloc_vector_data(priv);
3900+
if (ret)
3901+
netdev_err(netdev, "dealloc vector error\n");
3902+
38593903
ret = hns3_uninit_all_ring(priv);
38603904
if (ret)
38613905
netdev_err(netdev, "uninit ring error\n");

drivers/net/ethernet/hisilicon/hns3/hns3_enet.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,11 @@ static inline void hns3_write_reg(void __iomem *base, u32 reg, u32 value)
593593

594594
static inline bool hns3_dev_ongoing_func_reset(struct hnae3_ae_dev *ae_dev)
595595
{
596-
return (ae_dev && (ae_dev->reset_type == HNAE3_FUNC_RESET));
596+
return (ae_dev && (ae_dev->reset_type == HNAE3_FUNC_RESET ||
597+
ae_dev->reset_type == HNAE3_FLR_RESET ||
598+
ae_dev->reset_type == HNAE3_VF_FUNC_RESET ||
599+
ae_dev->reset_type == HNAE3_VF_FULL_RESET ||
600+
ae_dev->reset_type == HNAE3_VF_PF_FUNC_RESET));
597601
}
598602

599603
#define hns3_read_dev(a, reg) \

drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,11 +350,20 @@ int hclge_cmd_init(struct hclge_dev *hdev)
350350
hdev->hw.cmq.crq.next_to_use = 0;
351351

352352
hclge_cmd_init_regs(&hdev->hw);
353-
clear_bit(HCLGE_STATE_CMD_DISABLE, &hdev->state);
354353

355354
spin_unlock_bh(&hdev->hw.cmq.crq.lock);
356355
spin_unlock_bh(&hdev->hw.cmq.csq.lock);
357356

357+
clear_bit(HCLGE_STATE_CMD_DISABLE, &hdev->state);
358+
359+
/* Check if there is new reset pending, because the higher level
360+
* reset may happen when lower level reset is being processed.
361+
*/
362+
if ((hclge_is_reset_pending(hdev))) {
363+
set_bit(HCLGE_STATE_CMD_DISABLE, &hdev->state);
364+
return -EBUSY;
365+
}
366+
358367
ret = hclge_cmd_query_firmware_version(&hdev->hw, &version);
359368
if (ret) {
360369
dev_err(&hdev->pdev->dev,

0 commit comments

Comments
 (0)