blob: be4121c867c30a389b086ba04a584c485f874bae [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
Sudarsana Kallurua2ec6172015-10-26 11:02:32 +0200213static struct qed_eth_cb_ops qede_ll_ops = {
214 {
215 .link_update = qede_link_update,
216 },
Yuval Mintzeff16962016-05-11 16:36:21 +0300217 .force_mac = qede_force_mac,
Sudarsana Kallurua2ec6172015-10-26 11:02:32 +0200218};
219
Yuval Mintz29502192015-10-26 11:02:29 +0200220static int qede_netdev_event(struct notifier_block *this, unsigned long event,
221 void *ptr)
222{
223 struct net_device *ndev = netdev_notifier_info_to_dev(ptr);
224 struct ethtool_drvinfo drvinfo;
225 struct qede_dev *edev;
226
Ram Amranicee9fbd2016-10-01 21:59:56 +0300227 if (event != NETDEV_CHANGENAME && event != NETDEV_CHANGEADDR)
Yuval Mintz29502192015-10-26 11:02:29 +0200228 goto done;
229
230 /* Check whether this is a qede device */
231 if (!ndev || !ndev->ethtool_ops || !ndev->ethtool_ops->get_drvinfo)
232 goto done;
233
234 memset(&drvinfo, 0, sizeof(drvinfo));
235 ndev->ethtool_ops->get_drvinfo(ndev, &drvinfo);
236 if (strcmp(drvinfo.driver, "qede"))
237 goto done;
238 edev = netdev_priv(ndev);
239
Ram Amranicee9fbd2016-10-01 21:59:56 +0300240 switch (event) {
241 case NETDEV_CHANGENAME:
242 /* Notify qed of the name change */
243 if (!edev->ops || !edev->ops->common)
244 goto done;
245 edev->ops->common->set_id(edev->cdev, edev->ndev->name, "qede");
246 break;
247 case NETDEV_CHANGEADDR:
248 edev = netdev_priv(ndev);
249 qede_roce_event_changeaddr(edev);
250 break;
251 }
Yuval Mintz29502192015-10-26 11:02:29 +0200252
253done:
254 return NOTIFY_DONE;
255}
256
257static struct notifier_block qede_netdev_notifier = {
258 .notifier_call = qede_netdev_event,
259};
260
Yuval Mintze712d522015-10-26 11:02:27 +0200261static
262int __init qede_init(void)
263{
264 int ret;
Yuval Mintze712d522015-10-26 11:02:27 +0200265
Yuval Mintz525ef5c2016-08-15 10:42:45 +0300266 pr_info("qede_init: %s\n", version);
Yuval Mintze712d522015-10-26 11:02:27 +0200267
Rahul Verma95114342016-04-10 12:42:59 +0300268 qed_ops = qed_get_eth_ops();
Yuval Mintze712d522015-10-26 11:02:27 +0200269 if (!qed_ops) {
270 pr_notice("Failed to get qed ethtool operations\n");
271 return -EINVAL;
272 }
273
Yuval Mintz29502192015-10-26 11:02:29 +0200274 /* Must register notifier before pci ops, since we might miss
275 * interface rename after pci probe and netdev registeration.
276 */
277 ret = register_netdevice_notifier(&qede_netdev_notifier);
278 if (ret) {
279 pr_notice("Failed to register netdevice_notifier\n");
280 qed_put_eth_ops();
281 return -EINVAL;
282 }
283
Yuval Mintze712d522015-10-26 11:02:27 +0200284 ret = pci_register_driver(&qede_pci_driver);
285 if (ret) {
286 pr_notice("Failed to register driver\n");
Yuval Mintz29502192015-10-26 11:02:29 +0200287 unregister_netdevice_notifier(&qede_netdev_notifier);
Yuval Mintze712d522015-10-26 11:02:27 +0200288 qed_put_eth_ops();
289 return -EINVAL;
290 }
291
292 return 0;
293}
294
295static void __exit qede_cleanup(void)
296{
Yuval Mintz525ef5c2016-08-15 10:42:45 +0300297 if (debug & QED_LOG_INFO_MASK)
298 pr_info("qede_cleanup called\n");
Yuval Mintze712d522015-10-26 11:02:27 +0200299
Yuval Mintz29502192015-10-26 11:02:29 +0200300 unregister_netdevice_notifier(&qede_netdev_notifier);
Yuval Mintze712d522015-10-26 11:02:27 +0200301 pci_unregister_driver(&qede_pci_driver);
302 qed_put_eth_ops();
303}
304
305module_init(qede_init);
306module_exit(qede_cleanup);
307
Yuval Mintz29502192015-10-26 11:02:29 +0200308static int qede_open(struct net_device *ndev);
309static int qede_close(struct net_device *ndev);
Sudarsana Reddy Kalluru7c1bfca2016-02-18 17:00:40 +0200310
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200311void qede_fill_by_demand_stats(struct qede_dev *edev)
312{
313 struct qed_eth_stats stats;
314
315 edev->ops->get_vport_stats(edev->cdev, &stats);
316 edev->stats.no_buff_discards = stats.no_buff_discards;
Sudarsana Reddy Kalluru1a5a3662016-08-16 10:51:01 -0400317 edev->stats.packet_too_big_discard = stats.packet_too_big_discard;
318 edev->stats.ttl0_discard = stats.ttl0_discard;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200319 edev->stats.rx_ucast_bytes = stats.rx_ucast_bytes;
320 edev->stats.rx_mcast_bytes = stats.rx_mcast_bytes;
321 edev->stats.rx_bcast_bytes = stats.rx_bcast_bytes;
322 edev->stats.rx_ucast_pkts = stats.rx_ucast_pkts;
323 edev->stats.rx_mcast_pkts = stats.rx_mcast_pkts;
324 edev->stats.rx_bcast_pkts = stats.rx_bcast_pkts;
325 edev->stats.mftag_filter_discards = stats.mftag_filter_discards;
326 edev->stats.mac_filter_discards = stats.mac_filter_discards;
327
328 edev->stats.tx_ucast_bytes = stats.tx_ucast_bytes;
329 edev->stats.tx_mcast_bytes = stats.tx_mcast_bytes;
330 edev->stats.tx_bcast_bytes = stats.tx_bcast_bytes;
331 edev->stats.tx_ucast_pkts = stats.tx_ucast_pkts;
332 edev->stats.tx_mcast_pkts = stats.tx_mcast_pkts;
333 edev->stats.tx_bcast_pkts = stats.tx_bcast_pkts;
334 edev->stats.tx_err_drop_pkts = stats.tx_err_drop_pkts;
335 edev->stats.coalesced_pkts = stats.tpa_coalesced_pkts;
336 edev->stats.coalesced_events = stats.tpa_coalesced_events;
337 edev->stats.coalesced_aborts_num = stats.tpa_aborts_num;
338 edev->stats.non_coalesced_pkts = stats.tpa_not_coalesced_pkts;
339 edev->stats.coalesced_bytes = stats.tpa_coalesced_bytes;
340
341 edev->stats.rx_64_byte_packets = stats.rx_64_byte_packets;
Yuval Mintzd4967cf2016-04-22 08:41:01 +0300342 edev->stats.rx_65_to_127_byte_packets = stats.rx_65_to_127_byte_packets;
343 edev->stats.rx_128_to_255_byte_packets =
344 stats.rx_128_to_255_byte_packets;
345 edev->stats.rx_256_to_511_byte_packets =
346 stats.rx_256_to_511_byte_packets;
347 edev->stats.rx_512_to_1023_byte_packets =
348 stats.rx_512_to_1023_byte_packets;
349 edev->stats.rx_1024_to_1518_byte_packets =
350 stats.rx_1024_to_1518_byte_packets;
351 edev->stats.rx_1519_to_1522_byte_packets =
352 stats.rx_1519_to_1522_byte_packets;
353 edev->stats.rx_1519_to_2047_byte_packets =
354 stats.rx_1519_to_2047_byte_packets;
355 edev->stats.rx_2048_to_4095_byte_packets =
356 stats.rx_2048_to_4095_byte_packets;
357 edev->stats.rx_4096_to_9216_byte_packets =
358 stats.rx_4096_to_9216_byte_packets;
359 edev->stats.rx_9217_to_16383_byte_packets =
360 stats.rx_9217_to_16383_byte_packets;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200361 edev->stats.rx_crc_errors = stats.rx_crc_errors;
362 edev->stats.rx_mac_crtl_frames = stats.rx_mac_crtl_frames;
363 edev->stats.rx_pause_frames = stats.rx_pause_frames;
364 edev->stats.rx_pfc_frames = stats.rx_pfc_frames;
365 edev->stats.rx_align_errors = stats.rx_align_errors;
366 edev->stats.rx_carrier_errors = stats.rx_carrier_errors;
367 edev->stats.rx_oversize_packets = stats.rx_oversize_packets;
368 edev->stats.rx_jabbers = stats.rx_jabbers;
369 edev->stats.rx_undersize_packets = stats.rx_undersize_packets;
370 edev->stats.rx_fragments = stats.rx_fragments;
371 edev->stats.tx_64_byte_packets = stats.tx_64_byte_packets;
372 edev->stats.tx_65_to_127_byte_packets = stats.tx_65_to_127_byte_packets;
373 edev->stats.tx_128_to_255_byte_packets =
374 stats.tx_128_to_255_byte_packets;
375 edev->stats.tx_256_to_511_byte_packets =
376 stats.tx_256_to_511_byte_packets;
377 edev->stats.tx_512_to_1023_byte_packets =
378 stats.tx_512_to_1023_byte_packets;
379 edev->stats.tx_1024_to_1518_byte_packets =
380 stats.tx_1024_to_1518_byte_packets;
381 edev->stats.tx_1519_to_2047_byte_packets =
382 stats.tx_1519_to_2047_byte_packets;
383 edev->stats.tx_2048_to_4095_byte_packets =
384 stats.tx_2048_to_4095_byte_packets;
385 edev->stats.tx_4096_to_9216_byte_packets =
386 stats.tx_4096_to_9216_byte_packets;
387 edev->stats.tx_9217_to_16383_byte_packets =
388 stats.tx_9217_to_16383_byte_packets;
389 edev->stats.tx_pause_frames = stats.tx_pause_frames;
390 edev->stats.tx_pfc_frames = stats.tx_pfc_frames;
391 edev->stats.tx_lpi_entry_count = stats.tx_lpi_entry_count;
392 edev->stats.tx_total_collisions = stats.tx_total_collisions;
393 edev->stats.brb_truncates = stats.brb_truncates;
394 edev->stats.brb_discards = stats.brb_discards;
395 edev->stats.tx_mac_ctrl_frames = stats.tx_mac_ctrl_frames;
396}
397
Yuval Mintz1a635e42016-08-15 10:42:43 +0300398static
399struct rtnl_link_stats64 *qede_get_stats64(struct net_device *dev,
400 struct rtnl_link_stats64 *stats)
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200401{
402 struct qede_dev *edev = netdev_priv(dev);
403
404 qede_fill_by_demand_stats(edev);
405
406 stats->rx_packets = edev->stats.rx_ucast_pkts +
407 edev->stats.rx_mcast_pkts +
408 edev->stats.rx_bcast_pkts;
409 stats->tx_packets = edev->stats.tx_ucast_pkts +
410 edev->stats.tx_mcast_pkts +
411 edev->stats.tx_bcast_pkts;
412
413 stats->rx_bytes = edev->stats.rx_ucast_bytes +
414 edev->stats.rx_mcast_bytes +
415 edev->stats.rx_bcast_bytes;
416
417 stats->tx_bytes = edev->stats.tx_ucast_bytes +
418 edev->stats.tx_mcast_bytes +
419 edev->stats.tx_bcast_bytes;
420
421 stats->tx_errors = edev->stats.tx_err_drop_pkts;
422 stats->multicast = edev->stats.rx_mcast_pkts +
423 edev->stats.rx_bcast_pkts;
424
425 stats->rx_fifo_errors = edev->stats.no_buff_discards;
426
427 stats->collisions = edev->stats.tx_total_collisions;
428 stats->rx_crc_errors = edev->stats.rx_crc_errors;
429 stats->rx_frame_errors = edev->stats.rx_align_errors;
430
431 return stats;
432}
433
Yuval Mintz733def62016-05-11 16:36:22 +0300434#ifdef CONFIG_QED_SRIOV
Yuval Mintz73390ac2016-05-11 16:36:24 +0300435static int qede_get_vf_config(struct net_device *dev, int vfidx,
436 struct ifla_vf_info *ivi)
437{
438 struct qede_dev *edev = netdev_priv(dev);
439
440 if (!edev->ops)
441 return -EINVAL;
442
443 return edev->ops->iov->get_config(edev->cdev, vfidx, ivi);
444}
445
Yuval Mintz733def62016-05-11 16:36:22 +0300446static int qede_set_vf_rate(struct net_device *dev, int vfidx,
447 int min_tx_rate, int max_tx_rate)
448{
449 struct qede_dev *edev = netdev_priv(dev);
450
Yuval Mintzbe7b6d62016-05-26 11:01:17 +0300451 return edev->ops->iov->set_rate(edev->cdev, vfidx, min_tx_rate,
Yuval Mintz733def62016-05-11 16:36:22 +0300452 max_tx_rate);
453}
454
Yuval Mintz6ddc7602016-05-11 16:36:23 +0300455static int qede_set_vf_spoofchk(struct net_device *dev, int vfidx, bool val)
456{
457 struct qede_dev *edev = netdev_priv(dev);
458
459 if (!edev->ops)
460 return -EINVAL;
461
462 return edev->ops->iov->set_spoof(edev->cdev, vfidx, val);
463}
464
Yuval Mintz733def62016-05-11 16:36:22 +0300465static int qede_set_vf_link_state(struct net_device *dev, int vfidx,
466 int link_state)
467{
468 struct qede_dev *edev = netdev_priv(dev);
469
470 if (!edev->ops)
471 return -EINVAL;
472
473 return edev->ops->iov->set_link_state(edev->cdev, vfidx, link_state);
474}
475#endif
476
Yuval Mintz29502192015-10-26 11:02:29 +0200477static const struct net_device_ops qede_netdev_ops = {
478 .ndo_open = qede_open,
479 .ndo_stop = qede_close,
480 .ndo_start_xmit = qede_start_xmit,
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +0200481 .ndo_set_rx_mode = qede_set_rx_mode,
482 .ndo_set_mac_address = qede_set_mac_addr,
Yuval Mintz29502192015-10-26 11:02:29 +0200483 .ndo_validate_addr = eth_validate_addr,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200484 .ndo_change_mtu = qede_change_mtu,
Yuval Mintz08feecd2016-05-11 16:36:20 +0300485#ifdef CONFIG_QED_SRIOV
Yuval Mintzeff16962016-05-11 16:36:21 +0300486 .ndo_set_vf_mac = qede_set_vf_mac,
Yuval Mintz08feecd2016-05-11 16:36:20 +0300487 .ndo_set_vf_vlan = qede_set_vf_vlan,
488#endif
Sudarsana Reddy Kalluru7c1bfca2016-02-18 17:00:40 +0200489 .ndo_vlan_rx_add_vid = qede_vlan_rx_add_vid,
490 .ndo_vlan_rx_kill_vid = qede_vlan_rx_kill_vid,
Yuval Mintzce2b8852016-05-26 11:01:18 +0300491 .ndo_set_features = qede_set_features,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200492 .ndo_get_stats64 = qede_get_stats64,
Yuval Mintz733def62016-05-11 16:36:22 +0300493#ifdef CONFIG_QED_SRIOV
494 .ndo_set_vf_link_state = qede_set_vf_link_state,
Yuval Mintz6ddc7602016-05-11 16:36:23 +0300495 .ndo_set_vf_spoofchk = qede_set_vf_spoofchk,
Yuval Mintz73390ac2016-05-11 16:36:24 +0300496 .ndo_get_vf_config = qede_get_vf_config,
Yuval Mintz733def62016-05-11 16:36:22 +0300497 .ndo_set_vf_rate = qede_set_vf_rate,
498#endif
Alexander Duyckf9f082a2016-06-16 12:22:57 -0700499 .ndo_udp_tunnel_add = qede_udp_tunnel_add,
500 .ndo_udp_tunnel_del = qede_udp_tunnel_del,
Manish Chopra25695852016-10-14 05:19:19 -0400501 .ndo_features_check = qede_features_check,
Mintz, Yuval496e0512016-11-29 16:47:09 +0200502 .ndo_xdp = qede_xdp,
Yuval Mintz29502192015-10-26 11:02:29 +0200503};
504
505/* -------------------------------------------------------------------------
Yuval Mintze712d522015-10-26 11:02:27 +0200506 * START OF PROBE / REMOVE
507 * -------------------------------------------------------------------------
508 */
509
510static struct qede_dev *qede_alloc_etherdev(struct qed_dev *cdev,
511 struct pci_dev *pdev,
512 struct qed_dev_eth_info *info,
Yuval Mintz1a635e42016-08-15 10:42:43 +0300513 u32 dp_module, u8 dp_level)
Yuval Mintze712d522015-10-26 11:02:27 +0200514{
515 struct net_device *ndev;
516 struct qede_dev *edev;
517
518 ndev = alloc_etherdev_mqs(sizeof(*edev),
Yuval Mintz1a635e42016-08-15 10:42:43 +0300519 info->num_queues, info->num_queues);
Yuval Mintze712d522015-10-26 11:02:27 +0200520 if (!ndev) {
521 pr_err("etherdev allocation failed\n");
522 return NULL;
523 }
524
525 edev = netdev_priv(ndev);
526 edev->ndev = ndev;
527 edev->cdev = cdev;
528 edev->pdev = pdev;
529 edev->dp_module = dp_module;
530 edev->dp_level = dp_level;
531 edev->ops = qed_ops;
Yuval Mintz29502192015-10-26 11:02:29 +0200532 edev->q_num_rx_buffers = NUM_RX_BDS_DEF;
533 edev->q_num_tx_buffers = NUM_TX_BDS_DEF;
Yuval Mintze712d522015-10-26 11:02:27 +0200534
Yuval Mintz525ef5c2016-08-15 10:42:45 +0300535 DP_INFO(edev, "Allocated netdev with %d tx queues and %d rx queues\n",
536 info->num_queues, info->num_queues);
537
Yuval Mintze712d522015-10-26 11:02:27 +0200538 SET_NETDEV_DEV(ndev, &pdev->dev);
539
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200540 memset(&edev->stats, 0, sizeof(edev->stats));
Yuval Mintze712d522015-10-26 11:02:27 +0200541 memcpy(&edev->dev_info, info, sizeof(*info));
542
Sudarsana Reddy Kalluru7c1bfca2016-02-18 17:00:40 +0200543 INIT_LIST_HEAD(&edev->vlan_list);
544
Yuval Mintze712d522015-10-26 11:02:27 +0200545 return edev;
546}
547
548static void qede_init_ndev(struct qede_dev *edev)
549{
550 struct net_device *ndev = edev->ndev;
551 struct pci_dev *pdev = edev->pdev;
552 u32 hw_features;
553
554 pci_set_drvdata(pdev, ndev);
555
556 ndev->mem_start = edev->dev_info.common.pci_mem_start;
557 ndev->base_addr = ndev->mem_start;
558 ndev->mem_end = edev->dev_info.common.pci_mem_end;
559 ndev->irq = edev->dev_info.common.pci_irq;
560
561 ndev->watchdog_timeo = TX_TIMEOUT;
562
Yuval Mintz29502192015-10-26 11:02:29 +0200563 ndev->netdev_ops = &qede_netdev_ops;
564
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200565 qede_set_ethtool_ops(ndev);
566
Mintz, Yuval0183eb12016-10-31 22:26:53 +0200567 ndev->priv_flags |= IFF_UNICAST_FLT;
Yuval Mintz7b7e70f2016-10-14 05:19:20 -0400568
Yuval Mintze712d522015-10-26 11:02:27 +0200569 /* user-changeble features */
570 hw_features = NETIF_F_GRO | NETIF_F_SG |
571 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
572 NETIF_F_TSO | NETIF_F_TSO6;
573
Manish Chopra14db81d2016-04-14 01:38:33 -0400574 /* Encap features*/
575 hw_features |= NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL |
Manish Chopraa1502412016-10-14 05:19:18 -0400576 NETIF_F_TSO_ECN | NETIF_F_GSO_UDP_TUNNEL_CSUM |
577 NETIF_F_GSO_GRE_CSUM;
Manish Chopra14db81d2016-04-14 01:38:33 -0400578 ndev->hw_enc_features = NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
579 NETIF_F_SG | NETIF_F_TSO | NETIF_F_TSO_ECN |
580 NETIF_F_TSO6 | NETIF_F_GSO_GRE |
Manish Chopraa1502412016-10-14 05:19:18 -0400581 NETIF_F_GSO_UDP_TUNNEL | NETIF_F_RXCSUM |
582 NETIF_F_GSO_UDP_TUNNEL_CSUM |
583 NETIF_F_GSO_GRE_CSUM;
Manish Chopra14db81d2016-04-14 01:38:33 -0400584
Yuval Mintze712d522015-10-26 11:02:27 +0200585 ndev->vlan_features = hw_features | NETIF_F_RXHASH | NETIF_F_RXCSUM |
586 NETIF_F_HIGHDMA;
587 ndev->features = hw_features | NETIF_F_RXHASH | NETIF_F_RXCSUM |
588 NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HIGHDMA |
Sudarsana Reddy Kalluru7c1bfca2016-02-18 17:00:40 +0200589 NETIF_F_HW_VLAN_CTAG_FILTER | NETIF_F_HW_VLAN_CTAG_TX;
Yuval Mintze712d522015-10-26 11:02:27 +0200590
591 ndev->hw_features = hw_features;
592
Jarod Wilsoncaff2a82016-10-17 15:54:08 -0400593 /* MTU range: 46 - 9600 */
594 ndev->min_mtu = ETH_ZLEN - ETH_HLEN;
595 ndev->max_mtu = QEDE_MAX_JUMBO_PACKET_SIZE;
596
Yuval Mintze712d522015-10-26 11:02:27 +0200597 /* Set network device HW mac */
598 ether_addr_copy(edev->ndev->dev_addr, edev->dev_info.common.hw_mac);
Sudarsana Kalluru0fefbfb2016-10-31 07:14:21 +0200599
600 ndev->mtu = edev->dev_info.common.mtu;
Yuval Mintze712d522015-10-26 11:02:27 +0200601}
602
603/* This function converts from 32b param to two params of level and module
604 * Input 32b decoding:
605 * b31 - enable all NOTICE prints. NOTICE prints are for deviation from the
606 * 'happy' flow, e.g. memory allocation failed.
607 * b30 - enable all INFO prints. INFO prints are for major steps in the flow
608 * and provide important parameters.
609 * b29-b0 - per-module bitmap, where each bit enables VERBOSE prints of that
610 * module. VERBOSE prints are for tracking the specific flow in low level.
611 *
612 * Notice that the level should be that of the lowest required logs.
613 */
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200614void qede_config_debug(uint debug, u32 *p_dp_module, u8 *p_dp_level)
Yuval Mintze712d522015-10-26 11:02:27 +0200615{
616 *p_dp_level = QED_LEVEL_NOTICE;
617 *p_dp_module = 0;
618
619 if (debug & QED_LOG_VERBOSE_MASK) {
620 *p_dp_level = QED_LEVEL_VERBOSE;
621 *p_dp_module = (debug & 0x3FFFFFFF);
622 } else if (debug & QED_LOG_INFO_MASK) {
623 *p_dp_level = QED_LEVEL_INFO;
624 } else if (debug & QED_LOG_NOTICE_MASK) {
625 *p_dp_level = QED_LEVEL_NOTICE;
626 }
627}
628
Yuval Mintz29502192015-10-26 11:02:29 +0200629static void qede_free_fp_array(struct qede_dev *edev)
630{
631 if (edev->fp_array) {
632 struct qede_fastpath *fp;
633 int i;
634
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400635 for_each_queue(i) {
Yuval Mintz29502192015-10-26 11:02:29 +0200636 fp = &edev->fp_array[i];
637
638 kfree(fp->sb_info);
639 kfree(fp->rxq);
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +0200640 kfree(fp->xdp_tx);
Mintz, Yuval80439a12016-11-29 16:47:02 +0200641 kfree(fp->txq);
Yuval Mintz29502192015-10-26 11:02:29 +0200642 }
643 kfree(edev->fp_array);
644 }
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400645
646 edev->num_queues = 0;
647 edev->fp_num_tx = 0;
648 edev->fp_num_rx = 0;
Yuval Mintz29502192015-10-26 11:02:29 +0200649}
650
651static int qede_alloc_fp_array(struct qede_dev *edev)
652{
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400653 u8 fp_combined, fp_rx = edev->fp_num_rx;
Yuval Mintz29502192015-10-26 11:02:29 +0200654 struct qede_fastpath *fp;
655 int i;
656
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400657 edev->fp_array = kcalloc(QEDE_QUEUE_CNT(edev),
Yuval Mintz29502192015-10-26 11:02:29 +0200658 sizeof(*edev->fp_array), GFP_KERNEL);
659 if (!edev->fp_array) {
660 DP_NOTICE(edev, "fp array allocation failed\n");
661 goto err;
662 }
663
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400664 fp_combined = QEDE_QUEUE_CNT(edev) - fp_rx - edev->fp_num_tx;
665
666 /* Allocate the FP elements for Rx queues followed by combined and then
667 * the Tx. This ordering should be maintained so that the respective
668 * queues (Rx or Tx) will be together in the fastpath array and the
669 * associated ids will be sequential.
670 */
671 for_each_queue(i) {
Yuval Mintz29502192015-10-26 11:02:29 +0200672 fp = &edev->fp_array[i];
673
Mintz, Yuval80439a12016-11-29 16:47:02 +0200674 fp->sb_info = kzalloc(sizeof(*fp->sb_info), GFP_KERNEL);
Yuval Mintz29502192015-10-26 11:02:29 +0200675 if (!fp->sb_info) {
676 DP_NOTICE(edev, "sb info struct allocation failed\n");
677 goto err;
678 }
679
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400680 if (fp_rx) {
681 fp->type = QEDE_FASTPATH_RX;
682 fp_rx--;
683 } else if (fp_combined) {
684 fp->type = QEDE_FASTPATH_COMBINED;
685 fp_combined--;
686 } else {
687 fp->type = QEDE_FASTPATH_TX;
Yuval Mintz29502192015-10-26 11:02:29 +0200688 }
689
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400690 if (fp->type & QEDE_FASTPATH_TX) {
Mintz, Yuval80439a12016-11-29 16:47:02 +0200691 fp->txq = kzalloc(sizeof(*fp->txq), GFP_KERNEL);
692 if (!fp->txq)
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400693 goto err;
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400694 }
695
696 if (fp->type & QEDE_FASTPATH_RX) {
Mintz, Yuval80439a12016-11-29 16:47:02 +0200697 fp->rxq = kzalloc(sizeof(*fp->rxq), GFP_KERNEL);
698 if (!fp->rxq)
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400699 goto err;
Mintz, Yuval496e0512016-11-29 16:47:09 +0200700
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +0200701 if (edev->xdp_prog) {
702 fp->xdp_tx = kzalloc(sizeof(*fp->xdp_tx),
703 GFP_KERNEL);
704 if (!fp->xdp_tx)
705 goto err;
Mintz, Yuval496e0512016-11-29 16:47:09 +0200706 fp->type |= QEDE_FASTPATH_XDP;
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +0200707 }
Yuval Mintz29502192015-10-26 11:02:29 +0200708 }
709 }
710
711 return 0;
712err:
713 qede_free_fp_array(edev);
714 return -ENOMEM;
715}
716
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +0200717static void qede_sp_task(struct work_struct *work)
718{
719 struct qede_dev *edev = container_of(work, struct qede_dev,
720 sp_task.work);
Manish Choprab18e1702016-04-14 01:38:30 -0400721 struct qed_dev *cdev = edev->cdev;
722
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200723 __qede_lock(edev);
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +0200724
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200725 if (test_and_clear_bit(QEDE_SP_RX_MODE, &edev->sp_flags))
726 if (edev->state == QEDE_STATE_OPEN)
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +0200727 qede_config_rx_mode(edev->ndev);
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +0200728
Manish Choprab18e1702016-04-14 01:38:30 -0400729 if (test_and_clear_bit(QEDE_SP_VXLAN_PORT_CONFIG, &edev->sp_flags)) {
730 struct qed_tunn_params tunn_params;
731
732 memset(&tunn_params, 0, sizeof(tunn_params));
733 tunn_params.update_vxlan_port = 1;
734 tunn_params.vxlan_port = edev->vxlan_dst_port;
735 qed_ops->tunn_config(cdev, &tunn_params);
736 }
737
Manish Chopra9a109dd2016-04-14 01:38:31 -0400738 if (test_and_clear_bit(QEDE_SP_GENEVE_PORT_CONFIG, &edev->sp_flags)) {
739 struct qed_tunn_params tunn_params;
740
741 memset(&tunn_params, 0, sizeof(tunn_params));
742 tunn_params.update_geneve_port = 1;
743 tunn_params.geneve_port = edev->geneve_dst_port;
744 qed_ops->tunn_config(cdev, &tunn_params);
745 }
746
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200747 __qede_unlock(edev);
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +0200748}
749
Yuval Mintze712d522015-10-26 11:02:27 +0200750static void qede_update_pf_params(struct qed_dev *cdev)
751{
752 struct qed_pf_params pf_params;
753
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +0200754 /* 64 rx + 64 tx + 64 XDP */
Yuval Mintze712d522015-10-26 11:02:27 +0200755 memset(&pf_params, 0, sizeof(struct qed_pf_params));
Mintz, Yuvale1d32ac2017-01-01 13:57:03 +0200756 pf_params.eth_pf_params.num_cons = (MAX_SB_PER_PF_MIMD - 1) * 3;
Yuval Mintze712d522015-10-26 11:02:27 +0200757 qed_ops->common->update_pf_params(cdev, &pf_params);
758}
759
760enum qede_probe_mode {
761 QEDE_PROBE_NORMAL,
762};
763
764static int __qede_probe(struct pci_dev *pdev, u32 dp_module, u8 dp_level,
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300765 bool is_vf, enum qede_probe_mode mode)
Yuval Mintze712d522015-10-26 11:02:27 +0200766{
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300767 struct qed_probe_params probe_params;
Yuval Mintz1a635e42016-08-15 10:42:43 +0300768 struct qed_slowpath_params sp_params;
Yuval Mintze712d522015-10-26 11:02:27 +0200769 struct qed_dev_eth_info dev_info;
770 struct qede_dev *edev;
771 struct qed_dev *cdev;
772 int rc;
773
774 if (unlikely(dp_level & QED_LEVEL_INFO))
775 pr_notice("Starting qede probe\n");
776
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300777 memset(&probe_params, 0, sizeof(probe_params));
778 probe_params.protocol = QED_PROTOCOL_ETH;
779 probe_params.dp_module = dp_module;
780 probe_params.dp_level = dp_level;
781 probe_params.is_vf = is_vf;
782 cdev = qed_ops->common->probe(pdev, &probe_params);
Yuval Mintze712d522015-10-26 11:02:27 +0200783 if (!cdev) {
784 rc = -ENODEV;
785 goto err0;
786 }
787
788 qede_update_pf_params(cdev);
789
790 /* Start the Slowpath-process */
Yuval Mintz1a635e42016-08-15 10:42:43 +0300791 memset(&sp_params, 0, sizeof(sp_params));
792 sp_params.int_mode = QED_INT_MODE_MSIX;
793 sp_params.drv_major = QEDE_MAJOR_VERSION;
794 sp_params.drv_minor = QEDE_MINOR_VERSION;
795 sp_params.drv_rev = QEDE_REVISION_VERSION;
796 sp_params.drv_eng = QEDE_ENGINEERING_VERSION;
797 strlcpy(sp_params.name, "qede LAN", QED_DRV_VER_STR_SIZE);
798 rc = qed_ops->common->slowpath_start(cdev, &sp_params);
Yuval Mintze712d522015-10-26 11:02:27 +0200799 if (rc) {
800 pr_notice("Cannot start slowpath\n");
801 goto err1;
802 }
803
804 /* Learn information crucial for qede to progress */
805 rc = qed_ops->fill_dev_info(cdev, &dev_info);
806 if (rc)
807 goto err2;
808
809 edev = qede_alloc_etherdev(cdev, pdev, &dev_info, dp_module,
810 dp_level);
811 if (!edev) {
812 rc = -ENOMEM;
813 goto err2;
814 }
815
Yuval Mintzfefb0202016-05-11 16:36:19 +0300816 if (is_vf)
817 edev->flags |= QEDE_FLAG_IS_VF;
818
Yuval Mintze712d522015-10-26 11:02:27 +0200819 qede_init_ndev(edev);
820
Ram Amranicee9fbd2016-10-01 21:59:56 +0300821 rc = qede_roce_dev_add(edev);
822 if (rc)
823 goto err3;
824
Yuval Mintz29502192015-10-26 11:02:29 +0200825 rc = register_netdev(edev->ndev);
826 if (rc) {
827 DP_NOTICE(edev, "Cannot register net-device\n");
Ram Amranicee9fbd2016-10-01 21:59:56 +0300828 goto err4;
Yuval Mintz29502192015-10-26 11:02:29 +0200829 }
830
Yuval Mintze712d522015-10-26 11:02:27 +0200831 edev->ops->common->set_id(cdev, edev->ndev->name, DRV_MODULE_VERSION);
832
Sudarsana Kallurua2ec6172015-10-26 11:02:32 +0200833 edev->ops->register_ops(cdev, &qede_ll_ops, edev);
834
Sudarsana Reddy Kalluru489e45a2016-06-08 06:22:12 -0400835#ifdef CONFIG_DCB
Sudarsana Reddy Kalluru5fe118c2016-08-29 08:29:52 -0400836 if (!IS_VF(edev))
837 qede_set_dcbnl_ops(edev->ndev);
Sudarsana Reddy Kalluru489e45a2016-06-08 06:22:12 -0400838#endif
839
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +0200840 INIT_DELAYED_WORK(&edev->sp_task, qede_sp_task);
841 mutex_init(&edev->qede_lock);
Manish Chopra3d789992016-06-30 02:35:21 -0400842 edev->rx_copybreak = QEDE_RX_HDR_SIZE;
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +0200843
Yuval Mintze712d522015-10-26 11:02:27 +0200844 DP_INFO(edev, "Ending successfully qede probe\n");
845
846 return 0;
847
Ram Amranicee9fbd2016-10-01 21:59:56 +0300848err4:
849 qede_roce_dev_remove(edev);
Yuval Mintz29502192015-10-26 11:02:29 +0200850err3:
851 free_netdev(edev->ndev);
Yuval Mintze712d522015-10-26 11:02:27 +0200852err2:
853 qed_ops->common->slowpath_stop(cdev);
854err1:
855 qed_ops->common->remove(cdev);
856err0:
857 return rc;
858}
859
860static int qede_probe(struct pci_dev *pdev, const struct pci_device_id *id)
861{
Yuval Mintzfefb0202016-05-11 16:36:19 +0300862 bool is_vf = false;
Yuval Mintze712d522015-10-26 11:02:27 +0200863 u32 dp_module = 0;
864 u8 dp_level = 0;
865
Yuval Mintzfefb0202016-05-11 16:36:19 +0300866 switch ((enum qede_pci_private)id->driver_data) {
867 case QEDE_PRIVATE_VF:
868 if (debug & QED_LOG_VERBOSE_MASK)
869 dev_err(&pdev->dev, "Probing a VF\n");
870 is_vf = true;
871 break;
872 default:
873 if (debug & QED_LOG_VERBOSE_MASK)
874 dev_err(&pdev->dev, "Probing a PF\n");
875 }
876
Yuval Mintze712d522015-10-26 11:02:27 +0200877 qede_config_debug(debug, &dp_module, &dp_level);
878
Yuval Mintzfefb0202016-05-11 16:36:19 +0300879 return __qede_probe(pdev, dp_module, dp_level, is_vf,
Yuval Mintze712d522015-10-26 11:02:27 +0200880 QEDE_PROBE_NORMAL);
881}
882
883enum qede_remove_mode {
884 QEDE_REMOVE_NORMAL,
885};
886
887static void __qede_remove(struct pci_dev *pdev, enum qede_remove_mode mode)
888{
889 struct net_device *ndev = pci_get_drvdata(pdev);
890 struct qede_dev *edev = netdev_priv(ndev);
891 struct qed_dev *cdev = edev->cdev;
892
893 DP_INFO(edev, "Starting qede_remove\n");
894
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +0200895 cancel_delayed_work_sync(&edev->sp_task);
Ram Amranicee9fbd2016-10-01 21:59:56 +0300896
Yuval Mintz29502192015-10-26 11:02:29 +0200897 unregister_netdev(ndev);
898
Ram Amranicee9fbd2016-10-01 21:59:56 +0300899 qede_roce_dev_remove(edev);
900
Yuval Mintze712d522015-10-26 11:02:27 +0200901 edev->ops->common->set_power_state(cdev, PCI_D0);
902
903 pci_set_drvdata(pdev, NULL);
904
Mintz, Yuval496e0512016-11-29 16:47:09 +0200905 /* Release edev's reference to XDP's bpf if such exist */
906 if (edev->xdp_prog)
907 bpf_prog_put(edev->xdp_prog);
908
Yuval Mintze712d522015-10-26 11:02:27 +0200909 free_netdev(ndev);
910
911 /* Use global ops since we've freed edev */
912 qed_ops->common->slowpath_stop(cdev);
Mintz, Yuval14d39642016-10-31 07:14:23 +0200913 if (system_state == SYSTEM_POWER_OFF)
914 return;
Yuval Mintze712d522015-10-26 11:02:27 +0200915 qed_ops->common->remove(cdev);
916
Yuval Mintz525ef5c2016-08-15 10:42:45 +0300917 dev_info(&pdev->dev, "Ending qede_remove successfully\n");
Yuval Mintze712d522015-10-26 11:02:27 +0200918}
919
920static void qede_remove(struct pci_dev *pdev)
921{
922 __qede_remove(pdev, QEDE_REMOVE_NORMAL);
923}
Yuval Mintz29502192015-10-26 11:02:29 +0200924
Mintz, Yuval14d39642016-10-31 07:14:23 +0200925static void qede_shutdown(struct pci_dev *pdev)
926{
927 __qede_remove(pdev, QEDE_REMOVE_NORMAL);
928}
929
Yuval Mintz29502192015-10-26 11:02:29 +0200930/* -------------------------------------------------------------------------
931 * START OF LOAD / UNLOAD
932 * -------------------------------------------------------------------------
933 */
934
935static int qede_set_num_queues(struct qede_dev *edev)
936{
937 int rc;
938 u16 rss_num;
939
940 /* Setup queues according to possible resources*/
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400941 if (edev->req_queues)
942 rss_num = edev->req_queues;
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200943 else
944 rss_num = netif_get_num_default_rss_queues() *
945 edev->dev_info.common.num_hwfns;
Yuval Mintz29502192015-10-26 11:02:29 +0200946
947 rss_num = min_t(u16, QEDE_MAX_RSS_CNT(edev), rss_num);
948
949 rc = edev->ops->common->set_fp_int(edev->cdev, rss_num);
950 if (rc > 0) {
951 /* Managed to request interrupts for our queues */
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400952 edev->num_queues = rc;
Yuval Mintz29502192015-10-26 11:02:29 +0200953 DP_INFO(edev, "Managed %d [of %d] RSS queues\n",
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400954 QEDE_QUEUE_CNT(edev), rss_num);
Yuval Mintz29502192015-10-26 11:02:29 +0200955 rc = 0;
956 }
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400957
958 edev->fp_num_tx = edev->req_num_tx;
959 edev->fp_num_rx = edev->req_num_rx;
960
Yuval Mintz29502192015-10-26 11:02:29 +0200961 return rc;
962}
963
964static void qede_free_mem_sb(struct qede_dev *edev,
965 struct qed_sb_info *sb_info)
966{
967 if (sb_info->sb_virt)
968 dma_free_coherent(&edev->pdev->dev, sizeof(*sb_info->sb_virt),
969 (void *)sb_info->sb_virt, sb_info->sb_phys);
970}
971
972/* This function allocates fast-path status block memory */
973static int qede_alloc_mem_sb(struct qede_dev *edev,
Yuval Mintz1a635e42016-08-15 10:42:43 +0300974 struct qed_sb_info *sb_info, u16 sb_id)
Yuval Mintz29502192015-10-26 11:02:29 +0200975{
976 struct status_block *sb_virt;
977 dma_addr_t sb_phys;
978 int rc;
979
980 sb_virt = dma_alloc_coherent(&edev->pdev->dev,
Yuval Mintz1a635e42016-08-15 10:42:43 +0300981 sizeof(*sb_virt), &sb_phys, GFP_KERNEL);
Yuval Mintz29502192015-10-26 11:02:29 +0200982 if (!sb_virt) {
983 DP_ERR(edev, "Status block allocation failed\n");
984 return -ENOMEM;
985 }
986
987 rc = edev->ops->common->sb_init(edev->cdev, sb_info,
988 sb_virt, sb_phys, sb_id,
989 QED_SB_TYPE_L2_QUEUE);
990 if (rc) {
991 DP_ERR(edev, "Status block initialization failed\n");
992 dma_free_coherent(&edev->pdev->dev, sizeof(*sb_virt),
993 sb_virt, sb_phys);
994 return rc;
995 }
996
997 return 0;
998}
999
1000static void qede_free_rx_buffers(struct qede_dev *edev,
1001 struct qede_rx_queue *rxq)
1002{
1003 u16 i;
1004
1005 for (i = rxq->sw_rx_cons; i != rxq->sw_rx_prod; i++) {
1006 struct sw_rx_data *rx_buf;
Yuval Mintzfc48b7a2016-02-15 13:22:35 -05001007 struct page *data;
Yuval Mintz29502192015-10-26 11:02:29 +02001008
1009 rx_buf = &rxq->sw_rx_ring[i & NUM_RX_BDS_MAX];
1010 data = rx_buf->data;
1011
Yuval Mintzfc48b7a2016-02-15 13:22:35 -05001012 dma_unmap_page(&edev->pdev->dev,
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001013 rx_buf->mapping, PAGE_SIZE, rxq->data_direction);
Yuval Mintz29502192015-10-26 11:02:29 +02001014
1015 rx_buf->data = NULL;
Yuval Mintzfc48b7a2016-02-15 13:22:35 -05001016 __free_page(data);
Yuval Mintz29502192015-10-26 11:02:29 +02001017 }
1018}
1019
Yuval Mintz1a635e42016-08-15 10:42:43 +03001020static void qede_free_sge_mem(struct qede_dev *edev, struct qede_rx_queue *rxq)
1021{
Manish Chopra55482ed2016-03-04 12:35:06 -05001022 int i;
1023
1024 if (edev->gro_disable)
1025 return;
1026
1027 for (i = 0; i < ETH_TPA_MAX_AGGS_NUM; i++) {
1028 struct qede_agg_info *tpa_info = &rxq->tpa_info[i];
Mintz, Yuval01e23012016-11-29 16:47:00 +02001029 struct sw_rx_data *replace_buf = &tpa_info->buffer;
Manish Chopra55482ed2016-03-04 12:35:06 -05001030
Manish Chopraf86af2d2016-04-20 03:03:27 -04001031 if (replace_buf->data) {
Manish Chopra55482ed2016-03-04 12:35:06 -05001032 dma_unmap_page(&edev->pdev->dev,
Manish Chopra09ec8e72016-05-18 07:43:57 -04001033 replace_buf->mapping,
Manish Chopra55482ed2016-03-04 12:35:06 -05001034 PAGE_SIZE, DMA_FROM_DEVICE);
1035 __free_page(replace_buf->data);
1036 }
1037 }
1038}
1039
Yuval Mintz1a635e42016-08-15 10:42:43 +03001040static void qede_free_mem_rxq(struct qede_dev *edev, struct qede_rx_queue *rxq)
Yuval Mintz29502192015-10-26 11:02:29 +02001041{
Manish Chopra55482ed2016-03-04 12:35:06 -05001042 qede_free_sge_mem(edev, rxq);
1043
Yuval Mintz29502192015-10-26 11:02:29 +02001044 /* Free rx buffers */
1045 qede_free_rx_buffers(edev, rxq);
1046
1047 /* Free the parallel SW ring */
1048 kfree(rxq->sw_rx_ring);
1049
1050 /* Free the real RQ ring used by FW */
1051 edev->ops->common->chain_free(edev->cdev, &rxq->rx_bd_ring);
1052 edev->ops->common->chain_free(edev->cdev, &rxq->rx_comp_ring);
1053}
1054
Yuval Mintz1a635e42016-08-15 10:42:43 +03001055static int qede_alloc_sge_mem(struct qede_dev *edev, struct qede_rx_queue *rxq)
Manish Chopra55482ed2016-03-04 12:35:06 -05001056{
1057 dma_addr_t mapping;
1058 int i;
1059
Mintz, Yuval496e0512016-11-29 16:47:09 +02001060 /* Don't perform FW aggregations in case of XDP */
1061 if (edev->xdp_prog)
1062 edev->gro_disable = 1;
1063
Manish Chopra55482ed2016-03-04 12:35:06 -05001064 if (edev->gro_disable)
1065 return 0;
1066
1067 if (edev->ndev->mtu > PAGE_SIZE) {
1068 edev->gro_disable = 1;
1069 return 0;
1070 }
1071
1072 for (i = 0; i < ETH_TPA_MAX_AGGS_NUM; i++) {
1073 struct qede_agg_info *tpa_info = &rxq->tpa_info[i];
Mintz, Yuval01e23012016-11-29 16:47:00 +02001074 struct sw_rx_data *replace_buf = &tpa_info->buffer;
Manish Chopra55482ed2016-03-04 12:35:06 -05001075
1076 replace_buf->data = alloc_pages(GFP_ATOMIC, 0);
1077 if (unlikely(!replace_buf->data)) {
1078 DP_NOTICE(edev,
1079 "Failed to allocate TPA skb pool [replacement buffer]\n");
1080 goto err;
1081 }
1082
1083 mapping = dma_map_page(&edev->pdev->dev, replace_buf->data, 0,
Mintz, Yuval95129252016-11-02 16:36:46 +02001084 PAGE_SIZE, DMA_FROM_DEVICE);
Manish Chopra55482ed2016-03-04 12:35:06 -05001085 if (unlikely(dma_mapping_error(&edev->pdev->dev, mapping))) {
1086 DP_NOTICE(edev,
1087 "Failed to map TPA replacement buffer\n");
1088 goto err;
1089 }
1090
Manish Chopra09ec8e72016-05-18 07:43:57 -04001091 replace_buf->mapping = mapping;
Mintz, Yuval01e23012016-11-29 16:47:00 +02001092 tpa_info->buffer.page_offset = 0;
1093 tpa_info->buffer_mapping = mapping;
1094 tpa_info->state = QEDE_AGG_STATE_NONE;
Manish Chopra55482ed2016-03-04 12:35:06 -05001095 }
1096
1097 return 0;
1098err:
1099 qede_free_sge_mem(edev, rxq);
1100 edev->gro_disable = 1;
1101 return -ENOMEM;
1102}
1103
Yuval Mintz29502192015-10-26 11:02:29 +02001104/* This function allocates all memory needed per Rx queue */
Yuval Mintz1a635e42016-08-15 10:42:43 +03001105static int qede_alloc_mem_rxq(struct qede_dev *edev, struct qede_rx_queue *rxq)
Yuval Mintz29502192015-10-26 11:02:29 +02001106{
Manish Chopraf86af2d2016-04-20 03:03:27 -04001107 int i, rc, size;
Yuval Mintz29502192015-10-26 11:02:29 +02001108
1109 rxq->num_rx_buffers = edev->q_num_rx_buffers;
1110
Yuval Mintz1a635e42016-08-15 10:42:43 +03001111 rxq->rx_buf_size = NET_IP_ALIGN + ETH_OVERHEAD + edev->ndev->mtu;
1112
Yuval Mintzfc48b7a2016-02-15 13:22:35 -05001113 if (rxq->rx_buf_size > PAGE_SIZE)
1114 rxq->rx_buf_size = PAGE_SIZE;
1115
Mintz, Yuval496e0512016-11-29 16:47:09 +02001116 /* Segment size to spilt a page in multiple equal parts,
1117 * unless XDP is used in which case we'd use the entire page.
1118 */
1119 if (!edev->xdp_prog)
1120 rxq->rx_buf_seg_size = roundup_pow_of_two(rxq->rx_buf_size);
1121 else
1122 rxq->rx_buf_seg_size = PAGE_SIZE;
Yuval Mintz29502192015-10-26 11:02:29 +02001123
1124 /* Allocate the parallel driver ring for Rx buffers */
Yuval Mintzfc48b7a2016-02-15 13:22:35 -05001125 size = sizeof(*rxq->sw_rx_ring) * RX_RING_SIZE;
Yuval Mintz29502192015-10-26 11:02:29 +02001126 rxq->sw_rx_ring = kzalloc(size, GFP_KERNEL);
1127 if (!rxq->sw_rx_ring) {
1128 DP_ERR(edev, "Rx buffers ring allocation failed\n");
Manish Chopraf86af2d2016-04-20 03:03:27 -04001129 rc = -ENOMEM;
Yuval Mintz29502192015-10-26 11:02:29 +02001130 goto err;
1131 }
1132
1133 /* Allocate FW Rx ring */
1134 rc = edev->ops->common->chain_alloc(edev->cdev,
1135 QED_CHAIN_USE_TO_CONSUME_PRODUCE,
1136 QED_CHAIN_MODE_NEXT_PTR,
Yuval Mintza91eb522016-06-03 14:35:32 +03001137 QED_CHAIN_CNT_TYPE_U16,
Yuval Mintzfc48b7a2016-02-15 13:22:35 -05001138 RX_RING_SIZE,
Yuval Mintz29502192015-10-26 11:02:29 +02001139 sizeof(struct eth_rx_bd),
1140 &rxq->rx_bd_ring);
1141
1142 if (rc)
1143 goto err;
1144
1145 /* Allocate FW completion ring */
1146 rc = edev->ops->common->chain_alloc(edev->cdev,
1147 QED_CHAIN_USE_TO_CONSUME,
1148 QED_CHAIN_MODE_PBL,
Yuval Mintza91eb522016-06-03 14:35:32 +03001149 QED_CHAIN_CNT_TYPE_U16,
Yuval Mintzfc48b7a2016-02-15 13:22:35 -05001150 RX_RING_SIZE,
Yuval Mintz29502192015-10-26 11:02:29 +02001151 sizeof(union eth_rx_cqe),
1152 &rxq->rx_comp_ring);
1153 if (rc)
1154 goto err;
1155
1156 /* Allocate buffers for the Rx ring */
Mintz, Yuvale3eef7e2017-01-01 13:57:04 +02001157 rxq->filled_buffers = 0;
Yuval Mintz29502192015-10-26 11:02:29 +02001158 for (i = 0; i < rxq->num_rx_buffers; i++) {
Mintz, Yuvale3eef7e2017-01-01 13:57:04 +02001159 rc = qede_alloc_rx_buffer(rxq, false);
Manish Chopraf86af2d2016-04-20 03:03:27 -04001160 if (rc) {
1161 DP_ERR(edev,
1162 "Rx buffers allocation failed at index %d\n", i);
1163 goto err;
1164 }
Yuval Mintz29502192015-10-26 11:02:29 +02001165 }
1166
Manish Chopraf86af2d2016-04-20 03:03:27 -04001167 rc = qede_alloc_sge_mem(edev, rxq);
Yuval Mintz29502192015-10-26 11:02:29 +02001168err:
Manish Chopraf86af2d2016-04-20 03:03:27 -04001169 return rc;
Yuval Mintz29502192015-10-26 11:02:29 +02001170}
1171
Yuval Mintz1a635e42016-08-15 10:42:43 +03001172static void qede_free_mem_txq(struct qede_dev *edev, struct qede_tx_queue *txq)
Yuval Mintz29502192015-10-26 11:02:29 +02001173{
1174 /* Free the parallel SW ring */
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001175 if (txq->is_xdp)
1176 kfree(txq->sw_tx_ring.pages);
1177 else
1178 kfree(txq->sw_tx_ring.skbs);
Yuval Mintz29502192015-10-26 11:02:29 +02001179
1180 /* Free the real RQ ring used by FW */
1181 edev->ops->common->chain_free(edev->cdev, &txq->tx_pbl);
1182}
1183
1184/* This function allocates all memory needed per Tx queue */
Yuval Mintz1a635e42016-08-15 10:42:43 +03001185static int qede_alloc_mem_txq(struct qede_dev *edev, struct qede_tx_queue *txq)
Yuval Mintz29502192015-10-26 11:02:29 +02001186{
Yuval Mintz29502192015-10-26 11:02:29 +02001187 union eth_tx_bd_types *p_virt;
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001188 int size, rc;
Yuval Mintz29502192015-10-26 11:02:29 +02001189
1190 txq->num_tx_buffers = edev->q_num_tx_buffers;
1191
1192 /* Allocate the parallel driver ring for Tx buffers */
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001193 if (txq->is_xdp) {
1194 size = sizeof(*txq->sw_tx_ring.pages) * TX_RING_SIZE;
1195 txq->sw_tx_ring.pages = kzalloc(size, GFP_KERNEL);
1196 if (!txq->sw_tx_ring.pages)
1197 goto err;
1198 } else {
1199 size = sizeof(*txq->sw_tx_ring.skbs) * TX_RING_SIZE;
1200 txq->sw_tx_ring.skbs = kzalloc(size, GFP_KERNEL);
1201 if (!txq->sw_tx_ring.skbs)
1202 goto err;
Yuval Mintz29502192015-10-26 11:02:29 +02001203 }
1204
1205 rc = edev->ops->common->chain_alloc(edev->cdev,
1206 QED_CHAIN_USE_TO_CONSUME_PRODUCE,
1207 QED_CHAIN_MODE_PBL,
Yuval Mintza91eb522016-06-03 14:35:32 +03001208 QED_CHAIN_CNT_TYPE_U16,
Mintz, Yuval087892d2016-10-29 17:04:35 +03001209 TX_RING_SIZE,
Yuval Mintza91eb522016-06-03 14:35:32 +03001210 sizeof(*p_virt), &txq->tx_pbl);
Yuval Mintz29502192015-10-26 11:02:29 +02001211 if (rc)
1212 goto err;
1213
1214 return 0;
1215
1216err:
1217 qede_free_mem_txq(edev, txq);
1218 return -ENOMEM;
1219}
1220
1221/* This function frees all memory of a single fp */
Yuval Mintz1a635e42016-08-15 10:42:43 +03001222static void qede_free_mem_fp(struct qede_dev *edev, struct qede_fastpath *fp)
Yuval Mintz29502192015-10-26 11:02:29 +02001223{
Yuval Mintz29502192015-10-26 11:02:29 +02001224 qede_free_mem_sb(edev, fp->sb_info);
1225
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001226 if (fp->type & QEDE_FASTPATH_RX)
1227 qede_free_mem_rxq(edev, fp->rxq);
Yuval Mintz29502192015-10-26 11:02:29 +02001228
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001229 if (fp->type & QEDE_FASTPATH_TX)
Mintz, Yuval80439a12016-11-29 16:47:02 +02001230 qede_free_mem_txq(edev, fp->txq);
Yuval Mintz29502192015-10-26 11:02:29 +02001231}
1232
1233/* This function allocates all memory needed for a single fp (i.e. an entity
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001234 * which contains status block, one rx queue and/or multiple per-TC tx queues.
Yuval Mintz29502192015-10-26 11:02:29 +02001235 */
Yuval Mintz1a635e42016-08-15 10:42:43 +03001236static int qede_alloc_mem_fp(struct qede_dev *edev, struct qede_fastpath *fp)
Yuval Mintz29502192015-10-26 11:02:29 +02001237{
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001238 int rc = 0;
Yuval Mintz29502192015-10-26 11:02:29 +02001239
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001240 rc = qede_alloc_mem_sb(edev, fp->sb_info, fp->id);
Yuval Mintz29502192015-10-26 11:02:29 +02001241 if (rc)
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001242 goto out;
Yuval Mintz29502192015-10-26 11:02:29 +02001243
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001244 if (fp->type & QEDE_FASTPATH_RX) {
1245 rc = qede_alloc_mem_rxq(edev, fp->rxq);
Yuval Mintz29502192015-10-26 11:02:29 +02001246 if (rc)
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001247 goto out;
1248 }
1249
1250 if (fp->type & QEDE_FASTPATH_XDP) {
1251 rc = qede_alloc_mem_txq(edev, fp->xdp_tx);
1252 if (rc)
1253 goto out;
Yuval Mintz29502192015-10-26 11:02:29 +02001254 }
1255
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001256 if (fp->type & QEDE_FASTPATH_TX) {
Mintz, Yuval80439a12016-11-29 16:47:02 +02001257 rc = qede_alloc_mem_txq(edev, fp->txq);
1258 if (rc)
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001259 goto out;
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001260 }
1261
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001262out:
Manish Chopraf86af2d2016-04-20 03:03:27 -04001263 return rc;
Yuval Mintz29502192015-10-26 11:02:29 +02001264}
1265
1266static void qede_free_mem_load(struct qede_dev *edev)
1267{
1268 int i;
1269
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001270 for_each_queue(i) {
Yuval Mintz29502192015-10-26 11:02:29 +02001271 struct qede_fastpath *fp = &edev->fp_array[i];
1272
1273 qede_free_mem_fp(edev, fp);
1274 }
1275}
1276
1277/* This function allocates all qede memory at NIC load. */
1278static int qede_alloc_mem_load(struct qede_dev *edev)
1279{
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001280 int rc = 0, queue_id;
Yuval Mintz29502192015-10-26 11:02:29 +02001281
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001282 for (queue_id = 0; queue_id < QEDE_QUEUE_CNT(edev); queue_id++) {
1283 struct qede_fastpath *fp = &edev->fp_array[queue_id];
Yuval Mintz29502192015-10-26 11:02:29 +02001284
1285 rc = qede_alloc_mem_fp(edev, fp);
Manish Chopraf86af2d2016-04-20 03:03:27 -04001286 if (rc) {
Yuval Mintz29502192015-10-26 11:02:29 +02001287 DP_ERR(edev,
Manish Chopraf86af2d2016-04-20 03:03:27 -04001288 "Failed to allocate memory for fastpath - rss id = %d\n",
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001289 queue_id);
Manish Chopraf86af2d2016-04-20 03:03:27 -04001290 qede_free_mem_load(edev);
1291 return rc;
Yuval Mintz29502192015-10-26 11:02:29 +02001292 }
Yuval Mintz29502192015-10-26 11:02:29 +02001293 }
1294
1295 return 0;
1296}
1297
1298/* This function inits fp content and resets the SB, RXQ and TXQ structures */
1299static void qede_init_fp(struct qede_dev *edev)
1300{
Mintz, Yuval80439a12016-11-29 16:47:02 +02001301 int queue_id, rxq_index = 0, txq_index = 0;
Yuval Mintz29502192015-10-26 11:02:29 +02001302 struct qede_fastpath *fp;
1303
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001304 for_each_queue(queue_id) {
1305 fp = &edev->fp_array[queue_id];
Yuval Mintz29502192015-10-26 11:02:29 +02001306
1307 fp->edev = edev;
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001308 fp->id = queue_id;
Yuval Mintz29502192015-10-26 11:02:29 +02001309
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001310 if (fp->type & QEDE_FASTPATH_XDP) {
1311 fp->xdp_tx->index = QEDE_TXQ_IDX_TO_XDP(edev,
1312 rxq_index);
1313 fp->xdp_tx->is_xdp = 1;
1314 }
Yuval Mintz29502192015-10-26 11:02:29 +02001315
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001316 if (fp->type & QEDE_FASTPATH_RX) {
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001317 fp->rxq->rxq_id = rxq_index++;
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001318
1319 /* Determine how to map buffers for this queue */
1320 if (fp->type & QEDE_FASTPATH_XDP)
1321 fp->rxq->data_direction = DMA_BIDIRECTIONAL;
1322 else
1323 fp->rxq->data_direction = DMA_FROM_DEVICE;
Mintz, Yuval9eb22352016-11-29 16:47:08 +02001324 fp->rxq->dev = &edev->pdev->dev;
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001325 }
Yuval Mintz29502192015-10-26 11:02:29 +02001326
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001327 if (fp->type & QEDE_FASTPATH_TX) {
Mintz, Yuval80439a12016-11-29 16:47:02 +02001328 fp->txq->index = txq_index++;
1329 if (edev->dev_info.is_legacy)
1330 fp->txq->is_legacy = 1;
Mintz, Yuval9eb22352016-11-29 16:47:08 +02001331 fp->txq->dev = &edev->pdev->dev;
Yuval Mintz29502192015-10-26 11:02:29 +02001332 }
1333
1334 snprintf(fp->name, sizeof(fp->name), "%s-fp-%d",
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001335 edev->ndev->name, queue_id);
Yuval Mintz29502192015-10-26 11:02:29 +02001336 }
Manish Chopra55482ed2016-03-04 12:35:06 -05001337
1338 edev->gro_disable = !(edev->ndev->features & NETIF_F_GRO);
Yuval Mintz29502192015-10-26 11:02:29 +02001339}
1340
1341static int qede_set_real_num_queues(struct qede_dev *edev)
1342{
1343 int rc = 0;
1344
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001345 rc = netif_set_real_num_tx_queues(edev->ndev, QEDE_TSS_COUNT(edev));
Yuval Mintz29502192015-10-26 11:02:29 +02001346 if (rc) {
1347 DP_NOTICE(edev, "Failed to set real number of Tx queues\n");
1348 return rc;
1349 }
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001350
1351 rc = netif_set_real_num_rx_queues(edev->ndev, QEDE_RSS_COUNT(edev));
Yuval Mintz29502192015-10-26 11:02:29 +02001352 if (rc) {
1353 DP_NOTICE(edev, "Failed to set real number of Rx queues\n");
1354 return rc;
1355 }
1356
1357 return 0;
1358}
1359
1360static void qede_napi_disable_remove(struct qede_dev *edev)
1361{
1362 int i;
1363
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001364 for_each_queue(i) {
Yuval Mintz29502192015-10-26 11:02:29 +02001365 napi_disable(&edev->fp_array[i].napi);
1366
1367 netif_napi_del(&edev->fp_array[i].napi);
1368 }
1369}
1370
1371static void qede_napi_add_enable(struct qede_dev *edev)
1372{
1373 int i;
1374
1375 /* Add NAPI objects */
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001376 for_each_queue(i) {
Yuval Mintz29502192015-10-26 11:02:29 +02001377 netif_napi_add(edev->ndev, &edev->fp_array[i].napi,
1378 qede_poll, NAPI_POLL_WEIGHT);
1379 napi_enable(&edev->fp_array[i].napi);
1380 }
1381}
1382
1383static void qede_sync_free_irqs(struct qede_dev *edev)
1384{
1385 int i;
1386
1387 for (i = 0; i < edev->int_info.used_cnt; i++) {
1388 if (edev->int_info.msix_cnt) {
1389 synchronize_irq(edev->int_info.msix[i].vector);
1390 free_irq(edev->int_info.msix[i].vector,
1391 &edev->fp_array[i]);
1392 } else {
1393 edev->ops->common->simd_handler_clean(edev->cdev, i);
1394 }
1395 }
1396
1397 edev->int_info.used_cnt = 0;
1398}
1399
1400static int qede_req_msix_irqs(struct qede_dev *edev)
1401{
1402 int i, rc;
1403
1404 /* Sanitize number of interrupts == number of prepared RSS queues */
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001405 if (QEDE_QUEUE_CNT(edev) > edev->int_info.msix_cnt) {
Yuval Mintz29502192015-10-26 11:02:29 +02001406 DP_ERR(edev,
1407 "Interrupt mismatch: %d RSS queues > %d MSI-x vectors\n",
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001408 QEDE_QUEUE_CNT(edev), edev->int_info.msix_cnt);
Yuval Mintz29502192015-10-26 11:02:29 +02001409 return -EINVAL;
1410 }
1411
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001412 for (i = 0; i < QEDE_QUEUE_CNT(edev); i++) {
Yuval Mintz29502192015-10-26 11:02:29 +02001413 rc = request_irq(edev->int_info.msix[i].vector,
1414 qede_msix_fp_int, 0, edev->fp_array[i].name,
1415 &edev->fp_array[i]);
1416 if (rc) {
1417 DP_ERR(edev, "Request fp %d irq failed\n", i);
1418 qede_sync_free_irqs(edev);
1419 return rc;
1420 }
1421 DP_VERBOSE(edev, NETIF_MSG_INTR,
1422 "Requested fp irq for %s [entry %d]. Cookie is at %p\n",
1423 edev->fp_array[i].name, i,
1424 &edev->fp_array[i]);
1425 edev->int_info.used_cnt++;
1426 }
1427
1428 return 0;
1429}
1430
1431static void qede_simd_fp_handler(void *cookie)
1432{
1433 struct qede_fastpath *fp = (struct qede_fastpath *)cookie;
1434
1435 napi_schedule_irqoff(&fp->napi);
1436}
1437
1438static int qede_setup_irqs(struct qede_dev *edev)
1439{
1440 int i, rc = 0;
1441
1442 /* Learn Interrupt configuration */
1443 rc = edev->ops->common->get_fp_int(edev->cdev, &edev->int_info);
1444 if (rc)
1445 return rc;
1446
1447 if (edev->int_info.msix_cnt) {
1448 rc = qede_req_msix_irqs(edev);
1449 if (rc)
1450 return rc;
1451 edev->ndev->irq = edev->int_info.msix[0].vector;
1452 } else {
1453 const struct qed_common_ops *ops;
1454
1455 /* qed should learn receive the RSS ids and callbacks */
1456 ops = edev->ops->common;
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001457 for (i = 0; i < QEDE_QUEUE_CNT(edev); i++)
Yuval Mintz29502192015-10-26 11:02:29 +02001458 ops->simd_handler_config(edev->cdev,
1459 &edev->fp_array[i], i,
1460 qede_simd_fp_handler);
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001461 edev->int_info.used_cnt = QEDE_QUEUE_CNT(edev);
Yuval Mintz29502192015-10-26 11:02:29 +02001462 }
1463 return 0;
1464}
1465
1466static int qede_drain_txq(struct qede_dev *edev,
Yuval Mintz1a635e42016-08-15 10:42:43 +03001467 struct qede_tx_queue *txq, bool allow_drain)
Yuval Mintz29502192015-10-26 11:02:29 +02001468{
1469 int rc, cnt = 1000;
1470
1471 while (txq->sw_tx_cons != txq->sw_tx_prod) {
1472 if (!cnt) {
1473 if (allow_drain) {
1474 DP_NOTICE(edev,
1475 "Tx queue[%d] is stuck, requesting MCP to drain\n",
1476 txq->index);
1477 rc = edev->ops->common->drain(edev->cdev);
1478 if (rc)
1479 return rc;
1480 return qede_drain_txq(edev, txq, false);
1481 }
1482 DP_NOTICE(edev,
1483 "Timeout waiting for tx queue[%d]: PROD=%d, CONS=%d\n",
1484 txq->index, txq->sw_tx_prod,
1485 txq->sw_tx_cons);
1486 return -ENODEV;
1487 }
1488 cnt--;
1489 usleep_range(1000, 2000);
1490 barrier();
1491 }
1492
1493 /* FW finished processing, wait for HW to transmit all tx packets */
1494 usleep_range(1000, 2000);
1495
1496 return 0;
1497}
1498
Mintz, Yuval3da7a372016-11-29 16:47:06 +02001499static int qede_stop_txq(struct qede_dev *edev,
1500 struct qede_tx_queue *txq, int rss_id)
1501{
1502 return edev->ops->q_tx_stop(edev->cdev, rss_id, txq->handle);
1503}
1504
Yuval Mintz29502192015-10-26 11:02:29 +02001505static int qede_stop_queues(struct qede_dev *edev)
1506{
1507 struct qed_update_vport_params vport_update_params;
1508 struct qed_dev *cdev = edev->cdev;
Mintz, Yuval80439a12016-11-29 16:47:02 +02001509 struct qede_fastpath *fp;
1510 int rc, i;
Yuval Mintz29502192015-10-26 11:02:29 +02001511
1512 /* Disable the vport */
1513 memset(&vport_update_params, 0, sizeof(vport_update_params));
1514 vport_update_params.vport_id = 0;
1515 vport_update_params.update_vport_active_flg = 1;
1516 vport_update_params.vport_active_flg = 0;
1517 vport_update_params.update_rss_flg = 0;
1518
1519 rc = edev->ops->vport_update(cdev, &vport_update_params);
1520 if (rc) {
1521 DP_ERR(edev, "Failed to update vport\n");
1522 return rc;
1523 }
1524
1525 /* Flush Tx queues. If needed, request drain from MCP */
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001526 for_each_queue(i) {
Mintz, Yuval80439a12016-11-29 16:47:02 +02001527 fp = &edev->fp_array[i];
Yuval Mintz29502192015-10-26 11:02:29 +02001528
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001529 if (fp->type & QEDE_FASTPATH_TX) {
Mintz, Yuval80439a12016-11-29 16:47:02 +02001530 rc = qede_drain_txq(edev, fp->txq, true);
1531 if (rc)
1532 return rc;
Yuval Mintz29502192015-10-26 11:02:29 +02001533 }
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001534
1535 if (fp->type & QEDE_FASTPATH_XDP) {
1536 rc = qede_drain_txq(edev, fp->xdp_tx, true);
1537 if (rc)
1538 return rc;
1539 }
Yuval Mintz29502192015-10-26 11:02:29 +02001540 }
1541
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001542 /* Stop all Queues in reverse order */
1543 for (i = QEDE_QUEUE_CNT(edev) - 1; i >= 0; i--) {
Mintz, Yuval80439a12016-11-29 16:47:02 +02001544 fp = &edev->fp_array[i];
Yuval Mintz29502192015-10-26 11:02:29 +02001545
Mintz, Yuval80439a12016-11-29 16:47:02 +02001546 /* Stop the Tx Queue(s) */
1547 if (fp->type & QEDE_FASTPATH_TX) {
Mintz, Yuval3da7a372016-11-29 16:47:06 +02001548 rc = qede_stop_txq(edev, fp->txq, i);
1549 if (rc)
1550 return rc;
Yuval Mintz29502192015-10-26 11:02:29 +02001551 }
1552
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001553 /* Stop the Rx Queue */
Mintz, Yuval80439a12016-11-29 16:47:02 +02001554 if (fp->type & QEDE_FASTPATH_RX) {
Mintz, Yuval3da7a372016-11-29 16:47:06 +02001555 rc = edev->ops->q_rx_stop(cdev, i, fp->rxq->handle);
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001556 if (rc) {
1557 DP_ERR(edev, "Failed to stop RXQ #%d\n", i);
1558 return rc;
1559 }
Yuval Mintz29502192015-10-26 11:02:29 +02001560 }
Mintz, Yuval496e0512016-11-29 16:47:09 +02001561
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001562 /* Stop the XDP forwarding queue */
1563 if (fp->type & QEDE_FASTPATH_XDP) {
1564 rc = qede_stop_txq(edev, fp->xdp_tx, i);
1565 if (rc)
1566 return rc;
1567
Mintz, Yuval496e0512016-11-29 16:47:09 +02001568 bpf_prog_put(fp->rxq->xdp_prog);
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001569 }
Yuval Mintz29502192015-10-26 11:02:29 +02001570 }
1571
1572 /* Stop the vport */
1573 rc = edev->ops->vport_stop(cdev, 0);
1574 if (rc)
1575 DP_ERR(edev, "Failed to stop VPORT\n");
1576
1577 return rc;
1578}
1579
Mintz, Yuval3da7a372016-11-29 16:47:06 +02001580static int qede_start_txq(struct qede_dev *edev,
1581 struct qede_fastpath *fp,
1582 struct qede_tx_queue *txq, u8 rss_id, u16 sb_idx)
1583{
1584 dma_addr_t phys_table = qed_chain_get_pbl_phys(&txq->tx_pbl);
1585 u32 page_cnt = qed_chain_get_page_cnt(&txq->tx_pbl);
1586 struct qed_queue_start_common_params params;
1587 struct qed_txq_start_ret_params ret_params;
1588 int rc;
1589
1590 memset(&params, 0, sizeof(params));
1591 memset(&ret_params, 0, sizeof(ret_params));
1592
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001593 /* Let the XDP queue share the queue-zone with one of the regular txq.
1594 * We don't really care about its coalescing.
1595 */
1596 if (txq->is_xdp)
1597 params.queue_id = QEDE_TXQ_XDP_TO_IDX(edev, txq);
1598 else
1599 params.queue_id = txq->index;
1600
Mintz, Yuval3da7a372016-11-29 16:47:06 +02001601 params.sb = fp->sb_info->igu_sb_id;
1602 params.sb_idx = sb_idx;
1603
1604 rc = edev->ops->q_tx_start(edev->cdev, rss_id, &params, phys_table,
1605 page_cnt, &ret_params);
1606 if (rc) {
1607 DP_ERR(edev, "Start TXQ #%d failed %d\n", txq->index, rc);
1608 return rc;
1609 }
1610
1611 txq->doorbell_addr = ret_params.p_doorbell;
1612 txq->handle = ret_params.p_handle;
1613
1614 /* Determine the FW consumer address associated */
1615 txq->hw_cons_ptr = &fp->sb_info->sb_virt->pi_array[sb_idx];
1616
1617 /* Prepare the doorbell parameters */
1618 SET_FIELD(txq->tx_db.data.params, ETH_DB_DATA_DEST, DB_DEST_XCM);
1619 SET_FIELD(txq->tx_db.data.params, ETH_DB_DATA_AGG_CMD, DB_AGG_CMD_SET);
1620 SET_FIELD(txq->tx_db.data.params, ETH_DB_DATA_AGG_VAL_SEL,
1621 DQ_XCM_ETH_TX_BD_PROD_CMD);
1622 txq->tx_db.data.agg_flags = DQ_XCM_ETH_DQ_CF_CMD;
1623
1624 return rc;
1625}
1626
Yuval Mintza0d26d52016-06-19 15:18:13 +03001627static int qede_start_queues(struct qede_dev *edev, bool clear_stats)
Yuval Mintz29502192015-10-26 11:02:29 +02001628{
Manish Chopra088c8612016-03-04 12:35:05 -05001629 int vlan_removal_en = 1;
Yuval Mintz29502192015-10-26 11:02:29 +02001630 struct qed_dev *cdev = edev->cdev;
Yuval Mintz29502192015-10-26 11:02:29 +02001631 struct qed_update_vport_params vport_update_params;
1632 struct qed_queue_start_common_params q_params;
Yuval Mintzfefb0202016-05-11 16:36:19 +03001633 struct qed_dev_info *qed_info = &edev->dev_info.common;
Manish Chopra088c8612016-03-04 12:35:05 -05001634 struct qed_start_vport_params start = {0};
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001635 bool reset_rss_indir = false;
Mintz, Yuval80439a12016-11-29 16:47:02 +02001636 int rc, i;
Yuval Mintz29502192015-10-26 11:02:29 +02001637
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001638 if (!edev->num_queues) {
Yuval Mintz29502192015-10-26 11:02:29 +02001639 DP_ERR(edev,
1640 "Cannot update V-VPORT as active as there are no Rx queues\n");
1641 return -EINVAL;
1642 }
1643
Manish Chopra55482ed2016-03-04 12:35:06 -05001644 start.gro_enable = !edev->gro_disable;
Manish Chopra088c8612016-03-04 12:35:05 -05001645 start.mtu = edev->ndev->mtu;
1646 start.vport_id = 0;
1647 start.drop_ttl0 = true;
1648 start.remove_inner_vlan = vlan_removal_en;
Yuval Mintz7f7a1442016-07-27 14:45:22 +03001649 start.clear_stats = clear_stats;
Manish Chopra088c8612016-03-04 12:35:05 -05001650
1651 rc = edev->ops->vport_start(cdev, &start);
Yuval Mintz29502192015-10-26 11:02:29 +02001652
1653 if (rc) {
1654 DP_ERR(edev, "Start V-PORT failed %d\n", rc);
1655 return rc;
1656 }
1657
1658 DP_VERBOSE(edev, NETIF_MSG_IFUP,
1659 "Start vport ramrod passed, vport_id = %d, MTU = %d, vlan_removal_en = %d\n",
Manish Chopra088c8612016-03-04 12:35:05 -05001660 start.vport_id, edev->ndev->mtu + 0xe, vlan_removal_en);
Yuval Mintz29502192015-10-26 11:02:29 +02001661
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001662 for_each_queue(i) {
Yuval Mintz29502192015-10-26 11:02:29 +02001663 struct qede_fastpath *fp = &edev->fp_array[i];
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001664 dma_addr_t p_phys_table;
1665 u32 page_cnt;
Yuval Mintz29502192015-10-26 11:02:29 +02001666
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001667 if (fp->type & QEDE_FASTPATH_RX) {
Mintz, Yuval3da7a372016-11-29 16:47:06 +02001668 struct qed_rxq_start_ret_params ret_params;
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001669 struct qede_rx_queue *rxq = fp->rxq;
1670 __le16 *val;
Yuval Mintz29502192015-10-26 11:02:29 +02001671
Mintz, Yuval3da7a372016-11-29 16:47:06 +02001672 memset(&ret_params, 0, sizeof(ret_params));
Yuval Mintz29502192015-10-26 11:02:29 +02001673 memset(&q_params, 0, sizeof(q_params));
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001674 q_params.queue_id = rxq->rxq_id;
1675 q_params.vport_id = 0;
1676 q_params.sb = fp->sb_info->igu_sb_id;
1677 q_params.sb_idx = RX_PI;
1678
1679 p_phys_table =
1680 qed_chain_get_pbl_phys(&rxq->rx_comp_ring);
1681 page_cnt = qed_chain_get_page_cnt(&rxq->rx_comp_ring);
1682
Mintz, Yuval3da7a372016-11-29 16:47:06 +02001683 rc = edev->ops->q_rx_start(cdev, i, &q_params,
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001684 rxq->rx_buf_size,
1685 rxq->rx_bd_ring.p_phys_addr,
1686 p_phys_table,
Mintz, Yuval3da7a372016-11-29 16:47:06 +02001687 page_cnt, &ret_params);
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001688 if (rc) {
1689 DP_ERR(edev, "Start RXQ #%d failed %d\n", i,
1690 rc);
1691 return rc;
1692 }
1693
Mintz, Yuval3da7a372016-11-29 16:47:06 +02001694 /* Use the return parameters */
1695 rxq->hw_rxq_prod_addr = ret_params.p_prod;
1696 rxq->handle = ret_params.p_handle;
1697
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001698 val = &fp->sb_info->sb_virt->pi_array[RX_PI];
1699 rxq->hw_cons_ptr = val;
1700
1701 qede_update_rx_prod(edev, rxq);
1702 }
1703
Mintz, Yuval496e0512016-11-29 16:47:09 +02001704 if (fp->type & QEDE_FASTPATH_XDP) {
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001705 rc = qede_start_txq(edev, fp, fp->xdp_tx, i, XDP_PI);
1706 if (rc)
1707 return rc;
1708
Mintz, Yuval496e0512016-11-29 16:47:09 +02001709 fp->rxq->xdp_prog = bpf_prog_add(edev->xdp_prog, 1);
1710 if (IS_ERR(fp->rxq->xdp_prog)) {
1711 rc = PTR_ERR(fp->rxq->xdp_prog);
1712 fp->rxq->xdp_prog = NULL;
1713 return rc;
1714 }
1715 }
1716
Mintz, Yuval80439a12016-11-29 16:47:02 +02001717 if (fp->type & QEDE_FASTPATH_TX) {
Mintz, Yuval3da7a372016-11-29 16:47:06 +02001718 rc = qede_start_txq(edev, fp, fp->txq, i, TX_PI(0));
1719 if (rc)
Yuval Mintz29502192015-10-26 11:02:29 +02001720 return rc;
Yuval Mintz29502192015-10-26 11:02:29 +02001721 }
1722 }
1723
1724 /* Prepare and send the vport enable */
1725 memset(&vport_update_params, 0, sizeof(vport_update_params));
Manish Chopra088c8612016-03-04 12:35:05 -05001726 vport_update_params.vport_id = start.vport_id;
Yuval Mintz29502192015-10-26 11:02:29 +02001727 vport_update_params.update_vport_active_flg = 1;
1728 vport_update_params.vport_active_flg = 1;
1729
Yuval Mintz831bfb0e2016-05-11 16:36:25 +03001730 if ((qed_info->mf_mode == QED_MF_NPAR || pci_num_vf(edev->pdev)) &&
1731 qed_info->tx_switching) {
1732 vport_update_params.update_tx_switching_flg = 1;
1733 vport_update_params.tx_switching_flg = 1;
1734 }
1735
Yuval Mintz29502192015-10-26 11:02:29 +02001736 /* Fill struct with RSS params */
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001737 if (QEDE_RSS_COUNT(edev) > 1) {
Yuval Mintz29502192015-10-26 11:02:29 +02001738 vport_update_params.update_rss_flg = 1;
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001739
1740 /* Need to validate current RSS config uses valid entries */
1741 for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++) {
1742 if (edev->rss_params.rss_ind_table[i] >=
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001743 QEDE_RSS_COUNT(edev)) {
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001744 reset_rss_indir = true;
1745 break;
1746 }
1747 }
1748
1749 if (!(edev->rss_params_inited & QEDE_RSS_INDIR_INITED) ||
1750 reset_rss_indir) {
1751 u16 val;
1752
1753 for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++) {
1754 u16 indir_val;
1755
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001756 val = QEDE_RSS_COUNT(edev);
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001757 indir_val = ethtool_rxfh_indir_default(i, val);
1758 edev->rss_params.rss_ind_table[i] = indir_val;
1759 }
1760 edev->rss_params_inited |= QEDE_RSS_INDIR_INITED;
1761 }
1762
1763 if (!(edev->rss_params_inited & QEDE_RSS_KEY_INITED)) {
1764 netdev_rss_key_fill(edev->rss_params.rss_key,
1765 sizeof(edev->rss_params.rss_key));
1766 edev->rss_params_inited |= QEDE_RSS_KEY_INITED;
1767 }
1768
1769 if (!(edev->rss_params_inited & QEDE_RSS_CAPS_INITED)) {
1770 edev->rss_params.rss_caps = QED_RSS_IPV4 |
1771 QED_RSS_IPV6 |
1772 QED_RSS_IPV4_TCP |
1773 QED_RSS_IPV6_TCP;
1774 edev->rss_params_inited |= QEDE_RSS_CAPS_INITED;
1775 }
1776
1777 memcpy(&vport_update_params.rss_params, &edev->rss_params,
1778 sizeof(vport_update_params.rss_params));
Yuval Mintz29502192015-10-26 11:02:29 +02001779 } else {
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001780 memset(&vport_update_params.rss_params, 0,
1781 sizeof(vport_update_params.rss_params));
Yuval Mintz29502192015-10-26 11:02:29 +02001782 }
Yuval Mintz29502192015-10-26 11:02:29 +02001783
1784 rc = edev->ops->vport_update(cdev, &vport_update_params);
1785 if (rc) {
1786 DP_ERR(edev, "Update V-PORT failed %d\n", rc);
1787 return rc;
1788 }
1789
1790 return 0;
1791}
1792
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +02001793
Yuval Mintz29502192015-10-26 11:02:29 +02001794enum qede_unload_mode {
1795 QEDE_UNLOAD_NORMAL,
1796};
1797
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001798static void qede_unload(struct qede_dev *edev, enum qede_unload_mode mode,
1799 bool is_locked)
Yuval Mintz29502192015-10-26 11:02:29 +02001800{
Sudarsana Kallurua2ec6172015-10-26 11:02:32 +02001801 struct qed_link_params link_params;
Yuval Mintz29502192015-10-26 11:02:29 +02001802 int rc;
1803
1804 DP_INFO(edev, "Starting qede unload\n");
1805
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001806 if (!is_locked)
1807 __qede_lock(edev);
1808
Ram Amranicee9fbd2016-10-01 21:59:56 +03001809 qede_roce_dev_event_close(edev);
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +02001810 edev->state = QEDE_STATE_CLOSED;
1811
Yuval Mintz29502192015-10-26 11:02:29 +02001812 /* Close OS Tx */
1813 netif_tx_disable(edev->ndev);
1814 netif_carrier_off(edev->ndev);
1815
Sudarsana Kallurua2ec6172015-10-26 11:02:32 +02001816 /* Reset the link */
1817 memset(&link_params, 0, sizeof(link_params));
1818 link_params.link_up = false;
1819 edev->ops->common->set_link(edev->cdev, &link_params);
Yuval Mintz29502192015-10-26 11:02:29 +02001820 rc = qede_stop_queues(edev);
1821 if (rc) {
1822 qede_sync_free_irqs(edev);
1823 goto out;
1824 }
1825
1826 DP_INFO(edev, "Stopped Queues\n");
1827
Sudarsana Reddy Kalluru7c1bfca2016-02-18 17:00:40 +02001828 qede_vlan_mark_nonconfigured(edev);
Yuval Mintz29502192015-10-26 11:02:29 +02001829 edev->ops->fastpath_stop(edev->cdev);
1830
1831 /* Release the interrupts */
1832 qede_sync_free_irqs(edev);
1833 edev->ops->common->set_fp_int(edev->cdev, 0);
1834
1835 qede_napi_disable_remove(edev);
1836
1837 qede_free_mem_load(edev);
1838 qede_free_fp_array(edev);
1839
1840out:
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001841 if (!is_locked)
1842 __qede_unlock(edev);
Yuval Mintz29502192015-10-26 11:02:29 +02001843 DP_INFO(edev, "Ending qede unload\n");
1844}
1845
1846enum qede_load_mode {
1847 QEDE_LOAD_NORMAL,
Yuval Mintza0d26d52016-06-19 15:18:13 +03001848 QEDE_LOAD_RELOAD,
Yuval Mintz29502192015-10-26 11:02:29 +02001849};
1850
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001851static int qede_load(struct qede_dev *edev, enum qede_load_mode mode,
1852 bool is_locked)
Yuval Mintz29502192015-10-26 11:02:29 +02001853{
Sudarsana Kallurua2ec6172015-10-26 11:02:32 +02001854 struct qed_link_params link_params;
1855 struct qed_link_output link_output;
Yuval Mintz29502192015-10-26 11:02:29 +02001856 int rc;
1857
1858 DP_INFO(edev, "Starting qede load\n");
1859
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001860 if (!is_locked)
1861 __qede_lock(edev);
1862
Yuval Mintz29502192015-10-26 11:02:29 +02001863 rc = qede_set_num_queues(edev);
1864 if (rc)
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001865 goto out;
Yuval Mintz29502192015-10-26 11:02:29 +02001866
1867 rc = qede_alloc_fp_array(edev);
1868 if (rc)
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001869 goto out;
Yuval Mintz29502192015-10-26 11:02:29 +02001870
1871 qede_init_fp(edev);
1872
1873 rc = qede_alloc_mem_load(edev);
1874 if (rc)
1875 goto err1;
Mintz, Yuval80439a12016-11-29 16:47:02 +02001876 DP_INFO(edev, "Allocated %d Rx, %d Tx queues\n",
1877 QEDE_RSS_COUNT(edev), QEDE_TSS_COUNT(edev));
Yuval Mintz29502192015-10-26 11:02:29 +02001878
1879 rc = qede_set_real_num_queues(edev);
1880 if (rc)
1881 goto err2;
1882
1883 qede_napi_add_enable(edev);
1884 DP_INFO(edev, "Napi added and enabled\n");
1885
1886 rc = qede_setup_irqs(edev);
1887 if (rc)
1888 goto err3;
1889 DP_INFO(edev, "Setup IRQs succeeded\n");
1890
Yuval Mintza0d26d52016-06-19 15:18:13 +03001891 rc = qede_start_queues(edev, mode != QEDE_LOAD_RELOAD);
Yuval Mintz29502192015-10-26 11:02:29 +02001892 if (rc)
1893 goto err4;
1894 DP_INFO(edev, "Start VPORT, RXQ and TXQ succeeded\n");
1895
1896 /* Add primary mac and set Rx filters */
1897 ether_addr_copy(edev->primary_mac, edev->ndev->dev_addr);
1898
Sudarsana Reddy Kalluru7c1bfca2016-02-18 17:00:40 +02001899 /* Program un-configured VLANs */
1900 qede_configure_vlan_filters(edev);
1901
Sudarsana Kallurua2ec6172015-10-26 11:02:32 +02001902 /* Ask for link-up using current configuration */
1903 memset(&link_params, 0, sizeof(link_params));
1904 link_params.link_up = true;
1905 edev->ops->common->set_link(edev->cdev, &link_params);
1906
1907 /* Query whether link is already-up */
1908 memset(&link_output, 0, sizeof(link_output));
1909 edev->ops->common->get_link(edev->cdev, &link_output);
Ram Amranicee9fbd2016-10-01 21:59:56 +03001910 qede_roce_dev_event_open(edev);
Sudarsana Kallurua2ec6172015-10-26 11:02:32 +02001911 qede_link_update(edev, &link_output);
1912
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001913 edev->state = QEDE_STATE_OPEN;
1914
Yuval Mintz29502192015-10-26 11:02:29 +02001915 DP_INFO(edev, "Ending successfully qede load\n");
1916
Yuval Mintz29502192015-10-26 11:02:29 +02001917
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001918 goto out;
Yuval Mintz29502192015-10-26 11:02:29 +02001919err4:
1920 qede_sync_free_irqs(edev);
1921 memset(&edev->int_info.msix_cnt, 0, sizeof(struct qed_int_info));
1922err3:
1923 qede_napi_disable_remove(edev);
1924err2:
1925 qede_free_mem_load(edev);
1926err1:
1927 edev->ops->common->set_fp_int(edev->cdev, 0);
1928 qede_free_fp_array(edev);
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001929 edev->num_queues = 0;
1930 edev->fp_num_tx = 0;
1931 edev->fp_num_rx = 0;
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001932out:
1933 if (!is_locked)
1934 __qede_unlock(edev);
1935
Yuval Mintz29502192015-10-26 11:02:29 +02001936 return rc;
1937}
1938
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001939/* 'func' should be able to run between unload and reload assuming interface
1940 * is actually running, or afterwards in case it's currently DOWN.
1941 */
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001942void qede_reload(struct qede_dev *edev,
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001943 struct qede_reload_args *args, bool is_locked)
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001944{
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001945 if (!is_locked)
1946 __qede_lock(edev);
1947
1948 /* Since qede_lock is held, internal state wouldn't change even
1949 * if netdev state would start transitioning. Check whether current
1950 * internal configuration indicates device is up, then reload.
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001951 */
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001952 if (edev->state == QEDE_STATE_OPEN) {
1953 qede_unload(edev, QEDE_UNLOAD_NORMAL, true);
1954 if (args)
1955 args->func(edev, args);
1956 qede_load(edev, QEDE_LOAD_RELOAD, true);
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001957
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001958 /* Since no one is going to do it for us, re-configure */
1959 qede_config_rx_mode(edev->ndev);
1960 } else if (args) {
1961 args->func(edev, args);
1962 }
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001963
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001964 if (!is_locked)
1965 __qede_unlock(edev);
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001966}
1967
Yuval Mintz29502192015-10-26 11:02:29 +02001968/* called with rtnl_lock */
1969static int qede_open(struct net_device *ndev)
1970{
1971 struct qede_dev *edev = netdev_priv(ndev);
Manish Choprab18e1702016-04-14 01:38:30 -04001972 int rc;
Yuval Mintz29502192015-10-26 11:02:29 +02001973
1974 netif_carrier_off(ndev);
1975
1976 edev->ops->common->set_power_state(edev->cdev, PCI_D0);
1977
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001978 rc = qede_load(edev, QEDE_LOAD_NORMAL, false);
Manish Choprab18e1702016-04-14 01:38:30 -04001979 if (rc)
1980 return rc;
1981
Alexander Duyckf9f082a2016-06-16 12:22:57 -07001982 udp_tunnel_get_rx_info(ndev);
1983
Sudarsana Kalluru0fefbfb2016-10-31 07:14:21 +02001984 edev->ops->common->update_drv_state(edev->cdev, true);
1985
Manish Choprab18e1702016-04-14 01:38:30 -04001986 return 0;
Yuval Mintz29502192015-10-26 11:02:29 +02001987}
1988
1989static int qede_close(struct net_device *ndev)
1990{
1991 struct qede_dev *edev = netdev_priv(ndev);
1992
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001993 qede_unload(edev, QEDE_UNLOAD_NORMAL, false);
Yuval Mintz29502192015-10-26 11:02:29 +02001994
Sudarsana Kalluru0fefbfb2016-10-31 07:14:21 +02001995 edev->ops->common->update_drv_state(edev->cdev, false);
1996
Yuval Mintz29502192015-10-26 11:02:29 +02001997 return 0;
1998}
Sudarsana Kalluru0d8e0aa2015-10-26 11:02:30 +02001999
Sudarsana Kallurua2ec6172015-10-26 11:02:32 +02002000static void qede_link_update(void *dev, struct qed_link_output *link)
2001{
2002 struct qede_dev *edev = dev;
2003
2004 if (!netif_running(edev->ndev)) {
2005 DP_VERBOSE(edev, NETIF_MSG_LINK, "Interface is not running\n");
2006 return;
2007 }
2008
2009 if (link->link_up) {
Yuval Mintz8e025ae2016-02-24 16:52:47 +02002010 if (!netif_carrier_ok(edev->ndev)) {
2011 DP_NOTICE(edev, "Link is up\n");
2012 netif_tx_start_all_queues(edev->ndev);
2013 netif_carrier_on(edev->ndev);
2014 }
Sudarsana Kallurua2ec6172015-10-26 11:02:32 +02002015 } else {
Yuval Mintz8e025ae2016-02-24 16:52:47 +02002016 if (netif_carrier_ok(edev->ndev)) {
2017 DP_NOTICE(edev, "Link is down\n");
2018 netif_tx_disable(edev->ndev);
2019 netif_carrier_off(edev->ndev);
2020 }
Sudarsana Kallurua2ec6172015-10-26 11:02:32 +02002021 }
2022}