1 /* QLogic qede NIC Driver
2 * Copyright (c) 2015 QLogic Corporation
4 * This software is available under the terms of the GNU General Public License
5 * (GPL) Version 2, available from the file COPYING in the main directory of
9 #include <linux/module.h>
10 #include <linux/pci.h>
11 #include <linux/version.h>
12 #include <linux/device.h>
13 #include <linux/netdevice.h>
14 #include <linux/etherdevice.h>
15 #include <linux/skbuff.h>
16 #include <linux/errno.h>
17 #include <linux/list.h>
18 #include <linux/string.h>
19 #include <linux/dma-mapping.h>
20 #include <linux/interrupt.h>
21 #include <asm/byteorder.h>
22 #include <asm/param.h>
24 #include <linux/netdev_features.h>
25 #include <linux/udp.h>
26 #include <linux/tcp.h>
27 #include <net/vxlan.h>
31 #include <linux/if_ether.h>
32 #include <linux/if_vlan.h>
33 #include <linux/pkt_sched.h>
34 #include <linux/ethtool.h>
36 #include <linux/random.h>
37 #include <net/ip6_checksum.h>
38 #include <linux/bitops.h>
42 static const char version[] = "QLogic QL4xxx 40G/100G Ethernet Driver qede "
43 DRV_MODULE_VERSION "\n";
45 MODULE_DESCRIPTION("QLogic 40G/100G Ethernet Driver");
46 MODULE_LICENSE("GPL");
47 MODULE_VERSION(DRV_MODULE_VERSION);
50 module_param(debug, uint, 0);
51 MODULE_PARM_DESC(debug, " Default debug msglevel");
53 static const struct qed_eth_ops *qed_ops;
55 #define CHIP_NUM_57980S_40 0x1634
56 #define CHIP_NUM_57980S_10 0x1635
57 #define CHIP_NUM_57980S_MF 0x1636
58 #define CHIP_NUM_57980S_100 0x1644
59 #define CHIP_NUM_57980S_50 0x1654
60 #define CHIP_NUM_57980S_25 0x1656
62 #ifndef PCI_DEVICE_ID_NX2_57980E
63 #define PCI_DEVICE_ID_57980S_40 CHIP_NUM_57980S_40
64 #define PCI_DEVICE_ID_57980S_10 CHIP_NUM_57980S_10
65 #define PCI_DEVICE_ID_57980S_MF CHIP_NUM_57980S_MF
66 #define PCI_DEVICE_ID_57980S_100 CHIP_NUM_57980S_100
67 #define PCI_DEVICE_ID_57980S_50 CHIP_NUM_57980S_50
68 #define PCI_DEVICE_ID_57980S_25 CHIP_NUM_57980S_25
71 static const struct pci_device_id qede_pci_tbl[] = {
72 { PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_57980S_40), 0 },
73 { PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_57980S_10), 0 },
74 { PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_57980S_MF), 0 },
75 { PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_57980S_100), 0 },
76 { PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_57980S_50), 0 },
77 { PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_57980S_25), 0 },
81 MODULE_DEVICE_TABLE(pci, qede_pci_tbl);
83 static int qede_probe(struct pci_dev *pdev, const struct pci_device_id *id);
85 #define TX_TIMEOUT (5 * HZ)
87 static void qede_remove(struct pci_dev *pdev);
89 static struct pci_driver qede_pci_driver = {
91 .id_table = qede_pci_tbl,
93 .remove = qede_remove,
97 int __init qede_init(void)
102 pr_notice("qede_init: %s\n", version);
104 qed_ver = qed_get_protocol_version(QED_PROTOCOL_ETH);
105 if (qed_ver != QEDE_ETH_INTERFACE_VERSION) {
106 pr_notice("Version mismatch [%08x != %08x]\n",
108 QEDE_ETH_INTERFACE_VERSION);
112 qed_ops = qed_get_eth_ops(QEDE_ETH_INTERFACE_VERSION);
114 pr_notice("Failed to get qed ethtool operations\n");
118 ret = pci_register_driver(&qede_pci_driver);
120 pr_notice("Failed to register driver\n");
128 static void __exit qede_cleanup(void)
130 pr_notice("qede_cleanup called\n");
132 pci_unregister_driver(&qede_pci_driver);
136 module_init(qede_init);
137 module_exit(qede_cleanup);
139 /* -------------------------------------------------------------------------
140 * START OF PROBE / REMOVE
141 * -------------------------------------------------------------------------
144 static struct qede_dev *qede_alloc_etherdev(struct qed_dev *cdev,
145 struct pci_dev *pdev,
146 struct qed_dev_eth_info *info,
150 struct net_device *ndev;
151 struct qede_dev *edev;
153 ndev = alloc_etherdev_mqs(sizeof(*edev),
157 pr_err("etherdev allocation failed\n");
161 edev = netdev_priv(ndev);
165 edev->dp_module = dp_module;
166 edev->dp_level = dp_level;
169 DP_INFO(edev, "Allocated netdev with 64 tx queues and 64 rx queues\n");
171 SET_NETDEV_DEV(ndev, &pdev->dev);
173 memcpy(&edev->dev_info, info, sizeof(*info));
175 edev->num_tc = edev->dev_info.num_tc;
180 static void qede_init_ndev(struct qede_dev *edev)
182 struct net_device *ndev = edev->ndev;
183 struct pci_dev *pdev = edev->pdev;
186 pci_set_drvdata(pdev, ndev);
188 ndev->mem_start = edev->dev_info.common.pci_mem_start;
189 ndev->base_addr = ndev->mem_start;
190 ndev->mem_end = edev->dev_info.common.pci_mem_end;
191 ndev->irq = edev->dev_info.common.pci_irq;
193 ndev->watchdog_timeo = TX_TIMEOUT;
195 /* user-changeble features */
196 hw_features = NETIF_F_GRO | NETIF_F_SG |
197 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
198 NETIF_F_TSO | NETIF_F_TSO6;
200 ndev->vlan_features = hw_features | NETIF_F_RXHASH | NETIF_F_RXCSUM |
202 ndev->features = hw_features | NETIF_F_RXHASH | NETIF_F_RXCSUM |
203 NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HIGHDMA |
204 NETIF_F_HW_VLAN_CTAG_TX;
206 ndev->hw_features = hw_features;
208 /* Set network device HW mac */
209 ether_addr_copy(edev->ndev->dev_addr, edev->dev_info.common.hw_mac);
212 /* This function converts from 32b param to two params of level and module
213 * Input 32b decoding:
214 * b31 - enable all NOTICE prints. NOTICE prints are for deviation from the
215 * 'happy' flow, e.g. memory allocation failed.
216 * b30 - enable all INFO prints. INFO prints are for major steps in the flow
217 * and provide important parameters.
218 * b29-b0 - per-module bitmap, where each bit enables VERBOSE prints of that
219 * module. VERBOSE prints are for tracking the specific flow in low level.
221 * Notice that the level should be that of the lowest required logs.
223 static void qede_config_debug(uint debug, u32 *p_dp_module, u8 *p_dp_level)
225 *p_dp_level = QED_LEVEL_NOTICE;
228 if (debug & QED_LOG_VERBOSE_MASK) {
229 *p_dp_level = QED_LEVEL_VERBOSE;
230 *p_dp_module = (debug & 0x3FFFFFFF);
231 } else if (debug & QED_LOG_INFO_MASK) {
232 *p_dp_level = QED_LEVEL_INFO;
233 } else if (debug & QED_LOG_NOTICE_MASK) {
234 *p_dp_level = QED_LEVEL_NOTICE;
238 static void qede_update_pf_params(struct qed_dev *cdev)
240 struct qed_pf_params pf_params;
243 memset(&pf_params, 0, sizeof(struct qed_pf_params));
244 pf_params.eth_pf_params.num_cons = 32;
245 qed_ops->common->update_pf_params(cdev, &pf_params);
248 enum qede_probe_mode {
252 static int __qede_probe(struct pci_dev *pdev, u32 dp_module, u8 dp_level,
253 enum qede_probe_mode mode)
255 struct qed_slowpath_params params;
256 struct qed_dev_eth_info dev_info;
257 struct qede_dev *edev;
258 struct qed_dev *cdev;
261 if (unlikely(dp_level & QED_LEVEL_INFO))
262 pr_notice("Starting qede probe\n");
264 cdev = qed_ops->common->probe(pdev, QED_PROTOCOL_ETH,
265 dp_module, dp_level);
271 qede_update_pf_params(cdev);
273 /* Start the Slowpath-process */
274 memset(¶ms, 0, sizeof(struct qed_slowpath_params));
275 params.int_mode = QED_INT_MODE_MSIX;
276 params.drv_major = QEDE_MAJOR_VERSION;
277 params.drv_minor = QEDE_MINOR_VERSION;
278 params.drv_rev = QEDE_REVISION_VERSION;
279 params.drv_eng = QEDE_ENGINEERING_VERSION;
280 strlcpy(params.name, "qede LAN", QED_DRV_VER_STR_SIZE);
281 rc = qed_ops->common->slowpath_start(cdev, ¶ms);
283 pr_notice("Cannot start slowpath\n");
287 /* Learn information crucial for qede to progress */
288 rc = qed_ops->fill_dev_info(cdev, &dev_info);
292 edev = qede_alloc_etherdev(cdev, pdev, &dev_info, dp_module,
299 qede_init_ndev(edev);
301 edev->ops->common->set_id(cdev, edev->ndev->name, DRV_MODULE_VERSION);
303 DP_INFO(edev, "Ending successfully qede probe\n");
308 qed_ops->common->slowpath_stop(cdev);
310 qed_ops->common->remove(cdev);
315 static int qede_probe(struct pci_dev *pdev, const struct pci_device_id *id)
320 qede_config_debug(debug, &dp_module, &dp_level);
322 return __qede_probe(pdev, dp_module, dp_level,
326 enum qede_remove_mode {
330 static void __qede_remove(struct pci_dev *pdev, enum qede_remove_mode mode)
332 struct net_device *ndev = pci_get_drvdata(pdev);
333 struct qede_dev *edev = netdev_priv(ndev);
334 struct qed_dev *cdev = edev->cdev;
336 DP_INFO(edev, "Starting qede_remove\n");
338 edev->ops->common->set_power_state(cdev, PCI_D0);
340 pci_set_drvdata(pdev, NULL);
344 /* Use global ops since we've freed edev */
345 qed_ops->common->slowpath_stop(cdev);
346 qed_ops->common->remove(cdev);
348 pr_notice("Ending successfully qede_remove\n");
351 static void qede_remove(struct pci_dev *pdev)
353 __qede_remove(pdev, QEDE_REMOVE_NORMAL);