]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - drivers/net/ethernet/qlogic/qede/qede_main.c
qede: Split filtering logic to its own file
[mirror_ubuntu-artful-kernel.git] / drivers / net / ethernet / qlogic / qede / qede_main.c
1 /* QLogic qede NIC Driver
2 * Copyright (c) 2015-2017 QLogic Corporation
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and /or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32 #include <linux/module.h>
33 #include <linux/pci.h>
34 #include <linux/version.h>
35 #include <linux/device.h>
36 #include <linux/netdevice.h>
37 #include <linux/etherdevice.h>
38 #include <linux/skbuff.h>
39 #include <linux/errno.h>
40 #include <linux/list.h>
41 #include <linux/string.h>
42 #include <linux/dma-mapping.h>
43 #include <linux/interrupt.h>
44 #include <asm/byteorder.h>
45 #include <asm/param.h>
46 #include <linux/io.h>
47 #include <linux/netdev_features.h>
48 #include <linux/udp.h>
49 #include <linux/tcp.h>
50 #include <net/udp_tunnel.h>
51 #include <linux/ip.h>
52 #include <net/ipv6.h>
53 #include <net/tcp.h>
54 #include <linux/if_ether.h>
55 #include <linux/if_vlan.h>
56 #include <linux/pkt_sched.h>
57 #include <linux/ethtool.h>
58 #include <linux/in.h>
59 #include <linux/random.h>
60 #include <net/ip6_checksum.h>
61 #include <linux/bitops.h>
62 #include <linux/qed/qede_roce.h>
63 #include "qede.h"
64
65 static char version[] =
66 "QLogic FastLinQ 4xxxx Ethernet Driver qede " DRV_MODULE_VERSION "\n";
67
68 MODULE_DESCRIPTION("QLogic FastLinQ 4xxxx Ethernet Driver");
69 MODULE_LICENSE("GPL");
70 MODULE_VERSION(DRV_MODULE_VERSION);
71
72 static uint debug;
73 module_param(debug, uint, 0);
74 MODULE_PARM_DESC(debug, " Default debug msglevel");
75
76 static const struct qed_eth_ops *qed_ops;
77
78 #define CHIP_NUM_57980S_40 0x1634
79 #define CHIP_NUM_57980S_10 0x1666
80 #define CHIP_NUM_57980S_MF 0x1636
81 #define CHIP_NUM_57980S_100 0x1644
82 #define CHIP_NUM_57980S_50 0x1654
83 #define CHIP_NUM_57980S_25 0x1656
84 #define CHIP_NUM_57980S_IOV 0x1664
85
86 #ifndef PCI_DEVICE_ID_NX2_57980E
87 #define PCI_DEVICE_ID_57980S_40 CHIP_NUM_57980S_40
88 #define PCI_DEVICE_ID_57980S_10 CHIP_NUM_57980S_10
89 #define PCI_DEVICE_ID_57980S_MF CHIP_NUM_57980S_MF
90 #define PCI_DEVICE_ID_57980S_100 CHIP_NUM_57980S_100
91 #define PCI_DEVICE_ID_57980S_50 CHIP_NUM_57980S_50
92 #define PCI_DEVICE_ID_57980S_25 CHIP_NUM_57980S_25
93 #define PCI_DEVICE_ID_57980S_IOV CHIP_NUM_57980S_IOV
94 #endif
95
96 enum qede_pci_private {
97 QEDE_PRIVATE_PF,
98 QEDE_PRIVATE_VF
99 };
100
101 static const struct pci_device_id qede_pci_tbl[] = {
102 {PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_57980S_40), QEDE_PRIVATE_PF},
103 {PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_57980S_10), QEDE_PRIVATE_PF},
104 {PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_57980S_MF), QEDE_PRIVATE_PF},
105 {PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_57980S_100), QEDE_PRIVATE_PF},
106 {PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_57980S_50), QEDE_PRIVATE_PF},
107 {PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_57980S_25), QEDE_PRIVATE_PF},
108 #ifdef CONFIG_QED_SRIOV
109 {PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_57980S_IOV), QEDE_PRIVATE_VF},
110 #endif
111 { 0 }
112 };
113
114 MODULE_DEVICE_TABLE(pci, qede_pci_tbl);
115
116 static int qede_probe(struct pci_dev *pdev, const struct pci_device_id *id);
117
118 #define TX_TIMEOUT (5 * HZ)
119
120 /* Utilize last protocol index for XDP */
121 #define XDP_PI 11
122
123 static void qede_remove(struct pci_dev *pdev);
124 static void qede_shutdown(struct pci_dev *pdev);
125 static void qede_link_update(void *dev, struct qed_link_output *link);
126
127 /* The qede lock is used to protect driver state change and driver flows that
128 * are not reentrant.
129 */
130 void __qede_lock(struct qede_dev *edev)
131 {
132 mutex_lock(&edev->qede_lock);
133 }
134
135 void __qede_unlock(struct qede_dev *edev)
136 {
137 mutex_unlock(&edev->qede_lock);
138 }
139
140 #ifdef CONFIG_QED_SRIOV
141 static int qede_set_vf_vlan(struct net_device *ndev, int vf, u16 vlan, u8 qos,
142 __be16 vlan_proto)
143 {
144 struct qede_dev *edev = netdev_priv(ndev);
145
146 if (vlan > 4095) {
147 DP_NOTICE(edev, "Illegal vlan value %d\n", vlan);
148 return -EINVAL;
149 }
150
151 if (vlan_proto != htons(ETH_P_8021Q))
152 return -EPROTONOSUPPORT;
153
154 DP_VERBOSE(edev, QED_MSG_IOV, "Setting Vlan 0x%04x to VF [%d]\n",
155 vlan, vf);
156
157 return edev->ops->iov->set_vlan(edev->cdev, vlan, vf);
158 }
159
160 static int qede_set_vf_mac(struct net_device *ndev, int vfidx, u8 *mac)
161 {
162 struct qede_dev *edev = netdev_priv(ndev);
163
164 DP_VERBOSE(edev, QED_MSG_IOV,
165 "Setting MAC %02x:%02x:%02x:%02x:%02x:%02x to VF [%d]\n",
166 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], vfidx);
167
168 if (!is_valid_ether_addr(mac)) {
169 DP_VERBOSE(edev, QED_MSG_IOV, "MAC address isn't valid\n");
170 return -EINVAL;
171 }
172
173 return edev->ops->iov->set_mac(edev->cdev, mac, vfidx);
174 }
175
176 static int qede_sriov_configure(struct pci_dev *pdev, int num_vfs_param)
177 {
178 struct qede_dev *edev = netdev_priv(pci_get_drvdata(pdev));
179 struct qed_dev_info *qed_info = &edev->dev_info.common;
180 int rc;
181
182 DP_VERBOSE(edev, QED_MSG_IOV, "Requested %d VFs\n", num_vfs_param);
183
184 rc = edev->ops->iov->configure(edev->cdev, num_vfs_param);
185
186 /* Enable/Disable Tx switching for PF */
187 if ((rc == num_vfs_param) && netif_running(edev->ndev) &&
188 qed_info->mf_mode != QED_MF_NPAR && qed_info->tx_switching) {
189 struct qed_update_vport_params params;
190
191 memset(&params, 0, sizeof(params));
192 params.vport_id = 0;
193 params.update_tx_switching_flg = 1;
194 params.tx_switching_flg = num_vfs_param ? 1 : 0;
195 edev->ops->vport_update(edev->cdev, &params);
196 }
197
198 return rc;
199 }
200 #endif
201
202 static struct pci_driver qede_pci_driver = {
203 .name = "qede",
204 .id_table = qede_pci_tbl,
205 .probe = qede_probe,
206 .remove = qede_remove,
207 .shutdown = qede_shutdown,
208 #ifdef CONFIG_QED_SRIOV
209 .sriov_configure = qede_sriov_configure,
210 #endif
211 };
212
213 static struct qed_eth_cb_ops qede_ll_ops = {
214 {
215 .link_update = qede_link_update,
216 },
217 .force_mac = qede_force_mac,
218 };
219
220 static int qede_netdev_event(struct notifier_block *this, unsigned long event,
221 void *ptr)
222 {
223 struct net_device *ndev = netdev_notifier_info_to_dev(ptr);
224 struct ethtool_drvinfo drvinfo;
225 struct qede_dev *edev;
226
227 if (event != NETDEV_CHANGENAME && event != NETDEV_CHANGEADDR)
228 goto done;
229
230 /* Check whether this is a qede device */
231 if (!ndev || !ndev->ethtool_ops || !ndev->ethtool_ops->get_drvinfo)
232 goto done;
233
234 memset(&drvinfo, 0, sizeof(drvinfo));
235 ndev->ethtool_ops->get_drvinfo(ndev, &drvinfo);
236 if (strcmp(drvinfo.driver, "qede"))
237 goto done;
238 edev = netdev_priv(ndev);
239
240 switch (event) {
241 case NETDEV_CHANGENAME:
242 /* Notify qed of the name change */
243 if (!edev->ops || !edev->ops->common)
244 goto done;
245 edev->ops->common->set_id(edev->cdev, edev->ndev->name, "qede");
246 break;
247 case NETDEV_CHANGEADDR:
248 edev = netdev_priv(ndev);
249 qede_roce_event_changeaddr(edev);
250 break;
251 }
252
253 done:
254 return NOTIFY_DONE;
255 }
256
257 static struct notifier_block qede_netdev_notifier = {
258 .notifier_call = qede_netdev_event,
259 };
260
261 static
262 int __init qede_init(void)
263 {
264 int ret;
265
266 pr_info("qede_init: %s\n", version);
267
268 qed_ops = qed_get_eth_ops();
269 if (!qed_ops) {
270 pr_notice("Failed to get qed ethtool operations\n");
271 return -EINVAL;
272 }
273
274 /* Must register notifier before pci ops, since we might miss
275 * interface rename after pci probe and netdev registeration.
276 */
277 ret = register_netdevice_notifier(&qede_netdev_notifier);
278 if (ret) {
279 pr_notice("Failed to register netdevice_notifier\n");
280 qed_put_eth_ops();
281 return -EINVAL;
282 }
283
284 ret = pci_register_driver(&qede_pci_driver);
285 if (ret) {
286 pr_notice("Failed to register driver\n");
287 unregister_netdevice_notifier(&qede_netdev_notifier);
288 qed_put_eth_ops();
289 return -EINVAL;
290 }
291
292 return 0;
293 }
294
295 static void __exit qede_cleanup(void)
296 {
297 if (debug & QED_LOG_INFO_MASK)
298 pr_info("qede_cleanup called\n");
299
300 unregister_netdevice_notifier(&qede_netdev_notifier);
301 pci_unregister_driver(&qede_pci_driver);
302 qed_put_eth_ops();
303 }
304
305 module_init(qede_init);
306 module_exit(qede_cleanup);
307
308 static int qede_open(struct net_device *ndev);
309 static int qede_close(struct net_device *ndev);
310
311 void qede_fill_by_demand_stats(struct qede_dev *edev)
312 {
313 struct qed_eth_stats stats;
314
315 edev->ops->get_vport_stats(edev->cdev, &stats);
316 edev->stats.no_buff_discards = stats.no_buff_discards;
317 edev->stats.packet_too_big_discard = stats.packet_too_big_discard;
318 edev->stats.ttl0_discard = stats.ttl0_discard;
319 edev->stats.rx_ucast_bytes = stats.rx_ucast_bytes;
320 edev->stats.rx_mcast_bytes = stats.rx_mcast_bytes;
321 edev->stats.rx_bcast_bytes = stats.rx_bcast_bytes;
322 edev->stats.rx_ucast_pkts = stats.rx_ucast_pkts;
323 edev->stats.rx_mcast_pkts = stats.rx_mcast_pkts;
324 edev->stats.rx_bcast_pkts = stats.rx_bcast_pkts;
325 edev->stats.mftag_filter_discards = stats.mftag_filter_discards;
326 edev->stats.mac_filter_discards = stats.mac_filter_discards;
327
328 edev->stats.tx_ucast_bytes = stats.tx_ucast_bytes;
329 edev->stats.tx_mcast_bytes = stats.tx_mcast_bytes;
330 edev->stats.tx_bcast_bytes = stats.tx_bcast_bytes;
331 edev->stats.tx_ucast_pkts = stats.tx_ucast_pkts;
332 edev->stats.tx_mcast_pkts = stats.tx_mcast_pkts;
333 edev->stats.tx_bcast_pkts = stats.tx_bcast_pkts;
334 edev->stats.tx_err_drop_pkts = stats.tx_err_drop_pkts;
335 edev->stats.coalesced_pkts = stats.tpa_coalesced_pkts;
336 edev->stats.coalesced_events = stats.tpa_coalesced_events;
337 edev->stats.coalesced_aborts_num = stats.tpa_aborts_num;
338 edev->stats.non_coalesced_pkts = stats.tpa_not_coalesced_pkts;
339 edev->stats.coalesced_bytes = stats.tpa_coalesced_bytes;
340
341 edev->stats.rx_64_byte_packets = stats.rx_64_byte_packets;
342 edev->stats.rx_65_to_127_byte_packets = stats.rx_65_to_127_byte_packets;
343 edev->stats.rx_128_to_255_byte_packets =
344 stats.rx_128_to_255_byte_packets;
345 edev->stats.rx_256_to_511_byte_packets =
346 stats.rx_256_to_511_byte_packets;
347 edev->stats.rx_512_to_1023_byte_packets =
348 stats.rx_512_to_1023_byte_packets;
349 edev->stats.rx_1024_to_1518_byte_packets =
350 stats.rx_1024_to_1518_byte_packets;
351 edev->stats.rx_1519_to_1522_byte_packets =
352 stats.rx_1519_to_1522_byte_packets;
353 edev->stats.rx_1519_to_2047_byte_packets =
354 stats.rx_1519_to_2047_byte_packets;
355 edev->stats.rx_2048_to_4095_byte_packets =
356 stats.rx_2048_to_4095_byte_packets;
357 edev->stats.rx_4096_to_9216_byte_packets =
358 stats.rx_4096_to_9216_byte_packets;
359 edev->stats.rx_9217_to_16383_byte_packets =
360 stats.rx_9217_to_16383_byte_packets;
361 edev->stats.rx_crc_errors = stats.rx_crc_errors;
362 edev->stats.rx_mac_crtl_frames = stats.rx_mac_crtl_frames;
363 edev->stats.rx_pause_frames = stats.rx_pause_frames;
364 edev->stats.rx_pfc_frames = stats.rx_pfc_frames;
365 edev->stats.rx_align_errors = stats.rx_align_errors;
366 edev->stats.rx_carrier_errors = stats.rx_carrier_errors;
367 edev->stats.rx_oversize_packets = stats.rx_oversize_packets;
368 edev->stats.rx_jabbers = stats.rx_jabbers;
369 edev->stats.rx_undersize_packets = stats.rx_undersize_packets;
370 edev->stats.rx_fragments = stats.rx_fragments;
371 edev->stats.tx_64_byte_packets = stats.tx_64_byte_packets;
372 edev->stats.tx_65_to_127_byte_packets = stats.tx_65_to_127_byte_packets;
373 edev->stats.tx_128_to_255_byte_packets =
374 stats.tx_128_to_255_byte_packets;
375 edev->stats.tx_256_to_511_byte_packets =
376 stats.tx_256_to_511_byte_packets;
377 edev->stats.tx_512_to_1023_byte_packets =
378 stats.tx_512_to_1023_byte_packets;
379 edev->stats.tx_1024_to_1518_byte_packets =
380 stats.tx_1024_to_1518_byte_packets;
381 edev->stats.tx_1519_to_2047_byte_packets =
382 stats.tx_1519_to_2047_byte_packets;
383 edev->stats.tx_2048_to_4095_byte_packets =
384 stats.tx_2048_to_4095_byte_packets;
385 edev->stats.tx_4096_to_9216_byte_packets =
386 stats.tx_4096_to_9216_byte_packets;
387 edev->stats.tx_9217_to_16383_byte_packets =
388 stats.tx_9217_to_16383_byte_packets;
389 edev->stats.tx_pause_frames = stats.tx_pause_frames;
390 edev->stats.tx_pfc_frames = stats.tx_pfc_frames;
391 edev->stats.tx_lpi_entry_count = stats.tx_lpi_entry_count;
392 edev->stats.tx_total_collisions = stats.tx_total_collisions;
393 edev->stats.brb_truncates = stats.brb_truncates;
394 edev->stats.brb_discards = stats.brb_discards;
395 edev->stats.tx_mac_ctrl_frames = stats.tx_mac_ctrl_frames;
396 }
397
398 static
399 struct rtnl_link_stats64 *qede_get_stats64(struct net_device *dev,
400 struct rtnl_link_stats64 *stats)
401 {
402 struct qede_dev *edev = netdev_priv(dev);
403
404 qede_fill_by_demand_stats(edev);
405
406 stats->rx_packets = edev->stats.rx_ucast_pkts +
407 edev->stats.rx_mcast_pkts +
408 edev->stats.rx_bcast_pkts;
409 stats->tx_packets = edev->stats.tx_ucast_pkts +
410 edev->stats.tx_mcast_pkts +
411 edev->stats.tx_bcast_pkts;
412
413 stats->rx_bytes = edev->stats.rx_ucast_bytes +
414 edev->stats.rx_mcast_bytes +
415 edev->stats.rx_bcast_bytes;
416
417 stats->tx_bytes = edev->stats.tx_ucast_bytes +
418 edev->stats.tx_mcast_bytes +
419 edev->stats.tx_bcast_bytes;
420
421 stats->tx_errors = edev->stats.tx_err_drop_pkts;
422 stats->multicast = edev->stats.rx_mcast_pkts +
423 edev->stats.rx_bcast_pkts;
424
425 stats->rx_fifo_errors = edev->stats.no_buff_discards;
426
427 stats->collisions = edev->stats.tx_total_collisions;
428 stats->rx_crc_errors = edev->stats.rx_crc_errors;
429 stats->rx_frame_errors = edev->stats.rx_align_errors;
430
431 return stats;
432 }
433
434 #ifdef CONFIG_QED_SRIOV
435 static int qede_get_vf_config(struct net_device *dev, int vfidx,
436 struct ifla_vf_info *ivi)
437 {
438 struct qede_dev *edev = netdev_priv(dev);
439
440 if (!edev->ops)
441 return -EINVAL;
442
443 return edev->ops->iov->get_config(edev->cdev, vfidx, ivi);
444 }
445
446 static int qede_set_vf_rate(struct net_device *dev, int vfidx,
447 int min_tx_rate, int max_tx_rate)
448 {
449 struct qede_dev *edev = netdev_priv(dev);
450
451 return edev->ops->iov->set_rate(edev->cdev, vfidx, min_tx_rate,
452 max_tx_rate);
453 }
454
455 static int qede_set_vf_spoofchk(struct net_device *dev, int vfidx, bool val)
456 {
457 struct qede_dev *edev = netdev_priv(dev);
458
459 if (!edev->ops)
460 return -EINVAL;
461
462 return edev->ops->iov->set_spoof(edev->cdev, vfidx, val);
463 }
464
465 static int qede_set_vf_link_state(struct net_device *dev, int vfidx,
466 int link_state)
467 {
468 struct qede_dev *edev = netdev_priv(dev);
469
470 if (!edev->ops)
471 return -EINVAL;
472
473 return edev->ops->iov->set_link_state(edev->cdev, vfidx, link_state);
474 }
475 #endif
476
477 static const struct net_device_ops qede_netdev_ops = {
478 .ndo_open = qede_open,
479 .ndo_stop = qede_close,
480 .ndo_start_xmit = qede_start_xmit,
481 .ndo_set_rx_mode = qede_set_rx_mode,
482 .ndo_set_mac_address = qede_set_mac_addr,
483 .ndo_validate_addr = eth_validate_addr,
484 .ndo_change_mtu = qede_change_mtu,
485 #ifdef CONFIG_QED_SRIOV
486 .ndo_set_vf_mac = qede_set_vf_mac,
487 .ndo_set_vf_vlan = qede_set_vf_vlan,
488 #endif
489 .ndo_vlan_rx_add_vid = qede_vlan_rx_add_vid,
490 .ndo_vlan_rx_kill_vid = qede_vlan_rx_kill_vid,
491 .ndo_set_features = qede_set_features,
492 .ndo_get_stats64 = qede_get_stats64,
493 #ifdef CONFIG_QED_SRIOV
494 .ndo_set_vf_link_state = qede_set_vf_link_state,
495 .ndo_set_vf_spoofchk = qede_set_vf_spoofchk,
496 .ndo_get_vf_config = qede_get_vf_config,
497 .ndo_set_vf_rate = qede_set_vf_rate,
498 #endif
499 .ndo_udp_tunnel_add = qede_udp_tunnel_add,
500 .ndo_udp_tunnel_del = qede_udp_tunnel_del,
501 .ndo_features_check = qede_features_check,
502 .ndo_xdp = qede_xdp,
503 };
504
505 /* -------------------------------------------------------------------------
506 * START OF PROBE / REMOVE
507 * -------------------------------------------------------------------------
508 */
509
510 static struct qede_dev *qede_alloc_etherdev(struct qed_dev *cdev,
511 struct pci_dev *pdev,
512 struct qed_dev_eth_info *info,
513 u32 dp_module, u8 dp_level)
514 {
515 struct net_device *ndev;
516 struct qede_dev *edev;
517
518 ndev = alloc_etherdev_mqs(sizeof(*edev),
519 info->num_queues, info->num_queues);
520 if (!ndev) {
521 pr_err("etherdev allocation failed\n");
522 return NULL;
523 }
524
525 edev = netdev_priv(ndev);
526 edev->ndev = ndev;
527 edev->cdev = cdev;
528 edev->pdev = pdev;
529 edev->dp_module = dp_module;
530 edev->dp_level = dp_level;
531 edev->ops = qed_ops;
532 edev->q_num_rx_buffers = NUM_RX_BDS_DEF;
533 edev->q_num_tx_buffers = NUM_TX_BDS_DEF;
534
535 DP_INFO(edev, "Allocated netdev with %d tx queues and %d rx queues\n",
536 info->num_queues, info->num_queues);
537
538 SET_NETDEV_DEV(ndev, &pdev->dev);
539
540 memset(&edev->stats, 0, sizeof(edev->stats));
541 memcpy(&edev->dev_info, info, sizeof(*info));
542
543 INIT_LIST_HEAD(&edev->vlan_list);
544
545 return edev;
546 }
547
548 static void qede_init_ndev(struct qede_dev *edev)
549 {
550 struct net_device *ndev = edev->ndev;
551 struct pci_dev *pdev = edev->pdev;
552 u32 hw_features;
553
554 pci_set_drvdata(pdev, ndev);
555
556 ndev->mem_start = edev->dev_info.common.pci_mem_start;
557 ndev->base_addr = ndev->mem_start;
558 ndev->mem_end = edev->dev_info.common.pci_mem_end;
559 ndev->irq = edev->dev_info.common.pci_irq;
560
561 ndev->watchdog_timeo = TX_TIMEOUT;
562
563 ndev->netdev_ops = &qede_netdev_ops;
564
565 qede_set_ethtool_ops(ndev);
566
567 ndev->priv_flags |= IFF_UNICAST_FLT;
568
569 /* user-changeble features */
570 hw_features = NETIF_F_GRO | NETIF_F_SG |
571 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
572 NETIF_F_TSO | NETIF_F_TSO6;
573
574 /* Encap features*/
575 hw_features |= NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL |
576 NETIF_F_TSO_ECN | NETIF_F_GSO_UDP_TUNNEL_CSUM |
577 NETIF_F_GSO_GRE_CSUM;
578 ndev->hw_enc_features = NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
579 NETIF_F_SG | NETIF_F_TSO | NETIF_F_TSO_ECN |
580 NETIF_F_TSO6 | NETIF_F_GSO_GRE |
581 NETIF_F_GSO_UDP_TUNNEL | NETIF_F_RXCSUM |
582 NETIF_F_GSO_UDP_TUNNEL_CSUM |
583 NETIF_F_GSO_GRE_CSUM;
584
585 ndev->vlan_features = hw_features | NETIF_F_RXHASH | NETIF_F_RXCSUM |
586 NETIF_F_HIGHDMA;
587 ndev->features = hw_features | NETIF_F_RXHASH | NETIF_F_RXCSUM |
588 NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HIGHDMA |
589 NETIF_F_HW_VLAN_CTAG_FILTER | NETIF_F_HW_VLAN_CTAG_TX;
590
591 ndev->hw_features = hw_features;
592
593 /* MTU range: 46 - 9600 */
594 ndev->min_mtu = ETH_ZLEN - ETH_HLEN;
595 ndev->max_mtu = QEDE_MAX_JUMBO_PACKET_SIZE;
596
597 /* Set network device HW mac */
598 ether_addr_copy(edev->ndev->dev_addr, edev->dev_info.common.hw_mac);
599
600 ndev->mtu = edev->dev_info.common.mtu;
601 }
602
603 /* This function converts from 32b param to two params of level and module
604 * Input 32b decoding:
605 * b31 - enable all NOTICE prints. NOTICE prints are for deviation from the
606 * 'happy' flow, e.g. memory allocation failed.
607 * b30 - enable all INFO prints. INFO prints are for major steps in the flow
608 * and provide important parameters.
609 * b29-b0 - per-module bitmap, where each bit enables VERBOSE prints of that
610 * module. VERBOSE prints are for tracking the specific flow in low level.
611 *
612 * Notice that the level should be that of the lowest required logs.
613 */
614 void qede_config_debug(uint debug, u32 *p_dp_module, u8 *p_dp_level)
615 {
616 *p_dp_level = QED_LEVEL_NOTICE;
617 *p_dp_module = 0;
618
619 if (debug & QED_LOG_VERBOSE_MASK) {
620 *p_dp_level = QED_LEVEL_VERBOSE;
621 *p_dp_module = (debug & 0x3FFFFFFF);
622 } else if (debug & QED_LOG_INFO_MASK) {
623 *p_dp_level = QED_LEVEL_INFO;
624 } else if (debug & QED_LOG_NOTICE_MASK) {
625 *p_dp_level = QED_LEVEL_NOTICE;
626 }
627 }
628
629 static void qede_free_fp_array(struct qede_dev *edev)
630 {
631 if (edev->fp_array) {
632 struct qede_fastpath *fp;
633 int i;
634
635 for_each_queue(i) {
636 fp = &edev->fp_array[i];
637
638 kfree(fp->sb_info);
639 kfree(fp->rxq);
640 kfree(fp->xdp_tx);
641 kfree(fp->txq);
642 }
643 kfree(edev->fp_array);
644 }
645
646 edev->num_queues = 0;
647 edev->fp_num_tx = 0;
648 edev->fp_num_rx = 0;
649 }
650
651 static int qede_alloc_fp_array(struct qede_dev *edev)
652 {
653 u8 fp_combined, fp_rx = edev->fp_num_rx;
654 struct qede_fastpath *fp;
655 int i;
656
657 edev->fp_array = kcalloc(QEDE_QUEUE_CNT(edev),
658 sizeof(*edev->fp_array), GFP_KERNEL);
659 if (!edev->fp_array) {
660 DP_NOTICE(edev, "fp array allocation failed\n");
661 goto err;
662 }
663
664 fp_combined = QEDE_QUEUE_CNT(edev) - fp_rx - edev->fp_num_tx;
665
666 /* Allocate the FP elements for Rx queues followed by combined and then
667 * the Tx. This ordering should be maintained so that the respective
668 * queues (Rx or Tx) will be together in the fastpath array and the
669 * associated ids will be sequential.
670 */
671 for_each_queue(i) {
672 fp = &edev->fp_array[i];
673
674 fp->sb_info = kzalloc(sizeof(*fp->sb_info), GFP_KERNEL);
675 if (!fp->sb_info) {
676 DP_NOTICE(edev, "sb info struct allocation failed\n");
677 goto err;
678 }
679
680 if (fp_rx) {
681 fp->type = QEDE_FASTPATH_RX;
682 fp_rx--;
683 } else if (fp_combined) {
684 fp->type = QEDE_FASTPATH_COMBINED;
685 fp_combined--;
686 } else {
687 fp->type = QEDE_FASTPATH_TX;
688 }
689
690 if (fp->type & QEDE_FASTPATH_TX) {
691 fp->txq = kzalloc(sizeof(*fp->txq), GFP_KERNEL);
692 if (!fp->txq)
693 goto err;
694 }
695
696 if (fp->type & QEDE_FASTPATH_RX) {
697 fp->rxq = kzalloc(sizeof(*fp->rxq), GFP_KERNEL);
698 if (!fp->rxq)
699 goto err;
700
701 if (edev->xdp_prog) {
702 fp->xdp_tx = kzalloc(sizeof(*fp->xdp_tx),
703 GFP_KERNEL);
704 if (!fp->xdp_tx)
705 goto err;
706 fp->type |= QEDE_FASTPATH_XDP;
707 }
708 }
709 }
710
711 return 0;
712 err:
713 qede_free_fp_array(edev);
714 return -ENOMEM;
715 }
716
717 static void qede_sp_task(struct work_struct *work)
718 {
719 struct qede_dev *edev = container_of(work, struct qede_dev,
720 sp_task.work);
721 struct qed_dev *cdev = edev->cdev;
722
723 __qede_lock(edev);
724
725 if (test_and_clear_bit(QEDE_SP_RX_MODE, &edev->sp_flags))
726 if (edev->state == QEDE_STATE_OPEN)
727 qede_config_rx_mode(edev->ndev);
728
729 if (test_and_clear_bit(QEDE_SP_VXLAN_PORT_CONFIG, &edev->sp_flags)) {
730 struct qed_tunn_params tunn_params;
731
732 memset(&tunn_params, 0, sizeof(tunn_params));
733 tunn_params.update_vxlan_port = 1;
734 tunn_params.vxlan_port = edev->vxlan_dst_port;
735 qed_ops->tunn_config(cdev, &tunn_params);
736 }
737
738 if (test_and_clear_bit(QEDE_SP_GENEVE_PORT_CONFIG, &edev->sp_flags)) {
739 struct qed_tunn_params tunn_params;
740
741 memset(&tunn_params, 0, sizeof(tunn_params));
742 tunn_params.update_geneve_port = 1;
743 tunn_params.geneve_port = edev->geneve_dst_port;
744 qed_ops->tunn_config(cdev, &tunn_params);
745 }
746
747 __qede_unlock(edev);
748 }
749
750 static void qede_update_pf_params(struct qed_dev *cdev)
751 {
752 struct qed_pf_params pf_params;
753
754 /* 64 rx + 64 tx + 64 XDP */
755 memset(&pf_params, 0, sizeof(struct qed_pf_params));
756 pf_params.eth_pf_params.num_cons = 192;
757 qed_ops->common->update_pf_params(cdev, &pf_params);
758 }
759
760 enum qede_probe_mode {
761 QEDE_PROBE_NORMAL,
762 };
763
764 static int __qede_probe(struct pci_dev *pdev, u32 dp_module, u8 dp_level,
765 bool is_vf, enum qede_probe_mode mode)
766 {
767 struct qed_probe_params probe_params;
768 struct qed_slowpath_params sp_params;
769 struct qed_dev_eth_info dev_info;
770 struct qede_dev *edev;
771 struct qed_dev *cdev;
772 int rc;
773
774 if (unlikely(dp_level & QED_LEVEL_INFO))
775 pr_notice("Starting qede probe\n");
776
777 memset(&probe_params, 0, sizeof(probe_params));
778 probe_params.protocol = QED_PROTOCOL_ETH;
779 probe_params.dp_module = dp_module;
780 probe_params.dp_level = dp_level;
781 probe_params.is_vf = is_vf;
782 cdev = qed_ops->common->probe(pdev, &probe_params);
783 if (!cdev) {
784 rc = -ENODEV;
785 goto err0;
786 }
787
788 qede_update_pf_params(cdev);
789
790 /* Start the Slowpath-process */
791 memset(&sp_params, 0, sizeof(sp_params));
792 sp_params.int_mode = QED_INT_MODE_MSIX;
793 sp_params.drv_major = QEDE_MAJOR_VERSION;
794 sp_params.drv_minor = QEDE_MINOR_VERSION;
795 sp_params.drv_rev = QEDE_REVISION_VERSION;
796 sp_params.drv_eng = QEDE_ENGINEERING_VERSION;
797 strlcpy(sp_params.name, "qede LAN", QED_DRV_VER_STR_SIZE);
798 rc = qed_ops->common->slowpath_start(cdev, &sp_params);
799 if (rc) {
800 pr_notice("Cannot start slowpath\n");
801 goto err1;
802 }
803
804 /* Learn information crucial for qede to progress */
805 rc = qed_ops->fill_dev_info(cdev, &dev_info);
806 if (rc)
807 goto err2;
808
809 edev = qede_alloc_etherdev(cdev, pdev, &dev_info, dp_module,
810 dp_level);
811 if (!edev) {
812 rc = -ENOMEM;
813 goto err2;
814 }
815
816 if (is_vf)
817 edev->flags |= QEDE_FLAG_IS_VF;
818
819 qede_init_ndev(edev);
820
821 rc = qede_roce_dev_add(edev);
822 if (rc)
823 goto err3;
824
825 rc = register_netdev(edev->ndev);
826 if (rc) {
827 DP_NOTICE(edev, "Cannot register net-device\n");
828 goto err4;
829 }
830
831 edev->ops->common->set_id(cdev, edev->ndev->name, DRV_MODULE_VERSION);
832
833 edev->ops->register_ops(cdev, &qede_ll_ops, edev);
834
835 #ifdef CONFIG_DCB
836 if (!IS_VF(edev))
837 qede_set_dcbnl_ops(edev->ndev);
838 #endif
839
840 INIT_DELAYED_WORK(&edev->sp_task, qede_sp_task);
841 mutex_init(&edev->qede_lock);
842 edev->rx_copybreak = QEDE_RX_HDR_SIZE;
843
844 DP_INFO(edev, "Ending successfully qede probe\n");
845
846 return 0;
847
848 err4:
849 qede_roce_dev_remove(edev);
850 err3:
851 free_netdev(edev->ndev);
852 err2:
853 qed_ops->common->slowpath_stop(cdev);
854 err1:
855 qed_ops->common->remove(cdev);
856 err0:
857 return rc;
858 }
859
860 static int qede_probe(struct pci_dev *pdev, const struct pci_device_id *id)
861 {
862 bool is_vf = false;
863 u32 dp_module = 0;
864 u8 dp_level = 0;
865
866 switch ((enum qede_pci_private)id->driver_data) {
867 case QEDE_PRIVATE_VF:
868 if (debug & QED_LOG_VERBOSE_MASK)
869 dev_err(&pdev->dev, "Probing a VF\n");
870 is_vf = true;
871 break;
872 default:
873 if (debug & QED_LOG_VERBOSE_MASK)
874 dev_err(&pdev->dev, "Probing a PF\n");
875 }
876
877 qede_config_debug(debug, &dp_module, &dp_level);
878
879 return __qede_probe(pdev, dp_module, dp_level, is_vf,
880 QEDE_PROBE_NORMAL);
881 }
882
883 enum qede_remove_mode {
884 QEDE_REMOVE_NORMAL,
885 };
886
887 static void __qede_remove(struct pci_dev *pdev, enum qede_remove_mode mode)
888 {
889 struct net_device *ndev = pci_get_drvdata(pdev);
890 struct qede_dev *edev = netdev_priv(ndev);
891 struct qed_dev *cdev = edev->cdev;
892
893 DP_INFO(edev, "Starting qede_remove\n");
894
895 cancel_delayed_work_sync(&edev->sp_task);
896
897 unregister_netdev(ndev);
898
899 qede_roce_dev_remove(edev);
900
901 edev->ops->common->set_power_state(cdev, PCI_D0);
902
903 pci_set_drvdata(pdev, NULL);
904
905 /* Release edev's reference to XDP's bpf if such exist */
906 if (edev->xdp_prog)
907 bpf_prog_put(edev->xdp_prog);
908
909 free_netdev(ndev);
910
911 /* Use global ops since we've freed edev */
912 qed_ops->common->slowpath_stop(cdev);
913 if (system_state == SYSTEM_POWER_OFF)
914 return;
915 qed_ops->common->remove(cdev);
916
917 dev_info(&pdev->dev, "Ending qede_remove successfully\n");
918 }
919
920 static void qede_remove(struct pci_dev *pdev)
921 {
922 __qede_remove(pdev, QEDE_REMOVE_NORMAL);
923 }
924
925 static void qede_shutdown(struct pci_dev *pdev)
926 {
927 __qede_remove(pdev, QEDE_REMOVE_NORMAL);
928 }
929
930 /* -------------------------------------------------------------------------
931 * START OF LOAD / UNLOAD
932 * -------------------------------------------------------------------------
933 */
934
935 static int qede_set_num_queues(struct qede_dev *edev)
936 {
937 int rc;
938 u16 rss_num;
939
940 /* Setup queues according to possible resources*/
941 if (edev->req_queues)
942 rss_num = edev->req_queues;
943 else
944 rss_num = netif_get_num_default_rss_queues() *
945 edev->dev_info.common.num_hwfns;
946
947 rss_num = min_t(u16, QEDE_MAX_RSS_CNT(edev), rss_num);
948
949 rc = edev->ops->common->set_fp_int(edev->cdev, rss_num);
950 if (rc > 0) {
951 /* Managed to request interrupts for our queues */
952 edev->num_queues = rc;
953 DP_INFO(edev, "Managed %d [of %d] RSS queues\n",
954 QEDE_QUEUE_CNT(edev), rss_num);
955 rc = 0;
956 }
957
958 edev->fp_num_tx = edev->req_num_tx;
959 edev->fp_num_rx = edev->req_num_rx;
960
961 return rc;
962 }
963
964 static void qede_free_mem_sb(struct qede_dev *edev,
965 struct qed_sb_info *sb_info)
966 {
967 if (sb_info->sb_virt)
968 dma_free_coherent(&edev->pdev->dev, sizeof(*sb_info->sb_virt),
969 (void *)sb_info->sb_virt, sb_info->sb_phys);
970 }
971
972 /* This function allocates fast-path status block memory */
973 static int qede_alloc_mem_sb(struct qede_dev *edev,
974 struct qed_sb_info *sb_info, u16 sb_id)
975 {
976 struct status_block *sb_virt;
977 dma_addr_t sb_phys;
978 int rc;
979
980 sb_virt = dma_alloc_coherent(&edev->pdev->dev,
981 sizeof(*sb_virt), &sb_phys, GFP_KERNEL);
982 if (!sb_virt) {
983 DP_ERR(edev, "Status block allocation failed\n");
984 return -ENOMEM;
985 }
986
987 rc = edev->ops->common->sb_init(edev->cdev, sb_info,
988 sb_virt, sb_phys, sb_id,
989 QED_SB_TYPE_L2_QUEUE);
990 if (rc) {
991 DP_ERR(edev, "Status block initialization failed\n");
992 dma_free_coherent(&edev->pdev->dev, sizeof(*sb_virt),
993 sb_virt, sb_phys);
994 return rc;
995 }
996
997 return 0;
998 }
999
1000 static void qede_free_rx_buffers(struct qede_dev *edev,
1001 struct qede_rx_queue *rxq)
1002 {
1003 u16 i;
1004
1005 for (i = rxq->sw_rx_cons; i != rxq->sw_rx_prod; i++) {
1006 struct sw_rx_data *rx_buf;
1007 struct page *data;
1008
1009 rx_buf = &rxq->sw_rx_ring[i & NUM_RX_BDS_MAX];
1010 data = rx_buf->data;
1011
1012 dma_unmap_page(&edev->pdev->dev,
1013 rx_buf->mapping, PAGE_SIZE, rxq->data_direction);
1014
1015 rx_buf->data = NULL;
1016 __free_page(data);
1017 }
1018 }
1019
1020 static void qede_free_sge_mem(struct qede_dev *edev, struct qede_rx_queue *rxq)
1021 {
1022 int i;
1023
1024 if (edev->gro_disable)
1025 return;
1026
1027 for (i = 0; i < ETH_TPA_MAX_AGGS_NUM; i++) {
1028 struct qede_agg_info *tpa_info = &rxq->tpa_info[i];
1029 struct sw_rx_data *replace_buf = &tpa_info->buffer;
1030
1031 if (replace_buf->data) {
1032 dma_unmap_page(&edev->pdev->dev,
1033 replace_buf->mapping,
1034 PAGE_SIZE, DMA_FROM_DEVICE);
1035 __free_page(replace_buf->data);
1036 }
1037 }
1038 }
1039
1040 static void qede_free_mem_rxq(struct qede_dev *edev, struct qede_rx_queue *rxq)
1041 {
1042 qede_free_sge_mem(edev, rxq);
1043
1044 /* Free rx buffers */
1045 qede_free_rx_buffers(edev, rxq);
1046
1047 /* Free the parallel SW ring */
1048 kfree(rxq->sw_rx_ring);
1049
1050 /* Free the real RQ ring used by FW */
1051 edev->ops->common->chain_free(edev->cdev, &rxq->rx_bd_ring);
1052 edev->ops->common->chain_free(edev->cdev, &rxq->rx_comp_ring);
1053 }
1054
1055 static int qede_alloc_sge_mem(struct qede_dev *edev, struct qede_rx_queue *rxq)
1056 {
1057 dma_addr_t mapping;
1058 int i;
1059
1060 /* Don't perform FW aggregations in case of XDP */
1061 if (edev->xdp_prog)
1062 edev->gro_disable = 1;
1063
1064 if (edev->gro_disable)
1065 return 0;
1066
1067 if (edev->ndev->mtu > PAGE_SIZE) {
1068 edev->gro_disable = 1;
1069 return 0;
1070 }
1071
1072 for (i = 0; i < ETH_TPA_MAX_AGGS_NUM; i++) {
1073 struct qede_agg_info *tpa_info = &rxq->tpa_info[i];
1074 struct sw_rx_data *replace_buf = &tpa_info->buffer;
1075
1076 replace_buf->data = alloc_pages(GFP_ATOMIC, 0);
1077 if (unlikely(!replace_buf->data)) {
1078 DP_NOTICE(edev,
1079 "Failed to allocate TPA skb pool [replacement buffer]\n");
1080 goto err;
1081 }
1082
1083 mapping = dma_map_page(&edev->pdev->dev, replace_buf->data, 0,
1084 PAGE_SIZE, DMA_FROM_DEVICE);
1085 if (unlikely(dma_mapping_error(&edev->pdev->dev, mapping))) {
1086 DP_NOTICE(edev,
1087 "Failed to map TPA replacement buffer\n");
1088 goto err;
1089 }
1090
1091 replace_buf->mapping = mapping;
1092 tpa_info->buffer.page_offset = 0;
1093 tpa_info->buffer_mapping = mapping;
1094 tpa_info->state = QEDE_AGG_STATE_NONE;
1095 }
1096
1097 return 0;
1098 err:
1099 qede_free_sge_mem(edev, rxq);
1100 edev->gro_disable = 1;
1101 return -ENOMEM;
1102 }
1103
1104 /* This function allocates all memory needed per Rx queue */
1105 static int qede_alloc_mem_rxq(struct qede_dev *edev, struct qede_rx_queue *rxq)
1106 {
1107 int i, rc, size;
1108
1109 rxq->num_rx_buffers = edev->q_num_rx_buffers;
1110
1111 rxq->rx_buf_size = NET_IP_ALIGN + ETH_OVERHEAD + edev->ndev->mtu;
1112
1113 if (rxq->rx_buf_size > PAGE_SIZE)
1114 rxq->rx_buf_size = PAGE_SIZE;
1115
1116 /* Segment size to spilt a page in multiple equal parts,
1117 * unless XDP is used in which case we'd use the entire page.
1118 */
1119 if (!edev->xdp_prog)
1120 rxq->rx_buf_seg_size = roundup_pow_of_two(rxq->rx_buf_size);
1121 else
1122 rxq->rx_buf_seg_size = PAGE_SIZE;
1123
1124 /* Allocate the parallel driver ring for Rx buffers */
1125 size = sizeof(*rxq->sw_rx_ring) * RX_RING_SIZE;
1126 rxq->sw_rx_ring = kzalloc(size, GFP_KERNEL);
1127 if (!rxq->sw_rx_ring) {
1128 DP_ERR(edev, "Rx buffers ring allocation failed\n");
1129 rc = -ENOMEM;
1130 goto err;
1131 }
1132
1133 /* Allocate FW Rx ring */
1134 rc = edev->ops->common->chain_alloc(edev->cdev,
1135 QED_CHAIN_USE_TO_CONSUME_PRODUCE,
1136 QED_CHAIN_MODE_NEXT_PTR,
1137 QED_CHAIN_CNT_TYPE_U16,
1138 RX_RING_SIZE,
1139 sizeof(struct eth_rx_bd),
1140 &rxq->rx_bd_ring);
1141
1142 if (rc)
1143 goto err;
1144
1145 /* Allocate FW completion ring */
1146 rc = edev->ops->common->chain_alloc(edev->cdev,
1147 QED_CHAIN_USE_TO_CONSUME,
1148 QED_CHAIN_MODE_PBL,
1149 QED_CHAIN_CNT_TYPE_U16,
1150 RX_RING_SIZE,
1151 sizeof(union eth_rx_cqe),
1152 &rxq->rx_comp_ring);
1153 if (rc)
1154 goto err;
1155
1156 /* Allocate buffers for the Rx ring */
1157 for (i = 0; i < rxq->num_rx_buffers; i++) {
1158 rc = qede_alloc_rx_buffer(rxq);
1159 if (rc) {
1160 DP_ERR(edev,
1161 "Rx buffers allocation failed at index %d\n", i);
1162 goto err;
1163 }
1164 }
1165
1166 rc = qede_alloc_sge_mem(edev, rxq);
1167 err:
1168 return rc;
1169 }
1170
1171 static void qede_free_mem_txq(struct qede_dev *edev, struct qede_tx_queue *txq)
1172 {
1173 /* Free the parallel SW ring */
1174 if (txq->is_xdp)
1175 kfree(txq->sw_tx_ring.pages);
1176 else
1177 kfree(txq->sw_tx_ring.skbs);
1178
1179 /* Free the real RQ ring used by FW */
1180 edev->ops->common->chain_free(edev->cdev, &txq->tx_pbl);
1181 }
1182
1183 /* This function allocates all memory needed per Tx queue */
1184 static int qede_alloc_mem_txq(struct qede_dev *edev, struct qede_tx_queue *txq)
1185 {
1186 union eth_tx_bd_types *p_virt;
1187 int size, rc;
1188
1189 txq->num_tx_buffers = edev->q_num_tx_buffers;
1190
1191 /* Allocate the parallel driver ring for Tx buffers */
1192 if (txq->is_xdp) {
1193 size = sizeof(*txq->sw_tx_ring.pages) * TX_RING_SIZE;
1194 txq->sw_tx_ring.pages = kzalloc(size, GFP_KERNEL);
1195 if (!txq->sw_tx_ring.pages)
1196 goto err;
1197 } else {
1198 size = sizeof(*txq->sw_tx_ring.skbs) * TX_RING_SIZE;
1199 txq->sw_tx_ring.skbs = kzalloc(size, GFP_KERNEL);
1200 if (!txq->sw_tx_ring.skbs)
1201 goto err;
1202 }
1203
1204 rc = edev->ops->common->chain_alloc(edev->cdev,
1205 QED_CHAIN_USE_TO_CONSUME_PRODUCE,
1206 QED_CHAIN_MODE_PBL,
1207 QED_CHAIN_CNT_TYPE_U16,
1208 TX_RING_SIZE,
1209 sizeof(*p_virt), &txq->tx_pbl);
1210 if (rc)
1211 goto err;
1212
1213 return 0;
1214
1215 err:
1216 qede_free_mem_txq(edev, txq);
1217 return -ENOMEM;
1218 }
1219
1220 /* This function frees all memory of a single fp */
1221 static void qede_free_mem_fp(struct qede_dev *edev, struct qede_fastpath *fp)
1222 {
1223 qede_free_mem_sb(edev, fp->sb_info);
1224
1225 if (fp->type & QEDE_FASTPATH_RX)
1226 qede_free_mem_rxq(edev, fp->rxq);
1227
1228 if (fp->type & QEDE_FASTPATH_TX)
1229 qede_free_mem_txq(edev, fp->txq);
1230 }
1231
1232 /* This function allocates all memory needed for a single fp (i.e. an entity
1233 * which contains status block, one rx queue and/or multiple per-TC tx queues.
1234 */
1235 static int qede_alloc_mem_fp(struct qede_dev *edev, struct qede_fastpath *fp)
1236 {
1237 int rc = 0;
1238
1239 rc = qede_alloc_mem_sb(edev, fp->sb_info, fp->id);
1240 if (rc)
1241 goto out;
1242
1243 if (fp->type & QEDE_FASTPATH_RX) {
1244 rc = qede_alloc_mem_rxq(edev, fp->rxq);
1245 if (rc)
1246 goto out;
1247 }
1248
1249 if (fp->type & QEDE_FASTPATH_XDP) {
1250 rc = qede_alloc_mem_txq(edev, fp->xdp_tx);
1251 if (rc)
1252 goto out;
1253 }
1254
1255 if (fp->type & QEDE_FASTPATH_TX) {
1256 rc = qede_alloc_mem_txq(edev, fp->txq);
1257 if (rc)
1258 goto out;
1259 }
1260
1261 out:
1262 return rc;
1263 }
1264
1265 static void qede_free_mem_load(struct qede_dev *edev)
1266 {
1267 int i;
1268
1269 for_each_queue(i) {
1270 struct qede_fastpath *fp = &edev->fp_array[i];
1271
1272 qede_free_mem_fp(edev, fp);
1273 }
1274 }
1275
1276 /* This function allocates all qede memory at NIC load. */
1277 static int qede_alloc_mem_load(struct qede_dev *edev)
1278 {
1279 int rc = 0, queue_id;
1280
1281 for (queue_id = 0; queue_id < QEDE_QUEUE_CNT(edev); queue_id++) {
1282 struct qede_fastpath *fp = &edev->fp_array[queue_id];
1283
1284 rc = qede_alloc_mem_fp(edev, fp);
1285 if (rc) {
1286 DP_ERR(edev,
1287 "Failed to allocate memory for fastpath - rss id = %d\n",
1288 queue_id);
1289 qede_free_mem_load(edev);
1290 return rc;
1291 }
1292 }
1293
1294 return 0;
1295 }
1296
1297 /* This function inits fp content and resets the SB, RXQ and TXQ structures */
1298 static void qede_init_fp(struct qede_dev *edev)
1299 {
1300 int queue_id, rxq_index = 0, txq_index = 0;
1301 struct qede_fastpath *fp;
1302
1303 for_each_queue(queue_id) {
1304 fp = &edev->fp_array[queue_id];
1305
1306 fp->edev = edev;
1307 fp->id = queue_id;
1308
1309 if (fp->type & QEDE_FASTPATH_XDP) {
1310 fp->xdp_tx->index = QEDE_TXQ_IDX_TO_XDP(edev,
1311 rxq_index);
1312 fp->xdp_tx->is_xdp = 1;
1313 }
1314
1315 if (fp->type & QEDE_FASTPATH_RX) {
1316 fp->rxq->rxq_id = rxq_index++;
1317
1318 /* Determine how to map buffers for this queue */
1319 if (fp->type & QEDE_FASTPATH_XDP)
1320 fp->rxq->data_direction = DMA_BIDIRECTIONAL;
1321 else
1322 fp->rxq->data_direction = DMA_FROM_DEVICE;
1323 fp->rxq->dev = &edev->pdev->dev;
1324 }
1325
1326 if (fp->type & QEDE_FASTPATH_TX) {
1327 fp->txq->index = txq_index++;
1328 if (edev->dev_info.is_legacy)
1329 fp->txq->is_legacy = 1;
1330 fp->txq->dev = &edev->pdev->dev;
1331 }
1332
1333 snprintf(fp->name, sizeof(fp->name), "%s-fp-%d",
1334 edev->ndev->name, queue_id);
1335 }
1336
1337 edev->gro_disable = !(edev->ndev->features & NETIF_F_GRO);
1338 }
1339
1340 static int qede_set_real_num_queues(struct qede_dev *edev)
1341 {
1342 int rc = 0;
1343
1344 rc = netif_set_real_num_tx_queues(edev->ndev, QEDE_TSS_COUNT(edev));
1345 if (rc) {
1346 DP_NOTICE(edev, "Failed to set real number of Tx queues\n");
1347 return rc;
1348 }
1349
1350 rc = netif_set_real_num_rx_queues(edev->ndev, QEDE_RSS_COUNT(edev));
1351 if (rc) {
1352 DP_NOTICE(edev, "Failed to set real number of Rx queues\n");
1353 return rc;
1354 }
1355
1356 return 0;
1357 }
1358
1359 static void qede_napi_disable_remove(struct qede_dev *edev)
1360 {
1361 int i;
1362
1363 for_each_queue(i) {
1364 napi_disable(&edev->fp_array[i].napi);
1365
1366 netif_napi_del(&edev->fp_array[i].napi);
1367 }
1368 }
1369
1370 static void qede_napi_add_enable(struct qede_dev *edev)
1371 {
1372 int i;
1373
1374 /* Add NAPI objects */
1375 for_each_queue(i) {
1376 netif_napi_add(edev->ndev, &edev->fp_array[i].napi,
1377 qede_poll, NAPI_POLL_WEIGHT);
1378 napi_enable(&edev->fp_array[i].napi);
1379 }
1380 }
1381
1382 static void qede_sync_free_irqs(struct qede_dev *edev)
1383 {
1384 int i;
1385
1386 for (i = 0; i < edev->int_info.used_cnt; i++) {
1387 if (edev->int_info.msix_cnt) {
1388 synchronize_irq(edev->int_info.msix[i].vector);
1389 free_irq(edev->int_info.msix[i].vector,
1390 &edev->fp_array[i]);
1391 } else {
1392 edev->ops->common->simd_handler_clean(edev->cdev, i);
1393 }
1394 }
1395
1396 edev->int_info.used_cnt = 0;
1397 }
1398
1399 static int qede_req_msix_irqs(struct qede_dev *edev)
1400 {
1401 int i, rc;
1402
1403 /* Sanitize number of interrupts == number of prepared RSS queues */
1404 if (QEDE_QUEUE_CNT(edev) > edev->int_info.msix_cnt) {
1405 DP_ERR(edev,
1406 "Interrupt mismatch: %d RSS queues > %d MSI-x vectors\n",
1407 QEDE_QUEUE_CNT(edev), edev->int_info.msix_cnt);
1408 return -EINVAL;
1409 }
1410
1411 for (i = 0; i < QEDE_QUEUE_CNT(edev); i++) {
1412 rc = request_irq(edev->int_info.msix[i].vector,
1413 qede_msix_fp_int, 0, edev->fp_array[i].name,
1414 &edev->fp_array[i]);
1415 if (rc) {
1416 DP_ERR(edev, "Request fp %d irq failed\n", i);
1417 qede_sync_free_irqs(edev);
1418 return rc;
1419 }
1420 DP_VERBOSE(edev, NETIF_MSG_INTR,
1421 "Requested fp irq for %s [entry %d]. Cookie is at %p\n",
1422 edev->fp_array[i].name, i,
1423 &edev->fp_array[i]);
1424 edev->int_info.used_cnt++;
1425 }
1426
1427 return 0;
1428 }
1429
1430 static void qede_simd_fp_handler(void *cookie)
1431 {
1432 struct qede_fastpath *fp = (struct qede_fastpath *)cookie;
1433
1434 napi_schedule_irqoff(&fp->napi);
1435 }
1436
1437 static int qede_setup_irqs(struct qede_dev *edev)
1438 {
1439 int i, rc = 0;
1440
1441 /* Learn Interrupt configuration */
1442 rc = edev->ops->common->get_fp_int(edev->cdev, &edev->int_info);
1443 if (rc)
1444 return rc;
1445
1446 if (edev->int_info.msix_cnt) {
1447 rc = qede_req_msix_irqs(edev);
1448 if (rc)
1449 return rc;
1450 edev->ndev->irq = edev->int_info.msix[0].vector;
1451 } else {
1452 const struct qed_common_ops *ops;
1453
1454 /* qed should learn receive the RSS ids and callbacks */
1455 ops = edev->ops->common;
1456 for (i = 0; i < QEDE_QUEUE_CNT(edev); i++)
1457 ops->simd_handler_config(edev->cdev,
1458 &edev->fp_array[i], i,
1459 qede_simd_fp_handler);
1460 edev->int_info.used_cnt = QEDE_QUEUE_CNT(edev);
1461 }
1462 return 0;
1463 }
1464
1465 static int qede_drain_txq(struct qede_dev *edev,
1466 struct qede_tx_queue *txq, bool allow_drain)
1467 {
1468 int rc, cnt = 1000;
1469
1470 while (txq->sw_tx_cons != txq->sw_tx_prod) {
1471 if (!cnt) {
1472 if (allow_drain) {
1473 DP_NOTICE(edev,
1474 "Tx queue[%d] is stuck, requesting MCP to drain\n",
1475 txq->index);
1476 rc = edev->ops->common->drain(edev->cdev);
1477 if (rc)
1478 return rc;
1479 return qede_drain_txq(edev, txq, false);
1480 }
1481 DP_NOTICE(edev,
1482 "Timeout waiting for tx queue[%d]: PROD=%d, CONS=%d\n",
1483 txq->index, txq->sw_tx_prod,
1484 txq->sw_tx_cons);
1485 return -ENODEV;
1486 }
1487 cnt--;
1488 usleep_range(1000, 2000);
1489 barrier();
1490 }
1491
1492 /* FW finished processing, wait for HW to transmit all tx packets */
1493 usleep_range(1000, 2000);
1494
1495 return 0;
1496 }
1497
1498 static int qede_stop_txq(struct qede_dev *edev,
1499 struct qede_tx_queue *txq, int rss_id)
1500 {
1501 return edev->ops->q_tx_stop(edev->cdev, rss_id, txq->handle);
1502 }
1503
1504 static int qede_stop_queues(struct qede_dev *edev)
1505 {
1506 struct qed_update_vport_params vport_update_params;
1507 struct qed_dev *cdev = edev->cdev;
1508 struct qede_fastpath *fp;
1509 int rc, i;
1510
1511 /* Disable the vport */
1512 memset(&vport_update_params, 0, sizeof(vport_update_params));
1513 vport_update_params.vport_id = 0;
1514 vport_update_params.update_vport_active_flg = 1;
1515 vport_update_params.vport_active_flg = 0;
1516 vport_update_params.update_rss_flg = 0;
1517
1518 rc = edev->ops->vport_update(cdev, &vport_update_params);
1519 if (rc) {
1520 DP_ERR(edev, "Failed to update vport\n");
1521 return rc;
1522 }
1523
1524 /* Flush Tx queues. If needed, request drain from MCP */
1525 for_each_queue(i) {
1526 fp = &edev->fp_array[i];
1527
1528 if (fp->type & QEDE_FASTPATH_TX) {
1529 rc = qede_drain_txq(edev, fp->txq, true);
1530 if (rc)
1531 return rc;
1532 }
1533
1534 if (fp->type & QEDE_FASTPATH_XDP) {
1535 rc = qede_drain_txq(edev, fp->xdp_tx, true);
1536 if (rc)
1537 return rc;
1538 }
1539 }
1540
1541 /* Stop all Queues in reverse order */
1542 for (i = QEDE_QUEUE_CNT(edev) - 1; i >= 0; i--) {
1543 fp = &edev->fp_array[i];
1544
1545 /* Stop the Tx Queue(s) */
1546 if (fp->type & QEDE_FASTPATH_TX) {
1547 rc = qede_stop_txq(edev, fp->txq, i);
1548 if (rc)
1549 return rc;
1550 }
1551
1552 /* Stop the Rx Queue */
1553 if (fp->type & QEDE_FASTPATH_RX) {
1554 rc = edev->ops->q_rx_stop(cdev, i, fp->rxq->handle);
1555 if (rc) {
1556 DP_ERR(edev, "Failed to stop RXQ #%d\n", i);
1557 return rc;
1558 }
1559 }
1560
1561 /* Stop the XDP forwarding queue */
1562 if (fp->type & QEDE_FASTPATH_XDP) {
1563 rc = qede_stop_txq(edev, fp->xdp_tx, i);
1564 if (rc)
1565 return rc;
1566
1567 bpf_prog_put(fp->rxq->xdp_prog);
1568 }
1569 }
1570
1571 /* Stop the vport */
1572 rc = edev->ops->vport_stop(cdev, 0);
1573 if (rc)
1574 DP_ERR(edev, "Failed to stop VPORT\n");
1575
1576 return rc;
1577 }
1578
1579 static int qede_start_txq(struct qede_dev *edev,
1580 struct qede_fastpath *fp,
1581 struct qede_tx_queue *txq, u8 rss_id, u16 sb_idx)
1582 {
1583 dma_addr_t phys_table = qed_chain_get_pbl_phys(&txq->tx_pbl);
1584 u32 page_cnt = qed_chain_get_page_cnt(&txq->tx_pbl);
1585 struct qed_queue_start_common_params params;
1586 struct qed_txq_start_ret_params ret_params;
1587 int rc;
1588
1589 memset(&params, 0, sizeof(params));
1590 memset(&ret_params, 0, sizeof(ret_params));
1591
1592 /* Let the XDP queue share the queue-zone with one of the regular txq.
1593 * We don't really care about its coalescing.
1594 */
1595 if (txq->is_xdp)
1596 params.queue_id = QEDE_TXQ_XDP_TO_IDX(edev, txq);
1597 else
1598 params.queue_id = txq->index;
1599
1600 params.sb = fp->sb_info->igu_sb_id;
1601 params.sb_idx = sb_idx;
1602
1603 rc = edev->ops->q_tx_start(edev->cdev, rss_id, &params, phys_table,
1604 page_cnt, &ret_params);
1605 if (rc) {
1606 DP_ERR(edev, "Start TXQ #%d failed %d\n", txq->index, rc);
1607 return rc;
1608 }
1609
1610 txq->doorbell_addr = ret_params.p_doorbell;
1611 txq->handle = ret_params.p_handle;
1612
1613 /* Determine the FW consumer address associated */
1614 txq->hw_cons_ptr = &fp->sb_info->sb_virt->pi_array[sb_idx];
1615
1616 /* Prepare the doorbell parameters */
1617 SET_FIELD(txq->tx_db.data.params, ETH_DB_DATA_DEST, DB_DEST_XCM);
1618 SET_FIELD(txq->tx_db.data.params, ETH_DB_DATA_AGG_CMD, DB_AGG_CMD_SET);
1619 SET_FIELD(txq->tx_db.data.params, ETH_DB_DATA_AGG_VAL_SEL,
1620 DQ_XCM_ETH_TX_BD_PROD_CMD);
1621 txq->tx_db.data.agg_flags = DQ_XCM_ETH_DQ_CF_CMD;
1622
1623 return rc;
1624 }
1625
1626 static int qede_start_queues(struct qede_dev *edev, bool clear_stats)
1627 {
1628 int vlan_removal_en = 1;
1629 struct qed_dev *cdev = edev->cdev;
1630 struct qed_update_vport_params vport_update_params;
1631 struct qed_queue_start_common_params q_params;
1632 struct qed_dev_info *qed_info = &edev->dev_info.common;
1633 struct qed_start_vport_params start = {0};
1634 bool reset_rss_indir = false;
1635 int rc, i;
1636
1637 if (!edev->num_queues) {
1638 DP_ERR(edev,
1639 "Cannot update V-VPORT as active as there are no Rx queues\n");
1640 return -EINVAL;
1641 }
1642
1643 start.gro_enable = !edev->gro_disable;
1644 start.mtu = edev->ndev->mtu;
1645 start.vport_id = 0;
1646 start.drop_ttl0 = true;
1647 start.remove_inner_vlan = vlan_removal_en;
1648 start.clear_stats = clear_stats;
1649
1650 rc = edev->ops->vport_start(cdev, &start);
1651
1652 if (rc) {
1653 DP_ERR(edev, "Start V-PORT failed %d\n", rc);
1654 return rc;
1655 }
1656
1657 DP_VERBOSE(edev, NETIF_MSG_IFUP,
1658 "Start vport ramrod passed, vport_id = %d, MTU = %d, vlan_removal_en = %d\n",
1659 start.vport_id, edev->ndev->mtu + 0xe, vlan_removal_en);
1660
1661 for_each_queue(i) {
1662 struct qede_fastpath *fp = &edev->fp_array[i];
1663 dma_addr_t p_phys_table;
1664 u32 page_cnt;
1665
1666 if (fp->type & QEDE_FASTPATH_RX) {
1667 struct qed_rxq_start_ret_params ret_params;
1668 struct qede_rx_queue *rxq = fp->rxq;
1669 __le16 *val;
1670
1671 memset(&ret_params, 0, sizeof(ret_params));
1672 memset(&q_params, 0, sizeof(q_params));
1673 q_params.queue_id = rxq->rxq_id;
1674 q_params.vport_id = 0;
1675 q_params.sb = fp->sb_info->igu_sb_id;
1676 q_params.sb_idx = RX_PI;
1677
1678 p_phys_table =
1679 qed_chain_get_pbl_phys(&rxq->rx_comp_ring);
1680 page_cnt = qed_chain_get_page_cnt(&rxq->rx_comp_ring);
1681
1682 rc = edev->ops->q_rx_start(cdev, i, &q_params,
1683 rxq->rx_buf_size,
1684 rxq->rx_bd_ring.p_phys_addr,
1685 p_phys_table,
1686 page_cnt, &ret_params);
1687 if (rc) {
1688 DP_ERR(edev, "Start RXQ #%d failed %d\n", i,
1689 rc);
1690 return rc;
1691 }
1692
1693 /* Use the return parameters */
1694 rxq->hw_rxq_prod_addr = ret_params.p_prod;
1695 rxq->handle = ret_params.p_handle;
1696
1697 val = &fp->sb_info->sb_virt->pi_array[RX_PI];
1698 rxq->hw_cons_ptr = val;
1699
1700 qede_update_rx_prod(edev, rxq);
1701 }
1702
1703 if (fp->type & QEDE_FASTPATH_XDP) {
1704 rc = qede_start_txq(edev, fp, fp->xdp_tx, i, XDP_PI);
1705 if (rc)
1706 return rc;
1707
1708 fp->rxq->xdp_prog = bpf_prog_add(edev->xdp_prog, 1);
1709 if (IS_ERR(fp->rxq->xdp_prog)) {
1710 rc = PTR_ERR(fp->rxq->xdp_prog);
1711 fp->rxq->xdp_prog = NULL;
1712 return rc;
1713 }
1714 }
1715
1716 if (fp->type & QEDE_FASTPATH_TX) {
1717 rc = qede_start_txq(edev, fp, fp->txq, i, TX_PI(0));
1718 if (rc)
1719 return rc;
1720 }
1721 }
1722
1723 /* Prepare and send the vport enable */
1724 memset(&vport_update_params, 0, sizeof(vport_update_params));
1725 vport_update_params.vport_id = start.vport_id;
1726 vport_update_params.update_vport_active_flg = 1;
1727 vport_update_params.vport_active_flg = 1;
1728
1729 if ((qed_info->mf_mode == QED_MF_NPAR || pci_num_vf(edev->pdev)) &&
1730 qed_info->tx_switching) {
1731 vport_update_params.update_tx_switching_flg = 1;
1732 vport_update_params.tx_switching_flg = 1;
1733 }
1734
1735 /* Fill struct with RSS params */
1736 if (QEDE_RSS_COUNT(edev) > 1) {
1737 vport_update_params.update_rss_flg = 1;
1738
1739 /* Need to validate current RSS config uses valid entries */
1740 for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++) {
1741 if (edev->rss_params.rss_ind_table[i] >=
1742 QEDE_RSS_COUNT(edev)) {
1743 reset_rss_indir = true;
1744 break;
1745 }
1746 }
1747
1748 if (!(edev->rss_params_inited & QEDE_RSS_INDIR_INITED) ||
1749 reset_rss_indir) {
1750 u16 val;
1751
1752 for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++) {
1753 u16 indir_val;
1754
1755 val = QEDE_RSS_COUNT(edev);
1756 indir_val = ethtool_rxfh_indir_default(i, val);
1757 edev->rss_params.rss_ind_table[i] = indir_val;
1758 }
1759 edev->rss_params_inited |= QEDE_RSS_INDIR_INITED;
1760 }
1761
1762 if (!(edev->rss_params_inited & QEDE_RSS_KEY_INITED)) {
1763 netdev_rss_key_fill(edev->rss_params.rss_key,
1764 sizeof(edev->rss_params.rss_key));
1765 edev->rss_params_inited |= QEDE_RSS_KEY_INITED;
1766 }
1767
1768 if (!(edev->rss_params_inited & QEDE_RSS_CAPS_INITED)) {
1769 edev->rss_params.rss_caps = QED_RSS_IPV4 |
1770 QED_RSS_IPV6 |
1771 QED_RSS_IPV4_TCP |
1772 QED_RSS_IPV6_TCP;
1773 edev->rss_params_inited |= QEDE_RSS_CAPS_INITED;
1774 }
1775
1776 memcpy(&vport_update_params.rss_params, &edev->rss_params,
1777 sizeof(vport_update_params.rss_params));
1778 } else {
1779 memset(&vport_update_params.rss_params, 0,
1780 sizeof(vport_update_params.rss_params));
1781 }
1782
1783 rc = edev->ops->vport_update(cdev, &vport_update_params);
1784 if (rc) {
1785 DP_ERR(edev, "Update V-PORT failed %d\n", rc);
1786 return rc;
1787 }
1788
1789 return 0;
1790 }
1791
1792
1793 enum qede_unload_mode {
1794 QEDE_UNLOAD_NORMAL,
1795 };
1796
1797 static void qede_unload(struct qede_dev *edev, enum qede_unload_mode mode,
1798 bool is_locked)
1799 {
1800 struct qed_link_params link_params;
1801 int rc;
1802
1803 DP_INFO(edev, "Starting qede unload\n");
1804
1805 if (!is_locked)
1806 __qede_lock(edev);
1807
1808 qede_roce_dev_event_close(edev);
1809 edev->state = QEDE_STATE_CLOSED;
1810
1811 /* Close OS Tx */
1812 netif_tx_disable(edev->ndev);
1813 netif_carrier_off(edev->ndev);
1814
1815 /* Reset the link */
1816 memset(&link_params, 0, sizeof(link_params));
1817 link_params.link_up = false;
1818 edev->ops->common->set_link(edev->cdev, &link_params);
1819 rc = qede_stop_queues(edev);
1820 if (rc) {
1821 qede_sync_free_irqs(edev);
1822 goto out;
1823 }
1824
1825 DP_INFO(edev, "Stopped Queues\n");
1826
1827 qede_vlan_mark_nonconfigured(edev);
1828 edev->ops->fastpath_stop(edev->cdev);
1829
1830 /* Release the interrupts */
1831 qede_sync_free_irqs(edev);
1832 edev->ops->common->set_fp_int(edev->cdev, 0);
1833
1834 qede_napi_disable_remove(edev);
1835
1836 qede_free_mem_load(edev);
1837 qede_free_fp_array(edev);
1838
1839 out:
1840 if (!is_locked)
1841 __qede_unlock(edev);
1842 DP_INFO(edev, "Ending qede unload\n");
1843 }
1844
1845 enum qede_load_mode {
1846 QEDE_LOAD_NORMAL,
1847 QEDE_LOAD_RELOAD,
1848 };
1849
1850 static int qede_load(struct qede_dev *edev, enum qede_load_mode mode,
1851 bool is_locked)
1852 {
1853 struct qed_link_params link_params;
1854 struct qed_link_output link_output;
1855 int rc;
1856
1857 DP_INFO(edev, "Starting qede load\n");
1858
1859 if (!is_locked)
1860 __qede_lock(edev);
1861
1862 rc = qede_set_num_queues(edev);
1863 if (rc)
1864 goto out;
1865
1866 rc = qede_alloc_fp_array(edev);
1867 if (rc)
1868 goto out;
1869
1870 qede_init_fp(edev);
1871
1872 rc = qede_alloc_mem_load(edev);
1873 if (rc)
1874 goto err1;
1875 DP_INFO(edev, "Allocated %d Rx, %d Tx queues\n",
1876 QEDE_RSS_COUNT(edev), QEDE_TSS_COUNT(edev));
1877
1878 rc = qede_set_real_num_queues(edev);
1879 if (rc)
1880 goto err2;
1881
1882 qede_napi_add_enable(edev);
1883 DP_INFO(edev, "Napi added and enabled\n");
1884
1885 rc = qede_setup_irqs(edev);
1886 if (rc)
1887 goto err3;
1888 DP_INFO(edev, "Setup IRQs succeeded\n");
1889
1890 rc = qede_start_queues(edev, mode != QEDE_LOAD_RELOAD);
1891 if (rc)
1892 goto err4;
1893 DP_INFO(edev, "Start VPORT, RXQ and TXQ succeeded\n");
1894
1895 /* Add primary mac and set Rx filters */
1896 ether_addr_copy(edev->primary_mac, edev->ndev->dev_addr);
1897
1898 /* Program un-configured VLANs */
1899 qede_configure_vlan_filters(edev);
1900
1901 /* Ask for link-up using current configuration */
1902 memset(&link_params, 0, sizeof(link_params));
1903 link_params.link_up = true;
1904 edev->ops->common->set_link(edev->cdev, &link_params);
1905
1906 /* Query whether link is already-up */
1907 memset(&link_output, 0, sizeof(link_output));
1908 edev->ops->common->get_link(edev->cdev, &link_output);
1909 qede_roce_dev_event_open(edev);
1910 qede_link_update(edev, &link_output);
1911
1912 edev->state = QEDE_STATE_OPEN;
1913
1914 DP_INFO(edev, "Ending successfully qede load\n");
1915
1916
1917 goto out;
1918 err4:
1919 qede_sync_free_irqs(edev);
1920 memset(&edev->int_info.msix_cnt, 0, sizeof(struct qed_int_info));
1921 err3:
1922 qede_napi_disable_remove(edev);
1923 err2:
1924 qede_free_mem_load(edev);
1925 err1:
1926 edev->ops->common->set_fp_int(edev->cdev, 0);
1927 qede_free_fp_array(edev);
1928 edev->num_queues = 0;
1929 edev->fp_num_tx = 0;
1930 edev->fp_num_rx = 0;
1931 out:
1932 if (!is_locked)
1933 __qede_unlock(edev);
1934
1935 return rc;
1936 }
1937
1938 /* 'func' should be able to run between unload and reload assuming interface
1939 * is actually running, or afterwards in case it's currently DOWN.
1940 */
1941 void qede_reload(struct qede_dev *edev,
1942 struct qede_reload_args *args, bool is_locked)
1943 {
1944 if (!is_locked)
1945 __qede_lock(edev);
1946
1947 /* Since qede_lock is held, internal state wouldn't change even
1948 * if netdev state would start transitioning. Check whether current
1949 * internal configuration indicates device is up, then reload.
1950 */
1951 if (edev->state == QEDE_STATE_OPEN) {
1952 qede_unload(edev, QEDE_UNLOAD_NORMAL, true);
1953 if (args)
1954 args->func(edev, args);
1955 qede_load(edev, QEDE_LOAD_RELOAD, true);
1956
1957 /* Since no one is going to do it for us, re-configure */
1958 qede_config_rx_mode(edev->ndev);
1959 } else if (args) {
1960 args->func(edev, args);
1961 }
1962
1963 if (!is_locked)
1964 __qede_unlock(edev);
1965 }
1966
1967 /* called with rtnl_lock */
1968 static int qede_open(struct net_device *ndev)
1969 {
1970 struct qede_dev *edev = netdev_priv(ndev);
1971 int rc;
1972
1973 netif_carrier_off(ndev);
1974
1975 edev->ops->common->set_power_state(edev->cdev, PCI_D0);
1976
1977 rc = qede_load(edev, QEDE_LOAD_NORMAL, false);
1978 if (rc)
1979 return rc;
1980
1981 udp_tunnel_get_rx_info(ndev);
1982
1983 edev->ops->common->update_drv_state(edev->cdev, true);
1984
1985 return 0;
1986 }
1987
1988 static int qede_close(struct net_device *ndev)
1989 {
1990 struct qede_dev *edev = netdev_priv(ndev);
1991
1992 qede_unload(edev, QEDE_UNLOAD_NORMAL, false);
1993
1994 edev->ops->common->update_drv_state(edev->cdev, false);
1995
1996 return 0;
1997 }
1998
1999 static void qede_link_update(void *dev, struct qed_link_output *link)
2000 {
2001 struct qede_dev *edev = dev;
2002
2003 if (!netif_running(edev->ndev)) {
2004 DP_VERBOSE(edev, NETIF_MSG_LINK, "Interface is not running\n");
2005 return;
2006 }
2007
2008 if (link->link_up) {
2009 if (!netif_carrier_ok(edev->ndev)) {
2010 DP_NOTICE(edev, "Link is up\n");
2011 netif_tx_start_all_queues(edev->ndev);
2012 netif_carrier_on(edev->ndev);
2013 }
2014 } else {
2015 if (netif_carrier_ok(edev->ndev)) {
2016 DP_NOTICE(edev, "Link is down\n");
2017 netif_tx_disable(edev->ndev);
2018 netif_carrier_off(edev->ndev);
2019 }
2020 }
2021 }