blob: 1393bf4add7a7cea8d98423a6d5485efa75b71c3 [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>
Ram Amranicee9fbd2016-10-01 21:59:56 +030062#include <linux/qed/qede_roce.h>
Yuval Mintze712d522015-10-26 11:02:27 +020063#include "qede.h"
64
Yuval Mintz5abd7e922016-02-24 16:52:50 +020065static char version[] =
66 "QLogic FastLinQ 4xxxx Ethernet Driver qede " DRV_MODULE_VERSION "\n";
Yuval Mintze712d522015-10-26 11:02:27 +020067
Yuval Mintz5abd7e922016-02-24 16:52:50 +020068MODULE_DESCRIPTION("QLogic FastLinQ 4xxxx Ethernet Driver");
Yuval Mintze712d522015-10-26 11:02:27 +020069MODULE_LICENSE("GPL");
70MODULE_VERSION(DRV_MODULE_VERSION);
71
72static uint debug;
73module_param(debug, uint, 0);
74MODULE_PARM_DESC(debug, " Default debug msglevel");
75
76static const struct qed_eth_ops *qed_ops;
77
78#define CHIP_NUM_57980S_40 0x1634
Yuval Mintz0e7441d2016-02-24 16:52:45 +020079#define CHIP_NUM_57980S_10 0x1666
Yuval Mintze712d522015-10-26 11:02:27 +020080#define CHIP_NUM_57980S_MF 0x1636
81#define CHIP_NUM_57980S_100 0x1644
82#define CHIP_NUM_57980S_50 0x1654
83#define CHIP_NUM_57980S_25 0x1656
Yuval Mintzfefb0202016-05-11 16:36:19 +030084#define CHIP_NUM_57980S_IOV 0x1664
Yuval Mintze712d522015-10-26 11:02:27 +020085
86#ifndef PCI_DEVICE_ID_NX2_57980E
87#define PCI_DEVICE_ID_57980S_40 CHIP_NUM_57980S_40
88#define PCI_DEVICE_ID_57980S_10 CHIP_NUM_57980S_10
89#define PCI_DEVICE_ID_57980S_MF CHIP_NUM_57980S_MF
90#define PCI_DEVICE_ID_57980S_100 CHIP_NUM_57980S_100
91#define PCI_DEVICE_ID_57980S_50 CHIP_NUM_57980S_50
92#define PCI_DEVICE_ID_57980S_25 CHIP_NUM_57980S_25
Yuval Mintzfefb0202016-05-11 16:36:19 +030093#define PCI_DEVICE_ID_57980S_IOV CHIP_NUM_57980S_IOV
Yuval Mintze712d522015-10-26 11:02:27 +020094#endif
95
Yuval Mintzfefb0202016-05-11 16:36:19 +030096enum qede_pci_private {
97 QEDE_PRIVATE_PF,
98 QEDE_PRIVATE_VF
99};
100
Yuval Mintze712d522015-10-26 11:02:27 +0200101static const struct pci_device_id qede_pci_tbl[] = {
Yuval Mintzfefb0202016-05-11 16:36:19 +0300102 {PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_57980S_40), QEDE_PRIVATE_PF},
103 {PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_57980S_10), QEDE_PRIVATE_PF},
104 {PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_57980S_MF), QEDE_PRIVATE_PF},
105 {PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_57980S_100), QEDE_PRIVATE_PF},
106 {PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_57980S_50), QEDE_PRIVATE_PF},
107 {PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_57980S_25), QEDE_PRIVATE_PF},
Arnd Bergmann14b84e82016-06-01 15:29:13 +0200108#ifdef CONFIG_QED_SRIOV
Yuval Mintzfefb0202016-05-11 16:36:19 +0300109 {PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_57980S_IOV), QEDE_PRIVATE_VF},
Arnd Bergmann14b84e82016-06-01 15:29:13 +0200110#endif
Yuval Mintze712d522015-10-26 11:02:27 +0200111 { 0 }
112};
113
114MODULE_DEVICE_TABLE(pci, qede_pci_tbl);
115
116static int qede_probe(struct pci_dev *pdev, const struct pci_device_id *id);
117
118#define TX_TIMEOUT (5 * HZ)
119
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +0200120/* Utilize last protocol index for XDP */
121#define XDP_PI 11
122
Yuval Mintze712d522015-10-26 11:02:27 +0200123static void qede_remove(struct pci_dev *pdev);
Mintz, Yuval14d39642016-10-31 07:14:23 +0200124static void qede_shutdown(struct pci_dev *pdev);
Sudarsana Kallurua2ec6172015-10-26 11:02:32 +0200125static void qede_link_update(void *dev, struct qed_link_output *link);
Yuval Mintze712d522015-10-26 11:02:27 +0200126
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200127/* The qede lock is used to protect driver state change and driver flows that
128 * are not reentrant.
129 */
130void __qede_lock(struct qede_dev *edev)
131{
132 mutex_lock(&edev->qede_lock);
133}
134
135void __qede_unlock(struct qede_dev *edev)
136{
137 mutex_unlock(&edev->qede_lock);
138}
139
Yuval Mintzfefb0202016-05-11 16:36:19 +0300140#ifdef CONFIG_QED_SRIOV
Moshe Shemesh79aab092016-09-22 12:11:15 +0300141static int qede_set_vf_vlan(struct net_device *ndev, int vf, u16 vlan, u8 qos,
142 __be16 vlan_proto)
Yuval Mintz08feecd2016-05-11 16:36:20 +0300143{
144 struct qede_dev *edev = netdev_priv(ndev);
145
146 if (vlan > 4095) {
147 DP_NOTICE(edev, "Illegal vlan value %d\n", vlan);
148 return -EINVAL;
149 }
150
Moshe Shemesh79aab092016-09-22 12:11:15 +0300151 if (vlan_proto != htons(ETH_P_8021Q))
152 return -EPROTONOSUPPORT;
153
Yuval Mintz08feecd2016-05-11 16:36:20 +0300154 DP_VERBOSE(edev, QED_MSG_IOV, "Setting Vlan 0x%04x to VF [%d]\n",
155 vlan, vf);
156
157 return edev->ops->iov->set_vlan(edev->cdev, vlan, vf);
158}
159
Yuval Mintzeff16962016-05-11 16:36:21 +0300160static int qede_set_vf_mac(struct net_device *ndev, int vfidx, u8 *mac)
161{
162 struct qede_dev *edev = netdev_priv(ndev);
163
164 DP_VERBOSE(edev, QED_MSG_IOV,
165 "Setting MAC %02x:%02x:%02x:%02x:%02x:%02x to VF [%d]\n",
166 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], vfidx);
167
168 if (!is_valid_ether_addr(mac)) {
169 DP_VERBOSE(edev, QED_MSG_IOV, "MAC address isn't valid\n");
170 return -EINVAL;
171 }
172
173 return edev->ops->iov->set_mac(edev->cdev, mac, vfidx);
174}
175
Yuval Mintzfefb0202016-05-11 16:36:19 +0300176static int qede_sriov_configure(struct pci_dev *pdev, int num_vfs_param)
177{
178 struct qede_dev *edev = netdev_priv(pci_get_drvdata(pdev));
Yuval Mintz831bfb0e2016-05-11 16:36:25 +0300179 struct qed_dev_info *qed_info = &edev->dev_info.common;
180 int rc;
Yuval Mintzfefb0202016-05-11 16:36:19 +0300181
182 DP_VERBOSE(edev, QED_MSG_IOV, "Requested %d VFs\n", num_vfs_param);
183
Yuval Mintz831bfb0e2016-05-11 16:36:25 +0300184 rc = edev->ops->iov->configure(edev->cdev, num_vfs_param);
185
186 /* Enable/Disable Tx switching for PF */
187 if ((rc == num_vfs_param) && netif_running(edev->ndev) &&
188 qed_info->mf_mode != QED_MF_NPAR && qed_info->tx_switching) {
189 struct qed_update_vport_params params;
190
191 memset(&params, 0, sizeof(params));
192 params.vport_id = 0;
193 params.update_tx_switching_flg = 1;
194 params.tx_switching_flg = num_vfs_param ? 1 : 0;
195 edev->ops->vport_update(edev->cdev, &params);
196 }
197
198 return rc;
Yuval Mintzfefb0202016-05-11 16:36:19 +0300199}
200#endif
201
Yuval Mintze712d522015-10-26 11:02:27 +0200202static struct pci_driver qede_pci_driver = {
203 .name = "qede",
204 .id_table = qede_pci_tbl,
205 .probe = qede_probe,
206 .remove = qede_remove,
Mintz, Yuval14d39642016-10-31 07:14:23 +0200207 .shutdown = qede_shutdown,
Yuval Mintzfefb0202016-05-11 16:36:19 +0300208#ifdef CONFIG_QED_SRIOV
209 .sriov_configure = qede_sriov_configure,
210#endif
Yuval Mintze712d522015-10-26 11:02:27 +0200211};
212
Yuval Mintzc3aaa402016-10-14 05:19:17 -0400213static void qede_force_mac(void *dev, u8 *mac, bool forced)
Yuval Mintzeff16962016-05-11 16:36:21 +0300214{
215 struct qede_dev *edev = dev;
216
Yuval Mintzc3aaa402016-10-14 05:19:17 -0400217 /* MAC hints take effect only if we haven't set one already */
218 if (is_valid_ether_addr(edev->ndev->dev_addr) && !forced)
219 return;
220
Yuval Mintzeff16962016-05-11 16:36:21 +0300221 ether_addr_copy(edev->ndev->dev_addr, mac);
222 ether_addr_copy(edev->primary_mac, mac);
223}
224
Sudarsana Kallurua2ec6172015-10-26 11:02:32 +0200225static struct qed_eth_cb_ops qede_ll_ops = {
226 {
227 .link_update = qede_link_update,
228 },
Yuval Mintzeff16962016-05-11 16:36:21 +0300229 .force_mac = qede_force_mac,
Sudarsana Kallurua2ec6172015-10-26 11:02:32 +0200230};
231
Yuval Mintz29502192015-10-26 11:02:29 +0200232static int qede_netdev_event(struct notifier_block *this, unsigned long event,
233 void *ptr)
234{
235 struct net_device *ndev = netdev_notifier_info_to_dev(ptr);
236 struct ethtool_drvinfo drvinfo;
237 struct qede_dev *edev;
238
Ram Amranicee9fbd2016-10-01 21:59:56 +0300239 if (event != NETDEV_CHANGENAME && event != NETDEV_CHANGEADDR)
Yuval Mintz29502192015-10-26 11:02:29 +0200240 goto done;
241
242 /* Check whether this is a qede device */
243 if (!ndev || !ndev->ethtool_ops || !ndev->ethtool_ops->get_drvinfo)
244 goto done;
245
246 memset(&drvinfo, 0, sizeof(drvinfo));
247 ndev->ethtool_ops->get_drvinfo(ndev, &drvinfo);
248 if (strcmp(drvinfo.driver, "qede"))
249 goto done;
250 edev = netdev_priv(ndev);
251
Ram Amranicee9fbd2016-10-01 21:59:56 +0300252 switch (event) {
253 case NETDEV_CHANGENAME:
254 /* Notify qed of the name change */
255 if (!edev->ops || !edev->ops->common)
256 goto done;
257 edev->ops->common->set_id(edev->cdev, edev->ndev->name, "qede");
258 break;
259 case NETDEV_CHANGEADDR:
260 edev = netdev_priv(ndev);
261 qede_roce_event_changeaddr(edev);
262 break;
263 }
Yuval Mintz29502192015-10-26 11:02:29 +0200264
265done:
266 return NOTIFY_DONE;
267}
268
269static struct notifier_block qede_netdev_notifier = {
270 .notifier_call = qede_netdev_event,
271};
272
Yuval Mintze712d522015-10-26 11:02:27 +0200273static
274int __init qede_init(void)
275{
276 int ret;
Yuval Mintze712d522015-10-26 11:02:27 +0200277
Yuval Mintz525ef5c2016-08-15 10:42:45 +0300278 pr_info("qede_init: %s\n", version);
Yuval Mintze712d522015-10-26 11:02:27 +0200279
Rahul Verma95114342016-04-10 12:42:59 +0300280 qed_ops = qed_get_eth_ops();
Yuval Mintze712d522015-10-26 11:02:27 +0200281 if (!qed_ops) {
282 pr_notice("Failed to get qed ethtool operations\n");
283 return -EINVAL;
284 }
285
Yuval Mintz29502192015-10-26 11:02:29 +0200286 /* Must register notifier before pci ops, since we might miss
287 * interface rename after pci probe and netdev registeration.
288 */
289 ret = register_netdevice_notifier(&qede_netdev_notifier);
290 if (ret) {
291 pr_notice("Failed to register netdevice_notifier\n");
292 qed_put_eth_ops();
293 return -EINVAL;
294 }
295
Yuval Mintze712d522015-10-26 11:02:27 +0200296 ret = pci_register_driver(&qede_pci_driver);
297 if (ret) {
298 pr_notice("Failed to register driver\n");
Yuval Mintz29502192015-10-26 11:02:29 +0200299 unregister_netdevice_notifier(&qede_netdev_notifier);
Yuval Mintze712d522015-10-26 11:02:27 +0200300 qed_put_eth_ops();
301 return -EINVAL;
302 }
303
304 return 0;
305}
306
307static void __exit qede_cleanup(void)
308{
Yuval Mintz525ef5c2016-08-15 10:42:45 +0300309 if (debug & QED_LOG_INFO_MASK)
310 pr_info("qede_cleanup called\n");
Yuval Mintze712d522015-10-26 11:02:27 +0200311
Yuval Mintz29502192015-10-26 11:02:29 +0200312 unregister_netdevice_notifier(&qede_netdev_notifier);
Yuval Mintze712d522015-10-26 11:02:27 +0200313 pci_unregister_driver(&qede_pci_driver);
314 qed_put_eth_ops();
315}
316
317module_init(qede_init);
318module_exit(qede_cleanup);
319
Yuval Mintz29502192015-10-26 11:02:29 +0200320static int qede_open(struct net_device *ndev);
321static int qede_close(struct net_device *ndev);
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +0200322static int qede_set_mac_addr(struct net_device *ndev, void *p);
323static void qede_set_rx_mode(struct net_device *ndev);
324static void qede_config_rx_mode(struct net_device *ndev);
325
326static int qede_set_ucast_rx_mac(struct qede_dev *edev,
327 enum qed_filter_xcast_params_type opcode,
328 unsigned char mac[ETH_ALEN])
329{
330 struct qed_filter_params filter_cmd;
331
332 memset(&filter_cmd, 0, sizeof(filter_cmd));
333 filter_cmd.type = QED_FILTER_TYPE_UCAST;
334 filter_cmd.filter.ucast.type = opcode;
335 filter_cmd.filter.ucast.mac_valid = 1;
336 ether_addr_copy(filter_cmd.filter.ucast.mac, mac);
337
338 return edev->ops->filter_config(edev->cdev, &filter_cmd);
339}
340
Sudarsana Reddy Kalluru7c1bfca2016-02-18 17:00:40 +0200341static int qede_set_ucast_rx_vlan(struct qede_dev *edev,
342 enum qed_filter_xcast_params_type opcode,
343 u16 vid)
344{
345 struct qed_filter_params filter_cmd;
346
347 memset(&filter_cmd, 0, sizeof(filter_cmd));
348 filter_cmd.type = QED_FILTER_TYPE_UCAST;
349 filter_cmd.filter.ucast.type = opcode;
350 filter_cmd.filter.ucast.vlan_valid = 1;
351 filter_cmd.filter.ucast.vlan = vid;
352
353 return edev->ops->filter_config(edev->cdev, &filter_cmd);
354}
355
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200356void qede_fill_by_demand_stats(struct qede_dev *edev)
357{
358 struct qed_eth_stats stats;
359
360 edev->ops->get_vport_stats(edev->cdev, &stats);
361 edev->stats.no_buff_discards = stats.no_buff_discards;
Sudarsana Reddy Kalluru1a5a3662016-08-16 10:51:01 -0400362 edev->stats.packet_too_big_discard = stats.packet_too_big_discard;
363 edev->stats.ttl0_discard = stats.ttl0_discard;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200364 edev->stats.rx_ucast_bytes = stats.rx_ucast_bytes;
365 edev->stats.rx_mcast_bytes = stats.rx_mcast_bytes;
366 edev->stats.rx_bcast_bytes = stats.rx_bcast_bytes;
367 edev->stats.rx_ucast_pkts = stats.rx_ucast_pkts;
368 edev->stats.rx_mcast_pkts = stats.rx_mcast_pkts;
369 edev->stats.rx_bcast_pkts = stats.rx_bcast_pkts;
370 edev->stats.mftag_filter_discards = stats.mftag_filter_discards;
371 edev->stats.mac_filter_discards = stats.mac_filter_discards;
372
373 edev->stats.tx_ucast_bytes = stats.tx_ucast_bytes;
374 edev->stats.tx_mcast_bytes = stats.tx_mcast_bytes;
375 edev->stats.tx_bcast_bytes = stats.tx_bcast_bytes;
376 edev->stats.tx_ucast_pkts = stats.tx_ucast_pkts;
377 edev->stats.tx_mcast_pkts = stats.tx_mcast_pkts;
378 edev->stats.tx_bcast_pkts = stats.tx_bcast_pkts;
379 edev->stats.tx_err_drop_pkts = stats.tx_err_drop_pkts;
380 edev->stats.coalesced_pkts = stats.tpa_coalesced_pkts;
381 edev->stats.coalesced_events = stats.tpa_coalesced_events;
382 edev->stats.coalesced_aborts_num = stats.tpa_aborts_num;
383 edev->stats.non_coalesced_pkts = stats.tpa_not_coalesced_pkts;
384 edev->stats.coalesced_bytes = stats.tpa_coalesced_bytes;
385
386 edev->stats.rx_64_byte_packets = stats.rx_64_byte_packets;
Yuval Mintzd4967cf2016-04-22 08:41:01 +0300387 edev->stats.rx_65_to_127_byte_packets = stats.rx_65_to_127_byte_packets;
388 edev->stats.rx_128_to_255_byte_packets =
389 stats.rx_128_to_255_byte_packets;
390 edev->stats.rx_256_to_511_byte_packets =
391 stats.rx_256_to_511_byte_packets;
392 edev->stats.rx_512_to_1023_byte_packets =
393 stats.rx_512_to_1023_byte_packets;
394 edev->stats.rx_1024_to_1518_byte_packets =
395 stats.rx_1024_to_1518_byte_packets;
396 edev->stats.rx_1519_to_1522_byte_packets =
397 stats.rx_1519_to_1522_byte_packets;
398 edev->stats.rx_1519_to_2047_byte_packets =
399 stats.rx_1519_to_2047_byte_packets;
400 edev->stats.rx_2048_to_4095_byte_packets =
401 stats.rx_2048_to_4095_byte_packets;
402 edev->stats.rx_4096_to_9216_byte_packets =
403 stats.rx_4096_to_9216_byte_packets;
404 edev->stats.rx_9217_to_16383_byte_packets =
405 stats.rx_9217_to_16383_byte_packets;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200406 edev->stats.rx_crc_errors = stats.rx_crc_errors;
407 edev->stats.rx_mac_crtl_frames = stats.rx_mac_crtl_frames;
408 edev->stats.rx_pause_frames = stats.rx_pause_frames;
409 edev->stats.rx_pfc_frames = stats.rx_pfc_frames;
410 edev->stats.rx_align_errors = stats.rx_align_errors;
411 edev->stats.rx_carrier_errors = stats.rx_carrier_errors;
412 edev->stats.rx_oversize_packets = stats.rx_oversize_packets;
413 edev->stats.rx_jabbers = stats.rx_jabbers;
414 edev->stats.rx_undersize_packets = stats.rx_undersize_packets;
415 edev->stats.rx_fragments = stats.rx_fragments;
416 edev->stats.tx_64_byte_packets = stats.tx_64_byte_packets;
417 edev->stats.tx_65_to_127_byte_packets = stats.tx_65_to_127_byte_packets;
418 edev->stats.tx_128_to_255_byte_packets =
419 stats.tx_128_to_255_byte_packets;
420 edev->stats.tx_256_to_511_byte_packets =
421 stats.tx_256_to_511_byte_packets;
422 edev->stats.tx_512_to_1023_byte_packets =
423 stats.tx_512_to_1023_byte_packets;
424 edev->stats.tx_1024_to_1518_byte_packets =
425 stats.tx_1024_to_1518_byte_packets;
426 edev->stats.tx_1519_to_2047_byte_packets =
427 stats.tx_1519_to_2047_byte_packets;
428 edev->stats.tx_2048_to_4095_byte_packets =
429 stats.tx_2048_to_4095_byte_packets;
430 edev->stats.tx_4096_to_9216_byte_packets =
431 stats.tx_4096_to_9216_byte_packets;
432 edev->stats.tx_9217_to_16383_byte_packets =
433 stats.tx_9217_to_16383_byte_packets;
434 edev->stats.tx_pause_frames = stats.tx_pause_frames;
435 edev->stats.tx_pfc_frames = stats.tx_pfc_frames;
436 edev->stats.tx_lpi_entry_count = stats.tx_lpi_entry_count;
437 edev->stats.tx_total_collisions = stats.tx_total_collisions;
438 edev->stats.brb_truncates = stats.brb_truncates;
439 edev->stats.brb_discards = stats.brb_discards;
440 edev->stats.tx_mac_ctrl_frames = stats.tx_mac_ctrl_frames;
441}
442
Yuval Mintz1a635e42016-08-15 10:42:43 +0300443static
444struct rtnl_link_stats64 *qede_get_stats64(struct net_device *dev,
445 struct rtnl_link_stats64 *stats)
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200446{
447 struct qede_dev *edev = netdev_priv(dev);
448
449 qede_fill_by_demand_stats(edev);
450
451 stats->rx_packets = edev->stats.rx_ucast_pkts +
452 edev->stats.rx_mcast_pkts +
453 edev->stats.rx_bcast_pkts;
454 stats->tx_packets = edev->stats.tx_ucast_pkts +
455 edev->stats.tx_mcast_pkts +
456 edev->stats.tx_bcast_pkts;
457
458 stats->rx_bytes = edev->stats.rx_ucast_bytes +
459 edev->stats.rx_mcast_bytes +
460 edev->stats.rx_bcast_bytes;
461
462 stats->tx_bytes = edev->stats.tx_ucast_bytes +
463 edev->stats.tx_mcast_bytes +
464 edev->stats.tx_bcast_bytes;
465
466 stats->tx_errors = edev->stats.tx_err_drop_pkts;
467 stats->multicast = edev->stats.rx_mcast_pkts +
468 edev->stats.rx_bcast_pkts;
469
470 stats->rx_fifo_errors = edev->stats.no_buff_discards;
471
472 stats->collisions = edev->stats.tx_total_collisions;
473 stats->rx_crc_errors = edev->stats.rx_crc_errors;
474 stats->rx_frame_errors = edev->stats.rx_align_errors;
475
476 return stats;
477}
478
Yuval Mintz733def62016-05-11 16:36:22 +0300479#ifdef CONFIG_QED_SRIOV
Yuval Mintz73390ac2016-05-11 16:36:24 +0300480static int qede_get_vf_config(struct net_device *dev, int vfidx,
481 struct ifla_vf_info *ivi)
482{
483 struct qede_dev *edev = netdev_priv(dev);
484
485 if (!edev->ops)
486 return -EINVAL;
487
488 return edev->ops->iov->get_config(edev->cdev, vfidx, ivi);
489}
490
Yuval Mintz733def62016-05-11 16:36:22 +0300491static int qede_set_vf_rate(struct net_device *dev, int vfidx,
492 int min_tx_rate, int max_tx_rate)
493{
494 struct qede_dev *edev = netdev_priv(dev);
495
Yuval Mintzbe7b6d62016-05-26 11:01:17 +0300496 return edev->ops->iov->set_rate(edev->cdev, vfidx, min_tx_rate,
Yuval Mintz733def62016-05-11 16:36:22 +0300497 max_tx_rate);
498}
499
Yuval Mintz6ddc7602016-05-11 16:36:23 +0300500static int qede_set_vf_spoofchk(struct net_device *dev, int vfidx, bool val)
501{
502 struct qede_dev *edev = netdev_priv(dev);
503
504 if (!edev->ops)
505 return -EINVAL;
506
507 return edev->ops->iov->set_spoof(edev->cdev, vfidx, val);
508}
509
Yuval Mintz733def62016-05-11 16:36:22 +0300510static int qede_set_vf_link_state(struct net_device *dev, int vfidx,
511 int link_state)
512{
513 struct qede_dev *edev = netdev_priv(dev);
514
515 if (!edev->ops)
516 return -EINVAL;
517
518 return edev->ops->iov->set_link_state(edev->cdev, vfidx, link_state);
519}
520#endif
521
Sudarsana Reddy Kalluru7c1bfca2016-02-18 17:00:40 +0200522static void qede_config_accept_any_vlan(struct qede_dev *edev, bool action)
523{
524 struct qed_update_vport_params params;
525 int rc;
526
527 /* Proceed only if action actually needs to be performed */
528 if (edev->accept_any_vlan == action)
529 return;
530
531 memset(&params, 0, sizeof(params));
532
533 params.vport_id = 0;
534 params.accept_any_vlan = action;
535 params.update_accept_any_vlan_flg = 1;
536
537 rc = edev->ops->vport_update(edev->cdev, &params);
538 if (rc) {
539 DP_ERR(edev, "Failed to %s accept-any-vlan\n",
540 action ? "enable" : "disable");
541 } else {
542 DP_INFO(edev, "%s accept-any-vlan\n",
543 action ? "enabled" : "disabled");
544 edev->accept_any_vlan = action;
545 }
546}
547
548static int qede_vlan_rx_add_vid(struct net_device *dev, __be16 proto, u16 vid)
549{
550 struct qede_dev *edev = netdev_priv(dev);
551 struct qede_vlan *vlan, *tmp;
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200552 int rc = 0;
Sudarsana Reddy Kalluru7c1bfca2016-02-18 17:00:40 +0200553
554 DP_VERBOSE(edev, NETIF_MSG_IFUP, "Adding vlan 0x%04x\n", vid);
555
556 vlan = kzalloc(sizeof(*vlan), GFP_KERNEL);
557 if (!vlan) {
558 DP_INFO(edev, "Failed to allocate struct for vlan\n");
559 return -ENOMEM;
560 }
561 INIT_LIST_HEAD(&vlan->list);
562 vlan->vid = vid;
563 vlan->configured = false;
564
565 /* Verify vlan isn't already configured */
566 list_for_each_entry(tmp, &edev->vlan_list, list) {
567 if (tmp->vid == vlan->vid) {
568 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
569 "vlan already configured\n");
570 kfree(vlan);
571 return -EEXIST;
572 }
573 }
574
575 /* If interface is down, cache this VLAN ID and return */
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200576 __qede_lock(edev);
Sudarsana Reddy Kalluru7c1bfca2016-02-18 17:00:40 +0200577 if (edev->state != QEDE_STATE_OPEN) {
578 DP_VERBOSE(edev, NETIF_MSG_IFDOWN,
579 "Interface is down, VLAN %d will be configured when interface is up\n",
580 vid);
581 if (vid != 0)
582 edev->non_configured_vlans++;
583 list_add(&vlan->list, &edev->vlan_list);
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200584 goto out;
Sudarsana Reddy Kalluru7c1bfca2016-02-18 17:00:40 +0200585 }
586
587 /* Check for the filter limit.
588 * Note - vlan0 has a reserved filter and can be added without
589 * worrying about quota
590 */
591 if ((edev->configured_vlans < edev->dev_info.num_vlan_filters) ||
592 (vlan->vid == 0)) {
593 rc = qede_set_ucast_rx_vlan(edev,
594 QED_FILTER_XCAST_TYPE_ADD,
595 vlan->vid);
596 if (rc) {
597 DP_ERR(edev, "Failed to configure VLAN %d\n",
598 vlan->vid);
599 kfree(vlan);
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200600 goto out;
Sudarsana Reddy Kalluru7c1bfca2016-02-18 17:00:40 +0200601 }
602 vlan->configured = true;
603
604 /* vlan0 filter isn't consuming out of our quota */
605 if (vlan->vid != 0)
606 edev->configured_vlans++;
607 } else {
608 /* Out of quota; Activate accept-any-VLAN mode */
609 if (!edev->non_configured_vlans)
610 qede_config_accept_any_vlan(edev, true);
611
612 edev->non_configured_vlans++;
613 }
614
615 list_add(&vlan->list, &edev->vlan_list);
616
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200617out:
618 __qede_unlock(edev);
619 return rc;
Sudarsana Reddy Kalluru7c1bfca2016-02-18 17:00:40 +0200620}
621
622static void qede_del_vlan_from_list(struct qede_dev *edev,
623 struct qede_vlan *vlan)
624{
625 /* vlan0 filter isn't consuming out of our quota */
626 if (vlan->vid != 0) {
627 if (vlan->configured)
628 edev->configured_vlans--;
629 else
630 edev->non_configured_vlans--;
631 }
632
633 list_del(&vlan->list);
634 kfree(vlan);
635}
636
637static int qede_configure_vlan_filters(struct qede_dev *edev)
638{
639 int rc = 0, real_rc = 0, accept_any_vlan = 0;
640 struct qed_dev_eth_info *dev_info;
641 struct qede_vlan *vlan = NULL;
642
643 if (list_empty(&edev->vlan_list))
644 return 0;
645
646 dev_info = &edev->dev_info;
647
648 /* Configure non-configured vlans */
649 list_for_each_entry(vlan, &edev->vlan_list, list) {
650 if (vlan->configured)
651 continue;
652
653 /* We have used all our credits, now enable accept_any_vlan */
654 if ((vlan->vid != 0) &&
655 (edev->configured_vlans == dev_info->num_vlan_filters)) {
656 accept_any_vlan = 1;
657 continue;
658 }
659
660 DP_VERBOSE(edev, NETIF_MSG_IFUP, "Adding vlan %d\n", vlan->vid);
661
662 rc = qede_set_ucast_rx_vlan(edev, QED_FILTER_XCAST_TYPE_ADD,
663 vlan->vid);
664 if (rc) {
665 DP_ERR(edev, "Failed to configure VLAN %u\n",
666 vlan->vid);
667 real_rc = rc;
668 continue;
669 }
670
671 vlan->configured = true;
672 /* vlan0 filter doesn't consume our VLAN filter's quota */
673 if (vlan->vid != 0) {
674 edev->non_configured_vlans--;
675 edev->configured_vlans++;
676 }
677 }
678
679 /* enable accept_any_vlan mode if we have more VLANs than credits,
680 * or remove accept_any_vlan mode if we've actually removed
681 * a non-configured vlan, and all remaining vlans are truly configured.
682 */
683
684 if (accept_any_vlan)
685 qede_config_accept_any_vlan(edev, true);
686 else if (!edev->non_configured_vlans)
687 qede_config_accept_any_vlan(edev, false);
688
689 return real_rc;
690}
691
692static int qede_vlan_rx_kill_vid(struct net_device *dev, __be16 proto, u16 vid)
693{
694 struct qede_dev *edev = netdev_priv(dev);
695 struct qede_vlan *vlan = NULL;
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200696 int rc = 0;
Sudarsana Reddy Kalluru7c1bfca2016-02-18 17:00:40 +0200697
698 DP_VERBOSE(edev, NETIF_MSG_IFDOWN, "Removing vlan 0x%04x\n", vid);
699
700 /* Find whether entry exists */
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200701 __qede_lock(edev);
Sudarsana Reddy Kalluru7c1bfca2016-02-18 17:00:40 +0200702 list_for_each_entry(vlan, &edev->vlan_list, list)
703 if (vlan->vid == vid)
704 break;
705
706 if (!vlan || (vlan->vid != vid)) {
707 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
708 "Vlan isn't configured\n");
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200709 goto out;
Sudarsana Reddy Kalluru7c1bfca2016-02-18 17:00:40 +0200710 }
711
712 if (edev->state != QEDE_STATE_OPEN) {
713 /* As interface is already down, we don't have a VPORT
714 * instance to remove vlan filter. So just update vlan list
715 */
716 DP_VERBOSE(edev, NETIF_MSG_IFDOWN,
717 "Interface is down, removing VLAN from list only\n");
718 qede_del_vlan_from_list(edev, vlan);
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200719 goto out;
Sudarsana Reddy Kalluru7c1bfca2016-02-18 17:00:40 +0200720 }
721
722 /* Remove vlan */
Yuval Mintzc524e2f52016-07-27 14:45:19 +0300723 if (vlan->configured) {
724 rc = qede_set_ucast_rx_vlan(edev, QED_FILTER_XCAST_TYPE_DEL,
725 vid);
726 if (rc) {
727 DP_ERR(edev, "Failed to remove VLAN %d\n", vid);
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200728 goto out;
Yuval Mintzc524e2f52016-07-27 14:45:19 +0300729 }
Sudarsana Reddy Kalluru7c1bfca2016-02-18 17:00:40 +0200730 }
731
732 qede_del_vlan_from_list(edev, vlan);
733
734 /* We have removed a VLAN - try to see if we can
735 * configure non-configured VLAN from the list.
736 */
737 rc = qede_configure_vlan_filters(edev);
738
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200739out:
740 __qede_unlock(edev);
Sudarsana Reddy Kalluru7c1bfca2016-02-18 17:00:40 +0200741 return rc;
742}
743
744static void qede_vlan_mark_nonconfigured(struct qede_dev *edev)
745{
746 struct qede_vlan *vlan = NULL;
747
748 if (list_empty(&edev->vlan_list))
749 return;
750
751 list_for_each_entry(vlan, &edev->vlan_list, list) {
752 if (!vlan->configured)
753 continue;
754
755 vlan->configured = false;
756
757 /* vlan0 filter isn't consuming out of our quota */
758 if (vlan->vid != 0) {
759 edev->non_configured_vlans++;
760 edev->configured_vlans--;
761 }
762
763 DP_VERBOSE(edev, NETIF_MSG_IFDOWN,
Yuval Mintz1a635e42016-08-15 10:42:43 +0300764 "marked vlan %d as non-configured\n", vlan->vid);
Sudarsana Reddy Kalluru7c1bfca2016-02-18 17:00:40 +0200765 }
766
767 edev->accept_any_vlan = false;
768}
769
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200770static void qede_set_features_reload(struct qede_dev *edev,
771 struct qede_reload_args *args)
772{
773 edev->ndev->features = args->u.features;
774}
775
776int qede_set_features(struct net_device *dev, netdev_features_t features)
Yuval Mintzce2b8852016-05-26 11:01:18 +0300777{
778 struct qede_dev *edev = netdev_priv(dev);
779 netdev_features_t changes = features ^ dev->features;
780 bool need_reload = false;
781
782 /* No action needed if hardware GRO is disabled during driver load */
783 if (changes & NETIF_F_GRO) {
784 if (dev->features & NETIF_F_GRO)
785 need_reload = !edev->gro_disable;
786 else
787 need_reload = edev->gro_disable;
788 }
789
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200790 if (need_reload) {
791 struct qede_reload_args args;
792
793 args.u.features = features;
794 args.func = &qede_set_features_reload;
795
Mintz, Yuval496e0512016-11-29 16:47:09 +0200796 /* Make sure that we definitely need to reload.
797 * In case of an eBPF attached program, there will be no FW
798 * aggregations, so no need to actually reload.
799 */
800 __qede_lock(edev);
801 if (edev->xdp_prog)
802 args.func(edev, &args);
803 else
804 qede_reload(edev, &args, true);
805 __qede_unlock(edev);
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200806
Yuval Mintzce2b8852016-05-26 11:01:18 +0300807 return 1;
808 }
809
810 return 0;
811}
812
Alexander Duyckf9f082a2016-06-16 12:22:57 -0700813static void qede_udp_tunnel_add(struct net_device *dev,
814 struct udp_tunnel_info *ti)
Manish Choprab18e1702016-04-14 01:38:30 -0400815{
816 struct qede_dev *edev = netdev_priv(dev);
Alexander Duyckf9f082a2016-06-16 12:22:57 -0700817 u16 t_port = ntohs(ti->port);
Manish Choprab18e1702016-04-14 01:38:30 -0400818
Alexander Duyckf9f082a2016-06-16 12:22:57 -0700819 switch (ti->type) {
820 case UDP_TUNNEL_TYPE_VXLAN:
821 if (edev->vxlan_dst_port)
822 return;
823
824 edev->vxlan_dst_port = t_port;
825
Yuval Mintz525ef5c2016-08-15 10:42:45 +0300826 DP_VERBOSE(edev, QED_MSG_DEBUG, "Added vxlan port=%d\n",
Alexander Duyckf9f082a2016-06-16 12:22:57 -0700827 t_port);
828
829 set_bit(QEDE_SP_VXLAN_PORT_CONFIG, &edev->sp_flags);
830 break;
831 case UDP_TUNNEL_TYPE_GENEVE:
832 if (edev->geneve_dst_port)
833 return;
834
835 edev->geneve_dst_port = t_port;
836
Yuval Mintz525ef5c2016-08-15 10:42:45 +0300837 DP_VERBOSE(edev, QED_MSG_DEBUG, "Added geneve port=%d\n",
Alexander Duyckf9f082a2016-06-16 12:22:57 -0700838 t_port);
839 set_bit(QEDE_SP_GENEVE_PORT_CONFIG, &edev->sp_flags);
840 break;
841 default:
Manish Choprab18e1702016-04-14 01:38:30 -0400842 return;
Alexander Duyckf9f082a2016-06-16 12:22:57 -0700843 }
Manish Choprab18e1702016-04-14 01:38:30 -0400844
Manish Choprab18e1702016-04-14 01:38:30 -0400845 schedule_delayed_work(&edev->sp_task, 0);
846}
847
Alexander Duyckf9f082a2016-06-16 12:22:57 -0700848static void qede_udp_tunnel_del(struct net_device *dev,
849 struct udp_tunnel_info *ti)
Manish Choprab18e1702016-04-14 01:38:30 -0400850{
851 struct qede_dev *edev = netdev_priv(dev);
Alexander Duyckf9f082a2016-06-16 12:22:57 -0700852 u16 t_port = ntohs(ti->port);
Manish Choprab18e1702016-04-14 01:38:30 -0400853
Alexander Duyckf9f082a2016-06-16 12:22:57 -0700854 switch (ti->type) {
855 case UDP_TUNNEL_TYPE_VXLAN:
856 if (t_port != edev->vxlan_dst_port)
857 return;
858
859 edev->vxlan_dst_port = 0;
860
Yuval Mintz525ef5c2016-08-15 10:42:45 +0300861 DP_VERBOSE(edev, QED_MSG_DEBUG, "Deleted vxlan port=%d\n",
Alexander Duyckf9f082a2016-06-16 12:22:57 -0700862 t_port);
863
864 set_bit(QEDE_SP_VXLAN_PORT_CONFIG, &edev->sp_flags);
865 break;
866 case UDP_TUNNEL_TYPE_GENEVE:
867 if (t_port != edev->geneve_dst_port)
868 return;
869
870 edev->geneve_dst_port = 0;
871
Yuval Mintz525ef5c2016-08-15 10:42:45 +0300872 DP_VERBOSE(edev, QED_MSG_DEBUG, "Deleted geneve port=%d\n",
Alexander Duyckf9f082a2016-06-16 12:22:57 -0700873 t_port);
874 set_bit(QEDE_SP_GENEVE_PORT_CONFIG, &edev->sp_flags);
875 break;
876 default:
Manish Choprab18e1702016-04-14 01:38:30 -0400877 return;
Alexander Duyckf9f082a2016-06-16 12:22:57 -0700878 }
Manish Choprab18e1702016-04-14 01:38:30 -0400879
Manish Choprab18e1702016-04-14 01:38:30 -0400880 schedule_delayed_work(&edev->sp_task, 0);
881}
Manish Chopra9a109dd2016-04-14 01:38:31 -0400882
Mintz, Yuval496e0512016-11-29 16:47:09 +0200883static void qede_xdp_reload_func(struct qede_dev *edev,
884 struct qede_reload_args *args)
885{
886 struct bpf_prog *old;
887
888 old = xchg(&edev->xdp_prog, args->u.new_prog);
889 if (old)
890 bpf_prog_put(old);
891}
892
893static int qede_xdp_set(struct qede_dev *edev, struct bpf_prog *prog)
894{
895 struct qede_reload_args args;
896
Martin KaFai Lau17bedab2016-12-07 15:53:11 -0800897 if (prog && prog->xdp_adjust_head) {
898 DP_ERR(edev, "Does not support bpf_xdp_adjust_head()\n");
899 return -EOPNOTSUPP;
900 }
901
Mintz, Yuval496e0512016-11-29 16:47:09 +0200902 /* If we're called, there was already a bpf reference increment */
903 args.func = &qede_xdp_reload_func;
904 args.u.new_prog = prog;
905 qede_reload(edev, &args, false);
906
907 return 0;
908}
909
910static int qede_xdp(struct net_device *dev, struct netdev_xdp *xdp)
911{
912 struct qede_dev *edev = netdev_priv(dev);
913
914 switch (xdp->command) {
915 case XDP_SETUP_PROG:
916 return qede_xdp_set(edev, xdp->prog);
917 case XDP_QUERY_PROG:
918 xdp->prog_attached = !!edev->xdp_prog;
919 return 0;
920 default:
921 return -EINVAL;
922 }
923}
924
Yuval Mintz29502192015-10-26 11:02:29 +0200925static const struct net_device_ops qede_netdev_ops = {
926 .ndo_open = qede_open,
927 .ndo_stop = qede_close,
928 .ndo_start_xmit = qede_start_xmit,
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +0200929 .ndo_set_rx_mode = qede_set_rx_mode,
930 .ndo_set_mac_address = qede_set_mac_addr,
Yuval Mintz29502192015-10-26 11:02:29 +0200931 .ndo_validate_addr = eth_validate_addr,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200932 .ndo_change_mtu = qede_change_mtu,
Yuval Mintz08feecd2016-05-11 16:36:20 +0300933#ifdef CONFIG_QED_SRIOV
Yuval Mintzeff16962016-05-11 16:36:21 +0300934 .ndo_set_vf_mac = qede_set_vf_mac,
Yuval Mintz08feecd2016-05-11 16:36:20 +0300935 .ndo_set_vf_vlan = qede_set_vf_vlan,
936#endif
Sudarsana Reddy Kalluru7c1bfca2016-02-18 17:00:40 +0200937 .ndo_vlan_rx_add_vid = qede_vlan_rx_add_vid,
938 .ndo_vlan_rx_kill_vid = qede_vlan_rx_kill_vid,
Yuval Mintzce2b8852016-05-26 11:01:18 +0300939 .ndo_set_features = qede_set_features,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200940 .ndo_get_stats64 = qede_get_stats64,
Yuval Mintz733def62016-05-11 16:36:22 +0300941#ifdef CONFIG_QED_SRIOV
942 .ndo_set_vf_link_state = qede_set_vf_link_state,
Yuval Mintz6ddc7602016-05-11 16:36:23 +0300943 .ndo_set_vf_spoofchk = qede_set_vf_spoofchk,
Yuval Mintz73390ac2016-05-11 16:36:24 +0300944 .ndo_get_vf_config = qede_get_vf_config,
Yuval Mintz733def62016-05-11 16:36:22 +0300945 .ndo_set_vf_rate = qede_set_vf_rate,
946#endif
Alexander Duyckf9f082a2016-06-16 12:22:57 -0700947 .ndo_udp_tunnel_add = qede_udp_tunnel_add,
948 .ndo_udp_tunnel_del = qede_udp_tunnel_del,
Manish Chopra25695852016-10-14 05:19:19 -0400949 .ndo_features_check = qede_features_check,
Mintz, Yuval496e0512016-11-29 16:47:09 +0200950 .ndo_xdp = qede_xdp,
Yuval Mintz29502192015-10-26 11:02:29 +0200951};
952
953/* -------------------------------------------------------------------------
Yuval Mintze712d522015-10-26 11:02:27 +0200954 * START OF PROBE / REMOVE
955 * -------------------------------------------------------------------------
956 */
957
958static struct qede_dev *qede_alloc_etherdev(struct qed_dev *cdev,
959 struct pci_dev *pdev,
960 struct qed_dev_eth_info *info,
Yuval Mintz1a635e42016-08-15 10:42:43 +0300961 u32 dp_module, u8 dp_level)
Yuval Mintze712d522015-10-26 11:02:27 +0200962{
963 struct net_device *ndev;
964 struct qede_dev *edev;
965
966 ndev = alloc_etherdev_mqs(sizeof(*edev),
Yuval Mintz1a635e42016-08-15 10:42:43 +0300967 info->num_queues, info->num_queues);
Yuval Mintze712d522015-10-26 11:02:27 +0200968 if (!ndev) {
969 pr_err("etherdev allocation failed\n");
970 return NULL;
971 }
972
973 edev = netdev_priv(ndev);
974 edev->ndev = ndev;
975 edev->cdev = cdev;
976 edev->pdev = pdev;
977 edev->dp_module = dp_module;
978 edev->dp_level = dp_level;
979 edev->ops = qed_ops;
Yuval Mintz29502192015-10-26 11:02:29 +0200980 edev->q_num_rx_buffers = NUM_RX_BDS_DEF;
981 edev->q_num_tx_buffers = NUM_TX_BDS_DEF;
Yuval Mintze712d522015-10-26 11:02:27 +0200982
Yuval Mintz525ef5c2016-08-15 10:42:45 +0300983 DP_INFO(edev, "Allocated netdev with %d tx queues and %d rx queues\n",
984 info->num_queues, info->num_queues);
985
Yuval Mintze712d522015-10-26 11:02:27 +0200986 SET_NETDEV_DEV(ndev, &pdev->dev);
987
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200988 memset(&edev->stats, 0, sizeof(edev->stats));
Yuval Mintze712d522015-10-26 11:02:27 +0200989 memcpy(&edev->dev_info, info, sizeof(*info));
990
Sudarsana Reddy Kalluru7c1bfca2016-02-18 17:00:40 +0200991 INIT_LIST_HEAD(&edev->vlan_list);
992
Yuval Mintze712d522015-10-26 11:02:27 +0200993 return edev;
994}
995
996static void qede_init_ndev(struct qede_dev *edev)
997{
998 struct net_device *ndev = edev->ndev;
999 struct pci_dev *pdev = edev->pdev;
1000 u32 hw_features;
1001
1002 pci_set_drvdata(pdev, ndev);
1003
1004 ndev->mem_start = edev->dev_info.common.pci_mem_start;
1005 ndev->base_addr = ndev->mem_start;
1006 ndev->mem_end = edev->dev_info.common.pci_mem_end;
1007 ndev->irq = edev->dev_info.common.pci_irq;
1008
1009 ndev->watchdog_timeo = TX_TIMEOUT;
1010
Yuval Mintz29502192015-10-26 11:02:29 +02001011 ndev->netdev_ops = &qede_netdev_ops;
1012
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001013 qede_set_ethtool_ops(ndev);
1014
Mintz, Yuval0183eb12016-10-31 22:26:53 +02001015 ndev->priv_flags |= IFF_UNICAST_FLT;
Yuval Mintz7b7e70f2016-10-14 05:19:20 -04001016
Yuval Mintze712d522015-10-26 11:02:27 +02001017 /* user-changeble features */
1018 hw_features = NETIF_F_GRO | NETIF_F_SG |
1019 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
1020 NETIF_F_TSO | NETIF_F_TSO6;
1021
Manish Chopra14db81d2016-04-14 01:38:33 -04001022 /* Encap features*/
1023 hw_features |= NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL |
Manish Chopraa1502412016-10-14 05:19:18 -04001024 NETIF_F_TSO_ECN | NETIF_F_GSO_UDP_TUNNEL_CSUM |
1025 NETIF_F_GSO_GRE_CSUM;
Manish Chopra14db81d2016-04-14 01:38:33 -04001026 ndev->hw_enc_features = NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
1027 NETIF_F_SG | NETIF_F_TSO | NETIF_F_TSO_ECN |
1028 NETIF_F_TSO6 | NETIF_F_GSO_GRE |
Manish Chopraa1502412016-10-14 05:19:18 -04001029 NETIF_F_GSO_UDP_TUNNEL | NETIF_F_RXCSUM |
1030 NETIF_F_GSO_UDP_TUNNEL_CSUM |
1031 NETIF_F_GSO_GRE_CSUM;
Manish Chopra14db81d2016-04-14 01:38:33 -04001032
Yuval Mintze712d522015-10-26 11:02:27 +02001033 ndev->vlan_features = hw_features | NETIF_F_RXHASH | NETIF_F_RXCSUM |
1034 NETIF_F_HIGHDMA;
1035 ndev->features = hw_features | NETIF_F_RXHASH | NETIF_F_RXCSUM |
1036 NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HIGHDMA |
Sudarsana Reddy Kalluru7c1bfca2016-02-18 17:00:40 +02001037 NETIF_F_HW_VLAN_CTAG_FILTER | NETIF_F_HW_VLAN_CTAG_TX;
Yuval Mintze712d522015-10-26 11:02:27 +02001038
1039 ndev->hw_features = hw_features;
1040
Jarod Wilsoncaff2a82016-10-17 15:54:08 -04001041 /* MTU range: 46 - 9600 */
1042 ndev->min_mtu = ETH_ZLEN - ETH_HLEN;
1043 ndev->max_mtu = QEDE_MAX_JUMBO_PACKET_SIZE;
1044
Yuval Mintze712d522015-10-26 11:02:27 +02001045 /* Set network device HW mac */
1046 ether_addr_copy(edev->ndev->dev_addr, edev->dev_info.common.hw_mac);
Sudarsana Kalluru0fefbfb2016-10-31 07:14:21 +02001047
1048 ndev->mtu = edev->dev_info.common.mtu;
Yuval Mintze712d522015-10-26 11:02:27 +02001049}
1050
1051/* This function converts from 32b param to two params of level and module
1052 * Input 32b decoding:
1053 * b31 - enable all NOTICE prints. NOTICE prints are for deviation from the
1054 * 'happy' flow, e.g. memory allocation failed.
1055 * b30 - enable all INFO prints. INFO prints are for major steps in the flow
1056 * and provide important parameters.
1057 * b29-b0 - per-module bitmap, where each bit enables VERBOSE prints of that
1058 * module. VERBOSE prints are for tracking the specific flow in low level.
1059 *
1060 * Notice that the level should be that of the lowest required logs.
1061 */
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001062void qede_config_debug(uint debug, u32 *p_dp_module, u8 *p_dp_level)
Yuval Mintze712d522015-10-26 11:02:27 +02001063{
1064 *p_dp_level = QED_LEVEL_NOTICE;
1065 *p_dp_module = 0;
1066
1067 if (debug & QED_LOG_VERBOSE_MASK) {
1068 *p_dp_level = QED_LEVEL_VERBOSE;
1069 *p_dp_module = (debug & 0x3FFFFFFF);
1070 } else if (debug & QED_LOG_INFO_MASK) {
1071 *p_dp_level = QED_LEVEL_INFO;
1072 } else if (debug & QED_LOG_NOTICE_MASK) {
1073 *p_dp_level = QED_LEVEL_NOTICE;
1074 }
1075}
1076
Yuval Mintz29502192015-10-26 11:02:29 +02001077static void qede_free_fp_array(struct qede_dev *edev)
1078{
1079 if (edev->fp_array) {
1080 struct qede_fastpath *fp;
1081 int i;
1082
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001083 for_each_queue(i) {
Yuval Mintz29502192015-10-26 11:02:29 +02001084 fp = &edev->fp_array[i];
1085
1086 kfree(fp->sb_info);
1087 kfree(fp->rxq);
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001088 kfree(fp->xdp_tx);
Mintz, Yuval80439a12016-11-29 16:47:02 +02001089 kfree(fp->txq);
Yuval Mintz29502192015-10-26 11:02:29 +02001090 }
1091 kfree(edev->fp_array);
1092 }
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001093
1094 edev->num_queues = 0;
1095 edev->fp_num_tx = 0;
1096 edev->fp_num_rx = 0;
Yuval Mintz29502192015-10-26 11:02:29 +02001097}
1098
1099static int qede_alloc_fp_array(struct qede_dev *edev)
1100{
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001101 u8 fp_combined, fp_rx = edev->fp_num_rx;
Yuval Mintz29502192015-10-26 11:02:29 +02001102 struct qede_fastpath *fp;
1103 int i;
1104
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001105 edev->fp_array = kcalloc(QEDE_QUEUE_CNT(edev),
Yuval Mintz29502192015-10-26 11:02:29 +02001106 sizeof(*edev->fp_array), GFP_KERNEL);
1107 if (!edev->fp_array) {
1108 DP_NOTICE(edev, "fp array allocation failed\n");
1109 goto err;
1110 }
1111
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001112 fp_combined = QEDE_QUEUE_CNT(edev) - fp_rx - edev->fp_num_tx;
1113
1114 /* Allocate the FP elements for Rx queues followed by combined and then
1115 * the Tx. This ordering should be maintained so that the respective
1116 * queues (Rx or Tx) will be together in the fastpath array and the
1117 * associated ids will be sequential.
1118 */
1119 for_each_queue(i) {
Yuval Mintz29502192015-10-26 11:02:29 +02001120 fp = &edev->fp_array[i];
1121
Mintz, Yuval80439a12016-11-29 16:47:02 +02001122 fp->sb_info = kzalloc(sizeof(*fp->sb_info), GFP_KERNEL);
Yuval Mintz29502192015-10-26 11:02:29 +02001123 if (!fp->sb_info) {
1124 DP_NOTICE(edev, "sb info struct allocation failed\n");
1125 goto err;
1126 }
1127
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001128 if (fp_rx) {
1129 fp->type = QEDE_FASTPATH_RX;
1130 fp_rx--;
1131 } else if (fp_combined) {
1132 fp->type = QEDE_FASTPATH_COMBINED;
1133 fp_combined--;
1134 } else {
1135 fp->type = QEDE_FASTPATH_TX;
Yuval Mintz29502192015-10-26 11:02:29 +02001136 }
1137
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001138 if (fp->type & QEDE_FASTPATH_TX) {
Mintz, Yuval80439a12016-11-29 16:47:02 +02001139 fp->txq = kzalloc(sizeof(*fp->txq), GFP_KERNEL);
1140 if (!fp->txq)
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001141 goto err;
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001142 }
1143
1144 if (fp->type & QEDE_FASTPATH_RX) {
Mintz, Yuval80439a12016-11-29 16:47:02 +02001145 fp->rxq = kzalloc(sizeof(*fp->rxq), GFP_KERNEL);
1146 if (!fp->rxq)
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001147 goto err;
Mintz, Yuval496e0512016-11-29 16:47:09 +02001148
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001149 if (edev->xdp_prog) {
1150 fp->xdp_tx = kzalloc(sizeof(*fp->xdp_tx),
1151 GFP_KERNEL);
1152 if (!fp->xdp_tx)
1153 goto err;
Mintz, Yuval496e0512016-11-29 16:47:09 +02001154 fp->type |= QEDE_FASTPATH_XDP;
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001155 }
Yuval Mintz29502192015-10-26 11:02:29 +02001156 }
1157 }
1158
1159 return 0;
1160err:
1161 qede_free_fp_array(edev);
1162 return -ENOMEM;
1163}
1164
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +02001165static void qede_sp_task(struct work_struct *work)
1166{
1167 struct qede_dev *edev = container_of(work, struct qede_dev,
1168 sp_task.work);
Manish Choprab18e1702016-04-14 01:38:30 -04001169 struct qed_dev *cdev = edev->cdev;
1170
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001171 __qede_lock(edev);
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +02001172
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001173 if (test_and_clear_bit(QEDE_SP_RX_MODE, &edev->sp_flags))
1174 if (edev->state == QEDE_STATE_OPEN)
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +02001175 qede_config_rx_mode(edev->ndev);
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +02001176
Manish Choprab18e1702016-04-14 01:38:30 -04001177 if (test_and_clear_bit(QEDE_SP_VXLAN_PORT_CONFIG, &edev->sp_flags)) {
1178 struct qed_tunn_params tunn_params;
1179
1180 memset(&tunn_params, 0, sizeof(tunn_params));
1181 tunn_params.update_vxlan_port = 1;
1182 tunn_params.vxlan_port = edev->vxlan_dst_port;
1183 qed_ops->tunn_config(cdev, &tunn_params);
1184 }
1185
Manish Chopra9a109dd2016-04-14 01:38:31 -04001186 if (test_and_clear_bit(QEDE_SP_GENEVE_PORT_CONFIG, &edev->sp_flags)) {
1187 struct qed_tunn_params tunn_params;
1188
1189 memset(&tunn_params, 0, sizeof(tunn_params));
1190 tunn_params.update_geneve_port = 1;
1191 tunn_params.geneve_port = edev->geneve_dst_port;
1192 qed_ops->tunn_config(cdev, &tunn_params);
1193 }
1194
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001195 __qede_unlock(edev);
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +02001196}
1197
Yuval Mintze712d522015-10-26 11:02:27 +02001198static void qede_update_pf_params(struct qed_dev *cdev)
1199{
1200 struct qed_pf_params pf_params;
1201
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001202 /* 64 rx + 64 tx + 64 XDP */
Yuval Mintze712d522015-10-26 11:02:27 +02001203 memset(&pf_params, 0, sizeof(struct qed_pf_params));
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001204 pf_params.eth_pf_params.num_cons = 192;
Yuval Mintze712d522015-10-26 11:02:27 +02001205 qed_ops->common->update_pf_params(cdev, &pf_params);
1206}
1207
1208enum qede_probe_mode {
1209 QEDE_PROBE_NORMAL,
1210};
1211
1212static int __qede_probe(struct pci_dev *pdev, u32 dp_module, u8 dp_level,
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001213 bool is_vf, enum qede_probe_mode mode)
Yuval Mintze712d522015-10-26 11:02:27 +02001214{
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001215 struct qed_probe_params probe_params;
Yuval Mintz1a635e42016-08-15 10:42:43 +03001216 struct qed_slowpath_params sp_params;
Yuval Mintze712d522015-10-26 11:02:27 +02001217 struct qed_dev_eth_info dev_info;
1218 struct qede_dev *edev;
1219 struct qed_dev *cdev;
1220 int rc;
1221
1222 if (unlikely(dp_level & QED_LEVEL_INFO))
1223 pr_notice("Starting qede probe\n");
1224
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001225 memset(&probe_params, 0, sizeof(probe_params));
1226 probe_params.protocol = QED_PROTOCOL_ETH;
1227 probe_params.dp_module = dp_module;
1228 probe_params.dp_level = dp_level;
1229 probe_params.is_vf = is_vf;
1230 cdev = qed_ops->common->probe(pdev, &probe_params);
Yuval Mintze712d522015-10-26 11:02:27 +02001231 if (!cdev) {
1232 rc = -ENODEV;
1233 goto err0;
1234 }
1235
1236 qede_update_pf_params(cdev);
1237
1238 /* Start the Slowpath-process */
Yuval Mintz1a635e42016-08-15 10:42:43 +03001239 memset(&sp_params, 0, sizeof(sp_params));
1240 sp_params.int_mode = QED_INT_MODE_MSIX;
1241 sp_params.drv_major = QEDE_MAJOR_VERSION;
1242 sp_params.drv_minor = QEDE_MINOR_VERSION;
1243 sp_params.drv_rev = QEDE_REVISION_VERSION;
1244 sp_params.drv_eng = QEDE_ENGINEERING_VERSION;
1245 strlcpy(sp_params.name, "qede LAN", QED_DRV_VER_STR_SIZE);
1246 rc = qed_ops->common->slowpath_start(cdev, &sp_params);
Yuval Mintze712d522015-10-26 11:02:27 +02001247 if (rc) {
1248 pr_notice("Cannot start slowpath\n");
1249 goto err1;
1250 }
1251
1252 /* Learn information crucial for qede to progress */
1253 rc = qed_ops->fill_dev_info(cdev, &dev_info);
1254 if (rc)
1255 goto err2;
1256
1257 edev = qede_alloc_etherdev(cdev, pdev, &dev_info, dp_module,
1258 dp_level);
1259 if (!edev) {
1260 rc = -ENOMEM;
1261 goto err2;
1262 }
1263
Yuval Mintzfefb0202016-05-11 16:36:19 +03001264 if (is_vf)
1265 edev->flags |= QEDE_FLAG_IS_VF;
1266
Yuval Mintze712d522015-10-26 11:02:27 +02001267 qede_init_ndev(edev);
1268
Ram Amranicee9fbd2016-10-01 21:59:56 +03001269 rc = qede_roce_dev_add(edev);
1270 if (rc)
1271 goto err3;
1272
Yuval Mintz29502192015-10-26 11:02:29 +02001273 rc = register_netdev(edev->ndev);
1274 if (rc) {
1275 DP_NOTICE(edev, "Cannot register net-device\n");
Ram Amranicee9fbd2016-10-01 21:59:56 +03001276 goto err4;
Yuval Mintz29502192015-10-26 11:02:29 +02001277 }
1278
Yuval Mintze712d522015-10-26 11:02:27 +02001279 edev->ops->common->set_id(cdev, edev->ndev->name, DRV_MODULE_VERSION);
1280
Sudarsana Kallurua2ec6172015-10-26 11:02:32 +02001281 edev->ops->register_ops(cdev, &qede_ll_ops, edev);
1282
Sudarsana Reddy Kalluru489e45a2016-06-08 06:22:12 -04001283#ifdef CONFIG_DCB
Sudarsana Reddy Kalluru5fe118c2016-08-29 08:29:52 -04001284 if (!IS_VF(edev))
1285 qede_set_dcbnl_ops(edev->ndev);
Sudarsana Reddy Kalluru489e45a2016-06-08 06:22:12 -04001286#endif
1287
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +02001288 INIT_DELAYED_WORK(&edev->sp_task, qede_sp_task);
1289 mutex_init(&edev->qede_lock);
Manish Chopra3d789992016-06-30 02:35:21 -04001290 edev->rx_copybreak = QEDE_RX_HDR_SIZE;
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +02001291
Yuval Mintze712d522015-10-26 11:02:27 +02001292 DP_INFO(edev, "Ending successfully qede probe\n");
1293
1294 return 0;
1295
Ram Amranicee9fbd2016-10-01 21:59:56 +03001296err4:
1297 qede_roce_dev_remove(edev);
Yuval Mintz29502192015-10-26 11:02:29 +02001298err3:
1299 free_netdev(edev->ndev);
Yuval Mintze712d522015-10-26 11:02:27 +02001300err2:
1301 qed_ops->common->slowpath_stop(cdev);
1302err1:
1303 qed_ops->common->remove(cdev);
1304err0:
1305 return rc;
1306}
1307
1308static int qede_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1309{
Yuval Mintzfefb0202016-05-11 16:36:19 +03001310 bool is_vf = false;
Yuval Mintze712d522015-10-26 11:02:27 +02001311 u32 dp_module = 0;
1312 u8 dp_level = 0;
1313
Yuval Mintzfefb0202016-05-11 16:36:19 +03001314 switch ((enum qede_pci_private)id->driver_data) {
1315 case QEDE_PRIVATE_VF:
1316 if (debug & QED_LOG_VERBOSE_MASK)
1317 dev_err(&pdev->dev, "Probing a VF\n");
1318 is_vf = true;
1319 break;
1320 default:
1321 if (debug & QED_LOG_VERBOSE_MASK)
1322 dev_err(&pdev->dev, "Probing a PF\n");
1323 }
1324
Yuval Mintze712d522015-10-26 11:02:27 +02001325 qede_config_debug(debug, &dp_module, &dp_level);
1326
Yuval Mintzfefb0202016-05-11 16:36:19 +03001327 return __qede_probe(pdev, dp_module, dp_level, is_vf,
Yuval Mintze712d522015-10-26 11:02:27 +02001328 QEDE_PROBE_NORMAL);
1329}
1330
1331enum qede_remove_mode {
1332 QEDE_REMOVE_NORMAL,
1333};
1334
1335static void __qede_remove(struct pci_dev *pdev, enum qede_remove_mode mode)
1336{
1337 struct net_device *ndev = pci_get_drvdata(pdev);
1338 struct qede_dev *edev = netdev_priv(ndev);
1339 struct qed_dev *cdev = edev->cdev;
1340
1341 DP_INFO(edev, "Starting qede_remove\n");
1342
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +02001343 cancel_delayed_work_sync(&edev->sp_task);
Ram Amranicee9fbd2016-10-01 21:59:56 +03001344
Yuval Mintz29502192015-10-26 11:02:29 +02001345 unregister_netdev(ndev);
1346
Ram Amranicee9fbd2016-10-01 21:59:56 +03001347 qede_roce_dev_remove(edev);
1348
Yuval Mintze712d522015-10-26 11:02:27 +02001349 edev->ops->common->set_power_state(cdev, PCI_D0);
1350
1351 pci_set_drvdata(pdev, NULL);
1352
Mintz, Yuval496e0512016-11-29 16:47:09 +02001353 /* Release edev's reference to XDP's bpf if such exist */
1354 if (edev->xdp_prog)
1355 bpf_prog_put(edev->xdp_prog);
1356
Yuval Mintze712d522015-10-26 11:02:27 +02001357 free_netdev(ndev);
1358
1359 /* Use global ops since we've freed edev */
1360 qed_ops->common->slowpath_stop(cdev);
Mintz, Yuval14d39642016-10-31 07:14:23 +02001361 if (system_state == SYSTEM_POWER_OFF)
1362 return;
Yuval Mintze712d522015-10-26 11:02:27 +02001363 qed_ops->common->remove(cdev);
1364
Yuval Mintz525ef5c2016-08-15 10:42:45 +03001365 dev_info(&pdev->dev, "Ending qede_remove successfully\n");
Yuval Mintze712d522015-10-26 11:02:27 +02001366}
1367
1368static void qede_remove(struct pci_dev *pdev)
1369{
1370 __qede_remove(pdev, QEDE_REMOVE_NORMAL);
1371}
Yuval Mintz29502192015-10-26 11:02:29 +02001372
Mintz, Yuval14d39642016-10-31 07:14:23 +02001373static void qede_shutdown(struct pci_dev *pdev)
1374{
1375 __qede_remove(pdev, QEDE_REMOVE_NORMAL);
1376}
1377
Yuval Mintz29502192015-10-26 11:02:29 +02001378/* -------------------------------------------------------------------------
1379 * START OF LOAD / UNLOAD
1380 * -------------------------------------------------------------------------
1381 */
1382
1383static int qede_set_num_queues(struct qede_dev *edev)
1384{
1385 int rc;
1386 u16 rss_num;
1387
1388 /* Setup queues according to possible resources*/
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001389 if (edev->req_queues)
1390 rss_num = edev->req_queues;
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +02001391 else
1392 rss_num = netif_get_num_default_rss_queues() *
1393 edev->dev_info.common.num_hwfns;
Yuval Mintz29502192015-10-26 11:02:29 +02001394
1395 rss_num = min_t(u16, QEDE_MAX_RSS_CNT(edev), rss_num);
1396
1397 rc = edev->ops->common->set_fp_int(edev->cdev, rss_num);
1398 if (rc > 0) {
1399 /* Managed to request interrupts for our queues */
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001400 edev->num_queues = rc;
Yuval Mintz29502192015-10-26 11:02:29 +02001401 DP_INFO(edev, "Managed %d [of %d] RSS queues\n",
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001402 QEDE_QUEUE_CNT(edev), rss_num);
Yuval Mintz29502192015-10-26 11:02:29 +02001403 rc = 0;
1404 }
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001405
1406 edev->fp_num_tx = edev->req_num_tx;
1407 edev->fp_num_rx = edev->req_num_rx;
1408
Yuval Mintz29502192015-10-26 11:02:29 +02001409 return rc;
1410}
1411
1412static void qede_free_mem_sb(struct qede_dev *edev,
1413 struct qed_sb_info *sb_info)
1414{
1415 if (sb_info->sb_virt)
1416 dma_free_coherent(&edev->pdev->dev, sizeof(*sb_info->sb_virt),
1417 (void *)sb_info->sb_virt, sb_info->sb_phys);
1418}
1419
1420/* This function allocates fast-path status block memory */
1421static int qede_alloc_mem_sb(struct qede_dev *edev,
Yuval Mintz1a635e42016-08-15 10:42:43 +03001422 struct qed_sb_info *sb_info, u16 sb_id)
Yuval Mintz29502192015-10-26 11:02:29 +02001423{
1424 struct status_block *sb_virt;
1425 dma_addr_t sb_phys;
1426 int rc;
1427
1428 sb_virt = dma_alloc_coherent(&edev->pdev->dev,
Yuval Mintz1a635e42016-08-15 10:42:43 +03001429 sizeof(*sb_virt), &sb_phys, GFP_KERNEL);
Yuval Mintz29502192015-10-26 11:02:29 +02001430 if (!sb_virt) {
1431 DP_ERR(edev, "Status block allocation failed\n");
1432 return -ENOMEM;
1433 }
1434
1435 rc = edev->ops->common->sb_init(edev->cdev, sb_info,
1436 sb_virt, sb_phys, sb_id,
1437 QED_SB_TYPE_L2_QUEUE);
1438 if (rc) {
1439 DP_ERR(edev, "Status block initialization failed\n");
1440 dma_free_coherent(&edev->pdev->dev, sizeof(*sb_virt),
1441 sb_virt, sb_phys);
1442 return rc;
1443 }
1444
1445 return 0;
1446}
1447
1448static void qede_free_rx_buffers(struct qede_dev *edev,
1449 struct qede_rx_queue *rxq)
1450{
1451 u16 i;
1452
1453 for (i = rxq->sw_rx_cons; i != rxq->sw_rx_prod; i++) {
1454 struct sw_rx_data *rx_buf;
Yuval Mintzfc48b7a2016-02-15 13:22:35 -05001455 struct page *data;
Yuval Mintz29502192015-10-26 11:02:29 +02001456
1457 rx_buf = &rxq->sw_rx_ring[i & NUM_RX_BDS_MAX];
1458 data = rx_buf->data;
1459
Yuval Mintzfc48b7a2016-02-15 13:22:35 -05001460 dma_unmap_page(&edev->pdev->dev,
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001461 rx_buf->mapping, PAGE_SIZE, rxq->data_direction);
Yuval Mintz29502192015-10-26 11:02:29 +02001462
1463 rx_buf->data = NULL;
Yuval Mintzfc48b7a2016-02-15 13:22:35 -05001464 __free_page(data);
Yuval Mintz29502192015-10-26 11:02:29 +02001465 }
1466}
1467
Yuval Mintz1a635e42016-08-15 10:42:43 +03001468static void qede_free_sge_mem(struct qede_dev *edev, struct qede_rx_queue *rxq)
1469{
Manish Chopra55482ed2016-03-04 12:35:06 -05001470 int i;
1471
1472 if (edev->gro_disable)
1473 return;
1474
1475 for (i = 0; i < ETH_TPA_MAX_AGGS_NUM; i++) {
1476 struct qede_agg_info *tpa_info = &rxq->tpa_info[i];
Mintz, Yuval01e23012016-11-29 16:47:00 +02001477 struct sw_rx_data *replace_buf = &tpa_info->buffer;
Manish Chopra55482ed2016-03-04 12:35:06 -05001478
Manish Chopraf86af2d2016-04-20 03:03:27 -04001479 if (replace_buf->data) {
Manish Chopra55482ed2016-03-04 12:35:06 -05001480 dma_unmap_page(&edev->pdev->dev,
Manish Chopra09ec8e72016-05-18 07:43:57 -04001481 replace_buf->mapping,
Manish Chopra55482ed2016-03-04 12:35:06 -05001482 PAGE_SIZE, DMA_FROM_DEVICE);
1483 __free_page(replace_buf->data);
1484 }
1485 }
1486}
1487
Yuval Mintz1a635e42016-08-15 10:42:43 +03001488static void qede_free_mem_rxq(struct qede_dev *edev, struct qede_rx_queue *rxq)
Yuval Mintz29502192015-10-26 11:02:29 +02001489{
Manish Chopra55482ed2016-03-04 12:35:06 -05001490 qede_free_sge_mem(edev, rxq);
1491
Yuval Mintz29502192015-10-26 11:02:29 +02001492 /* Free rx buffers */
1493 qede_free_rx_buffers(edev, rxq);
1494
1495 /* Free the parallel SW ring */
1496 kfree(rxq->sw_rx_ring);
1497
1498 /* Free the real RQ ring used by FW */
1499 edev->ops->common->chain_free(edev->cdev, &rxq->rx_bd_ring);
1500 edev->ops->common->chain_free(edev->cdev, &rxq->rx_comp_ring);
1501}
1502
Yuval Mintz1a635e42016-08-15 10:42:43 +03001503static int qede_alloc_sge_mem(struct qede_dev *edev, struct qede_rx_queue *rxq)
Manish Chopra55482ed2016-03-04 12:35:06 -05001504{
1505 dma_addr_t mapping;
1506 int i;
1507
Mintz, Yuval496e0512016-11-29 16:47:09 +02001508 /* Don't perform FW aggregations in case of XDP */
1509 if (edev->xdp_prog)
1510 edev->gro_disable = 1;
1511
Manish Chopra55482ed2016-03-04 12:35:06 -05001512 if (edev->gro_disable)
1513 return 0;
1514
1515 if (edev->ndev->mtu > PAGE_SIZE) {
1516 edev->gro_disable = 1;
1517 return 0;
1518 }
1519
1520 for (i = 0; i < ETH_TPA_MAX_AGGS_NUM; i++) {
1521 struct qede_agg_info *tpa_info = &rxq->tpa_info[i];
Mintz, Yuval01e23012016-11-29 16:47:00 +02001522 struct sw_rx_data *replace_buf = &tpa_info->buffer;
Manish Chopra55482ed2016-03-04 12:35:06 -05001523
1524 replace_buf->data = alloc_pages(GFP_ATOMIC, 0);
1525 if (unlikely(!replace_buf->data)) {
1526 DP_NOTICE(edev,
1527 "Failed to allocate TPA skb pool [replacement buffer]\n");
1528 goto err;
1529 }
1530
1531 mapping = dma_map_page(&edev->pdev->dev, replace_buf->data, 0,
Mintz, Yuval95129252016-11-02 16:36:46 +02001532 PAGE_SIZE, DMA_FROM_DEVICE);
Manish Chopra55482ed2016-03-04 12:35:06 -05001533 if (unlikely(dma_mapping_error(&edev->pdev->dev, mapping))) {
1534 DP_NOTICE(edev,
1535 "Failed to map TPA replacement buffer\n");
1536 goto err;
1537 }
1538
Manish Chopra09ec8e72016-05-18 07:43:57 -04001539 replace_buf->mapping = mapping;
Mintz, Yuval01e23012016-11-29 16:47:00 +02001540 tpa_info->buffer.page_offset = 0;
1541 tpa_info->buffer_mapping = mapping;
1542 tpa_info->state = QEDE_AGG_STATE_NONE;
Manish Chopra55482ed2016-03-04 12:35:06 -05001543 }
1544
1545 return 0;
1546err:
1547 qede_free_sge_mem(edev, rxq);
1548 edev->gro_disable = 1;
1549 return -ENOMEM;
1550}
1551
Yuval Mintz29502192015-10-26 11:02:29 +02001552/* This function allocates all memory needed per Rx queue */
Yuval Mintz1a635e42016-08-15 10:42:43 +03001553static int qede_alloc_mem_rxq(struct qede_dev *edev, struct qede_rx_queue *rxq)
Yuval Mintz29502192015-10-26 11:02:29 +02001554{
Manish Chopraf86af2d2016-04-20 03:03:27 -04001555 int i, rc, size;
Yuval Mintz29502192015-10-26 11:02:29 +02001556
1557 rxq->num_rx_buffers = edev->q_num_rx_buffers;
1558
Yuval Mintz1a635e42016-08-15 10:42:43 +03001559 rxq->rx_buf_size = NET_IP_ALIGN + ETH_OVERHEAD + edev->ndev->mtu;
1560
Yuval Mintzfc48b7a2016-02-15 13:22:35 -05001561 if (rxq->rx_buf_size > PAGE_SIZE)
1562 rxq->rx_buf_size = PAGE_SIZE;
1563
Mintz, Yuval496e0512016-11-29 16:47:09 +02001564 /* Segment size to spilt a page in multiple equal parts,
1565 * unless XDP is used in which case we'd use the entire page.
1566 */
1567 if (!edev->xdp_prog)
1568 rxq->rx_buf_seg_size = roundup_pow_of_two(rxq->rx_buf_size);
1569 else
1570 rxq->rx_buf_seg_size = PAGE_SIZE;
Yuval Mintz29502192015-10-26 11:02:29 +02001571
1572 /* Allocate the parallel driver ring for Rx buffers */
Yuval Mintzfc48b7a2016-02-15 13:22:35 -05001573 size = sizeof(*rxq->sw_rx_ring) * RX_RING_SIZE;
Yuval Mintz29502192015-10-26 11:02:29 +02001574 rxq->sw_rx_ring = kzalloc(size, GFP_KERNEL);
1575 if (!rxq->sw_rx_ring) {
1576 DP_ERR(edev, "Rx buffers ring allocation failed\n");
Manish Chopraf86af2d2016-04-20 03:03:27 -04001577 rc = -ENOMEM;
Yuval Mintz29502192015-10-26 11:02:29 +02001578 goto err;
1579 }
1580
1581 /* Allocate FW Rx ring */
1582 rc = edev->ops->common->chain_alloc(edev->cdev,
1583 QED_CHAIN_USE_TO_CONSUME_PRODUCE,
1584 QED_CHAIN_MODE_NEXT_PTR,
Yuval Mintza91eb522016-06-03 14:35:32 +03001585 QED_CHAIN_CNT_TYPE_U16,
Yuval Mintzfc48b7a2016-02-15 13:22:35 -05001586 RX_RING_SIZE,
Yuval Mintz29502192015-10-26 11:02:29 +02001587 sizeof(struct eth_rx_bd),
1588 &rxq->rx_bd_ring);
1589
1590 if (rc)
1591 goto err;
1592
1593 /* Allocate FW completion ring */
1594 rc = edev->ops->common->chain_alloc(edev->cdev,
1595 QED_CHAIN_USE_TO_CONSUME,
1596 QED_CHAIN_MODE_PBL,
Yuval Mintza91eb522016-06-03 14:35:32 +03001597 QED_CHAIN_CNT_TYPE_U16,
Yuval Mintzfc48b7a2016-02-15 13:22:35 -05001598 RX_RING_SIZE,
Yuval Mintz29502192015-10-26 11:02:29 +02001599 sizeof(union eth_rx_cqe),
1600 &rxq->rx_comp_ring);
1601 if (rc)
1602 goto err;
1603
1604 /* Allocate buffers for the Rx ring */
1605 for (i = 0; i < rxq->num_rx_buffers; i++) {
Mintz, Yuval9eb22352016-11-29 16:47:08 +02001606 rc = qede_alloc_rx_buffer(rxq);
Manish Chopraf86af2d2016-04-20 03:03:27 -04001607 if (rc) {
1608 DP_ERR(edev,
1609 "Rx buffers allocation failed at index %d\n", i);
1610 goto err;
1611 }
Yuval Mintz29502192015-10-26 11:02:29 +02001612 }
1613
Manish Chopraf86af2d2016-04-20 03:03:27 -04001614 rc = qede_alloc_sge_mem(edev, rxq);
Yuval Mintz29502192015-10-26 11:02:29 +02001615err:
Manish Chopraf86af2d2016-04-20 03:03:27 -04001616 return rc;
Yuval Mintz29502192015-10-26 11:02:29 +02001617}
1618
Yuval Mintz1a635e42016-08-15 10:42:43 +03001619static void qede_free_mem_txq(struct qede_dev *edev, struct qede_tx_queue *txq)
Yuval Mintz29502192015-10-26 11:02:29 +02001620{
1621 /* Free the parallel SW ring */
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001622 if (txq->is_xdp)
1623 kfree(txq->sw_tx_ring.pages);
1624 else
1625 kfree(txq->sw_tx_ring.skbs);
Yuval Mintz29502192015-10-26 11:02:29 +02001626
1627 /* Free the real RQ ring used by FW */
1628 edev->ops->common->chain_free(edev->cdev, &txq->tx_pbl);
1629}
1630
1631/* This function allocates all memory needed per Tx queue */
Yuval Mintz1a635e42016-08-15 10:42:43 +03001632static int qede_alloc_mem_txq(struct qede_dev *edev, struct qede_tx_queue *txq)
Yuval Mintz29502192015-10-26 11:02:29 +02001633{
Yuval Mintz29502192015-10-26 11:02:29 +02001634 union eth_tx_bd_types *p_virt;
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001635 int size, rc;
Yuval Mintz29502192015-10-26 11:02:29 +02001636
1637 txq->num_tx_buffers = edev->q_num_tx_buffers;
1638
1639 /* Allocate the parallel driver ring for Tx buffers */
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001640 if (txq->is_xdp) {
1641 size = sizeof(*txq->sw_tx_ring.pages) * TX_RING_SIZE;
1642 txq->sw_tx_ring.pages = kzalloc(size, GFP_KERNEL);
1643 if (!txq->sw_tx_ring.pages)
1644 goto err;
1645 } else {
1646 size = sizeof(*txq->sw_tx_ring.skbs) * TX_RING_SIZE;
1647 txq->sw_tx_ring.skbs = kzalloc(size, GFP_KERNEL);
1648 if (!txq->sw_tx_ring.skbs)
1649 goto err;
Yuval Mintz29502192015-10-26 11:02:29 +02001650 }
1651
1652 rc = edev->ops->common->chain_alloc(edev->cdev,
1653 QED_CHAIN_USE_TO_CONSUME_PRODUCE,
1654 QED_CHAIN_MODE_PBL,
Yuval Mintza91eb522016-06-03 14:35:32 +03001655 QED_CHAIN_CNT_TYPE_U16,
Mintz, Yuval087892d2016-10-29 17:04:35 +03001656 TX_RING_SIZE,
Yuval Mintza91eb522016-06-03 14:35:32 +03001657 sizeof(*p_virt), &txq->tx_pbl);
Yuval Mintz29502192015-10-26 11:02:29 +02001658 if (rc)
1659 goto err;
1660
1661 return 0;
1662
1663err:
1664 qede_free_mem_txq(edev, txq);
1665 return -ENOMEM;
1666}
1667
1668/* This function frees all memory of a single fp */
Yuval Mintz1a635e42016-08-15 10:42:43 +03001669static void qede_free_mem_fp(struct qede_dev *edev, struct qede_fastpath *fp)
Yuval Mintz29502192015-10-26 11:02:29 +02001670{
Yuval Mintz29502192015-10-26 11:02:29 +02001671 qede_free_mem_sb(edev, fp->sb_info);
1672
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001673 if (fp->type & QEDE_FASTPATH_RX)
1674 qede_free_mem_rxq(edev, fp->rxq);
Yuval Mintz29502192015-10-26 11:02:29 +02001675
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001676 if (fp->type & QEDE_FASTPATH_TX)
Mintz, Yuval80439a12016-11-29 16:47:02 +02001677 qede_free_mem_txq(edev, fp->txq);
Yuval Mintz29502192015-10-26 11:02:29 +02001678}
1679
1680/* This function allocates all memory needed for a single fp (i.e. an entity
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001681 * which contains status block, one rx queue and/or multiple per-TC tx queues.
Yuval Mintz29502192015-10-26 11:02:29 +02001682 */
Yuval Mintz1a635e42016-08-15 10:42:43 +03001683static int qede_alloc_mem_fp(struct qede_dev *edev, struct qede_fastpath *fp)
Yuval Mintz29502192015-10-26 11:02:29 +02001684{
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001685 int rc = 0;
Yuval Mintz29502192015-10-26 11:02:29 +02001686
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001687 rc = qede_alloc_mem_sb(edev, fp->sb_info, fp->id);
Yuval Mintz29502192015-10-26 11:02:29 +02001688 if (rc)
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001689 goto out;
Yuval Mintz29502192015-10-26 11:02:29 +02001690
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001691 if (fp->type & QEDE_FASTPATH_RX) {
1692 rc = qede_alloc_mem_rxq(edev, fp->rxq);
Yuval Mintz29502192015-10-26 11:02:29 +02001693 if (rc)
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001694 goto out;
1695 }
1696
1697 if (fp->type & QEDE_FASTPATH_XDP) {
1698 rc = qede_alloc_mem_txq(edev, fp->xdp_tx);
1699 if (rc)
1700 goto out;
Yuval Mintz29502192015-10-26 11:02:29 +02001701 }
1702
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001703 if (fp->type & QEDE_FASTPATH_TX) {
Mintz, Yuval80439a12016-11-29 16:47:02 +02001704 rc = qede_alloc_mem_txq(edev, fp->txq);
1705 if (rc)
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001706 goto out;
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001707 }
1708
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001709out:
Manish Chopraf86af2d2016-04-20 03:03:27 -04001710 return rc;
Yuval Mintz29502192015-10-26 11:02:29 +02001711}
1712
1713static void qede_free_mem_load(struct qede_dev *edev)
1714{
1715 int i;
1716
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001717 for_each_queue(i) {
Yuval Mintz29502192015-10-26 11:02:29 +02001718 struct qede_fastpath *fp = &edev->fp_array[i];
1719
1720 qede_free_mem_fp(edev, fp);
1721 }
1722}
1723
1724/* This function allocates all qede memory at NIC load. */
1725static int qede_alloc_mem_load(struct qede_dev *edev)
1726{
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001727 int rc = 0, queue_id;
Yuval Mintz29502192015-10-26 11:02:29 +02001728
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001729 for (queue_id = 0; queue_id < QEDE_QUEUE_CNT(edev); queue_id++) {
1730 struct qede_fastpath *fp = &edev->fp_array[queue_id];
Yuval Mintz29502192015-10-26 11:02:29 +02001731
1732 rc = qede_alloc_mem_fp(edev, fp);
Manish Chopraf86af2d2016-04-20 03:03:27 -04001733 if (rc) {
Yuval Mintz29502192015-10-26 11:02:29 +02001734 DP_ERR(edev,
Manish Chopraf86af2d2016-04-20 03:03:27 -04001735 "Failed to allocate memory for fastpath - rss id = %d\n",
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001736 queue_id);
Manish Chopraf86af2d2016-04-20 03:03:27 -04001737 qede_free_mem_load(edev);
1738 return rc;
Yuval Mintz29502192015-10-26 11:02:29 +02001739 }
Yuval Mintz29502192015-10-26 11:02:29 +02001740 }
1741
1742 return 0;
1743}
1744
1745/* This function inits fp content and resets the SB, RXQ and TXQ structures */
1746static void qede_init_fp(struct qede_dev *edev)
1747{
Mintz, Yuval80439a12016-11-29 16:47:02 +02001748 int queue_id, rxq_index = 0, txq_index = 0;
Yuval Mintz29502192015-10-26 11:02:29 +02001749 struct qede_fastpath *fp;
1750
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001751 for_each_queue(queue_id) {
1752 fp = &edev->fp_array[queue_id];
Yuval Mintz29502192015-10-26 11:02:29 +02001753
1754 fp->edev = edev;
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001755 fp->id = queue_id;
Yuval Mintz29502192015-10-26 11:02:29 +02001756
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001757 if (fp->type & QEDE_FASTPATH_XDP) {
1758 fp->xdp_tx->index = QEDE_TXQ_IDX_TO_XDP(edev,
1759 rxq_index);
1760 fp->xdp_tx->is_xdp = 1;
1761 }
Yuval Mintz29502192015-10-26 11:02:29 +02001762
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001763 if (fp->type & QEDE_FASTPATH_RX) {
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001764 fp->rxq->rxq_id = rxq_index++;
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001765
1766 /* Determine how to map buffers for this queue */
1767 if (fp->type & QEDE_FASTPATH_XDP)
1768 fp->rxq->data_direction = DMA_BIDIRECTIONAL;
1769 else
1770 fp->rxq->data_direction = DMA_FROM_DEVICE;
Mintz, Yuval9eb22352016-11-29 16:47:08 +02001771 fp->rxq->dev = &edev->pdev->dev;
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001772 }
Yuval Mintz29502192015-10-26 11:02:29 +02001773
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001774 if (fp->type & QEDE_FASTPATH_TX) {
Mintz, Yuval80439a12016-11-29 16:47:02 +02001775 fp->txq->index = txq_index++;
1776 if (edev->dev_info.is_legacy)
1777 fp->txq->is_legacy = 1;
Mintz, Yuval9eb22352016-11-29 16:47:08 +02001778 fp->txq->dev = &edev->pdev->dev;
Yuval Mintz29502192015-10-26 11:02:29 +02001779 }
1780
1781 snprintf(fp->name, sizeof(fp->name), "%s-fp-%d",
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001782 edev->ndev->name, queue_id);
Yuval Mintz29502192015-10-26 11:02:29 +02001783 }
Manish Chopra55482ed2016-03-04 12:35:06 -05001784
1785 edev->gro_disable = !(edev->ndev->features & NETIF_F_GRO);
Yuval Mintz29502192015-10-26 11:02:29 +02001786}
1787
1788static int qede_set_real_num_queues(struct qede_dev *edev)
1789{
1790 int rc = 0;
1791
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001792 rc = netif_set_real_num_tx_queues(edev->ndev, QEDE_TSS_COUNT(edev));
Yuval Mintz29502192015-10-26 11:02:29 +02001793 if (rc) {
1794 DP_NOTICE(edev, "Failed to set real number of Tx queues\n");
1795 return rc;
1796 }
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001797
1798 rc = netif_set_real_num_rx_queues(edev->ndev, QEDE_RSS_COUNT(edev));
Yuval Mintz29502192015-10-26 11:02:29 +02001799 if (rc) {
1800 DP_NOTICE(edev, "Failed to set real number of Rx queues\n");
1801 return rc;
1802 }
1803
1804 return 0;
1805}
1806
1807static void qede_napi_disable_remove(struct qede_dev *edev)
1808{
1809 int i;
1810
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001811 for_each_queue(i) {
Yuval Mintz29502192015-10-26 11:02:29 +02001812 napi_disable(&edev->fp_array[i].napi);
1813
1814 netif_napi_del(&edev->fp_array[i].napi);
1815 }
1816}
1817
1818static void qede_napi_add_enable(struct qede_dev *edev)
1819{
1820 int i;
1821
1822 /* Add NAPI objects */
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001823 for_each_queue(i) {
Yuval Mintz29502192015-10-26 11:02:29 +02001824 netif_napi_add(edev->ndev, &edev->fp_array[i].napi,
1825 qede_poll, NAPI_POLL_WEIGHT);
1826 napi_enable(&edev->fp_array[i].napi);
1827 }
1828}
1829
1830static void qede_sync_free_irqs(struct qede_dev *edev)
1831{
1832 int i;
1833
1834 for (i = 0; i < edev->int_info.used_cnt; i++) {
1835 if (edev->int_info.msix_cnt) {
1836 synchronize_irq(edev->int_info.msix[i].vector);
1837 free_irq(edev->int_info.msix[i].vector,
1838 &edev->fp_array[i]);
1839 } else {
1840 edev->ops->common->simd_handler_clean(edev->cdev, i);
1841 }
1842 }
1843
1844 edev->int_info.used_cnt = 0;
1845}
1846
1847static int qede_req_msix_irqs(struct qede_dev *edev)
1848{
1849 int i, rc;
1850
1851 /* Sanitize number of interrupts == number of prepared RSS queues */
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001852 if (QEDE_QUEUE_CNT(edev) > edev->int_info.msix_cnt) {
Yuval Mintz29502192015-10-26 11:02:29 +02001853 DP_ERR(edev,
1854 "Interrupt mismatch: %d RSS queues > %d MSI-x vectors\n",
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001855 QEDE_QUEUE_CNT(edev), edev->int_info.msix_cnt);
Yuval Mintz29502192015-10-26 11:02:29 +02001856 return -EINVAL;
1857 }
1858
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001859 for (i = 0; i < QEDE_QUEUE_CNT(edev); i++) {
Yuval Mintz29502192015-10-26 11:02:29 +02001860 rc = request_irq(edev->int_info.msix[i].vector,
1861 qede_msix_fp_int, 0, edev->fp_array[i].name,
1862 &edev->fp_array[i]);
1863 if (rc) {
1864 DP_ERR(edev, "Request fp %d irq failed\n", i);
1865 qede_sync_free_irqs(edev);
1866 return rc;
1867 }
1868 DP_VERBOSE(edev, NETIF_MSG_INTR,
1869 "Requested fp irq for %s [entry %d]. Cookie is at %p\n",
1870 edev->fp_array[i].name, i,
1871 &edev->fp_array[i]);
1872 edev->int_info.used_cnt++;
1873 }
1874
1875 return 0;
1876}
1877
1878static void qede_simd_fp_handler(void *cookie)
1879{
1880 struct qede_fastpath *fp = (struct qede_fastpath *)cookie;
1881
1882 napi_schedule_irqoff(&fp->napi);
1883}
1884
1885static int qede_setup_irqs(struct qede_dev *edev)
1886{
1887 int i, rc = 0;
1888
1889 /* Learn Interrupt configuration */
1890 rc = edev->ops->common->get_fp_int(edev->cdev, &edev->int_info);
1891 if (rc)
1892 return rc;
1893
1894 if (edev->int_info.msix_cnt) {
1895 rc = qede_req_msix_irqs(edev);
1896 if (rc)
1897 return rc;
1898 edev->ndev->irq = edev->int_info.msix[0].vector;
1899 } else {
1900 const struct qed_common_ops *ops;
1901
1902 /* qed should learn receive the RSS ids and callbacks */
1903 ops = edev->ops->common;
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001904 for (i = 0; i < QEDE_QUEUE_CNT(edev); i++)
Yuval Mintz29502192015-10-26 11:02:29 +02001905 ops->simd_handler_config(edev->cdev,
1906 &edev->fp_array[i], i,
1907 qede_simd_fp_handler);
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001908 edev->int_info.used_cnt = QEDE_QUEUE_CNT(edev);
Yuval Mintz29502192015-10-26 11:02:29 +02001909 }
1910 return 0;
1911}
1912
1913static int qede_drain_txq(struct qede_dev *edev,
Yuval Mintz1a635e42016-08-15 10:42:43 +03001914 struct qede_tx_queue *txq, bool allow_drain)
Yuval Mintz29502192015-10-26 11:02:29 +02001915{
1916 int rc, cnt = 1000;
1917
1918 while (txq->sw_tx_cons != txq->sw_tx_prod) {
1919 if (!cnt) {
1920 if (allow_drain) {
1921 DP_NOTICE(edev,
1922 "Tx queue[%d] is stuck, requesting MCP to drain\n",
1923 txq->index);
1924 rc = edev->ops->common->drain(edev->cdev);
1925 if (rc)
1926 return rc;
1927 return qede_drain_txq(edev, txq, false);
1928 }
1929 DP_NOTICE(edev,
1930 "Timeout waiting for tx queue[%d]: PROD=%d, CONS=%d\n",
1931 txq->index, txq->sw_tx_prod,
1932 txq->sw_tx_cons);
1933 return -ENODEV;
1934 }
1935 cnt--;
1936 usleep_range(1000, 2000);
1937 barrier();
1938 }
1939
1940 /* FW finished processing, wait for HW to transmit all tx packets */
1941 usleep_range(1000, 2000);
1942
1943 return 0;
1944}
1945
Mintz, Yuval3da7a372016-11-29 16:47:06 +02001946static int qede_stop_txq(struct qede_dev *edev,
1947 struct qede_tx_queue *txq, int rss_id)
1948{
1949 return edev->ops->q_tx_stop(edev->cdev, rss_id, txq->handle);
1950}
1951
Yuval Mintz29502192015-10-26 11:02:29 +02001952static int qede_stop_queues(struct qede_dev *edev)
1953{
1954 struct qed_update_vport_params vport_update_params;
1955 struct qed_dev *cdev = edev->cdev;
Mintz, Yuval80439a12016-11-29 16:47:02 +02001956 struct qede_fastpath *fp;
1957 int rc, i;
Yuval Mintz29502192015-10-26 11:02:29 +02001958
1959 /* Disable the vport */
1960 memset(&vport_update_params, 0, sizeof(vport_update_params));
1961 vport_update_params.vport_id = 0;
1962 vport_update_params.update_vport_active_flg = 1;
1963 vport_update_params.vport_active_flg = 0;
1964 vport_update_params.update_rss_flg = 0;
1965
1966 rc = edev->ops->vport_update(cdev, &vport_update_params);
1967 if (rc) {
1968 DP_ERR(edev, "Failed to update vport\n");
1969 return rc;
1970 }
1971
1972 /* Flush Tx queues. If needed, request drain from MCP */
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001973 for_each_queue(i) {
Mintz, Yuval80439a12016-11-29 16:47:02 +02001974 fp = &edev->fp_array[i];
Yuval Mintz29502192015-10-26 11:02:29 +02001975
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001976 if (fp->type & QEDE_FASTPATH_TX) {
Mintz, Yuval80439a12016-11-29 16:47:02 +02001977 rc = qede_drain_txq(edev, fp->txq, true);
1978 if (rc)
1979 return rc;
Yuval Mintz29502192015-10-26 11:02:29 +02001980 }
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001981
1982 if (fp->type & QEDE_FASTPATH_XDP) {
1983 rc = qede_drain_txq(edev, fp->xdp_tx, true);
1984 if (rc)
1985 return rc;
1986 }
Yuval Mintz29502192015-10-26 11:02:29 +02001987 }
1988
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001989 /* Stop all Queues in reverse order */
1990 for (i = QEDE_QUEUE_CNT(edev) - 1; i >= 0; i--) {
Mintz, Yuval80439a12016-11-29 16:47:02 +02001991 fp = &edev->fp_array[i];
Yuval Mintz29502192015-10-26 11:02:29 +02001992
Mintz, Yuval80439a12016-11-29 16:47:02 +02001993 /* Stop the Tx Queue(s) */
1994 if (fp->type & QEDE_FASTPATH_TX) {
Mintz, Yuval3da7a372016-11-29 16:47:06 +02001995 rc = qede_stop_txq(edev, fp->txq, i);
1996 if (rc)
1997 return rc;
Yuval Mintz29502192015-10-26 11:02:29 +02001998 }
1999
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04002000 /* Stop the Rx Queue */
Mintz, Yuval80439a12016-11-29 16:47:02 +02002001 if (fp->type & QEDE_FASTPATH_RX) {
Mintz, Yuval3da7a372016-11-29 16:47:06 +02002002 rc = edev->ops->q_rx_stop(cdev, i, fp->rxq->handle);
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04002003 if (rc) {
2004 DP_ERR(edev, "Failed to stop RXQ #%d\n", i);
2005 return rc;
2006 }
Yuval Mintz29502192015-10-26 11:02:29 +02002007 }
Mintz, Yuval496e0512016-11-29 16:47:09 +02002008
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02002009 /* Stop the XDP forwarding queue */
2010 if (fp->type & QEDE_FASTPATH_XDP) {
2011 rc = qede_stop_txq(edev, fp->xdp_tx, i);
2012 if (rc)
2013 return rc;
2014
Mintz, Yuval496e0512016-11-29 16:47:09 +02002015 bpf_prog_put(fp->rxq->xdp_prog);
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02002016 }
Yuval Mintz29502192015-10-26 11:02:29 +02002017 }
2018
2019 /* Stop the vport */
2020 rc = edev->ops->vport_stop(cdev, 0);
2021 if (rc)
2022 DP_ERR(edev, "Failed to stop VPORT\n");
2023
2024 return rc;
2025}
2026
Mintz, Yuval3da7a372016-11-29 16:47:06 +02002027static int qede_start_txq(struct qede_dev *edev,
2028 struct qede_fastpath *fp,
2029 struct qede_tx_queue *txq, u8 rss_id, u16 sb_idx)
2030{
2031 dma_addr_t phys_table = qed_chain_get_pbl_phys(&txq->tx_pbl);
2032 u32 page_cnt = qed_chain_get_page_cnt(&txq->tx_pbl);
2033 struct qed_queue_start_common_params params;
2034 struct qed_txq_start_ret_params ret_params;
2035 int rc;
2036
2037 memset(&params, 0, sizeof(params));
2038 memset(&ret_params, 0, sizeof(ret_params));
2039
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02002040 /* Let the XDP queue share the queue-zone with one of the regular txq.
2041 * We don't really care about its coalescing.
2042 */
2043 if (txq->is_xdp)
2044 params.queue_id = QEDE_TXQ_XDP_TO_IDX(edev, txq);
2045 else
2046 params.queue_id = txq->index;
2047
Mintz, Yuval3da7a372016-11-29 16:47:06 +02002048 params.sb = fp->sb_info->igu_sb_id;
2049 params.sb_idx = sb_idx;
2050
2051 rc = edev->ops->q_tx_start(edev->cdev, rss_id, &params, phys_table,
2052 page_cnt, &ret_params);
2053 if (rc) {
2054 DP_ERR(edev, "Start TXQ #%d failed %d\n", txq->index, rc);
2055 return rc;
2056 }
2057
2058 txq->doorbell_addr = ret_params.p_doorbell;
2059 txq->handle = ret_params.p_handle;
2060
2061 /* Determine the FW consumer address associated */
2062 txq->hw_cons_ptr = &fp->sb_info->sb_virt->pi_array[sb_idx];
2063
2064 /* Prepare the doorbell parameters */
2065 SET_FIELD(txq->tx_db.data.params, ETH_DB_DATA_DEST, DB_DEST_XCM);
2066 SET_FIELD(txq->tx_db.data.params, ETH_DB_DATA_AGG_CMD, DB_AGG_CMD_SET);
2067 SET_FIELD(txq->tx_db.data.params, ETH_DB_DATA_AGG_VAL_SEL,
2068 DQ_XCM_ETH_TX_BD_PROD_CMD);
2069 txq->tx_db.data.agg_flags = DQ_XCM_ETH_DQ_CF_CMD;
2070
2071 return rc;
2072}
2073
Yuval Mintza0d26d52016-06-19 15:18:13 +03002074static int qede_start_queues(struct qede_dev *edev, bool clear_stats)
Yuval Mintz29502192015-10-26 11:02:29 +02002075{
Manish Chopra088c8612016-03-04 12:35:05 -05002076 int vlan_removal_en = 1;
Yuval Mintz29502192015-10-26 11:02:29 +02002077 struct qed_dev *cdev = edev->cdev;
Yuval Mintz29502192015-10-26 11:02:29 +02002078 struct qed_update_vport_params vport_update_params;
2079 struct qed_queue_start_common_params q_params;
Yuval Mintzfefb0202016-05-11 16:36:19 +03002080 struct qed_dev_info *qed_info = &edev->dev_info.common;
Manish Chopra088c8612016-03-04 12:35:05 -05002081 struct qed_start_vport_params start = {0};
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03002082 bool reset_rss_indir = false;
Mintz, Yuval80439a12016-11-29 16:47:02 +02002083 int rc, i;
Yuval Mintz29502192015-10-26 11:02:29 +02002084
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04002085 if (!edev->num_queues) {
Yuval Mintz29502192015-10-26 11:02:29 +02002086 DP_ERR(edev,
2087 "Cannot update V-VPORT as active as there are no Rx queues\n");
2088 return -EINVAL;
2089 }
2090
Manish Chopra55482ed2016-03-04 12:35:06 -05002091 start.gro_enable = !edev->gro_disable;
Manish Chopra088c8612016-03-04 12:35:05 -05002092 start.mtu = edev->ndev->mtu;
2093 start.vport_id = 0;
2094 start.drop_ttl0 = true;
2095 start.remove_inner_vlan = vlan_removal_en;
Yuval Mintz7f7a1442016-07-27 14:45:22 +03002096 start.clear_stats = clear_stats;
Manish Chopra088c8612016-03-04 12:35:05 -05002097
2098 rc = edev->ops->vport_start(cdev, &start);
Yuval Mintz29502192015-10-26 11:02:29 +02002099
2100 if (rc) {
2101 DP_ERR(edev, "Start V-PORT failed %d\n", rc);
2102 return rc;
2103 }
2104
2105 DP_VERBOSE(edev, NETIF_MSG_IFUP,
2106 "Start vport ramrod passed, vport_id = %d, MTU = %d, vlan_removal_en = %d\n",
Manish Chopra088c8612016-03-04 12:35:05 -05002107 start.vport_id, edev->ndev->mtu + 0xe, vlan_removal_en);
Yuval Mintz29502192015-10-26 11:02:29 +02002108
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04002109 for_each_queue(i) {
Yuval Mintz29502192015-10-26 11:02:29 +02002110 struct qede_fastpath *fp = &edev->fp_array[i];
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04002111 dma_addr_t p_phys_table;
2112 u32 page_cnt;
Yuval Mintz29502192015-10-26 11:02:29 +02002113
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04002114 if (fp->type & QEDE_FASTPATH_RX) {
Mintz, Yuval3da7a372016-11-29 16:47:06 +02002115 struct qed_rxq_start_ret_params ret_params;
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04002116 struct qede_rx_queue *rxq = fp->rxq;
2117 __le16 *val;
Yuval Mintz29502192015-10-26 11:02:29 +02002118
Mintz, Yuval3da7a372016-11-29 16:47:06 +02002119 memset(&ret_params, 0, sizeof(ret_params));
Yuval Mintz29502192015-10-26 11:02:29 +02002120 memset(&q_params, 0, sizeof(q_params));
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04002121 q_params.queue_id = rxq->rxq_id;
2122 q_params.vport_id = 0;
2123 q_params.sb = fp->sb_info->igu_sb_id;
2124 q_params.sb_idx = RX_PI;
2125
2126 p_phys_table =
2127 qed_chain_get_pbl_phys(&rxq->rx_comp_ring);
2128 page_cnt = qed_chain_get_page_cnt(&rxq->rx_comp_ring);
2129
Mintz, Yuval3da7a372016-11-29 16:47:06 +02002130 rc = edev->ops->q_rx_start(cdev, i, &q_params,
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04002131 rxq->rx_buf_size,
2132 rxq->rx_bd_ring.p_phys_addr,
2133 p_phys_table,
Mintz, Yuval3da7a372016-11-29 16:47:06 +02002134 page_cnt, &ret_params);
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04002135 if (rc) {
2136 DP_ERR(edev, "Start RXQ #%d failed %d\n", i,
2137 rc);
2138 return rc;
2139 }
2140
Mintz, Yuval3da7a372016-11-29 16:47:06 +02002141 /* Use the return parameters */
2142 rxq->hw_rxq_prod_addr = ret_params.p_prod;
2143 rxq->handle = ret_params.p_handle;
2144
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04002145 val = &fp->sb_info->sb_virt->pi_array[RX_PI];
2146 rxq->hw_cons_ptr = val;
2147
2148 qede_update_rx_prod(edev, rxq);
2149 }
2150
Mintz, Yuval496e0512016-11-29 16:47:09 +02002151 if (fp->type & QEDE_FASTPATH_XDP) {
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02002152 rc = qede_start_txq(edev, fp, fp->xdp_tx, i, XDP_PI);
2153 if (rc)
2154 return rc;
2155
Mintz, Yuval496e0512016-11-29 16:47:09 +02002156 fp->rxq->xdp_prog = bpf_prog_add(edev->xdp_prog, 1);
2157 if (IS_ERR(fp->rxq->xdp_prog)) {
2158 rc = PTR_ERR(fp->rxq->xdp_prog);
2159 fp->rxq->xdp_prog = NULL;
2160 return rc;
2161 }
2162 }
2163
Mintz, Yuval80439a12016-11-29 16:47:02 +02002164 if (fp->type & QEDE_FASTPATH_TX) {
Mintz, Yuval3da7a372016-11-29 16:47:06 +02002165 rc = qede_start_txq(edev, fp, fp->txq, i, TX_PI(0));
2166 if (rc)
Yuval Mintz29502192015-10-26 11:02:29 +02002167 return rc;
Yuval Mintz29502192015-10-26 11:02:29 +02002168 }
2169 }
2170
2171 /* Prepare and send the vport enable */
2172 memset(&vport_update_params, 0, sizeof(vport_update_params));
Manish Chopra088c8612016-03-04 12:35:05 -05002173 vport_update_params.vport_id = start.vport_id;
Yuval Mintz29502192015-10-26 11:02:29 +02002174 vport_update_params.update_vport_active_flg = 1;
2175 vport_update_params.vport_active_flg = 1;
2176
Yuval Mintz831bfb0e2016-05-11 16:36:25 +03002177 if ((qed_info->mf_mode == QED_MF_NPAR || pci_num_vf(edev->pdev)) &&
2178 qed_info->tx_switching) {
2179 vport_update_params.update_tx_switching_flg = 1;
2180 vport_update_params.tx_switching_flg = 1;
2181 }
2182
Yuval Mintz29502192015-10-26 11:02:29 +02002183 /* Fill struct with RSS params */
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04002184 if (QEDE_RSS_COUNT(edev) > 1) {
Yuval Mintz29502192015-10-26 11:02:29 +02002185 vport_update_params.update_rss_flg = 1;
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03002186
2187 /* Need to validate current RSS config uses valid entries */
2188 for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++) {
2189 if (edev->rss_params.rss_ind_table[i] >=
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04002190 QEDE_RSS_COUNT(edev)) {
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03002191 reset_rss_indir = true;
2192 break;
2193 }
2194 }
2195
2196 if (!(edev->rss_params_inited & QEDE_RSS_INDIR_INITED) ||
2197 reset_rss_indir) {
2198 u16 val;
2199
2200 for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++) {
2201 u16 indir_val;
2202
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04002203 val = QEDE_RSS_COUNT(edev);
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03002204 indir_val = ethtool_rxfh_indir_default(i, val);
2205 edev->rss_params.rss_ind_table[i] = indir_val;
2206 }
2207 edev->rss_params_inited |= QEDE_RSS_INDIR_INITED;
2208 }
2209
2210 if (!(edev->rss_params_inited & QEDE_RSS_KEY_INITED)) {
2211 netdev_rss_key_fill(edev->rss_params.rss_key,
2212 sizeof(edev->rss_params.rss_key));
2213 edev->rss_params_inited |= QEDE_RSS_KEY_INITED;
2214 }
2215
2216 if (!(edev->rss_params_inited & QEDE_RSS_CAPS_INITED)) {
2217 edev->rss_params.rss_caps = QED_RSS_IPV4 |
2218 QED_RSS_IPV6 |
2219 QED_RSS_IPV4_TCP |
2220 QED_RSS_IPV6_TCP;
2221 edev->rss_params_inited |= QEDE_RSS_CAPS_INITED;
2222 }
2223
2224 memcpy(&vport_update_params.rss_params, &edev->rss_params,
2225 sizeof(vport_update_params.rss_params));
Yuval Mintz29502192015-10-26 11:02:29 +02002226 } else {
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03002227 memset(&vport_update_params.rss_params, 0,
2228 sizeof(vport_update_params.rss_params));
Yuval Mintz29502192015-10-26 11:02:29 +02002229 }
Yuval Mintz29502192015-10-26 11:02:29 +02002230
2231 rc = edev->ops->vport_update(cdev, &vport_update_params);
2232 if (rc) {
2233 DP_ERR(edev, "Update V-PORT failed %d\n", rc);
2234 return rc;
2235 }
2236
2237 return 0;
2238}
2239
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +02002240static int qede_set_mcast_rx_mac(struct qede_dev *edev,
2241 enum qed_filter_xcast_params_type opcode,
2242 unsigned char *mac, int num_macs)
2243{
2244 struct qed_filter_params filter_cmd;
2245 int i;
2246
2247 memset(&filter_cmd, 0, sizeof(filter_cmd));
2248 filter_cmd.type = QED_FILTER_TYPE_MCAST;
2249 filter_cmd.filter.mcast.type = opcode;
2250 filter_cmd.filter.mcast.num = num_macs;
2251
2252 for (i = 0; i < num_macs; i++, mac += ETH_ALEN)
2253 ether_addr_copy(filter_cmd.filter.mcast.mac[i], mac);
2254
2255 return edev->ops->filter_config(edev->cdev, &filter_cmd);
2256}
2257
Yuval Mintz29502192015-10-26 11:02:29 +02002258enum qede_unload_mode {
2259 QEDE_UNLOAD_NORMAL,
2260};
2261
Mintz, Yuval567b3c12016-11-29 16:47:05 +02002262static void qede_unload(struct qede_dev *edev, enum qede_unload_mode mode,
2263 bool is_locked)
Yuval Mintz29502192015-10-26 11:02:29 +02002264{
Sudarsana Kallurua2ec6172015-10-26 11:02:32 +02002265 struct qed_link_params link_params;
Yuval Mintz29502192015-10-26 11:02:29 +02002266 int rc;
2267
2268 DP_INFO(edev, "Starting qede unload\n");
2269
Mintz, Yuval567b3c12016-11-29 16:47:05 +02002270 if (!is_locked)
2271 __qede_lock(edev);
2272
Ram Amranicee9fbd2016-10-01 21:59:56 +03002273 qede_roce_dev_event_close(edev);
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +02002274 edev->state = QEDE_STATE_CLOSED;
2275
Yuval Mintz29502192015-10-26 11:02:29 +02002276 /* Close OS Tx */
2277 netif_tx_disable(edev->ndev);
2278 netif_carrier_off(edev->ndev);
2279
Sudarsana Kallurua2ec6172015-10-26 11:02:32 +02002280 /* Reset the link */
2281 memset(&link_params, 0, sizeof(link_params));
2282 link_params.link_up = false;
2283 edev->ops->common->set_link(edev->cdev, &link_params);
Yuval Mintz29502192015-10-26 11:02:29 +02002284 rc = qede_stop_queues(edev);
2285 if (rc) {
2286 qede_sync_free_irqs(edev);
2287 goto out;
2288 }
2289
2290 DP_INFO(edev, "Stopped Queues\n");
2291
Sudarsana Reddy Kalluru7c1bfca2016-02-18 17:00:40 +02002292 qede_vlan_mark_nonconfigured(edev);
Yuval Mintz29502192015-10-26 11:02:29 +02002293 edev->ops->fastpath_stop(edev->cdev);
2294
2295 /* Release the interrupts */
2296 qede_sync_free_irqs(edev);
2297 edev->ops->common->set_fp_int(edev->cdev, 0);
2298
2299 qede_napi_disable_remove(edev);
2300
2301 qede_free_mem_load(edev);
2302 qede_free_fp_array(edev);
2303
2304out:
Mintz, Yuval567b3c12016-11-29 16:47:05 +02002305 if (!is_locked)
2306 __qede_unlock(edev);
Yuval Mintz29502192015-10-26 11:02:29 +02002307 DP_INFO(edev, "Ending qede unload\n");
2308}
2309
2310enum qede_load_mode {
2311 QEDE_LOAD_NORMAL,
Yuval Mintza0d26d52016-06-19 15:18:13 +03002312 QEDE_LOAD_RELOAD,
Yuval Mintz29502192015-10-26 11:02:29 +02002313};
2314
Mintz, Yuval567b3c12016-11-29 16:47:05 +02002315static int qede_load(struct qede_dev *edev, enum qede_load_mode mode,
2316 bool is_locked)
Yuval Mintz29502192015-10-26 11:02:29 +02002317{
Sudarsana Kallurua2ec6172015-10-26 11:02:32 +02002318 struct qed_link_params link_params;
2319 struct qed_link_output link_output;
Yuval Mintz29502192015-10-26 11:02:29 +02002320 int rc;
2321
2322 DP_INFO(edev, "Starting qede load\n");
2323
Mintz, Yuval567b3c12016-11-29 16:47:05 +02002324 if (!is_locked)
2325 __qede_lock(edev);
2326
Yuval Mintz29502192015-10-26 11:02:29 +02002327 rc = qede_set_num_queues(edev);
2328 if (rc)
Mintz, Yuval567b3c12016-11-29 16:47:05 +02002329 goto out;
Yuval Mintz29502192015-10-26 11:02:29 +02002330
2331 rc = qede_alloc_fp_array(edev);
2332 if (rc)
Mintz, Yuval567b3c12016-11-29 16:47:05 +02002333 goto out;
Yuval Mintz29502192015-10-26 11:02:29 +02002334
2335 qede_init_fp(edev);
2336
2337 rc = qede_alloc_mem_load(edev);
2338 if (rc)
2339 goto err1;
Mintz, Yuval80439a12016-11-29 16:47:02 +02002340 DP_INFO(edev, "Allocated %d Rx, %d Tx queues\n",
2341 QEDE_RSS_COUNT(edev), QEDE_TSS_COUNT(edev));
Yuval Mintz29502192015-10-26 11:02:29 +02002342
2343 rc = qede_set_real_num_queues(edev);
2344 if (rc)
2345 goto err2;
2346
2347 qede_napi_add_enable(edev);
2348 DP_INFO(edev, "Napi added and enabled\n");
2349
2350 rc = qede_setup_irqs(edev);
2351 if (rc)
2352 goto err3;
2353 DP_INFO(edev, "Setup IRQs succeeded\n");
2354
Yuval Mintza0d26d52016-06-19 15:18:13 +03002355 rc = qede_start_queues(edev, mode != QEDE_LOAD_RELOAD);
Yuval Mintz29502192015-10-26 11:02:29 +02002356 if (rc)
2357 goto err4;
2358 DP_INFO(edev, "Start VPORT, RXQ and TXQ succeeded\n");
2359
2360 /* Add primary mac and set Rx filters */
2361 ether_addr_copy(edev->primary_mac, edev->ndev->dev_addr);
2362
Sudarsana Reddy Kalluru7c1bfca2016-02-18 17:00:40 +02002363 /* Program un-configured VLANs */
2364 qede_configure_vlan_filters(edev);
2365
Sudarsana Kallurua2ec6172015-10-26 11:02:32 +02002366 /* Ask for link-up using current configuration */
2367 memset(&link_params, 0, sizeof(link_params));
2368 link_params.link_up = true;
2369 edev->ops->common->set_link(edev->cdev, &link_params);
2370
2371 /* Query whether link is already-up */
2372 memset(&link_output, 0, sizeof(link_output));
2373 edev->ops->common->get_link(edev->cdev, &link_output);
Ram Amranicee9fbd2016-10-01 21:59:56 +03002374 qede_roce_dev_event_open(edev);
Sudarsana Kallurua2ec6172015-10-26 11:02:32 +02002375 qede_link_update(edev, &link_output);
2376
Mintz, Yuval567b3c12016-11-29 16:47:05 +02002377 edev->state = QEDE_STATE_OPEN;
2378
Yuval Mintz29502192015-10-26 11:02:29 +02002379 DP_INFO(edev, "Ending successfully qede load\n");
2380
Yuval Mintz29502192015-10-26 11:02:29 +02002381
Mintz, Yuval567b3c12016-11-29 16:47:05 +02002382 goto out;
Yuval Mintz29502192015-10-26 11:02:29 +02002383err4:
2384 qede_sync_free_irqs(edev);
2385 memset(&edev->int_info.msix_cnt, 0, sizeof(struct qed_int_info));
2386err3:
2387 qede_napi_disable_remove(edev);
2388err2:
2389 qede_free_mem_load(edev);
2390err1:
2391 edev->ops->common->set_fp_int(edev->cdev, 0);
2392 qede_free_fp_array(edev);
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04002393 edev->num_queues = 0;
2394 edev->fp_num_tx = 0;
2395 edev->fp_num_rx = 0;
Mintz, Yuval567b3c12016-11-29 16:47:05 +02002396out:
2397 if (!is_locked)
2398 __qede_unlock(edev);
2399
Yuval Mintz29502192015-10-26 11:02:29 +02002400 return rc;
2401}
2402
Mintz, Yuval567b3c12016-11-29 16:47:05 +02002403/* 'func' should be able to run between unload and reload assuming interface
2404 * is actually running, or afterwards in case it's currently DOWN.
2405 */
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02002406void qede_reload(struct qede_dev *edev,
Mintz, Yuval567b3c12016-11-29 16:47:05 +02002407 struct qede_reload_args *args, bool is_locked)
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02002408{
Mintz, Yuval567b3c12016-11-29 16:47:05 +02002409 if (!is_locked)
2410 __qede_lock(edev);
2411
2412 /* Since qede_lock is held, internal state wouldn't change even
2413 * if netdev state would start transitioning. Check whether current
2414 * internal configuration indicates device is up, then reload.
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02002415 */
Mintz, Yuval567b3c12016-11-29 16:47:05 +02002416 if (edev->state == QEDE_STATE_OPEN) {
2417 qede_unload(edev, QEDE_UNLOAD_NORMAL, true);
2418 if (args)
2419 args->func(edev, args);
2420 qede_load(edev, QEDE_LOAD_RELOAD, true);
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02002421
Mintz, Yuval567b3c12016-11-29 16:47:05 +02002422 /* Since no one is going to do it for us, re-configure */
2423 qede_config_rx_mode(edev->ndev);
2424 } else if (args) {
2425 args->func(edev, args);
2426 }
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02002427
Mintz, Yuval567b3c12016-11-29 16:47:05 +02002428 if (!is_locked)
2429 __qede_unlock(edev);
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02002430}
2431
Yuval Mintz29502192015-10-26 11:02:29 +02002432/* called with rtnl_lock */
2433static int qede_open(struct net_device *ndev)
2434{
2435 struct qede_dev *edev = netdev_priv(ndev);
Manish Choprab18e1702016-04-14 01:38:30 -04002436 int rc;
Yuval Mintz29502192015-10-26 11:02:29 +02002437
2438 netif_carrier_off(ndev);
2439
2440 edev->ops->common->set_power_state(edev->cdev, PCI_D0);
2441
Mintz, Yuval567b3c12016-11-29 16:47:05 +02002442 rc = qede_load(edev, QEDE_LOAD_NORMAL, false);
Manish Choprab18e1702016-04-14 01:38:30 -04002443 if (rc)
2444 return rc;
2445
Alexander Duyckf9f082a2016-06-16 12:22:57 -07002446 udp_tunnel_get_rx_info(ndev);
2447
Sudarsana Kalluru0fefbfb2016-10-31 07:14:21 +02002448 edev->ops->common->update_drv_state(edev->cdev, true);
2449
Manish Choprab18e1702016-04-14 01:38:30 -04002450 return 0;
Yuval Mintz29502192015-10-26 11:02:29 +02002451}
2452
2453static int qede_close(struct net_device *ndev)
2454{
2455 struct qede_dev *edev = netdev_priv(ndev);
2456
Mintz, Yuval567b3c12016-11-29 16:47:05 +02002457 qede_unload(edev, QEDE_UNLOAD_NORMAL, false);
Yuval Mintz29502192015-10-26 11:02:29 +02002458
Sudarsana Kalluru0fefbfb2016-10-31 07:14:21 +02002459 edev->ops->common->update_drv_state(edev->cdev, false);
2460
Yuval Mintz29502192015-10-26 11:02:29 +02002461 return 0;
2462}
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +02002463
Sudarsana Kallurua2ec6172015-10-26 11:02:32 +02002464static void qede_link_update(void *dev, struct qed_link_output *link)
2465{
2466 struct qede_dev *edev = dev;
2467
2468 if (!netif_running(edev->ndev)) {
2469 DP_VERBOSE(edev, NETIF_MSG_LINK, "Interface is not running\n");
2470 return;
2471 }
2472
2473 if (link->link_up) {
Yuval Mintz8e025ae2016-02-24 16:52:47 +02002474 if (!netif_carrier_ok(edev->ndev)) {
2475 DP_NOTICE(edev, "Link is up\n");
2476 netif_tx_start_all_queues(edev->ndev);
2477 netif_carrier_on(edev->ndev);
2478 }
Sudarsana Kallurua2ec6172015-10-26 11:02:32 +02002479 } else {
Yuval Mintz8e025ae2016-02-24 16:52:47 +02002480 if (netif_carrier_ok(edev->ndev)) {
2481 DP_NOTICE(edev, "Link is down\n");
2482 netif_tx_disable(edev->ndev);
2483 netif_carrier_off(edev->ndev);
2484 }
Sudarsana Kallurua2ec6172015-10-26 11:02:32 +02002485 }
2486}
2487
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +02002488static int qede_set_mac_addr(struct net_device *ndev, void *p)
2489{
2490 struct qede_dev *edev = netdev_priv(ndev);
2491 struct sockaddr *addr = p;
2492 int rc;
2493
2494 ASSERT_RTNL(); /* @@@TBD To be removed */
2495
2496 DP_INFO(edev, "Set_mac_addr called\n");
2497
2498 if (!is_valid_ether_addr(addr->sa_data)) {
2499 DP_NOTICE(edev, "The MAC address is not valid\n");
2500 return -EFAULT;
2501 }
2502
Yuval Mintzeff16962016-05-11 16:36:21 +03002503 if (!edev->ops->check_mac(edev->cdev, addr->sa_data)) {
2504 DP_NOTICE(edev, "qed prevents setting MAC\n");
2505 return -EINVAL;
2506 }
2507
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +02002508 ether_addr_copy(ndev->dev_addr, addr->sa_data);
2509
2510 if (!netif_running(ndev)) {
2511 DP_NOTICE(edev, "The device is currently down\n");
2512 return 0;
2513 }
2514
2515 /* Remove the previous primary mac */
2516 rc = qede_set_ucast_rx_mac(edev, QED_FILTER_XCAST_TYPE_DEL,
2517 edev->primary_mac);
2518 if (rc)
2519 return rc;
2520
Sudarsana Kalluru0fefbfb2016-10-31 07:14:21 +02002521 edev->ops->common->update_mac(edev->cdev, addr->sa_data);
2522
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +02002523 /* Add MAC filter according to the new unicast HW MAC address */
2524 ether_addr_copy(edev->primary_mac, ndev->dev_addr);
2525 return qede_set_ucast_rx_mac(edev, QED_FILTER_XCAST_TYPE_ADD,
2526 edev->primary_mac);
2527}
2528
2529static int
2530qede_configure_mcast_filtering(struct net_device *ndev,
2531 enum qed_filter_rx_mode_type *accept_flags)
2532{
2533 struct qede_dev *edev = netdev_priv(ndev);
2534 unsigned char *mc_macs, *temp;
2535 struct netdev_hw_addr *ha;
2536 int rc = 0, mc_count;
2537 size_t size;
2538
2539 size = 64 * ETH_ALEN;
2540
2541 mc_macs = kzalloc(size, GFP_KERNEL);
2542 if (!mc_macs) {
2543 DP_NOTICE(edev,
2544 "Failed to allocate memory for multicast MACs\n");
2545 rc = -ENOMEM;
2546 goto exit;
2547 }
2548
2549 temp = mc_macs;
2550
2551 /* Remove all previously configured MAC filters */
2552 rc = qede_set_mcast_rx_mac(edev, QED_FILTER_XCAST_TYPE_DEL,
2553 mc_macs, 1);
2554 if (rc)
2555 goto exit;
2556
2557 netif_addr_lock_bh(ndev);
2558
2559 mc_count = netdev_mc_count(ndev);
2560 if (mc_count < 64) {
2561 netdev_for_each_mc_addr(ha, ndev) {
2562 ether_addr_copy(temp, ha->addr);
2563 temp += ETH_ALEN;
2564 }
2565 }
2566
2567 netif_addr_unlock_bh(ndev);
2568
2569 /* Check for all multicast @@@TBD resource allocation */
2570 if ((ndev->flags & IFF_ALLMULTI) ||
2571 (mc_count > 64)) {
2572 if (*accept_flags == QED_FILTER_RX_MODE_TYPE_REGULAR)
2573 *accept_flags = QED_FILTER_RX_MODE_TYPE_MULTI_PROMISC;
2574 } else {
2575 /* Add all multicast MAC filters */
2576 rc = qede_set_mcast_rx_mac(edev, QED_FILTER_XCAST_TYPE_ADD,
2577 mc_macs, mc_count);
2578 }
2579
2580exit:
2581 kfree(mc_macs);
2582 return rc;
2583}
2584
2585static void qede_set_rx_mode(struct net_device *ndev)
2586{
2587 struct qede_dev *edev = netdev_priv(ndev);
2588
Mintz, Yuval567b3c12016-11-29 16:47:05 +02002589 set_bit(QEDE_SP_RX_MODE, &edev->sp_flags);
2590 schedule_delayed_work(&edev->sp_task, 0);
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +02002591}
2592
2593/* Must be called with qede_lock held */
2594static void qede_config_rx_mode(struct net_device *ndev)
2595{
2596 enum qed_filter_rx_mode_type accept_flags = QED_FILTER_TYPE_UCAST;
2597 struct qede_dev *edev = netdev_priv(ndev);
2598 struct qed_filter_params rx_mode;
2599 unsigned char *uc_macs, *temp;
2600 struct netdev_hw_addr *ha;
2601 int rc, uc_count;
2602 size_t size;
2603
2604 netif_addr_lock_bh(ndev);
2605
2606 uc_count = netdev_uc_count(ndev);
2607 size = uc_count * ETH_ALEN;
2608
2609 uc_macs = kzalloc(size, GFP_ATOMIC);
2610 if (!uc_macs) {
2611 DP_NOTICE(edev, "Failed to allocate memory for unicast MACs\n");
2612 netif_addr_unlock_bh(ndev);
2613 return;
2614 }
2615
2616 temp = uc_macs;
2617 netdev_for_each_uc_addr(ha, ndev) {
2618 ether_addr_copy(temp, ha->addr);
2619 temp += ETH_ALEN;
2620 }
2621
2622 netif_addr_unlock_bh(ndev);
2623
2624 /* Configure the struct for the Rx mode */
2625 memset(&rx_mode, 0, sizeof(struct qed_filter_params));
2626 rx_mode.type = QED_FILTER_TYPE_RX_MODE;
2627
2628 /* Remove all previous unicast secondary macs and multicast macs
2629 * (configrue / leave the primary mac)
2630 */
2631 rc = qede_set_ucast_rx_mac(edev, QED_FILTER_XCAST_TYPE_REPLACE,
2632 edev->primary_mac);
2633 if (rc)
2634 goto out;
2635
2636 /* Check for promiscuous */
2637 if ((ndev->flags & IFF_PROMISC) ||
Yuval Mintz7b7e70f2016-10-14 05:19:20 -04002638 (uc_count > edev->dev_info.num_mac_filters - 1)) {
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +02002639 accept_flags = QED_FILTER_RX_MODE_TYPE_PROMISC;
2640 } else {
2641 /* Add MAC filters according to the unicast secondary macs */
2642 int i;
2643
2644 temp = uc_macs;
2645 for (i = 0; i < uc_count; i++) {
2646 rc = qede_set_ucast_rx_mac(edev,
2647 QED_FILTER_XCAST_TYPE_ADD,
2648 temp);
2649 if (rc)
2650 goto out;
2651
2652 temp += ETH_ALEN;
2653 }
2654
2655 rc = qede_configure_mcast_filtering(ndev, &accept_flags);
2656 if (rc)
2657 goto out;
2658 }
2659
Sudarsana Reddy Kalluru7c1bfca2016-02-18 17:00:40 +02002660 /* take care of VLAN mode */
2661 if (ndev->flags & IFF_PROMISC) {
2662 qede_config_accept_any_vlan(edev, true);
2663 } else if (!edev->non_configured_vlans) {
2664 /* It's possible that accept_any_vlan mode is set due to a
2665 * previous setting of IFF_PROMISC. If vlan credits are
2666 * sufficient, disable accept_any_vlan.
2667 */
2668 qede_config_accept_any_vlan(edev, false);
2669 }
2670
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +02002671 rx_mode.filter.accept_flags = accept_flags;
2672 edev->ops->filter_config(edev->cdev, &rx_mode);
2673out:
2674 kfree(uc_macs);
2675}