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