hc
2024-01-31 f9004dbfff8a3fbbd7e2a88c8a4327c7f2f8e5b2
kernel/drivers/net/ethernet/chelsio/cxgb4vf/cxgb4vf_main.c
....@@ -55,7 +55,6 @@
5555 /*
5656 * Generic information about the driver.
5757 */
58
-#define DRV_VERSION "2.0.0-ko"
5958 #define DRV_DESC "Chelsio T4/T5/T6 Virtual Function (VF) Network Driver"
6059
6160 /*
....@@ -155,6 +154,8 @@
155154 const char *fc;
156155 const struct port_info *pi = netdev_priv(dev);
157156
157
+ netif_carrier_on(dev);
158
+
158159 switch (pi->link_cfg.speed) {
159160 case 100:
160161 s = "100Mbps";
....@@ -200,6 +201,7 @@
200201
201202 netdev_info(dev, "link up, %s, full-duplex, %s PAUSE\n", s, fc);
202203 } else {
204
+ netif_carrier_off(dev);
203205 netdev_info(dev, "link down\n");
204206 }
205207 }
....@@ -236,6 +238,72 @@
236238 "inserted\n", dev->name, pi->mod_type);
237239 }
238240
241
+static int cxgb4vf_set_addr_hash(struct port_info *pi)
242
+{
243
+ struct adapter *adapter = pi->adapter;
244
+ u64 vec = 0;
245
+ bool ucast = false;
246
+ struct hash_mac_addr *entry;
247
+
248
+ /* Calculate the hash vector for the updated list and program it */
249
+ list_for_each_entry(entry, &adapter->mac_hlist, list) {
250
+ ucast |= is_unicast_ether_addr(entry->addr);
251
+ vec |= (1ULL << hash_mac_addr(entry->addr));
252
+ }
253
+ return t4vf_set_addr_hash(adapter, pi->viid, ucast, vec, false);
254
+}
255
+
256
+/**
257
+ * cxgb4vf_change_mac - Update match filter for a MAC address.
258
+ * @pi: the port_info
259
+ * @viid: the VI id
260
+ * @tcam_idx: TCAM index of existing filter for old value of MAC address,
261
+ * or -1
262
+ * @addr: the new MAC address value
263
+ * @persistent: whether a new MAC allocation should be persistent
264
+ *
265
+ * Modifies an MPS filter and sets it to the new MAC address if
266
+ * @tcam_idx >= 0, or adds the MAC address to a new filter if
267
+ * @tcam_idx < 0. In the latter case the address is added persistently
268
+ * if @persist is %true.
269
+ * Addresses are programmed to hash region, if tcam runs out of entries.
270
+ *
271
+ */
272
+static int cxgb4vf_change_mac(struct port_info *pi, unsigned int viid,
273
+ int *tcam_idx, const u8 *addr, bool persistent)
274
+{
275
+ struct hash_mac_addr *new_entry, *entry;
276
+ struct adapter *adapter = pi->adapter;
277
+ int ret;
278
+
279
+ ret = t4vf_change_mac(adapter, viid, *tcam_idx, addr, persistent);
280
+ /* We ran out of TCAM entries. try programming hash region. */
281
+ if (ret == -ENOMEM) {
282
+ /* If the MAC address to be updated is in the hash addr
283
+ * list, update it from the list
284
+ */
285
+ list_for_each_entry(entry, &adapter->mac_hlist, list) {
286
+ if (entry->iface_mac) {
287
+ ether_addr_copy(entry->addr, addr);
288
+ goto set_hash;
289
+ }
290
+ }
291
+ new_entry = kzalloc(sizeof(*new_entry), GFP_KERNEL);
292
+ if (!new_entry)
293
+ return -ENOMEM;
294
+ ether_addr_copy(new_entry->addr, addr);
295
+ new_entry->iface_mac = true;
296
+ list_add_tail(&new_entry->list, &adapter->mac_hlist);
297
+set_hash:
298
+ ret = cxgb4vf_set_addr_hash(pi);
299
+ } else if (ret >= 0) {
300
+ *tcam_idx = ret;
301
+ ret = 0;
302
+ }
303
+
304
+ return ret;
305
+}
306
+
239307 /*
240308 * Net device operations.
241309 * ======================
....@@ -259,14 +327,10 @@
259327 */
260328 ret = t4vf_set_rxmode(pi->adapter, pi->viid, dev->mtu, -1, -1, -1, 1,
261329 true);
262
- if (ret == 0) {
263
- ret = t4vf_change_mac(pi->adapter, pi->viid,
264
- pi->xact_addr_filt, dev->dev_addr, true);
265
- if (ret >= 0) {
266
- pi->xact_addr_filt = ret;
267
- ret = 0;
268
- }
269
- }
330
+ if (ret == 0)
331
+ ret = cxgb4vf_change_mac(pi, pi->viid,
332
+ &pi->xact_addr_filt,
333
+ dev->dev_addr, true);
270334
271335 /*
272336 * We don't need to actually "start the link" itself since the
....@@ -275,16 +339,6 @@
275339 */
276340 if (ret == 0)
277341 ret = t4vf_enable_pi(pi->adapter, pi, true, true);
278
-
279
- /* The Virtual Interfaces are connected to an internal switch on the
280
- * chip which allows VIs attached to the same port to talk to each
281
- * other even when the port link is down. As a result, we generally
282
- * want to always report a VI's link as being "up", provided there are
283
- * no errors in enabling vi.
284
- */
285
-
286
- if (ret == 0)
287
- netif_carrier_on(dev);
288342
289343 return ret;
290344 }
....@@ -406,7 +460,7 @@
406460 * The interrupt queue doesn't use NAPI so we do the 0-increment of
407461 * its Going To Sleep register here to get it started.
408462 */
409
- if (adapter->flags & USING_MSI)
463
+ if (adapter->flags & CXGB4VF_USING_MSI)
410464 t4_write_reg(adapter, T4VF_SGE_BASE_ADDR + SGE_VF_GTS,
411465 CIDXINC_V(0) |
412466 SEINTARM_V(s->intrq.intr_params) |
....@@ -462,8 +516,8 @@
462516 break;
463517 }
464518 cpl = (void *)p;
465
- /*FALLTHROUGH*/
466519 }
520
+ fallthrough;
467521
468522 case CPL_SGE_EGR_UPDATE: {
469523 /*
....@@ -550,7 +604,7 @@
550604 * the intrq's queue ID as the interrupt forwarding queue for the
551605 * subsequent calls ...
552606 */
553
- if (adapter->flags & USING_MSI) {
607
+ if (adapter->flags & CXGB4VF_USING_MSI) {
554608 err = t4vf_sge_alloc_rxq(adapter, &s->intrq, false,
555609 adapter->port[0], 0, NULL, NULL);
556610 if (err)
....@@ -710,7 +764,7 @@
710764 * adapter setup. Once we've done this, many of our adapter
711765 * parameters can no longer be changed ...
712766 */
713
- if ((adapter->flags & FULL_INIT_DONE) == 0) {
767
+ if ((adapter->flags & CXGB4VF_FULL_INIT_DONE) == 0) {
714768 err = setup_sge_queues(adapter);
715769 if (err)
716770 return err;
....@@ -720,17 +774,18 @@
720774 return err;
721775 }
722776
723
- if (adapter->flags & USING_MSIX)
777
+ if (adapter->flags & CXGB4VF_USING_MSIX)
724778 name_msix_vecs(adapter);
725779
726
- adapter->flags |= FULL_INIT_DONE;
780
+ adapter->flags |= CXGB4VF_FULL_INIT_DONE;
727781 }
728782
729783 /*
730784 * Acquire our interrupt resources. We only support MSI-X and MSI.
731785 */
732
- BUG_ON((adapter->flags & (USING_MSIX|USING_MSI)) == 0);
733
- if (adapter->flags & USING_MSIX)
786
+ BUG_ON((adapter->flags &
787
+ (CXGB4VF_USING_MSIX | CXGB4VF_USING_MSI)) == 0);
788
+ if (adapter->flags & CXGB4VF_USING_MSIX)
734789 err = request_msix_queue_irqs(adapter);
735790 else
736791 err = request_irq(adapter->pdev->irq,
....@@ -761,7 +816,7 @@
761816 /*
762817 * Free interrupt resources.
763818 */
764
- if (adapter->flags & USING_MSIX)
819
+ if (adapter->flags & CXGB4VF_USING_MSIX)
765820 free_msix_queue_irqs(adapter);
766821 else
767822 free_irq(adapter->pdev->irq, adapter);
....@@ -782,6 +837,13 @@
782837 struct adapter *adapter = pi->adapter;
783838
784839 /*
840
+ * If we don't have a connection to the firmware there's nothing we
841
+ * can do.
842
+ */
843
+ if (!(adapter->flags & CXGB4VF_FW_OK))
844
+ return -ENXIO;
845
+
846
+ /*
785847 * If this is the first interface that we're opening on the "adapter",
786848 * bring the "adapter" up now.
787849 */
....@@ -790,6 +852,13 @@
790852 if (err)
791853 return err;
792854 }
855
+
856
+ /* It's possible that the basic port information could have
857
+ * changed since we first read it.
858
+ */
859
+ err = t4vf_update_port_info(pi);
860
+ if (err < 0)
861
+ goto err_unwind;
793862
794863 /*
795864 * Note that this interface is up and start everything up ...
....@@ -861,21 +930,6 @@
861930 ns->rx_errors = stats.rx_err_frames;
862931
863932 return ns;
864
-}
865
-
866
-static inline int cxgb4vf_set_addr_hash(struct port_info *pi)
867
-{
868
- struct adapter *adapter = pi->adapter;
869
- u64 vec = 0;
870
- bool ucast = false;
871
- struct hash_mac_addr *entry;
872
-
873
- /* Calculate the hash vector for the updated list and program it */
874
- list_for_each_entry(entry, &adapter->mac_hlist, list) {
875
- ucast |= is_unicast_ether_addr(entry->addr);
876
- vec |= (1ULL << hash_mac_addr(entry->addr));
877
- }
878
- return t4vf_set_addr_hash(adapter, pi->viid, ucast, vec, false);
879933 }
880934
881935 static int cxgb4vf_mac_sync(struct net_device *netdev, const u8 *mac_addr)
....@@ -1159,13 +1213,12 @@
11591213 if (!is_valid_ether_addr(addr->sa_data))
11601214 return -EADDRNOTAVAIL;
11611215
1162
- ret = t4vf_change_mac(pi->adapter, pi->viid, pi->xact_addr_filt,
1163
- addr->sa_data, true);
1216
+ ret = cxgb4vf_change_mac(pi, pi->viid, &pi->xact_addr_filt,
1217
+ addr->sa_data, true);
11641218 if (ret < 0)
11651219 return ret;
11661220
11671221 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
1168
- pi->xact_addr_filt = ret;
11691222 return 0;
11701223 }
11711224
....@@ -1179,7 +1232,7 @@
11791232 struct port_info *pi = netdev_priv(dev);
11801233 struct adapter *adapter = pi->adapter;
11811234
1182
- if (adapter->flags & USING_MSIX) {
1235
+ if (adapter->flags & CXGB4VF_USING_MSIX) {
11831236 struct sge_eth_rxq *rxq;
11841237 int nqsets;
11851238
....@@ -1354,7 +1407,7 @@
13541407 case FW_PORT_TYPE_CR4_QSFP:
13551408 SET_LMM(FIBRE);
13561409 FW_CAPS_TO_LMM(SPEED_1G, 1000baseT_Full);
1357
- FW_CAPS_TO_LMM(SPEED_10G, 10000baseSR_Full);
1410
+ FW_CAPS_TO_LMM(SPEED_10G, 10000baseKR_Full);
13581411 FW_CAPS_TO_LMM(SPEED_40G, 40000baseSR4_Full);
13591412 FW_CAPS_TO_LMM(SPEED_25G, 25000baseCR_Full);
13601413 FW_CAPS_TO_LMM(SPEED_50G, 50000baseCR2_Full);
....@@ -1363,6 +1416,13 @@
13631416
13641417 default:
13651418 break;
1419
+ }
1420
+
1421
+ if (fw_caps & FW_PORT_CAP32_FEC_V(FW_PORT_CAP32_FEC_M)) {
1422
+ FW_CAPS_TO_LMM(FEC_RS, FEC_RS);
1423
+ FW_CAPS_TO_LMM(FEC_BASER_RS, FEC_BASER);
1424
+ } else {
1425
+ SET_LMM(FEC_NONE);
13661426 }
13671427
13681428 FW_CAPS_TO_LMM(ANEG, Autoneg);
....@@ -1415,22 +1475,6 @@
14151475 } else {
14161476 base->speed = SPEED_UNKNOWN;
14171477 base->duplex = DUPLEX_UNKNOWN;
1418
- }
1419
-
1420
- if (pi->link_cfg.fc & PAUSE_RX) {
1421
- if (pi->link_cfg.fc & PAUSE_TX) {
1422
- ethtool_link_ksettings_add_link_mode(link_ksettings,
1423
- advertising,
1424
- Pause);
1425
- } else {
1426
- ethtool_link_ksettings_add_link_mode(link_ksettings,
1427
- advertising,
1428
- Asym_Pause);
1429
- }
1430
- } else if (pi->link_cfg.fc & PAUSE_TX) {
1431
- ethtool_link_ksettings_add_link_mode(link_ksettings,
1432
- advertising,
1433
- Asym_Pause);
14341478 }
14351479
14361480 base->autoneg = pi->link_cfg.autoneg;
....@@ -1510,7 +1554,6 @@
15101554 struct adapter *adapter = netdev2adap(dev);
15111555
15121556 strlcpy(drvinfo->driver, KBUILD_MODNAME, sizeof(drvinfo->driver));
1513
- strlcpy(drvinfo->version, DRV_VERSION, sizeof(drvinfo->version));
15141557 strlcpy(drvinfo->bus_info, pci_name(to_pci_dev(dev->dev.parent)),
15151558 sizeof(drvinfo->bus_info));
15161559 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
....@@ -1587,7 +1630,7 @@
15871630 rp->tx_pending < MIN_TXQ_ENTRIES)
15881631 return -EINVAL;
15891632
1590
- if (adapter->flags & FULL_INIT_DONE)
1633
+ if (adapter->flags & CXGB4VF_FULL_INIT_DONE)
15911634 return -EBUSY;
15921635
15931636 for (qs = pi->first_qset; qs < pi->first_qset + pi->nqsets; qs++) {
....@@ -1644,8 +1687,8 @@
16441687 struct port_info *pi = netdev_priv(dev);
16451688
16461689 pauseparam->autoneg = (pi->link_cfg.requested_fc & PAUSE_AUTONEG) != 0;
1647
- pauseparam->rx_pause = (pi->link_cfg.fc & PAUSE_RX) != 0;
1648
- pauseparam->tx_pause = (pi->link_cfg.fc & PAUSE_TX) != 0;
1690
+ pauseparam->rx_pause = (pi->link_cfg.advertised_fc & PAUSE_RX) != 0;
1691
+ pauseparam->tx_pause = (pi->link_cfg.advertised_fc & PAUSE_TX) != 0;
16491692 }
16501693
16511694 /*
....@@ -1871,8 +1914,12 @@
18711914 * TCP Segmentation Offload flags which we support.
18721915 */
18731916 #define TSO_FLAGS (NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_TSO_ECN)
1917
+#define VLAN_FEAT (NETIF_F_SG | NETIF_F_IP_CSUM | TSO_FLAGS | \
1918
+ NETIF_F_GRO | NETIF_F_IPV6_CSUM | NETIF_F_HIGHDMA)
18741919
18751920 static const struct ethtool_ops cxgb4vf_ethtool_ops = {
1921
+ .supported_coalesce_params = ETHTOOL_COALESCE_RX_USECS |
1922
+ ETHTOOL_COALESCE_RX_MAX_FRAMES,
18761923 .get_link_ksettings = cxgb4vf_get_link_ksettings,
18771924 .get_fecparam = cxgb4vf_get_fecparam,
18781925 .get_drvinfo = cxgb4vf_get_drvinfo,
....@@ -1970,33 +2017,14 @@
19702017 {
19712018 }
19722019
1973
-static const struct seq_operations mboxlog_seq_ops = {
2020
+static const struct seq_operations mboxlog_sops = {
19742021 .start = mboxlog_start,
19752022 .next = mboxlog_next,
19762023 .stop = mboxlog_stop,
19772024 .show = mboxlog_show
19782025 };
19792026
1980
-static int mboxlog_open(struct inode *inode, struct file *file)
1981
-{
1982
- int res = seq_open(file, &mboxlog_seq_ops);
1983
-
1984
- if (!res) {
1985
- struct seq_file *seq = file->private_data;
1986
-
1987
- seq->private = inode->i_private;
1988
- }
1989
- return res;
1990
-}
1991
-
1992
-static const struct file_operations mboxlog_fops = {
1993
- .owner = THIS_MODULE,
1994
- .open = mboxlog_open,
1995
- .read = seq_read,
1996
- .llseek = seq_lseek,
1997
- .release = seq_release,
1998
-};
1999
-
2027
+DEFINE_SEQ_ATTRIBUTE(mboxlog);
20002028 /*
20012029 * Show SGE Queue Set information. We display QPL Queues Sets per line.
20022030 */
....@@ -2102,7 +2130,7 @@
21022130 static int sge_queue_entries(const struct adapter *adapter)
21032131 {
21042132 return DIV_ROUND_UP(adapter->sge.ethqsets, QPL) + 1 +
2105
- ((adapter->flags & USING_MSI) != 0);
2133
+ ((adapter->flags & CXGB4VF_USING_MSI) != 0);
21062134 }
21072135
21082136 static void *sge_queue_start(struct seq_file *seq, loff_t *pos)
....@@ -2124,31 +2152,14 @@
21242152 return *pos < entries ? (void *)((uintptr_t)*pos + 1) : NULL;
21252153 }
21262154
2127
-static const struct seq_operations sge_qinfo_seq_ops = {
2155
+static const struct seq_operations sge_qinfo_sops = {
21282156 .start = sge_queue_start,
21292157 .next = sge_queue_next,
21302158 .stop = sge_queue_stop,
21312159 .show = sge_qinfo_show
21322160 };
21332161
2134
-static int sge_qinfo_open(struct inode *inode, struct file *file)
2135
-{
2136
- int res = seq_open(file, &sge_qinfo_seq_ops);
2137
-
2138
- if (!res) {
2139
- struct seq_file *seq = file->private_data;
2140
- seq->private = inode->i_private;
2141
- }
2142
- return res;
2143
-}
2144
-
2145
-static const struct file_operations sge_qinfo_debugfs_fops = {
2146
- .owner = THIS_MODULE,
2147
- .open = sge_qinfo_open,
2148
- .read = seq_read,
2149
- .llseek = seq_lseek,
2150
- .release = seq_release,
2151
-};
2162
+DEFINE_SEQ_ATTRIBUTE(sge_qinfo);
21522163
21532164 /*
21542165 * Show SGE Queue Set statistics. We display QPL Queues Sets per line.
....@@ -2248,7 +2259,7 @@
22482259 static int sge_qstats_entries(const struct adapter *adapter)
22492260 {
22502261 return DIV_ROUND_UP(adapter->sge.ethqsets, QPL) + 1 +
2251
- ((adapter->flags & USING_MSI) != 0);
2262
+ ((adapter->flags & CXGB4VF_USING_MSI) != 0);
22522263 }
22532264
22542265 static void *sge_qstats_start(struct seq_file *seq, loff_t *pos)
....@@ -2270,31 +2281,14 @@
22702281 return *pos < entries ? (void *)((uintptr_t)*pos + 1) : NULL;
22712282 }
22722283
2273
-static const struct seq_operations sge_qstats_seq_ops = {
2284
+static const struct seq_operations sge_qstats_sops = {
22742285 .start = sge_qstats_start,
22752286 .next = sge_qstats_next,
22762287 .stop = sge_qstats_stop,
22772288 .show = sge_qstats_show
22782289 };
22792290
2280
-static int sge_qstats_open(struct inode *inode, struct file *file)
2281
-{
2282
- int res = seq_open(file, &sge_qstats_seq_ops);
2283
-
2284
- if (res == 0) {
2285
- struct seq_file *seq = file->private_data;
2286
- seq->private = inode->i_private;
2287
- }
2288
- return res;
2289
-}
2290
-
2291
-static const struct file_operations sge_qstats_proc_fops = {
2292
- .owner = THIS_MODULE,
2293
- .open = sge_qstats_open,
2294
- .read = seq_read,
2295
- .llseek = seq_lseek,
2296
- .release = seq_release,
2297
-};
2291
+DEFINE_SEQ_ATTRIBUTE(sge_qstats);
22982292
22992293 /*
23002294 * Show PCI-E SR-IOV Virtual Function Resource Limits.
....@@ -2323,19 +2317,7 @@
23232317
23242318 return 0;
23252319 }
2326
-
2327
-static int resources_open(struct inode *inode, struct file *file)
2328
-{
2329
- return single_open(file, resources_show, inode->i_private);
2330
-}
2331
-
2332
-static const struct file_operations resources_proc_fops = {
2333
- .owner = THIS_MODULE,
2334
- .open = resources_open,
2335
- .read = seq_read,
2336
- .llseek = seq_lseek,
2337
- .release = single_release,
2338
-};
2320
+DEFINE_SHOW_ATTRIBUTE(resources);
23392321
23402322 /*
23412323 * Show Virtual Interfaces.
....@@ -2380,31 +2362,14 @@
23802362 {
23812363 }
23822364
2383
-static const struct seq_operations interfaces_seq_ops = {
2365
+static const struct seq_operations interfaces_sops = {
23842366 .start = interfaces_start,
23852367 .next = interfaces_next,
23862368 .stop = interfaces_stop,
23872369 .show = interfaces_show
23882370 };
23892371
2390
-static int interfaces_open(struct inode *inode, struct file *file)
2391
-{
2392
- int res = seq_open(file, &interfaces_seq_ops);
2393
-
2394
- if (res == 0) {
2395
- struct seq_file *seq = file->private_data;
2396
- seq->private = inode->i_private;
2397
- }
2398
- return res;
2399
-}
2400
-
2401
-static const struct file_operations interfaces_proc_fops = {
2402
- .owner = THIS_MODULE,
2403
- .open = interfaces_open,
2404
- .read = seq_read,
2405
- .llseek = seq_lseek,
2406
- .release = seq_release,
2407
-};
2372
+DEFINE_SEQ_ATTRIBUTE(interfaces);
24082373
24092374 /*
24102375 * /sys/kernel/debugfs/cxgb4vf/ files list.
....@@ -2417,10 +2382,10 @@
24172382
24182383 static struct cxgb4vf_debugfs_entry debugfs_files[] = {
24192384 { "mboxlog", 0444, &mboxlog_fops },
2420
- { "sge_qinfo", 0444, &sge_qinfo_debugfs_fops },
2421
- { "sge_qstats", 0444, &sge_qstats_proc_fops },
2422
- { "resources", 0444, &resources_proc_fops },
2423
- { "interfaces", 0444, &interfaces_proc_fops },
2385
+ { "sge_qinfo", 0444, &sge_qinfo_fops },
2386
+ { "sge_qstats", 0444, &sge_qstats_fops },
2387
+ { "resources", 0444, &resources_fops },
2388
+ { "interfaces", 0444, &interfaces_fops },
24242389 };
24252390
24262391 /*
....@@ -2442,11 +2407,10 @@
24422407 * Debugfs support is best effort.
24432408 */
24442409 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
2445
- (void)debugfs_create_file(debugfs_files[i].name,
2446
- debugfs_files[i].mode,
2447
- adapter->debugfs_root,
2448
- (void *)adapter,
2449
- debugfs_files[i].fops);
2410
+ debugfs_create_file(debugfs_files[i].name,
2411
+ debugfs_files[i].mode,
2412
+ adapter->debugfs_root, adapter,
2413
+ debugfs_files[i].fops);
24502414
24512415 return 0;
24522416 }
....@@ -2669,6 +2633,7 @@
26692633 */
26702634 size_nports_qsets(adapter);
26712635
2636
+ adapter->flags |= CXGB4VF_FW_OK;
26722637 return 0;
26732638 }
26742639
....@@ -2703,7 +2668,8 @@
27032668 * support. In particular, this means that we need to know what kind
27042669 * of interrupts we'll be using ...
27052670 */
2706
- BUG_ON((adapter->flags & (USING_MSIX|USING_MSI)) == 0);
2671
+ BUG_ON((adapter->flags &
2672
+ (CXGB4VF_USING_MSIX | CXGB4VF_USING_MSI)) == 0);
27072673
27082674 /*
27092675 * Count the number of 10GbE Virtual Interfaces that we have.
....@@ -2880,6 +2846,39 @@
28802846 #endif
28812847 };
28822848
2849
+/**
2850
+ * cxgb4vf_get_port_mask - Get port mask for the VF based on mac
2851
+ * address stored on the adapter
2852
+ * @adapter: The adapter
2853
+ *
2854
+ * Find the the port mask for the VF based on the index of mac
2855
+ * address stored in the adapter. If no mac address is stored on
2856
+ * the adapter for the VF, use the port mask received from the
2857
+ * firmware.
2858
+ */
2859
+static unsigned int cxgb4vf_get_port_mask(struct adapter *adapter)
2860
+{
2861
+ unsigned int naddr = 1, pidx = 0;
2862
+ unsigned int pmask, rmask = 0;
2863
+ u8 mac[ETH_ALEN];
2864
+ int err;
2865
+
2866
+ pmask = adapter->params.vfres.pmask;
2867
+ while (pmask) {
2868
+ if (pmask & 1) {
2869
+ err = t4vf_get_vf_mac_acl(adapter, pidx, &naddr, mac);
2870
+ if (!err && !is_zero_ether_addr(mac))
2871
+ rmask |= (1 << pidx);
2872
+ }
2873
+ pmask >>= 1;
2874
+ pidx++;
2875
+ }
2876
+ if (!rmask)
2877
+ rmask = adapter->params.vfres.pmask;
2878
+
2879
+ return rmask;
2880
+}
2881
+
28832882 /*
28842883 * "Probe" a device: initialize a device and construct all kernel and driver
28852884 * state needed to manage the device. This routine is called "init_one" in
....@@ -2888,19 +2887,12 @@
28882887 static int cxgb4vf_pci_probe(struct pci_dev *pdev,
28892888 const struct pci_device_id *ent)
28902889 {
2890
+ struct adapter *adapter;
2891
+ struct net_device *netdev;
2892
+ struct port_info *pi;
2893
+ unsigned int pmask;
28912894 int pci_using_dac;
28922895 int err, pidx;
2893
- unsigned int pmask;
2894
- struct adapter *adapter;
2895
- struct port_info *pi;
2896
- struct net_device *netdev;
2897
- unsigned int pf;
2898
-
2899
- /*
2900
- * Print our driver banner the first time we're called to initialize a
2901
- * device.
2902
- */
2903
- pr_info_once("%s - version %s\n", DRV_DESC, DRV_VERSION);
29042896
29052897 /*
29062898 * Initialize generic PCI device state.
....@@ -3029,11 +3021,13 @@
30293021 * using Relaxed Ordering.
30303022 */
30313023 if (!pcie_relaxed_ordering_enabled(pdev))
3032
- adapter->flags |= ROOT_NO_RELAXED_ORDERING;
3024
+ adapter->flags |= CXGB4VF_ROOT_NO_RELAXED_ORDERING;
30333025
30343026 err = adap_init0(adapter);
30353027 if (err)
3036
- goto err_unmap_bar;
3028
+ dev_err(&pdev->dev,
3029
+ "Adapter initialization failed, error %d. Continuing in debug mode\n",
3030
+ err);
30373031
30383032 /* Initialize hash mac addr list */
30393033 INIT_LIST_HEAD(&adapter->mac_hlist);
....@@ -3041,8 +3035,7 @@
30413035 /*
30423036 * Allocate our "adapter ports" and stitch everything together.
30433037 */
3044
- pmask = adapter->params.vfres.pmask;
3045
- pf = t4vf_get_pf_from_vf(adapter);
3038
+ pmask = cxgb4vf_get_port_mask(adapter);
30463039 for_each_port(adapter, pidx) {
30473040 int port_id, viid;
30483041 u8 mac[ETH_ALEN];
....@@ -3058,13 +3051,6 @@
30583051 break;
30593052 port_id = ffs(pmask) - 1;
30603053 pmask &= ~(1 << port_id);
3061
- viid = t4vf_alloc_vi(adapter, port_id);
3062
- if (viid < 0) {
3063
- dev_err(&pdev->dev, "cannot allocate VI for port %d:"
3064
- " err=%d\n", port_id, viid);
3065
- err = viid;
3066
- goto err_free_dev;
3067
- }
30683054
30693055 /*
30703056 * Allocate our network device and stitch things together.
....@@ -3072,7 +3058,6 @@
30723058 netdev = alloc_etherdev_mq(sizeof(struct port_info),
30733059 MAX_PORT_QSETS);
30743060 if (netdev == NULL) {
3075
- t4vf_free_vi(adapter, viid);
30763061 err = -ENOMEM;
30773062 goto err_free_dev;
30783063 }
....@@ -3082,26 +3067,21 @@
30823067 pi->adapter = adapter;
30833068 pi->pidx = pidx;
30843069 pi->port_id = port_id;
3085
- pi->viid = viid;
30863070
30873071 /*
30883072 * Initialize the starting state of our "port" and register
30893073 * it.
30903074 */
30913075 pi->xact_addr_filt = -1;
3092
- netif_carrier_off(netdev);
30933076 netdev->irq = pdev->irq;
30943077
3095
- netdev->hw_features = NETIF_F_SG | TSO_FLAGS |
3096
- NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
3097
- NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_RXCSUM;
3098
- netdev->vlan_features = NETIF_F_SG | TSO_FLAGS |
3099
- NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
3100
- NETIF_F_HIGHDMA;
3101
- netdev->features = netdev->hw_features |
3102
- NETIF_F_HW_VLAN_CTAG_TX;
3078
+ netdev->hw_features = NETIF_F_SG | TSO_FLAGS | NETIF_F_GRO |
3079
+ NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM |
3080
+ NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX;
3081
+ netdev->features = netdev->hw_features;
31033082 if (pci_using_dac)
31043083 netdev->features |= NETIF_F_HIGHDMA;
3084
+ netdev->vlan_features = netdev->features & VLAN_FEAT;
31053085
31063086 netdev->priv_flags |= IFF_UNICAST_FLT;
31073087 netdev->min_mtu = 81;
....@@ -3110,6 +3090,23 @@
31103090 netdev->netdev_ops = &cxgb4vf_netdev_ops;
31113091 netdev->ethtool_ops = &cxgb4vf_ethtool_ops;
31123092 netdev->dev_port = pi->port_id;
3093
+
3094
+ /*
3095
+ * If we haven't been able to contact the firmware, there's
3096
+ * nothing else we can do for this "port" ...
3097
+ */
3098
+ if (!(adapter->flags & CXGB4VF_FW_OK))
3099
+ continue;
3100
+
3101
+ viid = t4vf_alloc_vi(adapter, port_id);
3102
+ if (viid < 0) {
3103
+ dev_err(&pdev->dev,
3104
+ "cannot allocate VI for port %d: err=%d\n",
3105
+ port_id, viid);
3106
+ err = viid;
3107
+ goto err_free_dev;
3108
+ }
3109
+ pi->viid = viid;
31133110
31143111 /*
31153112 * Initialize the hardware/software state for the port.
....@@ -3121,7 +3118,7 @@
31213118 goto err_free_dev;
31223119 }
31233120
3124
- err = t4vf_get_vf_mac_acl(adapter, pf, &naddr, mac);
3121
+ err = t4vf_get_vf_mac_acl(adapter, port_id, &naddr, mac);
31253122 if (err) {
31263123 dev_err(&pdev->dev,
31273124 "unable to determine MAC ACL address, "
....@@ -3148,7 +3145,7 @@
31483145 * get MSI interrupts we bail with the error.
31493146 */
31503147 if (msi == MSI_MSIX && enable_msix(adapter) == 0)
3151
- adapter->flags |= USING_MSIX;
3148
+ adapter->flags |= CXGB4VF_USING_MSIX;
31523149 else {
31533150 if (msi == MSI_MSIX) {
31543151 dev_info(adapter->pdev_dev,
....@@ -3168,7 +3165,7 @@
31683165 " err=%d\n", err);
31693166 goto err_free_dev;
31703167 }
3171
- adapter->flags |= USING_MSI;
3168
+ adapter->flags |= CXGB4VF_USING_MSI;
31723169 }
31733170
31743171 /* Now that we know how many "ports" we have and what interrupt
....@@ -3198,6 +3195,7 @@
31983195 continue;
31993196 }
32003197
3198
+ netif_carrier_off(netdev);
32013199 set_bit(pidx, &adapter->registered_device_map);
32023200 }
32033201 if (adapter->registered_device_map == 0) {
....@@ -3212,11 +3210,7 @@
32123210 adapter->debugfs_root =
32133211 debugfs_create_dir(pci_name(pdev),
32143212 cxgb4vf_debugfs_root);
3215
- if (IS_ERR_OR_NULL(adapter->debugfs_root))
3216
- dev_warn(&pdev->dev, "could not create debugfs"
3217
- " directory");
3218
- else
3219
- setup_debugfs(adapter);
3213
+ setup_debugfs(adapter);
32203214 }
32213215
32223216 /*
....@@ -3226,8 +3220,8 @@
32263220 for_each_port(adapter, pidx) {
32273221 dev_info(adapter->pdev_dev, "%s: Chelsio VF NIC PCIe %s\n",
32283222 adapter->port[pidx]->name,
3229
- (adapter->flags & USING_MSIX) ? "MSI-X" :
3230
- (adapter->flags & USING_MSI) ? "MSI" : "");
3223
+ (adapter->flags & CXGB4VF_USING_MSIX) ? "MSI-X" :
3224
+ (adapter->flags & CXGB4VF_USING_MSI) ? "MSI" : "");
32313225 }
32323226
32333227 /*
....@@ -3240,12 +3234,12 @@
32403234 * so far and return the error.
32413235 */
32423236 err_disable_interrupts:
3243
- if (adapter->flags & USING_MSIX) {
3237
+ if (adapter->flags & CXGB4VF_USING_MSIX) {
32443238 pci_disable_msix(adapter->pdev);
3245
- adapter->flags &= ~USING_MSIX;
3246
- } else if (adapter->flags & USING_MSI) {
3239
+ adapter->flags &= ~CXGB4VF_USING_MSIX;
3240
+ } else if (adapter->flags & CXGB4VF_USING_MSI) {
32473241 pci_disable_msi(adapter->pdev);
3248
- adapter->flags &= ~USING_MSI;
3242
+ adapter->flags &= ~CXGB4VF_USING_MSI;
32493243 }
32503244
32513245 err_free_dev:
....@@ -3254,13 +3248,13 @@
32543248 if (netdev == NULL)
32553249 continue;
32563250 pi = netdev_priv(netdev);
3257
- t4vf_free_vi(adapter, pi->viid);
3251
+ if (pi->viid)
3252
+ t4vf_free_vi(adapter, pi->viid);
32583253 if (test_bit(pidx, &adapter->registered_device_map))
32593254 unregister_netdev(netdev);
32603255 free_netdev(netdev);
32613256 }
32623257
3263
-err_unmap_bar:
32643258 if (!is_t4(adapter->params.chip))
32653259 iounmap(adapter->bar2);
32663260
....@@ -3289,6 +3283,7 @@
32893283 static void cxgb4vf_pci_remove(struct pci_dev *pdev)
32903284 {
32913285 struct adapter *adapter = pci_get_drvdata(pdev);
3286
+ struct hash_mac_addr *entry, *tmp;
32923287
32933288 /*
32943289 * Tear down driver state associated with device.
....@@ -3304,12 +3299,12 @@
33043299 if (test_bit(pidx, &adapter->registered_device_map))
33053300 unregister_netdev(adapter->port[pidx]);
33063301 t4vf_sge_stop(adapter);
3307
- if (adapter->flags & USING_MSIX) {
3302
+ if (adapter->flags & CXGB4VF_USING_MSIX) {
33083303 pci_disable_msix(adapter->pdev);
3309
- adapter->flags &= ~USING_MSIX;
3310
- } else if (adapter->flags & USING_MSI) {
3304
+ adapter->flags &= ~CXGB4VF_USING_MSIX;
3305
+ } else if (adapter->flags & CXGB4VF_USING_MSI) {
33113306 pci_disable_msi(adapter->pdev);
3312
- adapter->flags &= ~USING_MSI;
3307
+ adapter->flags &= ~CXGB4VF_USING_MSI;
33133308 }
33143309
33153310 /*
....@@ -3332,13 +3327,19 @@
33323327 continue;
33333328
33343329 pi = netdev_priv(netdev);
3335
- t4vf_free_vi(adapter, pi->viid);
3330
+ if (pi->viid)
3331
+ t4vf_free_vi(adapter, pi->viid);
33363332 free_netdev(netdev);
33373333 }
33383334 iounmap(adapter->regs);
33393335 if (!is_t4(adapter->params.chip))
33403336 iounmap(adapter->bar2);
33413337 kfree(adapter->mbox_log);
3338
+ list_for_each_entry_safe(entry, tmp, &adapter->mac_hlist,
3339
+ list) {
3340
+ list_del(&entry->list);
3341
+ kfree(entry);
3342
+ }
33423343 kfree(adapter);
33433344 }
33443345
....@@ -3375,12 +3376,12 @@
33753376 * Interrupts allowing various internal pathways to drain.
33763377 */
33773378 t4vf_sge_stop(adapter);
3378
- if (adapter->flags & USING_MSIX) {
3379
+ if (adapter->flags & CXGB4VF_USING_MSIX) {
33793380 pci_disable_msix(adapter->pdev);
3380
- adapter->flags &= ~USING_MSIX;
3381
- } else if (adapter->flags & USING_MSI) {
3381
+ adapter->flags &= ~CXGB4VF_USING_MSIX;
3382
+ } else if (adapter->flags & CXGB4VF_USING_MSI) {
33823383 pci_disable_msi(adapter->pdev);
3383
- adapter->flags &= ~USING_MSI;
3384
+ adapter->flags &= ~CXGB4VF_USING_MSI;
33843385 }
33853386
33863387 /*
....@@ -3407,7 +3408,6 @@
34073408 MODULE_DESCRIPTION(DRV_DESC);
34083409 MODULE_AUTHOR("Chelsio Communications");
34093410 MODULE_LICENSE("Dual BSD/GPL");
3410
-MODULE_VERSION(DRV_VERSION);
34113411 MODULE_DEVICE_TABLE(pci, cxgb4vf_pci_tbl);
34123412
34133413 static struct pci_driver cxgb4vf_driver = {
....@@ -3434,13 +3434,11 @@
34343434 return -EINVAL;
34353435 }
34363436
3437
- /* Debugfs support is optional, just warn if this fails */
3437
+ /* Debugfs support is optional, debugfs will warn if this fails */
34383438 cxgb4vf_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
3439
- if (IS_ERR_OR_NULL(cxgb4vf_debugfs_root))
3440
- pr_warn("could not create debugfs entry, continuing\n");
34413439
34423440 ret = pci_register_driver(&cxgb4vf_driver);
3443
- if (ret < 0 && !IS_ERR_OR_NULL(cxgb4vf_debugfs_root))
3441
+ if (ret < 0)
34443442 debugfs_remove(cxgb4vf_debugfs_root);
34453443 return ret;
34463444 }