Skip to content

Commit 8df0fa9

Browse files
Huazhong Tandavem330
authored andcommitted
net: hns3: enable/disable ring in the enet while doing UP/DOWN
While hardware gets into reset status, the firmware will not respond to driver's command request, which may cause ring not disabled problem during reset process. So this patch uses register instead of command to enable/disable the ring in the enet while doing UP/DOWN operation. Also, HNS3_RING_RX_VM_REG is previously unused, so change it to the correct meaning, and add a wrapper function for readl(). Fixes: 46a3df9 ("net: hns3: Add HNS3 Acceleration Engine & Compatibility Layer Support") Signed-off-by: Huazhong Tan <tanhuazhong@huawei.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 7edff53 commit 8df0fa9

File tree

4 files changed

+41
-44
lines changed

4 files changed

+41
-44
lines changed

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

Lines changed: 30 additions & 0 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

@@ -385,6 +410,7 @@ static int hns3_nic_net_open(struct net_device *netdev)
385410
static void hns3_nic_net_down(struct net_device *netdev)
386411
{
387412
struct hns3_nic_priv *priv = netdev_priv(netdev);
413+
struct hnae3_handle *h = hns3_get_handle(netdev);
388414
const struct hnae3_ae_ops *ops;
389415
int i;
390416

@@ -395,6 +421,10 @@ static void hns3_nic_net_down(struct net_device *netdev)
395421
for (i = 0; i < priv->vector_num; i++)
396422
hns3_vector_disable(&priv->tqp_vector[i]);
397423

424+
/* disable rcb */
425+
for (i = 0; i < h->kinfo.num_tqps; i++)
426+
hns3_tqp_disable(h->kinfo.tqp[i]);
427+
398428
/* stop ae_dev */
399429
ops = priv->ae_handle->ae_algo->ops;
400430
if (ops->stop)

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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,9 @@ 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+
592602
#define hns3_write_dev(a, reg, value) \
593603
hns3_write_reg((a)->io_base, (reg), (value))
594604

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4843,10 +4843,6 @@ static int hclge_ae_start(struct hnae3_handle *handle)
48434843
{
48444844
struct hclge_vport *vport = hclge_get_vport(handle);
48454845
struct hclge_dev *hdev = vport->back;
4846-
int i;
4847-
4848-
for (i = 0; i < vport->alloc_tqps; i++)
4849-
hclge_tqp_enable(hdev, i, 0, true);
48504846

48514847
/* mac enable */
48524848
hclge_cfg_mac_mode(hdev, true);
@@ -4866,7 +4862,6 @@ static void hclge_ae_stop(struct hnae3_handle *handle)
48664862
{
48674863
struct hclge_vport *vport = hclge_get_vport(handle);
48684864
struct hclge_dev *hdev = vport->back;
4869-
int i;
48704865

48714866
set_bit(HCLGE_STATE_DOWN, &hdev->state);
48724867

@@ -4879,9 +4874,6 @@ static void hclge_ae_stop(struct hnae3_handle *handle)
48794874
return;
48804875
}
48814876

4882-
for (i = 0; i < vport->alloc_tqps; i++)
4883-
hclge_tqp_enable(hdev, i, 0, false);
4884-
48854877
/* Mac disable */
48864878
hclge_cfg_mac_mode(hdev, false);
48874879

drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -956,13 +956,6 @@ static int hclgevf_tqp_enable(struct hclgevf_dev *hdev, int tqp_id,
956956
return status;
957957
}
958958

959-
static int hclgevf_get_queue_id(struct hnae3_queue *queue)
960-
{
961-
struct hclgevf_tqp *tqp = container_of(queue, struct hclgevf_tqp, q);
962-
963-
return tqp->index;
964-
}
965-
966959
static void hclgevf_reset_tqp_stats(struct hnae3_handle *handle)
967960
{
968961
struct hnae3_knic_private_info *kinfo = &handle->kinfo;
@@ -1593,21 +1586,7 @@ static int hclgevf_init_vlan_config(struct hclgevf_dev *hdev)
15931586

15941587
static int hclgevf_ae_start(struct hnae3_handle *handle)
15951588
{
1596-
struct hnae3_knic_private_info *kinfo = &handle->kinfo;
15971589
struct hclgevf_dev *hdev = hclgevf_ae_get_hdev(handle);
1598-
int i, queue_id;
1599-
1600-
for (i = 0; i < kinfo->num_tqps; i++) {
1601-
/* ring enable */
1602-
queue_id = hclgevf_get_queue_id(kinfo->tqp[i]);
1603-
if (queue_id < 0) {
1604-
dev_warn(&hdev->pdev->dev,
1605-
"Get invalid queue id, ignore it\n");
1606-
continue;
1607-
}
1608-
1609-
hclgevf_tqp_enable(hdev, queue_id, 0, true);
1610-
}
16111590

16121591
/* reset tqp stats */
16131592
hclgevf_reset_tqp_stats(handle);
@@ -1622,24 +1601,10 @@ static int hclgevf_ae_start(struct hnae3_handle *handle)
16221601

16231602
static void hclgevf_ae_stop(struct hnae3_handle *handle)
16241603
{
1625-
struct hnae3_knic_private_info *kinfo = &handle->kinfo;
16261604
struct hclgevf_dev *hdev = hclgevf_ae_get_hdev(handle);
1627-
int i, queue_id;
16281605

16291606
set_bit(HCLGEVF_STATE_DOWN, &hdev->state);
16301607

1631-
for (i = 0; i < kinfo->num_tqps; i++) {
1632-
/* Ring disable */
1633-
queue_id = hclgevf_get_queue_id(kinfo->tqp[i]);
1634-
if (queue_id < 0) {
1635-
dev_warn(&hdev->pdev->dev,
1636-
"Get invalid queue id, ignore it\n");
1637-
continue;
1638-
}
1639-
1640-
hclgevf_tqp_enable(hdev, queue_id, 0, false);
1641-
}
1642-
16431608
/* reset tqp stats */
16441609
hclgevf_reset_tqp_stats(handle);
16451610
del_timer_sync(&hdev->service_timer);

0 commit comments

Comments
 (0)