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