blob: 7a8e07d0e01c376f64551fdef508c00ee5fcb19f [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"
Sudarsana Reddy Kalluru4c552152017-02-15 10:24:11 +020065#include "qede_ptp.h"
Yuval Mintze712d522015-10-26 11:02:27 +020066
Yuval Mintz5abd7e922016-02-24 16:52:50 +020067static char version[] =
68 "QLogic FastLinQ 4xxxx Ethernet Driver qede " DRV_MODULE_VERSION "\n";
Yuval Mintze712d522015-10-26 11:02:27 +020069
Yuval Mintz5abd7e922016-02-24 16:52:50 +020070MODULE_DESCRIPTION("QLogic FastLinQ 4xxxx Ethernet Driver");
Yuval Mintze712d522015-10-26 11:02:27 +020071MODULE_LICENSE("GPL");
72MODULE_VERSION(DRV_MODULE_VERSION);
73
74static uint debug;
75module_param(debug, uint, 0);
76MODULE_PARM_DESC(debug, " Default debug msglevel");
77
78static const struct qed_eth_ops *qed_ops;
79
80#define CHIP_NUM_57980S_40 0x1634
Yuval Mintz0e7441d2016-02-24 16:52:45 +020081#define CHIP_NUM_57980S_10 0x1666
Yuval Mintze712d522015-10-26 11:02:27 +020082#define CHIP_NUM_57980S_MF 0x1636
83#define CHIP_NUM_57980S_100 0x1644
84#define CHIP_NUM_57980S_50 0x1654
85#define CHIP_NUM_57980S_25 0x1656
Yuval Mintzfefb0202016-05-11 16:36:19 +030086#define CHIP_NUM_57980S_IOV 0x1664
Yuval Mintze712d522015-10-26 11:02:27 +020087
88#ifndef PCI_DEVICE_ID_NX2_57980E
89#define PCI_DEVICE_ID_57980S_40 CHIP_NUM_57980S_40
90#define PCI_DEVICE_ID_57980S_10 CHIP_NUM_57980S_10
91#define PCI_DEVICE_ID_57980S_MF CHIP_NUM_57980S_MF
92#define PCI_DEVICE_ID_57980S_100 CHIP_NUM_57980S_100
93#define PCI_DEVICE_ID_57980S_50 CHIP_NUM_57980S_50
94#define PCI_DEVICE_ID_57980S_25 CHIP_NUM_57980S_25
Yuval Mintzfefb0202016-05-11 16:36:19 +030095#define PCI_DEVICE_ID_57980S_IOV CHIP_NUM_57980S_IOV
Yuval Mintze712d522015-10-26 11:02:27 +020096#endif
97
Yuval Mintzfefb0202016-05-11 16:36:19 +030098enum qede_pci_private {
99 QEDE_PRIVATE_PF,
100 QEDE_PRIVATE_VF
101};
102
Yuval Mintze712d522015-10-26 11:02:27 +0200103static const struct pci_device_id qede_pci_tbl[] = {
Yuval Mintzfefb0202016-05-11 16:36:19 +0300104 {PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_57980S_40), QEDE_PRIVATE_PF},
105 {PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_57980S_10), QEDE_PRIVATE_PF},
106 {PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_57980S_MF), QEDE_PRIVATE_PF},
107 {PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_57980S_100), QEDE_PRIVATE_PF},
108 {PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_57980S_50), QEDE_PRIVATE_PF},
109 {PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_57980S_25), QEDE_PRIVATE_PF},
Arnd Bergmann14b84e82016-06-01 15:29:13 +0200110#ifdef CONFIG_QED_SRIOV
Yuval Mintzfefb0202016-05-11 16:36:19 +0300111 {PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_57980S_IOV), QEDE_PRIVATE_VF},
Arnd Bergmann14b84e82016-06-01 15:29:13 +0200112#endif
Yuval Mintze712d522015-10-26 11:02:27 +0200113 { 0 }
114};
115
116MODULE_DEVICE_TABLE(pci, qede_pci_tbl);
117
118static int qede_probe(struct pci_dev *pdev, const struct pci_device_id *id);
119
120#define TX_TIMEOUT (5 * HZ)
121
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +0200122/* Utilize last protocol index for XDP */
123#define XDP_PI 11
124
Yuval Mintze712d522015-10-26 11:02:27 +0200125static void qede_remove(struct pci_dev *pdev);
Mintz, Yuval14d39642016-10-31 07:14:23 +0200126static void qede_shutdown(struct pci_dev *pdev);
Sudarsana Kallurua2ec6172015-10-26 11:02:32 +0200127static void qede_link_update(void *dev, struct qed_link_output *link);
Yuval Mintze712d522015-10-26 11:02:27 +0200128
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200129/* The qede lock is used to protect driver state change and driver flows that
130 * are not reentrant.
131 */
132void __qede_lock(struct qede_dev *edev)
133{
134 mutex_lock(&edev->qede_lock);
135}
136
137void __qede_unlock(struct qede_dev *edev)
138{
139 mutex_unlock(&edev->qede_lock);
140}
141
Yuval Mintzfefb0202016-05-11 16:36:19 +0300142#ifdef CONFIG_QED_SRIOV
Moshe Shemesh79aab092016-09-22 12:11:15 +0300143static int qede_set_vf_vlan(struct net_device *ndev, int vf, u16 vlan, u8 qos,
144 __be16 vlan_proto)
Yuval Mintz08feecd2016-05-11 16:36:20 +0300145{
146 struct qede_dev *edev = netdev_priv(ndev);
147
148 if (vlan > 4095) {
149 DP_NOTICE(edev, "Illegal vlan value %d\n", vlan);
150 return -EINVAL;
151 }
152
Moshe Shemesh79aab092016-09-22 12:11:15 +0300153 if (vlan_proto != htons(ETH_P_8021Q))
154 return -EPROTONOSUPPORT;
155
Yuval Mintz08feecd2016-05-11 16:36:20 +0300156 DP_VERBOSE(edev, QED_MSG_IOV, "Setting Vlan 0x%04x to VF [%d]\n",
157 vlan, vf);
158
159 return edev->ops->iov->set_vlan(edev->cdev, vlan, vf);
160}
161
Yuval Mintzeff16962016-05-11 16:36:21 +0300162static int qede_set_vf_mac(struct net_device *ndev, int vfidx, u8 *mac)
163{
164 struct qede_dev *edev = netdev_priv(ndev);
165
166 DP_VERBOSE(edev, QED_MSG_IOV,
167 "Setting MAC %02x:%02x:%02x:%02x:%02x:%02x to VF [%d]\n",
168 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], vfidx);
169
170 if (!is_valid_ether_addr(mac)) {
171 DP_VERBOSE(edev, QED_MSG_IOV, "MAC address isn't valid\n");
172 return -EINVAL;
173 }
174
175 return edev->ops->iov->set_mac(edev->cdev, mac, vfidx);
176}
177
Yuval Mintzfefb0202016-05-11 16:36:19 +0300178static int qede_sriov_configure(struct pci_dev *pdev, int num_vfs_param)
179{
180 struct qede_dev *edev = netdev_priv(pci_get_drvdata(pdev));
Yuval Mintz831bfb0e2016-05-11 16:36:25 +0300181 struct qed_dev_info *qed_info = &edev->dev_info.common;
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +0200182 struct qed_update_vport_params *vport_params;
Yuval Mintz831bfb0e2016-05-11 16:36:25 +0300183 int rc;
Yuval Mintzfefb0202016-05-11 16:36:19 +0300184
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +0200185 vport_params = vzalloc(sizeof(*vport_params));
186 if (!vport_params)
187 return -ENOMEM;
Yuval Mintzfefb0202016-05-11 16:36:19 +0300188 DP_VERBOSE(edev, QED_MSG_IOV, "Requested %d VFs\n", num_vfs_param);
189
Yuval Mintz831bfb0e2016-05-11 16:36:25 +0300190 rc = edev->ops->iov->configure(edev->cdev, num_vfs_param);
191
192 /* Enable/Disable Tx switching for PF */
193 if ((rc == num_vfs_param) && netif_running(edev->ndev) &&
194 qed_info->mf_mode != QED_MF_NPAR && qed_info->tx_switching) {
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +0200195 vport_params->vport_id = 0;
196 vport_params->update_tx_switching_flg = 1;
197 vport_params->tx_switching_flg = num_vfs_param ? 1 : 0;
198 edev->ops->vport_update(edev->cdev, vport_params);
Yuval Mintz831bfb0e2016-05-11 16:36:25 +0300199 }
200
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +0200201 vfree(vport_params);
Yuval Mintz831bfb0e2016-05-11 16:36:25 +0300202 return rc;
Yuval Mintzfefb0202016-05-11 16:36:19 +0300203}
204#endif
205
Yuval Mintze712d522015-10-26 11:02:27 +0200206static struct pci_driver qede_pci_driver = {
207 .name = "qede",
208 .id_table = qede_pci_tbl,
209 .probe = qede_probe,
210 .remove = qede_remove,
Mintz, Yuval14d39642016-10-31 07:14:23 +0200211 .shutdown = qede_shutdown,
Yuval Mintzfefb0202016-05-11 16:36:19 +0300212#ifdef CONFIG_QED_SRIOV
213 .sriov_configure = qede_sriov_configure,
214#endif
Yuval Mintze712d522015-10-26 11:02:27 +0200215};
216
Sudarsana Kallurua2ec6172015-10-26 11:02:32 +0200217static struct qed_eth_cb_ops qede_ll_ops = {
218 {
219 .link_update = qede_link_update,
220 },
Yuval Mintzeff16962016-05-11 16:36:21 +0300221 .force_mac = qede_force_mac,
Sudarsana Kallurua2ec6172015-10-26 11:02:32 +0200222};
223
Yuval Mintz29502192015-10-26 11:02:29 +0200224static int qede_netdev_event(struct notifier_block *this, unsigned long event,
225 void *ptr)
226{
227 struct net_device *ndev = netdev_notifier_info_to_dev(ptr);
228 struct ethtool_drvinfo drvinfo;
229 struct qede_dev *edev;
230
Ram Amranicee9fbd2016-10-01 21:59:56 +0300231 if (event != NETDEV_CHANGENAME && event != NETDEV_CHANGEADDR)
Yuval Mintz29502192015-10-26 11:02:29 +0200232 goto done;
233
234 /* Check whether this is a qede device */
235 if (!ndev || !ndev->ethtool_ops || !ndev->ethtool_ops->get_drvinfo)
236 goto done;
237
238 memset(&drvinfo, 0, sizeof(drvinfo));
239 ndev->ethtool_ops->get_drvinfo(ndev, &drvinfo);
240 if (strcmp(drvinfo.driver, "qede"))
241 goto done;
242 edev = netdev_priv(ndev);
243
Ram Amranicee9fbd2016-10-01 21:59:56 +0300244 switch (event) {
245 case NETDEV_CHANGENAME:
246 /* Notify qed of the name change */
247 if (!edev->ops || !edev->ops->common)
248 goto done;
249 edev->ops->common->set_id(edev->cdev, edev->ndev->name, "qede");
250 break;
251 case NETDEV_CHANGEADDR:
252 edev = netdev_priv(ndev);
253 qede_roce_event_changeaddr(edev);
254 break;
255 }
Yuval Mintz29502192015-10-26 11:02:29 +0200256
257done:
258 return NOTIFY_DONE;
259}
260
261static struct notifier_block qede_netdev_notifier = {
262 .notifier_call = qede_netdev_event,
263};
264
Yuval Mintze712d522015-10-26 11:02:27 +0200265static
266int __init qede_init(void)
267{
268 int ret;
Yuval Mintze712d522015-10-26 11:02:27 +0200269
Yuval Mintz525ef5c2016-08-15 10:42:45 +0300270 pr_info("qede_init: %s\n", version);
Yuval Mintze712d522015-10-26 11:02:27 +0200271
Rahul Verma95114342016-04-10 12:42:59 +0300272 qed_ops = qed_get_eth_ops();
Yuval Mintze712d522015-10-26 11:02:27 +0200273 if (!qed_ops) {
274 pr_notice("Failed to get qed ethtool operations\n");
275 return -EINVAL;
276 }
277
Yuval Mintz29502192015-10-26 11:02:29 +0200278 /* Must register notifier before pci ops, since we might miss
279 * interface rename after pci probe and netdev registeration.
280 */
281 ret = register_netdevice_notifier(&qede_netdev_notifier);
282 if (ret) {
283 pr_notice("Failed to register netdevice_notifier\n");
284 qed_put_eth_ops();
285 return -EINVAL;
286 }
287
Yuval Mintze712d522015-10-26 11:02:27 +0200288 ret = pci_register_driver(&qede_pci_driver);
289 if (ret) {
290 pr_notice("Failed to register driver\n");
Yuval Mintz29502192015-10-26 11:02:29 +0200291 unregister_netdevice_notifier(&qede_netdev_notifier);
Yuval Mintze712d522015-10-26 11:02:27 +0200292 qed_put_eth_ops();
293 return -EINVAL;
294 }
295
296 return 0;
297}
298
299static void __exit qede_cleanup(void)
300{
Yuval Mintz525ef5c2016-08-15 10:42:45 +0300301 if (debug & QED_LOG_INFO_MASK)
302 pr_info("qede_cleanup called\n");
Yuval Mintze712d522015-10-26 11:02:27 +0200303
Yuval Mintz29502192015-10-26 11:02:29 +0200304 unregister_netdevice_notifier(&qede_netdev_notifier);
Yuval Mintze712d522015-10-26 11:02:27 +0200305 pci_unregister_driver(&qede_pci_driver);
306 qed_put_eth_ops();
307}
308
309module_init(qede_init);
310module_exit(qede_cleanup);
311
Yuval Mintz29502192015-10-26 11:02:29 +0200312static int qede_open(struct net_device *ndev);
313static int qede_close(struct net_device *ndev);
Sudarsana Reddy Kalluru7c1bfca2016-02-18 17:00:40 +0200314
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200315void qede_fill_by_demand_stats(struct qede_dev *edev)
316{
317 struct qed_eth_stats stats;
318
319 edev->ops->get_vport_stats(edev->cdev, &stats);
320 edev->stats.no_buff_discards = stats.no_buff_discards;
Sudarsana Reddy Kalluru1a5a3662016-08-16 10:51:01 -0400321 edev->stats.packet_too_big_discard = stats.packet_too_big_discard;
322 edev->stats.ttl0_discard = stats.ttl0_discard;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200323 edev->stats.rx_ucast_bytes = stats.rx_ucast_bytes;
324 edev->stats.rx_mcast_bytes = stats.rx_mcast_bytes;
325 edev->stats.rx_bcast_bytes = stats.rx_bcast_bytes;
326 edev->stats.rx_ucast_pkts = stats.rx_ucast_pkts;
327 edev->stats.rx_mcast_pkts = stats.rx_mcast_pkts;
328 edev->stats.rx_bcast_pkts = stats.rx_bcast_pkts;
329 edev->stats.mftag_filter_discards = stats.mftag_filter_discards;
330 edev->stats.mac_filter_discards = stats.mac_filter_discards;
331
332 edev->stats.tx_ucast_bytes = stats.tx_ucast_bytes;
333 edev->stats.tx_mcast_bytes = stats.tx_mcast_bytes;
334 edev->stats.tx_bcast_bytes = stats.tx_bcast_bytes;
335 edev->stats.tx_ucast_pkts = stats.tx_ucast_pkts;
336 edev->stats.tx_mcast_pkts = stats.tx_mcast_pkts;
337 edev->stats.tx_bcast_pkts = stats.tx_bcast_pkts;
338 edev->stats.tx_err_drop_pkts = stats.tx_err_drop_pkts;
339 edev->stats.coalesced_pkts = stats.tpa_coalesced_pkts;
340 edev->stats.coalesced_events = stats.tpa_coalesced_events;
341 edev->stats.coalesced_aborts_num = stats.tpa_aborts_num;
342 edev->stats.non_coalesced_pkts = stats.tpa_not_coalesced_pkts;
343 edev->stats.coalesced_bytes = stats.tpa_coalesced_bytes;
344
345 edev->stats.rx_64_byte_packets = stats.rx_64_byte_packets;
Yuval Mintzd4967cf2016-04-22 08:41:01 +0300346 edev->stats.rx_65_to_127_byte_packets = stats.rx_65_to_127_byte_packets;
347 edev->stats.rx_128_to_255_byte_packets =
348 stats.rx_128_to_255_byte_packets;
349 edev->stats.rx_256_to_511_byte_packets =
350 stats.rx_256_to_511_byte_packets;
351 edev->stats.rx_512_to_1023_byte_packets =
352 stats.rx_512_to_1023_byte_packets;
353 edev->stats.rx_1024_to_1518_byte_packets =
354 stats.rx_1024_to_1518_byte_packets;
355 edev->stats.rx_1519_to_1522_byte_packets =
356 stats.rx_1519_to_1522_byte_packets;
357 edev->stats.rx_1519_to_2047_byte_packets =
358 stats.rx_1519_to_2047_byte_packets;
359 edev->stats.rx_2048_to_4095_byte_packets =
360 stats.rx_2048_to_4095_byte_packets;
361 edev->stats.rx_4096_to_9216_byte_packets =
362 stats.rx_4096_to_9216_byte_packets;
363 edev->stats.rx_9217_to_16383_byte_packets =
364 stats.rx_9217_to_16383_byte_packets;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200365 edev->stats.rx_crc_errors = stats.rx_crc_errors;
366 edev->stats.rx_mac_crtl_frames = stats.rx_mac_crtl_frames;
367 edev->stats.rx_pause_frames = stats.rx_pause_frames;
368 edev->stats.rx_pfc_frames = stats.rx_pfc_frames;
369 edev->stats.rx_align_errors = stats.rx_align_errors;
370 edev->stats.rx_carrier_errors = stats.rx_carrier_errors;
371 edev->stats.rx_oversize_packets = stats.rx_oversize_packets;
372 edev->stats.rx_jabbers = stats.rx_jabbers;
373 edev->stats.rx_undersize_packets = stats.rx_undersize_packets;
374 edev->stats.rx_fragments = stats.rx_fragments;
375 edev->stats.tx_64_byte_packets = stats.tx_64_byte_packets;
376 edev->stats.tx_65_to_127_byte_packets = stats.tx_65_to_127_byte_packets;
377 edev->stats.tx_128_to_255_byte_packets =
378 stats.tx_128_to_255_byte_packets;
379 edev->stats.tx_256_to_511_byte_packets =
380 stats.tx_256_to_511_byte_packets;
381 edev->stats.tx_512_to_1023_byte_packets =
382 stats.tx_512_to_1023_byte_packets;
383 edev->stats.tx_1024_to_1518_byte_packets =
384 stats.tx_1024_to_1518_byte_packets;
385 edev->stats.tx_1519_to_2047_byte_packets =
386 stats.tx_1519_to_2047_byte_packets;
387 edev->stats.tx_2048_to_4095_byte_packets =
388 stats.tx_2048_to_4095_byte_packets;
389 edev->stats.tx_4096_to_9216_byte_packets =
390 stats.tx_4096_to_9216_byte_packets;
391 edev->stats.tx_9217_to_16383_byte_packets =
392 stats.tx_9217_to_16383_byte_packets;
393 edev->stats.tx_pause_frames = stats.tx_pause_frames;
394 edev->stats.tx_pfc_frames = stats.tx_pfc_frames;
395 edev->stats.tx_lpi_entry_count = stats.tx_lpi_entry_count;
396 edev->stats.tx_total_collisions = stats.tx_total_collisions;
397 edev->stats.brb_truncates = stats.brb_truncates;
398 edev->stats.brb_discards = stats.brb_discards;
399 edev->stats.tx_mac_ctrl_frames = stats.tx_mac_ctrl_frames;
400}
401
stephen hemmingerbc1f4472017-01-06 19:12:52 -0800402static void 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;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200433}
434
Yuval Mintz733def62016-05-11 16:36:22 +0300435#ifdef CONFIG_QED_SRIOV
Yuval Mintz73390ac2016-05-11 16:36:24 +0300436static int qede_get_vf_config(struct net_device *dev, int vfidx,
437 struct ifla_vf_info *ivi)
438{
439 struct qede_dev *edev = netdev_priv(dev);
440
441 if (!edev->ops)
442 return -EINVAL;
443
444 return edev->ops->iov->get_config(edev->cdev, vfidx, ivi);
445}
446
Yuval Mintz733def62016-05-11 16:36:22 +0300447static int qede_set_vf_rate(struct net_device *dev, int vfidx,
448 int min_tx_rate, int max_tx_rate)
449{
450 struct qede_dev *edev = netdev_priv(dev);
451
Yuval Mintzbe7b6d62016-05-26 11:01:17 +0300452 return edev->ops->iov->set_rate(edev->cdev, vfidx, min_tx_rate,
Yuval Mintz733def62016-05-11 16:36:22 +0300453 max_tx_rate);
454}
455
Yuval Mintz6ddc7602016-05-11 16:36:23 +0300456static int qede_set_vf_spoofchk(struct net_device *dev, int vfidx, bool val)
457{
458 struct qede_dev *edev = netdev_priv(dev);
459
460 if (!edev->ops)
461 return -EINVAL;
462
463 return edev->ops->iov->set_spoof(edev->cdev, vfidx, val);
464}
465
Yuval Mintz733def62016-05-11 16:36:22 +0300466static int qede_set_vf_link_state(struct net_device *dev, int vfidx,
467 int link_state)
468{
469 struct qede_dev *edev = netdev_priv(dev);
470
471 if (!edev->ops)
472 return -EINVAL;
473
474 return edev->ops->iov->set_link_state(edev->cdev, vfidx, link_state);
475}
Mintz, Yuvalf990c822017-01-01 13:57:08 +0200476
477static int qede_set_vf_trust(struct net_device *dev, int vfidx, bool setting)
478{
479 struct qede_dev *edev = netdev_priv(dev);
480
481 if (!edev->ops)
482 return -EINVAL;
483
484 return edev->ops->iov->set_trust(edev->cdev, vfidx, setting);
485}
Yuval Mintz733def62016-05-11 16:36:22 +0300486#endif
487
Sudarsana Reddy Kalluru4c552152017-02-15 10:24:11 +0200488static int qede_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
489{
490 struct qede_dev *edev = netdev_priv(dev);
491
492 if (!netif_running(dev))
493 return -EAGAIN;
494
495 switch (cmd) {
496 case SIOCSHWTSTAMP:
497 return qede_ptp_hw_ts(edev, ifr);
498 default:
499 DP_VERBOSE(edev, QED_MSG_DEBUG,
500 "default IOCTL cmd 0x%x\n", cmd);
501 return -EOPNOTSUPP;
502 }
503
504 return 0;
505}
506
Yuval Mintz29502192015-10-26 11:02:29 +0200507static const struct net_device_ops qede_netdev_ops = {
508 .ndo_open = qede_open,
509 .ndo_stop = qede_close,
510 .ndo_start_xmit = qede_start_xmit,
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +0200511 .ndo_set_rx_mode = qede_set_rx_mode,
512 .ndo_set_mac_address = qede_set_mac_addr,
Yuval Mintz29502192015-10-26 11:02:29 +0200513 .ndo_validate_addr = eth_validate_addr,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200514 .ndo_change_mtu = qede_change_mtu,
Sudarsana Reddy Kalluru4c552152017-02-15 10:24:11 +0200515 .ndo_do_ioctl = qede_ioctl,
Yuval Mintz08feecd2016-05-11 16:36:20 +0300516#ifdef CONFIG_QED_SRIOV
Yuval Mintzeff16962016-05-11 16:36:21 +0300517 .ndo_set_vf_mac = qede_set_vf_mac,
Yuval Mintz08feecd2016-05-11 16:36:20 +0300518 .ndo_set_vf_vlan = qede_set_vf_vlan,
Mintz, Yuvalf990c822017-01-01 13:57:08 +0200519 .ndo_set_vf_trust = qede_set_vf_trust,
Yuval Mintz08feecd2016-05-11 16:36:20 +0300520#endif
Sudarsana Reddy Kalluru7c1bfca2016-02-18 17:00:40 +0200521 .ndo_vlan_rx_add_vid = qede_vlan_rx_add_vid,
522 .ndo_vlan_rx_kill_vid = qede_vlan_rx_kill_vid,
Yuval Mintzce2b8852016-05-26 11:01:18 +0300523 .ndo_set_features = qede_set_features,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200524 .ndo_get_stats64 = qede_get_stats64,
Yuval Mintz733def62016-05-11 16:36:22 +0300525#ifdef CONFIG_QED_SRIOV
526 .ndo_set_vf_link_state = qede_set_vf_link_state,
Yuval Mintz6ddc7602016-05-11 16:36:23 +0300527 .ndo_set_vf_spoofchk = qede_set_vf_spoofchk,
Yuval Mintz73390ac2016-05-11 16:36:24 +0300528 .ndo_get_vf_config = qede_get_vf_config,
Yuval Mintz733def62016-05-11 16:36:22 +0300529 .ndo_set_vf_rate = qede_set_vf_rate,
530#endif
Alexander Duyckf9f082a2016-06-16 12:22:57 -0700531 .ndo_udp_tunnel_add = qede_udp_tunnel_add,
532 .ndo_udp_tunnel_del = qede_udp_tunnel_del,
Manish Chopra25695852016-10-14 05:19:19 -0400533 .ndo_features_check = qede_features_check,
Mintz, Yuval496e0512016-11-29 16:47:09 +0200534 .ndo_xdp = qede_xdp,
Yuval Mintz29502192015-10-26 11:02:29 +0200535};
536
537/* -------------------------------------------------------------------------
Yuval Mintze712d522015-10-26 11:02:27 +0200538 * START OF PROBE / REMOVE
539 * -------------------------------------------------------------------------
540 */
541
542static struct qede_dev *qede_alloc_etherdev(struct qed_dev *cdev,
543 struct pci_dev *pdev,
544 struct qed_dev_eth_info *info,
Yuval Mintz1a635e42016-08-15 10:42:43 +0300545 u32 dp_module, u8 dp_level)
Yuval Mintze712d522015-10-26 11:02:27 +0200546{
547 struct net_device *ndev;
548 struct qede_dev *edev;
549
550 ndev = alloc_etherdev_mqs(sizeof(*edev),
Yuval Mintz1a635e42016-08-15 10:42:43 +0300551 info->num_queues, info->num_queues);
Yuval Mintze712d522015-10-26 11:02:27 +0200552 if (!ndev) {
553 pr_err("etherdev allocation failed\n");
554 return NULL;
555 }
556
557 edev = netdev_priv(ndev);
558 edev->ndev = ndev;
559 edev->cdev = cdev;
560 edev->pdev = pdev;
561 edev->dp_module = dp_module;
562 edev->dp_level = dp_level;
563 edev->ops = qed_ops;
Yuval Mintz29502192015-10-26 11:02:29 +0200564 edev->q_num_rx_buffers = NUM_RX_BDS_DEF;
565 edev->q_num_tx_buffers = NUM_TX_BDS_DEF;
Yuval Mintze712d522015-10-26 11:02:27 +0200566
Yuval Mintz525ef5c2016-08-15 10:42:45 +0300567 DP_INFO(edev, "Allocated netdev with %d tx queues and %d rx queues\n",
568 info->num_queues, info->num_queues);
569
Yuval Mintze712d522015-10-26 11:02:27 +0200570 SET_NETDEV_DEV(ndev, &pdev->dev);
571
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200572 memset(&edev->stats, 0, sizeof(edev->stats));
Yuval Mintze712d522015-10-26 11:02:27 +0200573 memcpy(&edev->dev_info, info, sizeof(*info));
574
Sudarsana Reddy Kalluru7c1bfca2016-02-18 17:00:40 +0200575 INIT_LIST_HEAD(&edev->vlan_list);
576
Yuval Mintze712d522015-10-26 11:02:27 +0200577 return edev;
578}
579
580static void qede_init_ndev(struct qede_dev *edev)
581{
582 struct net_device *ndev = edev->ndev;
583 struct pci_dev *pdev = edev->pdev;
584 u32 hw_features;
585
586 pci_set_drvdata(pdev, ndev);
587
588 ndev->mem_start = edev->dev_info.common.pci_mem_start;
589 ndev->base_addr = ndev->mem_start;
590 ndev->mem_end = edev->dev_info.common.pci_mem_end;
591 ndev->irq = edev->dev_info.common.pci_irq;
592
593 ndev->watchdog_timeo = TX_TIMEOUT;
594
Yuval Mintz29502192015-10-26 11:02:29 +0200595 ndev->netdev_ops = &qede_netdev_ops;
596
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200597 qede_set_ethtool_ops(ndev);
598
Mintz, Yuval0183eb12016-10-31 22:26:53 +0200599 ndev->priv_flags |= IFF_UNICAST_FLT;
Yuval Mintz7b7e70f2016-10-14 05:19:20 -0400600
Yuval Mintze712d522015-10-26 11:02:27 +0200601 /* user-changeble features */
602 hw_features = NETIF_F_GRO | NETIF_F_SG |
603 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
604 NETIF_F_TSO | NETIF_F_TSO6;
605
Manish Chopra14db81d2016-04-14 01:38:33 -0400606 /* Encap features*/
607 hw_features |= NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL |
Manish Chopraa1502412016-10-14 05:19:18 -0400608 NETIF_F_TSO_ECN | NETIF_F_GSO_UDP_TUNNEL_CSUM |
609 NETIF_F_GSO_GRE_CSUM;
Manish Chopra14db81d2016-04-14 01:38:33 -0400610 ndev->hw_enc_features = NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
611 NETIF_F_SG | NETIF_F_TSO | NETIF_F_TSO_ECN |
612 NETIF_F_TSO6 | NETIF_F_GSO_GRE |
Manish Chopraa1502412016-10-14 05:19:18 -0400613 NETIF_F_GSO_UDP_TUNNEL | NETIF_F_RXCSUM |
614 NETIF_F_GSO_UDP_TUNNEL_CSUM |
615 NETIF_F_GSO_GRE_CSUM;
Manish Chopra14db81d2016-04-14 01:38:33 -0400616
Yuval Mintze712d522015-10-26 11:02:27 +0200617 ndev->vlan_features = hw_features | NETIF_F_RXHASH | NETIF_F_RXCSUM |
618 NETIF_F_HIGHDMA;
619 ndev->features = hw_features | NETIF_F_RXHASH | NETIF_F_RXCSUM |
620 NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HIGHDMA |
Sudarsana Reddy Kalluru7c1bfca2016-02-18 17:00:40 +0200621 NETIF_F_HW_VLAN_CTAG_FILTER | NETIF_F_HW_VLAN_CTAG_TX;
Yuval Mintze712d522015-10-26 11:02:27 +0200622
623 ndev->hw_features = hw_features;
624
Jarod Wilsoncaff2a82016-10-17 15:54:08 -0400625 /* MTU range: 46 - 9600 */
626 ndev->min_mtu = ETH_ZLEN - ETH_HLEN;
627 ndev->max_mtu = QEDE_MAX_JUMBO_PACKET_SIZE;
628
Yuval Mintze712d522015-10-26 11:02:27 +0200629 /* Set network device HW mac */
630 ether_addr_copy(edev->ndev->dev_addr, edev->dev_info.common.hw_mac);
Sudarsana Kalluru0fefbfb2016-10-31 07:14:21 +0200631
632 ndev->mtu = edev->dev_info.common.mtu;
Yuval Mintze712d522015-10-26 11:02:27 +0200633}
634
635/* This function converts from 32b param to two params of level and module
636 * Input 32b decoding:
637 * b31 - enable all NOTICE prints. NOTICE prints are for deviation from the
638 * 'happy' flow, e.g. memory allocation failed.
639 * b30 - enable all INFO prints. INFO prints are for major steps in the flow
640 * and provide important parameters.
641 * b29-b0 - per-module bitmap, where each bit enables VERBOSE prints of that
642 * module. VERBOSE prints are for tracking the specific flow in low level.
643 *
644 * Notice that the level should be that of the lowest required logs.
645 */
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200646void qede_config_debug(uint debug, u32 *p_dp_module, u8 *p_dp_level)
Yuval Mintze712d522015-10-26 11:02:27 +0200647{
648 *p_dp_level = QED_LEVEL_NOTICE;
649 *p_dp_module = 0;
650
651 if (debug & QED_LOG_VERBOSE_MASK) {
652 *p_dp_level = QED_LEVEL_VERBOSE;
653 *p_dp_module = (debug & 0x3FFFFFFF);
654 } else if (debug & QED_LOG_INFO_MASK) {
655 *p_dp_level = QED_LEVEL_INFO;
656 } else if (debug & QED_LOG_NOTICE_MASK) {
657 *p_dp_level = QED_LEVEL_NOTICE;
658 }
659}
660
Yuval Mintz29502192015-10-26 11:02:29 +0200661static void qede_free_fp_array(struct qede_dev *edev)
662{
663 if (edev->fp_array) {
664 struct qede_fastpath *fp;
665 int i;
666
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400667 for_each_queue(i) {
Yuval Mintz29502192015-10-26 11:02:29 +0200668 fp = &edev->fp_array[i];
669
670 kfree(fp->sb_info);
671 kfree(fp->rxq);
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +0200672 kfree(fp->xdp_tx);
Mintz, Yuval80439a12016-11-29 16:47:02 +0200673 kfree(fp->txq);
Yuval Mintz29502192015-10-26 11:02:29 +0200674 }
675 kfree(edev->fp_array);
676 }
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400677
678 edev->num_queues = 0;
679 edev->fp_num_tx = 0;
680 edev->fp_num_rx = 0;
Yuval Mintz29502192015-10-26 11:02:29 +0200681}
682
683static int qede_alloc_fp_array(struct qede_dev *edev)
684{
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400685 u8 fp_combined, fp_rx = edev->fp_num_rx;
Yuval Mintz29502192015-10-26 11:02:29 +0200686 struct qede_fastpath *fp;
687 int i;
688
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400689 edev->fp_array = kcalloc(QEDE_QUEUE_CNT(edev),
Yuval Mintz29502192015-10-26 11:02:29 +0200690 sizeof(*edev->fp_array), GFP_KERNEL);
691 if (!edev->fp_array) {
692 DP_NOTICE(edev, "fp array allocation failed\n");
693 goto err;
694 }
695
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400696 fp_combined = QEDE_QUEUE_CNT(edev) - fp_rx - edev->fp_num_tx;
697
698 /* Allocate the FP elements for Rx queues followed by combined and then
699 * the Tx. This ordering should be maintained so that the respective
700 * queues (Rx or Tx) will be together in the fastpath array and the
701 * associated ids will be sequential.
702 */
703 for_each_queue(i) {
Yuval Mintz29502192015-10-26 11:02:29 +0200704 fp = &edev->fp_array[i];
705
Mintz, Yuval80439a12016-11-29 16:47:02 +0200706 fp->sb_info = kzalloc(sizeof(*fp->sb_info), GFP_KERNEL);
Yuval Mintz29502192015-10-26 11:02:29 +0200707 if (!fp->sb_info) {
708 DP_NOTICE(edev, "sb info struct allocation failed\n");
709 goto err;
710 }
711
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400712 if (fp_rx) {
713 fp->type = QEDE_FASTPATH_RX;
714 fp_rx--;
715 } else if (fp_combined) {
716 fp->type = QEDE_FASTPATH_COMBINED;
717 fp_combined--;
718 } else {
719 fp->type = QEDE_FASTPATH_TX;
Yuval Mintz29502192015-10-26 11:02:29 +0200720 }
721
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400722 if (fp->type & QEDE_FASTPATH_TX) {
Mintz, Yuval80439a12016-11-29 16:47:02 +0200723 fp->txq = kzalloc(sizeof(*fp->txq), GFP_KERNEL);
724 if (!fp->txq)
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400725 goto err;
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400726 }
727
728 if (fp->type & QEDE_FASTPATH_RX) {
Mintz, Yuval80439a12016-11-29 16:47:02 +0200729 fp->rxq = kzalloc(sizeof(*fp->rxq), GFP_KERNEL);
730 if (!fp->rxq)
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400731 goto err;
Mintz, Yuval496e0512016-11-29 16:47:09 +0200732
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +0200733 if (edev->xdp_prog) {
734 fp->xdp_tx = kzalloc(sizeof(*fp->xdp_tx),
735 GFP_KERNEL);
736 if (!fp->xdp_tx)
737 goto err;
Mintz, Yuval496e0512016-11-29 16:47:09 +0200738 fp->type |= QEDE_FASTPATH_XDP;
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +0200739 }
Yuval Mintz29502192015-10-26 11:02:29 +0200740 }
741 }
742
743 return 0;
744err:
745 qede_free_fp_array(edev);
746 return -ENOMEM;
747}
748
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +0200749static void qede_sp_task(struct work_struct *work)
750{
751 struct qede_dev *edev = container_of(work, struct qede_dev,
752 sp_task.work);
Manish Choprab18e1702016-04-14 01:38:30 -0400753 struct qed_dev *cdev = edev->cdev;
754
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200755 __qede_lock(edev);
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +0200756
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200757 if (test_and_clear_bit(QEDE_SP_RX_MODE, &edev->sp_flags))
758 if (edev->state == QEDE_STATE_OPEN)
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +0200759 qede_config_rx_mode(edev->ndev);
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +0200760
Manish Choprab18e1702016-04-14 01:38:30 -0400761 if (test_and_clear_bit(QEDE_SP_VXLAN_PORT_CONFIG, &edev->sp_flags)) {
762 struct qed_tunn_params tunn_params;
763
764 memset(&tunn_params, 0, sizeof(tunn_params));
765 tunn_params.update_vxlan_port = 1;
766 tunn_params.vxlan_port = edev->vxlan_dst_port;
767 qed_ops->tunn_config(cdev, &tunn_params);
768 }
769
Manish Chopra9a109dd2016-04-14 01:38:31 -0400770 if (test_and_clear_bit(QEDE_SP_GENEVE_PORT_CONFIG, &edev->sp_flags)) {
771 struct qed_tunn_params tunn_params;
772
773 memset(&tunn_params, 0, sizeof(tunn_params));
774 tunn_params.update_geneve_port = 1;
775 tunn_params.geneve_port = edev->geneve_dst_port;
776 qed_ops->tunn_config(cdev, &tunn_params);
777 }
778
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200779 __qede_unlock(edev);
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +0200780}
781
Yuval Mintze712d522015-10-26 11:02:27 +0200782static void qede_update_pf_params(struct qed_dev *cdev)
783{
784 struct qed_pf_params pf_params;
785
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +0200786 /* 64 rx + 64 tx + 64 XDP */
Yuval Mintze712d522015-10-26 11:02:27 +0200787 memset(&pf_params, 0, sizeof(struct qed_pf_params));
Mintz, Yuvale1d32ac2017-01-01 13:57:03 +0200788 pf_params.eth_pf_params.num_cons = (MAX_SB_PER_PF_MIMD - 1) * 3;
Yuval Mintze712d522015-10-26 11:02:27 +0200789 qed_ops->common->update_pf_params(cdev, &pf_params);
790}
791
792enum qede_probe_mode {
793 QEDE_PROBE_NORMAL,
794};
795
796static int __qede_probe(struct pci_dev *pdev, u32 dp_module, u8 dp_level,
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300797 bool is_vf, enum qede_probe_mode mode)
Yuval Mintze712d522015-10-26 11:02:27 +0200798{
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300799 struct qed_probe_params probe_params;
Yuval Mintz1a635e42016-08-15 10:42:43 +0300800 struct qed_slowpath_params sp_params;
Yuval Mintze712d522015-10-26 11:02:27 +0200801 struct qed_dev_eth_info dev_info;
802 struct qede_dev *edev;
803 struct qed_dev *cdev;
804 int rc;
805
806 if (unlikely(dp_level & QED_LEVEL_INFO))
807 pr_notice("Starting qede probe\n");
808
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300809 memset(&probe_params, 0, sizeof(probe_params));
810 probe_params.protocol = QED_PROTOCOL_ETH;
811 probe_params.dp_module = dp_module;
812 probe_params.dp_level = dp_level;
813 probe_params.is_vf = is_vf;
814 cdev = qed_ops->common->probe(pdev, &probe_params);
Yuval Mintze712d522015-10-26 11:02:27 +0200815 if (!cdev) {
816 rc = -ENODEV;
817 goto err0;
818 }
819
820 qede_update_pf_params(cdev);
821
822 /* Start the Slowpath-process */
Yuval Mintz1a635e42016-08-15 10:42:43 +0300823 memset(&sp_params, 0, sizeof(sp_params));
824 sp_params.int_mode = QED_INT_MODE_MSIX;
825 sp_params.drv_major = QEDE_MAJOR_VERSION;
826 sp_params.drv_minor = QEDE_MINOR_VERSION;
827 sp_params.drv_rev = QEDE_REVISION_VERSION;
828 sp_params.drv_eng = QEDE_ENGINEERING_VERSION;
829 strlcpy(sp_params.name, "qede LAN", QED_DRV_VER_STR_SIZE);
830 rc = qed_ops->common->slowpath_start(cdev, &sp_params);
Yuval Mintze712d522015-10-26 11:02:27 +0200831 if (rc) {
832 pr_notice("Cannot start slowpath\n");
833 goto err1;
834 }
835
836 /* Learn information crucial for qede to progress */
837 rc = qed_ops->fill_dev_info(cdev, &dev_info);
838 if (rc)
839 goto err2;
840
841 edev = qede_alloc_etherdev(cdev, pdev, &dev_info, dp_module,
842 dp_level);
843 if (!edev) {
844 rc = -ENOMEM;
845 goto err2;
846 }
847
Yuval Mintzfefb0202016-05-11 16:36:19 +0300848 if (is_vf)
849 edev->flags |= QEDE_FLAG_IS_VF;
850
Yuval Mintze712d522015-10-26 11:02:27 +0200851 qede_init_ndev(edev);
852
Ram Amranicee9fbd2016-10-01 21:59:56 +0300853 rc = qede_roce_dev_add(edev);
854 if (rc)
855 goto err3;
856
Mintz, Yuval0e0b80a2017-02-20 22:43:34 +0200857 /* Prepare the lock prior to the registeration of the netdev,
858 * as once it's registered we might reach flows requiring it
859 * [it's even possible to reach a flow needing it directly
860 * from there, although it's unlikely].
861 */
862 INIT_DELAYED_WORK(&edev->sp_task, qede_sp_task);
863 mutex_init(&edev->qede_lock);
Yuval Mintz29502192015-10-26 11:02:29 +0200864 rc = register_netdev(edev->ndev);
865 if (rc) {
866 DP_NOTICE(edev, "Cannot register net-device\n");
Ram Amranicee9fbd2016-10-01 21:59:56 +0300867 goto err4;
Yuval Mintz29502192015-10-26 11:02:29 +0200868 }
869
Yuval Mintze712d522015-10-26 11:02:27 +0200870 edev->ops->common->set_id(cdev, edev->ndev->name, DRV_MODULE_VERSION);
871
Sudarsana Reddy Kalluru4c552152017-02-15 10:24:11 +0200872 /* PTP not supported on VFs */
873 if (!is_vf) {
874 rc = qede_ptp_register_phc(edev);
875 if (rc) {
876 DP_NOTICE(edev, "Cannot register PHC\n");
877 goto err5;
878 }
879 }
880
Sudarsana Kallurua2ec6172015-10-26 11:02:32 +0200881 edev->ops->register_ops(cdev, &qede_ll_ops, edev);
882
Sudarsana Reddy Kalluru489e45a2016-06-08 06:22:12 -0400883#ifdef CONFIG_DCB
Sudarsana Reddy Kalluru5fe118c2016-08-29 08:29:52 -0400884 if (!IS_VF(edev))
885 qede_set_dcbnl_ops(edev->ndev);
Sudarsana Reddy Kalluru489e45a2016-06-08 06:22:12 -0400886#endif
887
Manish Chopra3d789992016-06-30 02:35:21 -0400888 edev->rx_copybreak = QEDE_RX_HDR_SIZE;
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +0200889
Yuval Mintze712d522015-10-26 11:02:27 +0200890 DP_INFO(edev, "Ending successfully qede probe\n");
891
892 return 0;
893
Sudarsana Reddy Kalluru4c552152017-02-15 10:24:11 +0200894err5:
895 unregister_netdev(edev->ndev);
Ram Amranicee9fbd2016-10-01 21:59:56 +0300896err4:
897 qede_roce_dev_remove(edev);
Yuval Mintz29502192015-10-26 11:02:29 +0200898err3:
899 free_netdev(edev->ndev);
Yuval Mintze712d522015-10-26 11:02:27 +0200900err2:
901 qed_ops->common->slowpath_stop(cdev);
902err1:
903 qed_ops->common->remove(cdev);
904err0:
905 return rc;
906}
907
908static int qede_probe(struct pci_dev *pdev, const struct pci_device_id *id)
909{
Yuval Mintzfefb0202016-05-11 16:36:19 +0300910 bool is_vf = false;
Yuval Mintze712d522015-10-26 11:02:27 +0200911 u32 dp_module = 0;
912 u8 dp_level = 0;
913
Yuval Mintzfefb0202016-05-11 16:36:19 +0300914 switch ((enum qede_pci_private)id->driver_data) {
915 case QEDE_PRIVATE_VF:
916 if (debug & QED_LOG_VERBOSE_MASK)
917 dev_err(&pdev->dev, "Probing a VF\n");
918 is_vf = true;
919 break;
920 default:
921 if (debug & QED_LOG_VERBOSE_MASK)
922 dev_err(&pdev->dev, "Probing a PF\n");
923 }
924
Yuval Mintze712d522015-10-26 11:02:27 +0200925 qede_config_debug(debug, &dp_module, &dp_level);
926
Yuval Mintzfefb0202016-05-11 16:36:19 +0300927 return __qede_probe(pdev, dp_module, dp_level, is_vf,
Yuval Mintze712d522015-10-26 11:02:27 +0200928 QEDE_PROBE_NORMAL);
929}
930
931enum qede_remove_mode {
932 QEDE_REMOVE_NORMAL,
933};
934
935static void __qede_remove(struct pci_dev *pdev, enum qede_remove_mode mode)
936{
937 struct net_device *ndev = pci_get_drvdata(pdev);
938 struct qede_dev *edev = netdev_priv(ndev);
939 struct qed_dev *cdev = edev->cdev;
940
941 DP_INFO(edev, "Starting qede_remove\n");
942
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +0200943 cancel_delayed_work_sync(&edev->sp_task);
Ram Amranicee9fbd2016-10-01 21:59:56 +0300944
Yuval Mintz29502192015-10-26 11:02:29 +0200945 unregister_netdev(ndev);
946
Sudarsana Reddy Kalluru4c552152017-02-15 10:24:11 +0200947 qede_ptp_remove(edev);
948
Ram Amranicee9fbd2016-10-01 21:59:56 +0300949 qede_roce_dev_remove(edev);
950
Yuval Mintze712d522015-10-26 11:02:27 +0200951 edev->ops->common->set_power_state(cdev, PCI_D0);
952
953 pci_set_drvdata(pdev, NULL);
954
Mintz, Yuval496e0512016-11-29 16:47:09 +0200955 /* Release edev's reference to XDP's bpf if such exist */
956 if (edev->xdp_prog)
957 bpf_prog_put(edev->xdp_prog);
958
Yuval Mintze712d522015-10-26 11:02:27 +0200959 free_netdev(ndev);
960
961 /* Use global ops since we've freed edev */
962 qed_ops->common->slowpath_stop(cdev);
Mintz, Yuval14d39642016-10-31 07:14:23 +0200963 if (system_state == SYSTEM_POWER_OFF)
964 return;
Yuval Mintze712d522015-10-26 11:02:27 +0200965 qed_ops->common->remove(cdev);
966
Yuval Mintz525ef5c2016-08-15 10:42:45 +0300967 dev_info(&pdev->dev, "Ending qede_remove successfully\n");
Yuval Mintze712d522015-10-26 11:02:27 +0200968}
969
970static void qede_remove(struct pci_dev *pdev)
971{
972 __qede_remove(pdev, QEDE_REMOVE_NORMAL);
973}
Yuval Mintz29502192015-10-26 11:02:29 +0200974
Mintz, Yuval14d39642016-10-31 07:14:23 +0200975static void qede_shutdown(struct pci_dev *pdev)
976{
977 __qede_remove(pdev, QEDE_REMOVE_NORMAL);
978}
979
Yuval Mintz29502192015-10-26 11:02:29 +0200980/* -------------------------------------------------------------------------
981 * START OF LOAD / UNLOAD
982 * -------------------------------------------------------------------------
983 */
984
985static int qede_set_num_queues(struct qede_dev *edev)
986{
987 int rc;
988 u16 rss_num;
989
990 /* Setup queues according to possible resources*/
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400991 if (edev->req_queues)
992 rss_num = edev->req_queues;
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200993 else
994 rss_num = netif_get_num_default_rss_queues() *
995 edev->dev_info.common.num_hwfns;
Yuval Mintz29502192015-10-26 11:02:29 +0200996
997 rss_num = min_t(u16, QEDE_MAX_RSS_CNT(edev), rss_num);
998
999 rc = edev->ops->common->set_fp_int(edev->cdev, rss_num);
1000 if (rc > 0) {
1001 /* Managed to request interrupts for our queues */
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001002 edev->num_queues = rc;
Yuval Mintz29502192015-10-26 11:02:29 +02001003 DP_INFO(edev, "Managed %d [of %d] RSS queues\n",
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001004 QEDE_QUEUE_CNT(edev), rss_num);
Yuval Mintz29502192015-10-26 11:02:29 +02001005 rc = 0;
1006 }
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001007
1008 edev->fp_num_tx = edev->req_num_tx;
1009 edev->fp_num_rx = edev->req_num_rx;
1010
Yuval Mintz29502192015-10-26 11:02:29 +02001011 return rc;
1012}
1013
1014static void qede_free_mem_sb(struct qede_dev *edev,
1015 struct qed_sb_info *sb_info)
1016{
1017 if (sb_info->sb_virt)
1018 dma_free_coherent(&edev->pdev->dev, sizeof(*sb_info->sb_virt),
1019 (void *)sb_info->sb_virt, sb_info->sb_phys);
1020}
1021
1022/* This function allocates fast-path status block memory */
1023static int qede_alloc_mem_sb(struct qede_dev *edev,
Yuval Mintz1a635e42016-08-15 10:42:43 +03001024 struct qed_sb_info *sb_info, u16 sb_id)
Yuval Mintz29502192015-10-26 11:02:29 +02001025{
1026 struct status_block *sb_virt;
1027 dma_addr_t sb_phys;
1028 int rc;
1029
1030 sb_virt = dma_alloc_coherent(&edev->pdev->dev,
Yuval Mintz1a635e42016-08-15 10:42:43 +03001031 sizeof(*sb_virt), &sb_phys, GFP_KERNEL);
Yuval Mintz29502192015-10-26 11:02:29 +02001032 if (!sb_virt) {
1033 DP_ERR(edev, "Status block allocation failed\n");
1034 return -ENOMEM;
1035 }
1036
1037 rc = edev->ops->common->sb_init(edev->cdev, sb_info,
1038 sb_virt, sb_phys, sb_id,
1039 QED_SB_TYPE_L2_QUEUE);
1040 if (rc) {
1041 DP_ERR(edev, "Status block initialization failed\n");
1042 dma_free_coherent(&edev->pdev->dev, sizeof(*sb_virt),
1043 sb_virt, sb_phys);
1044 return rc;
1045 }
1046
1047 return 0;
1048}
1049
1050static void qede_free_rx_buffers(struct qede_dev *edev,
1051 struct qede_rx_queue *rxq)
1052{
1053 u16 i;
1054
1055 for (i = rxq->sw_rx_cons; i != rxq->sw_rx_prod; i++) {
1056 struct sw_rx_data *rx_buf;
Yuval Mintzfc48b7a2016-02-15 13:22:35 -05001057 struct page *data;
Yuval Mintz29502192015-10-26 11:02:29 +02001058
1059 rx_buf = &rxq->sw_rx_ring[i & NUM_RX_BDS_MAX];
1060 data = rx_buf->data;
1061
Yuval Mintzfc48b7a2016-02-15 13:22:35 -05001062 dma_unmap_page(&edev->pdev->dev,
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001063 rx_buf->mapping, PAGE_SIZE, rxq->data_direction);
Yuval Mintz29502192015-10-26 11:02:29 +02001064
1065 rx_buf->data = NULL;
Yuval Mintzfc48b7a2016-02-15 13:22:35 -05001066 __free_page(data);
Yuval Mintz29502192015-10-26 11:02:29 +02001067 }
1068}
1069
Yuval Mintz1a635e42016-08-15 10:42:43 +03001070static void qede_free_sge_mem(struct qede_dev *edev, struct qede_rx_queue *rxq)
1071{
Manish Chopra55482ed2016-03-04 12:35:06 -05001072 int i;
1073
1074 if (edev->gro_disable)
1075 return;
1076
1077 for (i = 0; i < ETH_TPA_MAX_AGGS_NUM; i++) {
1078 struct qede_agg_info *tpa_info = &rxq->tpa_info[i];
Mintz, Yuval01e23012016-11-29 16:47:00 +02001079 struct sw_rx_data *replace_buf = &tpa_info->buffer;
Manish Chopra55482ed2016-03-04 12:35:06 -05001080
Manish Chopraf86af2d2016-04-20 03:03:27 -04001081 if (replace_buf->data) {
Manish Chopra55482ed2016-03-04 12:35:06 -05001082 dma_unmap_page(&edev->pdev->dev,
Manish Chopra09ec8e72016-05-18 07:43:57 -04001083 replace_buf->mapping,
Manish Chopra55482ed2016-03-04 12:35:06 -05001084 PAGE_SIZE, DMA_FROM_DEVICE);
1085 __free_page(replace_buf->data);
1086 }
1087 }
1088}
1089
Yuval Mintz1a635e42016-08-15 10:42:43 +03001090static void qede_free_mem_rxq(struct qede_dev *edev, struct qede_rx_queue *rxq)
Yuval Mintz29502192015-10-26 11:02:29 +02001091{
Manish Chopra55482ed2016-03-04 12:35:06 -05001092 qede_free_sge_mem(edev, rxq);
1093
Yuval Mintz29502192015-10-26 11:02:29 +02001094 /* Free rx buffers */
1095 qede_free_rx_buffers(edev, rxq);
1096
1097 /* Free the parallel SW ring */
1098 kfree(rxq->sw_rx_ring);
1099
1100 /* Free the real RQ ring used by FW */
1101 edev->ops->common->chain_free(edev->cdev, &rxq->rx_bd_ring);
1102 edev->ops->common->chain_free(edev->cdev, &rxq->rx_comp_ring);
1103}
1104
Yuval Mintz1a635e42016-08-15 10:42:43 +03001105static int qede_alloc_sge_mem(struct qede_dev *edev, struct qede_rx_queue *rxq)
Manish Chopra55482ed2016-03-04 12:35:06 -05001106{
1107 dma_addr_t mapping;
1108 int i;
1109
Mintz, Yuval496e0512016-11-29 16:47:09 +02001110 /* Don't perform FW aggregations in case of XDP */
1111 if (edev->xdp_prog)
1112 edev->gro_disable = 1;
1113
Manish Chopra55482ed2016-03-04 12:35:06 -05001114 if (edev->gro_disable)
1115 return 0;
1116
1117 if (edev->ndev->mtu > PAGE_SIZE) {
1118 edev->gro_disable = 1;
1119 return 0;
1120 }
1121
1122 for (i = 0; i < ETH_TPA_MAX_AGGS_NUM; i++) {
1123 struct qede_agg_info *tpa_info = &rxq->tpa_info[i];
Mintz, Yuval01e23012016-11-29 16:47:00 +02001124 struct sw_rx_data *replace_buf = &tpa_info->buffer;
Manish Chopra55482ed2016-03-04 12:35:06 -05001125
1126 replace_buf->data = alloc_pages(GFP_ATOMIC, 0);
1127 if (unlikely(!replace_buf->data)) {
1128 DP_NOTICE(edev,
1129 "Failed to allocate TPA skb pool [replacement buffer]\n");
1130 goto err;
1131 }
1132
1133 mapping = dma_map_page(&edev->pdev->dev, replace_buf->data, 0,
Mintz, Yuval95129252016-11-02 16:36:46 +02001134 PAGE_SIZE, DMA_FROM_DEVICE);
Manish Chopra55482ed2016-03-04 12:35:06 -05001135 if (unlikely(dma_mapping_error(&edev->pdev->dev, mapping))) {
1136 DP_NOTICE(edev,
1137 "Failed to map TPA replacement buffer\n");
1138 goto err;
1139 }
1140
Manish Chopra09ec8e72016-05-18 07:43:57 -04001141 replace_buf->mapping = mapping;
Mintz, Yuval01e23012016-11-29 16:47:00 +02001142 tpa_info->buffer.page_offset = 0;
1143 tpa_info->buffer_mapping = mapping;
1144 tpa_info->state = QEDE_AGG_STATE_NONE;
Manish Chopra55482ed2016-03-04 12:35:06 -05001145 }
1146
1147 return 0;
1148err:
1149 qede_free_sge_mem(edev, rxq);
1150 edev->gro_disable = 1;
1151 return -ENOMEM;
1152}
1153
Yuval Mintz29502192015-10-26 11:02:29 +02001154/* This function allocates all memory needed per Rx queue */
Yuval Mintz1a635e42016-08-15 10:42:43 +03001155static int qede_alloc_mem_rxq(struct qede_dev *edev, struct qede_rx_queue *rxq)
Yuval Mintz29502192015-10-26 11:02:29 +02001156{
Manish Chopraf86af2d2016-04-20 03:03:27 -04001157 int i, rc, size;
Yuval Mintz29502192015-10-26 11:02:29 +02001158
1159 rxq->num_rx_buffers = edev->q_num_rx_buffers;
1160
Yuval Mintz1a635e42016-08-15 10:42:43 +03001161 rxq->rx_buf_size = NET_IP_ALIGN + ETH_OVERHEAD + edev->ndev->mtu;
1162
Yuval Mintzfc48b7a2016-02-15 13:22:35 -05001163 if (rxq->rx_buf_size > PAGE_SIZE)
1164 rxq->rx_buf_size = PAGE_SIZE;
1165
Mintz, Yuval496e0512016-11-29 16:47:09 +02001166 /* Segment size to spilt a page in multiple equal parts,
1167 * unless XDP is used in which case we'd use the entire page.
1168 */
1169 if (!edev->xdp_prog)
1170 rxq->rx_buf_seg_size = roundup_pow_of_two(rxq->rx_buf_size);
1171 else
1172 rxq->rx_buf_seg_size = PAGE_SIZE;
Yuval Mintz29502192015-10-26 11:02:29 +02001173
1174 /* Allocate the parallel driver ring for Rx buffers */
Yuval Mintzfc48b7a2016-02-15 13:22:35 -05001175 size = sizeof(*rxq->sw_rx_ring) * RX_RING_SIZE;
Yuval Mintz29502192015-10-26 11:02:29 +02001176 rxq->sw_rx_ring = kzalloc(size, GFP_KERNEL);
1177 if (!rxq->sw_rx_ring) {
1178 DP_ERR(edev, "Rx buffers ring allocation failed\n");
Manish Chopraf86af2d2016-04-20 03:03:27 -04001179 rc = -ENOMEM;
Yuval Mintz29502192015-10-26 11:02:29 +02001180 goto err;
1181 }
1182
1183 /* Allocate FW Rx ring */
1184 rc = edev->ops->common->chain_alloc(edev->cdev,
1185 QED_CHAIN_USE_TO_CONSUME_PRODUCE,
1186 QED_CHAIN_MODE_NEXT_PTR,
Yuval Mintza91eb522016-06-03 14:35:32 +03001187 QED_CHAIN_CNT_TYPE_U16,
Yuval Mintzfc48b7a2016-02-15 13:22:35 -05001188 RX_RING_SIZE,
Yuval Mintz29502192015-10-26 11:02:29 +02001189 sizeof(struct eth_rx_bd),
1190 &rxq->rx_bd_ring);
1191
1192 if (rc)
1193 goto err;
1194
1195 /* Allocate FW completion ring */
1196 rc = edev->ops->common->chain_alloc(edev->cdev,
1197 QED_CHAIN_USE_TO_CONSUME,
1198 QED_CHAIN_MODE_PBL,
Yuval Mintza91eb522016-06-03 14:35:32 +03001199 QED_CHAIN_CNT_TYPE_U16,
Yuval Mintzfc48b7a2016-02-15 13:22:35 -05001200 RX_RING_SIZE,
Yuval Mintz29502192015-10-26 11:02:29 +02001201 sizeof(union eth_rx_cqe),
1202 &rxq->rx_comp_ring);
1203 if (rc)
1204 goto err;
1205
1206 /* Allocate buffers for the Rx ring */
Mintz, Yuvale3eef7e2017-01-01 13:57:04 +02001207 rxq->filled_buffers = 0;
Yuval Mintz29502192015-10-26 11:02:29 +02001208 for (i = 0; i < rxq->num_rx_buffers; i++) {
Mintz, Yuvale3eef7e2017-01-01 13:57:04 +02001209 rc = qede_alloc_rx_buffer(rxq, false);
Manish Chopraf86af2d2016-04-20 03:03:27 -04001210 if (rc) {
1211 DP_ERR(edev,
1212 "Rx buffers allocation failed at index %d\n", i);
1213 goto err;
1214 }
Yuval Mintz29502192015-10-26 11:02:29 +02001215 }
1216
Manish Chopraf86af2d2016-04-20 03:03:27 -04001217 rc = qede_alloc_sge_mem(edev, rxq);
Yuval Mintz29502192015-10-26 11:02:29 +02001218err:
Manish Chopraf86af2d2016-04-20 03:03:27 -04001219 return rc;
Yuval Mintz29502192015-10-26 11:02:29 +02001220}
1221
Yuval Mintz1a635e42016-08-15 10:42:43 +03001222static void qede_free_mem_txq(struct qede_dev *edev, struct qede_tx_queue *txq)
Yuval Mintz29502192015-10-26 11:02:29 +02001223{
1224 /* Free the parallel SW ring */
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001225 if (txq->is_xdp)
1226 kfree(txq->sw_tx_ring.pages);
1227 else
1228 kfree(txq->sw_tx_ring.skbs);
Yuval Mintz29502192015-10-26 11:02:29 +02001229
1230 /* Free the real RQ ring used by FW */
1231 edev->ops->common->chain_free(edev->cdev, &txq->tx_pbl);
1232}
1233
1234/* This function allocates all memory needed per Tx queue */
Yuval Mintz1a635e42016-08-15 10:42:43 +03001235static int qede_alloc_mem_txq(struct qede_dev *edev, struct qede_tx_queue *txq)
Yuval Mintz29502192015-10-26 11:02:29 +02001236{
Yuval Mintz29502192015-10-26 11:02:29 +02001237 union eth_tx_bd_types *p_virt;
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001238 int size, rc;
Yuval Mintz29502192015-10-26 11:02:29 +02001239
1240 txq->num_tx_buffers = edev->q_num_tx_buffers;
1241
1242 /* Allocate the parallel driver ring for Tx buffers */
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001243 if (txq->is_xdp) {
1244 size = sizeof(*txq->sw_tx_ring.pages) * TX_RING_SIZE;
1245 txq->sw_tx_ring.pages = kzalloc(size, GFP_KERNEL);
1246 if (!txq->sw_tx_ring.pages)
1247 goto err;
1248 } else {
1249 size = sizeof(*txq->sw_tx_ring.skbs) * TX_RING_SIZE;
1250 txq->sw_tx_ring.skbs = kzalloc(size, GFP_KERNEL);
1251 if (!txq->sw_tx_ring.skbs)
1252 goto err;
Yuval Mintz29502192015-10-26 11:02:29 +02001253 }
1254
1255 rc = edev->ops->common->chain_alloc(edev->cdev,
1256 QED_CHAIN_USE_TO_CONSUME_PRODUCE,
1257 QED_CHAIN_MODE_PBL,
Yuval Mintza91eb522016-06-03 14:35:32 +03001258 QED_CHAIN_CNT_TYPE_U16,
Mintz, Yuval087892d2016-10-29 17:04:35 +03001259 TX_RING_SIZE,
Yuval Mintza91eb522016-06-03 14:35:32 +03001260 sizeof(*p_virt), &txq->tx_pbl);
Yuval Mintz29502192015-10-26 11:02:29 +02001261 if (rc)
1262 goto err;
1263
1264 return 0;
1265
1266err:
1267 qede_free_mem_txq(edev, txq);
1268 return -ENOMEM;
1269}
1270
1271/* This function frees all memory of a single fp */
Yuval Mintz1a635e42016-08-15 10:42:43 +03001272static void qede_free_mem_fp(struct qede_dev *edev, struct qede_fastpath *fp)
Yuval Mintz29502192015-10-26 11:02:29 +02001273{
Yuval Mintz29502192015-10-26 11:02:29 +02001274 qede_free_mem_sb(edev, fp->sb_info);
1275
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001276 if (fp->type & QEDE_FASTPATH_RX)
1277 qede_free_mem_rxq(edev, fp->rxq);
Yuval Mintz29502192015-10-26 11:02:29 +02001278
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001279 if (fp->type & QEDE_FASTPATH_TX)
Mintz, Yuval80439a12016-11-29 16:47:02 +02001280 qede_free_mem_txq(edev, fp->txq);
Yuval Mintz29502192015-10-26 11:02:29 +02001281}
1282
1283/* This function allocates all memory needed for a single fp (i.e. an entity
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001284 * which contains status block, one rx queue and/or multiple per-TC tx queues.
Yuval Mintz29502192015-10-26 11:02:29 +02001285 */
Yuval Mintz1a635e42016-08-15 10:42:43 +03001286static int qede_alloc_mem_fp(struct qede_dev *edev, struct qede_fastpath *fp)
Yuval Mintz29502192015-10-26 11:02:29 +02001287{
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001288 int rc = 0;
Yuval Mintz29502192015-10-26 11:02:29 +02001289
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001290 rc = qede_alloc_mem_sb(edev, fp->sb_info, fp->id);
Yuval Mintz29502192015-10-26 11:02:29 +02001291 if (rc)
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001292 goto out;
Yuval Mintz29502192015-10-26 11:02:29 +02001293
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001294 if (fp->type & QEDE_FASTPATH_RX) {
1295 rc = qede_alloc_mem_rxq(edev, fp->rxq);
Yuval Mintz29502192015-10-26 11:02:29 +02001296 if (rc)
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001297 goto out;
1298 }
1299
1300 if (fp->type & QEDE_FASTPATH_XDP) {
1301 rc = qede_alloc_mem_txq(edev, fp->xdp_tx);
1302 if (rc)
1303 goto out;
Yuval Mintz29502192015-10-26 11:02:29 +02001304 }
1305
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001306 if (fp->type & QEDE_FASTPATH_TX) {
Mintz, Yuval80439a12016-11-29 16:47:02 +02001307 rc = qede_alloc_mem_txq(edev, fp->txq);
1308 if (rc)
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001309 goto out;
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001310 }
1311
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001312out:
Manish Chopraf86af2d2016-04-20 03:03:27 -04001313 return rc;
Yuval Mintz29502192015-10-26 11:02:29 +02001314}
1315
1316static void qede_free_mem_load(struct qede_dev *edev)
1317{
1318 int i;
1319
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001320 for_each_queue(i) {
Yuval Mintz29502192015-10-26 11:02:29 +02001321 struct qede_fastpath *fp = &edev->fp_array[i];
1322
1323 qede_free_mem_fp(edev, fp);
1324 }
1325}
1326
1327/* This function allocates all qede memory at NIC load. */
1328static int qede_alloc_mem_load(struct qede_dev *edev)
1329{
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001330 int rc = 0, queue_id;
Yuval Mintz29502192015-10-26 11:02:29 +02001331
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001332 for (queue_id = 0; queue_id < QEDE_QUEUE_CNT(edev); queue_id++) {
1333 struct qede_fastpath *fp = &edev->fp_array[queue_id];
Yuval Mintz29502192015-10-26 11:02:29 +02001334
1335 rc = qede_alloc_mem_fp(edev, fp);
Manish Chopraf86af2d2016-04-20 03:03:27 -04001336 if (rc) {
Yuval Mintz29502192015-10-26 11:02:29 +02001337 DP_ERR(edev,
Manish Chopraf86af2d2016-04-20 03:03:27 -04001338 "Failed to allocate memory for fastpath - rss id = %d\n",
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001339 queue_id);
Manish Chopraf86af2d2016-04-20 03:03:27 -04001340 qede_free_mem_load(edev);
1341 return rc;
Yuval Mintz29502192015-10-26 11:02:29 +02001342 }
Yuval Mintz29502192015-10-26 11:02:29 +02001343 }
1344
1345 return 0;
1346}
1347
1348/* This function inits fp content and resets the SB, RXQ and TXQ structures */
1349static void qede_init_fp(struct qede_dev *edev)
1350{
Mintz, Yuval80439a12016-11-29 16:47:02 +02001351 int queue_id, rxq_index = 0, txq_index = 0;
Yuval Mintz29502192015-10-26 11:02:29 +02001352 struct qede_fastpath *fp;
1353
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001354 for_each_queue(queue_id) {
1355 fp = &edev->fp_array[queue_id];
Yuval Mintz29502192015-10-26 11:02:29 +02001356
1357 fp->edev = edev;
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001358 fp->id = queue_id;
Yuval Mintz29502192015-10-26 11:02:29 +02001359
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001360 if (fp->type & QEDE_FASTPATH_XDP) {
1361 fp->xdp_tx->index = QEDE_TXQ_IDX_TO_XDP(edev,
1362 rxq_index);
1363 fp->xdp_tx->is_xdp = 1;
1364 }
Yuval Mintz29502192015-10-26 11:02:29 +02001365
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001366 if (fp->type & QEDE_FASTPATH_RX) {
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001367 fp->rxq->rxq_id = rxq_index++;
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001368
1369 /* Determine how to map buffers for this queue */
1370 if (fp->type & QEDE_FASTPATH_XDP)
1371 fp->rxq->data_direction = DMA_BIDIRECTIONAL;
1372 else
1373 fp->rxq->data_direction = DMA_FROM_DEVICE;
Mintz, Yuval9eb22352016-11-29 16:47:08 +02001374 fp->rxq->dev = &edev->pdev->dev;
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001375 }
Yuval Mintz29502192015-10-26 11:02:29 +02001376
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001377 if (fp->type & QEDE_FASTPATH_TX) {
Mintz, Yuval80439a12016-11-29 16:47:02 +02001378 fp->txq->index = txq_index++;
1379 if (edev->dev_info.is_legacy)
1380 fp->txq->is_legacy = 1;
Mintz, Yuval9eb22352016-11-29 16:47:08 +02001381 fp->txq->dev = &edev->pdev->dev;
Yuval Mintz29502192015-10-26 11:02:29 +02001382 }
1383
1384 snprintf(fp->name, sizeof(fp->name), "%s-fp-%d",
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001385 edev->ndev->name, queue_id);
Yuval Mintz29502192015-10-26 11:02:29 +02001386 }
Manish Chopra55482ed2016-03-04 12:35:06 -05001387
1388 edev->gro_disable = !(edev->ndev->features & NETIF_F_GRO);
Yuval Mintz29502192015-10-26 11:02:29 +02001389}
1390
1391static int qede_set_real_num_queues(struct qede_dev *edev)
1392{
1393 int rc = 0;
1394
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001395 rc = netif_set_real_num_tx_queues(edev->ndev, QEDE_TSS_COUNT(edev));
Yuval Mintz29502192015-10-26 11:02:29 +02001396 if (rc) {
1397 DP_NOTICE(edev, "Failed to set real number of Tx queues\n");
1398 return rc;
1399 }
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001400
1401 rc = netif_set_real_num_rx_queues(edev->ndev, QEDE_RSS_COUNT(edev));
Yuval Mintz29502192015-10-26 11:02:29 +02001402 if (rc) {
1403 DP_NOTICE(edev, "Failed to set real number of Rx queues\n");
1404 return rc;
1405 }
1406
1407 return 0;
1408}
1409
1410static void qede_napi_disable_remove(struct qede_dev *edev)
1411{
1412 int i;
1413
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001414 for_each_queue(i) {
Yuval Mintz29502192015-10-26 11:02:29 +02001415 napi_disable(&edev->fp_array[i].napi);
1416
1417 netif_napi_del(&edev->fp_array[i].napi);
1418 }
1419}
1420
1421static void qede_napi_add_enable(struct qede_dev *edev)
1422{
1423 int i;
1424
1425 /* Add NAPI objects */
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001426 for_each_queue(i) {
Yuval Mintz29502192015-10-26 11:02:29 +02001427 netif_napi_add(edev->ndev, &edev->fp_array[i].napi,
1428 qede_poll, NAPI_POLL_WEIGHT);
1429 napi_enable(&edev->fp_array[i].napi);
1430 }
1431}
1432
1433static void qede_sync_free_irqs(struct qede_dev *edev)
1434{
1435 int i;
1436
1437 for (i = 0; i < edev->int_info.used_cnt; i++) {
1438 if (edev->int_info.msix_cnt) {
1439 synchronize_irq(edev->int_info.msix[i].vector);
1440 free_irq(edev->int_info.msix[i].vector,
1441 &edev->fp_array[i]);
1442 } else {
1443 edev->ops->common->simd_handler_clean(edev->cdev, i);
1444 }
1445 }
1446
1447 edev->int_info.used_cnt = 0;
1448}
1449
1450static int qede_req_msix_irqs(struct qede_dev *edev)
1451{
1452 int i, rc;
1453
1454 /* Sanitize number of interrupts == number of prepared RSS queues */
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001455 if (QEDE_QUEUE_CNT(edev) > edev->int_info.msix_cnt) {
Yuval Mintz29502192015-10-26 11:02:29 +02001456 DP_ERR(edev,
1457 "Interrupt mismatch: %d RSS queues > %d MSI-x vectors\n",
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001458 QEDE_QUEUE_CNT(edev), edev->int_info.msix_cnt);
Yuval Mintz29502192015-10-26 11:02:29 +02001459 return -EINVAL;
1460 }
1461
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001462 for (i = 0; i < QEDE_QUEUE_CNT(edev); i++) {
Yuval Mintz29502192015-10-26 11:02:29 +02001463 rc = request_irq(edev->int_info.msix[i].vector,
1464 qede_msix_fp_int, 0, edev->fp_array[i].name,
1465 &edev->fp_array[i]);
1466 if (rc) {
1467 DP_ERR(edev, "Request fp %d irq failed\n", i);
1468 qede_sync_free_irqs(edev);
1469 return rc;
1470 }
1471 DP_VERBOSE(edev, NETIF_MSG_INTR,
1472 "Requested fp irq for %s [entry %d]. Cookie is at %p\n",
1473 edev->fp_array[i].name, i,
1474 &edev->fp_array[i]);
1475 edev->int_info.used_cnt++;
1476 }
1477
1478 return 0;
1479}
1480
1481static void qede_simd_fp_handler(void *cookie)
1482{
1483 struct qede_fastpath *fp = (struct qede_fastpath *)cookie;
1484
1485 napi_schedule_irqoff(&fp->napi);
1486}
1487
1488static int qede_setup_irqs(struct qede_dev *edev)
1489{
1490 int i, rc = 0;
1491
1492 /* Learn Interrupt configuration */
1493 rc = edev->ops->common->get_fp_int(edev->cdev, &edev->int_info);
1494 if (rc)
1495 return rc;
1496
1497 if (edev->int_info.msix_cnt) {
1498 rc = qede_req_msix_irqs(edev);
1499 if (rc)
1500 return rc;
1501 edev->ndev->irq = edev->int_info.msix[0].vector;
1502 } else {
1503 const struct qed_common_ops *ops;
1504
1505 /* qed should learn receive the RSS ids and callbacks */
1506 ops = edev->ops->common;
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001507 for (i = 0; i < QEDE_QUEUE_CNT(edev); i++)
Yuval Mintz29502192015-10-26 11:02:29 +02001508 ops->simd_handler_config(edev->cdev,
1509 &edev->fp_array[i], i,
1510 qede_simd_fp_handler);
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001511 edev->int_info.used_cnt = QEDE_QUEUE_CNT(edev);
Yuval Mintz29502192015-10-26 11:02:29 +02001512 }
1513 return 0;
1514}
1515
1516static int qede_drain_txq(struct qede_dev *edev,
Yuval Mintz1a635e42016-08-15 10:42:43 +03001517 struct qede_tx_queue *txq, bool allow_drain)
Yuval Mintz29502192015-10-26 11:02:29 +02001518{
1519 int rc, cnt = 1000;
1520
1521 while (txq->sw_tx_cons != txq->sw_tx_prod) {
1522 if (!cnt) {
1523 if (allow_drain) {
1524 DP_NOTICE(edev,
1525 "Tx queue[%d] is stuck, requesting MCP to drain\n",
1526 txq->index);
1527 rc = edev->ops->common->drain(edev->cdev);
1528 if (rc)
1529 return rc;
1530 return qede_drain_txq(edev, txq, false);
1531 }
1532 DP_NOTICE(edev,
1533 "Timeout waiting for tx queue[%d]: PROD=%d, CONS=%d\n",
1534 txq->index, txq->sw_tx_prod,
1535 txq->sw_tx_cons);
1536 return -ENODEV;
1537 }
1538 cnt--;
1539 usleep_range(1000, 2000);
1540 barrier();
1541 }
1542
1543 /* FW finished processing, wait for HW to transmit all tx packets */
1544 usleep_range(1000, 2000);
1545
1546 return 0;
1547}
1548
Mintz, Yuval3da7a372016-11-29 16:47:06 +02001549static int qede_stop_txq(struct qede_dev *edev,
1550 struct qede_tx_queue *txq, int rss_id)
1551{
1552 return edev->ops->q_tx_stop(edev->cdev, rss_id, txq->handle);
1553}
1554
Yuval Mintz29502192015-10-26 11:02:29 +02001555static int qede_stop_queues(struct qede_dev *edev)
1556{
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001557 struct qed_update_vport_params *vport_update_params;
Yuval Mintz29502192015-10-26 11:02:29 +02001558 struct qed_dev *cdev = edev->cdev;
Mintz, Yuval80439a12016-11-29 16:47:02 +02001559 struct qede_fastpath *fp;
1560 int rc, i;
Yuval Mintz29502192015-10-26 11:02:29 +02001561
1562 /* Disable the vport */
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001563 vport_update_params = vzalloc(sizeof(*vport_update_params));
1564 if (!vport_update_params)
1565 return -ENOMEM;
Yuval Mintz29502192015-10-26 11:02:29 +02001566
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001567 vport_update_params->vport_id = 0;
1568 vport_update_params->update_vport_active_flg = 1;
1569 vport_update_params->vport_active_flg = 0;
1570 vport_update_params->update_rss_flg = 0;
1571
1572 rc = edev->ops->vport_update(cdev, vport_update_params);
1573 vfree(vport_update_params);
1574
Yuval Mintz29502192015-10-26 11:02:29 +02001575 if (rc) {
1576 DP_ERR(edev, "Failed to update vport\n");
1577 return rc;
1578 }
1579
1580 /* Flush Tx queues. If needed, request drain from MCP */
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001581 for_each_queue(i) {
Mintz, Yuval80439a12016-11-29 16:47:02 +02001582 fp = &edev->fp_array[i];
Yuval Mintz29502192015-10-26 11:02:29 +02001583
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001584 if (fp->type & QEDE_FASTPATH_TX) {
Mintz, Yuval80439a12016-11-29 16:47:02 +02001585 rc = qede_drain_txq(edev, fp->txq, true);
1586 if (rc)
1587 return rc;
Yuval Mintz29502192015-10-26 11:02:29 +02001588 }
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001589
1590 if (fp->type & QEDE_FASTPATH_XDP) {
1591 rc = qede_drain_txq(edev, fp->xdp_tx, true);
1592 if (rc)
1593 return rc;
1594 }
Yuval Mintz29502192015-10-26 11:02:29 +02001595 }
1596
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001597 /* Stop all Queues in reverse order */
1598 for (i = QEDE_QUEUE_CNT(edev) - 1; i >= 0; i--) {
Mintz, Yuval80439a12016-11-29 16:47:02 +02001599 fp = &edev->fp_array[i];
Yuval Mintz29502192015-10-26 11:02:29 +02001600
Mintz, Yuval80439a12016-11-29 16:47:02 +02001601 /* Stop the Tx Queue(s) */
1602 if (fp->type & QEDE_FASTPATH_TX) {
Mintz, Yuval3da7a372016-11-29 16:47:06 +02001603 rc = qede_stop_txq(edev, fp->txq, i);
1604 if (rc)
1605 return rc;
Yuval Mintz29502192015-10-26 11:02:29 +02001606 }
1607
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001608 /* Stop the Rx Queue */
Mintz, Yuval80439a12016-11-29 16:47:02 +02001609 if (fp->type & QEDE_FASTPATH_RX) {
Mintz, Yuval3da7a372016-11-29 16:47:06 +02001610 rc = edev->ops->q_rx_stop(cdev, i, fp->rxq->handle);
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001611 if (rc) {
1612 DP_ERR(edev, "Failed to stop RXQ #%d\n", i);
1613 return rc;
1614 }
Yuval Mintz29502192015-10-26 11:02:29 +02001615 }
Mintz, Yuval496e0512016-11-29 16:47:09 +02001616
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001617 /* Stop the XDP forwarding queue */
1618 if (fp->type & QEDE_FASTPATH_XDP) {
1619 rc = qede_stop_txq(edev, fp->xdp_tx, i);
1620 if (rc)
1621 return rc;
1622
Mintz, Yuval496e0512016-11-29 16:47:09 +02001623 bpf_prog_put(fp->rxq->xdp_prog);
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001624 }
Yuval Mintz29502192015-10-26 11:02:29 +02001625 }
1626
1627 /* Stop the vport */
1628 rc = edev->ops->vport_stop(cdev, 0);
1629 if (rc)
1630 DP_ERR(edev, "Failed to stop VPORT\n");
1631
1632 return rc;
1633}
1634
Mintz, Yuval3da7a372016-11-29 16:47:06 +02001635static int qede_start_txq(struct qede_dev *edev,
1636 struct qede_fastpath *fp,
1637 struct qede_tx_queue *txq, u8 rss_id, u16 sb_idx)
1638{
1639 dma_addr_t phys_table = qed_chain_get_pbl_phys(&txq->tx_pbl);
1640 u32 page_cnt = qed_chain_get_page_cnt(&txq->tx_pbl);
1641 struct qed_queue_start_common_params params;
1642 struct qed_txq_start_ret_params ret_params;
1643 int rc;
1644
1645 memset(&params, 0, sizeof(params));
1646 memset(&ret_params, 0, sizeof(ret_params));
1647
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001648 /* Let the XDP queue share the queue-zone with one of the regular txq.
1649 * We don't really care about its coalescing.
1650 */
1651 if (txq->is_xdp)
1652 params.queue_id = QEDE_TXQ_XDP_TO_IDX(edev, txq);
1653 else
1654 params.queue_id = txq->index;
1655
Mintz, Yuval3da7a372016-11-29 16:47:06 +02001656 params.sb = fp->sb_info->igu_sb_id;
1657 params.sb_idx = sb_idx;
1658
1659 rc = edev->ops->q_tx_start(edev->cdev, rss_id, &params, phys_table,
1660 page_cnt, &ret_params);
1661 if (rc) {
1662 DP_ERR(edev, "Start TXQ #%d failed %d\n", txq->index, rc);
1663 return rc;
1664 }
1665
1666 txq->doorbell_addr = ret_params.p_doorbell;
1667 txq->handle = ret_params.p_handle;
1668
1669 /* Determine the FW consumer address associated */
1670 txq->hw_cons_ptr = &fp->sb_info->sb_virt->pi_array[sb_idx];
1671
1672 /* Prepare the doorbell parameters */
1673 SET_FIELD(txq->tx_db.data.params, ETH_DB_DATA_DEST, DB_DEST_XCM);
1674 SET_FIELD(txq->tx_db.data.params, ETH_DB_DATA_AGG_CMD, DB_AGG_CMD_SET);
1675 SET_FIELD(txq->tx_db.data.params, ETH_DB_DATA_AGG_VAL_SEL,
1676 DQ_XCM_ETH_TX_BD_PROD_CMD);
1677 txq->tx_db.data.agg_flags = DQ_XCM_ETH_DQ_CF_CMD;
1678
1679 return rc;
1680}
1681
Yuval Mintza0d26d52016-06-19 15:18:13 +03001682static int qede_start_queues(struct qede_dev *edev, bool clear_stats)
Yuval Mintz29502192015-10-26 11:02:29 +02001683{
Manish Chopra088c8612016-03-04 12:35:05 -05001684 int vlan_removal_en = 1;
Yuval Mintz29502192015-10-26 11:02:29 +02001685 struct qed_dev *cdev = edev->cdev;
Yuval Mintzfefb0202016-05-11 16:36:19 +03001686 struct qed_dev_info *qed_info = &edev->dev_info.common;
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001687 struct qed_update_vport_params *vport_update_params;
1688 struct qed_queue_start_common_params q_params;
Manish Chopra088c8612016-03-04 12:35:05 -05001689 struct qed_start_vport_params start = {0};
Mintz, Yuval80439a12016-11-29 16:47:02 +02001690 int rc, i;
Yuval Mintz29502192015-10-26 11:02:29 +02001691
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001692 if (!edev->num_queues) {
Yuval Mintz29502192015-10-26 11:02:29 +02001693 DP_ERR(edev,
1694 "Cannot update V-VPORT as active as there are no Rx queues\n");
1695 return -EINVAL;
1696 }
1697
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001698 vport_update_params = vzalloc(sizeof(*vport_update_params));
1699 if (!vport_update_params)
1700 return -ENOMEM;
1701
Sudarsana Reddy Kalluru4c552152017-02-15 10:24:11 +02001702 start.handle_ptp_pkts = !!(edev->ptp);
Manish Chopra55482ed2016-03-04 12:35:06 -05001703 start.gro_enable = !edev->gro_disable;
Manish Chopra088c8612016-03-04 12:35:05 -05001704 start.mtu = edev->ndev->mtu;
1705 start.vport_id = 0;
1706 start.drop_ttl0 = true;
1707 start.remove_inner_vlan = vlan_removal_en;
Yuval Mintz7f7a1442016-07-27 14:45:22 +03001708 start.clear_stats = clear_stats;
Manish Chopra088c8612016-03-04 12:35:05 -05001709
1710 rc = edev->ops->vport_start(cdev, &start);
Yuval Mintz29502192015-10-26 11:02:29 +02001711
1712 if (rc) {
1713 DP_ERR(edev, "Start V-PORT failed %d\n", rc);
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001714 goto out;
Yuval Mintz29502192015-10-26 11:02:29 +02001715 }
1716
1717 DP_VERBOSE(edev, NETIF_MSG_IFUP,
1718 "Start vport ramrod passed, vport_id = %d, MTU = %d, vlan_removal_en = %d\n",
Manish Chopra088c8612016-03-04 12:35:05 -05001719 start.vport_id, edev->ndev->mtu + 0xe, vlan_removal_en);
Yuval Mintz29502192015-10-26 11:02:29 +02001720
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001721 for_each_queue(i) {
Yuval Mintz29502192015-10-26 11:02:29 +02001722 struct qede_fastpath *fp = &edev->fp_array[i];
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001723 dma_addr_t p_phys_table;
1724 u32 page_cnt;
Yuval Mintz29502192015-10-26 11:02:29 +02001725
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001726 if (fp->type & QEDE_FASTPATH_RX) {
Mintz, Yuval3da7a372016-11-29 16:47:06 +02001727 struct qed_rxq_start_ret_params ret_params;
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001728 struct qede_rx_queue *rxq = fp->rxq;
1729 __le16 *val;
Yuval Mintz29502192015-10-26 11:02:29 +02001730
Mintz, Yuval3da7a372016-11-29 16:47:06 +02001731 memset(&ret_params, 0, sizeof(ret_params));
Yuval Mintz29502192015-10-26 11:02:29 +02001732 memset(&q_params, 0, sizeof(q_params));
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001733 q_params.queue_id = rxq->rxq_id;
1734 q_params.vport_id = 0;
1735 q_params.sb = fp->sb_info->igu_sb_id;
1736 q_params.sb_idx = RX_PI;
1737
1738 p_phys_table =
1739 qed_chain_get_pbl_phys(&rxq->rx_comp_ring);
1740 page_cnt = qed_chain_get_page_cnt(&rxq->rx_comp_ring);
1741
Mintz, Yuval3da7a372016-11-29 16:47:06 +02001742 rc = edev->ops->q_rx_start(cdev, i, &q_params,
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001743 rxq->rx_buf_size,
1744 rxq->rx_bd_ring.p_phys_addr,
1745 p_phys_table,
Mintz, Yuval3da7a372016-11-29 16:47:06 +02001746 page_cnt, &ret_params);
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001747 if (rc) {
1748 DP_ERR(edev, "Start RXQ #%d failed %d\n", i,
1749 rc);
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001750 goto out;
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001751 }
1752
Mintz, Yuval3da7a372016-11-29 16:47:06 +02001753 /* Use the return parameters */
1754 rxq->hw_rxq_prod_addr = ret_params.p_prod;
1755 rxq->handle = ret_params.p_handle;
1756
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001757 val = &fp->sb_info->sb_virt->pi_array[RX_PI];
1758 rxq->hw_cons_ptr = val;
1759
1760 qede_update_rx_prod(edev, rxq);
1761 }
1762
Mintz, Yuval496e0512016-11-29 16:47:09 +02001763 if (fp->type & QEDE_FASTPATH_XDP) {
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001764 rc = qede_start_txq(edev, fp, fp->xdp_tx, i, XDP_PI);
1765 if (rc)
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001766 goto out;
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001767
Mintz, Yuval496e0512016-11-29 16:47:09 +02001768 fp->rxq->xdp_prog = bpf_prog_add(edev->xdp_prog, 1);
1769 if (IS_ERR(fp->rxq->xdp_prog)) {
1770 rc = PTR_ERR(fp->rxq->xdp_prog);
1771 fp->rxq->xdp_prog = NULL;
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001772 goto out;
Mintz, Yuval496e0512016-11-29 16:47:09 +02001773 }
1774 }
1775
Mintz, Yuval80439a12016-11-29 16:47:02 +02001776 if (fp->type & QEDE_FASTPATH_TX) {
Mintz, Yuval3da7a372016-11-29 16:47:06 +02001777 rc = qede_start_txq(edev, fp, fp->txq, i, TX_PI(0));
1778 if (rc)
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001779 goto out;
Yuval Mintz29502192015-10-26 11:02:29 +02001780 }
1781 }
1782
1783 /* Prepare and send the vport enable */
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001784 vport_update_params->vport_id = start.vport_id;
1785 vport_update_params->update_vport_active_flg = 1;
1786 vport_update_params->vport_active_flg = 1;
Yuval Mintz29502192015-10-26 11:02:29 +02001787
Yuval Mintz831bfb0e2016-05-11 16:36:25 +03001788 if ((qed_info->mf_mode == QED_MF_NPAR || pci_num_vf(edev->pdev)) &&
1789 qed_info->tx_switching) {
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001790 vport_update_params->update_tx_switching_flg = 1;
1791 vport_update_params->tx_switching_flg = 1;
Yuval Mintz831bfb0e2016-05-11 16:36:25 +03001792 }
1793
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001794 qede_fill_rss_params(edev, &vport_update_params->rss_params,
1795 &vport_update_params->update_rss_flg);
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001796
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001797 rc = edev->ops->vport_update(cdev, vport_update_params);
1798 if (rc)
Yuval Mintz29502192015-10-26 11:02:29 +02001799 DP_ERR(edev, "Update V-PORT failed %d\n", rc);
Yuval Mintz29502192015-10-26 11:02:29 +02001800
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001801out:
1802 vfree(vport_update_params);
1803 return rc;
Yuval Mintz29502192015-10-26 11:02:29 +02001804}
1805
1806enum qede_unload_mode {
1807 QEDE_UNLOAD_NORMAL,
1808};
1809
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001810static void qede_unload(struct qede_dev *edev, enum qede_unload_mode mode,
1811 bool is_locked)
Yuval Mintz29502192015-10-26 11:02:29 +02001812{
Sudarsana Kallurua2ec6172015-10-26 11:02:32 +02001813 struct qed_link_params link_params;
Yuval Mintz29502192015-10-26 11:02:29 +02001814 int rc;
1815
1816 DP_INFO(edev, "Starting qede unload\n");
1817
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001818 if (!is_locked)
1819 __qede_lock(edev);
1820
Ram Amranicee9fbd2016-10-01 21:59:56 +03001821 qede_roce_dev_event_close(edev);
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +02001822 edev->state = QEDE_STATE_CLOSED;
1823
Sudarsana Reddy Kalluru4c552152017-02-15 10:24:11 +02001824 qede_ptp_stop(edev);
1825
Yuval Mintz29502192015-10-26 11:02:29 +02001826 /* Close OS Tx */
1827 netif_tx_disable(edev->ndev);
1828 netif_carrier_off(edev->ndev);
1829
Sudarsana Kallurua2ec6172015-10-26 11:02:32 +02001830 /* Reset the link */
1831 memset(&link_params, 0, sizeof(link_params));
1832 link_params.link_up = false;
1833 edev->ops->common->set_link(edev->cdev, &link_params);
Yuval Mintz29502192015-10-26 11:02:29 +02001834 rc = qede_stop_queues(edev);
1835 if (rc) {
1836 qede_sync_free_irqs(edev);
1837 goto out;
1838 }
1839
1840 DP_INFO(edev, "Stopped Queues\n");
1841
Sudarsana Reddy Kalluru7c1bfca2016-02-18 17:00:40 +02001842 qede_vlan_mark_nonconfigured(edev);
Yuval Mintz29502192015-10-26 11:02:29 +02001843 edev->ops->fastpath_stop(edev->cdev);
1844
1845 /* Release the interrupts */
1846 qede_sync_free_irqs(edev);
1847 edev->ops->common->set_fp_int(edev->cdev, 0);
1848
1849 qede_napi_disable_remove(edev);
1850
1851 qede_free_mem_load(edev);
1852 qede_free_fp_array(edev);
1853
1854out:
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001855 if (!is_locked)
1856 __qede_unlock(edev);
Yuval Mintz29502192015-10-26 11:02:29 +02001857 DP_INFO(edev, "Ending qede unload\n");
1858}
1859
1860enum qede_load_mode {
1861 QEDE_LOAD_NORMAL,
Yuval Mintza0d26d52016-06-19 15:18:13 +03001862 QEDE_LOAD_RELOAD,
Yuval Mintz29502192015-10-26 11:02:29 +02001863};
1864
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001865static int qede_load(struct qede_dev *edev, enum qede_load_mode mode,
1866 bool is_locked)
Yuval Mintz29502192015-10-26 11:02:29 +02001867{
Sudarsana Kallurua2ec6172015-10-26 11:02:32 +02001868 struct qed_link_params link_params;
1869 struct qed_link_output link_output;
Yuval Mintz29502192015-10-26 11:02:29 +02001870 int rc;
1871
1872 DP_INFO(edev, "Starting qede load\n");
1873
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001874 if (!is_locked)
1875 __qede_lock(edev);
1876
Yuval Mintz29502192015-10-26 11:02:29 +02001877 rc = qede_set_num_queues(edev);
1878 if (rc)
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001879 goto out;
Yuval Mintz29502192015-10-26 11:02:29 +02001880
1881 rc = qede_alloc_fp_array(edev);
1882 if (rc)
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001883 goto out;
Yuval Mintz29502192015-10-26 11:02:29 +02001884
1885 qede_init_fp(edev);
1886
1887 rc = qede_alloc_mem_load(edev);
1888 if (rc)
1889 goto err1;
Mintz, Yuval80439a12016-11-29 16:47:02 +02001890 DP_INFO(edev, "Allocated %d Rx, %d Tx queues\n",
1891 QEDE_RSS_COUNT(edev), QEDE_TSS_COUNT(edev));
Yuval Mintz29502192015-10-26 11:02:29 +02001892
1893 rc = qede_set_real_num_queues(edev);
1894 if (rc)
1895 goto err2;
1896
1897 qede_napi_add_enable(edev);
1898 DP_INFO(edev, "Napi added and enabled\n");
1899
1900 rc = qede_setup_irqs(edev);
1901 if (rc)
1902 goto err3;
1903 DP_INFO(edev, "Setup IRQs succeeded\n");
1904
Yuval Mintza0d26d52016-06-19 15:18:13 +03001905 rc = qede_start_queues(edev, mode != QEDE_LOAD_RELOAD);
Yuval Mintz29502192015-10-26 11:02:29 +02001906 if (rc)
1907 goto err4;
1908 DP_INFO(edev, "Start VPORT, RXQ and TXQ succeeded\n");
1909
1910 /* Add primary mac and set Rx filters */
1911 ether_addr_copy(edev->primary_mac, edev->ndev->dev_addr);
1912
Sudarsana Reddy Kalluru7c1bfca2016-02-18 17:00:40 +02001913 /* Program un-configured VLANs */
1914 qede_configure_vlan_filters(edev);
1915
Sudarsana Kallurua2ec6172015-10-26 11:02:32 +02001916 /* Ask for link-up using current configuration */
1917 memset(&link_params, 0, sizeof(link_params));
1918 link_params.link_up = true;
1919 edev->ops->common->set_link(edev->cdev, &link_params);
1920
1921 /* Query whether link is already-up */
1922 memset(&link_output, 0, sizeof(link_output));
1923 edev->ops->common->get_link(edev->cdev, &link_output);
Ram Amranicee9fbd2016-10-01 21:59:56 +03001924 qede_roce_dev_event_open(edev);
Sudarsana Kallurua2ec6172015-10-26 11:02:32 +02001925 qede_link_update(edev, &link_output);
1926
Sudarsana Reddy Kalluru4c552152017-02-15 10:24:11 +02001927 qede_ptp_start(edev, (mode == QEDE_LOAD_NORMAL));
1928
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001929 edev->state = QEDE_STATE_OPEN;
1930
Yuval Mintz29502192015-10-26 11:02:29 +02001931 DP_INFO(edev, "Ending successfully qede load\n");
1932
Yuval Mintz29502192015-10-26 11:02:29 +02001933
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001934 goto out;
Yuval Mintz29502192015-10-26 11:02:29 +02001935err4:
1936 qede_sync_free_irqs(edev);
1937 memset(&edev->int_info.msix_cnt, 0, sizeof(struct qed_int_info));
1938err3:
1939 qede_napi_disable_remove(edev);
1940err2:
1941 qede_free_mem_load(edev);
1942err1:
1943 edev->ops->common->set_fp_int(edev->cdev, 0);
1944 qede_free_fp_array(edev);
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001945 edev->num_queues = 0;
1946 edev->fp_num_tx = 0;
1947 edev->fp_num_rx = 0;
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001948out:
1949 if (!is_locked)
1950 __qede_unlock(edev);
1951
Yuval Mintz29502192015-10-26 11:02:29 +02001952 return rc;
1953}
1954
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001955/* 'func' should be able to run between unload and reload assuming interface
1956 * is actually running, or afterwards in case it's currently DOWN.
1957 */
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001958void qede_reload(struct qede_dev *edev,
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001959 struct qede_reload_args *args, bool is_locked)
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001960{
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001961 if (!is_locked)
1962 __qede_lock(edev);
1963
1964 /* Since qede_lock is held, internal state wouldn't change even
1965 * if netdev state would start transitioning. Check whether current
1966 * internal configuration indicates device is up, then reload.
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001967 */
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001968 if (edev->state == QEDE_STATE_OPEN) {
1969 qede_unload(edev, QEDE_UNLOAD_NORMAL, true);
1970 if (args)
1971 args->func(edev, args);
1972 qede_load(edev, QEDE_LOAD_RELOAD, true);
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001973
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001974 /* Since no one is going to do it for us, re-configure */
1975 qede_config_rx_mode(edev->ndev);
1976 } else if (args) {
1977 args->func(edev, args);
1978 }
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001979
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001980 if (!is_locked)
1981 __qede_unlock(edev);
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001982}
1983
Yuval Mintz29502192015-10-26 11:02:29 +02001984/* called with rtnl_lock */
1985static int qede_open(struct net_device *ndev)
1986{
1987 struct qede_dev *edev = netdev_priv(ndev);
Manish Choprab18e1702016-04-14 01:38:30 -04001988 int rc;
Yuval Mintz29502192015-10-26 11:02:29 +02001989
1990 netif_carrier_off(ndev);
1991
1992 edev->ops->common->set_power_state(edev->cdev, PCI_D0);
1993
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001994 rc = qede_load(edev, QEDE_LOAD_NORMAL, false);
Manish Choprab18e1702016-04-14 01:38:30 -04001995 if (rc)
1996 return rc;
1997
Alexander Duyckf9f082a2016-06-16 12:22:57 -07001998 udp_tunnel_get_rx_info(ndev);
1999
Sudarsana Kalluru0fefbfb2016-10-31 07:14:21 +02002000 edev->ops->common->update_drv_state(edev->cdev, true);
2001
Manish Choprab18e1702016-04-14 01:38:30 -04002002 return 0;
Yuval Mintz29502192015-10-26 11:02:29 +02002003}
2004
2005static int qede_close(struct net_device *ndev)
2006{
2007 struct qede_dev *edev = netdev_priv(ndev);
2008
Mintz, Yuval567b3c12016-11-29 16:47:05 +02002009 qede_unload(edev, QEDE_UNLOAD_NORMAL, false);
Yuval Mintz29502192015-10-26 11:02:29 +02002010
Sudarsana Kalluru0fefbfb2016-10-31 07:14:21 +02002011 edev->ops->common->update_drv_state(edev->cdev, false);
2012
Yuval Mintz29502192015-10-26 11:02:29 +02002013 return 0;
2014}
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +02002015
Sudarsana Kallurua2ec6172015-10-26 11:02:32 +02002016static void qede_link_update(void *dev, struct qed_link_output *link)
2017{
2018 struct qede_dev *edev = dev;
2019
2020 if (!netif_running(edev->ndev)) {
2021 DP_VERBOSE(edev, NETIF_MSG_LINK, "Interface is not running\n");
2022 return;
2023 }
2024
2025 if (link->link_up) {
Yuval Mintz8e025ae2016-02-24 16:52:47 +02002026 if (!netif_carrier_ok(edev->ndev)) {
2027 DP_NOTICE(edev, "Link is up\n");
2028 netif_tx_start_all_queues(edev->ndev);
2029 netif_carrier_on(edev->ndev);
2030 }
Sudarsana Kallurua2ec6172015-10-26 11:02:32 +02002031 } else {
Yuval Mintz8e025ae2016-02-24 16:52:47 +02002032 if (netif_carrier_ok(edev->ndev)) {
2033 DP_NOTICE(edev, "Link is down\n");
2034 netif_tx_disable(edev->ndev);
2035 netif_carrier_off(edev->ndev);
2036 }
Sudarsana Kallurua2ec6172015-10-26 11:02:32 +02002037 }
2038}