blob: f4e816af1783577ec686f4c50a66175523efbe9d [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 */
Yuval Mintz1a635e42016-08-15 10:42:43 +0300109static int qed_init_pci(struct qed_dev *cdev, struct pci_dev *pdev)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200110{
Yuval Mintz0dfaba62016-02-24 16:52:49 +0200111 u8 rev_id;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200112 int rc;
113
114 cdev->pdev = pdev;
115
116 rc = pci_enable_device(pdev);
117 if (rc) {
118 DP_NOTICE(cdev, "Cannot enable PCI device\n");
119 goto err0;
120 }
121
122 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
123 DP_NOTICE(cdev, "No memory region found in bar #0\n");
124 rc = -EIO;
125 goto err1;
126 }
127
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300128 if (IS_PF(cdev) && !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200129 DP_NOTICE(cdev, "No memory region found in bar #2\n");
130 rc = -EIO;
131 goto err1;
132 }
133
134 if (atomic_read(&pdev->enable_cnt) == 1) {
135 rc = pci_request_regions(pdev, "qed");
136 if (rc) {
137 DP_NOTICE(cdev,
138 "Failed to request PCI memory resources\n");
139 goto err1;
140 }
141 pci_set_master(pdev);
142 pci_save_state(pdev);
143 }
144
Yuval Mintz0dfaba62016-02-24 16:52:49 +0200145 pci_read_config_byte(pdev, PCI_REVISION_ID, &rev_id);
146 if (rev_id == PCI_REVISION_ID_ERROR_VAL) {
147 DP_NOTICE(cdev,
148 "Detected PCI device error [rev_id 0x%x]. Probably due to prior indication. Aborting.\n",
149 rev_id);
150 rc = -ENODEV;
151 goto err2;
152 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200153 if (!pci_is_pcie(pdev)) {
154 DP_NOTICE(cdev, "The bus is not PCI Express\n");
155 rc = -EIO;
156 goto err2;
157 }
158
159 cdev->pci_params.pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
Yuval Mintz416cdf02016-05-15 14:48:09 +0300160 if (IS_PF(cdev) && !cdev->pci_params.pm_cap)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200161 DP_NOTICE(cdev, "Cannot find power management capability\n");
162
163 rc = qed_set_coherency_mask(cdev);
164 if (rc)
165 goto err2;
166
167 cdev->pci_params.mem_start = pci_resource_start(pdev, 0);
168 cdev->pci_params.mem_end = pci_resource_end(pdev, 0);
169 cdev->pci_params.irq = pdev->irq;
170
171 cdev->regview = pci_ioremap_bar(pdev, 0);
172 if (!cdev->regview) {
173 DP_NOTICE(cdev, "Cannot map register space, aborting\n");
174 rc = -ENOMEM;
175 goto err2;
176 }
177
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300178 if (IS_PF(cdev)) {
Dan Carpenterf82731b2016-05-17 11:09:20 +0300179 cdev->db_phys_addr = pci_resource_start(cdev->pdev, 2);
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300180 cdev->db_size = pci_resource_len(cdev->pdev, 2);
181 cdev->doorbells = ioremap_wc(cdev->db_phys_addr, cdev->db_size);
182 if (!cdev->doorbells) {
183 DP_NOTICE(cdev, "Cannot map doorbell space\n");
184 return -ENOMEM;
185 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200186 }
187
188 return 0;
189
190err2:
191 pci_release_regions(pdev);
192err1:
193 pci_disable_device(pdev);
194err0:
195 return rc;
196}
197
198int qed_fill_dev_info(struct qed_dev *cdev,
199 struct qed_dev_info *dev_info)
200{
Manish Chopracee4d262015-10-26 11:02:28 +0200201 struct qed_ptt *ptt;
202
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200203 memset(dev_info, 0, sizeof(struct qed_dev_info));
204
205 dev_info->num_hwfns = cdev->num_hwfns;
206 dev_info->pci_mem_start = cdev->pci_params.mem_start;
207 dev_info->pci_mem_end = cdev->pci_params.mem_end;
208 dev_info->pci_irq = cdev->pci_params.irq;
Yuval Mintzc5ac9312016-06-03 14:35:34 +0300209 dev_info->rdma_supported =
210 (cdev->hwfns[0].hw_info.personality == QED_PCI_ETH_ROCE);
Yuval Mintzfc48b7a2016-02-15 13:22:35 -0500211 dev_info->is_mf_default = IS_MF_DEFAULT(&cdev->hwfns[0]);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200212 ether_addr_copy(dev_info->hw_mac, cdev->hwfns[0].hw_info.hw_mac_addr);
213
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300214 if (IS_PF(cdev)) {
215 dev_info->fw_major = FW_MAJOR_VERSION;
216 dev_info->fw_minor = FW_MINOR_VERSION;
217 dev_info->fw_rev = FW_REVISION_VERSION;
218 dev_info->fw_eng = FW_ENGINEERING_VERSION;
219 dev_info->mf_mode = cdev->mf_mode;
Yuval Mintz831bfb0e2016-05-11 16:36:25 +0300220 dev_info->tx_switching = true;
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300221 } else {
222 qed_vf_get_fw_version(&cdev->hwfns[0], &dev_info->fw_major,
223 &dev_info->fw_minor, &dev_info->fw_rev,
224 &dev_info->fw_eng);
225 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200226
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300227 if (IS_PF(cdev)) {
228 ptt = qed_ptt_acquire(QED_LEADING_HWFN(cdev));
229 if (ptt) {
230 qed_mcp_get_mfw_ver(QED_LEADING_HWFN(cdev), ptt,
231 &dev_info->mfw_rev, NULL);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200232
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300233 qed_mcp_get_flash_size(QED_LEADING_HWFN(cdev), ptt,
234 &dev_info->flash_size);
Manish Chopracee4d262015-10-26 11:02:28 +0200235
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300236 qed_ptt_release(QED_LEADING_HWFN(cdev), ptt);
237 }
238 } else {
239 qed_mcp_get_mfw_ver(QED_LEADING_HWFN(cdev), NULL,
240 &dev_info->mfw_rev, NULL);
Manish Chopracee4d262015-10-26 11:02:28 +0200241 }
242
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200243 return 0;
244}
245
246static void qed_free_cdev(struct qed_dev *cdev)
247{
248 kfree((void *)cdev);
249}
250
251static struct qed_dev *qed_alloc_cdev(struct pci_dev *pdev)
252{
253 struct qed_dev *cdev;
254
255 cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
256 if (!cdev)
257 return cdev;
258
259 qed_init_struct(cdev);
260
261 return cdev;
262}
263
264/* Sets the requested power state */
Yuval Mintz1a635e42016-08-15 10:42:43 +0300265static int qed_set_power_state(struct qed_dev *cdev, pci_power_t state)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200266{
267 if (!cdev)
268 return -ENODEV;
269
270 DP_VERBOSE(cdev, NETIF_MSG_DRV, "Omitting Power state change\n");
271 return 0;
272}
273
274/* probing */
275static struct qed_dev *qed_probe(struct pci_dev *pdev,
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300276 struct qed_probe_params *params)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200277{
278 struct qed_dev *cdev;
279 int rc;
280
281 cdev = qed_alloc_cdev(pdev);
282 if (!cdev)
283 goto err0;
284
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300285 cdev->protocol = params->protocol;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200286
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300287 if (params->is_vf)
288 cdev->b_is_vf = true;
289
290 qed_init_dp(cdev, params->dp_module, params->dp_level);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200291
292 rc = qed_init_pci(cdev, pdev);
293 if (rc) {
294 DP_ERR(cdev, "init pci failed\n");
295 goto err1;
296 }
297 DP_INFO(cdev, "PCI init completed successfully\n");
298
299 rc = qed_hw_prepare(cdev, QED_PCI_DEFAULT);
300 if (rc) {
301 DP_ERR(cdev, "hw prepare failed\n");
302 goto err2;
303 }
304
305 DP_INFO(cdev, "qed_probe completed successffuly\n");
306
307 return cdev;
308
309err2:
310 qed_free_pci(cdev);
311err1:
312 qed_free_cdev(cdev);
313err0:
314 return NULL;
315}
316
317static void qed_remove(struct qed_dev *cdev)
318{
319 if (!cdev)
320 return;
321
322 qed_hw_remove(cdev);
323
324 qed_free_pci(cdev);
325
326 qed_set_power_state(cdev, PCI_D3hot);
327
328 qed_free_cdev(cdev);
329}
330
331static void qed_disable_msix(struct qed_dev *cdev)
332{
333 if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) {
334 pci_disable_msix(cdev->pdev);
335 kfree(cdev->int_params.msix_table);
336 } else if (cdev->int_params.out.int_mode == QED_INT_MODE_MSI) {
337 pci_disable_msi(cdev->pdev);
338 }
339
340 memset(&cdev->int_params.out, 0, sizeof(struct qed_int_param));
341}
342
343static int qed_enable_msix(struct qed_dev *cdev,
344 struct qed_int_params *int_params)
345{
346 int i, rc, cnt;
347
348 cnt = int_params->in.num_vectors;
349
350 for (i = 0; i < cnt; i++)
351 int_params->msix_table[i].entry = i;
352
353 rc = pci_enable_msix_range(cdev->pdev, int_params->msix_table,
354 int_params->in.min_msix_cnt, cnt);
355 if (rc < cnt && rc >= int_params->in.min_msix_cnt &&
356 (rc % cdev->num_hwfns)) {
357 pci_disable_msix(cdev->pdev);
358
359 /* If fastpath is initialized, we need at least one interrupt
360 * per hwfn [and the slow path interrupts]. New requested number
361 * should be a multiple of the number of hwfns.
362 */
363 cnt = (rc / cdev->num_hwfns) * cdev->num_hwfns;
364 DP_NOTICE(cdev,
365 "Trying to enable MSI-X with less vectors (%d out of %d)\n",
366 cnt, int_params->in.num_vectors);
Yuval Mintz1a635e42016-08-15 10:42:43 +0300367 rc = pci_enable_msix_exact(cdev->pdev, int_params->msix_table,
368 cnt);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200369 if (!rc)
370 rc = cnt;
371 }
372
373 if (rc > 0) {
374 /* MSI-x configuration was achieved */
375 int_params->out.int_mode = QED_INT_MODE_MSIX;
376 int_params->out.num_vectors = rc;
377 rc = 0;
378 } else {
379 DP_NOTICE(cdev,
380 "Failed to enable MSI-X [Requested %d vectors][rc %d]\n",
381 cnt, rc);
382 }
383
384 return rc;
385}
386
387/* This function outputs the int mode and the number of enabled msix vector */
388static int qed_set_int_mode(struct qed_dev *cdev, bool force_mode)
389{
390 struct qed_int_params *int_params = &cdev->int_params;
391 struct msix_entry *tbl;
392 int rc = 0, cnt;
393
394 switch (int_params->in.int_mode) {
395 case QED_INT_MODE_MSIX:
396 /* Allocate MSIX table */
397 cnt = int_params->in.num_vectors;
398 int_params->msix_table = kcalloc(cnt, sizeof(*tbl), GFP_KERNEL);
399 if (!int_params->msix_table) {
400 rc = -ENOMEM;
401 goto out;
402 }
403
404 /* Enable MSIX */
405 rc = qed_enable_msix(cdev, int_params);
406 if (!rc)
407 goto out;
408
409 DP_NOTICE(cdev, "Failed to enable MSI-X\n");
410 kfree(int_params->msix_table);
411 if (force_mode)
412 goto out;
413 /* Fallthrough */
414
415 case QED_INT_MODE_MSI:
Sudarsana Reddy Kallurubb13ace2016-05-26 11:01:23 +0300416 if (cdev->num_hwfns == 1) {
417 rc = pci_enable_msi(cdev->pdev);
418 if (!rc) {
419 int_params->out.int_mode = QED_INT_MODE_MSI;
420 goto out;
421 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200422
Sudarsana Reddy Kallurubb13ace2016-05-26 11:01:23 +0300423 DP_NOTICE(cdev, "Failed to enable MSI\n");
424 if (force_mode)
425 goto out;
426 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200427 /* Fallthrough */
428
429 case QED_INT_MODE_INTA:
430 int_params->out.int_mode = QED_INT_MODE_INTA;
431 rc = 0;
432 goto out;
433 default:
434 DP_NOTICE(cdev, "Unknown int_mode value %d\n",
435 int_params->in.int_mode);
436 rc = -EINVAL;
437 }
438
439out:
440 cdev->int_coalescing_mode = QED_COAL_MODE_ENABLE;
441
442 return rc;
443}
444
445static void qed_simd_handler_config(struct qed_dev *cdev, void *token,
446 int index, void(*handler)(void *))
447{
448 struct qed_hwfn *hwfn = &cdev->hwfns[index % cdev->num_hwfns];
449 int relative_idx = index / cdev->num_hwfns;
450
451 hwfn->simd_proto_handler[relative_idx].func = handler;
452 hwfn->simd_proto_handler[relative_idx].token = token;
453}
454
455static void qed_simd_handler_clean(struct qed_dev *cdev, int index)
456{
457 struct qed_hwfn *hwfn = &cdev->hwfns[index % cdev->num_hwfns];
458 int relative_idx = index / cdev->num_hwfns;
459
460 memset(&hwfn->simd_proto_handler[relative_idx], 0,
461 sizeof(struct qed_simd_fp_handler));
462}
463
464static irqreturn_t qed_msix_sp_int(int irq, void *tasklet)
465{
466 tasklet_schedule((struct tasklet_struct *)tasklet);
467 return IRQ_HANDLED;
468}
469
470static irqreturn_t qed_single_int(int irq, void *dev_instance)
471{
472 struct qed_dev *cdev = (struct qed_dev *)dev_instance;
473 struct qed_hwfn *hwfn;
474 irqreturn_t rc = IRQ_NONE;
475 u64 status;
476 int i, j;
477
478 for (i = 0; i < cdev->num_hwfns; i++) {
479 status = qed_int_igu_read_sisr_reg(&cdev->hwfns[i]);
480
481 if (!status)
482 continue;
483
484 hwfn = &cdev->hwfns[i];
485
486 /* Slowpath interrupt */
487 if (unlikely(status & 0x1)) {
488 tasklet_schedule(hwfn->sp_dpc);
489 status &= ~0x1;
490 rc = IRQ_HANDLED;
491 }
492
493 /* Fastpath interrupts */
494 for (j = 0; j < 64; j++) {
495 if ((0x2ULL << j) & status) {
496 hwfn->simd_proto_handler[j].func(
497 hwfn->simd_proto_handler[j].token);
498 status &= ~(0x2ULL << j);
499 rc = IRQ_HANDLED;
500 }
501 }
502
503 if (unlikely(status))
504 DP_VERBOSE(hwfn, NETIF_MSG_INTR,
505 "got an unknown interrupt status 0x%llx\n",
506 status);
507 }
508
509 return rc;
510}
511
Sudarsana Kalluru8f16bc92015-12-07 06:25:59 -0500512int qed_slowpath_irq_req(struct qed_hwfn *hwfn)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200513{
Sudarsana Kalluru8f16bc92015-12-07 06:25:59 -0500514 struct qed_dev *cdev = hwfn->cdev;
515 int rc = 0;
516 u8 id;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200517
518 if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) {
Sudarsana Kalluru8f16bc92015-12-07 06:25:59 -0500519 id = hwfn->my_id;
520 snprintf(hwfn->name, NAME_SIZE, "sp-%d-%02x:%02x.%02x",
521 id, cdev->pdev->bus->number,
522 PCI_SLOT(cdev->pdev->devfn), hwfn->abs_pf_id);
523 rc = request_irq(cdev->int_params.msix_table[id].vector,
524 qed_msix_sp_int, 0, hwfn->name, hwfn->sp_dpc);
525 if (!rc)
526 DP_VERBOSE(hwfn, (NETIF_MSG_INTR | QED_MSG_SP),
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200527 "Requested slowpath MSI-X\n");
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200528 } else {
529 unsigned long flags = 0;
530
531 snprintf(cdev->name, NAME_SIZE, "%02x:%02x.%02x",
532 cdev->pdev->bus->number, PCI_SLOT(cdev->pdev->devfn),
533 PCI_FUNC(cdev->pdev->devfn));
534
535 if (cdev->int_params.out.int_mode == QED_INT_MODE_INTA)
536 flags |= IRQF_SHARED;
537
538 rc = request_irq(cdev->pdev->irq, qed_single_int,
539 flags, cdev->name, cdev);
540 }
541
542 return rc;
543}
544
545static void qed_slowpath_irq_free(struct qed_dev *cdev)
546{
547 int i;
548
549 if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) {
550 for_each_hwfn(cdev, i) {
Sudarsana Kalluru8f16bc92015-12-07 06:25:59 -0500551 if (!cdev->hwfns[i].b_int_requested)
552 break;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200553 synchronize_irq(cdev->int_params.msix_table[i].vector);
554 free_irq(cdev->int_params.msix_table[i].vector,
555 cdev->hwfns[i].sp_dpc);
556 }
557 } else {
Sudarsana Kalluru8f16bc92015-12-07 06:25:59 -0500558 if (QED_LEADING_HWFN(cdev)->b_int_requested)
559 free_irq(cdev->pdev->irq, cdev);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200560 }
Sudarsana Kalluru8f16bc92015-12-07 06:25:59 -0500561 qed_int_disable_post_isr_release(cdev);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200562}
563
564static int qed_nic_stop(struct qed_dev *cdev)
565{
566 int i, rc;
567
568 rc = qed_hw_stop(cdev);
569
570 for (i = 0; i < cdev->num_hwfns; i++) {
571 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
572
573 if (p_hwfn->b_sp_dpc_enabled) {
574 tasklet_disable(p_hwfn->sp_dpc);
575 p_hwfn->b_sp_dpc_enabled = false;
576 DP_VERBOSE(cdev, NETIF_MSG_IFDOWN,
577 "Disabled sp taskelt [hwfn %d] at %p\n",
578 i, p_hwfn->sp_dpc);
579 }
580 }
581
582 return rc;
583}
584
585static int qed_nic_reset(struct qed_dev *cdev)
586{
587 int rc;
588
589 rc = qed_hw_reset(cdev);
590 if (rc)
591 return rc;
592
593 qed_resc_free(cdev);
594
595 return 0;
596}
597
598static int qed_nic_setup(struct qed_dev *cdev)
599{
600 int rc;
601
602 rc = qed_resc_alloc(cdev);
603 if (rc)
604 return rc;
605
606 DP_INFO(cdev, "Allocated qed resources\n");
607
608 qed_resc_setup(cdev);
609
610 return rc;
611}
612
613static int qed_set_int_fp(struct qed_dev *cdev, u16 cnt)
614{
615 int limit = 0;
616
617 /* Mark the fastpath as free/used */
618 cdev->int_params.fp_initialized = cnt ? true : false;
619
620 if (cdev->int_params.out.int_mode != QED_INT_MODE_MSIX)
621 limit = cdev->num_hwfns * 63;
622 else if (cdev->int_params.fp_msix_cnt)
623 limit = cdev->int_params.fp_msix_cnt;
624
625 if (!limit)
626 return -ENOMEM;
627
628 return min_t(int, cnt, limit);
629}
630
631static int qed_get_int_fp(struct qed_dev *cdev, struct qed_int_info *info)
632{
633 memset(info, 0, sizeof(struct qed_int_info));
634
635 if (!cdev->int_params.fp_initialized) {
636 DP_INFO(cdev,
637 "Protocol driver requested interrupt information, but its support is not yet configured\n");
638 return -EINVAL;
639 }
640
641 /* Need to expose only MSI-X information; Single IRQ is handled solely
642 * by qed.
643 */
644 if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) {
645 int msix_base = cdev->int_params.fp_msix_base;
646
647 info->msix_cnt = cdev->int_params.fp_msix_cnt;
648 info->msix = &cdev->int_params.msix_table[msix_base];
649 }
650
651 return 0;
652}
653
654static int qed_slowpath_setup_int(struct qed_dev *cdev,
655 enum qed_int_mode int_mode)
656{
Yuval Mintz4ac801b2016-02-28 12:26:52 +0200657 struct qed_sb_cnt_info sb_cnt_info;
658 int rc;
659 int i;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200660
Sudarsana Reddy Kalluru1d2c2022016-08-01 09:08:13 -0400661 if ((int_mode == QED_INT_MODE_MSI) && (cdev->num_hwfns > 1)) {
662 DP_NOTICE(cdev, "MSI mode is not supported for CMT devices\n");
663 return -EINVAL;
664 }
665
666 memset(&cdev->int_params, 0, sizeof(struct qed_int_params));
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200667 cdev->int_params.in.int_mode = int_mode;
Yuval Mintz4ac801b2016-02-28 12:26:52 +0200668 for_each_hwfn(cdev, i) {
669 memset(&sb_cnt_info, 0, sizeof(sb_cnt_info));
670 qed_int_get_num_sbs(&cdev->hwfns[i], &sb_cnt_info);
671 cdev->int_params.in.num_vectors += sb_cnt_info.sb_cnt;
672 cdev->int_params.in.num_vectors++; /* slowpath */
673 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200674
675 /* We want a minimum of one slowpath and one fastpath vector per hwfn */
676 cdev->int_params.in.min_msix_cnt = cdev->num_hwfns * 2;
677
678 rc = qed_set_int_mode(cdev, false);
679 if (rc) {
680 DP_ERR(cdev, "qed_slowpath_setup_int ERR\n");
681 return rc;
682 }
683
684 cdev->int_params.fp_msix_base = cdev->num_hwfns;
685 cdev->int_params.fp_msix_cnt = cdev->int_params.out.num_vectors -
686 cdev->num_hwfns;
687
688 return 0;
689}
690
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300691static int qed_slowpath_vf_setup_int(struct qed_dev *cdev)
692{
693 int rc;
694
695 memset(&cdev->int_params, 0, sizeof(struct qed_int_params));
696 cdev->int_params.in.int_mode = QED_INT_MODE_MSIX;
697
698 qed_vf_get_num_rxqs(QED_LEADING_HWFN(cdev),
699 &cdev->int_params.in.num_vectors);
700 if (cdev->num_hwfns > 1) {
701 u8 vectors = 0;
702
703 qed_vf_get_num_rxqs(&cdev->hwfns[1], &vectors);
704 cdev->int_params.in.num_vectors += vectors;
705 }
706
707 /* We want a minimum of one fastpath vector per vf hwfn */
708 cdev->int_params.in.min_msix_cnt = cdev->num_hwfns;
709
710 rc = qed_set_int_mode(cdev, true);
711 if (rc)
712 return rc;
713
714 cdev->int_params.fp_msix_base = 0;
715 cdev->int_params.fp_msix_cnt = cdev->int_params.out.num_vectors;
716
717 return 0;
718}
719
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200720u32 qed_unzip_data(struct qed_hwfn *p_hwfn, u32 input_len,
721 u8 *input_buf, u32 max_size, u8 *unzip_buf)
722{
723 int rc;
724
725 p_hwfn->stream->next_in = input_buf;
726 p_hwfn->stream->avail_in = input_len;
727 p_hwfn->stream->next_out = unzip_buf;
728 p_hwfn->stream->avail_out = max_size;
729
730 rc = zlib_inflateInit2(p_hwfn->stream, MAX_WBITS);
731
732 if (rc != Z_OK) {
733 DP_VERBOSE(p_hwfn, NETIF_MSG_DRV, "zlib init failed, rc = %d\n",
734 rc);
735 return 0;
736 }
737
738 rc = zlib_inflate(p_hwfn->stream, Z_FINISH);
739 zlib_inflateEnd(p_hwfn->stream);
740
741 if (rc != Z_OK && rc != Z_STREAM_END) {
742 DP_VERBOSE(p_hwfn, NETIF_MSG_DRV, "FW unzip error: %s, rc=%d\n",
743 p_hwfn->stream->msg, rc);
744 return 0;
745 }
746
747 return p_hwfn->stream->total_out / 4;
748}
749
750static int qed_alloc_stream_mem(struct qed_dev *cdev)
751{
752 int i;
753 void *workspace;
754
755 for_each_hwfn(cdev, i) {
756 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
757
758 p_hwfn->stream = kzalloc(sizeof(*p_hwfn->stream), GFP_KERNEL);
759 if (!p_hwfn->stream)
760 return -ENOMEM;
761
762 workspace = vzalloc(zlib_inflate_workspacesize());
763 if (!workspace)
764 return -ENOMEM;
765 p_hwfn->stream->workspace = workspace;
766 }
767
768 return 0;
769}
770
771static void qed_free_stream_mem(struct qed_dev *cdev)
772{
773 int i;
774
775 for_each_hwfn(cdev, i) {
776 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
777
778 if (!p_hwfn->stream)
779 return;
780
781 vfree(p_hwfn->stream->workspace);
782 kfree(p_hwfn->stream);
783 }
784}
785
786static void qed_update_pf_params(struct qed_dev *cdev,
787 struct qed_pf_params *params)
788{
789 int i;
790
791 for (i = 0; i < cdev->num_hwfns; i++) {
792 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
793
794 p_hwfn->pf_params = *params;
795 }
796}
797
798static int qed_slowpath_start(struct qed_dev *cdev,
799 struct qed_slowpath_params *params)
800{
Manish Choprab18e1702016-04-14 01:38:30 -0400801 struct qed_tunn_start_params tunn_info;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200802 struct qed_mcp_drv_version drv_version;
803 const u8 *data = NULL;
804 struct qed_hwfn *hwfn;
Yuval Mintz37bff2b2016-05-11 16:36:13 +0300805 int rc = -EINVAL;
806
807 if (qed_iov_wq_start(cdev))
808 goto err;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200809
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300810 if (IS_PF(cdev)) {
811 rc = request_firmware(&cdev->firmware, QED_FW_FILE_NAME,
812 &cdev->pdev->dev);
813 if (rc) {
814 DP_NOTICE(cdev,
815 "Failed to find fw file - /lib/firmware/%s\n",
816 QED_FW_FILE_NAME);
817 goto err;
818 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200819 }
820
821 rc = qed_nic_setup(cdev);
822 if (rc)
823 goto err;
824
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300825 if (IS_PF(cdev))
826 rc = qed_slowpath_setup_int(cdev, params->int_mode);
827 else
828 rc = qed_slowpath_vf_setup_int(cdev);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200829 if (rc)
830 goto err1;
831
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300832 if (IS_PF(cdev)) {
833 /* Allocate stream for unzipping */
834 rc = qed_alloc_stream_mem(cdev);
835 if (rc) {
836 DP_NOTICE(cdev, "Failed to allocate stream memory\n");
837 goto err2;
838 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200839
Yuval Mintz351a4ded2016-06-02 10:23:29 +0300840 /* First Dword used to diffrentiate between various sources */
841 data = cdev->firmware->data + sizeof(u32);
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300842 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200843
Manish Choprab18e1702016-04-14 01:38:30 -0400844 memset(&tunn_info, 0, sizeof(tunn_info));
Manish Chopra9a109dd2016-04-14 01:38:31 -0400845 tunn_info.tunn_mode |= 1 << QED_MODE_VXLAN_TUNN |
Manish Chopraf7985862016-04-14 01:38:32 -0400846 1 << QED_MODE_L2GRE_TUNN |
847 1 << QED_MODE_IPGRE_TUNN |
Manish Chopra9a109dd2016-04-14 01:38:31 -0400848 1 << QED_MODE_L2GENEVE_TUNN |
849 1 << QED_MODE_IPGENEVE_TUNN;
850
Manish Choprab18e1702016-04-14 01:38:30 -0400851 tunn_info.tunn_clss_vxlan = QED_TUNN_CLSS_MAC_VLAN;
Manish Chopraf7985862016-04-14 01:38:32 -0400852 tunn_info.tunn_clss_l2gre = QED_TUNN_CLSS_MAC_VLAN;
853 tunn_info.tunn_clss_ipgre = QED_TUNN_CLSS_MAC_VLAN;
Manish Choprab18e1702016-04-14 01:38:30 -0400854
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300855 /* Start the slowpath */
Manish Choprab18e1702016-04-14 01:38:30 -0400856 rc = qed_hw_init(cdev, &tunn_info, true,
857 cdev->int_params.out.int_mode,
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200858 true, data);
859 if (rc)
Yuval Mintz8c925c42016-03-02 20:26:03 +0200860 goto err2;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200861
862 DP_INFO(cdev,
863 "HW initialization and function start completed successfully\n");
864
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300865 if (IS_PF(cdev)) {
866 hwfn = QED_LEADING_HWFN(cdev);
867 drv_version.version = (params->drv_major << 24) |
868 (params->drv_minor << 16) |
869 (params->drv_rev << 8) |
870 (params->drv_eng);
871 strlcpy(drv_version.name, params->name,
872 MCP_DRV_VER_STR_SIZE - 4);
873 rc = qed_mcp_send_drv_version(hwfn, hwfn->p_main_ptt,
874 &drv_version);
875 if (rc) {
876 DP_NOTICE(cdev, "Failed sending drv version command\n");
877 return rc;
878 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200879 }
880
Yuval Mintz8c925c42016-03-02 20:26:03 +0200881 qed_reset_vport_stats(cdev);
882
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200883 return 0;
884
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200885err2:
Yuval Mintz8c925c42016-03-02 20:26:03 +0200886 qed_hw_timers_stop_all(cdev);
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300887 if (IS_PF(cdev))
888 qed_slowpath_irq_free(cdev);
Yuval Mintz8c925c42016-03-02 20:26:03 +0200889 qed_free_stream_mem(cdev);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200890 qed_disable_msix(cdev);
891err1:
892 qed_resc_free(cdev);
893err:
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300894 if (IS_PF(cdev))
895 release_firmware(cdev->firmware);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200896
Yuval Mintz37bff2b2016-05-11 16:36:13 +0300897 qed_iov_wq_stop(cdev, false);
898
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200899 return rc;
900}
901
902static int qed_slowpath_stop(struct qed_dev *cdev)
903{
904 if (!cdev)
905 return -ENODEV;
906
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300907 if (IS_PF(cdev)) {
908 qed_free_stream_mem(cdev);
Yuval Mintzc5ac9312016-06-03 14:35:34 +0300909 if (IS_QED_ETH_IF(cdev))
910 qed_sriov_disable(cdev, true);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200911
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300912 qed_nic_stop(cdev);
913 qed_slowpath_irq_free(cdev);
914 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200915
916 qed_disable_msix(cdev);
917 qed_nic_reset(cdev);
918
Yuval Mintz37bff2b2016-05-11 16:36:13 +0300919 qed_iov_wq_stop(cdev, true);
920
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300921 if (IS_PF(cdev))
922 release_firmware(cdev->firmware);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200923
924 return 0;
925}
926
927static void qed_set_id(struct qed_dev *cdev, char name[NAME_SIZE],
928 char ver_str[VER_SIZE])
929{
930 int i;
931
932 memcpy(cdev->name, name, NAME_SIZE);
933 for_each_hwfn(cdev, i)
934 snprintf(cdev->hwfns[i].name, NAME_SIZE, "%s-%d", name, i);
935
936 memcpy(cdev->ver_str, ver_str, VER_SIZE);
937 cdev->drv_type = DRV_ID_DRV_TYPE_LINUX;
938}
939
940static u32 qed_sb_init(struct qed_dev *cdev,
941 struct qed_sb_info *sb_info,
942 void *sb_virt_addr,
943 dma_addr_t sb_phy_addr, u16 sb_id,
944 enum qed_sb_type type)
945{
946 struct qed_hwfn *p_hwfn;
947 int hwfn_index;
948 u16 rel_sb_id;
949 u8 n_hwfns;
950 u32 rc;
951
952 /* RoCE uses single engine and CMT uses two engines. When using both
953 * we force only a single engine. Storage uses only engine 0 too.
954 */
955 if (type == QED_SB_TYPE_L2_QUEUE)
956 n_hwfns = cdev->num_hwfns;
957 else
958 n_hwfns = 1;
959
960 hwfn_index = sb_id % n_hwfns;
961 p_hwfn = &cdev->hwfns[hwfn_index];
962 rel_sb_id = sb_id / n_hwfns;
963
964 DP_VERBOSE(cdev, NETIF_MSG_INTR,
965 "hwfn [%d] <--[init]-- SB %04x [0x%04x upper]\n",
966 hwfn_index, rel_sb_id, sb_id);
967
968 rc = qed_int_sb_init(p_hwfn, p_hwfn->p_main_ptt, sb_info,
969 sb_virt_addr, sb_phy_addr, rel_sb_id);
970
971 return rc;
972}
973
974static u32 qed_sb_release(struct qed_dev *cdev,
Yuval Mintz1a635e42016-08-15 10:42:43 +0300975 struct qed_sb_info *sb_info, u16 sb_id)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200976{
977 struct qed_hwfn *p_hwfn;
978 int hwfn_index;
979 u16 rel_sb_id;
980 u32 rc;
981
982 hwfn_index = sb_id % cdev->num_hwfns;
983 p_hwfn = &cdev->hwfns[hwfn_index];
984 rel_sb_id = sb_id / cdev->num_hwfns;
985
986 DP_VERBOSE(cdev, NETIF_MSG_INTR,
987 "hwfn [%d] <--[init]-- SB %04x [0x%04x upper]\n",
988 hwfn_index, rel_sb_id, sb_id);
989
990 rc = qed_int_sb_release(p_hwfn, sb_info, rel_sb_id);
991
992 return rc;
993}
994
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +0300995static bool qed_can_link_change(struct qed_dev *cdev)
996{
997 return true;
998}
999
Yuval Mintz351a4ded2016-06-02 10:23:29 +03001000static int qed_set_link(struct qed_dev *cdev, struct qed_link_params *params)
Yuval Mintzcc875c22015-10-26 11:02:31 +02001001{
1002 struct qed_hwfn *hwfn;
1003 struct qed_mcp_link_params *link_params;
1004 struct qed_ptt *ptt;
1005 int rc;
1006
1007 if (!cdev)
1008 return -ENODEV;
1009
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001010 if (IS_VF(cdev))
1011 return 0;
1012
Yuval Mintzcc875c22015-10-26 11:02:31 +02001013 /* The link should be set only once per PF */
1014 hwfn = &cdev->hwfns[0];
1015
1016 ptt = qed_ptt_acquire(hwfn);
1017 if (!ptt)
1018 return -EBUSY;
1019
1020 link_params = qed_mcp_get_link_params(hwfn);
1021 if (params->override_flags & QED_LINK_OVERRIDE_SPEED_AUTONEG)
1022 link_params->speed.autoneg = params->autoneg;
1023 if (params->override_flags & QED_LINK_OVERRIDE_SPEED_ADV_SPEEDS) {
1024 link_params->speed.advertised_speeds = 0;
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001025 if ((params->adv_speeds & QED_LM_1000baseT_Half_BIT) ||
1026 (params->adv_speeds & QED_LM_1000baseT_Full_BIT))
Yuval Mintzcc875c22015-10-26 11:02:31 +02001027 link_params->speed.advertised_speeds |=
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001028 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G;
1029 if (params->adv_speeds & QED_LM_10000baseKR_Full_BIT)
Yuval Mintzcc875c22015-10-26 11:02:31 +02001030 link_params->speed.advertised_speeds |=
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001031 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G;
1032 if (params->adv_speeds & QED_LM_25000baseKR_Full_BIT)
Yuval Mintzcc875c22015-10-26 11:02:31 +02001033 link_params->speed.advertised_speeds |=
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001034 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_25G;
1035 if (params->adv_speeds & QED_LM_40000baseLR4_Full_BIT)
Yuval Mintzcc875c22015-10-26 11:02:31 +02001036 link_params->speed.advertised_speeds |=
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001037 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G;
1038 if (params->adv_speeds & QED_LM_50000baseKR2_Full_BIT)
1039 link_params->speed.advertised_speeds |=
1040 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_50G;
1041 if (params->adv_speeds & QED_LM_100000baseKR4_Full_BIT)
Yuval Mintzcc875c22015-10-26 11:02:31 +02001042 link_params->speed.advertised_speeds |=
Yuval Mintz351a4ded2016-06-02 10:23:29 +03001043 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_BB_100G;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001044 }
1045 if (params->override_flags & QED_LINK_OVERRIDE_SPEED_FORCED_SPEED)
1046 link_params->speed.forced_speed = params->forced_speed;
Sudarsana Reddy Kallurua43f2352016-04-22 08:41:04 +03001047 if (params->override_flags & QED_LINK_OVERRIDE_PAUSE_CONFIG) {
1048 if (params->pause_config & QED_LINK_PAUSE_AUTONEG_ENABLE)
1049 link_params->pause.autoneg = true;
1050 else
1051 link_params->pause.autoneg = false;
1052 if (params->pause_config & QED_LINK_PAUSE_RX_ENABLE)
1053 link_params->pause.forced_rx = true;
1054 else
1055 link_params->pause.forced_rx = false;
1056 if (params->pause_config & QED_LINK_PAUSE_TX_ENABLE)
1057 link_params->pause.forced_tx = true;
1058 else
1059 link_params->pause.forced_tx = false;
1060 }
Sudarsana Reddy Kalluru03dc76c2016-04-28 20:20:52 -04001061 if (params->override_flags & QED_LINK_OVERRIDE_LOOPBACK_MODE) {
1062 switch (params->loopback_mode) {
1063 case QED_LINK_LOOPBACK_INT_PHY:
Yuval Mintz351a4ded2016-06-02 10:23:29 +03001064 link_params->loopback_mode = ETH_LOOPBACK_INT_PHY;
Sudarsana Reddy Kalluru03dc76c2016-04-28 20:20:52 -04001065 break;
1066 case QED_LINK_LOOPBACK_EXT_PHY:
Yuval Mintz351a4ded2016-06-02 10:23:29 +03001067 link_params->loopback_mode = ETH_LOOPBACK_EXT_PHY;
Sudarsana Reddy Kalluru03dc76c2016-04-28 20:20:52 -04001068 break;
1069 case QED_LINK_LOOPBACK_EXT:
Yuval Mintz351a4ded2016-06-02 10:23:29 +03001070 link_params->loopback_mode = ETH_LOOPBACK_EXT;
Sudarsana Reddy Kalluru03dc76c2016-04-28 20:20:52 -04001071 break;
1072 case QED_LINK_LOOPBACK_MAC:
Yuval Mintz351a4ded2016-06-02 10:23:29 +03001073 link_params->loopback_mode = ETH_LOOPBACK_MAC;
Sudarsana Reddy Kalluru03dc76c2016-04-28 20:20:52 -04001074 break;
1075 default:
Yuval Mintz351a4ded2016-06-02 10:23:29 +03001076 link_params->loopback_mode = ETH_LOOPBACK_NONE;
Sudarsana Reddy Kalluru03dc76c2016-04-28 20:20:52 -04001077 break;
1078 }
1079 }
Yuval Mintzcc875c22015-10-26 11:02:31 +02001080
1081 rc = qed_mcp_set_link(hwfn, ptt, params->link_up);
1082
1083 qed_ptt_release(hwfn, ptt);
1084
1085 return rc;
1086}
1087
1088static int qed_get_port_type(u32 media_type)
1089{
1090 int port_type;
1091
1092 switch (media_type) {
1093 case MEDIA_SFPP_10G_FIBER:
1094 case MEDIA_SFP_1G_FIBER:
1095 case MEDIA_XFP_FIBER:
Yuval Mintzb639f192016-06-19 15:18:15 +03001096 case MEDIA_MODULE_FIBER:
Yuval Mintzcc875c22015-10-26 11:02:31 +02001097 case MEDIA_KR:
1098 port_type = PORT_FIBRE;
1099 break;
1100 case MEDIA_DA_TWINAX:
1101 port_type = PORT_DA;
1102 break;
1103 case MEDIA_BASE_T:
1104 port_type = PORT_TP;
1105 break;
1106 case MEDIA_NOT_PRESENT:
1107 port_type = PORT_NONE;
1108 break;
1109 case MEDIA_UNSPECIFIED:
1110 default:
1111 port_type = PORT_OTHER;
1112 break;
1113 }
1114 return port_type;
1115}
1116
Arnd Bergmann14b84e82016-06-01 15:29:13 +02001117static int qed_get_link_data(struct qed_hwfn *hwfn,
1118 struct qed_mcp_link_params *params,
1119 struct qed_mcp_link_state *link,
1120 struct qed_mcp_link_capabilities *link_caps)
1121{
1122 void *p;
1123
1124 if (!IS_PF(hwfn->cdev)) {
1125 qed_vf_get_link_params(hwfn, params);
1126 qed_vf_get_link_state(hwfn, link);
1127 qed_vf_get_link_caps(hwfn, link_caps);
1128
1129 return 0;
1130 }
1131
1132 p = qed_mcp_get_link_params(hwfn);
1133 if (!p)
1134 return -ENXIO;
1135 memcpy(params, p, sizeof(*params));
1136
1137 p = qed_mcp_get_link_state(hwfn);
1138 if (!p)
1139 return -ENXIO;
1140 memcpy(link, p, sizeof(*link));
1141
1142 p = qed_mcp_get_link_capabilities(hwfn);
1143 if (!p)
1144 return -ENXIO;
1145 memcpy(link_caps, p, sizeof(*link_caps));
1146
1147 return 0;
1148}
1149
Yuval Mintzcc875c22015-10-26 11:02:31 +02001150static void qed_fill_link(struct qed_hwfn *hwfn,
1151 struct qed_link_output *if_link)
1152{
1153 struct qed_mcp_link_params params;
1154 struct qed_mcp_link_state link;
1155 struct qed_mcp_link_capabilities link_caps;
1156 u32 media_type;
1157
1158 memset(if_link, 0, sizeof(*if_link));
1159
1160 /* Prepare source inputs */
Arnd Bergmann14b84e82016-06-01 15:29:13 +02001161 if (qed_get_link_data(hwfn, &params, &link, &link_caps)) {
1162 dev_warn(&hwfn->cdev->pdev->dev, "no link data available\n");
1163 return;
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001164 }
Yuval Mintzcc875c22015-10-26 11:02:31 +02001165
1166 /* Set the link parameters to pass to protocol driver */
1167 if (link.link_up)
1168 if_link->link_up = true;
1169
1170 /* TODO - at the moment assume supported and advertised speed equal */
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001171 if_link->supported_caps = QED_LM_FIBRE_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001172 if (params.speed.autoneg)
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001173 if_link->supported_caps |= QED_LM_Autoneg_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001174 if (params.pause.autoneg ||
1175 (params.pause.forced_rx && params.pause.forced_tx))
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001176 if_link->supported_caps |= QED_LM_Asym_Pause_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001177 if (params.pause.autoneg || params.pause.forced_rx ||
1178 params.pause.forced_tx)
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001179 if_link->supported_caps |= QED_LM_Pause_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001180
1181 if_link->advertised_caps = if_link->supported_caps;
1182 if (params.speed.advertised_speeds &
1183 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G)
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001184 if_link->advertised_caps |= QED_LM_1000baseT_Half_BIT |
1185 QED_LM_1000baseT_Full_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001186 if (params.speed.advertised_speeds &
1187 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G)
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001188 if_link->advertised_caps |= QED_LM_10000baseKR_Full_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001189 if (params.speed.advertised_speeds &
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001190 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_25G)
1191 if_link->advertised_caps |= QED_LM_25000baseKR_Full_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001192 if (params.speed.advertised_speeds &
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001193 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G)
1194 if_link->advertised_caps |= QED_LM_40000baseLR4_Full_BIT;
1195 if (params.speed.advertised_speeds &
1196 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_50G)
1197 if_link->advertised_caps |= QED_LM_50000baseKR2_Full_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001198 if (params.speed.advertised_speeds &
Yuval Mintz351a4ded2016-06-02 10:23:29 +03001199 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_BB_100G)
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001200 if_link->advertised_caps |= QED_LM_100000baseKR4_Full_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001201
1202 if (link_caps.speed_capabilities &
1203 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G)
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001204 if_link->supported_caps |= QED_LM_1000baseT_Half_BIT |
1205 QED_LM_1000baseT_Full_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001206 if (link_caps.speed_capabilities &
1207 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G)
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001208 if_link->supported_caps |= QED_LM_10000baseKR_Full_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001209 if (link_caps.speed_capabilities &
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001210 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_25G)
1211 if_link->supported_caps |= QED_LM_25000baseKR_Full_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001212 if (link_caps.speed_capabilities &
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001213 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G)
1214 if_link->supported_caps |= QED_LM_40000baseLR4_Full_BIT;
1215 if (link_caps.speed_capabilities &
1216 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_50G)
1217 if_link->supported_caps |= QED_LM_50000baseKR2_Full_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001218 if (link_caps.speed_capabilities &
Yuval Mintz351a4ded2016-06-02 10:23:29 +03001219 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_BB_100G)
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001220 if_link->supported_caps |= QED_LM_100000baseKR4_Full_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001221
1222 if (link.link_up)
1223 if_link->speed = link.speed;
1224
1225 /* TODO - fill duplex properly */
1226 if_link->duplex = DUPLEX_FULL;
1227 qed_mcp_get_media_type(hwfn->cdev, &media_type);
1228 if_link->port = qed_get_port_type(media_type);
1229
1230 if_link->autoneg = params.speed.autoneg;
1231
1232 if (params.pause.autoneg)
1233 if_link->pause_config |= QED_LINK_PAUSE_AUTONEG_ENABLE;
1234 if (params.pause.forced_rx)
1235 if_link->pause_config |= QED_LINK_PAUSE_RX_ENABLE;
1236 if (params.pause.forced_tx)
1237 if_link->pause_config |= QED_LINK_PAUSE_TX_ENABLE;
1238
1239 /* Link partner capabilities */
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001240 if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_1G_HD)
1241 if_link->lp_caps |= QED_LM_1000baseT_Half_BIT;
1242 if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_1G_FD)
1243 if_link->lp_caps |= QED_LM_1000baseT_Full_BIT;
1244 if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_10G)
1245 if_link->lp_caps |= QED_LM_10000baseKR_Full_BIT;
1246 if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_25G)
1247 if_link->lp_caps |= QED_LM_25000baseKR_Full_BIT;
1248 if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_40G)
1249 if_link->lp_caps |= QED_LM_40000baseLR4_Full_BIT;
1250 if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_50G)
1251 if_link->lp_caps |= QED_LM_50000baseKR2_Full_BIT;
1252 if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_100G)
1253 if_link->lp_caps |= QED_LM_100000baseKR4_Full_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001254
1255 if (link.an_complete)
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001256 if_link->lp_caps |= QED_LM_Autoneg_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001257
1258 if (link.partner_adv_pause)
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001259 if_link->lp_caps |= QED_LM_Pause_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001260 if (link.partner_adv_pause == QED_LINK_PARTNER_ASYMMETRIC_PAUSE ||
1261 link.partner_adv_pause == QED_LINK_PARTNER_BOTH_PAUSE)
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001262 if_link->lp_caps |= QED_LM_Asym_Pause_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001263}
1264
1265static void qed_get_current_link(struct qed_dev *cdev,
1266 struct qed_link_output *if_link)
1267{
Yuval Mintz36558c32016-05-11 16:36:17 +03001268 int i;
1269
Yuval Mintzcc875c22015-10-26 11:02:31 +02001270 qed_fill_link(&cdev->hwfns[0], if_link);
Yuval Mintz36558c32016-05-11 16:36:17 +03001271
1272 for_each_hwfn(cdev, i)
1273 qed_inform_vf_link_state(&cdev->hwfns[i]);
Yuval Mintzcc875c22015-10-26 11:02:31 +02001274}
1275
1276void qed_link_update(struct qed_hwfn *hwfn)
1277{
1278 void *cookie = hwfn->cdev->ops_cookie;
1279 struct qed_common_cb_ops *op = hwfn->cdev->protocol_ops.common;
1280 struct qed_link_output if_link;
1281
1282 qed_fill_link(hwfn, &if_link);
Yuval Mintz36558c32016-05-11 16:36:17 +03001283 qed_inform_vf_link_state(hwfn);
Yuval Mintzcc875c22015-10-26 11:02:31 +02001284
1285 if (IS_LEAD_HWFN(hwfn) && cookie)
1286 op->link_update(cookie, &if_link);
1287}
1288
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001289static int qed_drain(struct qed_dev *cdev)
1290{
1291 struct qed_hwfn *hwfn;
1292 struct qed_ptt *ptt;
1293 int i, rc;
1294
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001295 if (IS_VF(cdev))
1296 return 0;
1297
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001298 for_each_hwfn(cdev, i) {
1299 hwfn = &cdev->hwfns[i];
1300 ptt = qed_ptt_acquire(hwfn);
1301 if (!ptt) {
1302 DP_NOTICE(hwfn, "Failed to drain NIG; No PTT\n");
1303 return -EBUSY;
1304 }
1305 rc = qed_mcp_drain(hwfn, ptt);
1306 if (rc)
1307 return rc;
1308 qed_ptt_release(hwfn, ptt);
1309 }
1310
1311 return 0;
1312}
1313
Sudarsana Reddy Kalluru722003a2016-06-21 09:36:21 -04001314static void qed_get_coalesce(struct qed_dev *cdev, u16 *rx_coal, u16 *tx_coal)
1315{
1316 *rx_coal = cdev->rx_coalesce_usecs;
1317 *tx_coal = cdev->tx_coalesce_usecs;
1318}
1319
1320static int qed_set_coalesce(struct qed_dev *cdev, u16 rx_coal, u16 tx_coal,
1321 u8 qid, u16 sb_id)
1322{
1323 struct qed_hwfn *hwfn;
1324 struct qed_ptt *ptt;
1325 int hwfn_index;
1326 int status = 0;
1327
1328 hwfn_index = qid % cdev->num_hwfns;
1329 hwfn = &cdev->hwfns[hwfn_index];
1330 ptt = qed_ptt_acquire(hwfn);
1331 if (!ptt)
1332 return -EAGAIN;
1333
1334 status = qed_set_rxq_coalesce(hwfn, ptt, rx_coal,
1335 qid / cdev->num_hwfns, sb_id);
1336 if (status)
1337 goto out;
1338 status = qed_set_txq_coalesce(hwfn, ptt, tx_coal,
1339 qid / cdev->num_hwfns, sb_id);
1340out:
1341 qed_ptt_release(hwfn, ptt);
1342
1343 return status;
1344}
1345
Sudarsana Kalluru91420b82015-11-30 12:25:03 +02001346static int qed_set_led(struct qed_dev *cdev, enum qed_led_mode mode)
1347{
1348 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1349 struct qed_ptt *ptt;
1350 int status = 0;
1351
1352 ptt = qed_ptt_acquire(hwfn);
1353 if (!ptt)
1354 return -EAGAIN;
1355
1356 status = qed_mcp_set_led(hwfn, ptt, mode);
1357
1358 qed_ptt_release(hwfn, ptt);
1359
1360 return status;
1361}
1362
Sudarsana Reddy Kalluru03dc76c2016-04-28 20:20:52 -04001363struct qed_selftest_ops qed_selftest_ops_pass = {
1364 .selftest_memory = &qed_selftest_memory,
1365 .selftest_interrupt = &qed_selftest_interrupt,
1366 .selftest_register = &qed_selftest_register,
1367 .selftest_clock = &qed_selftest_clock,
1368};
1369
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001370const struct qed_common_ops qed_common_ops_pass = {
Sudarsana Reddy Kalluru03dc76c2016-04-28 20:20:52 -04001371 .selftest = &qed_selftest_ops_pass,
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001372 .probe = &qed_probe,
1373 .remove = &qed_remove,
1374 .set_power_state = &qed_set_power_state,
1375 .set_id = &qed_set_id,
1376 .update_pf_params = &qed_update_pf_params,
1377 .slowpath_start = &qed_slowpath_start,
1378 .slowpath_stop = &qed_slowpath_stop,
1379 .set_fp_int = &qed_set_int_fp,
1380 .get_fp_int = &qed_get_int_fp,
1381 .sb_init = &qed_sb_init,
1382 .sb_release = &qed_sb_release,
1383 .simd_handler_config = &qed_simd_handler_config,
1384 .simd_handler_clean = &qed_simd_handler_clean,
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +03001385 .can_link_change = &qed_can_link_change,
Yuval Mintzcc875c22015-10-26 11:02:31 +02001386 .set_link = &qed_set_link,
1387 .get_link = &qed_get_current_link,
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001388 .drain = &qed_drain,
1389 .update_msglvl = &qed_init_dp,
1390 .chain_alloc = &qed_chain_alloc,
1391 .chain_free = &qed_chain_free,
Sudarsana Reddy Kalluru722003a2016-06-21 09:36:21 -04001392 .get_coalesce = &qed_get_coalesce,
1393 .set_coalesce = &qed_set_coalesce,
Sudarsana Kalluru91420b82015-11-30 12:25:03 +02001394 .set_led = &qed_set_led,
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001395};