blob: 68c4399ffd508e4cfe563e1fe08ae246d8416bfb [file] [log] [blame]
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001/* QLogic qed NIC Driver
Mintz, Yuvale8f1cb52017-01-01 13:57:00 +02002 * Copyright (c) 2015-2017 QLogic Corporation
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02003 *
Mintz, Yuvale8f1cb52017-01-01 13:57:00 +02004 * 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 Mintzfe56b9e2015-10-26 11:02:25 +020031 */
32
33#include <linux/stddef.h>
34#include <linux/pci.h>
35#include <linux/kernel.h>
36#include <linux/slab.h>
Yuval Mintzfe56b9e2015-10-26 11:02:25 +020037#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 Tayar5d24bcf2017-03-28 15:12:52 +030047#include <linux/crash_dump.h>
Sudarsana Reddy Kalluru3a69cae2018-03-28 05:14:22 -070048#include <linux/crc32.h>
Yuval Mintzfe56b9e2015-10-26 11:02:25 +020049#include <linux/qed/qed_if.h>
Yuval Mintz0a7fb112016-10-01 21:59:55 +030050#include <linux/qed/qed_ll2_if.h>
Yuval Mintzfe56b9e2015-10-26 11:02:25 +020051
52#include "qed.h"
Yuval Mintz37bff2b2016-05-11 16:36:13 +030053#include "qed_sriov.h"
Yuval Mintzfe56b9e2015-10-26 11:02:25 +020054#include "qed_sp.h"
55#include "qed_dev_api.h"
Yuval Mintz0a7fb112016-10-01 21:59:55 +030056#include "qed_ll2.h"
Arun Easi1e128c82017-02-15 06:28:22 -080057#include "qed_fcoe.h"
Mintz, Yuval2f2b2612017-04-06 15:58:34 +030058#include "qed_iscsi.h"
59
Yuval Mintzfe56b9e2015-10-26 11:02:25 +020060#include "qed_mcp.h"
61#include "qed_hw.h"
Sudarsana Reddy Kalluru03dc76c2016-04-28 20:20:52 -040062#include "qed_selftest.h"
Arun Easi1e128c82017-02-15 06:28:22 -080063#include "qed_debug.h"
Yuval Mintzfe56b9e2015-10-26 11:02:25 +020064
Ram Amrani51ff1722016-10-01 21:59:57 +030065#define QED_ROCE_QPS (8192)
66#define QED_ROCE_DPIS (8)
Ram Amrani51ff1722016-10-01 21:59:57 +030067
Yuval Mintz5abd7e922016-02-24 16:52:50 +020068static char version[] =
69 "QLogic FastLinQ 4xxxx Core Module qed " DRV_MODULE_VERSION "\n";
Yuval Mintzfe56b9e2015-10-26 11:02:25 +020070
Yuval Mintz5abd7e922016-02-24 16:52:50 +020071MODULE_DESCRIPTION("QLogic FastLinQ 4xxxx Core Module");
Yuval Mintzfe56b9e2015-10-26 11:02:25 +020072MODULE_LICENSE("GPL");
73MODULE_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 Mintzd43d3f02016-02-24 16:52:48 +020084MODULE_FIRMWARE(QED_FW_FILE_NAME);
85
Yuval Mintzfe56b9e2015-10-26 11:02:25 +020086static int __init qed_init(void)
87{
Yuval Mintzfe56b9e2015-10-26 11:02:25 +020088 pr_info("%s", version);
89
90 return 0;
91}
92
93static void __exit qed_cleanup(void)
94{
95 pr_notice("qed_cleanup called\n");
96}
97
98module_init(qed_init);
99module_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*/
104static 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
122static void qed_free_pci(struct qed_dev *cdev)
123{
124 struct pci_dev *pdev = cdev->pdev;
125
Mintz, Yuval1a850bf2017-06-04 13:31:07 +0300126 if (cdev->doorbells && cdev->db_size)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200127 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 Mintz0dfaba62016-02-24 16:52:49 +0200136#define PCI_REVISION_ID_ERROR_VAL 0xff
137
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200138/* Performs PCI initializations as well as initializing PCI-related parameters
139 * in the device structrue. Returns 0 in case of success.
140 */
Yuval Mintz1a635e42016-08-15 10:42:43 +0300141static int qed_init_pci(struct qed_dev *cdev, struct pci_dev *pdev)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200142{
Yuval Mintz0dfaba62016-02-24 16:52:49 +0200143 u8 rev_id;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200144 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 Mintz1408cc1f2016-05-11 16:36:14 +0300160 if (IS_PF(cdev) && !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200161 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 Mintz0dfaba62016-02-24 16:52:49 +0200177 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 Mintzfe56b9e2015-10-26 11:02:25 +0200185 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 Mintz416cdf02016-05-15 14:48:09 +0300192 if (IS_PF(cdev) && !cdev->pci_params.pm_cap)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200193 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, Yuval1a850bf2017-06-04 13:31:07 +0300210 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 Mintz1408cc1f2016-05-11 16:36:14 +0300218 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200219 }
220
Mintz, Yuval1a850bf2017-06-04 13:31:07 +0300221 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 Mintzfe56b9e2015-10-26 11:02:25 +0200228 return 0;
229
230err2:
231 pci_release_regions(pdev);
232err1:
233 pci_disable_device(pdev);
234err0:
235 return rc;
236}
237
238int qed_fill_dev_info(struct qed_dev *cdev,
239 struct qed_dev_info *dev_info)
240{
Kalderon, Michalc851a9d2017-07-02 10:29:21 +0300241 struct qed_hwfn *p_hwfn = QED_LEADING_HWFN(cdev);
242 struct qed_hw_info *hw_info = &p_hwfn->hw_info;
Chopra, Manish19489c72017-04-24 10:00:45 -0700243 struct qed_tunnel_info *tun = &cdev->tunnel;
Manish Chopracee4d262015-10-26 11:02:28 +0200244 struct qed_ptt *ptt;
245
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200246 memset(dev_info, 0, sizeof(struct qed_dev_info));
247
Chopra, Manish19489c72017-04-24 10:00:45 -0700248 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 Mintzfe56b9e2015-10-26 11:02:25 +0200262 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, Michalc851a9d2017-07-02 10:29:21 +0300266 dev_info->rdma_supported = QED_IS_RDMA_PERSONALITY(p_hwfn);
Mintz, Yuval9c79dda2017-03-14 16:23:54 +0200267 dev_info->dev_type = cdev->type;
Kalderon, Michalc851a9d2017-07-02 10:29:21 +0300268 ether_addr_copy(dev_info->hw_mac, hw_info->hw_mac_addr);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200269
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300270 if (IS_PF(cdev)) {
271 dev_info->fw_major = FW_MAJOR_VERSION;
272 dev_info->fw_minor = FW_MINOR_VERSION;
273 dev_info->fw_rev = FW_REVISION_VERSION;
274 dev_info->fw_eng = FW_ENGINEERING_VERSION;
Sudarsana Reddy Kalluru0bc5fe82018-05-05 18:42:59 -0700275 dev_info->b_inter_pf_switch = test_bit(QED_MF_INTER_PF_SWITCH,
276 &cdev->mf_bits);
Yuval Mintz831bfb0e2016-05-11 16:36:25 +0300277 dev_info->tx_switching = true;
Mintz, Yuval14d39642016-10-31 07:14:23 +0200278
Kalderon, Michalc851a9d2017-07-02 10:29:21 +0300279 if (hw_info->b_wol_support == QED_WOL_SUPPORT_PME)
Mintz, Yuval14d39642016-10-31 07:14:23 +0200280 dev_info->wol_support = true;
Mintz, Yuval3c5da942017-06-02 08:58:31 +0300281
282 dev_info->abs_pf_id = QED_LEADING_HWFN(cdev)->abs_pf_id;
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300283 } 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 Mintzfe56b9e2015-10-26 11:02:25 +0200288
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300289 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 Mintzfe56b9e2015-10-26 11:02:25 +0200294
Tomer Tayarae336662017-05-23 09:41:26 +0300295 qed_mcp_get_mbi_ver(QED_LEADING_HWFN(cdev), ptt,
296 &dev_info->mbi_version);
297
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300298 qed_mcp_get_flash_size(QED_LEADING_HWFN(cdev), ptt,
299 &dev_info->flash_size);
Manish Chopracee4d262015-10-26 11:02:28 +0200300
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300301 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 Chopracee4d262015-10-26 11:02:28 +0200306 }
307
Kalderon, Michalc851a9d2017-07-02 10:29:21 +0300308 dev_info->mtu = hw_info->mtu;
Sudarsana Kalluru0fefbfb2016-10-31 07:14:21 +0200309
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200310 return 0;
311}
312
313static void qed_free_cdev(struct qed_dev *cdev)
314{
315 kfree((void *)cdev);
316}
317
318static 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 Mintz1a635e42016-08-15 10:42:43 +0300332static int qed_set_power_state(struct qed_dev *cdev, pci_power_t state)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200333{
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 */
342static struct qed_dev *qed_probe(struct pci_dev *pdev,
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300343 struct qed_probe_params *params)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200344{
345 struct qed_dev *cdev;
346 int rc;
347
348 cdev = qed_alloc_cdev(pdev);
349 if (!cdev)
350 goto err0;
351
Mintz, Yuval712c3cb2017-05-23 09:41:28 +0300352 cdev->drv_type = DRV_ID_DRV_TYPE_LINUX;
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300353 cdev->protocol = params->protocol;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200354
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300355 if (params->is_vf)
356 cdev->b_is_vf = true;
357
358 qed_init_dp(cdev, params->dp_module, params->dp_level);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200359
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
377err2:
378 qed_free_pci(cdev);
379err1:
380 qed_free_cdev(cdev);
381err0:
382 return NULL;
383}
384
385static 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
399static 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
411static 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 Mintz1a635e42016-08-15 10:42:43 +0300435 rc = pci_enable_msix_exact(cdev->pdev, int_params->msix_table,
436 cnt);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200437 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 */
456static 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 Kallurubb13ace2016-05-26 11:01:23 +0300484 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 Mintzfe56b9e2015-10-26 11:02:25 +0200490
Sudarsana Reddy Kallurubb13ace2016-05-26 11:01:23 +0300491 DP_NOTICE(cdev, "Failed to enable MSI\n");
492 if (force_mode)
493 goto out;
494 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200495 /* 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
507out:
Yuval Mintz525ef5c2016-08-15 10:42:45 +0300508 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 Mintzfe56b9e2015-10-26 11:02:25 +0200513 cdev->int_coalescing_mode = QED_COAL_MODE_ENABLE;
514
515 return rc;
516}
517
518static 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
528static 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
537static irqreturn_t qed_msix_sp_int(int irq, void *tasklet)
538{
539 tasklet_schedule((struct tasklet_struct *)tasklet);
540 return IRQ_HANDLED;
541}
542
543static 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 Kalluru8f16bc92015-12-07 06:25:59 -0500585int qed_slowpath_irq_req(struct qed_hwfn *hwfn)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200586{
Sudarsana Kalluru8f16bc92015-12-07 06:25:59 -0500587 struct qed_dev *cdev = hwfn->cdev;
Yuval Mintz525ef5c2016-08-15 10:42:45 +0300588 u32 int_mode;
Sudarsana Kalluru8f16bc92015-12-07 06:25:59 -0500589 int rc = 0;
590 u8 id;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200591
Yuval Mintz525ef5c2016-08-15 10:42:45 +0300592 int_mode = cdev->int_params.out.int_mode;
593 if (int_mode == QED_INT_MODE_MSIX) {
Sudarsana Kalluru8f16bc92015-12-07 06:25:59 -0500594 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 Mintzfe56b9e2015-10-26 11:02:25 +0200600 } 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 Mintz525ef5c2016-08-15 10:42:45 +0300614 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 Mintzfe56b9e2015-10-26 11:02:25 +0200621 return rc;
622}
623
Tomer Tayar06892f22017-05-23 09:41:24 +0300624static 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 Tayar12263372017-03-28 15:12:50 +0300636void 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 Tayar06892f22017-05-23 09:41:24 +0300647
648 qed_slowpath_tasklet_flush(p_hwfn);
Tomer Tayar12263372017-03-28 15:12:50 +0300649}
650
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200651static 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 Kalluru8f16bc92015-12-07 06:25:59 -0500657 if (!cdev->hwfns[i].b_int_requested)
658 break;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200659 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 Kalluru8f16bc92015-12-07 06:25:59 -0500664 if (QED_LEADING_HWFN(cdev)->b_int_requested)
665 free_irq(cdev->pdev->irq, cdev);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200666 }
Sudarsana Kalluru8f16bc92015-12-07 06:25:59 -0500667 qed_int_disable_post_isr_release(cdev);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200668}
669
670static 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 King2fdae032018-05-10 15:03:27 +0100683 "Disabled sp tasklet [hwfn %d] at %p\n",
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200684 i, p_hwfn->sp_dpc);
685 }
686 }
687
Tomer Tayarc965db42016-09-07 16:36:24 +0300688 qed_dbg_pf_exit(cdev);
689
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200690 return rc;
691}
692
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200693static int qed_nic_setup(struct qed_dev *cdev)
694{
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300695 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 Mintzfe56b9e2015-10-26 11:02:25 +0200705
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
717static 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
735static 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
758static int qed_slowpath_setup_int(struct qed_dev *cdev,
759 enum qed_int_mode int_mode)
760{
Yuval Mintz4ac801b2016-02-28 12:26:52 +0200761 struct qed_sb_cnt_info sb_cnt_info;
Yuval Mintz0189efb2016-10-13 22:57:02 +0300762 int num_l2_queues = 0;
Yuval Mintz4ac801b2016-02-28 12:26:52 +0200763 int rc;
764 int i;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200765
Sudarsana Reddy Kalluru1d2c2022016-08-01 09:08:13 -0400766 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 Mintzfe56b9e2015-10-26 11:02:25 +0200772 cdev->int_params.in.int_mode = int_mode;
Yuval Mintz4ac801b2016-02-28 12:26:52 +0200773 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, Yuval726fdbe2017-06-01 15:29:06 +0300776 cdev->int_params.in.num_vectors += sb_cnt_info.cnt;
Yuval Mintz4ac801b2016-02-28 12:26:52 +0200777 cdev->int_params.in.num_vectors++; /* slowpath */
778 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200779
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, Yuval2f782272017-04-05 21:20:11 +0300793 if (!IS_ENABLED(CONFIG_QED_RDMA) ||
Kalderon, Michalc851a9d2017-07-02 10:29:21 +0300794 !QED_IS_RDMA_PERSONALITY(QED_LEADING_HWFN(cdev)))
Yuval Mintz0189efb2016-10-13 22:57:02 +0300795 return 0;
796
Ram Amrani51ff1722016-10-01 21:59:57 +0300797 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 Amrani51ff1722016-10-01 21:59:57 +0300818
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200819 return 0;
820}
821
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300822static 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 Mintzfe56b9e2015-10-26 11:02:25 +0200851u32 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
881static 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
902static 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
917static void qed_update_pf_params(struct qed_dev *cdev,
918 struct qed_pf_params *params)
919{
920 int i;
921
Ram Amrani5c5f2602016-11-09 22:48:44 +0200922 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 Amrani5c5f2602016-11-09 22:48:44 +0200926 params->rdma_pf_params.gl_pi = QED_ROCE_PROTOCOL_INDEX;
927 }
928
Chopra, Manishd51e4af2017-04-13 04:54:44 -0700929 if (cdev->num_hwfns > 1 || IS_VF(cdev))
930 params->eth_pf_params.num_arfs_filters = 0;
931
Mintz, Yuvale1d32ac2017-01-01 13:57:03 +0200932 /* 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, Michalc851a9d2017-07-02 10:29:21 +0300935 if (QED_IS_RDMA_PERSONALITY(QED_LEADING_HWFN(cdev))) {
Mintz, Yuvale1d32ac2017-01-01 13:57:03 +0200936 u16 *num_cons;
937
938 num_cons = &params->eth_pf_params.num_cons;
939 *num_cons = min_t(u16, *num_cons, 192);
940 }
941
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200942 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
Sudarsana Reddy Kalluru59ccf862018-05-22 00:28:41 -0700949static void qed_slowpath_wq_stop(struct qed_dev *cdev)
950{
951 int i;
952
953 if (IS_VF(cdev))
954 return;
955
956 for_each_hwfn(cdev, i) {
957 if (!cdev->hwfns[i].slowpath_wq)
958 continue;
959
960 flush_workqueue(cdev->hwfns[i].slowpath_wq);
961 destroy_workqueue(cdev->hwfns[i].slowpath_wq);
962 }
963}
964
965static void qed_slowpath_task(struct work_struct *work)
966{
967 struct qed_hwfn *hwfn = container_of(work, struct qed_hwfn,
968 slowpath_task.work);
969 struct qed_ptt *ptt = qed_ptt_acquire(hwfn);
970
971 if (!ptt) {
972 queue_delayed_work(hwfn->slowpath_wq, &hwfn->slowpath_task, 0);
973 return;
974 }
975
976 if (test_and_clear_bit(QED_SLOWPATH_MFW_TLV_REQ,
977 &hwfn->slowpath_task_flags))
978 qed_mfw_process_tlv_req(hwfn, ptt);
979
980 qed_ptt_release(hwfn, ptt);
981}
982
983static int qed_slowpath_wq_start(struct qed_dev *cdev)
984{
985 struct qed_hwfn *hwfn;
986 char name[NAME_SIZE];
987 int i;
988
989 if (IS_VF(cdev))
990 return 0;
991
992 for_each_hwfn(cdev, i) {
993 hwfn = &cdev->hwfns[i];
994
995 snprintf(name, NAME_SIZE, "slowpath-%02x:%02x.%02x",
996 cdev->pdev->bus->number,
997 PCI_SLOT(cdev->pdev->devfn), hwfn->abs_pf_id);
998
999 hwfn->slowpath_wq = alloc_workqueue(name, 0, 0);
1000 if (!hwfn->slowpath_wq) {
1001 DP_NOTICE(hwfn, "Cannot create slowpath workqueue\n");
1002 return -ENOMEM;
1003 }
1004
1005 INIT_DELAYED_WORK(&hwfn->slowpath_task, qed_slowpath_task);
1006 }
1007
1008 return 0;
1009}
1010
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001011static int qed_slowpath_start(struct qed_dev *cdev,
1012 struct qed_slowpath_params *params)
1013{
Tomer Tayar5d24bcf2017-03-28 15:12:52 +03001014 struct qed_drv_load_params drv_load_params;
Mintz, Yuvalc0c2d0b2017-03-28 15:12:51 +03001015 struct qed_hw_init_params hw_init_params;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001016 struct qed_mcp_drv_version drv_version;
Chopra, Manish199684302017-04-24 10:00:44 -07001017 struct qed_tunnel_info tunn_info;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001018 const u8 *data = NULL;
1019 struct qed_hwfn *hwfn;
Sudarsana Reddy Kalluruc78c70f2017-02-15 10:24:10 +02001020 struct qed_ptt *p_ptt;
Yuval Mintz37bff2b2016-05-11 16:36:13 +03001021 int rc = -EINVAL;
1022
1023 if (qed_iov_wq_start(cdev))
1024 goto err;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001025
Sudarsana Reddy Kalluru59ccf862018-05-22 00:28:41 -07001026 if (qed_slowpath_wq_start(cdev))
1027 goto err;
1028
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001029 if (IS_PF(cdev)) {
1030 rc = request_firmware(&cdev->firmware, QED_FW_FILE_NAME,
1031 &cdev->pdev->dev);
1032 if (rc) {
1033 DP_NOTICE(cdev,
1034 "Failed to find fw file - /lib/firmware/%s\n",
1035 QED_FW_FILE_NAME);
1036 goto err;
1037 }
Sudarsana Reddy Kalluruc78c70f2017-02-15 10:24:10 +02001038
Chopra, Manishd51e4af2017-04-13 04:54:44 -07001039 if (cdev->num_hwfns == 1) {
1040 p_ptt = qed_ptt_acquire(QED_LEADING_HWFN(cdev));
1041 if (p_ptt) {
1042 QED_LEADING_HWFN(cdev)->p_arfs_ptt = p_ptt;
1043 } else {
1044 DP_NOTICE(cdev,
1045 "Failed to acquire PTT for aRFS\n");
1046 goto err;
1047 }
1048 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001049 }
1050
Sudarsana Reddy Kalluru0e191822016-10-21 04:43:42 -04001051 cdev->rx_coalesce_usecs = QED_DEFAULT_RX_USECS;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001052 rc = qed_nic_setup(cdev);
1053 if (rc)
1054 goto err;
1055
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001056 if (IS_PF(cdev))
1057 rc = qed_slowpath_setup_int(cdev, params->int_mode);
1058 else
1059 rc = qed_slowpath_vf_setup_int(cdev);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001060 if (rc)
1061 goto err1;
1062
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001063 if (IS_PF(cdev)) {
1064 /* Allocate stream for unzipping */
1065 rc = qed_alloc_stream_mem(cdev);
Joe Perches2591c282016-09-04 14:24:03 -07001066 if (rc)
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001067 goto err2;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001068
Joe Perches8ac1ed72017-05-08 15:57:56 -07001069 /* First Dword used to differentiate between various sources */
Yuval Mintz351a4ded2016-06-02 10:23:29 +03001070 data = cdev->firmware->data + sizeof(u32);
Tomer Tayarc965db42016-09-07 16:36:24 +03001071
1072 qed_dbg_pf_init(cdev);
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001073 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001074
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001075 /* Start the slowpath */
Mintz, Yuvalc0c2d0b2017-03-28 15:12:51 +03001076 memset(&hw_init_params, 0, sizeof(hw_init_params));
Chopra, Manish199684302017-04-24 10:00:44 -07001077 memset(&tunn_info, 0, sizeof(tunn_info));
1078 tunn_info.vxlan.b_mode_enabled = true;
1079 tunn_info.l2_gre.b_mode_enabled = true;
1080 tunn_info.ip_gre.b_mode_enabled = true;
1081 tunn_info.l2_geneve.b_mode_enabled = true;
1082 tunn_info.ip_geneve.b_mode_enabled = true;
1083 tunn_info.vxlan.tun_cls = QED_TUNN_CLSS_MAC_VLAN;
1084 tunn_info.l2_gre.tun_cls = QED_TUNN_CLSS_MAC_VLAN;
1085 tunn_info.ip_gre.tun_cls = QED_TUNN_CLSS_MAC_VLAN;
1086 tunn_info.l2_geneve.tun_cls = QED_TUNN_CLSS_MAC_VLAN;
1087 tunn_info.ip_geneve.tun_cls = QED_TUNN_CLSS_MAC_VLAN;
Mintz, Yuvalc0c2d0b2017-03-28 15:12:51 +03001088 hw_init_params.p_tunn = &tunn_info;
1089 hw_init_params.b_hw_start = true;
1090 hw_init_params.int_mode = cdev->int_params.out.int_mode;
1091 hw_init_params.allow_npar_tx_switch = true;
1092 hw_init_params.bin_fw_data = data;
1093
Tomer Tayar5d24bcf2017-03-28 15:12:52 +03001094 memset(&drv_load_params, 0, sizeof(drv_load_params));
1095 drv_load_params.is_crash_kernel = is_kdump_kernel();
1096 drv_load_params.mfw_timeout_val = QED_LOAD_REQ_LOCK_TO_DEFAULT;
1097 drv_load_params.avoid_eng_reset = false;
1098 drv_load_params.override_force_load = QED_OVERRIDE_FORCE_LOAD_NONE;
1099 hw_init_params.p_drv_load_params = &drv_load_params;
1100
Mintz, Yuvalc0c2d0b2017-03-28 15:12:51 +03001101 rc = qed_hw_init(cdev, &hw_init_params);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001102 if (rc)
Yuval Mintz8c925c42016-03-02 20:26:03 +02001103 goto err2;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001104
1105 DP_INFO(cdev,
1106 "HW initialization and function start completed successfully\n");
1107
Chopra, Manisheaf3c0c2017-04-24 10:00:49 -07001108 if (IS_PF(cdev)) {
1109 cdev->tunn_feature_mask = (BIT(QED_MODE_VXLAN_TUNN) |
1110 BIT(QED_MODE_L2GENEVE_TUNN) |
1111 BIT(QED_MODE_IPGENEVE_TUNN) |
1112 BIT(QED_MODE_L2GRE_TUNN) |
1113 BIT(QED_MODE_IPGRE_TUNN));
1114 }
1115
Yuval Mintz0a7fb112016-10-01 21:59:55 +03001116 /* Allocate LL2 interface if needed */
1117 if (QED_LEADING_HWFN(cdev)->using_ll2) {
1118 rc = qed_ll2_alloc_if(cdev);
1119 if (rc)
1120 goto err3;
1121 }
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001122 if (IS_PF(cdev)) {
1123 hwfn = QED_LEADING_HWFN(cdev);
1124 drv_version.version = (params->drv_major << 24) |
1125 (params->drv_minor << 16) |
1126 (params->drv_rev << 8) |
1127 (params->drv_eng);
1128 strlcpy(drv_version.name, params->name,
1129 MCP_DRV_VER_STR_SIZE - 4);
1130 rc = qed_mcp_send_drv_version(hwfn, hwfn->p_main_ptt,
1131 &drv_version);
1132 if (rc) {
1133 DP_NOTICE(cdev, "Failed sending drv version command\n");
1134 return rc;
1135 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001136 }
1137
Yuval Mintz8c925c42016-03-02 20:26:03 +02001138 qed_reset_vport_stats(cdev);
1139
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001140 return 0;
1141
Yuval Mintz0a7fb112016-10-01 21:59:55 +03001142err3:
1143 qed_hw_stop(cdev);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001144err2:
Yuval Mintz8c925c42016-03-02 20:26:03 +02001145 qed_hw_timers_stop_all(cdev);
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001146 if (IS_PF(cdev))
1147 qed_slowpath_irq_free(cdev);
Yuval Mintz8c925c42016-03-02 20:26:03 +02001148 qed_free_stream_mem(cdev);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001149 qed_disable_msix(cdev);
1150err1:
1151 qed_resc_free(cdev);
1152err:
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001153 if (IS_PF(cdev))
1154 release_firmware(cdev->firmware);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001155
Chopra, Manishd51e4af2017-04-13 04:54:44 -07001156 if (IS_PF(cdev) && (cdev->num_hwfns == 1) &&
1157 QED_LEADING_HWFN(cdev)->p_arfs_ptt)
1158 qed_ptt_release(QED_LEADING_HWFN(cdev),
1159 QED_LEADING_HWFN(cdev)->p_arfs_ptt);
Sudarsana Reddy Kalluruc78c70f2017-02-15 10:24:10 +02001160
Yuval Mintz37bff2b2016-05-11 16:36:13 +03001161 qed_iov_wq_stop(cdev, false);
1162
Sudarsana Reddy Kalluru59ccf862018-05-22 00:28:41 -07001163 qed_slowpath_wq_stop(cdev);
1164
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001165 return rc;
1166}
1167
1168static int qed_slowpath_stop(struct qed_dev *cdev)
1169{
1170 if (!cdev)
1171 return -ENODEV;
1172
Sudarsana Reddy Kalluru59ccf862018-05-22 00:28:41 -07001173 qed_slowpath_wq_stop(cdev);
1174
Yuval Mintz0a7fb112016-10-01 21:59:55 +03001175 qed_ll2_dealloc_if(cdev);
1176
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001177 if (IS_PF(cdev)) {
Chopra, Manishd51e4af2017-04-13 04:54:44 -07001178 if (cdev->num_hwfns == 1)
1179 qed_ptt_release(QED_LEADING_HWFN(cdev),
1180 QED_LEADING_HWFN(cdev)->p_arfs_ptt);
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001181 qed_free_stream_mem(cdev);
Yuval Mintzc5ac9312016-06-03 14:35:34 +03001182 if (IS_QED_ETH_IF(cdev))
1183 qed_sriov_disable(cdev, true);
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001184 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001185
Mintz, Yuval5f027d72017-05-09 15:07:48 +03001186 qed_nic_stop(cdev);
1187
1188 if (IS_PF(cdev))
1189 qed_slowpath_irq_free(cdev);
1190
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001191 qed_disable_msix(cdev);
Tomer Tayar12263372017-03-28 15:12:50 +03001192
1193 qed_resc_free(cdev);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001194
Yuval Mintz37bff2b2016-05-11 16:36:13 +03001195 qed_iov_wq_stop(cdev, true);
1196
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001197 if (IS_PF(cdev))
1198 release_firmware(cdev->firmware);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001199
1200 return 0;
1201}
1202
Mintz, Yuval712c3cb2017-05-23 09:41:28 +03001203static void qed_set_name(struct qed_dev *cdev, char name[NAME_SIZE])
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001204{
1205 int i;
1206
1207 memcpy(cdev->name, name, NAME_SIZE);
1208 for_each_hwfn(cdev, i)
1209 snprintf(cdev->hwfns[i].name, NAME_SIZE, "%s-%d", name, i);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001210}
1211
1212static u32 qed_sb_init(struct qed_dev *cdev,
1213 struct qed_sb_info *sb_info,
1214 void *sb_virt_addr,
1215 dma_addr_t sb_phy_addr, u16 sb_id,
1216 enum qed_sb_type type)
1217{
1218 struct qed_hwfn *p_hwfn;
Mintz, Yuval85750d72017-02-20 22:43:38 +02001219 struct qed_ptt *p_ptt;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001220 int hwfn_index;
1221 u16 rel_sb_id;
1222 u8 n_hwfns;
1223 u32 rc;
1224
1225 /* RoCE uses single engine and CMT uses two engines. When using both
1226 * we force only a single engine. Storage uses only engine 0 too.
1227 */
1228 if (type == QED_SB_TYPE_L2_QUEUE)
1229 n_hwfns = cdev->num_hwfns;
1230 else
1231 n_hwfns = 1;
1232
1233 hwfn_index = sb_id % n_hwfns;
1234 p_hwfn = &cdev->hwfns[hwfn_index];
1235 rel_sb_id = sb_id / n_hwfns;
1236
1237 DP_VERBOSE(cdev, NETIF_MSG_INTR,
1238 "hwfn [%d] <--[init]-- SB %04x [0x%04x upper]\n",
1239 hwfn_index, rel_sb_id, sb_id);
1240
Mintz, Yuval85750d72017-02-20 22:43:38 +02001241 if (IS_PF(p_hwfn->cdev)) {
1242 p_ptt = qed_ptt_acquire(p_hwfn);
1243 if (!p_ptt)
1244 return -EBUSY;
1245
1246 rc = qed_int_sb_init(p_hwfn, p_ptt, sb_info, sb_virt_addr,
1247 sb_phy_addr, rel_sb_id);
1248 qed_ptt_release(p_hwfn, p_ptt);
1249 } else {
1250 rc = qed_int_sb_init(p_hwfn, NULL, sb_info, sb_virt_addr,
1251 sb_phy_addr, rel_sb_id);
1252 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001253
1254 return rc;
1255}
1256
1257static u32 qed_sb_release(struct qed_dev *cdev,
Yuval Mintz1a635e42016-08-15 10:42:43 +03001258 struct qed_sb_info *sb_info, u16 sb_id)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001259{
1260 struct qed_hwfn *p_hwfn;
1261 int hwfn_index;
1262 u16 rel_sb_id;
1263 u32 rc;
1264
1265 hwfn_index = sb_id % cdev->num_hwfns;
1266 p_hwfn = &cdev->hwfns[hwfn_index];
1267 rel_sb_id = sb_id / cdev->num_hwfns;
1268
1269 DP_VERBOSE(cdev, NETIF_MSG_INTR,
1270 "hwfn [%d] <--[init]-- SB %04x [0x%04x upper]\n",
1271 hwfn_index, rel_sb_id, sb_id);
1272
1273 rc = qed_int_sb_release(p_hwfn, sb_info, rel_sb_id);
1274
1275 return rc;
1276}
1277
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +03001278static bool qed_can_link_change(struct qed_dev *cdev)
1279{
1280 return true;
1281}
1282
Yuval Mintz351a4ded2016-06-02 10:23:29 +03001283static int qed_set_link(struct qed_dev *cdev, struct qed_link_params *params)
Yuval Mintzcc875c22015-10-26 11:02:31 +02001284{
1285 struct qed_hwfn *hwfn;
1286 struct qed_mcp_link_params *link_params;
1287 struct qed_ptt *ptt;
1288 int rc;
1289
1290 if (!cdev)
1291 return -ENODEV;
1292
1293 /* The link should be set only once per PF */
1294 hwfn = &cdev->hwfns[0];
1295
Mintz, Yuval65ed2ff2017-02-20 22:43:39 +02001296 /* When VF wants to set link, force it to read the bulletin instead.
1297 * This mimics the PF behavior, where a noitification [both immediate
1298 * and possible later] would be generated when changing properties.
1299 */
1300 if (IS_VF(cdev)) {
1301 qed_schedule_iov(hwfn, QED_IOV_WQ_VF_FORCE_LINK_QUERY_FLAG);
1302 return 0;
1303 }
1304
Yuval Mintzcc875c22015-10-26 11:02:31 +02001305 ptt = qed_ptt_acquire(hwfn);
1306 if (!ptt)
1307 return -EBUSY;
1308
1309 link_params = qed_mcp_get_link_params(hwfn);
1310 if (params->override_flags & QED_LINK_OVERRIDE_SPEED_AUTONEG)
1311 link_params->speed.autoneg = params->autoneg;
1312 if (params->override_flags & QED_LINK_OVERRIDE_SPEED_ADV_SPEEDS) {
1313 link_params->speed.advertised_speeds = 0;
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001314 if ((params->adv_speeds & QED_LM_1000baseT_Half_BIT) ||
1315 (params->adv_speeds & QED_LM_1000baseT_Full_BIT))
Yuval Mintzcc875c22015-10-26 11:02:31 +02001316 link_params->speed.advertised_speeds |=
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001317 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G;
1318 if (params->adv_speeds & QED_LM_10000baseKR_Full_BIT)
Yuval Mintzcc875c22015-10-26 11:02:31 +02001319 link_params->speed.advertised_speeds |=
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001320 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G;
1321 if (params->adv_speeds & QED_LM_25000baseKR_Full_BIT)
Yuval Mintzcc875c22015-10-26 11:02:31 +02001322 link_params->speed.advertised_speeds |=
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001323 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_25G;
1324 if (params->adv_speeds & QED_LM_40000baseLR4_Full_BIT)
Yuval Mintzcc875c22015-10-26 11:02:31 +02001325 link_params->speed.advertised_speeds |=
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001326 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G;
1327 if (params->adv_speeds & QED_LM_50000baseKR2_Full_BIT)
1328 link_params->speed.advertised_speeds |=
1329 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_50G;
1330 if (params->adv_speeds & QED_LM_100000baseKR4_Full_BIT)
Yuval Mintzcc875c22015-10-26 11:02:31 +02001331 link_params->speed.advertised_speeds |=
Yuval Mintz351a4ded2016-06-02 10:23:29 +03001332 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_BB_100G;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001333 }
1334 if (params->override_flags & QED_LINK_OVERRIDE_SPEED_FORCED_SPEED)
1335 link_params->speed.forced_speed = params->forced_speed;
Sudarsana Reddy Kallurua43f2352016-04-22 08:41:04 +03001336 if (params->override_flags & QED_LINK_OVERRIDE_PAUSE_CONFIG) {
1337 if (params->pause_config & QED_LINK_PAUSE_AUTONEG_ENABLE)
1338 link_params->pause.autoneg = true;
1339 else
1340 link_params->pause.autoneg = false;
1341 if (params->pause_config & QED_LINK_PAUSE_RX_ENABLE)
1342 link_params->pause.forced_rx = true;
1343 else
1344 link_params->pause.forced_rx = false;
1345 if (params->pause_config & QED_LINK_PAUSE_TX_ENABLE)
1346 link_params->pause.forced_tx = true;
1347 else
1348 link_params->pause.forced_tx = false;
1349 }
Sudarsana Reddy Kalluru03dc76c2016-04-28 20:20:52 -04001350 if (params->override_flags & QED_LINK_OVERRIDE_LOOPBACK_MODE) {
1351 switch (params->loopback_mode) {
1352 case QED_LINK_LOOPBACK_INT_PHY:
Yuval Mintz351a4ded2016-06-02 10:23:29 +03001353 link_params->loopback_mode = ETH_LOOPBACK_INT_PHY;
Sudarsana Reddy Kalluru03dc76c2016-04-28 20:20:52 -04001354 break;
1355 case QED_LINK_LOOPBACK_EXT_PHY:
Yuval Mintz351a4ded2016-06-02 10:23:29 +03001356 link_params->loopback_mode = ETH_LOOPBACK_EXT_PHY;
Sudarsana Reddy Kalluru03dc76c2016-04-28 20:20:52 -04001357 break;
1358 case QED_LINK_LOOPBACK_EXT:
Yuval Mintz351a4ded2016-06-02 10:23:29 +03001359 link_params->loopback_mode = ETH_LOOPBACK_EXT;
Sudarsana Reddy Kalluru03dc76c2016-04-28 20:20:52 -04001360 break;
1361 case QED_LINK_LOOPBACK_MAC:
Yuval Mintz351a4ded2016-06-02 10:23:29 +03001362 link_params->loopback_mode = ETH_LOOPBACK_MAC;
Sudarsana Reddy Kalluru03dc76c2016-04-28 20:20:52 -04001363 break;
1364 default:
Yuval Mintz351a4ded2016-06-02 10:23:29 +03001365 link_params->loopback_mode = ETH_LOOPBACK_NONE;
Sudarsana Reddy Kalluru03dc76c2016-04-28 20:20:52 -04001366 break;
1367 }
1368 }
Yuval Mintzcc875c22015-10-26 11:02:31 +02001369
Sudarsana Reddy Kalluru645874e2017-07-26 06:07:11 -07001370 if (params->override_flags & QED_LINK_OVERRIDE_EEE_CONFIG)
1371 memcpy(&link_params->eee, &params->eee,
1372 sizeof(link_params->eee));
1373
Yuval Mintzcc875c22015-10-26 11:02:31 +02001374 rc = qed_mcp_set_link(hwfn, ptt, params->link_up);
1375
1376 qed_ptt_release(hwfn, ptt);
1377
1378 return rc;
1379}
1380
1381static int qed_get_port_type(u32 media_type)
1382{
1383 int port_type;
1384
1385 switch (media_type) {
1386 case MEDIA_SFPP_10G_FIBER:
1387 case MEDIA_SFP_1G_FIBER:
1388 case MEDIA_XFP_FIBER:
Yuval Mintzb639f192016-06-19 15:18:15 +03001389 case MEDIA_MODULE_FIBER:
Yuval Mintzcc875c22015-10-26 11:02:31 +02001390 case MEDIA_KR:
1391 port_type = PORT_FIBRE;
1392 break;
1393 case MEDIA_DA_TWINAX:
1394 port_type = PORT_DA;
1395 break;
1396 case MEDIA_BASE_T:
1397 port_type = PORT_TP;
1398 break;
1399 case MEDIA_NOT_PRESENT:
1400 port_type = PORT_NONE;
1401 break;
1402 case MEDIA_UNSPECIFIED:
1403 default:
1404 port_type = PORT_OTHER;
1405 break;
1406 }
1407 return port_type;
1408}
1409
Arnd Bergmann14b84e82016-06-01 15:29:13 +02001410static int qed_get_link_data(struct qed_hwfn *hwfn,
1411 struct qed_mcp_link_params *params,
1412 struct qed_mcp_link_state *link,
1413 struct qed_mcp_link_capabilities *link_caps)
1414{
1415 void *p;
1416
1417 if (!IS_PF(hwfn->cdev)) {
1418 qed_vf_get_link_params(hwfn, params);
1419 qed_vf_get_link_state(hwfn, link);
1420 qed_vf_get_link_caps(hwfn, link_caps);
1421
1422 return 0;
1423 }
1424
1425 p = qed_mcp_get_link_params(hwfn);
1426 if (!p)
1427 return -ENXIO;
1428 memcpy(params, p, sizeof(*params));
1429
1430 p = qed_mcp_get_link_state(hwfn);
1431 if (!p)
1432 return -ENXIO;
1433 memcpy(link, p, sizeof(*link));
1434
1435 p = qed_mcp_get_link_capabilities(hwfn);
1436 if (!p)
1437 return -ENXIO;
1438 memcpy(link_caps, p, sizeof(*link_caps));
1439
1440 return 0;
1441}
1442
Yuval Mintzcc875c22015-10-26 11:02:31 +02001443static void qed_fill_link(struct qed_hwfn *hwfn,
1444 struct qed_link_output *if_link)
1445{
1446 struct qed_mcp_link_params params;
1447 struct qed_mcp_link_state link;
1448 struct qed_mcp_link_capabilities link_caps;
1449 u32 media_type;
1450
1451 memset(if_link, 0, sizeof(*if_link));
1452
1453 /* Prepare source inputs */
Arnd Bergmann14b84e82016-06-01 15:29:13 +02001454 if (qed_get_link_data(hwfn, &params, &link, &link_caps)) {
1455 dev_warn(&hwfn->cdev->pdev->dev, "no link data available\n");
1456 return;
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001457 }
Yuval Mintzcc875c22015-10-26 11:02:31 +02001458
1459 /* Set the link parameters to pass to protocol driver */
1460 if (link.link_up)
1461 if_link->link_up = true;
1462
1463 /* TODO - at the moment assume supported and advertised speed equal */
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001464 if_link->supported_caps = QED_LM_FIBRE_BIT;
sudarsana.kalluru@cavium.com34f91992017-05-04 08:15:04 -07001465 if (link_caps.default_speed_autoneg)
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001466 if_link->supported_caps |= QED_LM_Autoneg_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001467 if (params.pause.autoneg ||
1468 (params.pause.forced_rx && params.pause.forced_tx))
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001469 if_link->supported_caps |= QED_LM_Asym_Pause_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001470 if (params.pause.autoneg || params.pause.forced_rx ||
1471 params.pause.forced_tx)
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001472 if_link->supported_caps |= QED_LM_Pause_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001473
1474 if_link->advertised_caps = if_link->supported_caps;
sudarsana.kalluru@cavium.com34f91992017-05-04 08:15:04 -07001475 if (params.speed.autoneg)
1476 if_link->advertised_caps |= QED_LM_Autoneg_BIT;
1477 else
1478 if_link->advertised_caps &= ~QED_LM_Autoneg_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001479 if (params.speed.advertised_speeds &
1480 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G)
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001481 if_link->advertised_caps |= QED_LM_1000baseT_Half_BIT |
1482 QED_LM_1000baseT_Full_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001483 if (params.speed.advertised_speeds &
1484 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G)
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001485 if_link->advertised_caps |= QED_LM_10000baseKR_Full_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001486 if (params.speed.advertised_speeds &
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001487 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_25G)
1488 if_link->advertised_caps |= QED_LM_25000baseKR_Full_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001489 if (params.speed.advertised_speeds &
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001490 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G)
1491 if_link->advertised_caps |= QED_LM_40000baseLR4_Full_BIT;
1492 if (params.speed.advertised_speeds &
1493 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_50G)
1494 if_link->advertised_caps |= QED_LM_50000baseKR2_Full_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001495 if (params.speed.advertised_speeds &
Yuval Mintz351a4ded2016-06-02 10:23:29 +03001496 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_BB_100G)
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001497 if_link->advertised_caps |= QED_LM_100000baseKR4_Full_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001498
1499 if (link_caps.speed_capabilities &
1500 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G)
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001501 if_link->supported_caps |= QED_LM_1000baseT_Half_BIT |
1502 QED_LM_1000baseT_Full_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001503 if (link_caps.speed_capabilities &
1504 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G)
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001505 if_link->supported_caps |= QED_LM_10000baseKR_Full_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001506 if (link_caps.speed_capabilities &
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001507 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_25G)
1508 if_link->supported_caps |= QED_LM_25000baseKR_Full_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001509 if (link_caps.speed_capabilities &
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001510 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G)
1511 if_link->supported_caps |= QED_LM_40000baseLR4_Full_BIT;
1512 if (link_caps.speed_capabilities &
1513 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_50G)
1514 if_link->supported_caps |= QED_LM_50000baseKR2_Full_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001515 if (link_caps.speed_capabilities &
Yuval Mintz351a4ded2016-06-02 10:23:29 +03001516 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_BB_100G)
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001517 if_link->supported_caps |= QED_LM_100000baseKR4_Full_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001518
1519 if (link.link_up)
1520 if_link->speed = link.speed;
1521
1522 /* TODO - fill duplex properly */
1523 if_link->duplex = DUPLEX_FULL;
1524 qed_mcp_get_media_type(hwfn->cdev, &media_type);
1525 if_link->port = qed_get_port_type(media_type);
1526
1527 if_link->autoneg = params.speed.autoneg;
1528
1529 if (params.pause.autoneg)
1530 if_link->pause_config |= QED_LINK_PAUSE_AUTONEG_ENABLE;
1531 if (params.pause.forced_rx)
1532 if_link->pause_config |= QED_LINK_PAUSE_RX_ENABLE;
1533 if (params.pause.forced_tx)
1534 if_link->pause_config |= QED_LINK_PAUSE_TX_ENABLE;
1535
1536 /* Link partner capabilities */
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001537 if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_1G_HD)
1538 if_link->lp_caps |= QED_LM_1000baseT_Half_BIT;
1539 if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_1G_FD)
1540 if_link->lp_caps |= QED_LM_1000baseT_Full_BIT;
1541 if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_10G)
1542 if_link->lp_caps |= QED_LM_10000baseKR_Full_BIT;
1543 if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_25G)
1544 if_link->lp_caps |= QED_LM_25000baseKR_Full_BIT;
1545 if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_40G)
1546 if_link->lp_caps |= QED_LM_40000baseLR4_Full_BIT;
1547 if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_50G)
1548 if_link->lp_caps |= QED_LM_50000baseKR2_Full_BIT;
1549 if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_100G)
1550 if_link->lp_caps |= QED_LM_100000baseKR4_Full_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001551
1552 if (link.an_complete)
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001553 if_link->lp_caps |= QED_LM_Autoneg_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001554
1555 if (link.partner_adv_pause)
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001556 if_link->lp_caps |= QED_LM_Pause_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001557 if (link.partner_adv_pause == QED_LINK_PARTNER_ASYMMETRIC_PAUSE ||
1558 link.partner_adv_pause == QED_LINK_PARTNER_BOTH_PAUSE)
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001559 if_link->lp_caps |= QED_LM_Asym_Pause_BIT;
Sudarsana Reddy Kalluru645874e2017-07-26 06:07:11 -07001560
1561 if (link_caps.default_eee == QED_MCP_EEE_UNSUPPORTED) {
1562 if_link->eee_supported = false;
1563 } else {
1564 if_link->eee_supported = true;
1565 if_link->eee_active = link.eee_active;
1566 if_link->sup_caps = link_caps.eee_speed_caps;
1567 /* MFW clears adv_caps on eee disable; use configured value */
1568 if_link->eee.adv_caps = link.eee_adv_caps ? link.eee_adv_caps :
1569 params.eee.adv_caps;
1570 if_link->eee.lp_adv_caps = link.eee_lp_adv_caps;
1571 if_link->eee.enable = params.eee.enable;
1572 if_link->eee.tx_lpi_enable = params.eee.tx_lpi_enable;
1573 if_link->eee.tx_lpi_timer = params.eee.tx_lpi_timer;
1574 }
Yuval Mintzcc875c22015-10-26 11:02:31 +02001575}
1576
1577static void qed_get_current_link(struct qed_dev *cdev,
1578 struct qed_link_output *if_link)
1579{
Yuval Mintz36558c32016-05-11 16:36:17 +03001580 int i;
1581
Yuval Mintzcc875c22015-10-26 11:02:31 +02001582 qed_fill_link(&cdev->hwfns[0], if_link);
Yuval Mintz36558c32016-05-11 16:36:17 +03001583
1584 for_each_hwfn(cdev, i)
1585 qed_inform_vf_link_state(&cdev->hwfns[i]);
Yuval Mintzcc875c22015-10-26 11:02:31 +02001586}
1587
1588void qed_link_update(struct qed_hwfn *hwfn)
1589{
1590 void *cookie = hwfn->cdev->ops_cookie;
1591 struct qed_common_cb_ops *op = hwfn->cdev->protocol_ops.common;
1592 struct qed_link_output if_link;
1593
1594 qed_fill_link(hwfn, &if_link);
Yuval Mintz36558c32016-05-11 16:36:17 +03001595 qed_inform_vf_link_state(hwfn);
Yuval Mintzcc875c22015-10-26 11:02:31 +02001596
1597 if (IS_LEAD_HWFN(hwfn) && cookie)
1598 op->link_update(cookie, &if_link);
1599}
1600
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001601static int qed_drain(struct qed_dev *cdev)
1602{
1603 struct qed_hwfn *hwfn;
1604 struct qed_ptt *ptt;
1605 int i, rc;
1606
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001607 if (IS_VF(cdev))
1608 return 0;
1609
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001610 for_each_hwfn(cdev, i) {
1611 hwfn = &cdev->hwfns[i];
1612 ptt = qed_ptt_acquire(hwfn);
1613 if (!ptt) {
1614 DP_NOTICE(hwfn, "Failed to drain NIG; No PTT\n");
1615 return -EBUSY;
1616 }
1617 rc = qed_mcp_drain(hwfn, ptt);
1618 if (rc)
1619 return rc;
1620 qed_ptt_release(hwfn, ptt);
1621 }
1622
1623 return 0;
1624}
1625
Sudarsana Reddy Kalluru3a69cae2018-03-28 05:14:22 -07001626static u32 qed_nvm_flash_image_access_crc(struct qed_dev *cdev,
1627 struct qed_nvm_image_att *nvm_image,
1628 u32 *crc)
1629{
1630 u8 *buf = NULL;
1631 int rc, j;
1632 u32 val;
1633
1634 /* Allocate a buffer for holding the nvram image */
1635 buf = kzalloc(nvm_image->length, GFP_KERNEL);
1636 if (!buf)
1637 return -ENOMEM;
1638
1639 /* Read image into buffer */
1640 rc = qed_mcp_nvm_read(cdev, nvm_image->start_addr,
1641 buf, nvm_image->length);
1642 if (rc) {
1643 DP_ERR(cdev, "Failed reading image from nvm\n");
1644 goto out;
1645 }
1646
1647 /* Convert the buffer into big-endian format (excluding the
1648 * closing 4 bytes of CRC).
1649 */
1650 for (j = 0; j < nvm_image->length - 4; j += 4) {
1651 val = cpu_to_be32(*(u32 *)&buf[j]);
1652 *(u32 *)&buf[j] = val;
1653 }
1654
1655 /* Calc CRC for the "actual" image buffer, i.e. not including
1656 * the last 4 CRC bytes.
1657 */
1658 *crc = (~cpu_to_be32(crc32(0xffffffff, buf, nvm_image->length - 4)));
1659
1660out:
1661 kfree(buf);
1662
1663 return rc;
1664}
1665
1666/* Binary file format -
1667 * /----------------------------------------------------------------------\
1668 * 0B | 0x4 [command index] |
1669 * 4B | image_type | Options | Number of register settings |
1670 * 8B | Value |
1671 * 12B | Mask |
1672 * 16B | Offset |
1673 * \----------------------------------------------------------------------/
1674 * There can be several Value-Mask-Offset sets as specified by 'Number of...'.
1675 * Options - 0'b - Calculate & Update CRC for image
1676 */
1677static int qed_nvm_flash_image_access(struct qed_dev *cdev, const u8 **data,
1678 bool *check_resp)
1679{
1680 struct qed_nvm_image_att nvm_image;
1681 struct qed_hwfn *p_hwfn;
1682 bool is_crc = false;
1683 u32 image_type;
1684 int rc = 0, i;
1685 u16 len;
1686
1687 *data += 4;
1688 image_type = **data;
1689 p_hwfn = QED_LEADING_HWFN(cdev);
1690 for (i = 0; i < p_hwfn->nvm_info.num_images; i++)
1691 if (image_type == p_hwfn->nvm_info.image_att[i].image_type)
1692 break;
1693 if (i == p_hwfn->nvm_info.num_images) {
1694 DP_ERR(cdev, "Failed to find nvram image of type %08x\n",
1695 image_type);
1696 return -ENOENT;
1697 }
1698
1699 nvm_image.start_addr = p_hwfn->nvm_info.image_att[i].nvm_start_addr;
1700 nvm_image.length = p_hwfn->nvm_info.image_att[i].len;
1701
1702 DP_VERBOSE(cdev, NETIF_MSG_DRV,
1703 "Read image %02x; type = %08x; NVM [%08x,...,%08x]\n",
1704 **data, image_type, nvm_image.start_addr,
1705 nvm_image.start_addr + nvm_image.length - 1);
1706 (*data)++;
1707 is_crc = !!(**data & BIT(0));
1708 (*data)++;
1709 len = *((u16 *)*data);
1710 *data += 2;
1711 if (is_crc) {
1712 u32 crc = 0;
1713
1714 rc = qed_nvm_flash_image_access_crc(cdev, &nvm_image, &crc);
1715 if (rc) {
1716 DP_ERR(cdev, "Failed calculating CRC, rc = %d\n", rc);
1717 goto exit;
1718 }
1719
1720 rc = qed_mcp_nvm_write(cdev, QED_NVM_WRITE_NVRAM,
1721 (nvm_image.start_addr +
1722 nvm_image.length - 4), (u8 *)&crc, 4);
1723 if (rc)
1724 DP_ERR(cdev, "Failed writing to %08x, rc = %d\n",
1725 nvm_image.start_addr + nvm_image.length - 4, rc);
1726 goto exit;
1727 }
1728
1729 /* Iterate over the values for setting */
1730 while (len) {
1731 u32 offset, mask, value, cur_value;
1732 u8 buf[4];
1733
1734 value = *((u32 *)*data);
1735 *data += 4;
1736 mask = *((u32 *)*data);
1737 *data += 4;
1738 offset = *((u32 *)*data);
1739 *data += 4;
1740
1741 rc = qed_mcp_nvm_read(cdev, nvm_image.start_addr + offset, buf,
1742 4);
1743 if (rc) {
1744 DP_ERR(cdev, "Failed reading from %08x\n",
1745 nvm_image.start_addr + offset);
1746 goto exit;
1747 }
1748
1749 cur_value = le32_to_cpu(*((__le32 *)buf));
1750 DP_VERBOSE(cdev, NETIF_MSG_DRV,
1751 "NVM %08x: %08x -> %08x [Value %08x Mask %08x]\n",
1752 nvm_image.start_addr + offset, cur_value,
1753 (cur_value & ~mask) | (value & mask), value, mask);
1754 value = (value & mask) | (cur_value & ~mask);
1755 rc = qed_mcp_nvm_write(cdev, QED_NVM_WRITE_NVRAM,
1756 nvm_image.start_addr + offset,
1757 (u8 *)&value, 4);
1758 if (rc) {
1759 DP_ERR(cdev, "Failed writing to %08x\n",
1760 nvm_image.start_addr + offset);
1761 goto exit;
1762 }
1763
1764 len--;
1765 }
1766exit:
1767 return rc;
1768}
1769
1770/* Binary file format -
1771 * /----------------------------------------------------------------------\
1772 * 0B | 0x3 [command index] |
1773 * 4B | b'0: check_response? | b'1-31 reserved |
1774 * 8B | File-type | reserved |
1775 * \----------------------------------------------------------------------/
1776 * Start a new file of the provided type
1777 */
1778static int qed_nvm_flash_image_file_start(struct qed_dev *cdev,
1779 const u8 **data, bool *check_resp)
1780{
1781 int rc;
1782
1783 *data += 4;
1784 *check_resp = !!(**data & BIT(0));
1785 *data += 4;
1786
1787 DP_VERBOSE(cdev, NETIF_MSG_DRV,
1788 "About to start a new file of type %02x\n", **data);
1789 rc = qed_mcp_nvm_put_file_begin(cdev, **data);
1790 *data += 4;
1791
1792 return rc;
1793}
1794
1795/* Binary file format -
1796 * /----------------------------------------------------------------------\
1797 * 0B | 0x2 [command index] |
1798 * 4B | Length in bytes |
1799 * 8B | b'0: check_response? | b'1-31 reserved |
1800 * 12B | Offset in bytes |
1801 * 16B | Data ... |
1802 * \----------------------------------------------------------------------/
1803 * Write data as part of a file that was previously started. Data should be
1804 * of length equal to that provided in the message
1805 */
1806static int qed_nvm_flash_image_file_data(struct qed_dev *cdev,
1807 const u8 **data, bool *check_resp)
1808{
1809 u32 offset, len;
1810 int rc;
1811
1812 *data += 4;
1813 len = *((u32 *)(*data));
1814 *data += 4;
1815 *check_resp = !!(**data & BIT(0));
1816 *data += 4;
1817 offset = *((u32 *)(*data));
1818 *data += 4;
1819
1820 DP_VERBOSE(cdev, NETIF_MSG_DRV,
1821 "About to write File-data: %08x bytes to offset %08x\n",
1822 len, offset);
1823
1824 rc = qed_mcp_nvm_write(cdev, QED_PUT_FILE_DATA, offset,
1825 (char *)(*data), len);
1826 *data += len;
1827
1828 return rc;
1829}
1830
1831/* Binary file format [General header] -
1832 * /----------------------------------------------------------------------\
1833 * 0B | QED_NVM_SIGNATURE |
1834 * 4B | Length in bytes |
1835 * 8B | Highest command in this batchfile | Reserved |
1836 * \----------------------------------------------------------------------/
1837 */
1838static int qed_nvm_flash_image_validate(struct qed_dev *cdev,
1839 const struct firmware *image,
1840 const u8 **data)
1841{
1842 u32 signature, len;
1843
1844 /* Check minimum size */
1845 if (image->size < 12) {
1846 DP_ERR(cdev, "Image is too short [%08x]\n", (u32)image->size);
1847 return -EINVAL;
1848 }
1849
1850 /* Check signature */
1851 signature = *((u32 *)(*data));
1852 if (signature != QED_NVM_SIGNATURE) {
1853 DP_ERR(cdev, "Wrong signature '%08x'\n", signature);
1854 return -EINVAL;
1855 }
1856
1857 *data += 4;
1858 /* Validate internal size equals the image-size */
1859 len = *((u32 *)(*data));
1860 if (len != image->size) {
1861 DP_ERR(cdev, "Size mismatch: internal = %08x image = %08x\n",
1862 len, (u32)image->size);
1863 return -EINVAL;
1864 }
1865
1866 *data += 4;
1867 /* Make sure driver familiar with all commands necessary for this */
1868 if (*((u16 *)(*data)) >= QED_NVM_FLASH_CMD_NVM_MAX) {
1869 DP_ERR(cdev, "File contains unsupported commands [Need %04x]\n",
1870 *((u16 *)(*data)));
1871 return -EINVAL;
1872 }
1873
1874 *data += 4;
1875
1876 return 0;
1877}
1878
1879static int qed_nvm_flash(struct qed_dev *cdev, const char *name)
1880{
1881 const struct firmware *image;
1882 const u8 *data, *data_end;
1883 u32 cmd_type;
1884 int rc;
1885
1886 rc = request_firmware(&image, name, &cdev->pdev->dev);
1887 if (rc) {
1888 DP_ERR(cdev, "Failed to find '%s'\n", name);
1889 return rc;
1890 }
1891
1892 DP_VERBOSE(cdev, NETIF_MSG_DRV,
1893 "Flashing '%s' - firmware's data at %p, size is %08x\n",
1894 name, image->data, (u32)image->size);
1895 data = image->data;
1896 data_end = data + image->size;
1897
1898 rc = qed_nvm_flash_image_validate(cdev, image, &data);
1899 if (rc)
1900 goto exit;
1901
1902 while (data < data_end) {
1903 bool check_resp = false;
1904
1905 /* Parse the actual command */
1906 cmd_type = *((u32 *)data);
1907 switch (cmd_type) {
1908 case QED_NVM_FLASH_CMD_FILE_DATA:
1909 rc = qed_nvm_flash_image_file_data(cdev, &data,
1910 &check_resp);
1911 break;
1912 case QED_NVM_FLASH_CMD_FILE_START:
1913 rc = qed_nvm_flash_image_file_start(cdev, &data,
1914 &check_resp);
1915 break;
1916 case QED_NVM_FLASH_CMD_NVM_CHANGE:
1917 rc = qed_nvm_flash_image_access(cdev, &data,
1918 &check_resp);
1919 break;
1920 default:
1921 DP_ERR(cdev, "Unknown command %08x\n", cmd_type);
1922 rc = -EINVAL;
1923 goto exit;
1924 }
1925
1926 if (rc) {
1927 DP_ERR(cdev, "Command %08x failed\n", cmd_type);
1928 goto exit;
1929 }
1930
1931 /* Check response if needed */
1932 if (check_resp) {
1933 u32 mcp_response = 0;
1934
1935 if (qed_mcp_nvm_resp(cdev, (u8 *)&mcp_response)) {
1936 DP_ERR(cdev, "Failed getting MCP response\n");
1937 rc = -EINVAL;
1938 goto exit;
1939 }
1940
1941 switch (mcp_response & FW_MSG_CODE_MASK) {
1942 case FW_MSG_CODE_OK:
1943 case FW_MSG_CODE_NVM_OK:
1944 case FW_MSG_CODE_NVM_PUT_FILE_FINISH_OK:
1945 case FW_MSG_CODE_PHY_OK:
1946 break;
1947 default:
1948 DP_ERR(cdev, "MFW returns error: %08x\n",
1949 mcp_response);
1950 rc = -EINVAL;
1951 goto exit;
1952 }
1953 }
1954 }
1955
1956exit:
1957 release_firmware(image);
1958
1959 return rc;
1960}
1961
Mintz, Yuval20675b32017-06-02 08:58:32 +03001962static int qed_nvm_get_image(struct qed_dev *cdev, enum qed_nvm_images type,
1963 u8 *buf, u16 len)
1964{
1965 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
Mintz, Yuval20675b32017-06-02 08:58:32 +03001966
Denis Bolotinb60bfdf2018-04-23 14:56:04 +03001967 return qed_mcp_get_nvm_image(hwfn, type, buf, len);
Mintz, Yuval20675b32017-06-02 08:58:32 +03001968}
1969
Sudarsana Reddy Kalluru722003a2016-06-21 09:36:21 -04001970static int qed_set_coalesce(struct qed_dev *cdev, u16 rx_coal, u16 tx_coal,
Rahul Verma477f2d12017-07-26 06:07:13 -07001971 void *handle)
Sudarsana Reddy Kalluru722003a2016-06-21 09:36:21 -04001972{
Rahul Verma477f2d12017-07-26 06:07:13 -07001973 return qed_set_queue_coalesce(rx_coal, tx_coal, handle);
Sudarsana Reddy Kalluru722003a2016-06-21 09:36:21 -04001974}
1975
Sudarsana Kalluru91420b82015-11-30 12:25:03 +02001976static int qed_set_led(struct qed_dev *cdev, enum qed_led_mode mode)
1977{
1978 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1979 struct qed_ptt *ptt;
1980 int status = 0;
1981
1982 ptt = qed_ptt_acquire(hwfn);
1983 if (!ptt)
1984 return -EAGAIN;
1985
1986 status = qed_mcp_set_led(hwfn, ptt, mode);
1987
1988 qed_ptt_release(hwfn, ptt);
1989
1990 return status;
1991}
1992
Mintz, Yuval14d39642016-10-31 07:14:23 +02001993static int qed_update_wol(struct qed_dev *cdev, bool enabled)
1994{
1995 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1996 struct qed_ptt *ptt;
1997 int rc = 0;
1998
1999 if (IS_VF(cdev))
2000 return 0;
2001
2002 ptt = qed_ptt_acquire(hwfn);
2003 if (!ptt)
2004 return -EAGAIN;
2005
2006 rc = qed_mcp_ov_update_wol(hwfn, ptt, enabled ? QED_OV_WOL_ENABLED
2007 : QED_OV_WOL_DISABLED);
2008 if (rc)
2009 goto out;
2010 rc = qed_mcp_ov_update_current_config(hwfn, ptt, QED_OV_CLIENT_DRV);
2011
2012out:
2013 qed_ptt_release(hwfn, ptt);
2014 return rc;
2015}
2016
Sudarsana Kalluru0fefbfb2016-10-31 07:14:21 +02002017static int qed_update_drv_state(struct qed_dev *cdev, bool active)
2018{
2019 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2020 struct qed_ptt *ptt;
2021 int status = 0;
2022
2023 if (IS_VF(cdev))
2024 return 0;
2025
2026 ptt = qed_ptt_acquire(hwfn);
2027 if (!ptt)
2028 return -EAGAIN;
2029
2030 status = qed_mcp_ov_update_driver_state(hwfn, ptt, active ?
2031 QED_OV_DRIVER_STATE_ACTIVE :
2032 QED_OV_DRIVER_STATE_DISABLED);
2033
2034 qed_ptt_release(hwfn, ptt);
2035
2036 return status;
2037}
2038
2039static int qed_update_mac(struct qed_dev *cdev, u8 *mac)
2040{
2041 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2042 struct qed_ptt *ptt;
2043 int status = 0;
2044
2045 if (IS_VF(cdev))
2046 return 0;
2047
2048 ptt = qed_ptt_acquire(hwfn);
2049 if (!ptt)
2050 return -EAGAIN;
2051
2052 status = qed_mcp_ov_update_mac(hwfn, ptt, mac);
2053 if (status)
2054 goto out;
2055
2056 status = qed_mcp_ov_update_current_config(hwfn, ptt, QED_OV_CLIENT_DRV);
2057
2058out:
2059 qed_ptt_release(hwfn, ptt);
2060 return status;
2061}
2062
2063static int qed_update_mtu(struct qed_dev *cdev, u16 mtu)
2064{
2065 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2066 struct qed_ptt *ptt;
2067 int status = 0;
2068
2069 if (IS_VF(cdev))
2070 return 0;
2071
2072 ptt = qed_ptt_acquire(hwfn);
2073 if (!ptt)
2074 return -EAGAIN;
2075
2076 status = qed_mcp_ov_update_mtu(hwfn, ptt, mtu);
2077 if (status)
2078 goto out;
2079
2080 status = qed_mcp_ov_update_current_config(hwfn, ptt, QED_OV_CLIENT_DRV);
2081
2082out:
2083 qed_ptt_release(hwfn, ptt);
2084 return status;
2085}
2086
Yuval Mintz8c93bea2016-10-13 22:57:03 +03002087static struct qed_selftest_ops qed_selftest_ops_pass = {
Sudarsana Reddy Kalluru03dc76c2016-04-28 20:20:52 -04002088 .selftest_memory = &qed_selftest_memory,
2089 .selftest_interrupt = &qed_selftest_interrupt,
2090 .selftest_register = &qed_selftest_register,
2091 .selftest_clock = &qed_selftest_clock,
Mintz, Yuval7a4b21b2016-10-31 07:14:22 +02002092 .selftest_nvram = &qed_selftest_nvram,
Sudarsana Reddy Kalluru03dc76c2016-04-28 20:20:52 -04002093};
2094
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002095const struct qed_common_ops qed_common_ops_pass = {
Sudarsana Reddy Kalluru03dc76c2016-04-28 20:20:52 -04002096 .selftest = &qed_selftest_ops_pass,
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002097 .probe = &qed_probe,
2098 .remove = &qed_remove,
2099 .set_power_state = &qed_set_power_state,
Mintz, Yuval712c3cb2017-05-23 09:41:28 +03002100 .set_name = &qed_set_name,
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002101 .update_pf_params = &qed_update_pf_params,
2102 .slowpath_start = &qed_slowpath_start,
2103 .slowpath_stop = &qed_slowpath_stop,
2104 .set_fp_int = &qed_set_int_fp,
2105 .get_fp_int = &qed_get_int_fp,
2106 .sb_init = &qed_sb_init,
2107 .sb_release = &qed_sb_release,
2108 .simd_handler_config = &qed_simd_handler_config,
2109 .simd_handler_clean = &qed_simd_handler_clean,
Arun Easi1e128c82017-02-15 06:28:22 -08002110 .dbg_grc = &qed_dbg_grc,
2111 .dbg_grc_size = &qed_dbg_grc_size,
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +03002112 .can_link_change = &qed_can_link_change,
Yuval Mintzcc875c22015-10-26 11:02:31 +02002113 .set_link = &qed_set_link,
2114 .get_link = &qed_get_current_link,
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002115 .drain = &qed_drain,
2116 .update_msglvl = &qed_init_dp,
Tomer Tayare0971c82016-09-07 16:36:25 +03002117 .dbg_all_data = &qed_dbg_all_data,
2118 .dbg_all_data_size = &qed_dbg_all_data_size,
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002119 .chain_alloc = &qed_chain_alloc,
2120 .chain_free = &qed_chain_free,
Sudarsana Reddy Kalluru3a69cae2018-03-28 05:14:22 -07002121 .nvm_flash = &qed_nvm_flash,
Mintz, Yuval20675b32017-06-02 08:58:32 +03002122 .nvm_get_image = &qed_nvm_get_image,
Sudarsana Reddy Kalluru722003a2016-06-21 09:36:21 -04002123 .set_coalesce = &qed_set_coalesce,
Sudarsana Kalluru91420b82015-11-30 12:25:03 +02002124 .set_led = &qed_set_led,
Sudarsana Kalluru0fefbfb2016-10-31 07:14:21 +02002125 .update_drv_state = &qed_update_drv_state,
2126 .update_mac = &qed_update_mac,
2127 .update_mtu = &qed_update_mtu,
Mintz, Yuval14d39642016-10-31 07:14:23 +02002128 .update_wol = &qed_update_wol,
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002129};
Sudarsana Reddy Kalluru6c754242016-08-16 10:51:03 -04002130
2131void qed_get_protocol_stats(struct qed_dev *cdev,
2132 enum qed_mcp_protocol_type type,
2133 union qed_mcp_protocol_stats *stats)
2134{
2135 struct qed_eth_stats eth_stats;
2136
2137 memset(stats, 0, sizeof(*stats));
2138
2139 switch (type) {
2140 case QED_MCP_LAN_STATS:
2141 qed_get_vport_stats(cdev, &eth_stats);
Mintz, Yuval9c79dda2017-03-14 16:23:54 +02002142 stats->lan_stats.ucast_rx_pkts =
2143 eth_stats.common.rx_ucast_pkts;
2144 stats->lan_stats.ucast_tx_pkts =
2145 eth_stats.common.tx_ucast_pkts;
Sudarsana Reddy Kalluru6c754242016-08-16 10:51:03 -04002146 stats->lan_stats.fcs_err = -1;
2147 break;
Arun Easi1e128c82017-02-15 06:28:22 -08002148 case QED_MCP_FCOE_STATS:
2149 qed_get_protocol_stats_fcoe(cdev, &stats->fcoe_stats);
2150 break;
Mintz, Yuval2f2b2612017-04-06 15:58:34 +03002151 case QED_MCP_ISCSI_STATS:
2152 qed_get_protocol_stats_iscsi(cdev, &stats->iscsi_stats);
2153 break;
Sudarsana Reddy Kalluru6c754242016-08-16 10:51:03 -04002154 default:
Mintz, Yuval512c7842017-05-29 11:24:49 +03002155 DP_VERBOSE(cdev, QED_MSG_SP,
2156 "Invalid protocol type = %d\n", type);
Sudarsana Reddy Kalluru6c754242016-08-16 10:51:03 -04002157 return;
2158 }
2159}
Sudarsana Reddy Kalluru2528c382018-05-22 00:28:38 -07002160
Sudarsana Reddy Kalluru59ccf862018-05-22 00:28:41 -07002161int qed_mfw_tlv_req(struct qed_hwfn *hwfn)
2162{
2163 DP_VERBOSE(hwfn->cdev, NETIF_MSG_DRV,
2164 "Scheduling slowpath task [Flag: %d]\n",
2165 QED_SLOWPATH_MFW_TLV_REQ);
2166 smp_mb__before_atomic();
2167 set_bit(QED_SLOWPATH_MFW_TLV_REQ, &hwfn->slowpath_task_flags);
2168 smp_mb__after_atomic();
2169 queue_delayed_work(hwfn->slowpath_wq, &hwfn->slowpath_task, 0);
2170
2171 return 0;
2172}
2173
2174static void
2175qed_fill_generic_tlv_data(struct qed_dev *cdev, struct qed_mfw_tlv_generic *tlv)
2176{
2177 struct qed_common_cb_ops *op = cdev->protocol_ops.common;
2178 struct qed_eth_stats_common *p_common;
2179 struct qed_generic_tlvs gen_tlvs;
2180 struct qed_eth_stats stats;
2181 int i;
2182
2183 memset(&gen_tlvs, 0, sizeof(gen_tlvs));
2184 op->get_generic_tlv_data(cdev->ops_cookie, &gen_tlvs);
2185
2186 if (gen_tlvs.feat_flags & QED_TLV_IP_CSUM)
2187 tlv->flags.ipv4_csum_offload = true;
2188 if (gen_tlvs.feat_flags & QED_TLV_LSO)
2189 tlv->flags.lso_supported = true;
2190 tlv->flags.b_set = true;
2191
2192 for (i = 0; i < QED_TLV_MAC_COUNT; i++) {
2193 if (is_valid_ether_addr(gen_tlvs.mac[i])) {
2194 ether_addr_copy(tlv->mac[i], gen_tlvs.mac[i]);
2195 tlv->mac_set[i] = true;
2196 }
2197 }
2198
2199 qed_get_vport_stats(cdev, &stats);
2200 p_common = &stats.common;
2201 tlv->rx_frames = p_common->rx_ucast_pkts + p_common->rx_mcast_pkts +
2202 p_common->rx_bcast_pkts;
2203 tlv->rx_frames_set = true;
2204 tlv->rx_bytes = p_common->rx_ucast_bytes + p_common->rx_mcast_bytes +
2205 p_common->rx_bcast_bytes;
2206 tlv->rx_bytes_set = true;
2207 tlv->tx_frames = p_common->tx_ucast_pkts + p_common->tx_mcast_pkts +
2208 p_common->tx_bcast_pkts;
2209 tlv->tx_frames_set = true;
2210 tlv->tx_bytes = p_common->tx_ucast_bytes + p_common->tx_mcast_bytes +
2211 p_common->tx_bcast_bytes;
2212 tlv->rx_bytes_set = true;
2213}
2214
Sudarsana Reddy Kalluru2528c382018-05-22 00:28:38 -07002215int qed_mfw_fill_tlv_data(struct qed_hwfn *hwfn, enum qed_mfw_tlv_type type,
2216 union qed_mfw_tlv_data *tlv_buf)
2217{
Sudarsana Reddy Kalluru59ccf862018-05-22 00:28:41 -07002218 struct qed_dev *cdev = hwfn->cdev;
2219 struct qed_common_cb_ops *ops;
2220
2221 ops = cdev->protocol_ops.common;
2222 if (!ops || !ops->get_protocol_tlv_data || !ops->get_generic_tlv_data) {
2223 DP_NOTICE(hwfn, "Can't collect TLV management info\n");
2224 return -EINVAL;
2225 }
2226
2227 switch (type) {
2228 case QED_MFW_TLV_GENERIC:
2229 qed_fill_generic_tlv_data(hwfn->cdev, &tlv_buf->generic);
2230 break;
2231 case QED_MFW_TLV_ETH:
2232 ops->get_protocol_tlv_data(cdev->ops_cookie, &tlv_buf->eth);
2233 break;
2234 case QED_MFW_TLV_FCOE:
2235 ops->get_protocol_tlv_data(cdev->ops_cookie, &tlv_buf->fcoe);
2236 break;
2237 case QED_MFW_TLV_ISCSI:
2238 ops->get_protocol_tlv_data(cdev->ops_cookie, &tlv_buf->iscsi);
2239 break;
2240 default:
2241 break;
2242 }
2243
2244 return 0;
Sudarsana Reddy Kalluru2528c382018-05-22 00:28:38 -07002245}