blob: dcb782c14e5cb4620843bd0125e4fbc87603b624 [file] [log] [blame]
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001/* QLogic qed NIC Driver
2 * Copyright (c) 2015 QLogic Corporation
3 *
4 * This software is available under the terms of the GNU General Public License
5 * (GPL) Version 2, available from the file COPYING in the main directory of
6 * this source tree.
7 */
8
9#include <linux/stddef.h>
10#include <linux/pci.h>
11#include <linux/kernel.h>
12#include <linux/slab.h>
13#include <linux/version.h>
14#include <linux/delay.h>
15#include <asm/byteorder.h>
16#include <linux/dma-mapping.h>
17#include <linux/string.h>
18#include <linux/module.h>
19#include <linux/interrupt.h>
20#include <linux/workqueue.h>
21#include <linux/ethtool.h>
22#include <linux/etherdevice.h>
23#include <linux/vmalloc.h>
24#include <linux/qed/qed_if.h>
25
26#include "qed.h"
Yuval Mintz37bff2b2016-05-11 16:36:13 +030027#include "qed_sriov.h"
Yuval Mintzfe56b9e2015-10-26 11:02:25 +020028#include "qed_sp.h"
29#include "qed_dev_api.h"
30#include "qed_mcp.h"
31#include "qed_hw.h"
Sudarsana Reddy Kalluru03dc76c2016-04-28 20:20:52 -040032#include "qed_selftest.h"
Yuval Mintzfe56b9e2015-10-26 11:02:25 +020033
Yuval Mintz5abd7e922016-02-24 16:52:50 +020034static char version[] =
35 "QLogic FastLinQ 4xxxx Core Module qed " DRV_MODULE_VERSION "\n";
Yuval Mintzfe56b9e2015-10-26 11:02:25 +020036
Yuval Mintz5abd7e922016-02-24 16:52:50 +020037MODULE_DESCRIPTION("QLogic FastLinQ 4xxxx Core Module");
Yuval Mintzfe56b9e2015-10-26 11:02:25 +020038MODULE_LICENSE("GPL");
39MODULE_VERSION(DRV_MODULE_VERSION);
40
41#define FW_FILE_VERSION \
42 __stringify(FW_MAJOR_VERSION) "." \
43 __stringify(FW_MINOR_VERSION) "." \
44 __stringify(FW_REVISION_VERSION) "." \
45 __stringify(FW_ENGINEERING_VERSION)
46
47#define QED_FW_FILE_NAME \
48 "qed/qed_init_values_zipped-" FW_FILE_VERSION ".bin"
49
Yuval Mintzd43d3f02016-02-24 16:52:48 +020050MODULE_FIRMWARE(QED_FW_FILE_NAME);
51
Yuval Mintzfe56b9e2015-10-26 11:02:25 +020052static int __init qed_init(void)
53{
54 pr_notice("qed_init called\n");
55
56 pr_info("%s", version);
57
58 return 0;
59}
60
61static void __exit qed_cleanup(void)
62{
63 pr_notice("qed_cleanup called\n");
64}
65
66module_init(qed_init);
67module_exit(qed_cleanup);
68
69/* Check if the DMA controller on the machine can properly handle the DMA
70 * addressing required by the device.
71*/
72static int qed_set_coherency_mask(struct qed_dev *cdev)
73{
74 struct device *dev = &cdev->pdev->dev;
75
76 if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
77 if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
78 DP_NOTICE(cdev,
79 "Can't request 64-bit consistent allocations\n");
80 return -EIO;
81 }
82 } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
83 DP_NOTICE(cdev, "Can't request 64b/32b DMA addresses\n");
84 return -EIO;
85 }
86
87 return 0;
88}
89
90static void qed_free_pci(struct qed_dev *cdev)
91{
92 struct pci_dev *pdev = cdev->pdev;
93
94 if (cdev->doorbells)
95 iounmap(cdev->doorbells);
96 if (cdev->regview)
97 iounmap(cdev->regview);
98 if (atomic_read(&pdev->enable_cnt) == 1)
99 pci_release_regions(pdev);
100
101 pci_disable_device(pdev);
102}
103
Yuval Mintz0dfaba62016-02-24 16:52:49 +0200104#define PCI_REVISION_ID_ERROR_VAL 0xff
105
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200106/* Performs PCI initializations as well as initializing PCI-related parameters
107 * in the device structrue. Returns 0 in case of success.
108 */
109static int qed_init_pci(struct qed_dev *cdev,
110 struct pci_dev *pdev)
111{
Yuval Mintz0dfaba62016-02-24 16:52:49 +0200112 u8 rev_id;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200113 int rc;
114
115 cdev->pdev = pdev;
116
117 rc = pci_enable_device(pdev);
118 if (rc) {
119 DP_NOTICE(cdev, "Cannot enable PCI device\n");
120 goto err0;
121 }
122
123 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
124 DP_NOTICE(cdev, "No memory region found in bar #0\n");
125 rc = -EIO;
126 goto err1;
127 }
128
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300129 if (IS_PF(cdev) && !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200130 DP_NOTICE(cdev, "No memory region found in bar #2\n");
131 rc = -EIO;
132 goto err1;
133 }
134
135 if (atomic_read(&pdev->enable_cnt) == 1) {
136 rc = pci_request_regions(pdev, "qed");
137 if (rc) {
138 DP_NOTICE(cdev,
139 "Failed to request PCI memory resources\n");
140 goto err1;
141 }
142 pci_set_master(pdev);
143 pci_save_state(pdev);
144 }
145
Yuval Mintz0dfaba62016-02-24 16:52:49 +0200146 pci_read_config_byte(pdev, PCI_REVISION_ID, &rev_id);
147 if (rev_id == PCI_REVISION_ID_ERROR_VAL) {
148 DP_NOTICE(cdev,
149 "Detected PCI device error [rev_id 0x%x]. Probably due to prior indication. Aborting.\n",
150 rev_id);
151 rc = -ENODEV;
152 goto err2;
153 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200154 if (!pci_is_pcie(pdev)) {
155 DP_NOTICE(cdev, "The bus is not PCI Express\n");
156 rc = -EIO;
157 goto err2;
158 }
159
160 cdev->pci_params.pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
161 if (cdev->pci_params.pm_cap == 0)
162 DP_NOTICE(cdev, "Cannot find power management capability\n");
163
164 rc = qed_set_coherency_mask(cdev);
165 if (rc)
166 goto err2;
167
168 cdev->pci_params.mem_start = pci_resource_start(pdev, 0);
169 cdev->pci_params.mem_end = pci_resource_end(pdev, 0);
170 cdev->pci_params.irq = pdev->irq;
171
172 cdev->regview = pci_ioremap_bar(pdev, 0);
173 if (!cdev->regview) {
174 DP_NOTICE(cdev, "Cannot map register space, aborting\n");
175 rc = -ENOMEM;
176 goto err2;
177 }
178
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300179 if (IS_PF(cdev)) {
180 cdev->db_phys_addr = pci_resource_start(cdev->pdev, 2);
181 cdev->db_size = pci_resource_len(cdev->pdev, 2);
182 cdev->doorbells = ioremap_wc(cdev->db_phys_addr, cdev->db_size);
183 if (!cdev->doorbells) {
184 DP_NOTICE(cdev, "Cannot map doorbell space\n");
185 return -ENOMEM;
186 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200187 }
188
189 return 0;
190
191err2:
192 pci_release_regions(pdev);
193err1:
194 pci_disable_device(pdev);
195err0:
196 return rc;
197}
198
199int qed_fill_dev_info(struct qed_dev *cdev,
200 struct qed_dev_info *dev_info)
201{
Manish Chopracee4d262015-10-26 11:02:28 +0200202 struct qed_ptt *ptt;
203
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200204 memset(dev_info, 0, sizeof(struct qed_dev_info));
205
206 dev_info->num_hwfns = cdev->num_hwfns;
207 dev_info->pci_mem_start = cdev->pci_params.mem_start;
208 dev_info->pci_mem_end = cdev->pci_params.mem_end;
209 dev_info->pci_irq = cdev->pci_params.irq;
Yuval Mintzfc48b7a2016-02-15 13:22:35 -0500210 dev_info->is_mf_default = IS_MF_DEFAULT(&cdev->hwfns[0]);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200211 ether_addr_copy(dev_info->hw_mac, cdev->hwfns[0].hw_info.hw_mac_addr);
212
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300213 if (IS_PF(cdev)) {
214 dev_info->fw_major = FW_MAJOR_VERSION;
215 dev_info->fw_minor = FW_MINOR_VERSION;
216 dev_info->fw_rev = FW_REVISION_VERSION;
217 dev_info->fw_eng = FW_ENGINEERING_VERSION;
218 dev_info->mf_mode = cdev->mf_mode;
219 } else {
220 qed_vf_get_fw_version(&cdev->hwfns[0], &dev_info->fw_major,
221 &dev_info->fw_minor, &dev_info->fw_rev,
222 &dev_info->fw_eng);
223 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200224
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300225 if (IS_PF(cdev)) {
226 ptt = qed_ptt_acquire(QED_LEADING_HWFN(cdev));
227 if (ptt) {
228 qed_mcp_get_mfw_ver(QED_LEADING_HWFN(cdev), ptt,
229 &dev_info->mfw_rev, NULL);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200230
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300231 qed_mcp_get_flash_size(QED_LEADING_HWFN(cdev), ptt,
232 &dev_info->flash_size);
Manish Chopracee4d262015-10-26 11:02:28 +0200233
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300234 qed_ptt_release(QED_LEADING_HWFN(cdev), ptt);
235 }
236 } else {
237 qed_mcp_get_mfw_ver(QED_LEADING_HWFN(cdev), NULL,
238 &dev_info->mfw_rev, NULL);
Manish Chopracee4d262015-10-26 11:02:28 +0200239 }
240
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200241 return 0;
242}
243
244static void qed_free_cdev(struct qed_dev *cdev)
245{
246 kfree((void *)cdev);
247}
248
249static struct qed_dev *qed_alloc_cdev(struct pci_dev *pdev)
250{
251 struct qed_dev *cdev;
252
253 cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
254 if (!cdev)
255 return cdev;
256
257 qed_init_struct(cdev);
258
259 return cdev;
260}
261
262/* Sets the requested power state */
263static int qed_set_power_state(struct qed_dev *cdev,
264 pci_power_t state)
265{
266 if (!cdev)
267 return -ENODEV;
268
269 DP_VERBOSE(cdev, NETIF_MSG_DRV, "Omitting Power state change\n");
270 return 0;
271}
272
273/* probing */
274static struct qed_dev *qed_probe(struct pci_dev *pdev,
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300275 struct qed_probe_params *params)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200276{
277 struct qed_dev *cdev;
278 int rc;
279
280 cdev = qed_alloc_cdev(pdev);
281 if (!cdev)
282 goto err0;
283
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300284 cdev->protocol = params->protocol;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200285
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300286 if (params->is_vf)
287 cdev->b_is_vf = true;
288
289 qed_init_dp(cdev, params->dp_module, params->dp_level);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200290
291 rc = qed_init_pci(cdev, pdev);
292 if (rc) {
293 DP_ERR(cdev, "init pci failed\n");
294 goto err1;
295 }
296 DP_INFO(cdev, "PCI init completed successfully\n");
297
298 rc = qed_hw_prepare(cdev, QED_PCI_DEFAULT);
299 if (rc) {
300 DP_ERR(cdev, "hw prepare failed\n");
301 goto err2;
302 }
303
304 DP_INFO(cdev, "qed_probe completed successffuly\n");
305
306 return cdev;
307
308err2:
309 qed_free_pci(cdev);
310err1:
311 qed_free_cdev(cdev);
312err0:
313 return NULL;
314}
315
316static void qed_remove(struct qed_dev *cdev)
317{
318 if (!cdev)
319 return;
320
321 qed_hw_remove(cdev);
322
323 qed_free_pci(cdev);
324
325 qed_set_power_state(cdev, PCI_D3hot);
326
327 qed_free_cdev(cdev);
328}
329
330static void qed_disable_msix(struct qed_dev *cdev)
331{
332 if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) {
333 pci_disable_msix(cdev->pdev);
334 kfree(cdev->int_params.msix_table);
335 } else if (cdev->int_params.out.int_mode == QED_INT_MODE_MSI) {
336 pci_disable_msi(cdev->pdev);
337 }
338
339 memset(&cdev->int_params.out, 0, sizeof(struct qed_int_param));
340}
341
342static int qed_enable_msix(struct qed_dev *cdev,
343 struct qed_int_params *int_params)
344{
345 int i, rc, cnt;
346
347 cnt = int_params->in.num_vectors;
348
349 for (i = 0; i < cnt; i++)
350 int_params->msix_table[i].entry = i;
351
352 rc = pci_enable_msix_range(cdev->pdev, int_params->msix_table,
353 int_params->in.min_msix_cnt, cnt);
354 if (rc < cnt && rc >= int_params->in.min_msix_cnt &&
355 (rc % cdev->num_hwfns)) {
356 pci_disable_msix(cdev->pdev);
357
358 /* If fastpath is initialized, we need at least one interrupt
359 * per hwfn [and the slow path interrupts]. New requested number
360 * should be a multiple of the number of hwfns.
361 */
362 cnt = (rc / cdev->num_hwfns) * cdev->num_hwfns;
363 DP_NOTICE(cdev,
364 "Trying to enable MSI-X with less vectors (%d out of %d)\n",
365 cnt, int_params->in.num_vectors);
366 rc = pci_enable_msix_exact(cdev->pdev,
367 int_params->msix_table, cnt);
368 if (!rc)
369 rc = cnt;
370 }
371
372 if (rc > 0) {
373 /* MSI-x configuration was achieved */
374 int_params->out.int_mode = QED_INT_MODE_MSIX;
375 int_params->out.num_vectors = rc;
376 rc = 0;
377 } else {
378 DP_NOTICE(cdev,
379 "Failed to enable MSI-X [Requested %d vectors][rc %d]\n",
380 cnt, rc);
381 }
382
383 return rc;
384}
385
386/* This function outputs the int mode and the number of enabled msix vector */
387static int qed_set_int_mode(struct qed_dev *cdev, bool force_mode)
388{
389 struct qed_int_params *int_params = &cdev->int_params;
390 struct msix_entry *tbl;
391 int rc = 0, cnt;
392
393 switch (int_params->in.int_mode) {
394 case QED_INT_MODE_MSIX:
395 /* Allocate MSIX table */
396 cnt = int_params->in.num_vectors;
397 int_params->msix_table = kcalloc(cnt, sizeof(*tbl), GFP_KERNEL);
398 if (!int_params->msix_table) {
399 rc = -ENOMEM;
400 goto out;
401 }
402
403 /* Enable MSIX */
404 rc = qed_enable_msix(cdev, int_params);
405 if (!rc)
406 goto out;
407
408 DP_NOTICE(cdev, "Failed to enable MSI-X\n");
409 kfree(int_params->msix_table);
410 if (force_mode)
411 goto out;
412 /* Fallthrough */
413
414 case QED_INT_MODE_MSI:
415 rc = pci_enable_msi(cdev->pdev);
416 if (!rc) {
417 int_params->out.int_mode = QED_INT_MODE_MSI;
418 goto out;
419 }
420
421 DP_NOTICE(cdev, "Failed to enable MSI\n");
422 if (force_mode)
423 goto out;
424 /* Fallthrough */
425
426 case QED_INT_MODE_INTA:
427 int_params->out.int_mode = QED_INT_MODE_INTA;
428 rc = 0;
429 goto out;
430 default:
431 DP_NOTICE(cdev, "Unknown int_mode value %d\n",
432 int_params->in.int_mode);
433 rc = -EINVAL;
434 }
435
436out:
437 cdev->int_coalescing_mode = QED_COAL_MODE_ENABLE;
438
439 return rc;
440}
441
442static void qed_simd_handler_config(struct qed_dev *cdev, void *token,
443 int index, void(*handler)(void *))
444{
445 struct qed_hwfn *hwfn = &cdev->hwfns[index % cdev->num_hwfns];
446 int relative_idx = index / cdev->num_hwfns;
447
448 hwfn->simd_proto_handler[relative_idx].func = handler;
449 hwfn->simd_proto_handler[relative_idx].token = token;
450}
451
452static void qed_simd_handler_clean(struct qed_dev *cdev, int index)
453{
454 struct qed_hwfn *hwfn = &cdev->hwfns[index % cdev->num_hwfns];
455 int relative_idx = index / cdev->num_hwfns;
456
457 memset(&hwfn->simd_proto_handler[relative_idx], 0,
458 sizeof(struct qed_simd_fp_handler));
459}
460
461static irqreturn_t qed_msix_sp_int(int irq, void *tasklet)
462{
463 tasklet_schedule((struct tasklet_struct *)tasklet);
464 return IRQ_HANDLED;
465}
466
467static irqreturn_t qed_single_int(int irq, void *dev_instance)
468{
469 struct qed_dev *cdev = (struct qed_dev *)dev_instance;
470 struct qed_hwfn *hwfn;
471 irqreturn_t rc = IRQ_NONE;
472 u64 status;
473 int i, j;
474
475 for (i = 0; i < cdev->num_hwfns; i++) {
476 status = qed_int_igu_read_sisr_reg(&cdev->hwfns[i]);
477
478 if (!status)
479 continue;
480
481 hwfn = &cdev->hwfns[i];
482
483 /* Slowpath interrupt */
484 if (unlikely(status & 0x1)) {
485 tasklet_schedule(hwfn->sp_dpc);
486 status &= ~0x1;
487 rc = IRQ_HANDLED;
488 }
489
490 /* Fastpath interrupts */
491 for (j = 0; j < 64; j++) {
492 if ((0x2ULL << j) & status) {
493 hwfn->simd_proto_handler[j].func(
494 hwfn->simd_proto_handler[j].token);
495 status &= ~(0x2ULL << j);
496 rc = IRQ_HANDLED;
497 }
498 }
499
500 if (unlikely(status))
501 DP_VERBOSE(hwfn, NETIF_MSG_INTR,
502 "got an unknown interrupt status 0x%llx\n",
503 status);
504 }
505
506 return rc;
507}
508
Sudarsana Kalluru8f16bc92015-12-07 06:25:59 -0500509int qed_slowpath_irq_req(struct qed_hwfn *hwfn)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200510{
Sudarsana Kalluru8f16bc92015-12-07 06:25:59 -0500511 struct qed_dev *cdev = hwfn->cdev;
512 int rc = 0;
513 u8 id;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200514
515 if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) {
Sudarsana Kalluru8f16bc92015-12-07 06:25:59 -0500516 id = hwfn->my_id;
517 snprintf(hwfn->name, NAME_SIZE, "sp-%d-%02x:%02x.%02x",
518 id, cdev->pdev->bus->number,
519 PCI_SLOT(cdev->pdev->devfn), hwfn->abs_pf_id);
520 rc = request_irq(cdev->int_params.msix_table[id].vector,
521 qed_msix_sp_int, 0, hwfn->name, hwfn->sp_dpc);
522 if (!rc)
523 DP_VERBOSE(hwfn, (NETIF_MSG_INTR | QED_MSG_SP),
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200524 "Requested slowpath MSI-X\n");
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200525 } else {
526 unsigned long flags = 0;
527
528 snprintf(cdev->name, NAME_SIZE, "%02x:%02x.%02x",
529 cdev->pdev->bus->number, PCI_SLOT(cdev->pdev->devfn),
530 PCI_FUNC(cdev->pdev->devfn));
531
532 if (cdev->int_params.out.int_mode == QED_INT_MODE_INTA)
533 flags |= IRQF_SHARED;
534
535 rc = request_irq(cdev->pdev->irq, qed_single_int,
536 flags, cdev->name, cdev);
537 }
538
539 return rc;
540}
541
542static void qed_slowpath_irq_free(struct qed_dev *cdev)
543{
544 int i;
545
546 if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) {
547 for_each_hwfn(cdev, i) {
Sudarsana Kalluru8f16bc92015-12-07 06:25:59 -0500548 if (!cdev->hwfns[i].b_int_requested)
549 break;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200550 synchronize_irq(cdev->int_params.msix_table[i].vector);
551 free_irq(cdev->int_params.msix_table[i].vector,
552 cdev->hwfns[i].sp_dpc);
553 }
554 } else {
Sudarsana Kalluru8f16bc92015-12-07 06:25:59 -0500555 if (QED_LEADING_HWFN(cdev)->b_int_requested)
556 free_irq(cdev->pdev->irq, cdev);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200557 }
Sudarsana Kalluru8f16bc92015-12-07 06:25:59 -0500558 qed_int_disable_post_isr_release(cdev);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200559}
560
561static int qed_nic_stop(struct qed_dev *cdev)
562{
563 int i, rc;
564
565 rc = qed_hw_stop(cdev);
566
567 for (i = 0; i < cdev->num_hwfns; i++) {
568 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
569
570 if (p_hwfn->b_sp_dpc_enabled) {
571 tasklet_disable(p_hwfn->sp_dpc);
572 p_hwfn->b_sp_dpc_enabled = false;
573 DP_VERBOSE(cdev, NETIF_MSG_IFDOWN,
574 "Disabled sp taskelt [hwfn %d] at %p\n",
575 i, p_hwfn->sp_dpc);
576 }
577 }
578
579 return rc;
580}
581
582static int qed_nic_reset(struct qed_dev *cdev)
583{
584 int rc;
585
586 rc = qed_hw_reset(cdev);
587 if (rc)
588 return rc;
589
590 qed_resc_free(cdev);
591
592 return 0;
593}
594
595static int qed_nic_setup(struct qed_dev *cdev)
596{
597 int rc;
598
599 rc = qed_resc_alloc(cdev);
600 if (rc)
601 return rc;
602
603 DP_INFO(cdev, "Allocated qed resources\n");
604
605 qed_resc_setup(cdev);
606
607 return rc;
608}
609
610static int qed_set_int_fp(struct qed_dev *cdev, u16 cnt)
611{
612 int limit = 0;
613
614 /* Mark the fastpath as free/used */
615 cdev->int_params.fp_initialized = cnt ? true : false;
616
617 if (cdev->int_params.out.int_mode != QED_INT_MODE_MSIX)
618 limit = cdev->num_hwfns * 63;
619 else if (cdev->int_params.fp_msix_cnt)
620 limit = cdev->int_params.fp_msix_cnt;
621
622 if (!limit)
623 return -ENOMEM;
624
625 return min_t(int, cnt, limit);
626}
627
628static int qed_get_int_fp(struct qed_dev *cdev, struct qed_int_info *info)
629{
630 memset(info, 0, sizeof(struct qed_int_info));
631
632 if (!cdev->int_params.fp_initialized) {
633 DP_INFO(cdev,
634 "Protocol driver requested interrupt information, but its support is not yet configured\n");
635 return -EINVAL;
636 }
637
638 /* Need to expose only MSI-X information; Single IRQ is handled solely
639 * by qed.
640 */
641 if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) {
642 int msix_base = cdev->int_params.fp_msix_base;
643
644 info->msix_cnt = cdev->int_params.fp_msix_cnt;
645 info->msix = &cdev->int_params.msix_table[msix_base];
646 }
647
648 return 0;
649}
650
651static int qed_slowpath_setup_int(struct qed_dev *cdev,
652 enum qed_int_mode int_mode)
653{
Yuval Mintz4ac801b2016-02-28 12:26:52 +0200654 struct qed_sb_cnt_info sb_cnt_info;
655 int rc;
656 int i;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200657 memset(&cdev->int_params, 0, sizeof(struct qed_int_params));
658
659 cdev->int_params.in.int_mode = int_mode;
Yuval Mintz4ac801b2016-02-28 12:26:52 +0200660 for_each_hwfn(cdev, i) {
661 memset(&sb_cnt_info, 0, sizeof(sb_cnt_info));
662 qed_int_get_num_sbs(&cdev->hwfns[i], &sb_cnt_info);
663 cdev->int_params.in.num_vectors += sb_cnt_info.sb_cnt;
664 cdev->int_params.in.num_vectors++; /* slowpath */
665 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200666
667 /* We want a minimum of one slowpath and one fastpath vector per hwfn */
668 cdev->int_params.in.min_msix_cnt = cdev->num_hwfns * 2;
669
670 rc = qed_set_int_mode(cdev, false);
671 if (rc) {
672 DP_ERR(cdev, "qed_slowpath_setup_int ERR\n");
673 return rc;
674 }
675
676 cdev->int_params.fp_msix_base = cdev->num_hwfns;
677 cdev->int_params.fp_msix_cnt = cdev->int_params.out.num_vectors -
678 cdev->num_hwfns;
679
680 return 0;
681}
682
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300683static int qed_slowpath_vf_setup_int(struct qed_dev *cdev)
684{
685 int rc;
686
687 memset(&cdev->int_params, 0, sizeof(struct qed_int_params));
688 cdev->int_params.in.int_mode = QED_INT_MODE_MSIX;
689
690 qed_vf_get_num_rxqs(QED_LEADING_HWFN(cdev),
691 &cdev->int_params.in.num_vectors);
692 if (cdev->num_hwfns > 1) {
693 u8 vectors = 0;
694
695 qed_vf_get_num_rxqs(&cdev->hwfns[1], &vectors);
696 cdev->int_params.in.num_vectors += vectors;
697 }
698
699 /* We want a minimum of one fastpath vector per vf hwfn */
700 cdev->int_params.in.min_msix_cnt = cdev->num_hwfns;
701
702 rc = qed_set_int_mode(cdev, true);
703 if (rc)
704 return rc;
705
706 cdev->int_params.fp_msix_base = 0;
707 cdev->int_params.fp_msix_cnt = cdev->int_params.out.num_vectors;
708
709 return 0;
710}
711
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200712u32 qed_unzip_data(struct qed_hwfn *p_hwfn, u32 input_len,
713 u8 *input_buf, u32 max_size, u8 *unzip_buf)
714{
715 int rc;
716
717 p_hwfn->stream->next_in = input_buf;
718 p_hwfn->stream->avail_in = input_len;
719 p_hwfn->stream->next_out = unzip_buf;
720 p_hwfn->stream->avail_out = max_size;
721
722 rc = zlib_inflateInit2(p_hwfn->stream, MAX_WBITS);
723
724 if (rc != Z_OK) {
725 DP_VERBOSE(p_hwfn, NETIF_MSG_DRV, "zlib init failed, rc = %d\n",
726 rc);
727 return 0;
728 }
729
730 rc = zlib_inflate(p_hwfn->stream, Z_FINISH);
731 zlib_inflateEnd(p_hwfn->stream);
732
733 if (rc != Z_OK && rc != Z_STREAM_END) {
734 DP_VERBOSE(p_hwfn, NETIF_MSG_DRV, "FW unzip error: %s, rc=%d\n",
735 p_hwfn->stream->msg, rc);
736 return 0;
737 }
738
739 return p_hwfn->stream->total_out / 4;
740}
741
742static int qed_alloc_stream_mem(struct qed_dev *cdev)
743{
744 int i;
745 void *workspace;
746
747 for_each_hwfn(cdev, i) {
748 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
749
750 p_hwfn->stream = kzalloc(sizeof(*p_hwfn->stream), GFP_KERNEL);
751 if (!p_hwfn->stream)
752 return -ENOMEM;
753
754 workspace = vzalloc(zlib_inflate_workspacesize());
755 if (!workspace)
756 return -ENOMEM;
757 p_hwfn->stream->workspace = workspace;
758 }
759
760 return 0;
761}
762
763static void qed_free_stream_mem(struct qed_dev *cdev)
764{
765 int i;
766
767 for_each_hwfn(cdev, i) {
768 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
769
770 if (!p_hwfn->stream)
771 return;
772
773 vfree(p_hwfn->stream->workspace);
774 kfree(p_hwfn->stream);
775 }
776}
777
778static void qed_update_pf_params(struct qed_dev *cdev,
779 struct qed_pf_params *params)
780{
781 int i;
782
783 for (i = 0; i < cdev->num_hwfns; i++) {
784 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
785
786 p_hwfn->pf_params = *params;
787 }
788}
789
790static int qed_slowpath_start(struct qed_dev *cdev,
791 struct qed_slowpath_params *params)
792{
Manish Choprab18e1702016-04-14 01:38:30 -0400793 struct qed_tunn_start_params tunn_info;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200794 struct qed_mcp_drv_version drv_version;
795 const u8 *data = NULL;
796 struct qed_hwfn *hwfn;
Yuval Mintz37bff2b2016-05-11 16:36:13 +0300797 int rc = -EINVAL;
798
799 if (qed_iov_wq_start(cdev))
800 goto err;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200801
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300802 if (IS_PF(cdev)) {
803 rc = request_firmware(&cdev->firmware, QED_FW_FILE_NAME,
804 &cdev->pdev->dev);
805 if (rc) {
806 DP_NOTICE(cdev,
807 "Failed to find fw file - /lib/firmware/%s\n",
808 QED_FW_FILE_NAME);
809 goto err;
810 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200811 }
812
813 rc = qed_nic_setup(cdev);
814 if (rc)
815 goto err;
816
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300817 if (IS_PF(cdev))
818 rc = qed_slowpath_setup_int(cdev, params->int_mode);
819 else
820 rc = qed_slowpath_vf_setup_int(cdev);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200821 if (rc)
822 goto err1;
823
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300824 if (IS_PF(cdev)) {
825 /* Allocate stream for unzipping */
826 rc = qed_alloc_stream_mem(cdev);
827 if (rc) {
828 DP_NOTICE(cdev, "Failed to allocate stream memory\n");
829 goto err2;
830 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200831
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300832 data = cdev->firmware->data;
833 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200834
Manish Choprab18e1702016-04-14 01:38:30 -0400835 memset(&tunn_info, 0, sizeof(tunn_info));
Manish Chopra9a109dd2016-04-14 01:38:31 -0400836 tunn_info.tunn_mode |= 1 << QED_MODE_VXLAN_TUNN |
Manish Chopraf7985862016-04-14 01:38:32 -0400837 1 << QED_MODE_L2GRE_TUNN |
838 1 << QED_MODE_IPGRE_TUNN |
Manish Chopra9a109dd2016-04-14 01:38:31 -0400839 1 << QED_MODE_L2GENEVE_TUNN |
840 1 << QED_MODE_IPGENEVE_TUNN;
841
Manish Choprab18e1702016-04-14 01:38:30 -0400842 tunn_info.tunn_clss_vxlan = QED_TUNN_CLSS_MAC_VLAN;
Manish Chopraf7985862016-04-14 01:38:32 -0400843 tunn_info.tunn_clss_l2gre = QED_TUNN_CLSS_MAC_VLAN;
844 tunn_info.tunn_clss_ipgre = QED_TUNN_CLSS_MAC_VLAN;
Manish Choprab18e1702016-04-14 01:38:30 -0400845
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300846 /* Start the slowpath */
Manish Choprab18e1702016-04-14 01:38:30 -0400847 rc = qed_hw_init(cdev, &tunn_info, true,
848 cdev->int_params.out.int_mode,
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200849 true, data);
850 if (rc)
Yuval Mintz8c925c42016-03-02 20:26:03 +0200851 goto err2;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200852
853 DP_INFO(cdev,
854 "HW initialization and function start completed successfully\n");
855
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300856 if (IS_PF(cdev)) {
857 hwfn = QED_LEADING_HWFN(cdev);
858 drv_version.version = (params->drv_major << 24) |
859 (params->drv_minor << 16) |
860 (params->drv_rev << 8) |
861 (params->drv_eng);
862 strlcpy(drv_version.name, params->name,
863 MCP_DRV_VER_STR_SIZE - 4);
864 rc = qed_mcp_send_drv_version(hwfn, hwfn->p_main_ptt,
865 &drv_version);
866 if (rc) {
867 DP_NOTICE(cdev, "Failed sending drv version command\n");
868 return rc;
869 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200870 }
871
Yuval Mintz8c925c42016-03-02 20:26:03 +0200872 qed_reset_vport_stats(cdev);
873
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200874 return 0;
875
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200876err2:
Yuval Mintz8c925c42016-03-02 20:26:03 +0200877 qed_hw_timers_stop_all(cdev);
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300878 if (IS_PF(cdev))
879 qed_slowpath_irq_free(cdev);
Yuval Mintz8c925c42016-03-02 20:26:03 +0200880 qed_free_stream_mem(cdev);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200881 qed_disable_msix(cdev);
882err1:
883 qed_resc_free(cdev);
884err:
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300885 if (IS_PF(cdev))
886 release_firmware(cdev->firmware);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200887
Yuval Mintz37bff2b2016-05-11 16:36:13 +0300888 qed_iov_wq_stop(cdev, false);
889
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200890 return rc;
891}
892
893static int qed_slowpath_stop(struct qed_dev *cdev)
894{
895 if (!cdev)
896 return -ENODEV;
897
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300898 if (IS_PF(cdev)) {
899 qed_free_stream_mem(cdev);
Yuval Mintz0b55e272016-05-11 16:36:15 +0300900 qed_sriov_disable(cdev, true);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200901
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300902 qed_nic_stop(cdev);
903 qed_slowpath_irq_free(cdev);
904 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200905
906 qed_disable_msix(cdev);
907 qed_nic_reset(cdev);
908
Yuval Mintz37bff2b2016-05-11 16:36:13 +0300909 qed_iov_wq_stop(cdev, true);
910
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300911 if (IS_PF(cdev))
912 release_firmware(cdev->firmware);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200913
914 return 0;
915}
916
917static void qed_set_id(struct qed_dev *cdev, char name[NAME_SIZE],
918 char ver_str[VER_SIZE])
919{
920 int i;
921
922 memcpy(cdev->name, name, NAME_SIZE);
923 for_each_hwfn(cdev, i)
924 snprintf(cdev->hwfns[i].name, NAME_SIZE, "%s-%d", name, i);
925
926 memcpy(cdev->ver_str, ver_str, VER_SIZE);
927 cdev->drv_type = DRV_ID_DRV_TYPE_LINUX;
928}
929
930static u32 qed_sb_init(struct qed_dev *cdev,
931 struct qed_sb_info *sb_info,
932 void *sb_virt_addr,
933 dma_addr_t sb_phy_addr, u16 sb_id,
934 enum qed_sb_type type)
935{
936 struct qed_hwfn *p_hwfn;
937 int hwfn_index;
938 u16 rel_sb_id;
939 u8 n_hwfns;
940 u32 rc;
941
942 /* RoCE uses single engine and CMT uses two engines. When using both
943 * we force only a single engine. Storage uses only engine 0 too.
944 */
945 if (type == QED_SB_TYPE_L2_QUEUE)
946 n_hwfns = cdev->num_hwfns;
947 else
948 n_hwfns = 1;
949
950 hwfn_index = sb_id % n_hwfns;
951 p_hwfn = &cdev->hwfns[hwfn_index];
952 rel_sb_id = sb_id / n_hwfns;
953
954 DP_VERBOSE(cdev, NETIF_MSG_INTR,
955 "hwfn [%d] <--[init]-- SB %04x [0x%04x upper]\n",
956 hwfn_index, rel_sb_id, sb_id);
957
958 rc = qed_int_sb_init(p_hwfn, p_hwfn->p_main_ptt, sb_info,
959 sb_virt_addr, sb_phy_addr, rel_sb_id);
960
961 return rc;
962}
963
964static u32 qed_sb_release(struct qed_dev *cdev,
965 struct qed_sb_info *sb_info,
966 u16 sb_id)
967{
968 struct qed_hwfn *p_hwfn;
969 int hwfn_index;
970 u16 rel_sb_id;
971 u32 rc;
972
973 hwfn_index = sb_id % cdev->num_hwfns;
974 p_hwfn = &cdev->hwfns[hwfn_index];
975 rel_sb_id = sb_id / cdev->num_hwfns;
976
977 DP_VERBOSE(cdev, NETIF_MSG_INTR,
978 "hwfn [%d] <--[init]-- SB %04x [0x%04x upper]\n",
979 hwfn_index, rel_sb_id, sb_id);
980
981 rc = qed_int_sb_release(p_hwfn, sb_info, rel_sb_id);
982
983 return rc;
984}
985
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +0300986static bool qed_can_link_change(struct qed_dev *cdev)
987{
988 return true;
989}
990
Yuval Mintzcc875c22015-10-26 11:02:31 +0200991static int qed_set_link(struct qed_dev *cdev,
992 struct qed_link_params *params)
993{
994 struct qed_hwfn *hwfn;
995 struct qed_mcp_link_params *link_params;
996 struct qed_ptt *ptt;
997 int rc;
998
999 if (!cdev)
1000 return -ENODEV;
1001
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001002 if (IS_VF(cdev))
1003 return 0;
1004
Yuval Mintzcc875c22015-10-26 11:02:31 +02001005 /* The link should be set only once per PF */
1006 hwfn = &cdev->hwfns[0];
1007
1008 ptt = qed_ptt_acquire(hwfn);
1009 if (!ptt)
1010 return -EBUSY;
1011
1012 link_params = qed_mcp_get_link_params(hwfn);
1013 if (params->override_flags & QED_LINK_OVERRIDE_SPEED_AUTONEG)
1014 link_params->speed.autoneg = params->autoneg;
1015 if (params->override_flags & QED_LINK_OVERRIDE_SPEED_ADV_SPEEDS) {
1016 link_params->speed.advertised_speeds = 0;
1017 if ((params->adv_speeds & SUPPORTED_1000baseT_Half) ||
1018 (params->adv_speeds & SUPPORTED_1000baseT_Full))
1019 link_params->speed.advertised_speeds |=
1020 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G;
1021 if (params->adv_speeds & SUPPORTED_10000baseKR_Full)
1022 link_params->speed.advertised_speeds |=
1023 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G;
1024 if (params->adv_speeds & SUPPORTED_40000baseLR4_Full)
1025 link_params->speed.advertised_speeds |=
1026 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G;
1027 if (params->adv_speeds & 0)
1028 link_params->speed.advertised_speeds |=
1029 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_50G;
1030 if (params->adv_speeds & 0)
1031 link_params->speed.advertised_speeds |=
1032 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_100G;
1033 }
1034 if (params->override_flags & QED_LINK_OVERRIDE_SPEED_FORCED_SPEED)
1035 link_params->speed.forced_speed = params->forced_speed;
Sudarsana Reddy Kallurua43f2352016-04-22 08:41:04 +03001036 if (params->override_flags & QED_LINK_OVERRIDE_PAUSE_CONFIG) {
1037 if (params->pause_config & QED_LINK_PAUSE_AUTONEG_ENABLE)
1038 link_params->pause.autoneg = true;
1039 else
1040 link_params->pause.autoneg = false;
1041 if (params->pause_config & QED_LINK_PAUSE_RX_ENABLE)
1042 link_params->pause.forced_rx = true;
1043 else
1044 link_params->pause.forced_rx = false;
1045 if (params->pause_config & QED_LINK_PAUSE_TX_ENABLE)
1046 link_params->pause.forced_tx = true;
1047 else
1048 link_params->pause.forced_tx = false;
1049 }
Sudarsana Reddy Kalluru03dc76c2016-04-28 20:20:52 -04001050 if (params->override_flags & QED_LINK_OVERRIDE_LOOPBACK_MODE) {
1051 switch (params->loopback_mode) {
1052 case QED_LINK_LOOPBACK_INT_PHY:
1053 link_params->loopback_mode = PMM_LOOPBACK_INT_PHY;
1054 break;
1055 case QED_LINK_LOOPBACK_EXT_PHY:
1056 link_params->loopback_mode = PMM_LOOPBACK_EXT_PHY;
1057 break;
1058 case QED_LINK_LOOPBACK_EXT:
1059 link_params->loopback_mode = PMM_LOOPBACK_EXT;
1060 break;
1061 case QED_LINK_LOOPBACK_MAC:
1062 link_params->loopback_mode = PMM_LOOPBACK_MAC;
1063 break;
1064 default:
1065 link_params->loopback_mode = PMM_LOOPBACK_NONE;
1066 break;
1067 }
1068 }
Yuval Mintzcc875c22015-10-26 11:02:31 +02001069
1070 rc = qed_mcp_set_link(hwfn, ptt, params->link_up);
1071
1072 qed_ptt_release(hwfn, ptt);
1073
1074 return rc;
1075}
1076
1077static int qed_get_port_type(u32 media_type)
1078{
1079 int port_type;
1080
1081 switch (media_type) {
1082 case MEDIA_SFPP_10G_FIBER:
1083 case MEDIA_SFP_1G_FIBER:
1084 case MEDIA_XFP_FIBER:
1085 case MEDIA_KR:
1086 port_type = PORT_FIBRE;
1087 break;
1088 case MEDIA_DA_TWINAX:
1089 port_type = PORT_DA;
1090 break;
1091 case MEDIA_BASE_T:
1092 port_type = PORT_TP;
1093 break;
1094 case MEDIA_NOT_PRESENT:
1095 port_type = PORT_NONE;
1096 break;
1097 case MEDIA_UNSPECIFIED:
1098 default:
1099 port_type = PORT_OTHER;
1100 break;
1101 }
1102 return port_type;
1103}
1104
1105static void qed_fill_link(struct qed_hwfn *hwfn,
1106 struct qed_link_output *if_link)
1107{
1108 struct qed_mcp_link_params params;
1109 struct qed_mcp_link_state link;
1110 struct qed_mcp_link_capabilities link_caps;
1111 u32 media_type;
1112
1113 memset(if_link, 0, sizeof(*if_link));
1114
1115 /* Prepare source inputs */
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001116 if (IS_PF(hwfn->cdev)) {
1117 memcpy(&params, qed_mcp_get_link_params(hwfn), sizeof(params));
1118 memcpy(&link, qed_mcp_get_link_state(hwfn), sizeof(link));
1119 memcpy(&link_caps, qed_mcp_get_link_capabilities(hwfn),
1120 sizeof(link_caps));
1121 } else {
Yuval Mintz36558c32016-05-11 16:36:17 +03001122 qed_vf_get_link_params(hwfn, &params);
1123 qed_vf_get_link_state(hwfn, &link);
1124 qed_vf_get_link_caps(hwfn, &link_caps);
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001125 }
Yuval Mintzcc875c22015-10-26 11:02:31 +02001126
1127 /* Set the link parameters to pass to protocol driver */
1128 if (link.link_up)
1129 if_link->link_up = true;
1130
1131 /* TODO - at the moment assume supported and advertised speed equal */
1132 if_link->supported_caps = SUPPORTED_FIBRE;
1133 if (params.speed.autoneg)
1134 if_link->supported_caps |= SUPPORTED_Autoneg;
1135 if (params.pause.autoneg ||
1136 (params.pause.forced_rx && params.pause.forced_tx))
1137 if_link->supported_caps |= SUPPORTED_Asym_Pause;
1138 if (params.pause.autoneg || params.pause.forced_rx ||
1139 params.pause.forced_tx)
1140 if_link->supported_caps |= SUPPORTED_Pause;
1141
1142 if_link->advertised_caps = if_link->supported_caps;
1143 if (params.speed.advertised_speeds &
1144 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G)
1145 if_link->advertised_caps |= SUPPORTED_1000baseT_Half |
1146 SUPPORTED_1000baseT_Full;
1147 if (params.speed.advertised_speeds &
1148 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G)
1149 if_link->advertised_caps |= SUPPORTED_10000baseKR_Full;
1150 if (params.speed.advertised_speeds &
1151 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G)
1152 if_link->advertised_caps |= SUPPORTED_40000baseLR4_Full;
1153 if (params.speed.advertised_speeds &
1154 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_50G)
1155 if_link->advertised_caps |= 0;
1156 if (params.speed.advertised_speeds &
1157 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_100G)
1158 if_link->advertised_caps |= 0;
1159
1160 if (link_caps.speed_capabilities &
1161 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G)
1162 if_link->supported_caps |= SUPPORTED_1000baseT_Half |
1163 SUPPORTED_1000baseT_Full;
1164 if (link_caps.speed_capabilities &
1165 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G)
1166 if_link->supported_caps |= SUPPORTED_10000baseKR_Full;
1167 if (link_caps.speed_capabilities &
1168 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G)
1169 if_link->supported_caps |= SUPPORTED_40000baseLR4_Full;
1170 if (link_caps.speed_capabilities &
1171 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_50G)
1172 if_link->supported_caps |= 0;
1173 if (link_caps.speed_capabilities &
1174 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_100G)
1175 if_link->supported_caps |= 0;
1176
1177 if (link.link_up)
1178 if_link->speed = link.speed;
1179
1180 /* TODO - fill duplex properly */
1181 if_link->duplex = DUPLEX_FULL;
1182 qed_mcp_get_media_type(hwfn->cdev, &media_type);
1183 if_link->port = qed_get_port_type(media_type);
1184
1185 if_link->autoneg = params.speed.autoneg;
1186
1187 if (params.pause.autoneg)
1188 if_link->pause_config |= QED_LINK_PAUSE_AUTONEG_ENABLE;
1189 if (params.pause.forced_rx)
1190 if_link->pause_config |= QED_LINK_PAUSE_RX_ENABLE;
1191 if (params.pause.forced_tx)
1192 if_link->pause_config |= QED_LINK_PAUSE_TX_ENABLE;
1193
1194 /* Link partner capabilities */
1195 if (link.partner_adv_speed &
1196 QED_LINK_PARTNER_SPEED_1G_HD)
1197 if_link->lp_caps |= SUPPORTED_1000baseT_Half;
1198 if (link.partner_adv_speed &
1199 QED_LINK_PARTNER_SPEED_1G_FD)
1200 if_link->lp_caps |= SUPPORTED_1000baseT_Full;
1201 if (link.partner_adv_speed &
1202 QED_LINK_PARTNER_SPEED_10G)
1203 if_link->lp_caps |= SUPPORTED_10000baseKR_Full;
1204 if (link.partner_adv_speed &
1205 QED_LINK_PARTNER_SPEED_40G)
1206 if_link->lp_caps |= SUPPORTED_40000baseLR4_Full;
1207 if (link.partner_adv_speed &
1208 QED_LINK_PARTNER_SPEED_50G)
1209 if_link->lp_caps |= 0;
1210 if (link.partner_adv_speed &
1211 QED_LINK_PARTNER_SPEED_100G)
1212 if_link->lp_caps |= 0;
1213
1214 if (link.an_complete)
1215 if_link->lp_caps |= SUPPORTED_Autoneg;
1216
1217 if (link.partner_adv_pause)
1218 if_link->lp_caps |= SUPPORTED_Pause;
1219 if (link.partner_adv_pause == QED_LINK_PARTNER_ASYMMETRIC_PAUSE ||
1220 link.partner_adv_pause == QED_LINK_PARTNER_BOTH_PAUSE)
1221 if_link->lp_caps |= SUPPORTED_Asym_Pause;
1222}
1223
1224static void qed_get_current_link(struct qed_dev *cdev,
1225 struct qed_link_output *if_link)
1226{
Yuval Mintz36558c32016-05-11 16:36:17 +03001227 int i;
1228
Yuval Mintzcc875c22015-10-26 11:02:31 +02001229 qed_fill_link(&cdev->hwfns[0], if_link);
Yuval Mintz36558c32016-05-11 16:36:17 +03001230
1231 for_each_hwfn(cdev, i)
1232 qed_inform_vf_link_state(&cdev->hwfns[i]);
Yuval Mintzcc875c22015-10-26 11:02:31 +02001233}
1234
1235void qed_link_update(struct qed_hwfn *hwfn)
1236{
1237 void *cookie = hwfn->cdev->ops_cookie;
1238 struct qed_common_cb_ops *op = hwfn->cdev->protocol_ops.common;
1239 struct qed_link_output if_link;
1240
1241 qed_fill_link(hwfn, &if_link);
Yuval Mintz36558c32016-05-11 16:36:17 +03001242 qed_inform_vf_link_state(hwfn);
Yuval Mintzcc875c22015-10-26 11:02:31 +02001243
1244 if (IS_LEAD_HWFN(hwfn) && cookie)
1245 op->link_update(cookie, &if_link);
1246}
1247
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001248static int qed_drain(struct qed_dev *cdev)
1249{
1250 struct qed_hwfn *hwfn;
1251 struct qed_ptt *ptt;
1252 int i, rc;
1253
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001254 if (IS_VF(cdev))
1255 return 0;
1256
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001257 for_each_hwfn(cdev, i) {
1258 hwfn = &cdev->hwfns[i];
1259 ptt = qed_ptt_acquire(hwfn);
1260 if (!ptt) {
1261 DP_NOTICE(hwfn, "Failed to drain NIG; No PTT\n");
1262 return -EBUSY;
1263 }
1264 rc = qed_mcp_drain(hwfn, ptt);
1265 if (rc)
1266 return rc;
1267 qed_ptt_release(hwfn, ptt);
1268 }
1269
1270 return 0;
1271}
1272
Sudarsana Kalluru91420b82015-11-30 12:25:03 +02001273static int qed_set_led(struct qed_dev *cdev, enum qed_led_mode mode)
1274{
1275 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1276 struct qed_ptt *ptt;
1277 int status = 0;
1278
1279 ptt = qed_ptt_acquire(hwfn);
1280 if (!ptt)
1281 return -EAGAIN;
1282
1283 status = qed_mcp_set_led(hwfn, ptt, mode);
1284
1285 qed_ptt_release(hwfn, ptt);
1286
1287 return status;
1288}
1289
Sudarsana Reddy Kalluru03dc76c2016-04-28 20:20:52 -04001290struct qed_selftest_ops qed_selftest_ops_pass = {
1291 .selftest_memory = &qed_selftest_memory,
1292 .selftest_interrupt = &qed_selftest_interrupt,
1293 .selftest_register = &qed_selftest_register,
1294 .selftest_clock = &qed_selftest_clock,
1295};
1296
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001297const struct qed_common_ops qed_common_ops_pass = {
Sudarsana Reddy Kalluru03dc76c2016-04-28 20:20:52 -04001298 .selftest = &qed_selftest_ops_pass,
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001299 .probe = &qed_probe,
1300 .remove = &qed_remove,
1301 .set_power_state = &qed_set_power_state,
1302 .set_id = &qed_set_id,
1303 .update_pf_params = &qed_update_pf_params,
1304 .slowpath_start = &qed_slowpath_start,
1305 .slowpath_stop = &qed_slowpath_stop,
1306 .set_fp_int = &qed_set_int_fp,
1307 .get_fp_int = &qed_get_int_fp,
1308 .sb_init = &qed_sb_init,
1309 .sb_release = &qed_sb_release,
1310 .simd_handler_config = &qed_simd_handler_config,
1311 .simd_handler_clean = &qed_simd_handler_clean,
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +03001312 .can_link_change = &qed_can_link_change,
Yuval Mintzcc875c22015-10-26 11:02:31 +02001313 .set_link = &qed_set_link,
1314 .get_link = &qed_get_current_link,
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001315 .drain = &qed_drain,
1316 .update_msglvl = &qed_init_dp,
1317 .chain_alloc = &qed_chain_alloc,
1318 .chain_free = &qed_chain_free,
Sudarsana Kalluru91420b82015-11-30 12:25:03 +02001319 .set_led = &qed_set_led,
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001320};