Skip to content

Commit 6a02d1f

Browse files
committed
Merge branch 'hns3-next'
Huazhong Tan says: ==================== hns3: provide new interfaces & bugfixes & code optimization This patchset provides some reset interfaces for RAS & RoCE, also some bugfixes and optimization related to reset. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 7c588c7 + 8b0195a commit 6a02d1f

File tree

12 files changed

+544
-180
lines changed

12 files changed

+544
-180
lines changed

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ struct hnae3_client_ops {
162162
int (*setup_tc)(struct hnae3_handle *handle, u8 tc);
163163
int (*reset_notify)(struct hnae3_handle *handle,
164164
enum hnae3_reset_notify_type type);
165+
enum hnae3_reset_type (*process_hw_error)(struct hnae3_handle *handle);
165166
};
166167

167168
#define HNAE3_CLIENT_NAME_LENGTH 16
@@ -403,6 +404,8 @@ struct hnae3_ae_ops {
403404
u16 vlan, u8 qos, __be16 proto);
404405
int (*enable_hw_strip_rxvtag)(struct hnae3_handle *handle, bool enable);
405406
void (*reset_event)(struct pci_dev *pdev, struct hnae3_handle *handle);
407+
void (*set_default_reset_request)(struct hnae3_ae_dev *ae_dev,
408+
enum hnae3_reset_type rst_type);
406409
void (*get_channels)(struct hnae3_handle *handle,
407410
struct ethtool_channels *ch);
408411
void (*get_tqps_and_rss_info)(struct hnae3_handle *h,
@@ -430,6 +433,9 @@ struct hnae3_ae_ops {
430433
int (*restore_fd_rules)(struct hnae3_handle *handle);
431434
void (*enable_fd)(struct hnae3_handle *handle, bool enable);
432435
pci_ers_result_t (*process_hw_error)(struct hnae3_ae_dev *ae_dev);
436+
bool (*get_hw_reset_stat)(struct hnae3_handle *handle);
437+
bool (*ae_dev_resetting)(struct hnae3_handle *handle);
438+
unsigned long (*ae_dev_reset_cnt)(struct hnae3_handle *handle);
433439
};
434440

435441
struct hnae3_dcb_ops {
@@ -488,6 +494,14 @@ struct hnae3_roce_private_info {
488494
void __iomem *roce_io_base;
489495
int base_vector;
490496
int num_vectors;
497+
498+
/* The below attributes defined for RoCE client, hnae3 gives
499+
* initial values to them, and RoCE client can modify and use
500+
* them.
501+
*/
502+
unsigned long reset_state;
503+
unsigned long instance_state;
504+
unsigned long state;
491505
};
492506

493507
struct hnae3_unic_private_info {
@@ -520,9 +534,6 @@ struct hnae3_handle {
520534
struct hnae3_ae_algo *ae_algo; /* the class who provides this handle */
521535
u64 flags; /* Indicate the capabilities for this handle*/
522536

523-
unsigned long last_reset_time;
524-
enum hnae3_reset_type reset_level;
525-
526537
union {
527538
struct net_device *netdev; /* first member */
528539
struct hnae3_knic_private_info kinfo;

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ int hns3_dcbnl_ieee_getets(struct net_device *ndev, struct ieee_ets *ets)
99
{
1010
struct hnae3_handle *h = hns3_get_handle(ndev);
1111

12+
if (hns3_nic_resetting(ndev))
13+
return -EBUSY;
14+
1215
if (h->kinfo.dcb_ops->ieee_getets)
1316
return h->kinfo.dcb_ops->ieee_getets(h, ets);
1417

@@ -20,6 +23,9 @@ int hns3_dcbnl_ieee_setets(struct net_device *ndev, struct ieee_ets *ets)
2023
{
2124
struct hnae3_handle *h = hns3_get_handle(ndev);
2225

26+
if (hns3_nic_resetting(ndev))
27+
return -EBUSY;
28+
2329
if (h->kinfo.dcb_ops->ieee_setets)
2430
return h->kinfo.dcb_ops->ieee_setets(h, ets);
2531

@@ -31,6 +37,9 @@ int hns3_dcbnl_ieee_getpfc(struct net_device *ndev, struct ieee_pfc *pfc)
3137
{
3238
struct hnae3_handle *h = hns3_get_handle(ndev);
3339

40+
if (hns3_nic_resetting(ndev))
41+
return -EBUSY;
42+
3443
if (h->kinfo.dcb_ops->ieee_getpfc)
3544
return h->kinfo.dcb_ops->ieee_getpfc(h, pfc);
3645

@@ -42,6 +51,9 @@ int hns3_dcbnl_ieee_setpfc(struct net_device *ndev, struct ieee_pfc *pfc)
4251
{
4352
struct hnae3_handle *h = hns3_get_handle(ndev);
4453

54+
if (hns3_nic_resetting(ndev))
55+
return -EBUSY;
56+
4557
if (h->kinfo.dcb_ops->ieee_setpfc)
4658
return h->kinfo.dcb_ops->ieee_setpfc(h, pfc);
4759

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

Lines changed: 69 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,24 @@ static u16 hns3_get_max_available_channels(struct hnae3_handle *h)
312312
return min_t(u16, rss_size, max_rss_size);
313313
}
314314

315+
static void hns3_tqp_enable(struct hnae3_queue *tqp)
316+
{
317+
u32 rcb_reg;
318+
319+
rcb_reg = hns3_read_dev(tqp, HNS3_RING_EN_REG);
320+
rcb_reg |= BIT(HNS3_RING_EN_B);
321+
hns3_write_dev(tqp, HNS3_RING_EN_REG, rcb_reg);
322+
}
323+
324+
static void hns3_tqp_disable(struct hnae3_queue *tqp)
325+
{
326+
u32 rcb_reg;
327+
328+
rcb_reg = hns3_read_dev(tqp, HNS3_RING_EN_REG);
329+
rcb_reg &= ~BIT(HNS3_RING_EN_B);
330+
hns3_write_dev(tqp, HNS3_RING_EN_REG, rcb_reg);
331+
}
332+
315333
static int hns3_nic_net_up(struct net_device *netdev)
316334
{
317335
struct hns3_nic_priv *priv = netdev_priv(netdev);
@@ -334,6 +352,10 @@ static int hns3_nic_net_up(struct net_device *netdev)
334352
for (i = 0; i < priv->vector_num; i++)
335353
hns3_vector_enable(&priv->tqp_vector[i]);
336354

355+
/* enable rcb */
356+
for (j = 0; j < h->kinfo.num_tqps; j++)
357+
hns3_tqp_enable(h->kinfo.tqp[j]);
358+
337359
/* start the ae_dev */
338360
ret = h->ae_algo->ops->start ? h->ae_algo->ops->start(h) : 0;
339361
if (ret)
@@ -344,6 +366,9 @@ static int hns3_nic_net_up(struct net_device *netdev)
344366
return 0;
345367

346368
out_start_err:
369+
while (j--)
370+
hns3_tqp_disable(h->kinfo.tqp[j]);
371+
347372
for (j = i - 1; j >= 0; j--)
348373
hns3_vector_disable(&priv->tqp_vector[j]);
349374

@@ -354,11 +379,13 @@ static int hns3_nic_net_up(struct net_device *netdev)
354379

355380
static int hns3_nic_net_open(struct net_device *netdev)
356381
{
357-
struct hns3_nic_priv *priv = netdev_priv(netdev);
358382
struct hnae3_handle *h = hns3_get_handle(netdev);
359383
struct hnae3_knic_private_info *kinfo;
360384
int i, ret;
361385

386+
if (hns3_nic_resetting(netdev))
387+
return -EBUSY;
388+
362389
netif_carrier_off(netdev);
363390

364391
ret = hns3_nic_set_real_num_queue(netdev);
@@ -378,13 +405,13 @@ static int hns3_nic_net_open(struct net_device *netdev)
378405
kinfo->prio_tc[i]);
379406
}
380407

381-
priv->ae_handle->last_reset_time = jiffies;
382408
return 0;
383409
}
384410

385411
static void hns3_nic_net_down(struct net_device *netdev)
386412
{
387413
struct hns3_nic_priv *priv = netdev_priv(netdev);
414+
struct hnae3_handle *h = hns3_get_handle(netdev);
388415
const struct hnae3_ae_ops *ops;
389416
int i;
390417

@@ -395,6 +422,10 @@ static void hns3_nic_net_down(struct net_device *netdev)
395422
for (i = 0; i < priv->vector_num; i++)
396423
hns3_vector_disable(&priv->tqp_vector[i]);
397424

425+
/* disable rcb */
426+
for (i = 0; i < h->kinfo.num_tqps; i++)
427+
hns3_tqp_disable(h->kinfo.tqp[i]);
428+
398429
/* stop ae_dev */
399430
ops = priv->ae_handle->ae_algo->ops;
400431
if (ops->stop)
@@ -1615,10 +1646,9 @@ static void hns3_nic_net_timeout(struct net_device *ndev)
16151646

16161647
priv->tx_timeout_count++;
16171648

1618-
if (time_before(jiffies, (h->last_reset_time + ndev->watchdog_timeo)))
1619-
return;
1620-
1621-
/* request the reset */
1649+
/* request the reset, and let the hclge to determine
1650+
* which reset level should be done
1651+
*/
16221652
if (h->ae_algo->ops->reset_event)
16231653
h->ae_algo->ops->reset_event(h->pdev, h);
16241654
}
@@ -3337,7 +3367,6 @@ static int hns3_client_init(struct hnae3_handle *handle)
33373367
priv->dev = &pdev->dev;
33383368
priv->netdev = netdev;
33393369
priv->ae_handle = handle;
3340-
priv->ae_handle->last_reset_time = jiffies;
33413370
priv->tx_timeout_count = 0;
33423371

33433372
handle->kinfo.netdev = netdev;
@@ -3357,11 +3386,6 @@ static int hns3_client_init(struct hnae3_handle *handle)
33573386
/* Carrier off reporting is important to ethtool even BEFORE open */
33583387
netif_carrier_off(netdev);
33593388

3360-
if (handle->flags & HNAE3_SUPPORT_VF)
3361-
handle->reset_level = HNAE3_VF_RESET;
3362-
else
3363-
handle->reset_level = HNAE3_FUNC_RESET;
3364-
33653389
ret = hns3_get_ring_config(priv);
33663390
if (ret) {
33673391
ret = -ENOMEM;
@@ -3397,6 +3421,8 @@ static int hns3_client_init(struct hnae3_handle *handle)
33973421
/* MTU range: (ETH_MIN_MTU(kernel default) - 9706) */
33983422
netdev->max_mtu = HNS3_MAX_MTU - (ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN);
33993423

3424+
set_bit(HNS3_NIC_STATE_INITED, &priv->state);
3425+
34003426
return ret;
34013427

34023428
out_reg_netdev_fail:
@@ -3423,6 +3449,11 @@ static void hns3_client_uninit(struct hnae3_handle *handle, bool reset)
34233449
if (netdev->reg_state != NETREG_UNINITIALIZED)
34243450
unregister_netdev(netdev);
34253451

3452+
if (!test_and_clear_bit(HNS3_NIC_STATE_INITED, &priv->state)) {
3453+
netdev_warn(netdev, "already uninitialized\n");
3454+
goto out_netdev_free;
3455+
}
3456+
34263457
hns3_del_all_fd_rules(netdev, true);
34273458

34283459
hns3_force_clear_all_rx_ring(handle);
@@ -3443,6 +3474,7 @@ static void hns3_client_uninit(struct hnae3_handle *handle, bool reset)
34433474

34443475
priv->ring_data = NULL;
34453476

3477+
out_netdev_free:
34463478
free_netdev(netdev);
34473479
}
34483480

@@ -3708,8 +3740,22 @@ static void hns3_restore_coal(struct hns3_nic_priv *priv)
37083740

37093741
static int hns3_reset_notify_down_enet(struct hnae3_handle *handle)
37103742
{
3743+
struct hnae3_ae_dev *ae_dev = pci_get_drvdata(handle->pdev);
37113744
struct hnae3_knic_private_info *kinfo = &handle->kinfo;
37123745
struct net_device *ndev = kinfo->netdev;
3746+
struct hns3_nic_priv *priv = netdev_priv(ndev);
3747+
3748+
if (test_and_set_bit(HNS3_NIC_STATE_RESETTING, &priv->state))
3749+
return 0;
3750+
3751+
/* it is cumbersome for hardware to pick-and-choose entries for deletion
3752+
* from table space. Hence, for function reset software intervention is
3753+
* required to delete the entries
3754+
*/
3755+
if (hns3_dev_ongoing_func_reset(ae_dev)) {
3756+
hns3_remove_hw_addr(ndev);
3757+
hns3_del_all_fd_rules(ndev, false);
3758+
}
37133759

37143760
if (!netif_running(ndev))
37153761
return 0;
@@ -3720,6 +3766,7 @@ static int hns3_reset_notify_down_enet(struct hnae3_handle *handle)
37203766
static int hns3_reset_notify_up_enet(struct hnae3_handle *handle)
37213767
{
37223768
struct hnae3_knic_private_info *kinfo = &handle->kinfo;
3769+
struct hns3_nic_priv *priv = netdev_priv(kinfo->netdev);
37233770
int ret = 0;
37243771

37253772
if (netif_running(kinfo->netdev)) {
@@ -3729,9 +3776,10 @@ static int hns3_reset_notify_up_enet(struct hnae3_handle *handle)
37293776
"hns net up fail, ret=%d!\n", ret);
37303777
return ret;
37313778
}
3732-
handle->last_reset_time = jiffies;
37333779
}
37343780

3781+
clear_bit(HNS3_NIC_STATE_RESETTING, &priv->state);
3782+
37353783
return ret;
37363784
}
37373785

@@ -3782,16 +3830,22 @@ static int hns3_reset_notify_init_enet(struct hnae3_handle *handle)
37823830
priv->ring_data = NULL;
37833831
}
37843832

3833+
set_bit(HNS3_NIC_STATE_INITED, &priv->state);
3834+
37853835
return ret;
37863836
}
37873837

37883838
static int hns3_reset_notify_uninit_enet(struct hnae3_handle *handle)
37893839
{
3790-
struct hnae3_ae_dev *ae_dev = pci_get_drvdata(handle->pdev);
37913840
struct net_device *netdev = handle->kinfo.netdev;
37923841
struct hns3_nic_priv *priv = netdev_priv(netdev);
37933842
int ret;
37943843

3844+
if (!test_bit(HNS3_NIC_STATE_INITED, &priv->state)) {
3845+
netdev_warn(netdev, "already uninitialized\n");
3846+
return 0;
3847+
}
3848+
37953849
hns3_force_clear_all_rx_ring(handle);
37963850

37973851
ret = hns3_nic_uninit_vector_data(priv);
@@ -3806,14 +3860,7 @@ static int hns3_reset_notify_uninit_enet(struct hnae3_handle *handle)
38063860
if (ret)
38073861
netdev_err(netdev, "uninit ring error\n");
38083862

3809-
/* it is cumbersome for hardware to pick-and-choose entries for deletion
3810-
* from table space. Hence, for function reset software intervention is
3811-
* required to delete the entries
3812-
*/
3813-
if (hns3_dev_ongoing_func_reset(ae_dev)) {
3814-
hns3_remove_hw_addr(netdev);
3815-
hns3_del_all_fd_rules(netdev, false);
3816-
}
3863+
clear_bit(HNS3_NIC_STATE_INITED, &priv->state);
38173864

38183865
return ret;
38193866
}

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ extern const char hns3_driver_version[];
1515
enum hns3_nic_state {
1616
HNS3_NIC_STATE_TESTING,
1717
HNS3_NIC_STATE_RESETTING,
18-
HNS3_NIC_STATE_REINITING,
18+
HNS3_NIC_STATE_INITED,
1919
HNS3_NIC_STATE_DOWN,
2020
HNS3_NIC_STATE_DISABLED,
2121
HNS3_NIC_STATE_REMOVING,
@@ -47,7 +47,7 @@ enum hns3_nic_state {
4747
#define HNS3_RING_PREFETCH_EN_REG 0x0007C
4848
#define HNS3_RING_CFG_VF_NUM_REG 0x00080
4949
#define HNS3_RING_ASID_REG 0x0008C
50-
#define HNS3_RING_RX_VM_REG 0x00090
50+
#define HNS3_RING_EN_REG 0x00090
5151
#define HNS3_RING_T0_BE_RST 0x00094
5252
#define HNS3_RING_COULD_BE_RST 0x00098
5353
#define HNS3_RING_WRR_WEIGHT_REG 0x0009c
@@ -194,6 +194,8 @@ enum hns3_nic_state {
194194
#define HNS3_VECTOR_RL_OFFSET 0x900
195195
#define HNS3_VECTOR_RL_EN_B 6
196196

197+
#define HNS3_RING_EN_B 0
198+
197199
enum hns3_pkt_l3t_type {
198200
HNS3_L3T_NONE,
199201
HNS3_L3T_IPV6,
@@ -577,6 +579,11 @@ static inline int is_ring_empty(struct hns3_enet_ring *ring)
577579
return ring->next_to_use == ring->next_to_clean;
578580
}
579581

582+
static inline u32 hns3_read_reg(void __iomem *base, u32 reg)
583+
{
584+
return readl(base + reg);
585+
}
586+
580587
static inline void hns3_write_reg(void __iomem *base, u32 reg, u32 value)
581588
{
582589
u8 __iomem *reg_addr = READ_ONCE(base);
@@ -589,6 +596,16 @@ static inline bool hns3_dev_ongoing_func_reset(struct hnae3_ae_dev *ae_dev)
589596
return (ae_dev && (ae_dev->reset_type == HNAE3_FUNC_RESET));
590597
}
591598

599+
#define hns3_read_dev(a, reg) \
600+
hns3_read_reg((a)->io_base, (reg))
601+
602+
static inline bool hns3_nic_resetting(struct net_device *netdev)
603+
{
604+
struct hns3_nic_priv *priv = netdev_priv(netdev);
605+
606+
return test_bit(HNS3_NIC_STATE_RESETTING, &priv->state);
607+
}
608+
592609
#define hns3_write_dev(a, reg, value) \
593610
hns3_write_reg((a)->io_base, (reg), (value))
594611

0 commit comments

Comments
 (0)