Skip to content

Commit f04d402

Browse files
committed
Merge branch 'hns3-fixes'
Huazhong Tan says: ==================== net: hns3: code optimizations & bugfixes for HNS3 driver This patchset includes bugfixes and code optimizations for the HNS3 ethernet controller driver ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 51a5365 + 1f60949 commit f04d402

File tree

9 files changed

+166
-200
lines changed

9 files changed

+166
-200
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ enum hnae3_reset_notify_type {
124124
HNAE3_DOWN_CLIENT,
125125
HNAE3_INIT_CLIENT,
126126
HNAE3_UNINIT_CLIENT,
127+
HNAE3_RESTORE_CLIENT,
127128
};
128129

129130
enum hnae3_reset_type {
@@ -500,6 +501,7 @@ struct hnae3_tc_info {
500501
struct hnae3_knic_private_info {
501502
struct net_device *netdev; /* Set by KNIC client when init instance */
502503
u16 rss_size; /* Allocated RSS queues */
504+
u16 req_rss_size;
503505
u16 rx_buf_len;
504506
u16 num_desc;
505507

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

Lines changed: 65 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -3185,6 +3185,9 @@ static int hns3_nic_uninit_vector_data(struct hns3_nic_priv *priv)
31853185
for (i = 0; i < priv->vector_num; i++) {
31863186
tqp_vector = &priv->tqp_vector[i];
31873187

3188+
if (!tqp_vector->rx_group.ring && !tqp_vector->tx_group.ring)
3189+
continue;
3190+
31883191
ret = hns3_get_vector_ring_chain(tqp_vector,
31893192
&vector_ring_chain);
31903193
if (ret)
@@ -3205,7 +3208,6 @@ static int hns3_nic_uninit_vector_data(struct hns3_nic_priv *priv)
32053208
tqp_vector->irq_init_flag = HNS3_VECTOR_NOT_INITED;
32063209
}
32073210

3208-
priv->ring_data[i].ring->irq_init_flag = HNS3_VECTOR_NOT_INITED;
32093211
hns3_clear_ring_group(&tqp_vector->rx_group);
32103212
hns3_clear_ring_group(&tqp_vector->tx_group);
32113213
netif_napi_del(&priv->tqp_vector[i].napi);
@@ -3238,6 +3240,7 @@ static int hns3_ring_get_cfg(struct hnae3_queue *q, struct hns3_nic_priv *priv,
32383240
{
32393241
struct hns3_nic_ring_data *ring_data = priv->ring_data;
32403242
int queue_num = priv->ae_handle->kinfo.num_tqps;
3243+
int desc_num = priv->ae_handle->kinfo.num_desc;
32413244
struct pci_dev *pdev = priv->ae_handle->pdev;
32423245
struct hns3_enet_ring *ring;
32433246

@@ -3263,7 +3266,7 @@ static int hns3_ring_get_cfg(struct hnae3_queue *q, struct hns3_nic_priv *priv,
32633266
ring->dev = priv->dev;
32643267
ring->desc_dma_addr = 0;
32653268
ring->buf_size = q->buf_size;
3266-
ring->desc_num = q->desc_num;
3269+
ring->desc_num = desc_num;
32673270
ring->next_to_use = 0;
32683271
ring->next_to_clean = 0;
32693272

@@ -3725,7 +3728,6 @@ static int hns3_client_setup_tc(struct hnae3_handle *handle, u8 tc)
37253728
{
37263729
struct hnae3_knic_private_info *kinfo = &handle->kinfo;
37273730
struct net_device *ndev = kinfo->netdev;
3728-
bool if_running;
37293731
int ret;
37303732

37313733
if (tc > HNAE3_MAX_TC)
@@ -3734,24 +3736,13 @@ static int hns3_client_setup_tc(struct hnae3_handle *handle, u8 tc)
37343736
if (!ndev)
37353737
return -ENODEV;
37363738

3737-
if_running = netif_running(ndev);
3738-
3739-
if (if_running) {
3740-
(void)hns3_nic_net_stop(ndev);
3741-
msleep(100);
3742-
}
3743-
37443739
ret = (kinfo->dcb_ops && kinfo->dcb_ops->map_update) ?
37453740
kinfo->dcb_ops->map_update(handle) : -EOPNOTSUPP;
37463741
if (ret)
3747-
goto err_out;
3742+
return ret;
37483743

37493744
ret = hns3_nic_set_real_num_queue(ndev);
37503745

3751-
err_out:
3752-
if (if_running)
3753-
(void)hns3_nic_net_open(ndev);
3754-
37553746
return ret;
37563747
}
37573748

@@ -4013,41 +4004,18 @@ static int hns3_reset_notify_init_enet(struct hnae3_handle *handle)
40134004
{
40144005
struct net_device *netdev = handle->kinfo.netdev;
40154006
struct hns3_nic_priv *priv = netdev_priv(netdev);
4016-
bool vlan_filter_enable;
40174007
int ret;
40184008

4019-
ret = hns3_init_mac_addr(netdev, false);
4020-
if (ret)
4021-
return ret;
4022-
4023-
ret = hns3_recover_hw_addr(netdev);
4024-
if (ret)
4025-
return ret;
4026-
4027-
ret = hns3_update_promisc_mode(netdev, handle->netdev_flags);
4028-
if (ret)
4029-
return ret;
4030-
4031-
vlan_filter_enable = netdev->flags & IFF_PROMISC ? false : true;
4032-
hns3_enable_vlan_filter(netdev, vlan_filter_enable);
4033-
4034-
/* Hardware table is only clear when pf resets */
4035-
if (!(handle->flags & HNAE3_SUPPORT_VF)) {
4036-
ret = hns3_restore_vlan(netdev);
4037-
if (ret)
4038-
return ret;
4039-
}
4009+
/* Carrier off reporting is important to ethtool even BEFORE open */
4010+
netif_carrier_off(netdev);
40404011

4041-
ret = hns3_restore_fd_rules(netdev);
4012+
ret = hns3_get_ring_config(priv);
40424013
if (ret)
40434014
return ret;
40444015

4045-
/* Carrier off reporting is important to ethtool even BEFORE open */
4046-
netif_carrier_off(netdev);
4047-
40484016
ret = hns3_nic_alloc_vector_data(priv);
40494017
if (ret)
4050-
return ret;
4018+
goto err_put_ring;
40514019

40524020
hns3_restore_coal(priv);
40534021

@@ -4068,10 +4036,44 @@ static int hns3_reset_notify_init_enet(struct hnae3_handle *handle)
40684036
priv->ring_data = NULL;
40694037
err_dealloc_vector:
40704038
hns3_nic_dealloc_vector_data(priv);
4039+
err_put_ring:
4040+
hns3_put_ring_config(priv);
4041+
priv->ring_data = NULL;
40714042

40724043
return ret;
40734044
}
40744045

4046+
static int hns3_reset_notify_restore_enet(struct hnae3_handle *handle)
4047+
{
4048+
struct net_device *netdev = handle->kinfo.netdev;
4049+
bool vlan_filter_enable;
4050+
int ret;
4051+
4052+
ret = hns3_init_mac_addr(netdev, false);
4053+
if (ret)
4054+
return ret;
4055+
4056+
ret = hns3_recover_hw_addr(netdev);
4057+
if (ret)
4058+
return ret;
4059+
4060+
ret = hns3_update_promisc_mode(netdev, handle->netdev_flags);
4061+
if (ret)
4062+
return ret;
4063+
4064+
vlan_filter_enable = netdev->flags & IFF_PROMISC ? false : true;
4065+
hns3_enable_vlan_filter(netdev, vlan_filter_enable);
4066+
4067+
/* Hardware table is only clear when pf resets */
4068+
if (!(handle->flags & HNAE3_SUPPORT_VF)) {
4069+
ret = hns3_restore_vlan(netdev);
4070+
if (ret)
4071+
return ret;
4072+
}
4073+
4074+
return hns3_restore_fd_rules(netdev);
4075+
}
4076+
40754077
static int hns3_reset_notify_uninit_enet(struct hnae3_handle *handle)
40764078
{
40774079
struct net_device *netdev = handle->kinfo.netdev;
@@ -4101,6 +4103,9 @@ static int hns3_reset_notify_uninit_enet(struct hnae3_handle *handle)
41014103
if (ret)
41024104
netdev_err(netdev, "uninit ring error\n");
41034105

4106+
hns3_put_ring_config(priv);
4107+
priv->ring_data = NULL;
4108+
41044109
clear_bit(HNS3_NIC_STATE_INITED, &priv->state);
41054110

41064111
return ret;
@@ -4124,64 +4129,21 @@ static int hns3_reset_notify(struct hnae3_handle *handle,
41244129
case HNAE3_UNINIT_CLIENT:
41254130
ret = hns3_reset_notify_uninit_enet(handle);
41264131
break;
4132+
case HNAE3_RESTORE_CLIENT:
4133+
ret = hns3_reset_notify_restore_enet(handle);
4134+
break;
41274135
default:
41284136
break;
41294137
}
41304138

41314139
return ret;
41324140
}
41334141

4134-
static int hns3_modify_tqp_num(struct net_device *netdev, u16 new_tqp_num)
4135-
{
4136-
struct hns3_nic_priv *priv = netdev_priv(netdev);
4137-
struct hnae3_handle *h = hns3_get_handle(netdev);
4138-
int ret;
4139-
4140-
ret = h->ae_algo->ops->set_channels(h, new_tqp_num);
4141-
if (ret)
4142-
return ret;
4143-
4144-
ret = hns3_get_ring_config(priv);
4145-
if (ret)
4146-
return ret;
4147-
4148-
ret = hns3_nic_alloc_vector_data(priv);
4149-
if (ret)
4150-
goto err_alloc_vector;
4151-
4152-
hns3_restore_coal(priv);
4153-
4154-
ret = hns3_nic_init_vector_data(priv);
4155-
if (ret)
4156-
goto err_uninit_vector;
4157-
4158-
ret = hns3_init_all_ring(priv);
4159-
if (ret)
4160-
goto err_put_ring;
4161-
4162-
return 0;
4163-
4164-
err_put_ring:
4165-
hns3_put_ring_config(priv);
4166-
err_uninit_vector:
4167-
hns3_nic_uninit_vector_data(priv);
4168-
err_alloc_vector:
4169-
hns3_nic_dealloc_vector_data(priv);
4170-
return ret;
4171-
}
4172-
4173-
static int hns3_adjust_tqps_num(u8 num_tc, u32 new_tqp_num)
4174-
{
4175-
return (new_tqp_num / num_tc) * num_tc;
4176-
}
4177-
41784142
int hns3_set_channels(struct net_device *netdev,
41794143
struct ethtool_channels *ch)
41804144
{
4181-
struct hns3_nic_priv *priv = netdev_priv(netdev);
41824145
struct hnae3_handle *h = hns3_get_handle(netdev);
41834146
struct hnae3_knic_private_info *kinfo = &h->kinfo;
4184-
bool if_running = netif_running(netdev);
41854147
u32 new_tqp_num = ch->combined_count;
41864148
u16 org_tqp_num;
41874149
int ret;
@@ -4190,39 +4152,28 @@ int hns3_set_channels(struct net_device *netdev,
41904152
return -EINVAL;
41914153

41924154
if (new_tqp_num > hns3_get_max_available_channels(h) ||
4193-
new_tqp_num < kinfo->num_tc) {
4155+
new_tqp_num < 1) {
41944156
dev_err(&netdev->dev,
4195-
"Change tqps fail, the tqp range is from %d to %d",
4196-
kinfo->num_tc,
4157+
"Change tqps fail, the tqp range is from 1 to %d",
41974158
hns3_get_max_available_channels(h));
41984159
return -EINVAL;
41994160
}
42004161

4201-
new_tqp_num = hns3_adjust_tqps_num(kinfo->num_tc, new_tqp_num);
4202-
if (kinfo->num_tqps == new_tqp_num)
4162+
if (kinfo->rss_size == new_tqp_num)
42034163
return 0;
42044164

4205-
if (if_running)
4206-
hns3_nic_net_stop(netdev);
4207-
4208-
ret = hns3_nic_uninit_vector_data(priv);
4209-
if (ret) {
4210-
dev_err(&netdev->dev,
4211-
"Unbind vector with tqp fail, nothing is changed");
4212-
goto open_netdev;
4213-
}
4214-
4215-
hns3_store_coal(priv);
4216-
4217-
hns3_nic_dealloc_vector_data(priv);
4165+
ret = hns3_reset_notify(h, HNAE3_DOWN_CLIENT);
4166+
if (ret)
4167+
return ret;
42184168

4219-
hns3_uninit_all_ring(priv);
4220-
hns3_put_ring_config(priv);
4169+
ret = hns3_reset_notify(h, HNAE3_UNINIT_CLIENT);
4170+
if (ret)
4171+
return ret;
42214172

42224173
org_tqp_num = h->kinfo.num_tqps;
4223-
ret = hns3_modify_tqp_num(netdev, new_tqp_num);
4174+
ret = h->ae_algo->ops->set_channels(h, new_tqp_num);
42244175
if (ret) {
4225-
ret = hns3_modify_tqp_num(netdev, org_tqp_num);
4176+
ret = h->ae_algo->ops->set_channels(h, org_tqp_num);
42264177
if (ret) {
42274178
/* If revert to old tqp failed, fatal error occurred */
42284179
dev_err(&netdev->dev,
@@ -4232,12 +4183,11 @@ int hns3_set_channels(struct net_device *netdev,
42324183
dev_info(&netdev->dev,
42334184
"Change tqp num fail, Revert to old tqp num");
42344185
}
4186+
ret = hns3_reset_notify(h, HNAE3_INIT_CLIENT);
4187+
if (ret)
4188+
return ret;
42354189

4236-
open_netdev:
4237-
if (if_running)
4238-
hns3_nic_net_open(netdev);
4239-
4240-
return ret;
4190+
return hns3_reset_notify(h, HNAE3_UP_CLIENT);
42414191
}
42424192

42434193
static const struct hnae3_client_ops client_ops = {

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,6 @@ struct hns3_enet_ring {
412412
unsigned char *va; /* first buffer address for current packet */
413413

414414
u32 flag; /* ring attribute */
415-
int irq_init_flag;
416415

417416
int numa_node;
418417
cpumask_t affinity_mask;

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,16 @@ static int hclge_ieee_setets(struct hnae3_handle *h, struct ieee_ets *ets)
222222
if (ret)
223223
return ret;
224224

225+
if (map_changed) {
226+
ret = hclge_notify_client(hdev, HNAE3_DOWN_CLIENT);
227+
if (ret)
228+
return ret;
229+
230+
ret = hclge_notify_client(hdev, HNAE3_UNINIT_CLIENT);
231+
if (ret)
232+
return ret;
233+
}
234+
225235
hclge_tm_schd_info_update(hdev, num_tc);
226236

227237
ret = hclge_ieee_ets_to_tm_info(hdev, ets);
@@ -232,6 +242,13 @@ static int hclge_ieee_setets(struct hnae3_handle *h, struct ieee_ets *ets)
232242
ret = hclge_client_setup_tc(hdev);
233243
if (ret)
234244
return ret;
245+
ret = hclge_notify_client(hdev, HNAE3_INIT_CLIENT);
246+
if (ret)
247+
return ret;
248+
249+
ret = hclge_notify_client(hdev, HNAE3_UP_CLIENT);
250+
if (ret)
251+
return ret;
235252
}
236253

237254
return hclge_tm_dwrr_cfg(hdev);

0 commit comments

Comments
 (0)