forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/drivers/net/ethernet/huawei/hinic/hinic_main.c
....@@ -1,16 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Huawei HiNIC PCI Express Linux driver
34 * Copyright(c) 2017 Huawei Technologies Co., Ltd
4
- *
5
- * This program is free software; you can redistribute it and/or modify it
6
- * under the terms and conditions of the GNU General Public License,
7
- * version 2, as published by the Free Software Foundation.
8
- *
9
- * This program is distributed in the hope it will be useful, but WITHOUT
10
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
- * for more details.
13
- *
145 */
156
167 #include <linux/kernel.h>
....@@ -27,17 +18,21 @@
2718 #include <linux/semaphore.h>
2819 #include <linux/workqueue.h>
2920 #include <net/ip.h>
21
+#include <net/devlink.h>
3022 #include <linux/bitops.h>
3123 #include <linux/bitmap.h>
3224 #include <linux/delay.h>
3325 #include <linux/err.h>
3426
27
+#include "hinic_debugfs.h"
3528 #include "hinic_hw_qp.h"
3629 #include "hinic_hw_dev.h"
30
+#include "hinic_devlink.h"
3731 #include "hinic_port.h"
3832 #include "hinic_tx.h"
3933 #include "hinic_rx.h"
4034 #include "hinic_dev.h"
35
+#include "hinic_sriov.h"
4136
4237 MODULE_AUTHOR("Huawei Technologies CO., Ltd");
4338 MODULE_DESCRIPTION("Huawei Intelligent NIC driver");
....@@ -51,9 +46,11 @@
5146 module_param(rx_weight, uint, 0644);
5247 MODULE_PARM_DESC(rx_weight, "Number Rx packets for NAPI budget (default=64)");
5348
54
-#define HINIC_DEV_ID_QUAD_PORT_25GE 0x1822
55
-#define HINIC_DEV_ID_DUAL_PORT_25GE 0x0200
56
-#define HINIC_DEV_ID_DUAL_PORT_100GE 0x0201
49
+#define HINIC_DEV_ID_QUAD_PORT_25GE 0x1822
50
+#define HINIC_DEV_ID_DUAL_PORT_100GE 0x0200
51
+#define HINIC_DEV_ID_DUAL_PORT_100GE_MEZZ 0x0205
52
+#define HINIC_DEV_ID_QUAD_PORT_25GE_MEZZ 0x0210
53
+#define HINIC_DEV_ID_VF 0x375e
5754
5855 #define HINIC_WQ_NAME "hinic_dev"
5956
....@@ -61,7 +58,9 @@
6158 NETIF_MSG_IFUP | \
6259 NETIF_MSG_TX_ERR | NETIF_MSG_RX_ERR)
6360
64
-#define VLAN_BITMAP_SIZE(nic_dev) (ALIGN(VLAN_N_VID, 8) / 8)
61
+#define HINIC_LRO_MAX_WQE_NUM_DEFAULT 8
62
+
63
+#define HINIC_LRO_RX_TIMER_DEFAULT 16
6564
6665 #define work_to_rx_mode_work(work) \
6766 container_of(work, struct hinic_rx_mode_work, work)
....@@ -69,186 +68,56 @@
6968 #define rx_mode_work_to_nic_dev(rx_mode_work) \
7069 container_of(rx_mode_work, struct hinic_dev, rx_mode_work)
7170
71
+#define HINIC_WAIT_SRIOV_CFG_TIMEOUT 15000
72
+
73
+#define HINIC_DEAULT_TXRX_MSIX_PENDING_LIMIT 2
74
+#define HINIC_DEAULT_TXRX_MSIX_COALESC_TIMER_CFG 32
75
+#define HINIC_DEAULT_TXRX_MSIX_RESEND_TIMER_CFG 7
76
+
7277 static int change_mac_addr(struct net_device *netdev, const u8 *addr);
7378
74
-static void set_link_speed(struct ethtool_link_ksettings *link_ksettings,
75
- enum hinic_speed speed)
79
+static int set_features(struct hinic_dev *nic_dev,
80
+ netdev_features_t pre_features,
81
+ netdev_features_t features, bool force_change);
82
+
83
+static void gather_rx_stats(struct hinic_rxq_stats *nic_rx_stats, struct hinic_rxq *rxq)
7684 {
77
- switch (speed) {
78
- case HINIC_SPEED_10MB_LINK:
79
- link_ksettings->base.speed = SPEED_10;
80
- break;
81
-
82
- case HINIC_SPEED_100MB_LINK:
83
- link_ksettings->base.speed = SPEED_100;
84
- break;
85
-
86
- case HINIC_SPEED_1000MB_LINK:
87
- link_ksettings->base.speed = SPEED_1000;
88
- break;
89
-
90
- case HINIC_SPEED_10GB_LINK:
91
- link_ksettings->base.speed = SPEED_10000;
92
- break;
93
-
94
- case HINIC_SPEED_25GB_LINK:
95
- link_ksettings->base.speed = SPEED_25000;
96
- break;
97
-
98
- case HINIC_SPEED_40GB_LINK:
99
- link_ksettings->base.speed = SPEED_40000;
100
- break;
101
-
102
- case HINIC_SPEED_100GB_LINK:
103
- link_ksettings->base.speed = SPEED_100000;
104
- break;
105
-
106
- default:
107
- link_ksettings->base.speed = SPEED_UNKNOWN;
108
- break;
109
- }
110
-}
111
-
112
-static int hinic_get_link_ksettings(struct net_device *netdev,
113
- struct ethtool_link_ksettings
114
- *link_ksettings)
115
-{
116
- struct hinic_dev *nic_dev = netdev_priv(netdev);
117
- enum hinic_port_link_state link_state;
118
- struct hinic_port_cap port_cap;
119
- int err;
120
-
121
- ethtool_link_ksettings_zero_link_mode(link_ksettings, advertising);
122
- ethtool_link_ksettings_add_link_mode(link_ksettings, supported,
123
- Autoneg);
124
-
125
- link_ksettings->base.speed = SPEED_UNKNOWN;
126
- link_ksettings->base.autoneg = AUTONEG_DISABLE;
127
- link_ksettings->base.duplex = DUPLEX_UNKNOWN;
128
-
129
- err = hinic_port_get_cap(nic_dev, &port_cap);
130
- if (err) {
131
- netif_err(nic_dev, drv, netdev,
132
- "Failed to get port capabilities\n");
133
- return err;
134
- }
135
-
136
- err = hinic_port_link_state(nic_dev, &link_state);
137
- if (err) {
138
- netif_err(nic_dev, drv, netdev,
139
- "Failed to get port link state\n");
140
- return err;
141
- }
142
-
143
- if (link_state != HINIC_LINK_STATE_UP) {
144
- netif_info(nic_dev, drv, netdev, "No link\n");
145
- return err;
146
- }
147
-
148
- set_link_speed(link_ksettings, port_cap.speed);
149
-
150
- if (!!(port_cap.autoneg_cap & HINIC_AUTONEG_SUPPORTED))
151
- ethtool_link_ksettings_add_link_mode(link_ksettings,
152
- advertising, Autoneg);
153
-
154
- if (port_cap.autoneg_state == HINIC_AUTONEG_ACTIVE)
155
- link_ksettings->base.autoneg = AUTONEG_ENABLE;
156
-
157
- link_ksettings->base.duplex = (port_cap.duplex == HINIC_DUPLEX_FULL) ?
158
- DUPLEX_FULL : DUPLEX_HALF;
159
- return 0;
160
-}
161
-
162
-static void hinic_get_drvinfo(struct net_device *netdev,
163
- struct ethtool_drvinfo *info)
164
-{
165
- struct hinic_dev *nic_dev = netdev_priv(netdev);
166
- struct hinic_hwdev *hwdev = nic_dev->hwdev;
167
- struct hinic_hwif *hwif = hwdev->hwif;
168
-
169
- strlcpy(info->driver, HINIC_DRV_NAME, sizeof(info->driver));
170
- strlcpy(info->bus_info, pci_name(hwif->pdev), sizeof(info->bus_info));
171
-}
172
-
173
-static void hinic_get_ringparam(struct net_device *netdev,
174
- struct ethtool_ringparam *ring)
175
-{
176
- ring->rx_max_pending = HINIC_RQ_DEPTH;
177
- ring->tx_max_pending = HINIC_SQ_DEPTH;
178
- ring->rx_pending = HINIC_RQ_DEPTH;
179
- ring->tx_pending = HINIC_SQ_DEPTH;
180
-}
181
-
182
-static void hinic_get_channels(struct net_device *netdev,
183
- struct ethtool_channels *channels)
184
-{
185
- struct hinic_dev *nic_dev = netdev_priv(netdev);
186
- struct hinic_hwdev *hwdev = nic_dev->hwdev;
187
-
188
- channels->max_rx = hwdev->nic_cap.max_qps;
189
- channels->max_tx = hwdev->nic_cap.max_qps;
190
- channels->max_other = 0;
191
- channels->max_combined = 0;
192
- channels->rx_count = hinic_hwdev_num_qps(hwdev);
193
- channels->tx_count = hinic_hwdev_num_qps(hwdev);
194
- channels->other_count = 0;
195
- channels->combined_count = 0;
196
-}
197
-
198
-static const struct ethtool_ops hinic_ethtool_ops = {
199
- .get_link_ksettings = hinic_get_link_ksettings,
200
- .get_drvinfo = hinic_get_drvinfo,
201
- .get_link = ethtool_op_get_link,
202
- .get_ringparam = hinic_get_ringparam,
203
- .get_channels = hinic_get_channels,
204
-};
205
-
206
-static void update_rx_stats(struct hinic_dev *nic_dev, struct hinic_rxq *rxq)
207
-{
208
- struct hinic_rxq_stats *nic_rx_stats = &nic_dev->rx_stats;
20985 struct hinic_rxq_stats rx_stats;
210
-
211
- u64_stats_init(&rx_stats.syncp);
21286
21387 hinic_rxq_get_stats(rxq, &rx_stats);
21488
215
- u64_stats_update_begin(&nic_rx_stats->syncp);
21689 nic_rx_stats->bytes += rx_stats.bytes;
21790 nic_rx_stats->pkts += rx_stats.pkts;
218
- u64_stats_update_end(&nic_rx_stats->syncp);
219
-
220
- hinic_rxq_clean_stats(rxq);
91
+ nic_rx_stats->errors += rx_stats.errors;
92
+ nic_rx_stats->csum_errors += rx_stats.csum_errors;
93
+ nic_rx_stats->other_errors += rx_stats.other_errors;
22194 }
22295
223
-static void update_tx_stats(struct hinic_dev *nic_dev, struct hinic_txq *txq)
96
+static void gather_tx_stats(struct hinic_txq_stats *nic_tx_stats, struct hinic_txq *txq)
22497 {
225
- struct hinic_txq_stats *nic_tx_stats = &nic_dev->tx_stats;
22698 struct hinic_txq_stats tx_stats;
227
-
228
- u64_stats_init(&tx_stats.syncp);
22999
230100 hinic_txq_get_stats(txq, &tx_stats);
231101
232
- u64_stats_update_begin(&nic_tx_stats->syncp);
233102 nic_tx_stats->bytes += tx_stats.bytes;
234103 nic_tx_stats->pkts += tx_stats.pkts;
235104 nic_tx_stats->tx_busy += tx_stats.tx_busy;
236105 nic_tx_stats->tx_wake += tx_stats.tx_wake;
237106 nic_tx_stats->tx_dropped += tx_stats.tx_dropped;
238
- u64_stats_update_end(&nic_tx_stats->syncp);
239
-
240
- hinic_txq_clean_stats(txq);
107
+ nic_tx_stats->big_frags_pkts += tx_stats.big_frags_pkts;
241108 }
242109
243
-static void update_nic_stats(struct hinic_dev *nic_dev)
110
+static void gather_nic_stats(struct hinic_dev *nic_dev,
111
+ struct hinic_rxq_stats *nic_rx_stats,
112
+ struct hinic_txq_stats *nic_tx_stats)
244113 {
245114 int i, num_qps = hinic_hwdev_num_qps(nic_dev->hwdev);
246115
247116 for (i = 0; i < num_qps; i++)
248
- update_rx_stats(nic_dev, &nic_dev->rxqs[i]);
117
+ gather_rx_stats(nic_rx_stats, &nic_dev->rxqs[i]);
249118
250119 for (i = 0; i < num_qps; i++)
251
- update_tx_stats(nic_dev, &nic_dev->txqs[i]);
120
+ gather_tx_stats(nic_tx_stats, &nic_dev->txqs[i]);
252121 }
253122
254123 /**
....@@ -261,15 +130,16 @@
261130 {
262131 int err, i, j, num_txqs = hinic_hwdev_num_qps(nic_dev->hwdev);
263132 struct net_device *netdev = nic_dev->netdev;
264
- size_t txq_size;
265133
266134 if (nic_dev->txqs)
267135 return -EINVAL;
268136
269
- txq_size = num_txqs * sizeof(*nic_dev->txqs);
270
- nic_dev->txqs = devm_kzalloc(&netdev->dev, txq_size, GFP_KERNEL);
137
+ nic_dev->txqs = devm_kcalloc(&netdev->dev, num_txqs,
138
+ sizeof(*nic_dev->txqs), GFP_KERNEL);
271139 if (!nic_dev->txqs)
272140 return -ENOMEM;
141
+
142
+ hinic_sq_dbgfs_init(nic_dev);
273143
274144 for (i = 0; i < num_txqs; i++) {
275145 struct hinic_sq *sq = hinic_hwdev_get_sq(nic_dev->hwdev, i);
....@@ -280,16 +150,48 @@
280150 "Failed to init Txq\n");
281151 goto err_init_txq;
282152 }
153
+
154
+ err = hinic_sq_debug_add(nic_dev, i);
155
+ if (err) {
156
+ netif_err(nic_dev, drv, netdev,
157
+ "Failed to add SQ%d debug\n", i);
158
+ goto err_add_sq_dbg;
159
+ }
160
+
283161 }
284162
285163 return 0;
286164
165
+err_add_sq_dbg:
166
+ hinic_clean_txq(&nic_dev->txqs[i]);
287167 err_init_txq:
288
- for (j = 0; j < i; j++)
168
+ for (j = 0; j < i; j++) {
169
+ hinic_sq_debug_rem(nic_dev->txqs[j].sq);
289170 hinic_clean_txq(&nic_dev->txqs[j]);
171
+ }
172
+
173
+ hinic_sq_dbgfs_uninit(nic_dev);
290174
291175 devm_kfree(&netdev->dev, nic_dev->txqs);
292176 return err;
177
+}
178
+
179
+static void enable_txqs_napi(struct hinic_dev *nic_dev)
180
+{
181
+ int num_txqs = hinic_hwdev_num_qps(nic_dev->hwdev);
182
+ int i;
183
+
184
+ for (i = 0; i < num_txqs; i++)
185
+ napi_enable(&nic_dev->txqs[i].napi);
186
+}
187
+
188
+static void disable_txqs_napi(struct hinic_dev *nic_dev)
189
+{
190
+ int num_txqs = hinic_hwdev_num_qps(nic_dev->hwdev);
191
+ int i;
192
+
193
+ for (i = 0; i < num_txqs; i++)
194
+ napi_disable(&nic_dev->txqs[i].napi);
293195 }
294196
295197 /**
....@@ -304,8 +206,12 @@
304206 if (!nic_dev->txqs)
305207 return;
306208
307
- for (i = 0; i < num_txqs; i++)
209
+ for (i = 0; i < num_txqs; i++) {
210
+ hinic_sq_debug_rem(nic_dev->txqs[i].sq);
308211 hinic_clean_txq(&nic_dev->txqs[i]);
212
+ }
213
+
214
+ hinic_sq_dbgfs_uninit(nic_dev);
309215
310216 devm_kfree(&netdev->dev, nic_dev->txqs);
311217 nic_dev->txqs = NULL;
....@@ -321,15 +227,16 @@
321227 {
322228 int err, i, j, num_rxqs = hinic_hwdev_num_qps(nic_dev->hwdev);
323229 struct net_device *netdev = nic_dev->netdev;
324
- size_t rxq_size;
325230
326231 if (nic_dev->rxqs)
327232 return -EINVAL;
328233
329
- rxq_size = num_rxqs * sizeof(*nic_dev->rxqs);
330
- nic_dev->rxqs = devm_kzalloc(&netdev->dev, rxq_size, GFP_KERNEL);
234
+ nic_dev->rxqs = devm_kcalloc(&netdev->dev, num_rxqs,
235
+ sizeof(*nic_dev->rxqs), GFP_KERNEL);
331236 if (!nic_dev->rxqs)
332237 return -ENOMEM;
238
+
239
+ hinic_rq_dbgfs_init(nic_dev);
333240
334241 for (i = 0; i < num_rxqs; i++) {
335242 struct hinic_rq *rq = hinic_hwdev_get_rq(nic_dev->hwdev, i);
....@@ -340,13 +247,26 @@
340247 "Failed to init rxq\n");
341248 goto err_init_rxq;
342249 }
250
+
251
+ err = hinic_rq_debug_add(nic_dev, i);
252
+ if (err) {
253
+ netif_err(nic_dev, drv, netdev,
254
+ "Failed to add RQ%d debug\n", i);
255
+ goto err_add_rq_dbg;
256
+ }
343257 }
344258
345259 return 0;
346260
261
+err_add_rq_dbg:
262
+ hinic_clean_rxq(&nic_dev->rxqs[i]);
347263 err_init_rxq:
348
- for (j = 0; j < i; j++)
264
+ for (j = 0; j < i; j++) {
265
+ hinic_rq_debug_rem(nic_dev->rxqs[j].rq);
349266 hinic_clean_rxq(&nic_dev->rxqs[j]);
267
+ }
268
+
269
+ hinic_rq_dbgfs_uninit(nic_dev);
350270
351271 devm_kfree(&netdev->dev, nic_dev->rxqs);
352272 return err;
....@@ -364,21 +284,150 @@
364284 if (!nic_dev->rxqs)
365285 return;
366286
367
- for (i = 0; i < num_rxqs; i++)
287
+ for (i = 0; i < num_rxqs; i++) {
288
+ hinic_rq_debug_rem(nic_dev->rxqs[i].rq);
368289 hinic_clean_rxq(&nic_dev->rxqs[i]);
290
+ }
291
+
292
+ hinic_rq_dbgfs_uninit(nic_dev);
369293
370294 devm_kfree(&netdev->dev, nic_dev->rxqs);
371295 nic_dev->rxqs = NULL;
372296 }
373297
374
-static int hinic_open(struct net_device *netdev)
298
+static int hinic_configure_max_qnum(struct hinic_dev *nic_dev)
299
+{
300
+ int err;
301
+
302
+ err = hinic_set_max_qnum(nic_dev, nic_dev->hwdev->nic_cap.max_qps);
303
+ if (err)
304
+ return err;
305
+
306
+ return 0;
307
+}
308
+
309
+static int hinic_rss_init(struct hinic_dev *nic_dev)
310
+{
311
+ u8 default_rss_key[HINIC_RSS_KEY_SIZE];
312
+ u8 tmpl_idx = nic_dev->rss_tmpl_idx;
313
+ u32 *indir_tbl;
314
+ int err, i;
315
+
316
+ indir_tbl = kcalloc(HINIC_RSS_INDIR_SIZE, sizeof(u32), GFP_KERNEL);
317
+ if (!indir_tbl)
318
+ return -ENOMEM;
319
+
320
+ netdev_rss_key_fill(default_rss_key, sizeof(default_rss_key));
321
+ for (i = 0; i < HINIC_RSS_INDIR_SIZE; i++)
322
+ indir_tbl[i] = ethtool_rxfh_indir_default(i, nic_dev->num_rss);
323
+
324
+ err = hinic_rss_set_template_tbl(nic_dev, tmpl_idx, default_rss_key);
325
+ if (err)
326
+ goto out;
327
+
328
+ err = hinic_rss_set_indir_tbl(nic_dev, tmpl_idx, indir_tbl);
329
+ if (err)
330
+ goto out;
331
+
332
+ err = hinic_set_rss_type(nic_dev, tmpl_idx, nic_dev->rss_type);
333
+ if (err)
334
+ goto out;
335
+
336
+ err = hinic_rss_set_hash_engine(nic_dev, tmpl_idx,
337
+ nic_dev->rss_hash_engine);
338
+ if (err)
339
+ goto out;
340
+
341
+ err = hinic_rss_cfg(nic_dev, 1, tmpl_idx);
342
+ if (err)
343
+ goto out;
344
+
345
+out:
346
+ kfree(indir_tbl);
347
+ return err;
348
+}
349
+
350
+static void hinic_rss_deinit(struct hinic_dev *nic_dev)
351
+{
352
+ hinic_rss_cfg(nic_dev, 0, nic_dev->rss_tmpl_idx);
353
+}
354
+
355
+static void hinic_init_rss_parameters(struct hinic_dev *nic_dev)
356
+{
357
+ nic_dev->rss_hash_engine = HINIC_RSS_HASH_ENGINE_TYPE_XOR;
358
+ nic_dev->rss_type.tcp_ipv6_ext = 1;
359
+ nic_dev->rss_type.ipv6_ext = 1;
360
+ nic_dev->rss_type.tcp_ipv6 = 1;
361
+ nic_dev->rss_type.ipv6 = 1;
362
+ nic_dev->rss_type.tcp_ipv4 = 1;
363
+ nic_dev->rss_type.ipv4 = 1;
364
+ nic_dev->rss_type.udp_ipv6 = 1;
365
+ nic_dev->rss_type.udp_ipv4 = 1;
366
+}
367
+
368
+static void hinic_enable_rss(struct hinic_dev *nic_dev)
369
+{
370
+ struct net_device *netdev = nic_dev->netdev;
371
+ struct hinic_hwdev *hwdev = nic_dev->hwdev;
372
+ struct hinic_hwif *hwif = hwdev->hwif;
373
+ struct pci_dev *pdev = hwif->pdev;
374
+ int i, node, err = 0;
375
+ u16 num_cpus = 0;
376
+
377
+ if (nic_dev->max_qps <= 1) {
378
+ nic_dev->flags &= ~HINIC_RSS_ENABLE;
379
+ nic_dev->rss_limit = nic_dev->max_qps;
380
+ nic_dev->num_qps = nic_dev->max_qps;
381
+ nic_dev->num_rss = nic_dev->max_qps;
382
+
383
+ return;
384
+ }
385
+
386
+ err = hinic_rss_template_alloc(nic_dev, &nic_dev->rss_tmpl_idx);
387
+ if (err) {
388
+ netif_err(nic_dev, drv, netdev,
389
+ "Failed to alloc tmpl_idx for rss, can't enable rss for this function\n");
390
+ nic_dev->flags &= ~HINIC_RSS_ENABLE;
391
+ nic_dev->max_qps = 1;
392
+ nic_dev->rss_limit = nic_dev->max_qps;
393
+ nic_dev->num_qps = nic_dev->max_qps;
394
+ nic_dev->num_rss = nic_dev->max_qps;
395
+
396
+ return;
397
+ }
398
+
399
+ nic_dev->flags |= HINIC_RSS_ENABLE;
400
+
401
+ for (i = 0; i < num_online_cpus(); i++) {
402
+ node = cpu_to_node(i);
403
+ if (node == dev_to_node(&pdev->dev))
404
+ num_cpus++;
405
+ }
406
+
407
+ if (!num_cpus)
408
+ num_cpus = num_online_cpus();
409
+
410
+ nic_dev->num_qps = hinic_hwdev_num_qps(hwdev);
411
+ nic_dev->num_qps = min_t(u16, nic_dev->num_qps, num_cpus);
412
+
413
+ nic_dev->rss_limit = nic_dev->num_qps;
414
+ nic_dev->num_rss = nic_dev->num_qps;
415
+
416
+ hinic_init_rss_parameters(nic_dev);
417
+ err = hinic_rss_init(nic_dev);
418
+ if (err)
419
+ netif_err(nic_dev, drv, netdev, "Failed to init rss\n");
420
+}
421
+
422
+int hinic_open(struct net_device *netdev)
375423 {
376424 struct hinic_dev *nic_dev = netdev_priv(netdev);
377425 enum hinic_port_link_state link_state;
378
- int err, ret, num_qps;
426
+ int err, ret;
379427
380428 if (!(nic_dev->flags & HINIC_INTF_UP)) {
381
- err = hinic_hwdev_ifup(nic_dev->hwdev);
429
+ err = hinic_hwdev_ifup(nic_dev->hwdev, nic_dev->sq_depth,
430
+ nic_dev->rq_depth);
382431 if (err) {
383432 netif_err(nic_dev, drv, netdev,
384433 "Failed - HW interface up\n");
....@@ -393,6 +442,8 @@
393442 goto err_create_txqs;
394443 }
395444
445
+ enable_txqs_napi(nic_dev);
446
+
396447 err = create_rxqs(nic_dev);
397448 if (err) {
398449 netif_err(nic_dev, drv, netdev,
....@@ -400,9 +451,17 @@
400451 goto err_create_rxqs;
401452 }
402453
403
- num_qps = hinic_hwdev_num_qps(nic_dev->hwdev);
404
- netif_set_real_num_tx_queues(netdev, num_qps);
405
- netif_set_real_num_rx_queues(netdev, num_qps);
454
+ hinic_enable_rss(nic_dev);
455
+
456
+ err = hinic_configure_max_qnum(nic_dev);
457
+ if (err) {
458
+ netif_err(nic_dev, drv, nic_dev->netdev,
459
+ "Failed to configure the maximum number of queues\n");
460
+ goto err_port_state;
461
+ }
462
+
463
+ netif_set_real_num_tx_queues(netdev, nic_dev->num_qps);
464
+ netif_set_real_num_rx_queues(netdev, nic_dev->num_qps);
406465
407466 err = hinic_port_set_state(nic_dev, HINIC_PORT_ENABLE);
408467 if (err) {
....@@ -418,9 +477,6 @@
418477 goto err_func_port_state;
419478 }
420479
421
- /* Wait up to 3 sec between port enable to link state */
422
- msleep(3000);
423
-
424480 down(&nic_dev->mgmt_lock);
425481
426482 err = hinic_port_link_state(nic_dev, &link_state);
....@@ -429,8 +485,14 @@
429485 goto err_port_link;
430486 }
431487
432
- if (link_state == HINIC_LINK_STATE_UP)
488
+ if (!HINIC_IS_VF(nic_dev->hwdev->hwif))
489
+ hinic_notify_all_vfs_link_changed(nic_dev->hwdev, link_state);
490
+
491
+ if (link_state == HINIC_LINK_STATE_UP) {
433492 nic_dev->flags |= HINIC_LINK_UP;
493
+ nic_dev->cable_unplugged = false;
494
+ nic_dev->module_unrecognized = false;
495
+ }
434496
435497 nic_dev->flags |= HINIC_INTF_UP;
436498
....@@ -458,11 +520,15 @@
458520 if (ret)
459521 netif_warn(nic_dev, drv, netdev,
460522 "Failed to revert port state\n");
461
-
462523 err_port_state:
463524 free_rxqs(nic_dev);
525
+ if (nic_dev->flags & HINIC_RSS_ENABLE) {
526
+ hinic_rss_deinit(nic_dev);
527
+ hinic_rss_template_free(nic_dev, nic_dev->rss_tmpl_idx);
528
+ }
464529
465530 err_create_rxqs:
531
+ disable_txqs_napi(nic_dev);
466532 free_txqs(nic_dev);
467533
468534 err_create_txqs:
....@@ -471,10 +537,13 @@
471537 return err;
472538 }
473539
474
-static int hinic_close(struct net_device *netdev)
540
+int hinic_close(struct net_device *netdev)
475541 {
476542 struct hinic_dev *nic_dev = netdev_priv(netdev);
477543 unsigned int flags;
544
+
545
+ /* Disable txq napi firstly to aviod rewaking txq in free_tx_poll */
546
+ disable_txqs_napi(nic_dev);
478547
479548 down(&nic_dev->mgmt_lock);
480549
....@@ -484,13 +553,19 @@
484553 netif_carrier_off(netdev);
485554 netif_tx_disable(netdev);
486555
487
- update_nic_stats(nic_dev);
488
-
489556 up(&nic_dev->mgmt_lock);
557
+
558
+ if (!HINIC_IS_VF(nic_dev->hwdev->hwif))
559
+ hinic_notify_all_vfs_link_changed(nic_dev->hwdev, 0);
490560
491561 hinic_port_set_state(nic_dev, HINIC_PORT_DISABLE);
492562
493563 hinic_port_set_func_state(nic_dev, HINIC_FUNC_PORT_DISABLE);
564
+
565
+ if (nic_dev->flags & HINIC_RSS_ENABLE) {
566
+ hinic_rss_deinit(nic_dev);
567
+ hinic_rss_template_free(nic_dev, nic_dev->rss_tmpl_idx);
568
+ }
494569
495570 free_rxqs(nic_dev);
496571 free_txqs(nic_dev);
....@@ -660,7 +735,7 @@
660735 }
661736
662737 err = hinic_port_add_mac(nic_dev, netdev->dev_addr, vid);
663
- if (err) {
738
+ if (err && err != HINIC_PF_SET_VF_ALREADY) {
664739 netif_err(nic_dev, drv, netdev, "Failed to set mac\n");
665740 goto err_add_mac;
666741 }
....@@ -711,17 +786,11 @@
711786 {
712787 struct hinic_rx_mode_work *rx_mode_work = work_to_rx_mode_work(work);
713788 struct hinic_dev *nic_dev = rx_mode_work_to_nic_dev(rx_mode_work);
714
- struct netdev_hw_addr *ha;
715
-
716
- netif_info(nic_dev, drv, nic_dev->netdev, "set rx mode work\n");
717789
718790 hinic_port_set_rx_mode(nic_dev, rx_mode_work->rx_mode);
719791
720792 __dev_uc_sync(nic_dev->netdev, add_mac_addr, remove_mac_addr);
721793 __dev_mc_sync(nic_dev->netdev, add_mac_addr, remove_mac_addr);
722
-
723
- netdev_for_each_mc_addr(ha, nic_dev->netdev)
724
- add_mac_addr(nic_dev->netdev, ha->addr);
725794 }
726795
727796 static void hinic_set_rx_mode(struct net_device *netdev)
....@@ -736,46 +805,83 @@
736805 HINIC_RX_MODE_MC |
737806 HINIC_RX_MODE_BC;
738807
739
- if (netdev->flags & IFF_PROMISC)
740
- rx_mode |= HINIC_RX_MODE_PROMISC;
741
- else if (netdev->flags & IFF_ALLMULTI)
808
+ if (netdev->flags & IFF_PROMISC) {
809
+ if (!HINIC_IS_VF(nic_dev->hwdev->hwif))
810
+ rx_mode |= HINIC_RX_MODE_PROMISC;
811
+ } else if (netdev->flags & IFF_ALLMULTI) {
742812 rx_mode |= HINIC_RX_MODE_MC_ALL;
813
+ }
743814
744815 rx_mode_work->rx_mode = rx_mode;
745816
746817 queue_work(nic_dev->workq, &rx_mode_work->work);
747818 }
748819
749
-static void hinic_tx_timeout(struct net_device *netdev)
820
+static void hinic_tx_timeout(struct net_device *netdev, unsigned int txqueue)
750821 {
751822 struct hinic_dev *nic_dev = netdev_priv(netdev);
823
+ u16 sw_pi, hw_ci, sw_ci;
824
+ struct hinic_sq *sq;
825
+ u16 num_sqs, q_id;
826
+
827
+ num_sqs = hinic_hwdev_num_qps(nic_dev->hwdev);
752828
753829 netif_err(nic_dev, drv, netdev, "Tx timeout\n");
830
+
831
+ for (q_id = 0; q_id < num_sqs; q_id++) {
832
+ if (!netif_xmit_stopped(netdev_get_tx_queue(netdev, q_id)))
833
+ continue;
834
+
835
+ sq = hinic_hwdev_get_sq(nic_dev->hwdev, q_id);
836
+ sw_pi = atomic_read(&sq->wq->prod_idx) & sq->wq->mask;
837
+ hw_ci = be16_to_cpu(*(u16 *)(sq->hw_ci_addr)) & sq->wq->mask;
838
+ sw_ci = atomic_read(&sq->wq->cons_idx) & sq->wq->mask;
839
+ netif_err(nic_dev, drv, netdev, "Txq%d: sw_pi: %d, hw_ci: %d, sw_ci: %d, napi->state: 0x%lx\n",
840
+ q_id, sw_pi, hw_ci, sw_ci,
841
+ nic_dev->txqs[q_id].napi.state);
842
+ }
754843 }
755844
756845 static void hinic_get_stats64(struct net_device *netdev,
757846 struct rtnl_link_stats64 *stats)
758847 {
759848 struct hinic_dev *nic_dev = netdev_priv(netdev);
760
- struct hinic_rxq_stats *nic_rx_stats;
761
- struct hinic_txq_stats *nic_tx_stats;
762
-
763
- nic_rx_stats = &nic_dev->rx_stats;
764
- nic_tx_stats = &nic_dev->tx_stats;
765
-
766
- down(&nic_dev->mgmt_lock);
849
+ struct hinic_rxq_stats nic_rx_stats = {};
850
+ struct hinic_txq_stats nic_tx_stats = {};
767851
768852 if (nic_dev->flags & HINIC_INTF_UP)
769
- update_nic_stats(nic_dev);
853
+ gather_nic_stats(nic_dev, &nic_rx_stats, &nic_tx_stats);
770854
771
- up(&nic_dev->mgmt_lock);
855
+ stats->rx_bytes = nic_rx_stats.bytes;
856
+ stats->rx_packets = nic_rx_stats.pkts;
857
+ stats->rx_errors = nic_rx_stats.errors;
772858
773
- stats->rx_bytes = nic_rx_stats->bytes;
774
- stats->rx_packets = nic_rx_stats->pkts;
859
+ stats->tx_bytes = nic_tx_stats.bytes;
860
+ stats->tx_packets = nic_tx_stats.pkts;
861
+ stats->tx_errors = nic_tx_stats.tx_dropped;
862
+}
775863
776
- stats->tx_bytes = nic_tx_stats->bytes;
777
- stats->tx_packets = nic_tx_stats->pkts;
778
- stats->tx_errors = nic_tx_stats->tx_dropped;
864
+static int hinic_set_features(struct net_device *netdev,
865
+ netdev_features_t features)
866
+{
867
+ struct hinic_dev *nic_dev = netdev_priv(netdev);
868
+
869
+ return set_features(nic_dev, nic_dev->netdev->features,
870
+ features, false);
871
+}
872
+
873
+static netdev_features_t hinic_fix_features(struct net_device *netdev,
874
+ netdev_features_t features)
875
+{
876
+ struct hinic_dev *nic_dev = netdev_priv(netdev);
877
+
878
+ /* If Rx checksum is disabled, then LRO should also be disabled */
879
+ if (!(features & NETIF_F_RXCSUM)) {
880
+ netif_info(nic_dev, drv, netdev, "disabling LRO as RXCSUM is off\n");
881
+ features &= ~NETIF_F_LRO;
882
+ }
883
+
884
+ return features;
779885 }
780886
781887 static const struct net_device_ops hinic_netdev_ops = {
....@@ -790,15 +896,68 @@
790896 .ndo_start_xmit = hinic_xmit_frame,
791897 .ndo_tx_timeout = hinic_tx_timeout,
792898 .ndo_get_stats64 = hinic_get_stats64,
899
+ .ndo_fix_features = hinic_fix_features,
900
+ .ndo_set_features = hinic_set_features,
901
+ .ndo_set_vf_mac = hinic_ndo_set_vf_mac,
902
+ .ndo_set_vf_vlan = hinic_ndo_set_vf_vlan,
903
+ .ndo_get_vf_config = hinic_ndo_get_vf_config,
904
+ .ndo_set_vf_trust = hinic_ndo_set_vf_trust,
905
+ .ndo_set_vf_rate = hinic_ndo_set_vf_bw,
906
+ .ndo_set_vf_spoofchk = hinic_ndo_set_vf_spoofchk,
907
+ .ndo_set_vf_link_state = hinic_ndo_set_vf_link_state,
908
+};
909
+
910
+static const struct net_device_ops hinicvf_netdev_ops = {
911
+ .ndo_open = hinic_open,
912
+ .ndo_stop = hinic_close,
913
+ .ndo_change_mtu = hinic_change_mtu,
914
+ .ndo_set_mac_address = hinic_set_mac_addr,
915
+ .ndo_validate_addr = eth_validate_addr,
916
+ .ndo_vlan_rx_add_vid = hinic_vlan_rx_add_vid,
917
+ .ndo_vlan_rx_kill_vid = hinic_vlan_rx_kill_vid,
918
+ .ndo_set_rx_mode = hinic_set_rx_mode,
919
+ .ndo_start_xmit = hinic_xmit_frame,
920
+ .ndo_tx_timeout = hinic_tx_timeout,
921
+ .ndo_get_stats64 = hinic_get_stats64,
922
+ .ndo_fix_features = hinic_fix_features,
923
+ .ndo_set_features = hinic_set_features,
793924 };
794925
795926 static void netdev_features_init(struct net_device *netdev)
796927 {
797
- netdev->hw_features = NETIF_F_SG | NETIF_F_HIGHDMA;
928
+ netdev->hw_features = NETIF_F_SG | NETIF_F_HIGHDMA | NETIF_F_IP_CSUM |
929
+ NETIF_F_IPV6_CSUM | NETIF_F_TSO | NETIF_F_TSO6 |
930
+ NETIF_F_RXCSUM | NETIF_F_LRO |
931
+ NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX |
932
+ NETIF_F_GSO_UDP_TUNNEL | NETIF_F_GSO_UDP_TUNNEL_CSUM;
798933
799934 netdev->vlan_features = netdev->hw_features;
800935
801936 netdev->features = netdev->hw_features | NETIF_F_HW_VLAN_CTAG_FILTER;
937
+
938
+ netdev->hw_enc_features = NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SCTP_CRC |
939
+ NETIF_F_SG | NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_TSO_ECN |
940
+ NETIF_F_GSO_UDP_TUNNEL_CSUM | NETIF_F_GSO_UDP_TUNNEL;
941
+}
942
+
943
+static void hinic_refresh_nic_cfg(struct hinic_dev *nic_dev)
944
+{
945
+ struct hinic_nic_cfg *nic_cfg = &nic_dev->hwdev->func_to_io.nic_cfg;
946
+ struct hinic_pause_config pause_info = {0};
947
+ struct hinic_port_cap port_cap = {0};
948
+
949
+ if (hinic_port_get_cap(nic_dev, &port_cap))
950
+ return;
951
+
952
+ mutex_lock(&nic_cfg->cfg_mutex);
953
+ if (nic_cfg->pause_set || !port_cap.autoneg_state) {
954
+ nic_cfg->auto_neg = port_cap.autoneg_state;
955
+ pause_info.auto_neg = nic_cfg->auto_neg;
956
+ pause_info.rx_pause = nic_cfg->rx_pause;
957
+ pause_info.tx_pause = nic_cfg->tx_pause;
958
+ hinic_set_hw_pause_info(nic_dev->hwdev, &pause_info);
959
+ }
960
+ mutex_unlock(&nic_cfg->cfg_mutex);
802961 }
803962
804963 /**
....@@ -806,7 +965,7 @@
806965 * @handle: nic device for the handler
807966 * @buf_in: input buffer
808967 * @in_size: input size
809
- * @buf_in: output buffer
968
+ * @buf_out: output buffer
810969 * @out_size: returned output size
811970 *
812971 * Return 0 - Success, negative - Failure
....@@ -823,6 +982,8 @@
823982 down(&nic_dev->mgmt_lock);
824983
825984 nic_dev->flags |= HINIC_LINK_UP;
985
+ nic_dev->cable_unplugged = false;
986
+ nic_dev->module_unrecognized = false;
826987
827988 if ((nic_dev->flags & (HINIC_LINK_UP | HINIC_INTF_UP)) ==
828989 (HINIC_LINK_UP | HINIC_INTF_UP)) {
....@@ -831,6 +992,9 @@
831992 }
832993
833994 up(&nic_dev->mgmt_lock);
995
+
996
+ if (!HINIC_IS_VF(nic_dev->hwdev->hwif))
997
+ hinic_refresh_nic_cfg(nic_dev);
834998
835999 netif_info(nic_dev, drv, nic_dev->netdev, "HINIC_Link is UP\n");
8361000 } else {
....@@ -846,10 +1010,142 @@
8461010 netif_info(nic_dev, drv, nic_dev->netdev, "HINIC_Link is DOWN\n");
8471011 }
8481012
1013
+ if (!HINIC_IS_VF(nic_dev->hwdev->hwif))
1014
+ hinic_notify_all_vfs_link_changed(nic_dev->hwdev,
1015
+ link_status->link);
1016
+
8491017 ret_link_status = buf_out;
8501018 ret_link_status->status = 0;
8511019
8521020 *out_size = sizeof(*ret_link_status);
1021
+}
1022
+
1023
+static void cable_plug_event(void *handle,
1024
+ void *buf_in, u16 in_size,
1025
+ void *buf_out, u16 *out_size)
1026
+{
1027
+ struct hinic_cable_plug_event *plug_event = buf_in;
1028
+ struct hinic_dev *nic_dev = handle;
1029
+
1030
+ nic_dev->cable_unplugged = plug_event->plugged ? false : true;
1031
+
1032
+ *out_size = sizeof(*plug_event);
1033
+ plug_event = buf_out;
1034
+ plug_event->status = 0;
1035
+}
1036
+
1037
+static void link_err_event(void *handle,
1038
+ void *buf_in, u16 in_size,
1039
+ void *buf_out, u16 *out_size)
1040
+{
1041
+ struct hinic_link_err_event *link_err = buf_in;
1042
+ struct hinic_dev *nic_dev = handle;
1043
+
1044
+ if (link_err->err_type >= LINK_ERR_NUM)
1045
+ netif_info(nic_dev, link, nic_dev->netdev,
1046
+ "Link failed, Unknown error type: 0x%x\n",
1047
+ link_err->err_type);
1048
+ else
1049
+ nic_dev->module_unrecognized = true;
1050
+
1051
+ *out_size = sizeof(*link_err);
1052
+ link_err = buf_out;
1053
+ link_err->status = 0;
1054
+}
1055
+
1056
+static int set_features(struct hinic_dev *nic_dev,
1057
+ netdev_features_t pre_features,
1058
+ netdev_features_t features, bool force_change)
1059
+{
1060
+ netdev_features_t changed = force_change ? ~0 : pre_features ^ features;
1061
+ u32 csum_en = HINIC_RX_CSUM_OFFLOAD_EN;
1062
+ netdev_features_t failed_features = 0;
1063
+ int ret = 0;
1064
+ int err = 0;
1065
+
1066
+ if (changed & NETIF_F_TSO) {
1067
+ ret = hinic_port_set_tso(nic_dev, (features & NETIF_F_TSO) ?
1068
+ HINIC_TSO_ENABLE : HINIC_TSO_DISABLE);
1069
+ if (ret) {
1070
+ err = ret;
1071
+ failed_features |= NETIF_F_TSO;
1072
+ }
1073
+ }
1074
+
1075
+ if (changed & NETIF_F_RXCSUM) {
1076
+ ret = hinic_set_rx_csum_offload(nic_dev, csum_en);
1077
+ if (ret) {
1078
+ err = ret;
1079
+ failed_features |= NETIF_F_RXCSUM;
1080
+ }
1081
+ }
1082
+
1083
+ if (changed & NETIF_F_LRO) {
1084
+ ret = hinic_set_rx_lro_state(nic_dev,
1085
+ !!(features & NETIF_F_LRO),
1086
+ HINIC_LRO_RX_TIMER_DEFAULT,
1087
+ HINIC_LRO_MAX_WQE_NUM_DEFAULT);
1088
+ if (ret) {
1089
+ err = ret;
1090
+ failed_features |= NETIF_F_LRO;
1091
+ }
1092
+ }
1093
+
1094
+ if (changed & NETIF_F_HW_VLAN_CTAG_RX) {
1095
+ ret = hinic_set_rx_vlan_offload(nic_dev,
1096
+ !!(features &
1097
+ NETIF_F_HW_VLAN_CTAG_RX));
1098
+ if (ret) {
1099
+ err = ret;
1100
+ failed_features |= NETIF_F_HW_VLAN_CTAG_RX;
1101
+ }
1102
+ }
1103
+
1104
+ if (err) {
1105
+ nic_dev->netdev->features = features ^ failed_features;
1106
+ return -EIO;
1107
+ }
1108
+
1109
+ return 0;
1110
+}
1111
+
1112
+static int hinic_init_intr_coalesce(struct hinic_dev *nic_dev)
1113
+{
1114
+ u64 size;
1115
+ u16 i;
1116
+
1117
+ size = sizeof(struct hinic_intr_coal_info) * nic_dev->max_qps;
1118
+ nic_dev->rx_intr_coalesce = kzalloc(size, GFP_KERNEL);
1119
+ if (!nic_dev->rx_intr_coalesce)
1120
+ return -ENOMEM;
1121
+ nic_dev->tx_intr_coalesce = kzalloc(size, GFP_KERNEL);
1122
+ if (!nic_dev->tx_intr_coalesce) {
1123
+ kfree(nic_dev->rx_intr_coalesce);
1124
+ return -ENOMEM;
1125
+ }
1126
+
1127
+ for (i = 0; i < nic_dev->max_qps; i++) {
1128
+ nic_dev->rx_intr_coalesce[i].pending_limt =
1129
+ HINIC_DEAULT_TXRX_MSIX_PENDING_LIMIT;
1130
+ nic_dev->rx_intr_coalesce[i].coalesce_timer_cfg =
1131
+ HINIC_DEAULT_TXRX_MSIX_COALESC_TIMER_CFG;
1132
+ nic_dev->rx_intr_coalesce[i].resend_timer_cfg =
1133
+ HINIC_DEAULT_TXRX_MSIX_RESEND_TIMER_CFG;
1134
+ nic_dev->tx_intr_coalesce[i].pending_limt =
1135
+ HINIC_DEAULT_TXRX_MSIX_PENDING_LIMIT;
1136
+ nic_dev->tx_intr_coalesce[i].coalesce_timer_cfg =
1137
+ HINIC_DEAULT_TXRX_MSIX_COALESC_TIMER_CFG;
1138
+ nic_dev->tx_intr_coalesce[i].resend_timer_cfg =
1139
+ HINIC_DEAULT_TXRX_MSIX_RESEND_TIMER_CFG;
1140
+ }
1141
+
1142
+ return 0;
1143
+}
1144
+
1145
+static void hinic_free_intr_coalesce(struct hinic_dev *nic_dev)
1146
+{
1147
+ kfree(nic_dev->tx_intr_coalesce);
1148
+ kfree(nic_dev->rx_intr_coalesce);
8531149 }
8541150
8551151 /**
....@@ -861,16 +1157,22 @@
8611157 static int nic_dev_init(struct pci_dev *pdev)
8621158 {
8631159 struct hinic_rx_mode_work *rx_mode_work;
864
- struct hinic_txq_stats *tx_stats;
865
- struct hinic_rxq_stats *rx_stats;
8661160 struct hinic_dev *nic_dev;
8671161 struct net_device *netdev;
8681162 struct hinic_hwdev *hwdev;
1163
+ struct devlink *devlink;
8691164 int err, num_qps;
8701165
871
- hwdev = hinic_init_hwdev(pdev);
1166
+ devlink = hinic_devlink_alloc();
1167
+ if (!devlink) {
1168
+ dev_err(&pdev->dev, "Hinic devlink alloc failed\n");
1169
+ return -ENOMEM;
1170
+ }
1171
+
1172
+ hwdev = hinic_init_hwdev(pdev, devlink);
8721173 if (IS_ERR(hwdev)) {
8731174 dev_err(&pdev->dev, "Failed to initialize HW device\n");
1175
+ hinic_devlink_free(devlink);
8741176 return PTR_ERR(hwdev);
8751177 }
8761178
....@@ -888,8 +1190,11 @@
8881190 goto err_alloc_etherdev;
8891191 }
8901192
891
- netdev->netdev_ops = &hinic_netdev_ops;
892
- netdev->ethtool_ops = &hinic_ethtool_ops;
1193
+ if (!HINIC_IS_VF(hwdev->hwif))
1194
+ netdev->netdev_ops = &hinic_netdev_ops;
1195
+ else
1196
+ netdev->netdev_ops = &hinicvf_netdev_ops;
1197
+
8931198 netdev->max_mtu = ETH_MAX_MTU;
8941199
8951200 nic_dev = netdev_priv(netdev);
....@@ -901,18 +1206,19 @@
9011206 nic_dev->rxqs = NULL;
9021207 nic_dev->tx_weight = tx_weight;
9031208 nic_dev->rx_weight = rx_weight;
1209
+ nic_dev->sq_depth = HINIC_SQ_DEPTH;
1210
+ nic_dev->rq_depth = HINIC_RQ_DEPTH;
1211
+ nic_dev->sriov_info.hwdev = hwdev;
1212
+ nic_dev->sriov_info.pdev = pdev;
1213
+ nic_dev->max_qps = num_qps;
1214
+ nic_dev->devlink = devlink;
1215
+
1216
+ hinic_set_ethtool_ops(netdev);
9041217
9051218 sema_init(&nic_dev->mgmt_lock, 1);
9061219
907
- tx_stats = &nic_dev->tx_stats;
908
- rx_stats = &nic_dev->rx_stats;
909
-
910
- u64_stats_init(&tx_stats->syncp);
911
- u64_stats_init(&rx_stats->syncp);
912
-
913
- nic_dev->vlan_bitmap = devm_kzalloc(&pdev->dev,
914
- VLAN_BITMAP_SIZE(nic_dev),
915
- GFP_KERNEL);
1220
+ nic_dev->vlan_bitmap = devm_bitmap_zalloc(&pdev->dev, VLAN_N_VID,
1221
+ GFP_KERNEL);
9161222 if (!nic_dev->vlan_bitmap) {
9171223 err = -ENOMEM;
9181224 goto err_vlan_bitmap;
....@@ -927,11 +1233,25 @@
9271233 pci_set_drvdata(pdev, netdev);
9281234
9291235 err = hinic_port_get_mac(nic_dev, netdev->dev_addr);
930
- if (err)
931
- dev_warn(&pdev->dev, "Failed to get mac address\n");
1236
+ if (err) {
1237
+ dev_err(&pdev->dev, "Failed to get mac address\n");
1238
+ goto err_get_mac;
1239
+ }
1240
+
1241
+ if (!is_valid_ether_addr(netdev->dev_addr)) {
1242
+ if (!HINIC_IS_VF(nic_dev->hwdev->hwif)) {
1243
+ dev_err(&pdev->dev, "Invalid MAC address\n");
1244
+ err = -EIO;
1245
+ goto err_add_mac;
1246
+ }
1247
+
1248
+ dev_info(&pdev->dev, "Invalid MAC address %pM, using random\n",
1249
+ netdev->dev_addr);
1250
+ eth_hw_addr_random(netdev);
1251
+ }
9321252
9331253 err = hinic_port_add_mac(nic_dev, netdev->dev_addr, 0);
934
- if (err) {
1254
+ if (err && err != HINIC_PF_SET_VF_ALREADY) {
9351255 dev_err(&pdev->dev, "Failed to add mac\n");
9361256 goto err_add_mac;
9371257 }
....@@ -951,8 +1271,40 @@
9511271
9521272 hinic_hwdev_cb_register(nic_dev->hwdev, HINIC_MGMT_MSG_CMD_LINK_STATUS,
9531273 nic_dev, link_status_event_handler);
1274
+ hinic_hwdev_cb_register(nic_dev->hwdev,
1275
+ HINIC_MGMT_MSG_CMD_CABLE_PLUG_EVENT,
1276
+ nic_dev, cable_plug_event);
1277
+ hinic_hwdev_cb_register(nic_dev->hwdev,
1278
+ HINIC_MGMT_MSG_CMD_LINK_ERR_EVENT,
1279
+ nic_dev, link_err_event);
1280
+
1281
+ err = set_features(nic_dev, 0, nic_dev->netdev->features, true);
1282
+ if (err)
1283
+ goto err_set_features;
1284
+
1285
+ /* enable pause and disable pfc by default */
1286
+ err = hinic_dcb_set_pfc(nic_dev->hwdev, 0, 0);
1287
+ if (err)
1288
+ goto err_set_pfc;
9541289
9551290 SET_NETDEV_DEV(netdev, &pdev->dev);
1291
+
1292
+ err = hinic_init_intr_coalesce(nic_dev);
1293
+ if (err) {
1294
+ dev_err(&pdev->dev, "Failed to init_intr_coalesce\n");
1295
+ goto err_init_intr;
1296
+ }
1297
+
1298
+ hinic_dbg_init(nic_dev);
1299
+
1300
+ hinic_func_tbl_dbgfs_init(nic_dev);
1301
+
1302
+ err = hinic_func_table_debug_add(nic_dev);
1303
+ if (err) {
1304
+ dev_err(&pdev->dev, "Failed to add func_table debug\n");
1305
+ goto err_add_func_table_dbg;
1306
+ }
1307
+
9561308 err = register_netdev(netdev);
9571309 if (err) {
9581310 dev_err(&pdev->dev, "Failed to register netdev\n");
....@@ -962,15 +1314,28 @@
9621314 return 0;
9631315
9641316 err_reg_netdev:
1317
+ hinic_func_table_debug_rem(nic_dev);
1318
+err_add_func_table_dbg:
1319
+ hinic_func_tbl_dbgfs_uninit(nic_dev);
1320
+ hinic_dbg_uninit(nic_dev);
1321
+ hinic_free_intr_coalesce(nic_dev);
1322
+err_init_intr:
1323
+err_set_pfc:
1324
+err_set_features:
1325
+ hinic_hwdev_cb_unregister(nic_dev->hwdev,
1326
+ HINIC_MGMT_MSG_CMD_LINK_ERR_EVENT);
1327
+ hinic_hwdev_cb_unregister(nic_dev->hwdev,
1328
+ HINIC_MGMT_MSG_CMD_CABLE_PLUG_EVENT);
9651329 hinic_hwdev_cb_unregister(nic_dev->hwdev,
9661330 HINIC_MGMT_MSG_CMD_LINK_STATUS);
9671331 cancel_work_sync(&rx_mode_work->work);
9681332
9691333 err_set_mtu:
1334
+ hinic_port_del_mac(nic_dev, netdev->dev_addr, 0);
9701335 err_add_mac:
1336
+err_get_mac:
9711337 pci_set_drvdata(pdev, NULL);
9721338 destroy_workqueue(nic_dev->workq);
973
-
9741339 err_workq:
9751340 err_vlan_bitmap:
9761341 free_netdev(netdev);
....@@ -978,6 +1343,7 @@
9781343 err_alloc_etherdev:
9791344 err_num_qps:
9801345 hinic_free_hwdev(hwdev);
1346
+ hinic_devlink_free(devlink);
9811347 return err;
9821348 }
9831349
....@@ -1040,14 +1406,54 @@
10401406 return err;
10411407 }
10421408
1409
+#define HINIC_WAIT_SRIOV_CFG_TIMEOUT 15000
1410
+
1411
+static void wait_sriov_cfg_complete(struct hinic_dev *nic_dev)
1412
+{
1413
+ struct hinic_sriov_info *sriov_info = &nic_dev->sriov_info;
1414
+ u32 loop_cnt = 0;
1415
+
1416
+ set_bit(HINIC_FUNC_REMOVE, &sriov_info->state);
1417
+ usleep_range(9900, 10000);
1418
+
1419
+ while (loop_cnt < HINIC_WAIT_SRIOV_CFG_TIMEOUT) {
1420
+ if (!test_bit(HINIC_SRIOV_ENABLE, &sriov_info->state) &&
1421
+ !test_bit(HINIC_SRIOV_DISABLE, &sriov_info->state))
1422
+ return;
1423
+
1424
+ usleep_range(9900, 10000);
1425
+ loop_cnt++;
1426
+ }
1427
+}
1428
+
10431429 static void hinic_remove(struct pci_dev *pdev)
10441430 {
10451431 struct net_device *netdev = pci_get_drvdata(pdev);
10461432 struct hinic_dev *nic_dev = netdev_priv(netdev);
1433
+ struct devlink *devlink = nic_dev->devlink;
10471434 struct hinic_rx_mode_work *rx_mode_work;
1435
+
1436
+ if (!HINIC_IS_VF(nic_dev->hwdev->hwif)) {
1437
+ wait_sriov_cfg_complete(nic_dev);
1438
+ hinic_pci_sriov_disable(pdev);
1439
+ }
10481440
10491441 unregister_netdev(netdev);
10501442
1443
+ hinic_func_table_debug_rem(nic_dev);
1444
+
1445
+ hinic_func_tbl_dbgfs_uninit(nic_dev);
1446
+
1447
+ hinic_dbg_uninit(nic_dev);
1448
+
1449
+ hinic_free_intr_coalesce(nic_dev);
1450
+
1451
+ hinic_port_del_mac(nic_dev, netdev->dev_addr, 0);
1452
+
1453
+ hinic_hwdev_cb_unregister(nic_dev->hwdev,
1454
+ HINIC_MGMT_MSG_CMD_LINK_ERR_EVENT);
1455
+ hinic_hwdev_cb_unregister(nic_dev->hwdev,
1456
+ HINIC_MGMT_MSG_CMD_CABLE_PLUG_EVENT);
10511457 hinic_hwdev_cb_unregister(nic_dev->hwdev,
10521458 HINIC_MGMT_MSG_CMD_LINK_STATUS);
10531459
....@@ -1062,16 +1468,25 @@
10621468
10631469 free_netdev(netdev);
10641470
1471
+ hinic_devlink_free(devlink);
1472
+
10651473 pci_release_regions(pdev);
10661474 pci_disable_device(pdev);
10671475
10681476 dev_info(&pdev->dev, "HiNIC driver - removed\n");
10691477 }
10701478
1479
+static void hinic_shutdown(struct pci_dev *pdev)
1480
+{
1481
+ pci_disable_device(pdev);
1482
+}
1483
+
10711484 static const struct pci_device_id hinic_pci_table[] = {
10721485 { PCI_VDEVICE(HUAWEI, HINIC_DEV_ID_QUAD_PORT_25GE), 0},
1073
- { PCI_VDEVICE(HUAWEI, HINIC_DEV_ID_DUAL_PORT_25GE), 0},
10741486 { PCI_VDEVICE(HUAWEI, HINIC_DEV_ID_DUAL_PORT_100GE), 0},
1487
+ { PCI_VDEVICE(HUAWEI, HINIC_DEV_ID_DUAL_PORT_100GE_MEZZ), 0},
1488
+ { PCI_VDEVICE(HUAWEI, HINIC_DEV_ID_QUAD_PORT_25GE_MEZZ), 0},
1489
+ { PCI_VDEVICE(HUAWEI, HINIC_DEV_ID_VF), 0},
10751490 { 0, 0}
10761491 };
10771492 MODULE_DEVICE_TABLE(pci, hinic_pci_table);
....@@ -1081,6 +1496,28 @@
10811496 .id_table = hinic_pci_table,
10821497 .probe = hinic_probe,
10831498 .remove = hinic_remove,
1499
+ .shutdown = hinic_shutdown,
1500
+ .sriov_configure = hinic_pci_sriov_configure,
10841501 };
10851502
1086
-module_pci_driver(hinic_driver);
1503
+static int __init hinic_module_init(void)
1504
+{
1505
+ int ret;
1506
+
1507
+ hinic_dbg_register_debugfs(HINIC_DRV_NAME);
1508
+
1509
+ ret = pci_register_driver(&hinic_driver);
1510
+ if (ret)
1511
+ hinic_dbg_unregister_debugfs();
1512
+
1513
+ return ret;
1514
+}
1515
+
1516
+static void __exit hinic_module_exit(void)
1517
+{
1518
+ pci_unregister_driver(&hinic_driver);
1519
+ hinic_dbg_unregister_debugfs();
1520
+}
1521
+
1522
+module_init(hinic_module_init);
1523
+module_exit(hinic_module_exit);