Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 1 | /* QLogic qede NIC Driver |
Mintz, Yuval | e8f1cb5 | 2017-01-01 13:57:00 +0200 | [diff] [blame] | 2 | * 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 Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 32 | #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 Duyck | f9f082a | 2016-06-16 12:22:57 -0700 | [diff] [blame] | 50 | #include <net/udp_tunnel.h> |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 51 | #include <linux/ip.h> |
| 52 | #include <net/ipv6.h> |
| 53 | #include <net/tcp.h> |
| 54 | #include <linux/if_ether.h> |
| 55 | #include <linux/if_vlan.h> |
| 56 | #include <linux/pkt_sched.h> |
| 57 | #include <linux/ethtool.h> |
| 58 | #include <linux/in.h> |
| 59 | #include <linux/random.h> |
| 60 | #include <net/ip6_checksum.h> |
| 61 | #include <linux/bitops.h> |
Mintz, Yuval | f29ffdb | 2017-01-01 13:57:07 +0200 | [diff] [blame^] | 62 | #include <linux/vmalloc.h> |
Ram Amrani | cee9fbd | 2016-10-01 21:59:56 +0300 | [diff] [blame] | 63 | #include <linux/qed/qede_roce.h> |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 64 | #include "qede.h" |
| 65 | |
Yuval Mintz | 5abd7e92 | 2016-02-24 16:52:50 +0200 | [diff] [blame] | 66 | static char version[] = |
| 67 | "QLogic FastLinQ 4xxxx Ethernet Driver qede " DRV_MODULE_VERSION "\n"; |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 68 | |
Yuval Mintz | 5abd7e92 | 2016-02-24 16:52:50 +0200 | [diff] [blame] | 69 | MODULE_DESCRIPTION("QLogic FastLinQ 4xxxx Ethernet Driver"); |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 70 | MODULE_LICENSE("GPL"); |
| 71 | MODULE_VERSION(DRV_MODULE_VERSION); |
| 72 | |
| 73 | static uint debug; |
| 74 | module_param(debug, uint, 0); |
| 75 | MODULE_PARM_DESC(debug, " Default debug msglevel"); |
| 76 | |
| 77 | static const struct qed_eth_ops *qed_ops; |
| 78 | |
| 79 | #define CHIP_NUM_57980S_40 0x1634 |
Yuval Mintz | 0e7441d | 2016-02-24 16:52:45 +0200 | [diff] [blame] | 80 | #define CHIP_NUM_57980S_10 0x1666 |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 81 | #define CHIP_NUM_57980S_MF 0x1636 |
| 82 | #define CHIP_NUM_57980S_100 0x1644 |
| 83 | #define CHIP_NUM_57980S_50 0x1654 |
| 84 | #define CHIP_NUM_57980S_25 0x1656 |
Yuval Mintz | fefb020 | 2016-05-11 16:36:19 +0300 | [diff] [blame] | 85 | #define CHIP_NUM_57980S_IOV 0x1664 |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 86 | |
| 87 | #ifndef PCI_DEVICE_ID_NX2_57980E |
| 88 | #define PCI_DEVICE_ID_57980S_40 CHIP_NUM_57980S_40 |
| 89 | #define PCI_DEVICE_ID_57980S_10 CHIP_NUM_57980S_10 |
| 90 | #define PCI_DEVICE_ID_57980S_MF CHIP_NUM_57980S_MF |
| 91 | #define PCI_DEVICE_ID_57980S_100 CHIP_NUM_57980S_100 |
| 92 | #define PCI_DEVICE_ID_57980S_50 CHIP_NUM_57980S_50 |
| 93 | #define PCI_DEVICE_ID_57980S_25 CHIP_NUM_57980S_25 |
Yuval Mintz | fefb020 | 2016-05-11 16:36:19 +0300 | [diff] [blame] | 94 | #define PCI_DEVICE_ID_57980S_IOV CHIP_NUM_57980S_IOV |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 95 | #endif |
| 96 | |
Yuval Mintz | fefb020 | 2016-05-11 16:36:19 +0300 | [diff] [blame] | 97 | enum qede_pci_private { |
| 98 | QEDE_PRIVATE_PF, |
| 99 | QEDE_PRIVATE_VF |
| 100 | }; |
| 101 | |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 102 | static const struct pci_device_id qede_pci_tbl[] = { |
Yuval Mintz | fefb020 | 2016-05-11 16:36:19 +0300 | [diff] [blame] | 103 | {PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_57980S_40), QEDE_PRIVATE_PF}, |
| 104 | {PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_57980S_10), QEDE_PRIVATE_PF}, |
| 105 | {PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_57980S_MF), QEDE_PRIVATE_PF}, |
| 106 | {PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_57980S_100), QEDE_PRIVATE_PF}, |
| 107 | {PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_57980S_50), QEDE_PRIVATE_PF}, |
| 108 | {PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_57980S_25), QEDE_PRIVATE_PF}, |
Arnd Bergmann | 14b84e8 | 2016-06-01 15:29:13 +0200 | [diff] [blame] | 109 | #ifdef CONFIG_QED_SRIOV |
Yuval Mintz | fefb020 | 2016-05-11 16:36:19 +0300 | [diff] [blame] | 110 | {PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_57980S_IOV), QEDE_PRIVATE_VF}, |
Arnd Bergmann | 14b84e8 | 2016-06-01 15:29:13 +0200 | [diff] [blame] | 111 | #endif |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 112 | { 0 } |
| 113 | }; |
| 114 | |
| 115 | MODULE_DEVICE_TABLE(pci, qede_pci_tbl); |
| 116 | |
| 117 | static int qede_probe(struct pci_dev *pdev, const struct pci_device_id *id); |
| 118 | |
| 119 | #define TX_TIMEOUT (5 * HZ) |
| 120 | |
Mintz, Yuval | cb6aeb0 | 2016-11-29 16:47:10 +0200 | [diff] [blame] | 121 | /* Utilize last protocol index for XDP */ |
| 122 | #define XDP_PI 11 |
| 123 | |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 124 | static void qede_remove(struct pci_dev *pdev); |
Mintz, Yuval | 14d3964 | 2016-10-31 07:14:23 +0200 | [diff] [blame] | 125 | static void qede_shutdown(struct pci_dev *pdev); |
Sudarsana Kalluru | a2ec617 | 2015-10-26 11:02:32 +0200 | [diff] [blame] | 126 | static void qede_link_update(void *dev, struct qed_link_output *link); |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 127 | |
Mintz, Yuval | 567b3c1 | 2016-11-29 16:47:05 +0200 | [diff] [blame] | 128 | /* The qede lock is used to protect driver state change and driver flows that |
| 129 | * are not reentrant. |
| 130 | */ |
| 131 | void __qede_lock(struct qede_dev *edev) |
| 132 | { |
| 133 | mutex_lock(&edev->qede_lock); |
| 134 | } |
| 135 | |
| 136 | void __qede_unlock(struct qede_dev *edev) |
| 137 | { |
| 138 | mutex_unlock(&edev->qede_lock); |
| 139 | } |
| 140 | |
Yuval Mintz | fefb020 | 2016-05-11 16:36:19 +0300 | [diff] [blame] | 141 | #ifdef CONFIG_QED_SRIOV |
Moshe Shemesh | 79aab09 | 2016-09-22 12:11:15 +0300 | [diff] [blame] | 142 | static int qede_set_vf_vlan(struct net_device *ndev, int vf, u16 vlan, u8 qos, |
| 143 | __be16 vlan_proto) |
Yuval Mintz | 08feecd | 2016-05-11 16:36:20 +0300 | [diff] [blame] | 144 | { |
| 145 | struct qede_dev *edev = netdev_priv(ndev); |
| 146 | |
| 147 | if (vlan > 4095) { |
| 148 | DP_NOTICE(edev, "Illegal vlan value %d\n", vlan); |
| 149 | return -EINVAL; |
| 150 | } |
| 151 | |
Moshe Shemesh | 79aab09 | 2016-09-22 12:11:15 +0300 | [diff] [blame] | 152 | if (vlan_proto != htons(ETH_P_8021Q)) |
| 153 | return -EPROTONOSUPPORT; |
| 154 | |
Yuval Mintz | 08feecd | 2016-05-11 16:36:20 +0300 | [diff] [blame] | 155 | DP_VERBOSE(edev, QED_MSG_IOV, "Setting Vlan 0x%04x to VF [%d]\n", |
| 156 | vlan, vf); |
| 157 | |
| 158 | return edev->ops->iov->set_vlan(edev->cdev, vlan, vf); |
| 159 | } |
| 160 | |
Yuval Mintz | eff1696 | 2016-05-11 16:36:21 +0300 | [diff] [blame] | 161 | static int qede_set_vf_mac(struct net_device *ndev, int vfidx, u8 *mac) |
| 162 | { |
| 163 | struct qede_dev *edev = netdev_priv(ndev); |
| 164 | |
| 165 | DP_VERBOSE(edev, QED_MSG_IOV, |
| 166 | "Setting MAC %02x:%02x:%02x:%02x:%02x:%02x to VF [%d]\n", |
| 167 | mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], vfidx); |
| 168 | |
| 169 | if (!is_valid_ether_addr(mac)) { |
| 170 | DP_VERBOSE(edev, QED_MSG_IOV, "MAC address isn't valid\n"); |
| 171 | return -EINVAL; |
| 172 | } |
| 173 | |
| 174 | return edev->ops->iov->set_mac(edev->cdev, mac, vfidx); |
| 175 | } |
| 176 | |
Yuval Mintz | fefb020 | 2016-05-11 16:36:19 +0300 | [diff] [blame] | 177 | static int qede_sriov_configure(struct pci_dev *pdev, int num_vfs_param) |
| 178 | { |
| 179 | struct qede_dev *edev = netdev_priv(pci_get_drvdata(pdev)); |
Yuval Mintz | 831bfb0e | 2016-05-11 16:36:25 +0300 | [diff] [blame] | 180 | struct qed_dev_info *qed_info = &edev->dev_info.common; |
Mintz, Yuval | f29ffdb | 2017-01-01 13:57:07 +0200 | [diff] [blame^] | 181 | struct qed_update_vport_params *vport_params; |
Yuval Mintz | 831bfb0e | 2016-05-11 16:36:25 +0300 | [diff] [blame] | 182 | int rc; |
Yuval Mintz | fefb020 | 2016-05-11 16:36:19 +0300 | [diff] [blame] | 183 | |
Mintz, Yuval | f29ffdb | 2017-01-01 13:57:07 +0200 | [diff] [blame^] | 184 | vport_params = vzalloc(sizeof(*vport_params)); |
| 185 | if (!vport_params) |
| 186 | return -ENOMEM; |
Yuval Mintz | fefb020 | 2016-05-11 16:36:19 +0300 | [diff] [blame] | 187 | DP_VERBOSE(edev, QED_MSG_IOV, "Requested %d VFs\n", num_vfs_param); |
| 188 | |
Yuval Mintz | 831bfb0e | 2016-05-11 16:36:25 +0300 | [diff] [blame] | 189 | rc = edev->ops->iov->configure(edev->cdev, num_vfs_param); |
| 190 | |
| 191 | /* Enable/Disable Tx switching for PF */ |
| 192 | if ((rc == num_vfs_param) && netif_running(edev->ndev) && |
| 193 | qed_info->mf_mode != QED_MF_NPAR && qed_info->tx_switching) { |
Mintz, Yuval | f29ffdb | 2017-01-01 13:57:07 +0200 | [diff] [blame^] | 194 | vport_params->vport_id = 0; |
| 195 | vport_params->update_tx_switching_flg = 1; |
| 196 | vport_params->tx_switching_flg = num_vfs_param ? 1 : 0; |
| 197 | edev->ops->vport_update(edev->cdev, vport_params); |
Yuval Mintz | 831bfb0e | 2016-05-11 16:36:25 +0300 | [diff] [blame] | 198 | } |
| 199 | |
Mintz, Yuval | f29ffdb | 2017-01-01 13:57:07 +0200 | [diff] [blame^] | 200 | vfree(vport_params); |
Yuval Mintz | 831bfb0e | 2016-05-11 16:36:25 +0300 | [diff] [blame] | 201 | return rc; |
Yuval Mintz | fefb020 | 2016-05-11 16:36:19 +0300 | [diff] [blame] | 202 | } |
| 203 | #endif |
| 204 | |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 205 | static struct pci_driver qede_pci_driver = { |
| 206 | .name = "qede", |
| 207 | .id_table = qede_pci_tbl, |
| 208 | .probe = qede_probe, |
| 209 | .remove = qede_remove, |
Mintz, Yuval | 14d3964 | 2016-10-31 07:14:23 +0200 | [diff] [blame] | 210 | .shutdown = qede_shutdown, |
Yuval Mintz | fefb020 | 2016-05-11 16:36:19 +0300 | [diff] [blame] | 211 | #ifdef CONFIG_QED_SRIOV |
| 212 | .sriov_configure = qede_sriov_configure, |
| 213 | #endif |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 214 | }; |
| 215 | |
Sudarsana Kalluru | a2ec617 | 2015-10-26 11:02:32 +0200 | [diff] [blame] | 216 | static struct qed_eth_cb_ops qede_ll_ops = { |
| 217 | { |
| 218 | .link_update = qede_link_update, |
| 219 | }, |
Yuval Mintz | eff1696 | 2016-05-11 16:36:21 +0300 | [diff] [blame] | 220 | .force_mac = qede_force_mac, |
Sudarsana Kalluru | a2ec617 | 2015-10-26 11:02:32 +0200 | [diff] [blame] | 221 | }; |
| 222 | |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 223 | static int qede_netdev_event(struct notifier_block *this, unsigned long event, |
| 224 | void *ptr) |
| 225 | { |
| 226 | struct net_device *ndev = netdev_notifier_info_to_dev(ptr); |
| 227 | struct ethtool_drvinfo drvinfo; |
| 228 | struct qede_dev *edev; |
| 229 | |
Ram Amrani | cee9fbd | 2016-10-01 21:59:56 +0300 | [diff] [blame] | 230 | if (event != NETDEV_CHANGENAME && event != NETDEV_CHANGEADDR) |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 231 | goto done; |
| 232 | |
| 233 | /* Check whether this is a qede device */ |
| 234 | if (!ndev || !ndev->ethtool_ops || !ndev->ethtool_ops->get_drvinfo) |
| 235 | goto done; |
| 236 | |
| 237 | memset(&drvinfo, 0, sizeof(drvinfo)); |
| 238 | ndev->ethtool_ops->get_drvinfo(ndev, &drvinfo); |
| 239 | if (strcmp(drvinfo.driver, "qede")) |
| 240 | goto done; |
| 241 | edev = netdev_priv(ndev); |
| 242 | |
Ram Amrani | cee9fbd | 2016-10-01 21:59:56 +0300 | [diff] [blame] | 243 | switch (event) { |
| 244 | case NETDEV_CHANGENAME: |
| 245 | /* Notify qed of the name change */ |
| 246 | if (!edev->ops || !edev->ops->common) |
| 247 | goto done; |
| 248 | edev->ops->common->set_id(edev->cdev, edev->ndev->name, "qede"); |
| 249 | break; |
| 250 | case NETDEV_CHANGEADDR: |
| 251 | edev = netdev_priv(ndev); |
| 252 | qede_roce_event_changeaddr(edev); |
| 253 | break; |
| 254 | } |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 255 | |
| 256 | done: |
| 257 | return NOTIFY_DONE; |
| 258 | } |
| 259 | |
| 260 | static struct notifier_block qede_netdev_notifier = { |
| 261 | .notifier_call = qede_netdev_event, |
| 262 | }; |
| 263 | |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 264 | static |
| 265 | int __init qede_init(void) |
| 266 | { |
| 267 | int ret; |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 268 | |
Yuval Mintz | 525ef5c | 2016-08-15 10:42:45 +0300 | [diff] [blame] | 269 | pr_info("qede_init: %s\n", version); |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 270 | |
Rahul Verma | 9511434 | 2016-04-10 12:42:59 +0300 | [diff] [blame] | 271 | qed_ops = qed_get_eth_ops(); |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 272 | if (!qed_ops) { |
| 273 | pr_notice("Failed to get qed ethtool operations\n"); |
| 274 | return -EINVAL; |
| 275 | } |
| 276 | |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 277 | /* Must register notifier before pci ops, since we might miss |
| 278 | * interface rename after pci probe and netdev registeration. |
| 279 | */ |
| 280 | ret = register_netdevice_notifier(&qede_netdev_notifier); |
| 281 | if (ret) { |
| 282 | pr_notice("Failed to register netdevice_notifier\n"); |
| 283 | qed_put_eth_ops(); |
| 284 | return -EINVAL; |
| 285 | } |
| 286 | |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 287 | ret = pci_register_driver(&qede_pci_driver); |
| 288 | if (ret) { |
| 289 | pr_notice("Failed to register driver\n"); |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 290 | unregister_netdevice_notifier(&qede_netdev_notifier); |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 291 | qed_put_eth_ops(); |
| 292 | return -EINVAL; |
| 293 | } |
| 294 | |
| 295 | return 0; |
| 296 | } |
| 297 | |
| 298 | static void __exit qede_cleanup(void) |
| 299 | { |
Yuval Mintz | 525ef5c | 2016-08-15 10:42:45 +0300 | [diff] [blame] | 300 | if (debug & QED_LOG_INFO_MASK) |
| 301 | pr_info("qede_cleanup called\n"); |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 302 | |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 303 | unregister_netdevice_notifier(&qede_netdev_notifier); |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 304 | pci_unregister_driver(&qede_pci_driver); |
| 305 | qed_put_eth_ops(); |
| 306 | } |
| 307 | |
| 308 | module_init(qede_init); |
| 309 | module_exit(qede_cleanup); |
| 310 | |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 311 | static int qede_open(struct net_device *ndev); |
| 312 | static int qede_close(struct net_device *ndev); |
Sudarsana Reddy Kalluru | 7c1bfca | 2016-02-18 17:00:40 +0200 | [diff] [blame] | 313 | |
Sudarsana Kalluru | 133fac0 | 2015-10-26 11:02:34 +0200 | [diff] [blame] | 314 | void qede_fill_by_demand_stats(struct qede_dev *edev) |
| 315 | { |
| 316 | struct qed_eth_stats stats; |
| 317 | |
| 318 | edev->ops->get_vport_stats(edev->cdev, &stats); |
| 319 | edev->stats.no_buff_discards = stats.no_buff_discards; |
Sudarsana Reddy Kalluru | 1a5a366 | 2016-08-16 10:51:01 -0400 | [diff] [blame] | 320 | edev->stats.packet_too_big_discard = stats.packet_too_big_discard; |
| 321 | edev->stats.ttl0_discard = stats.ttl0_discard; |
Sudarsana Kalluru | 133fac0 | 2015-10-26 11:02:34 +0200 | [diff] [blame] | 322 | edev->stats.rx_ucast_bytes = stats.rx_ucast_bytes; |
| 323 | edev->stats.rx_mcast_bytes = stats.rx_mcast_bytes; |
| 324 | edev->stats.rx_bcast_bytes = stats.rx_bcast_bytes; |
| 325 | edev->stats.rx_ucast_pkts = stats.rx_ucast_pkts; |
| 326 | edev->stats.rx_mcast_pkts = stats.rx_mcast_pkts; |
| 327 | edev->stats.rx_bcast_pkts = stats.rx_bcast_pkts; |
| 328 | edev->stats.mftag_filter_discards = stats.mftag_filter_discards; |
| 329 | edev->stats.mac_filter_discards = stats.mac_filter_discards; |
| 330 | |
| 331 | edev->stats.tx_ucast_bytes = stats.tx_ucast_bytes; |
| 332 | edev->stats.tx_mcast_bytes = stats.tx_mcast_bytes; |
| 333 | edev->stats.tx_bcast_bytes = stats.tx_bcast_bytes; |
| 334 | edev->stats.tx_ucast_pkts = stats.tx_ucast_pkts; |
| 335 | edev->stats.tx_mcast_pkts = stats.tx_mcast_pkts; |
| 336 | edev->stats.tx_bcast_pkts = stats.tx_bcast_pkts; |
| 337 | edev->stats.tx_err_drop_pkts = stats.tx_err_drop_pkts; |
| 338 | edev->stats.coalesced_pkts = stats.tpa_coalesced_pkts; |
| 339 | edev->stats.coalesced_events = stats.tpa_coalesced_events; |
| 340 | edev->stats.coalesced_aborts_num = stats.tpa_aborts_num; |
| 341 | edev->stats.non_coalesced_pkts = stats.tpa_not_coalesced_pkts; |
| 342 | edev->stats.coalesced_bytes = stats.tpa_coalesced_bytes; |
| 343 | |
| 344 | edev->stats.rx_64_byte_packets = stats.rx_64_byte_packets; |
Yuval Mintz | d4967cf | 2016-04-22 08:41:01 +0300 | [diff] [blame] | 345 | edev->stats.rx_65_to_127_byte_packets = stats.rx_65_to_127_byte_packets; |
| 346 | edev->stats.rx_128_to_255_byte_packets = |
| 347 | stats.rx_128_to_255_byte_packets; |
| 348 | edev->stats.rx_256_to_511_byte_packets = |
| 349 | stats.rx_256_to_511_byte_packets; |
| 350 | edev->stats.rx_512_to_1023_byte_packets = |
| 351 | stats.rx_512_to_1023_byte_packets; |
| 352 | edev->stats.rx_1024_to_1518_byte_packets = |
| 353 | stats.rx_1024_to_1518_byte_packets; |
| 354 | edev->stats.rx_1519_to_1522_byte_packets = |
| 355 | stats.rx_1519_to_1522_byte_packets; |
| 356 | edev->stats.rx_1519_to_2047_byte_packets = |
| 357 | stats.rx_1519_to_2047_byte_packets; |
| 358 | edev->stats.rx_2048_to_4095_byte_packets = |
| 359 | stats.rx_2048_to_4095_byte_packets; |
| 360 | edev->stats.rx_4096_to_9216_byte_packets = |
| 361 | stats.rx_4096_to_9216_byte_packets; |
| 362 | edev->stats.rx_9217_to_16383_byte_packets = |
| 363 | stats.rx_9217_to_16383_byte_packets; |
Sudarsana Kalluru | 133fac0 | 2015-10-26 11:02:34 +0200 | [diff] [blame] | 364 | edev->stats.rx_crc_errors = stats.rx_crc_errors; |
| 365 | edev->stats.rx_mac_crtl_frames = stats.rx_mac_crtl_frames; |
| 366 | edev->stats.rx_pause_frames = stats.rx_pause_frames; |
| 367 | edev->stats.rx_pfc_frames = stats.rx_pfc_frames; |
| 368 | edev->stats.rx_align_errors = stats.rx_align_errors; |
| 369 | edev->stats.rx_carrier_errors = stats.rx_carrier_errors; |
| 370 | edev->stats.rx_oversize_packets = stats.rx_oversize_packets; |
| 371 | edev->stats.rx_jabbers = stats.rx_jabbers; |
| 372 | edev->stats.rx_undersize_packets = stats.rx_undersize_packets; |
| 373 | edev->stats.rx_fragments = stats.rx_fragments; |
| 374 | edev->stats.tx_64_byte_packets = stats.tx_64_byte_packets; |
| 375 | edev->stats.tx_65_to_127_byte_packets = stats.tx_65_to_127_byte_packets; |
| 376 | edev->stats.tx_128_to_255_byte_packets = |
| 377 | stats.tx_128_to_255_byte_packets; |
| 378 | edev->stats.tx_256_to_511_byte_packets = |
| 379 | stats.tx_256_to_511_byte_packets; |
| 380 | edev->stats.tx_512_to_1023_byte_packets = |
| 381 | stats.tx_512_to_1023_byte_packets; |
| 382 | edev->stats.tx_1024_to_1518_byte_packets = |
| 383 | stats.tx_1024_to_1518_byte_packets; |
| 384 | edev->stats.tx_1519_to_2047_byte_packets = |
| 385 | stats.tx_1519_to_2047_byte_packets; |
| 386 | edev->stats.tx_2048_to_4095_byte_packets = |
| 387 | stats.tx_2048_to_4095_byte_packets; |
| 388 | edev->stats.tx_4096_to_9216_byte_packets = |
| 389 | stats.tx_4096_to_9216_byte_packets; |
| 390 | edev->stats.tx_9217_to_16383_byte_packets = |
| 391 | stats.tx_9217_to_16383_byte_packets; |
| 392 | edev->stats.tx_pause_frames = stats.tx_pause_frames; |
| 393 | edev->stats.tx_pfc_frames = stats.tx_pfc_frames; |
| 394 | edev->stats.tx_lpi_entry_count = stats.tx_lpi_entry_count; |
| 395 | edev->stats.tx_total_collisions = stats.tx_total_collisions; |
| 396 | edev->stats.brb_truncates = stats.brb_truncates; |
| 397 | edev->stats.brb_discards = stats.brb_discards; |
| 398 | edev->stats.tx_mac_ctrl_frames = stats.tx_mac_ctrl_frames; |
| 399 | } |
| 400 | |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 401 | static |
| 402 | struct rtnl_link_stats64 *qede_get_stats64(struct net_device *dev, |
| 403 | struct rtnl_link_stats64 *stats) |
Sudarsana Kalluru | 133fac0 | 2015-10-26 11:02:34 +0200 | [diff] [blame] | 404 | { |
| 405 | struct qede_dev *edev = netdev_priv(dev); |
| 406 | |
| 407 | qede_fill_by_demand_stats(edev); |
| 408 | |
| 409 | stats->rx_packets = edev->stats.rx_ucast_pkts + |
| 410 | edev->stats.rx_mcast_pkts + |
| 411 | edev->stats.rx_bcast_pkts; |
| 412 | stats->tx_packets = edev->stats.tx_ucast_pkts + |
| 413 | edev->stats.tx_mcast_pkts + |
| 414 | edev->stats.tx_bcast_pkts; |
| 415 | |
| 416 | stats->rx_bytes = edev->stats.rx_ucast_bytes + |
| 417 | edev->stats.rx_mcast_bytes + |
| 418 | edev->stats.rx_bcast_bytes; |
| 419 | |
| 420 | stats->tx_bytes = edev->stats.tx_ucast_bytes + |
| 421 | edev->stats.tx_mcast_bytes + |
| 422 | edev->stats.tx_bcast_bytes; |
| 423 | |
| 424 | stats->tx_errors = edev->stats.tx_err_drop_pkts; |
| 425 | stats->multicast = edev->stats.rx_mcast_pkts + |
| 426 | edev->stats.rx_bcast_pkts; |
| 427 | |
| 428 | stats->rx_fifo_errors = edev->stats.no_buff_discards; |
| 429 | |
| 430 | stats->collisions = edev->stats.tx_total_collisions; |
| 431 | stats->rx_crc_errors = edev->stats.rx_crc_errors; |
| 432 | stats->rx_frame_errors = edev->stats.rx_align_errors; |
| 433 | |
| 434 | return stats; |
| 435 | } |
| 436 | |
Yuval Mintz | 733def6 | 2016-05-11 16:36:22 +0300 | [diff] [blame] | 437 | #ifdef CONFIG_QED_SRIOV |
Yuval Mintz | 73390ac | 2016-05-11 16:36:24 +0300 | [diff] [blame] | 438 | static int qede_get_vf_config(struct net_device *dev, int vfidx, |
| 439 | struct ifla_vf_info *ivi) |
| 440 | { |
| 441 | struct qede_dev *edev = netdev_priv(dev); |
| 442 | |
| 443 | if (!edev->ops) |
| 444 | return -EINVAL; |
| 445 | |
| 446 | return edev->ops->iov->get_config(edev->cdev, vfidx, ivi); |
| 447 | } |
| 448 | |
Yuval Mintz | 733def6 | 2016-05-11 16:36:22 +0300 | [diff] [blame] | 449 | static int qede_set_vf_rate(struct net_device *dev, int vfidx, |
| 450 | int min_tx_rate, int max_tx_rate) |
| 451 | { |
| 452 | struct qede_dev *edev = netdev_priv(dev); |
| 453 | |
Yuval Mintz | be7b6d6 | 2016-05-26 11:01:17 +0300 | [diff] [blame] | 454 | return edev->ops->iov->set_rate(edev->cdev, vfidx, min_tx_rate, |
Yuval Mintz | 733def6 | 2016-05-11 16:36:22 +0300 | [diff] [blame] | 455 | max_tx_rate); |
| 456 | } |
| 457 | |
Yuval Mintz | 6ddc760 | 2016-05-11 16:36:23 +0300 | [diff] [blame] | 458 | static int qede_set_vf_spoofchk(struct net_device *dev, int vfidx, bool val) |
| 459 | { |
| 460 | struct qede_dev *edev = netdev_priv(dev); |
| 461 | |
| 462 | if (!edev->ops) |
| 463 | return -EINVAL; |
| 464 | |
| 465 | return edev->ops->iov->set_spoof(edev->cdev, vfidx, val); |
| 466 | } |
| 467 | |
Yuval Mintz | 733def6 | 2016-05-11 16:36:22 +0300 | [diff] [blame] | 468 | static int qede_set_vf_link_state(struct net_device *dev, int vfidx, |
| 469 | int link_state) |
| 470 | { |
| 471 | struct qede_dev *edev = netdev_priv(dev); |
| 472 | |
| 473 | if (!edev->ops) |
| 474 | return -EINVAL; |
| 475 | |
| 476 | return edev->ops->iov->set_link_state(edev->cdev, vfidx, link_state); |
| 477 | } |
| 478 | #endif |
| 479 | |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 480 | static const struct net_device_ops qede_netdev_ops = { |
| 481 | .ndo_open = qede_open, |
| 482 | .ndo_stop = qede_close, |
| 483 | .ndo_start_xmit = qede_start_xmit, |
Sudarsana Kalluru | 0d8e0aa | 2015-10-26 11:02:30 +0200 | [diff] [blame] | 484 | .ndo_set_rx_mode = qede_set_rx_mode, |
| 485 | .ndo_set_mac_address = qede_set_mac_addr, |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 486 | .ndo_validate_addr = eth_validate_addr, |
Sudarsana Kalluru | 133fac0 | 2015-10-26 11:02:34 +0200 | [diff] [blame] | 487 | .ndo_change_mtu = qede_change_mtu, |
Yuval Mintz | 08feecd | 2016-05-11 16:36:20 +0300 | [diff] [blame] | 488 | #ifdef CONFIG_QED_SRIOV |
Yuval Mintz | eff1696 | 2016-05-11 16:36:21 +0300 | [diff] [blame] | 489 | .ndo_set_vf_mac = qede_set_vf_mac, |
Yuval Mintz | 08feecd | 2016-05-11 16:36:20 +0300 | [diff] [blame] | 490 | .ndo_set_vf_vlan = qede_set_vf_vlan, |
| 491 | #endif |
Sudarsana Reddy Kalluru | 7c1bfca | 2016-02-18 17:00:40 +0200 | [diff] [blame] | 492 | .ndo_vlan_rx_add_vid = qede_vlan_rx_add_vid, |
| 493 | .ndo_vlan_rx_kill_vid = qede_vlan_rx_kill_vid, |
Yuval Mintz | ce2b885 | 2016-05-26 11:01:18 +0300 | [diff] [blame] | 494 | .ndo_set_features = qede_set_features, |
Sudarsana Kalluru | 133fac0 | 2015-10-26 11:02:34 +0200 | [diff] [blame] | 495 | .ndo_get_stats64 = qede_get_stats64, |
Yuval Mintz | 733def6 | 2016-05-11 16:36:22 +0300 | [diff] [blame] | 496 | #ifdef CONFIG_QED_SRIOV |
| 497 | .ndo_set_vf_link_state = qede_set_vf_link_state, |
Yuval Mintz | 6ddc760 | 2016-05-11 16:36:23 +0300 | [diff] [blame] | 498 | .ndo_set_vf_spoofchk = qede_set_vf_spoofchk, |
Yuval Mintz | 73390ac | 2016-05-11 16:36:24 +0300 | [diff] [blame] | 499 | .ndo_get_vf_config = qede_get_vf_config, |
Yuval Mintz | 733def6 | 2016-05-11 16:36:22 +0300 | [diff] [blame] | 500 | .ndo_set_vf_rate = qede_set_vf_rate, |
| 501 | #endif |
Alexander Duyck | f9f082a | 2016-06-16 12:22:57 -0700 | [diff] [blame] | 502 | .ndo_udp_tunnel_add = qede_udp_tunnel_add, |
| 503 | .ndo_udp_tunnel_del = qede_udp_tunnel_del, |
Manish Chopra | 2569585 | 2016-10-14 05:19:19 -0400 | [diff] [blame] | 504 | .ndo_features_check = qede_features_check, |
Mintz, Yuval | 496e051 | 2016-11-29 16:47:09 +0200 | [diff] [blame] | 505 | .ndo_xdp = qede_xdp, |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 506 | }; |
| 507 | |
| 508 | /* ------------------------------------------------------------------------- |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 509 | * START OF PROBE / REMOVE |
| 510 | * ------------------------------------------------------------------------- |
| 511 | */ |
| 512 | |
| 513 | static struct qede_dev *qede_alloc_etherdev(struct qed_dev *cdev, |
| 514 | struct pci_dev *pdev, |
| 515 | struct qed_dev_eth_info *info, |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 516 | u32 dp_module, u8 dp_level) |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 517 | { |
| 518 | struct net_device *ndev; |
| 519 | struct qede_dev *edev; |
| 520 | |
| 521 | ndev = alloc_etherdev_mqs(sizeof(*edev), |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 522 | info->num_queues, info->num_queues); |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 523 | if (!ndev) { |
| 524 | pr_err("etherdev allocation failed\n"); |
| 525 | return NULL; |
| 526 | } |
| 527 | |
| 528 | edev = netdev_priv(ndev); |
| 529 | edev->ndev = ndev; |
| 530 | edev->cdev = cdev; |
| 531 | edev->pdev = pdev; |
| 532 | edev->dp_module = dp_module; |
| 533 | edev->dp_level = dp_level; |
| 534 | edev->ops = qed_ops; |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 535 | edev->q_num_rx_buffers = NUM_RX_BDS_DEF; |
| 536 | edev->q_num_tx_buffers = NUM_TX_BDS_DEF; |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 537 | |
Yuval Mintz | 525ef5c | 2016-08-15 10:42:45 +0300 | [diff] [blame] | 538 | DP_INFO(edev, "Allocated netdev with %d tx queues and %d rx queues\n", |
| 539 | info->num_queues, info->num_queues); |
| 540 | |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 541 | SET_NETDEV_DEV(ndev, &pdev->dev); |
| 542 | |
Sudarsana Kalluru | 133fac0 | 2015-10-26 11:02:34 +0200 | [diff] [blame] | 543 | memset(&edev->stats, 0, sizeof(edev->stats)); |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 544 | memcpy(&edev->dev_info, info, sizeof(*info)); |
| 545 | |
Sudarsana Reddy Kalluru | 7c1bfca | 2016-02-18 17:00:40 +0200 | [diff] [blame] | 546 | INIT_LIST_HEAD(&edev->vlan_list); |
| 547 | |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 548 | return edev; |
| 549 | } |
| 550 | |
| 551 | static void qede_init_ndev(struct qede_dev *edev) |
| 552 | { |
| 553 | struct net_device *ndev = edev->ndev; |
| 554 | struct pci_dev *pdev = edev->pdev; |
| 555 | u32 hw_features; |
| 556 | |
| 557 | pci_set_drvdata(pdev, ndev); |
| 558 | |
| 559 | ndev->mem_start = edev->dev_info.common.pci_mem_start; |
| 560 | ndev->base_addr = ndev->mem_start; |
| 561 | ndev->mem_end = edev->dev_info.common.pci_mem_end; |
| 562 | ndev->irq = edev->dev_info.common.pci_irq; |
| 563 | |
| 564 | ndev->watchdog_timeo = TX_TIMEOUT; |
| 565 | |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 566 | ndev->netdev_ops = &qede_netdev_ops; |
| 567 | |
Sudarsana Kalluru | 133fac0 | 2015-10-26 11:02:34 +0200 | [diff] [blame] | 568 | qede_set_ethtool_ops(ndev); |
| 569 | |
Mintz, Yuval | 0183eb1 | 2016-10-31 22:26:53 +0200 | [diff] [blame] | 570 | ndev->priv_flags |= IFF_UNICAST_FLT; |
Yuval Mintz | 7b7e70f | 2016-10-14 05:19:20 -0400 | [diff] [blame] | 571 | |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 572 | /* user-changeble features */ |
| 573 | hw_features = NETIF_F_GRO | NETIF_F_SG | |
| 574 | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | |
| 575 | NETIF_F_TSO | NETIF_F_TSO6; |
| 576 | |
Manish Chopra | 14db81d | 2016-04-14 01:38:33 -0400 | [diff] [blame] | 577 | /* Encap features*/ |
| 578 | hw_features |= NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL | |
Manish Chopra | a150241 | 2016-10-14 05:19:18 -0400 | [diff] [blame] | 579 | NETIF_F_TSO_ECN | NETIF_F_GSO_UDP_TUNNEL_CSUM | |
| 580 | NETIF_F_GSO_GRE_CSUM; |
Manish Chopra | 14db81d | 2016-04-14 01:38:33 -0400 | [diff] [blame] | 581 | ndev->hw_enc_features = NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | |
| 582 | NETIF_F_SG | NETIF_F_TSO | NETIF_F_TSO_ECN | |
| 583 | NETIF_F_TSO6 | NETIF_F_GSO_GRE | |
Manish Chopra | a150241 | 2016-10-14 05:19:18 -0400 | [diff] [blame] | 584 | NETIF_F_GSO_UDP_TUNNEL | NETIF_F_RXCSUM | |
| 585 | NETIF_F_GSO_UDP_TUNNEL_CSUM | |
| 586 | NETIF_F_GSO_GRE_CSUM; |
Manish Chopra | 14db81d | 2016-04-14 01:38:33 -0400 | [diff] [blame] | 587 | |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 588 | ndev->vlan_features = hw_features | NETIF_F_RXHASH | NETIF_F_RXCSUM | |
| 589 | NETIF_F_HIGHDMA; |
| 590 | ndev->features = hw_features | NETIF_F_RXHASH | NETIF_F_RXCSUM | |
| 591 | NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HIGHDMA | |
Sudarsana Reddy Kalluru | 7c1bfca | 2016-02-18 17:00:40 +0200 | [diff] [blame] | 592 | NETIF_F_HW_VLAN_CTAG_FILTER | NETIF_F_HW_VLAN_CTAG_TX; |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 593 | |
| 594 | ndev->hw_features = hw_features; |
| 595 | |
Jarod Wilson | caff2a8 | 2016-10-17 15:54:08 -0400 | [diff] [blame] | 596 | /* MTU range: 46 - 9600 */ |
| 597 | ndev->min_mtu = ETH_ZLEN - ETH_HLEN; |
| 598 | ndev->max_mtu = QEDE_MAX_JUMBO_PACKET_SIZE; |
| 599 | |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 600 | /* Set network device HW mac */ |
| 601 | ether_addr_copy(edev->ndev->dev_addr, edev->dev_info.common.hw_mac); |
Sudarsana Kalluru | 0fefbfb | 2016-10-31 07:14:21 +0200 | [diff] [blame] | 602 | |
| 603 | ndev->mtu = edev->dev_info.common.mtu; |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 604 | } |
| 605 | |
| 606 | /* This function converts from 32b param to two params of level and module |
| 607 | * Input 32b decoding: |
| 608 | * b31 - enable all NOTICE prints. NOTICE prints are for deviation from the |
| 609 | * 'happy' flow, e.g. memory allocation failed. |
| 610 | * b30 - enable all INFO prints. INFO prints are for major steps in the flow |
| 611 | * and provide important parameters. |
| 612 | * b29-b0 - per-module bitmap, where each bit enables VERBOSE prints of that |
| 613 | * module. VERBOSE prints are for tracking the specific flow in low level. |
| 614 | * |
| 615 | * Notice that the level should be that of the lowest required logs. |
| 616 | */ |
Sudarsana Kalluru | 133fac0 | 2015-10-26 11:02:34 +0200 | [diff] [blame] | 617 | void qede_config_debug(uint debug, u32 *p_dp_module, u8 *p_dp_level) |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 618 | { |
| 619 | *p_dp_level = QED_LEVEL_NOTICE; |
| 620 | *p_dp_module = 0; |
| 621 | |
| 622 | if (debug & QED_LOG_VERBOSE_MASK) { |
| 623 | *p_dp_level = QED_LEVEL_VERBOSE; |
| 624 | *p_dp_module = (debug & 0x3FFFFFFF); |
| 625 | } else if (debug & QED_LOG_INFO_MASK) { |
| 626 | *p_dp_level = QED_LEVEL_INFO; |
| 627 | } else if (debug & QED_LOG_NOTICE_MASK) { |
| 628 | *p_dp_level = QED_LEVEL_NOTICE; |
| 629 | } |
| 630 | } |
| 631 | |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 632 | static void qede_free_fp_array(struct qede_dev *edev) |
| 633 | { |
| 634 | if (edev->fp_array) { |
| 635 | struct qede_fastpath *fp; |
| 636 | int i; |
| 637 | |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 638 | for_each_queue(i) { |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 639 | fp = &edev->fp_array[i]; |
| 640 | |
| 641 | kfree(fp->sb_info); |
| 642 | kfree(fp->rxq); |
Mintz, Yuval | cb6aeb0 | 2016-11-29 16:47:10 +0200 | [diff] [blame] | 643 | kfree(fp->xdp_tx); |
Mintz, Yuval | 80439a1 | 2016-11-29 16:47:02 +0200 | [diff] [blame] | 644 | kfree(fp->txq); |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 645 | } |
| 646 | kfree(edev->fp_array); |
| 647 | } |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 648 | |
| 649 | edev->num_queues = 0; |
| 650 | edev->fp_num_tx = 0; |
| 651 | edev->fp_num_rx = 0; |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | static int qede_alloc_fp_array(struct qede_dev *edev) |
| 655 | { |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 656 | u8 fp_combined, fp_rx = edev->fp_num_rx; |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 657 | struct qede_fastpath *fp; |
| 658 | int i; |
| 659 | |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 660 | edev->fp_array = kcalloc(QEDE_QUEUE_CNT(edev), |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 661 | sizeof(*edev->fp_array), GFP_KERNEL); |
| 662 | if (!edev->fp_array) { |
| 663 | DP_NOTICE(edev, "fp array allocation failed\n"); |
| 664 | goto err; |
| 665 | } |
| 666 | |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 667 | fp_combined = QEDE_QUEUE_CNT(edev) - fp_rx - edev->fp_num_tx; |
| 668 | |
| 669 | /* Allocate the FP elements for Rx queues followed by combined and then |
| 670 | * the Tx. This ordering should be maintained so that the respective |
| 671 | * queues (Rx or Tx) will be together in the fastpath array and the |
| 672 | * associated ids will be sequential. |
| 673 | */ |
| 674 | for_each_queue(i) { |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 675 | fp = &edev->fp_array[i]; |
| 676 | |
Mintz, Yuval | 80439a1 | 2016-11-29 16:47:02 +0200 | [diff] [blame] | 677 | fp->sb_info = kzalloc(sizeof(*fp->sb_info), GFP_KERNEL); |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 678 | if (!fp->sb_info) { |
| 679 | DP_NOTICE(edev, "sb info struct allocation failed\n"); |
| 680 | goto err; |
| 681 | } |
| 682 | |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 683 | if (fp_rx) { |
| 684 | fp->type = QEDE_FASTPATH_RX; |
| 685 | fp_rx--; |
| 686 | } else if (fp_combined) { |
| 687 | fp->type = QEDE_FASTPATH_COMBINED; |
| 688 | fp_combined--; |
| 689 | } else { |
| 690 | fp->type = QEDE_FASTPATH_TX; |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 691 | } |
| 692 | |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 693 | if (fp->type & QEDE_FASTPATH_TX) { |
Mintz, Yuval | 80439a1 | 2016-11-29 16:47:02 +0200 | [diff] [blame] | 694 | fp->txq = kzalloc(sizeof(*fp->txq), GFP_KERNEL); |
| 695 | if (!fp->txq) |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 696 | goto err; |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | if (fp->type & QEDE_FASTPATH_RX) { |
Mintz, Yuval | 80439a1 | 2016-11-29 16:47:02 +0200 | [diff] [blame] | 700 | fp->rxq = kzalloc(sizeof(*fp->rxq), GFP_KERNEL); |
| 701 | if (!fp->rxq) |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 702 | goto err; |
Mintz, Yuval | 496e051 | 2016-11-29 16:47:09 +0200 | [diff] [blame] | 703 | |
Mintz, Yuval | cb6aeb0 | 2016-11-29 16:47:10 +0200 | [diff] [blame] | 704 | if (edev->xdp_prog) { |
| 705 | fp->xdp_tx = kzalloc(sizeof(*fp->xdp_tx), |
| 706 | GFP_KERNEL); |
| 707 | if (!fp->xdp_tx) |
| 708 | goto err; |
Mintz, Yuval | 496e051 | 2016-11-29 16:47:09 +0200 | [diff] [blame] | 709 | fp->type |= QEDE_FASTPATH_XDP; |
Mintz, Yuval | cb6aeb0 | 2016-11-29 16:47:10 +0200 | [diff] [blame] | 710 | } |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 711 | } |
| 712 | } |
| 713 | |
| 714 | return 0; |
| 715 | err: |
| 716 | qede_free_fp_array(edev); |
| 717 | return -ENOMEM; |
| 718 | } |
| 719 | |
Sudarsana Kalluru | 0d8e0aa | 2015-10-26 11:02:30 +0200 | [diff] [blame] | 720 | static void qede_sp_task(struct work_struct *work) |
| 721 | { |
| 722 | struct qede_dev *edev = container_of(work, struct qede_dev, |
| 723 | sp_task.work); |
Manish Chopra | b18e170 | 2016-04-14 01:38:30 -0400 | [diff] [blame] | 724 | struct qed_dev *cdev = edev->cdev; |
| 725 | |
Mintz, Yuval | 567b3c1 | 2016-11-29 16:47:05 +0200 | [diff] [blame] | 726 | __qede_lock(edev); |
Sudarsana Kalluru | 0d8e0aa | 2015-10-26 11:02:30 +0200 | [diff] [blame] | 727 | |
Mintz, Yuval | 567b3c1 | 2016-11-29 16:47:05 +0200 | [diff] [blame] | 728 | if (test_and_clear_bit(QEDE_SP_RX_MODE, &edev->sp_flags)) |
| 729 | if (edev->state == QEDE_STATE_OPEN) |
Sudarsana Kalluru | 0d8e0aa | 2015-10-26 11:02:30 +0200 | [diff] [blame] | 730 | qede_config_rx_mode(edev->ndev); |
Sudarsana Kalluru | 0d8e0aa | 2015-10-26 11:02:30 +0200 | [diff] [blame] | 731 | |
Manish Chopra | b18e170 | 2016-04-14 01:38:30 -0400 | [diff] [blame] | 732 | if (test_and_clear_bit(QEDE_SP_VXLAN_PORT_CONFIG, &edev->sp_flags)) { |
| 733 | struct qed_tunn_params tunn_params; |
| 734 | |
| 735 | memset(&tunn_params, 0, sizeof(tunn_params)); |
| 736 | tunn_params.update_vxlan_port = 1; |
| 737 | tunn_params.vxlan_port = edev->vxlan_dst_port; |
| 738 | qed_ops->tunn_config(cdev, &tunn_params); |
| 739 | } |
| 740 | |
Manish Chopra | 9a109dd | 2016-04-14 01:38:31 -0400 | [diff] [blame] | 741 | if (test_and_clear_bit(QEDE_SP_GENEVE_PORT_CONFIG, &edev->sp_flags)) { |
| 742 | struct qed_tunn_params tunn_params; |
| 743 | |
| 744 | memset(&tunn_params, 0, sizeof(tunn_params)); |
| 745 | tunn_params.update_geneve_port = 1; |
| 746 | tunn_params.geneve_port = edev->geneve_dst_port; |
| 747 | qed_ops->tunn_config(cdev, &tunn_params); |
| 748 | } |
| 749 | |
Mintz, Yuval | 567b3c1 | 2016-11-29 16:47:05 +0200 | [diff] [blame] | 750 | __qede_unlock(edev); |
Sudarsana Kalluru | 0d8e0aa | 2015-10-26 11:02:30 +0200 | [diff] [blame] | 751 | } |
| 752 | |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 753 | static void qede_update_pf_params(struct qed_dev *cdev) |
| 754 | { |
| 755 | struct qed_pf_params pf_params; |
| 756 | |
Mintz, Yuval | cb6aeb0 | 2016-11-29 16:47:10 +0200 | [diff] [blame] | 757 | /* 64 rx + 64 tx + 64 XDP */ |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 758 | memset(&pf_params, 0, sizeof(struct qed_pf_params)); |
Mintz, Yuval | e1d32ac | 2017-01-01 13:57:03 +0200 | [diff] [blame] | 759 | pf_params.eth_pf_params.num_cons = (MAX_SB_PER_PF_MIMD - 1) * 3; |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 760 | qed_ops->common->update_pf_params(cdev, &pf_params); |
| 761 | } |
| 762 | |
| 763 | enum qede_probe_mode { |
| 764 | QEDE_PROBE_NORMAL, |
| 765 | }; |
| 766 | |
| 767 | static int __qede_probe(struct pci_dev *pdev, u32 dp_module, u8 dp_level, |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 768 | bool is_vf, enum qede_probe_mode mode) |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 769 | { |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 770 | struct qed_probe_params probe_params; |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 771 | struct qed_slowpath_params sp_params; |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 772 | struct qed_dev_eth_info dev_info; |
| 773 | struct qede_dev *edev; |
| 774 | struct qed_dev *cdev; |
| 775 | int rc; |
| 776 | |
| 777 | if (unlikely(dp_level & QED_LEVEL_INFO)) |
| 778 | pr_notice("Starting qede probe\n"); |
| 779 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 780 | memset(&probe_params, 0, sizeof(probe_params)); |
| 781 | probe_params.protocol = QED_PROTOCOL_ETH; |
| 782 | probe_params.dp_module = dp_module; |
| 783 | probe_params.dp_level = dp_level; |
| 784 | probe_params.is_vf = is_vf; |
| 785 | cdev = qed_ops->common->probe(pdev, &probe_params); |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 786 | if (!cdev) { |
| 787 | rc = -ENODEV; |
| 788 | goto err0; |
| 789 | } |
| 790 | |
| 791 | qede_update_pf_params(cdev); |
| 792 | |
| 793 | /* Start the Slowpath-process */ |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 794 | memset(&sp_params, 0, sizeof(sp_params)); |
| 795 | sp_params.int_mode = QED_INT_MODE_MSIX; |
| 796 | sp_params.drv_major = QEDE_MAJOR_VERSION; |
| 797 | sp_params.drv_minor = QEDE_MINOR_VERSION; |
| 798 | sp_params.drv_rev = QEDE_REVISION_VERSION; |
| 799 | sp_params.drv_eng = QEDE_ENGINEERING_VERSION; |
| 800 | strlcpy(sp_params.name, "qede LAN", QED_DRV_VER_STR_SIZE); |
| 801 | rc = qed_ops->common->slowpath_start(cdev, &sp_params); |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 802 | if (rc) { |
| 803 | pr_notice("Cannot start slowpath\n"); |
| 804 | goto err1; |
| 805 | } |
| 806 | |
| 807 | /* Learn information crucial for qede to progress */ |
| 808 | rc = qed_ops->fill_dev_info(cdev, &dev_info); |
| 809 | if (rc) |
| 810 | goto err2; |
| 811 | |
| 812 | edev = qede_alloc_etherdev(cdev, pdev, &dev_info, dp_module, |
| 813 | dp_level); |
| 814 | if (!edev) { |
| 815 | rc = -ENOMEM; |
| 816 | goto err2; |
| 817 | } |
| 818 | |
Yuval Mintz | fefb020 | 2016-05-11 16:36:19 +0300 | [diff] [blame] | 819 | if (is_vf) |
| 820 | edev->flags |= QEDE_FLAG_IS_VF; |
| 821 | |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 822 | qede_init_ndev(edev); |
| 823 | |
Ram Amrani | cee9fbd | 2016-10-01 21:59:56 +0300 | [diff] [blame] | 824 | rc = qede_roce_dev_add(edev); |
| 825 | if (rc) |
| 826 | goto err3; |
| 827 | |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 828 | rc = register_netdev(edev->ndev); |
| 829 | if (rc) { |
| 830 | DP_NOTICE(edev, "Cannot register net-device\n"); |
Ram Amrani | cee9fbd | 2016-10-01 21:59:56 +0300 | [diff] [blame] | 831 | goto err4; |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 832 | } |
| 833 | |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 834 | edev->ops->common->set_id(cdev, edev->ndev->name, DRV_MODULE_VERSION); |
| 835 | |
Sudarsana Kalluru | a2ec617 | 2015-10-26 11:02:32 +0200 | [diff] [blame] | 836 | edev->ops->register_ops(cdev, &qede_ll_ops, edev); |
| 837 | |
Sudarsana Reddy Kalluru | 489e45a | 2016-06-08 06:22:12 -0400 | [diff] [blame] | 838 | #ifdef CONFIG_DCB |
Sudarsana Reddy Kalluru | 5fe118c | 2016-08-29 08:29:52 -0400 | [diff] [blame] | 839 | if (!IS_VF(edev)) |
| 840 | qede_set_dcbnl_ops(edev->ndev); |
Sudarsana Reddy Kalluru | 489e45a | 2016-06-08 06:22:12 -0400 | [diff] [blame] | 841 | #endif |
| 842 | |
Sudarsana Kalluru | 0d8e0aa | 2015-10-26 11:02:30 +0200 | [diff] [blame] | 843 | INIT_DELAYED_WORK(&edev->sp_task, qede_sp_task); |
| 844 | mutex_init(&edev->qede_lock); |
Manish Chopra | 3d78999 | 2016-06-30 02:35:21 -0400 | [diff] [blame] | 845 | edev->rx_copybreak = QEDE_RX_HDR_SIZE; |
Sudarsana Kalluru | 0d8e0aa | 2015-10-26 11:02:30 +0200 | [diff] [blame] | 846 | |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 847 | DP_INFO(edev, "Ending successfully qede probe\n"); |
| 848 | |
| 849 | return 0; |
| 850 | |
Ram Amrani | cee9fbd | 2016-10-01 21:59:56 +0300 | [diff] [blame] | 851 | err4: |
| 852 | qede_roce_dev_remove(edev); |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 853 | err3: |
| 854 | free_netdev(edev->ndev); |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 855 | err2: |
| 856 | qed_ops->common->slowpath_stop(cdev); |
| 857 | err1: |
| 858 | qed_ops->common->remove(cdev); |
| 859 | err0: |
| 860 | return rc; |
| 861 | } |
| 862 | |
| 863 | static int qede_probe(struct pci_dev *pdev, const struct pci_device_id *id) |
| 864 | { |
Yuval Mintz | fefb020 | 2016-05-11 16:36:19 +0300 | [diff] [blame] | 865 | bool is_vf = false; |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 866 | u32 dp_module = 0; |
| 867 | u8 dp_level = 0; |
| 868 | |
Yuval Mintz | fefb020 | 2016-05-11 16:36:19 +0300 | [diff] [blame] | 869 | switch ((enum qede_pci_private)id->driver_data) { |
| 870 | case QEDE_PRIVATE_VF: |
| 871 | if (debug & QED_LOG_VERBOSE_MASK) |
| 872 | dev_err(&pdev->dev, "Probing a VF\n"); |
| 873 | is_vf = true; |
| 874 | break; |
| 875 | default: |
| 876 | if (debug & QED_LOG_VERBOSE_MASK) |
| 877 | dev_err(&pdev->dev, "Probing a PF\n"); |
| 878 | } |
| 879 | |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 880 | qede_config_debug(debug, &dp_module, &dp_level); |
| 881 | |
Yuval Mintz | fefb020 | 2016-05-11 16:36:19 +0300 | [diff] [blame] | 882 | return __qede_probe(pdev, dp_module, dp_level, is_vf, |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 883 | QEDE_PROBE_NORMAL); |
| 884 | } |
| 885 | |
| 886 | enum qede_remove_mode { |
| 887 | QEDE_REMOVE_NORMAL, |
| 888 | }; |
| 889 | |
| 890 | static void __qede_remove(struct pci_dev *pdev, enum qede_remove_mode mode) |
| 891 | { |
| 892 | struct net_device *ndev = pci_get_drvdata(pdev); |
| 893 | struct qede_dev *edev = netdev_priv(ndev); |
| 894 | struct qed_dev *cdev = edev->cdev; |
| 895 | |
| 896 | DP_INFO(edev, "Starting qede_remove\n"); |
| 897 | |
Sudarsana Kalluru | 0d8e0aa | 2015-10-26 11:02:30 +0200 | [diff] [blame] | 898 | cancel_delayed_work_sync(&edev->sp_task); |
Ram Amrani | cee9fbd | 2016-10-01 21:59:56 +0300 | [diff] [blame] | 899 | |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 900 | unregister_netdev(ndev); |
| 901 | |
Ram Amrani | cee9fbd | 2016-10-01 21:59:56 +0300 | [diff] [blame] | 902 | qede_roce_dev_remove(edev); |
| 903 | |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 904 | edev->ops->common->set_power_state(cdev, PCI_D0); |
| 905 | |
| 906 | pci_set_drvdata(pdev, NULL); |
| 907 | |
Mintz, Yuval | 496e051 | 2016-11-29 16:47:09 +0200 | [diff] [blame] | 908 | /* Release edev's reference to XDP's bpf if such exist */ |
| 909 | if (edev->xdp_prog) |
| 910 | bpf_prog_put(edev->xdp_prog); |
| 911 | |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 912 | free_netdev(ndev); |
| 913 | |
| 914 | /* Use global ops since we've freed edev */ |
| 915 | qed_ops->common->slowpath_stop(cdev); |
Mintz, Yuval | 14d3964 | 2016-10-31 07:14:23 +0200 | [diff] [blame] | 916 | if (system_state == SYSTEM_POWER_OFF) |
| 917 | return; |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 918 | qed_ops->common->remove(cdev); |
| 919 | |
Yuval Mintz | 525ef5c | 2016-08-15 10:42:45 +0300 | [diff] [blame] | 920 | dev_info(&pdev->dev, "Ending qede_remove successfully\n"); |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 921 | } |
| 922 | |
| 923 | static void qede_remove(struct pci_dev *pdev) |
| 924 | { |
| 925 | __qede_remove(pdev, QEDE_REMOVE_NORMAL); |
| 926 | } |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 927 | |
Mintz, Yuval | 14d3964 | 2016-10-31 07:14:23 +0200 | [diff] [blame] | 928 | static void qede_shutdown(struct pci_dev *pdev) |
| 929 | { |
| 930 | __qede_remove(pdev, QEDE_REMOVE_NORMAL); |
| 931 | } |
| 932 | |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 933 | /* ------------------------------------------------------------------------- |
| 934 | * START OF LOAD / UNLOAD |
| 935 | * ------------------------------------------------------------------------- |
| 936 | */ |
| 937 | |
| 938 | static int qede_set_num_queues(struct qede_dev *edev) |
| 939 | { |
| 940 | int rc; |
| 941 | u16 rss_num; |
| 942 | |
| 943 | /* Setup queues according to possible resources*/ |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 944 | if (edev->req_queues) |
| 945 | rss_num = edev->req_queues; |
Sudarsana Kalluru | 8edf049 | 2015-11-30 12:25:01 +0200 | [diff] [blame] | 946 | else |
| 947 | rss_num = netif_get_num_default_rss_queues() * |
| 948 | edev->dev_info.common.num_hwfns; |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 949 | |
| 950 | rss_num = min_t(u16, QEDE_MAX_RSS_CNT(edev), rss_num); |
| 951 | |
| 952 | rc = edev->ops->common->set_fp_int(edev->cdev, rss_num); |
| 953 | if (rc > 0) { |
| 954 | /* Managed to request interrupts for our queues */ |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 955 | edev->num_queues = rc; |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 956 | DP_INFO(edev, "Managed %d [of %d] RSS queues\n", |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 957 | QEDE_QUEUE_CNT(edev), rss_num); |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 958 | rc = 0; |
| 959 | } |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 960 | |
| 961 | edev->fp_num_tx = edev->req_num_tx; |
| 962 | edev->fp_num_rx = edev->req_num_rx; |
| 963 | |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 964 | return rc; |
| 965 | } |
| 966 | |
| 967 | static void qede_free_mem_sb(struct qede_dev *edev, |
| 968 | struct qed_sb_info *sb_info) |
| 969 | { |
| 970 | if (sb_info->sb_virt) |
| 971 | dma_free_coherent(&edev->pdev->dev, sizeof(*sb_info->sb_virt), |
| 972 | (void *)sb_info->sb_virt, sb_info->sb_phys); |
| 973 | } |
| 974 | |
| 975 | /* This function allocates fast-path status block memory */ |
| 976 | static int qede_alloc_mem_sb(struct qede_dev *edev, |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 977 | struct qed_sb_info *sb_info, u16 sb_id) |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 978 | { |
| 979 | struct status_block *sb_virt; |
| 980 | dma_addr_t sb_phys; |
| 981 | int rc; |
| 982 | |
| 983 | sb_virt = dma_alloc_coherent(&edev->pdev->dev, |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 984 | sizeof(*sb_virt), &sb_phys, GFP_KERNEL); |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 985 | if (!sb_virt) { |
| 986 | DP_ERR(edev, "Status block allocation failed\n"); |
| 987 | return -ENOMEM; |
| 988 | } |
| 989 | |
| 990 | rc = edev->ops->common->sb_init(edev->cdev, sb_info, |
| 991 | sb_virt, sb_phys, sb_id, |
| 992 | QED_SB_TYPE_L2_QUEUE); |
| 993 | if (rc) { |
| 994 | DP_ERR(edev, "Status block initialization failed\n"); |
| 995 | dma_free_coherent(&edev->pdev->dev, sizeof(*sb_virt), |
| 996 | sb_virt, sb_phys); |
| 997 | return rc; |
| 998 | } |
| 999 | |
| 1000 | return 0; |
| 1001 | } |
| 1002 | |
| 1003 | static void qede_free_rx_buffers(struct qede_dev *edev, |
| 1004 | struct qede_rx_queue *rxq) |
| 1005 | { |
| 1006 | u16 i; |
| 1007 | |
| 1008 | for (i = rxq->sw_rx_cons; i != rxq->sw_rx_prod; i++) { |
| 1009 | struct sw_rx_data *rx_buf; |
Yuval Mintz | fc48b7a | 2016-02-15 13:22:35 -0500 | [diff] [blame] | 1010 | struct page *data; |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1011 | |
| 1012 | rx_buf = &rxq->sw_rx_ring[i & NUM_RX_BDS_MAX]; |
| 1013 | data = rx_buf->data; |
| 1014 | |
Yuval Mintz | fc48b7a | 2016-02-15 13:22:35 -0500 | [diff] [blame] | 1015 | dma_unmap_page(&edev->pdev->dev, |
Mintz, Yuval | cb6aeb0 | 2016-11-29 16:47:10 +0200 | [diff] [blame] | 1016 | rx_buf->mapping, PAGE_SIZE, rxq->data_direction); |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1017 | |
| 1018 | rx_buf->data = NULL; |
Yuval Mintz | fc48b7a | 2016-02-15 13:22:35 -0500 | [diff] [blame] | 1019 | __free_page(data); |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1020 | } |
| 1021 | } |
| 1022 | |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 1023 | static void qede_free_sge_mem(struct qede_dev *edev, struct qede_rx_queue *rxq) |
| 1024 | { |
Manish Chopra | 55482ed | 2016-03-04 12:35:06 -0500 | [diff] [blame] | 1025 | int i; |
| 1026 | |
| 1027 | if (edev->gro_disable) |
| 1028 | return; |
| 1029 | |
| 1030 | for (i = 0; i < ETH_TPA_MAX_AGGS_NUM; i++) { |
| 1031 | struct qede_agg_info *tpa_info = &rxq->tpa_info[i]; |
Mintz, Yuval | 01e2301 | 2016-11-29 16:47:00 +0200 | [diff] [blame] | 1032 | struct sw_rx_data *replace_buf = &tpa_info->buffer; |
Manish Chopra | 55482ed | 2016-03-04 12:35:06 -0500 | [diff] [blame] | 1033 | |
Manish Chopra | f86af2d | 2016-04-20 03:03:27 -0400 | [diff] [blame] | 1034 | if (replace_buf->data) { |
Manish Chopra | 55482ed | 2016-03-04 12:35:06 -0500 | [diff] [blame] | 1035 | dma_unmap_page(&edev->pdev->dev, |
Manish Chopra | 09ec8e7 | 2016-05-18 07:43:57 -0400 | [diff] [blame] | 1036 | replace_buf->mapping, |
Manish Chopra | 55482ed | 2016-03-04 12:35:06 -0500 | [diff] [blame] | 1037 | PAGE_SIZE, DMA_FROM_DEVICE); |
| 1038 | __free_page(replace_buf->data); |
| 1039 | } |
| 1040 | } |
| 1041 | } |
| 1042 | |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 1043 | static void qede_free_mem_rxq(struct qede_dev *edev, struct qede_rx_queue *rxq) |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1044 | { |
Manish Chopra | 55482ed | 2016-03-04 12:35:06 -0500 | [diff] [blame] | 1045 | qede_free_sge_mem(edev, rxq); |
| 1046 | |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1047 | /* Free rx buffers */ |
| 1048 | qede_free_rx_buffers(edev, rxq); |
| 1049 | |
| 1050 | /* Free the parallel SW ring */ |
| 1051 | kfree(rxq->sw_rx_ring); |
| 1052 | |
| 1053 | /* Free the real RQ ring used by FW */ |
| 1054 | edev->ops->common->chain_free(edev->cdev, &rxq->rx_bd_ring); |
| 1055 | edev->ops->common->chain_free(edev->cdev, &rxq->rx_comp_ring); |
| 1056 | } |
| 1057 | |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 1058 | static int qede_alloc_sge_mem(struct qede_dev *edev, struct qede_rx_queue *rxq) |
Manish Chopra | 55482ed | 2016-03-04 12:35:06 -0500 | [diff] [blame] | 1059 | { |
| 1060 | dma_addr_t mapping; |
| 1061 | int i; |
| 1062 | |
Mintz, Yuval | 496e051 | 2016-11-29 16:47:09 +0200 | [diff] [blame] | 1063 | /* Don't perform FW aggregations in case of XDP */ |
| 1064 | if (edev->xdp_prog) |
| 1065 | edev->gro_disable = 1; |
| 1066 | |
Manish Chopra | 55482ed | 2016-03-04 12:35:06 -0500 | [diff] [blame] | 1067 | if (edev->gro_disable) |
| 1068 | return 0; |
| 1069 | |
| 1070 | if (edev->ndev->mtu > PAGE_SIZE) { |
| 1071 | edev->gro_disable = 1; |
| 1072 | return 0; |
| 1073 | } |
| 1074 | |
| 1075 | for (i = 0; i < ETH_TPA_MAX_AGGS_NUM; i++) { |
| 1076 | struct qede_agg_info *tpa_info = &rxq->tpa_info[i]; |
Mintz, Yuval | 01e2301 | 2016-11-29 16:47:00 +0200 | [diff] [blame] | 1077 | struct sw_rx_data *replace_buf = &tpa_info->buffer; |
Manish Chopra | 55482ed | 2016-03-04 12:35:06 -0500 | [diff] [blame] | 1078 | |
| 1079 | replace_buf->data = alloc_pages(GFP_ATOMIC, 0); |
| 1080 | if (unlikely(!replace_buf->data)) { |
| 1081 | DP_NOTICE(edev, |
| 1082 | "Failed to allocate TPA skb pool [replacement buffer]\n"); |
| 1083 | goto err; |
| 1084 | } |
| 1085 | |
| 1086 | mapping = dma_map_page(&edev->pdev->dev, replace_buf->data, 0, |
Mintz, Yuval | 9512925 | 2016-11-02 16:36:46 +0200 | [diff] [blame] | 1087 | PAGE_SIZE, DMA_FROM_DEVICE); |
Manish Chopra | 55482ed | 2016-03-04 12:35:06 -0500 | [diff] [blame] | 1088 | if (unlikely(dma_mapping_error(&edev->pdev->dev, mapping))) { |
| 1089 | DP_NOTICE(edev, |
| 1090 | "Failed to map TPA replacement buffer\n"); |
| 1091 | goto err; |
| 1092 | } |
| 1093 | |
Manish Chopra | 09ec8e7 | 2016-05-18 07:43:57 -0400 | [diff] [blame] | 1094 | replace_buf->mapping = mapping; |
Mintz, Yuval | 01e2301 | 2016-11-29 16:47:00 +0200 | [diff] [blame] | 1095 | tpa_info->buffer.page_offset = 0; |
| 1096 | tpa_info->buffer_mapping = mapping; |
| 1097 | tpa_info->state = QEDE_AGG_STATE_NONE; |
Manish Chopra | 55482ed | 2016-03-04 12:35:06 -0500 | [diff] [blame] | 1098 | } |
| 1099 | |
| 1100 | return 0; |
| 1101 | err: |
| 1102 | qede_free_sge_mem(edev, rxq); |
| 1103 | edev->gro_disable = 1; |
| 1104 | return -ENOMEM; |
| 1105 | } |
| 1106 | |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1107 | /* This function allocates all memory needed per Rx queue */ |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 1108 | static int qede_alloc_mem_rxq(struct qede_dev *edev, struct qede_rx_queue *rxq) |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1109 | { |
Manish Chopra | f86af2d | 2016-04-20 03:03:27 -0400 | [diff] [blame] | 1110 | int i, rc, size; |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1111 | |
| 1112 | rxq->num_rx_buffers = edev->q_num_rx_buffers; |
| 1113 | |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 1114 | rxq->rx_buf_size = NET_IP_ALIGN + ETH_OVERHEAD + edev->ndev->mtu; |
| 1115 | |
Yuval Mintz | fc48b7a | 2016-02-15 13:22:35 -0500 | [diff] [blame] | 1116 | if (rxq->rx_buf_size > PAGE_SIZE) |
| 1117 | rxq->rx_buf_size = PAGE_SIZE; |
| 1118 | |
Mintz, Yuval | 496e051 | 2016-11-29 16:47:09 +0200 | [diff] [blame] | 1119 | /* Segment size to spilt a page in multiple equal parts, |
| 1120 | * unless XDP is used in which case we'd use the entire page. |
| 1121 | */ |
| 1122 | if (!edev->xdp_prog) |
| 1123 | rxq->rx_buf_seg_size = roundup_pow_of_two(rxq->rx_buf_size); |
| 1124 | else |
| 1125 | rxq->rx_buf_seg_size = PAGE_SIZE; |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1126 | |
| 1127 | /* Allocate the parallel driver ring for Rx buffers */ |
Yuval Mintz | fc48b7a | 2016-02-15 13:22:35 -0500 | [diff] [blame] | 1128 | size = sizeof(*rxq->sw_rx_ring) * RX_RING_SIZE; |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1129 | rxq->sw_rx_ring = kzalloc(size, GFP_KERNEL); |
| 1130 | if (!rxq->sw_rx_ring) { |
| 1131 | DP_ERR(edev, "Rx buffers ring allocation failed\n"); |
Manish Chopra | f86af2d | 2016-04-20 03:03:27 -0400 | [diff] [blame] | 1132 | rc = -ENOMEM; |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1133 | goto err; |
| 1134 | } |
| 1135 | |
| 1136 | /* Allocate FW Rx ring */ |
| 1137 | rc = edev->ops->common->chain_alloc(edev->cdev, |
| 1138 | QED_CHAIN_USE_TO_CONSUME_PRODUCE, |
| 1139 | QED_CHAIN_MODE_NEXT_PTR, |
Yuval Mintz | a91eb52 | 2016-06-03 14:35:32 +0300 | [diff] [blame] | 1140 | QED_CHAIN_CNT_TYPE_U16, |
Yuval Mintz | fc48b7a | 2016-02-15 13:22:35 -0500 | [diff] [blame] | 1141 | RX_RING_SIZE, |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1142 | sizeof(struct eth_rx_bd), |
| 1143 | &rxq->rx_bd_ring); |
| 1144 | |
| 1145 | if (rc) |
| 1146 | goto err; |
| 1147 | |
| 1148 | /* Allocate FW completion ring */ |
| 1149 | rc = edev->ops->common->chain_alloc(edev->cdev, |
| 1150 | QED_CHAIN_USE_TO_CONSUME, |
| 1151 | QED_CHAIN_MODE_PBL, |
Yuval Mintz | a91eb52 | 2016-06-03 14:35:32 +0300 | [diff] [blame] | 1152 | QED_CHAIN_CNT_TYPE_U16, |
Yuval Mintz | fc48b7a | 2016-02-15 13:22:35 -0500 | [diff] [blame] | 1153 | RX_RING_SIZE, |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1154 | sizeof(union eth_rx_cqe), |
| 1155 | &rxq->rx_comp_ring); |
| 1156 | if (rc) |
| 1157 | goto err; |
| 1158 | |
| 1159 | /* Allocate buffers for the Rx ring */ |
Mintz, Yuval | e3eef7e | 2017-01-01 13:57:04 +0200 | [diff] [blame] | 1160 | rxq->filled_buffers = 0; |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1161 | for (i = 0; i < rxq->num_rx_buffers; i++) { |
Mintz, Yuval | e3eef7e | 2017-01-01 13:57:04 +0200 | [diff] [blame] | 1162 | rc = qede_alloc_rx_buffer(rxq, false); |
Manish Chopra | f86af2d | 2016-04-20 03:03:27 -0400 | [diff] [blame] | 1163 | if (rc) { |
| 1164 | DP_ERR(edev, |
| 1165 | "Rx buffers allocation failed at index %d\n", i); |
| 1166 | goto err; |
| 1167 | } |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1168 | } |
| 1169 | |
Manish Chopra | f86af2d | 2016-04-20 03:03:27 -0400 | [diff] [blame] | 1170 | rc = qede_alloc_sge_mem(edev, rxq); |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1171 | err: |
Manish Chopra | f86af2d | 2016-04-20 03:03:27 -0400 | [diff] [blame] | 1172 | return rc; |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1173 | } |
| 1174 | |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 1175 | static void qede_free_mem_txq(struct qede_dev *edev, struct qede_tx_queue *txq) |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1176 | { |
| 1177 | /* Free the parallel SW ring */ |
Mintz, Yuval | cb6aeb0 | 2016-11-29 16:47:10 +0200 | [diff] [blame] | 1178 | if (txq->is_xdp) |
| 1179 | kfree(txq->sw_tx_ring.pages); |
| 1180 | else |
| 1181 | kfree(txq->sw_tx_ring.skbs); |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1182 | |
| 1183 | /* Free the real RQ ring used by FW */ |
| 1184 | edev->ops->common->chain_free(edev->cdev, &txq->tx_pbl); |
| 1185 | } |
| 1186 | |
| 1187 | /* This function allocates all memory needed per Tx queue */ |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 1188 | static int qede_alloc_mem_txq(struct qede_dev *edev, struct qede_tx_queue *txq) |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1189 | { |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1190 | union eth_tx_bd_types *p_virt; |
Mintz, Yuval | cb6aeb0 | 2016-11-29 16:47:10 +0200 | [diff] [blame] | 1191 | int size, rc; |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1192 | |
| 1193 | txq->num_tx_buffers = edev->q_num_tx_buffers; |
| 1194 | |
| 1195 | /* Allocate the parallel driver ring for Tx buffers */ |
Mintz, Yuval | cb6aeb0 | 2016-11-29 16:47:10 +0200 | [diff] [blame] | 1196 | if (txq->is_xdp) { |
| 1197 | size = sizeof(*txq->sw_tx_ring.pages) * TX_RING_SIZE; |
| 1198 | txq->sw_tx_ring.pages = kzalloc(size, GFP_KERNEL); |
| 1199 | if (!txq->sw_tx_ring.pages) |
| 1200 | goto err; |
| 1201 | } else { |
| 1202 | size = sizeof(*txq->sw_tx_ring.skbs) * TX_RING_SIZE; |
| 1203 | txq->sw_tx_ring.skbs = kzalloc(size, GFP_KERNEL); |
| 1204 | if (!txq->sw_tx_ring.skbs) |
| 1205 | goto err; |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1206 | } |
| 1207 | |
| 1208 | rc = edev->ops->common->chain_alloc(edev->cdev, |
| 1209 | QED_CHAIN_USE_TO_CONSUME_PRODUCE, |
| 1210 | QED_CHAIN_MODE_PBL, |
Yuval Mintz | a91eb52 | 2016-06-03 14:35:32 +0300 | [diff] [blame] | 1211 | QED_CHAIN_CNT_TYPE_U16, |
Mintz, Yuval | 087892d | 2016-10-29 17:04:35 +0300 | [diff] [blame] | 1212 | TX_RING_SIZE, |
Yuval Mintz | a91eb52 | 2016-06-03 14:35:32 +0300 | [diff] [blame] | 1213 | sizeof(*p_virt), &txq->tx_pbl); |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1214 | if (rc) |
| 1215 | goto err; |
| 1216 | |
| 1217 | return 0; |
| 1218 | |
| 1219 | err: |
| 1220 | qede_free_mem_txq(edev, txq); |
| 1221 | return -ENOMEM; |
| 1222 | } |
| 1223 | |
| 1224 | /* This function frees all memory of a single fp */ |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 1225 | static void qede_free_mem_fp(struct qede_dev *edev, struct qede_fastpath *fp) |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1226 | { |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1227 | qede_free_mem_sb(edev, fp->sb_info); |
| 1228 | |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 1229 | if (fp->type & QEDE_FASTPATH_RX) |
| 1230 | qede_free_mem_rxq(edev, fp->rxq); |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1231 | |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 1232 | if (fp->type & QEDE_FASTPATH_TX) |
Mintz, Yuval | 80439a1 | 2016-11-29 16:47:02 +0200 | [diff] [blame] | 1233 | qede_free_mem_txq(edev, fp->txq); |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1234 | } |
| 1235 | |
| 1236 | /* This function allocates all memory needed for a single fp (i.e. an entity |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 1237 | * which contains status block, one rx queue and/or multiple per-TC tx queues. |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1238 | */ |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 1239 | static int qede_alloc_mem_fp(struct qede_dev *edev, struct qede_fastpath *fp) |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1240 | { |
Mintz, Yuval | cb6aeb0 | 2016-11-29 16:47:10 +0200 | [diff] [blame] | 1241 | int rc = 0; |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1242 | |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 1243 | rc = qede_alloc_mem_sb(edev, fp->sb_info, fp->id); |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1244 | if (rc) |
Mintz, Yuval | cb6aeb0 | 2016-11-29 16:47:10 +0200 | [diff] [blame] | 1245 | goto out; |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1246 | |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 1247 | if (fp->type & QEDE_FASTPATH_RX) { |
| 1248 | rc = qede_alloc_mem_rxq(edev, fp->rxq); |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1249 | if (rc) |
Mintz, Yuval | cb6aeb0 | 2016-11-29 16:47:10 +0200 | [diff] [blame] | 1250 | goto out; |
| 1251 | } |
| 1252 | |
| 1253 | if (fp->type & QEDE_FASTPATH_XDP) { |
| 1254 | rc = qede_alloc_mem_txq(edev, fp->xdp_tx); |
| 1255 | if (rc) |
| 1256 | goto out; |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1257 | } |
| 1258 | |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 1259 | if (fp->type & QEDE_FASTPATH_TX) { |
Mintz, Yuval | 80439a1 | 2016-11-29 16:47:02 +0200 | [diff] [blame] | 1260 | rc = qede_alloc_mem_txq(edev, fp->txq); |
| 1261 | if (rc) |
Mintz, Yuval | cb6aeb0 | 2016-11-29 16:47:10 +0200 | [diff] [blame] | 1262 | goto out; |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 1263 | } |
| 1264 | |
Mintz, Yuval | cb6aeb0 | 2016-11-29 16:47:10 +0200 | [diff] [blame] | 1265 | out: |
Manish Chopra | f86af2d | 2016-04-20 03:03:27 -0400 | [diff] [blame] | 1266 | return rc; |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1267 | } |
| 1268 | |
| 1269 | static void qede_free_mem_load(struct qede_dev *edev) |
| 1270 | { |
| 1271 | int i; |
| 1272 | |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 1273 | for_each_queue(i) { |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1274 | struct qede_fastpath *fp = &edev->fp_array[i]; |
| 1275 | |
| 1276 | qede_free_mem_fp(edev, fp); |
| 1277 | } |
| 1278 | } |
| 1279 | |
| 1280 | /* This function allocates all qede memory at NIC load. */ |
| 1281 | static int qede_alloc_mem_load(struct qede_dev *edev) |
| 1282 | { |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 1283 | int rc = 0, queue_id; |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1284 | |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 1285 | for (queue_id = 0; queue_id < QEDE_QUEUE_CNT(edev); queue_id++) { |
| 1286 | struct qede_fastpath *fp = &edev->fp_array[queue_id]; |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1287 | |
| 1288 | rc = qede_alloc_mem_fp(edev, fp); |
Manish Chopra | f86af2d | 2016-04-20 03:03:27 -0400 | [diff] [blame] | 1289 | if (rc) { |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1290 | DP_ERR(edev, |
Manish Chopra | f86af2d | 2016-04-20 03:03:27 -0400 | [diff] [blame] | 1291 | "Failed to allocate memory for fastpath - rss id = %d\n", |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 1292 | queue_id); |
Manish Chopra | f86af2d | 2016-04-20 03:03:27 -0400 | [diff] [blame] | 1293 | qede_free_mem_load(edev); |
| 1294 | return rc; |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1295 | } |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1296 | } |
| 1297 | |
| 1298 | return 0; |
| 1299 | } |
| 1300 | |
| 1301 | /* This function inits fp content and resets the SB, RXQ and TXQ structures */ |
| 1302 | static void qede_init_fp(struct qede_dev *edev) |
| 1303 | { |
Mintz, Yuval | 80439a1 | 2016-11-29 16:47:02 +0200 | [diff] [blame] | 1304 | int queue_id, rxq_index = 0, txq_index = 0; |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1305 | struct qede_fastpath *fp; |
| 1306 | |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 1307 | for_each_queue(queue_id) { |
| 1308 | fp = &edev->fp_array[queue_id]; |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1309 | |
| 1310 | fp->edev = edev; |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 1311 | fp->id = queue_id; |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1312 | |
Mintz, Yuval | cb6aeb0 | 2016-11-29 16:47:10 +0200 | [diff] [blame] | 1313 | if (fp->type & QEDE_FASTPATH_XDP) { |
| 1314 | fp->xdp_tx->index = QEDE_TXQ_IDX_TO_XDP(edev, |
| 1315 | rxq_index); |
| 1316 | fp->xdp_tx->is_xdp = 1; |
| 1317 | } |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1318 | |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 1319 | if (fp->type & QEDE_FASTPATH_RX) { |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 1320 | fp->rxq->rxq_id = rxq_index++; |
Mintz, Yuval | cb6aeb0 | 2016-11-29 16:47:10 +0200 | [diff] [blame] | 1321 | |
| 1322 | /* Determine how to map buffers for this queue */ |
| 1323 | if (fp->type & QEDE_FASTPATH_XDP) |
| 1324 | fp->rxq->data_direction = DMA_BIDIRECTIONAL; |
| 1325 | else |
| 1326 | fp->rxq->data_direction = DMA_FROM_DEVICE; |
Mintz, Yuval | 9eb2235 | 2016-11-29 16:47:08 +0200 | [diff] [blame] | 1327 | fp->rxq->dev = &edev->pdev->dev; |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 1328 | } |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1329 | |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 1330 | if (fp->type & QEDE_FASTPATH_TX) { |
Mintz, Yuval | 80439a1 | 2016-11-29 16:47:02 +0200 | [diff] [blame] | 1331 | fp->txq->index = txq_index++; |
| 1332 | if (edev->dev_info.is_legacy) |
| 1333 | fp->txq->is_legacy = 1; |
Mintz, Yuval | 9eb2235 | 2016-11-29 16:47:08 +0200 | [diff] [blame] | 1334 | fp->txq->dev = &edev->pdev->dev; |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1335 | } |
| 1336 | |
| 1337 | snprintf(fp->name, sizeof(fp->name), "%s-fp-%d", |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 1338 | edev->ndev->name, queue_id); |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1339 | } |
Manish Chopra | 55482ed | 2016-03-04 12:35:06 -0500 | [diff] [blame] | 1340 | |
| 1341 | edev->gro_disable = !(edev->ndev->features & NETIF_F_GRO); |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1342 | } |
| 1343 | |
| 1344 | static int qede_set_real_num_queues(struct qede_dev *edev) |
| 1345 | { |
| 1346 | int rc = 0; |
| 1347 | |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 1348 | rc = netif_set_real_num_tx_queues(edev->ndev, QEDE_TSS_COUNT(edev)); |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1349 | if (rc) { |
| 1350 | DP_NOTICE(edev, "Failed to set real number of Tx queues\n"); |
| 1351 | return rc; |
| 1352 | } |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 1353 | |
| 1354 | rc = netif_set_real_num_rx_queues(edev->ndev, QEDE_RSS_COUNT(edev)); |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1355 | if (rc) { |
| 1356 | DP_NOTICE(edev, "Failed to set real number of Rx queues\n"); |
| 1357 | return rc; |
| 1358 | } |
| 1359 | |
| 1360 | return 0; |
| 1361 | } |
| 1362 | |
| 1363 | static void qede_napi_disable_remove(struct qede_dev *edev) |
| 1364 | { |
| 1365 | int i; |
| 1366 | |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 1367 | for_each_queue(i) { |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1368 | napi_disable(&edev->fp_array[i].napi); |
| 1369 | |
| 1370 | netif_napi_del(&edev->fp_array[i].napi); |
| 1371 | } |
| 1372 | } |
| 1373 | |
| 1374 | static void qede_napi_add_enable(struct qede_dev *edev) |
| 1375 | { |
| 1376 | int i; |
| 1377 | |
| 1378 | /* Add NAPI objects */ |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 1379 | for_each_queue(i) { |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1380 | netif_napi_add(edev->ndev, &edev->fp_array[i].napi, |
| 1381 | qede_poll, NAPI_POLL_WEIGHT); |
| 1382 | napi_enable(&edev->fp_array[i].napi); |
| 1383 | } |
| 1384 | } |
| 1385 | |
| 1386 | static void qede_sync_free_irqs(struct qede_dev *edev) |
| 1387 | { |
| 1388 | int i; |
| 1389 | |
| 1390 | for (i = 0; i < edev->int_info.used_cnt; i++) { |
| 1391 | if (edev->int_info.msix_cnt) { |
| 1392 | synchronize_irq(edev->int_info.msix[i].vector); |
| 1393 | free_irq(edev->int_info.msix[i].vector, |
| 1394 | &edev->fp_array[i]); |
| 1395 | } else { |
| 1396 | edev->ops->common->simd_handler_clean(edev->cdev, i); |
| 1397 | } |
| 1398 | } |
| 1399 | |
| 1400 | edev->int_info.used_cnt = 0; |
| 1401 | } |
| 1402 | |
| 1403 | static int qede_req_msix_irqs(struct qede_dev *edev) |
| 1404 | { |
| 1405 | int i, rc; |
| 1406 | |
| 1407 | /* Sanitize number of interrupts == number of prepared RSS queues */ |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 1408 | if (QEDE_QUEUE_CNT(edev) > edev->int_info.msix_cnt) { |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1409 | DP_ERR(edev, |
| 1410 | "Interrupt mismatch: %d RSS queues > %d MSI-x vectors\n", |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 1411 | QEDE_QUEUE_CNT(edev), edev->int_info.msix_cnt); |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1412 | return -EINVAL; |
| 1413 | } |
| 1414 | |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 1415 | for (i = 0; i < QEDE_QUEUE_CNT(edev); i++) { |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1416 | rc = request_irq(edev->int_info.msix[i].vector, |
| 1417 | qede_msix_fp_int, 0, edev->fp_array[i].name, |
| 1418 | &edev->fp_array[i]); |
| 1419 | if (rc) { |
| 1420 | DP_ERR(edev, "Request fp %d irq failed\n", i); |
| 1421 | qede_sync_free_irqs(edev); |
| 1422 | return rc; |
| 1423 | } |
| 1424 | DP_VERBOSE(edev, NETIF_MSG_INTR, |
| 1425 | "Requested fp irq for %s [entry %d]. Cookie is at %p\n", |
| 1426 | edev->fp_array[i].name, i, |
| 1427 | &edev->fp_array[i]); |
| 1428 | edev->int_info.used_cnt++; |
| 1429 | } |
| 1430 | |
| 1431 | return 0; |
| 1432 | } |
| 1433 | |
| 1434 | static void qede_simd_fp_handler(void *cookie) |
| 1435 | { |
| 1436 | struct qede_fastpath *fp = (struct qede_fastpath *)cookie; |
| 1437 | |
| 1438 | napi_schedule_irqoff(&fp->napi); |
| 1439 | } |
| 1440 | |
| 1441 | static int qede_setup_irqs(struct qede_dev *edev) |
| 1442 | { |
| 1443 | int i, rc = 0; |
| 1444 | |
| 1445 | /* Learn Interrupt configuration */ |
| 1446 | rc = edev->ops->common->get_fp_int(edev->cdev, &edev->int_info); |
| 1447 | if (rc) |
| 1448 | return rc; |
| 1449 | |
| 1450 | if (edev->int_info.msix_cnt) { |
| 1451 | rc = qede_req_msix_irqs(edev); |
| 1452 | if (rc) |
| 1453 | return rc; |
| 1454 | edev->ndev->irq = edev->int_info.msix[0].vector; |
| 1455 | } else { |
| 1456 | const struct qed_common_ops *ops; |
| 1457 | |
| 1458 | /* qed should learn receive the RSS ids and callbacks */ |
| 1459 | ops = edev->ops->common; |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 1460 | for (i = 0; i < QEDE_QUEUE_CNT(edev); i++) |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1461 | ops->simd_handler_config(edev->cdev, |
| 1462 | &edev->fp_array[i], i, |
| 1463 | qede_simd_fp_handler); |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 1464 | edev->int_info.used_cnt = QEDE_QUEUE_CNT(edev); |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1465 | } |
| 1466 | return 0; |
| 1467 | } |
| 1468 | |
| 1469 | static int qede_drain_txq(struct qede_dev *edev, |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 1470 | struct qede_tx_queue *txq, bool allow_drain) |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1471 | { |
| 1472 | int rc, cnt = 1000; |
| 1473 | |
| 1474 | while (txq->sw_tx_cons != txq->sw_tx_prod) { |
| 1475 | if (!cnt) { |
| 1476 | if (allow_drain) { |
| 1477 | DP_NOTICE(edev, |
| 1478 | "Tx queue[%d] is stuck, requesting MCP to drain\n", |
| 1479 | txq->index); |
| 1480 | rc = edev->ops->common->drain(edev->cdev); |
| 1481 | if (rc) |
| 1482 | return rc; |
| 1483 | return qede_drain_txq(edev, txq, false); |
| 1484 | } |
| 1485 | DP_NOTICE(edev, |
| 1486 | "Timeout waiting for tx queue[%d]: PROD=%d, CONS=%d\n", |
| 1487 | txq->index, txq->sw_tx_prod, |
| 1488 | txq->sw_tx_cons); |
| 1489 | return -ENODEV; |
| 1490 | } |
| 1491 | cnt--; |
| 1492 | usleep_range(1000, 2000); |
| 1493 | barrier(); |
| 1494 | } |
| 1495 | |
| 1496 | /* FW finished processing, wait for HW to transmit all tx packets */ |
| 1497 | usleep_range(1000, 2000); |
| 1498 | |
| 1499 | return 0; |
| 1500 | } |
| 1501 | |
Mintz, Yuval | 3da7a37 | 2016-11-29 16:47:06 +0200 | [diff] [blame] | 1502 | static int qede_stop_txq(struct qede_dev *edev, |
| 1503 | struct qede_tx_queue *txq, int rss_id) |
| 1504 | { |
| 1505 | return edev->ops->q_tx_stop(edev->cdev, rss_id, txq->handle); |
| 1506 | } |
| 1507 | |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1508 | static int qede_stop_queues(struct qede_dev *edev) |
| 1509 | { |
Mintz, Yuval | f29ffdb | 2017-01-01 13:57:07 +0200 | [diff] [blame^] | 1510 | struct qed_update_vport_params *vport_update_params; |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1511 | struct qed_dev *cdev = edev->cdev; |
Mintz, Yuval | 80439a1 | 2016-11-29 16:47:02 +0200 | [diff] [blame] | 1512 | struct qede_fastpath *fp; |
| 1513 | int rc, i; |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1514 | |
| 1515 | /* Disable the vport */ |
Mintz, Yuval | f29ffdb | 2017-01-01 13:57:07 +0200 | [diff] [blame^] | 1516 | vport_update_params = vzalloc(sizeof(*vport_update_params)); |
| 1517 | if (!vport_update_params) |
| 1518 | return -ENOMEM; |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1519 | |
Mintz, Yuval | f29ffdb | 2017-01-01 13:57:07 +0200 | [diff] [blame^] | 1520 | vport_update_params->vport_id = 0; |
| 1521 | vport_update_params->update_vport_active_flg = 1; |
| 1522 | vport_update_params->vport_active_flg = 0; |
| 1523 | vport_update_params->update_rss_flg = 0; |
| 1524 | |
| 1525 | rc = edev->ops->vport_update(cdev, vport_update_params); |
| 1526 | vfree(vport_update_params); |
| 1527 | |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1528 | if (rc) { |
| 1529 | DP_ERR(edev, "Failed to update vport\n"); |
| 1530 | return rc; |
| 1531 | } |
| 1532 | |
| 1533 | /* Flush Tx queues. If needed, request drain from MCP */ |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 1534 | for_each_queue(i) { |
Mintz, Yuval | 80439a1 | 2016-11-29 16:47:02 +0200 | [diff] [blame] | 1535 | fp = &edev->fp_array[i]; |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1536 | |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 1537 | if (fp->type & QEDE_FASTPATH_TX) { |
Mintz, Yuval | 80439a1 | 2016-11-29 16:47:02 +0200 | [diff] [blame] | 1538 | rc = qede_drain_txq(edev, fp->txq, true); |
| 1539 | if (rc) |
| 1540 | return rc; |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1541 | } |
Mintz, Yuval | cb6aeb0 | 2016-11-29 16:47:10 +0200 | [diff] [blame] | 1542 | |
| 1543 | if (fp->type & QEDE_FASTPATH_XDP) { |
| 1544 | rc = qede_drain_txq(edev, fp->xdp_tx, true); |
| 1545 | if (rc) |
| 1546 | return rc; |
| 1547 | } |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1548 | } |
| 1549 | |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 1550 | /* Stop all Queues in reverse order */ |
| 1551 | for (i = QEDE_QUEUE_CNT(edev) - 1; i >= 0; i--) { |
Mintz, Yuval | 80439a1 | 2016-11-29 16:47:02 +0200 | [diff] [blame] | 1552 | fp = &edev->fp_array[i]; |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1553 | |
Mintz, Yuval | 80439a1 | 2016-11-29 16:47:02 +0200 | [diff] [blame] | 1554 | /* Stop the Tx Queue(s) */ |
| 1555 | if (fp->type & QEDE_FASTPATH_TX) { |
Mintz, Yuval | 3da7a37 | 2016-11-29 16:47:06 +0200 | [diff] [blame] | 1556 | rc = qede_stop_txq(edev, fp->txq, i); |
| 1557 | if (rc) |
| 1558 | return rc; |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1559 | } |
| 1560 | |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 1561 | /* Stop the Rx Queue */ |
Mintz, Yuval | 80439a1 | 2016-11-29 16:47:02 +0200 | [diff] [blame] | 1562 | if (fp->type & QEDE_FASTPATH_RX) { |
Mintz, Yuval | 3da7a37 | 2016-11-29 16:47:06 +0200 | [diff] [blame] | 1563 | rc = edev->ops->q_rx_stop(cdev, i, fp->rxq->handle); |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 1564 | if (rc) { |
| 1565 | DP_ERR(edev, "Failed to stop RXQ #%d\n", i); |
| 1566 | return rc; |
| 1567 | } |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1568 | } |
Mintz, Yuval | 496e051 | 2016-11-29 16:47:09 +0200 | [diff] [blame] | 1569 | |
Mintz, Yuval | cb6aeb0 | 2016-11-29 16:47:10 +0200 | [diff] [blame] | 1570 | /* Stop the XDP forwarding queue */ |
| 1571 | if (fp->type & QEDE_FASTPATH_XDP) { |
| 1572 | rc = qede_stop_txq(edev, fp->xdp_tx, i); |
| 1573 | if (rc) |
| 1574 | return rc; |
| 1575 | |
Mintz, Yuval | 496e051 | 2016-11-29 16:47:09 +0200 | [diff] [blame] | 1576 | bpf_prog_put(fp->rxq->xdp_prog); |
Mintz, Yuval | cb6aeb0 | 2016-11-29 16:47:10 +0200 | [diff] [blame] | 1577 | } |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1578 | } |
| 1579 | |
| 1580 | /* Stop the vport */ |
| 1581 | rc = edev->ops->vport_stop(cdev, 0); |
| 1582 | if (rc) |
| 1583 | DP_ERR(edev, "Failed to stop VPORT\n"); |
| 1584 | |
| 1585 | return rc; |
| 1586 | } |
| 1587 | |
Mintz, Yuval | 3da7a37 | 2016-11-29 16:47:06 +0200 | [diff] [blame] | 1588 | static int qede_start_txq(struct qede_dev *edev, |
| 1589 | struct qede_fastpath *fp, |
| 1590 | struct qede_tx_queue *txq, u8 rss_id, u16 sb_idx) |
| 1591 | { |
| 1592 | dma_addr_t phys_table = qed_chain_get_pbl_phys(&txq->tx_pbl); |
| 1593 | u32 page_cnt = qed_chain_get_page_cnt(&txq->tx_pbl); |
| 1594 | struct qed_queue_start_common_params params; |
| 1595 | struct qed_txq_start_ret_params ret_params; |
| 1596 | int rc; |
| 1597 | |
| 1598 | memset(¶ms, 0, sizeof(params)); |
| 1599 | memset(&ret_params, 0, sizeof(ret_params)); |
| 1600 | |
Mintz, Yuval | cb6aeb0 | 2016-11-29 16:47:10 +0200 | [diff] [blame] | 1601 | /* Let the XDP queue share the queue-zone with one of the regular txq. |
| 1602 | * We don't really care about its coalescing. |
| 1603 | */ |
| 1604 | if (txq->is_xdp) |
| 1605 | params.queue_id = QEDE_TXQ_XDP_TO_IDX(edev, txq); |
| 1606 | else |
| 1607 | params.queue_id = txq->index; |
| 1608 | |
Mintz, Yuval | 3da7a37 | 2016-11-29 16:47:06 +0200 | [diff] [blame] | 1609 | params.sb = fp->sb_info->igu_sb_id; |
| 1610 | params.sb_idx = sb_idx; |
| 1611 | |
| 1612 | rc = edev->ops->q_tx_start(edev->cdev, rss_id, ¶ms, phys_table, |
| 1613 | page_cnt, &ret_params); |
| 1614 | if (rc) { |
| 1615 | DP_ERR(edev, "Start TXQ #%d failed %d\n", txq->index, rc); |
| 1616 | return rc; |
| 1617 | } |
| 1618 | |
| 1619 | txq->doorbell_addr = ret_params.p_doorbell; |
| 1620 | txq->handle = ret_params.p_handle; |
| 1621 | |
| 1622 | /* Determine the FW consumer address associated */ |
| 1623 | txq->hw_cons_ptr = &fp->sb_info->sb_virt->pi_array[sb_idx]; |
| 1624 | |
| 1625 | /* Prepare the doorbell parameters */ |
| 1626 | SET_FIELD(txq->tx_db.data.params, ETH_DB_DATA_DEST, DB_DEST_XCM); |
| 1627 | SET_FIELD(txq->tx_db.data.params, ETH_DB_DATA_AGG_CMD, DB_AGG_CMD_SET); |
| 1628 | SET_FIELD(txq->tx_db.data.params, ETH_DB_DATA_AGG_VAL_SEL, |
| 1629 | DQ_XCM_ETH_TX_BD_PROD_CMD); |
| 1630 | txq->tx_db.data.agg_flags = DQ_XCM_ETH_DQ_CF_CMD; |
| 1631 | |
| 1632 | return rc; |
| 1633 | } |
| 1634 | |
Yuval Mintz | a0d26d5 | 2016-06-19 15:18:13 +0300 | [diff] [blame] | 1635 | static int qede_start_queues(struct qede_dev *edev, bool clear_stats) |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1636 | { |
Manish Chopra | 088c861 | 2016-03-04 12:35:05 -0500 | [diff] [blame] | 1637 | int vlan_removal_en = 1; |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1638 | struct qed_dev *cdev = edev->cdev; |
Yuval Mintz | fefb020 | 2016-05-11 16:36:19 +0300 | [diff] [blame] | 1639 | struct qed_dev_info *qed_info = &edev->dev_info.common; |
Mintz, Yuval | f29ffdb | 2017-01-01 13:57:07 +0200 | [diff] [blame^] | 1640 | struct qed_update_vport_params *vport_update_params; |
| 1641 | struct qed_queue_start_common_params q_params; |
Manish Chopra | 088c861 | 2016-03-04 12:35:05 -0500 | [diff] [blame] | 1642 | struct qed_start_vport_params start = {0}; |
Mintz, Yuval | 80439a1 | 2016-11-29 16:47:02 +0200 | [diff] [blame] | 1643 | int rc, i; |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1644 | |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 1645 | if (!edev->num_queues) { |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1646 | DP_ERR(edev, |
| 1647 | "Cannot update V-VPORT as active as there are no Rx queues\n"); |
| 1648 | return -EINVAL; |
| 1649 | } |
| 1650 | |
Mintz, Yuval | f29ffdb | 2017-01-01 13:57:07 +0200 | [diff] [blame^] | 1651 | vport_update_params = vzalloc(sizeof(*vport_update_params)); |
| 1652 | if (!vport_update_params) |
| 1653 | return -ENOMEM; |
| 1654 | |
Manish Chopra | 55482ed | 2016-03-04 12:35:06 -0500 | [diff] [blame] | 1655 | start.gro_enable = !edev->gro_disable; |
Manish Chopra | 088c861 | 2016-03-04 12:35:05 -0500 | [diff] [blame] | 1656 | start.mtu = edev->ndev->mtu; |
| 1657 | start.vport_id = 0; |
| 1658 | start.drop_ttl0 = true; |
| 1659 | start.remove_inner_vlan = vlan_removal_en; |
Yuval Mintz | 7f7a144 | 2016-07-27 14:45:22 +0300 | [diff] [blame] | 1660 | start.clear_stats = clear_stats; |
Manish Chopra | 088c861 | 2016-03-04 12:35:05 -0500 | [diff] [blame] | 1661 | |
| 1662 | rc = edev->ops->vport_start(cdev, &start); |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1663 | |
| 1664 | if (rc) { |
| 1665 | DP_ERR(edev, "Start V-PORT failed %d\n", rc); |
Mintz, Yuval | f29ffdb | 2017-01-01 13:57:07 +0200 | [diff] [blame^] | 1666 | goto out; |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1667 | } |
| 1668 | |
| 1669 | DP_VERBOSE(edev, NETIF_MSG_IFUP, |
| 1670 | "Start vport ramrod passed, vport_id = %d, MTU = %d, vlan_removal_en = %d\n", |
Manish Chopra | 088c861 | 2016-03-04 12:35:05 -0500 | [diff] [blame] | 1671 | start.vport_id, edev->ndev->mtu + 0xe, vlan_removal_en); |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1672 | |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 1673 | for_each_queue(i) { |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1674 | struct qede_fastpath *fp = &edev->fp_array[i]; |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 1675 | dma_addr_t p_phys_table; |
| 1676 | u32 page_cnt; |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1677 | |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 1678 | if (fp->type & QEDE_FASTPATH_RX) { |
Mintz, Yuval | 3da7a37 | 2016-11-29 16:47:06 +0200 | [diff] [blame] | 1679 | struct qed_rxq_start_ret_params ret_params; |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 1680 | struct qede_rx_queue *rxq = fp->rxq; |
| 1681 | __le16 *val; |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1682 | |
Mintz, Yuval | 3da7a37 | 2016-11-29 16:47:06 +0200 | [diff] [blame] | 1683 | memset(&ret_params, 0, sizeof(ret_params)); |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1684 | memset(&q_params, 0, sizeof(q_params)); |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 1685 | q_params.queue_id = rxq->rxq_id; |
| 1686 | q_params.vport_id = 0; |
| 1687 | q_params.sb = fp->sb_info->igu_sb_id; |
| 1688 | q_params.sb_idx = RX_PI; |
| 1689 | |
| 1690 | p_phys_table = |
| 1691 | qed_chain_get_pbl_phys(&rxq->rx_comp_ring); |
| 1692 | page_cnt = qed_chain_get_page_cnt(&rxq->rx_comp_ring); |
| 1693 | |
Mintz, Yuval | 3da7a37 | 2016-11-29 16:47:06 +0200 | [diff] [blame] | 1694 | rc = edev->ops->q_rx_start(cdev, i, &q_params, |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 1695 | rxq->rx_buf_size, |
| 1696 | rxq->rx_bd_ring.p_phys_addr, |
| 1697 | p_phys_table, |
Mintz, Yuval | 3da7a37 | 2016-11-29 16:47:06 +0200 | [diff] [blame] | 1698 | page_cnt, &ret_params); |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 1699 | if (rc) { |
| 1700 | DP_ERR(edev, "Start RXQ #%d failed %d\n", i, |
| 1701 | rc); |
Mintz, Yuval | f29ffdb | 2017-01-01 13:57:07 +0200 | [diff] [blame^] | 1702 | goto out; |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 1703 | } |
| 1704 | |
Mintz, Yuval | 3da7a37 | 2016-11-29 16:47:06 +0200 | [diff] [blame] | 1705 | /* Use the return parameters */ |
| 1706 | rxq->hw_rxq_prod_addr = ret_params.p_prod; |
| 1707 | rxq->handle = ret_params.p_handle; |
| 1708 | |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 1709 | val = &fp->sb_info->sb_virt->pi_array[RX_PI]; |
| 1710 | rxq->hw_cons_ptr = val; |
| 1711 | |
| 1712 | qede_update_rx_prod(edev, rxq); |
| 1713 | } |
| 1714 | |
Mintz, Yuval | 496e051 | 2016-11-29 16:47:09 +0200 | [diff] [blame] | 1715 | if (fp->type & QEDE_FASTPATH_XDP) { |
Mintz, Yuval | cb6aeb0 | 2016-11-29 16:47:10 +0200 | [diff] [blame] | 1716 | rc = qede_start_txq(edev, fp, fp->xdp_tx, i, XDP_PI); |
| 1717 | if (rc) |
Mintz, Yuval | f29ffdb | 2017-01-01 13:57:07 +0200 | [diff] [blame^] | 1718 | goto out; |
Mintz, Yuval | cb6aeb0 | 2016-11-29 16:47:10 +0200 | [diff] [blame] | 1719 | |
Mintz, Yuval | 496e051 | 2016-11-29 16:47:09 +0200 | [diff] [blame] | 1720 | fp->rxq->xdp_prog = bpf_prog_add(edev->xdp_prog, 1); |
| 1721 | if (IS_ERR(fp->rxq->xdp_prog)) { |
| 1722 | rc = PTR_ERR(fp->rxq->xdp_prog); |
| 1723 | fp->rxq->xdp_prog = NULL; |
Mintz, Yuval | f29ffdb | 2017-01-01 13:57:07 +0200 | [diff] [blame^] | 1724 | goto out; |
Mintz, Yuval | 496e051 | 2016-11-29 16:47:09 +0200 | [diff] [blame] | 1725 | } |
| 1726 | } |
| 1727 | |
Mintz, Yuval | 80439a1 | 2016-11-29 16:47:02 +0200 | [diff] [blame] | 1728 | if (fp->type & QEDE_FASTPATH_TX) { |
Mintz, Yuval | 3da7a37 | 2016-11-29 16:47:06 +0200 | [diff] [blame] | 1729 | rc = qede_start_txq(edev, fp, fp->txq, i, TX_PI(0)); |
| 1730 | if (rc) |
Mintz, Yuval | f29ffdb | 2017-01-01 13:57:07 +0200 | [diff] [blame^] | 1731 | goto out; |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1732 | } |
| 1733 | } |
| 1734 | |
| 1735 | /* Prepare and send the vport enable */ |
Mintz, Yuval | f29ffdb | 2017-01-01 13:57:07 +0200 | [diff] [blame^] | 1736 | vport_update_params->vport_id = start.vport_id; |
| 1737 | vport_update_params->update_vport_active_flg = 1; |
| 1738 | vport_update_params->vport_active_flg = 1; |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1739 | |
Yuval Mintz | 831bfb0e | 2016-05-11 16:36:25 +0300 | [diff] [blame] | 1740 | if ((qed_info->mf_mode == QED_MF_NPAR || pci_num_vf(edev->pdev)) && |
| 1741 | qed_info->tx_switching) { |
Mintz, Yuval | f29ffdb | 2017-01-01 13:57:07 +0200 | [diff] [blame^] | 1742 | vport_update_params->update_tx_switching_flg = 1; |
| 1743 | vport_update_params->tx_switching_flg = 1; |
Yuval Mintz | 831bfb0e | 2016-05-11 16:36:25 +0300 | [diff] [blame] | 1744 | } |
| 1745 | |
Mintz, Yuval | f29ffdb | 2017-01-01 13:57:07 +0200 | [diff] [blame^] | 1746 | qede_fill_rss_params(edev, &vport_update_params->rss_params, |
| 1747 | &vport_update_params->update_rss_flg); |
Sudarsana Reddy Kalluru | 961acde | 2016-04-10 12:43:01 +0300 | [diff] [blame] | 1748 | |
Mintz, Yuval | f29ffdb | 2017-01-01 13:57:07 +0200 | [diff] [blame^] | 1749 | rc = edev->ops->vport_update(cdev, vport_update_params); |
| 1750 | if (rc) |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1751 | DP_ERR(edev, "Update V-PORT failed %d\n", rc); |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1752 | |
Mintz, Yuval | f29ffdb | 2017-01-01 13:57:07 +0200 | [diff] [blame^] | 1753 | out: |
| 1754 | vfree(vport_update_params); |
| 1755 | return rc; |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1756 | } |
| 1757 | |
| 1758 | enum qede_unload_mode { |
| 1759 | QEDE_UNLOAD_NORMAL, |
| 1760 | }; |
| 1761 | |
Mintz, Yuval | 567b3c1 | 2016-11-29 16:47:05 +0200 | [diff] [blame] | 1762 | static void qede_unload(struct qede_dev *edev, enum qede_unload_mode mode, |
| 1763 | bool is_locked) |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1764 | { |
Sudarsana Kalluru | a2ec617 | 2015-10-26 11:02:32 +0200 | [diff] [blame] | 1765 | struct qed_link_params link_params; |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1766 | int rc; |
| 1767 | |
| 1768 | DP_INFO(edev, "Starting qede unload\n"); |
| 1769 | |
Mintz, Yuval | 567b3c1 | 2016-11-29 16:47:05 +0200 | [diff] [blame] | 1770 | if (!is_locked) |
| 1771 | __qede_lock(edev); |
| 1772 | |
Ram Amrani | cee9fbd | 2016-10-01 21:59:56 +0300 | [diff] [blame] | 1773 | qede_roce_dev_event_close(edev); |
Sudarsana Kalluru | 0d8e0aa | 2015-10-26 11:02:30 +0200 | [diff] [blame] | 1774 | edev->state = QEDE_STATE_CLOSED; |
| 1775 | |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1776 | /* Close OS Tx */ |
| 1777 | netif_tx_disable(edev->ndev); |
| 1778 | netif_carrier_off(edev->ndev); |
| 1779 | |
Sudarsana Kalluru | a2ec617 | 2015-10-26 11:02:32 +0200 | [diff] [blame] | 1780 | /* Reset the link */ |
| 1781 | memset(&link_params, 0, sizeof(link_params)); |
| 1782 | link_params.link_up = false; |
| 1783 | edev->ops->common->set_link(edev->cdev, &link_params); |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1784 | rc = qede_stop_queues(edev); |
| 1785 | if (rc) { |
| 1786 | qede_sync_free_irqs(edev); |
| 1787 | goto out; |
| 1788 | } |
| 1789 | |
| 1790 | DP_INFO(edev, "Stopped Queues\n"); |
| 1791 | |
Sudarsana Reddy Kalluru | 7c1bfca | 2016-02-18 17:00:40 +0200 | [diff] [blame] | 1792 | qede_vlan_mark_nonconfigured(edev); |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1793 | edev->ops->fastpath_stop(edev->cdev); |
| 1794 | |
| 1795 | /* Release the interrupts */ |
| 1796 | qede_sync_free_irqs(edev); |
| 1797 | edev->ops->common->set_fp_int(edev->cdev, 0); |
| 1798 | |
| 1799 | qede_napi_disable_remove(edev); |
| 1800 | |
| 1801 | qede_free_mem_load(edev); |
| 1802 | qede_free_fp_array(edev); |
| 1803 | |
| 1804 | out: |
Mintz, Yuval | 567b3c1 | 2016-11-29 16:47:05 +0200 | [diff] [blame] | 1805 | if (!is_locked) |
| 1806 | __qede_unlock(edev); |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1807 | DP_INFO(edev, "Ending qede unload\n"); |
| 1808 | } |
| 1809 | |
| 1810 | enum qede_load_mode { |
| 1811 | QEDE_LOAD_NORMAL, |
Yuval Mintz | a0d26d5 | 2016-06-19 15:18:13 +0300 | [diff] [blame] | 1812 | QEDE_LOAD_RELOAD, |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1813 | }; |
| 1814 | |
Mintz, Yuval | 567b3c1 | 2016-11-29 16:47:05 +0200 | [diff] [blame] | 1815 | static int qede_load(struct qede_dev *edev, enum qede_load_mode mode, |
| 1816 | bool is_locked) |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1817 | { |
Sudarsana Kalluru | a2ec617 | 2015-10-26 11:02:32 +0200 | [diff] [blame] | 1818 | struct qed_link_params link_params; |
| 1819 | struct qed_link_output link_output; |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1820 | int rc; |
| 1821 | |
| 1822 | DP_INFO(edev, "Starting qede load\n"); |
| 1823 | |
Mintz, Yuval | 567b3c1 | 2016-11-29 16:47:05 +0200 | [diff] [blame] | 1824 | if (!is_locked) |
| 1825 | __qede_lock(edev); |
| 1826 | |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1827 | rc = qede_set_num_queues(edev); |
| 1828 | if (rc) |
Mintz, Yuval | 567b3c1 | 2016-11-29 16:47:05 +0200 | [diff] [blame] | 1829 | goto out; |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1830 | |
| 1831 | rc = qede_alloc_fp_array(edev); |
| 1832 | if (rc) |
Mintz, Yuval | 567b3c1 | 2016-11-29 16:47:05 +0200 | [diff] [blame] | 1833 | goto out; |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1834 | |
| 1835 | qede_init_fp(edev); |
| 1836 | |
| 1837 | rc = qede_alloc_mem_load(edev); |
| 1838 | if (rc) |
| 1839 | goto err1; |
Mintz, Yuval | 80439a1 | 2016-11-29 16:47:02 +0200 | [diff] [blame] | 1840 | DP_INFO(edev, "Allocated %d Rx, %d Tx queues\n", |
| 1841 | QEDE_RSS_COUNT(edev), QEDE_TSS_COUNT(edev)); |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1842 | |
| 1843 | rc = qede_set_real_num_queues(edev); |
| 1844 | if (rc) |
| 1845 | goto err2; |
| 1846 | |
| 1847 | qede_napi_add_enable(edev); |
| 1848 | DP_INFO(edev, "Napi added and enabled\n"); |
| 1849 | |
| 1850 | rc = qede_setup_irqs(edev); |
| 1851 | if (rc) |
| 1852 | goto err3; |
| 1853 | DP_INFO(edev, "Setup IRQs succeeded\n"); |
| 1854 | |
Yuval Mintz | a0d26d5 | 2016-06-19 15:18:13 +0300 | [diff] [blame] | 1855 | rc = qede_start_queues(edev, mode != QEDE_LOAD_RELOAD); |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1856 | if (rc) |
| 1857 | goto err4; |
| 1858 | DP_INFO(edev, "Start VPORT, RXQ and TXQ succeeded\n"); |
| 1859 | |
| 1860 | /* Add primary mac and set Rx filters */ |
| 1861 | ether_addr_copy(edev->primary_mac, edev->ndev->dev_addr); |
| 1862 | |
Sudarsana Reddy Kalluru | 7c1bfca | 2016-02-18 17:00:40 +0200 | [diff] [blame] | 1863 | /* Program un-configured VLANs */ |
| 1864 | qede_configure_vlan_filters(edev); |
| 1865 | |
Sudarsana Kalluru | a2ec617 | 2015-10-26 11:02:32 +0200 | [diff] [blame] | 1866 | /* Ask for link-up using current configuration */ |
| 1867 | memset(&link_params, 0, sizeof(link_params)); |
| 1868 | link_params.link_up = true; |
| 1869 | edev->ops->common->set_link(edev->cdev, &link_params); |
| 1870 | |
| 1871 | /* Query whether link is already-up */ |
| 1872 | memset(&link_output, 0, sizeof(link_output)); |
| 1873 | edev->ops->common->get_link(edev->cdev, &link_output); |
Ram Amrani | cee9fbd | 2016-10-01 21:59:56 +0300 | [diff] [blame] | 1874 | qede_roce_dev_event_open(edev); |
Sudarsana Kalluru | a2ec617 | 2015-10-26 11:02:32 +0200 | [diff] [blame] | 1875 | qede_link_update(edev, &link_output); |
| 1876 | |
Mintz, Yuval | 567b3c1 | 2016-11-29 16:47:05 +0200 | [diff] [blame] | 1877 | edev->state = QEDE_STATE_OPEN; |
| 1878 | |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1879 | DP_INFO(edev, "Ending successfully qede load\n"); |
| 1880 | |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1881 | |
Mintz, Yuval | 567b3c1 | 2016-11-29 16:47:05 +0200 | [diff] [blame] | 1882 | goto out; |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1883 | err4: |
| 1884 | qede_sync_free_irqs(edev); |
| 1885 | memset(&edev->int_info.msix_cnt, 0, sizeof(struct qed_int_info)); |
| 1886 | err3: |
| 1887 | qede_napi_disable_remove(edev); |
| 1888 | err2: |
| 1889 | qede_free_mem_load(edev); |
| 1890 | err1: |
| 1891 | edev->ops->common->set_fp_int(edev->cdev, 0); |
| 1892 | qede_free_fp_array(edev); |
Sudarsana Reddy Kalluru | 9a4d7e8 | 2016-08-23 10:56:55 -0400 | [diff] [blame] | 1893 | edev->num_queues = 0; |
| 1894 | edev->fp_num_tx = 0; |
| 1895 | edev->fp_num_rx = 0; |
Mintz, Yuval | 567b3c1 | 2016-11-29 16:47:05 +0200 | [diff] [blame] | 1896 | out: |
| 1897 | if (!is_locked) |
| 1898 | __qede_unlock(edev); |
| 1899 | |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1900 | return rc; |
| 1901 | } |
| 1902 | |
Mintz, Yuval | 567b3c1 | 2016-11-29 16:47:05 +0200 | [diff] [blame] | 1903 | /* 'func' should be able to run between unload and reload assuming interface |
| 1904 | * is actually running, or afterwards in case it's currently DOWN. |
| 1905 | */ |
Sudarsana Kalluru | 133fac0 | 2015-10-26 11:02:34 +0200 | [diff] [blame] | 1906 | void qede_reload(struct qede_dev *edev, |
Mintz, Yuval | 567b3c1 | 2016-11-29 16:47:05 +0200 | [diff] [blame] | 1907 | struct qede_reload_args *args, bool is_locked) |
Sudarsana Kalluru | 133fac0 | 2015-10-26 11:02:34 +0200 | [diff] [blame] | 1908 | { |
Mintz, Yuval | 567b3c1 | 2016-11-29 16:47:05 +0200 | [diff] [blame] | 1909 | if (!is_locked) |
| 1910 | __qede_lock(edev); |
| 1911 | |
| 1912 | /* Since qede_lock is held, internal state wouldn't change even |
| 1913 | * if netdev state would start transitioning. Check whether current |
| 1914 | * internal configuration indicates device is up, then reload. |
Sudarsana Kalluru | 133fac0 | 2015-10-26 11:02:34 +0200 | [diff] [blame] | 1915 | */ |
Mintz, Yuval | 567b3c1 | 2016-11-29 16:47:05 +0200 | [diff] [blame] | 1916 | if (edev->state == QEDE_STATE_OPEN) { |
| 1917 | qede_unload(edev, QEDE_UNLOAD_NORMAL, true); |
| 1918 | if (args) |
| 1919 | args->func(edev, args); |
| 1920 | qede_load(edev, QEDE_LOAD_RELOAD, true); |
Sudarsana Kalluru | 133fac0 | 2015-10-26 11:02:34 +0200 | [diff] [blame] | 1921 | |
Mintz, Yuval | 567b3c1 | 2016-11-29 16:47:05 +0200 | [diff] [blame] | 1922 | /* Since no one is going to do it for us, re-configure */ |
| 1923 | qede_config_rx_mode(edev->ndev); |
| 1924 | } else if (args) { |
| 1925 | args->func(edev, args); |
| 1926 | } |
Sudarsana Kalluru | 133fac0 | 2015-10-26 11:02:34 +0200 | [diff] [blame] | 1927 | |
Mintz, Yuval | 567b3c1 | 2016-11-29 16:47:05 +0200 | [diff] [blame] | 1928 | if (!is_locked) |
| 1929 | __qede_unlock(edev); |
Sudarsana Kalluru | 133fac0 | 2015-10-26 11:02:34 +0200 | [diff] [blame] | 1930 | } |
| 1931 | |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1932 | /* called with rtnl_lock */ |
| 1933 | static int qede_open(struct net_device *ndev) |
| 1934 | { |
| 1935 | struct qede_dev *edev = netdev_priv(ndev); |
Manish Chopra | b18e170 | 2016-04-14 01:38:30 -0400 | [diff] [blame] | 1936 | int rc; |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1937 | |
| 1938 | netif_carrier_off(ndev); |
| 1939 | |
| 1940 | edev->ops->common->set_power_state(edev->cdev, PCI_D0); |
| 1941 | |
Mintz, Yuval | 567b3c1 | 2016-11-29 16:47:05 +0200 | [diff] [blame] | 1942 | rc = qede_load(edev, QEDE_LOAD_NORMAL, false); |
Manish Chopra | b18e170 | 2016-04-14 01:38:30 -0400 | [diff] [blame] | 1943 | if (rc) |
| 1944 | return rc; |
| 1945 | |
Alexander Duyck | f9f082a | 2016-06-16 12:22:57 -0700 | [diff] [blame] | 1946 | udp_tunnel_get_rx_info(ndev); |
| 1947 | |
Sudarsana Kalluru | 0fefbfb | 2016-10-31 07:14:21 +0200 | [diff] [blame] | 1948 | edev->ops->common->update_drv_state(edev->cdev, true); |
| 1949 | |
Manish Chopra | b18e170 | 2016-04-14 01:38:30 -0400 | [diff] [blame] | 1950 | return 0; |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1951 | } |
| 1952 | |
| 1953 | static int qede_close(struct net_device *ndev) |
| 1954 | { |
| 1955 | struct qede_dev *edev = netdev_priv(ndev); |
| 1956 | |
Mintz, Yuval | 567b3c1 | 2016-11-29 16:47:05 +0200 | [diff] [blame] | 1957 | qede_unload(edev, QEDE_UNLOAD_NORMAL, false); |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1958 | |
Sudarsana Kalluru | 0fefbfb | 2016-10-31 07:14:21 +0200 | [diff] [blame] | 1959 | edev->ops->common->update_drv_state(edev->cdev, false); |
| 1960 | |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame] | 1961 | return 0; |
| 1962 | } |
Sudarsana Kalluru | 0d8e0aa | 2015-10-26 11:02:30 +0200 | [diff] [blame] | 1963 | |
Sudarsana Kalluru | a2ec617 | 2015-10-26 11:02:32 +0200 | [diff] [blame] | 1964 | static void qede_link_update(void *dev, struct qed_link_output *link) |
| 1965 | { |
| 1966 | struct qede_dev *edev = dev; |
| 1967 | |
| 1968 | if (!netif_running(edev->ndev)) { |
| 1969 | DP_VERBOSE(edev, NETIF_MSG_LINK, "Interface is not running\n"); |
| 1970 | return; |
| 1971 | } |
| 1972 | |
| 1973 | if (link->link_up) { |
Yuval Mintz | 8e025ae | 2016-02-24 16:52:47 +0200 | [diff] [blame] | 1974 | if (!netif_carrier_ok(edev->ndev)) { |
| 1975 | DP_NOTICE(edev, "Link is up\n"); |
| 1976 | netif_tx_start_all_queues(edev->ndev); |
| 1977 | netif_carrier_on(edev->ndev); |
| 1978 | } |
Sudarsana Kalluru | a2ec617 | 2015-10-26 11:02:32 +0200 | [diff] [blame] | 1979 | } else { |
Yuval Mintz | 8e025ae | 2016-02-24 16:52:47 +0200 | [diff] [blame] | 1980 | if (netif_carrier_ok(edev->ndev)) { |
| 1981 | DP_NOTICE(edev, "Link is down\n"); |
| 1982 | netif_tx_disable(edev->ndev); |
| 1983 | netif_carrier_off(edev->ndev); |
| 1984 | } |
Sudarsana Kalluru | a2ec617 | 2015-10-26 11:02:32 +0200 | [diff] [blame] | 1985 | } |
| 1986 | } |