Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1 | /* QLogic qed NIC Driver |
Mintz, Yuval | e8f1cb5 | 2017-01-01 13:57:00 +0200 | [diff] [blame] | 2 | * Copyright (c) 2015-2017 QLogic Corporation |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 3 | * |
Mintz, Yuval | e8f1cb5 | 2017-01-01 13:57:00 +0200 | [diff] [blame] | 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. |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 31 | */ |
| 32 | |
| 33 | #include <linux/stddef.h> |
| 34 | #include <linux/pci.h> |
| 35 | #include <linux/kernel.h> |
| 36 | #include <linux/slab.h> |
| 37 | #include <linux/version.h> |
| 38 | #include <linux/delay.h> |
| 39 | #include <asm/byteorder.h> |
| 40 | #include <linux/dma-mapping.h> |
| 41 | #include <linux/string.h> |
| 42 | #include <linux/module.h> |
| 43 | #include <linux/interrupt.h> |
| 44 | #include <linux/workqueue.h> |
| 45 | #include <linux/ethtool.h> |
| 46 | #include <linux/etherdevice.h> |
| 47 | #include <linux/vmalloc.h> |
| 48 | #include <linux/qed/qed_if.h> |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 49 | #include <linux/qed/qed_ll2_if.h> |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 50 | |
| 51 | #include "qed.h" |
Yuval Mintz | 37bff2b | 2016-05-11 16:36:13 +0300 | [diff] [blame] | 52 | #include "qed_sriov.h" |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 53 | #include "qed_sp.h" |
| 54 | #include "qed_dev_api.h" |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 55 | #include "qed_ll2.h" |
Arun Easi | 1e128c8 | 2017-02-15 06:28:22 -0800 | [diff] [blame] | 56 | #include "qed_fcoe.h" |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 57 | #include "qed_mcp.h" |
| 58 | #include "qed_hw.h" |
Sudarsana Reddy Kalluru | 03dc76c | 2016-04-28 20:20:52 -0400 | [diff] [blame] | 59 | #include "qed_selftest.h" |
Arun Easi | 1e128c8 | 2017-02-15 06:28:22 -0800 | [diff] [blame] | 60 | #include "qed_debug.h" |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 61 | |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 62 | #define QED_ROCE_QPS (8192) |
| 63 | #define QED_ROCE_DPIS (8) |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 64 | |
Yuval Mintz | 5abd7e92 | 2016-02-24 16:52:50 +0200 | [diff] [blame] | 65 | static char version[] = |
| 66 | "QLogic FastLinQ 4xxxx Core Module qed " DRV_MODULE_VERSION "\n"; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 67 | |
Yuval Mintz | 5abd7e92 | 2016-02-24 16:52:50 +0200 | [diff] [blame] | 68 | MODULE_DESCRIPTION("QLogic FastLinQ 4xxxx Core Module"); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 69 | MODULE_LICENSE("GPL"); |
| 70 | MODULE_VERSION(DRV_MODULE_VERSION); |
| 71 | |
| 72 | #define FW_FILE_VERSION \ |
| 73 | __stringify(FW_MAJOR_VERSION) "." \ |
| 74 | __stringify(FW_MINOR_VERSION) "." \ |
| 75 | __stringify(FW_REVISION_VERSION) "." \ |
| 76 | __stringify(FW_ENGINEERING_VERSION) |
| 77 | |
| 78 | #define QED_FW_FILE_NAME \ |
| 79 | "qed/qed_init_values_zipped-" FW_FILE_VERSION ".bin" |
| 80 | |
Yuval Mintz | d43d3f0 | 2016-02-24 16:52:48 +0200 | [diff] [blame] | 81 | MODULE_FIRMWARE(QED_FW_FILE_NAME); |
| 82 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 83 | static int __init qed_init(void) |
| 84 | { |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 85 | pr_info("%s", version); |
| 86 | |
| 87 | return 0; |
| 88 | } |
| 89 | |
| 90 | static void __exit qed_cleanup(void) |
| 91 | { |
| 92 | pr_notice("qed_cleanup called\n"); |
| 93 | } |
| 94 | |
| 95 | module_init(qed_init); |
| 96 | module_exit(qed_cleanup); |
| 97 | |
| 98 | /* Check if the DMA controller on the machine can properly handle the DMA |
| 99 | * addressing required by the device. |
| 100 | */ |
| 101 | static int qed_set_coherency_mask(struct qed_dev *cdev) |
| 102 | { |
| 103 | struct device *dev = &cdev->pdev->dev; |
| 104 | |
| 105 | if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) { |
| 106 | if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) { |
| 107 | DP_NOTICE(cdev, |
| 108 | "Can't request 64-bit consistent allocations\n"); |
| 109 | return -EIO; |
| 110 | } |
| 111 | } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) { |
| 112 | DP_NOTICE(cdev, "Can't request 64b/32b DMA addresses\n"); |
| 113 | return -EIO; |
| 114 | } |
| 115 | |
| 116 | return 0; |
| 117 | } |
| 118 | |
| 119 | static void qed_free_pci(struct qed_dev *cdev) |
| 120 | { |
| 121 | struct pci_dev *pdev = cdev->pdev; |
| 122 | |
| 123 | if (cdev->doorbells) |
| 124 | iounmap(cdev->doorbells); |
| 125 | if (cdev->regview) |
| 126 | iounmap(cdev->regview); |
| 127 | if (atomic_read(&pdev->enable_cnt) == 1) |
| 128 | pci_release_regions(pdev); |
| 129 | |
| 130 | pci_disable_device(pdev); |
| 131 | } |
| 132 | |
Yuval Mintz | 0dfaba6 | 2016-02-24 16:52:49 +0200 | [diff] [blame] | 133 | #define PCI_REVISION_ID_ERROR_VAL 0xff |
| 134 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 135 | /* Performs PCI initializations as well as initializing PCI-related parameters |
| 136 | * in the device structrue. Returns 0 in case of success. |
| 137 | */ |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 138 | static int qed_init_pci(struct qed_dev *cdev, struct pci_dev *pdev) |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 139 | { |
Yuval Mintz | 0dfaba6 | 2016-02-24 16:52:49 +0200 | [diff] [blame] | 140 | u8 rev_id; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 141 | int rc; |
| 142 | |
| 143 | cdev->pdev = pdev; |
| 144 | |
| 145 | rc = pci_enable_device(pdev); |
| 146 | if (rc) { |
| 147 | DP_NOTICE(cdev, "Cannot enable PCI device\n"); |
| 148 | goto err0; |
| 149 | } |
| 150 | |
| 151 | if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { |
| 152 | DP_NOTICE(cdev, "No memory region found in bar #0\n"); |
| 153 | rc = -EIO; |
| 154 | goto err1; |
| 155 | } |
| 156 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 157 | if (IS_PF(cdev) && !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) { |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 158 | DP_NOTICE(cdev, "No memory region found in bar #2\n"); |
| 159 | rc = -EIO; |
| 160 | goto err1; |
| 161 | } |
| 162 | |
| 163 | if (atomic_read(&pdev->enable_cnt) == 1) { |
| 164 | rc = pci_request_regions(pdev, "qed"); |
| 165 | if (rc) { |
| 166 | DP_NOTICE(cdev, |
| 167 | "Failed to request PCI memory resources\n"); |
| 168 | goto err1; |
| 169 | } |
| 170 | pci_set_master(pdev); |
| 171 | pci_save_state(pdev); |
| 172 | } |
| 173 | |
Yuval Mintz | 0dfaba6 | 2016-02-24 16:52:49 +0200 | [diff] [blame] | 174 | pci_read_config_byte(pdev, PCI_REVISION_ID, &rev_id); |
| 175 | if (rev_id == PCI_REVISION_ID_ERROR_VAL) { |
| 176 | DP_NOTICE(cdev, |
| 177 | "Detected PCI device error [rev_id 0x%x]. Probably due to prior indication. Aborting.\n", |
| 178 | rev_id); |
| 179 | rc = -ENODEV; |
| 180 | goto err2; |
| 181 | } |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 182 | if (!pci_is_pcie(pdev)) { |
| 183 | DP_NOTICE(cdev, "The bus is not PCI Express\n"); |
| 184 | rc = -EIO; |
| 185 | goto err2; |
| 186 | } |
| 187 | |
| 188 | cdev->pci_params.pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM); |
Yuval Mintz | 416cdf0 | 2016-05-15 14:48:09 +0300 | [diff] [blame] | 189 | if (IS_PF(cdev) && !cdev->pci_params.pm_cap) |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 190 | DP_NOTICE(cdev, "Cannot find power management capability\n"); |
| 191 | |
| 192 | rc = qed_set_coherency_mask(cdev); |
| 193 | if (rc) |
| 194 | goto err2; |
| 195 | |
| 196 | cdev->pci_params.mem_start = pci_resource_start(pdev, 0); |
| 197 | cdev->pci_params.mem_end = pci_resource_end(pdev, 0); |
| 198 | cdev->pci_params.irq = pdev->irq; |
| 199 | |
| 200 | cdev->regview = pci_ioremap_bar(pdev, 0); |
| 201 | if (!cdev->regview) { |
| 202 | DP_NOTICE(cdev, "Cannot map register space, aborting\n"); |
| 203 | rc = -ENOMEM; |
| 204 | goto err2; |
| 205 | } |
| 206 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 207 | if (IS_PF(cdev)) { |
Dan Carpenter | f82731b | 2016-05-17 11:09:20 +0300 | [diff] [blame] | 208 | cdev->db_phys_addr = pci_resource_start(cdev->pdev, 2); |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 209 | cdev->db_size = pci_resource_len(cdev->pdev, 2); |
| 210 | cdev->doorbells = ioremap_wc(cdev->db_phys_addr, cdev->db_size); |
| 211 | if (!cdev->doorbells) { |
| 212 | DP_NOTICE(cdev, "Cannot map doorbell space\n"); |
| 213 | return -ENOMEM; |
| 214 | } |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | return 0; |
| 218 | |
| 219 | err2: |
| 220 | pci_release_regions(pdev); |
| 221 | err1: |
| 222 | pci_disable_device(pdev); |
| 223 | err0: |
| 224 | return rc; |
| 225 | } |
| 226 | |
| 227 | int qed_fill_dev_info(struct qed_dev *cdev, |
| 228 | struct qed_dev_info *dev_info) |
| 229 | { |
Manish Chopra | cee4d26 | 2015-10-26 11:02:28 +0200 | [diff] [blame] | 230 | struct qed_ptt *ptt; |
| 231 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 232 | memset(dev_info, 0, sizeof(struct qed_dev_info)); |
| 233 | |
| 234 | dev_info->num_hwfns = cdev->num_hwfns; |
| 235 | dev_info->pci_mem_start = cdev->pci_params.mem_start; |
| 236 | dev_info->pci_mem_end = cdev->pci_params.mem_end; |
| 237 | dev_info->pci_irq = cdev->pci_params.irq; |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 238 | dev_info->rdma_supported = (cdev->hwfns[0].hw_info.personality == |
| 239 | QED_PCI_ETH_ROCE); |
Yuval Mintz | fc48b7a | 2016-02-15 13:22:35 -0500 | [diff] [blame] | 240 | dev_info->is_mf_default = IS_MF_DEFAULT(&cdev->hwfns[0]); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 241 | ether_addr_copy(dev_info->hw_mac, cdev->hwfns[0].hw_info.hw_mac_addr); |
| 242 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 243 | if (IS_PF(cdev)) { |
| 244 | dev_info->fw_major = FW_MAJOR_VERSION; |
| 245 | dev_info->fw_minor = FW_MINOR_VERSION; |
| 246 | dev_info->fw_rev = FW_REVISION_VERSION; |
| 247 | dev_info->fw_eng = FW_ENGINEERING_VERSION; |
| 248 | dev_info->mf_mode = cdev->mf_mode; |
Yuval Mintz | 831bfb0e | 2016-05-11 16:36:25 +0300 | [diff] [blame] | 249 | dev_info->tx_switching = true; |
Mintz, Yuval | 14d3964 | 2016-10-31 07:14:23 +0200 | [diff] [blame] | 250 | |
| 251 | if (QED_LEADING_HWFN(cdev)->hw_info.b_wol_support == |
| 252 | QED_WOL_SUPPORT_PME) |
| 253 | dev_info->wol_support = true; |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 254 | } else { |
| 255 | qed_vf_get_fw_version(&cdev->hwfns[0], &dev_info->fw_major, |
| 256 | &dev_info->fw_minor, &dev_info->fw_rev, |
| 257 | &dev_info->fw_eng); |
| 258 | } |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 259 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 260 | if (IS_PF(cdev)) { |
| 261 | ptt = qed_ptt_acquire(QED_LEADING_HWFN(cdev)); |
| 262 | if (ptt) { |
| 263 | qed_mcp_get_mfw_ver(QED_LEADING_HWFN(cdev), ptt, |
| 264 | &dev_info->mfw_rev, NULL); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 265 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 266 | qed_mcp_get_flash_size(QED_LEADING_HWFN(cdev), ptt, |
| 267 | &dev_info->flash_size); |
Manish Chopra | cee4d26 | 2015-10-26 11:02:28 +0200 | [diff] [blame] | 268 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 269 | qed_ptt_release(QED_LEADING_HWFN(cdev), ptt); |
| 270 | } |
| 271 | } else { |
| 272 | qed_mcp_get_mfw_ver(QED_LEADING_HWFN(cdev), NULL, |
| 273 | &dev_info->mfw_rev, NULL); |
Manish Chopra | cee4d26 | 2015-10-26 11:02:28 +0200 | [diff] [blame] | 274 | } |
| 275 | |
Sudarsana Kalluru | 0fefbfb | 2016-10-31 07:14:21 +0200 | [diff] [blame] | 276 | dev_info->mtu = QED_LEADING_HWFN(cdev)->hw_info.mtu; |
| 277 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 278 | return 0; |
| 279 | } |
| 280 | |
| 281 | static void qed_free_cdev(struct qed_dev *cdev) |
| 282 | { |
| 283 | kfree((void *)cdev); |
| 284 | } |
| 285 | |
| 286 | static struct qed_dev *qed_alloc_cdev(struct pci_dev *pdev) |
| 287 | { |
| 288 | struct qed_dev *cdev; |
| 289 | |
| 290 | cdev = kzalloc(sizeof(*cdev), GFP_KERNEL); |
| 291 | if (!cdev) |
| 292 | return cdev; |
| 293 | |
| 294 | qed_init_struct(cdev); |
| 295 | |
| 296 | return cdev; |
| 297 | } |
| 298 | |
| 299 | /* Sets the requested power state */ |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 300 | static int qed_set_power_state(struct qed_dev *cdev, pci_power_t state) |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 301 | { |
| 302 | if (!cdev) |
| 303 | return -ENODEV; |
| 304 | |
| 305 | DP_VERBOSE(cdev, NETIF_MSG_DRV, "Omitting Power state change\n"); |
| 306 | return 0; |
| 307 | } |
| 308 | |
| 309 | /* probing */ |
| 310 | static struct qed_dev *qed_probe(struct pci_dev *pdev, |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 311 | struct qed_probe_params *params) |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 312 | { |
| 313 | struct qed_dev *cdev; |
| 314 | int rc; |
| 315 | |
| 316 | cdev = qed_alloc_cdev(pdev); |
| 317 | if (!cdev) |
| 318 | goto err0; |
| 319 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 320 | cdev->protocol = params->protocol; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 321 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 322 | if (params->is_vf) |
| 323 | cdev->b_is_vf = true; |
| 324 | |
| 325 | qed_init_dp(cdev, params->dp_module, params->dp_level); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 326 | |
| 327 | rc = qed_init_pci(cdev, pdev); |
| 328 | if (rc) { |
| 329 | DP_ERR(cdev, "init pci failed\n"); |
| 330 | goto err1; |
| 331 | } |
| 332 | DP_INFO(cdev, "PCI init completed successfully\n"); |
| 333 | |
| 334 | rc = qed_hw_prepare(cdev, QED_PCI_DEFAULT); |
| 335 | if (rc) { |
| 336 | DP_ERR(cdev, "hw prepare failed\n"); |
| 337 | goto err2; |
| 338 | } |
| 339 | |
| 340 | DP_INFO(cdev, "qed_probe completed successffuly\n"); |
| 341 | |
| 342 | return cdev; |
| 343 | |
| 344 | err2: |
| 345 | qed_free_pci(cdev); |
| 346 | err1: |
| 347 | qed_free_cdev(cdev); |
| 348 | err0: |
| 349 | return NULL; |
| 350 | } |
| 351 | |
| 352 | static void qed_remove(struct qed_dev *cdev) |
| 353 | { |
| 354 | if (!cdev) |
| 355 | return; |
| 356 | |
| 357 | qed_hw_remove(cdev); |
| 358 | |
| 359 | qed_free_pci(cdev); |
| 360 | |
| 361 | qed_set_power_state(cdev, PCI_D3hot); |
| 362 | |
| 363 | qed_free_cdev(cdev); |
| 364 | } |
| 365 | |
| 366 | static void qed_disable_msix(struct qed_dev *cdev) |
| 367 | { |
| 368 | if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) { |
| 369 | pci_disable_msix(cdev->pdev); |
| 370 | kfree(cdev->int_params.msix_table); |
| 371 | } else if (cdev->int_params.out.int_mode == QED_INT_MODE_MSI) { |
| 372 | pci_disable_msi(cdev->pdev); |
| 373 | } |
| 374 | |
| 375 | memset(&cdev->int_params.out, 0, sizeof(struct qed_int_param)); |
| 376 | } |
| 377 | |
| 378 | static int qed_enable_msix(struct qed_dev *cdev, |
| 379 | struct qed_int_params *int_params) |
| 380 | { |
| 381 | int i, rc, cnt; |
| 382 | |
| 383 | cnt = int_params->in.num_vectors; |
| 384 | |
| 385 | for (i = 0; i < cnt; i++) |
| 386 | int_params->msix_table[i].entry = i; |
| 387 | |
| 388 | rc = pci_enable_msix_range(cdev->pdev, int_params->msix_table, |
| 389 | int_params->in.min_msix_cnt, cnt); |
| 390 | if (rc < cnt && rc >= int_params->in.min_msix_cnt && |
| 391 | (rc % cdev->num_hwfns)) { |
| 392 | pci_disable_msix(cdev->pdev); |
| 393 | |
| 394 | /* If fastpath is initialized, we need at least one interrupt |
| 395 | * per hwfn [and the slow path interrupts]. New requested number |
| 396 | * should be a multiple of the number of hwfns. |
| 397 | */ |
| 398 | cnt = (rc / cdev->num_hwfns) * cdev->num_hwfns; |
| 399 | DP_NOTICE(cdev, |
| 400 | "Trying to enable MSI-X with less vectors (%d out of %d)\n", |
| 401 | cnt, int_params->in.num_vectors); |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 402 | rc = pci_enable_msix_exact(cdev->pdev, int_params->msix_table, |
| 403 | cnt); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 404 | if (!rc) |
| 405 | rc = cnt; |
| 406 | } |
| 407 | |
| 408 | if (rc > 0) { |
| 409 | /* MSI-x configuration was achieved */ |
| 410 | int_params->out.int_mode = QED_INT_MODE_MSIX; |
| 411 | int_params->out.num_vectors = rc; |
| 412 | rc = 0; |
| 413 | } else { |
| 414 | DP_NOTICE(cdev, |
| 415 | "Failed to enable MSI-X [Requested %d vectors][rc %d]\n", |
| 416 | cnt, rc); |
| 417 | } |
| 418 | |
| 419 | return rc; |
| 420 | } |
| 421 | |
| 422 | /* This function outputs the int mode and the number of enabled msix vector */ |
| 423 | static int qed_set_int_mode(struct qed_dev *cdev, bool force_mode) |
| 424 | { |
| 425 | struct qed_int_params *int_params = &cdev->int_params; |
| 426 | struct msix_entry *tbl; |
| 427 | int rc = 0, cnt; |
| 428 | |
| 429 | switch (int_params->in.int_mode) { |
| 430 | case QED_INT_MODE_MSIX: |
| 431 | /* Allocate MSIX table */ |
| 432 | cnt = int_params->in.num_vectors; |
| 433 | int_params->msix_table = kcalloc(cnt, sizeof(*tbl), GFP_KERNEL); |
| 434 | if (!int_params->msix_table) { |
| 435 | rc = -ENOMEM; |
| 436 | goto out; |
| 437 | } |
| 438 | |
| 439 | /* Enable MSIX */ |
| 440 | rc = qed_enable_msix(cdev, int_params); |
| 441 | if (!rc) |
| 442 | goto out; |
| 443 | |
| 444 | DP_NOTICE(cdev, "Failed to enable MSI-X\n"); |
| 445 | kfree(int_params->msix_table); |
| 446 | if (force_mode) |
| 447 | goto out; |
| 448 | /* Fallthrough */ |
| 449 | |
| 450 | case QED_INT_MODE_MSI: |
Sudarsana Reddy Kalluru | bb13ace | 2016-05-26 11:01:23 +0300 | [diff] [blame] | 451 | if (cdev->num_hwfns == 1) { |
| 452 | rc = pci_enable_msi(cdev->pdev); |
| 453 | if (!rc) { |
| 454 | int_params->out.int_mode = QED_INT_MODE_MSI; |
| 455 | goto out; |
| 456 | } |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 457 | |
Sudarsana Reddy Kalluru | bb13ace | 2016-05-26 11:01:23 +0300 | [diff] [blame] | 458 | DP_NOTICE(cdev, "Failed to enable MSI\n"); |
| 459 | if (force_mode) |
| 460 | goto out; |
| 461 | } |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 462 | /* Fallthrough */ |
| 463 | |
| 464 | case QED_INT_MODE_INTA: |
| 465 | int_params->out.int_mode = QED_INT_MODE_INTA; |
| 466 | rc = 0; |
| 467 | goto out; |
| 468 | default: |
| 469 | DP_NOTICE(cdev, "Unknown int_mode value %d\n", |
| 470 | int_params->in.int_mode); |
| 471 | rc = -EINVAL; |
| 472 | } |
| 473 | |
| 474 | out: |
Yuval Mintz | 525ef5c | 2016-08-15 10:42:45 +0300 | [diff] [blame] | 475 | if (!rc) |
| 476 | DP_INFO(cdev, "Using %s interrupts\n", |
| 477 | int_params->out.int_mode == QED_INT_MODE_INTA ? |
| 478 | "INTa" : int_params->out.int_mode == QED_INT_MODE_MSI ? |
| 479 | "MSI" : "MSIX"); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 480 | cdev->int_coalescing_mode = QED_COAL_MODE_ENABLE; |
| 481 | |
| 482 | return rc; |
| 483 | } |
| 484 | |
| 485 | static void qed_simd_handler_config(struct qed_dev *cdev, void *token, |
| 486 | int index, void(*handler)(void *)) |
| 487 | { |
| 488 | struct qed_hwfn *hwfn = &cdev->hwfns[index % cdev->num_hwfns]; |
| 489 | int relative_idx = index / cdev->num_hwfns; |
| 490 | |
| 491 | hwfn->simd_proto_handler[relative_idx].func = handler; |
| 492 | hwfn->simd_proto_handler[relative_idx].token = token; |
| 493 | } |
| 494 | |
| 495 | static void qed_simd_handler_clean(struct qed_dev *cdev, int index) |
| 496 | { |
| 497 | struct qed_hwfn *hwfn = &cdev->hwfns[index % cdev->num_hwfns]; |
| 498 | int relative_idx = index / cdev->num_hwfns; |
| 499 | |
| 500 | memset(&hwfn->simd_proto_handler[relative_idx], 0, |
| 501 | sizeof(struct qed_simd_fp_handler)); |
| 502 | } |
| 503 | |
| 504 | static irqreturn_t qed_msix_sp_int(int irq, void *tasklet) |
| 505 | { |
| 506 | tasklet_schedule((struct tasklet_struct *)tasklet); |
| 507 | return IRQ_HANDLED; |
| 508 | } |
| 509 | |
| 510 | static irqreturn_t qed_single_int(int irq, void *dev_instance) |
| 511 | { |
| 512 | struct qed_dev *cdev = (struct qed_dev *)dev_instance; |
| 513 | struct qed_hwfn *hwfn; |
| 514 | irqreturn_t rc = IRQ_NONE; |
| 515 | u64 status; |
| 516 | int i, j; |
| 517 | |
| 518 | for (i = 0; i < cdev->num_hwfns; i++) { |
| 519 | status = qed_int_igu_read_sisr_reg(&cdev->hwfns[i]); |
| 520 | |
| 521 | if (!status) |
| 522 | continue; |
| 523 | |
| 524 | hwfn = &cdev->hwfns[i]; |
| 525 | |
| 526 | /* Slowpath interrupt */ |
| 527 | if (unlikely(status & 0x1)) { |
| 528 | tasklet_schedule(hwfn->sp_dpc); |
| 529 | status &= ~0x1; |
| 530 | rc = IRQ_HANDLED; |
| 531 | } |
| 532 | |
| 533 | /* Fastpath interrupts */ |
| 534 | for (j = 0; j < 64; j++) { |
| 535 | if ((0x2ULL << j) & status) { |
| 536 | hwfn->simd_proto_handler[j].func( |
| 537 | hwfn->simd_proto_handler[j].token); |
| 538 | status &= ~(0x2ULL << j); |
| 539 | rc = IRQ_HANDLED; |
| 540 | } |
| 541 | } |
| 542 | |
| 543 | if (unlikely(status)) |
| 544 | DP_VERBOSE(hwfn, NETIF_MSG_INTR, |
| 545 | "got an unknown interrupt status 0x%llx\n", |
| 546 | status); |
| 547 | } |
| 548 | |
| 549 | return rc; |
| 550 | } |
| 551 | |
Sudarsana Kalluru | 8f16bc9 | 2015-12-07 06:25:59 -0500 | [diff] [blame] | 552 | int qed_slowpath_irq_req(struct qed_hwfn *hwfn) |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 553 | { |
Sudarsana Kalluru | 8f16bc9 | 2015-12-07 06:25:59 -0500 | [diff] [blame] | 554 | struct qed_dev *cdev = hwfn->cdev; |
Yuval Mintz | 525ef5c | 2016-08-15 10:42:45 +0300 | [diff] [blame] | 555 | u32 int_mode; |
Sudarsana Kalluru | 8f16bc9 | 2015-12-07 06:25:59 -0500 | [diff] [blame] | 556 | int rc = 0; |
| 557 | u8 id; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 558 | |
Yuval Mintz | 525ef5c | 2016-08-15 10:42:45 +0300 | [diff] [blame] | 559 | int_mode = cdev->int_params.out.int_mode; |
| 560 | if (int_mode == QED_INT_MODE_MSIX) { |
Sudarsana Kalluru | 8f16bc9 | 2015-12-07 06:25:59 -0500 | [diff] [blame] | 561 | id = hwfn->my_id; |
| 562 | snprintf(hwfn->name, NAME_SIZE, "sp-%d-%02x:%02x.%02x", |
| 563 | id, cdev->pdev->bus->number, |
| 564 | PCI_SLOT(cdev->pdev->devfn), hwfn->abs_pf_id); |
| 565 | rc = request_irq(cdev->int_params.msix_table[id].vector, |
| 566 | qed_msix_sp_int, 0, hwfn->name, hwfn->sp_dpc); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 567 | } else { |
| 568 | unsigned long flags = 0; |
| 569 | |
| 570 | snprintf(cdev->name, NAME_SIZE, "%02x:%02x.%02x", |
| 571 | cdev->pdev->bus->number, PCI_SLOT(cdev->pdev->devfn), |
| 572 | PCI_FUNC(cdev->pdev->devfn)); |
| 573 | |
| 574 | if (cdev->int_params.out.int_mode == QED_INT_MODE_INTA) |
| 575 | flags |= IRQF_SHARED; |
| 576 | |
| 577 | rc = request_irq(cdev->pdev->irq, qed_single_int, |
| 578 | flags, cdev->name, cdev); |
| 579 | } |
| 580 | |
Yuval Mintz | 525ef5c | 2016-08-15 10:42:45 +0300 | [diff] [blame] | 581 | if (rc) |
| 582 | DP_NOTICE(cdev, "request_irq failed, rc = %d\n", rc); |
| 583 | else |
| 584 | DP_VERBOSE(hwfn, (NETIF_MSG_INTR | QED_MSG_SP), |
| 585 | "Requested slowpath %s\n", |
| 586 | (int_mode == QED_INT_MODE_MSIX) ? "MSI-X" : "IRQ"); |
| 587 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 588 | return rc; |
| 589 | } |
| 590 | |
| 591 | static void qed_slowpath_irq_free(struct qed_dev *cdev) |
| 592 | { |
| 593 | int i; |
| 594 | |
| 595 | if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) { |
| 596 | for_each_hwfn(cdev, i) { |
Sudarsana Kalluru | 8f16bc9 | 2015-12-07 06:25:59 -0500 | [diff] [blame] | 597 | if (!cdev->hwfns[i].b_int_requested) |
| 598 | break; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 599 | synchronize_irq(cdev->int_params.msix_table[i].vector); |
| 600 | free_irq(cdev->int_params.msix_table[i].vector, |
| 601 | cdev->hwfns[i].sp_dpc); |
| 602 | } |
| 603 | } else { |
Sudarsana Kalluru | 8f16bc9 | 2015-12-07 06:25:59 -0500 | [diff] [blame] | 604 | if (QED_LEADING_HWFN(cdev)->b_int_requested) |
| 605 | free_irq(cdev->pdev->irq, cdev); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 606 | } |
Sudarsana Kalluru | 8f16bc9 | 2015-12-07 06:25:59 -0500 | [diff] [blame] | 607 | qed_int_disable_post_isr_release(cdev); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | static int qed_nic_stop(struct qed_dev *cdev) |
| 611 | { |
| 612 | int i, rc; |
| 613 | |
| 614 | rc = qed_hw_stop(cdev); |
| 615 | |
| 616 | for (i = 0; i < cdev->num_hwfns; i++) { |
| 617 | struct qed_hwfn *p_hwfn = &cdev->hwfns[i]; |
| 618 | |
| 619 | if (p_hwfn->b_sp_dpc_enabled) { |
| 620 | tasklet_disable(p_hwfn->sp_dpc); |
| 621 | p_hwfn->b_sp_dpc_enabled = false; |
| 622 | DP_VERBOSE(cdev, NETIF_MSG_IFDOWN, |
| 623 | "Disabled sp taskelt [hwfn %d] at %p\n", |
| 624 | i, p_hwfn->sp_dpc); |
| 625 | } |
| 626 | } |
| 627 | |
Tomer Tayar | c965db4 | 2016-09-07 16:36:24 +0300 | [diff] [blame] | 628 | qed_dbg_pf_exit(cdev); |
| 629 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 630 | return rc; |
| 631 | } |
| 632 | |
| 633 | static int qed_nic_reset(struct qed_dev *cdev) |
| 634 | { |
| 635 | int rc; |
| 636 | |
| 637 | rc = qed_hw_reset(cdev); |
| 638 | if (rc) |
| 639 | return rc; |
| 640 | |
| 641 | qed_resc_free(cdev); |
| 642 | |
| 643 | return 0; |
| 644 | } |
| 645 | |
| 646 | static int qed_nic_setup(struct qed_dev *cdev) |
| 647 | { |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 648 | int rc, i; |
| 649 | |
| 650 | /* Determine if interface is going to require LL2 */ |
| 651 | if (QED_LEADING_HWFN(cdev)->hw_info.personality != QED_PCI_ETH) { |
| 652 | for (i = 0; i < cdev->num_hwfns; i++) { |
| 653 | struct qed_hwfn *p_hwfn = &cdev->hwfns[i]; |
| 654 | |
| 655 | p_hwfn->using_ll2 = true; |
| 656 | } |
| 657 | } |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 658 | |
| 659 | rc = qed_resc_alloc(cdev); |
| 660 | if (rc) |
| 661 | return rc; |
| 662 | |
| 663 | DP_INFO(cdev, "Allocated qed resources\n"); |
| 664 | |
| 665 | qed_resc_setup(cdev); |
| 666 | |
| 667 | return rc; |
| 668 | } |
| 669 | |
| 670 | static int qed_set_int_fp(struct qed_dev *cdev, u16 cnt) |
| 671 | { |
| 672 | int limit = 0; |
| 673 | |
| 674 | /* Mark the fastpath as free/used */ |
| 675 | cdev->int_params.fp_initialized = cnt ? true : false; |
| 676 | |
| 677 | if (cdev->int_params.out.int_mode != QED_INT_MODE_MSIX) |
| 678 | limit = cdev->num_hwfns * 63; |
| 679 | else if (cdev->int_params.fp_msix_cnt) |
| 680 | limit = cdev->int_params.fp_msix_cnt; |
| 681 | |
| 682 | if (!limit) |
| 683 | return -ENOMEM; |
| 684 | |
| 685 | return min_t(int, cnt, limit); |
| 686 | } |
| 687 | |
| 688 | static int qed_get_int_fp(struct qed_dev *cdev, struct qed_int_info *info) |
| 689 | { |
| 690 | memset(info, 0, sizeof(struct qed_int_info)); |
| 691 | |
| 692 | if (!cdev->int_params.fp_initialized) { |
| 693 | DP_INFO(cdev, |
| 694 | "Protocol driver requested interrupt information, but its support is not yet configured\n"); |
| 695 | return -EINVAL; |
| 696 | } |
| 697 | |
| 698 | /* Need to expose only MSI-X information; Single IRQ is handled solely |
| 699 | * by qed. |
| 700 | */ |
| 701 | if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) { |
| 702 | int msix_base = cdev->int_params.fp_msix_base; |
| 703 | |
| 704 | info->msix_cnt = cdev->int_params.fp_msix_cnt; |
| 705 | info->msix = &cdev->int_params.msix_table[msix_base]; |
| 706 | } |
| 707 | |
| 708 | return 0; |
| 709 | } |
| 710 | |
| 711 | static int qed_slowpath_setup_int(struct qed_dev *cdev, |
| 712 | enum qed_int_mode int_mode) |
| 713 | { |
Yuval Mintz | 4ac801b | 2016-02-28 12:26:52 +0200 | [diff] [blame] | 714 | struct qed_sb_cnt_info sb_cnt_info; |
Yuval Mintz | 0189efb | 2016-10-13 22:57:02 +0300 | [diff] [blame] | 715 | int num_l2_queues = 0; |
Yuval Mintz | 4ac801b | 2016-02-28 12:26:52 +0200 | [diff] [blame] | 716 | int rc; |
| 717 | int i; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 718 | |
Sudarsana Reddy Kalluru | 1d2c202 | 2016-08-01 09:08:13 -0400 | [diff] [blame] | 719 | if ((int_mode == QED_INT_MODE_MSI) && (cdev->num_hwfns > 1)) { |
| 720 | DP_NOTICE(cdev, "MSI mode is not supported for CMT devices\n"); |
| 721 | return -EINVAL; |
| 722 | } |
| 723 | |
| 724 | memset(&cdev->int_params, 0, sizeof(struct qed_int_params)); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 725 | cdev->int_params.in.int_mode = int_mode; |
Yuval Mintz | 4ac801b | 2016-02-28 12:26:52 +0200 | [diff] [blame] | 726 | for_each_hwfn(cdev, i) { |
| 727 | memset(&sb_cnt_info, 0, sizeof(sb_cnt_info)); |
| 728 | qed_int_get_num_sbs(&cdev->hwfns[i], &sb_cnt_info); |
| 729 | cdev->int_params.in.num_vectors += sb_cnt_info.sb_cnt; |
| 730 | cdev->int_params.in.num_vectors++; /* slowpath */ |
| 731 | } |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 732 | |
| 733 | /* We want a minimum of one slowpath and one fastpath vector per hwfn */ |
| 734 | cdev->int_params.in.min_msix_cnt = cdev->num_hwfns * 2; |
| 735 | |
| 736 | rc = qed_set_int_mode(cdev, false); |
| 737 | if (rc) { |
| 738 | DP_ERR(cdev, "qed_slowpath_setup_int ERR\n"); |
| 739 | return rc; |
| 740 | } |
| 741 | |
| 742 | cdev->int_params.fp_msix_base = cdev->num_hwfns; |
| 743 | cdev->int_params.fp_msix_cnt = cdev->int_params.out.num_vectors - |
| 744 | cdev->num_hwfns; |
| 745 | |
Yuval Mintz | 0189efb | 2016-10-13 22:57:02 +0300 | [diff] [blame] | 746 | if (!IS_ENABLED(CONFIG_QED_RDMA)) |
| 747 | return 0; |
| 748 | |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 749 | for_each_hwfn(cdev, i) |
| 750 | num_l2_queues += FEAT_NUM(&cdev->hwfns[i], QED_PF_L2_QUE); |
| 751 | |
| 752 | DP_VERBOSE(cdev, QED_MSG_RDMA, |
| 753 | "cdev->int_params.fp_msix_cnt=%d num_l2_queues=%d\n", |
| 754 | cdev->int_params.fp_msix_cnt, num_l2_queues); |
| 755 | |
| 756 | if (cdev->int_params.fp_msix_cnt > num_l2_queues) { |
| 757 | cdev->int_params.rdma_msix_cnt = |
| 758 | (cdev->int_params.fp_msix_cnt - num_l2_queues) |
| 759 | / cdev->num_hwfns; |
| 760 | cdev->int_params.rdma_msix_base = |
| 761 | cdev->int_params.fp_msix_base + num_l2_queues; |
| 762 | cdev->int_params.fp_msix_cnt = num_l2_queues; |
| 763 | } else { |
| 764 | cdev->int_params.rdma_msix_cnt = 0; |
| 765 | } |
| 766 | |
| 767 | DP_VERBOSE(cdev, QED_MSG_RDMA, "roce_msix_cnt=%d roce_msix_base=%d\n", |
| 768 | cdev->int_params.rdma_msix_cnt, |
| 769 | cdev->int_params.rdma_msix_base); |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 770 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 771 | return 0; |
| 772 | } |
| 773 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 774 | static int qed_slowpath_vf_setup_int(struct qed_dev *cdev) |
| 775 | { |
| 776 | int rc; |
| 777 | |
| 778 | memset(&cdev->int_params, 0, sizeof(struct qed_int_params)); |
| 779 | cdev->int_params.in.int_mode = QED_INT_MODE_MSIX; |
| 780 | |
| 781 | qed_vf_get_num_rxqs(QED_LEADING_HWFN(cdev), |
| 782 | &cdev->int_params.in.num_vectors); |
| 783 | if (cdev->num_hwfns > 1) { |
| 784 | u8 vectors = 0; |
| 785 | |
| 786 | qed_vf_get_num_rxqs(&cdev->hwfns[1], &vectors); |
| 787 | cdev->int_params.in.num_vectors += vectors; |
| 788 | } |
| 789 | |
| 790 | /* We want a minimum of one fastpath vector per vf hwfn */ |
| 791 | cdev->int_params.in.min_msix_cnt = cdev->num_hwfns; |
| 792 | |
| 793 | rc = qed_set_int_mode(cdev, true); |
| 794 | if (rc) |
| 795 | return rc; |
| 796 | |
| 797 | cdev->int_params.fp_msix_base = 0; |
| 798 | cdev->int_params.fp_msix_cnt = cdev->int_params.out.num_vectors; |
| 799 | |
| 800 | return 0; |
| 801 | } |
| 802 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 803 | u32 qed_unzip_data(struct qed_hwfn *p_hwfn, u32 input_len, |
| 804 | u8 *input_buf, u32 max_size, u8 *unzip_buf) |
| 805 | { |
| 806 | int rc; |
| 807 | |
| 808 | p_hwfn->stream->next_in = input_buf; |
| 809 | p_hwfn->stream->avail_in = input_len; |
| 810 | p_hwfn->stream->next_out = unzip_buf; |
| 811 | p_hwfn->stream->avail_out = max_size; |
| 812 | |
| 813 | rc = zlib_inflateInit2(p_hwfn->stream, MAX_WBITS); |
| 814 | |
| 815 | if (rc != Z_OK) { |
| 816 | DP_VERBOSE(p_hwfn, NETIF_MSG_DRV, "zlib init failed, rc = %d\n", |
| 817 | rc); |
| 818 | return 0; |
| 819 | } |
| 820 | |
| 821 | rc = zlib_inflate(p_hwfn->stream, Z_FINISH); |
| 822 | zlib_inflateEnd(p_hwfn->stream); |
| 823 | |
| 824 | if (rc != Z_OK && rc != Z_STREAM_END) { |
| 825 | DP_VERBOSE(p_hwfn, NETIF_MSG_DRV, "FW unzip error: %s, rc=%d\n", |
| 826 | p_hwfn->stream->msg, rc); |
| 827 | return 0; |
| 828 | } |
| 829 | |
| 830 | return p_hwfn->stream->total_out / 4; |
| 831 | } |
| 832 | |
| 833 | static int qed_alloc_stream_mem(struct qed_dev *cdev) |
| 834 | { |
| 835 | int i; |
| 836 | void *workspace; |
| 837 | |
| 838 | for_each_hwfn(cdev, i) { |
| 839 | struct qed_hwfn *p_hwfn = &cdev->hwfns[i]; |
| 840 | |
| 841 | p_hwfn->stream = kzalloc(sizeof(*p_hwfn->stream), GFP_KERNEL); |
| 842 | if (!p_hwfn->stream) |
| 843 | return -ENOMEM; |
| 844 | |
| 845 | workspace = vzalloc(zlib_inflate_workspacesize()); |
| 846 | if (!workspace) |
| 847 | return -ENOMEM; |
| 848 | p_hwfn->stream->workspace = workspace; |
| 849 | } |
| 850 | |
| 851 | return 0; |
| 852 | } |
| 853 | |
| 854 | static void qed_free_stream_mem(struct qed_dev *cdev) |
| 855 | { |
| 856 | int i; |
| 857 | |
| 858 | for_each_hwfn(cdev, i) { |
| 859 | struct qed_hwfn *p_hwfn = &cdev->hwfns[i]; |
| 860 | |
| 861 | if (!p_hwfn->stream) |
| 862 | return; |
| 863 | |
| 864 | vfree(p_hwfn->stream->workspace); |
| 865 | kfree(p_hwfn->stream); |
| 866 | } |
| 867 | } |
| 868 | |
| 869 | static void qed_update_pf_params(struct qed_dev *cdev, |
| 870 | struct qed_pf_params *params) |
| 871 | { |
| 872 | int i; |
| 873 | |
Ram Amrani | 5c5f260 | 2016-11-09 22:48:44 +0200 | [diff] [blame] | 874 | if (IS_ENABLED(CONFIG_QED_RDMA)) { |
| 875 | params->rdma_pf_params.num_qps = QED_ROCE_QPS; |
| 876 | params->rdma_pf_params.min_dpis = QED_ROCE_DPIS; |
| 877 | /* divide by 3 the MRs to avoid MF ILT overflow */ |
| 878 | params->rdma_pf_params.num_mrs = RDMA_MAX_TIDS; |
| 879 | params->rdma_pf_params.gl_pi = QED_ROCE_PROTOCOL_INDEX; |
| 880 | } |
| 881 | |
Mintz, Yuval | e1d32ac | 2017-01-01 13:57:03 +0200 | [diff] [blame] | 882 | /* In case we might support RDMA, don't allow qede to be greedy |
| 883 | * with the L2 contexts. Allow for 64 queues [rx, tx, xdp] per hwfn. |
| 884 | */ |
| 885 | if (QED_LEADING_HWFN(cdev)->hw_info.personality == |
| 886 | QED_PCI_ETH_ROCE) { |
| 887 | u16 *num_cons; |
| 888 | |
| 889 | num_cons = ¶ms->eth_pf_params.num_cons; |
| 890 | *num_cons = min_t(u16, *num_cons, 192); |
| 891 | } |
| 892 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 893 | for (i = 0; i < cdev->num_hwfns; i++) { |
| 894 | struct qed_hwfn *p_hwfn = &cdev->hwfns[i]; |
| 895 | |
| 896 | p_hwfn->pf_params = *params; |
| 897 | } |
| 898 | } |
| 899 | |
| 900 | static int qed_slowpath_start(struct qed_dev *cdev, |
| 901 | struct qed_slowpath_params *params) |
| 902 | { |
Manish Chopra | b18e170 | 2016-04-14 01:38:30 -0400 | [diff] [blame] | 903 | struct qed_tunn_start_params tunn_info; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 904 | struct qed_mcp_drv_version drv_version; |
| 905 | const u8 *data = NULL; |
| 906 | struct qed_hwfn *hwfn; |
Sudarsana Reddy Kalluru | c78c70f | 2017-02-15 10:24:10 +0200 | [diff] [blame] | 907 | struct qed_ptt *p_ptt; |
Yuval Mintz | 37bff2b | 2016-05-11 16:36:13 +0300 | [diff] [blame] | 908 | int rc = -EINVAL; |
| 909 | |
| 910 | if (qed_iov_wq_start(cdev)) |
| 911 | goto err; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 912 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 913 | if (IS_PF(cdev)) { |
| 914 | rc = request_firmware(&cdev->firmware, QED_FW_FILE_NAME, |
| 915 | &cdev->pdev->dev); |
| 916 | if (rc) { |
| 917 | DP_NOTICE(cdev, |
| 918 | "Failed to find fw file - /lib/firmware/%s\n", |
| 919 | QED_FW_FILE_NAME); |
| 920 | goto err; |
| 921 | } |
Sudarsana Reddy Kalluru | c78c70f | 2017-02-15 10:24:10 +0200 | [diff] [blame] | 922 | |
| 923 | p_ptt = qed_ptt_acquire(QED_LEADING_HWFN(cdev)); |
| 924 | if (p_ptt) { |
| 925 | QED_LEADING_HWFN(cdev)->p_ptp_ptt = p_ptt; |
| 926 | } else { |
| 927 | DP_NOTICE(cdev, "Failed to acquire PTT for PTP\n"); |
| 928 | goto err; |
| 929 | } |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 930 | } |
| 931 | |
Sudarsana Reddy Kalluru | 0e19182 | 2016-10-21 04:43:42 -0400 | [diff] [blame] | 932 | cdev->rx_coalesce_usecs = QED_DEFAULT_RX_USECS; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 933 | rc = qed_nic_setup(cdev); |
| 934 | if (rc) |
| 935 | goto err; |
| 936 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 937 | if (IS_PF(cdev)) |
| 938 | rc = qed_slowpath_setup_int(cdev, params->int_mode); |
| 939 | else |
| 940 | rc = qed_slowpath_vf_setup_int(cdev); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 941 | if (rc) |
| 942 | goto err1; |
| 943 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 944 | if (IS_PF(cdev)) { |
| 945 | /* Allocate stream for unzipping */ |
| 946 | rc = qed_alloc_stream_mem(cdev); |
Joe Perches | 2591c28 | 2016-09-04 14:24:03 -0700 | [diff] [blame] | 947 | if (rc) |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 948 | goto err2; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 949 | |
Yuval Mintz | 351a4ded | 2016-06-02 10:23:29 +0300 | [diff] [blame] | 950 | /* First Dword used to diffrentiate between various sources */ |
| 951 | data = cdev->firmware->data + sizeof(u32); |
Tomer Tayar | c965db4 | 2016-09-07 16:36:24 +0300 | [diff] [blame] | 952 | |
| 953 | qed_dbg_pf_init(cdev); |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 954 | } |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 955 | |
Manish Chopra | b18e170 | 2016-04-14 01:38:30 -0400 | [diff] [blame] | 956 | memset(&tunn_info, 0, sizeof(tunn_info)); |
Manish Chopra | 9a109dd | 2016-04-14 01:38:31 -0400 | [diff] [blame] | 957 | tunn_info.tunn_mode |= 1 << QED_MODE_VXLAN_TUNN | |
Manish Chopra | f798586 | 2016-04-14 01:38:32 -0400 | [diff] [blame] | 958 | 1 << QED_MODE_L2GRE_TUNN | |
| 959 | 1 << QED_MODE_IPGRE_TUNN | |
Manish Chopra | 9a109dd | 2016-04-14 01:38:31 -0400 | [diff] [blame] | 960 | 1 << QED_MODE_L2GENEVE_TUNN | |
| 961 | 1 << QED_MODE_IPGENEVE_TUNN; |
| 962 | |
Manish Chopra | b18e170 | 2016-04-14 01:38:30 -0400 | [diff] [blame] | 963 | tunn_info.tunn_clss_vxlan = QED_TUNN_CLSS_MAC_VLAN; |
Manish Chopra | f798586 | 2016-04-14 01:38:32 -0400 | [diff] [blame] | 964 | tunn_info.tunn_clss_l2gre = QED_TUNN_CLSS_MAC_VLAN; |
| 965 | tunn_info.tunn_clss_ipgre = QED_TUNN_CLSS_MAC_VLAN; |
Manish Chopra | b18e170 | 2016-04-14 01:38:30 -0400 | [diff] [blame] | 966 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 967 | /* Start the slowpath */ |
Manish Chopra | b18e170 | 2016-04-14 01:38:30 -0400 | [diff] [blame] | 968 | rc = qed_hw_init(cdev, &tunn_info, true, |
| 969 | cdev->int_params.out.int_mode, |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 970 | true, data); |
| 971 | if (rc) |
Yuval Mintz | 8c925c4 | 2016-03-02 20:26:03 +0200 | [diff] [blame] | 972 | goto err2; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 973 | |
| 974 | DP_INFO(cdev, |
| 975 | "HW initialization and function start completed successfully\n"); |
| 976 | |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 977 | /* Allocate LL2 interface if needed */ |
| 978 | if (QED_LEADING_HWFN(cdev)->using_ll2) { |
| 979 | rc = qed_ll2_alloc_if(cdev); |
| 980 | if (rc) |
| 981 | goto err3; |
| 982 | } |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 983 | if (IS_PF(cdev)) { |
| 984 | hwfn = QED_LEADING_HWFN(cdev); |
| 985 | drv_version.version = (params->drv_major << 24) | |
| 986 | (params->drv_minor << 16) | |
| 987 | (params->drv_rev << 8) | |
| 988 | (params->drv_eng); |
| 989 | strlcpy(drv_version.name, params->name, |
| 990 | MCP_DRV_VER_STR_SIZE - 4); |
| 991 | rc = qed_mcp_send_drv_version(hwfn, hwfn->p_main_ptt, |
| 992 | &drv_version); |
| 993 | if (rc) { |
| 994 | DP_NOTICE(cdev, "Failed sending drv version command\n"); |
| 995 | return rc; |
| 996 | } |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 997 | } |
| 998 | |
Yuval Mintz | 8c925c4 | 2016-03-02 20:26:03 +0200 | [diff] [blame] | 999 | qed_reset_vport_stats(cdev); |
| 1000 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1001 | return 0; |
| 1002 | |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1003 | err3: |
| 1004 | qed_hw_stop(cdev); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1005 | err2: |
Yuval Mintz | 8c925c4 | 2016-03-02 20:26:03 +0200 | [diff] [blame] | 1006 | qed_hw_timers_stop_all(cdev); |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 1007 | if (IS_PF(cdev)) |
| 1008 | qed_slowpath_irq_free(cdev); |
Yuval Mintz | 8c925c4 | 2016-03-02 20:26:03 +0200 | [diff] [blame] | 1009 | qed_free_stream_mem(cdev); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1010 | qed_disable_msix(cdev); |
| 1011 | err1: |
| 1012 | qed_resc_free(cdev); |
| 1013 | err: |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 1014 | if (IS_PF(cdev)) |
| 1015 | release_firmware(cdev->firmware); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1016 | |
Sudarsana Reddy Kalluru | c78c70f | 2017-02-15 10:24:10 +0200 | [diff] [blame] | 1017 | if (IS_PF(cdev) && QED_LEADING_HWFN(cdev)->p_ptp_ptt) |
| 1018 | qed_ptt_release(QED_LEADING_HWFN(cdev), |
| 1019 | QED_LEADING_HWFN(cdev)->p_ptp_ptt); |
| 1020 | |
Yuval Mintz | 37bff2b | 2016-05-11 16:36:13 +0300 | [diff] [blame] | 1021 | qed_iov_wq_stop(cdev, false); |
| 1022 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1023 | return rc; |
| 1024 | } |
| 1025 | |
| 1026 | static int qed_slowpath_stop(struct qed_dev *cdev) |
| 1027 | { |
| 1028 | if (!cdev) |
| 1029 | return -ENODEV; |
| 1030 | |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1031 | qed_ll2_dealloc_if(cdev); |
| 1032 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 1033 | if (IS_PF(cdev)) { |
Sudarsana Reddy Kalluru | c78c70f | 2017-02-15 10:24:10 +0200 | [diff] [blame] | 1034 | qed_ptt_release(QED_LEADING_HWFN(cdev), |
| 1035 | QED_LEADING_HWFN(cdev)->p_ptp_ptt); |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 1036 | qed_free_stream_mem(cdev); |
Yuval Mintz | c5ac931 | 2016-06-03 14:35:34 +0300 | [diff] [blame] | 1037 | if (IS_QED_ETH_IF(cdev)) |
| 1038 | qed_sriov_disable(cdev, true); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1039 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 1040 | qed_nic_stop(cdev); |
| 1041 | qed_slowpath_irq_free(cdev); |
| 1042 | } |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1043 | |
| 1044 | qed_disable_msix(cdev); |
| 1045 | qed_nic_reset(cdev); |
| 1046 | |
Yuval Mintz | 37bff2b | 2016-05-11 16:36:13 +0300 | [diff] [blame] | 1047 | qed_iov_wq_stop(cdev, true); |
| 1048 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 1049 | if (IS_PF(cdev)) |
| 1050 | release_firmware(cdev->firmware); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1051 | |
| 1052 | return 0; |
| 1053 | } |
| 1054 | |
| 1055 | static void qed_set_id(struct qed_dev *cdev, char name[NAME_SIZE], |
| 1056 | char ver_str[VER_SIZE]) |
| 1057 | { |
| 1058 | int i; |
| 1059 | |
| 1060 | memcpy(cdev->name, name, NAME_SIZE); |
| 1061 | for_each_hwfn(cdev, i) |
| 1062 | snprintf(cdev->hwfns[i].name, NAME_SIZE, "%s-%d", name, i); |
| 1063 | |
| 1064 | memcpy(cdev->ver_str, ver_str, VER_SIZE); |
| 1065 | cdev->drv_type = DRV_ID_DRV_TYPE_LINUX; |
| 1066 | } |
| 1067 | |
| 1068 | static u32 qed_sb_init(struct qed_dev *cdev, |
| 1069 | struct qed_sb_info *sb_info, |
| 1070 | void *sb_virt_addr, |
| 1071 | dma_addr_t sb_phy_addr, u16 sb_id, |
| 1072 | enum qed_sb_type type) |
| 1073 | { |
| 1074 | struct qed_hwfn *p_hwfn; |
Mintz, Yuval | 85750d7 | 2017-02-20 22:43:38 +0200 | [diff] [blame^] | 1075 | struct qed_ptt *p_ptt; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1076 | int hwfn_index; |
| 1077 | u16 rel_sb_id; |
| 1078 | u8 n_hwfns; |
| 1079 | u32 rc; |
| 1080 | |
| 1081 | /* RoCE uses single engine and CMT uses two engines. When using both |
| 1082 | * we force only a single engine. Storage uses only engine 0 too. |
| 1083 | */ |
| 1084 | if (type == QED_SB_TYPE_L2_QUEUE) |
| 1085 | n_hwfns = cdev->num_hwfns; |
| 1086 | else |
| 1087 | n_hwfns = 1; |
| 1088 | |
| 1089 | hwfn_index = sb_id % n_hwfns; |
| 1090 | p_hwfn = &cdev->hwfns[hwfn_index]; |
| 1091 | rel_sb_id = sb_id / n_hwfns; |
| 1092 | |
| 1093 | DP_VERBOSE(cdev, NETIF_MSG_INTR, |
| 1094 | "hwfn [%d] <--[init]-- SB %04x [0x%04x upper]\n", |
| 1095 | hwfn_index, rel_sb_id, sb_id); |
| 1096 | |
Mintz, Yuval | 85750d7 | 2017-02-20 22:43:38 +0200 | [diff] [blame^] | 1097 | if (IS_PF(p_hwfn->cdev)) { |
| 1098 | p_ptt = qed_ptt_acquire(p_hwfn); |
| 1099 | if (!p_ptt) |
| 1100 | return -EBUSY; |
| 1101 | |
| 1102 | rc = qed_int_sb_init(p_hwfn, p_ptt, sb_info, sb_virt_addr, |
| 1103 | sb_phy_addr, rel_sb_id); |
| 1104 | qed_ptt_release(p_hwfn, p_ptt); |
| 1105 | } else { |
| 1106 | rc = qed_int_sb_init(p_hwfn, NULL, sb_info, sb_virt_addr, |
| 1107 | sb_phy_addr, rel_sb_id); |
| 1108 | } |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1109 | |
| 1110 | return rc; |
| 1111 | } |
| 1112 | |
| 1113 | static u32 qed_sb_release(struct qed_dev *cdev, |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 1114 | struct qed_sb_info *sb_info, u16 sb_id) |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1115 | { |
| 1116 | struct qed_hwfn *p_hwfn; |
| 1117 | int hwfn_index; |
| 1118 | u16 rel_sb_id; |
| 1119 | u32 rc; |
| 1120 | |
| 1121 | hwfn_index = sb_id % cdev->num_hwfns; |
| 1122 | p_hwfn = &cdev->hwfns[hwfn_index]; |
| 1123 | rel_sb_id = sb_id / cdev->num_hwfns; |
| 1124 | |
| 1125 | DP_VERBOSE(cdev, NETIF_MSG_INTR, |
| 1126 | "hwfn [%d] <--[init]-- SB %04x [0x%04x upper]\n", |
| 1127 | hwfn_index, rel_sb_id, sb_id); |
| 1128 | |
| 1129 | rc = qed_int_sb_release(p_hwfn, sb_info, rel_sb_id); |
| 1130 | |
| 1131 | return rc; |
| 1132 | } |
| 1133 | |
Yuval Mintz | fe7cd2b | 2016-04-22 08:41:03 +0300 | [diff] [blame] | 1134 | static bool qed_can_link_change(struct qed_dev *cdev) |
| 1135 | { |
| 1136 | return true; |
| 1137 | } |
| 1138 | |
Yuval Mintz | 351a4ded | 2016-06-02 10:23:29 +0300 | [diff] [blame] | 1139 | static int qed_set_link(struct qed_dev *cdev, struct qed_link_params *params) |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1140 | { |
| 1141 | struct qed_hwfn *hwfn; |
| 1142 | struct qed_mcp_link_params *link_params; |
| 1143 | struct qed_ptt *ptt; |
| 1144 | int rc; |
| 1145 | |
| 1146 | if (!cdev) |
| 1147 | return -ENODEV; |
| 1148 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 1149 | if (IS_VF(cdev)) |
| 1150 | return 0; |
| 1151 | |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1152 | /* The link should be set only once per PF */ |
| 1153 | hwfn = &cdev->hwfns[0]; |
| 1154 | |
| 1155 | ptt = qed_ptt_acquire(hwfn); |
| 1156 | if (!ptt) |
| 1157 | return -EBUSY; |
| 1158 | |
| 1159 | link_params = qed_mcp_get_link_params(hwfn); |
| 1160 | if (params->override_flags & QED_LINK_OVERRIDE_SPEED_AUTONEG) |
| 1161 | link_params->speed.autoneg = params->autoneg; |
| 1162 | if (params->override_flags & QED_LINK_OVERRIDE_SPEED_ADV_SPEEDS) { |
| 1163 | link_params->speed.advertised_speeds = 0; |
Sudarsana Reddy Kalluru | 054c67d | 2016-08-09 03:51:23 -0400 | [diff] [blame] | 1164 | if ((params->adv_speeds & QED_LM_1000baseT_Half_BIT) || |
| 1165 | (params->adv_speeds & QED_LM_1000baseT_Full_BIT)) |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1166 | link_params->speed.advertised_speeds |= |
Sudarsana Reddy Kalluru | 054c67d | 2016-08-09 03:51:23 -0400 | [diff] [blame] | 1167 | NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G; |
| 1168 | if (params->adv_speeds & QED_LM_10000baseKR_Full_BIT) |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1169 | link_params->speed.advertised_speeds |= |
Sudarsana Reddy Kalluru | 054c67d | 2016-08-09 03:51:23 -0400 | [diff] [blame] | 1170 | NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G; |
| 1171 | if (params->adv_speeds & QED_LM_25000baseKR_Full_BIT) |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1172 | link_params->speed.advertised_speeds |= |
Sudarsana Reddy Kalluru | 054c67d | 2016-08-09 03:51:23 -0400 | [diff] [blame] | 1173 | NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_25G; |
| 1174 | if (params->adv_speeds & QED_LM_40000baseLR4_Full_BIT) |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1175 | link_params->speed.advertised_speeds |= |
Sudarsana Reddy Kalluru | 054c67d | 2016-08-09 03:51:23 -0400 | [diff] [blame] | 1176 | NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G; |
| 1177 | if (params->adv_speeds & QED_LM_50000baseKR2_Full_BIT) |
| 1178 | link_params->speed.advertised_speeds |= |
| 1179 | NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_50G; |
| 1180 | if (params->adv_speeds & QED_LM_100000baseKR4_Full_BIT) |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1181 | link_params->speed.advertised_speeds |= |
Yuval Mintz | 351a4ded | 2016-06-02 10:23:29 +0300 | [diff] [blame] | 1182 | NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_BB_100G; |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1183 | } |
| 1184 | if (params->override_flags & QED_LINK_OVERRIDE_SPEED_FORCED_SPEED) |
| 1185 | link_params->speed.forced_speed = params->forced_speed; |
Sudarsana Reddy Kalluru | a43f235 | 2016-04-22 08:41:04 +0300 | [diff] [blame] | 1186 | if (params->override_flags & QED_LINK_OVERRIDE_PAUSE_CONFIG) { |
| 1187 | if (params->pause_config & QED_LINK_PAUSE_AUTONEG_ENABLE) |
| 1188 | link_params->pause.autoneg = true; |
| 1189 | else |
| 1190 | link_params->pause.autoneg = false; |
| 1191 | if (params->pause_config & QED_LINK_PAUSE_RX_ENABLE) |
| 1192 | link_params->pause.forced_rx = true; |
| 1193 | else |
| 1194 | link_params->pause.forced_rx = false; |
| 1195 | if (params->pause_config & QED_LINK_PAUSE_TX_ENABLE) |
| 1196 | link_params->pause.forced_tx = true; |
| 1197 | else |
| 1198 | link_params->pause.forced_tx = false; |
| 1199 | } |
Sudarsana Reddy Kalluru | 03dc76c | 2016-04-28 20:20:52 -0400 | [diff] [blame] | 1200 | if (params->override_flags & QED_LINK_OVERRIDE_LOOPBACK_MODE) { |
| 1201 | switch (params->loopback_mode) { |
| 1202 | case QED_LINK_LOOPBACK_INT_PHY: |
Yuval Mintz | 351a4ded | 2016-06-02 10:23:29 +0300 | [diff] [blame] | 1203 | link_params->loopback_mode = ETH_LOOPBACK_INT_PHY; |
Sudarsana Reddy Kalluru | 03dc76c | 2016-04-28 20:20:52 -0400 | [diff] [blame] | 1204 | break; |
| 1205 | case QED_LINK_LOOPBACK_EXT_PHY: |
Yuval Mintz | 351a4ded | 2016-06-02 10:23:29 +0300 | [diff] [blame] | 1206 | link_params->loopback_mode = ETH_LOOPBACK_EXT_PHY; |
Sudarsana Reddy Kalluru | 03dc76c | 2016-04-28 20:20:52 -0400 | [diff] [blame] | 1207 | break; |
| 1208 | case QED_LINK_LOOPBACK_EXT: |
Yuval Mintz | 351a4ded | 2016-06-02 10:23:29 +0300 | [diff] [blame] | 1209 | link_params->loopback_mode = ETH_LOOPBACK_EXT; |
Sudarsana Reddy Kalluru | 03dc76c | 2016-04-28 20:20:52 -0400 | [diff] [blame] | 1210 | break; |
| 1211 | case QED_LINK_LOOPBACK_MAC: |
Yuval Mintz | 351a4ded | 2016-06-02 10:23:29 +0300 | [diff] [blame] | 1212 | link_params->loopback_mode = ETH_LOOPBACK_MAC; |
Sudarsana Reddy Kalluru | 03dc76c | 2016-04-28 20:20:52 -0400 | [diff] [blame] | 1213 | break; |
| 1214 | default: |
Yuval Mintz | 351a4ded | 2016-06-02 10:23:29 +0300 | [diff] [blame] | 1215 | link_params->loopback_mode = ETH_LOOPBACK_NONE; |
Sudarsana Reddy Kalluru | 03dc76c | 2016-04-28 20:20:52 -0400 | [diff] [blame] | 1216 | break; |
| 1217 | } |
| 1218 | } |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1219 | |
| 1220 | rc = qed_mcp_set_link(hwfn, ptt, params->link_up); |
| 1221 | |
| 1222 | qed_ptt_release(hwfn, ptt); |
| 1223 | |
| 1224 | return rc; |
| 1225 | } |
| 1226 | |
| 1227 | static int qed_get_port_type(u32 media_type) |
| 1228 | { |
| 1229 | int port_type; |
| 1230 | |
| 1231 | switch (media_type) { |
| 1232 | case MEDIA_SFPP_10G_FIBER: |
| 1233 | case MEDIA_SFP_1G_FIBER: |
| 1234 | case MEDIA_XFP_FIBER: |
Yuval Mintz | b639f19 | 2016-06-19 15:18:15 +0300 | [diff] [blame] | 1235 | case MEDIA_MODULE_FIBER: |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1236 | case MEDIA_KR: |
| 1237 | port_type = PORT_FIBRE; |
| 1238 | break; |
| 1239 | case MEDIA_DA_TWINAX: |
| 1240 | port_type = PORT_DA; |
| 1241 | break; |
| 1242 | case MEDIA_BASE_T: |
| 1243 | port_type = PORT_TP; |
| 1244 | break; |
| 1245 | case MEDIA_NOT_PRESENT: |
| 1246 | port_type = PORT_NONE; |
| 1247 | break; |
| 1248 | case MEDIA_UNSPECIFIED: |
| 1249 | default: |
| 1250 | port_type = PORT_OTHER; |
| 1251 | break; |
| 1252 | } |
| 1253 | return port_type; |
| 1254 | } |
| 1255 | |
Arnd Bergmann | 14b84e8 | 2016-06-01 15:29:13 +0200 | [diff] [blame] | 1256 | static int qed_get_link_data(struct qed_hwfn *hwfn, |
| 1257 | struct qed_mcp_link_params *params, |
| 1258 | struct qed_mcp_link_state *link, |
| 1259 | struct qed_mcp_link_capabilities *link_caps) |
| 1260 | { |
| 1261 | void *p; |
| 1262 | |
| 1263 | if (!IS_PF(hwfn->cdev)) { |
| 1264 | qed_vf_get_link_params(hwfn, params); |
| 1265 | qed_vf_get_link_state(hwfn, link); |
| 1266 | qed_vf_get_link_caps(hwfn, link_caps); |
| 1267 | |
| 1268 | return 0; |
| 1269 | } |
| 1270 | |
| 1271 | p = qed_mcp_get_link_params(hwfn); |
| 1272 | if (!p) |
| 1273 | return -ENXIO; |
| 1274 | memcpy(params, p, sizeof(*params)); |
| 1275 | |
| 1276 | p = qed_mcp_get_link_state(hwfn); |
| 1277 | if (!p) |
| 1278 | return -ENXIO; |
| 1279 | memcpy(link, p, sizeof(*link)); |
| 1280 | |
| 1281 | p = qed_mcp_get_link_capabilities(hwfn); |
| 1282 | if (!p) |
| 1283 | return -ENXIO; |
| 1284 | memcpy(link_caps, p, sizeof(*link_caps)); |
| 1285 | |
| 1286 | return 0; |
| 1287 | } |
| 1288 | |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1289 | static void qed_fill_link(struct qed_hwfn *hwfn, |
| 1290 | struct qed_link_output *if_link) |
| 1291 | { |
| 1292 | struct qed_mcp_link_params params; |
| 1293 | struct qed_mcp_link_state link; |
| 1294 | struct qed_mcp_link_capabilities link_caps; |
| 1295 | u32 media_type; |
| 1296 | |
| 1297 | memset(if_link, 0, sizeof(*if_link)); |
| 1298 | |
| 1299 | /* Prepare source inputs */ |
Arnd Bergmann | 14b84e8 | 2016-06-01 15:29:13 +0200 | [diff] [blame] | 1300 | if (qed_get_link_data(hwfn, ¶ms, &link, &link_caps)) { |
| 1301 | dev_warn(&hwfn->cdev->pdev->dev, "no link data available\n"); |
| 1302 | return; |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 1303 | } |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1304 | |
| 1305 | /* Set the link parameters to pass to protocol driver */ |
| 1306 | if (link.link_up) |
| 1307 | if_link->link_up = true; |
| 1308 | |
| 1309 | /* TODO - at the moment assume supported and advertised speed equal */ |
Sudarsana Reddy Kalluru | 054c67d | 2016-08-09 03:51:23 -0400 | [diff] [blame] | 1310 | if_link->supported_caps = QED_LM_FIBRE_BIT; |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1311 | if (params.speed.autoneg) |
Sudarsana Reddy Kalluru | 054c67d | 2016-08-09 03:51:23 -0400 | [diff] [blame] | 1312 | if_link->supported_caps |= QED_LM_Autoneg_BIT; |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1313 | if (params.pause.autoneg || |
| 1314 | (params.pause.forced_rx && params.pause.forced_tx)) |
Sudarsana Reddy Kalluru | 054c67d | 2016-08-09 03:51:23 -0400 | [diff] [blame] | 1315 | if_link->supported_caps |= QED_LM_Asym_Pause_BIT; |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1316 | if (params.pause.autoneg || params.pause.forced_rx || |
| 1317 | params.pause.forced_tx) |
Sudarsana Reddy Kalluru | 054c67d | 2016-08-09 03:51:23 -0400 | [diff] [blame] | 1318 | if_link->supported_caps |= QED_LM_Pause_BIT; |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1319 | |
| 1320 | if_link->advertised_caps = if_link->supported_caps; |
| 1321 | if (params.speed.advertised_speeds & |
| 1322 | NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G) |
Sudarsana Reddy Kalluru | 054c67d | 2016-08-09 03:51:23 -0400 | [diff] [blame] | 1323 | if_link->advertised_caps |= QED_LM_1000baseT_Half_BIT | |
| 1324 | QED_LM_1000baseT_Full_BIT; |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1325 | if (params.speed.advertised_speeds & |
| 1326 | NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G) |
Sudarsana Reddy Kalluru | 054c67d | 2016-08-09 03:51:23 -0400 | [diff] [blame] | 1327 | if_link->advertised_caps |= QED_LM_10000baseKR_Full_BIT; |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1328 | if (params.speed.advertised_speeds & |
Sudarsana Reddy Kalluru | 054c67d | 2016-08-09 03:51:23 -0400 | [diff] [blame] | 1329 | NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_25G) |
| 1330 | if_link->advertised_caps |= QED_LM_25000baseKR_Full_BIT; |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1331 | if (params.speed.advertised_speeds & |
Sudarsana Reddy Kalluru | 054c67d | 2016-08-09 03:51:23 -0400 | [diff] [blame] | 1332 | NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G) |
| 1333 | if_link->advertised_caps |= QED_LM_40000baseLR4_Full_BIT; |
| 1334 | if (params.speed.advertised_speeds & |
| 1335 | NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_50G) |
| 1336 | if_link->advertised_caps |= QED_LM_50000baseKR2_Full_BIT; |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1337 | if (params.speed.advertised_speeds & |
Yuval Mintz | 351a4ded | 2016-06-02 10:23:29 +0300 | [diff] [blame] | 1338 | NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_BB_100G) |
Sudarsana Reddy Kalluru | 054c67d | 2016-08-09 03:51:23 -0400 | [diff] [blame] | 1339 | if_link->advertised_caps |= QED_LM_100000baseKR4_Full_BIT; |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1340 | |
| 1341 | if (link_caps.speed_capabilities & |
| 1342 | NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G) |
Sudarsana Reddy Kalluru | 054c67d | 2016-08-09 03:51:23 -0400 | [diff] [blame] | 1343 | if_link->supported_caps |= QED_LM_1000baseT_Half_BIT | |
| 1344 | QED_LM_1000baseT_Full_BIT; |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1345 | if (link_caps.speed_capabilities & |
| 1346 | NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G) |
Sudarsana Reddy Kalluru | 054c67d | 2016-08-09 03:51:23 -0400 | [diff] [blame] | 1347 | if_link->supported_caps |= QED_LM_10000baseKR_Full_BIT; |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1348 | if (link_caps.speed_capabilities & |
Sudarsana Reddy Kalluru | 054c67d | 2016-08-09 03:51:23 -0400 | [diff] [blame] | 1349 | NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_25G) |
| 1350 | if_link->supported_caps |= QED_LM_25000baseKR_Full_BIT; |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1351 | if (link_caps.speed_capabilities & |
Sudarsana Reddy Kalluru | 054c67d | 2016-08-09 03:51:23 -0400 | [diff] [blame] | 1352 | NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G) |
| 1353 | if_link->supported_caps |= QED_LM_40000baseLR4_Full_BIT; |
| 1354 | if (link_caps.speed_capabilities & |
| 1355 | NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_50G) |
| 1356 | if_link->supported_caps |= QED_LM_50000baseKR2_Full_BIT; |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1357 | if (link_caps.speed_capabilities & |
Yuval Mintz | 351a4ded | 2016-06-02 10:23:29 +0300 | [diff] [blame] | 1358 | NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_BB_100G) |
Sudarsana Reddy Kalluru | 054c67d | 2016-08-09 03:51:23 -0400 | [diff] [blame] | 1359 | if_link->supported_caps |= QED_LM_100000baseKR4_Full_BIT; |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1360 | |
| 1361 | if (link.link_up) |
| 1362 | if_link->speed = link.speed; |
| 1363 | |
| 1364 | /* TODO - fill duplex properly */ |
| 1365 | if_link->duplex = DUPLEX_FULL; |
| 1366 | qed_mcp_get_media_type(hwfn->cdev, &media_type); |
| 1367 | if_link->port = qed_get_port_type(media_type); |
| 1368 | |
| 1369 | if_link->autoneg = params.speed.autoneg; |
| 1370 | |
| 1371 | if (params.pause.autoneg) |
| 1372 | if_link->pause_config |= QED_LINK_PAUSE_AUTONEG_ENABLE; |
| 1373 | if (params.pause.forced_rx) |
| 1374 | if_link->pause_config |= QED_LINK_PAUSE_RX_ENABLE; |
| 1375 | if (params.pause.forced_tx) |
| 1376 | if_link->pause_config |= QED_LINK_PAUSE_TX_ENABLE; |
| 1377 | |
| 1378 | /* Link partner capabilities */ |
Sudarsana Reddy Kalluru | 054c67d | 2016-08-09 03:51:23 -0400 | [diff] [blame] | 1379 | if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_1G_HD) |
| 1380 | if_link->lp_caps |= QED_LM_1000baseT_Half_BIT; |
| 1381 | if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_1G_FD) |
| 1382 | if_link->lp_caps |= QED_LM_1000baseT_Full_BIT; |
| 1383 | if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_10G) |
| 1384 | if_link->lp_caps |= QED_LM_10000baseKR_Full_BIT; |
| 1385 | if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_25G) |
| 1386 | if_link->lp_caps |= QED_LM_25000baseKR_Full_BIT; |
| 1387 | if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_40G) |
| 1388 | if_link->lp_caps |= QED_LM_40000baseLR4_Full_BIT; |
| 1389 | if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_50G) |
| 1390 | if_link->lp_caps |= QED_LM_50000baseKR2_Full_BIT; |
| 1391 | if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_100G) |
| 1392 | if_link->lp_caps |= QED_LM_100000baseKR4_Full_BIT; |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1393 | |
| 1394 | if (link.an_complete) |
Sudarsana Reddy Kalluru | 054c67d | 2016-08-09 03:51:23 -0400 | [diff] [blame] | 1395 | if_link->lp_caps |= QED_LM_Autoneg_BIT; |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1396 | |
| 1397 | if (link.partner_adv_pause) |
Sudarsana Reddy Kalluru | 054c67d | 2016-08-09 03:51:23 -0400 | [diff] [blame] | 1398 | if_link->lp_caps |= QED_LM_Pause_BIT; |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1399 | if (link.partner_adv_pause == QED_LINK_PARTNER_ASYMMETRIC_PAUSE || |
| 1400 | link.partner_adv_pause == QED_LINK_PARTNER_BOTH_PAUSE) |
Sudarsana Reddy Kalluru | 054c67d | 2016-08-09 03:51:23 -0400 | [diff] [blame] | 1401 | if_link->lp_caps |= QED_LM_Asym_Pause_BIT; |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1402 | } |
| 1403 | |
| 1404 | static void qed_get_current_link(struct qed_dev *cdev, |
| 1405 | struct qed_link_output *if_link) |
| 1406 | { |
Yuval Mintz | 36558c3 | 2016-05-11 16:36:17 +0300 | [diff] [blame] | 1407 | int i; |
| 1408 | |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1409 | qed_fill_link(&cdev->hwfns[0], if_link); |
Yuval Mintz | 36558c3 | 2016-05-11 16:36:17 +0300 | [diff] [blame] | 1410 | |
| 1411 | for_each_hwfn(cdev, i) |
| 1412 | qed_inform_vf_link_state(&cdev->hwfns[i]); |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1413 | } |
| 1414 | |
| 1415 | void qed_link_update(struct qed_hwfn *hwfn) |
| 1416 | { |
| 1417 | void *cookie = hwfn->cdev->ops_cookie; |
| 1418 | struct qed_common_cb_ops *op = hwfn->cdev->protocol_ops.common; |
| 1419 | struct qed_link_output if_link; |
| 1420 | |
| 1421 | qed_fill_link(hwfn, &if_link); |
Yuval Mintz | 36558c3 | 2016-05-11 16:36:17 +0300 | [diff] [blame] | 1422 | qed_inform_vf_link_state(hwfn); |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1423 | |
| 1424 | if (IS_LEAD_HWFN(hwfn) && cookie) |
| 1425 | op->link_update(cookie, &if_link); |
| 1426 | } |
| 1427 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1428 | static int qed_drain(struct qed_dev *cdev) |
| 1429 | { |
| 1430 | struct qed_hwfn *hwfn; |
| 1431 | struct qed_ptt *ptt; |
| 1432 | int i, rc; |
| 1433 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 1434 | if (IS_VF(cdev)) |
| 1435 | return 0; |
| 1436 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1437 | for_each_hwfn(cdev, i) { |
| 1438 | hwfn = &cdev->hwfns[i]; |
| 1439 | ptt = qed_ptt_acquire(hwfn); |
| 1440 | if (!ptt) { |
| 1441 | DP_NOTICE(hwfn, "Failed to drain NIG; No PTT\n"); |
| 1442 | return -EBUSY; |
| 1443 | } |
| 1444 | rc = qed_mcp_drain(hwfn, ptt); |
| 1445 | if (rc) |
| 1446 | return rc; |
| 1447 | qed_ptt_release(hwfn, ptt); |
| 1448 | } |
| 1449 | |
| 1450 | return 0; |
| 1451 | } |
| 1452 | |
Sudarsana Reddy Kalluru | 722003a | 2016-06-21 09:36:21 -0400 | [diff] [blame] | 1453 | static void qed_get_coalesce(struct qed_dev *cdev, u16 *rx_coal, u16 *tx_coal) |
| 1454 | { |
| 1455 | *rx_coal = cdev->rx_coalesce_usecs; |
| 1456 | *tx_coal = cdev->tx_coalesce_usecs; |
| 1457 | } |
| 1458 | |
| 1459 | static int qed_set_coalesce(struct qed_dev *cdev, u16 rx_coal, u16 tx_coal, |
| 1460 | u8 qid, u16 sb_id) |
| 1461 | { |
| 1462 | struct qed_hwfn *hwfn; |
| 1463 | struct qed_ptt *ptt; |
| 1464 | int hwfn_index; |
| 1465 | int status = 0; |
| 1466 | |
| 1467 | hwfn_index = qid % cdev->num_hwfns; |
| 1468 | hwfn = &cdev->hwfns[hwfn_index]; |
| 1469 | ptt = qed_ptt_acquire(hwfn); |
| 1470 | if (!ptt) |
| 1471 | return -EAGAIN; |
| 1472 | |
| 1473 | status = qed_set_rxq_coalesce(hwfn, ptt, rx_coal, |
| 1474 | qid / cdev->num_hwfns, sb_id); |
| 1475 | if (status) |
| 1476 | goto out; |
| 1477 | status = qed_set_txq_coalesce(hwfn, ptt, tx_coal, |
| 1478 | qid / cdev->num_hwfns, sb_id); |
| 1479 | out: |
| 1480 | qed_ptt_release(hwfn, ptt); |
| 1481 | |
| 1482 | return status; |
| 1483 | } |
| 1484 | |
Sudarsana Kalluru | 91420b8 | 2015-11-30 12:25:03 +0200 | [diff] [blame] | 1485 | static int qed_set_led(struct qed_dev *cdev, enum qed_led_mode mode) |
| 1486 | { |
| 1487 | struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev); |
| 1488 | struct qed_ptt *ptt; |
| 1489 | int status = 0; |
| 1490 | |
| 1491 | ptt = qed_ptt_acquire(hwfn); |
| 1492 | if (!ptt) |
| 1493 | return -EAGAIN; |
| 1494 | |
| 1495 | status = qed_mcp_set_led(hwfn, ptt, mode); |
| 1496 | |
| 1497 | qed_ptt_release(hwfn, ptt); |
| 1498 | |
| 1499 | return status; |
| 1500 | } |
| 1501 | |
Mintz, Yuval | 14d3964 | 2016-10-31 07:14:23 +0200 | [diff] [blame] | 1502 | static int qed_update_wol(struct qed_dev *cdev, bool enabled) |
| 1503 | { |
| 1504 | struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev); |
| 1505 | struct qed_ptt *ptt; |
| 1506 | int rc = 0; |
| 1507 | |
| 1508 | if (IS_VF(cdev)) |
| 1509 | return 0; |
| 1510 | |
| 1511 | ptt = qed_ptt_acquire(hwfn); |
| 1512 | if (!ptt) |
| 1513 | return -EAGAIN; |
| 1514 | |
| 1515 | rc = qed_mcp_ov_update_wol(hwfn, ptt, enabled ? QED_OV_WOL_ENABLED |
| 1516 | : QED_OV_WOL_DISABLED); |
| 1517 | if (rc) |
| 1518 | goto out; |
| 1519 | rc = qed_mcp_ov_update_current_config(hwfn, ptt, QED_OV_CLIENT_DRV); |
| 1520 | |
| 1521 | out: |
| 1522 | qed_ptt_release(hwfn, ptt); |
| 1523 | return rc; |
| 1524 | } |
| 1525 | |
Sudarsana Kalluru | 0fefbfb | 2016-10-31 07:14:21 +0200 | [diff] [blame] | 1526 | static int qed_update_drv_state(struct qed_dev *cdev, bool active) |
| 1527 | { |
| 1528 | struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev); |
| 1529 | struct qed_ptt *ptt; |
| 1530 | int status = 0; |
| 1531 | |
| 1532 | if (IS_VF(cdev)) |
| 1533 | return 0; |
| 1534 | |
| 1535 | ptt = qed_ptt_acquire(hwfn); |
| 1536 | if (!ptt) |
| 1537 | return -EAGAIN; |
| 1538 | |
| 1539 | status = qed_mcp_ov_update_driver_state(hwfn, ptt, active ? |
| 1540 | QED_OV_DRIVER_STATE_ACTIVE : |
| 1541 | QED_OV_DRIVER_STATE_DISABLED); |
| 1542 | |
| 1543 | qed_ptt_release(hwfn, ptt); |
| 1544 | |
| 1545 | return status; |
| 1546 | } |
| 1547 | |
| 1548 | static int qed_update_mac(struct qed_dev *cdev, u8 *mac) |
| 1549 | { |
| 1550 | struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev); |
| 1551 | struct qed_ptt *ptt; |
| 1552 | int status = 0; |
| 1553 | |
| 1554 | if (IS_VF(cdev)) |
| 1555 | return 0; |
| 1556 | |
| 1557 | ptt = qed_ptt_acquire(hwfn); |
| 1558 | if (!ptt) |
| 1559 | return -EAGAIN; |
| 1560 | |
| 1561 | status = qed_mcp_ov_update_mac(hwfn, ptt, mac); |
| 1562 | if (status) |
| 1563 | goto out; |
| 1564 | |
| 1565 | status = qed_mcp_ov_update_current_config(hwfn, ptt, QED_OV_CLIENT_DRV); |
| 1566 | |
| 1567 | out: |
| 1568 | qed_ptt_release(hwfn, ptt); |
| 1569 | return status; |
| 1570 | } |
| 1571 | |
| 1572 | static int qed_update_mtu(struct qed_dev *cdev, u16 mtu) |
| 1573 | { |
| 1574 | struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev); |
| 1575 | struct qed_ptt *ptt; |
| 1576 | int status = 0; |
| 1577 | |
| 1578 | if (IS_VF(cdev)) |
| 1579 | return 0; |
| 1580 | |
| 1581 | ptt = qed_ptt_acquire(hwfn); |
| 1582 | if (!ptt) |
| 1583 | return -EAGAIN; |
| 1584 | |
| 1585 | status = qed_mcp_ov_update_mtu(hwfn, ptt, mtu); |
| 1586 | if (status) |
| 1587 | goto out; |
| 1588 | |
| 1589 | status = qed_mcp_ov_update_current_config(hwfn, ptt, QED_OV_CLIENT_DRV); |
| 1590 | |
| 1591 | out: |
| 1592 | qed_ptt_release(hwfn, ptt); |
| 1593 | return status; |
| 1594 | } |
| 1595 | |
Yuval Mintz | 8c93bea | 2016-10-13 22:57:03 +0300 | [diff] [blame] | 1596 | static struct qed_selftest_ops qed_selftest_ops_pass = { |
Sudarsana Reddy Kalluru | 03dc76c | 2016-04-28 20:20:52 -0400 | [diff] [blame] | 1597 | .selftest_memory = &qed_selftest_memory, |
| 1598 | .selftest_interrupt = &qed_selftest_interrupt, |
| 1599 | .selftest_register = &qed_selftest_register, |
| 1600 | .selftest_clock = &qed_selftest_clock, |
Mintz, Yuval | 7a4b21b | 2016-10-31 07:14:22 +0200 | [diff] [blame] | 1601 | .selftest_nvram = &qed_selftest_nvram, |
Sudarsana Reddy Kalluru | 03dc76c | 2016-04-28 20:20:52 -0400 | [diff] [blame] | 1602 | }; |
| 1603 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1604 | const struct qed_common_ops qed_common_ops_pass = { |
Sudarsana Reddy Kalluru | 03dc76c | 2016-04-28 20:20:52 -0400 | [diff] [blame] | 1605 | .selftest = &qed_selftest_ops_pass, |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1606 | .probe = &qed_probe, |
| 1607 | .remove = &qed_remove, |
| 1608 | .set_power_state = &qed_set_power_state, |
| 1609 | .set_id = &qed_set_id, |
| 1610 | .update_pf_params = &qed_update_pf_params, |
| 1611 | .slowpath_start = &qed_slowpath_start, |
| 1612 | .slowpath_stop = &qed_slowpath_stop, |
| 1613 | .set_fp_int = &qed_set_int_fp, |
| 1614 | .get_fp_int = &qed_get_int_fp, |
| 1615 | .sb_init = &qed_sb_init, |
| 1616 | .sb_release = &qed_sb_release, |
| 1617 | .simd_handler_config = &qed_simd_handler_config, |
| 1618 | .simd_handler_clean = &qed_simd_handler_clean, |
Arun Easi | 1e128c8 | 2017-02-15 06:28:22 -0800 | [diff] [blame] | 1619 | .dbg_grc = &qed_dbg_grc, |
| 1620 | .dbg_grc_size = &qed_dbg_grc_size, |
Yuval Mintz | fe7cd2b | 2016-04-22 08:41:03 +0300 | [diff] [blame] | 1621 | .can_link_change = &qed_can_link_change, |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1622 | .set_link = &qed_set_link, |
| 1623 | .get_link = &qed_get_current_link, |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1624 | .drain = &qed_drain, |
| 1625 | .update_msglvl = &qed_init_dp, |
Tomer Tayar | e0971c8 | 2016-09-07 16:36:25 +0300 | [diff] [blame] | 1626 | .dbg_all_data = &qed_dbg_all_data, |
| 1627 | .dbg_all_data_size = &qed_dbg_all_data_size, |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1628 | .chain_alloc = &qed_chain_alloc, |
| 1629 | .chain_free = &qed_chain_free, |
Sudarsana Reddy Kalluru | 722003a | 2016-06-21 09:36:21 -0400 | [diff] [blame] | 1630 | .get_coalesce = &qed_get_coalesce, |
| 1631 | .set_coalesce = &qed_set_coalesce, |
Sudarsana Kalluru | 91420b8 | 2015-11-30 12:25:03 +0200 | [diff] [blame] | 1632 | .set_led = &qed_set_led, |
Sudarsana Kalluru | 0fefbfb | 2016-10-31 07:14:21 +0200 | [diff] [blame] | 1633 | .update_drv_state = &qed_update_drv_state, |
| 1634 | .update_mac = &qed_update_mac, |
| 1635 | .update_mtu = &qed_update_mtu, |
Mintz, Yuval | 14d3964 | 2016-10-31 07:14:23 +0200 | [diff] [blame] | 1636 | .update_wol = &qed_update_wol, |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1637 | }; |
Sudarsana Reddy Kalluru | 6c75424 | 2016-08-16 10:51:03 -0400 | [diff] [blame] | 1638 | |
| 1639 | void qed_get_protocol_stats(struct qed_dev *cdev, |
| 1640 | enum qed_mcp_protocol_type type, |
| 1641 | union qed_mcp_protocol_stats *stats) |
| 1642 | { |
| 1643 | struct qed_eth_stats eth_stats; |
| 1644 | |
| 1645 | memset(stats, 0, sizeof(*stats)); |
| 1646 | |
| 1647 | switch (type) { |
| 1648 | case QED_MCP_LAN_STATS: |
| 1649 | qed_get_vport_stats(cdev, ð_stats); |
| 1650 | stats->lan_stats.ucast_rx_pkts = eth_stats.rx_ucast_pkts; |
| 1651 | stats->lan_stats.ucast_tx_pkts = eth_stats.tx_ucast_pkts; |
| 1652 | stats->lan_stats.fcs_err = -1; |
| 1653 | break; |
Arun Easi | 1e128c8 | 2017-02-15 06:28:22 -0800 | [diff] [blame] | 1654 | case QED_MCP_FCOE_STATS: |
| 1655 | qed_get_protocol_stats_fcoe(cdev, &stats->fcoe_stats); |
| 1656 | break; |
Sudarsana Reddy Kalluru | 6c75424 | 2016-08-16 10:51:03 -0400 | [diff] [blame] | 1657 | default: |
| 1658 | DP_ERR(cdev, "Invalid protocol type = %d\n", type); |
| 1659 | return; |
| 1660 | } |
| 1661 | } |