]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - drivers/net/ethernet/qlogic/qed/qed_dev.c
qed: Fix allocation in interrupt context
[mirror_ubuntu-zesty-kernel.git] / drivers / net / ethernet / qlogic / qed / qed_dev.c
CommitLineData
fe56b9e6
YM
1/* 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/types.h>
10#include <asm/byteorder.h>
11#include <linux/io.h>
12#include <linux/delay.h>
13#include <linux/dma-mapping.h>
14#include <linux/errno.h>
15#include <linux/kernel.h>
16#include <linux/mutex.h>
17#include <linux/pci.h>
18#include <linux/slab.h>
19#include <linux/string.h>
20#include <linux/etherdevice.h>
21#include <linux/qed/qed_chain.h>
22#include <linux/qed/qed_if.h>
23#include "qed.h"
24#include "qed_cxt.h"
39651abd 25#include "qed_dcbx.h"
fe56b9e6
YM
26#include "qed_dev_api.h"
27#include "qed_hsi.h"
28#include "qed_hw.h"
29#include "qed_init_ops.h"
30#include "qed_int.h"
31#include "qed_mcp.h"
32#include "qed_reg_addr.h"
33#include "qed_sp.h"
32a47e72 34#include "qed_sriov.h"
0b55e27d 35#include "qed_vf.h"
fe56b9e6 36
39651abd
SRK
37static spinlock_t qm_lock;
38static bool qm_lock_init = false;
39
fe56b9e6 40/* API common to all protocols */
c2035eea
RA
41enum BAR_ID {
42 BAR_ID_0, /* used for GRC */
43 BAR_ID_1 /* Used for doorbells */
44};
45
46static u32 qed_hw_bar_size(struct qed_hwfn *p_hwfn,
47 enum BAR_ID bar_id)
48{
1408cc1f
YM
49 u32 bar_reg = (bar_id == BAR_ID_0 ?
50 PGLUE_B_REG_PF_BAR0_SIZE : PGLUE_B_REG_PF_BAR1_SIZE);
51 u32 val;
c2035eea 52
1408cc1f
YM
53 if (IS_VF(p_hwfn->cdev))
54 return 1 << 17;
55
56 val = qed_rd(p_hwfn, p_hwfn->p_main_ptt, bar_reg);
c2035eea
RA
57 if (val)
58 return 1 << (val + 15);
59
60 /* Old MFW initialized above registered only conditionally */
61 if (p_hwfn->cdev->num_hwfns > 1) {
62 DP_INFO(p_hwfn,
63 "BAR size not configured. Assuming BAR size of 256kB for GRC and 512kB for DB\n");
64 return BAR_ID_0 ? 256 * 1024 : 512 * 1024;
65 } else {
66 DP_INFO(p_hwfn,
67 "BAR size not configured. Assuming BAR size of 512kB for GRC and 512kB for DB\n");
68 return 512 * 1024;
69 }
70}
71
fe56b9e6
YM
72void qed_init_dp(struct qed_dev *cdev,
73 u32 dp_module, u8 dp_level)
74{
75 u32 i;
76
77 cdev->dp_level = dp_level;
78 cdev->dp_module = dp_module;
79 for (i = 0; i < MAX_HWFNS_PER_DEVICE; i++) {
80 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
81
82 p_hwfn->dp_level = dp_level;
83 p_hwfn->dp_module = dp_module;
84 }
85}
86
87void qed_init_struct(struct qed_dev *cdev)
88{
89 u8 i;
90
91 for (i = 0; i < MAX_HWFNS_PER_DEVICE; i++) {
92 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
93
94 p_hwfn->cdev = cdev;
95 p_hwfn->my_id = i;
96 p_hwfn->b_active = false;
97
98 mutex_init(&p_hwfn->dmae_info.mutex);
99 }
100
101 /* hwfn 0 is always active */
102 cdev->hwfns[0].b_active = true;
103
104 /* set the default cache alignment to 128 */
105 cdev->cache_shift = 7;
106}
107
108static void qed_qm_info_free(struct qed_hwfn *p_hwfn)
109{
110 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
111
112 kfree(qm_info->qm_pq_params);
113 qm_info->qm_pq_params = NULL;
114 kfree(qm_info->qm_vport_params);
115 qm_info->qm_vport_params = NULL;
116 kfree(qm_info->qm_port_params);
117 qm_info->qm_port_params = NULL;
bcd197c8
MC
118 kfree(qm_info->wfq_data);
119 qm_info->wfq_data = NULL;
fe56b9e6
YM
120}
121
122void qed_resc_free(struct qed_dev *cdev)
123{
124 int i;
125
1408cc1f
YM
126 if (IS_VF(cdev))
127 return;
128
fe56b9e6
YM
129 kfree(cdev->fw_data);
130 cdev->fw_data = NULL;
131
132 kfree(cdev->reset_stats);
133
25c089d7
YM
134 for_each_hwfn(cdev, i) {
135 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
136
137 kfree(p_hwfn->p_tx_cids);
138 p_hwfn->p_tx_cids = NULL;
139 kfree(p_hwfn->p_rx_cids);
140 p_hwfn->p_rx_cids = NULL;
141 }
142
fe56b9e6
YM
143 for_each_hwfn(cdev, i) {
144 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
145
146 qed_cxt_mngr_free(p_hwfn);
147 qed_qm_info_free(p_hwfn);
148 qed_spq_free(p_hwfn);
149 qed_eq_free(p_hwfn, p_hwfn->p_eq);
150 qed_consq_free(p_hwfn, p_hwfn->p_consq);
151 qed_int_free(p_hwfn);
32a47e72 152 qed_iov_free(p_hwfn);
fe56b9e6 153 qed_dmae_info_free(p_hwfn);
39651abd 154 qed_dcbx_info_free(p_hwfn, p_hwfn->p_dcbx_info);
fe56b9e6
YM
155 }
156}
157
79529291 158static int qed_init_qm_info(struct qed_hwfn *p_hwfn, bool b_sleepable)
fe56b9e6 159{
1408cc1f 160 u8 num_vports, vf_offset = 0, i, vport_id, num_ports, curr_queue = 0;
fe56b9e6
YM
161 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
162 struct init_qm_port_params *p_qm_port;
fe56b9e6 163 u16 num_pqs, multi_cos_tcs = 1;
1408cc1f 164 u16 num_vfs = 0;
fe56b9e6 165
1408cc1f
YM
166#ifdef CONFIG_QED_SRIOV
167 if (p_hwfn->cdev->p_iov_info)
168 num_vfs = p_hwfn->cdev->p_iov_info->total_vfs;
169#endif
fe56b9e6
YM
170 memset(qm_info, 0, sizeof(*qm_info));
171
1408cc1f 172 num_pqs = multi_cos_tcs + num_vfs + 1; /* The '1' is for pure-LB */
fe56b9e6
YM
173 num_vports = (u8)RESC_NUM(p_hwfn, QED_VPORT);
174
175 /* Sanity checking that setup requires legal number of resources */
176 if (num_pqs > RESC_NUM(p_hwfn, QED_PQ)) {
177 DP_ERR(p_hwfn,
178 "Need too many Physical queues - 0x%04x when only %04x are available\n",
179 num_pqs, RESC_NUM(p_hwfn, QED_PQ));
180 return -EINVAL;
181 }
182
183 /* PQs will be arranged as follows: First per-TC PQ then pure-LB quete.
184 */
79529291
SRK
185 qm_info->qm_pq_params = kcalloc(num_pqs,
186 sizeof(struct init_qm_pq_params),
187 b_sleepable ? GFP_KERNEL : GFP_ATOMIC);
fe56b9e6
YM
188 if (!qm_info->qm_pq_params)
189 goto alloc_err;
190
79529291
SRK
191 qm_info->qm_vport_params = kcalloc(num_vports,
192 sizeof(struct init_qm_vport_params),
193 b_sleepable ? GFP_KERNEL
194 : GFP_ATOMIC);
fe56b9e6
YM
195 if (!qm_info->qm_vport_params)
196 goto alloc_err;
197
79529291
SRK
198 qm_info->qm_port_params = kcalloc(MAX_NUM_PORTS,
199 sizeof(struct init_qm_port_params),
200 b_sleepable ? GFP_KERNEL
201 : GFP_ATOMIC);
fe56b9e6
YM
202 if (!qm_info->qm_port_params)
203 goto alloc_err;
204
79529291
SRK
205 qm_info->wfq_data = kcalloc(num_vports, sizeof(struct qed_wfq_data),
206 b_sleepable ? GFP_KERNEL : GFP_ATOMIC);
bcd197c8
MC
207 if (!qm_info->wfq_data)
208 goto alloc_err;
209
fe56b9e6
YM
210 vport_id = (u8)RESC_START(p_hwfn, QED_VPORT);
211
212 /* First init per-TC PQs */
39651abd 213 for (i = 0; i < multi_cos_tcs; i++) {
1408cc1f 214 struct init_qm_pq_params *params =
39651abd
SRK
215 &qm_info->qm_pq_params[curr_queue++];
216
217 if (p_hwfn->hw_info.personality == QED_PCI_ETH) {
218 params->vport_id = vport_id;
219 params->tc_id = p_hwfn->hw_info.non_offload_tc;
220 params->wrr_group = 1;
221 } else {
222 params->vport_id = vport_id;
223 params->tc_id = p_hwfn->hw_info.offload_tc;
224 params->wrr_group = 1;
225 }
fe56b9e6
YM
226 }
227
228 /* Then init pure-LB PQ */
1408cc1f
YM
229 qm_info->pure_lb_pq = curr_queue;
230 qm_info->qm_pq_params[curr_queue].vport_id =
231 (u8) RESC_START(p_hwfn, QED_VPORT);
232 qm_info->qm_pq_params[curr_queue].tc_id = PURE_LB_TC;
233 qm_info->qm_pq_params[curr_queue].wrr_group = 1;
234 curr_queue++;
fe56b9e6
YM
235
236 qm_info->offload_pq = 0;
1408cc1f
YM
237 /* Then init per-VF PQs */
238 vf_offset = curr_queue;
239 for (i = 0; i < num_vfs; i++) {
240 /* First vport is used by the PF */
241 qm_info->qm_pq_params[curr_queue].vport_id = vport_id + i + 1;
242 qm_info->qm_pq_params[curr_queue].tc_id =
243 p_hwfn->hw_info.non_offload_tc;
244 qm_info->qm_pq_params[curr_queue].wrr_group = 1;
245 curr_queue++;
246 }
247
248 qm_info->vf_queues_offset = vf_offset;
fe56b9e6
YM
249 qm_info->num_pqs = num_pqs;
250 qm_info->num_vports = num_vports;
251
252 /* Initialize qm port parameters */
253 num_ports = p_hwfn->cdev->num_ports_in_engines;
254 for (i = 0; i < num_ports; i++) {
255 p_qm_port = &qm_info->qm_port_params[i];
256 p_qm_port->active = 1;
257 p_qm_port->num_active_phys_tcs = 4;
258 p_qm_port->num_pbf_cmd_lines = PBF_MAX_CMD_LINES / num_ports;
259 p_qm_port->num_btb_blocks = BTB_MAX_BLOCKS / num_ports;
260 }
261
262 qm_info->max_phys_tcs_per_port = NUM_OF_PHYS_TCS;
263
264 qm_info->start_pq = (u16)RESC_START(p_hwfn, QED_PQ);
265
1408cc1f
YM
266 qm_info->num_vf_pqs = num_vfs;
267 qm_info->start_vport = (u8) RESC_START(p_hwfn, QED_VPORT);
fe56b9e6 268
a64b02d5
MC
269 for (i = 0; i < qm_info->num_vports; i++)
270 qm_info->qm_vport_params[i].vport_wfq = 1;
271
fe56b9e6
YM
272 qm_info->pf_wfq = 0;
273 qm_info->pf_rl = 0;
274 qm_info->vport_rl_en = 1;
a64b02d5 275 qm_info->vport_wfq_en = 1;
fe56b9e6
YM
276
277 return 0;
278
279alloc_err:
280 DP_NOTICE(p_hwfn, "Failed to allocate memory for QM params\n");
bcd197c8 281 qed_qm_info_free(p_hwfn);
fe56b9e6
YM
282 return -ENOMEM;
283}
284
39651abd
SRK
285/* This function reconfigures the QM pf on the fly.
286 * For this purpose we:
287 * 1. reconfigure the QM database
288 * 2. set new values to runtime arrat
289 * 3. send an sdm_qm_cmd through the rbc interface to stop the QM
290 * 4. activate init tool in QM_PF stage
291 * 5. send an sdm_qm_cmd through rbc interface to release the QM
292 */
293int qed_qm_reconf(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
294{
295 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
296 bool b_rc;
297 int rc;
298
299 /* qm_info is allocated in qed_init_qm_info() which is already called
300 * from qed_resc_alloc() or previous call of qed_qm_reconf().
301 * The allocated size may change each init, so we free it before next
302 * allocation.
303 */
304 qed_qm_info_free(p_hwfn);
305
306 /* initialize qed's qm data structure */
79529291 307 rc = qed_init_qm_info(p_hwfn, false);
39651abd
SRK
308 if (rc)
309 return rc;
310
311 /* stop PF's qm queues */
312 spin_lock_bh(&qm_lock);
313 b_rc = qed_send_qm_stop_cmd(p_hwfn, p_ptt, false, true,
314 qm_info->start_pq, qm_info->num_pqs);
315 spin_unlock_bh(&qm_lock);
316 if (!b_rc)
317 return -EINVAL;
318
319 /* clear the QM_PF runtime phase leftovers from previous init */
320 qed_init_clear_rt_data(p_hwfn);
321
322 /* prepare QM portion of runtime array */
323 qed_qm_init_pf(p_hwfn);
324
325 /* activate init tool on runtime array */
326 rc = qed_init_run(p_hwfn, p_ptt, PHASE_QM_PF, p_hwfn->rel_pf_id,
327 p_hwfn->hw_info.hw_mode);
328 if (rc)
329 return rc;
330
331 /* start PF's qm queues */
332 spin_lock_bh(&qm_lock);
333 b_rc = qed_send_qm_stop_cmd(p_hwfn, p_ptt, true, true,
334 qm_info->start_pq, qm_info->num_pqs);
335 spin_unlock_bh(&qm_lock);
336 if (!b_rc)
337 return -EINVAL;
338
339 return 0;
340}
341
fe56b9e6
YM
342int qed_resc_alloc(struct qed_dev *cdev)
343{
344 struct qed_consq *p_consq;
345 struct qed_eq *p_eq;
346 int i, rc = 0;
347
1408cc1f
YM
348 if (IS_VF(cdev))
349 return rc;
350
fe56b9e6
YM
351 cdev->fw_data = kzalloc(sizeof(*cdev->fw_data), GFP_KERNEL);
352 if (!cdev->fw_data)
353 return -ENOMEM;
354
25c089d7
YM
355 /* Allocate Memory for the Queue->CID mapping */
356 for_each_hwfn(cdev, i) {
357 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
358 int tx_size = sizeof(struct qed_hw_cid_data) *
359 RESC_NUM(p_hwfn, QED_L2_QUEUE);
360 int rx_size = sizeof(struct qed_hw_cid_data) *
361 RESC_NUM(p_hwfn, QED_L2_QUEUE);
362
363 p_hwfn->p_tx_cids = kzalloc(tx_size, GFP_KERNEL);
364 if (!p_hwfn->p_tx_cids) {
365 DP_NOTICE(p_hwfn,
366 "Failed to allocate memory for Tx Cids\n");
9b15acbf 367 rc = -ENOMEM;
25c089d7
YM
368 goto alloc_err;
369 }
370
371 p_hwfn->p_rx_cids = kzalloc(rx_size, GFP_KERNEL);
372 if (!p_hwfn->p_rx_cids) {
373 DP_NOTICE(p_hwfn,
374 "Failed to allocate memory for Rx Cids\n");
9b15acbf 375 rc = -ENOMEM;
25c089d7
YM
376 goto alloc_err;
377 }
378 }
379
fe56b9e6
YM
380 for_each_hwfn(cdev, i) {
381 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
382
383 /* First allocate the context manager structure */
384 rc = qed_cxt_mngr_alloc(p_hwfn);
385 if (rc)
386 goto alloc_err;
387
388 /* Set the HW cid/tid numbers (in the contest manager)
389 * Must be done prior to any further computations.
390 */
391 rc = qed_cxt_set_pf_params(p_hwfn);
392 if (rc)
393 goto alloc_err;
394
395 /* Prepare and process QM requirements */
79529291 396 rc = qed_init_qm_info(p_hwfn, true);
fe56b9e6
YM
397 if (rc)
398 goto alloc_err;
399
400 /* Compute the ILT client partition */
401 rc = qed_cxt_cfg_ilt_compute(p_hwfn);
402 if (rc)
403 goto alloc_err;
404
405 /* CID map / ILT shadow table / T2
406 * The talbes sizes are determined by the computations above
407 */
408 rc = qed_cxt_tables_alloc(p_hwfn);
409 if (rc)
410 goto alloc_err;
411
412 /* SPQ, must follow ILT because initializes SPQ context */
413 rc = qed_spq_alloc(p_hwfn);
414 if (rc)
415 goto alloc_err;
416
417 /* SP status block allocation */
418 p_hwfn->p_dpc_ptt = qed_get_reserved_ptt(p_hwfn,
419 RESERVED_PTT_DPC);
420
421 rc = qed_int_alloc(p_hwfn, p_hwfn->p_main_ptt);
422 if (rc)
423 goto alloc_err;
424
32a47e72
YM
425 rc = qed_iov_alloc(p_hwfn);
426 if (rc)
427 goto alloc_err;
428
fe56b9e6
YM
429 /* EQ */
430 p_eq = qed_eq_alloc(p_hwfn, 256);
9b15acbf
DC
431 if (!p_eq) {
432 rc = -ENOMEM;
fe56b9e6 433 goto alloc_err;
9b15acbf 434 }
fe56b9e6
YM
435 p_hwfn->p_eq = p_eq;
436
437 p_consq = qed_consq_alloc(p_hwfn);
9b15acbf
DC
438 if (!p_consq) {
439 rc = -ENOMEM;
fe56b9e6 440 goto alloc_err;
9b15acbf 441 }
fe56b9e6
YM
442 p_hwfn->p_consq = p_consq;
443
444 /* DMA info initialization */
445 rc = qed_dmae_info_alloc(p_hwfn);
446 if (rc) {
447 DP_NOTICE(p_hwfn,
448 "Failed to allocate memory for dmae_info structure\n");
449 goto alloc_err;
450 }
39651abd
SRK
451
452 /* DCBX initialization */
453 rc = qed_dcbx_info_alloc(p_hwfn);
454 if (rc) {
455 DP_NOTICE(p_hwfn,
456 "Failed to allocate memory for dcbx structure\n");
457 goto alloc_err;
458 }
fe56b9e6
YM
459 }
460
461 cdev->reset_stats = kzalloc(sizeof(*cdev->reset_stats), GFP_KERNEL);
462 if (!cdev->reset_stats) {
463 DP_NOTICE(cdev, "Failed to allocate reset statistics\n");
9b15acbf 464 rc = -ENOMEM;
fe56b9e6
YM
465 goto alloc_err;
466 }
467
468 return 0;
469
470alloc_err:
471 qed_resc_free(cdev);
472 return rc;
473}
474
475void qed_resc_setup(struct qed_dev *cdev)
476{
477 int i;
478
1408cc1f
YM
479 if (IS_VF(cdev))
480 return;
481
fe56b9e6
YM
482 for_each_hwfn(cdev, i) {
483 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
484
485 qed_cxt_mngr_setup(p_hwfn);
486 qed_spq_setup(p_hwfn);
487 qed_eq_setup(p_hwfn, p_hwfn->p_eq);
488 qed_consq_setup(p_hwfn, p_hwfn->p_consq);
489
490 /* Read shadow of current MFW mailbox */
491 qed_mcp_read_mb(p_hwfn, p_hwfn->p_main_ptt);
492 memcpy(p_hwfn->mcp_info->mfw_mb_shadow,
493 p_hwfn->mcp_info->mfw_mb_cur,
494 p_hwfn->mcp_info->mfw_mb_length);
495
496 qed_int_setup(p_hwfn, p_hwfn->p_main_ptt);
32a47e72
YM
497
498 qed_iov_setup(p_hwfn, p_hwfn->p_main_ptt);
fe56b9e6
YM
499 }
500}
501
fe56b9e6
YM
502#define FINAL_CLEANUP_POLL_CNT (100)
503#define FINAL_CLEANUP_POLL_TIME (10)
504int qed_final_cleanup(struct qed_hwfn *p_hwfn,
0b55e27d 505 struct qed_ptt *p_ptt, u16 id, bool is_vf)
fe56b9e6
YM
506{
507 u32 command = 0, addr, count = FINAL_CLEANUP_POLL_CNT;
508 int rc = -EBUSY;
509
fc48b7a6
YM
510 addr = GTT_BAR0_MAP_REG_USDM_RAM +
511 USTORM_FLR_FINAL_ACK_OFFSET(p_hwfn->rel_pf_id);
fe56b9e6 512
0b55e27d
YM
513 if (is_vf)
514 id += 0x10;
515
fc48b7a6
YM
516 command |= X_FINAL_CLEANUP_AGG_INT <<
517 SDM_AGG_INT_COMP_PARAMS_AGG_INT_INDEX_SHIFT;
518 command |= 1 << SDM_AGG_INT_COMP_PARAMS_AGG_VECTOR_ENABLE_SHIFT;
519 command |= id << SDM_AGG_INT_COMP_PARAMS_AGG_VECTOR_BIT_SHIFT;
520 command |= SDM_COMP_TYPE_AGG_INT << SDM_OP_GEN_COMP_TYPE_SHIFT;
fe56b9e6
YM
521
522 /* Make sure notification is not set before initiating final cleanup */
523 if (REG_RD(p_hwfn, addr)) {
524 DP_NOTICE(
525 p_hwfn,
526 "Unexpected; Found final cleanup notification before initiating final cleanup\n");
527 REG_WR(p_hwfn, addr, 0);
528 }
529
530 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
531 "Sending final cleanup for PFVF[%d] [Command %08x\n]",
532 id, command);
533
534 qed_wr(p_hwfn, p_ptt, XSDM_REG_OPERATION_GEN, command);
535
536 /* Poll until completion */
537 while (!REG_RD(p_hwfn, addr) && count--)
538 msleep(FINAL_CLEANUP_POLL_TIME);
539
540 if (REG_RD(p_hwfn, addr))
541 rc = 0;
542 else
543 DP_NOTICE(p_hwfn,
544 "Failed to receive FW final cleanup notification\n");
545
546 /* Cleanup afterwards */
547 REG_WR(p_hwfn, addr, 0);
548
549 return rc;
550}
551
552static void qed_calc_hw_mode(struct qed_hwfn *p_hwfn)
553{
554 int hw_mode = 0;
555
12e09c69 556 hw_mode = (1 << MODE_BB_B0);
fe56b9e6
YM
557
558 switch (p_hwfn->cdev->num_ports_in_engines) {
559 case 1:
560 hw_mode |= 1 << MODE_PORTS_PER_ENG_1;
561 break;
562 case 2:
563 hw_mode |= 1 << MODE_PORTS_PER_ENG_2;
564 break;
565 case 4:
566 hw_mode |= 1 << MODE_PORTS_PER_ENG_4;
567 break;
568 default:
569 DP_NOTICE(p_hwfn, "num_ports_in_engine = %d not supported\n",
570 p_hwfn->cdev->num_ports_in_engines);
571 return;
572 }
573
574 switch (p_hwfn->cdev->mf_mode) {
fc48b7a6
YM
575 case QED_MF_DEFAULT:
576 case QED_MF_NPAR:
577 hw_mode |= 1 << MODE_MF_SI;
fe56b9e6 578 break;
fc48b7a6 579 case QED_MF_OVLAN:
fe56b9e6
YM
580 hw_mode |= 1 << MODE_MF_SD;
581 break;
fe56b9e6 582 default:
fc48b7a6
YM
583 DP_NOTICE(p_hwfn, "Unsupported MF mode, init as DEFAULT\n");
584 hw_mode |= 1 << MODE_MF_SI;
fe56b9e6
YM
585 }
586
587 hw_mode |= 1 << MODE_ASIC;
588
589 p_hwfn->hw_info.hw_mode = hw_mode;
590}
591
592/* Init run time data for all PFs on an engine. */
593static void qed_init_cau_rt_data(struct qed_dev *cdev)
594{
595 u32 offset = CAU_REG_SB_VAR_MEMORY_RT_OFFSET;
596 int i, sb_id;
597
598 for_each_hwfn(cdev, i) {
599 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
600 struct qed_igu_info *p_igu_info;
601 struct qed_igu_block *p_block;
602 struct cau_sb_entry sb_entry;
603
604 p_igu_info = p_hwfn->hw_info.p_igu_info;
605
606 for (sb_id = 0; sb_id < QED_MAPPING_MEMORY_SIZE(cdev);
607 sb_id++) {
608 p_block = &p_igu_info->igu_map.igu_blocks[sb_id];
609 if (!p_block->is_pf)
610 continue;
611
612 qed_init_cau_sb_entry(p_hwfn, &sb_entry,
613 p_block->function_id,
614 0, 0);
615 STORE_RT_REG_AGG(p_hwfn, offset + sb_id * 2,
616 sb_entry);
617 }
618 }
619}
620
621static int qed_hw_init_common(struct qed_hwfn *p_hwfn,
622 struct qed_ptt *p_ptt,
623 int hw_mode)
624{
625 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
626 struct qed_qm_common_rt_init_params params;
627 struct qed_dev *cdev = p_hwfn->cdev;
1408cc1f 628 u32 concrete_fid;
fe56b9e6 629 int rc = 0;
1408cc1f 630 u8 vf_id;
fe56b9e6
YM
631
632 qed_init_cau_rt_data(cdev);
633
634 /* Program GTT windows */
635 qed_gtt_init(p_hwfn);
636
637 if (p_hwfn->mcp_info) {
638 if (p_hwfn->mcp_info->func_info.bandwidth_max)
639 qm_info->pf_rl_en = 1;
640 if (p_hwfn->mcp_info->func_info.bandwidth_min)
641 qm_info->pf_wfq_en = 1;
642 }
643
644 memset(&params, 0, sizeof(params));
645 params.max_ports_per_engine = p_hwfn->cdev->num_ports_in_engines;
646 params.max_phys_tcs_per_port = qm_info->max_phys_tcs_per_port;
647 params.pf_rl_en = qm_info->pf_rl_en;
648 params.pf_wfq_en = qm_info->pf_wfq_en;
649 params.vport_rl_en = qm_info->vport_rl_en;
650 params.vport_wfq_en = qm_info->vport_wfq_en;
651 params.port_params = qm_info->qm_port_params;
652
653 qed_qm_common_rt_init(p_hwfn, &params);
654
655 qed_cxt_hw_init_common(p_hwfn);
656
657 /* Close gate from NIG to BRB/Storm; By default they are open, but
658 * we close them to prevent NIG from passing data to reset blocks.
659 * Should have been done in the ENGINE phase, but init-tool lacks
660 * proper port-pretend capabilities.
661 */
662 qed_wr(p_hwfn, p_ptt, NIG_REG_RX_BRB_OUT_EN, 0);
663 qed_wr(p_hwfn, p_ptt, NIG_REG_STORM_OUT_EN, 0);
664 qed_port_pretend(p_hwfn, p_ptt, p_hwfn->port_id ^ 1);
665 qed_wr(p_hwfn, p_ptt, NIG_REG_RX_BRB_OUT_EN, 0);
666 qed_wr(p_hwfn, p_ptt, NIG_REG_STORM_OUT_EN, 0);
667 qed_port_unpretend(p_hwfn, p_ptt);
668
669 rc = qed_init_run(p_hwfn, p_ptt, PHASE_ENGINE, ANY_PHASE_ID, hw_mode);
670 if (rc != 0)
671 return rc;
672
673 qed_wr(p_hwfn, p_ptt, PSWRQ2_REG_L2P_VALIDATE_VFID, 0);
674 qed_wr(p_hwfn, p_ptt, PGLUE_B_REG_USE_CLIENTID_IN_TAG, 1);
675
676 /* Disable relaxed ordering in the PCI config space */
677 qed_wr(p_hwfn, p_ptt, 0x20b4,
678 qed_rd(p_hwfn, p_ptt, 0x20b4) & ~0x10);
679
1408cc1f
YM
680 for (vf_id = 0; vf_id < MAX_NUM_VFS_BB; vf_id++) {
681 concrete_fid = qed_vfid_to_concrete(p_hwfn, vf_id);
682 qed_fid_pretend(p_hwfn, p_ptt, (u16) concrete_fid);
683 qed_wr(p_hwfn, p_ptt, CCFC_REG_STRONG_ENABLE_VF, 0x1);
684 }
685 /* pretend to original PF */
686 qed_fid_pretend(p_hwfn, p_ptt, p_hwfn->rel_pf_id);
687
fe56b9e6
YM
688 return rc;
689}
690
691static int qed_hw_init_port(struct qed_hwfn *p_hwfn,
692 struct qed_ptt *p_ptt,
693 int hw_mode)
694{
695 int rc = 0;
696
697 rc = qed_init_run(p_hwfn, p_ptt, PHASE_PORT, p_hwfn->port_id,
698 hw_mode);
699 return rc;
700}
701
702static int qed_hw_init_pf(struct qed_hwfn *p_hwfn,
703 struct qed_ptt *p_ptt,
464f6645 704 struct qed_tunn_start_params *p_tunn,
fe56b9e6
YM
705 int hw_mode,
706 bool b_hw_start,
707 enum qed_int_mode int_mode,
708 bool allow_npar_tx_switch)
709{
710 u8 rel_pf_id = p_hwfn->rel_pf_id;
711 int rc = 0;
712
713 if (p_hwfn->mcp_info) {
714 struct qed_mcp_function_info *p_info;
715
716 p_info = &p_hwfn->mcp_info->func_info;
717 if (p_info->bandwidth_min)
718 p_hwfn->qm_info.pf_wfq = p_info->bandwidth_min;
719
720 /* Update rate limit once we'll actually have a link */
4b01e519 721 p_hwfn->qm_info.pf_rl = 100000;
fe56b9e6
YM
722 }
723
724 qed_cxt_hw_init_pf(p_hwfn);
725
726 qed_int_igu_init_rt(p_hwfn);
727
728 /* Set VLAN in NIG if needed */
729 if (hw_mode & (1 << MODE_MF_SD)) {
730 DP_VERBOSE(p_hwfn, NETIF_MSG_HW, "Configuring LLH_FUNC_TAG\n");
731 STORE_RT_REG(p_hwfn, NIG_REG_LLH_FUNC_TAG_EN_RT_OFFSET, 1);
732 STORE_RT_REG(p_hwfn, NIG_REG_LLH_FUNC_TAG_VALUE_RT_OFFSET,
733 p_hwfn->hw_info.ovlan);
734 }
735
736 /* Enable classification by MAC if needed */
87aec47d 737 if (hw_mode & (1 << MODE_MF_SI)) {
fe56b9e6
YM
738 DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
739 "Configuring TAGMAC_CLS_TYPE\n");
740 STORE_RT_REG(p_hwfn,
741 NIG_REG_LLH_FUNC_TAGMAC_CLS_TYPE_RT_OFFSET, 1);
742 }
743
744 /* Protocl Configuration */
745 STORE_RT_REG(p_hwfn, PRS_REG_SEARCH_TCP_RT_OFFSET, 0);
746 STORE_RT_REG(p_hwfn, PRS_REG_SEARCH_FCOE_RT_OFFSET, 0);
747 STORE_RT_REG(p_hwfn, PRS_REG_SEARCH_ROCE_RT_OFFSET, 0);
748
749 /* Cleanup chip from previous driver if such remains exist */
0b55e27d 750 rc = qed_final_cleanup(p_hwfn, p_ptt, rel_pf_id, false);
fe56b9e6
YM
751 if (rc != 0)
752 return rc;
753
754 /* PF Init sequence */
755 rc = qed_init_run(p_hwfn, p_ptt, PHASE_PF, rel_pf_id, hw_mode);
756 if (rc)
757 return rc;
758
759 /* QM_PF Init sequence (may be invoked separately e.g. for DCB) */
760 rc = qed_init_run(p_hwfn, p_ptt, PHASE_QM_PF, rel_pf_id, hw_mode);
761 if (rc)
762 return rc;
763
764 /* Pure runtime initializations - directly to the HW */
765 qed_int_igu_init_pure_rt(p_hwfn, p_ptt, true, true);
766
767 if (b_hw_start) {
768 /* enable interrupts */
769 qed_int_igu_enable(p_hwfn, p_ptt, int_mode);
770
771 /* send function start command */
831bfb0e
YM
772 rc = qed_sp_pf_start(p_hwfn, p_tunn, p_hwfn->cdev->mf_mode,
773 allow_npar_tx_switch);
fe56b9e6
YM
774 if (rc)
775 DP_NOTICE(p_hwfn, "Function start ramrod failed\n");
776 }
777 return rc;
778}
779
780static int qed_change_pci_hwfn(struct qed_hwfn *p_hwfn,
781 struct qed_ptt *p_ptt,
782 u8 enable)
783{
784 u32 delay_idx = 0, val, set_val = enable ? 1 : 0;
785
786 /* Change PF in PXP */
787 qed_wr(p_hwfn, p_ptt,
788 PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, set_val);
789
790 /* wait until value is set - try for 1 second every 50us */
791 for (delay_idx = 0; delay_idx < 20000; delay_idx++) {
792 val = qed_rd(p_hwfn, p_ptt,
793 PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
794 if (val == set_val)
795 break;
796
797 usleep_range(50, 60);
798 }
799
800 if (val != set_val) {
801 DP_NOTICE(p_hwfn,
802 "PFID_ENABLE_MASTER wasn't changed after a second\n");
803 return -EAGAIN;
804 }
805
806 return 0;
807}
808
809static void qed_reset_mb_shadow(struct qed_hwfn *p_hwfn,
810 struct qed_ptt *p_main_ptt)
811{
812 /* Read shadow of current MFW mailbox */
813 qed_mcp_read_mb(p_hwfn, p_main_ptt);
814 memcpy(p_hwfn->mcp_info->mfw_mb_shadow,
815 p_hwfn->mcp_info->mfw_mb_cur,
816 p_hwfn->mcp_info->mfw_mb_length);
817}
818
819int qed_hw_init(struct qed_dev *cdev,
464f6645 820 struct qed_tunn_start_params *p_tunn,
fe56b9e6
YM
821 bool b_hw_start,
822 enum qed_int_mode int_mode,
823 bool allow_npar_tx_switch,
824 const u8 *bin_fw_data)
825{
86622ee7 826 u32 load_code, param;
fe56b9e6
YM
827 int rc, mfw_rc, i;
828
1408cc1f
YM
829 if (IS_PF(cdev)) {
830 rc = qed_init_fw_data(cdev, bin_fw_data);
831 if (rc != 0)
832 return rc;
833 }
fe56b9e6
YM
834
835 for_each_hwfn(cdev, i) {
836 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
837
1408cc1f
YM
838 if (IS_VF(cdev)) {
839 p_hwfn->b_int_enabled = 1;
840 continue;
841 }
842
fe56b9e6
YM
843 /* Enable DMAE in PXP */
844 rc = qed_change_pci_hwfn(p_hwfn, p_hwfn->p_main_ptt, true);
845
846 qed_calc_hw_mode(p_hwfn);
847
848 rc = qed_mcp_load_req(p_hwfn, p_hwfn->p_main_ptt,
849 &load_code);
850 if (rc) {
851 DP_NOTICE(p_hwfn, "Failed sending LOAD_REQ command\n");
852 return rc;
853 }
854
855 qed_reset_mb_shadow(p_hwfn, p_hwfn->p_main_ptt);
856
857 DP_VERBOSE(p_hwfn, QED_MSG_SP,
858 "Load request was sent. Resp:0x%x, Load code: 0x%x\n",
859 rc, load_code);
860
861 p_hwfn->first_on_engine = (load_code ==
862 FW_MSG_CODE_DRV_LOAD_ENGINE);
863
39651abd
SRK
864 if (!qm_lock_init) {
865 spin_lock_init(&qm_lock);
866 qm_lock_init = true;
867 }
868
fe56b9e6
YM
869 switch (load_code) {
870 case FW_MSG_CODE_DRV_LOAD_ENGINE:
871 rc = qed_hw_init_common(p_hwfn, p_hwfn->p_main_ptt,
872 p_hwfn->hw_info.hw_mode);
873 if (rc)
874 break;
875 /* Fall into */
876 case FW_MSG_CODE_DRV_LOAD_PORT:
877 rc = qed_hw_init_port(p_hwfn, p_hwfn->p_main_ptt,
878 p_hwfn->hw_info.hw_mode);
879 if (rc)
880 break;
881
882 /* Fall into */
883 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
884 rc = qed_hw_init_pf(p_hwfn, p_hwfn->p_main_ptt,
464f6645 885 p_tunn, p_hwfn->hw_info.hw_mode,
fe56b9e6
YM
886 b_hw_start, int_mode,
887 allow_npar_tx_switch);
888 break;
889 default:
890 rc = -EINVAL;
891 break;
892 }
893
894 if (rc)
895 DP_NOTICE(p_hwfn,
896 "init phase failed for loadcode 0x%x (rc %d)\n",
897 load_code, rc);
898
899 /* ACK mfw regardless of success or failure of initialization */
900 mfw_rc = qed_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
901 DRV_MSG_CODE_LOAD_DONE,
902 0, &load_code, &param);
903 if (rc)
904 return rc;
905 if (mfw_rc) {
906 DP_NOTICE(p_hwfn, "Failed sending LOAD_DONE command\n");
907 return mfw_rc;
908 }
909
39651abd
SRK
910 /* send DCBX attention request command */
911 DP_VERBOSE(p_hwfn,
912 QED_MSG_DCB,
913 "sending phony dcbx set command to trigger DCBx attention handling\n");
914 mfw_rc = qed_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
915 DRV_MSG_CODE_SET_DCBX,
916 1 << DRV_MB_PARAM_DCBX_NOTIFY_SHIFT,
917 &load_code, &param);
918 if (mfw_rc) {
919 DP_NOTICE(p_hwfn,
920 "Failed to send DCBX attention request\n");
921 return mfw_rc;
922 }
923
fe56b9e6
YM
924 p_hwfn->hw_init_done = true;
925 }
926
927 return 0;
928}
929
930#define QED_HW_STOP_RETRY_LIMIT (10)
8c925c44
YM
931static inline void qed_hw_timers_stop(struct qed_dev *cdev,
932 struct qed_hwfn *p_hwfn,
933 struct qed_ptt *p_ptt)
934{
935 int i;
936
937 /* close timers */
938 qed_wr(p_hwfn, p_ptt, TM_REG_PF_ENABLE_CONN, 0x0);
939 qed_wr(p_hwfn, p_ptt, TM_REG_PF_ENABLE_TASK, 0x0);
940
941 for (i = 0; i < QED_HW_STOP_RETRY_LIMIT; i++) {
942 if ((!qed_rd(p_hwfn, p_ptt,
943 TM_REG_PF_SCAN_ACTIVE_CONN)) &&
944 (!qed_rd(p_hwfn, p_ptt,
945 TM_REG_PF_SCAN_ACTIVE_TASK)))
946 break;
947
948 /* Dependent on number of connection/tasks, possibly
949 * 1ms sleep is required between polls
950 */
951 usleep_range(1000, 2000);
952 }
953
954 if (i < QED_HW_STOP_RETRY_LIMIT)
955 return;
956
957 DP_NOTICE(p_hwfn,
958 "Timers linear scans are not over [Connection %02x Tasks %02x]\n",
959 (u8)qed_rd(p_hwfn, p_ptt, TM_REG_PF_SCAN_ACTIVE_CONN),
960 (u8)qed_rd(p_hwfn, p_ptt, TM_REG_PF_SCAN_ACTIVE_TASK));
961}
962
963void qed_hw_timers_stop_all(struct qed_dev *cdev)
964{
965 int j;
966
967 for_each_hwfn(cdev, j) {
968 struct qed_hwfn *p_hwfn = &cdev->hwfns[j];
969 struct qed_ptt *p_ptt = p_hwfn->p_main_ptt;
970
971 qed_hw_timers_stop(cdev, p_hwfn, p_ptt);
972 }
973}
974
fe56b9e6
YM
975int qed_hw_stop(struct qed_dev *cdev)
976{
977 int rc = 0, t_rc;
8c925c44 978 int j;
fe56b9e6
YM
979
980 for_each_hwfn(cdev, j) {
981 struct qed_hwfn *p_hwfn = &cdev->hwfns[j];
982 struct qed_ptt *p_ptt = p_hwfn->p_main_ptt;
983
984 DP_VERBOSE(p_hwfn, NETIF_MSG_IFDOWN, "Stopping hw/fw\n");
985
1408cc1f 986 if (IS_VF(cdev)) {
0b55e27d 987 qed_vf_pf_int_cleanup(p_hwfn);
1408cc1f
YM
988 continue;
989 }
990
fe56b9e6
YM
991 /* mark the hw as uninitialized... */
992 p_hwfn->hw_init_done = false;
993
994 rc = qed_sp_pf_stop(p_hwfn);
995 if (rc)
8c925c44
YM
996 DP_NOTICE(p_hwfn,
997 "Failed to close PF against FW. Continue to stop HW to prevent illegal host access by the device\n");
fe56b9e6
YM
998
999 qed_wr(p_hwfn, p_ptt,
1000 NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF, 0x1);
1001
1002 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TCP, 0x0);
1003 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_UDP, 0x0);
1004 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_FCOE, 0x0);
1005 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_ROCE, 0x0);
1006 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_OPENFLOW, 0x0);
1007
8c925c44 1008 qed_hw_timers_stop(cdev, p_hwfn, p_ptt);
fe56b9e6
YM
1009
1010 /* Disable Attention Generation */
1011 qed_int_igu_disable_int(p_hwfn, p_ptt);
1012
1013 qed_wr(p_hwfn, p_ptt, IGU_REG_LEADING_EDGE_LATCH, 0);
1014 qed_wr(p_hwfn, p_ptt, IGU_REG_TRAILING_EDGE_LATCH, 0);
1015
1016 qed_int_igu_init_pure_rt(p_hwfn, p_ptt, false, true);
1017
1018 /* Need to wait 1ms to guarantee SBs are cleared */
1019 usleep_range(1000, 2000);
1020 }
1021
1408cc1f
YM
1022 if (IS_PF(cdev)) {
1023 /* Disable DMAE in PXP - in CMT, this should only be done for
1024 * first hw-function, and only after all transactions have
1025 * stopped for all active hw-functions.
1026 */
1027 t_rc = qed_change_pci_hwfn(&cdev->hwfns[0],
1028 cdev->hwfns[0].p_main_ptt, false);
1029 if (t_rc != 0)
1030 rc = t_rc;
1031 }
fe56b9e6
YM
1032
1033 return rc;
1034}
1035
cee4d264
MC
1036void qed_hw_stop_fastpath(struct qed_dev *cdev)
1037{
8c925c44 1038 int j;
cee4d264
MC
1039
1040 for_each_hwfn(cdev, j) {
1041 struct qed_hwfn *p_hwfn = &cdev->hwfns[j];
dacd88d6
YM
1042 struct qed_ptt *p_ptt = p_hwfn->p_main_ptt;
1043
1044 if (IS_VF(cdev)) {
1045 qed_vf_pf_int_cleanup(p_hwfn);
1046 continue;
1047 }
cee4d264
MC
1048
1049 DP_VERBOSE(p_hwfn,
1050 NETIF_MSG_IFDOWN,
1051 "Shutting down the fastpath\n");
1052
1053 qed_wr(p_hwfn, p_ptt,
1054 NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF, 0x1);
1055
1056 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TCP, 0x0);
1057 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_UDP, 0x0);
1058 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_FCOE, 0x0);
1059 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_ROCE, 0x0);
1060 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_OPENFLOW, 0x0);
1061
cee4d264
MC
1062 qed_int_igu_init_pure_rt(p_hwfn, p_ptt, false, false);
1063
1064 /* Need to wait 1ms to guarantee SBs are cleared */
1065 usleep_range(1000, 2000);
1066 }
1067}
1068
1069void qed_hw_start_fastpath(struct qed_hwfn *p_hwfn)
1070{
dacd88d6
YM
1071 if (IS_VF(p_hwfn->cdev))
1072 return;
1073
cee4d264
MC
1074 /* Re-open incoming traffic */
1075 qed_wr(p_hwfn, p_hwfn->p_main_ptt,
1076 NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF, 0x0);
1077}
1078
fe56b9e6
YM
1079static int qed_reg_assert(struct qed_hwfn *hwfn,
1080 struct qed_ptt *ptt, u32 reg,
1081 bool expected)
1082{
1083 u32 assert_val = qed_rd(hwfn, ptt, reg);
1084
1085 if (assert_val != expected) {
1086 DP_NOTICE(hwfn, "Value at address 0x%x != 0x%08x\n",
1087 reg, expected);
1088 return -EINVAL;
1089 }
1090
1091 return 0;
1092}
1093
1094int qed_hw_reset(struct qed_dev *cdev)
1095{
1096 int rc = 0;
1097 u32 unload_resp, unload_param;
1098 int i;
1099
1100 for_each_hwfn(cdev, i) {
1101 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
1102
1408cc1f 1103 if (IS_VF(cdev)) {
0b55e27d
YM
1104 rc = qed_vf_pf_reset(p_hwfn);
1105 if (rc)
1106 return rc;
1408cc1f
YM
1107 continue;
1108 }
1109
fe56b9e6
YM
1110 DP_VERBOSE(p_hwfn, NETIF_MSG_IFDOWN, "Resetting hw/fw\n");
1111
1112 /* Check for incorrect states */
1113 qed_reg_assert(p_hwfn, p_hwfn->p_main_ptt,
1114 QM_REG_USG_CNT_PF_TX, 0);
1115 qed_reg_assert(p_hwfn, p_hwfn->p_main_ptt,
1116 QM_REG_USG_CNT_PF_OTHER, 0);
1117
1118 /* Disable PF in HW blocks */
1119 qed_wr(p_hwfn, p_hwfn->p_main_ptt, DORQ_REG_PF_DB_ENABLE, 0);
1120 qed_wr(p_hwfn, p_hwfn->p_main_ptt, QM_REG_PF_EN, 0);
1121 qed_wr(p_hwfn, p_hwfn->p_main_ptt,
1122 TCFC_REG_STRONG_ENABLE_PF, 0);
1123 qed_wr(p_hwfn, p_hwfn->p_main_ptt,
1124 CCFC_REG_STRONG_ENABLE_PF, 0);
1125
1126 /* Send unload command to MCP */
1127 rc = qed_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
1128 DRV_MSG_CODE_UNLOAD_REQ,
1129 DRV_MB_PARAM_UNLOAD_WOL_MCP,
1130 &unload_resp, &unload_param);
1131 if (rc) {
1132 DP_NOTICE(p_hwfn, "qed_hw_reset: UNLOAD_REQ failed\n");
1133 unload_resp = FW_MSG_CODE_DRV_UNLOAD_ENGINE;
1134 }
1135
1136 rc = qed_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
1137 DRV_MSG_CODE_UNLOAD_DONE,
1138 0, &unload_resp, &unload_param);
1139 if (rc) {
1140 DP_NOTICE(p_hwfn, "qed_hw_reset: UNLOAD_DONE failed\n");
1141 return rc;
1142 }
1143 }
1144
1145 return rc;
1146}
1147
1148/* Free hwfn memory and resources acquired in hw_hwfn_prepare */
1149static void qed_hw_hwfn_free(struct qed_hwfn *p_hwfn)
1150{
1151 qed_ptt_pool_free(p_hwfn);
1152 kfree(p_hwfn->hw_info.p_igu_info);
1153}
1154
1155/* Setup bar access */
12e09c69 1156static void qed_hw_hwfn_prepare(struct qed_hwfn *p_hwfn)
fe56b9e6 1157{
fe56b9e6
YM
1158 /* clear indirect access */
1159 qed_wr(p_hwfn, p_hwfn->p_main_ptt, PGLUE_B_REG_PGL_ADDR_88_F0, 0);
1160 qed_wr(p_hwfn, p_hwfn->p_main_ptt, PGLUE_B_REG_PGL_ADDR_8C_F0, 0);
1161 qed_wr(p_hwfn, p_hwfn->p_main_ptt, PGLUE_B_REG_PGL_ADDR_90_F0, 0);
1162 qed_wr(p_hwfn, p_hwfn->p_main_ptt, PGLUE_B_REG_PGL_ADDR_94_F0, 0);
1163
1164 /* Clean Previous errors if such exist */
1165 qed_wr(p_hwfn, p_hwfn->p_main_ptt,
1166 PGLUE_B_REG_WAS_ERROR_PF_31_0_CLR,
1167 1 << p_hwfn->abs_pf_id);
1168
1169 /* enable internal target-read */
1170 qed_wr(p_hwfn, p_hwfn->p_main_ptt,
1171 PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
fe56b9e6
YM
1172}
1173
1174static void get_function_id(struct qed_hwfn *p_hwfn)
1175{
1176 /* ME Register */
1177 p_hwfn->hw_info.opaque_fid = (u16)REG_RD(p_hwfn, PXP_PF_ME_OPAQUE_ADDR);
1178
1179 p_hwfn->hw_info.concrete_fid = REG_RD(p_hwfn, PXP_PF_ME_CONCRETE_ADDR);
1180
1181 p_hwfn->abs_pf_id = (p_hwfn->hw_info.concrete_fid >> 16) & 0xf;
1182 p_hwfn->rel_pf_id = GET_FIELD(p_hwfn->hw_info.concrete_fid,
1183 PXP_CONCRETE_FID_PFID);
1184 p_hwfn->port_id = GET_FIELD(p_hwfn->hw_info.concrete_fid,
1185 PXP_CONCRETE_FID_PORT);
1186}
1187
25c089d7
YM
1188static void qed_hw_set_feat(struct qed_hwfn *p_hwfn)
1189{
1190 u32 *feat_num = p_hwfn->hw_info.feat_num;
1191 int num_features = 1;
1192
1193 feat_num[QED_PF_L2_QUE] = min_t(u32, RESC_NUM(p_hwfn, QED_SB) /
1194 num_features,
1195 RESC_NUM(p_hwfn, QED_L2_QUEUE));
1196 DP_VERBOSE(p_hwfn, NETIF_MSG_PROBE,
1197 "#PF_L2_QUEUES=%d #SBS=%d num_features=%d\n",
1198 feat_num[QED_PF_L2_QUE], RESC_NUM(p_hwfn, QED_SB),
1199 num_features);
1200}
1201
fe56b9e6
YM
1202static void qed_hw_get_resc(struct qed_hwfn *p_hwfn)
1203{
1204 u32 *resc_start = p_hwfn->hw_info.resc_start;
1408cc1f 1205 u8 num_funcs = p_hwfn->num_funcs_on_engine;
fe56b9e6 1206 u32 *resc_num = p_hwfn->hw_info.resc_num;
4ac801b7 1207 struct qed_sb_cnt_info sb_cnt_info;
08feecd7 1208 int i, max_vf_vlan_filters;
fe56b9e6 1209
4ac801b7 1210 memset(&sb_cnt_info, 0, sizeof(sb_cnt_info));
08feecd7
YM
1211
1212#ifdef CONFIG_QED_SRIOV
1213 max_vf_vlan_filters = QED_ETH_MAX_VF_NUM_VLAN_FILTERS;
1214#else
1215 max_vf_vlan_filters = 0;
1216#endif
1217
4ac801b7
YM
1218 qed_int_get_num_sbs(p_hwfn, &sb_cnt_info);
1219
fe56b9e6
YM
1220 resc_num[QED_SB] = min_t(u32,
1221 (MAX_SB_PER_PATH_BB / num_funcs),
4ac801b7 1222 sb_cnt_info.sb_cnt);
25c089d7 1223 resc_num[QED_L2_QUEUE] = MAX_NUM_L2_QUEUES_BB / num_funcs;
fe56b9e6 1224 resc_num[QED_VPORT] = MAX_NUM_VPORTS_BB / num_funcs;
25c089d7 1225 resc_num[QED_RSS_ENG] = ETH_RSS_ENGINE_NUM_BB / num_funcs;
fe56b9e6
YM
1226 resc_num[QED_PQ] = MAX_QM_TX_QUEUES_BB / num_funcs;
1227 resc_num[QED_RL] = 8;
25c089d7
YM
1228 resc_num[QED_MAC] = ETH_NUM_MAC_FILTERS / num_funcs;
1229 resc_num[QED_VLAN] = (ETH_NUM_VLAN_FILTERS - 1 /*For vlan0*/) /
1230 num_funcs;
fe56b9e6
YM
1231 resc_num[QED_ILT] = 950;
1232
1233 for (i = 0; i < QED_MAX_RESC; i++)
1234 resc_start[i] = resc_num[i] * p_hwfn->rel_pf_id;
1235
25c089d7
YM
1236 qed_hw_set_feat(p_hwfn);
1237
fe56b9e6
YM
1238 DP_VERBOSE(p_hwfn, NETIF_MSG_PROBE,
1239 "The numbers for each resource are:\n"
1240 "SB = %d start = %d\n"
25c089d7 1241 "L2_QUEUE = %d start = %d\n"
fe56b9e6
YM
1242 "VPORT = %d start = %d\n"
1243 "PQ = %d start = %d\n"
1244 "RL = %d start = %d\n"
25c089d7
YM
1245 "MAC = %d start = %d\n"
1246 "VLAN = %d start = %d\n"
fe56b9e6
YM
1247 "ILT = %d start = %d\n",
1248 p_hwfn->hw_info.resc_num[QED_SB],
1249 p_hwfn->hw_info.resc_start[QED_SB],
25c089d7
YM
1250 p_hwfn->hw_info.resc_num[QED_L2_QUEUE],
1251 p_hwfn->hw_info.resc_start[QED_L2_QUEUE],
fe56b9e6
YM
1252 p_hwfn->hw_info.resc_num[QED_VPORT],
1253 p_hwfn->hw_info.resc_start[QED_VPORT],
1254 p_hwfn->hw_info.resc_num[QED_PQ],
1255 p_hwfn->hw_info.resc_start[QED_PQ],
1256 p_hwfn->hw_info.resc_num[QED_RL],
1257 p_hwfn->hw_info.resc_start[QED_RL],
25c089d7
YM
1258 p_hwfn->hw_info.resc_num[QED_MAC],
1259 p_hwfn->hw_info.resc_start[QED_MAC],
1260 p_hwfn->hw_info.resc_num[QED_VLAN],
1261 p_hwfn->hw_info.resc_start[QED_VLAN],
fe56b9e6
YM
1262 p_hwfn->hw_info.resc_num[QED_ILT],
1263 p_hwfn->hw_info.resc_start[QED_ILT]);
1264}
1265
1266static int qed_hw_get_nvm_info(struct qed_hwfn *p_hwfn,
1267 struct qed_ptt *p_ptt)
1268{
cc875c2e 1269 u32 nvm_cfg1_offset, mf_mode, addr, generic_cont0, core_cfg;
fc48b7a6 1270 u32 port_cfg_addr, link_temp, nvm_cfg_addr, device_capabilities;
cc875c2e 1271 struct qed_mcp_link_params *link;
fe56b9e6
YM
1272
1273 /* Read global nvm_cfg address */
1274 nvm_cfg_addr = qed_rd(p_hwfn, p_ptt, MISC_REG_GEN_PURP_CR0);
1275
1276 /* Verify MCP has initialized it */
1277 if (!nvm_cfg_addr) {
1278 DP_NOTICE(p_hwfn, "Shared memory not initialized\n");
1279 return -EINVAL;
1280 }
1281
1282 /* Read nvm_cfg1 (Notice this is just offset, and not offsize (TBD) */
1283 nvm_cfg1_offset = qed_rd(p_hwfn, p_ptt, nvm_cfg_addr + 4);
1284
cc875c2e
YM
1285 addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
1286 offsetof(struct nvm_cfg1, glob) +
1287 offsetof(struct nvm_cfg1_glob, core_cfg);
1288
1289 core_cfg = qed_rd(p_hwfn, p_ptt, addr);
1290
1291 switch ((core_cfg & NVM_CFG1_GLOB_NETWORK_PORT_MODE_MASK) >>
1292 NVM_CFG1_GLOB_NETWORK_PORT_MODE_OFFSET) {
1293 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_DE_2X40G:
1294 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_2X40G;
1295 break;
1296 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_DE_2X50G:
1297 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_2X50G;
1298 break;
1299 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_DE_1X100G:
1300 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_1X100G;
1301 break;
1302 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_DE_4X10G_F:
1303 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_4X10G_F;
1304 break;
1305 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_DE_4X10G_E:
1306 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_4X10G_E;
1307 break;
1308 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_DE_4X20G:
1309 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_4X20G;
1310 break;
1311 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_DE_1X40G:
1312 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_1X40G;
1313 break;
1314 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_DE_2X25G:
1315 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_2X25G;
1316 break;
1317 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_DE_1X25G:
1318 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_1X25G;
1319 break;
1320 default:
1321 DP_NOTICE(p_hwfn, "Unknown port mode in 0x%08x\n",
1322 core_cfg);
1323 break;
1324 }
1325
cc875c2e
YM
1326 /* Read default link configuration */
1327 link = &p_hwfn->mcp_info->link_input;
1328 port_cfg_addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
1329 offsetof(struct nvm_cfg1, port[MFW_PORT(p_hwfn)]);
1330 link_temp = qed_rd(p_hwfn, p_ptt,
1331 port_cfg_addr +
1332 offsetof(struct nvm_cfg1_port, speed_cap_mask));
1333 link->speed.advertised_speeds =
1334 link_temp & NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_MASK;
1335
1336 p_hwfn->mcp_info->link_capabilities.speed_capabilities =
1337 link->speed.advertised_speeds;
1338
1339 link_temp = qed_rd(p_hwfn, p_ptt,
1340 port_cfg_addr +
1341 offsetof(struct nvm_cfg1_port, link_settings));
1342 switch ((link_temp & NVM_CFG1_PORT_DRV_LINK_SPEED_MASK) >>
1343 NVM_CFG1_PORT_DRV_LINK_SPEED_OFFSET) {
1344 case NVM_CFG1_PORT_DRV_LINK_SPEED_AUTONEG:
1345 link->speed.autoneg = true;
1346 break;
1347 case NVM_CFG1_PORT_DRV_LINK_SPEED_1G:
1348 link->speed.forced_speed = 1000;
1349 break;
1350 case NVM_CFG1_PORT_DRV_LINK_SPEED_10G:
1351 link->speed.forced_speed = 10000;
1352 break;
1353 case NVM_CFG1_PORT_DRV_LINK_SPEED_25G:
1354 link->speed.forced_speed = 25000;
1355 break;
1356 case NVM_CFG1_PORT_DRV_LINK_SPEED_40G:
1357 link->speed.forced_speed = 40000;
1358 break;
1359 case NVM_CFG1_PORT_DRV_LINK_SPEED_50G:
1360 link->speed.forced_speed = 50000;
1361 break;
1362 case NVM_CFG1_PORT_DRV_LINK_SPEED_100G:
1363 link->speed.forced_speed = 100000;
1364 break;
1365 default:
1366 DP_NOTICE(p_hwfn, "Unknown Speed in 0x%08x\n",
1367 link_temp);
1368 }
1369
1370 link_temp &= NVM_CFG1_PORT_DRV_FLOW_CONTROL_MASK;
1371 link_temp >>= NVM_CFG1_PORT_DRV_FLOW_CONTROL_OFFSET;
1372 link->pause.autoneg = !!(link_temp &
1373 NVM_CFG1_PORT_DRV_FLOW_CONTROL_AUTONEG);
1374 link->pause.forced_rx = !!(link_temp &
1375 NVM_CFG1_PORT_DRV_FLOW_CONTROL_RX);
1376 link->pause.forced_tx = !!(link_temp &
1377 NVM_CFG1_PORT_DRV_FLOW_CONTROL_TX);
1378 link->loopback_mode = 0;
1379
1380 DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
1381 "Read default link: Speed 0x%08x, Adv. Speed 0x%08x, AN: 0x%02x, PAUSE AN: 0x%02x\n",
1382 link->speed.forced_speed, link->speed.advertised_speeds,
1383 link->speed.autoneg, link->pause.autoneg);
1384
fe56b9e6
YM
1385 /* Read Multi-function information from shmem */
1386 addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
1387 offsetof(struct nvm_cfg1, glob) +
1388 offsetof(struct nvm_cfg1_glob, generic_cont0);
1389
1390 generic_cont0 = qed_rd(p_hwfn, p_ptt, addr);
1391
1392 mf_mode = (generic_cont0 & NVM_CFG1_GLOB_MF_MODE_MASK) >>
1393 NVM_CFG1_GLOB_MF_MODE_OFFSET;
1394
1395 switch (mf_mode) {
1396 case NVM_CFG1_GLOB_MF_MODE_MF_ALLOWED:
fc48b7a6 1397 p_hwfn->cdev->mf_mode = QED_MF_OVLAN;
fe56b9e6
YM
1398 break;
1399 case NVM_CFG1_GLOB_MF_MODE_NPAR1_0:
fc48b7a6 1400 p_hwfn->cdev->mf_mode = QED_MF_NPAR;
fe56b9e6 1401 break;
fc48b7a6
YM
1402 case NVM_CFG1_GLOB_MF_MODE_DEFAULT:
1403 p_hwfn->cdev->mf_mode = QED_MF_DEFAULT;
fe56b9e6
YM
1404 break;
1405 }
1406 DP_INFO(p_hwfn, "Multi function mode is %08x\n",
1407 p_hwfn->cdev->mf_mode);
1408
fc48b7a6
YM
1409 /* Read Multi-function information from shmem */
1410 addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
1411 offsetof(struct nvm_cfg1, glob) +
1412 offsetof(struct nvm_cfg1_glob, device_capabilities);
1413
1414 device_capabilities = qed_rd(p_hwfn, p_ptt, addr);
1415 if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_ETHERNET)
1416 __set_bit(QED_DEV_CAP_ETH,
1417 &p_hwfn->hw_info.device_capabilities);
1418
fe56b9e6
YM
1419 return qed_mcp_fill_shmem_func_info(p_hwfn, p_ptt);
1420}
1421
1408cc1f
YM
1422static void qed_get_num_funcs(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
1423{
1424 u32 reg_function_hide, tmp, eng_mask;
1425 u8 num_funcs;
1426
1427 num_funcs = MAX_NUM_PFS_BB;
1428
1429 /* Bit 0 of MISCS_REG_FUNCTION_HIDE indicates whether the bypass values
1430 * in the other bits are selected.
1431 * Bits 1-15 are for functions 1-15, respectively, and their value is
1432 * '0' only for enabled functions (function 0 always exists and
1433 * enabled).
1434 * In case of CMT, only the "even" functions are enabled, and thus the
1435 * number of functions for both hwfns is learnt from the same bits.
1436 */
1437 reg_function_hide = qed_rd(p_hwfn, p_ptt, MISCS_REG_FUNCTION_HIDE);
1438
1439 if (reg_function_hide & 0x1) {
1440 if (QED_PATH_ID(p_hwfn) && p_hwfn->cdev->num_hwfns == 1) {
1441 num_funcs = 0;
1442 eng_mask = 0xaaaa;
1443 } else {
1444 num_funcs = 1;
1445 eng_mask = 0x5554;
1446 }
1447
1448 /* Get the number of the enabled functions on the engine */
1449 tmp = (reg_function_hide ^ 0xffffffff) & eng_mask;
1450 while (tmp) {
1451 if (tmp & 0x1)
1452 num_funcs++;
1453 tmp >>= 0x1;
1454 }
1455 }
1456
1457 p_hwfn->num_funcs_on_engine = num_funcs;
1458
1459 DP_VERBOSE(p_hwfn,
1460 NETIF_MSG_PROBE,
1461 "PF [rel_id %d, abs_id %d] within the %d enabled functions on the engine\n",
1462 p_hwfn->rel_pf_id,
1463 p_hwfn->abs_pf_id,
1464 p_hwfn->num_funcs_on_engine);
1465}
1466
fe56b9e6
YM
1467static int
1468qed_get_hw_info(struct qed_hwfn *p_hwfn,
1469 struct qed_ptt *p_ptt,
1470 enum qed_pci_personality personality)
1471{
1472 u32 port_mode;
1473 int rc;
1474
32a47e72
YM
1475 /* Since all information is common, only first hwfns should do this */
1476 if (IS_LEAD_HWFN(p_hwfn)) {
1477 rc = qed_iov_hw_info(p_hwfn);
1478 if (rc)
1479 return rc;
1480 }
1481
fe56b9e6
YM
1482 /* Read the port mode */
1483 port_mode = qed_rd(p_hwfn, p_ptt,
1484 CNIG_REG_NW_PORT_MODE_BB_B0);
1485
1486 if (port_mode < 3) {
1487 p_hwfn->cdev->num_ports_in_engines = 1;
1488 } else if (port_mode <= 5) {
1489 p_hwfn->cdev->num_ports_in_engines = 2;
1490 } else {
1491 DP_NOTICE(p_hwfn, "PORT MODE: %d not supported\n",
1492 p_hwfn->cdev->num_ports_in_engines);
1493
1494 /* Default num_ports_in_engines to something */
1495 p_hwfn->cdev->num_ports_in_engines = 1;
1496 }
1497
1498 qed_hw_get_nvm_info(p_hwfn, p_ptt);
1499
1500 rc = qed_int_igu_read_cam(p_hwfn, p_ptt);
1501 if (rc)
1502 return rc;
1503
1504 if (qed_mcp_is_init(p_hwfn))
1505 ether_addr_copy(p_hwfn->hw_info.hw_mac_addr,
1506 p_hwfn->mcp_info->func_info.mac);
1507 else
1508 eth_random_addr(p_hwfn->hw_info.hw_mac_addr);
1509
1510 if (qed_mcp_is_init(p_hwfn)) {
1511 if (p_hwfn->mcp_info->func_info.ovlan != QED_MCP_VLAN_UNSET)
1512 p_hwfn->hw_info.ovlan =
1513 p_hwfn->mcp_info->func_info.ovlan;
1514
1515 qed_mcp_cmd_port_init(p_hwfn, p_ptt);
1516 }
1517
1518 if (qed_mcp_is_init(p_hwfn)) {
1519 enum qed_pci_personality protocol;
1520
1521 protocol = p_hwfn->mcp_info->func_info.protocol;
1522 p_hwfn->hw_info.personality = protocol;
1523 }
1524
1408cc1f
YM
1525 qed_get_num_funcs(p_hwfn, p_ptt);
1526
fe56b9e6
YM
1527 qed_hw_get_resc(p_hwfn);
1528
1529 return rc;
1530}
1531
12e09c69 1532static int qed_get_dev_info(struct qed_dev *cdev)
fe56b9e6 1533{
fc48b7a6 1534 struct qed_hwfn *p_hwfn = QED_LEADING_HWFN(cdev);
fe56b9e6
YM
1535 u32 tmp;
1536
fc48b7a6
YM
1537 /* Read Vendor Id / Device Id */
1538 pci_read_config_word(cdev->pdev, PCI_VENDOR_ID,
1539 &cdev->vendor_id);
1540 pci_read_config_word(cdev->pdev, PCI_DEVICE_ID,
1541 &cdev->device_id);
1542 cdev->chip_num = (u16)qed_rd(p_hwfn, p_hwfn->p_main_ptt,
fe56b9e6 1543 MISCS_REG_CHIP_NUM);
fc48b7a6 1544 cdev->chip_rev = (u16)qed_rd(p_hwfn, p_hwfn->p_main_ptt,
fe56b9e6
YM
1545 MISCS_REG_CHIP_REV);
1546 MASK_FIELD(CHIP_REV, cdev->chip_rev);
1547
fc48b7a6 1548 cdev->type = QED_DEV_TYPE_BB;
fe56b9e6 1549 /* Learn number of HW-functions */
fc48b7a6 1550 tmp = qed_rd(p_hwfn, p_hwfn->p_main_ptt,
fe56b9e6
YM
1551 MISCS_REG_CMT_ENABLED_FOR_PAIR);
1552
fc48b7a6 1553 if (tmp & (1 << p_hwfn->rel_pf_id)) {
fe56b9e6
YM
1554 DP_NOTICE(cdev->hwfns, "device in CMT mode\n");
1555 cdev->num_hwfns = 2;
1556 } else {
1557 cdev->num_hwfns = 1;
1558 }
1559
fc48b7a6 1560 cdev->chip_bond_id = qed_rd(p_hwfn, p_hwfn->p_main_ptt,
fe56b9e6
YM
1561 MISCS_REG_CHIP_TEST_REG) >> 4;
1562 MASK_FIELD(CHIP_BOND_ID, cdev->chip_bond_id);
fc48b7a6 1563 cdev->chip_metal = (u16)qed_rd(p_hwfn, p_hwfn->p_main_ptt,
fe56b9e6
YM
1564 MISCS_REG_CHIP_METAL);
1565 MASK_FIELD(CHIP_METAL, cdev->chip_metal);
1566
1567 DP_INFO(cdev->hwfns,
1568 "Chip details - Num: %04x Rev: %04x Bond id: %04x Metal: %04x\n",
1569 cdev->chip_num, cdev->chip_rev,
1570 cdev->chip_bond_id, cdev->chip_metal);
12e09c69
YM
1571
1572 if (QED_IS_BB(cdev) && CHIP_REV_IS_A0(cdev)) {
1573 DP_NOTICE(cdev->hwfns,
1574 "The chip type/rev (BB A0) is not supported!\n");
1575 return -EINVAL;
1576 }
1577
1578 return 0;
fe56b9e6
YM
1579}
1580
1581static int qed_hw_prepare_single(struct qed_hwfn *p_hwfn,
1582 void __iomem *p_regview,
1583 void __iomem *p_doorbells,
1584 enum qed_pci_personality personality)
1585{
1586 int rc = 0;
1587
1588 /* Split PCI bars evenly between hwfns */
1589 p_hwfn->regview = p_regview;
1590 p_hwfn->doorbells = p_doorbells;
1591
1408cc1f
YM
1592 if (IS_VF(p_hwfn->cdev))
1593 return qed_vf_hw_prepare(p_hwfn);
1594
fe56b9e6
YM
1595 /* Validate that chip access is feasible */
1596 if (REG_RD(p_hwfn, PXP_PF_ME_OPAQUE_ADDR) == 0xffffffff) {
1597 DP_ERR(p_hwfn,
1598 "Reading the ME register returns all Fs; Preventing further chip access\n");
1599 return -EINVAL;
1600 }
1601
1602 get_function_id(p_hwfn);
1603
12e09c69
YM
1604 /* Allocate PTT pool */
1605 rc = qed_ptt_pool_alloc(p_hwfn);
fe56b9e6
YM
1606 if (rc) {
1607 DP_NOTICE(p_hwfn, "Failed to prepare hwfn's hw\n");
1608 goto err0;
1609 }
1610
12e09c69
YM
1611 /* Allocate the main PTT */
1612 p_hwfn->p_main_ptt = qed_get_reserved_ptt(p_hwfn, RESERVED_PTT_MAIN);
1613
fe56b9e6 1614 /* First hwfn learns basic information, e.g., number of hwfns */
12e09c69
YM
1615 if (!p_hwfn->my_id) {
1616 rc = qed_get_dev_info(p_hwfn->cdev);
1617 if (rc != 0)
1618 goto err1;
1619 }
1620
1621 qed_hw_hwfn_prepare(p_hwfn);
fe56b9e6
YM
1622
1623 /* Initialize MCP structure */
1624 rc = qed_mcp_cmd_init(p_hwfn, p_hwfn->p_main_ptt);
1625 if (rc) {
1626 DP_NOTICE(p_hwfn, "Failed initializing mcp command\n");
1627 goto err1;
1628 }
1629
1630 /* Read the device configuration information from the HW and SHMEM */
1631 rc = qed_get_hw_info(p_hwfn, p_hwfn->p_main_ptt, personality);
1632 if (rc) {
1633 DP_NOTICE(p_hwfn, "Failed to get HW information\n");
1634 goto err2;
1635 }
1636
1637 /* Allocate the init RT array and initialize the init-ops engine */
1638 rc = qed_init_alloc(p_hwfn);
1639 if (rc) {
1640 DP_NOTICE(p_hwfn, "Failed to allocate the init array\n");
1641 goto err2;
1642 }
1643
1644 return rc;
1645err2:
32a47e72
YM
1646 if (IS_LEAD_HWFN(p_hwfn))
1647 qed_iov_free_hw_info(p_hwfn->cdev);
fe56b9e6
YM
1648 qed_mcp_free(p_hwfn);
1649err1:
1650 qed_hw_hwfn_free(p_hwfn);
1651err0:
1652 return rc;
1653}
1654
fe56b9e6
YM
1655int qed_hw_prepare(struct qed_dev *cdev,
1656 int personality)
1657{
c78df14e
AE
1658 struct qed_hwfn *p_hwfn = QED_LEADING_HWFN(cdev);
1659 int rc;
fe56b9e6
YM
1660
1661 /* Store the precompiled init data ptrs */
1408cc1f
YM
1662 if (IS_PF(cdev))
1663 qed_init_iro_array(cdev);
fe56b9e6
YM
1664
1665 /* Initialize the first hwfn - will learn number of hwfns */
c78df14e
AE
1666 rc = qed_hw_prepare_single(p_hwfn,
1667 cdev->regview,
fe56b9e6
YM
1668 cdev->doorbells, personality);
1669 if (rc)
1670 return rc;
1671
c78df14e 1672 personality = p_hwfn->hw_info.personality;
fe56b9e6
YM
1673
1674 /* Initialize the rest of the hwfns */
c78df14e 1675 if (cdev->num_hwfns > 1) {
fe56b9e6 1676 void __iomem *p_regview, *p_doorbell;
c78df14e
AE
1677 u8 __iomem *addr;
1678
1679 /* adjust bar offset for second engine */
c2035eea 1680 addr = cdev->regview + qed_hw_bar_size(p_hwfn, BAR_ID_0) / 2;
c78df14e 1681 p_regview = addr;
fe56b9e6 1682
c78df14e 1683 /* adjust doorbell bar offset for second engine */
c2035eea 1684 addr = cdev->doorbells + qed_hw_bar_size(p_hwfn, BAR_ID_1) / 2;
c78df14e
AE
1685 p_doorbell = addr;
1686
1687 /* prepare second hw function */
1688 rc = qed_hw_prepare_single(&cdev->hwfns[1], p_regview,
fe56b9e6 1689 p_doorbell, personality);
c78df14e
AE
1690
1691 /* in case of error, need to free the previously
1692 * initiliazed hwfn 0.
1693 */
fe56b9e6 1694 if (rc) {
1408cc1f
YM
1695 if (IS_PF(cdev)) {
1696 qed_init_free(p_hwfn);
1697 qed_mcp_free(p_hwfn);
1698 qed_hw_hwfn_free(p_hwfn);
1699 }
fe56b9e6
YM
1700 }
1701 }
1702
c78df14e 1703 return rc;
fe56b9e6
YM
1704}
1705
1706void qed_hw_remove(struct qed_dev *cdev)
1707{
1708 int i;
1709
1710 for_each_hwfn(cdev, i) {
1711 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
1712
1408cc1f 1713 if (IS_VF(cdev)) {
0b55e27d 1714 qed_vf_pf_release(p_hwfn);
1408cc1f
YM
1715 continue;
1716 }
1717
fe56b9e6
YM
1718 qed_init_free(p_hwfn);
1719 qed_hw_hwfn_free(p_hwfn);
1720 qed_mcp_free(p_hwfn);
1721 }
32a47e72
YM
1722
1723 qed_iov_free_hw_info(cdev);
fe56b9e6
YM
1724}
1725
1726int qed_chain_alloc(struct qed_dev *cdev,
1727 enum qed_chain_use_mode intended_use,
1728 enum qed_chain_mode mode,
1729 u16 num_elems,
1730 size_t elem_size,
1731 struct qed_chain *p_chain)
1732{
1733 dma_addr_t p_pbl_phys = 0;
1734 void *p_pbl_virt = NULL;
1735 dma_addr_t p_phys = 0;
1736 void *p_virt = NULL;
1737 u16 page_cnt = 0;
1738 size_t size;
1739
1740 if (mode == QED_CHAIN_MODE_SINGLE)
1741 page_cnt = 1;
1742 else
1743 page_cnt = QED_CHAIN_PAGE_CNT(num_elems, elem_size, mode);
1744
1745 size = page_cnt * QED_CHAIN_PAGE_SIZE;
1746 p_virt = dma_alloc_coherent(&cdev->pdev->dev,
1747 size, &p_phys, GFP_KERNEL);
1748 if (!p_virt) {
1749 DP_NOTICE(cdev, "Failed to allocate chain mem\n");
1750 goto nomem;
1751 }
1752
1753 if (mode == QED_CHAIN_MODE_PBL) {
1754 size = page_cnt * QED_CHAIN_PBL_ENTRY_SIZE;
1755 p_pbl_virt = dma_alloc_coherent(&cdev->pdev->dev,
1756 size, &p_pbl_phys,
1757 GFP_KERNEL);
1758 if (!p_pbl_virt) {
1759 DP_NOTICE(cdev, "Failed to allocate chain pbl mem\n");
1760 goto nomem;
1761 }
1762
1763 qed_chain_pbl_init(p_chain, p_virt, p_phys, page_cnt,
1764 (u8)elem_size, intended_use,
1765 p_pbl_phys, p_pbl_virt);
1766 } else {
1767 qed_chain_init(p_chain, p_virt, p_phys, page_cnt,
1768 (u8)elem_size, intended_use, mode);
1769 }
1770
1771 return 0;
1772
1773nomem:
1774 dma_free_coherent(&cdev->pdev->dev,
1775 page_cnt * QED_CHAIN_PAGE_SIZE,
1776 p_virt, p_phys);
1777 dma_free_coherent(&cdev->pdev->dev,
1778 page_cnt * QED_CHAIN_PBL_ENTRY_SIZE,
1779 p_pbl_virt, p_pbl_phys);
1780
1781 return -ENOMEM;
1782}
1783
1784void qed_chain_free(struct qed_dev *cdev,
1785 struct qed_chain *p_chain)
1786{
1787 size_t size;
1788
1789 if (!p_chain->p_virt_addr)
1790 return;
1791
1792 if (p_chain->mode == QED_CHAIN_MODE_PBL) {
1793 size = p_chain->page_cnt * QED_CHAIN_PBL_ENTRY_SIZE;
1794 dma_free_coherent(&cdev->pdev->dev, size,
1795 p_chain->pbl.p_virt_table,
1796 p_chain->pbl.p_phys_table);
1797 }
1798
1799 size = p_chain->page_cnt * QED_CHAIN_PAGE_SIZE;
1800 dma_free_coherent(&cdev->pdev->dev, size,
1801 p_chain->p_virt_addr,
1802 p_chain->p_phys_addr);
1803}
cee4d264
MC
1804
1805int qed_fw_l2_queue(struct qed_hwfn *p_hwfn,
1806 u16 src_id, u16 *dst_id)
1807{
1808 if (src_id >= RESC_NUM(p_hwfn, QED_L2_QUEUE)) {
1809 u16 min, max;
1810
1811 min = (u16)RESC_START(p_hwfn, QED_L2_QUEUE);
1812 max = min + RESC_NUM(p_hwfn, QED_L2_QUEUE);
1813 DP_NOTICE(p_hwfn,
1814 "l2_queue id [%d] is not valid, available indices [%d - %d]\n",
1815 src_id, min, max);
1816
1817 return -EINVAL;
1818 }
1819
1820 *dst_id = RESC_START(p_hwfn, QED_L2_QUEUE) + src_id;
1821
1822 return 0;
1823}
1824
1825int qed_fw_vport(struct qed_hwfn *p_hwfn,
1826 u8 src_id, u8 *dst_id)
1827{
1828 if (src_id >= RESC_NUM(p_hwfn, QED_VPORT)) {
1829 u8 min, max;
1830
1831 min = (u8)RESC_START(p_hwfn, QED_VPORT);
1832 max = min + RESC_NUM(p_hwfn, QED_VPORT);
1833 DP_NOTICE(p_hwfn,
1834 "vport id [%d] is not valid, available indices [%d - %d]\n",
1835 src_id, min, max);
1836
1837 return -EINVAL;
1838 }
1839
1840 *dst_id = RESC_START(p_hwfn, QED_VPORT) + src_id;
1841
1842 return 0;
1843}
1844
1845int qed_fw_rss_eng(struct qed_hwfn *p_hwfn,
1846 u8 src_id, u8 *dst_id)
1847{
1848 if (src_id >= RESC_NUM(p_hwfn, QED_RSS_ENG)) {
1849 u8 min, max;
1850
1851 min = (u8)RESC_START(p_hwfn, QED_RSS_ENG);
1852 max = min + RESC_NUM(p_hwfn, QED_RSS_ENG);
1853 DP_NOTICE(p_hwfn,
1854 "rss_eng id [%d] is not valid, available indices [%d - %d]\n",
1855 src_id, min, max);
1856
1857 return -EINVAL;
1858 }
1859
1860 *dst_id = RESC_START(p_hwfn, QED_RSS_ENG) + src_id;
1861
1862 return 0;
1863}
bcd197c8
MC
1864
1865/* Calculate final WFQ values for all vports and configure them.
1866 * After this configuration each vport will have
1867 * approx min rate = min_pf_rate * (vport_wfq / QED_WFQ_UNIT)
1868 */
1869static void qed_configure_wfq_for_all_vports(struct qed_hwfn *p_hwfn,
1870 struct qed_ptt *p_ptt,
1871 u32 min_pf_rate)
1872{
1873 struct init_qm_vport_params *vport_params;
1874 int i;
1875
1876 vport_params = p_hwfn->qm_info.qm_vport_params;
1877
1878 for (i = 0; i < p_hwfn->qm_info.num_vports; i++) {
1879 u32 wfq_speed = p_hwfn->qm_info.wfq_data[i].min_speed;
1880
1881 vport_params[i].vport_wfq = (wfq_speed * QED_WFQ_UNIT) /
1882 min_pf_rate;
1883 qed_init_vport_wfq(p_hwfn, p_ptt,
1884 vport_params[i].first_tx_pq_id,
1885 vport_params[i].vport_wfq);
1886 }
1887}
1888
1889static void qed_init_wfq_default_param(struct qed_hwfn *p_hwfn,
1890 u32 min_pf_rate)
1891
1892{
1893 int i;
1894
1895 for (i = 0; i < p_hwfn->qm_info.num_vports; i++)
1896 p_hwfn->qm_info.qm_vport_params[i].vport_wfq = 1;
1897}
1898
1899static void qed_disable_wfq_for_all_vports(struct qed_hwfn *p_hwfn,
1900 struct qed_ptt *p_ptt,
1901 u32 min_pf_rate)
1902{
1903 struct init_qm_vport_params *vport_params;
1904 int i;
1905
1906 vport_params = p_hwfn->qm_info.qm_vport_params;
1907
1908 for (i = 0; i < p_hwfn->qm_info.num_vports; i++) {
1909 qed_init_wfq_default_param(p_hwfn, min_pf_rate);
1910 qed_init_vport_wfq(p_hwfn, p_ptt,
1911 vport_params[i].first_tx_pq_id,
1912 vport_params[i].vport_wfq);
1913 }
1914}
1915
1916/* This function performs several validations for WFQ
1917 * configuration and required min rate for a given vport
1918 * 1. req_rate must be greater than one percent of min_pf_rate.
1919 * 2. req_rate should not cause other vports [not configured for WFQ explicitly]
1920 * rates to get less than one percent of min_pf_rate.
1921 * 3. total_req_min_rate [all vports min rate sum] shouldn't exceed min_pf_rate.
1922 */
1923static int qed_init_wfq_param(struct qed_hwfn *p_hwfn,
1924 u16 vport_id, u32 req_rate,
1925 u32 min_pf_rate)
1926{
1927 u32 total_req_min_rate = 0, total_left_rate = 0, left_rate_per_vp = 0;
1928 int non_requested_count = 0, req_count = 0, i, num_vports;
1929
1930 num_vports = p_hwfn->qm_info.num_vports;
1931
1932 /* Accounting for the vports which are configured for WFQ explicitly */
1933 for (i = 0; i < num_vports; i++) {
1934 u32 tmp_speed;
1935
1936 if ((i != vport_id) &&
1937 p_hwfn->qm_info.wfq_data[i].configured) {
1938 req_count++;
1939 tmp_speed = p_hwfn->qm_info.wfq_data[i].min_speed;
1940 total_req_min_rate += tmp_speed;
1941 }
1942 }
1943
1944 /* Include current vport data as well */
1945 req_count++;
1946 total_req_min_rate += req_rate;
1947 non_requested_count = num_vports - req_count;
1948
1949 if (req_rate < min_pf_rate / QED_WFQ_UNIT) {
1950 DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
1951 "Vport [%d] - Requested rate[%d Mbps] is less than one percent of configured PF min rate[%d Mbps]\n",
1952 vport_id, req_rate, min_pf_rate);
1953 return -EINVAL;
1954 }
1955
1956 if (num_vports > QED_WFQ_UNIT) {
1957 DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
1958 "Number of vports is greater than %d\n",
1959 QED_WFQ_UNIT);
1960 return -EINVAL;
1961 }
1962
1963 if (total_req_min_rate > min_pf_rate) {
1964 DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
1965 "Total requested min rate for all vports[%d Mbps] is greater than configured PF min rate[%d Mbps]\n",
1966 total_req_min_rate, min_pf_rate);
1967 return -EINVAL;
1968 }
1969
1970 total_left_rate = min_pf_rate - total_req_min_rate;
1971
1972 left_rate_per_vp = total_left_rate / non_requested_count;
1973 if (left_rate_per_vp < min_pf_rate / QED_WFQ_UNIT) {
1974 DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
1975 "Non WFQ configured vports rate [%d Mbps] is less than one percent of configured PF min rate[%d Mbps]\n",
1976 left_rate_per_vp, min_pf_rate);
1977 return -EINVAL;
1978 }
1979
1980 p_hwfn->qm_info.wfq_data[vport_id].min_speed = req_rate;
1981 p_hwfn->qm_info.wfq_data[vport_id].configured = true;
1982
1983 for (i = 0; i < num_vports; i++) {
1984 if (p_hwfn->qm_info.wfq_data[i].configured)
1985 continue;
1986
1987 p_hwfn->qm_info.wfq_data[i].min_speed = left_rate_per_vp;
1988 }
1989
1990 return 0;
1991}
1992
733def6a
YM
1993static int __qed_configure_vport_wfq(struct qed_hwfn *p_hwfn,
1994 struct qed_ptt *p_ptt, u16 vp_id, u32 rate)
1995{
1996 struct qed_mcp_link_state *p_link;
1997 int rc = 0;
1998
1999 p_link = &p_hwfn->cdev->hwfns[0].mcp_info->link_output;
2000
2001 if (!p_link->min_pf_rate) {
2002 p_hwfn->qm_info.wfq_data[vp_id].min_speed = rate;
2003 p_hwfn->qm_info.wfq_data[vp_id].configured = true;
2004 return rc;
2005 }
2006
2007 rc = qed_init_wfq_param(p_hwfn, vp_id, rate, p_link->min_pf_rate);
2008
2009 if (rc == 0)
2010 qed_configure_wfq_for_all_vports(p_hwfn, p_ptt,
2011 p_link->min_pf_rate);
2012 else
2013 DP_NOTICE(p_hwfn,
2014 "Validation failed while configuring min rate\n");
2015
2016 return rc;
2017}
2018
bcd197c8
MC
2019static int __qed_configure_vp_wfq_on_link_change(struct qed_hwfn *p_hwfn,
2020 struct qed_ptt *p_ptt,
2021 u32 min_pf_rate)
2022{
2023 bool use_wfq = false;
2024 int rc = 0;
2025 u16 i;
2026
2027 /* Validate all pre configured vports for wfq */
2028 for (i = 0; i < p_hwfn->qm_info.num_vports; i++) {
2029 u32 rate;
2030
2031 if (!p_hwfn->qm_info.wfq_data[i].configured)
2032 continue;
2033
2034 rate = p_hwfn->qm_info.wfq_data[i].min_speed;
2035 use_wfq = true;
2036
2037 rc = qed_init_wfq_param(p_hwfn, i, rate, min_pf_rate);
2038 if (rc) {
2039 DP_NOTICE(p_hwfn,
2040 "WFQ validation failed while configuring min rate\n");
2041 break;
2042 }
2043 }
2044
2045 if (!rc && use_wfq)
2046 qed_configure_wfq_for_all_vports(p_hwfn, p_ptt, min_pf_rate);
2047 else
2048 qed_disable_wfq_for_all_vports(p_hwfn, p_ptt, min_pf_rate);
2049
2050 return rc;
2051}
2052
733def6a
YM
2053/* Main API for qed clients to configure vport min rate.
2054 * vp_id - vport id in PF Range[0 - (total_num_vports_per_pf - 1)]
2055 * rate - Speed in Mbps needs to be assigned to a given vport.
2056 */
2057int qed_configure_vport_wfq(struct qed_dev *cdev, u16 vp_id, u32 rate)
2058{
2059 int i, rc = -EINVAL;
2060
2061 /* Currently not supported; Might change in future */
2062 if (cdev->num_hwfns > 1) {
2063 DP_NOTICE(cdev,
2064 "WFQ configuration is not supported for this device\n");
2065 return rc;
2066 }
2067
2068 for_each_hwfn(cdev, i) {
2069 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
2070 struct qed_ptt *p_ptt;
2071
2072 p_ptt = qed_ptt_acquire(p_hwfn);
2073 if (!p_ptt)
2074 return -EBUSY;
2075
2076 rc = __qed_configure_vport_wfq(p_hwfn, p_ptt, vp_id, rate);
2077
2078 if (!rc) {
2079 qed_ptt_release(p_hwfn, p_ptt);
2080 return rc;
2081 }
2082
2083 qed_ptt_release(p_hwfn, p_ptt);
2084 }
2085
2086 return rc;
2087}
2088
bcd197c8
MC
2089/* API to configure WFQ from mcp link change */
2090void qed_configure_vp_wfq_on_link_change(struct qed_dev *cdev, u32 min_pf_rate)
2091{
2092 int i;
2093
2094 for_each_hwfn(cdev, i) {
2095 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
2096
2097 __qed_configure_vp_wfq_on_link_change(p_hwfn,
2098 p_hwfn->p_dpc_ptt,
2099 min_pf_rate);
2100 }
2101}
4b01e519
MC
2102
2103int __qed_configure_pf_max_bandwidth(struct qed_hwfn *p_hwfn,
2104 struct qed_ptt *p_ptt,
2105 struct qed_mcp_link_state *p_link,
2106 u8 max_bw)
2107{
2108 int rc = 0;
2109
2110 p_hwfn->mcp_info->func_info.bandwidth_max = max_bw;
2111
2112 if (!p_link->line_speed && (max_bw != 100))
2113 return rc;
2114
2115 p_link->speed = (p_link->line_speed * max_bw) / 100;
2116 p_hwfn->qm_info.pf_rl = p_link->speed;
2117
2118 /* Since the limiter also affects Tx-switched traffic, we don't want it
2119 * to limit such traffic in case there's no actual limit.
2120 * In that case, set limit to imaginary high boundary.
2121 */
2122 if (max_bw == 100)
2123 p_hwfn->qm_info.pf_rl = 100000;
2124
2125 rc = qed_init_pf_rl(p_hwfn, p_ptt, p_hwfn->rel_pf_id,
2126 p_hwfn->qm_info.pf_rl);
2127
2128 DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
2129 "Configured MAX bandwidth to be %08x Mb/sec\n",
2130 p_link->speed);
2131
2132 return rc;
2133}
2134
2135/* Main API to configure PF max bandwidth where bw range is [1 - 100] */
2136int qed_configure_pf_max_bandwidth(struct qed_dev *cdev, u8 max_bw)
2137{
2138 int i, rc = -EINVAL;
2139
2140 if (max_bw < 1 || max_bw > 100) {
2141 DP_NOTICE(cdev, "PF max bw valid range is [1-100]\n");
2142 return rc;
2143 }
2144
2145 for_each_hwfn(cdev, i) {
2146 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
2147 struct qed_hwfn *p_lead = QED_LEADING_HWFN(cdev);
2148 struct qed_mcp_link_state *p_link;
2149 struct qed_ptt *p_ptt;
2150
2151 p_link = &p_lead->mcp_info->link_output;
2152
2153 p_ptt = qed_ptt_acquire(p_hwfn);
2154 if (!p_ptt)
2155 return -EBUSY;
2156
2157 rc = __qed_configure_pf_max_bandwidth(p_hwfn, p_ptt,
2158 p_link, max_bw);
2159
2160 qed_ptt_release(p_hwfn, p_ptt);
2161
2162 if (rc)
2163 break;
2164 }
2165
2166 return rc;
2167}
a64b02d5
MC
2168
2169int __qed_configure_pf_min_bandwidth(struct qed_hwfn *p_hwfn,
2170 struct qed_ptt *p_ptt,
2171 struct qed_mcp_link_state *p_link,
2172 u8 min_bw)
2173{
2174 int rc = 0;
2175
2176 p_hwfn->mcp_info->func_info.bandwidth_min = min_bw;
2177 p_hwfn->qm_info.pf_wfq = min_bw;
2178
2179 if (!p_link->line_speed)
2180 return rc;
2181
2182 p_link->min_pf_rate = (p_link->line_speed * min_bw) / 100;
2183
2184 rc = qed_init_pf_wfq(p_hwfn, p_ptt, p_hwfn->rel_pf_id, min_bw);
2185
2186 DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
2187 "Configured MIN bandwidth to be %d Mb/sec\n",
2188 p_link->min_pf_rate);
2189
2190 return rc;
2191}
2192
2193/* Main API to configure PF min bandwidth where bw range is [1-100] */
2194int qed_configure_pf_min_bandwidth(struct qed_dev *cdev, u8 min_bw)
2195{
2196 int i, rc = -EINVAL;
2197
2198 if (min_bw < 1 || min_bw > 100) {
2199 DP_NOTICE(cdev, "PF min bw valid range is [1-100]\n");
2200 return rc;
2201 }
2202
2203 for_each_hwfn(cdev, i) {
2204 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
2205 struct qed_hwfn *p_lead = QED_LEADING_HWFN(cdev);
2206 struct qed_mcp_link_state *p_link;
2207 struct qed_ptt *p_ptt;
2208
2209 p_link = &p_lead->mcp_info->link_output;
2210
2211 p_ptt = qed_ptt_acquire(p_hwfn);
2212 if (!p_ptt)
2213 return -EBUSY;
2214
2215 rc = __qed_configure_pf_min_bandwidth(p_hwfn, p_ptt,
2216 p_link, min_bw);
2217 if (rc) {
2218 qed_ptt_release(p_hwfn, p_ptt);
2219 return rc;
2220 }
2221
2222 if (p_link->min_pf_rate) {
2223 u32 min_rate = p_link->min_pf_rate;
2224
2225 rc = __qed_configure_vp_wfq_on_link_change(p_hwfn,
2226 p_ptt,
2227 min_rate);
2228 }
2229
2230 qed_ptt_release(p_hwfn, p_ptt);
2231 }
2232
2233 return rc;
2234}
733def6a
YM
2235
2236void qed_clean_wfq_db(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
2237{
2238 struct qed_mcp_link_state *p_link;
2239
2240 p_link = &p_hwfn->mcp_info->link_output;
2241
2242 if (p_link->min_pf_rate)
2243 qed_disable_wfq_for_all_vports(p_hwfn, p_ptt,
2244 p_link->min_pf_rate);
2245
2246 memset(p_hwfn->qm_info.wfq_data, 0,
2247 sizeof(*p_hwfn->qm_info.wfq_data) * p_hwfn->qm_info.num_vports);
2248}