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