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> |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 37 | #include <linux/delay.h> |
| 38 | #include <asm/byteorder.h> |
| 39 | #include <linux/dma-mapping.h> |
| 40 | #include <linux/string.h> |
| 41 | #include <linux/module.h> |
| 42 | #include <linux/interrupt.h> |
| 43 | #include <linux/workqueue.h> |
| 44 | #include <linux/ethtool.h> |
| 45 | #include <linux/etherdevice.h> |
| 46 | #include <linux/vmalloc.h> |
Tomer Tayar | 5d24bcf | 2017-03-28 15:12:52 +0300 | [diff] [blame] | 47 | #include <linux/crash_dump.h> |
Sudarsana Reddy Kalluru | 3a69cae | 2018-03-28 05:14:22 -0700 | [diff] [blame] | 48 | #include <linux/crc32.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 | |
Mintz, Yuval | 1a850bf | 2017-06-04 13:31:07 +0300 | [diff] [blame] | 126 | if (cdev->doorbells && cdev->db_size) |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 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 | |
Mintz, Yuval | 1a850bf | 2017-06-04 13:31:07 +0300 | [diff] [blame] | 210 | cdev->db_phys_addr = pci_resource_start(cdev->pdev, 2); |
| 211 | cdev->db_size = pci_resource_len(cdev->pdev, 2); |
| 212 | if (!cdev->db_size) { |
| 213 | if (IS_PF(cdev)) { |
| 214 | DP_NOTICE(cdev, "No Doorbell bar available\n"); |
| 215 | return -EINVAL; |
| 216 | } else { |
| 217 | return 0; |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 218 | } |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 219 | } |
| 220 | |
Mintz, Yuval | 1a850bf | 2017-06-04 13:31:07 +0300 | [diff] [blame] | 221 | cdev->doorbells = ioremap_wc(cdev->db_phys_addr, cdev->db_size); |
| 222 | |
| 223 | if (!cdev->doorbells) { |
| 224 | DP_NOTICE(cdev, "Cannot map doorbell space\n"); |
| 225 | return -ENOMEM; |
| 226 | } |
| 227 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 228 | return 0; |
| 229 | |
| 230 | err2: |
| 231 | pci_release_regions(pdev); |
| 232 | err1: |
| 233 | pci_disable_device(pdev); |
| 234 | err0: |
| 235 | return rc; |
| 236 | } |
| 237 | |
| 238 | int qed_fill_dev_info(struct qed_dev *cdev, |
| 239 | struct qed_dev_info *dev_info) |
| 240 | { |
Kalderon, Michal | c851a9d | 2017-07-02 10:29:21 +0300 | [diff] [blame] | 241 | struct qed_hwfn *p_hwfn = QED_LEADING_HWFN(cdev); |
| 242 | struct qed_hw_info *hw_info = &p_hwfn->hw_info; |
Chopra, Manish | 19489c7 | 2017-04-24 10:00:45 -0700 | [diff] [blame] | 243 | struct qed_tunnel_info *tun = &cdev->tunnel; |
Manish Chopra | cee4d26 | 2015-10-26 11:02:28 +0200 | [diff] [blame] | 244 | struct qed_ptt *ptt; |
| 245 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 246 | memset(dev_info, 0, sizeof(struct qed_dev_info)); |
| 247 | |
Chopra, Manish | 19489c7 | 2017-04-24 10:00:45 -0700 | [diff] [blame] | 248 | if (tun->vxlan.tun_cls == QED_TUNN_CLSS_MAC_VLAN && |
| 249 | tun->vxlan.b_mode_enabled) |
| 250 | dev_info->vxlan_enable = true; |
| 251 | |
| 252 | if (tun->l2_gre.b_mode_enabled && tun->ip_gre.b_mode_enabled && |
| 253 | tun->l2_gre.tun_cls == QED_TUNN_CLSS_MAC_VLAN && |
| 254 | tun->ip_gre.tun_cls == QED_TUNN_CLSS_MAC_VLAN) |
| 255 | dev_info->gre_enable = true; |
| 256 | |
| 257 | if (tun->l2_geneve.b_mode_enabled && tun->ip_geneve.b_mode_enabled && |
| 258 | tun->l2_geneve.tun_cls == QED_TUNN_CLSS_MAC_VLAN && |
| 259 | tun->ip_geneve.tun_cls == QED_TUNN_CLSS_MAC_VLAN) |
| 260 | dev_info->geneve_enable = true; |
| 261 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 262 | dev_info->num_hwfns = cdev->num_hwfns; |
| 263 | dev_info->pci_mem_start = cdev->pci_params.mem_start; |
| 264 | dev_info->pci_mem_end = cdev->pci_params.mem_end; |
| 265 | dev_info->pci_irq = cdev->pci_params.irq; |
Kalderon, Michal | c851a9d | 2017-07-02 10:29:21 +0300 | [diff] [blame] | 266 | dev_info->rdma_supported = QED_IS_RDMA_PERSONALITY(p_hwfn); |
Yuval Mintz | fc48b7a | 2016-02-15 13:22:35 -0500 | [diff] [blame] | 267 | dev_info->is_mf_default = IS_MF_DEFAULT(&cdev->hwfns[0]); |
Mintz, Yuval | 9c79dda | 2017-03-14 16:23:54 +0200 | [diff] [blame] | 268 | dev_info->dev_type = cdev->type; |
Kalderon, Michal | c851a9d | 2017-07-02 10:29:21 +0300 | [diff] [blame] | 269 | ether_addr_copy(dev_info->hw_mac, hw_info->hw_mac_addr); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 270 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 271 | if (IS_PF(cdev)) { |
| 272 | dev_info->fw_major = FW_MAJOR_VERSION; |
| 273 | dev_info->fw_minor = FW_MINOR_VERSION; |
| 274 | dev_info->fw_rev = FW_REVISION_VERSION; |
| 275 | dev_info->fw_eng = FW_ENGINEERING_VERSION; |
| 276 | dev_info->mf_mode = cdev->mf_mode; |
Yuval Mintz | 831bfb0e | 2016-05-11 16:36:25 +0300 | [diff] [blame] | 277 | dev_info->tx_switching = true; |
Mintz, Yuval | 14d3964 | 2016-10-31 07:14:23 +0200 | [diff] [blame] | 278 | |
Kalderon, Michal | c851a9d | 2017-07-02 10:29:21 +0300 | [diff] [blame] | 279 | if (hw_info->b_wol_support == QED_WOL_SUPPORT_PME) |
Mintz, Yuval | 14d3964 | 2016-10-31 07:14:23 +0200 | [diff] [blame] | 280 | dev_info->wol_support = true; |
Mintz, Yuval | 3c5da94 | 2017-06-02 08:58:31 +0300 | [diff] [blame] | 281 | |
| 282 | dev_info->abs_pf_id = QED_LEADING_HWFN(cdev)->abs_pf_id; |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 283 | } else { |
| 284 | qed_vf_get_fw_version(&cdev->hwfns[0], &dev_info->fw_major, |
| 285 | &dev_info->fw_minor, &dev_info->fw_rev, |
| 286 | &dev_info->fw_eng); |
| 287 | } |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 288 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 289 | if (IS_PF(cdev)) { |
| 290 | ptt = qed_ptt_acquire(QED_LEADING_HWFN(cdev)); |
| 291 | if (ptt) { |
| 292 | qed_mcp_get_mfw_ver(QED_LEADING_HWFN(cdev), ptt, |
| 293 | &dev_info->mfw_rev, NULL); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 294 | |
Tomer Tayar | ae33666 | 2017-05-23 09:41:26 +0300 | [diff] [blame] | 295 | qed_mcp_get_mbi_ver(QED_LEADING_HWFN(cdev), ptt, |
| 296 | &dev_info->mbi_version); |
| 297 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 298 | qed_mcp_get_flash_size(QED_LEADING_HWFN(cdev), ptt, |
| 299 | &dev_info->flash_size); |
Manish Chopra | cee4d26 | 2015-10-26 11:02:28 +0200 | [diff] [blame] | 300 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 301 | qed_ptt_release(QED_LEADING_HWFN(cdev), ptt); |
| 302 | } |
| 303 | } else { |
| 304 | qed_mcp_get_mfw_ver(QED_LEADING_HWFN(cdev), NULL, |
| 305 | &dev_info->mfw_rev, NULL); |
Manish Chopra | cee4d26 | 2015-10-26 11:02:28 +0200 | [diff] [blame] | 306 | } |
| 307 | |
Kalderon, Michal | c851a9d | 2017-07-02 10:29:21 +0300 | [diff] [blame] | 308 | dev_info->mtu = hw_info->mtu; |
Sudarsana Kalluru | 0fefbfb | 2016-10-31 07:14:21 +0200 | [diff] [blame] | 309 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 310 | return 0; |
| 311 | } |
| 312 | |
| 313 | static void qed_free_cdev(struct qed_dev *cdev) |
| 314 | { |
| 315 | kfree((void *)cdev); |
| 316 | } |
| 317 | |
| 318 | static struct qed_dev *qed_alloc_cdev(struct pci_dev *pdev) |
| 319 | { |
| 320 | struct qed_dev *cdev; |
| 321 | |
| 322 | cdev = kzalloc(sizeof(*cdev), GFP_KERNEL); |
| 323 | if (!cdev) |
| 324 | return cdev; |
| 325 | |
| 326 | qed_init_struct(cdev); |
| 327 | |
| 328 | return cdev; |
| 329 | } |
| 330 | |
| 331 | /* Sets the requested power state */ |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 332 | 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] | 333 | { |
| 334 | if (!cdev) |
| 335 | return -ENODEV; |
| 336 | |
| 337 | DP_VERBOSE(cdev, NETIF_MSG_DRV, "Omitting Power state change\n"); |
| 338 | return 0; |
| 339 | } |
| 340 | |
| 341 | /* probing */ |
| 342 | static struct qed_dev *qed_probe(struct pci_dev *pdev, |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 343 | struct qed_probe_params *params) |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 344 | { |
| 345 | struct qed_dev *cdev; |
| 346 | int rc; |
| 347 | |
| 348 | cdev = qed_alloc_cdev(pdev); |
| 349 | if (!cdev) |
| 350 | goto err0; |
| 351 | |
Mintz, Yuval | 712c3cb | 2017-05-23 09:41:28 +0300 | [diff] [blame] | 352 | cdev->drv_type = DRV_ID_DRV_TYPE_LINUX; |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 353 | cdev->protocol = params->protocol; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 354 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 355 | if (params->is_vf) |
| 356 | cdev->b_is_vf = true; |
| 357 | |
| 358 | qed_init_dp(cdev, params->dp_module, params->dp_level); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 359 | |
| 360 | rc = qed_init_pci(cdev, pdev); |
| 361 | if (rc) { |
| 362 | DP_ERR(cdev, "init pci failed\n"); |
| 363 | goto err1; |
| 364 | } |
| 365 | DP_INFO(cdev, "PCI init completed successfully\n"); |
| 366 | |
| 367 | rc = qed_hw_prepare(cdev, QED_PCI_DEFAULT); |
| 368 | if (rc) { |
| 369 | DP_ERR(cdev, "hw prepare failed\n"); |
| 370 | goto err2; |
| 371 | } |
| 372 | |
| 373 | DP_INFO(cdev, "qed_probe completed successffuly\n"); |
| 374 | |
| 375 | return cdev; |
| 376 | |
| 377 | err2: |
| 378 | qed_free_pci(cdev); |
| 379 | err1: |
| 380 | qed_free_cdev(cdev); |
| 381 | err0: |
| 382 | return NULL; |
| 383 | } |
| 384 | |
| 385 | static void qed_remove(struct qed_dev *cdev) |
| 386 | { |
| 387 | if (!cdev) |
| 388 | return; |
| 389 | |
| 390 | qed_hw_remove(cdev); |
| 391 | |
| 392 | qed_free_pci(cdev); |
| 393 | |
| 394 | qed_set_power_state(cdev, PCI_D3hot); |
| 395 | |
| 396 | qed_free_cdev(cdev); |
| 397 | } |
| 398 | |
| 399 | static void qed_disable_msix(struct qed_dev *cdev) |
| 400 | { |
| 401 | if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) { |
| 402 | pci_disable_msix(cdev->pdev); |
| 403 | kfree(cdev->int_params.msix_table); |
| 404 | } else if (cdev->int_params.out.int_mode == QED_INT_MODE_MSI) { |
| 405 | pci_disable_msi(cdev->pdev); |
| 406 | } |
| 407 | |
| 408 | memset(&cdev->int_params.out, 0, sizeof(struct qed_int_param)); |
| 409 | } |
| 410 | |
| 411 | static int qed_enable_msix(struct qed_dev *cdev, |
| 412 | struct qed_int_params *int_params) |
| 413 | { |
| 414 | int i, rc, cnt; |
| 415 | |
| 416 | cnt = int_params->in.num_vectors; |
| 417 | |
| 418 | for (i = 0; i < cnt; i++) |
| 419 | int_params->msix_table[i].entry = i; |
| 420 | |
| 421 | rc = pci_enable_msix_range(cdev->pdev, int_params->msix_table, |
| 422 | int_params->in.min_msix_cnt, cnt); |
| 423 | if (rc < cnt && rc >= int_params->in.min_msix_cnt && |
| 424 | (rc % cdev->num_hwfns)) { |
| 425 | pci_disable_msix(cdev->pdev); |
| 426 | |
| 427 | /* If fastpath is initialized, we need at least one interrupt |
| 428 | * per hwfn [and the slow path interrupts]. New requested number |
| 429 | * should be a multiple of the number of hwfns. |
| 430 | */ |
| 431 | cnt = (rc / cdev->num_hwfns) * cdev->num_hwfns; |
| 432 | DP_NOTICE(cdev, |
| 433 | "Trying to enable MSI-X with less vectors (%d out of %d)\n", |
| 434 | cnt, int_params->in.num_vectors); |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 435 | rc = pci_enable_msix_exact(cdev->pdev, int_params->msix_table, |
| 436 | cnt); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 437 | if (!rc) |
| 438 | rc = cnt; |
| 439 | } |
| 440 | |
| 441 | if (rc > 0) { |
| 442 | /* MSI-x configuration was achieved */ |
| 443 | int_params->out.int_mode = QED_INT_MODE_MSIX; |
| 444 | int_params->out.num_vectors = rc; |
| 445 | rc = 0; |
| 446 | } else { |
| 447 | DP_NOTICE(cdev, |
| 448 | "Failed to enable MSI-X [Requested %d vectors][rc %d]\n", |
| 449 | cnt, rc); |
| 450 | } |
| 451 | |
| 452 | return rc; |
| 453 | } |
| 454 | |
| 455 | /* This function outputs the int mode and the number of enabled msix vector */ |
| 456 | static int qed_set_int_mode(struct qed_dev *cdev, bool force_mode) |
| 457 | { |
| 458 | struct qed_int_params *int_params = &cdev->int_params; |
| 459 | struct msix_entry *tbl; |
| 460 | int rc = 0, cnt; |
| 461 | |
| 462 | switch (int_params->in.int_mode) { |
| 463 | case QED_INT_MODE_MSIX: |
| 464 | /* Allocate MSIX table */ |
| 465 | cnt = int_params->in.num_vectors; |
| 466 | int_params->msix_table = kcalloc(cnt, sizeof(*tbl), GFP_KERNEL); |
| 467 | if (!int_params->msix_table) { |
| 468 | rc = -ENOMEM; |
| 469 | goto out; |
| 470 | } |
| 471 | |
| 472 | /* Enable MSIX */ |
| 473 | rc = qed_enable_msix(cdev, int_params); |
| 474 | if (!rc) |
| 475 | goto out; |
| 476 | |
| 477 | DP_NOTICE(cdev, "Failed to enable MSI-X\n"); |
| 478 | kfree(int_params->msix_table); |
| 479 | if (force_mode) |
| 480 | goto out; |
| 481 | /* Fallthrough */ |
| 482 | |
| 483 | case QED_INT_MODE_MSI: |
Sudarsana Reddy Kalluru | bb13ace | 2016-05-26 11:01:23 +0300 | [diff] [blame] | 484 | if (cdev->num_hwfns == 1) { |
| 485 | rc = pci_enable_msi(cdev->pdev); |
| 486 | if (!rc) { |
| 487 | int_params->out.int_mode = QED_INT_MODE_MSI; |
| 488 | goto out; |
| 489 | } |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 490 | |
Sudarsana Reddy Kalluru | bb13ace | 2016-05-26 11:01:23 +0300 | [diff] [blame] | 491 | DP_NOTICE(cdev, "Failed to enable MSI\n"); |
| 492 | if (force_mode) |
| 493 | goto out; |
| 494 | } |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 495 | /* Fallthrough */ |
| 496 | |
| 497 | case QED_INT_MODE_INTA: |
| 498 | int_params->out.int_mode = QED_INT_MODE_INTA; |
| 499 | rc = 0; |
| 500 | goto out; |
| 501 | default: |
| 502 | DP_NOTICE(cdev, "Unknown int_mode value %d\n", |
| 503 | int_params->in.int_mode); |
| 504 | rc = -EINVAL; |
| 505 | } |
| 506 | |
| 507 | out: |
Yuval Mintz | 525ef5c | 2016-08-15 10:42:45 +0300 | [diff] [blame] | 508 | if (!rc) |
| 509 | DP_INFO(cdev, "Using %s interrupts\n", |
| 510 | int_params->out.int_mode == QED_INT_MODE_INTA ? |
| 511 | "INTa" : int_params->out.int_mode == QED_INT_MODE_MSI ? |
| 512 | "MSI" : "MSIX"); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 513 | cdev->int_coalescing_mode = QED_COAL_MODE_ENABLE; |
| 514 | |
| 515 | return rc; |
| 516 | } |
| 517 | |
| 518 | static void qed_simd_handler_config(struct qed_dev *cdev, void *token, |
| 519 | int index, void(*handler)(void *)) |
| 520 | { |
| 521 | struct qed_hwfn *hwfn = &cdev->hwfns[index % cdev->num_hwfns]; |
| 522 | int relative_idx = index / cdev->num_hwfns; |
| 523 | |
| 524 | hwfn->simd_proto_handler[relative_idx].func = handler; |
| 525 | hwfn->simd_proto_handler[relative_idx].token = token; |
| 526 | } |
| 527 | |
| 528 | static void qed_simd_handler_clean(struct qed_dev *cdev, int index) |
| 529 | { |
| 530 | struct qed_hwfn *hwfn = &cdev->hwfns[index % cdev->num_hwfns]; |
| 531 | int relative_idx = index / cdev->num_hwfns; |
| 532 | |
| 533 | memset(&hwfn->simd_proto_handler[relative_idx], 0, |
| 534 | sizeof(struct qed_simd_fp_handler)); |
| 535 | } |
| 536 | |
| 537 | static irqreturn_t qed_msix_sp_int(int irq, void *tasklet) |
| 538 | { |
| 539 | tasklet_schedule((struct tasklet_struct *)tasklet); |
| 540 | return IRQ_HANDLED; |
| 541 | } |
| 542 | |
| 543 | static irqreturn_t qed_single_int(int irq, void *dev_instance) |
| 544 | { |
| 545 | struct qed_dev *cdev = (struct qed_dev *)dev_instance; |
| 546 | struct qed_hwfn *hwfn; |
| 547 | irqreturn_t rc = IRQ_NONE; |
| 548 | u64 status; |
| 549 | int i, j; |
| 550 | |
| 551 | for (i = 0; i < cdev->num_hwfns; i++) { |
| 552 | status = qed_int_igu_read_sisr_reg(&cdev->hwfns[i]); |
| 553 | |
| 554 | if (!status) |
| 555 | continue; |
| 556 | |
| 557 | hwfn = &cdev->hwfns[i]; |
| 558 | |
| 559 | /* Slowpath interrupt */ |
| 560 | if (unlikely(status & 0x1)) { |
| 561 | tasklet_schedule(hwfn->sp_dpc); |
| 562 | status &= ~0x1; |
| 563 | rc = IRQ_HANDLED; |
| 564 | } |
| 565 | |
| 566 | /* Fastpath interrupts */ |
| 567 | for (j = 0; j < 64; j++) { |
| 568 | if ((0x2ULL << j) & status) { |
| 569 | hwfn->simd_proto_handler[j].func( |
| 570 | hwfn->simd_proto_handler[j].token); |
| 571 | status &= ~(0x2ULL << j); |
| 572 | rc = IRQ_HANDLED; |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | if (unlikely(status)) |
| 577 | DP_VERBOSE(hwfn, NETIF_MSG_INTR, |
| 578 | "got an unknown interrupt status 0x%llx\n", |
| 579 | status); |
| 580 | } |
| 581 | |
| 582 | return rc; |
| 583 | } |
| 584 | |
Sudarsana Kalluru | 8f16bc9 | 2015-12-07 06:25:59 -0500 | [diff] [blame] | 585 | int qed_slowpath_irq_req(struct qed_hwfn *hwfn) |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 586 | { |
Sudarsana Kalluru | 8f16bc9 | 2015-12-07 06:25:59 -0500 | [diff] [blame] | 587 | struct qed_dev *cdev = hwfn->cdev; |
Yuval Mintz | 525ef5c | 2016-08-15 10:42:45 +0300 | [diff] [blame] | 588 | u32 int_mode; |
Sudarsana Kalluru | 8f16bc9 | 2015-12-07 06:25:59 -0500 | [diff] [blame] | 589 | int rc = 0; |
| 590 | u8 id; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 591 | |
Yuval Mintz | 525ef5c | 2016-08-15 10:42:45 +0300 | [diff] [blame] | 592 | int_mode = cdev->int_params.out.int_mode; |
| 593 | if (int_mode == QED_INT_MODE_MSIX) { |
Sudarsana Kalluru | 8f16bc9 | 2015-12-07 06:25:59 -0500 | [diff] [blame] | 594 | id = hwfn->my_id; |
| 595 | snprintf(hwfn->name, NAME_SIZE, "sp-%d-%02x:%02x.%02x", |
| 596 | id, cdev->pdev->bus->number, |
| 597 | PCI_SLOT(cdev->pdev->devfn), hwfn->abs_pf_id); |
| 598 | rc = request_irq(cdev->int_params.msix_table[id].vector, |
| 599 | qed_msix_sp_int, 0, hwfn->name, hwfn->sp_dpc); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 600 | } else { |
| 601 | unsigned long flags = 0; |
| 602 | |
| 603 | snprintf(cdev->name, NAME_SIZE, "%02x:%02x.%02x", |
| 604 | cdev->pdev->bus->number, PCI_SLOT(cdev->pdev->devfn), |
| 605 | PCI_FUNC(cdev->pdev->devfn)); |
| 606 | |
| 607 | if (cdev->int_params.out.int_mode == QED_INT_MODE_INTA) |
| 608 | flags |= IRQF_SHARED; |
| 609 | |
| 610 | rc = request_irq(cdev->pdev->irq, qed_single_int, |
| 611 | flags, cdev->name, cdev); |
| 612 | } |
| 613 | |
Yuval Mintz | 525ef5c | 2016-08-15 10:42:45 +0300 | [diff] [blame] | 614 | if (rc) |
| 615 | DP_NOTICE(cdev, "request_irq failed, rc = %d\n", rc); |
| 616 | else |
| 617 | DP_VERBOSE(hwfn, (NETIF_MSG_INTR | QED_MSG_SP), |
| 618 | "Requested slowpath %s\n", |
| 619 | (int_mode == QED_INT_MODE_MSIX) ? "MSI-X" : "IRQ"); |
| 620 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 621 | return rc; |
| 622 | } |
| 623 | |
Tomer Tayar | 06892f2 | 2017-05-23 09:41:24 +0300 | [diff] [blame] | 624 | static void qed_slowpath_tasklet_flush(struct qed_hwfn *p_hwfn) |
| 625 | { |
| 626 | /* Calling the disable function will make sure that any |
| 627 | * currently-running function is completed. The following call to the |
| 628 | * enable function makes this sequence a flush-like operation. |
| 629 | */ |
| 630 | if (p_hwfn->b_sp_dpc_enabled) { |
| 631 | tasklet_disable(p_hwfn->sp_dpc); |
| 632 | tasklet_enable(p_hwfn->sp_dpc); |
| 633 | } |
| 634 | } |
| 635 | |
Tomer Tayar | 1226337 | 2017-03-28 15:12:50 +0300 | [diff] [blame] | 636 | void qed_slowpath_irq_sync(struct qed_hwfn *p_hwfn) |
| 637 | { |
| 638 | struct qed_dev *cdev = p_hwfn->cdev; |
| 639 | u8 id = p_hwfn->my_id; |
| 640 | u32 int_mode; |
| 641 | |
| 642 | int_mode = cdev->int_params.out.int_mode; |
| 643 | if (int_mode == QED_INT_MODE_MSIX) |
| 644 | synchronize_irq(cdev->int_params.msix_table[id].vector); |
| 645 | else |
| 646 | synchronize_irq(cdev->pdev->irq); |
Tomer Tayar | 06892f2 | 2017-05-23 09:41:24 +0300 | [diff] [blame] | 647 | |
| 648 | qed_slowpath_tasklet_flush(p_hwfn); |
Tomer Tayar | 1226337 | 2017-03-28 15:12:50 +0300 | [diff] [blame] | 649 | } |
| 650 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 651 | static void qed_slowpath_irq_free(struct qed_dev *cdev) |
| 652 | { |
| 653 | int i; |
| 654 | |
| 655 | if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) { |
| 656 | for_each_hwfn(cdev, i) { |
Sudarsana Kalluru | 8f16bc9 | 2015-12-07 06:25:59 -0500 | [diff] [blame] | 657 | if (!cdev->hwfns[i].b_int_requested) |
| 658 | break; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 659 | synchronize_irq(cdev->int_params.msix_table[i].vector); |
| 660 | free_irq(cdev->int_params.msix_table[i].vector, |
| 661 | cdev->hwfns[i].sp_dpc); |
| 662 | } |
| 663 | } else { |
Sudarsana Kalluru | 8f16bc9 | 2015-12-07 06:25:59 -0500 | [diff] [blame] | 664 | if (QED_LEADING_HWFN(cdev)->b_int_requested) |
| 665 | free_irq(cdev->pdev->irq, cdev); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 666 | } |
Sudarsana Kalluru | 8f16bc9 | 2015-12-07 06:25:59 -0500 | [diff] [blame] | 667 | qed_int_disable_post_isr_release(cdev); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | static int qed_nic_stop(struct qed_dev *cdev) |
| 671 | { |
| 672 | int i, rc; |
| 673 | |
| 674 | rc = qed_hw_stop(cdev); |
| 675 | |
| 676 | for (i = 0; i < cdev->num_hwfns; i++) { |
| 677 | struct qed_hwfn *p_hwfn = &cdev->hwfns[i]; |
| 678 | |
| 679 | if (p_hwfn->b_sp_dpc_enabled) { |
| 680 | tasklet_disable(p_hwfn->sp_dpc); |
| 681 | p_hwfn->b_sp_dpc_enabled = false; |
| 682 | DP_VERBOSE(cdev, NETIF_MSG_IFDOWN, |
Colin Ian King | 2fdae03 | 2018-05-10 15:03:27 +0100 | [diff] [blame^] | 683 | "Disabled sp tasklet [hwfn %d] at %p\n", |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 684 | i, p_hwfn->sp_dpc); |
| 685 | } |
| 686 | } |
| 687 | |
Tomer Tayar | c965db4 | 2016-09-07 16:36:24 +0300 | [diff] [blame] | 688 | qed_dbg_pf_exit(cdev); |
| 689 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 690 | return rc; |
| 691 | } |
| 692 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 693 | static int qed_nic_setup(struct qed_dev *cdev) |
| 694 | { |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 695 | int rc, i; |
| 696 | |
| 697 | /* Determine if interface is going to require LL2 */ |
| 698 | if (QED_LEADING_HWFN(cdev)->hw_info.personality != QED_PCI_ETH) { |
| 699 | for (i = 0; i < cdev->num_hwfns; i++) { |
| 700 | struct qed_hwfn *p_hwfn = &cdev->hwfns[i]; |
| 701 | |
| 702 | p_hwfn->using_ll2 = true; |
| 703 | } |
| 704 | } |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 705 | |
| 706 | rc = qed_resc_alloc(cdev); |
| 707 | if (rc) |
| 708 | return rc; |
| 709 | |
| 710 | DP_INFO(cdev, "Allocated qed resources\n"); |
| 711 | |
| 712 | qed_resc_setup(cdev); |
| 713 | |
| 714 | return rc; |
| 715 | } |
| 716 | |
| 717 | static int qed_set_int_fp(struct qed_dev *cdev, u16 cnt) |
| 718 | { |
| 719 | int limit = 0; |
| 720 | |
| 721 | /* Mark the fastpath as free/used */ |
| 722 | cdev->int_params.fp_initialized = cnt ? true : false; |
| 723 | |
| 724 | if (cdev->int_params.out.int_mode != QED_INT_MODE_MSIX) |
| 725 | limit = cdev->num_hwfns * 63; |
| 726 | else if (cdev->int_params.fp_msix_cnt) |
| 727 | limit = cdev->int_params.fp_msix_cnt; |
| 728 | |
| 729 | if (!limit) |
| 730 | return -ENOMEM; |
| 731 | |
| 732 | return min_t(int, cnt, limit); |
| 733 | } |
| 734 | |
| 735 | static int qed_get_int_fp(struct qed_dev *cdev, struct qed_int_info *info) |
| 736 | { |
| 737 | memset(info, 0, sizeof(struct qed_int_info)); |
| 738 | |
| 739 | if (!cdev->int_params.fp_initialized) { |
| 740 | DP_INFO(cdev, |
| 741 | "Protocol driver requested interrupt information, but its support is not yet configured\n"); |
| 742 | return -EINVAL; |
| 743 | } |
| 744 | |
| 745 | /* Need to expose only MSI-X information; Single IRQ is handled solely |
| 746 | * by qed. |
| 747 | */ |
| 748 | if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) { |
| 749 | int msix_base = cdev->int_params.fp_msix_base; |
| 750 | |
| 751 | info->msix_cnt = cdev->int_params.fp_msix_cnt; |
| 752 | info->msix = &cdev->int_params.msix_table[msix_base]; |
| 753 | } |
| 754 | |
| 755 | return 0; |
| 756 | } |
| 757 | |
| 758 | static int qed_slowpath_setup_int(struct qed_dev *cdev, |
| 759 | enum qed_int_mode int_mode) |
| 760 | { |
Yuval Mintz | 4ac801b | 2016-02-28 12:26:52 +0200 | [diff] [blame] | 761 | struct qed_sb_cnt_info sb_cnt_info; |
Yuval Mintz | 0189efb | 2016-10-13 22:57:02 +0300 | [diff] [blame] | 762 | int num_l2_queues = 0; |
Yuval Mintz | 4ac801b | 2016-02-28 12:26:52 +0200 | [diff] [blame] | 763 | int rc; |
| 764 | int i; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 765 | |
Sudarsana Reddy Kalluru | 1d2c202 | 2016-08-01 09:08:13 -0400 | [diff] [blame] | 766 | if ((int_mode == QED_INT_MODE_MSI) && (cdev->num_hwfns > 1)) { |
| 767 | DP_NOTICE(cdev, "MSI mode is not supported for CMT devices\n"); |
| 768 | return -EINVAL; |
| 769 | } |
| 770 | |
| 771 | memset(&cdev->int_params, 0, sizeof(struct qed_int_params)); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 772 | cdev->int_params.in.int_mode = int_mode; |
Yuval Mintz | 4ac801b | 2016-02-28 12:26:52 +0200 | [diff] [blame] | 773 | for_each_hwfn(cdev, i) { |
| 774 | memset(&sb_cnt_info, 0, sizeof(sb_cnt_info)); |
| 775 | qed_int_get_num_sbs(&cdev->hwfns[i], &sb_cnt_info); |
Mintz, Yuval | 726fdbe | 2017-06-01 15:29:06 +0300 | [diff] [blame] | 776 | cdev->int_params.in.num_vectors += sb_cnt_info.cnt; |
Yuval Mintz | 4ac801b | 2016-02-28 12:26:52 +0200 | [diff] [blame] | 777 | cdev->int_params.in.num_vectors++; /* slowpath */ |
| 778 | } |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 779 | |
| 780 | /* We want a minimum of one slowpath and one fastpath vector per hwfn */ |
| 781 | cdev->int_params.in.min_msix_cnt = cdev->num_hwfns * 2; |
| 782 | |
| 783 | rc = qed_set_int_mode(cdev, false); |
| 784 | if (rc) { |
| 785 | DP_ERR(cdev, "qed_slowpath_setup_int ERR\n"); |
| 786 | return rc; |
| 787 | } |
| 788 | |
| 789 | cdev->int_params.fp_msix_base = cdev->num_hwfns; |
| 790 | cdev->int_params.fp_msix_cnt = cdev->int_params.out.num_vectors - |
| 791 | cdev->num_hwfns; |
| 792 | |
Mintz, Yuval | 2f78227 | 2017-04-05 21:20:11 +0300 | [diff] [blame] | 793 | if (!IS_ENABLED(CONFIG_QED_RDMA) || |
Kalderon, Michal | c851a9d | 2017-07-02 10:29:21 +0300 | [diff] [blame] | 794 | !QED_IS_RDMA_PERSONALITY(QED_LEADING_HWFN(cdev))) |
Yuval Mintz | 0189efb | 2016-10-13 22:57:02 +0300 | [diff] [blame] | 795 | return 0; |
| 796 | |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 797 | for_each_hwfn(cdev, i) |
| 798 | num_l2_queues += FEAT_NUM(&cdev->hwfns[i], QED_PF_L2_QUE); |
| 799 | |
| 800 | DP_VERBOSE(cdev, QED_MSG_RDMA, |
| 801 | "cdev->int_params.fp_msix_cnt=%d num_l2_queues=%d\n", |
| 802 | cdev->int_params.fp_msix_cnt, num_l2_queues); |
| 803 | |
| 804 | if (cdev->int_params.fp_msix_cnt > num_l2_queues) { |
| 805 | cdev->int_params.rdma_msix_cnt = |
| 806 | (cdev->int_params.fp_msix_cnt - num_l2_queues) |
| 807 | / cdev->num_hwfns; |
| 808 | cdev->int_params.rdma_msix_base = |
| 809 | cdev->int_params.fp_msix_base + num_l2_queues; |
| 810 | cdev->int_params.fp_msix_cnt = num_l2_queues; |
| 811 | } else { |
| 812 | cdev->int_params.rdma_msix_cnt = 0; |
| 813 | } |
| 814 | |
| 815 | DP_VERBOSE(cdev, QED_MSG_RDMA, "roce_msix_cnt=%d roce_msix_base=%d\n", |
| 816 | cdev->int_params.rdma_msix_cnt, |
| 817 | cdev->int_params.rdma_msix_base); |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 818 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 819 | return 0; |
| 820 | } |
| 821 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 822 | static int qed_slowpath_vf_setup_int(struct qed_dev *cdev) |
| 823 | { |
| 824 | int rc; |
| 825 | |
| 826 | memset(&cdev->int_params, 0, sizeof(struct qed_int_params)); |
| 827 | cdev->int_params.in.int_mode = QED_INT_MODE_MSIX; |
| 828 | |
| 829 | qed_vf_get_num_rxqs(QED_LEADING_HWFN(cdev), |
| 830 | &cdev->int_params.in.num_vectors); |
| 831 | if (cdev->num_hwfns > 1) { |
| 832 | u8 vectors = 0; |
| 833 | |
| 834 | qed_vf_get_num_rxqs(&cdev->hwfns[1], &vectors); |
| 835 | cdev->int_params.in.num_vectors += vectors; |
| 836 | } |
| 837 | |
| 838 | /* We want a minimum of one fastpath vector per vf hwfn */ |
| 839 | cdev->int_params.in.min_msix_cnt = cdev->num_hwfns; |
| 840 | |
| 841 | rc = qed_set_int_mode(cdev, true); |
| 842 | if (rc) |
| 843 | return rc; |
| 844 | |
| 845 | cdev->int_params.fp_msix_base = 0; |
| 846 | cdev->int_params.fp_msix_cnt = cdev->int_params.out.num_vectors; |
| 847 | |
| 848 | return 0; |
| 849 | } |
| 850 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 851 | u32 qed_unzip_data(struct qed_hwfn *p_hwfn, u32 input_len, |
| 852 | u8 *input_buf, u32 max_size, u8 *unzip_buf) |
| 853 | { |
| 854 | int rc; |
| 855 | |
| 856 | p_hwfn->stream->next_in = input_buf; |
| 857 | p_hwfn->stream->avail_in = input_len; |
| 858 | p_hwfn->stream->next_out = unzip_buf; |
| 859 | p_hwfn->stream->avail_out = max_size; |
| 860 | |
| 861 | rc = zlib_inflateInit2(p_hwfn->stream, MAX_WBITS); |
| 862 | |
| 863 | if (rc != Z_OK) { |
| 864 | DP_VERBOSE(p_hwfn, NETIF_MSG_DRV, "zlib init failed, rc = %d\n", |
| 865 | rc); |
| 866 | return 0; |
| 867 | } |
| 868 | |
| 869 | rc = zlib_inflate(p_hwfn->stream, Z_FINISH); |
| 870 | zlib_inflateEnd(p_hwfn->stream); |
| 871 | |
| 872 | if (rc != Z_OK && rc != Z_STREAM_END) { |
| 873 | DP_VERBOSE(p_hwfn, NETIF_MSG_DRV, "FW unzip error: %s, rc=%d\n", |
| 874 | p_hwfn->stream->msg, rc); |
| 875 | return 0; |
| 876 | } |
| 877 | |
| 878 | return p_hwfn->stream->total_out / 4; |
| 879 | } |
| 880 | |
| 881 | static int qed_alloc_stream_mem(struct qed_dev *cdev) |
| 882 | { |
| 883 | int i; |
| 884 | void *workspace; |
| 885 | |
| 886 | for_each_hwfn(cdev, i) { |
| 887 | struct qed_hwfn *p_hwfn = &cdev->hwfns[i]; |
| 888 | |
| 889 | p_hwfn->stream = kzalloc(sizeof(*p_hwfn->stream), GFP_KERNEL); |
| 890 | if (!p_hwfn->stream) |
| 891 | return -ENOMEM; |
| 892 | |
| 893 | workspace = vzalloc(zlib_inflate_workspacesize()); |
| 894 | if (!workspace) |
| 895 | return -ENOMEM; |
| 896 | p_hwfn->stream->workspace = workspace; |
| 897 | } |
| 898 | |
| 899 | return 0; |
| 900 | } |
| 901 | |
| 902 | static void qed_free_stream_mem(struct qed_dev *cdev) |
| 903 | { |
| 904 | int i; |
| 905 | |
| 906 | for_each_hwfn(cdev, i) { |
| 907 | struct qed_hwfn *p_hwfn = &cdev->hwfns[i]; |
| 908 | |
| 909 | if (!p_hwfn->stream) |
| 910 | return; |
| 911 | |
| 912 | vfree(p_hwfn->stream->workspace); |
| 913 | kfree(p_hwfn->stream); |
| 914 | } |
| 915 | } |
| 916 | |
| 917 | static void qed_update_pf_params(struct qed_dev *cdev, |
| 918 | struct qed_pf_params *params) |
| 919 | { |
| 920 | int i; |
| 921 | |
Ram Amrani | 5c5f260 | 2016-11-09 22:48:44 +0200 | [diff] [blame] | 922 | if (IS_ENABLED(CONFIG_QED_RDMA)) { |
| 923 | params->rdma_pf_params.num_qps = QED_ROCE_QPS; |
| 924 | params->rdma_pf_params.min_dpis = QED_ROCE_DPIS; |
| 925 | /* divide by 3 the MRs to avoid MF ILT overflow */ |
Ram Amrani | 5c5f260 | 2016-11-09 22:48:44 +0200 | [diff] [blame] | 926 | params->rdma_pf_params.gl_pi = QED_ROCE_PROTOCOL_INDEX; |
| 927 | } |
| 928 | |
Chopra, Manish | d51e4af | 2017-04-13 04:54:44 -0700 | [diff] [blame] | 929 | if (cdev->num_hwfns > 1 || IS_VF(cdev)) |
| 930 | params->eth_pf_params.num_arfs_filters = 0; |
| 931 | |
Mintz, Yuval | e1d32ac | 2017-01-01 13:57:03 +0200 | [diff] [blame] | 932 | /* In case we might support RDMA, don't allow qede to be greedy |
| 933 | * with the L2 contexts. Allow for 64 queues [rx, tx, xdp] per hwfn. |
| 934 | */ |
Kalderon, Michal | c851a9d | 2017-07-02 10:29:21 +0300 | [diff] [blame] | 935 | if (QED_IS_RDMA_PERSONALITY(QED_LEADING_HWFN(cdev))) { |
Mintz, Yuval | e1d32ac | 2017-01-01 13:57:03 +0200 | [diff] [blame] | 936 | u16 *num_cons; |
| 937 | |
| 938 | num_cons = ¶ms->eth_pf_params.num_cons; |
| 939 | *num_cons = min_t(u16, *num_cons, 192); |
| 940 | } |
| 941 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 942 | for (i = 0; i < cdev->num_hwfns; i++) { |
| 943 | struct qed_hwfn *p_hwfn = &cdev->hwfns[i]; |
| 944 | |
| 945 | p_hwfn->pf_params = *params; |
| 946 | } |
| 947 | } |
| 948 | |
| 949 | static int qed_slowpath_start(struct qed_dev *cdev, |
| 950 | struct qed_slowpath_params *params) |
| 951 | { |
Tomer Tayar | 5d24bcf | 2017-03-28 15:12:52 +0300 | [diff] [blame] | 952 | struct qed_drv_load_params drv_load_params; |
Mintz, Yuval | c0c2d0b | 2017-03-28 15:12:51 +0300 | [diff] [blame] | 953 | struct qed_hw_init_params hw_init_params; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 954 | struct qed_mcp_drv_version drv_version; |
Chopra, Manish | 19968430 | 2017-04-24 10:00:44 -0700 | [diff] [blame] | 955 | struct qed_tunnel_info tunn_info; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 956 | const u8 *data = NULL; |
| 957 | struct qed_hwfn *hwfn; |
Sudarsana Reddy Kalluru | c78c70f | 2017-02-15 10:24:10 +0200 | [diff] [blame] | 958 | struct qed_ptt *p_ptt; |
Yuval Mintz | 37bff2b | 2016-05-11 16:36:13 +0300 | [diff] [blame] | 959 | int rc = -EINVAL; |
| 960 | |
| 961 | if (qed_iov_wq_start(cdev)) |
| 962 | goto err; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 963 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 964 | if (IS_PF(cdev)) { |
| 965 | rc = request_firmware(&cdev->firmware, QED_FW_FILE_NAME, |
| 966 | &cdev->pdev->dev); |
| 967 | if (rc) { |
| 968 | DP_NOTICE(cdev, |
| 969 | "Failed to find fw file - /lib/firmware/%s\n", |
| 970 | QED_FW_FILE_NAME); |
| 971 | goto err; |
| 972 | } |
Sudarsana Reddy Kalluru | c78c70f | 2017-02-15 10:24:10 +0200 | [diff] [blame] | 973 | |
Chopra, Manish | d51e4af | 2017-04-13 04:54:44 -0700 | [diff] [blame] | 974 | if (cdev->num_hwfns == 1) { |
| 975 | p_ptt = qed_ptt_acquire(QED_LEADING_HWFN(cdev)); |
| 976 | if (p_ptt) { |
| 977 | QED_LEADING_HWFN(cdev)->p_arfs_ptt = p_ptt; |
| 978 | } else { |
| 979 | DP_NOTICE(cdev, |
| 980 | "Failed to acquire PTT for aRFS\n"); |
| 981 | goto err; |
| 982 | } |
| 983 | } |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 984 | } |
| 985 | |
Sudarsana Reddy Kalluru | 0e19182 | 2016-10-21 04:43:42 -0400 | [diff] [blame] | 986 | cdev->rx_coalesce_usecs = QED_DEFAULT_RX_USECS; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 987 | rc = qed_nic_setup(cdev); |
| 988 | if (rc) |
| 989 | goto err; |
| 990 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 991 | if (IS_PF(cdev)) |
| 992 | rc = qed_slowpath_setup_int(cdev, params->int_mode); |
| 993 | else |
| 994 | rc = qed_slowpath_vf_setup_int(cdev); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 995 | if (rc) |
| 996 | goto err1; |
| 997 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 998 | if (IS_PF(cdev)) { |
| 999 | /* Allocate stream for unzipping */ |
| 1000 | rc = qed_alloc_stream_mem(cdev); |
Joe Perches | 2591c28 | 2016-09-04 14:24:03 -0700 | [diff] [blame] | 1001 | if (rc) |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 1002 | goto err2; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1003 | |
Joe Perches | 8ac1ed7 | 2017-05-08 15:57:56 -0700 | [diff] [blame] | 1004 | /* First Dword used to differentiate between various sources */ |
Yuval Mintz | 351a4ded | 2016-06-02 10:23:29 +0300 | [diff] [blame] | 1005 | data = cdev->firmware->data + sizeof(u32); |
Tomer Tayar | c965db4 | 2016-09-07 16:36:24 +0300 | [diff] [blame] | 1006 | |
| 1007 | qed_dbg_pf_init(cdev); |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 1008 | } |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1009 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 1010 | /* Start the slowpath */ |
Mintz, Yuval | c0c2d0b | 2017-03-28 15:12:51 +0300 | [diff] [blame] | 1011 | memset(&hw_init_params, 0, sizeof(hw_init_params)); |
Chopra, Manish | 19968430 | 2017-04-24 10:00:44 -0700 | [diff] [blame] | 1012 | memset(&tunn_info, 0, sizeof(tunn_info)); |
| 1013 | tunn_info.vxlan.b_mode_enabled = true; |
| 1014 | tunn_info.l2_gre.b_mode_enabled = true; |
| 1015 | tunn_info.ip_gre.b_mode_enabled = true; |
| 1016 | tunn_info.l2_geneve.b_mode_enabled = true; |
| 1017 | tunn_info.ip_geneve.b_mode_enabled = true; |
| 1018 | tunn_info.vxlan.tun_cls = QED_TUNN_CLSS_MAC_VLAN; |
| 1019 | tunn_info.l2_gre.tun_cls = QED_TUNN_CLSS_MAC_VLAN; |
| 1020 | tunn_info.ip_gre.tun_cls = QED_TUNN_CLSS_MAC_VLAN; |
| 1021 | tunn_info.l2_geneve.tun_cls = QED_TUNN_CLSS_MAC_VLAN; |
| 1022 | tunn_info.ip_geneve.tun_cls = QED_TUNN_CLSS_MAC_VLAN; |
Mintz, Yuval | c0c2d0b | 2017-03-28 15:12:51 +0300 | [diff] [blame] | 1023 | hw_init_params.p_tunn = &tunn_info; |
| 1024 | hw_init_params.b_hw_start = true; |
| 1025 | hw_init_params.int_mode = cdev->int_params.out.int_mode; |
| 1026 | hw_init_params.allow_npar_tx_switch = true; |
| 1027 | hw_init_params.bin_fw_data = data; |
| 1028 | |
Tomer Tayar | 5d24bcf | 2017-03-28 15:12:52 +0300 | [diff] [blame] | 1029 | memset(&drv_load_params, 0, sizeof(drv_load_params)); |
| 1030 | drv_load_params.is_crash_kernel = is_kdump_kernel(); |
| 1031 | drv_load_params.mfw_timeout_val = QED_LOAD_REQ_LOCK_TO_DEFAULT; |
| 1032 | drv_load_params.avoid_eng_reset = false; |
| 1033 | drv_load_params.override_force_load = QED_OVERRIDE_FORCE_LOAD_NONE; |
| 1034 | hw_init_params.p_drv_load_params = &drv_load_params; |
| 1035 | |
Mintz, Yuval | c0c2d0b | 2017-03-28 15:12:51 +0300 | [diff] [blame] | 1036 | rc = qed_hw_init(cdev, &hw_init_params); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1037 | if (rc) |
Yuval Mintz | 8c925c4 | 2016-03-02 20:26:03 +0200 | [diff] [blame] | 1038 | goto err2; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1039 | |
| 1040 | DP_INFO(cdev, |
| 1041 | "HW initialization and function start completed successfully\n"); |
| 1042 | |
Chopra, Manish | eaf3c0c | 2017-04-24 10:00:49 -0700 | [diff] [blame] | 1043 | if (IS_PF(cdev)) { |
| 1044 | cdev->tunn_feature_mask = (BIT(QED_MODE_VXLAN_TUNN) | |
| 1045 | BIT(QED_MODE_L2GENEVE_TUNN) | |
| 1046 | BIT(QED_MODE_IPGENEVE_TUNN) | |
| 1047 | BIT(QED_MODE_L2GRE_TUNN) | |
| 1048 | BIT(QED_MODE_IPGRE_TUNN)); |
| 1049 | } |
| 1050 | |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1051 | /* Allocate LL2 interface if needed */ |
| 1052 | if (QED_LEADING_HWFN(cdev)->using_ll2) { |
| 1053 | rc = qed_ll2_alloc_if(cdev); |
| 1054 | if (rc) |
| 1055 | goto err3; |
| 1056 | } |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 1057 | if (IS_PF(cdev)) { |
| 1058 | hwfn = QED_LEADING_HWFN(cdev); |
| 1059 | drv_version.version = (params->drv_major << 24) | |
| 1060 | (params->drv_minor << 16) | |
| 1061 | (params->drv_rev << 8) | |
| 1062 | (params->drv_eng); |
| 1063 | strlcpy(drv_version.name, params->name, |
| 1064 | MCP_DRV_VER_STR_SIZE - 4); |
| 1065 | rc = qed_mcp_send_drv_version(hwfn, hwfn->p_main_ptt, |
| 1066 | &drv_version); |
| 1067 | if (rc) { |
| 1068 | DP_NOTICE(cdev, "Failed sending drv version command\n"); |
| 1069 | return rc; |
| 1070 | } |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1071 | } |
| 1072 | |
Yuval Mintz | 8c925c4 | 2016-03-02 20:26:03 +0200 | [diff] [blame] | 1073 | qed_reset_vport_stats(cdev); |
| 1074 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1075 | return 0; |
| 1076 | |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1077 | err3: |
| 1078 | qed_hw_stop(cdev); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1079 | err2: |
Yuval Mintz | 8c925c4 | 2016-03-02 20:26:03 +0200 | [diff] [blame] | 1080 | qed_hw_timers_stop_all(cdev); |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 1081 | if (IS_PF(cdev)) |
| 1082 | qed_slowpath_irq_free(cdev); |
Yuval Mintz | 8c925c4 | 2016-03-02 20:26:03 +0200 | [diff] [blame] | 1083 | qed_free_stream_mem(cdev); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1084 | qed_disable_msix(cdev); |
| 1085 | err1: |
| 1086 | qed_resc_free(cdev); |
| 1087 | err: |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 1088 | if (IS_PF(cdev)) |
| 1089 | release_firmware(cdev->firmware); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1090 | |
Chopra, Manish | d51e4af | 2017-04-13 04:54:44 -0700 | [diff] [blame] | 1091 | if (IS_PF(cdev) && (cdev->num_hwfns == 1) && |
| 1092 | QED_LEADING_HWFN(cdev)->p_arfs_ptt) |
| 1093 | qed_ptt_release(QED_LEADING_HWFN(cdev), |
| 1094 | QED_LEADING_HWFN(cdev)->p_arfs_ptt); |
Sudarsana Reddy Kalluru | c78c70f | 2017-02-15 10:24:10 +0200 | [diff] [blame] | 1095 | |
Yuval Mintz | 37bff2b | 2016-05-11 16:36:13 +0300 | [diff] [blame] | 1096 | qed_iov_wq_stop(cdev, false); |
| 1097 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1098 | return rc; |
| 1099 | } |
| 1100 | |
| 1101 | static int qed_slowpath_stop(struct qed_dev *cdev) |
| 1102 | { |
| 1103 | if (!cdev) |
| 1104 | return -ENODEV; |
| 1105 | |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 1106 | qed_ll2_dealloc_if(cdev); |
| 1107 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 1108 | if (IS_PF(cdev)) { |
Chopra, Manish | d51e4af | 2017-04-13 04:54:44 -0700 | [diff] [blame] | 1109 | if (cdev->num_hwfns == 1) |
| 1110 | qed_ptt_release(QED_LEADING_HWFN(cdev), |
| 1111 | QED_LEADING_HWFN(cdev)->p_arfs_ptt); |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 1112 | qed_free_stream_mem(cdev); |
Yuval Mintz | c5ac931 | 2016-06-03 14:35:34 +0300 | [diff] [blame] | 1113 | if (IS_QED_ETH_IF(cdev)) |
| 1114 | qed_sriov_disable(cdev, true); |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 1115 | } |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1116 | |
Mintz, Yuval | 5f027d7 | 2017-05-09 15:07:48 +0300 | [diff] [blame] | 1117 | qed_nic_stop(cdev); |
| 1118 | |
| 1119 | if (IS_PF(cdev)) |
| 1120 | qed_slowpath_irq_free(cdev); |
| 1121 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1122 | qed_disable_msix(cdev); |
Tomer Tayar | 1226337 | 2017-03-28 15:12:50 +0300 | [diff] [blame] | 1123 | |
| 1124 | qed_resc_free(cdev); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1125 | |
Yuval Mintz | 37bff2b | 2016-05-11 16:36:13 +0300 | [diff] [blame] | 1126 | qed_iov_wq_stop(cdev, true); |
| 1127 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 1128 | if (IS_PF(cdev)) |
| 1129 | release_firmware(cdev->firmware); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1130 | |
| 1131 | return 0; |
| 1132 | } |
| 1133 | |
Mintz, Yuval | 712c3cb | 2017-05-23 09:41:28 +0300 | [diff] [blame] | 1134 | static void qed_set_name(struct qed_dev *cdev, char name[NAME_SIZE]) |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1135 | { |
| 1136 | int i; |
| 1137 | |
| 1138 | memcpy(cdev->name, name, NAME_SIZE); |
| 1139 | for_each_hwfn(cdev, i) |
| 1140 | snprintf(cdev->hwfns[i].name, NAME_SIZE, "%s-%d", name, i); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1141 | } |
| 1142 | |
| 1143 | static u32 qed_sb_init(struct qed_dev *cdev, |
| 1144 | struct qed_sb_info *sb_info, |
| 1145 | void *sb_virt_addr, |
| 1146 | dma_addr_t sb_phy_addr, u16 sb_id, |
| 1147 | enum qed_sb_type type) |
| 1148 | { |
| 1149 | struct qed_hwfn *p_hwfn; |
Mintz, Yuval | 85750d7 | 2017-02-20 22:43:38 +0200 | [diff] [blame] | 1150 | struct qed_ptt *p_ptt; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1151 | int hwfn_index; |
| 1152 | u16 rel_sb_id; |
| 1153 | u8 n_hwfns; |
| 1154 | u32 rc; |
| 1155 | |
| 1156 | /* RoCE uses single engine and CMT uses two engines. When using both |
| 1157 | * we force only a single engine. Storage uses only engine 0 too. |
| 1158 | */ |
| 1159 | if (type == QED_SB_TYPE_L2_QUEUE) |
| 1160 | n_hwfns = cdev->num_hwfns; |
| 1161 | else |
| 1162 | n_hwfns = 1; |
| 1163 | |
| 1164 | hwfn_index = sb_id % n_hwfns; |
| 1165 | p_hwfn = &cdev->hwfns[hwfn_index]; |
| 1166 | rel_sb_id = sb_id / n_hwfns; |
| 1167 | |
| 1168 | DP_VERBOSE(cdev, NETIF_MSG_INTR, |
| 1169 | "hwfn [%d] <--[init]-- SB %04x [0x%04x upper]\n", |
| 1170 | hwfn_index, rel_sb_id, sb_id); |
| 1171 | |
Mintz, Yuval | 85750d7 | 2017-02-20 22:43:38 +0200 | [diff] [blame] | 1172 | if (IS_PF(p_hwfn->cdev)) { |
| 1173 | p_ptt = qed_ptt_acquire(p_hwfn); |
| 1174 | if (!p_ptt) |
| 1175 | return -EBUSY; |
| 1176 | |
| 1177 | rc = qed_int_sb_init(p_hwfn, p_ptt, sb_info, sb_virt_addr, |
| 1178 | sb_phy_addr, rel_sb_id); |
| 1179 | qed_ptt_release(p_hwfn, p_ptt); |
| 1180 | } else { |
| 1181 | rc = qed_int_sb_init(p_hwfn, NULL, sb_info, sb_virt_addr, |
| 1182 | sb_phy_addr, rel_sb_id); |
| 1183 | } |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1184 | |
| 1185 | return rc; |
| 1186 | } |
| 1187 | |
| 1188 | static u32 qed_sb_release(struct qed_dev *cdev, |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 1189 | struct qed_sb_info *sb_info, u16 sb_id) |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1190 | { |
| 1191 | struct qed_hwfn *p_hwfn; |
| 1192 | int hwfn_index; |
| 1193 | u16 rel_sb_id; |
| 1194 | u32 rc; |
| 1195 | |
| 1196 | hwfn_index = sb_id % cdev->num_hwfns; |
| 1197 | p_hwfn = &cdev->hwfns[hwfn_index]; |
| 1198 | rel_sb_id = sb_id / cdev->num_hwfns; |
| 1199 | |
| 1200 | DP_VERBOSE(cdev, NETIF_MSG_INTR, |
| 1201 | "hwfn [%d] <--[init]-- SB %04x [0x%04x upper]\n", |
| 1202 | hwfn_index, rel_sb_id, sb_id); |
| 1203 | |
| 1204 | rc = qed_int_sb_release(p_hwfn, sb_info, rel_sb_id); |
| 1205 | |
| 1206 | return rc; |
| 1207 | } |
| 1208 | |
Yuval Mintz | fe7cd2b | 2016-04-22 08:41:03 +0300 | [diff] [blame] | 1209 | static bool qed_can_link_change(struct qed_dev *cdev) |
| 1210 | { |
| 1211 | return true; |
| 1212 | } |
| 1213 | |
Yuval Mintz | 351a4ded | 2016-06-02 10:23:29 +0300 | [diff] [blame] | 1214 | 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] | 1215 | { |
| 1216 | struct qed_hwfn *hwfn; |
| 1217 | struct qed_mcp_link_params *link_params; |
| 1218 | struct qed_ptt *ptt; |
| 1219 | int rc; |
| 1220 | |
| 1221 | if (!cdev) |
| 1222 | return -ENODEV; |
| 1223 | |
| 1224 | /* The link should be set only once per PF */ |
| 1225 | hwfn = &cdev->hwfns[0]; |
| 1226 | |
Mintz, Yuval | 65ed2ff | 2017-02-20 22:43:39 +0200 | [diff] [blame] | 1227 | /* When VF wants to set link, force it to read the bulletin instead. |
| 1228 | * This mimics the PF behavior, where a noitification [both immediate |
| 1229 | * and possible later] would be generated when changing properties. |
| 1230 | */ |
| 1231 | if (IS_VF(cdev)) { |
| 1232 | qed_schedule_iov(hwfn, QED_IOV_WQ_VF_FORCE_LINK_QUERY_FLAG); |
| 1233 | return 0; |
| 1234 | } |
| 1235 | |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1236 | ptt = qed_ptt_acquire(hwfn); |
| 1237 | if (!ptt) |
| 1238 | return -EBUSY; |
| 1239 | |
| 1240 | link_params = qed_mcp_get_link_params(hwfn); |
| 1241 | if (params->override_flags & QED_LINK_OVERRIDE_SPEED_AUTONEG) |
| 1242 | link_params->speed.autoneg = params->autoneg; |
| 1243 | if (params->override_flags & QED_LINK_OVERRIDE_SPEED_ADV_SPEEDS) { |
| 1244 | link_params->speed.advertised_speeds = 0; |
Sudarsana Reddy Kalluru | 054c67d | 2016-08-09 03:51:23 -0400 | [diff] [blame] | 1245 | if ((params->adv_speeds & QED_LM_1000baseT_Half_BIT) || |
| 1246 | (params->adv_speeds & QED_LM_1000baseT_Full_BIT)) |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1247 | link_params->speed.advertised_speeds |= |
Sudarsana Reddy Kalluru | 054c67d | 2016-08-09 03:51:23 -0400 | [diff] [blame] | 1248 | NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G; |
| 1249 | if (params->adv_speeds & QED_LM_10000baseKR_Full_BIT) |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1250 | link_params->speed.advertised_speeds |= |
Sudarsana Reddy Kalluru | 054c67d | 2016-08-09 03:51:23 -0400 | [diff] [blame] | 1251 | NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G; |
| 1252 | if (params->adv_speeds & QED_LM_25000baseKR_Full_BIT) |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1253 | link_params->speed.advertised_speeds |= |
Sudarsana Reddy Kalluru | 054c67d | 2016-08-09 03:51:23 -0400 | [diff] [blame] | 1254 | NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_25G; |
| 1255 | if (params->adv_speeds & QED_LM_40000baseLR4_Full_BIT) |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1256 | link_params->speed.advertised_speeds |= |
Sudarsana Reddy Kalluru | 054c67d | 2016-08-09 03:51:23 -0400 | [diff] [blame] | 1257 | NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G; |
| 1258 | if (params->adv_speeds & QED_LM_50000baseKR2_Full_BIT) |
| 1259 | link_params->speed.advertised_speeds |= |
| 1260 | NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_50G; |
| 1261 | if (params->adv_speeds & QED_LM_100000baseKR4_Full_BIT) |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1262 | link_params->speed.advertised_speeds |= |
Yuval Mintz | 351a4ded | 2016-06-02 10:23:29 +0300 | [diff] [blame] | 1263 | NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_BB_100G; |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1264 | } |
| 1265 | if (params->override_flags & QED_LINK_OVERRIDE_SPEED_FORCED_SPEED) |
| 1266 | link_params->speed.forced_speed = params->forced_speed; |
Sudarsana Reddy Kalluru | a43f235 | 2016-04-22 08:41:04 +0300 | [diff] [blame] | 1267 | if (params->override_flags & QED_LINK_OVERRIDE_PAUSE_CONFIG) { |
| 1268 | if (params->pause_config & QED_LINK_PAUSE_AUTONEG_ENABLE) |
| 1269 | link_params->pause.autoneg = true; |
| 1270 | else |
| 1271 | link_params->pause.autoneg = false; |
| 1272 | if (params->pause_config & QED_LINK_PAUSE_RX_ENABLE) |
| 1273 | link_params->pause.forced_rx = true; |
| 1274 | else |
| 1275 | link_params->pause.forced_rx = false; |
| 1276 | if (params->pause_config & QED_LINK_PAUSE_TX_ENABLE) |
| 1277 | link_params->pause.forced_tx = true; |
| 1278 | else |
| 1279 | link_params->pause.forced_tx = false; |
| 1280 | } |
Sudarsana Reddy Kalluru | 03dc76c | 2016-04-28 20:20:52 -0400 | [diff] [blame] | 1281 | if (params->override_flags & QED_LINK_OVERRIDE_LOOPBACK_MODE) { |
| 1282 | switch (params->loopback_mode) { |
| 1283 | case QED_LINK_LOOPBACK_INT_PHY: |
Yuval Mintz | 351a4ded | 2016-06-02 10:23:29 +0300 | [diff] [blame] | 1284 | link_params->loopback_mode = ETH_LOOPBACK_INT_PHY; |
Sudarsana Reddy Kalluru | 03dc76c | 2016-04-28 20:20:52 -0400 | [diff] [blame] | 1285 | break; |
| 1286 | case QED_LINK_LOOPBACK_EXT_PHY: |
Yuval Mintz | 351a4ded | 2016-06-02 10:23:29 +0300 | [diff] [blame] | 1287 | link_params->loopback_mode = ETH_LOOPBACK_EXT_PHY; |
Sudarsana Reddy Kalluru | 03dc76c | 2016-04-28 20:20:52 -0400 | [diff] [blame] | 1288 | break; |
| 1289 | case QED_LINK_LOOPBACK_EXT: |
Yuval Mintz | 351a4ded | 2016-06-02 10:23:29 +0300 | [diff] [blame] | 1290 | link_params->loopback_mode = ETH_LOOPBACK_EXT; |
Sudarsana Reddy Kalluru | 03dc76c | 2016-04-28 20:20:52 -0400 | [diff] [blame] | 1291 | break; |
| 1292 | case QED_LINK_LOOPBACK_MAC: |
Yuval Mintz | 351a4ded | 2016-06-02 10:23:29 +0300 | [diff] [blame] | 1293 | link_params->loopback_mode = ETH_LOOPBACK_MAC; |
Sudarsana Reddy Kalluru | 03dc76c | 2016-04-28 20:20:52 -0400 | [diff] [blame] | 1294 | break; |
| 1295 | default: |
Yuval Mintz | 351a4ded | 2016-06-02 10:23:29 +0300 | [diff] [blame] | 1296 | link_params->loopback_mode = ETH_LOOPBACK_NONE; |
Sudarsana Reddy Kalluru | 03dc76c | 2016-04-28 20:20:52 -0400 | [diff] [blame] | 1297 | break; |
| 1298 | } |
| 1299 | } |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1300 | |
Sudarsana Reddy Kalluru | 645874e | 2017-07-26 06:07:11 -0700 | [diff] [blame] | 1301 | if (params->override_flags & QED_LINK_OVERRIDE_EEE_CONFIG) |
| 1302 | memcpy(&link_params->eee, ¶ms->eee, |
| 1303 | sizeof(link_params->eee)); |
| 1304 | |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1305 | rc = qed_mcp_set_link(hwfn, ptt, params->link_up); |
| 1306 | |
| 1307 | qed_ptt_release(hwfn, ptt); |
| 1308 | |
| 1309 | return rc; |
| 1310 | } |
| 1311 | |
| 1312 | static int qed_get_port_type(u32 media_type) |
| 1313 | { |
| 1314 | int port_type; |
| 1315 | |
| 1316 | switch (media_type) { |
| 1317 | case MEDIA_SFPP_10G_FIBER: |
| 1318 | case MEDIA_SFP_1G_FIBER: |
| 1319 | case MEDIA_XFP_FIBER: |
Yuval Mintz | b639f19 | 2016-06-19 15:18:15 +0300 | [diff] [blame] | 1320 | case MEDIA_MODULE_FIBER: |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1321 | case MEDIA_KR: |
| 1322 | port_type = PORT_FIBRE; |
| 1323 | break; |
| 1324 | case MEDIA_DA_TWINAX: |
| 1325 | port_type = PORT_DA; |
| 1326 | break; |
| 1327 | case MEDIA_BASE_T: |
| 1328 | port_type = PORT_TP; |
| 1329 | break; |
| 1330 | case MEDIA_NOT_PRESENT: |
| 1331 | port_type = PORT_NONE; |
| 1332 | break; |
| 1333 | case MEDIA_UNSPECIFIED: |
| 1334 | default: |
| 1335 | port_type = PORT_OTHER; |
| 1336 | break; |
| 1337 | } |
| 1338 | return port_type; |
| 1339 | } |
| 1340 | |
Arnd Bergmann | 14b84e8 | 2016-06-01 15:29:13 +0200 | [diff] [blame] | 1341 | static int qed_get_link_data(struct qed_hwfn *hwfn, |
| 1342 | struct qed_mcp_link_params *params, |
| 1343 | struct qed_mcp_link_state *link, |
| 1344 | struct qed_mcp_link_capabilities *link_caps) |
| 1345 | { |
| 1346 | void *p; |
| 1347 | |
| 1348 | if (!IS_PF(hwfn->cdev)) { |
| 1349 | qed_vf_get_link_params(hwfn, params); |
| 1350 | qed_vf_get_link_state(hwfn, link); |
| 1351 | qed_vf_get_link_caps(hwfn, link_caps); |
| 1352 | |
| 1353 | return 0; |
| 1354 | } |
| 1355 | |
| 1356 | p = qed_mcp_get_link_params(hwfn); |
| 1357 | if (!p) |
| 1358 | return -ENXIO; |
| 1359 | memcpy(params, p, sizeof(*params)); |
| 1360 | |
| 1361 | p = qed_mcp_get_link_state(hwfn); |
| 1362 | if (!p) |
| 1363 | return -ENXIO; |
| 1364 | memcpy(link, p, sizeof(*link)); |
| 1365 | |
| 1366 | p = qed_mcp_get_link_capabilities(hwfn); |
| 1367 | if (!p) |
| 1368 | return -ENXIO; |
| 1369 | memcpy(link_caps, p, sizeof(*link_caps)); |
| 1370 | |
| 1371 | return 0; |
| 1372 | } |
| 1373 | |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1374 | static void qed_fill_link(struct qed_hwfn *hwfn, |
| 1375 | struct qed_link_output *if_link) |
| 1376 | { |
| 1377 | struct qed_mcp_link_params params; |
| 1378 | struct qed_mcp_link_state link; |
| 1379 | struct qed_mcp_link_capabilities link_caps; |
| 1380 | u32 media_type; |
| 1381 | |
| 1382 | memset(if_link, 0, sizeof(*if_link)); |
| 1383 | |
| 1384 | /* Prepare source inputs */ |
Arnd Bergmann | 14b84e8 | 2016-06-01 15:29:13 +0200 | [diff] [blame] | 1385 | if (qed_get_link_data(hwfn, ¶ms, &link, &link_caps)) { |
| 1386 | dev_warn(&hwfn->cdev->pdev->dev, "no link data available\n"); |
| 1387 | return; |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 1388 | } |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1389 | |
| 1390 | /* Set the link parameters to pass to protocol driver */ |
| 1391 | if (link.link_up) |
| 1392 | if_link->link_up = true; |
| 1393 | |
| 1394 | /* TODO - at the moment assume supported and advertised speed equal */ |
Sudarsana Reddy Kalluru | 054c67d | 2016-08-09 03:51:23 -0400 | [diff] [blame] | 1395 | if_link->supported_caps = QED_LM_FIBRE_BIT; |
sudarsana.kalluru@cavium.com | 34f9199 | 2017-05-04 08:15:04 -0700 | [diff] [blame] | 1396 | if (link_caps.default_speed_autoneg) |
Sudarsana Reddy Kalluru | 054c67d | 2016-08-09 03:51:23 -0400 | [diff] [blame] | 1397 | if_link->supported_caps |= QED_LM_Autoneg_BIT; |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1398 | if (params.pause.autoneg || |
| 1399 | (params.pause.forced_rx && params.pause.forced_tx)) |
Sudarsana Reddy Kalluru | 054c67d | 2016-08-09 03:51:23 -0400 | [diff] [blame] | 1400 | if_link->supported_caps |= QED_LM_Asym_Pause_BIT; |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1401 | if (params.pause.autoneg || params.pause.forced_rx || |
| 1402 | params.pause.forced_tx) |
Sudarsana Reddy Kalluru | 054c67d | 2016-08-09 03:51:23 -0400 | [diff] [blame] | 1403 | if_link->supported_caps |= QED_LM_Pause_BIT; |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1404 | |
| 1405 | if_link->advertised_caps = if_link->supported_caps; |
sudarsana.kalluru@cavium.com | 34f9199 | 2017-05-04 08:15:04 -0700 | [diff] [blame] | 1406 | if (params.speed.autoneg) |
| 1407 | if_link->advertised_caps |= QED_LM_Autoneg_BIT; |
| 1408 | else |
| 1409 | if_link->advertised_caps &= ~QED_LM_Autoneg_BIT; |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1410 | if (params.speed.advertised_speeds & |
| 1411 | NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G) |
Sudarsana Reddy Kalluru | 054c67d | 2016-08-09 03:51:23 -0400 | [diff] [blame] | 1412 | if_link->advertised_caps |= QED_LM_1000baseT_Half_BIT | |
| 1413 | QED_LM_1000baseT_Full_BIT; |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1414 | if (params.speed.advertised_speeds & |
| 1415 | NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G) |
Sudarsana Reddy Kalluru | 054c67d | 2016-08-09 03:51:23 -0400 | [diff] [blame] | 1416 | if_link->advertised_caps |= QED_LM_10000baseKR_Full_BIT; |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1417 | if (params.speed.advertised_speeds & |
Sudarsana Reddy Kalluru | 054c67d | 2016-08-09 03:51:23 -0400 | [diff] [blame] | 1418 | NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_25G) |
| 1419 | if_link->advertised_caps |= QED_LM_25000baseKR_Full_BIT; |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1420 | if (params.speed.advertised_speeds & |
Sudarsana Reddy Kalluru | 054c67d | 2016-08-09 03:51:23 -0400 | [diff] [blame] | 1421 | NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G) |
| 1422 | if_link->advertised_caps |= QED_LM_40000baseLR4_Full_BIT; |
| 1423 | if (params.speed.advertised_speeds & |
| 1424 | NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_50G) |
| 1425 | if_link->advertised_caps |= QED_LM_50000baseKR2_Full_BIT; |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1426 | if (params.speed.advertised_speeds & |
Yuval Mintz | 351a4ded | 2016-06-02 10:23:29 +0300 | [diff] [blame] | 1427 | NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_BB_100G) |
Sudarsana Reddy Kalluru | 054c67d | 2016-08-09 03:51:23 -0400 | [diff] [blame] | 1428 | if_link->advertised_caps |= QED_LM_100000baseKR4_Full_BIT; |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1429 | |
| 1430 | if (link_caps.speed_capabilities & |
| 1431 | NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G) |
Sudarsana Reddy Kalluru | 054c67d | 2016-08-09 03:51:23 -0400 | [diff] [blame] | 1432 | if_link->supported_caps |= QED_LM_1000baseT_Half_BIT | |
| 1433 | QED_LM_1000baseT_Full_BIT; |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1434 | if (link_caps.speed_capabilities & |
| 1435 | NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G) |
Sudarsana Reddy Kalluru | 054c67d | 2016-08-09 03:51:23 -0400 | [diff] [blame] | 1436 | if_link->supported_caps |= QED_LM_10000baseKR_Full_BIT; |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1437 | if (link_caps.speed_capabilities & |
Sudarsana Reddy Kalluru | 054c67d | 2016-08-09 03:51:23 -0400 | [diff] [blame] | 1438 | NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_25G) |
| 1439 | if_link->supported_caps |= QED_LM_25000baseKR_Full_BIT; |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1440 | if (link_caps.speed_capabilities & |
Sudarsana Reddy Kalluru | 054c67d | 2016-08-09 03:51:23 -0400 | [diff] [blame] | 1441 | NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G) |
| 1442 | if_link->supported_caps |= QED_LM_40000baseLR4_Full_BIT; |
| 1443 | if (link_caps.speed_capabilities & |
| 1444 | NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_50G) |
| 1445 | if_link->supported_caps |= QED_LM_50000baseKR2_Full_BIT; |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1446 | if (link_caps.speed_capabilities & |
Yuval Mintz | 351a4ded | 2016-06-02 10:23:29 +0300 | [diff] [blame] | 1447 | NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_BB_100G) |
Sudarsana Reddy Kalluru | 054c67d | 2016-08-09 03:51:23 -0400 | [diff] [blame] | 1448 | if_link->supported_caps |= QED_LM_100000baseKR4_Full_BIT; |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1449 | |
| 1450 | if (link.link_up) |
| 1451 | if_link->speed = link.speed; |
| 1452 | |
| 1453 | /* TODO - fill duplex properly */ |
| 1454 | if_link->duplex = DUPLEX_FULL; |
| 1455 | qed_mcp_get_media_type(hwfn->cdev, &media_type); |
| 1456 | if_link->port = qed_get_port_type(media_type); |
| 1457 | |
| 1458 | if_link->autoneg = params.speed.autoneg; |
| 1459 | |
| 1460 | if (params.pause.autoneg) |
| 1461 | if_link->pause_config |= QED_LINK_PAUSE_AUTONEG_ENABLE; |
| 1462 | if (params.pause.forced_rx) |
| 1463 | if_link->pause_config |= QED_LINK_PAUSE_RX_ENABLE; |
| 1464 | if (params.pause.forced_tx) |
| 1465 | if_link->pause_config |= QED_LINK_PAUSE_TX_ENABLE; |
| 1466 | |
| 1467 | /* Link partner capabilities */ |
Sudarsana Reddy Kalluru | 054c67d | 2016-08-09 03:51:23 -0400 | [diff] [blame] | 1468 | if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_1G_HD) |
| 1469 | if_link->lp_caps |= QED_LM_1000baseT_Half_BIT; |
| 1470 | if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_1G_FD) |
| 1471 | if_link->lp_caps |= QED_LM_1000baseT_Full_BIT; |
| 1472 | if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_10G) |
| 1473 | if_link->lp_caps |= QED_LM_10000baseKR_Full_BIT; |
| 1474 | if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_25G) |
| 1475 | if_link->lp_caps |= QED_LM_25000baseKR_Full_BIT; |
| 1476 | if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_40G) |
| 1477 | if_link->lp_caps |= QED_LM_40000baseLR4_Full_BIT; |
| 1478 | if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_50G) |
| 1479 | if_link->lp_caps |= QED_LM_50000baseKR2_Full_BIT; |
| 1480 | if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_100G) |
| 1481 | if_link->lp_caps |= QED_LM_100000baseKR4_Full_BIT; |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1482 | |
| 1483 | if (link.an_complete) |
Sudarsana Reddy Kalluru | 054c67d | 2016-08-09 03:51:23 -0400 | [diff] [blame] | 1484 | if_link->lp_caps |= QED_LM_Autoneg_BIT; |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1485 | |
| 1486 | if (link.partner_adv_pause) |
Sudarsana Reddy Kalluru | 054c67d | 2016-08-09 03:51:23 -0400 | [diff] [blame] | 1487 | if_link->lp_caps |= QED_LM_Pause_BIT; |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1488 | if (link.partner_adv_pause == QED_LINK_PARTNER_ASYMMETRIC_PAUSE || |
| 1489 | link.partner_adv_pause == QED_LINK_PARTNER_BOTH_PAUSE) |
Sudarsana Reddy Kalluru | 054c67d | 2016-08-09 03:51:23 -0400 | [diff] [blame] | 1490 | if_link->lp_caps |= QED_LM_Asym_Pause_BIT; |
Sudarsana Reddy Kalluru | 645874e | 2017-07-26 06:07:11 -0700 | [diff] [blame] | 1491 | |
| 1492 | if (link_caps.default_eee == QED_MCP_EEE_UNSUPPORTED) { |
| 1493 | if_link->eee_supported = false; |
| 1494 | } else { |
| 1495 | if_link->eee_supported = true; |
| 1496 | if_link->eee_active = link.eee_active; |
| 1497 | if_link->sup_caps = link_caps.eee_speed_caps; |
| 1498 | /* MFW clears adv_caps on eee disable; use configured value */ |
| 1499 | if_link->eee.adv_caps = link.eee_adv_caps ? link.eee_adv_caps : |
| 1500 | params.eee.adv_caps; |
| 1501 | if_link->eee.lp_adv_caps = link.eee_lp_adv_caps; |
| 1502 | if_link->eee.enable = params.eee.enable; |
| 1503 | if_link->eee.tx_lpi_enable = params.eee.tx_lpi_enable; |
| 1504 | if_link->eee.tx_lpi_timer = params.eee.tx_lpi_timer; |
| 1505 | } |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1506 | } |
| 1507 | |
| 1508 | static void qed_get_current_link(struct qed_dev *cdev, |
| 1509 | struct qed_link_output *if_link) |
| 1510 | { |
Yuval Mintz | 36558c3 | 2016-05-11 16:36:17 +0300 | [diff] [blame] | 1511 | int i; |
| 1512 | |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1513 | qed_fill_link(&cdev->hwfns[0], if_link); |
Yuval Mintz | 36558c3 | 2016-05-11 16:36:17 +0300 | [diff] [blame] | 1514 | |
| 1515 | for_each_hwfn(cdev, i) |
| 1516 | qed_inform_vf_link_state(&cdev->hwfns[i]); |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1517 | } |
| 1518 | |
| 1519 | void qed_link_update(struct qed_hwfn *hwfn) |
| 1520 | { |
| 1521 | void *cookie = hwfn->cdev->ops_cookie; |
| 1522 | struct qed_common_cb_ops *op = hwfn->cdev->protocol_ops.common; |
| 1523 | struct qed_link_output if_link; |
| 1524 | |
| 1525 | qed_fill_link(hwfn, &if_link); |
Yuval Mintz | 36558c3 | 2016-05-11 16:36:17 +0300 | [diff] [blame] | 1526 | qed_inform_vf_link_state(hwfn); |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1527 | |
| 1528 | if (IS_LEAD_HWFN(hwfn) && cookie) |
| 1529 | op->link_update(cookie, &if_link); |
| 1530 | } |
| 1531 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1532 | static int qed_drain(struct qed_dev *cdev) |
| 1533 | { |
| 1534 | struct qed_hwfn *hwfn; |
| 1535 | struct qed_ptt *ptt; |
| 1536 | int i, rc; |
| 1537 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 1538 | if (IS_VF(cdev)) |
| 1539 | return 0; |
| 1540 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1541 | for_each_hwfn(cdev, i) { |
| 1542 | hwfn = &cdev->hwfns[i]; |
| 1543 | ptt = qed_ptt_acquire(hwfn); |
| 1544 | if (!ptt) { |
| 1545 | DP_NOTICE(hwfn, "Failed to drain NIG; No PTT\n"); |
| 1546 | return -EBUSY; |
| 1547 | } |
| 1548 | rc = qed_mcp_drain(hwfn, ptt); |
| 1549 | if (rc) |
| 1550 | return rc; |
| 1551 | qed_ptt_release(hwfn, ptt); |
| 1552 | } |
| 1553 | |
| 1554 | return 0; |
| 1555 | } |
| 1556 | |
Sudarsana Reddy Kalluru | 3a69cae | 2018-03-28 05:14:22 -0700 | [diff] [blame] | 1557 | static u32 qed_nvm_flash_image_access_crc(struct qed_dev *cdev, |
| 1558 | struct qed_nvm_image_att *nvm_image, |
| 1559 | u32 *crc) |
| 1560 | { |
| 1561 | u8 *buf = NULL; |
| 1562 | int rc, j; |
| 1563 | u32 val; |
| 1564 | |
| 1565 | /* Allocate a buffer for holding the nvram image */ |
| 1566 | buf = kzalloc(nvm_image->length, GFP_KERNEL); |
| 1567 | if (!buf) |
| 1568 | return -ENOMEM; |
| 1569 | |
| 1570 | /* Read image into buffer */ |
| 1571 | rc = qed_mcp_nvm_read(cdev, nvm_image->start_addr, |
| 1572 | buf, nvm_image->length); |
| 1573 | if (rc) { |
| 1574 | DP_ERR(cdev, "Failed reading image from nvm\n"); |
| 1575 | goto out; |
| 1576 | } |
| 1577 | |
| 1578 | /* Convert the buffer into big-endian format (excluding the |
| 1579 | * closing 4 bytes of CRC). |
| 1580 | */ |
| 1581 | for (j = 0; j < nvm_image->length - 4; j += 4) { |
| 1582 | val = cpu_to_be32(*(u32 *)&buf[j]); |
| 1583 | *(u32 *)&buf[j] = val; |
| 1584 | } |
| 1585 | |
| 1586 | /* Calc CRC for the "actual" image buffer, i.e. not including |
| 1587 | * the last 4 CRC bytes. |
| 1588 | */ |
| 1589 | *crc = (~cpu_to_be32(crc32(0xffffffff, buf, nvm_image->length - 4))); |
| 1590 | |
| 1591 | out: |
| 1592 | kfree(buf); |
| 1593 | |
| 1594 | return rc; |
| 1595 | } |
| 1596 | |
| 1597 | /* Binary file format - |
| 1598 | * /----------------------------------------------------------------------\ |
| 1599 | * 0B | 0x4 [command index] | |
| 1600 | * 4B | image_type | Options | Number of register settings | |
| 1601 | * 8B | Value | |
| 1602 | * 12B | Mask | |
| 1603 | * 16B | Offset | |
| 1604 | * \----------------------------------------------------------------------/ |
| 1605 | * There can be several Value-Mask-Offset sets as specified by 'Number of...'. |
| 1606 | * Options - 0'b - Calculate & Update CRC for image |
| 1607 | */ |
| 1608 | static int qed_nvm_flash_image_access(struct qed_dev *cdev, const u8 **data, |
| 1609 | bool *check_resp) |
| 1610 | { |
| 1611 | struct qed_nvm_image_att nvm_image; |
| 1612 | struct qed_hwfn *p_hwfn; |
| 1613 | bool is_crc = false; |
| 1614 | u32 image_type; |
| 1615 | int rc = 0, i; |
| 1616 | u16 len; |
| 1617 | |
| 1618 | *data += 4; |
| 1619 | image_type = **data; |
| 1620 | p_hwfn = QED_LEADING_HWFN(cdev); |
| 1621 | for (i = 0; i < p_hwfn->nvm_info.num_images; i++) |
| 1622 | if (image_type == p_hwfn->nvm_info.image_att[i].image_type) |
| 1623 | break; |
| 1624 | if (i == p_hwfn->nvm_info.num_images) { |
| 1625 | DP_ERR(cdev, "Failed to find nvram image of type %08x\n", |
| 1626 | image_type); |
| 1627 | return -ENOENT; |
| 1628 | } |
| 1629 | |
| 1630 | nvm_image.start_addr = p_hwfn->nvm_info.image_att[i].nvm_start_addr; |
| 1631 | nvm_image.length = p_hwfn->nvm_info.image_att[i].len; |
| 1632 | |
| 1633 | DP_VERBOSE(cdev, NETIF_MSG_DRV, |
| 1634 | "Read image %02x; type = %08x; NVM [%08x,...,%08x]\n", |
| 1635 | **data, image_type, nvm_image.start_addr, |
| 1636 | nvm_image.start_addr + nvm_image.length - 1); |
| 1637 | (*data)++; |
| 1638 | is_crc = !!(**data & BIT(0)); |
| 1639 | (*data)++; |
| 1640 | len = *((u16 *)*data); |
| 1641 | *data += 2; |
| 1642 | if (is_crc) { |
| 1643 | u32 crc = 0; |
| 1644 | |
| 1645 | rc = qed_nvm_flash_image_access_crc(cdev, &nvm_image, &crc); |
| 1646 | if (rc) { |
| 1647 | DP_ERR(cdev, "Failed calculating CRC, rc = %d\n", rc); |
| 1648 | goto exit; |
| 1649 | } |
| 1650 | |
| 1651 | rc = qed_mcp_nvm_write(cdev, QED_NVM_WRITE_NVRAM, |
| 1652 | (nvm_image.start_addr + |
| 1653 | nvm_image.length - 4), (u8 *)&crc, 4); |
| 1654 | if (rc) |
| 1655 | DP_ERR(cdev, "Failed writing to %08x, rc = %d\n", |
| 1656 | nvm_image.start_addr + nvm_image.length - 4, rc); |
| 1657 | goto exit; |
| 1658 | } |
| 1659 | |
| 1660 | /* Iterate over the values for setting */ |
| 1661 | while (len) { |
| 1662 | u32 offset, mask, value, cur_value; |
| 1663 | u8 buf[4]; |
| 1664 | |
| 1665 | value = *((u32 *)*data); |
| 1666 | *data += 4; |
| 1667 | mask = *((u32 *)*data); |
| 1668 | *data += 4; |
| 1669 | offset = *((u32 *)*data); |
| 1670 | *data += 4; |
| 1671 | |
| 1672 | rc = qed_mcp_nvm_read(cdev, nvm_image.start_addr + offset, buf, |
| 1673 | 4); |
| 1674 | if (rc) { |
| 1675 | DP_ERR(cdev, "Failed reading from %08x\n", |
| 1676 | nvm_image.start_addr + offset); |
| 1677 | goto exit; |
| 1678 | } |
| 1679 | |
| 1680 | cur_value = le32_to_cpu(*((__le32 *)buf)); |
| 1681 | DP_VERBOSE(cdev, NETIF_MSG_DRV, |
| 1682 | "NVM %08x: %08x -> %08x [Value %08x Mask %08x]\n", |
| 1683 | nvm_image.start_addr + offset, cur_value, |
| 1684 | (cur_value & ~mask) | (value & mask), value, mask); |
| 1685 | value = (value & mask) | (cur_value & ~mask); |
| 1686 | rc = qed_mcp_nvm_write(cdev, QED_NVM_WRITE_NVRAM, |
| 1687 | nvm_image.start_addr + offset, |
| 1688 | (u8 *)&value, 4); |
| 1689 | if (rc) { |
| 1690 | DP_ERR(cdev, "Failed writing to %08x\n", |
| 1691 | nvm_image.start_addr + offset); |
| 1692 | goto exit; |
| 1693 | } |
| 1694 | |
| 1695 | len--; |
| 1696 | } |
| 1697 | exit: |
| 1698 | return rc; |
| 1699 | } |
| 1700 | |
| 1701 | /* Binary file format - |
| 1702 | * /----------------------------------------------------------------------\ |
| 1703 | * 0B | 0x3 [command index] | |
| 1704 | * 4B | b'0: check_response? | b'1-31 reserved | |
| 1705 | * 8B | File-type | reserved | |
| 1706 | * \----------------------------------------------------------------------/ |
| 1707 | * Start a new file of the provided type |
| 1708 | */ |
| 1709 | static int qed_nvm_flash_image_file_start(struct qed_dev *cdev, |
| 1710 | const u8 **data, bool *check_resp) |
| 1711 | { |
| 1712 | int rc; |
| 1713 | |
| 1714 | *data += 4; |
| 1715 | *check_resp = !!(**data & BIT(0)); |
| 1716 | *data += 4; |
| 1717 | |
| 1718 | DP_VERBOSE(cdev, NETIF_MSG_DRV, |
| 1719 | "About to start a new file of type %02x\n", **data); |
| 1720 | rc = qed_mcp_nvm_put_file_begin(cdev, **data); |
| 1721 | *data += 4; |
| 1722 | |
| 1723 | return rc; |
| 1724 | } |
| 1725 | |
| 1726 | /* Binary file format - |
| 1727 | * /----------------------------------------------------------------------\ |
| 1728 | * 0B | 0x2 [command index] | |
| 1729 | * 4B | Length in bytes | |
| 1730 | * 8B | b'0: check_response? | b'1-31 reserved | |
| 1731 | * 12B | Offset in bytes | |
| 1732 | * 16B | Data ... | |
| 1733 | * \----------------------------------------------------------------------/ |
| 1734 | * Write data as part of a file that was previously started. Data should be |
| 1735 | * of length equal to that provided in the message |
| 1736 | */ |
| 1737 | static int qed_nvm_flash_image_file_data(struct qed_dev *cdev, |
| 1738 | const u8 **data, bool *check_resp) |
| 1739 | { |
| 1740 | u32 offset, len; |
| 1741 | int rc; |
| 1742 | |
| 1743 | *data += 4; |
| 1744 | len = *((u32 *)(*data)); |
| 1745 | *data += 4; |
| 1746 | *check_resp = !!(**data & BIT(0)); |
| 1747 | *data += 4; |
| 1748 | offset = *((u32 *)(*data)); |
| 1749 | *data += 4; |
| 1750 | |
| 1751 | DP_VERBOSE(cdev, NETIF_MSG_DRV, |
| 1752 | "About to write File-data: %08x bytes to offset %08x\n", |
| 1753 | len, offset); |
| 1754 | |
| 1755 | rc = qed_mcp_nvm_write(cdev, QED_PUT_FILE_DATA, offset, |
| 1756 | (char *)(*data), len); |
| 1757 | *data += len; |
| 1758 | |
| 1759 | return rc; |
| 1760 | } |
| 1761 | |
| 1762 | /* Binary file format [General header] - |
| 1763 | * /----------------------------------------------------------------------\ |
| 1764 | * 0B | QED_NVM_SIGNATURE | |
| 1765 | * 4B | Length in bytes | |
| 1766 | * 8B | Highest command in this batchfile | Reserved | |
| 1767 | * \----------------------------------------------------------------------/ |
| 1768 | */ |
| 1769 | static int qed_nvm_flash_image_validate(struct qed_dev *cdev, |
| 1770 | const struct firmware *image, |
| 1771 | const u8 **data) |
| 1772 | { |
| 1773 | u32 signature, len; |
| 1774 | |
| 1775 | /* Check minimum size */ |
| 1776 | if (image->size < 12) { |
| 1777 | DP_ERR(cdev, "Image is too short [%08x]\n", (u32)image->size); |
| 1778 | return -EINVAL; |
| 1779 | } |
| 1780 | |
| 1781 | /* Check signature */ |
| 1782 | signature = *((u32 *)(*data)); |
| 1783 | if (signature != QED_NVM_SIGNATURE) { |
| 1784 | DP_ERR(cdev, "Wrong signature '%08x'\n", signature); |
| 1785 | return -EINVAL; |
| 1786 | } |
| 1787 | |
| 1788 | *data += 4; |
| 1789 | /* Validate internal size equals the image-size */ |
| 1790 | len = *((u32 *)(*data)); |
| 1791 | if (len != image->size) { |
| 1792 | DP_ERR(cdev, "Size mismatch: internal = %08x image = %08x\n", |
| 1793 | len, (u32)image->size); |
| 1794 | return -EINVAL; |
| 1795 | } |
| 1796 | |
| 1797 | *data += 4; |
| 1798 | /* Make sure driver familiar with all commands necessary for this */ |
| 1799 | if (*((u16 *)(*data)) >= QED_NVM_FLASH_CMD_NVM_MAX) { |
| 1800 | DP_ERR(cdev, "File contains unsupported commands [Need %04x]\n", |
| 1801 | *((u16 *)(*data))); |
| 1802 | return -EINVAL; |
| 1803 | } |
| 1804 | |
| 1805 | *data += 4; |
| 1806 | |
| 1807 | return 0; |
| 1808 | } |
| 1809 | |
| 1810 | static int qed_nvm_flash(struct qed_dev *cdev, const char *name) |
| 1811 | { |
| 1812 | const struct firmware *image; |
| 1813 | const u8 *data, *data_end; |
| 1814 | u32 cmd_type; |
| 1815 | int rc; |
| 1816 | |
| 1817 | rc = request_firmware(&image, name, &cdev->pdev->dev); |
| 1818 | if (rc) { |
| 1819 | DP_ERR(cdev, "Failed to find '%s'\n", name); |
| 1820 | return rc; |
| 1821 | } |
| 1822 | |
| 1823 | DP_VERBOSE(cdev, NETIF_MSG_DRV, |
| 1824 | "Flashing '%s' - firmware's data at %p, size is %08x\n", |
| 1825 | name, image->data, (u32)image->size); |
| 1826 | data = image->data; |
| 1827 | data_end = data + image->size; |
| 1828 | |
| 1829 | rc = qed_nvm_flash_image_validate(cdev, image, &data); |
| 1830 | if (rc) |
| 1831 | goto exit; |
| 1832 | |
| 1833 | while (data < data_end) { |
| 1834 | bool check_resp = false; |
| 1835 | |
| 1836 | /* Parse the actual command */ |
| 1837 | cmd_type = *((u32 *)data); |
| 1838 | switch (cmd_type) { |
| 1839 | case QED_NVM_FLASH_CMD_FILE_DATA: |
| 1840 | rc = qed_nvm_flash_image_file_data(cdev, &data, |
| 1841 | &check_resp); |
| 1842 | break; |
| 1843 | case QED_NVM_FLASH_CMD_FILE_START: |
| 1844 | rc = qed_nvm_flash_image_file_start(cdev, &data, |
| 1845 | &check_resp); |
| 1846 | break; |
| 1847 | case QED_NVM_FLASH_CMD_NVM_CHANGE: |
| 1848 | rc = qed_nvm_flash_image_access(cdev, &data, |
| 1849 | &check_resp); |
| 1850 | break; |
| 1851 | default: |
| 1852 | DP_ERR(cdev, "Unknown command %08x\n", cmd_type); |
| 1853 | rc = -EINVAL; |
| 1854 | goto exit; |
| 1855 | } |
| 1856 | |
| 1857 | if (rc) { |
| 1858 | DP_ERR(cdev, "Command %08x failed\n", cmd_type); |
| 1859 | goto exit; |
| 1860 | } |
| 1861 | |
| 1862 | /* Check response if needed */ |
| 1863 | if (check_resp) { |
| 1864 | u32 mcp_response = 0; |
| 1865 | |
| 1866 | if (qed_mcp_nvm_resp(cdev, (u8 *)&mcp_response)) { |
| 1867 | DP_ERR(cdev, "Failed getting MCP response\n"); |
| 1868 | rc = -EINVAL; |
| 1869 | goto exit; |
| 1870 | } |
| 1871 | |
| 1872 | switch (mcp_response & FW_MSG_CODE_MASK) { |
| 1873 | case FW_MSG_CODE_OK: |
| 1874 | case FW_MSG_CODE_NVM_OK: |
| 1875 | case FW_MSG_CODE_NVM_PUT_FILE_FINISH_OK: |
| 1876 | case FW_MSG_CODE_PHY_OK: |
| 1877 | break; |
| 1878 | default: |
| 1879 | DP_ERR(cdev, "MFW returns error: %08x\n", |
| 1880 | mcp_response); |
| 1881 | rc = -EINVAL; |
| 1882 | goto exit; |
| 1883 | } |
| 1884 | } |
| 1885 | } |
| 1886 | |
| 1887 | exit: |
| 1888 | release_firmware(image); |
| 1889 | |
| 1890 | return rc; |
| 1891 | } |
| 1892 | |
Mintz, Yuval | 20675b3 | 2017-06-02 08:58:32 +0300 | [diff] [blame] | 1893 | static int qed_nvm_get_image(struct qed_dev *cdev, enum qed_nvm_images type, |
| 1894 | u8 *buf, u16 len) |
| 1895 | { |
| 1896 | struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev); |
| 1897 | struct qed_ptt *ptt = qed_ptt_acquire(hwfn); |
| 1898 | int rc; |
| 1899 | |
| 1900 | if (!ptt) |
| 1901 | return -EAGAIN; |
| 1902 | |
| 1903 | rc = qed_mcp_get_nvm_image(hwfn, ptt, type, buf, len); |
| 1904 | qed_ptt_release(hwfn, ptt); |
| 1905 | return rc; |
| 1906 | } |
| 1907 | |
Sudarsana Reddy Kalluru | 722003a | 2016-06-21 09:36:21 -0400 | [diff] [blame] | 1908 | static int qed_set_coalesce(struct qed_dev *cdev, u16 rx_coal, u16 tx_coal, |
Rahul Verma | 477f2d1 | 2017-07-26 06:07:13 -0700 | [diff] [blame] | 1909 | void *handle) |
Sudarsana Reddy Kalluru | 722003a | 2016-06-21 09:36:21 -0400 | [diff] [blame] | 1910 | { |
Rahul Verma | 477f2d1 | 2017-07-26 06:07:13 -0700 | [diff] [blame] | 1911 | return qed_set_queue_coalesce(rx_coal, tx_coal, handle); |
Sudarsana Reddy Kalluru | 722003a | 2016-06-21 09:36:21 -0400 | [diff] [blame] | 1912 | } |
| 1913 | |
Sudarsana Kalluru | 91420b8 | 2015-11-30 12:25:03 +0200 | [diff] [blame] | 1914 | static int qed_set_led(struct qed_dev *cdev, enum qed_led_mode mode) |
| 1915 | { |
| 1916 | struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev); |
| 1917 | struct qed_ptt *ptt; |
| 1918 | int status = 0; |
| 1919 | |
| 1920 | ptt = qed_ptt_acquire(hwfn); |
| 1921 | if (!ptt) |
| 1922 | return -EAGAIN; |
| 1923 | |
| 1924 | status = qed_mcp_set_led(hwfn, ptt, mode); |
| 1925 | |
| 1926 | qed_ptt_release(hwfn, ptt); |
| 1927 | |
| 1928 | return status; |
| 1929 | } |
| 1930 | |
Mintz, Yuval | 14d3964 | 2016-10-31 07:14:23 +0200 | [diff] [blame] | 1931 | static int qed_update_wol(struct qed_dev *cdev, bool enabled) |
| 1932 | { |
| 1933 | struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev); |
| 1934 | struct qed_ptt *ptt; |
| 1935 | int rc = 0; |
| 1936 | |
| 1937 | if (IS_VF(cdev)) |
| 1938 | return 0; |
| 1939 | |
| 1940 | ptt = qed_ptt_acquire(hwfn); |
| 1941 | if (!ptt) |
| 1942 | return -EAGAIN; |
| 1943 | |
| 1944 | rc = qed_mcp_ov_update_wol(hwfn, ptt, enabled ? QED_OV_WOL_ENABLED |
| 1945 | : QED_OV_WOL_DISABLED); |
| 1946 | if (rc) |
| 1947 | goto out; |
| 1948 | rc = qed_mcp_ov_update_current_config(hwfn, ptt, QED_OV_CLIENT_DRV); |
| 1949 | |
| 1950 | out: |
| 1951 | qed_ptt_release(hwfn, ptt); |
| 1952 | return rc; |
| 1953 | } |
| 1954 | |
Sudarsana Kalluru | 0fefbfb | 2016-10-31 07:14:21 +0200 | [diff] [blame] | 1955 | static int qed_update_drv_state(struct qed_dev *cdev, bool active) |
| 1956 | { |
| 1957 | struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev); |
| 1958 | struct qed_ptt *ptt; |
| 1959 | int status = 0; |
| 1960 | |
| 1961 | if (IS_VF(cdev)) |
| 1962 | return 0; |
| 1963 | |
| 1964 | ptt = qed_ptt_acquire(hwfn); |
| 1965 | if (!ptt) |
| 1966 | return -EAGAIN; |
| 1967 | |
| 1968 | status = qed_mcp_ov_update_driver_state(hwfn, ptt, active ? |
| 1969 | QED_OV_DRIVER_STATE_ACTIVE : |
| 1970 | QED_OV_DRIVER_STATE_DISABLED); |
| 1971 | |
| 1972 | qed_ptt_release(hwfn, ptt); |
| 1973 | |
| 1974 | return status; |
| 1975 | } |
| 1976 | |
| 1977 | static int qed_update_mac(struct qed_dev *cdev, u8 *mac) |
| 1978 | { |
| 1979 | struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev); |
| 1980 | struct qed_ptt *ptt; |
| 1981 | int status = 0; |
| 1982 | |
| 1983 | if (IS_VF(cdev)) |
| 1984 | return 0; |
| 1985 | |
| 1986 | ptt = qed_ptt_acquire(hwfn); |
| 1987 | if (!ptt) |
| 1988 | return -EAGAIN; |
| 1989 | |
| 1990 | status = qed_mcp_ov_update_mac(hwfn, ptt, mac); |
| 1991 | if (status) |
| 1992 | goto out; |
| 1993 | |
| 1994 | status = qed_mcp_ov_update_current_config(hwfn, ptt, QED_OV_CLIENT_DRV); |
| 1995 | |
| 1996 | out: |
| 1997 | qed_ptt_release(hwfn, ptt); |
| 1998 | return status; |
| 1999 | } |
| 2000 | |
| 2001 | static int qed_update_mtu(struct qed_dev *cdev, u16 mtu) |
| 2002 | { |
| 2003 | struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev); |
| 2004 | struct qed_ptt *ptt; |
| 2005 | int status = 0; |
| 2006 | |
| 2007 | if (IS_VF(cdev)) |
| 2008 | return 0; |
| 2009 | |
| 2010 | ptt = qed_ptt_acquire(hwfn); |
| 2011 | if (!ptt) |
| 2012 | return -EAGAIN; |
| 2013 | |
| 2014 | status = qed_mcp_ov_update_mtu(hwfn, ptt, mtu); |
| 2015 | if (status) |
| 2016 | goto out; |
| 2017 | |
| 2018 | status = qed_mcp_ov_update_current_config(hwfn, ptt, QED_OV_CLIENT_DRV); |
| 2019 | |
| 2020 | out: |
| 2021 | qed_ptt_release(hwfn, ptt); |
| 2022 | return status; |
| 2023 | } |
| 2024 | |
Yuval Mintz | 8c93bea | 2016-10-13 22:57:03 +0300 | [diff] [blame] | 2025 | static struct qed_selftest_ops qed_selftest_ops_pass = { |
Sudarsana Reddy Kalluru | 03dc76c | 2016-04-28 20:20:52 -0400 | [diff] [blame] | 2026 | .selftest_memory = &qed_selftest_memory, |
| 2027 | .selftest_interrupt = &qed_selftest_interrupt, |
| 2028 | .selftest_register = &qed_selftest_register, |
| 2029 | .selftest_clock = &qed_selftest_clock, |
Mintz, Yuval | 7a4b21b | 2016-10-31 07:14:22 +0200 | [diff] [blame] | 2030 | .selftest_nvram = &qed_selftest_nvram, |
Sudarsana Reddy Kalluru | 03dc76c | 2016-04-28 20:20:52 -0400 | [diff] [blame] | 2031 | }; |
| 2032 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2033 | const struct qed_common_ops qed_common_ops_pass = { |
Sudarsana Reddy Kalluru | 03dc76c | 2016-04-28 20:20:52 -0400 | [diff] [blame] | 2034 | .selftest = &qed_selftest_ops_pass, |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2035 | .probe = &qed_probe, |
| 2036 | .remove = &qed_remove, |
| 2037 | .set_power_state = &qed_set_power_state, |
Mintz, Yuval | 712c3cb | 2017-05-23 09:41:28 +0300 | [diff] [blame] | 2038 | .set_name = &qed_set_name, |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2039 | .update_pf_params = &qed_update_pf_params, |
| 2040 | .slowpath_start = &qed_slowpath_start, |
| 2041 | .slowpath_stop = &qed_slowpath_stop, |
| 2042 | .set_fp_int = &qed_set_int_fp, |
| 2043 | .get_fp_int = &qed_get_int_fp, |
| 2044 | .sb_init = &qed_sb_init, |
| 2045 | .sb_release = &qed_sb_release, |
| 2046 | .simd_handler_config = &qed_simd_handler_config, |
| 2047 | .simd_handler_clean = &qed_simd_handler_clean, |
Arun Easi | 1e128c8 | 2017-02-15 06:28:22 -0800 | [diff] [blame] | 2048 | .dbg_grc = &qed_dbg_grc, |
| 2049 | .dbg_grc_size = &qed_dbg_grc_size, |
Yuval Mintz | fe7cd2b | 2016-04-22 08:41:03 +0300 | [diff] [blame] | 2050 | .can_link_change = &qed_can_link_change, |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 2051 | .set_link = &qed_set_link, |
| 2052 | .get_link = &qed_get_current_link, |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2053 | .drain = &qed_drain, |
| 2054 | .update_msglvl = &qed_init_dp, |
Tomer Tayar | e0971c8 | 2016-09-07 16:36:25 +0300 | [diff] [blame] | 2055 | .dbg_all_data = &qed_dbg_all_data, |
| 2056 | .dbg_all_data_size = &qed_dbg_all_data_size, |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2057 | .chain_alloc = &qed_chain_alloc, |
| 2058 | .chain_free = &qed_chain_free, |
Sudarsana Reddy Kalluru | 3a69cae | 2018-03-28 05:14:22 -0700 | [diff] [blame] | 2059 | .nvm_flash = &qed_nvm_flash, |
Mintz, Yuval | 20675b3 | 2017-06-02 08:58:32 +0300 | [diff] [blame] | 2060 | .nvm_get_image = &qed_nvm_get_image, |
Sudarsana Reddy Kalluru | 722003a | 2016-06-21 09:36:21 -0400 | [diff] [blame] | 2061 | .set_coalesce = &qed_set_coalesce, |
Sudarsana Kalluru | 91420b8 | 2015-11-30 12:25:03 +0200 | [diff] [blame] | 2062 | .set_led = &qed_set_led, |
Sudarsana Kalluru | 0fefbfb | 2016-10-31 07:14:21 +0200 | [diff] [blame] | 2063 | .update_drv_state = &qed_update_drv_state, |
| 2064 | .update_mac = &qed_update_mac, |
| 2065 | .update_mtu = &qed_update_mtu, |
Mintz, Yuval | 14d3964 | 2016-10-31 07:14:23 +0200 | [diff] [blame] | 2066 | .update_wol = &qed_update_wol, |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2067 | }; |
Sudarsana Reddy Kalluru | 6c75424 | 2016-08-16 10:51:03 -0400 | [diff] [blame] | 2068 | |
| 2069 | void qed_get_protocol_stats(struct qed_dev *cdev, |
| 2070 | enum qed_mcp_protocol_type type, |
| 2071 | union qed_mcp_protocol_stats *stats) |
| 2072 | { |
| 2073 | struct qed_eth_stats eth_stats; |
| 2074 | |
| 2075 | memset(stats, 0, sizeof(*stats)); |
| 2076 | |
| 2077 | switch (type) { |
| 2078 | case QED_MCP_LAN_STATS: |
| 2079 | qed_get_vport_stats(cdev, ð_stats); |
Mintz, Yuval | 9c79dda | 2017-03-14 16:23:54 +0200 | [diff] [blame] | 2080 | stats->lan_stats.ucast_rx_pkts = |
| 2081 | eth_stats.common.rx_ucast_pkts; |
| 2082 | stats->lan_stats.ucast_tx_pkts = |
| 2083 | eth_stats.common.tx_ucast_pkts; |
Sudarsana Reddy Kalluru | 6c75424 | 2016-08-16 10:51:03 -0400 | [diff] [blame] | 2084 | stats->lan_stats.fcs_err = -1; |
| 2085 | break; |
Arun Easi | 1e128c8 | 2017-02-15 06:28:22 -0800 | [diff] [blame] | 2086 | case QED_MCP_FCOE_STATS: |
| 2087 | qed_get_protocol_stats_fcoe(cdev, &stats->fcoe_stats); |
| 2088 | break; |
Mintz, Yuval | 2f2b261 | 2017-04-06 15:58:34 +0300 | [diff] [blame] | 2089 | case QED_MCP_ISCSI_STATS: |
| 2090 | qed_get_protocol_stats_iscsi(cdev, &stats->iscsi_stats); |
| 2091 | break; |
Sudarsana Reddy Kalluru | 6c75424 | 2016-08-16 10:51:03 -0400 | [diff] [blame] | 2092 | default: |
Mintz, Yuval | 512c784 | 2017-05-29 11:24:49 +0300 | [diff] [blame] | 2093 | DP_VERBOSE(cdev, QED_MSG_SP, |
| 2094 | "Invalid protocol type = %d\n", type); |
Sudarsana Reddy Kalluru | 6c75424 | 2016-08-16 10:51:03 -0400 | [diff] [blame] | 2095 | return; |
| 2096 | } |
| 2097 | } |