blob: 88d47d6f35ac9bf15691625f8caa16937f13e11f [file] [log] [blame]
Yuval Mintze712d522015-10-26 11:02:27 +02001/* QLogic qede NIC Driver
Mintz, Yuvale8f1cb52017-01-01 13:57:00 +02002 * 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 */
Yuval Mintze712d522015-10-26 11:02:27 +020032#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>
Alexander Duyckf9f082a2016-06-16 12:22:57 -070050#include <net/udp_tunnel.h>
Yuval Mintze712d522015-10-26 11:02:27 +020051#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>
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +020062#include <linux/vmalloc.h>
Ram Amranicee9fbd2016-10-01 21:59:56 +030063#include <linux/qed/qede_roce.h>
Yuval Mintze712d522015-10-26 11:02:27 +020064#include "qede.h"
65
Yuval Mintz5abd7e922016-02-24 16:52:50 +020066static char version[] =
67 "QLogic FastLinQ 4xxxx Ethernet Driver qede " DRV_MODULE_VERSION "\n";
Yuval Mintze712d522015-10-26 11:02:27 +020068
Yuval Mintz5abd7e922016-02-24 16:52:50 +020069MODULE_DESCRIPTION("QLogic FastLinQ 4xxxx Ethernet Driver");
Yuval Mintze712d522015-10-26 11:02:27 +020070MODULE_LICENSE("GPL");
71MODULE_VERSION(DRV_MODULE_VERSION);
72
73static uint debug;
74module_param(debug, uint, 0);
75MODULE_PARM_DESC(debug, " Default debug msglevel");
76
77static const struct qed_eth_ops *qed_ops;
78
79#define CHIP_NUM_57980S_40 0x1634
Yuval Mintz0e7441d2016-02-24 16:52:45 +020080#define CHIP_NUM_57980S_10 0x1666
Yuval Mintze712d522015-10-26 11:02:27 +020081#define CHIP_NUM_57980S_MF 0x1636
82#define CHIP_NUM_57980S_100 0x1644
83#define CHIP_NUM_57980S_50 0x1654
84#define CHIP_NUM_57980S_25 0x1656
Yuval Mintzfefb0202016-05-11 16:36:19 +030085#define CHIP_NUM_57980S_IOV 0x1664
Yuval Mintze712d522015-10-26 11:02:27 +020086
87#ifndef PCI_DEVICE_ID_NX2_57980E
88#define PCI_DEVICE_ID_57980S_40 CHIP_NUM_57980S_40
89#define PCI_DEVICE_ID_57980S_10 CHIP_NUM_57980S_10
90#define PCI_DEVICE_ID_57980S_MF CHIP_NUM_57980S_MF
91#define PCI_DEVICE_ID_57980S_100 CHIP_NUM_57980S_100
92#define PCI_DEVICE_ID_57980S_50 CHIP_NUM_57980S_50
93#define PCI_DEVICE_ID_57980S_25 CHIP_NUM_57980S_25
Yuval Mintzfefb0202016-05-11 16:36:19 +030094#define PCI_DEVICE_ID_57980S_IOV CHIP_NUM_57980S_IOV
Yuval Mintze712d522015-10-26 11:02:27 +020095#endif
96
Yuval Mintzfefb0202016-05-11 16:36:19 +030097enum qede_pci_private {
98 QEDE_PRIVATE_PF,
99 QEDE_PRIVATE_VF
100};
101
Yuval Mintze712d522015-10-26 11:02:27 +0200102static const struct pci_device_id qede_pci_tbl[] = {
Yuval Mintzfefb0202016-05-11 16:36:19 +0300103 {PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_57980S_40), QEDE_PRIVATE_PF},
104 {PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_57980S_10), QEDE_PRIVATE_PF},
105 {PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_57980S_MF), QEDE_PRIVATE_PF},
106 {PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_57980S_100), QEDE_PRIVATE_PF},
107 {PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_57980S_50), QEDE_PRIVATE_PF},
108 {PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_57980S_25), QEDE_PRIVATE_PF},
Arnd Bergmann14b84e82016-06-01 15:29:13 +0200109#ifdef CONFIG_QED_SRIOV
Yuval Mintzfefb0202016-05-11 16:36:19 +0300110 {PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_57980S_IOV), QEDE_PRIVATE_VF},
Arnd Bergmann14b84e82016-06-01 15:29:13 +0200111#endif
Yuval Mintze712d522015-10-26 11:02:27 +0200112 { 0 }
113};
114
115MODULE_DEVICE_TABLE(pci, qede_pci_tbl);
116
117static int qede_probe(struct pci_dev *pdev, const struct pci_device_id *id);
118
119#define TX_TIMEOUT (5 * HZ)
120
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +0200121/* Utilize last protocol index for XDP */
122#define XDP_PI 11
123
Yuval Mintze712d522015-10-26 11:02:27 +0200124static void qede_remove(struct pci_dev *pdev);
Mintz, Yuval14d39642016-10-31 07:14:23 +0200125static void qede_shutdown(struct pci_dev *pdev);
Sudarsana Kallurua2ec6172015-10-26 11:02:32 +0200126static void qede_link_update(void *dev, struct qed_link_output *link);
Yuval Mintze712d522015-10-26 11:02:27 +0200127
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200128/* The qede lock is used to protect driver state change and driver flows that
129 * are not reentrant.
130 */
131void __qede_lock(struct qede_dev *edev)
132{
133 mutex_lock(&edev->qede_lock);
134}
135
136void __qede_unlock(struct qede_dev *edev)
137{
138 mutex_unlock(&edev->qede_lock);
139}
140
Yuval Mintzfefb0202016-05-11 16:36:19 +0300141#ifdef CONFIG_QED_SRIOV
Moshe Shemesh79aab092016-09-22 12:11:15 +0300142static int qede_set_vf_vlan(struct net_device *ndev, int vf, u16 vlan, u8 qos,
143 __be16 vlan_proto)
Yuval Mintz08feecd2016-05-11 16:36:20 +0300144{
145 struct qede_dev *edev = netdev_priv(ndev);
146
147 if (vlan > 4095) {
148 DP_NOTICE(edev, "Illegal vlan value %d\n", vlan);
149 return -EINVAL;
150 }
151
Moshe Shemesh79aab092016-09-22 12:11:15 +0300152 if (vlan_proto != htons(ETH_P_8021Q))
153 return -EPROTONOSUPPORT;
154
Yuval Mintz08feecd2016-05-11 16:36:20 +0300155 DP_VERBOSE(edev, QED_MSG_IOV, "Setting Vlan 0x%04x to VF [%d]\n",
156 vlan, vf);
157
158 return edev->ops->iov->set_vlan(edev->cdev, vlan, vf);
159}
160
Yuval Mintzeff16962016-05-11 16:36:21 +0300161static int qede_set_vf_mac(struct net_device *ndev, int vfidx, u8 *mac)
162{
163 struct qede_dev *edev = netdev_priv(ndev);
164
165 DP_VERBOSE(edev, QED_MSG_IOV,
166 "Setting MAC %02x:%02x:%02x:%02x:%02x:%02x to VF [%d]\n",
167 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], vfidx);
168
169 if (!is_valid_ether_addr(mac)) {
170 DP_VERBOSE(edev, QED_MSG_IOV, "MAC address isn't valid\n");
171 return -EINVAL;
172 }
173
174 return edev->ops->iov->set_mac(edev->cdev, mac, vfidx);
175}
176
Yuval Mintzfefb0202016-05-11 16:36:19 +0300177static int qede_sriov_configure(struct pci_dev *pdev, int num_vfs_param)
178{
179 struct qede_dev *edev = netdev_priv(pci_get_drvdata(pdev));
Yuval Mintz831bfb0e2016-05-11 16:36:25 +0300180 struct qed_dev_info *qed_info = &edev->dev_info.common;
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +0200181 struct qed_update_vport_params *vport_params;
Yuval Mintz831bfb0e2016-05-11 16:36:25 +0300182 int rc;
Yuval Mintzfefb0202016-05-11 16:36:19 +0300183
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +0200184 vport_params = vzalloc(sizeof(*vport_params));
185 if (!vport_params)
186 return -ENOMEM;
Yuval Mintzfefb0202016-05-11 16:36:19 +0300187 DP_VERBOSE(edev, QED_MSG_IOV, "Requested %d VFs\n", num_vfs_param);
188
Yuval Mintz831bfb0e2016-05-11 16:36:25 +0300189 rc = edev->ops->iov->configure(edev->cdev, num_vfs_param);
190
191 /* Enable/Disable Tx switching for PF */
192 if ((rc == num_vfs_param) && netif_running(edev->ndev) &&
193 qed_info->mf_mode != QED_MF_NPAR && qed_info->tx_switching) {
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +0200194 vport_params->vport_id = 0;
195 vport_params->update_tx_switching_flg = 1;
196 vport_params->tx_switching_flg = num_vfs_param ? 1 : 0;
197 edev->ops->vport_update(edev->cdev, vport_params);
Yuval Mintz831bfb0e2016-05-11 16:36:25 +0300198 }
199
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +0200200 vfree(vport_params);
Yuval Mintz831bfb0e2016-05-11 16:36:25 +0300201 return rc;
Yuval Mintzfefb0202016-05-11 16:36:19 +0300202}
203#endif
204
Yuval Mintze712d522015-10-26 11:02:27 +0200205static struct pci_driver qede_pci_driver = {
206 .name = "qede",
207 .id_table = qede_pci_tbl,
208 .probe = qede_probe,
209 .remove = qede_remove,
Mintz, Yuval14d39642016-10-31 07:14:23 +0200210 .shutdown = qede_shutdown,
Yuval Mintzfefb0202016-05-11 16:36:19 +0300211#ifdef CONFIG_QED_SRIOV
212 .sriov_configure = qede_sriov_configure,
213#endif
Yuval Mintze712d522015-10-26 11:02:27 +0200214};
215
Sudarsana Kallurua2ec6172015-10-26 11:02:32 +0200216static struct qed_eth_cb_ops qede_ll_ops = {
217 {
218 .link_update = qede_link_update,
219 },
Yuval Mintzeff16962016-05-11 16:36:21 +0300220 .force_mac = qede_force_mac,
Sudarsana Kallurua2ec6172015-10-26 11:02:32 +0200221};
222
Yuval Mintz29502192015-10-26 11:02:29 +0200223static int qede_netdev_event(struct notifier_block *this, unsigned long event,
224 void *ptr)
225{
226 struct net_device *ndev = netdev_notifier_info_to_dev(ptr);
227 struct ethtool_drvinfo drvinfo;
228 struct qede_dev *edev;
229
Ram Amranicee9fbd2016-10-01 21:59:56 +0300230 if (event != NETDEV_CHANGENAME && event != NETDEV_CHANGEADDR)
Yuval Mintz29502192015-10-26 11:02:29 +0200231 goto done;
232
233 /* Check whether this is a qede device */
234 if (!ndev || !ndev->ethtool_ops || !ndev->ethtool_ops->get_drvinfo)
235 goto done;
236
237 memset(&drvinfo, 0, sizeof(drvinfo));
238 ndev->ethtool_ops->get_drvinfo(ndev, &drvinfo);
239 if (strcmp(drvinfo.driver, "qede"))
240 goto done;
241 edev = netdev_priv(ndev);
242
Ram Amranicee9fbd2016-10-01 21:59:56 +0300243 switch (event) {
244 case NETDEV_CHANGENAME:
245 /* Notify qed of the name change */
246 if (!edev->ops || !edev->ops->common)
247 goto done;
248 edev->ops->common->set_id(edev->cdev, edev->ndev->name, "qede");
249 break;
250 case NETDEV_CHANGEADDR:
251 edev = netdev_priv(ndev);
252 qede_roce_event_changeaddr(edev);
253 break;
254 }
Yuval Mintz29502192015-10-26 11:02:29 +0200255
256done:
257 return NOTIFY_DONE;
258}
259
260static struct notifier_block qede_netdev_notifier = {
261 .notifier_call = qede_netdev_event,
262};
263
Yuval Mintze712d522015-10-26 11:02:27 +0200264static
265int __init qede_init(void)
266{
267 int ret;
Yuval Mintze712d522015-10-26 11:02:27 +0200268
Yuval Mintz525ef5c2016-08-15 10:42:45 +0300269 pr_info("qede_init: %s\n", version);
Yuval Mintze712d522015-10-26 11:02:27 +0200270
Rahul Verma95114342016-04-10 12:42:59 +0300271 qed_ops = qed_get_eth_ops();
Yuval Mintze712d522015-10-26 11:02:27 +0200272 if (!qed_ops) {
273 pr_notice("Failed to get qed ethtool operations\n");
274 return -EINVAL;
275 }
276
Yuval Mintz29502192015-10-26 11:02:29 +0200277 /* Must register notifier before pci ops, since we might miss
278 * interface rename after pci probe and netdev registeration.
279 */
280 ret = register_netdevice_notifier(&qede_netdev_notifier);
281 if (ret) {
282 pr_notice("Failed to register netdevice_notifier\n");
283 qed_put_eth_ops();
284 return -EINVAL;
285 }
286
Yuval Mintze712d522015-10-26 11:02:27 +0200287 ret = pci_register_driver(&qede_pci_driver);
288 if (ret) {
289 pr_notice("Failed to register driver\n");
Yuval Mintz29502192015-10-26 11:02:29 +0200290 unregister_netdevice_notifier(&qede_netdev_notifier);
Yuval Mintze712d522015-10-26 11:02:27 +0200291 qed_put_eth_ops();
292 return -EINVAL;
293 }
294
295 return 0;
296}
297
298static void __exit qede_cleanup(void)
299{
Yuval Mintz525ef5c2016-08-15 10:42:45 +0300300 if (debug & QED_LOG_INFO_MASK)
301 pr_info("qede_cleanup called\n");
Yuval Mintze712d522015-10-26 11:02:27 +0200302
Yuval Mintz29502192015-10-26 11:02:29 +0200303 unregister_netdevice_notifier(&qede_netdev_notifier);
Yuval Mintze712d522015-10-26 11:02:27 +0200304 pci_unregister_driver(&qede_pci_driver);
305 qed_put_eth_ops();
306}
307
308module_init(qede_init);
309module_exit(qede_cleanup);
310
Yuval Mintz29502192015-10-26 11:02:29 +0200311static int qede_open(struct net_device *ndev);
312static int qede_close(struct net_device *ndev);
Sudarsana Reddy Kalluru7c1bfca2016-02-18 17:00:40 +0200313
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200314void qede_fill_by_demand_stats(struct qede_dev *edev)
315{
316 struct qed_eth_stats stats;
317
318 edev->ops->get_vport_stats(edev->cdev, &stats);
319 edev->stats.no_buff_discards = stats.no_buff_discards;
Sudarsana Reddy Kalluru1a5a3662016-08-16 10:51:01 -0400320 edev->stats.packet_too_big_discard = stats.packet_too_big_discard;
321 edev->stats.ttl0_discard = stats.ttl0_discard;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200322 edev->stats.rx_ucast_bytes = stats.rx_ucast_bytes;
323 edev->stats.rx_mcast_bytes = stats.rx_mcast_bytes;
324 edev->stats.rx_bcast_bytes = stats.rx_bcast_bytes;
325 edev->stats.rx_ucast_pkts = stats.rx_ucast_pkts;
326 edev->stats.rx_mcast_pkts = stats.rx_mcast_pkts;
327 edev->stats.rx_bcast_pkts = stats.rx_bcast_pkts;
328 edev->stats.mftag_filter_discards = stats.mftag_filter_discards;
329 edev->stats.mac_filter_discards = stats.mac_filter_discards;
330
331 edev->stats.tx_ucast_bytes = stats.tx_ucast_bytes;
332 edev->stats.tx_mcast_bytes = stats.tx_mcast_bytes;
333 edev->stats.tx_bcast_bytes = stats.tx_bcast_bytes;
334 edev->stats.tx_ucast_pkts = stats.tx_ucast_pkts;
335 edev->stats.tx_mcast_pkts = stats.tx_mcast_pkts;
336 edev->stats.tx_bcast_pkts = stats.tx_bcast_pkts;
337 edev->stats.tx_err_drop_pkts = stats.tx_err_drop_pkts;
338 edev->stats.coalesced_pkts = stats.tpa_coalesced_pkts;
339 edev->stats.coalesced_events = stats.tpa_coalesced_events;
340 edev->stats.coalesced_aborts_num = stats.tpa_aborts_num;
341 edev->stats.non_coalesced_pkts = stats.tpa_not_coalesced_pkts;
342 edev->stats.coalesced_bytes = stats.tpa_coalesced_bytes;
343
344 edev->stats.rx_64_byte_packets = stats.rx_64_byte_packets;
Yuval Mintzd4967cf2016-04-22 08:41:01 +0300345 edev->stats.rx_65_to_127_byte_packets = stats.rx_65_to_127_byte_packets;
346 edev->stats.rx_128_to_255_byte_packets =
347 stats.rx_128_to_255_byte_packets;
348 edev->stats.rx_256_to_511_byte_packets =
349 stats.rx_256_to_511_byte_packets;
350 edev->stats.rx_512_to_1023_byte_packets =
351 stats.rx_512_to_1023_byte_packets;
352 edev->stats.rx_1024_to_1518_byte_packets =
353 stats.rx_1024_to_1518_byte_packets;
354 edev->stats.rx_1519_to_1522_byte_packets =
355 stats.rx_1519_to_1522_byte_packets;
356 edev->stats.rx_1519_to_2047_byte_packets =
357 stats.rx_1519_to_2047_byte_packets;
358 edev->stats.rx_2048_to_4095_byte_packets =
359 stats.rx_2048_to_4095_byte_packets;
360 edev->stats.rx_4096_to_9216_byte_packets =
361 stats.rx_4096_to_9216_byte_packets;
362 edev->stats.rx_9217_to_16383_byte_packets =
363 stats.rx_9217_to_16383_byte_packets;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200364 edev->stats.rx_crc_errors = stats.rx_crc_errors;
365 edev->stats.rx_mac_crtl_frames = stats.rx_mac_crtl_frames;
366 edev->stats.rx_pause_frames = stats.rx_pause_frames;
367 edev->stats.rx_pfc_frames = stats.rx_pfc_frames;
368 edev->stats.rx_align_errors = stats.rx_align_errors;
369 edev->stats.rx_carrier_errors = stats.rx_carrier_errors;
370 edev->stats.rx_oversize_packets = stats.rx_oversize_packets;
371 edev->stats.rx_jabbers = stats.rx_jabbers;
372 edev->stats.rx_undersize_packets = stats.rx_undersize_packets;
373 edev->stats.rx_fragments = stats.rx_fragments;
374 edev->stats.tx_64_byte_packets = stats.tx_64_byte_packets;
375 edev->stats.tx_65_to_127_byte_packets = stats.tx_65_to_127_byte_packets;
376 edev->stats.tx_128_to_255_byte_packets =
377 stats.tx_128_to_255_byte_packets;
378 edev->stats.tx_256_to_511_byte_packets =
379 stats.tx_256_to_511_byte_packets;
380 edev->stats.tx_512_to_1023_byte_packets =
381 stats.tx_512_to_1023_byte_packets;
382 edev->stats.tx_1024_to_1518_byte_packets =
383 stats.tx_1024_to_1518_byte_packets;
384 edev->stats.tx_1519_to_2047_byte_packets =
385 stats.tx_1519_to_2047_byte_packets;
386 edev->stats.tx_2048_to_4095_byte_packets =
387 stats.tx_2048_to_4095_byte_packets;
388 edev->stats.tx_4096_to_9216_byte_packets =
389 stats.tx_4096_to_9216_byte_packets;
390 edev->stats.tx_9217_to_16383_byte_packets =
391 stats.tx_9217_to_16383_byte_packets;
392 edev->stats.tx_pause_frames = stats.tx_pause_frames;
393 edev->stats.tx_pfc_frames = stats.tx_pfc_frames;
394 edev->stats.tx_lpi_entry_count = stats.tx_lpi_entry_count;
395 edev->stats.tx_total_collisions = stats.tx_total_collisions;
396 edev->stats.brb_truncates = stats.brb_truncates;
397 edev->stats.brb_discards = stats.brb_discards;
398 edev->stats.tx_mac_ctrl_frames = stats.tx_mac_ctrl_frames;
399}
400
Yuval Mintz1a635e42016-08-15 10:42:43 +0300401static
402struct rtnl_link_stats64 *qede_get_stats64(struct net_device *dev,
403 struct rtnl_link_stats64 *stats)
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200404{
405 struct qede_dev *edev = netdev_priv(dev);
406
407 qede_fill_by_demand_stats(edev);
408
409 stats->rx_packets = edev->stats.rx_ucast_pkts +
410 edev->stats.rx_mcast_pkts +
411 edev->stats.rx_bcast_pkts;
412 stats->tx_packets = edev->stats.tx_ucast_pkts +
413 edev->stats.tx_mcast_pkts +
414 edev->stats.tx_bcast_pkts;
415
416 stats->rx_bytes = edev->stats.rx_ucast_bytes +
417 edev->stats.rx_mcast_bytes +
418 edev->stats.rx_bcast_bytes;
419
420 stats->tx_bytes = edev->stats.tx_ucast_bytes +
421 edev->stats.tx_mcast_bytes +
422 edev->stats.tx_bcast_bytes;
423
424 stats->tx_errors = edev->stats.tx_err_drop_pkts;
425 stats->multicast = edev->stats.rx_mcast_pkts +
426 edev->stats.rx_bcast_pkts;
427
428 stats->rx_fifo_errors = edev->stats.no_buff_discards;
429
430 stats->collisions = edev->stats.tx_total_collisions;
431 stats->rx_crc_errors = edev->stats.rx_crc_errors;
432 stats->rx_frame_errors = edev->stats.rx_align_errors;
433
434 return stats;
435}
436
Yuval Mintz733def62016-05-11 16:36:22 +0300437#ifdef CONFIG_QED_SRIOV
Yuval Mintz73390ac2016-05-11 16:36:24 +0300438static int qede_get_vf_config(struct net_device *dev, int vfidx,
439 struct ifla_vf_info *ivi)
440{
441 struct qede_dev *edev = netdev_priv(dev);
442
443 if (!edev->ops)
444 return -EINVAL;
445
446 return edev->ops->iov->get_config(edev->cdev, vfidx, ivi);
447}
448
Yuval Mintz733def62016-05-11 16:36:22 +0300449static int qede_set_vf_rate(struct net_device *dev, int vfidx,
450 int min_tx_rate, int max_tx_rate)
451{
452 struct qede_dev *edev = netdev_priv(dev);
453
Yuval Mintzbe7b6d62016-05-26 11:01:17 +0300454 return edev->ops->iov->set_rate(edev->cdev, vfidx, min_tx_rate,
Yuval Mintz733def62016-05-11 16:36:22 +0300455 max_tx_rate);
456}
457
Yuval Mintz6ddc7602016-05-11 16:36:23 +0300458static int qede_set_vf_spoofchk(struct net_device *dev, int vfidx, bool val)
459{
460 struct qede_dev *edev = netdev_priv(dev);
461
462 if (!edev->ops)
463 return -EINVAL;
464
465 return edev->ops->iov->set_spoof(edev->cdev, vfidx, val);
466}
467
Yuval Mintz733def62016-05-11 16:36:22 +0300468static int qede_set_vf_link_state(struct net_device *dev, int vfidx,
469 int link_state)
470{
471 struct qede_dev *edev = netdev_priv(dev);
472
473 if (!edev->ops)
474 return -EINVAL;
475
476 return edev->ops->iov->set_link_state(edev->cdev, vfidx, link_state);
477}
478#endif
479
Yuval Mintz29502192015-10-26 11:02:29 +0200480static const struct net_device_ops qede_netdev_ops = {
481 .ndo_open = qede_open,
482 .ndo_stop = qede_close,
483 .ndo_start_xmit = qede_start_xmit,
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +0200484 .ndo_set_rx_mode = qede_set_rx_mode,
485 .ndo_set_mac_address = qede_set_mac_addr,
Yuval Mintz29502192015-10-26 11:02:29 +0200486 .ndo_validate_addr = eth_validate_addr,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200487 .ndo_change_mtu = qede_change_mtu,
Yuval Mintz08feecd2016-05-11 16:36:20 +0300488#ifdef CONFIG_QED_SRIOV
Yuval Mintzeff16962016-05-11 16:36:21 +0300489 .ndo_set_vf_mac = qede_set_vf_mac,
Yuval Mintz08feecd2016-05-11 16:36:20 +0300490 .ndo_set_vf_vlan = qede_set_vf_vlan,
491#endif
Sudarsana Reddy Kalluru7c1bfca2016-02-18 17:00:40 +0200492 .ndo_vlan_rx_add_vid = qede_vlan_rx_add_vid,
493 .ndo_vlan_rx_kill_vid = qede_vlan_rx_kill_vid,
Yuval Mintzce2b8852016-05-26 11:01:18 +0300494 .ndo_set_features = qede_set_features,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200495 .ndo_get_stats64 = qede_get_stats64,
Yuval Mintz733def62016-05-11 16:36:22 +0300496#ifdef CONFIG_QED_SRIOV
497 .ndo_set_vf_link_state = qede_set_vf_link_state,
Yuval Mintz6ddc7602016-05-11 16:36:23 +0300498 .ndo_set_vf_spoofchk = qede_set_vf_spoofchk,
Yuval Mintz73390ac2016-05-11 16:36:24 +0300499 .ndo_get_vf_config = qede_get_vf_config,
Yuval Mintz733def62016-05-11 16:36:22 +0300500 .ndo_set_vf_rate = qede_set_vf_rate,
501#endif
Alexander Duyckf9f082a2016-06-16 12:22:57 -0700502 .ndo_udp_tunnel_add = qede_udp_tunnel_add,
503 .ndo_udp_tunnel_del = qede_udp_tunnel_del,
Manish Chopra25695852016-10-14 05:19:19 -0400504 .ndo_features_check = qede_features_check,
Mintz, Yuval496e0512016-11-29 16:47:09 +0200505 .ndo_xdp = qede_xdp,
Yuval Mintz29502192015-10-26 11:02:29 +0200506};
507
508/* -------------------------------------------------------------------------
Yuval Mintze712d522015-10-26 11:02:27 +0200509 * START OF PROBE / REMOVE
510 * -------------------------------------------------------------------------
511 */
512
513static struct qede_dev *qede_alloc_etherdev(struct qed_dev *cdev,
514 struct pci_dev *pdev,
515 struct qed_dev_eth_info *info,
Yuval Mintz1a635e42016-08-15 10:42:43 +0300516 u32 dp_module, u8 dp_level)
Yuval Mintze712d522015-10-26 11:02:27 +0200517{
518 struct net_device *ndev;
519 struct qede_dev *edev;
520
521 ndev = alloc_etherdev_mqs(sizeof(*edev),
Yuval Mintz1a635e42016-08-15 10:42:43 +0300522 info->num_queues, info->num_queues);
Yuval Mintze712d522015-10-26 11:02:27 +0200523 if (!ndev) {
524 pr_err("etherdev allocation failed\n");
525 return NULL;
526 }
527
528 edev = netdev_priv(ndev);
529 edev->ndev = ndev;
530 edev->cdev = cdev;
531 edev->pdev = pdev;
532 edev->dp_module = dp_module;
533 edev->dp_level = dp_level;
534 edev->ops = qed_ops;
Yuval Mintz29502192015-10-26 11:02:29 +0200535 edev->q_num_rx_buffers = NUM_RX_BDS_DEF;
536 edev->q_num_tx_buffers = NUM_TX_BDS_DEF;
Yuval Mintze712d522015-10-26 11:02:27 +0200537
Yuval Mintz525ef5c2016-08-15 10:42:45 +0300538 DP_INFO(edev, "Allocated netdev with %d tx queues and %d rx queues\n",
539 info->num_queues, info->num_queues);
540
Yuval Mintze712d522015-10-26 11:02:27 +0200541 SET_NETDEV_DEV(ndev, &pdev->dev);
542
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200543 memset(&edev->stats, 0, sizeof(edev->stats));
Yuval Mintze712d522015-10-26 11:02:27 +0200544 memcpy(&edev->dev_info, info, sizeof(*info));
545
Sudarsana Reddy Kalluru7c1bfca2016-02-18 17:00:40 +0200546 INIT_LIST_HEAD(&edev->vlan_list);
547
Yuval Mintze712d522015-10-26 11:02:27 +0200548 return edev;
549}
550
551static void qede_init_ndev(struct qede_dev *edev)
552{
553 struct net_device *ndev = edev->ndev;
554 struct pci_dev *pdev = edev->pdev;
555 u32 hw_features;
556
557 pci_set_drvdata(pdev, ndev);
558
559 ndev->mem_start = edev->dev_info.common.pci_mem_start;
560 ndev->base_addr = ndev->mem_start;
561 ndev->mem_end = edev->dev_info.common.pci_mem_end;
562 ndev->irq = edev->dev_info.common.pci_irq;
563
564 ndev->watchdog_timeo = TX_TIMEOUT;
565
Yuval Mintz29502192015-10-26 11:02:29 +0200566 ndev->netdev_ops = &qede_netdev_ops;
567
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200568 qede_set_ethtool_ops(ndev);
569
Mintz, Yuval0183eb12016-10-31 22:26:53 +0200570 ndev->priv_flags |= IFF_UNICAST_FLT;
Yuval Mintz7b7e70f2016-10-14 05:19:20 -0400571
Yuval Mintze712d522015-10-26 11:02:27 +0200572 /* user-changeble features */
573 hw_features = NETIF_F_GRO | NETIF_F_SG |
574 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
575 NETIF_F_TSO | NETIF_F_TSO6;
576
Manish Chopra14db81d2016-04-14 01:38:33 -0400577 /* Encap features*/
578 hw_features |= NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL |
Manish Chopraa1502412016-10-14 05:19:18 -0400579 NETIF_F_TSO_ECN | NETIF_F_GSO_UDP_TUNNEL_CSUM |
580 NETIF_F_GSO_GRE_CSUM;
Manish Chopra14db81d2016-04-14 01:38:33 -0400581 ndev->hw_enc_features = NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
582 NETIF_F_SG | NETIF_F_TSO | NETIF_F_TSO_ECN |
583 NETIF_F_TSO6 | NETIF_F_GSO_GRE |
Manish Chopraa1502412016-10-14 05:19:18 -0400584 NETIF_F_GSO_UDP_TUNNEL | NETIF_F_RXCSUM |
585 NETIF_F_GSO_UDP_TUNNEL_CSUM |
586 NETIF_F_GSO_GRE_CSUM;
Manish Chopra14db81d2016-04-14 01:38:33 -0400587
Yuval Mintze712d522015-10-26 11:02:27 +0200588 ndev->vlan_features = hw_features | NETIF_F_RXHASH | NETIF_F_RXCSUM |
589 NETIF_F_HIGHDMA;
590 ndev->features = hw_features | NETIF_F_RXHASH | NETIF_F_RXCSUM |
591 NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HIGHDMA |
Sudarsana Reddy Kalluru7c1bfca2016-02-18 17:00:40 +0200592 NETIF_F_HW_VLAN_CTAG_FILTER | NETIF_F_HW_VLAN_CTAG_TX;
Yuval Mintze712d522015-10-26 11:02:27 +0200593
594 ndev->hw_features = hw_features;
595
Jarod Wilsoncaff2a82016-10-17 15:54:08 -0400596 /* MTU range: 46 - 9600 */
597 ndev->min_mtu = ETH_ZLEN - ETH_HLEN;
598 ndev->max_mtu = QEDE_MAX_JUMBO_PACKET_SIZE;
599
Yuval Mintze712d522015-10-26 11:02:27 +0200600 /* Set network device HW mac */
601 ether_addr_copy(edev->ndev->dev_addr, edev->dev_info.common.hw_mac);
Sudarsana Kalluru0fefbfb2016-10-31 07:14:21 +0200602
603 ndev->mtu = edev->dev_info.common.mtu;
Yuval Mintze712d522015-10-26 11:02:27 +0200604}
605
606/* This function converts from 32b param to two params of level and module
607 * Input 32b decoding:
608 * b31 - enable all NOTICE prints. NOTICE prints are for deviation from the
609 * 'happy' flow, e.g. memory allocation failed.
610 * b30 - enable all INFO prints. INFO prints are for major steps in the flow
611 * and provide important parameters.
612 * b29-b0 - per-module bitmap, where each bit enables VERBOSE prints of that
613 * module. VERBOSE prints are for tracking the specific flow in low level.
614 *
615 * Notice that the level should be that of the lowest required logs.
616 */
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200617void qede_config_debug(uint debug, u32 *p_dp_module, u8 *p_dp_level)
Yuval Mintze712d522015-10-26 11:02:27 +0200618{
619 *p_dp_level = QED_LEVEL_NOTICE;
620 *p_dp_module = 0;
621
622 if (debug & QED_LOG_VERBOSE_MASK) {
623 *p_dp_level = QED_LEVEL_VERBOSE;
624 *p_dp_module = (debug & 0x3FFFFFFF);
625 } else if (debug & QED_LOG_INFO_MASK) {
626 *p_dp_level = QED_LEVEL_INFO;
627 } else if (debug & QED_LOG_NOTICE_MASK) {
628 *p_dp_level = QED_LEVEL_NOTICE;
629 }
630}
631
Yuval Mintz29502192015-10-26 11:02:29 +0200632static void qede_free_fp_array(struct qede_dev *edev)
633{
634 if (edev->fp_array) {
635 struct qede_fastpath *fp;
636 int i;
637
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400638 for_each_queue(i) {
Yuval Mintz29502192015-10-26 11:02:29 +0200639 fp = &edev->fp_array[i];
640
641 kfree(fp->sb_info);
642 kfree(fp->rxq);
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +0200643 kfree(fp->xdp_tx);
Mintz, Yuval80439a12016-11-29 16:47:02 +0200644 kfree(fp->txq);
Yuval Mintz29502192015-10-26 11:02:29 +0200645 }
646 kfree(edev->fp_array);
647 }
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400648
649 edev->num_queues = 0;
650 edev->fp_num_tx = 0;
651 edev->fp_num_rx = 0;
Yuval Mintz29502192015-10-26 11:02:29 +0200652}
653
654static int qede_alloc_fp_array(struct qede_dev *edev)
655{
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400656 u8 fp_combined, fp_rx = edev->fp_num_rx;
Yuval Mintz29502192015-10-26 11:02:29 +0200657 struct qede_fastpath *fp;
658 int i;
659
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400660 edev->fp_array = kcalloc(QEDE_QUEUE_CNT(edev),
Yuval Mintz29502192015-10-26 11:02:29 +0200661 sizeof(*edev->fp_array), GFP_KERNEL);
662 if (!edev->fp_array) {
663 DP_NOTICE(edev, "fp array allocation failed\n");
664 goto err;
665 }
666
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400667 fp_combined = QEDE_QUEUE_CNT(edev) - fp_rx - edev->fp_num_tx;
668
669 /* Allocate the FP elements for Rx queues followed by combined and then
670 * the Tx. This ordering should be maintained so that the respective
671 * queues (Rx or Tx) will be together in the fastpath array and the
672 * associated ids will be sequential.
673 */
674 for_each_queue(i) {
Yuval Mintz29502192015-10-26 11:02:29 +0200675 fp = &edev->fp_array[i];
676
Mintz, Yuval80439a12016-11-29 16:47:02 +0200677 fp->sb_info = kzalloc(sizeof(*fp->sb_info), GFP_KERNEL);
Yuval Mintz29502192015-10-26 11:02:29 +0200678 if (!fp->sb_info) {
679 DP_NOTICE(edev, "sb info struct allocation failed\n");
680 goto err;
681 }
682
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400683 if (fp_rx) {
684 fp->type = QEDE_FASTPATH_RX;
685 fp_rx--;
686 } else if (fp_combined) {
687 fp->type = QEDE_FASTPATH_COMBINED;
688 fp_combined--;
689 } else {
690 fp->type = QEDE_FASTPATH_TX;
Yuval Mintz29502192015-10-26 11:02:29 +0200691 }
692
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400693 if (fp->type & QEDE_FASTPATH_TX) {
Mintz, Yuval80439a12016-11-29 16:47:02 +0200694 fp->txq = kzalloc(sizeof(*fp->txq), GFP_KERNEL);
695 if (!fp->txq)
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400696 goto err;
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400697 }
698
699 if (fp->type & QEDE_FASTPATH_RX) {
Mintz, Yuval80439a12016-11-29 16:47:02 +0200700 fp->rxq = kzalloc(sizeof(*fp->rxq), GFP_KERNEL);
701 if (!fp->rxq)
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400702 goto err;
Mintz, Yuval496e0512016-11-29 16:47:09 +0200703
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +0200704 if (edev->xdp_prog) {
705 fp->xdp_tx = kzalloc(sizeof(*fp->xdp_tx),
706 GFP_KERNEL);
707 if (!fp->xdp_tx)
708 goto err;
Mintz, Yuval496e0512016-11-29 16:47:09 +0200709 fp->type |= QEDE_FASTPATH_XDP;
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +0200710 }
Yuval Mintz29502192015-10-26 11:02:29 +0200711 }
712 }
713
714 return 0;
715err:
716 qede_free_fp_array(edev);
717 return -ENOMEM;
718}
719
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +0200720static void qede_sp_task(struct work_struct *work)
721{
722 struct qede_dev *edev = container_of(work, struct qede_dev,
723 sp_task.work);
Manish Choprab18e1702016-04-14 01:38:30 -0400724 struct qed_dev *cdev = edev->cdev;
725
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200726 __qede_lock(edev);
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +0200727
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200728 if (test_and_clear_bit(QEDE_SP_RX_MODE, &edev->sp_flags))
729 if (edev->state == QEDE_STATE_OPEN)
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +0200730 qede_config_rx_mode(edev->ndev);
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +0200731
Manish Choprab18e1702016-04-14 01:38:30 -0400732 if (test_and_clear_bit(QEDE_SP_VXLAN_PORT_CONFIG, &edev->sp_flags)) {
733 struct qed_tunn_params tunn_params;
734
735 memset(&tunn_params, 0, sizeof(tunn_params));
736 tunn_params.update_vxlan_port = 1;
737 tunn_params.vxlan_port = edev->vxlan_dst_port;
738 qed_ops->tunn_config(cdev, &tunn_params);
739 }
740
Manish Chopra9a109dd2016-04-14 01:38:31 -0400741 if (test_and_clear_bit(QEDE_SP_GENEVE_PORT_CONFIG, &edev->sp_flags)) {
742 struct qed_tunn_params tunn_params;
743
744 memset(&tunn_params, 0, sizeof(tunn_params));
745 tunn_params.update_geneve_port = 1;
746 tunn_params.geneve_port = edev->geneve_dst_port;
747 qed_ops->tunn_config(cdev, &tunn_params);
748 }
749
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200750 __qede_unlock(edev);
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +0200751}
752
Yuval Mintze712d522015-10-26 11:02:27 +0200753static void qede_update_pf_params(struct qed_dev *cdev)
754{
755 struct qed_pf_params pf_params;
756
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +0200757 /* 64 rx + 64 tx + 64 XDP */
Yuval Mintze712d522015-10-26 11:02:27 +0200758 memset(&pf_params, 0, sizeof(struct qed_pf_params));
Mintz, Yuvale1d32ac2017-01-01 13:57:03 +0200759 pf_params.eth_pf_params.num_cons = (MAX_SB_PER_PF_MIMD - 1) * 3;
Yuval Mintze712d522015-10-26 11:02:27 +0200760 qed_ops->common->update_pf_params(cdev, &pf_params);
761}
762
763enum qede_probe_mode {
764 QEDE_PROBE_NORMAL,
765};
766
767static int __qede_probe(struct pci_dev *pdev, u32 dp_module, u8 dp_level,
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300768 bool is_vf, enum qede_probe_mode mode)
Yuval Mintze712d522015-10-26 11:02:27 +0200769{
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300770 struct qed_probe_params probe_params;
Yuval Mintz1a635e42016-08-15 10:42:43 +0300771 struct qed_slowpath_params sp_params;
Yuval Mintze712d522015-10-26 11:02:27 +0200772 struct qed_dev_eth_info dev_info;
773 struct qede_dev *edev;
774 struct qed_dev *cdev;
775 int rc;
776
777 if (unlikely(dp_level & QED_LEVEL_INFO))
778 pr_notice("Starting qede probe\n");
779
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300780 memset(&probe_params, 0, sizeof(probe_params));
781 probe_params.protocol = QED_PROTOCOL_ETH;
782 probe_params.dp_module = dp_module;
783 probe_params.dp_level = dp_level;
784 probe_params.is_vf = is_vf;
785 cdev = qed_ops->common->probe(pdev, &probe_params);
Yuval Mintze712d522015-10-26 11:02:27 +0200786 if (!cdev) {
787 rc = -ENODEV;
788 goto err0;
789 }
790
791 qede_update_pf_params(cdev);
792
793 /* Start the Slowpath-process */
Yuval Mintz1a635e42016-08-15 10:42:43 +0300794 memset(&sp_params, 0, sizeof(sp_params));
795 sp_params.int_mode = QED_INT_MODE_MSIX;
796 sp_params.drv_major = QEDE_MAJOR_VERSION;
797 sp_params.drv_minor = QEDE_MINOR_VERSION;
798 sp_params.drv_rev = QEDE_REVISION_VERSION;
799 sp_params.drv_eng = QEDE_ENGINEERING_VERSION;
800 strlcpy(sp_params.name, "qede LAN", QED_DRV_VER_STR_SIZE);
801 rc = qed_ops->common->slowpath_start(cdev, &sp_params);
Yuval Mintze712d522015-10-26 11:02:27 +0200802 if (rc) {
803 pr_notice("Cannot start slowpath\n");
804 goto err1;
805 }
806
807 /* Learn information crucial for qede to progress */
808 rc = qed_ops->fill_dev_info(cdev, &dev_info);
809 if (rc)
810 goto err2;
811
812 edev = qede_alloc_etherdev(cdev, pdev, &dev_info, dp_module,
813 dp_level);
814 if (!edev) {
815 rc = -ENOMEM;
816 goto err2;
817 }
818
Yuval Mintzfefb0202016-05-11 16:36:19 +0300819 if (is_vf)
820 edev->flags |= QEDE_FLAG_IS_VF;
821
Yuval Mintze712d522015-10-26 11:02:27 +0200822 qede_init_ndev(edev);
823
Ram Amranicee9fbd2016-10-01 21:59:56 +0300824 rc = qede_roce_dev_add(edev);
825 if (rc)
826 goto err3;
827
Yuval Mintz29502192015-10-26 11:02:29 +0200828 rc = register_netdev(edev->ndev);
829 if (rc) {
830 DP_NOTICE(edev, "Cannot register net-device\n");
Ram Amranicee9fbd2016-10-01 21:59:56 +0300831 goto err4;
Yuval Mintz29502192015-10-26 11:02:29 +0200832 }
833
Yuval Mintze712d522015-10-26 11:02:27 +0200834 edev->ops->common->set_id(cdev, edev->ndev->name, DRV_MODULE_VERSION);
835
Sudarsana Kallurua2ec6172015-10-26 11:02:32 +0200836 edev->ops->register_ops(cdev, &qede_ll_ops, edev);
837
Sudarsana Reddy Kalluru489e45a2016-06-08 06:22:12 -0400838#ifdef CONFIG_DCB
Sudarsana Reddy Kalluru5fe118c2016-08-29 08:29:52 -0400839 if (!IS_VF(edev))
840 qede_set_dcbnl_ops(edev->ndev);
Sudarsana Reddy Kalluru489e45a2016-06-08 06:22:12 -0400841#endif
842
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +0200843 INIT_DELAYED_WORK(&edev->sp_task, qede_sp_task);
844 mutex_init(&edev->qede_lock);
Manish Chopra3d789992016-06-30 02:35:21 -0400845 edev->rx_copybreak = QEDE_RX_HDR_SIZE;
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +0200846
Yuval Mintze712d522015-10-26 11:02:27 +0200847 DP_INFO(edev, "Ending successfully qede probe\n");
848
849 return 0;
850
Ram Amranicee9fbd2016-10-01 21:59:56 +0300851err4:
852 qede_roce_dev_remove(edev);
Yuval Mintz29502192015-10-26 11:02:29 +0200853err3:
854 free_netdev(edev->ndev);
Yuval Mintze712d522015-10-26 11:02:27 +0200855err2:
856 qed_ops->common->slowpath_stop(cdev);
857err1:
858 qed_ops->common->remove(cdev);
859err0:
860 return rc;
861}
862
863static int qede_probe(struct pci_dev *pdev, const struct pci_device_id *id)
864{
Yuval Mintzfefb0202016-05-11 16:36:19 +0300865 bool is_vf = false;
Yuval Mintze712d522015-10-26 11:02:27 +0200866 u32 dp_module = 0;
867 u8 dp_level = 0;
868
Yuval Mintzfefb0202016-05-11 16:36:19 +0300869 switch ((enum qede_pci_private)id->driver_data) {
870 case QEDE_PRIVATE_VF:
871 if (debug & QED_LOG_VERBOSE_MASK)
872 dev_err(&pdev->dev, "Probing a VF\n");
873 is_vf = true;
874 break;
875 default:
876 if (debug & QED_LOG_VERBOSE_MASK)
877 dev_err(&pdev->dev, "Probing a PF\n");
878 }
879
Yuval Mintze712d522015-10-26 11:02:27 +0200880 qede_config_debug(debug, &dp_module, &dp_level);
881
Yuval Mintzfefb0202016-05-11 16:36:19 +0300882 return __qede_probe(pdev, dp_module, dp_level, is_vf,
Yuval Mintze712d522015-10-26 11:02:27 +0200883 QEDE_PROBE_NORMAL);
884}
885
886enum qede_remove_mode {
887 QEDE_REMOVE_NORMAL,
888};
889
890static void __qede_remove(struct pci_dev *pdev, enum qede_remove_mode mode)
891{
892 struct net_device *ndev = pci_get_drvdata(pdev);
893 struct qede_dev *edev = netdev_priv(ndev);
894 struct qed_dev *cdev = edev->cdev;
895
896 DP_INFO(edev, "Starting qede_remove\n");
897
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +0200898 cancel_delayed_work_sync(&edev->sp_task);
Ram Amranicee9fbd2016-10-01 21:59:56 +0300899
Yuval Mintz29502192015-10-26 11:02:29 +0200900 unregister_netdev(ndev);
901
Ram Amranicee9fbd2016-10-01 21:59:56 +0300902 qede_roce_dev_remove(edev);
903
Yuval Mintze712d522015-10-26 11:02:27 +0200904 edev->ops->common->set_power_state(cdev, PCI_D0);
905
906 pci_set_drvdata(pdev, NULL);
907
Mintz, Yuval496e0512016-11-29 16:47:09 +0200908 /* Release edev's reference to XDP's bpf if such exist */
909 if (edev->xdp_prog)
910 bpf_prog_put(edev->xdp_prog);
911
Yuval Mintze712d522015-10-26 11:02:27 +0200912 free_netdev(ndev);
913
914 /* Use global ops since we've freed edev */
915 qed_ops->common->slowpath_stop(cdev);
Mintz, Yuval14d39642016-10-31 07:14:23 +0200916 if (system_state == SYSTEM_POWER_OFF)
917 return;
Yuval Mintze712d522015-10-26 11:02:27 +0200918 qed_ops->common->remove(cdev);
919
Yuval Mintz525ef5c2016-08-15 10:42:45 +0300920 dev_info(&pdev->dev, "Ending qede_remove successfully\n");
Yuval Mintze712d522015-10-26 11:02:27 +0200921}
922
923static void qede_remove(struct pci_dev *pdev)
924{
925 __qede_remove(pdev, QEDE_REMOVE_NORMAL);
926}
Yuval Mintz29502192015-10-26 11:02:29 +0200927
Mintz, Yuval14d39642016-10-31 07:14:23 +0200928static void qede_shutdown(struct pci_dev *pdev)
929{
930 __qede_remove(pdev, QEDE_REMOVE_NORMAL);
931}
932
Yuval Mintz29502192015-10-26 11:02:29 +0200933/* -------------------------------------------------------------------------
934 * START OF LOAD / UNLOAD
935 * -------------------------------------------------------------------------
936 */
937
938static int qede_set_num_queues(struct qede_dev *edev)
939{
940 int rc;
941 u16 rss_num;
942
943 /* Setup queues according to possible resources*/
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400944 if (edev->req_queues)
945 rss_num = edev->req_queues;
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200946 else
947 rss_num = netif_get_num_default_rss_queues() *
948 edev->dev_info.common.num_hwfns;
Yuval Mintz29502192015-10-26 11:02:29 +0200949
950 rss_num = min_t(u16, QEDE_MAX_RSS_CNT(edev), rss_num);
951
952 rc = edev->ops->common->set_fp_int(edev->cdev, rss_num);
953 if (rc > 0) {
954 /* Managed to request interrupts for our queues */
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400955 edev->num_queues = rc;
Yuval Mintz29502192015-10-26 11:02:29 +0200956 DP_INFO(edev, "Managed %d [of %d] RSS queues\n",
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400957 QEDE_QUEUE_CNT(edev), rss_num);
Yuval Mintz29502192015-10-26 11:02:29 +0200958 rc = 0;
959 }
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400960
961 edev->fp_num_tx = edev->req_num_tx;
962 edev->fp_num_rx = edev->req_num_rx;
963
Yuval Mintz29502192015-10-26 11:02:29 +0200964 return rc;
965}
966
967static void qede_free_mem_sb(struct qede_dev *edev,
968 struct qed_sb_info *sb_info)
969{
970 if (sb_info->sb_virt)
971 dma_free_coherent(&edev->pdev->dev, sizeof(*sb_info->sb_virt),
972 (void *)sb_info->sb_virt, sb_info->sb_phys);
973}
974
975/* This function allocates fast-path status block memory */
976static int qede_alloc_mem_sb(struct qede_dev *edev,
Yuval Mintz1a635e42016-08-15 10:42:43 +0300977 struct qed_sb_info *sb_info, u16 sb_id)
Yuval Mintz29502192015-10-26 11:02:29 +0200978{
979 struct status_block *sb_virt;
980 dma_addr_t sb_phys;
981 int rc;
982
983 sb_virt = dma_alloc_coherent(&edev->pdev->dev,
Yuval Mintz1a635e42016-08-15 10:42:43 +0300984 sizeof(*sb_virt), &sb_phys, GFP_KERNEL);
Yuval Mintz29502192015-10-26 11:02:29 +0200985 if (!sb_virt) {
986 DP_ERR(edev, "Status block allocation failed\n");
987 return -ENOMEM;
988 }
989
990 rc = edev->ops->common->sb_init(edev->cdev, sb_info,
991 sb_virt, sb_phys, sb_id,
992 QED_SB_TYPE_L2_QUEUE);
993 if (rc) {
994 DP_ERR(edev, "Status block initialization failed\n");
995 dma_free_coherent(&edev->pdev->dev, sizeof(*sb_virt),
996 sb_virt, sb_phys);
997 return rc;
998 }
999
1000 return 0;
1001}
1002
1003static void qede_free_rx_buffers(struct qede_dev *edev,
1004 struct qede_rx_queue *rxq)
1005{
1006 u16 i;
1007
1008 for (i = rxq->sw_rx_cons; i != rxq->sw_rx_prod; i++) {
1009 struct sw_rx_data *rx_buf;
Yuval Mintzfc48b7a2016-02-15 13:22:35 -05001010 struct page *data;
Yuval Mintz29502192015-10-26 11:02:29 +02001011
1012 rx_buf = &rxq->sw_rx_ring[i & NUM_RX_BDS_MAX];
1013 data = rx_buf->data;
1014
Yuval Mintzfc48b7a2016-02-15 13:22:35 -05001015 dma_unmap_page(&edev->pdev->dev,
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001016 rx_buf->mapping, PAGE_SIZE, rxq->data_direction);
Yuval Mintz29502192015-10-26 11:02:29 +02001017
1018 rx_buf->data = NULL;
Yuval Mintzfc48b7a2016-02-15 13:22:35 -05001019 __free_page(data);
Yuval Mintz29502192015-10-26 11:02:29 +02001020 }
1021}
1022
Yuval Mintz1a635e42016-08-15 10:42:43 +03001023static void qede_free_sge_mem(struct qede_dev *edev, struct qede_rx_queue *rxq)
1024{
Manish Chopra55482ed2016-03-04 12:35:06 -05001025 int i;
1026
1027 if (edev->gro_disable)
1028 return;
1029
1030 for (i = 0; i < ETH_TPA_MAX_AGGS_NUM; i++) {
1031 struct qede_agg_info *tpa_info = &rxq->tpa_info[i];
Mintz, Yuval01e23012016-11-29 16:47:00 +02001032 struct sw_rx_data *replace_buf = &tpa_info->buffer;
Manish Chopra55482ed2016-03-04 12:35:06 -05001033
Manish Chopraf86af2d2016-04-20 03:03:27 -04001034 if (replace_buf->data) {
Manish Chopra55482ed2016-03-04 12:35:06 -05001035 dma_unmap_page(&edev->pdev->dev,
Manish Chopra09ec8e72016-05-18 07:43:57 -04001036 replace_buf->mapping,
Manish Chopra55482ed2016-03-04 12:35:06 -05001037 PAGE_SIZE, DMA_FROM_DEVICE);
1038 __free_page(replace_buf->data);
1039 }
1040 }
1041}
1042
Yuval Mintz1a635e42016-08-15 10:42:43 +03001043static void qede_free_mem_rxq(struct qede_dev *edev, struct qede_rx_queue *rxq)
Yuval Mintz29502192015-10-26 11:02:29 +02001044{
Manish Chopra55482ed2016-03-04 12:35:06 -05001045 qede_free_sge_mem(edev, rxq);
1046
Yuval Mintz29502192015-10-26 11:02:29 +02001047 /* Free rx buffers */
1048 qede_free_rx_buffers(edev, rxq);
1049
1050 /* Free the parallel SW ring */
1051 kfree(rxq->sw_rx_ring);
1052
1053 /* Free the real RQ ring used by FW */
1054 edev->ops->common->chain_free(edev->cdev, &rxq->rx_bd_ring);
1055 edev->ops->common->chain_free(edev->cdev, &rxq->rx_comp_ring);
1056}
1057
Yuval Mintz1a635e42016-08-15 10:42:43 +03001058static int qede_alloc_sge_mem(struct qede_dev *edev, struct qede_rx_queue *rxq)
Manish Chopra55482ed2016-03-04 12:35:06 -05001059{
1060 dma_addr_t mapping;
1061 int i;
1062
Mintz, Yuval496e0512016-11-29 16:47:09 +02001063 /* Don't perform FW aggregations in case of XDP */
1064 if (edev->xdp_prog)
1065 edev->gro_disable = 1;
1066
Manish Chopra55482ed2016-03-04 12:35:06 -05001067 if (edev->gro_disable)
1068 return 0;
1069
1070 if (edev->ndev->mtu > PAGE_SIZE) {
1071 edev->gro_disable = 1;
1072 return 0;
1073 }
1074
1075 for (i = 0; i < ETH_TPA_MAX_AGGS_NUM; i++) {
1076 struct qede_agg_info *tpa_info = &rxq->tpa_info[i];
Mintz, Yuval01e23012016-11-29 16:47:00 +02001077 struct sw_rx_data *replace_buf = &tpa_info->buffer;
Manish Chopra55482ed2016-03-04 12:35:06 -05001078
1079 replace_buf->data = alloc_pages(GFP_ATOMIC, 0);
1080 if (unlikely(!replace_buf->data)) {
1081 DP_NOTICE(edev,
1082 "Failed to allocate TPA skb pool [replacement buffer]\n");
1083 goto err;
1084 }
1085
1086 mapping = dma_map_page(&edev->pdev->dev, replace_buf->data, 0,
Mintz, Yuval95129252016-11-02 16:36:46 +02001087 PAGE_SIZE, DMA_FROM_DEVICE);
Manish Chopra55482ed2016-03-04 12:35:06 -05001088 if (unlikely(dma_mapping_error(&edev->pdev->dev, mapping))) {
1089 DP_NOTICE(edev,
1090 "Failed to map TPA replacement buffer\n");
1091 goto err;
1092 }
1093
Manish Chopra09ec8e72016-05-18 07:43:57 -04001094 replace_buf->mapping = mapping;
Mintz, Yuval01e23012016-11-29 16:47:00 +02001095 tpa_info->buffer.page_offset = 0;
1096 tpa_info->buffer_mapping = mapping;
1097 tpa_info->state = QEDE_AGG_STATE_NONE;
Manish Chopra55482ed2016-03-04 12:35:06 -05001098 }
1099
1100 return 0;
1101err:
1102 qede_free_sge_mem(edev, rxq);
1103 edev->gro_disable = 1;
1104 return -ENOMEM;
1105}
1106
Yuval Mintz29502192015-10-26 11:02:29 +02001107/* This function allocates all memory needed per Rx queue */
Yuval Mintz1a635e42016-08-15 10:42:43 +03001108static int qede_alloc_mem_rxq(struct qede_dev *edev, struct qede_rx_queue *rxq)
Yuval Mintz29502192015-10-26 11:02:29 +02001109{
Manish Chopraf86af2d2016-04-20 03:03:27 -04001110 int i, rc, size;
Yuval Mintz29502192015-10-26 11:02:29 +02001111
1112 rxq->num_rx_buffers = edev->q_num_rx_buffers;
1113
Yuval Mintz1a635e42016-08-15 10:42:43 +03001114 rxq->rx_buf_size = NET_IP_ALIGN + ETH_OVERHEAD + edev->ndev->mtu;
1115
Yuval Mintzfc48b7a2016-02-15 13:22:35 -05001116 if (rxq->rx_buf_size > PAGE_SIZE)
1117 rxq->rx_buf_size = PAGE_SIZE;
1118
Mintz, Yuval496e0512016-11-29 16:47:09 +02001119 /* Segment size to spilt a page in multiple equal parts,
1120 * unless XDP is used in which case we'd use the entire page.
1121 */
1122 if (!edev->xdp_prog)
1123 rxq->rx_buf_seg_size = roundup_pow_of_two(rxq->rx_buf_size);
1124 else
1125 rxq->rx_buf_seg_size = PAGE_SIZE;
Yuval Mintz29502192015-10-26 11:02:29 +02001126
1127 /* Allocate the parallel driver ring for Rx buffers */
Yuval Mintzfc48b7a2016-02-15 13:22:35 -05001128 size = sizeof(*rxq->sw_rx_ring) * RX_RING_SIZE;
Yuval Mintz29502192015-10-26 11:02:29 +02001129 rxq->sw_rx_ring = kzalloc(size, GFP_KERNEL);
1130 if (!rxq->sw_rx_ring) {
1131 DP_ERR(edev, "Rx buffers ring allocation failed\n");
Manish Chopraf86af2d2016-04-20 03:03:27 -04001132 rc = -ENOMEM;
Yuval Mintz29502192015-10-26 11:02:29 +02001133 goto err;
1134 }
1135
1136 /* Allocate FW Rx ring */
1137 rc = edev->ops->common->chain_alloc(edev->cdev,
1138 QED_CHAIN_USE_TO_CONSUME_PRODUCE,
1139 QED_CHAIN_MODE_NEXT_PTR,
Yuval Mintza91eb522016-06-03 14:35:32 +03001140 QED_CHAIN_CNT_TYPE_U16,
Yuval Mintzfc48b7a2016-02-15 13:22:35 -05001141 RX_RING_SIZE,
Yuval Mintz29502192015-10-26 11:02:29 +02001142 sizeof(struct eth_rx_bd),
1143 &rxq->rx_bd_ring);
1144
1145 if (rc)
1146 goto err;
1147
1148 /* Allocate FW completion ring */
1149 rc = edev->ops->common->chain_alloc(edev->cdev,
1150 QED_CHAIN_USE_TO_CONSUME,
1151 QED_CHAIN_MODE_PBL,
Yuval Mintza91eb522016-06-03 14:35:32 +03001152 QED_CHAIN_CNT_TYPE_U16,
Yuval Mintzfc48b7a2016-02-15 13:22:35 -05001153 RX_RING_SIZE,
Yuval Mintz29502192015-10-26 11:02:29 +02001154 sizeof(union eth_rx_cqe),
1155 &rxq->rx_comp_ring);
1156 if (rc)
1157 goto err;
1158
1159 /* Allocate buffers for the Rx ring */
Mintz, Yuvale3eef7e2017-01-01 13:57:04 +02001160 rxq->filled_buffers = 0;
Yuval Mintz29502192015-10-26 11:02:29 +02001161 for (i = 0; i < rxq->num_rx_buffers; i++) {
Mintz, Yuvale3eef7e2017-01-01 13:57:04 +02001162 rc = qede_alloc_rx_buffer(rxq, false);
Manish Chopraf86af2d2016-04-20 03:03:27 -04001163 if (rc) {
1164 DP_ERR(edev,
1165 "Rx buffers allocation failed at index %d\n", i);
1166 goto err;
1167 }
Yuval Mintz29502192015-10-26 11:02:29 +02001168 }
1169
Manish Chopraf86af2d2016-04-20 03:03:27 -04001170 rc = qede_alloc_sge_mem(edev, rxq);
Yuval Mintz29502192015-10-26 11:02:29 +02001171err:
Manish Chopraf86af2d2016-04-20 03:03:27 -04001172 return rc;
Yuval Mintz29502192015-10-26 11:02:29 +02001173}
1174
Yuval Mintz1a635e42016-08-15 10:42:43 +03001175static void qede_free_mem_txq(struct qede_dev *edev, struct qede_tx_queue *txq)
Yuval Mintz29502192015-10-26 11:02:29 +02001176{
1177 /* Free the parallel SW ring */
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001178 if (txq->is_xdp)
1179 kfree(txq->sw_tx_ring.pages);
1180 else
1181 kfree(txq->sw_tx_ring.skbs);
Yuval Mintz29502192015-10-26 11:02:29 +02001182
1183 /* Free the real RQ ring used by FW */
1184 edev->ops->common->chain_free(edev->cdev, &txq->tx_pbl);
1185}
1186
1187/* This function allocates all memory needed per Tx queue */
Yuval Mintz1a635e42016-08-15 10:42:43 +03001188static int qede_alloc_mem_txq(struct qede_dev *edev, struct qede_tx_queue *txq)
Yuval Mintz29502192015-10-26 11:02:29 +02001189{
Yuval Mintz29502192015-10-26 11:02:29 +02001190 union eth_tx_bd_types *p_virt;
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001191 int size, rc;
Yuval Mintz29502192015-10-26 11:02:29 +02001192
1193 txq->num_tx_buffers = edev->q_num_tx_buffers;
1194
1195 /* Allocate the parallel driver ring for Tx buffers */
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001196 if (txq->is_xdp) {
1197 size = sizeof(*txq->sw_tx_ring.pages) * TX_RING_SIZE;
1198 txq->sw_tx_ring.pages = kzalloc(size, GFP_KERNEL);
1199 if (!txq->sw_tx_ring.pages)
1200 goto err;
1201 } else {
1202 size = sizeof(*txq->sw_tx_ring.skbs) * TX_RING_SIZE;
1203 txq->sw_tx_ring.skbs = kzalloc(size, GFP_KERNEL);
1204 if (!txq->sw_tx_ring.skbs)
1205 goto err;
Yuval Mintz29502192015-10-26 11:02:29 +02001206 }
1207
1208 rc = edev->ops->common->chain_alloc(edev->cdev,
1209 QED_CHAIN_USE_TO_CONSUME_PRODUCE,
1210 QED_CHAIN_MODE_PBL,
Yuval Mintza91eb522016-06-03 14:35:32 +03001211 QED_CHAIN_CNT_TYPE_U16,
Mintz, Yuval087892d2016-10-29 17:04:35 +03001212 TX_RING_SIZE,
Yuval Mintza91eb522016-06-03 14:35:32 +03001213 sizeof(*p_virt), &txq->tx_pbl);
Yuval Mintz29502192015-10-26 11:02:29 +02001214 if (rc)
1215 goto err;
1216
1217 return 0;
1218
1219err:
1220 qede_free_mem_txq(edev, txq);
1221 return -ENOMEM;
1222}
1223
1224/* This function frees all memory of a single fp */
Yuval Mintz1a635e42016-08-15 10:42:43 +03001225static void qede_free_mem_fp(struct qede_dev *edev, struct qede_fastpath *fp)
Yuval Mintz29502192015-10-26 11:02:29 +02001226{
Yuval Mintz29502192015-10-26 11:02:29 +02001227 qede_free_mem_sb(edev, fp->sb_info);
1228
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001229 if (fp->type & QEDE_FASTPATH_RX)
1230 qede_free_mem_rxq(edev, fp->rxq);
Yuval Mintz29502192015-10-26 11:02:29 +02001231
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001232 if (fp->type & QEDE_FASTPATH_TX)
Mintz, Yuval80439a12016-11-29 16:47:02 +02001233 qede_free_mem_txq(edev, fp->txq);
Yuval Mintz29502192015-10-26 11:02:29 +02001234}
1235
1236/* This function allocates all memory needed for a single fp (i.e. an entity
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001237 * which contains status block, one rx queue and/or multiple per-TC tx queues.
Yuval Mintz29502192015-10-26 11:02:29 +02001238 */
Yuval Mintz1a635e42016-08-15 10:42:43 +03001239static int qede_alloc_mem_fp(struct qede_dev *edev, struct qede_fastpath *fp)
Yuval Mintz29502192015-10-26 11:02:29 +02001240{
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001241 int rc = 0;
Yuval Mintz29502192015-10-26 11:02:29 +02001242
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001243 rc = qede_alloc_mem_sb(edev, fp->sb_info, fp->id);
Yuval Mintz29502192015-10-26 11:02:29 +02001244 if (rc)
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001245 goto out;
Yuval Mintz29502192015-10-26 11:02:29 +02001246
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001247 if (fp->type & QEDE_FASTPATH_RX) {
1248 rc = qede_alloc_mem_rxq(edev, fp->rxq);
Yuval Mintz29502192015-10-26 11:02:29 +02001249 if (rc)
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001250 goto out;
1251 }
1252
1253 if (fp->type & QEDE_FASTPATH_XDP) {
1254 rc = qede_alloc_mem_txq(edev, fp->xdp_tx);
1255 if (rc)
1256 goto out;
Yuval Mintz29502192015-10-26 11:02:29 +02001257 }
1258
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001259 if (fp->type & QEDE_FASTPATH_TX) {
Mintz, Yuval80439a12016-11-29 16:47:02 +02001260 rc = qede_alloc_mem_txq(edev, fp->txq);
1261 if (rc)
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001262 goto out;
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001263 }
1264
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001265out:
Manish Chopraf86af2d2016-04-20 03:03:27 -04001266 return rc;
Yuval Mintz29502192015-10-26 11:02:29 +02001267}
1268
1269static void qede_free_mem_load(struct qede_dev *edev)
1270{
1271 int i;
1272
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001273 for_each_queue(i) {
Yuval Mintz29502192015-10-26 11:02:29 +02001274 struct qede_fastpath *fp = &edev->fp_array[i];
1275
1276 qede_free_mem_fp(edev, fp);
1277 }
1278}
1279
1280/* This function allocates all qede memory at NIC load. */
1281static int qede_alloc_mem_load(struct qede_dev *edev)
1282{
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001283 int rc = 0, queue_id;
Yuval Mintz29502192015-10-26 11:02:29 +02001284
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001285 for (queue_id = 0; queue_id < QEDE_QUEUE_CNT(edev); queue_id++) {
1286 struct qede_fastpath *fp = &edev->fp_array[queue_id];
Yuval Mintz29502192015-10-26 11:02:29 +02001287
1288 rc = qede_alloc_mem_fp(edev, fp);
Manish Chopraf86af2d2016-04-20 03:03:27 -04001289 if (rc) {
Yuval Mintz29502192015-10-26 11:02:29 +02001290 DP_ERR(edev,
Manish Chopraf86af2d2016-04-20 03:03:27 -04001291 "Failed to allocate memory for fastpath - rss id = %d\n",
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001292 queue_id);
Manish Chopraf86af2d2016-04-20 03:03:27 -04001293 qede_free_mem_load(edev);
1294 return rc;
Yuval Mintz29502192015-10-26 11:02:29 +02001295 }
Yuval Mintz29502192015-10-26 11:02:29 +02001296 }
1297
1298 return 0;
1299}
1300
1301/* This function inits fp content and resets the SB, RXQ and TXQ structures */
1302static void qede_init_fp(struct qede_dev *edev)
1303{
Mintz, Yuval80439a12016-11-29 16:47:02 +02001304 int queue_id, rxq_index = 0, txq_index = 0;
Yuval Mintz29502192015-10-26 11:02:29 +02001305 struct qede_fastpath *fp;
1306
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001307 for_each_queue(queue_id) {
1308 fp = &edev->fp_array[queue_id];
Yuval Mintz29502192015-10-26 11:02:29 +02001309
1310 fp->edev = edev;
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001311 fp->id = queue_id;
Yuval Mintz29502192015-10-26 11:02:29 +02001312
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001313 if (fp->type & QEDE_FASTPATH_XDP) {
1314 fp->xdp_tx->index = QEDE_TXQ_IDX_TO_XDP(edev,
1315 rxq_index);
1316 fp->xdp_tx->is_xdp = 1;
1317 }
Yuval Mintz29502192015-10-26 11:02:29 +02001318
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001319 if (fp->type & QEDE_FASTPATH_RX) {
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001320 fp->rxq->rxq_id = rxq_index++;
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001321
1322 /* Determine how to map buffers for this queue */
1323 if (fp->type & QEDE_FASTPATH_XDP)
1324 fp->rxq->data_direction = DMA_BIDIRECTIONAL;
1325 else
1326 fp->rxq->data_direction = DMA_FROM_DEVICE;
Mintz, Yuval9eb22352016-11-29 16:47:08 +02001327 fp->rxq->dev = &edev->pdev->dev;
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001328 }
Yuval Mintz29502192015-10-26 11:02:29 +02001329
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001330 if (fp->type & QEDE_FASTPATH_TX) {
Mintz, Yuval80439a12016-11-29 16:47:02 +02001331 fp->txq->index = txq_index++;
1332 if (edev->dev_info.is_legacy)
1333 fp->txq->is_legacy = 1;
Mintz, Yuval9eb22352016-11-29 16:47:08 +02001334 fp->txq->dev = &edev->pdev->dev;
Yuval Mintz29502192015-10-26 11:02:29 +02001335 }
1336
1337 snprintf(fp->name, sizeof(fp->name), "%s-fp-%d",
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001338 edev->ndev->name, queue_id);
Yuval Mintz29502192015-10-26 11:02:29 +02001339 }
Manish Chopra55482ed2016-03-04 12:35:06 -05001340
1341 edev->gro_disable = !(edev->ndev->features & NETIF_F_GRO);
Yuval Mintz29502192015-10-26 11:02:29 +02001342}
1343
1344static int qede_set_real_num_queues(struct qede_dev *edev)
1345{
1346 int rc = 0;
1347
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001348 rc = netif_set_real_num_tx_queues(edev->ndev, QEDE_TSS_COUNT(edev));
Yuval Mintz29502192015-10-26 11:02:29 +02001349 if (rc) {
1350 DP_NOTICE(edev, "Failed to set real number of Tx queues\n");
1351 return rc;
1352 }
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001353
1354 rc = netif_set_real_num_rx_queues(edev->ndev, QEDE_RSS_COUNT(edev));
Yuval Mintz29502192015-10-26 11:02:29 +02001355 if (rc) {
1356 DP_NOTICE(edev, "Failed to set real number of Rx queues\n");
1357 return rc;
1358 }
1359
1360 return 0;
1361}
1362
1363static void qede_napi_disable_remove(struct qede_dev *edev)
1364{
1365 int i;
1366
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001367 for_each_queue(i) {
Yuval Mintz29502192015-10-26 11:02:29 +02001368 napi_disable(&edev->fp_array[i].napi);
1369
1370 netif_napi_del(&edev->fp_array[i].napi);
1371 }
1372}
1373
1374static void qede_napi_add_enable(struct qede_dev *edev)
1375{
1376 int i;
1377
1378 /* Add NAPI objects */
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001379 for_each_queue(i) {
Yuval Mintz29502192015-10-26 11:02:29 +02001380 netif_napi_add(edev->ndev, &edev->fp_array[i].napi,
1381 qede_poll, NAPI_POLL_WEIGHT);
1382 napi_enable(&edev->fp_array[i].napi);
1383 }
1384}
1385
1386static void qede_sync_free_irqs(struct qede_dev *edev)
1387{
1388 int i;
1389
1390 for (i = 0; i < edev->int_info.used_cnt; i++) {
1391 if (edev->int_info.msix_cnt) {
1392 synchronize_irq(edev->int_info.msix[i].vector);
1393 free_irq(edev->int_info.msix[i].vector,
1394 &edev->fp_array[i]);
1395 } else {
1396 edev->ops->common->simd_handler_clean(edev->cdev, i);
1397 }
1398 }
1399
1400 edev->int_info.used_cnt = 0;
1401}
1402
1403static int qede_req_msix_irqs(struct qede_dev *edev)
1404{
1405 int i, rc;
1406
1407 /* Sanitize number of interrupts == number of prepared RSS queues */
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001408 if (QEDE_QUEUE_CNT(edev) > edev->int_info.msix_cnt) {
Yuval Mintz29502192015-10-26 11:02:29 +02001409 DP_ERR(edev,
1410 "Interrupt mismatch: %d RSS queues > %d MSI-x vectors\n",
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001411 QEDE_QUEUE_CNT(edev), edev->int_info.msix_cnt);
Yuval Mintz29502192015-10-26 11:02:29 +02001412 return -EINVAL;
1413 }
1414
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001415 for (i = 0; i < QEDE_QUEUE_CNT(edev); i++) {
Yuval Mintz29502192015-10-26 11:02:29 +02001416 rc = request_irq(edev->int_info.msix[i].vector,
1417 qede_msix_fp_int, 0, edev->fp_array[i].name,
1418 &edev->fp_array[i]);
1419 if (rc) {
1420 DP_ERR(edev, "Request fp %d irq failed\n", i);
1421 qede_sync_free_irqs(edev);
1422 return rc;
1423 }
1424 DP_VERBOSE(edev, NETIF_MSG_INTR,
1425 "Requested fp irq for %s [entry %d]. Cookie is at %p\n",
1426 edev->fp_array[i].name, i,
1427 &edev->fp_array[i]);
1428 edev->int_info.used_cnt++;
1429 }
1430
1431 return 0;
1432}
1433
1434static void qede_simd_fp_handler(void *cookie)
1435{
1436 struct qede_fastpath *fp = (struct qede_fastpath *)cookie;
1437
1438 napi_schedule_irqoff(&fp->napi);
1439}
1440
1441static int qede_setup_irqs(struct qede_dev *edev)
1442{
1443 int i, rc = 0;
1444
1445 /* Learn Interrupt configuration */
1446 rc = edev->ops->common->get_fp_int(edev->cdev, &edev->int_info);
1447 if (rc)
1448 return rc;
1449
1450 if (edev->int_info.msix_cnt) {
1451 rc = qede_req_msix_irqs(edev);
1452 if (rc)
1453 return rc;
1454 edev->ndev->irq = edev->int_info.msix[0].vector;
1455 } else {
1456 const struct qed_common_ops *ops;
1457
1458 /* qed should learn receive the RSS ids and callbacks */
1459 ops = edev->ops->common;
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001460 for (i = 0; i < QEDE_QUEUE_CNT(edev); i++)
Yuval Mintz29502192015-10-26 11:02:29 +02001461 ops->simd_handler_config(edev->cdev,
1462 &edev->fp_array[i], i,
1463 qede_simd_fp_handler);
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001464 edev->int_info.used_cnt = QEDE_QUEUE_CNT(edev);
Yuval Mintz29502192015-10-26 11:02:29 +02001465 }
1466 return 0;
1467}
1468
1469static int qede_drain_txq(struct qede_dev *edev,
Yuval Mintz1a635e42016-08-15 10:42:43 +03001470 struct qede_tx_queue *txq, bool allow_drain)
Yuval Mintz29502192015-10-26 11:02:29 +02001471{
1472 int rc, cnt = 1000;
1473
1474 while (txq->sw_tx_cons != txq->sw_tx_prod) {
1475 if (!cnt) {
1476 if (allow_drain) {
1477 DP_NOTICE(edev,
1478 "Tx queue[%d] is stuck, requesting MCP to drain\n",
1479 txq->index);
1480 rc = edev->ops->common->drain(edev->cdev);
1481 if (rc)
1482 return rc;
1483 return qede_drain_txq(edev, txq, false);
1484 }
1485 DP_NOTICE(edev,
1486 "Timeout waiting for tx queue[%d]: PROD=%d, CONS=%d\n",
1487 txq->index, txq->sw_tx_prod,
1488 txq->sw_tx_cons);
1489 return -ENODEV;
1490 }
1491 cnt--;
1492 usleep_range(1000, 2000);
1493 barrier();
1494 }
1495
1496 /* FW finished processing, wait for HW to transmit all tx packets */
1497 usleep_range(1000, 2000);
1498
1499 return 0;
1500}
1501
Mintz, Yuval3da7a372016-11-29 16:47:06 +02001502static int qede_stop_txq(struct qede_dev *edev,
1503 struct qede_tx_queue *txq, int rss_id)
1504{
1505 return edev->ops->q_tx_stop(edev->cdev, rss_id, txq->handle);
1506}
1507
Yuval Mintz29502192015-10-26 11:02:29 +02001508static int qede_stop_queues(struct qede_dev *edev)
1509{
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001510 struct qed_update_vport_params *vport_update_params;
Yuval Mintz29502192015-10-26 11:02:29 +02001511 struct qed_dev *cdev = edev->cdev;
Mintz, Yuval80439a12016-11-29 16:47:02 +02001512 struct qede_fastpath *fp;
1513 int rc, i;
Yuval Mintz29502192015-10-26 11:02:29 +02001514
1515 /* Disable the vport */
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001516 vport_update_params = vzalloc(sizeof(*vport_update_params));
1517 if (!vport_update_params)
1518 return -ENOMEM;
Yuval Mintz29502192015-10-26 11:02:29 +02001519
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001520 vport_update_params->vport_id = 0;
1521 vport_update_params->update_vport_active_flg = 1;
1522 vport_update_params->vport_active_flg = 0;
1523 vport_update_params->update_rss_flg = 0;
1524
1525 rc = edev->ops->vport_update(cdev, vport_update_params);
1526 vfree(vport_update_params);
1527
Yuval Mintz29502192015-10-26 11:02:29 +02001528 if (rc) {
1529 DP_ERR(edev, "Failed to update vport\n");
1530 return rc;
1531 }
1532
1533 /* Flush Tx queues. If needed, request drain from MCP */
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001534 for_each_queue(i) {
Mintz, Yuval80439a12016-11-29 16:47:02 +02001535 fp = &edev->fp_array[i];
Yuval Mintz29502192015-10-26 11:02:29 +02001536
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001537 if (fp->type & QEDE_FASTPATH_TX) {
Mintz, Yuval80439a12016-11-29 16:47:02 +02001538 rc = qede_drain_txq(edev, fp->txq, true);
1539 if (rc)
1540 return rc;
Yuval Mintz29502192015-10-26 11:02:29 +02001541 }
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001542
1543 if (fp->type & QEDE_FASTPATH_XDP) {
1544 rc = qede_drain_txq(edev, fp->xdp_tx, true);
1545 if (rc)
1546 return rc;
1547 }
Yuval Mintz29502192015-10-26 11:02:29 +02001548 }
1549
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001550 /* Stop all Queues in reverse order */
1551 for (i = QEDE_QUEUE_CNT(edev) - 1; i >= 0; i--) {
Mintz, Yuval80439a12016-11-29 16:47:02 +02001552 fp = &edev->fp_array[i];
Yuval Mintz29502192015-10-26 11:02:29 +02001553
Mintz, Yuval80439a12016-11-29 16:47:02 +02001554 /* Stop the Tx Queue(s) */
1555 if (fp->type & QEDE_FASTPATH_TX) {
Mintz, Yuval3da7a372016-11-29 16:47:06 +02001556 rc = qede_stop_txq(edev, fp->txq, i);
1557 if (rc)
1558 return rc;
Yuval Mintz29502192015-10-26 11:02:29 +02001559 }
1560
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001561 /* Stop the Rx Queue */
Mintz, Yuval80439a12016-11-29 16:47:02 +02001562 if (fp->type & QEDE_FASTPATH_RX) {
Mintz, Yuval3da7a372016-11-29 16:47:06 +02001563 rc = edev->ops->q_rx_stop(cdev, i, fp->rxq->handle);
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001564 if (rc) {
1565 DP_ERR(edev, "Failed to stop RXQ #%d\n", i);
1566 return rc;
1567 }
Yuval Mintz29502192015-10-26 11:02:29 +02001568 }
Mintz, Yuval496e0512016-11-29 16:47:09 +02001569
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001570 /* Stop the XDP forwarding queue */
1571 if (fp->type & QEDE_FASTPATH_XDP) {
1572 rc = qede_stop_txq(edev, fp->xdp_tx, i);
1573 if (rc)
1574 return rc;
1575
Mintz, Yuval496e0512016-11-29 16:47:09 +02001576 bpf_prog_put(fp->rxq->xdp_prog);
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001577 }
Yuval Mintz29502192015-10-26 11:02:29 +02001578 }
1579
1580 /* Stop the vport */
1581 rc = edev->ops->vport_stop(cdev, 0);
1582 if (rc)
1583 DP_ERR(edev, "Failed to stop VPORT\n");
1584
1585 return rc;
1586}
1587
Mintz, Yuval3da7a372016-11-29 16:47:06 +02001588static int qede_start_txq(struct qede_dev *edev,
1589 struct qede_fastpath *fp,
1590 struct qede_tx_queue *txq, u8 rss_id, u16 sb_idx)
1591{
1592 dma_addr_t phys_table = qed_chain_get_pbl_phys(&txq->tx_pbl);
1593 u32 page_cnt = qed_chain_get_page_cnt(&txq->tx_pbl);
1594 struct qed_queue_start_common_params params;
1595 struct qed_txq_start_ret_params ret_params;
1596 int rc;
1597
1598 memset(&params, 0, sizeof(params));
1599 memset(&ret_params, 0, sizeof(ret_params));
1600
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001601 /* Let the XDP queue share the queue-zone with one of the regular txq.
1602 * We don't really care about its coalescing.
1603 */
1604 if (txq->is_xdp)
1605 params.queue_id = QEDE_TXQ_XDP_TO_IDX(edev, txq);
1606 else
1607 params.queue_id = txq->index;
1608
Mintz, Yuval3da7a372016-11-29 16:47:06 +02001609 params.sb = fp->sb_info->igu_sb_id;
1610 params.sb_idx = sb_idx;
1611
1612 rc = edev->ops->q_tx_start(edev->cdev, rss_id, &params, phys_table,
1613 page_cnt, &ret_params);
1614 if (rc) {
1615 DP_ERR(edev, "Start TXQ #%d failed %d\n", txq->index, rc);
1616 return rc;
1617 }
1618
1619 txq->doorbell_addr = ret_params.p_doorbell;
1620 txq->handle = ret_params.p_handle;
1621
1622 /* Determine the FW consumer address associated */
1623 txq->hw_cons_ptr = &fp->sb_info->sb_virt->pi_array[sb_idx];
1624
1625 /* Prepare the doorbell parameters */
1626 SET_FIELD(txq->tx_db.data.params, ETH_DB_DATA_DEST, DB_DEST_XCM);
1627 SET_FIELD(txq->tx_db.data.params, ETH_DB_DATA_AGG_CMD, DB_AGG_CMD_SET);
1628 SET_FIELD(txq->tx_db.data.params, ETH_DB_DATA_AGG_VAL_SEL,
1629 DQ_XCM_ETH_TX_BD_PROD_CMD);
1630 txq->tx_db.data.agg_flags = DQ_XCM_ETH_DQ_CF_CMD;
1631
1632 return rc;
1633}
1634
Yuval Mintza0d26d52016-06-19 15:18:13 +03001635static int qede_start_queues(struct qede_dev *edev, bool clear_stats)
Yuval Mintz29502192015-10-26 11:02:29 +02001636{
Manish Chopra088c8612016-03-04 12:35:05 -05001637 int vlan_removal_en = 1;
Yuval Mintz29502192015-10-26 11:02:29 +02001638 struct qed_dev *cdev = edev->cdev;
Yuval Mintzfefb0202016-05-11 16:36:19 +03001639 struct qed_dev_info *qed_info = &edev->dev_info.common;
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001640 struct qed_update_vport_params *vport_update_params;
1641 struct qed_queue_start_common_params q_params;
Manish Chopra088c8612016-03-04 12:35:05 -05001642 struct qed_start_vport_params start = {0};
Mintz, Yuval80439a12016-11-29 16:47:02 +02001643 int rc, i;
Yuval Mintz29502192015-10-26 11:02:29 +02001644
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001645 if (!edev->num_queues) {
Yuval Mintz29502192015-10-26 11:02:29 +02001646 DP_ERR(edev,
1647 "Cannot update V-VPORT as active as there are no Rx queues\n");
1648 return -EINVAL;
1649 }
1650
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001651 vport_update_params = vzalloc(sizeof(*vport_update_params));
1652 if (!vport_update_params)
1653 return -ENOMEM;
1654
Manish Chopra55482ed2016-03-04 12:35:06 -05001655 start.gro_enable = !edev->gro_disable;
Manish Chopra088c8612016-03-04 12:35:05 -05001656 start.mtu = edev->ndev->mtu;
1657 start.vport_id = 0;
1658 start.drop_ttl0 = true;
1659 start.remove_inner_vlan = vlan_removal_en;
Yuval Mintz7f7a1442016-07-27 14:45:22 +03001660 start.clear_stats = clear_stats;
Manish Chopra088c8612016-03-04 12:35:05 -05001661
1662 rc = edev->ops->vport_start(cdev, &start);
Yuval Mintz29502192015-10-26 11:02:29 +02001663
1664 if (rc) {
1665 DP_ERR(edev, "Start V-PORT failed %d\n", rc);
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001666 goto out;
Yuval Mintz29502192015-10-26 11:02:29 +02001667 }
1668
1669 DP_VERBOSE(edev, NETIF_MSG_IFUP,
1670 "Start vport ramrod passed, vport_id = %d, MTU = %d, vlan_removal_en = %d\n",
Manish Chopra088c8612016-03-04 12:35:05 -05001671 start.vport_id, edev->ndev->mtu + 0xe, vlan_removal_en);
Yuval Mintz29502192015-10-26 11:02:29 +02001672
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001673 for_each_queue(i) {
Yuval Mintz29502192015-10-26 11:02:29 +02001674 struct qede_fastpath *fp = &edev->fp_array[i];
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001675 dma_addr_t p_phys_table;
1676 u32 page_cnt;
Yuval Mintz29502192015-10-26 11:02:29 +02001677
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001678 if (fp->type & QEDE_FASTPATH_RX) {
Mintz, Yuval3da7a372016-11-29 16:47:06 +02001679 struct qed_rxq_start_ret_params ret_params;
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001680 struct qede_rx_queue *rxq = fp->rxq;
1681 __le16 *val;
Yuval Mintz29502192015-10-26 11:02:29 +02001682
Mintz, Yuval3da7a372016-11-29 16:47:06 +02001683 memset(&ret_params, 0, sizeof(ret_params));
Yuval Mintz29502192015-10-26 11:02:29 +02001684 memset(&q_params, 0, sizeof(q_params));
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001685 q_params.queue_id = rxq->rxq_id;
1686 q_params.vport_id = 0;
1687 q_params.sb = fp->sb_info->igu_sb_id;
1688 q_params.sb_idx = RX_PI;
1689
1690 p_phys_table =
1691 qed_chain_get_pbl_phys(&rxq->rx_comp_ring);
1692 page_cnt = qed_chain_get_page_cnt(&rxq->rx_comp_ring);
1693
Mintz, Yuval3da7a372016-11-29 16:47:06 +02001694 rc = edev->ops->q_rx_start(cdev, i, &q_params,
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001695 rxq->rx_buf_size,
1696 rxq->rx_bd_ring.p_phys_addr,
1697 p_phys_table,
Mintz, Yuval3da7a372016-11-29 16:47:06 +02001698 page_cnt, &ret_params);
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001699 if (rc) {
1700 DP_ERR(edev, "Start RXQ #%d failed %d\n", i,
1701 rc);
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001702 goto out;
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001703 }
1704
Mintz, Yuval3da7a372016-11-29 16:47:06 +02001705 /* Use the return parameters */
1706 rxq->hw_rxq_prod_addr = ret_params.p_prod;
1707 rxq->handle = ret_params.p_handle;
1708
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001709 val = &fp->sb_info->sb_virt->pi_array[RX_PI];
1710 rxq->hw_cons_ptr = val;
1711
1712 qede_update_rx_prod(edev, rxq);
1713 }
1714
Mintz, Yuval496e0512016-11-29 16:47:09 +02001715 if (fp->type & QEDE_FASTPATH_XDP) {
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001716 rc = qede_start_txq(edev, fp, fp->xdp_tx, i, XDP_PI);
1717 if (rc)
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001718 goto out;
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001719
Mintz, Yuval496e0512016-11-29 16:47:09 +02001720 fp->rxq->xdp_prog = bpf_prog_add(edev->xdp_prog, 1);
1721 if (IS_ERR(fp->rxq->xdp_prog)) {
1722 rc = PTR_ERR(fp->rxq->xdp_prog);
1723 fp->rxq->xdp_prog = NULL;
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001724 goto out;
Mintz, Yuval496e0512016-11-29 16:47:09 +02001725 }
1726 }
1727
Mintz, Yuval80439a12016-11-29 16:47:02 +02001728 if (fp->type & QEDE_FASTPATH_TX) {
Mintz, Yuval3da7a372016-11-29 16:47:06 +02001729 rc = qede_start_txq(edev, fp, fp->txq, i, TX_PI(0));
1730 if (rc)
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001731 goto out;
Yuval Mintz29502192015-10-26 11:02:29 +02001732 }
1733 }
1734
1735 /* Prepare and send the vport enable */
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001736 vport_update_params->vport_id = start.vport_id;
1737 vport_update_params->update_vport_active_flg = 1;
1738 vport_update_params->vport_active_flg = 1;
Yuval Mintz29502192015-10-26 11:02:29 +02001739
Yuval Mintz831bfb0e2016-05-11 16:36:25 +03001740 if ((qed_info->mf_mode == QED_MF_NPAR || pci_num_vf(edev->pdev)) &&
1741 qed_info->tx_switching) {
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001742 vport_update_params->update_tx_switching_flg = 1;
1743 vport_update_params->tx_switching_flg = 1;
Yuval Mintz831bfb0e2016-05-11 16:36:25 +03001744 }
1745
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001746 qede_fill_rss_params(edev, &vport_update_params->rss_params,
1747 &vport_update_params->update_rss_flg);
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001748
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001749 rc = edev->ops->vport_update(cdev, vport_update_params);
1750 if (rc)
Yuval Mintz29502192015-10-26 11:02:29 +02001751 DP_ERR(edev, "Update V-PORT failed %d\n", rc);
Yuval Mintz29502192015-10-26 11:02:29 +02001752
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001753out:
1754 vfree(vport_update_params);
1755 return rc;
Yuval Mintz29502192015-10-26 11:02:29 +02001756}
1757
1758enum qede_unload_mode {
1759 QEDE_UNLOAD_NORMAL,
1760};
1761
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001762static void qede_unload(struct qede_dev *edev, enum qede_unload_mode mode,
1763 bool is_locked)
Yuval Mintz29502192015-10-26 11:02:29 +02001764{
Sudarsana Kallurua2ec6172015-10-26 11:02:32 +02001765 struct qed_link_params link_params;
Yuval Mintz29502192015-10-26 11:02:29 +02001766 int rc;
1767
1768 DP_INFO(edev, "Starting qede unload\n");
1769
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001770 if (!is_locked)
1771 __qede_lock(edev);
1772
Ram Amranicee9fbd2016-10-01 21:59:56 +03001773 qede_roce_dev_event_close(edev);
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +02001774 edev->state = QEDE_STATE_CLOSED;
1775
Yuval Mintz29502192015-10-26 11:02:29 +02001776 /* Close OS Tx */
1777 netif_tx_disable(edev->ndev);
1778 netif_carrier_off(edev->ndev);
1779
Sudarsana Kallurua2ec6172015-10-26 11:02:32 +02001780 /* Reset the link */
1781 memset(&link_params, 0, sizeof(link_params));
1782 link_params.link_up = false;
1783 edev->ops->common->set_link(edev->cdev, &link_params);
Yuval Mintz29502192015-10-26 11:02:29 +02001784 rc = qede_stop_queues(edev);
1785 if (rc) {
1786 qede_sync_free_irqs(edev);
1787 goto out;
1788 }
1789
1790 DP_INFO(edev, "Stopped Queues\n");
1791
Sudarsana Reddy Kalluru7c1bfca2016-02-18 17:00:40 +02001792 qede_vlan_mark_nonconfigured(edev);
Yuval Mintz29502192015-10-26 11:02:29 +02001793 edev->ops->fastpath_stop(edev->cdev);
1794
1795 /* Release the interrupts */
1796 qede_sync_free_irqs(edev);
1797 edev->ops->common->set_fp_int(edev->cdev, 0);
1798
1799 qede_napi_disable_remove(edev);
1800
1801 qede_free_mem_load(edev);
1802 qede_free_fp_array(edev);
1803
1804out:
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001805 if (!is_locked)
1806 __qede_unlock(edev);
Yuval Mintz29502192015-10-26 11:02:29 +02001807 DP_INFO(edev, "Ending qede unload\n");
1808}
1809
1810enum qede_load_mode {
1811 QEDE_LOAD_NORMAL,
Yuval Mintza0d26d52016-06-19 15:18:13 +03001812 QEDE_LOAD_RELOAD,
Yuval Mintz29502192015-10-26 11:02:29 +02001813};
1814
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001815static int qede_load(struct qede_dev *edev, enum qede_load_mode mode,
1816 bool is_locked)
Yuval Mintz29502192015-10-26 11:02:29 +02001817{
Sudarsana Kallurua2ec6172015-10-26 11:02:32 +02001818 struct qed_link_params link_params;
1819 struct qed_link_output link_output;
Yuval Mintz29502192015-10-26 11:02:29 +02001820 int rc;
1821
1822 DP_INFO(edev, "Starting qede load\n");
1823
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001824 if (!is_locked)
1825 __qede_lock(edev);
1826
Yuval Mintz29502192015-10-26 11:02:29 +02001827 rc = qede_set_num_queues(edev);
1828 if (rc)
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001829 goto out;
Yuval Mintz29502192015-10-26 11:02:29 +02001830
1831 rc = qede_alloc_fp_array(edev);
1832 if (rc)
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001833 goto out;
Yuval Mintz29502192015-10-26 11:02:29 +02001834
1835 qede_init_fp(edev);
1836
1837 rc = qede_alloc_mem_load(edev);
1838 if (rc)
1839 goto err1;
Mintz, Yuval80439a12016-11-29 16:47:02 +02001840 DP_INFO(edev, "Allocated %d Rx, %d Tx queues\n",
1841 QEDE_RSS_COUNT(edev), QEDE_TSS_COUNT(edev));
Yuval Mintz29502192015-10-26 11:02:29 +02001842
1843 rc = qede_set_real_num_queues(edev);
1844 if (rc)
1845 goto err2;
1846
1847 qede_napi_add_enable(edev);
1848 DP_INFO(edev, "Napi added and enabled\n");
1849
1850 rc = qede_setup_irqs(edev);
1851 if (rc)
1852 goto err3;
1853 DP_INFO(edev, "Setup IRQs succeeded\n");
1854
Yuval Mintza0d26d52016-06-19 15:18:13 +03001855 rc = qede_start_queues(edev, mode != QEDE_LOAD_RELOAD);
Yuval Mintz29502192015-10-26 11:02:29 +02001856 if (rc)
1857 goto err4;
1858 DP_INFO(edev, "Start VPORT, RXQ and TXQ succeeded\n");
1859
1860 /* Add primary mac and set Rx filters */
1861 ether_addr_copy(edev->primary_mac, edev->ndev->dev_addr);
1862
Sudarsana Reddy Kalluru7c1bfca2016-02-18 17:00:40 +02001863 /* Program un-configured VLANs */
1864 qede_configure_vlan_filters(edev);
1865
Sudarsana Kallurua2ec6172015-10-26 11:02:32 +02001866 /* Ask for link-up using current configuration */
1867 memset(&link_params, 0, sizeof(link_params));
1868 link_params.link_up = true;
1869 edev->ops->common->set_link(edev->cdev, &link_params);
1870
1871 /* Query whether link is already-up */
1872 memset(&link_output, 0, sizeof(link_output));
1873 edev->ops->common->get_link(edev->cdev, &link_output);
Ram Amranicee9fbd2016-10-01 21:59:56 +03001874 qede_roce_dev_event_open(edev);
Sudarsana Kallurua2ec6172015-10-26 11:02:32 +02001875 qede_link_update(edev, &link_output);
1876
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001877 edev->state = QEDE_STATE_OPEN;
1878
Yuval Mintz29502192015-10-26 11:02:29 +02001879 DP_INFO(edev, "Ending successfully qede load\n");
1880
Yuval Mintz29502192015-10-26 11:02:29 +02001881
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001882 goto out;
Yuval Mintz29502192015-10-26 11:02:29 +02001883err4:
1884 qede_sync_free_irqs(edev);
1885 memset(&edev->int_info.msix_cnt, 0, sizeof(struct qed_int_info));
1886err3:
1887 qede_napi_disable_remove(edev);
1888err2:
1889 qede_free_mem_load(edev);
1890err1:
1891 edev->ops->common->set_fp_int(edev->cdev, 0);
1892 qede_free_fp_array(edev);
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001893 edev->num_queues = 0;
1894 edev->fp_num_tx = 0;
1895 edev->fp_num_rx = 0;
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001896out:
1897 if (!is_locked)
1898 __qede_unlock(edev);
1899
Yuval Mintz29502192015-10-26 11:02:29 +02001900 return rc;
1901}
1902
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001903/* 'func' should be able to run between unload and reload assuming interface
1904 * is actually running, or afterwards in case it's currently DOWN.
1905 */
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001906void qede_reload(struct qede_dev *edev,
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001907 struct qede_reload_args *args, bool is_locked)
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001908{
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001909 if (!is_locked)
1910 __qede_lock(edev);
1911
1912 /* Since qede_lock is held, internal state wouldn't change even
1913 * if netdev state would start transitioning. Check whether current
1914 * internal configuration indicates device is up, then reload.
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001915 */
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001916 if (edev->state == QEDE_STATE_OPEN) {
1917 qede_unload(edev, QEDE_UNLOAD_NORMAL, true);
1918 if (args)
1919 args->func(edev, args);
1920 qede_load(edev, QEDE_LOAD_RELOAD, true);
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001921
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001922 /* Since no one is going to do it for us, re-configure */
1923 qede_config_rx_mode(edev->ndev);
1924 } else if (args) {
1925 args->func(edev, args);
1926 }
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001927
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001928 if (!is_locked)
1929 __qede_unlock(edev);
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001930}
1931
Yuval Mintz29502192015-10-26 11:02:29 +02001932/* called with rtnl_lock */
1933static int qede_open(struct net_device *ndev)
1934{
1935 struct qede_dev *edev = netdev_priv(ndev);
Manish Choprab18e1702016-04-14 01:38:30 -04001936 int rc;
Yuval Mintz29502192015-10-26 11:02:29 +02001937
1938 netif_carrier_off(ndev);
1939
1940 edev->ops->common->set_power_state(edev->cdev, PCI_D0);
1941
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001942 rc = qede_load(edev, QEDE_LOAD_NORMAL, false);
Manish Choprab18e1702016-04-14 01:38:30 -04001943 if (rc)
1944 return rc;
1945
Alexander Duyckf9f082a2016-06-16 12:22:57 -07001946 udp_tunnel_get_rx_info(ndev);
1947
Sudarsana Kalluru0fefbfb2016-10-31 07:14:21 +02001948 edev->ops->common->update_drv_state(edev->cdev, true);
1949
Manish Choprab18e1702016-04-14 01:38:30 -04001950 return 0;
Yuval Mintz29502192015-10-26 11:02:29 +02001951}
1952
1953static int qede_close(struct net_device *ndev)
1954{
1955 struct qede_dev *edev = netdev_priv(ndev);
1956
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001957 qede_unload(edev, QEDE_UNLOAD_NORMAL, false);
Yuval Mintz29502192015-10-26 11:02:29 +02001958
Sudarsana Kalluru0fefbfb2016-10-31 07:14:21 +02001959 edev->ops->common->update_drv_state(edev->cdev, false);
1960
Yuval Mintz29502192015-10-26 11:02:29 +02001961 return 0;
1962}
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +02001963
Sudarsana Kallurua2ec6172015-10-26 11:02:32 +02001964static void qede_link_update(void *dev, struct qed_link_output *link)
1965{
1966 struct qede_dev *edev = dev;
1967
1968 if (!netif_running(edev->ndev)) {
1969 DP_VERBOSE(edev, NETIF_MSG_LINK, "Interface is not running\n");
1970 return;
1971 }
1972
1973 if (link->link_up) {
Yuval Mintz8e025ae2016-02-24 16:52:47 +02001974 if (!netif_carrier_ok(edev->ndev)) {
1975 DP_NOTICE(edev, "Link is up\n");
1976 netif_tx_start_all_queues(edev->ndev);
1977 netif_carrier_on(edev->ndev);
1978 }
Sudarsana Kallurua2ec6172015-10-26 11:02:32 +02001979 } else {
Yuval Mintz8e025ae2016-02-24 16:52:47 +02001980 if (netif_carrier_ok(edev->ndev)) {
1981 DP_NOTICE(edev, "Link is down\n");
1982 netif_tx_disable(edev->ndev);
1983 netif_carrier_off(edev->ndev);
1984 }
Sudarsana Kallurua2ec6172015-10-26 11:02:32 +02001985 }
1986}