blob: 029f431e89ecaa01343c8b4ae523f64ec38fffde [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>
37#include <linux/version.h>
38#include <linux/delay.h>
39#include <asm/byteorder.h>
40#include <linux/dma-mapping.h>
41#include <linux/string.h>
42#include <linux/module.h>
43#include <linux/interrupt.h>
44#include <linux/workqueue.h>
45#include <linux/ethtool.h>
46#include <linux/etherdevice.h>
47#include <linux/vmalloc.h>
Tomer Tayar5d24bcf2017-03-28 15:12:52 +030048#include <linux/crash_dump.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
126 if (cdev->doorbells)
127 iounmap(cdev->doorbells);
128 if (cdev->regview)
129 iounmap(cdev->regview);
130 if (atomic_read(&pdev->enable_cnt) == 1)
131 pci_release_regions(pdev);
132
133 pci_disable_device(pdev);
134}
135
Yuval 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
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300210 if (IS_PF(cdev)) {
Dan Carpenterf82731b2016-05-17 11:09:20 +0300211 cdev->db_phys_addr = pci_resource_start(cdev->pdev, 2);
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300212 cdev->db_size = pci_resource_len(cdev->pdev, 2);
213 cdev->doorbells = ioremap_wc(cdev->db_phys_addr, cdev->db_size);
214 if (!cdev->doorbells) {
215 DP_NOTICE(cdev, "Cannot map doorbell space\n");
216 return -ENOMEM;
217 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200218 }
219
220 return 0;
221
222err2:
223 pci_release_regions(pdev);
224err1:
225 pci_disable_device(pdev);
226err0:
227 return rc;
228}
229
230int qed_fill_dev_info(struct qed_dev *cdev,
231 struct qed_dev_info *dev_info)
232{
Manish Chopracee4d262015-10-26 11:02:28 +0200233 struct qed_ptt *ptt;
234
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200235 memset(dev_info, 0, sizeof(struct qed_dev_info));
236
237 dev_info->num_hwfns = cdev->num_hwfns;
238 dev_info->pci_mem_start = cdev->pci_params.mem_start;
239 dev_info->pci_mem_end = cdev->pci_params.mem_end;
240 dev_info->pci_irq = cdev->pci_params.irq;
Ram Amrani51ff1722016-10-01 21:59:57 +0300241 dev_info->rdma_supported = (cdev->hwfns[0].hw_info.personality ==
242 QED_PCI_ETH_ROCE);
Yuval Mintzfc48b7a2016-02-15 13:22:35 -0500243 dev_info->is_mf_default = IS_MF_DEFAULT(&cdev->hwfns[0]);
Mintz, Yuval9c79dda2017-03-14 16:23:54 +0200244 dev_info->dev_type = cdev->type;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200245 ether_addr_copy(dev_info->hw_mac, cdev->hwfns[0].hw_info.hw_mac_addr);
246
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300247 if (IS_PF(cdev)) {
248 dev_info->fw_major = FW_MAJOR_VERSION;
249 dev_info->fw_minor = FW_MINOR_VERSION;
250 dev_info->fw_rev = FW_REVISION_VERSION;
251 dev_info->fw_eng = FW_ENGINEERING_VERSION;
252 dev_info->mf_mode = cdev->mf_mode;
Yuval Mintz831bfb0e2016-05-11 16:36:25 +0300253 dev_info->tx_switching = true;
Mintz, Yuval14d39642016-10-31 07:14:23 +0200254
255 if (QED_LEADING_HWFN(cdev)->hw_info.b_wol_support ==
256 QED_WOL_SUPPORT_PME)
257 dev_info->wol_support = true;
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300258 } else {
259 qed_vf_get_fw_version(&cdev->hwfns[0], &dev_info->fw_major,
260 &dev_info->fw_minor, &dev_info->fw_rev,
261 &dev_info->fw_eng);
262 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200263
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300264 if (IS_PF(cdev)) {
265 ptt = qed_ptt_acquire(QED_LEADING_HWFN(cdev));
266 if (ptt) {
267 qed_mcp_get_mfw_ver(QED_LEADING_HWFN(cdev), ptt,
268 &dev_info->mfw_rev, NULL);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200269
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300270 qed_mcp_get_flash_size(QED_LEADING_HWFN(cdev), ptt,
271 &dev_info->flash_size);
Manish Chopracee4d262015-10-26 11:02:28 +0200272
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300273 qed_ptt_release(QED_LEADING_HWFN(cdev), ptt);
274 }
275 } else {
276 qed_mcp_get_mfw_ver(QED_LEADING_HWFN(cdev), NULL,
277 &dev_info->mfw_rev, NULL);
Manish Chopracee4d262015-10-26 11:02:28 +0200278 }
279
Sudarsana Kalluru0fefbfb2016-10-31 07:14:21 +0200280 dev_info->mtu = QED_LEADING_HWFN(cdev)->hw_info.mtu;
281
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200282 return 0;
283}
284
285static void qed_free_cdev(struct qed_dev *cdev)
286{
287 kfree((void *)cdev);
288}
289
290static struct qed_dev *qed_alloc_cdev(struct pci_dev *pdev)
291{
292 struct qed_dev *cdev;
293
294 cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
295 if (!cdev)
296 return cdev;
297
298 qed_init_struct(cdev);
299
300 return cdev;
301}
302
303/* Sets the requested power state */
Yuval Mintz1a635e42016-08-15 10:42:43 +0300304static int qed_set_power_state(struct qed_dev *cdev, pci_power_t state)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200305{
306 if (!cdev)
307 return -ENODEV;
308
309 DP_VERBOSE(cdev, NETIF_MSG_DRV, "Omitting Power state change\n");
310 return 0;
311}
312
313/* probing */
314static struct qed_dev *qed_probe(struct pci_dev *pdev,
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300315 struct qed_probe_params *params)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200316{
317 struct qed_dev *cdev;
318 int rc;
319
320 cdev = qed_alloc_cdev(pdev);
321 if (!cdev)
322 goto err0;
323
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300324 cdev->protocol = params->protocol;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200325
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300326 if (params->is_vf)
327 cdev->b_is_vf = true;
328
329 qed_init_dp(cdev, params->dp_module, params->dp_level);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200330
331 rc = qed_init_pci(cdev, pdev);
332 if (rc) {
333 DP_ERR(cdev, "init pci failed\n");
334 goto err1;
335 }
336 DP_INFO(cdev, "PCI init completed successfully\n");
337
338 rc = qed_hw_prepare(cdev, QED_PCI_DEFAULT);
339 if (rc) {
340 DP_ERR(cdev, "hw prepare failed\n");
341 goto err2;
342 }
343
344 DP_INFO(cdev, "qed_probe completed successffuly\n");
345
346 return cdev;
347
348err2:
349 qed_free_pci(cdev);
350err1:
351 qed_free_cdev(cdev);
352err0:
353 return NULL;
354}
355
356static void qed_remove(struct qed_dev *cdev)
357{
358 if (!cdev)
359 return;
360
361 qed_hw_remove(cdev);
362
363 qed_free_pci(cdev);
364
365 qed_set_power_state(cdev, PCI_D3hot);
366
367 qed_free_cdev(cdev);
368}
369
370static void qed_disable_msix(struct qed_dev *cdev)
371{
372 if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) {
373 pci_disable_msix(cdev->pdev);
374 kfree(cdev->int_params.msix_table);
375 } else if (cdev->int_params.out.int_mode == QED_INT_MODE_MSI) {
376 pci_disable_msi(cdev->pdev);
377 }
378
379 memset(&cdev->int_params.out, 0, sizeof(struct qed_int_param));
380}
381
382static int qed_enable_msix(struct qed_dev *cdev,
383 struct qed_int_params *int_params)
384{
385 int i, rc, cnt;
386
387 cnt = int_params->in.num_vectors;
388
389 for (i = 0; i < cnt; i++)
390 int_params->msix_table[i].entry = i;
391
392 rc = pci_enable_msix_range(cdev->pdev, int_params->msix_table,
393 int_params->in.min_msix_cnt, cnt);
394 if (rc < cnt && rc >= int_params->in.min_msix_cnt &&
395 (rc % cdev->num_hwfns)) {
396 pci_disable_msix(cdev->pdev);
397
398 /* If fastpath is initialized, we need at least one interrupt
399 * per hwfn [and the slow path interrupts]. New requested number
400 * should be a multiple of the number of hwfns.
401 */
402 cnt = (rc / cdev->num_hwfns) * cdev->num_hwfns;
403 DP_NOTICE(cdev,
404 "Trying to enable MSI-X with less vectors (%d out of %d)\n",
405 cnt, int_params->in.num_vectors);
Yuval Mintz1a635e42016-08-15 10:42:43 +0300406 rc = pci_enable_msix_exact(cdev->pdev, int_params->msix_table,
407 cnt);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200408 if (!rc)
409 rc = cnt;
410 }
411
412 if (rc > 0) {
413 /* MSI-x configuration was achieved */
414 int_params->out.int_mode = QED_INT_MODE_MSIX;
415 int_params->out.num_vectors = rc;
416 rc = 0;
417 } else {
418 DP_NOTICE(cdev,
419 "Failed to enable MSI-X [Requested %d vectors][rc %d]\n",
420 cnt, rc);
421 }
422
423 return rc;
424}
425
426/* This function outputs the int mode and the number of enabled msix vector */
427static int qed_set_int_mode(struct qed_dev *cdev, bool force_mode)
428{
429 struct qed_int_params *int_params = &cdev->int_params;
430 struct msix_entry *tbl;
431 int rc = 0, cnt;
432
433 switch (int_params->in.int_mode) {
434 case QED_INT_MODE_MSIX:
435 /* Allocate MSIX table */
436 cnt = int_params->in.num_vectors;
437 int_params->msix_table = kcalloc(cnt, sizeof(*tbl), GFP_KERNEL);
438 if (!int_params->msix_table) {
439 rc = -ENOMEM;
440 goto out;
441 }
442
443 /* Enable MSIX */
444 rc = qed_enable_msix(cdev, int_params);
445 if (!rc)
446 goto out;
447
448 DP_NOTICE(cdev, "Failed to enable MSI-X\n");
449 kfree(int_params->msix_table);
450 if (force_mode)
451 goto out;
452 /* Fallthrough */
453
454 case QED_INT_MODE_MSI:
Sudarsana Reddy Kallurubb13ace2016-05-26 11:01:23 +0300455 if (cdev->num_hwfns == 1) {
456 rc = pci_enable_msi(cdev->pdev);
457 if (!rc) {
458 int_params->out.int_mode = QED_INT_MODE_MSI;
459 goto out;
460 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200461
Sudarsana Reddy Kallurubb13ace2016-05-26 11:01:23 +0300462 DP_NOTICE(cdev, "Failed to enable MSI\n");
463 if (force_mode)
464 goto out;
465 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200466 /* Fallthrough */
467
468 case QED_INT_MODE_INTA:
469 int_params->out.int_mode = QED_INT_MODE_INTA;
470 rc = 0;
471 goto out;
472 default:
473 DP_NOTICE(cdev, "Unknown int_mode value %d\n",
474 int_params->in.int_mode);
475 rc = -EINVAL;
476 }
477
478out:
Yuval Mintz525ef5c2016-08-15 10:42:45 +0300479 if (!rc)
480 DP_INFO(cdev, "Using %s interrupts\n",
481 int_params->out.int_mode == QED_INT_MODE_INTA ?
482 "INTa" : int_params->out.int_mode == QED_INT_MODE_MSI ?
483 "MSI" : "MSIX");
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200484 cdev->int_coalescing_mode = QED_COAL_MODE_ENABLE;
485
486 return rc;
487}
488
489static void qed_simd_handler_config(struct qed_dev *cdev, void *token,
490 int index, void(*handler)(void *))
491{
492 struct qed_hwfn *hwfn = &cdev->hwfns[index % cdev->num_hwfns];
493 int relative_idx = index / cdev->num_hwfns;
494
495 hwfn->simd_proto_handler[relative_idx].func = handler;
496 hwfn->simd_proto_handler[relative_idx].token = token;
497}
498
499static void qed_simd_handler_clean(struct qed_dev *cdev, int index)
500{
501 struct qed_hwfn *hwfn = &cdev->hwfns[index % cdev->num_hwfns];
502 int relative_idx = index / cdev->num_hwfns;
503
504 memset(&hwfn->simd_proto_handler[relative_idx], 0,
505 sizeof(struct qed_simd_fp_handler));
506}
507
508static irqreturn_t qed_msix_sp_int(int irq, void *tasklet)
509{
510 tasklet_schedule((struct tasklet_struct *)tasklet);
511 return IRQ_HANDLED;
512}
513
514static irqreturn_t qed_single_int(int irq, void *dev_instance)
515{
516 struct qed_dev *cdev = (struct qed_dev *)dev_instance;
517 struct qed_hwfn *hwfn;
518 irqreturn_t rc = IRQ_NONE;
519 u64 status;
520 int i, j;
521
522 for (i = 0; i < cdev->num_hwfns; i++) {
523 status = qed_int_igu_read_sisr_reg(&cdev->hwfns[i]);
524
525 if (!status)
526 continue;
527
528 hwfn = &cdev->hwfns[i];
529
530 /* Slowpath interrupt */
531 if (unlikely(status & 0x1)) {
532 tasklet_schedule(hwfn->sp_dpc);
533 status &= ~0x1;
534 rc = IRQ_HANDLED;
535 }
536
537 /* Fastpath interrupts */
538 for (j = 0; j < 64; j++) {
539 if ((0x2ULL << j) & status) {
540 hwfn->simd_proto_handler[j].func(
541 hwfn->simd_proto_handler[j].token);
542 status &= ~(0x2ULL << j);
543 rc = IRQ_HANDLED;
544 }
545 }
546
547 if (unlikely(status))
548 DP_VERBOSE(hwfn, NETIF_MSG_INTR,
549 "got an unknown interrupt status 0x%llx\n",
550 status);
551 }
552
553 return rc;
554}
555
Sudarsana Kalluru8f16bc92015-12-07 06:25:59 -0500556int qed_slowpath_irq_req(struct qed_hwfn *hwfn)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200557{
Sudarsana Kalluru8f16bc92015-12-07 06:25:59 -0500558 struct qed_dev *cdev = hwfn->cdev;
Yuval Mintz525ef5c2016-08-15 10:42:45 +0300559 u32 int_mode;
Sudarsana Kalluru8f16bc92015-12-07 06:25:59 -0500560 int rc = 0;
561 u8 id;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200562
Yuval Mintz525ef5c2016-08-15 10:42:45 +0300563 int_mode = cdev->int_params.out.int_mode;
564 if (int_mode == QED_INT_MODE_MSIX) {
Sudarsana Kalluru8f16bc92015-12-07 06:25:59 -0500565 id = hwfn->my_id;
566 snprintf(hwfn->name, NAME_SIZE, "sp-%d-%02x:%02x.%02x",
567 id, cdev->pdev->bus->number,
568 PCI_SLOT(cdev->pdev->devfn), hwfn->abs_pf_id);
569 rc = request_irq(cdev->int_params.msix_table[id].vector,
570 qed_msix_sp_int, 0, hwfn->name, hwfn->sp_dpc);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200571 } else {
572 unsigned long flags = 0;
573
574 snprintf(cdev->name, NAME_SIZE, "%02x:%02x.%02x",
575 cdev->pdev->bus->number, PCI_SLOT(cdev->pdev->devfn),
576 PCI_FUNC(cdev->pdev->devfn));
577
578 if (cdev->int_params.out.int_mode == QED_INT_MODE_INTA)
579 flags |= IRQF_SHARED;
580
581 rc = request_irq(cdev->pdev->irq, qed_single_int,
582 flags, cdev->name, cdev);
583 }
584
Yuval Mintz525ef5c2016-08-15 10:42:45 +0300585 if (rc)
586 DP_NOTICE(cdev, "request_irq failed, rc = %d\n", rc);
587 else
588 DP_VERBOSE(hwfn, (NETIF_MSG_INTR | QED_MSG_SP),
589 "Requested slowpath %s\n",
590 (int_mode == QED_INT_MODE_MSIX) ? "MSI-X" : "IRQ");
591
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200592 return rc;
593}
594
Tomer Tayar12263372017-03-28 15:12:50 +0300595void qed_slowpath_irq_sync(struct qed_hwfn *p_hwfn)
596{
597 struct qed_dev *cdev = p_hwfn->cdev;
598 u8 id = p_hwfn->my_id;
599 u32 int_mode;
600
601 int_mode = cdev->int_params.out.int_mode;
602 if (int_mode == QED_INT_MODE_MSIX)
603 synchronize_irq(cdev->int_params.msix_table[id].vector);
604 else
605 synchronize_irq(cdev->pdev->irq);
606}
607
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200608static void qed_slowpath_irq_free(struct qed_dev *cdev)
609{
610 int i;
611
612 if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) {
613 for_each_hwfn(cdev, i) {
Sudarsana Kalluru8f16bc92015-12-07 06:25:59 -0500614 if (!cdev->hwfns[i].b_int_requested)
615 break;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200616 synchronize_irq(cdev->int_params.msix_table[i].vector);
617 free_irq(cdev->int_params.msix_table[i].vector,
618 cdev->hwfns[i].sp_dpc);
619 }
620 } else {
Sudarsana Kalluru8f16bc92015-12-07 06:25:59 -0500621 if (QED_LEADING_HWFN(cdev)->b_int_requested)
622 free_irq(cdev->pdev->irq, cdev);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200623 }
Sudarsana Kalluru8f16bc92015-12-07 06:25:59 -0500624 qed_int_disable_post_isr_release(cdev);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200625}
626
627static int qed_nic_stop(struct qed_dev *cdev)
628{
629 int i, rc;
630
631 rc = qed_hw_stop(cdev);
632
633 for (i = 0; i < cdev->num_hwfns; i++) {
634 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
635
636 if (p_hwfn->b_sp_dpc_enabled) {
637 tasklet_disable(p_hwfn->sp_dpc);
638 p_hwfn->b_sp_dpc_enabled = false;
639 DP_VERBOSE(cdev, NETIF_MSG_IFDOWN,
640 "Disabled sp taskelt [hwfn %d] at %p\n",
641 i, p_hwfn->sp_dpc);
642 }
643 }
644
Tomer Tayarc965db42016-09-07 16:36:24 +0300645 qed_dbg_pf_exit(cdev);
646
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200647 return rc;
648}
649
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200650static int qed_nic_setup(struct qed_dev *cdev)
651{
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300652 int rc, i;
653
654 /* Determine if interface is going to require LL2 */
655 if (QED_LEADING_HWFN(cdev)->hw_info.personality != QED_PCI_ETH) {
656 for (i = 0; i < cdev->num_hwfns; i++) {
657 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
658
659 p_hwfn->using_ll2 = true;
660 }
661 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200662
663 rc = qed_resc_alloc(cdev);
664 if (rc)
665 return rc;
666
667 DP_INFO(cdev, "Allocated qed resources\n");
668
669 qed_resc_setup(cdev);
670
671 return rc;
672}
673
674static int qed_set_int_fp(struct qed_dev *cdev, u16 cnt)
675{
676 int limit = 0;
677
678 /* Mark the fastpath as free/used */
679 cdev->int_params.fp_initialized = cnt ? true : false;
680
681 if (cdev->int_params.out.int_mode != QED_INT_MODE_MSIX)
682 limit = cdev->num_hwfns * 63;
683 else if (cdev->int_params.fp_msix_cnt)
684 limit = cdev->int_params.fp_msix_cnt;
685
686 if (!limit)
687 return -ENOMEM;
688
689 return min_t(int, cnt, limit);
690}
691
692static int qed_get_int_fp(struct qed_dev *cdev, struct qed_int_info *info)
693{
694 memset(info, 0, sizeof(struct qed_int_info));
695
696 if (!cdev->int_params.fp_initialized) {
697 DP_INFO(cdev,
698 "Protocol driver requested interrupt information, but its support is not yet configured\n");
699 return -EINVAL;
700 }
701
702 /* Need to expose only MSI-X information; Single IRQ is handled solely
703 * by qed.
704 */
705 if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) {
706 int msix_base = cdev->int_params.fp_msix_base;
707
708 info->msix_cnt = cdev->int_params.fp_msix_cnt;
709 info->msix = &cdev->int_params.msix_table[msix_base];
710 }
711
712 return 0;
713}
714
715static int qed_slowpath_setup_int(struct qed_dev *cdev,
716 enum qed_int_mode int_mode)
717{
Yuval Mintz4ac801b2016-02-28 12:26:52 +0200718 struct qed_sb_cnt_info sb_cnt_info;
Yuval Mintz0189efb2016-10-13 22:57:02 +0300719 int num_l2_queues = 0;
Yuval Mintz4ac801b2016-02-28 12:26:52 +0200720 int rc;
721 int i;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200722
Sudarsana Reddy Kalluru1d2c2022016-08-01 09:08:13 -0400723 if ((int_mode == QED_INT_MODE_MSI) && (cdev->num_hwfns > 1)) {
724 DP_NOTICE(cdev, "MSI mode is not supported for CMT devices\n");
725 return -EINVAL;
726 }
727
728 memset(&cdev->int_params, 0, sizeof(struct qed_int_params));
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200729 cdev->int_params.in.int_mode = int_mode;
Yuval Mintz4ac801b2016-02-28 12:26:52 +0200730 for_each_hwfn(cdev, i) {
731 memset(&sb_cnt_info, 0, sizeof(sb_cnt_info));
732 qed_int_get_num_sbs(&cdev->hwfns[i], &sb_cnt_info);
733 cdev->int_params.in.num_vectors += sb_cnt_info.sb_cnt;
734 cdev->int_params.in.num_vectors++; /* slowpath */
735 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200736
737 /* We want a minimum of one slowpath and one fastpath vector per hwfn */
738 cdev->int_params.in.min_msix_cnt = cdev->num_hwfns * 2;
739
740 rc = qed_set_int_mode(cdev, false);
741 if (rc) {
742 DP_ERR(cdev, "qed_slowpath_setup_int ERR\n");
743 return rc;
744 }
745
746 cdev->int_params.fp_msix_base = cdev->num_hwfns;
747 cdev->int_params.fp_msix_cnt = cdev->int_params.out.num_vectors -
748 cdev->num_hwfns;
749
Mintz, Yuval2f782272017-04-05 21:20:11 +0300750 if (!IS_ENABLED(CONFIG_QED_RDMA) ||
751 QED_LEADING_HWFN(cdev)->hw_info.personality != QED_PCI_ETH_ROCE)
Yuval Mintz0189efb2016-10-13 22:57:02 +0300752 return 0;
753
Ram Amrani51ff1722016-10-01 21:59:57 +0300754 for_each_hwfn(cdev, i)
755 num_l2_queues += FEAT_NUM(&cdev->hwfns[i], QED_PF_L2_QUE);
756
757 DP_VERBOSE(cdev, QED_MSG_RDMA,
758 "cdev->int_params.fp_msix_cnt=%d num_l2_queues=%d\n",
759 cdev->int_params.fp_msix_cnt, num_l2_queues);
760
761 if (cdev->int_params.fp_msix_cnt > num_l2_queues) {
762 cdev->int_params.rdma_msix_cnt =
763 (cdev->int_params.fp_msix_cnt - num_l2_queues)
764 / cdev->num_hwfns;
765 cdev->int_params.rdma_msix_base =
766 cdev->int_params.fp_msix_base + num_l2_queues;
767 cdev->int_params.fp_msix_cnt = num_l2_queues;
768 } else {
769 cdev->int_params.rdma_msix_cnt = 0;
770 }
771
772 DP_VERBOSE(cdev, QED_MSG_RDMA, "roce_msix_cnt=%d roce_msix_base=%d\n",
773 cdev->int_params.rdma_msix_cnt,
774 cdev->int_params.rdma_msix_base);
Ram Amrani51ff1722016-10-01 21:59:57 +0300775
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200776 return 0;
777}
778
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300779static int qed_slowpath_vf_setup_int(struct qed_dev *cdev)
780{
781 int rc;
782
783 memset(&cdev->int_params, 0, sizeof(struct qed_int_params));
784 cdev->int_params.in.int_mode = QED_INT_MODE_MSIX;
785
786 qed_vf_get_num_rxqs(QED_LEADING_HWFN(cdev),
787 &cdev->int_params.in.num_vectors);
788 if (cdev->num_hwfns > 1) {
789 u8 vectors = 0;
790
791 qed_vf_get_num_rxqs(&cdev->hwfns[1], &vectors);
792 cdev->int_params.in.num_vectors += vectors;
793 }
794
795 /* We want a minimum of one fastpath vector per vf hwfn */
796 cdev->int_params.in.min_msix_cnt = cdev->num_hwfns;
797
798 rc = qed_set_int_mode(cdev, true);
799 if (rc)
800 return rc;
801
802 cdev->int_params.fp_msix_base = 0;
803 cdev->int_params.fp_msix_cnt = cdev->int_params.out.num_vectors;
804
805 return 0;
806}
807
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200808u32 qed_unzip_data(struct qed_hwfn *p_hwfn, u32 input_len,
809 u8 *input_buf, u32 max_size, u8 *unzip_buf)
810{
811 int rc;
812
813 p_hwfn->stream->next_in = input_buf;
814 p_hwfn->stream->avail_in = input_len;
815 p_hwfn->stream->next_out = unzip_buf;
816 p_hwfn->stream->avail_out = max_size;
817
818 rc = zlib_inflateInit2(p_hwfn->stream, MAX_WBITS);
819
820 if (rc != Z_OK) {
821 DP_VERBOSE(p_hwfn, NETIF_MSG_DRV, "zlib init failed, rc = %d\n",
822 rc);
823 return 0;
824 }
825
826 rc = zlib_inflate(p_hwfn->stream, Z_FINISH);
827 zlib_inflateEnd(p_hwfn->stream);
828
829 if (rc != Z_OK && rc != Z_STREAM_END) {
830 DP_VERBOSE(p_hwfn, NETIF_MSG_DRV, "FW unzip error: %s, rc=%d\n",
831 p_hwfn->stream->msg, rc);
832 return 0;
833 }
834
835 return p_hwfn->stream->total_out / 4;
836}
837
838static int qed_alloc_stream_mem(struct qed_dev *cdev)
839{
840 int i;
841 void *workspace;
842
843 for_each_hwfn(cdev, i) {
844 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
845
846 p_hwfn->stream = kzalloc(sizeof(*p_hwfn->stream), GFP_KERNEL);
847 if (!p_hwfn->stream)
848 return -ENOMEM;
849
850 workspace = vzalloc(zlib_inflate_workspacesize());
851 if (!workspace)
852 return -ENOMEM;
853 p_hwfn->stream->workspace = workspace;
854 }
855
856 return 0;
857}
858
859static void qed_free_stream_mem(struct qed_dev *cdev)
860{
861 int i;
862
863 for_each_hwfn(cdev, i) {
864 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
865
866 if (!p_hwfn->stream)
867 return;
868
869 vfree(p_hwfn->stream->workspace);
870 kfree(p_hwfn->stream);
871 }
872}
873
874static void qed_update_pf_params(struct qed_dev *cdev,
875 struct qed_pf_params *params)
876{
877 int i;
878
Ram Amrani5c5f2602016-11-09 22:48:44 +0200879 if (IS_ENABLED(CONFIG_QED_RDMA)) {
880 params->rdma_pf_params.num_qps = QED_ROCE_QPS;
881 params->rdma_pf_params.min_dpis = QED_ROCE_DPIS;
882 /* divide by 3 the MRs to avoid MF ILT overflow */
Ram Amrani5c5f2602016-11-09 22:48:44 +0200883 params->rdma_pf_params.gl_pi = QED_ROCE_PROTOCOL_INDEX;
884 }
885
Mintz, Yuvale1d32ac2017-01-01 13:57:03 +0200886 /* In case we might support RDMA, don't allow qede to be greedy
887 * with the L2 contexts. Allow for 64 queues [rx, tx, xdp] per hwfn.
888 */
889 if (QED_LEADING_HWFN(cdev)->hw_info.personality ==
890 QED_PCI_ETH_ROCE) {
891 u16 *num_cons;
892
893 num_cons = &params->eth_pf_params.num_cons;
894 *num_cons = min_t(u16, *num_cons, 192);
895 }
896
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200897 for (i = 0; i < cdev->num_hwfns; i++) {
898 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
899
900 p_hwfn->pf_params = *params;
901 }
902}
903
904static int qed_slowpath_start(struct qed_dev *cdev,
905 struct qed_slowpath_params *params)
906{
Tomer Tayar5d24bcf2017-03-28 15:12:52 +0300907 struct qed_drv_load_params drv_load_params;
Mintz, Yuvalc0c2d0b2017-03-28 15:12:51 +0300908 struct qed_hw_init_params hw_init_params;
Manish Choprab18e1702016-04-14 01:38:30 -0400909 struct qed_tunn_start_params tunn_info;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200910 struct qed_mcp_drv_version drv_version;
911 const u8 *data = NULL;
912 struct qed_hwfn *hwfn;
Sudarsana Reddy Kalluruc78c70f2017-02-15 10:24:10 +0200913 struct qed_ptt *p_ptt;
Yuval Mintz37bff2b2016-05-11 16:36:13 +0300914 int rc = -EINVAL;
915
916 if (qed_iov_wq_start(cdev))
917 goto err;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200918
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300919 if (IS_PF(cdev)) {
920 rc = request_firmware(&cdev->firmware, QED_FW_FILE_NAME,
921 &cdev->pdev->dev);
922 if (rc) {
923 DP_NOTICE(cdev,
924 "Failed to find fw file - /lib/firmware/%s\n",
925 QED_FW_FILE_NAME);
926 goto err;
927 }
Sudarsana Reddy Kalluruc78c70f2017-02-15 10:24:10 +0200928
929 p_ptt = qed_ptt_acquire(QED_LEADING_HWFN(cdev));
930 if (p_ptt) {
931 QED_LEADING_HWFN(cdev)->p_ptp_ptt = p_ptt;
932 } else {
933 DP_NOTICE(cdev, "Failed to acquire PTT for PTP\n");
934 goto err;
935 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200936 }
937
Sudarsana Reddy Kalluru0e191822016-10-21 04:43:42 -0400938 cdev->rx_coalesce_usecs = QED_DEFAULT_RX_USECS;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200939 rc = qed_nic_setup(cdev);
940 if (rc)
941 goto err;
942
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300943 if (IS_PF(cdev))
944 rc = qed_slowpath_setup_int(cdev, params->int_mode);
945 else
946 rc = qed_slowpath_vf_setup_int(cdev);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200947 if (rc)
948 goto err1;
949
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300950 if (IS_PF(cdev)) {
951 /* Allocate stream for unzipping */
952 rc = qed_alloc_stream_mem(cdev);
Joe Perches2591c282016-09-04 14:24:03 -0700953 if (rc)
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300954 goto err2;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200955
Yuval Mintz351a4ded2016-06-02 10:23:29 +0300956 /* First Dword used to diffrentiate between various sources */
957 data = cdev->firmware->data + sizeof(u32);
Tomer Tayarc965db42016-09-07 16:36:24 +0300958
959 qed_dbg_pf_init(cdev);
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300960 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200961
Manish Choprab18e1702016-04-14 01:38:30 -0400962 memset(&tunn_info, 0, sizeof(tunn_info));
Manish Chopra9a109dd2016-04-14 01:38:31 -0400963 tunn_info.tunn_mode |= 1 << QED_MODE_VXLAN_TUNN |
Manish Chopraf7985862016-04-14 01:38:32 -0400964 1 << QED_MODE_L2GRE_TUNN |
965 1 << QED_MODE_IPGRE_TUNN |
Manish Chopra9a109dd2016-04-14 01:38:31 -0400966 1 << QED_MODE_L2GENEVE_TUNN |
967 1 << QED_MODE_IPGENEVE_TUNN;
968
Manish Choprab18e1702016-04-14 01:38:30 -0400969 tunn_info.tunn_clss_vxlan = QED_TUNN_CLSS_MAC_VLAN;
Manish Chopraf7985862016-04-14 01:38:32 -0400970 tunn_info.tunn_clss_l2gre = QED_TUNN_CLSS_MAC_VLAN;
971 tunn_info.tunn_clss_ipgre = QED_TUNN_CLSS_MAC_VLAN;
Manish Choprab18e1702016-04-14 01:38:30 -0400972
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300973 /* Start the slowpath */
Mintz, Yuvalc0c2d0b2017-03-28 15:12:51 +0300974 memset(&hw_init_params, 0, sizeof(hw_init_params));
975 hw_init_params.p_tunn = &tunn_info;
976 hw_init_params.b_hw_start = true;
977 hw_init_params.int_mode = cdev->int_params.out.int_mode;
978 hw_init_params.allow_npar_tx_switch = true;
979 hw_init_params.bin_fw_data = data;
980
Tomer Tayar5d24bcf2017-03-28 15:12:52 +0300981 memset(&drv_load_params, 0, sizeof(drv_load_params));
982 drv_load_params.is_crash_kernel = is_kdump_kernel();
983 drv_load_params.mfw_timeout_val = QED_LOAD_REQ_LOCK_TO_DEFAULT;
984 drv_load_params.avoid_eng_reset = false;
985 drv_load_params.override_force_load = QED_OVERRIDE_FORCE_LOAD_NONE;
986 hw_init_params.p_drv_load_params = &drv_load_params;
987
Mintz, Yuvalc0c2d0b2017-03-28 15:12:51 +0300988 rc = qed_hw_init(cdev, &hw_init_params);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200989 if (rc)
Yuval Mintz8c925c42016-03-02 20:26:03 +0200990 goto err2;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200991
992 DP_INFO(cdev,
993 "HW initialization and function start completed successfully\n");
994
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300995 /* Allocate LL2 interface if needed */
996 if (QED_LEADING_HWFN(cdev)->using_ll2) {
997 rc = qed_ll2_alloc_if(cdev);
998 if (rc)
999 goto err3;
1000 }
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001001 if (IS_PF(cdev)) {
1002 hwfn = QED_LEADING_HWFN(cdev);
1003 drv_version.version = (params->drv_major << 24) |
1004 (params->drv_minor << 16) |
1005 (params->drv_rev << 8) |
1006 (params->drv_eng);
1007 strlcpy(drv_version.name, params->name,
1008 MCP_DRV_VER_STR_SIZE - 4);
1009 rc = qed_mcp_send_drv_version(hwfn, hwfn->p_main_ptt,
1010 &drv_version);
1011 if (rc) {
1012 DP_NOTICE(cdev, "Failed sending drv version command\n");
1013 return rc;
1014 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001015 }
1016
Yuval Mintz8c925c42016-03-02 20:26:03 +02001017 qed_reset_vport_stats(cdev);
1018
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001019 return 0;
1020
Yuval Mintz0a7fb112016-10-01 21:59:55 +03001021err3:
1022 qed_hw_stop(cdev);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001023err2:
Yuval Mintz8c925c42016-03-02 20:26:03 +02001024 qed_hw_timers_stop_all(cdev);
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001025 if (IS_PF(cdev))
1026 qed_slowpath_irq_free(cdev);
Yuval Mintz8c925c42016-03-02 20:26:03 +02001027 qed_free_stream_mem(cdev);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001028 qed_disable_msix(cdev);
1029err1:
1030 qed_resc_free(cdev);
1031err:
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001032 if (IS_PF(cdev))
1033 release_firmware(cdev->firmware);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001034
Sudarsana Reddy Kalluruc78c70f2017-02-15 10:24:10 +02001035 if (IS_PF(cdev) && QED_LEADING_HWFN(cdev)->p_ptp_ptt)
1036 qed_ptt_release(QED_LEADING_HWFN(cdev),
1037 QED_LEADING_HWFN(cdev)->p_ptp_ptt);
1038
Yuval Mintz37bff2b2016-05-11 16:36:13 +03001039 qed_iov_wq_stop(cdev, false);
1040
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001041 return rc;
1042}
1043
1044static int qed_slowpath_stop(struct qed_dev *cdev)
1045{
1046 if (!cdev)
1047 return -ENODEV;
1048
Yuval Mintz0a7fb112016-10-01 21:59:55 +03001049 qed_ll2_dealloc_if(cdev);
1050
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001051 if (IS_PF(cdev)) {
Sudarsana Reddy Kalluruc78c70f2017-02-15 10:24:10 +02001052 qed_ptt_release(QED_LEADING_HWFN(cdev),
1053 QED_LEADING_HWFN(cdev)->p_ptp_ptt);
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001054 qed_free_stream_mem(cdev);
Yuval Mintzc5ac9312016-06-03 14:35:34 +03001055 if (IS_QED_ETH_IF(cdev))
1056 qed_sriov_disable(cdev, true);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001057
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001058 qed_nic_stop(cdev);
1059 qed_slowpath_irq_free(cdev);
1060 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001061
1062 qed_disable_msix(cdev);
Tomer Tayar12263372017-03-28 15:12:50 +03001063
1064 qed_resc_free(cdev);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001065
Yuval Mintz37bff2b2016-05-11 16:36:13 +03001066 qed_iov_wq_stop(cdev, true);
1067
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001068 if (IS_PF(cdev))
1069 release_firmware(cdev->firmware);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001070
1071 return 0;
1072}
1073
1074static void qed_set_id(struct qed_dev *cdev, char name[NAME_SIZE],
1075 char ver_str[VER_SIZE])
1076{
1077 int i;
1078
1079 memcpy(cdev->name, name, NAME_SIZE);
1080 for_each_hwfn(cdev, i)
1081 snprintf(cdev->hwfns[i].name, NAME_SIZE, "%s-%d", name, i);
1082
1083 memcpy(cdev->ver_str, ver_str, VER_SIZE);
1084 cdev->drv_type = DRV_ID_DRV_TYPE_LINUX;
1085}
1086
1087static u32 qed_sb_init(struct qed_dev *cdev,
1088 struct qed_sb_info *sb_info,
1089 void *sb_virt_addr,
1090 dma_addr_t sb_phy_addr, u16 sb_id,
1091 enum qed_sb_type type)
1092{
1093 struct qed_hwfn *p_hwfn;
Mintz, Yuval85750d72017-02-20 22:43:38 +02001094 struct qed_ptt *p_ptt;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001095 int hwfn_index;
1096 u16 rel_sb_id;
1097 u8 n_hwfns;
1098 u32 rc;
1099
1100 /* RoCE uses single engine and CMT uses two engines. When using both
1101 * we force only a single engine. Storage uses only engine 0 too.
1102 */
1103 if (type == QED_SB_TYPE_L2_QUEUE)
1104 n_hwfns = cdev->num_hwfns;
1105 else
1106 n_hwfns = 1;
1107
1108 hwfn_index = sb_id % n_hwfns;
1109 p_hwfn = &cdev->hwfns[hwfn_index];
1110 rel_sb_id = sb_id / n_hwfns;
1111
1112 DP_VERBOSE(cdev, NETIF_MSG_INTR,
1113 "hwfn [%d] <--[init]-- SB %04x [0x%04x upper]\n",
1114 hwfn_index, rel_sb_id, sb_id);
1115
Mintz, Yuval85750d72017-02-20 22:43:38 +02001116 if (IS_PF(p_hwfn->cdev)) {
1117 p_ptt = qed_ptt_acquire(p_hwfn);
1118 if (!p_ptt)
1119 return -EBUSY;
1120
1121 rc = qed_int_sb_init(p_hwfn, p_ptt, sb_info, sb_virt_addr,
1122 sb_phy_addr, rel_sb_id);
1123 qed_ptt_release(p_hwfn, p_ptt);
1124 } else {
1125 rc = qed_int_sb_init(p_hwfn, NULL, sb_info, sb_virt_addr,
1126 sb_phy_addr, rel_sb_id);
1127 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001128
1129 return rc;
1130}
1131
1132static u32 qed_sb_release(struct qed_dev *cdev,
Yuval Mintz1a635e42016-08-15 10:42:43 +03001133 struct qed_sb_info *sb_info, u16 sb_id)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001134{
1135 struct qed_hwfn *p_hwfn;
1136 int hwfn_index;
1137 u16 rel_sb_id;
1138 u32 rc;
1139
1140 hwfn_index = sb_id % cdev->num_hwfns;
1141 p_hwfn = &cdev->hwfns[hwfn_index];
1142 rel_sb_id = sb_id / cdev->num_hwfns;
1143
1144 DP_VERBOSE(cdev, NETIF_MSG_INTR,
1145 "hwfn [%d] <--[init]-- SB %04x [0x%04x upper]\n",
1146 hwfn_index, rel_sb_id, sb_id);
1147
1148 rc = qed_int_sb_release(p_hwfn, sb_info, rel_sb_id);
1149
1150 return rc;
1151}
1152
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +03001153static bool qed_can_link_change(struct qed_dev *cdev)
1154{
1155 return true;
1156}
1157
Yuval Mintz351a4ded2016-06-02 10:23:29 +03001158static int qed_set_link(struct qed_dev *cdev, struct qed_link_params *params)
Yuval Mintzcc875c22015-10-26 11:02:31 +02001159{
1160 struct qed_hwfn *hwfn;
1161 struct qed_mcp_link_params *link_params;
1162 struct qed_ptt *ptt;
1163 int rc;
1164
1165 if (!cdev)
1166 return -ENODEV;
1167
1168 /* The link should be set only once per PF */
1169 hwfn = &cdev->hwfns[0];
1170
Mintz, Yuval65ed2ff2017-02-20 22:43:39 +02001171 /* When VF wants to set link, force it to read the bulletin instead.
1172 * This mimics the PF behavior, where a noitification [both immediate
1173 * and possible later] would be generated when changing properties.
1174 */
1175 if (IS_VF(cdev)) {
1176 qed_schedule_iov(hwfn, QED_IOV_WQ_VF_FORCE_LINK_QUERY_FLAG);
1177 return 0;
1178 }
1179
Yuval Mintzcc875c22015-10-26 11:02:31 +02001180 ptt = qed_ptt_acquire(hwfn);
1181 if (!ptt)
1182 return -EBUSY;
1183
1184 link_params = qed_mcp_get_link_params(hwfn);
1185 if (params->override_flags & QED_LINK_OVERRIDE_SPEED_AUTONEG)
1186 link_params->speed.autoneg = params->autoneg;
1187 if (params->override_flags & QED_LINK_OVERRIDE_SPEED_ADV_SPEEDS) {
1188 link_params->speed.advertised_speeds = 0;
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001189 if ((params->adv_speeds & QED_LM_1000baseT_Half_BIT) ||
1190 (params->adv_speeds & QED_LM_1000baseT_Full_BIT))
Yuval Mintzcc875c22015-10-26 11:02:31 +02001191 link_params->speed.advertised_speeds |=
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001192 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G;
1193 if (params->adv_speeds & QED_LM_10000baseKR_Full_BIT)
Yuval Mintzcc875c22015-10-26 11:02:31 +02001194 link_params->speed.advertised_speeds |=
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001195 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G;
1196 if (params->adv_speeds & QED_LM_25000baseKR_Full_BIT)
Yuval Mintzcc875c22015-10-26 11:02:31 +02001197 link_params->speed.advertised_speeds |=
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001198 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_25G;
1199 if (params->adv_speeds & QED_LM_40000baseLR4_Full_BIT)
Yuval Mintzcc875c22015-10-26 11:02:31 +02001200 link_params->speed.advertised_speeds |=
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001201 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G;
1202 if (params->adv_speeds & QED_LM_50000baseKR2_Full_BIT)
1203 link_params->speed.advertised_speeds |=
1204 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_50G;
1205 if (params->adv_speeds & QED_LM_100000baseKR4_Full_BIT)
Yuval Mintzcc875c22015-10-26 11:02:31 +02001206 link_params->speed.advertised_speeds |=
Yuval Mintz351a4ded2016-06-02 10:23:29 +03001207 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_BB_100G;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001208 }
1209 if (params->override_flags & QED_LINK_OVERRIDE_SPEED_FORCED_SPEED)
1210 link_params->speed.forced_speed = params->forced_speed;
Sudarsana Reddy Kallurua43f2352016-04-22 08:41:04 +03001211 if (params->override_flags & QED_LINK_OVERRIDE_PAUSE_CONFIG) {
1212 if (params->pause_config & QED_LINK_PAUSE_AUTONEG_ENABLE)
1213 link_params->pause.autoneg = true;
1214 else
1215 link_params->pause.autoneg = false;
1216 if (params->pause_config & QED_LINK_PAUSE_RX_ENABLE)
1217 link_params->pause.forced_rx = true;
1218 else
1219 link_params->pause.forced_rx = false;
1220 if (params->pause_config & QED_LINK_PAUSE_TX_ENABLE)
1221 link_params->pause.forced_tx = true;
1222 else
1223 link_params->pause.forced_tx = false;
1224 }
Sudarsana Reddy Kalluru03dc76c2016-04-28 20:20:52 -04001225 if (params->override_flags & QED_LINK_OVERRIDE_LOOPBACK_MODE) {
1226 switch (params->loopback_mode) {
1227 case QED_LINK_LOOPBACK_INT_PHY:
Yuval Mintz351a4ded2016-06-02 10:23:29 +03001228 link_params->loopback_mode = ETH_LOOPBACK_INT_PHY;
Sudarsana Reddy Kalluru03dc76c2016-04-28 20:20:52 -04001229 break;
1230 case QED_LINK_LOOPBACK_EXT_PHY:
Yuval Mintz351a4ded2016-06-02 10:23:29 +03001231 link_params->loopback_mode = ETH_LOOPBACK_EXT_PHY;
Sudarsana Reddy Kalluru03dc76c2016-04-28 20:20:52 -04001232 break;
1233 case QED_LINK_LOOPBACK_EXT:
Yuval Mintz351a4ded2016-06-02 10:23:29 +03001234 link_params->loopback_mode = ETH_LOOPBACK_EXT;
Sudarsana Reddy Kalluru03dc76c2016-04-28 20:20:52 -04001235 break;
1236 case QED_LINK_LOOPBACK_MAC:
Yuval Mintz351a4ded2016-06-02 10:23:29 +03001237 link_params->loopback_mode = ETH_LOOPBACK_MAC;
Sudarsana Reddy Kalluru03dc76c2016-04-28 20:20:52 -04001238 break;
1239 default:
Yuval Mintz351a4ded2016-06-02 10:23:29 +03001240 link_params->loopback_mode = ETH_LOOPBACK_NONE;
Sudarsana Reddy Kalluru03dc76c2016-04-28 20:20:52 -04001241 break;
1242 }
1243 }
Yuval Mintzcc875c22015-10-26 11:02:31 +02001244
1245 rc = qed_mcp_set_link(hwfn, ptt, params->link_up);
1246
1247 qed_ptt_release(hwfn, ptt);
1248
1249 return rc;
1250}
1251
1252static int qed_get_port_type(u32 media_type)
1253{
1254 int port_type;
1255
1256 switch (media_type) {
1257 case MEDIA_SFPP_10G_FIBER:
1258 case MEDIA_SFP_1G_FIBER:
1259 case MEDIA_XFP_FIBER:
Yuval Mintzb639f192016-06-19 15:18:15 +03001260 case MEDIA_MODULE_FIBER:
Yuval Mintzcc875c22015-10-26 11:02:31 +02001261 case MEDIA_KR:
1262 port_type = PORT_FIBRE;
1263 break;
1264 case MEDIA_DA_TWINAX:
1265 port_type = PORT_DA;
1266 break;
1267 case MEDIA_BASE_T:
1268 port_type = PORT_TP;
1269 break;
1270 case MEDIA_NOT_PRESENT:
1271 port_type = PORT_NONE;
1272 break;
1273 case MEDIA_UNSPECIFIED:
1274 default:
1275 port_type = PORT_OTHER;
1276 break;
1277 }
1278 return port_type;
1279}
1280
Arnd Bergmann14b84e82016-06-01 15:29:13 +02001281static int qed_get_link_data(struct qed_hwfn *hwfn,
1282 struct qed_mcp_link_params *params,
1283 struct qed_mcp_link_state *link,
1284 struct qed_mcp_link_capabilities *link_caps)
1285{
1286 void *p;
1287
1288 if (!IS_PF(hwfn->cdev)) {
1289 qed_vf_get_link_params(hwfn, params);
1290 qed_vf_get_link_state(hwfn, link);
1291 qed_vf_get_link_caps(hwfn, link_caps);
1292
1293 return 0;
1294 }
1295
1296 p = qed_mcp_get_link_params(hwfn);
1297 if (!p)
1298 return -ENXIO;
1299 memcpy(params, p, sizeof(*params));
1300
1301 p = qed_mcp_get_link_state(hwfn);
1302 if (!p)
1303 return -ENXIO;
1304 memcpy(link, p, sizeof(*link));
1305
1306 p = qed_mcp_get_link_capabilities(hwfn);
1307 if (!p)
1308 return -ENXIO;
1309 memcpy(link_caps, p, sizeof(*link_caps));
1310
1311 return 0;
1312}
1313
Yuval Mintzcc875c22015-10-26 11:02:31 +02001314static void qed_fill_link(struct qed_hwfn *hwfn,
1315 struct qed_link_output *if_link)
1316{
1317 struct qed_mcp_link_params params;
1318 struct qed_mcp_link_state link;
1319 struct qed_mcp_link_capabilities link_caps;
1320 u32 media_type;
1321
1322 memset(if_link, 0, sizeof(*if_link));
1323
1324 /* Prepare source inputs */
Arnd Bergmann14b84e82016-06-01 15:29:13 +02001325 if (qed_get_link_data(hwfn, &params, &link, &link_caps)) {
1326 dev_warn(&hwfn->cdev->pdev->dev, "no link data available\n");
1327 return;
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001328 }
Yuval Mintzcc875c22015-10-26 11:02:31 +02001329
1330 /* Set the link parameters to pass to protocol driver */
1331 if (link.link_up)
1332 if_link->link_up = true;
1333
1334 /* TODO - at the moment assume supported and advertised speed equal */
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001335 if_link->supported_caps = QED_LM_FIBRE_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001336 if (params.speed.autoneg)
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001337 if_link->supported_caps |= QED_LM_Autoneg_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001338 if (params.pause.autoneg ||
1339 (params.pause.forced_rx && params.pause.forced_tx))
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001340 if_link->supported_caps |= QED_LM_Asym_Pause_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001341 if (params.pause.autoneg || params.pause.forced_rx ||
1342 params.pause.forced_tx)
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001343 if_link->supported_caps |= QED_LM_Pause_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001344
1345 if_link->advertised_caps = if_link->supported_caps;
1346 if (params.speed.advertised_speeds &
1347 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G)
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001348 if_link->advertised_caps |= QED_LM_1000baseT_Half_BIT |
1349 QED_LM_1000baseT_Full_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001350 if (params.speed.advertised_speeds &
1351 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G)
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001352 if_link->advertised_caps |= QED_LM_10000baseKR_Full_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001353 if (params.speed.advertised_speeds &
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001354 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_25G)
1355 if_link->advertised_caps |= QED_LM_25000baseKR_Full_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001356 if (params.speed.advertised_speeds &
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001357 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G)
1358 if_link->advertised_caps |= QED_LM_40000baseLR4_Full_BIT;
1359 if (params.speed.advertised_speeds &
1360 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_50G)
1361 if_link->advertised_caps |= QED_LM_50000baseKR2_Full_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001362 if (params.speed.advertised_speeds &
Yuval Mintz351a4ded2016-06-02 10:23:29 +03001363 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_BB_100G)
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001364 if_link->advertised_caps |= QED_LM_100000baseKR4_Full_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001365
1366 if (link_caps.speed_capabilities &
1367 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G)
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001368 if_link->supported_caps |= QED_LM_1000baseT_Half_BIT |
1369 QED_LM_1000baseT_Full_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001370 if (link_caps.speed_capabilities &
1371 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G)
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001372 if_link->supported_caps |= QED_LM_10000baseKR_Full_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001373 if (link_caps.speed_capabilities &
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001374 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_25G)
1375 if_link->supported_caps |= QED_LM_25000baseKR_Full_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001376 if (link_caps.speed_capabilities &
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001377 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G)
1378 if_link->supported_caps |= QED_LM_40000baseLR4_Full_BIT;
1379 if (link_caps.speed_capabilities &
1380 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_50G)
1381 if_link->supported_caps |= QED_LM_50000baseKR2_Full_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001382 if (link_caps.speed_capabilities &
Yuval Mintz351a4ded2016-06-02 10:23:29 +03001383 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_BB_100G)
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001384 if_link->supported_caps |= QED_LM_100000baseKR4_Full_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001385
1386 if (link.link_up)
1387 if_link->speed = link.speed;
1388
1389 /* TODO - fill duplex properly */
1390 if_link->duplex = DUPLEX_FULL;
1391 qed_mcp_get_media_type(hwfn->cdev, &media_type);
1392 if_link->port = qed_get_port_type(media_type);
1393
1394 if_link->autoneg = params.speed.autoneg;
1395
1396 if (params.pause.autoneg)
1397 if_link->pause_config |= QED_LINK_PAUSE_AUTONEG_ENABLE;
1398 if (params.pause.forced_rx)
1399 if_link->pause_config |= QED_LINK_PAUSE_RX_ENABLE;
1400 if (params.pause.forced_tx)
1401 if_link->pause_config |= QED_LINK_PAUSE_TX_ENABLE;
1402
1403 /* Link partner capabilities */
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001404 if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_1G_HD)
1405 if_link->lp_caps |= QED_LM_1000baseT_Half_BIT;
1406 if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_1G_FD)
1407 if_link->lp_caps |= QED_LM_1000baseT_Full_BIT;
1408 if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_10G)
1409 if_link->lp_caps |= QED_LM_10000baseKR_Full_BIT;
1410 if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_25G)
1411 if_link->lp_caps |= QED_LM_25000baseKR_Full_BIT;
1412 if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_40G)
1413 if_link->lp_caps |= QED_LM_40000baseLR4_Full_BIT;
1414 if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_50G)
1415 if_link->lp_caps |= QED_LM_50000baseKR2_Full_BIT;
1416 if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_100G)
1417 if_link->lp_caps |= QED_LM_100000baseKR4_Full_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001418
1419 if (link.an_complete)
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001420 if_link->lp_caps |= QED_LM_Autoneg_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001421
1422 if (link.partner_adv_pause)
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001423 if_link->lp_caps |= QED_LM_Pause_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001424 if (link.partner_adv_pause == QED_LINK_PARTNER_ASYMMETRIC_PAUSE ||
1425 link.partner_adv_pause == QED_LINK_PARTNER_BOTH_PAUSE)
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001426 if_link->lp_caps |= QED_LM_Asym_Pause_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001427}
1428
1429static void qed_get_current_link(struct qed_dev *cdev,
1430 struct qed_link_output *if_link)
1431{
Yuval Mintz36558c32016-05-11 16:36:17 +03001432 int i;
1433
Yuval Mintzcc875c22015-10-26 11:02:31 +02001434 qed_fill_link(&cdev->hwfns[0], if_link);
Yuval Mintz36558c32016-05-11 16:36:17 +03001435
1436 for_each_hwfn(cdev, i)
1437 qed_inform_vf_link_state(&cdev->hwfns[i]);
Yuval Mintzcc875c22015-10-26 11:02:31 +02001438}
1439
1440void qed_link_update(struct qed_hwfn *hwfn)
1441{
1442 void *cookie = hwfn->cdev->ops_cookie;
1443 struct qed_common_cb_ops *op = hwfn->cdev->protocol_ops.common;
1444 struct qed_link_output if_link;
1445
1446 qed_fill_link(hwfn, &if_link);
Yuval Mintz36558c32016-05-11 16:36:17 +03001447 qed_inform_vf_link_state(hwfn);
Yuval Mintzcc875c22015-10-26 11:02:31 +02001448
1449 if (IS_LEAD_HWFN(hwfn) && cookie)
1450 op->link_update(cookie, &if_link);
1451}
1452
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001453static int qed_drain(struct qed_dev *cdev)
1454{
1455 struct qed_hwfn *hwfn;
1456 struct qed_ptt *ptt;
1457 int i, rc;
1458
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001459 if (IS_VF(cdev))
1460 return 0;
1461
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001462 for_each_hwfn(cdev, i) {
1463 hwfn = &cdev->hwfns[i];
1464 ptt = qed_ptt_acquire(hwfn);
1465 if (!ptt) {
1466 DP_NOTICE(hwfn, "Failed to drain NIG; No PTT\n");
1467 return -EBUSY;
1468 }
1469 rc = qed_mcp_drain(hwfn, ptt);
1470 if (rc)
1471 return rc;
1472 qed_ptt_release(hwfn, ptt);
1473 }
1474
1475 return 0;
1476}
1477
Sudarsana Reddy Kalluru722003a2016-06-21 09:36:21 -04001478static void qed_get_coalesce(struct qed_dev *cdev, u16 *rx_coal, u16 *tx_coal)
1479{
1480 *rx_coal = cdev->rx_coalesce_usecs;
1481 *tx_coal = cdev->tx_coalesce_usecs;
1482}
1483
1484static int qed_set_coalesce(struct qed_dev *cdev, u16 rx_coal, u16 tx_coal,
1485 u8 qid, u16 sb_id)
1486{
1487 struct qed_hwfn *hwfn;
1488 struct qed_ptt *ptt;
1489 int hwfn_index;
1490 int status = 0;
1491
1492 hwfn_index = qid % cdev->num_hwfns;
1493 hwfn = &cdev->hwfns[hwfn_index];
1494 ptt = qed_ptt_acquire(hwfn);
1495 if (!ptt)
1496 return -EAGAIN;
1497
1498 status = qed_set_rxq_coalesce(hwfn, ptt, rx_coal,
1499 qid / cdev->num_hwfns, sb_id);
1500 if (status)
1501 goto out;
1502 status = qed_set_txq_coalesce(hwfn, ptt, tx_coal,
1503 qid / cdev->num_hwfns, sb_id);
1504out:
1505 qed_ptt_release(hwfn, ptt);
1506
1507 return status;
1508}
1509
Sudarsana Kalluru91420b82015-11-30 12:25:03 +02001510static int qed_set_led(struct qed_dev *cdev, enum qed_led_mode mode)
1511{
1512 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1513 struct qed_ptt *ptt;
1514 int status = 0;
1515
1516 ptt = qed_ptt_acquire(hwfn);
1517 if (!ptt)
1518 return -EAGAIN;
1519
1520 status = qed_mcp_set_led(hwfn, ptt, mode);
1521
1522 qed_ptt_release(hwfn, ptt);
1523
1524 return status;
1525}
1526
Mintz, Yuval14d39642016-10-31 07:14:23 +02001527static int qed_update_wol(struct qed_dev *cdev, bool enabled)
1528{
1529 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1530 struct qed_ptt *ptt;
1531 int rc = 0;
1532
1533 if (IS_VF(cdev))
1534 return 0;
1535
1536 ptt = qed_ptt_acquire(hwfn);
1537 if (!ptt)
1538 return -EAGAIN;
1539
1540 rc = qed_mcp_ov_update_wol(hwfn, ptt, enabled ? QED_OV_WOL_ENABLED
1541 : QED_OV_WOL_DISABLED);
1542 if (rc)
1543 goto out;
1544 rc = qed_mcp_ov_update_current_config(hwfn, ptt, QED_OV_CLIENT_DRV);
1545
1546out:
1547 qed_ptt_release(hwfn, ptt);
1548 return rc;
1549}
1550
Sudarsana Kalluru0fefbfb2016-10-31 07:14:21 +02001551static int qed_update_drv_state(struct qed_dev *cdev, bool active)
1552{
1553 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1554 struct qed_ptt *ptt;
1555 int status = 0;
1556
1557 if (IS_VF(cdev))
1558 return 0;
1559
1560 ptt = qed_ptt_acquire(hwfn);
1561 if (!ptt)
1562 return -EAGAIN;
1563
1564 status = qed_mcp_ov_update_driver_state(hwfn, ptt, active ?
1565 QED_OV_DRIVER_STATE_ACTIVE :
1566 QED_OV_DRIVER_STATE_DISABLED);
1567
1568 qed_ptt_release(hwfn, ptt);
1569
1570 return status;
1571}
1572
1573static int qed_update_mac(struct qed_dev *cdev, u8 *mac)
1574{
1575 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1576 struct qed_ptt *ptt;
1577 int status = 0;
1578
1579 if (IS_VF(cdev))
1580 return 0;
1581
1582 ptt = qed_ptt_acquire(hwfn);
1583 if (!ptt)
1584 return -EAGAIN;
1585
1586 status = qed_mcp_ov_update_mac(hwfn, ptt, mac);
1587 if (status)
1588 goto out;
1589
1590 status = qed_mcp_ov_update_current_config(hwfn, ptt, QED_OV_CLIENT_DRV);
1591
1592out:
1593 qed_ptt_release(hwfn, ptt);
1594 return status;
1595}
1596
1597static int qed_update_mtu(struct qed_dev *cdev, u16 mtu)
1598{
1599 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1600 struct qed_ptt *ptt;
1601 int status = 0;
1602
1603 if (IS_VF(cdev))
1604 return 0;
1605
1606 ptt = qed_ptt_acquire(hwfn);
1607 if (!ptt)
1608 return -EAGAIN;
1609
1610 status = qed_mcp_ov_update_mtu(hwfn, ptt, mtu);
1611 if (status)
1612 goto out;
1613
1614 status = qed_mcp_ov_update_current_config(hwfn, ptt, QED_OV_CLIENT_DRV);
1615
1616out:
1617 qed_ptt_release(hwfn, ptt);
1618 return status;
1619}
1620
Yuval Mintz8c93bea2016-10-13 22:57:03 +03001621static struct qed_selftest_ops qed_selftest_ops_pass = {
Sudarsana Reddy Kalluru03dc76c2016-04-28 20:20:52 -04001622 .selftest_memory = &qed_selftest_memory,
1623 .selftest_interrupt = &qed_selftest_interrupt,
1624 .selftest_register = &qed_selftest_register,
1625 .selftest_clock = &qed_selftest_clock,
Mintz, Yuval7a4b21b2016-10-31 07:14:22 +02001626 .selftest_nvram = &qed_selftest_nvram,
Sudarsana Reddy Kalluru03dc76c2016-04-28 20:20:52 -04001627};
1628
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001629const struct qed_common_ops qed_common_ops_pass = {
Sudarsana Reddy Kalluru03dc76c2016-04-28 20:20:52 -04001630 .selftest = &qed_selftest_ops_pass,
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001631 .probe = &qed_probe,
1632 .remove = &qed_remove,
1633 .set_power_state = &qed_set_power_state,
1634 .set_id = &qed_set_id,
1635 .update_pf_params = &qed_update_pf_params,
1636 .slowpath_start = &qed_slowpath_start,
1637 .slowpath_stop = &qed_slowpath_stop,
1638 .set_fp_int = &qed_set_int_fp,
1639 .get_fp_int = &qed_get_int_fp,
1640 .sb_init = &qed_sb_init,
1641 .sb_release = &qed_sb_release,
1642 .simd_handler_config = &qed_simd_handler_config,
1643 .simd_handler_clean = &qed_simd_handler_clean,
Arun Easi1e128c82017-02-15 06:28:22 -08001644 .dbg_grc = &qed_dbg_grc,
1645 .dbg_grc_size = &qed_dbg_grc_size,
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +03001646 .can_link_change = &qed_can_link_change,
Yuval Mintzcc875c22015-10-26 11:02:31 +02001647 .set_link = &qed_set_link,
1648 .get_link = &qed_get_current_link,
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001649 .drain = &qed_drain,
1650 .update_msglvl = &qed_init_dp,
Tomer Tayare0971c82016-09-07 16:36:25 +03001651 .dbg_all_data = &qed_dbg_all_data,
1652 .dbg_all_data_size = &qed_dbg_all_data_size,
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001653 .chain_alloc = &qed_chain_alloc,
1654 .chain_free = &qed_chain_free,
Sudarsana Reddy Kalluru722003a2016-06-21 09:36:21 -04001655 .get_coalesce = &qed_get_coalesce,
1656 .set_coalesce = &qed_set_coalesce,
Sudarsana Kalluru91420b82015-11-30 12:25:03 +02001657 .set_led = &qed_set_led,
Sudarsana Kalluru0fefbfb2016-10-31 07:14:21 +02001658 .update_drv_state = &qed_update_drv_state,
1659 .update_mac = &qed_update_mac,
1660 .update_mtu = &qed_update_mtu,
Mintz, Yuval14d39642016-10-31 07:14:23 +02001661 .update_wol = &qed_update_wol,
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001662};
Sudarsana Reddy Kalluru6c754242016-08-16 10:51:03 -04001663
1664void qed_get_protocol_stats(struct qed_dev *cdev,
1665 enum qed_mcp_protocol_type type,
1666 union qed_mcp_protocol_stats *stats)
1667{
1668 struct qed_eth_stats eth_stats;
1669
1670 memset(stats, 0, sizeof(*stats));
1671
1672 switch (type) {
1673 case QED_MCP_LAN_STATS:
1674 qed_get_vport_stats(cdev, &eth_stats);
Mintz, Yuval9c79dda2017-03-14 16:23:54 +02001675 stats->lan_stats.ucast_rx_pkts =
1676 eth_stats.common.rx_ucast_pkts;
1677 stats->lan_stats.ucast_tx_pkts =
1678 eth_stats.common.tx_ucast_pkts;
Sudarsana Reddy Kalluru6c754242016-08-16 10:51:03 -04001679 stats->lan_stats.fcs_err = -1;
1680 break;
Arun Easi1e128c82017-02-15 06:28:22 -08001681 case QED_MCP_FCOE_STATS:
1682 qed_get_protocol_stats_fcoe(cdev, &stats->fcoe_stats);
1683 break;
Mintz, Yuval2f2b2612017-04-06 15:58:34 +03001684 case QED_MCP_ISCSI_STATS:
1685 qed_get_protocol_stats_iscsi(cdev, &stats->iscsi_stats);
1686 break;
Sudarsana Reddy Kalluru6c754242016-08-16 10:51:03 -04001687 default:
1688 DP_ERR(cdev, "Invalid protocol type = %d\n", type);
1689 return;
1690 }
1691}