blob: ae0ab3b1601d278c0e04d71d43f64e4493c95cd7 [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>
48#include <linux/qed/qed_if.h>
Yuval Mintz0a7fb112016-10-01 21:59:55 +030049#include <linux/qed/qed_ll2_if.h>
Yuval Mintzfe56b9e2015-10-26 11:02:25 +020050
51#include "qed.h"
Yuval Mintz37bff2b2016-05-11 16:36:13 +030052#include "qed_sriov.h"
Yuval Mintzfe56b9e2015-10-26 11:02:25 +020053#include "qed_sp.h"
54#include "qed_dev_api.h"
Yuval Mintz0a7fb112016-10-01 21:59:55 +030055#include "qed_ll2.h"
Arun Easi1e128c82017-02-15 06:28:22 -080056#include "qed_fcoe.h"
Yuval Mintzfe56b9e2015-10-26 11:02:25 +020057#include "qed_mcp.h"
58#include "qed_hw.h"
Sudarsana Reddy Kalluru03dc76c2016-04-28 20:20:52 -040059#include "qed_selftest.h"
Arun Easi1e128c82017-02-15 06:28:22 -080060#include "qed_debug.h"
Yuval Mintzfe56b9e2015-10-26 11:02:25 +020061
Ram Amrani51ff1722016-10-01 21:59:57 +030062#define QED_ROCE_QPS (8192)
63#define QED_ROCE_DPIS (8)
Ram Amrani51ff1722016-10-01 21:59:57 +030064
Yuval Mintz5abd7e922016-02-24 16:52:50 +020065static char version[] =
66 "QLogic FastLinQ 4xxxx Core Module qed " DRV_MODULE_VERSION "\n";
Yuval Mintzfe56b9e2015-10-26 11:02:25 +020067
Yuval Mintz5abd7e922016-02-24 16:52:50 +020068MODULE_DESCRIPTION("QLogic FastLinQ 4xxxx Core Module");
Yuval Mintzfe56b9e2015-10-26 11:02:25 +020069MODULE_LICENSE("GPL");
70MODULE_VERSION(DRV_MODULE_VERSION);
71
72#define FW_FILE_VERSION \
73 __stringify(FW_MAJOR_VERSION) "." \
74 __stringify(FW_MINOR_VERSION) "." \
75 __stringify(FW_REVISION_VERSION) "." \
76 __stringify(FW_ENGINEERING_VERSION)
77
78#define QED_FW_FILE_NAME \
79 "qed/qed_init_values_zipped-" FW_FILE_VERSION ".bin"
80
Yuval Mintzd43d3f02016-02-24 16:52:48 +020081MODULE_FIRMWARE(QED_FW_FILE_NAME);
82
Yuval Mintzfe56b9e2015-10-26 11:02:25 +020083static int __init qed_init(void)
84{
Yuval Mintzfe56b9e2015-10-26 11:02:25 +020085 pr_info("%s", version);
86
87 return 0;
88}
89
90static void __exit qed_cleanup(void)
91{
92 pr_notice("qed_cleanup called\n");
93}
94
95module_init(qed_init);
96module_exit(qed_cleanup);
97
98/* Check if the DMA controller on the machine can properly handle the DMA
99 * addressing required by the device.
100*/
101static int qed_set_coherency_mask(struct qed_dev *cdev)
102{
103 struct device *dev = &cdev->pdev->dev;
104
105 if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
106 if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
107 DP_NOTICE(cdev,
108 "Can't request 64-bit consistent allocations\n");
109 return -EIO;
110 }
111 } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
112 DP_NOTICE(cdev, "Can't request 64b/32b DMA addresses\n");
113 return -EIO;
114 }
115
116 return 0;
117}
118
119static void qed_free_pci(struct qed_dev *cdev)
120{
121 struct pci_dev *pdev = cdev->pdev;
122
123 if (cdev->doorbells)
124 iounmap(cdev->doorbells);
125 if (cdev->regview)
126 iounmap(cdev->regview);
127 if (atomic_read(&pdev->enable_cnt) == 1)
128 pci_release_regions(pdev);
129
130 pci_disable_device(pdev);
131}
132
Yuval Mintz0dfaba62016-02-24 16:52:49 +0200133#define PCI_REVISION_ID_ERROR_VAL 0xff
134
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200135/* Performs PCI initializations as well as initializing PCI-related parameters
136 * in the device structrue. Returns 0 in case of success.
137 */
Yuval Mintz1a635e42016-08-15 10:42:43 +0300138static int qed_init_pci(struct qed_dev *cdev, struct pci_dev *pdev)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200139{
Yuval Mintz0dfaba62016-02-24 16:52:49 +0200140 u8 rev_id;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200141 int rc;
142
143 cdev->pdev = pdev;
144
145 rc = pci_enable_device(pdev);
146 if (rc) {
147 DP_NOTICE(cdev, "Cannot enable PCI device\n");
148 goto err0;
149 }
150
151 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
152 DP_NOTICE(cdev, "No memory region found in bar #0\n");
153 rc = -EIO;
154 goto err1;
155 }
156
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300157 if (IS_PF(cdev) && !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200158 DP_NOTICE(cdev, "No memory region found in bar #2\n");
159 rc = -EIO;
160 goto err1;
161 }
162
163 if (atomic_read(&pdev->enable_cnt) == 1) {
164 rc = pci_request_regions(pdev, "qed");
165 if (rc) {
166 DP_NOTICE(cdev,
167 "Failed to request PCI memory resources\n");
168 goto err1;
169 }
170 pci_set_master(pdev);
171 pci_save_state(pdev);
172 }
173
Yuval Mintz0dfaba62016-02-24 16:52:49 +0200174 pci_read_config_byte(pdev, PCI_REVISION_ID, &rev_id);
175 if (rev_id == PCI_REVISION_ID_ERROR_VAL) {
176 DP_NOTICE(cdev,
177 "Detected PCI device error [rev_id 0x%x]. Probably due to prior indication. Aborting.\n",
178 rev_id);
179 rc = -ENODEV;
180 goto err2;
181 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200182 if (!pci_is_pcie(pdev)) {
183 DP_NOTICE(cdev, "The bus is not PCI Express\n");
184 rc = -EIO;
185 goto err2;
186 }
187
188 cdev->pci_params.pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
Yuval Mintz416cdf02016-05-15 14:48:09 +0300189 if (IS_PF(cdev) && !cdev->pci_params.pm_cap)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200190 DP_NOTICE(cdev, "Cannot find power management capability\n");
191
192 rc = qed_set_coherency_mask(cdev);
193 if (rc)
194 goto err2;
195
196 cdev->pci_params.mem_start = pci_resource_start(pdev, 0);
197 cdev->pci_params.mem_end = pci_resource_end(pdev, 0);
198 cdev->pci_params.irq = pdev->irq;
199
200 cdev->regview = pci_ioremap_bar(pdev, 0);
201 if (!cdev->regview) {
202 DP_NOTICE(cdev, "Cannot map register space, aborting\n");
203 rc = -ENOMEM;
204 goto err2;
205 }
206
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300207 if (IS_PF(cdev)) {
Dan Carpenterf82731b2016-05-17 11:09:20 +0300208 cdev->db_phys_addr = pci_resource_start(cdev->pdev, 2);
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300209 cdev->db_size = pci_resource_len(cdev->pdev, 2);
210 cdev->doorbells = ioremap_wc(cdev->db_phys_addr, cdev->db_size);
211 if (!cdev->doorbells) {
212 DP_NOTICE(cdev, "Cannot map doorbell space\n");
213 return -ENOMEM;
214 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200215 }
216
217 return 0;
218
219err2:
220 pci_release_regions(pdev);
221err1:
222 pci_disable_device(pdev);
223err0:
224 return rc;
225}
226
227int qed_fill_dev_info(struct qed_dev *cdev,
228 struct qed_dev_info *dev_info)
229{
Manish Chopracee4d262015-10-26 11:02:28 +0200230 struct qed_ptt *ptt;
231
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200232 memset(dev_info, 0, sizeof(struct qed_dev_info));
233
234 dev_info->num_hwfns = cdev->num_hwfns;
235 dev_info->pci_mem_start = cdev->pci_params.mem_start;
236 dev_info->pci_mem_end = cdev->pci_params.mem_end;
237 dev_info->pci_irq = cdev->pci_params.irq;
Ram Amrani51ff1722016-10-01 21:59:57 +0300238 dev_info->rdma_supported = (cdev->hwfns[0].hw_info.personality ==
239 QED_PCI_ETH_ROCE);
Yuval Mintzfc48b7a2016-02-15 13:22:35 -0500240 dev_info->is_mf_default = IS_MF_DEFAULT(&cdev->hwfns[0]);
Mintz, Yuval9c79dda2017-03-14 16:23:54 +0200241 dev_info->dev_type = cdev->type;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200242 ether_addr_copy(dev_info->hw_mac, cdev->hwfns[0].hw_info.hw_mac_addr);
243
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300244 if (IS_PF(cdev)) {
245 dev_info->fw_major = FW_MAJOR_VERSION;
246 dev_info->fw_minor = FW_MINOR_VERSION;
247 dev_info->fw_rev = FW_REVISION_VERSION;
248 dev_info->fw_eng = FW_ENGINEERING_VERSION;
249 dev_info->mf_mode = cdev->mf_mode;
Yuval Mintz831bfb0e2016-05-11 16:36:25 +0300250 dev_info->tx_switching = true;
Mintz, Yuval14d39642016-10-31 07:14:23 +0200251
252 if (QED_LEADING_HWFN(cdev)->hw_info.b_wol_support ==
253 QED_WOL_SUPPORT_PME)
254 dev_info->wol_support = true;
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300255 } else {
256 qed_vf_get_fw_version(&cdev->hwfns[0], &dev_info->fw_major,
257 &dev_info->fw_minor, &dev_info->fw_rev,
258 &dev_info->fw_eng);
259 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200260
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300261 if (IS_PF(cdev)) {
262 ptt = qed_ptt_acquire(QED_LEADING_HWFN(cdev));
263 if (ptt) {
264 qed_mcp_get_mfw_ver(QED_LEADING_HWFN(cdev), ptt,
265 &dev_info->mfw_rev, NULL);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200266
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300267 qed_mcp_get_flash_size(QED_LEADING_HWFN(cdev), ptt,
268 &dev_info->flash_size);
Manish Chopracee4d262015-10-26 11:02:28 +0200269
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300270 qed_ptt_release(QED_LEADING_HWFN(cdev), ptt);
271 }
272 } else {
273 qed_mcp_get_mfw_ver(QED_LEADING_HWFN(cdev), NULL,
274 &dev_info->mfw_rev, NULL);
Manish Chopracee4d262015-10-26 11:02:28 +0200275 }
276
Sudarsana Kalluru0fefbfb2016-10-31 07:14:21 +0200277 dev_info->mtu = QED_LEADING_HWFN(cdev)->hw_info.mtu;
278
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200279 return 0;
280}
281
282static void qed_free_cdev(struct qed_dev *cdev)
283{
284 kfree((void *)cdev);
285}
286
287static struct qed_dev *qed_alloc_cdev(struct pci_dev *pdev)
288{
289 struct qed_dev *cdev;
290
291 cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
292 if (!cdev)
293 return cdev;
294
295 qed_init_struct(cdev);
296
297 return cdev;
298}
299
300/* Sets the requested power state */
Yuval Mintz1a635e42016-08-15 10:42:43 +0300301static int qed_set_power_state(struct qed_dev *cdev, pci_power_t state)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200302{
303 if (!cdev)
304 return -ENODEV;
305
306 DP_VERBOSE(cdev, NETIF_MSG_DRV, "Omitting Power state change\n");
307 return 0;
308}
309
310/* probing */
311static struct qed_dev *qed_probe(struct pci_dev *pdev,
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300312 struct qed_probe_params *params)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200313{
314 struct qed_dev *cdev;
315 int rc;
316
317 cdev = qed_alloc_cdev(pdev);
318 if (!cdev)
319 goto err0;
320
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300321 cdev->protocol = params->protocol;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200322
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300323 if (params->is_vf)
324 cdev->b_is_vf = true;
325
326 qed_init_dp(cdev, params->dp_module, params->dp_level);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200327
328 rc = qed_init_pci(cdev, pdev);
329 if (rc) {
330 DP_ERR(cdev, "init pci failed\n");
331 goto err1;
332 }
333 DP_INFO(cdev, "PCI init completed successfully\n");
334
335 rc = qed_hw_prepare(cdev, QED_PCI_DEFAULT);
336 if (rc) {
337 DP_ERR(cdev, "hw prepare failed\n");
338 goto err2;
339 }
340
341 DP_INFO(cdev, "qed_probe completed successffuly\n");
342
343 return cdev;
344
345err2:
346 qed_free_pci(cdev);
347err1:
348 qed_free_cdev(cdev);
349err0:
350 return NULL;
351}
352
353static void qed_remove(struct qed_dev *cdev)
354{
355 if (!cdev)
356 return;
357
358 qed_hw_remove(cdev);
359
360 qed_free_pci(cdev);
361
362 qed_set_power_state(cdev, PCI_D3hot);
363
364 qed_free_cdev(cdev);
365}
366
367static void qed_disable_msix(struct qed_dev *cdev)
368{
369 if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) {
370 pci_disable_msix(cdev->pdev);
371 kfree(cdev->int_params.msix_table);
372 } else if (cdev->int_params.out.int_mode == QED_INT_MODE_MSI) {
373 pci_disable_msi(cdev->pdev);
374 }
375
376 memset(&cdev->int_params.out, 0, sizeof(struct qed_int_param));
377}
378
379static int qed_enable_msix(struct qed_dev *cdev,
380 struct qed_int_params *int_params)
381{
382 int i, rc, cnt;
383
384 cnt = int_params->in.num_vectors;
385
386 for (i = 0; i < cnt; i++)
387 int_params->msix_table[i].entry = i;
388
389 rc = pci_enable_msix_range(cdev->pdev, int_params->msix_table,
390 int_params->in.min_msix_cnt, cnt);
391 if (rc < cnt && rc >= int_params->in.min_msix_cnt &&
392 (rc % cdev->num_hwfns)) {
393 pci_disable_msix(cdev->pdev);
394
395 /* If fastpath is initialized, we need at least one interrupt
396 * per hwfn [and the slow path interrupts]. New requested number
397 * should be a multiple of the number of hwfns.
398 */
399 cnt = (rc / cdev->num_hwfns) * cdev->num_hwfns;
400 DP_NOTICE(cdev,
401 "Trying to enable MSI-X with less vectors (%d out of %d)\n",
402 cnt, int_params->in.num_vectors);
Yuval Mintz1a635e42016-08-15 10:42:43 +0300403 rc = pci_enable_msix_exact(cdev->pdev, int_params->msix_table,
404 cnt);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200405 if (!rc)
406 rc = cnt;
407 }
408
409 if (rc > 0) {
410 /* MSI-x configuration was achieved */
411 int_params->out.int_mode = QED_INT_MODE_MSIX;
412 int_params->out.num_vectors = rc;
413 rc = 0;
414 } else {
415 DP_NOTICE(cdev,
416 "Failed to enable MSI-X [Requested %d vectors][rc %d]\n",
417 cnt, rc);
418 }
419
420 return rc;
421}
422
423/* This function outputs the int mode and the number of enabled msix vector */
424static int qed_set_int_mode(struct qed_dev *cdev, bool force_mode)
425{
426 struct qed_int_params *int_params = &cdev->int_params;
427 struct msix_entry *tbl;
428 int rc = 0, cnt;
429
430 switch (int_params->in.int_mode) {
431 case QED_INT_MODE_MSIX:
432 /* Allocate MSIX table */
433 cnt = int_params->in.num_vectors;
434 int_params->msix_table = kcalloc(cnt, sizeof(*tbl), GFP_KERNEL);
435 if (!int_params->msix_table) {
436 rc = -ENOMEM;
437 goto out;
438 }
439
440 /* Enable MSIX */
441 rc = qed_enable_msix(cdev, int_params);
442 if (!rc)
443 goto out;
444
445 DP_NOTICE(cdev, "Failed to enable MSI-X\n");
446 kfree(int_params->msix_table);
447 if (force_mode)
448 goto out;
449 /* Fallthrough */
450
451 case QED_INT_MODE_MSI:
Sudarsana Reddy Kallurubb13ace2016-05-26 11:01:23 +0300452 if (cdev->num_hwfns == 1) {
453 rc = pci_enable_msi(cdev->pdev);
454 if (!rc) {
455 int_params->out.int_mode = QED_INT_MODE_MSI;
456 goto out;
457 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200458
Sudarsana Reddy Kallurubb13ace2016-05-26 11:01:23 +0300459 DP_NOTICE(cdev, "Failed to enable MSI\n");
460 if (force_mode)
461 goto out;
462 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200463 /* Fallthrough */
464
465 case QED_INT_MODE_INTA:
466 int_params->out.int_mode = QED_INT_MODE_INTA;
467 rc = 0;
468 goto out;
469 default:
470 DP_NOTICE(cdev, "Unknown int_mode value %d\n",
471 int_params->in.int_mode);
472 rc = -EINVAL;
473 }
474
475out:
Yuval Mintz525ef5c2016-08-15 10:42:45 +0300476 if (!rc)
477 DP_INFO(cdev, "Using %s interrupts\n",
478 int_params->out.int_mode == QED_INT_MODE_INTA ?
479 "INTa" : int_params->out.int_mode == QED_INT_MODE_MSI ?
480 "MSI" : "MSIX");
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200481 cdev->int_coalescing_mode = QED_COAL_MODE_ENABLE;
482
483 return rc;
484}
485
486static void qed_simd_handler_config(struct qed_dev *cdev, void *token,
487 int index, void(*handler)(void *))
488{
489 struct qed_hwfn *hwfn = &cdev->hwfns[index % cdev->num_hwfns];
490 int relative_idx = index / cdev->num_hwfns;
491
492 hwfn->simd_proto_handler[relative_idx].func = handler;
493 hwfn->simd_proto_handler[relative_idx].token = token;
494}
495
496static void qed_simd_handler_clean(struct qed_dev *cdev, int index)
497{
498 struct qed_hwfn *hwfn = &cdev->hwfns[index % cdev->num_hwfns];
499 int relative_idx = index / cdev->num_hwfns;
500
501 memset(&hwfn->simd_proto_handler[relative_idx], 0,
502 sizeof(struct qed_simd_fp_handler));
503}
504
505static irqreturn_t qed_msix_sp_int(int irq, void *tasklet)
506{
507 tasklet_schedule((struct tasklet_struct *)tasklet);
508 return IRQ_HANDLED;
509}
510
511static irqreturn_t qed_single_int(int irq, void *dev_instance)
512{
513 struct qed_dev *cdev = (struct qed_dev *)dev_instance;
514 struct qed_hwfn *hwfn;
515 irqreturn_t rc = IRQ_NONE;
516 u64 status;
517 int i, j;
518
519 for (i = 0; i < cdev->num_hwfns; i++) {
520 status = qed_int_igu_read_sisr_reg(&cdev->hwfns[i]);
521
522 if (!status)
523 continue;
524
525 hwfn = &cdev->hwfns[i];
526
527 /* Slowpath interrupt */
528 if (unlikely(status & 0x1)) {
529 tasklet_schedule(hwfn->sp_dpc);
530 status &= ~0x1;
531 rc = IRQ_HANDLED;
532 }
533
534 /* Fastpath interrupts */
535 for (j = 0; j < 64; j++) {
536 if ((0x2ULL << j) & status) {
537 hwfn->simd_proto_handler[j].func(
538 hwfn->simd_proto_handler[j].token);
539 status &= ~(0x2ULL << j);
540 rc = IRQ_HANDLED;
541 }
542 }
543
544 if (unlikely(status))
545 DP_VERBOSE(hwfn, NETIF_MSG_INTR,
546 "got an unknown interrupt status 0x%llx\n",
547 status);
548 }
549
550 return rc;
551}
552
Sudarsana Kalluru8f16bc92015-12-07 06:25:59 -0500553int qed_slowpath_irq_req(struct qed_hwfn *hwfn)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200554{
Sudarsana Kalluru8f16bc92015-12-07 06:25:59 -0500555 struct qed_dev *cdev = hwfn->cdev;
Yuval Mintz525ef5c2016-08-15 10:42:45 +0300556 u32 int_mode;
Sudarsana Kalluru8f16bc92015-12-07 06:25:59 -0500557 int rc = 0;
558 u8 id;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200559
Yuval Mintz525ef5c2016-08-15 10:42:45 +0300560 int_mode = cdev->int_params.out.int_mode;
561 if (int_mode == QED_INT_MODE_MSIX) {
Sudarsana Kalluru8f16bc92015-12-07 06:25:59 -0500562 id = hwfn->my_id;
563 snprintf(hwfn->name, NAME_SIZE, "sp-%d-%02x:%02x.%02x",
564 id, cdev->pdev->bus->number,
565 PCI_SLOT(cdev->pdev->devfn), hwfn->abs_pf_id);
566 rc = request_irq(cdev->int_params.msix_table[id].vector,
567 qed_msix_sp_int, 0, hwfn->name, hwfn->sp_dpc);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200568 } else {
569 unsigned long flags = 0;
570
571 snprintf(cdev->name, NAME_SIZE, "%02x:%02x.%02x",
572 cdev->pdev->bus->number, PCI_SLOT(cdev->pdev->devfn),
573 PCI_FUNC(cdev->pdev->devfn));
574
575 if (cdev->int_params.out.int_mode == QED_INT_MODE_INTA)
576 flags |= IRQF_SHARED;
577
578 rc = request_irq(cdev->pdev->irq, qed_single_int,
579 flags, cdev->name, cdev);
580 }
581
Yuval Mintz525ef5c2016-08-15 10:42:45 +0300582 if (rc)
583 DP_NOTICE(cdev, "request_irq failed, rc = %d\n", rc);
584 else
585 DP_VERBOSE(hwfn, (NETIF_MSG_INTR | QED_MSG_SP),
586 "Requested slowpath %s\n",
587 (int_mode == QED_INT_MODE_MSIX) ? "MSI-X" : "IRQ");
588
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200589 return rc;
590}
591
Tomer Tayar12263372017-03-28 15:12:50 +0300592void qed_slowpath_irq_sync(struct qed_hwfn *p_hwfn)
593{
594 struct qed_dev *cdev = p_hwfn->cdev;
595 u8 id = p_hwfn->my_id;
596 u32 int_mode;
597
598 int_mode = cdev->int_params.out.int_mode;
599 if (int_mode == QED_INT_MODE_MSIX)
600 synchronize_irq(cdev->int_params.msix_table[id].vector);
601 else
602 synchronize_irq(cdev->pdev->irq);
603}
604
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200605static void qed_slowpath_irq_free(struct qed_dev *cdev)
606{
607 int i;
608
609 if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) {
610 for_each_hwfn(cdev, i) {
Sudarsana Kalluru8f16bc92015-12-07 06:25:59 -0500611 if (!cdev->hwfns[i].b_int_requested)
612 break;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200613 synchronize_irq(cdev->int_params.msix_table[i].vector);
614 free_irq(cdev->int_params.msix_table[i].vector,
615 cdev->hwfns[i].sp_dpc);
616 }
617 } else {
Sudarsana Kalluru8f16bc92015-12-07 06:25:59 -0500618 if (QED_LEADING_HWFN(cdev)->b_int_requested)
619 free_irq(cdev->pdev->irq, cdev);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200620 }
Sudarsana Kalluru8f16bc92015-12-07 06:25:59 -0500621 qed_int_disable_post_isr_release(cdev);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200622}
623
624static int qed_nic_stop(struct qed_dev *cdev)
625{
626 int i, rc;
627
628 rc = qed_hw_stop(cdev);
629
630 for (i = 0; i < cdev->num_hwfns; i++) {
631 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
632
633 if (p_hwfn->b_sp_dpc_enabled) {
634 tasklet_disable(p_hwfn->sp_dpc);
635 p_hwfn->b_sp_dpc_enabled = false;
636 DP_VERBOSE(cdev, NETIF_MSG_IFDOWN,
637 "Disabled sp taskelt [hwfn %d] at %p\n",
638 i, p_hwfn->sp_dpc);
639 }
640 }
641
Tomer Tayarc965db42016-09-07 16:36:24 +0300642 qed_dbg_pf_exit(cdev);
643
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200644 return rc;
645}
646
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200647static int qed_nic_setup(struct qed_dev *cdev)
648{
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300649 int rc, i;
650
651 /* Determine if interface is going to require LL2 */
652 if (QED_LEADING_HWFN(cdev)->hw_info.personality != QED_PCI_ETH) {
653 for (i = 0; i < cdev->num_hwfns; i++) {
654 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
655
656 p_hwfn->using_ll2 = true;
657 }
658 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200659
660 rc = qed_resc_alloc(cdev);
661 if (rc)
662 return rc;
663
664 DP_INFO(cdev, "Allocated qed resources\n");
665
666 qed_resc_setup(cdev);
667
668 return rc;
669}
670
671static int qed_set_int_fp(struct qed_dev *cdev, u16 cnt)
672{
673 int limit = 0;
674
675 /* Mark the fastpath as free/used */
676 cdev->int_params.fp_initialized = cnt ? true : false;
677
678 if (cdev->int_params.out.int_mode != QED_INT_MODE_MSIX)
679 limit = cdev->num_hwfns * 63;
680 else if (cdev->int_params.fp_msix_cnt)
681 limit = cdev->int_params.fp_msix_cnt;
682
683 if (!limit)
684 return -ENOMEM;
685
686 return min_t(int, cnt, limit);
687}
688
689static int qed_get_int_fp(struct qed_dev *cdev, struct qed_int_info *info)
690{
691 memset(info, 0, sizeof(struct qed_int_info));
692
693 if (!cdev->int_params.fp_initialized) {
694 DP_INFO(cdev,
695 "Protocol driver requested interrupt information, but its support is not yet configured\n");
696 return -EINVAL;
697 }
698
699 /* Need to expose only MSI-X information; Single IRQ is handled solely
700 * by qed.
701 */
702 if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) {
703 int msix_base = cdev->int_params.fp_msix_base;
704
705 info->msix_cnt = cdev->int_params.fp_msix_cnt;
706 info->msix = &cdev->int_params.msix_table[msix_base];
707 }
708
709 return 0;
710}
711
712static int qed_slowpath_setup_int(struct qed_dev *cdev,
713 enum qed_int_mode int_mode)
714{
Yuval Mintz4ac801b2016-02-28 12:26:52 +0200715 struct qed_sb_cnt_info sb_cnt_info;
Yuval Mintz0189efb2016-10-13 22:57:02 +0300716 int num_l2_queues = 0;
Yuval Mintz4ac801b2016-02-28 12:26:52 +0200717 int rc;
718 int i;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200719
Sudarsana Reddy Kalluru1d2c2022016-08-01 09:08:13 -0400720 if ((int_mode == QED_INT_MODE_MSI) && (cdev->num_hwfns > 1)) {
721 DP_NOTICE(cdev, "MSI mode is not supported for CMT devices\n");
722 return -EINVAL;
723 }
724
725 memset(&cdev->int_params, 0, sizeof(struct qed_int_params));
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200726 cdev->int_params.in.int_mode = int_mode;
Yuval Mintz4ac801b2016-02-28 12:26:52 +0200727 for_each_hwfn(cdev, i) {
728 memset(&sb_cnt_info, 0, sizeof(sb_cnt_info));
729 qed_int_get_num_sbs(&cdev->hwfns[i], &sb_cnt_info);
730 cdev->int_params.in.num_vectors += sb_cnt_info.sb_cnt;
731 cdev->int_params.in.num_vectors++; /* slowpath */
732 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200733
734 /* We want a minimum of one slowpath and one fastpath vector per hwfn */
735 cdev->int_params.in.min_msix_cnt = cdev->num_hwfns * 2;
736
737 rc = qed_set_int_mode(cdev, false);
738 if (rc) {
739 DP_ERR(cdev, "qed_slowpath_setup_int ERR\n");
740 return rc;
741 }
742
743 cdev->int_params.fp_msix_base = cdev->num_hwfns;
744 cdev->int_params.fp_msix_cnt = cdev->int_params.out.num_vectors -
745 cdev->num_hwfns;
746
Yuval Mintz0189efb2016-10-13 22:57:02 +0300747 if (!IS_ENABLED(CONFIG_QED_RDMA))
748 return 0;
749
Ram Amrani51ff1722016-10-01 21:59:57 +0300750 for_each_hwfn(cdev, i)
751 num_l2_queues += FEAT_NUM(&cdev->hwfns[i], QED_PF_L2_QUE);
752
753 DP_VERBOSE(cdev, QED_MSG_RDMA,
754 "cdev->int_params.fp_msix_cnt=%d num_l2_queues=%d\n",
755 cdev->int_params.fp_msix_cnt, num_l2_queues);
756
757 if (cdev->int_params.fp_msix_cnt > num_l2_queues) {
758 cdev->int_params.rdma_msix_cnt =
759 (cdev->int_params.fp_msix_cnt - num_l2_queues)
760 / cdev->num_hwfns;
761 cdev->int_params.rdma_msix_base =
762 cdev->int_params.fp_msix_base + num_l2_queues;
763 cdev->int_params.fp_msix_cnt = num_l2_queues;
764 } else {
765 cdev->int_params.rdma_msix_cnt = 0;
766 }
767
768 DP_VERBOSE(cdev, QED_MSG_RDMA, "roce_msix_cnt=%d roce_msix_base=%d\n",
769 cdev->int_params.rdma_msix_cnt,
770 cdev->int_params.rdma_msix_base);
Ram Amrani51ff1722016-10-01 21:59:57 +0300771
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200772 return 0;
773}
774
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300775static int qed_slowpath_vf_setup_int(struct qed_dev *cdev)
776{
777 int rc;
778
779 memset(&cdev->int_params, 0, sizeof(struct qed_int_params));
780 cdev->int_params.in.int_mode = QED_INT_MODE_MSIX;
781
782 qed_vf_get_num_rxqs(QED_LEADING_HWFN(cdev),
783 &cdev->int_params.in.num_vectors);
784 if (cdev->num_hwfns > 1) {
785 u8 vectors = 0;
786
787 qed_vf_get_num_rxqs(&cdev->hwfns[1], &vectors);
788 cdev->int_params.in.num_vectors += vectors;
789 }
790
791 /* We want a minimum of one fastpath vector per vf hwfn */
792 cdev->int_params.in.min_msix_cnt = cdev->num_hwfns;
793
794 rc = qed_set_int_mode(cdev, true);
795 if (rc)
796 return rc;
797
798 cdev->int_params.fp_msix_base = 0;
799 cdev->int_params.fp_msix_cnt = cdev->int_params.out.num_vectors;
800
801 return 0;
802}
803
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200804u32 qed_unzip_data(struct qed_hwfn *p_hwfn, u32 input_len,
805 u8 *input_buf, u32 max_size, u8 *unzip_buf)
806{
807 int rc;
808
809 p_hwfn->stream->next_in = input_buf;
810 p_hwfn->stream->avail_in = input_len;
811 p_hwfn->stream->next_out = unzip_buf;
812 p_hwfn->stream->avail_out = max_size;
813
814 rc = zlib_inflateInit2(p_hwfn->stream, MAX_WBITS);
815
816 if (rc != Z_OK) {
817 DP_VERBOSE(p_hwfn, NETIF_MSG_DRV, "zlib init failed, rc = %d\n",
818 rc);
819 return 0;
820 }
821
822 rc = zlib_inflate(p_hwfn->stream, Z_FINISH);
823 zlib_inflateEnd(p_hwfn->stream);
824
825 if (rc != Z_OK && rc != Z_STREAM_END) {
826 DP_VERBOSE(p_hwfn, NETIF_MSG_DRV, "FW unzip error: %s, rc=%d\n",
827 p_hwfn->stream->msg, rc);
828 return 0;
829 }
830
831 return p_hwfn->stream->total_out / 4;
832}
833
834static int qed_alloc_stream_mem(struct qed_dev *cdev)
835{
836 int i;
837 void *workspace;
838
839 for_each_hwfn(cdev, i) {
840 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
841
842 p_hwfn->stream = kzalloc(sizeof(*p_hwfn->stream), GFP_KERNEL);
843 if (!p_hwfn->stream)
844 return -ENOMEM;
845
846 workspace = vzalloc(zlib_inflate_workspacesize());
847 if (!workspace)
848 return -ENOMEM;
849 p_hwfn->stream->workspace = workspace;
850 }
851
852 return 0;
853}
854
855static void qed_free_stream_mem(struct qed_dev *cdev)
856{
857 int i;
858
859 for_each_hwfn(cdev, i) {
860 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
861
862 if (!p_hwfn->stream)
863 return;
864
865 vfree(p_hwfn->stream->workspace);
866 kfree(p_hwfn->stream);
867 }
868}
869
870static void qed_update_pf_params(struct qed_dev *cdev,
871 struct qed_pf_params *params)
872{
873 int i;
874
Ram Amrani5c5f2602016-11-09 22:48:44 +0200875 if (IS_ENABLED(CONFIG_QED_RDMA)) {
876 params->rdma_pf_params.num_qps = QED_ROCE_QPS;
877 params->rdma_pf_params.min_dpis = QED_ROCE_DPIS;
878 /* divide by 3 the MRs to avoid MF ILT overflow */
879 params->rdma_pf_params.num_mrs = RDMA_MAX_TIDS;
880 params->rdma_pf_params.gl_pi = QED_ROCE_PROTOCOL_INDEX;
881 }
882
Mintz, Yuvale1d32ac2017-01-01 13:57:03 +0200883 /* In case we might support RDMA, don't allow qede to be greedy
884 * with the L2 contexts. Allow for 64 queues [rx, tx, xdp] per hwfn.
885 */
886 if (QED_LEADING_HWFN(cdev)->hw_info.personality ==
887 QED_PCI_ETH_ROCE) {
888 u16 *num_cons;
889
890 num_cons = &params->eth_pf_params.num_cons;
891 *num_cons = min_t(u16, *num_cons, 192);
892 }
893
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200894 for (i = 0; i < cdev->num_hwfns; i++) {
895 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
896
897 p_hwfn->pf_params = *params;
898 }
899}
900
901static int qed_slowpath_start(struct qed_dev *cdev,
902 struct qed_slowpath_params *params)
903{
Mintz, Yuvalc0c2d0b2017-03-28 15:12:51 +0300904 struct qed_hw_init_params hw_init_params;
Manish Choprab18e1702016-04-14 01:38:30 -0400905 struct qed_tunn_start_params tunn_info;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200906 struct qed_mcp_drv_version drv_version;
907 const u8 *data = NULL;
908 struct qed_hwfn *hwfn;
Sudarsana Reddy Kalluruc78c70f2017-02-15 10:24:10 +0200909 struct qed_ptt *p_ptt;
Yuval Mintz37bff2b2016-05-11 16:36:13 +0300910 int rc = -EINVAL;
911
912 if (qed_iov_wq_start(cdev))
913 goto err;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200914
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300915 if (IS_PF(cdev)) {
916 rc = request_firmware(&cdev->firmware, QED_FW_FILE_NAME,
917 &cdev->pdev->dev);
918 if (rc) {
919 DP_NOTICE(cdev,
920 "Failed to find fw file - /lib/firmware/%s\n",
921 QED_FW_FILE_NAME);
922 goto err;
923 }
Sudarsana Reddy Kalluruc78c70f2017-02-15 10:24:10 +0200924
925 p_ptt = qed_ptt_acquire(QED_LEADING_HWFN(cdev));
926 if (p_ptt) {
927 QED_LEADING_HWFN(cdev)->p_ptp_ptt = p_ptt;
928 } else {
929 DP_NOTICE(cdev, "Failed to acquire PTT for PTP\n");
930 goto err;
931 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200932 }
933
Sudarsana Reddy Kalluru0e191822016-10-21 04:43:42 -0400934 cdev->rx_coalesce_usecs = QED_DEFAULT_RX_USECS;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200935 rc = qed_nic_setup(cdev);
936 if (rc)
937 goto err;
938
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300939 if (IS_PF(cdev))
940 rc = qed_slowpath_setup_int(cdev, params->int_mode);
941 else
942 rc = qed_slowpath_vf_setup_int(cdev);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200943 if (rc)
944 goto err1;
945
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300946 if (IS_PF(cdev)) {
947 /* Allocate stream for unzipping */
948 rc = qed_alloc_stream_mem(cdev);
Joe Perches2591c282016-09-04 14:24:03 -0700949 if (rc)
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300950 goto err2;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200951
Yuval Mintz351a4ded2016-06-02 10:23:29 +0300952 /* First Dword used to diffrentiate between various sources */
953 data = cdev->firmware->data + sizeof(u32);
Tomer Tayarc965db42016-09-07 16:36:24 +0300954
955 qed_dbg_pf_init(cdev);
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300956 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200957
Manish Choprab18e1702016-04-14 01:38:30 -0400958 memset(&tunn_info, 0, sizeof(tunn_info));
Manish Chopra9a109dd2016-04-14 01:38:31 -0400959 tunn_info.tunn_mode |= 1 << QED_MODE_VXLAN_TUNN |
Manish Chopraf7985862016-04-14 01:38:32 -0400960 1 << QED_MODE_L2GRE_TUNN |
961 1 << QED_MODE_IPGRE_TUNN |
Manish Chopra9a109dd2016-04-14 01:38:31 -0400962 1 << QED_MODE_L2GENEVE_TUNN |
963 1 << QED_MODE_IPGENEVE_TUNN;
964
Manish Choprab18e1702016-04-14 01:38:30 -0400965 tunn_info.tunn_clss_vxlan = QED_TUNN_CLSS_MAC_VLAN;
Manish Chopraf7985862016-04-14 01:38:32 -0400966 tunn_info.tunn_clss_l2gre = QED_TUNN_CLSS_MAC_VLAN;
967 tunn_info.tunn_clss_ipgre = QED_TUNN_CLSS_MAC_VLAN;
Manish Choprab18e1702016-04-14 01:38:30 -0400968
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300969 /* Start the slowpath */
Mintz, Yuvalc0c2d0b2017-03-28 15:12:51 +0300970 memset(&hw_init_params, 0, sizeof(hw_init_params));
971 hw_init_params.p_tunn = &tunn_info;
972 hw_init_params.b_hw_start = true;
973 hw_init_params.int_mode = cdev->int_params.out.int_mode;
974 hw_init_params.allow_npar_tx_switch = true;
975 hw_init_params.bin_fw_data = data;
976
977 rc = qed_hw_init(cdev, &hw_init_params);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200978 if (rc)
Yuval Mintz8c925c42016-03-02 20:26:03 +0200979 goto err2;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200980
981 DP_INFO(cdev,
982 "HW initialization and function start completed successfully\n");
983
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300984 /* Allocate LL2 interface if needed */
985 if (QED_LEADING_HWFN(cdev)->using_ll2) {
986 rc = qed_ll2_alloc_if(cdev);
987 if (rc)
988 goto err3;
989 }
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300990 if (IS_PF(cdev)) {
991 hwfn = QED_LEADING_HWFN(cdev);
992 drv_version.version = (params->drv_major << 24) |
993 (params->drv_minor << 16) |
994 (params->drv_rev << 8) |
995 (params->drv_eng);
996 strlcpy(drv_version.name, params->name,
997 MCP_DRV_VER_STR_SIZE - 4);
998 rc = qed_mcp_send_drv_version(hwfn, hwfn->p_main_ptt,
999 &drv_version);
1000 if (rc) {
1001 DP_NOTICE(cdev, "Failed sending drv version command\n");
1002 return rc;
1003 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001004 }
1005
Yuval Mintz8c925c42016-03-02 20:26:03 +02001006 qed_reset_vport_stats(cdev);
1007
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001008 return 0;
1009
Yuval Mintz0a7fb112016-10-01 21:59:55 +03001010err3:
1011 qed_hw_stop(cdev);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001012err2:
Yuval Mintz8c925c42016-03-02 20:26:03 +02001013 qed_hw_timers_stop_all(cdev);
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001014 if (IS_PF(cdev))
1015 qed_slowpath_irq_free(cdev);
Yuval Mintz8c925c42016-03-02 20:26:03 +02001016 qed_free_stream_mem(cdev);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001017 qed_disable_msix(cdev);
1018err1:
1019 qed_resc_free(cdev);
1020err:
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001021 if (IS_PF(cdev))
1022 release_firmware(cdev->firmware);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001023
Sudarsana Reddy Kalluruc78c70f2017-02-15 10:24:10 +02001024 if (IS_PF(cdev) && QED_LEADING_HWFN(cdev)->p_ptp_ptt)
1025 qed_ptt_release(QED_LEADING_HWFN(cdev),
1026 QED_LEADING_HWFN(cdev)->p_ptp_ptt);
1027
Yuval Mintz37bff2b2016-05-11 16:36:13 +03001028 qed_iov_wq_stop(cdev, false);
1029
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001030 return rc;
1031}
1032
1033static int qed_slowpath_stop(struct qed_dev *cdev)
1034{
1035 if (!cdev)
1036 return -ENODEV;
1037
Yuval Mintz0a7fb112016-10-01 21:59:55 +03001038 qed_ll2_dealloc_if(cdev);
1039
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001040 if (IS_PF(cdev)) {
Sudarsana Reddy Kalluruc78c70f2017-02-15 10:24:10 +02001041 qed_ptt_release(QED_LEADING_HWFN(cdev),
1042 QED_LEADING_HWFN(cdev)->p_ptp_ptt);
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001043 qed_free_stream_mem(cdev);
Yuval Mintzc5ac9312016-06-03 14:35:34 +03001044 if (IS_QED_ETH_IF(cdev))
1045 qed_sriov_disable(cdev, true);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001046
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001047 qed_nic_stop(cdev);
1048 qed_slowpath_irq_free(cdev);
1049 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001050
1051 qed_disable_msix(cdev);
Tomer Tayar12263372017-03-28 15:12:50 +03001052
1053 qed_resc_free(cdev);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001054
Yuval Mintz37bff2b2016-05-11 16:36:13 +03001055 qed_iov_wq_stop(cdev, true);
1056
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001057 if (IS_PF(cdev))
1058 release_firmware(cdev->firmware);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001059
1060 return 0;
1061}
1062
1063static void qed_set_id(struct qed_dev *cdev, char name[NAME_SIZE],
1064 char ver_str[VER_SIZE])
1065{
1066 int i;
1067
1068 memcpy(cdev->name, name, NAME_SIZE);
1069 for_each_hwfn(cdev, i)
1070 snprintf(cdev->hwfns[i].name, NAME_SIZE, "%s-%d", name, i);
1071
1072 memcpy(cdev->ver_str, ver_str, VER_SIZE);
1073 cdev->drv_type = DRV_ID_DRV_TYPE_LINUX;
1074}
1075
1076static u32 qed_sb_init(struct qed_dev *cdev,
1077 struct qed_sb_info *sb_info,
1078 void *sb_virt_addr,
1079 dma_addr_t sb_phy_addr, u16 sb_id,
1080 enum qed_sb_type type)
1081{
1082 struct qed_hwfn *p_hwfn;
Mintz, Yuval85750d72017-02-20 22:43:38 +02001083 struct qed_ptt *p_ptt;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001084 int hwfn_index;
1085 u16 rel_sb_id;
1086 u8 n_hwfns;
1087 u32 rc;
1088
1089 /* RoCE uses single engine and CMT uses two engines. When using both
1090 * we force only a single engine. Storage uses only engine 0 too.
1091 */
1092 if (type == QED_SB_TYPE_L2_QUEUE)
1093 n_hwfns = cdev->num_hwfns;
1094 else
1095 n_hwfns = 1;
1096
1097 hwfn_index = sb_id % n_hwfns;
1098 p_hwfn = &cdev->hwfns[hwfn_index];
1099 rel_sb_id = sb_id / n_hwfns;
1100
1101 DP_VERBOSE(cdev, NETIF_MSG_INTR,
1102 "hwfn [%d] <--[init]-- SB %04x [0x%04x upper]\n",
1103 hwfn_index, rel_sb_id, sb_id);
1104
Mintz, Yuval85750d72017-02-20 22:43:38 +02001105 if (IS_PF(p_hwfn->cdev)) {
1106 p_ptt = qed_ptt_acquire(p_hwfn);
1107 if (!p_ptt)
1108 return -EBUSY;
1109
1110 rc = qed_int_sb_init(p_hwfn, p_ptt, sb_info, sb_virt_addr,
1111 sb_phy_addr, rel_sb_id);
1112 qed_ptt_release(p_hwfn, p_ptt);
1113 } else {
1114 rc = qed_int_sb_init(p_hwfn, NULL, sb_info, sb_virt_addr,
1115 sb_phy_addr, rel_sb_id);
1116 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001117
1118 return rc;
1119}
1120
1121static u32 qed_sb_release(struct qed_dev *cdev,
Yuval Mintz1a635e42016-08-15 10:42:43 +03001122 struct qed_sb_info *sb_info, u16 sb_id)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001123{
1124 struct qed_hwfn *p_hwfn;
1125 int hwfn_index;
1126 u16 rel_sb_id;
1127 u32 rc;
1128
1129 hwfn_index = sb_id % cdev->num_hwfns;
1130 p_hwfn = &cdev->hwfns[hwfn_index];
1131 rel_sb_id = sb_id / cdev->num_hwfns;
1132
1133 DP_VERBOSE(cdev, NETIF_MSG_INTR,
1134 "hwfn [%d] <--[init]-- SB %04x [0x%04x upper]\n",
1135 hwfn_index, rel_sb_id, sb_id);
1136
1137 rc = qed_int_sb_release(p_hwfn, sb_info, rel_sb_id);
1138
1139 return rc;
1140}
1141
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +03001142static bool qed_can_link_change(struct qed_dev *cdev)
1143{
1144 return true;
1145}
1146
Yuval Mintz351a4ded2016-06-02 10:23:29 +03001147static int qed_set_link(struct qed_dev *cdev, struct qed_link_params *params)
Yuval Mintzcc875c22015-10-26 11:02:31 +02001148{
1149 struct qed_hwfn *hwfn;
1150 struct qed_mcp_link_params *link_params;
1151 struct qed_ptt *ptt;
1152 int rc;
1153
1154 if (!cdev)
1155 return -ENODEV;
1156
1157 /* The link should be set only once per PF */
1158 hwfn = &cdev->hwfns[0];
1159
Mintz, Yuval65ed2ff2017-02-20 22:43:39 +02001160 /* When VF wants to set link, force it to read the bulletin instead.
1161 * This mimics the PF behavior, where a noitification [both immediate
1162 * and possible later] would be generated when changing properties.
1163 */
1164 if (IS_VF(cdev)) {
1165 qed_schedule_iov(hwfn, QED_IOV_WQ_VF_FORCE_LINK_QUERY_FLAG);
1166 return 0;
1167 }
1168
Yuval Mintzcc875c22015-10-26 11:02:31 +02001169 ptt = qed_ptt_acquire(hwfn);
1170 if (!ptt)
1171 return -EBUSY;
1172
1173 link_params = qed_mcp_get_link_params(hwfn);
1174 if (params->override_flags & QED_LINK_OVERRIDE_SPEED_AUTONEG)
1175 link_params->speed.autoneg = params->autoneg;
1176 if (params->override_flags & QED_LINK_OVERRIDE_SPEED_ADV_SPEEDS) {
1177 link_params->speed.advertised_speeds = 0;
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001178 if ((params->adv_speeds & QED_LM_1000baseT_Half_BIT) ||
1179 (params->adv_speeds & QED_LM_1000baseT_Full_BIT))
Yuval Mintzcc875c22015-10-26 11:02:31 +02001180 link_params->speed.advertised_speeds |=
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001181 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G;
1182 if (params->adv_speeds & QED_LM_10000baseKR_Full_BIT)
Yuval Mintzcc875c22015-10-26 11:02:31 +02001183 link_params->speed.advertised_speeds |=
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001184 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G;
1185 if (params->adv_speeds & QED_LM_25000baseKR_Full_BIT)
Yuval Mintzcc875c22015-10-26 11:02:31 +02001186 link_params->speed.advertised_speeds |=
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001187 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_25G;
1188 if (params->adv_speeds & QED_LM_40000baseLR4_Full_BIT)
Yuval Mintzcc875c22015-10-26 11:02:31 +02001189 link_params->speed.advertised_speeds |=
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001190 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G;
1191 if (params->adv_speeds & QED_LM_50000baseKR2_Full_BIT)
1192 link_params->speed.advertised_speeds |=
1193 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_50G;
1194 if (params->adv_speeds & QED_LM_100000baseKR4_Full_BIT)
Yuval Mintzcc875c22015-10-26 11:02:31 +02001195 link_params->speed.advertised_speeds |=
Yuval Mintz351a4ded2016-06-02 10:23:29 +03001196 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_BB_100G;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001197 }
1198 if (params->override_flags & QED_LINK_OVERRIDE_SPEED_FORCED_SPEED)
1199 link_params->speed.forced_speed = params->forced_speed;
Sudarsana Reddy Kallurua43f2352016-04-22 08:41:04 +03001200 if (params->override_flags & QED_LINK_OVERRIDE_PAUSE_CONFIG) {
1201 if (params->pause_config & QED_LINK_PAUSE_AUTONEG_ENABLE)
1202 link_params->pause.autoneg = true;
1203 else
1204 link_params->pause.autoneg = false;
1205 if (params->pause_config & QED_LINK_PAUSE_RX_ENABLE)
1206 link_params->pause.forced_rx = true;
1207 else
1208 link_params->pause.forced_rx = false;
1209 if (params->pause_config & QED_LINK_PAUSE_TX_ENABLE)
1210 link_params->pause.forced_tx = true;
1211 else
1212 link_params->pause.forced_tx = false;
1213 }
Sudarsana Reddy Kalluru03dc76c2016-04-28 20:20:52 -04001214 if (params->override_flags & QED_LINK_OVERRIDE_LOOPBACK_MODE) {
1215 switch (params->loopback_mode) {
1216 case QED_LINK_LOOPBACK_INT_PHY:
Yuval Mintz351a4ded2016-06-02 10:23:29 +03001217 link_params->loopback_mode = ETH_LOOPBACK_INT_PHY;
Sudarsana Reddy Kalluru03dc76c2016-04-28 20:20:52 -04001218 break;
1219 case QED_LINK_LOOPBACK_EXT_PHY:
Yuval Mintz351a4ded2016-06-02 10:23:29 +03001220 link_params->loopback_mode = ETH_LOOPBACK_EXT_PHY;
Sudarsana Reddy Kalluru03dc76c2016-04-28 20:20:52 -04001221 break;
1222 case QED_LINK_LOOPBACK_EXT:
Yuval Mintz351a4ded2016-06-02 10:23:29 +03001223 link_params->loopback_mode = ETH_LOOPBACK_EXT;
Sudarsana Reddy Kalluru03dc76c2016-04-28 20:20:52 -04001224 break;
1225 case QED_LINK_LOOPBACK_MAC:
Yuval Mintz351a4ded2016-06-02 10:23:29 +03001226 link_params->loopback_mode = ETH_LOOPBACK_MAC;
Sudarsana Reddy Kalluru03dc76c2016-04-28 20:20:52 -04001227 break;
1228 default:
Yuval Mintz351a4ded2016-06-02 10:23:29 +03001229 link_params->loopback_mode = ETH_LOOPBACK_NONE;
Sudarsana Reddy Kalluru03dc76c2016-04-28 20:20:52 -04001230 break;
1231 }
1232 }
Yuval Mintzcc875c22015-10-26 11:02:31 +02001233
1234 rc = qed_mcp_set_link(hwfn, ptt, params->link_up);
1235
1236 qed_ptt_release(hwfn, ptt);
1237
1238 return rc;
1239}
1240
1241static int qed_get_port_type(u32 media_type)
1242{
1243 int port_type;
1244
1245 switch (media_type) {
1246 case MEDIA_SFPP_10G_FIBER:
1247 case MEDIA_SFP_1G_FIBER:
1248 case MEDIA_XFP_FIBER:
Yuval Mintzb639f192016-06-19 15:18:15 +03001249 case MEDIA_MODULE_FIBER:
Yuval Mintzcc875c22015-10-26 11:02:31 +02001250 case MEDIA_KR:
1251 port_type = PORT_FIBRE;
1252 break;
1253 case MEDIA_DA_TWINAX:
1254 port_type = PORT_DA;
1255 break;
1256 case MEDIA_BASE_T:
1257 port_type = PORT_TP;
1258 break;
1259 case MEDIA_NOT_PRESENT:
1260 port_type = PORT_NONE;
1261 break;
1262 case MEDIA_UNSPECIFIED:
1263 default:
1264 port_type = PORT_OTHER;
1265 break;
1266 }
1267 return port_type;
1268}
1269
Arnd Bergmann14b84e82016-06-01 15:29:13 +02001270static int qed_get_link_data(struct qed_hwfn *hwfn,
1271 struct qed_mcp_link_params *params,
1272 struct qed_mcp_link_state *link,
1273 struct qed_mcp_link_capabilities *link_caps)
1274{
1275 void *p;
1276
1277 if (!IS_PF(hwfn->cdev)) {
1278 qed_vf_get_link_params(hwfn, params);
1279 qed_vf_get_link_state(hwfn, link);
1280 qed_vf_get_link_caps(hwfn, link_caps);
1281
1282 return 0;
1283 }
1284
1285 p = qed_mcp_get_link_params(hwfn);
1286 if (!p)
1287 return -ENXIO;
1288 memcpy(params, p, sizeof(*params));
1289
1290 p = qed_mcp_get_link_state(hwfn);
1291 if (!p)
1292 return -ENXIO;
1293 memcpy(link, p, sizeof(*link));
1294
1295 p = qed_mcp_get_link_capabilities(hwfn);
1296 if (!p)
1297 return -ENXIO;
1298 memcpy(link_caps, p, sizeof(*link_caps));
1299
1300 return 0;
1301}
1302
Yuval Mintzcc875c22015-10-26 11:02:31 +02001303static void qed_fill_link(struct qed_hwfn *hwfn,
1304 struct qed_link_output *if_link)
1305{
1306 struct qed_mcp_link_params params;
1307 struct qed_mcp_link_state link;
1308 struct qed_mcp_link_capabilities link_caps;
1309 u32 media_type;
1310
1311 memset(if_link, 0, sizeof(*if_link));
1312
1313 /* Prepare source inputs */
Arnd Bergmann14b84e82016-06-01 15:29:13 +02001314 if (qed_get_link_data(hwfn, &params, &link, &link_caps)) {
1315 dev_warn(&hwfn->cdev->pdev->dev, "no link data available\n");
1316 return;
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001317 }
Yuval Mintzcc875c22015-10-26 11:02:31 +02001318
1319 /* Set the link parameters to pass to protocol driver */
1320 if (link.link_up)
1321 if_link->link_up = true;
1322
1323 /* TODO - at the moment assume supported and advertised speed equal */
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001324 if_link->supported_caps = QED_LM_FIBRE_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001325 if (params.speed.autoneg)
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001326 if_link->supported_caps |= QED_LM_Autoneg_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001327 if (params.pause.autoneg ||
1328 (params.pause.forced_rx && params.pause.forced_tx))
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001329 if_link->supported_caps |= QED_LM_Asym_Pause_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001330 if (params.pause.autoneg || params.pause.forced_rx ||
1331 params.pause.forced_tx)
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001332 if_link->supported_caps |= QED_LM_Pause_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001333
1334 if_link->advertised_caps = if_link->supported_caps;
1335 if (params.speed.advertised_speeds &
1336 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G)
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001337 if_link->advertised_caps |= QED_LM_1000baseT_Half_BIT |
1338 QED_LM_1000baseT_Full_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001339 if (params.speed.advertised_speeds &
1340 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G)
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001341 if_link->advertised_caps |= QED_LM_10000baseKR_Full_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001342 if (params.speed.advertised_speeds &
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001343 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_25G)
1344 if_link->advertised_caps |= QED_LM_25000baseKR_Full_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001345 if (params.speed.advertised_speeds &
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001346 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G)
1347 if_link->advertised_caps |= QED_LM_40000baseLR4_Full_BIT;
1348 if (params.speed.advertised_speeds &
1349 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_50G)
1350 if_link->advertised_caps |= QED_LM_50000baseKR2_Full_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001351 if (params.speed.advertised_speeds &
Yuval Mintz351a4ded2016-06-02 10:23:29 +03001352 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_BB_100G)
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001353 if_link->advertised_caps |= QED_LM_100000baseKR4_Full_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001354
1355 if (link_caps.speed_capabilities &
1356 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G)
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001357 if_link->supported_caps |= QED_LM_1000baseT_Half_BIT |
1358 QED_LM_1000baseT_Full_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001359 if (link_caps.speed_capabilities &
1360 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G)
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001361 if_link->supported_caps |= QED_LM_10000baseKR_Full_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001362 if (link_caps.speed_capabilities &
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001363 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_25G)
1364 if_link->supported_caps |= QED_LM_25000baseKR_Full_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001365 if (link_caps.speed_capabilities &
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001366 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G)
1367 if_link->supported_caps |= QED_LM_40000baseLR4_Full_BIT;
1368 if (link_caps.speed_capabilities &
1369 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_50G)
1370 if_link->supported_caps |= QED_LM_50000baseKR2_Full_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001371 if (link_caps.speed_capabilities &
Yuval Mintz351a4ded2016-06-02 10:23:29 +03001372 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_BB_100G)
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001373 if_link->supported_caps |= QED_LM_100000baseKR4_Full_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001374
1375 if (link.link_up)
1376 if_link->speed = link.speed;
1377
1378 /* TODO - fill duplex properly */
1379 if_link->duplex = DUPLEX_FULL;
1380 qed_mcp_get_media_type(hwfn->cdev, &media_type);
1381 if_link->port = qed_get_port_type(media_type);
1382
1383 if_link->autoneg = params.speed.autoneg;
1384
1385 if (params.pause.autoneg)
1386 if_link->pause_config |= QED_LINK_PAUSE_AUTONEG_ENABLE;
1387 if (params.pause.forced_rx)
1388 if_link->pause_config |= QED_LINK_PAUSE_RX_ENABLE;
1389 if (params.pause.forced_tx)
1390 if_link->pause_config |= QED_LINK_PAUSE_TX_ENABLE;
1391
1392 /* Link partner capabilities */
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001393 if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_1G_HD)
1394 if_link->lp_caps |= QED_LM_1000baseT_Half_BIT;
1395 if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_1G_FD)
1396 if_link->lp_caps |= QED_LM_1000baseT_Full_BIT;
1397 if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_10G)
1398 if_link->lp_caps |= QED_LM_10000baseKR_Full_BIT;
1399 if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_25G)
1400 if_link->lp_caps |= QED_LM_25000baseKR_Full_BIT;
1401 if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_40G)
1402 if_link->lp_caps |= QED_LM_40000baseLR4_Full_BIT;
1403 if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_50G)
1404 if_link->lp_caps |= QED_LM_50000baseKR2_Full_BIT;
1405 if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_100G)
1406 if_link->lp_caps |= QED_LM_100000baseKR4_Full_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001407
1408 if (link.an_complete)
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001409 if_link->lp_caps |= QED_LM_Autoneg_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001410
1411 if (link.partner_adv_pause)
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001412 if_link->lp_caps |= QED_LM_Pause_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001413 if (link.partner_adv_pause == QED_LINK_PARTNER_ASYMMETRIC_PAUSE ||
1414 link.partner_adv_pause == QED_LINK_PARTNER_BOTH_PAUSE)
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001415 if_link->lp_caps |= QED_LM_Asym_Pause_BIT;
Yuval Mintzcc875c22015-10-26 11:02:31 +02001416}
1417
1418static void qed_get_current_link(struct qed_dev *cdev,
1419 struct qed_link_output *if_link)
1420{
Yuval Mintz36558c32016-05-11 16:36:17 +03001421 int i;
1422
Yuval Mintzcc875c22015-10-26 11:02:31 +02001423 qed_fill_link(&cdev->hwfns[0], if_link);
Yuval Mintz36558c32016-05-11 16:36:17 +03001424
1425 for_each_hwfn(cdev, i)
1426 qed_inform_vf_link_state(&cdev->hwfns[i]);
Yuval Mintzcc875c22015-10-26 11:02:31 +02001427}
1428
1429void qed_link_update(struct qed_hwfn *hwfn)
1430{
1431 void *cookie = hwfn->cdev->ops_cookie;
1432 struct qed_common_cb_ops *op = hwfn->cdev->protocol_ops.common;
1433 struct qed_link_output if_link;
1434
1435 qed_fill_link(hwfn, &if_link);
Yuval Mintz36558c32016-05-11 16:36:17 +03001436 qed_inform_vf_link_state(hwfn);
Yuval Mintzcc875c22015-10-26 11:02:31 +02001437
1438 if (IS_LEAD_HWFN(hwfn) && cookie)
1439 op->link_update(cookie, &if_link);
1440}
1441
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001442static int qed_drain(struct qed_dev *cdev)
1443{
1444 struct qed_hwfn *hwfn;
1445 struct qed_ptt *ptt;
1446 int i, rc;
1447
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001448 if (IS_VF(cdev))
1449 return 0;
1450
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001451 for_each_hwfn(cdev, i) {
1452 hwfn = &cdev->hwfns[i];
1453 ptt = qed_ptt_acquire(hwfn);
1454 if (!ptt) {
1455 DP_NOTICE(hwfn, "Failed to drain NIG; No PTT\n");
1456 return -EBUSY;
1457 }
1458 rc = qed_mcp_drain(hwfn, ptt);
1459 if (rc)
1460 return rc;
1461 qed_ptt_release(hwfn, ptt);
1462 }
1463
1464 return 0;
1465}
1466
Sudarsana Reddy Kalluru722003a2016-06-21 09:36:21 -04001467static void qed_get_coalesce(struct qed_dev *cdev, u16 *rx_coal, u16 *tx_coal)
1468{
1469 *rx_coal = cdev->rx_coalesce_usecs;
1470 *tx_coal = cdev->tx_coalesce_usecs;
1471}
1472
1473static int qed_set_coalesce(struct qed_dev *cdev, u16 rx_coal, u16 tx_coal,
1474 u8 qid, u16 sb_id)
1475{
1476 struct qed_hwfn *hwfn;
1477 struct qed_ptt *ptt;
1478 int hwfn_index;
1479 int status = 0;
1480
1481 hwfn_index = qid % cdev->num_hwfns;
1482 hwfn = &cdev->hwfns[hwfn_index];
1483 ptt = qed_ptt_acquire(hwfn);
1484 if (!ptt)
1485 return -EAGAIN;
1486
1487 status = qed_set_rxq_coalesce(hwfn, ptt, rx_coal,
1488 qid / cdev->num_hwfns, sb_id);
1489 if (status)
1490 goto out;
1491 status = qed_set_txq_coalesce(hwfn, ptt, tx_coal,
1492 qid / cdev->num_hwfns, sb_id);
1493out:
1494 qed_ptt_release(hwfn, ptt);
1495
1496 return status;
1497}
1498
Sudarsana Kalluru91420b82015-11-30 12:25:03 +02001499static int qed_set_led(struct qed_dev *cdev, enum qed_led_mode mode)
1500{
1501 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1502 struct qed_ptt *ptt;
1503 int status = 0;
1504
1505 ptt = qed_ptt_acquire(hwfn);
1506 if (!ptt)
1507 return -EAGAIN;
1508
1509 status = qed_mcp_set_led(hwfn, ptt, mode);
1510
1511 qed_ptt_release(hwfn, ptt);
1512
1513 return status;
1514}
1515
Mintz, Yuval14d39642016-10-31 07:14:23 +02001516static int qed_update_wol(struct qed_dev *cdev, bool enabled)
1517{
1518 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1519 struct qed_ptt *ptt;
1520 int rc = 0;
1521
1522 if (IS_VF(cdev))
1523 return 0;
1524
1525 ptt = qed_ptt_acquire(hwfn);
1526 if (!ptt)
1527 return -EAGAIN;
1528
1529 rc = qed_mcp_ov_update_wol(hwfn, ptt, enabled ? QED_OV_WOL_ENABLED
1530 : QED_OV_WOL_DISABLED);
1531 if (rc)
1532 goto out;
1533 rc = qed_mcp_ov_update_current_config(hwfn, ptt, QED_OV_CLIENT_DRV);
1534
1535out:
1536 qed_ptt_release(hwfn, ptt);
1537 return rc;
1538}
1539
Sudarsana Kalluru0fefbfb2016-10-31 07:14:21 +02001540static int qed_update_drv_state(struct qed_dev *cdev, bool active)
1541{
1542 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1543 struct qed_ptt *ptt;
1544 int status = 0;
1545
1546 if (IS_VF(cdev))
1547 return 0;
1548
1549 ptt = qed_ptt_acquire(hwfn);
1550 if (!ptt)
1551 return -EAGAIN;
1552
1553 status = qed_mcp_ov_update_driver_state(hwfn, ptt, active ?
1554 QED_OV_DRIVER_STATE_ACTIVE :
1555 QED_OV_DRIVER_STATE_DISABLED);
1556
1557 qed_ptt_release(hwfn, ptt);
1558
1559 return status;
1560}
1561
1562static int qed_update_mac(struct qed_dev *cdev, u8 *mac)
1563{
1564 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1565 struct qed_ptt *ptt;
1566 int status = 0;
1567
1568 if (IS_VF(cdev))
1569 return 0;
1570
1571 ptt = qed_ptt_acquire(hwfn);
1572 if (!ptt)
1573 return -EAGAIN;
1574
1575 status = qed_mcp_ov_update_mac(hwfn, ptt, mac);
1576 if (status)
1577 goto out;
1578
1579 status = qed_mcp_ov_update_current_config(hwfn, ptt, QED_OV_CLIENT_DRV);
1580
1581out:
1582 qed_ptt_release(hwfn, ptt);
1583 return status;
1584}
1585
1586static int qed_update_mtu(struct qed_dev *cdev, u16 mtu)
1587{
1588 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1589 struct qed_ptt *ptt;
1590 int status = 0;
1591
1592 if (IS_VF(cdev))
1593 return 0;
1594
1595 ptt = qed_ptt_acquire(hwfn);
1596 if (!ptt)
1597 return -EAGAIN;
1598
1599 status = qed_mcp_ov_update_mtu(hwfn, ptt, mtu);
1600 if (status)
1601 goto out;
1602
1603 status = qed_mcp_ov_update_current_config(hwfn, ptt, QED_OV_CLIENT_DRV);
1604
1605out:
1606 qed_ptt_release(hwfn, ptt);
1607 return status;
1608}
1609
Yuval Mintz8c93bea2016-10-13 22:57:03 +03001610static struct qed_selftest_ops qed_selftest_ops_pass = {
Sudarsana Reddy Kalluru03dc76c2016-04-28 20:20:52 -04001611 .selftest_memory = &qed_selftest_memory,
1612 .selftest_interrupt = &qed_selftest_interrupt,
1613 .selftest_register = &qed_selftest_register,
1614 .selftest_clock = &qed_selftest_clock,
Mintz, Yuval7a4b21b2016-10-31 07:14:22 +02001615 .selftest_nvram = &qed_selftest_nvram,
Sudarsana Reddy Kalluru03dc76c2016-04-28 20:20:52 -04001616};
1617
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001618const struct qed_common_ops qed_common_ops_pass = {
Sudarsana Reddy Kalluru03dc76c2016-04-28 20:20:52 -04001619 .selftest = &qed_selftest_ops_pass,
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001620 .probe = &qed_probe,
1621 .remove = &qed_remove,
1622 .set_power_state = &qed_set_power_state,
1623 .set_id = &qed_set_id,
1624 .update_pf_params = &qed_update_pf_params,
1625 .slowpath_start = &qed_slowpath_start,
1626 .slowpath_stop = &qed_slowpath_stop,
1627 .set_fp_int = &qed_set_int_fp,
1628 .get_fp_int = &qed_get_int_fp,
1629 .sb_init = &qed_sb_init,
1630 .sb_release = &qed_sb_release,
1631 .simd_handler_config = &qed_simd_handler_config,
1632 .simd_handler_clean = &qed_simd_handler_clean,
Arun Easi1e128c82017-02-15 06:28:22 -08001633 .dbg_grc = &qed_dbg_grc,
1634 .dbg_grc_size = &qed_dbg_grc_size,
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +03001635 .can_link_change = &qed_can_link_change,
Yuval Mintzcc875c22015-10-26 11:02:31 +02001636 .set_link = &qed_set_link,
1637 .get_link = &qed_get_current_link,
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001638 .drain = &qed_drain,
1639 .update_msglvl = &qed_init_dp,
Tomer Tayare0971c82016-09-07 16:36:25 +03001640 .dbg_all_data = &qed_dbg_all_data,
1641 .dbg_all_data_size = &qed_dbg_all_data_size,
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001642 .chain_alloc = &qed_chain_alloc,
1643 .chain_free = &qed_chain_free,
Sudarsana Reddy Kalluru722003a2016-06-21 09:36:21 -04001644 .get_coalesce = &qed_get_coalesce,
1645 .set_coalesce = &qed_set_coalesce,
Sudarsana Kalluru91420b82015-11-30 12:25:03 +02001646 .set_led = &qed_set_led,
Sudarsana Kalluru0fefbfb2016-10-31 07:14:21 +02001647 .update_drv_state = &qed_update_drv_state,
1648 .update_mac = &qed_update_mac,
1649 .update_mtu = &qed_update_mtu,
Mintz, Yuval14d39642016-10-31 07:14:23 +02001650 .update_wol = &qed_update_wol,
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001651};
Sudarsana Reddy Kalluru6c754242016-08-16 10:51:03 -04001652
1653void qed_get_protocol_stats(struct qed_dev *cdev,
1654 enum qed_mcp_protocol_type type,
1655 union qed_mcp_protocol_stats *stats)
1656{
1657 struct qed_eth_stats eth_stats;
1658
1659 memset(stats, 0, sizeof(*stats));
1660
1661 switch (type) {
1662 case QED_MCP_LAN_STATS:
1663 qed_get_vport_stats(cdev, &eth_stats);
Mintz, Yuval9c79dda2017-03-14 16:23:54 +02001664 stats->lan_stats.ucast_rx_pkts =
1665 eth_stats.common.rx_ucast_pkts;
1666 stats->lan_stats.ucast_tx_pkts =
1667 eth_stats.common.tx_ucast_pkts;
Sudarsana Reddy Kalluru6c754242016-08-16 10:51:03 -04001668 stats->lan_stats.fcs_err = -1;
1669 break;
Arun Easi1e128c82017-02-15 06:28:22 -08001670 case QED_MCP_FCOE_STATS:
1671 qed_get_protocol_stats_fcoe(cdev, &stats->fcoe_stats);
1672 break;
Sudarsana Reddy Kalluru6c754242016-08-16 10:51:03 -04001673 default:
1674 DP_ERR(cdev, "Invalid protocol type = %d\n", type);
1675 return;
1676 }
1677}