blob: 7649f35000db919a9d4376910a85de1c10810885 [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/types.h>
34#include <asm/byteorder.h>
35#include <linux/io.h>
36#include <linux/delay.h>
37#include <linux/dma-mapping.h>
38#include <linux/errno.h>
39#include <linux/kernel.h>
40#include <linux/mutex.h>
41#include <linux/pci.h>
42#include <linux/slab.h>
43#include <linux/string.h>
Yuval Mintza91eb522016-06-03 14:35:32 +030044#include <linux/vmalloc.h>
Yuval Mintzfe56b9e2015-10-26 11:02:25 +020045#include <linux/etherdevice.h>
46#include <linux/qed/qed_chain.h>
47#include <linux/qed/qed_if.h>
48#include "qed.h"
49#include "qed_cxt.h"
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -040050#include "qed_dcbx.h"
Yuval Mintzfe56b9e2015-10-26 11:02:25 +020051#include "qed_dev_api.h"
Arun Easi1e128c82017-02-15 06:28:22 -080052#include "qed_fcoe.h"
Yuval Mintzfe56b9e2015-10-26 11:02:25 +020053#include "qed_hsi.h"
54#include "qed_hw.h"
55#include "qed_init_ops.h"
56#include "qed_int.h"
Yuval Mintzfc831822016-12-01 00:21:06 -080057#include "qed_iscsi.h"
Yuval Mintz0a7fb112016-10-01 21:59:55 +030058#include "qed_ll2.h"
Yuval Mintzfe56b9e2015-10-26 11:02:25 +020059#include "qed_mcp.h"
Yuval Mintz1d6cff42016-12-01 00:21:07 -080060#include "qed_ooo.h"
Yuval Mintzfe56b9e2015-10-26 11:02:25 +020061#include "qed_reg_addr.h"
62#include "qed_sp.h"
Yuval Mintz32a47e72016-05-11 16:36:12 +030063#include "qed_sriov.h"
Yuval Mintz0b55e272016-05-11 16:36:15 +030064#include "qed_vf.h"
Ram Amrani51ff1722016-10-01 21:59:57 +030065#include "qed_roce.h"
Yuval Mintzfe56b9e2015-10-26 11:02:25 +020066
Wei Yongjun0caf5b22016-08-02 13:49:00 +000067static DEFINE_SPINLOCK(qm_lock);
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -040068
Ram Amrani51ff1722016-10-01 21:59:57 +030069#define QED_MIN_DPIS (4)
70#define QED_MIN_PWM_REGION (QED_WID_SIZE * QED_MIN_DPIS)
71
Yuval Mintzfe56b9e2015-10-26 11:02:25 +020072/* API common to all protocols */
Ram Amranic2035ee2016-03-02 20:26:00 +020073enum BAR_ID {
74 BAR_ID_0, /* used for GRC */
75 BAR_ID_1 /* Used for doorbells */
76};
77
Rahul Verma15582962017-04-06 15:58:29 +030078static u32 qed_hw_bar_size(struct qed_hwfn *p_hwfn,
79 struct qed_ptt *p_ptt, enum BAR_ID bar_id)
Ram Amranic2035ee2016-03-02 20:26:00 +020080{
Yuval Mintz1408cc1f2016-05-11 16:36:14 +030081 u32 bar_reg = (bar_id == BAR_ID_0 ?
82 PGLUE_B_REG_PF_BAR0_SIZE : PGLUE_B_REG_PF_BAR1_SIZE);
83 u32 val;
Ram Amranic2035ee2016-03-02 20:26:00 +020084
Yuval Mintz1408cc1f2016-05-11 16:36:14 +030085 if (IS_VF(p_hwfn->cdev))
86 return 1 << 17;
87
Rahul Verma15582962017-04-06 15:58:29 +030088 val = qed_rd(p_hwfn, p_ptt, bar_reg);
Ram Amranic2035ee2016-03-02 20:26:00 +020089 if (val)
90 return 1 << (val + 15);
91
92 /* Old MFW initialized above registered only conditionally */
93 if (p_hwfn->cdev->num_hwfns > 1) {
94 DP_INFO(p_hwfn,
95 "BAR size not configured. Assuming BAR size of 256kB for GRC and 512kB for DB\n");
96 return BAR_ID_0 ? 256 * 1024 : 512 * 1024;
97 } else {
98 DP_INFO(p_hwfn,
99 "BAR size not configured. Assuming BAR size of 512kB for GRC and 512kB for DB\n");
100 return 512 * 1024;
101 }
102}
103
Yuval Mintz1a635e42016-08-15 10:42:43 +0300104void qed_init_dp(struct qed_dev *cdev, u32 dp_module, u8 dp_level)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200105{
106 u32 i;
107
108 cdev->dp_level = dp_level;
109 cdev->dp_module = dp_module;
110 for (i = 0; i < MAX_HWFNS_PER_DEVICE; i++) {
111 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
112
113 p_hwfn->dp_level = dp_level;
114 p_hwfn->dp_module = dp_module;
115 }
116}
117
118void qed_init_struct(struct qed_dev *cdev)
119{
120 u8 i;
121
122 for (i = 0; i < MAX_HWFNS_PER_DEVICE; i++) {
123 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
124
125 p_hwfn->cdev = cdev;
126 p_hwfn->my_id = i;
127 p_hwfn->b_active = false;
128
129 mutex_init(&p_hwfn->dmae_info.mutex);
130 }
131
132 /* hwfn 0 is always active */
133 cdev->hwfns[0].b_active = true;
134
135 /* set the default cache alignment to 128 */
136 cdev->cache_shift = 7;
137}
138
139static void qed_qm_info_free(struct qed_hwfn *p_hwfn)
140{
141 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
142
143 kfree(qm_info->qm_pq_params);
144 qm_info->qm_pq_params = NULL;
145 kfree(qm_info->qm_vport_params);
146 qm_info->qm_vport_params = NULL;
147 kfree(qm_info->qm_port_params);
148 qm_info->qm_port_params = NULL;
Manish Choprabcd197c2016-04-26 10:56:08 -0400149 kfree(qm_info->wfq_data);
150 qm_info->wfq_data = NULL;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200151}
152
153void qed_resc_free(struct qed_dev *cdev)
154{
155 int i;
156
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300157 if (IS_VF(cdev))
158 return;
159
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200160 kfree(cdev->fw_data);
161 cdev->fw_data = NULL;
162
163 kfree(cdev->reset_stats);
Tomer Tayar3587cb82017-05-21 12:10:56 +0300164 cdev->reset_stats = NULL;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200165
166 for_each_hwfn(cdev, i) {
167 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
168
169 qed_cxt_mngr_free(p_hwfn);
170 qed_qm_info_free(p_hwfn);
171 qed_spq_free(p_hwfn);
Tomer Tayar3587cb82017-05-21 12:10:56 +0300172 qed_eq_free(p_hwfn);
173 qed_consq_free(p_hwfn);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200174 qed_int_free(p_hwfn);
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300175#ifdef CONFIG_QED_LL2
Tomer Tayar3587cb82017-05-21 12:10:56 +0300176 qed_ll2_free(p_hwfn);
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300177#endif
Arun Easi1e128c82017-02-15 06:28:22 -0800178 if (p_hwfn->hw_info.personality == QED_PCI_FCOE)
Tomer Tayar3587cb82017-05-21 12:10:56 +0300179 qed_fcoe_free(p_hwfn);
Arun Easi1e128c82017-02-15 06:28:22 -0800180
Yuval Mintz1d6cff42016-12-01 00:21:07 -0800181 if (p_hwfn->hw_info.personality == QED_PCI_ISCSI) {
Tomer Tayar3587cb82017-05-21 12:10:56 +0300182 qed_iscsi_free(p_hwfn);
183 qed_ooo_free(p_hwfn);
Yuval Mintz1d6cff42016-12-01 00:21:07 -0800184 }
Yuval Mintz32a47e72016-05-11 16:36:12 +0300185 qed_iov_free(p_hwfn);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200186 qed_dmae_info_free(p_hwfn);
sudarsana.kalluru@cavium.com270837b2017-04-20 22:31:16 -0700187 qed_dcbx_info_free(p_hwfn);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200188 }
189}
190
Ariel Eliorb5a9ee72017-04-03 12:21:09 +0300191/******************** QM initialization *******************/
192#define ACTIVE_TCS_BMAP 0x9f
193#define ACTIVE_TCS_BMAP_4PORT_K2 0xf
194
195/* determines the physical queue flags for a given PF. */
196static u32 qed_get_pq_flags(struct qed_hwfn *p_hwfn)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200197{
Ariel Eliorb5a9ee72017-04-03 12:21:09 +0300198 u32 flags;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200199
Ariel Eliorb5a9ee72017-04-03 12:21:09 +0300200 /* common flags */
201 flags = PQ_FLAGS_LB;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200202
Ariel Eliorb5a9ee72017-04-03 12:21:09 +0300203 /* feature flags */
204 if (IS_QED_SRIOV(p_hwfn->cdev))
205 flags |= PQ_FLAGS_VFS;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200206
Ariel Eliorb5a9ee72017-04-03 12:21:09 +0300207 /* protocol flags */
208 switch (p_hwfn->hw_info.personality) {
209 case QED_PCI_ETH:
210 flags |= PQ_FLAGS_MCOS;
211 break;
212 case QED_PCI_FCOE:
213 flags |= PQ_FLAGS_OFLD;
214 break;
215 case QED_PCI_ISCSI:
216 flags |= PQ_FLAGS_ACK | PQ_FLAGS_OOO | PQ_FLAGS_OFLD;
217 break;
218 case QED_PCI_ETH_ROCE:
219 flags |= PQ_FLAGS_MCOS | PQ_FLAGS_OFLD | PQ_FLAGS_LLT;
220 break;
221 default:
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200222 DP_ERR(p_hwfn,
Ariel Eliorb5a9ee72017-04-03 12:21:09 +0300223 "unknown personality %d\n", p_hwfn->hw_info.personality);
224 return 0;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200225 }
226
Ariel Eliorb5a9ee72017-04-03 12:21:09 +0300227 return flags;
228}
229
230/* Getters for resource amounts necessary for qm initialization */
231u8 qed_init_qm_get_num_tcs(struct qed_hwfn *p_hwfn)
232{
233 return p_hwfn->hw_info.num_hw_tc;
234}
235
236u16 qed_init_qm_get_num_vfs(struct qed_hwfn *p_hwfn)
237{
238 return IS_QED_SRIOV(p_hwfn->cdev) ?
239 p_hwfn->cdev->p_iov_info->total_vfs : 0;
240}
241
242#define NUM_DEFAULT_RLS 1
243
244u16 qed_init_qm_get_num_pf_rls(struct qed_hwfn *p_hwfn)
245{
246 u16 num_pf_rls, num_vfs = qed_init_qm_get_num_vfs(p_hwfn);
247
248 /* num RLs can't exceed resource amount of rls or vports */
249 num_pf_rls = (u16) min_t(u32, RESC_NUM(p_hwfn, QED_RL),
250 RESC_NUM(p_hwfn, QED_VPORT));
251
252 /* Make sure after we reserve there's something left */
253 if (num_pf_rls < num_vfs + NUM_DEFAULT_RLS)
254 return 0;
255
256 /* subtract rls necessary for VFs and one default one for the PF */
257 num_pf_rls -= num_vfs + NUM_DEFAULT_RLS;
258
259 return num_pf_rls;
260}
261
262u16 qed_init_qm_get_num_vports(struct qed_hwfn *p_hwfn)
263{
264 u32 pq_flags = qed_get_pq_flags(p_hwfn);
265
266 /* all pqs share the same vport, except for vfs and pf_rl pqs */
267 return (!!(PQ_FLAGS_RLS & pq_flags)) *
268 qed_init_qm_get_num_pf_rls(p_hwfn) +
269 (!!(PQ_FLAGS_VFS & pq_flags)) *
270 qed_init_qm_get_num_vfs(p_hwfn) + 1;
271}
272
273/* calc amount of PQs according to the requested flags */
274u16 qed_init_qm_get_num_pqs(struct qed_hwfn *p_hwfn)
275{
276 u32 pq_flags = qed_get_pq_flags(p_hwfn);
277
278 return (!!(PQ_FLAGS_RLS & pq_flags)) *
279 qed_init_qm_get_num_pf_rls(p_hwfn) +
280 (!!(PQ_FLAGS_MCOS & pq_flags)) *
281 qed_init_qm_get_num_tcs(p_hwfn) +
282 (!!(PQ_FLAGS_LB & pq_flags)) + (!!(PQ_FLAGS_OOO & pq_flags)) +
283 (!!(PQ_FLAGS_ACK & pq_flags)) + (!!(PQ_FLAGS_OFLD & pq_flags)) +
284 (!!(PQ_FLAGS_LLT & pq_flags)) +
285 (!!(PQ_FLAGS_VFS & pq_flags)) * qed_init_qm_get_num_vfs(p_hwfn);
286}
287
288/* initialize the top level QM params */
289static void qed_init_qm_params(struct qed_hwfn *p_hwfn)
290{
291 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
292 bool four_port;
293
294 /* pq and vport bases for this PF */
295 qm_info->start_pq = (u16) RESC_START(p_hwfn, QED_PQ);
296 qm_info->start_vport = (u8) RESC_START(p_hwfn, QED_VPORT);
297
298 /* rate limiting and weighted fair queueing are always enabled */
299 qm_info->vport_rl_en = 1;
300 qm_info->vport_wfq_en = 1;
301
302 /* TC config is different for AH 4 port */
Tomer Tayar78cea9f2017-05-23 09:41:22 +0300303 four_port = p_hwfn->cdev->num_ports_in_engine == MAX_NUM_PORTS_K2;
Ariel Eliorb5a9ee72017-04-03 12:21:09 +0300304
305 /* in AH 4 port we have fewer TCs per port */
306 qm_info->max_phys_tcs_per_port = four_port ? NUM_PHYS_TCS_4PORT_K2 :
307 NUM_OF_PHYS_TCS;
308
309 /* unless MFW indicated otherwise, ooo_tc == 3 for
310 * AH 4-port and 4 otherwise.
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200311 */
Ariel Eliorb5a9ee72017-04-03 12:21:09 +0300312 if (!qm_info->ooo_tc)
313 qm_info->ooo_tc = four_port ? DCBX_TCP_OOO_K2_4PORT_TC :
314 DCBX_TCP_OOO_TC;
315}
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200316
Ariel Eliorb5a9ee72017-04-03 12:21:09 +0300317/* initialize qm vport params */
318static void qed_init_qm_vport_params(struct qed_hwfn *p_hwfn)
319{
320 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
321 u8 i;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200322
Ariel Eliorb5a9ee72017-04-03 12:21:09 +0300323 /* all vports participate in weighted fair queueing */
324 for (i = 0; i < qed_init_qm_get_num_vports(p_hwfn); i++)
325 qm_info->qm_vport_params[i].vport_wfq = 1;
326}
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200327
Ariel Eliorb5a9ee72017-04-03 12:21:09 +0300328/* initialize qm port params */
329static void qed_init_qm_port_params(struct qed_hwfn *p_hwfn)
330{
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200331 /* Initialize qm port parameters */
Tomer Tayar78cea9f2017-05-23 09:41:22 +0300332 u8 i, active_phys_tcs, num_ports = p_hwfn->cdev->num_ports_in_engine;
Ariel Eliorb5a9ee72017-04-03 12:21:09 +0300333
334 /* indicate how ooo and high pri traffic is dealt with */
335 active_phys_tcs = num_ports == MAX_NUM_PORTS_K2 ?
336 ACTIVE_TCS_BMAP_4PORT_K2 :
337 ACTIVE_TCS_BMAP;
338
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200339 for (i = 0; i < num_ports; i++) {
Ariel Eliorb5a9ee72017-04-03 12:21:09 +0300340 struct init_qm_port_params *p_qm_port =
341 &p_hwfn->qm_info.qm_port_params[i];
342
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200343 p_qm_port->active = 1;
Ariel Eliorb5a9ee72017-04-03 12:21:09 +0300344 p_qm_port->active_phys_tcs = active_phys_tcs;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200345 p_qm_port->num_pbf_cmd_lines = PBF_MAX_CMD_LINES / num_ports;
346 p_qm_port->num_btb_blocks = BTB_MAX_BLOCKS / num_ports;
347 }
Ariel Eliorb5a9ee72017-04-03 12:21:09 +0300348}
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200349
Ariel Eliorb5a9ee72017-04-03 12:21:09 +0300350/* Reset the params which must be reset for qm init. QM init may be called as
351 * a result of flows other than driver load (e.g. dcbx renegotiation). Other
352 * params may be affected by the init but would simply recalculate to the same
353 * values. The allocations made for QM init, ports, vports, pqs and vfqs are not
354 * affected as these amounts stay the same.
355 */
356static void qed_init_qm_reset_params(struct qed_hwfn *p_hwfn)
357{
358 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200359
Ariel Eliorb5a9ee72017-04-03 12:21:09 +0300360 qm_info->num_pqs = 0;
361 qm_info->num_vports = 0;
362 qm_info->num_pf_rls = 0;
363 qm_info->num_vf_pqs = 0;
364 qm_info->first_vf_pq = 0;
365 qm_info->first_mcos_pq = 0;
366 qm_info->first_rl_pq = 0;
367}
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200368
Ariel Eliorb5a9ee72017-04-03 12:21:09 +0300369static void qed_init_qm_advance_vport(struct qed_hwfn *p_hwfn)
370{
371 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
372
373 qm_info->num_vports++;
374
375 if (qm_info->num_vports > qed_init_qm_get_num_vports(p_hwfn))
376 DP_ERR(p_hwfn,
377 "vport overflow! qm_info->num_vports %d, qm_init_get_num_vports() %d\n",
378 qm_info->num_vports, qed_init_qm_get_num_vports(p_hwfn));
379}
380
381/* initialize a single pq and manage qm_info resources accounting.
382 * The pq_init_flags param determines whether the PQ is rate limited
383 * (for VF or PF) and whether a new vport is allocated to the pq or not
384 * (i.e. vport will be shared).
385 */
386
387/* flags for pq init */
388#define PQ_INIT_SHARE_VPORT (1 << 0)
389#define PQ_INIT_PF_RL (1 << 1)
390#define PQ_INIT_VF_RL (1 << 2)
391
392/* defines for pq init */
393#define PQ_INIT_DEFAULT_WRR_GROUP 1
394#define PQ_INIT_DEFAULT_TC 0
395#define PQ_INIT_OFLD_TC (p_hwfn->hw_info.offload_tc)
396
397static void qed_init_qm_pq(struct qed_hwfn *p_hwfn,
398 struct qed_qm_info *qm_info,
399 u8 tc, u32 pq_init_flags)
400{
401 u16 pq_idx = qm_info->num_pqs, max_pq = qed_init_qm_get_num_pqs(p_hwfn);
402
403 if (pq_idx > max_pq)
404 DP_ERR(p_hwfn,
405 "pq overflow! pq %d, max pq %d\n", pq_idx, max_pq);
406
407 /* init pq params */
408 qm_info->qm_pq_params[pq_idx].vport_id = qm_info->start_vport +
409 qm_info->num_vports;
410 qm_info->qm_pq_params[pq_idx].tc_id = tc;
411 qm_info->qm_pq_params[pq_idx].wrr_group = PQ_INIT_DEFAULT_WRR_GROUP;
412 qm_info->qm_pq_params[pq_idx].rl_valid =
413 (pq_init_flags & PQ_INIT_PF_RL || pq_init_flags & PQ_INIT_VF_RL);
414
415 /* qm params accounting */
416 qm_info->num_pqs++;
417 if (!(pq_init_flags & PQ_INIT_SHARE_VPORT))
418 qm_info->num_vports++;
419
420 if (pq_init_flags & PQ_INIT_PF_RL)
421 qm_info->num_pf_rls++;
422
423 if (qm_info->num_vports > qed_init_qm_get_num_vports(p_hwfn))
424 DP_ERR(p_hwfn,
425 "vport overflow! qm_info->num_vports %d, qm_init_get_num_vports() %d\n",
426 qm_info->num_vports, qed_init_qm_get_num_vports(p_hwfn));
427
428 if (qm_info->num_pf_rls > qed_init_qm_get_num_pf_rls(p_hwfn))
429 DP_ERR(p_hwfn,
430 "rl overflow! qm_info->num_pf_rls %d, qm_init_get_num_pf_rls() %d\n",
431 qm_info->num_pf_rls, qed_init_qm_get_num_pf_rls(p_hwfn));
432}
433
434/* get pq index according to PQ_FLAGS */
435static u16 *qed_init_qm_get_idx_from_flags(struct qed_hwfn *p_hwfn,
436 u32 pq_flags)
437{
438 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
439
440 /* Can't have multiple flags set here */
441 if (bitmap_weight((unsigned long *)&pq_flags, sizeof(pq_flags)) > 1)
442 goto err;
443
444 switch (pq_flags) {
445 case PQ_FLAGS_RLS:
446 return &qm_info->first_rl_pq;
447 case PQ_FLAGS_MCOS:
448 return &qm_info->first_mcos_pq;
449 case PQ_FLAGS_LB:
450 return &qm_info->pure_lb_pq;
451 case PQ_FLAGS_OOO:
452 return &qm_info->ooo_pq;
453 case PQ_FLAGS_ACK:
454 return &qm_info->pure_ack_pq;
455 case PQ_FLAGS_OFLD:
456 return &qm_info->offload_pq;
457 case PQ_FLAGS_LLT:
458 return &qm_info->low_latency_pq;
459 case PQ_FLAGS_VFS:
460 return &qm_info->first_vf_pq;
461 default:
462 goto err;
463 }
464
465err:
466 DP_ERR(p_hwfn, "BAD pq flags %d\n", pq_flags);
467 return NULL;
468}
469
470/* save pq index in qm info */
471static void qed_init_qm_set_idx(struct qed_hwfn *p_hwfn,
472 u32 pq_flags, u16 pq_val)
473{
474 u16 *base_pq_idx = qed_init_qm_get_idx_from_flags(p_hwfn, pq_flags);
475
476 *base_pq_idx = p_hwfn->qm_info.start_pq + pq_val;
477}
478
479/* get tx pq index, with the PQ TX base already set (ready for context init) */
480u16 qed_get_cm_pq_idx(struct qed_hwfn *p_hwfn, u32 pq_flags)
481{
482 u16 *base_pq_idx = qed_init_qm_get_idx_from_flags(p_hwfn, pq_flags);
483
484 return *base_pq_idx + CM_TX_PQ_BASE;
485}
486
487u16 qed_get_cm_pq_idx_mcos(struct qed_hwfn *p_hwfn, u8 tc)
488{
489 u8 max_tc = qed_init_qm_get_num_tcs(p_hwfn);
490
491 if (tc > max_tc)
492 DP_ERR(p_hwfn, "tc %d must be smaller than %d\n", tc, max_tc);
493
494 return qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_MCOS) + tc;
495}
496
497u16 qed_get_cm_pq_idx_vf(struct qed_hwfn *p_hwfn, u16 vf)
498{
499 u16 max_vf = qed_init_qm_get_num_vfs(p_hwfn);
500
501 if (vf > max_vf)
502 DP_ERR(p_hwfn, "vf %d must be smaller than %d\n", vf, max_vf);
503
504 return qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_VFS) + vf;
505}
506
507u16 qed_get_cm_pq_idx_rl(struct qed_hwfn *p_hwfn, u8 rl)
508{
509 u16 max_rl = qed_init_qm_get_num_pf_rls(p_hwfn);
510
511 if (rl > max_rl)
512 DP_ERR(p_hwfn, "rl %d must be smaller than %d\n", rl, max_rl);
513
514 return qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_RLS) + rl;
515}
516
517/* Functions for creating specific types of pqs */
518static void qed_init_qm_lb_pq(struct qed_hwfn *p_hwfn)
519{
520 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
521
522 if (!(qed_get_pq_flags(p_hwfn) & PQ_FLAGS_LB))
523 return;
524
525 qed_init_qm_set_idx(p_hwfn, PQ_FLAGS_LB, qm_info->num_pqs);
526 qed_init_qm_pq(p_hwfn, qm_info, PURE_LB_TC, PQ_INIT_SHARE_VPORT);
527}
528
529static void qed_init_qm_ooo_pq(struct qed_hwfn *p_hwfn)
530{
531 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
532
533 if (!(qed_get_pq_flags(p_hwfn) & PQ_FLAGS_OOO))
534 return;
535
536 qed_init_qm_set_idx(p_hwfn, PQ_FLAGS_OOO, qm_info->num_pqs);
537 qed_init_qm_pq(p_hwfn, qm_info, qm_info->ooo_tc, PQ_INIT_SHARE_VPORT);
538}
539
540static void qed_init_qm_pure_ack_pq(struct qed_hwfn *p_hwfn)
541{
542 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
543
544 if (!(qed_get_pq_flags(p_hwfn) & PQ_FLAGS_ACK))
545 return;
546
547 qed_init_qm_set_idx(p_hwfn, PQ_FLAGS_ACK, qm_info->num_pqs);
548 qed_init_qm_pq(p_hwfn, qm_info, PQ_INIT_OFLD_TC, PQ_INIT_SHARE_VPORT);
549}
550
551static void qed_init_qm_offload_pq(struct qed_hwfn *p_hwfn)
552{
553 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
554
555 if (!(qed_get_pq_flags(p_hwfn) & PQ_FLAGS_OFLD))
556 return;
557
558 qed_init_qm_set_idx(p_hwfn, PQ_FLAGS_OFLD, qm_info->num_pqs);
559 qed_init_qm_pq(p_hwfn, qm_info, PQ_INIT_OFLD_TC, PQ_INIT_SHARE_VPORT);
560}
561
562static void qed_init_qm_low_latency_pq(struct qed_hwfn *p_hwfn)
563{
564 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
565
566 if (!(qed_get_pq_flags(p_hwfn) & PQ_FLAGS_LLT))
567 return;
568
569 qed_init_qm_set_idx(p_hwfn, PQ_FLAGS_LLT, qm_info->num_pqs);
570 qed_init_qm_pq(p_hwfn, qm_info, PQ_INIT_OFLD_TC, PQ_INIT_SHARE_VPORT);
571}
572
573static void qed_init_qm_mcos_pqs(struct qed_hwfn *p_hwfn)
574{
575 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
576 u8 tc_idx;
577
578 if (!(qed_get_pq_flags(p_hwfn) & PQ_FLAGS_MCOS))
579 return;
580
581 qed_init_qm_set_idx(p_hwfn, PQ_FLAGS_MCOS, qm_info->num_pqs);
582 for (tc_idx = 0; tc_idx < qed_init_qm_get_num_tcs(p_hwfn); tc_idx++)
583 qed_init_qm_pq(p_hwfn, qm_info, tc_idx, PQ_INIT_SHARE_VPORT);
584}
585
586static void qed_init_qm_vf_pqs(struct qed_hwfn *p_hwfn)
587{
588 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
589 u16 vf_idx, num_vfs = qed_init_qm_get_num_vfs(p_hwfn);
590
591 if (!(qed_get_pq_flags(p_hwfn) & PQ_FLAGS_VFS))
592 return;
593
594 qed_init_qm_set_idx(p_hwfn, PQ_FLAGS_VFS, qm_info->num_pqs);
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300595 qm_info->num_vf_pqs = num_vfs;
Ariel Eliorb5a9ee72017-04-03 12:21:09 +0300596 for (vf_idx = 0; vf_idx < num_vfs; vf_idx++)
597 qed_init_qm_pq(p_hwfn,
598 qm_info, PQ_INIT_DEFAULT_TC, PQ_INIT_VF_RL);
599}
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200600
Ariel Eliorb5a9ee72017-04-03 12:21:09 +0300601static void qed_init_qm_rl_pqs(struct qed_hwfn *p_hwfn)
602{
603 u16 pf_rls_idx, num_pf_rls = qed_init_qm_get_num_pf_rls(p_hwfn);
604 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
Manish Chopraa64b02d2016-04-26 10:56:10 -0400605
Ariel Eliorb5a9ee72017-04-03 12:21:09 +0300606 if (!(qed_get_pq_flags(p_hwfn) & PQ_FLAGS_RLS))
607 return;
608
609 qed_init_qm_set_idx(p_hwfn, PQ_FLAGS_RLS, qm_info->num_pqs);
610 for (pf_rls_idx = 0; pf_rls_idx < num_pf_rls; pf_rls_idx++)
611 qed_init_qm_pq(p_hwfn, qm_info, PQ_INIT_OFLD_TC, PQ_INIT_PF_RL);
612}
613
614static void qed_init_qm_pq_params(struct qed_hwfn *p_hwfn)
615{
616 /* rate limited pqs, must come first (FW assumption) */
617 qed_init_qm_rl_pqs(p_hwfn);
618
619 /* pqs for multi cos */
620 qed_init_qm_mcos_pqs(p_hwfn);
621
622 /* pure loopback pq */
623 qed_init_qm_lb_pq(p_hwfn);
624
625 /* out of order pq */
626 qed_init_qm_ooo_pq(p_hwfn);
627
628 /* pure ack pq */
629 qed_init_qm_pure_ack_pq(p_hwfn);
630
631 /* pq for offloaded protocol */
632 qed_init_qm_offload_pq(p_hwfn);
633
634 /* low latency pq */
635 qed_init_qm_low_latency_pq(p_hwfn);
636
637 /* done sharing vports */
638 qed_init_qm_advance_vport(p_hwfn);
639
640 /* pqs for vfs */
641 qed_init_qm_vf_pqs(p_hwfn);
642}
643
644/* compare values of getters against resources amounts */
645static int qed_init_qm_sanity(struct qed_hwfn *p_hwfn)
646{
647 if (qed_init_qm_get_num_vports(p_hwfn) > RESC_NUM(p_hwfn, QED_VPORT)) {
648 DP_ERR(p_hwfn, "requested amount of vports exceeds resource\n");
649 return -EINVAL;
650 }
651
652 if (qed_init_qm_get_num_pqs(p_hwfn) > RESC_NUM(p_hwfn, QED_PQ)) {
653 DP_ERR(p_hwfn, "requested amount of pqs exceeds resource\n");
654 return -EINVAL;
655 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200656
657 return 0;
Ariel Eliorb5a9ee72017-04-03 12:21:09 +0300658}
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200659
Ariel Eliorb5a9ee72017-04-03 12:21:09 +0300660static void qed_dp_init_qm_params(struct qed_hwfn *p_hwfn)
661{
662 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
663 struct init_qm_vport_params *vport;
664 struct init_qm_port_params *port;
665 struct init_qm_pq_params *pq;
666 int i, tc;
667
668 /* top level params */
669 DP_VERBOSE(p_hwfn,
670 NETIF_MSG_HW,
671 "qm init top level params: start_pq %d, start_vport %d, pure_lb_pq %d, offload_pq %d, pure_ack_pq %d\n",
672 qm_info->start_pq,
673 qm_info->start_vport,
674 qm_info->pure_lb_pq,
675 qm_info->offload_pq, qm_info->pure_ack_pq);
676 DP_VERBOSE(p_hwfn,
677 NETIF_MSG_HW,
678 "ooo_pq %d, first_vf_pq %d, num_pqs %d, num_vf_pqs %d, num_vports %d, max_phys_tcs_per_port %d\n",
679 qm_info->ooo_pq,
680 qm_info->first_vf_pq,
681 qm_info->num_pqs,
682 qm_info->num_vf_pqs,
683 qm_info->num_vports, qm_info->max_phys_tcs_per_port);
684 DP_VERBOSE(p_hwfn,
685 NETIF_MSG_HW,
686 "pf_rl_en %d, pf_wfq_en %d, vport_rl_en %d, vport_wfq_en %d, pf_wfq %d, pf_rl %d, num_pf_rls %d, pq_flags %x\n",
687 qm_info->pf_rl_en,
688 qm_info->pf_wfq_en,
689 qm_info->vport_rl_en,
690 qm_info->vport_wfq_en,
691 qm_info->pf_wfq,
692 qm_info->pf_rl,
693 qm_info->num_pf_rls, qed_get_pq_flags(p_hwfn));
694
695 /* port table */
Tomer Tayar78cea9f2017-05-23 09:41:22 +0300696 for (i = 0; i < p_hwfn->cdev->num_ports_in_engine; i++) {
Ariel Eliorb5a9ee72017-04-03 12:21:09 +0300697 port = &(qm_info->qm_port_params[i]);
698 DP_VERBOSE(p_hwfn,
699 NETIF_MSG_HW,
700 "port idx %d, active %d, active_phys_tcs %d, num_pbf_cmd_lines %d, num_btb_blocks %d, reserved %d\n",
701 i,
702 port->active,
703 port->active_phys_tcs,
704 port->num_pbf_cmd_lines,
705 port->num_btb_blocks, port->reserved);
706 }
707
708 /* vport table */
709 for (i = 0; i < qm_info->num_vports; i++) {
710 vport = &(qm_info->qm_vport_params[i]);
711 DP_VERBOSE(p_hwfn,
712 NETIF_MSG_HW,
713 "vport idx %d, vport_rl %d, wfq %d, first_tx_pq_id [ ",
714 qm_info->start_vport + i,
715 vport->vport_rl, vport->vport_wfq);
716 for (tc = 0; tc < NUM_OF_TCS; tc++)
717 DP_VERBOSE(p_hwfn,
718 NETIF_MSG_HW,
719 "%d ", vport->first_tx_pq_id[tc]);
720 DP_VERBOSE(p_hwfn, NETIF_MSG_HW, "]\n");
721 }
722
723 /* pq table */
724 for (i = 0; i < qm_info->num_pqs; i++) {
725 pq = &(qm_info->qm_pq_params[i]);
726 DP_VERBOSE(p_hwfn,
727 NETIF_MSG_HW,
728 "pq idx %d, vport_id %d, tc %d, wrr_grp %d, rl_valid %d\n",
729 qm_info->start_pq + i,
730 pq->vport_id,
731 pq->tc_id, pq->wrr_group, pq->rl_valid);
732 }
733}
734
735static void qed_init_qm_info(struct qed_hwfn *p_hwfn)
736{
737 /* reset params required for init run */
738 qed_init_qm_reset_params(p_hwfn);
739
740 /* init QM top level params */
741 qed_init_qm_params(p_hwfn);
742
743 /* init QM port params */
744 qed_init_qm_port_params(p_hwfn);
745
746 /* init QM vport params */
747 qed_init_qm_vport_params(p_hwfn);
748
749 /* init QM physical queue params */
750 qed_init_qm_pq_params(p_hwfn);
751
752 /* display all that init */
753 qed_dp_init_qm_params(p_hwfn);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200754}
755
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400756/* This function reconfigures the QM pf on the fly.
757 * For this purpose we:
758 * 1. reconfigure the QM database
759 * 2. set new values to runtime arrat
760 * 3. send an sdm_qm_cmd through the rbc interface to stop the QM
761 * 4. activate init tool in QM_PF stage
762 * 5. send an sdm_qm_cmd through rbc interface to release the QM
763 */
764int qed_qm_reconf(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
765{
766 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
767 bool b_rc;
768 int rc;
769
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400770 /* initialize qed's qm data structure */
Ariel Eliorb5a9ee72017-04-03 12:21:09 +0300771 qed_init_qm_info(p_hwfn);
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400772
773 /* stop PF's qm queues */
774 spin_lock_bh(&qm_lock);
775 b_rc = qed_send_qm_stop_cmd(p_hwfn, p_ptt, false, true,
776 qm_info->start_pq, qm_info->num_pqs);
777 spin_unlock_bh(&qm_lock);
778 if (!b_rc)
779 return -EINVAL;
780
781 /* clear the QM_PF runtime phase leftovers from previous init */
782 qed_init_clear_rt_data(p_hwfn);
783
784 /* prepare QM portion of runtime array */
Rahul Verma15582962017-04-06 15:58:29 +0300785 qed_qm_init_pf(p_hwfn, p_ptt);
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400786
787 /* activate init tool on runtime array */
788 rc = qed_init_run(p_hwfn, p_ptt, PHASE_QM_PF, p_hwfn->rel_pf_id,
789 p_hwfn->hw_info.hw_mode);
790 if (rc)
791 return rc;
792
793 /* start PF's qm queues */
794 spin_lock_bh(&qm_lock);
795 b_rc = qed_send_qm_stop_cmd(p_hwfn, p_ptt, true, true,
796 qm_info->start_pq, qm_info->num_pqs);
797 spin_unlock_bh(&qm_lock);
798 if (!b_rc)
799 return -EINVAL;
800
801 return 0;
802}
803
Ariel Eliorb5a9ee72017-04-03 12:21:09 +0300804static int qed_alloc_qm_data(struct qed_hwfn *p_hwfn)
805{
806 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
807 int rc;
808
809 rc = qed_init_qm_sanity(p_hwfn);
810 if (rc)
811 goto alloc_err;
812
813 qm_info->qm_pq_params = kzalloc(sizeof(*qm_info->qm_pq_params) *
814 qed_init_qm_get_num_pqs(p_hwfn),
815 GFP_KERNEL);
816 if (!qm_info->qm_pq_params)
817 goto alloc_err;
818
819 qm_info->qm_vport_params = kzalloc(sizeof(*qm_info->qm_vport_params) *
820 qed_init_qm_get_num_vports(p_hwfn),
821 GFP_KERNEL);
822 if (!qm_info->qm_vport_params)
823 goto alloc_err;
824
Wei Yongjun2f7878c2017-04-25 07:07:18 +0000825 qm_info->qm_port_params = kzalloc(sizeof(*qm_info->qm_port_params) *
Tomer Tayar78cea9f2017-05-23 09:41:22 +0300826 p_hwfn->cdev->num_ports_in_engine,
Ariel Eliorb5a9ee72017-04-03 12:21:09 +0300827 GFP_KERNEL);
828 if (!qm_info->qm_port_params)
829 goto alloc_err;
830
831 qm_info->wfq_data = kzalloc(sizeof(*qm_info->wfq_data) *
832 qed_init_qm_get_num_vports(p_hwfn),
833 GFP_KERNEL);
834 if (!qm_info->wfq_data)
835 goto alloc_err;
836
837 return 0;
838
839alloc_err:
840 DP_NOTICE(p_hwfn, "Failed to allocate memory for QM params\n");
841 qed_qm_info_free(p_hwfn);
842 return -ENOMEM;
843}
844
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200845int qed_resc_alloc(struct qed_dev *cdev)
846{
Ram Amranif9dc4d12017-04-03 12:21:13 +0300847 u32 rdma_tasks, excess_tasks;
Ram Amranif9dc4d12017-04-03 12:21:13 +0300848 u32 line_count;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200849 int i, rc = 0;
850
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300851 if (IS_VF(cdev))
852 return rc;
853
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200854 cdev->fw_data = kzalloc(sizeof(*cdev->fw_data), GFP_KERNEL);
855 if (!cdev->fw_data)
856 return -ENOMEM;
857
858 for_each_hwfn(cdev, i) {
859 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
Yuval Mintzdbb799c2016-06-03 14:35:35 +0300860 u32 n_eqes, num_cons;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200861
862 /* First allocate the context manager structure */
863 rc = qed_cxt_mngr_alloc(p_hwfn);
864 if (rc)
865 goto alloc_err;
866
867 /* Set the HW cid/tid numbers (in the contest manager)
868 * Must be done prior to any further computations.
869 */
Ram Amranif9dc4d12017-04-03 12:21:13 +0300870 rc = qed_cxt_set_pf_params(p_hwfn, RDMA_MAX_TIDS);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200871 if (rc)
872 goto alloc_err;
873
Ariel Eliorb5a9ee72017-04-03 12:21:09 +0300874 rc = qed_alloc_qm_data(p_hwfn);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200875 if (rc)
876 goto alloc_err;
877
Ariel Eliorb5a9ee72017-04-03 12:21:09 +0300878 /* init qm info */
879 qed_init_qm_info(p_hwfn);
880
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200881 /* Compute the ILT client partition */
Ram Amranif9dc4d12017-04-03 12:21:13 +0300882 rc = qed_cxt_cfg_ilt_compute(p_hwfn, &line_count);
883 if (rc) {
884 DP_NOTICE(p_hwfn,
885 "too many ILT lines; re-computing with less lines\n");
886 /* In case there are not enough ILT lines we reduce the
887 * number of RDMA tasks and re-compute.
888 */
889 excess_tasks =
890 qed_cxt_cfg_ilt_compute_excess(p_hwfn, line_count);
891 if (!excess_tasks)
892 goto alloc_err;
893
894 rdma_tasks = RDMA_MAX_TIDS - excess_tasks;
895 rc = qed_cxt_set_pf_params(p_hwfn, rdma_tasks);
896 if (rc)
897 goto alloc_err;
898
899 rc = qed_cxt_cfg_ilt_compute(p_hwfn, &line_count);
900 if (rc) {
901 DP_ERR(p_hwfn,
902 "failed ILT compute. Requested too many lines: %u\n",
903 line_count);
904
905 goto alloc_err;
906 }
907 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200908
909 /* CID map / ILT shadow table / T2
910 * The talbes sizes are determined by the computations above
911 */
912 rc = qed_cxt_tables_alloc(p_hwfn);
913 if (rc)
914 goto alloc_err;
915
916 /* SPQ, must follow ILT because initializes SPQ context */
917 rc = qed_spq_alloc(p_hwfn);
918 if (rc)
919 goto alloc_err;
920
921 /* SP status block allocation */
922 p_hwfn->p_dpc_ptt = qed_get_reserved_ptt(p_hwfn,
923 RESERVED_PTT_DPC);
924
925 rc = qed_int_alloc(p_hwfn, p_hwfn->p_main_ptt);
926 if (rc)
927 goto alloc_err;
928
Yuval Mintz32a47e72016-05-11 16:36:12 +0300929 rc = qed_iov_alloc(p_hwfn);
930 if (rc)
931 goto alloc_err;
932
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200933 /* EQ */
Yuval Mintzdbb799c2016-06-03 14:35:35 +0300934 n_eqes = qed_chain_get_capacity(&p_hwfn->p_spq->chain);
935 if (p_hwfn->hw_info.personality == QED_PCI_ETH_ROCE) {
936 num_cons = qed_cxt_get_proto_cid_count(p_hwfn,
937 PROTOCOLID_ROCE,
Yuval Mintz8c93bea2016-10-13 22:57:03 +0300938 NULL) * 2;
Yuval Mintzdbb799c2016-06-03 14:35:35 +0300939 n_eqes += num_cons + 2 * MAX_NUM_VFS_BB;
940 } else if (p_hwfn->hw_info.personality == QED_PCI_ISCSI) {
941 num_cons =
942 qed_cxt_get_proto_cid_count(p_hwfn,
Yuval Mintz8c93bea2016-10-13 22:57:03 +0300943 PROTOCOLID_ISCSI,
944 NULL);
Yuval Mintzdbb799c2016-06-03 14:35:35 +0300945 n_eqes += 2 * num_cons;
946 }
947
948 if (n_eqes > 0xFFFF) {
949 DP_ERR(p_hwfn,
950 "Cannot allocate 0x%x EQ elements. The maximum of a u16 chain is 0x%x\n",
951 n_eqes, 0xFFFF);
Tomer Tayar3587cb82017-05-21 12:10:56 +0300952 goto alloc_no_mem;
Dan Carpenter9b15acb2015-11-05 11:41:28 +0300953 }
Yuval Mintzdbb799c2016-06-03 14:35:35 +0300954
Tomer Tayar3587cb82017-05-21 12:10:56 +0300955 rc = qed_eq_alloc(p_hwfn, (u16) n_eqes);
956 if (rc)
957 goto alloc_err;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200958
Tomer Tayar3587cb82017-05-21 12:10:56 +0300959 rc = qed_consq_alloc(p_hwfn);
960 if (rc)
961 goto alloc_err;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200962
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300963#ifdef CONFIG_QED_LL2
964 if (p_hwfn->using_ll2) {
Tomer Tayar3587cb82017-05-21 12:10:56 +0300965 rc = qed_ll2_alloc(p_hwfn);
966 if (rc)
967 goto alloc_err;
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300968 }
969#endif
Arun Easi1e128c82017-02-15 06:28:22 -0800970
971 if (p_hwfn->hw_info.personality == QED_PCI_FCOE) {
Tomer Tayar3587cb82017-05-21 12:10:56 +0300972 rc = qed_fcoe_alloc(p_hwfn);
973 if (rc)
974 goto alloc_err;
Arun Easi1e128c82017-02-15 06:28:22 -0800975 }
976
Yuval Mintzfc831822016-12-01 00:21:06 -0800977 if (p_hwfn->hw_info.personality == QED_PCI_ISCSI) {
Tomer Tayar3587cb82017-05-21 12:10:56 +0300978 rc = qed_iscsi_alloc(p_hwfn);
979 if (rc)
980 goto alloc_err;
981 rc = qed_ooo_alloc(p_hwfn);
982 if (rc)
983 goto alloc_err;
Yuval Mintzfc831822016-12-01 00:21:06 -0800984 }
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300985
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200986 /* DMA info initialization */
987 rc = qed_dmae_info_alloc(p_hwfn);
Joe Perches2591c282016-09-04 14:24:03 -0700988 if (rc)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200989 goto alloc_err;
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400990
991 /* DCBX initialization */
992 rc = qed_dcbx_info_alloc(p_hwfn);
Joe Perches2591c282016-09-04 14:24:03 -0700993 if (rc)
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -0400994 goto alloc_err;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +0200995 }
996
997 cdev->reset_stats = kzalloc(sizeof(*cdev->reset_stats), GFP_KERNEL);
Joe Perches2591c282016-09-04 14:24:03 -0700998 if (!cdev->reset_stats)
Yuval Mintz83aeb932016-08-15 10:42:44 +0300999 goto alloc_no_mem;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001000
1001 return 0;
1002
Yuval Mintzdbb799c2016-06-03 14:35:35 +03001003alloc_no_mem:
1004 rc = -ENOMEM;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001005alloc_err:
1006 qed_resc_free(cdev);
1007 return rc;
1008}
1009
1010void qed_resc_setup(struct qed_dev *cdev)
1011{
1012 int i;
1013
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001014 if (IS_VF(cdev))
1015 return;
1016
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001017 for_each_hwfn(cdev, i) {
1018 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
1019
1020 qed_cxt_mngr_setup(p_hwfn);
1021 qed_spq_setup(p_hwfn);
Tomer Tayar3587cb82017-05-21 12:10:56 +03001022 qed_eq_setup(p_hwfn);
1023 qed_consq_setup(p_hwfn);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001024
1025 /* Read shadow of current MFW mailbox */
1026 qed_mcp_read_mb(p_hwfn, p_hwfn->p_main_ptt);
1027 memcpy(p_hwfn->mcp_info->mfw_mb_shadow,
1028 p_hwfn->mcp_info->mfw_mb_cur,
1029 p_hwfn->mcp_info->mfw_mb_length);
1030
1031 qed_int_setup(p_hwfn, p_hwfn->p_main_ptt);
Yuval Mintz32a47e72016-05-11 16:36:12 +03001032
Mintz, Yuval1ee240e2017-06-01 15:29:11 +03001033 qed_iov_setup(p_hwfn);
Yuval Mintz0a7fb112016-10-01 21:59:55 +03001034#ifdef CONFIG_QED_LL2
1035 if (p_hwfn->using_ll2)
Tomer Tayar3587cb82017-05-21 12:10:56 +03001036 qed_ll2_setup(p_hwfn);
Yuval Mintz0a7fb112016-10-01 21:59:55 +03001037#endif
Arun Easi1e128c82017-02-15 06:28:22 -08001038 if (p_hwfn->hw_info.personality == QED_PCI_FCOE)
Tomer Tayar3587cb82017-05-21 12:10:56 +03001039 qed_fcoe_setup(p_hwfn);
Arun Easi1e128c82017-02-15 06:28:22 -08001040
Yuval Mintz1d6cff42016-12-01 00:21:07 -08001041 if (p_hwfn->hw_info.personality == QED_PCI_ISCSI) {
Tomer Tayar3587cb82017-05-21 12:10:56 +03001042 qed_iscsi_setup(p_hwfn);
1043 qed_ooo_setup(p_hwfn);
Yuval Mintz1d6cff42016-12-01 00:21:07 -08001044 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001045 }
1046}
1047
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001048#define FINAL_CLEANUP_POLL_CNT (100)
1049#define FINAL_CLEANUP_POLL_TIME (10)
1050int qed_final_cleanup(struct qed_hwfn *p_hwfn,
Yuval Mintz0b55e272016-05-11 16:36:15 +03001051 struct qed_ptt *p_ptt, u16 id, bool is_vf)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001052{
1053 u32 command = 0, addr, count = FINAL_CLEANUP_POLL_CNT;
1054 int rc = -EBUSY;
1055
Yuval Mintzfc48b7a2016-02-15 13:22:35 -05001056 addr = GTT_BAR0_MAP_REG_USDM_RAM +
1057 USTORM_FLR_FINAL_ACK_OFFSET(p_hwfn->rel_pf_id);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001058
Yuval Mintz0b55e272016-05-11 16:36:15 +03001059 if (is_vf)
1060 id += 0x10;
1061
Yuval Mintzfc48b7a2016-02-15 13:22:35 -05001062 command |= X_FINAL_CLEANUP_AGG_INT <<
1063 SDM_AGG_INT_COMP_PARAMS_AGG_INT_INDEX_SHIFT;
1064 command |= 1 << SDM_AGG_INT_COMP_PARAMS_AGG_VECTOR_ENABLE_SHIFT;
1065 command |= id << SDM_AGG_INT_COMP_PARAMS_AGG_VECTOR_BIT_SHIFT;
1066 command |= SDM_COMP_TYPE_AGG_INT << SDM_OP_GEN_COMP_TYPE_SHIFT;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001067
1068 /* Make sure notification is not set before initiating final cleanup */
1069 if (REG_RD(p_hwfn, addr)) {
Yuval Mintz1a635e42016-08-15 10:42:43 +03001070 DP_NOTICE(p_hwfn,
1071 "Unexpected; Found final cleanup notification before initiating final cleanup\n");
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001072 REG_WR(p_hwfn, addr, 0);
1073 }
1074
1075 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1076 "Sending final cleanup for PFVF[%d] [Command %08x\n]",
1077 id, command);
1078
1079 qed_wr(p_hwfn, p_ptt, XSDM_REG_OPERATION_GEN, command);
1080
1081 /* Poll until completion */
1082 while (!REG_RD(p_hwfn, addr) && count--)
1083 msleep(FINAL_CLEANUP_POLL_TIME);
1084
1085 if (REG_RD(p_hwfn, addr))
1086 rc = 0;
1087 else
1088 DP_NOTICE(p_hwfn,
1089 "Failed to receive FW final cleanup notification\n");
1090
1091 /* Cleanup afterwards */
1092 REG_WR(p_hwfn, addr, 0);
1093
1094 return rc;
1095}
1096
Mintz, Yuval9c79dda2017-03-14 16:23:54 +02001097static int qed_calc_hw_mode(struct qed_hwfn *p_hwfn)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001098{
1099 int hw_mode = 0;
1100
Mintz, Yuval9c79dda2017-03-14 16:23:54 +02001101 if (QED_IS_BB_B0(p_hwfn->cdev)) {
1102 hw_mode |= 1 << MODE_BB;
1103 } else if (QED_IS_AH(p_hwfn->cdev)) {
1104 hw_mode |= 1 << MODE_K2;
1105 } else {
1106 DP_NOTICE(p_hwfn, "Unknown chip type %#x\n",
1107 p_hwfn->cdev->type);
1108 return -EINVAL;
1109 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001110
Tomer Tayar78cea9f2017-05-23 09:41:22 +03001111 switch (p_hwfn->cdev->num_ports_in_engine) {
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001112 case 1:
1113 hw_mode |= 1 << MODE_PORTS_PER_ENG_1;
1114 break;
1115 case 2:
1116 hw_mode |= 1 << MODE_PORTS_PER_ENG_2;
1117 break;
1118 case 4:
1119 hw_mode |= 1 << MODE_PORTS_PER_ENG_4;
1120 break;
1121 default:
1122 DP_NOTICE(p_hwfn, "num_ports_in_engine = %d not supported\n",
Tomer Tayar78cea9f2017-05-23 09:41:22 +03001123 p_hwfn->cdev->num_ports_in_engine);
Mintz, Yuval9c79dda2017-03-14 16:23:54 +02001124 return -EINVAL;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001125 }
1126
1127 switch (p_hwfn->cdev->mf_mode) {
Yuval Mintzfc48b7a2016-02-15 13:22:35 -05001128 case QED_MF_DEFAULT:
1129 case QED_MF_NPAR:
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001130 hw_mode |= 1 << MODE_MF_SI;
1131 break;
Yuval Mintzfc48b7a2016-02-15 13:22:35 -05001132 case QED_MF_OVLAN:
1133 hw_mode |= 1 << MODE_MF_SD;
1134 break;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001135 default:
Yuval Mintzfc48b7a2016-02-15 13:22:35 -05001136 DP_NOTICE(p_hwfn, "Unsupported MF mode, init as DEFAULT\n");
1137 hw_mode |= 1 << MODE_MF_SI;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001138 }
1139
1140 hw_mode |= 1 << MODE_ASIC;
1141
Yuval Mintz1af9dcf2016-05-26 11:01:22 +03001142 if (p_hwfn->cdev->num_hwfns > 1)
1143 hw_mode |= 1 << MODE_100G;
1144
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001145 p_hwfn->hw_info.hw_mode = hw_mode;
Yuval Mintz1af9dcf2016-05-26 11:01:22 +03001146
1147 DP_VERBOSE(p_hwfn, (NETIF_MSG_PROBE | NETIF_MSG_IFUP),
1148 "Configuring function for hw_mode: 0x%08x\n",
1149 p_hwfn->hw_info.hw_mode);
Mintz, Yuval9c79dda2017-03-14 16:23:54 +02001150
1151 return 0;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001152}
1153
1154/* Init run time data for all PFs on an engine. */
1155static void qed_init_cau_rt_data(struct qed_dev *cdev)
1156{
1157 u32 offset = CAU_REG_SB_VAR_MEMORY_RT_OFFSET;
Mintz, Yuvald0315482017-06-01 15:29:04 +03001158 int i, igu_sb_id;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001159
1160 for_each_hwfn(cdev, i) {
1161 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
1162 struct qed_igu_info *p_igu_info;
1163 struct qed_igu_block *p_block;
1164 struct cau_sb_entry sb_entry;
1165
1166 p_igu_info = p_hwfn->hw_info.p_igu_info;
1167
Mintz, Yuvald0315482017-06-01 15:29:04 +03001168 for (igu_sb_id = 0;
1169 igu_sb_id < QED_MAPPING_MEMORY_SIZE(cdev); igu_sb_id++) {
1170 p_block = &p_igu_info->entry[igu_sb_id];
1171
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001172 if (!p_block->is_pf)
1173 continue;
1174
1175 qed_init_cau_sb_entry(p_hwfn, &sb_entry,
Yuval Mintz1a635e42016-08-15 10:42:43 +03001176 p_block->function_id, 0, 0);
Mintz, Yuvald0315482017-06-01 15:29:04 +03001177 STORE_RT_REG_AGG(p_hwfn, offset + igu_sb_id * 2,
1178 sb_entry);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001179 }
1180 }
1181}
1182
Tomer Tayar60afed72017-04-06 15:58:30 +03001183static void qed_init_cache_line_size(struct qed_hwfn *p_hwfn,
1184 struct qed_ptt *p_ptt)
1185{
1186 u32 val, wr_mbs, cache_line_size;
1187
1188 val = qed_rd(p_hwfn, p_ptt, PSWRQ2_REG_WR_MBS0);
1189 switch (val) {
1190 case 0:
1191 wr_mbs = 128;
1192 break;
1193 case 1:
1194 wr_mbs = 256;
1195 break;
1196 case 2:
1197 wr_mbs = 512;
1198 break;
1199 default:
1200 DP_INFO(p_hwfn,
1201 "Unexpected value of PSWRQ2_REG_WR_MBS0 [0x%x]. Avoid configuring PGLUE_B_REG_CACHE_LINE_SIZE.\n",
1202 val);
1203 return;
1204 }
1205
1206 cache_line_size = min_t(u32, L1_CACHE_BYTES, wr_mbs);
1207 switch (cache_line_size) {
1208 case 32:
1209 val = 0;
1210 break;
1211 case 64:
1212 val = 1;
1213 break;
1214 case 128:
1215 val = 2;
1216 break;
1217 case 256:
1218 val = 3;
1219 break;
1220 default:
1221 DP_INFO(p_hwfn,
1222 "Unexpected value of cache line size [0x%x]. Avoid configuring PGLUE_B_REG_CACHE_LINE_SIZE.\n",
1223 cache_line_size);
1224 }
1225
1226 if (L1_CACHE_BYTES > wr_mbs)
1227 DP_INFO(p_hwfn,
1228 "The cache line size for padding is suboptimal for performance [OS cache line size 0x%x, wr mbs 0x%x]\n",
1229 L1_CACHE_BYTES, wr_mbs);
1230
1231 STORE_RT_REG(p_hwfn, PGLUE_REG_B_CACHE_LINE_SIZE_RT_OFFSET, val);
Mintz, Yuvalfc6575b2017-05-29 09:53:14 +03001232 if (val > 0) {
1233 STORE_RT_REG(p_hwfn, PSWRQ2_REG_DRAM_ALIGN_WR_RT_OFFSET, val);
1234 STORE_RT_REG(p_hwfn, PSWRQ2_REG_DRAM_ALIGN_RD_RT_OFFSET, val);
1235 }
Tomer Tayar60afed72017-04-06 15:58:30 +03001236}
1237
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001238static int qed_hw_init_common(struct qed_hwfn *p_hwfn,
Yuval Mintz1a635e42016-08-15 10:42:43 +03001239 struct qed_ptt *p_ptt, int hw_mode)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001240{
1241 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
1242 struct qed_qm_common_rt_init_params params;
1243 struct qed_dev *cdev = p_hwfn->cdev;
Mintz, Yuval9c79dda2017-03-14 16:23:54 +02001244 u8 vf_id, max_num_vfs;
Yuval Mintzdbb799c2016-06-03 14:35:35 +03001245 u16 num_pfs, pf_id;
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001246 u32 concrete_fid;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001247 int rc = 0;
1248
1249 qed_init_cau_rt_data(cdev);
1250
1251 /* Program GTT windows */
1252 qed_gtt_init(p_hwfn);
1253
1254 if (p_hwfn->mcp_info) {
1255 if (p_hwfn->mcp_info->func_info.bandwidth_max)
1256 qm_info->pf_rl_en = 1;
1257 if (p_hwfn->mcp_info->func_info.bandwidth_min)
1258 qm_info->pf_wfq_en = 1;
1259 }
1260
1261 memset(&params, 0, sizeof(params));
Tomer Tayar78cea9f2017-05-23 09:41:22 +03001262 params.max_ports_per_engine = p_hwfn->cdev->num_ports_in_engine;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001263 params.max_phys_tcs_per_port = qm_info->max_phys_tcs_per_port;
1264 params.pf_rl_en = qm_info->pf_rl_en;
1265 params.pf_wfq_en = qm_info->pf_wfq_en;
1266 params.vport_rl_en = qm_info->vport_rl_en;
1267 params.vport_wfq_en = qm_info->vport_wfq_en;
1268 params.port_params = qm_info->qm_port_params;
1269
1270 qed_qm_common_rt_init(p_hwfn, &params);
1271
1272 qed_cxt_hw_init_common(p_hwfn);
1273
Tomer Tayar60afed72017-04-06 15:58:30 +03001274 qed_init_cache_line_size(p_hwfn, p_ptt);
1275
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001276 rc = qed_init_run(p_hwfn, p_ptt, PHASE_ENGINE, ANY_PHASE_ID, hw_mode);
Yuval Mintz1a635e42016-08-15 10:42:43 +03001277 if (rc)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001278 return rc;
1279
1280 qed_wr(p_hwfn, p_ptt, PSWRQ2_REG_L2P_VALIDATE_VFID, 0);
1281 qed_wr(p_hwfn, p_ptt, PGLUE_B_REG_USE_CLIENTID_IN_TAG, 1);
1282
Yuval Mintzdbb799c2016-06-03 14:35:35 +03001283 if (QED_IS_BB(p_hwfn->cdev)) {
1284 num_pfs = NUM_OF_ENG_PFS(p_hwfn->cdev);
1285 for (pf_id = 0; pf_id < num_pfs; pf_id++) {
1286 qed_fid_pretend(p_hwfn, p_ptt, pf_id);
1287 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_ROCE, 0x0);
1288 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TCP, 0x0);
1289 }
1290 /* pretend to original PF */
1291 qed_fid_pretend(p_hwfn, p_ptt, p_hwfn->rel_pf_id);
1292 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001293
Mintz, Yuval9c79dda2017-03-14 16:23:54 +02001294 max_num_vfs = QED_IS_AH(cdev) ? MAX_NUM_VFS_K2 : MAX_NUM_VFS_BB;
1295 for (vf_id = 0; vf_id < max_num_vfs; vf_id++) {
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001296 concrete_fid = qed_vfid_to_concrete(p_hwfn, vf_id);
1297 qed_fid_pretend(p_hwfn, p_ptt, (u16) concrete_fid);
1298 qed_wr(p_hwfn, p_ptt, CCFC_REG_STRONG_ENABLE_VF, 0x1);
Yuval Mintz05fafbf2016-08-19 09:33:31 +03001299 qed_wr(p_hwfn, p_ptt, CCFC_REG_WEAK_ENABLE_VF, 0x0);
1300 qed_wr(p_hwfn, p_ptt, TCFC_REG_STRONG_ENABLE_VF, 0x1);
1301 qed_wr(p_hwfn, p_ptt, TCFC_REG_WEAK_ENABLE_VF, 0x0);
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001302 }
1303 /* pretend to original PF */
1304 qed_fid_pretend(p_hwfn, p_ptt, p_hwfn->rel_pf_id);
1305
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001306 return rc;
1307}
1308
Ram Amrani51ff1722016-10-01 21:59:57 +03001309static int
1310qed_hw_init_dpi_size(struct qed_hwfn *p_hwfn,
1311 struct qed_ptt *p_ptt, u32 pwm_region_size, u32 n_cpus)
1312{
Ram Amrani107392b2017-04-30 11:49:09 +03001313 u32 dpi_bit_shift, dpi_count, dpi_page_size;
Ram Amrani51ff1722016-10-01 21:59:57 +03001314 u32 min_dpis;
Ram Amrani107392b2017-04-30 11:49:09 +03001315 u32 n_wids;
Ram Amrani51ff1722016-10-01 21:59:57 +03001316
1317 /* Calculate DPI size */
Ram Amrani107392b2017-04-30 11:49:09 +03001318 n_wids = max_t(u32, QED_MIN_WIDS, n_cpus);
1319 dpi_page_size = QED_WID_SIZE * roundup_pow_of_two(n_wids);
1320 dpi_page_size = (dpi_page_size + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1);
Ram Amrani51ff1722016-10-01 21:59:57 +03001321 dpi_bit_shift = ilog2(dpi_page_size / 4096);
Ram Amrani51ff1722016-10-01 21:59:57 +03001322 dpi_count = pwm_region_size / dpi_page_size;
1323
1324 min_dpis = p_hwfn->pf_params.rdma_pf_params.min_dpis;
1325 min_dpis = max_t(u32, QED_MIN_DPIS, min_dpis);
1326
1327 p_hwfn->dpi_size = dpi_page_size;
1328 p_hwfn->dpi_count = dpi_count;
1329
1330 qed_wr(p_hwfn, p_ptt, DORQ_REG_PF_DPI_BIT_SHIFT, dpi_bit_shift);
1331
1332 if (dpi_count < min_dpis)
1333 return -EINVAL;
1334
1335 return 0;
1336}
1337
1338enum QED_ROCE_EDPM_MODE {
1339 QED_ROCE_EDPM_MODE_ENABLE = 0,
1340 QED_ROCE_EDPM_MODE_FORCE_ON = 1,
1341 QED_ROCE_EDPM_MODE_DISABLE = 2,
1342};
1343
1344static int
1345qed_hw_init_pf_doorbell_bar(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
1346{
1347 u32 pwm_regsize, norm_regsize;
1348 u32 non_pwm_conn, min_addr_reg1;
Ram Amrani20b1bd92017-04-30 11:49:10 +03001349 u32 db_bar_size, n_cpus = 1;
Ram Amrani51ff1722016-10-01 21:59:57 +03001350 u32 roce_edpm_mode;
1351 u32 pf_dems_shift;
1352 int rc = 0;
1353 u8 cond;
1354
Rahul Verma15582962017-04-06 15:58:29 +03001355 db_bar_size = qed_hw_bar_size(p_hwfn, p_ptt, BAR_ID_1);
Ram Amrani51ff1722016-10-01 21:59:57 +03001356 if (p_hwfn->cdev->num_hwfns > 1)
1357 db_bar_size /= 2;
1358
1359 /* Calculate doorbell regions */
1360 non_pwm_conn = qed_cxt_get_proto_cid_start(p_hwfn, PROTOCOLID_CORE) +
1361 qed_cxt_get_proto_cid_count(p_hwfn, PROTOCOLID_CORE,
1362 NULL) +
1363 qed_cxt_get_proto_cid_count(p_hwfn, PROTOCOLID_ETH,
1364 NULL);
Ram Amrania82dadb2017-05-09 15:07:50 +03001365 norm_regsize = roundup(QED_PF_DEMS_SIZE * non_pwm_conn, PAGE_SIZE);
Ram Amrani51ff1722016-10-01 21:59:57 +03001366 min_addr_reg1 = norm_regsize / 4096;
1367 pwm_regsize = db_bar_size - norm_regsize;
1368
1369 /* Check that the normal and PWM sizes are valid */
1370 if (db_bar_size < norm_regsize) {
1371 DP_ERR(p_hwfn->cdev,
1372 "Doorbell BAR size 0x%x is too small (normal region is 0x%0x )\n",
1373 db_bar_size, norm_regsize);
1374 return -EINVAL;
1375 }
1376
1377 if (pwm_regsize < QED_MIN_PWM_REGION) {
1378 DP_ERR(p_hwfn->cdev,
1379 "PWM region size 0x%0x is too small. Should be at least 0x%0x (Doorbell BAR size is 0x%x and normal region size is 0x%0x)\n",
1380 pwm_regsize,
1381 QED_MIN_PWM_REGION, db_bar_size, norm_regsize);
1382 return -EINVAL;
1383 }
1384
1385 /* Calculate number of DPIs */
1386 roce_edpm_mode = p_hwfn->pf_params.rdma_pf_params.roce_edpm_mode;
1387 if ((roce_edpm_mode == QED_ROCE_EDPM_MODE_ENABLE) ||
1388 ((roce_edpm_mode == QED_ROCE_EDPM_MODE_FORCE_ON))) {
1389 /* Either EDPM is mandatory, or we are attempting to allocate a
1390 * WID per CPU.
1391 */
Ram Amranic2dedf82017-02-20 22:43:33 +02001392 n_cpus = num_present_cpus();
Ram Amrani51ff1722016-10-01 21:59:57 +03001393 rc = qed_hw_init_dpi_size(p_hwfn, p_ptt, pwm_regsize, n_cpus);
1394 }
1395
1396 cond = (rc && (roce_edpm_mode == QED_ROCE_EDPM_MODE_ENABLE)) ||
1397 (roce_edpm_mode == QED_ROCE_EDPM_MODE_DISABLE);
1398 if (cond || p_hwfn->dcbx_no_edpm) {
1399 /* Either EDPM is disabled from user configuration, or it is
1400 * disabled via DCBx, or it is not mandatory and we failed to
1401 * allocated a WID per CPU.
1402 */
1403 n_cpus = 1;
1404 rc = qed_hw_init_dpi_size(p_hwfn, p_ptt, pwm_regsize, n_cpus);
1405
1406 if (cond)
1407 qed_rdma_dpm_bar(p_hwfn, p_ptt);
1408 }
1409
Ram Amrani20b1bd92017-04-30 11:49:10 +03001410 p_hwfn->wid_count = (u16) n_cpus;
1411
Ram Amrani51ff1722016-10-01 21:59:57 +03001412 DP_INFO(p_hwfn,
1413 "doorbell bar: normal_region_size=%d, pwm_region_size=%d, dpi_size=%d, dpi_count=%d, roce_edpm=%s\n",
1414 norm_regsize,
1415 pwm_regsize,
1416 p_hwfn->dpi_size,
1417 p_hwfn->dpi_count,
1418 ((p_hwfn->dcbx_no_edpm) || (p_hwfn->db_bar_no_edpm)) ?
1419 "disabled" : "enabled");
1420
1421 if (rc) {
1422 DP_ERR(p_hwfn,
1423 "Failed to allocate enough DPIs. Allocated %d but the current minimum is %d.\n",
1424 p_hwfn->dpi_count,
1425 p_hwfn->pf_params.rdma_pf_params.min_dpis);
1426 return -EINVAL;
1427 }
1428
1429 p_hwfn->dpi_start_offset = norm_regsize;
1430
1431 /* DEMS size is configured log2 of DWORDs, hence the division by 4 */
1432 pf_dems_shift = ilog2(QED_PF_DEMS_SIZE / 4);
1433 qed_wr(p_hwfn, p_ptt, DORQ_REG_PF_ICID_BIT_SHIFT_NORM, pf_dems_shift);
1434 qed_wr(p_hwfn, p_ptt, DORQ_REG_PF_MIN_ADDR_REG1, min_addr_reg1);
1435
1436 return 0;
1437}
1438
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001439static int qed_hw_init_port(struct qed_hwfn *p_hwfn,
Yuval Mintz1a635e42016-08-15 10:42:43 +03001440 struct qed_ptt *p_ptt, int hw_mode)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001441{
Mintz, Yuvalfc6575b2017-05-29 09:53:14 +03001442 int rc = 0;
1443
1444 rc = qed_init_run(p_hwfn, p_ptt, PHASE_PORT, p_hwfn->port_id, hw_mode);
1445 if (rc)
1446 return rc;
1447
1448 qed_wr(p_hwfn, p_ptt, PGLUE_B_REG_MASTER_WRITE_PAD_ENABLE, 0);
1449
1450 return 0;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001451}
1452
1453static int qed_hw_init_pf(struct qed_hwfn *p_hwfn,
1454 struct qed_ptt *p_ptt,
Chopra, Manish199684302017-04-24 10:00:44 -07001455 struct qed_tunnel_info *p_tunn,
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001456 int hw_mode,
1457 bool b_hw_start,
1458 enum qed_int_mode int_mode,
1459 bool allow_npar_tx_switch)
1460{
1461 u8 rel_pf_id = p_hwfn->rel_pf_id;
1462 int rc = 0;
1463
1464 if (p_hwfn->mcp_info) {
1465 struct qed_mcp_function_info *p_info;
1466
1467 p_info = &p_hwfn->mcp_info->func_info;
1468 if (p_info->bandwidth_min)
1469 p_hwfn->qm_info.pf_wfq = p_info->bandwidth_min;
1470
1471 /* Update rate limit once we'll actually have a link */
Manish Chopra4b01e512016-04-26 10:56:09 -04001472 p_hwfn->qm_info.pf_rl = 100000;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001473 }
1474
Rahul Verma15582962017-04-06 15:58:29 +03001475 qed_cxt_hw_init_pf(p_hwfn, p_ptt);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001476
1477 qed_int_igu_init_rt(p_hwfn);
1478
1479 /* Set VLAN in NIG if needed */
Yuval Mintz1a635e42016-08-15 10:42:43 +03001480 if (hw_mode & BIT(MODE_MF_SD)) {
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001481 DP_VERBOSE(p_hwfn, NETIF_MSG_HW, "Configuring LLH_FUNC_TAG\n");
1482 STORE_RT_REG(p_hwfn, NIG_REG_LLH_FUNC_TAG_EN_RT_OFFSET, 1);
1483 STORE_RT_REG(p_hwfn, NIG_REG_LLH_FUNC_TAG_VALUE_RT_OFFSET,
1484 p_hwfn->hw_info.ovlan);
1485 }
1486
1487 /* Enable classification by MAC if needed */
Yuval Mintz1a635e42016-08-15 10:42:43 +03001488 if (hw_mode & BIT(MODE_MF_SI)) {
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001489 DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
1490 "Configuring TAGMAC_CLS_TYPE\n");
1491 STORE_RT_REG(p_hwfn,
1492 NIG_REG_LLH_FUNC_TAGMAC_CLS_TYPE_RT_OFFSET, 1);
1493 }
1494
1495 /* Protocl Configuration */
Yuval Mintzdbb799c2016-06-03 14:35:35 +03001496 STORE_RT_REG(p_hwfn, PRS_REG_SEARCH_TCP_RT_OFFSET,
1497 (p_hwfn->hw_info.personality == QED_PCI_ISCSI) ? 1 : 0);
Arun Easi1e128c82017-02-15 06:28:22 -08001498 STORE_RT_REG(p_hwfn, PRS_REG_SEARCH_FCOE_RT_OFFSET,
1499 (p_hwfn->hw_info.personality == QED_PCI_FCOE) ? 1 : 0);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001500 STORE_RT_REG(p_hwfn, PRS_REG_SEARCH_ROCE_RT_OFFSET, 0);
1501
1502 /* Cleanup chip from previous driver if such remains exist */
Yuval Mintz0b55e272016-05-11 16:36:15 +03001503 rc = qed_final_cleanup(p_hwfn, p_ptt, rel_pf_id, false);
Yuval Mintz1a635e42016-08-15 10:42:43 +03001504 if (rc)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001505 return rc;
1506
1507 /* PF Init sequence */
1508 rc = qed_init_run(p_hwfn, p_ptt, PHASE_PF, rel_pf_id, hw_mode);
1509 if (rc)
1510 return rc;
1511
1512 /* QM_PF Init sequence (may be invoked separately e.g. for DCB) */
1513 rc = qed_init_run(p_hwfn, p_ptt, PHASE_QM_PF, rel_pf_id, hw_mode);
1514 if (rc)
1515 return rc;
1516
1517 /* Pure runtime initializations - directly to the HW */
1518 qed_int_igu_init_pure_rt(p_hwfn, p_ptt, true, true);
1519
Ram Amrani51ff1722016-10-01 21:59:57 +03001520 rc = qed_hw_init_pf_doorbell_bar(p_hwfn, p_ptt);
1521 if (rc)
1522 return rc;
1523
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001524 if (b_hw_start) {
1525 /* enable interrupts */
1526 qed_int_igu_enable(p_hwfn, p_ptt, int_mode);
1527
1528 /* send function start command */
Manish Chopra4f646752017-05-23 09:41:20 +03001529 rc = qed_sp_pf_start(p_hwfn, p_ptt, p_tunn,
1530 p_hwfn->cdev->mf_mode,
Yuval Mintz831bfb0e2016-05-11 16:36:25 +03001531 allow_npar_tx_switch);
Arun Easi1e128c82017-02-15 06:28:22 -08001532 if (rc) {
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001533 DP_NOTICE(p_hwfn, "Function start ramrod failed\n");
Arun Easi1e128c82017-02-15 06:28:22 -08001534 return rc;
1535 }
1536 if (p_hwfn->hw_info.personality == QED_PCI_FCOE) {
1537 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TAG1, BIT(2));
1538 qed_wr(p_hwfn, p_ptt,
1539 PRS_REG_PKT_LEN_STAT_TAGS_NOT_COUNTED_FIRST,
1540 0x100);
1541 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001542 }
1543 return rc;
1544}
1545
1546static int qed_change_pci_hwfn(struct qed_hwfn *p_hwfn,
1547 struct qed_ptt *p_ptt,
1548 u8 enable)
1549{
1550 u32 delay_idx = 0, val, set_val = enable ? 1 : 0;
1551
1552 /* Change PF in PXP */
1553 qed_wr(p_hwfn, p_ptt,
1554 PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, set_val);
1555
1556 /* wait until value is set - try for 1 second every 50us */
1557 for (delay_idx = 0; delay_idx < 20000; delay_idx++) {
1558 val = qed_rd(p_hwfn, p_ptt,
1559 PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
1560 if (val == set_val)
1561 break;
1562
1563 usleep_range(50, 60);
1564 }
1565
1566 if (val != set_val) {
1567 DP_NOTICE(p_hwfn,
1568 "PFID_ENABLE_MASTER wasn't changed after a second\n");
1569 return -EAGAIN;
1570 }
1571
1572 return 0;
1573}
1574
1575static void qed_reset_mb_shadow(struct qed_hwfn *p_hwfn,
1576 struct qed_ptt *p_main_ptt)
1577{
1578 /* Read shadow of current MFW mailbox */
1579 qed_mcp_read_mb(p_hwfn, p_main_ptt);
1580 memcpy(p_hwfn->mcp_info->mfw_mb_shadow,
Yuval Mintz1a635e42016-08-15 10:42:43 +03001581 p_hwfn->mcp_info->mfw_mb_cur, p_hwfn->mcp_info->mfw_mb_length);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001582}
1583
Tomer Tayar5d24bcf2017-03-28 15:12:52 +03001584static void
1585qed_fill_load_req_params(struct qed_load_req_params *p_load_req,
1586 struct qed_drv_load_params *p_drv_load)
1587{
1588 memset(p_load_req, 0, sizeof(*p_load_req));
1589
1590 p_load_req->drv_role = p_drv_load->is_crash_kernel ?
1591 QED_DRV_ROLE_KDUMP : QED_DRV_ROLE_OS;
1592 p_load_req->timeout_val = p_drv_load->mfw_timeout_val;
1593 p_load_req->avoid_eng_reset = p_drv_load->avoid_eng_reset;
1594 p_load_req->override_force_load = p_drv_load->override_force_load;
1595}
1596
Chopra, Manisheaf3c0c2017-04-24 10:00:49 -07001597static int qed_vf_start(struct qed_hwfn *p_hwfn,
1598 struct qed_hw_init_params *p_params)
1599{
1600 if (p_params->p_tunn) {
1601 qed_vf_set_vf_start_tunn_update_param(p_params->p_tunn);
1602 qed_vf_pf_tunnel_param_update(p_hwfn, p_params->p_tunn);
1603 }
1604
1605 p_hwfn->b_int_enabled = 1;
1606
1607 return 0;
1608}
1609
Mintz, Yuvalc0c2d0b2017-03-28 15:12:51 +03001610int qed_hw_init(struct qed_dev *cdev, struct qed_hw_init_params *p_params)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001611{
Tomer Tayar5d24bcf2017-03-28 15:12:52 +03001612 struct qed_load_req_params load_req_params;
Sudarsana Kalluru0fefbfb2016-10-31 07:14:21 +02001613 u32 load_code, param, drv_mb_param;
1614 bool b_default_mtu = true;
1615 struct qed_hwfn *p_hwfn;
1616 int rc = 0, mfw_rc, i;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001617
Mintz, Yuvalc0c2d0b2017-03-28 15:12:51 +03001618 if ((p_params->int_mode == QED_INT_MODE_MSI) && (cdev->num_hwfns > 1)) {
Sudarsana Reddy Kallurubb13ace2016-05-26 11:01:23 +03001619 DP_NOTICE(cdev, "MSI mode is not supported for CMT devices\n");
1620 return -EINVAL;
1621 }
1622
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001623 if (IS_PF(cdev)) {
Mintz, Yuvalc0c2d0b2017-03-28 15:12:51 +03001624 rc = qed_init_fw_data(cdev, p_params->bin_fw_data);
Yuval Mintz1a635e42016-08-15 10:42:43 +03001625 if (rc)
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001626 return rc;
1627 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001628
1629 for_each_hwfn(cdev, i) {
1630 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
1631
Sudarsana Kalluru0fefbfb2016-10-31 07:14:21 +02001632 /* If management didn't provide a default, set one of our own */
1633 if (!p_hwfn->hw_info.mtu) {
1634 p_hwfn->hw_info.mtu = 1500;
1635 b_default_mtu = false;
1636 }
1637
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001638 if (IS_VF(cdev)) {
Chopra, Manisheaf3c0c2017-04-24 10:00:49 -07001639 qed_vf_start(p_hwfn, p_params);
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001640 continue;
1641 }
1642
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001643 /* Enable DMAE in PXP */
1644 rc = qed_change_pci_hwfn(p_hwfn, p_hwfn->p_main_ptt, true);
1645
Mintz, Yuval9c79dda2017-03-14 16:23:54 +02001646 rc = qed_calc_hw_mode(p_hwfn);
1647 if (rc)
1648 return rc;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001649
Tomer Tayar5d24bcf2017-03-28 15:12:52 +03001650 qed_fill_load_req_params(&load_req_params,
1651 p_params->p_drv_load_params);
1652 rc = qed_mcp_load_req(p_hwfn, p_hwfn->p_main_ptt,
1653 &load_req_params);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001654 if (rc) {
Tomer Tayar5d24bcf2017-03-28 15:12:52 +03001655 DP_NOTICE(p_hwfn, "Failed sending a LOAD_REQ command\n");
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001656 return rc;
1657 }
1658
Tomer Tayar5d24bcf2017-03-28 15:12:52 +03001659 load_code = load_req_params.load_code;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001660 DP_VERBOSE(p_hwfn, QED_MSG_SP,
Tomer Tayar5d24bcf2017-03-28 15:12:52 +03001661 "Load request was sent. Load code: 0x%x\n",
1662 load_code);
1663
1664 qed_reset_mb_shadow(p_hwfn, p_hwfn->p_main_ptt);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001665
1666 p_hwfn->first_on_engine = (load_code ==
1667 FW_MSG_CODE_DRV_LOAD_ENGINE);
1668
1669 switch (load_code) {
1670 case FW_MSG_CODE_DRV_LOAD_ENGINE:
1671 rc = qed_hw_init_common(p_hwfn, p_hwfn->p_main_ptt,
1672 p_hwfn->hw_info.hw_mode);
1673 if (rc)
1674 break;
1675 /* Fall into */
1676 case FW_MSG_CODE_DRV_LOAD_PORT:
1677 rc = qed_hw_init_port(p_hwfn, p_hwfn->p_main_ptt,
1678 p_hwfn->hw_info.hw_mode);
1679 if (rc)
1680 break;
1681
1682 /* Fall into */
1683 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
1684 rc = qed_hw_init_pf(p_hwfn, p_hwfn->p_main_ptt,
Mintz, Yuvalc0c2d0b2017-03-28 15:12:51 +03001685 p_params->p_tunn,
1686 p_hwfn->hw_info.hw_mode,
1687 p_params->b_hw_start,
1688 p_params->int_mode,
1689 p_params->allow_npar_tx_switch);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001690 break;
1691 default:
Mintz, Yuvalc0c2d0b2017-03-28 15:12:51 +03001692 DP_NOTICE(p_hwfn,
1693 "Unexpected load code [0x%08x]", load_code);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001694 rc = -EINVAL;
1695 break;
1696 }
1697
1698 if (rc)
1699 DP_NOTICE(p_hwfn,
1700 "init phase failed for loadcode 0x%x (rc %d)\n",
1701 load_code, rc);
1702
1703 /* ACK mfw regardless of success or failure of initialization */
1704 mfw_rc = qed_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
1705 DRV_MSG_CODE_LOAD_DONE,
1706 0, &load_code, &param);
1707 if (rc)
1708 return rc;
1709 if (mfw_rc) {
1710 DP_NOTICE(p_hwfn, "Failed sending LOAD_DONE command\n");
1711 return mfw_rc;
1712 }
1713
Tomer Tayarfc561c82017-05-23 09:41:21 +03001714 /* Check if there is a DID mismatch between nvm-cfg/efuse */
1715 if (param & FW_MB_PARAM_LOAD_DONE_DID_EFUSE_ERROR)
1716 DP_NOTICE(p_hwfn,
1717 "warning: device configuration is not supported on this board type. The device may not function as expected.\n");
1718
Sudarsana Reddy Kalluru39651ab2016-05-17 06:44:26 -04001719 /* send DCBX attention request command */
1720 DP_VERBOSE(p_hwfn,
1721 QED_MSG_DCB,
1722 "sending phony dcbx set command to trigger DCBx attention handling\n");
1723 mfw_rc = qed_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
1724 DRV_MSG_CODE_SET_DCBX,
1725 1 << DRV_MB_PARAM_DCBX_NOTIFY_SHIFT,
1726 &load_code, &param);
1727 if (mfw_rc) {
1728 DP_NOTICE(p_hwfn,
1729 "Failed to send DCBX attention request\n");
1730 return mfw_rc;
1731 }
1732
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001733 p_hwfn->hw_init_done = true;
1734 }
1735
Sudarsana Kalluru0fefbfb2016-10-31 07:14:21 +02001736 if (IS_PF(cdev)) {
1737 p_hwfn = QED_LEADING_HWFN(cdev);
Tomer Tayar5d24bcf2017-03-28 15:12:52 +03001738 drv_mb_param = STORM_FW_VERSION;
Sudarsana Kalluru0fefbfb2016-10-31 07:14:21 +02001739 rc = qed_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
1740 DRV_MSG_CODE_OV_UPDATE_STORM_FW_VER,
1741 drv_mb_param, &load_code, &param);
1742 if (rc)
1743 DP_INFO(p_hwfn, "Failed to update firmware version\n");
1744
1745 if (!b_default_mtu) {
1746 rc = qed_mcp_ov_update_mtu(p_hwfn, p_hwfn->p_main_ptt,
1747 p_hwfn->hw_info.mtu);
1748 if (rc)
1749 DP_INFO(p_hwfn,
1750 "Failed to update default mtu\n");
1751 }
1752
1753 rc = qed_mcp_ov_update_driver_state(p_hwfn,
1754 p_hwfn->p_main_ptt,
1755 QED_OV_DRIVER_STATE_DISABLED);
1756 if (rc)
1757 DP_INFO(p_hwfn, "Failed to update driver state\n");
1758
1759 rc = qed_mcp_ov_update_eswitch(p_hwfn, p_hwfn->p_main_ptt,
1760 QED_OV_ESWITCH_VEB);
1761 if (rc)
1762 DP_INFO(p_hwfn, "Failed to update eswitch mode\n");
1763 }
1764
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001765 return 0;
1766}
1767
1768#define QED_HW_STOP_RETRY_LIMIT (10)
Yuval Mintz1a635e42016-08-15 10:42:43 +03001769static void qed_hw_timers_stop(struct qed_dev *cdev,
1770 struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
Yuval Mintz8c925c42016-03-02 20:26:03 +02001771{
1772 int i;
1773
1774 /* close timers */
1775 qed_wr(p_hwfn, p_ptt, TM_REG_PF_ENABLE_CONN, 0x0);
1776 qed_wr(p_hwfn, p_ptt, TM_REG_PF_ENABLE_TASK, 0x0);
1777
1778 for (i = 0; i < QED_HW_STOP_RETRY_LIMIT; i++) {
1779 if ((!qed_rd(p_hwfn, p_ptt,
1780 TM_REG_PF_SCAN_ACTIVE_CONN)) &&
Yuval Mintz1a635e42016-08-15 10:42:43 +03001781 (!qed_rd(p_hwfn, p_ptt, TM_REG_PF_SCAN_ACTIVE_TASK)))
Yuval Mintz8c925c42016-03-02 20:26:03 +02001782 break;
1783
1784 /* Dependent on number of connection/tasks, possibly
1785 * 1ms sleep is required between polls
1786 */
1787 usleep_range(1000, 2000);
1788 }
1789
1790 if (i < QED_HW_STOP_RETRY_LIMIT)
1791 return;
1792
1793 DP_NOTICE(p_hwfn,
1794 "Timers linear scans are not over [Connection %02x Tasks %02x]\n",
1795 (u8)qed_rd(p_hwfn, p_ptt, TM_REG_PF_SCAN_ACTIVE_CONN),
1796 (u8)qed_rd(p_hwfn, p_ptt, TM_REG_PF_SCAN_ACTIVE_TASK));
1797}
1798
1799void qed_hw_timers_stop_all(struct qed_dev *cdev)
1800{
1801 int j;
1802
1803 for_each_hwfn(cdev, j) {
1804 struct qed_hwfn *p_hwfn = &cdev->hwfns[j];
1805 struct qed_ptt *p_ptt = p_hwfn->p_main_ptt;
1806
1807 qed_hw_timers_stop(cdev, p_hwfn, p_ptt);
1808 }
1809}
1810
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001811int qed_hw_stop(struct qed_dev *cdev)
1812{
Tomer Tayar12263372017-03-28 15:12:50 +03001813 struct qed_hwfn *p_hwfn;
1814 struct qed_ptt *p_ptt;
1815 int rc, rc2 = 0;
Yuval Mintz8c925c42016-03-02 20:26:03 +02001816 int j;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001817
1818 for_each_hwfn(cdev, j) {
Tomer Tayar12263372017-03-28 15:12:50 +03001819 p_hwfn = &cdev->hwfns[j];
1820 p_ptt = p_hwfn->p_main_ptt;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001821
1822 DP_VERBOSE(p_hwfn, NETIF_MSG_IFDOWN, "Stopping hw/fw\n");
1823
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001824 if (IS_VF(cdev)) {
Yuval Mintz0b55e272016-05-11 16:36:15 +03001825 qed_vf_pf_int_cleanup(p_hwfn);
Tomer Tayar12263372017-03-28 15:12:50 +03001826 rc = qed_vf_pf_reset(p_hwfn);
1827 if (rc) {
1828 DP_NOTICE(p_hwfn,
1829 "qed_vf_pf_reset failed. rc = %d.\n",
1830 rc);
1831 rc2 = -EINVAL;
1832 }
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001833 continue;
1834 }
1835
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001836 /* mark the hw as uninitialized... */
1837 p_hwfn->hw_init_done = false;
1838
Tomer Tayar12263372017-03-28 15:12:50 +03001839 /* Send unload command to MCP */
1840 rc = qed_mcp_unload_req(p_hwfn, p_ptt);
1841 if (rc) {
Yuval Mintz8c925c42016-03-02 20:26:03 +02001842 DP_NOTICE(p_hwfn,
Tomer Tayar12263372017-03-28 15:12:50 +03001843 "Failed sending a UNLOAD_REQ command. rc = %d.\n",
1844 rc);
1845 rc2 = -EINVAL;
1846 }
1847
1848 qed_slowpath_irq_sync(p_hwfn);
1849
1850 /* After this point no MFW attentions are expected, e.g. prevent
1851 * race between pf stop and dcbx pf update.
1852 */
1853 rc = qed_sp_pf_stop(p_hwfn);
1854 if (rc) {
1855 DP_NOTICE(p_hwfn,
1856 "Failed to close PF against FW [rc = %d]. Continue to stop HW to prevent illegal host access by the device.\n",
1857 rc);
1858 rc2 = -EINVAL;
1859 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001860
1861 qed_wr(p_hwfn, p_ptt,
1862 NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF, 0x1);
1863
1864 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TCP, 0x0);
1865 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_UDP, 0x0);
1866 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_FCOE, 0x0);
1867 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_ROCE, 0x0);
1868 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_OPENFLOW, 0x0);
1869
Yuval Mintz8c925c42016-03-02 20:26:03 +02001870 qed_hw_timers_stop(cdev, p_hwfn, p_ptt);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001871
1872 /* Disable Attention Generation */
1873 qed_int_igu_disable_int(p_hwfn, p_ptt);
1874
1875 qed_wr(p_hwfn, p_ptt, IGU_REG_LEADING_EDGE_LATCH, 0);
1876 qed_wr(p_hwfn, p_ptt, IGU_REG_TRAILING_EDGE_LATCH, 0);
1877
1878 qed_int_igu_init_pure_rt(p_hwfn, p_ptt, false, true);
1879
1880 /* Need to wait 1ms to guarantee SBs are cleared */
1881 usleep_range(1000, 2000);
Tomer Tayar12263372017-03-28 15:12:50 +03001882
1883 /* Disable PF in HW blocks */
1884 qed_wr(p_hwfn, p_ptt, DORQ_REG_PF_DB_ENABLE, 0);
1885 qed_wr(p_hwfn, p_ptt, QM_REG_PF_EN, 0);
1886
1887 qed_mcp_unload_done(p_hwfn, p_ptt);
1888 if (rc) {
1889 DP_NOTICE(p_hwfn,
1890 "Failed sending a UNLOAD_DONE command. rc = %d.\n",
1891 rc);
1892 rc2 = -EINVAL;
1893 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001894 }
1895
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001896 if (IS_PF(cdev)) {
Tomer Tayar12263372017-03-28 15:12:50 +03001897 p_hwfn = QED_LEADING_HWFN(cdev);
1898 p_ptt = QED_LEADING_HWFN(cdev)->p_main_ptt;
1899
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001900 /* Disable DMAE in PXP - in CMT, this should only be done for
1901 * first hw-function, and only after all transactions have
1902 * stopped for all active hw-functions.
1903 */
Tomer Tayar12263372017-03-28 15:12:50 +03001904 rc = qed_change_pci_hwfn(p_hwfn, p_ptt, false);
1905 if (rc) {
1906 DP_NOTICE(p_hwfn,
1907 "qed_change_pci_hwfn failed. rc = %d.\n", rc);
1908 rc2 = -EINVAL;
1909 }
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03001910 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001911
Tomer Tayar12263372017-03-28 15:12:50 +03001912 return rc2;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001913}
1914
Rahul Verma15582962017-04-06 15:58:29 +03001915int qed_hw_stop_fastpath(struct qed_dev *cdev)
Manish Chopracee4d262015-10-26 11:02:28 +02001916{
Yuval Mintz8c925c42016-03-02 20:26:03 +02001917 int j;
Manish Chopracee4d262015-10-26 11:02:28 +02001918
1919 for_each_hwfn(cdev, j) {
1920 struct qed_hwfn *p_hwfn = &cdev->hwfns[j];
Rahul Verma15582962017-04-06 15:58:29 +03001921 struct qed_ptt *p_ptt;
Yuval Mintzdacd88d2016-05-11 16:36:16 +03001922
1923 if (IS_VF(cdev)) {
1924 qed_vf_pf_int_cleanup(p_hwfn);
1925 continue;
1926 }
Rahul Verma15582962017-04-06 15:58:29 +03001927 p_ptt = qed_ptt_acquire(p_hwfn);
1928 if (!p_ptt)
1929 return -EAGAIN;
Manish Chopracee4d262015-10-26 11:02:28 +02001930
1931 DP_VERBOSE(p_hwfn,
Yuval Mintz1a635e42016-08-15 10:42:43 +03001932 NETIF_MSG_IFDOWN, "Shutting down the fastpath\n");
Manish Chopracee4d262015-10-26 11:02:28 +02001933
1934 qed_wr(p_hwfn, p_ptt,
1935 NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF, 0x1);
1936
1937 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TCP, 0x0);
1938 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_UDP, 0x0);
1939 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_FCOE, 0x0);
1940 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_ROCE, 0x0);
1941 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_OPENFLOW, 0x0);
1942
Manish Chopracee4d262015-10-26 11:02:28 +02001943 qed_int_igu_init_pure_rt(p_hwfn, p_ptt, false, false);
1944
1945 /* Need to wait 1ms to guarantee SBs are cleared */
1946 usleep_range(1000, 2000);
Rahul Verma15582962017-04-06 15:58:29 +03001947 qed_ptt_release(p_hwfn, p_ptt);
Manish Chopracee4d262015-10-26 11:02:28 +02001948 }
Rahul Verma15582962017-04-06 15:58:29 +03001949
1950 return 0;
Manish Chopracee4d262015-10-26 11:02:28 +02001951}
1952
Rahul Verma15582962017-04-06 15:58:29 +03001953int qed_hw_start_fastpath(struct qed_hwfn *p_hwfn)
Manish Chopracee4d262015-10-26 11:02:28 +02001954{
Rahul Verma15582962017-04-06 15:58:29 +03001955 struct qed_ptt *p_ptt;
1956
Yuval Mintzdacd88d2016-05-11 16:36:16 +03001957 if (IS_VF(p_hwfn->cdev))
Rahul Verma15582962017-04-06 15:58:29 +03001958 return 0;
1959
1960 p_ptt = qed_ptt_acquire(p_hwfn);
1961 if (!p_ptt)
1962 return -EAGAIN;
Yuval Mintzdacd88d2016-05-11 16:36:16 +03001963
Michal Kalderonf855df22017-05-23 09:41:25 +03001964 /* If roce info is allocated it means roce is initialized and should
1965 * be enabled in searcher.
1966 */
1967 if (p_hwfn->p_rdma_info &&
1968 p_hwfn->b_rdma_enabled_in_prs)
1969 qed_wr(p_hwfn, p_ptt, p_hwfn->rdma_prs_search_reg, 0x1);
1970
Manish Chopracee4d262015-10-26 11:02:28 +02001971 /* Re-open incoming traffic */
Rahul Verma15582962017-04-06 15:58:29 +03001972 qed_wr(p_hwfn, p_ptt, NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF, 0x0);
1973 qed_ptt_release(p_hwfn, p_ptt);
1974
1975 return 0;
Manish Chopracee4d262015-10-26 11:02:28 +02001976}
1977
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001978/* Free hwfn memory and resources acquired in hw_hwfn_prepare */
1979static void qed_hw_hwfn_free(struct qed_hwfn *p_hwfn)
1980{
1981 qed_ptt_pool_free(p_hwfn);
1982 kfree(p_hwfn->hw_info.p_igu_info);
Tomer Tayar3587cb82017-05-21 12:10:56 +03001983 p_hwfn->hw_info.p_igu_info = NULL;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001984}
1985
1986/* Setup bar access */
Yuval Mintz12e09c62016-03-02 20:26:01 +02001987static void qed_hw_hwfn_prepare(struct qed_hwfn *p_hwfn)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001988{
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02001989 /* clear indirect access */
Mintz, Yuval9c79dda2017-03-14 16:23:54 +02001990 if (QED_IS_AH(p_hwfn->cdev)) {
1991 qed_wr(p_hwfn, p_hwfn->p_main_ptt,
1992 PGLUE_B_REG_PGL_ADDR_E8_F0_K2, 0);
1993 qed_wr(p_hwfn, p_hwfn->p_main_ptt,
1994 PGLUE_B_REG_PGL_ADDR_EC_F0_K2, 0);
1995 qed_wr(p_hwfn, p_hwfn->p_main_ptt,
1996 PGLUE_B_REG_PGL_ADDR_F0_F0_K2, 0);
1997 qed_wr(p_hwfn, p_hwfn->p_main_ptt,
1998 PGLUE_B_REG_PGL_ADDR_F4_F0_K2, 0);
1999 } else {
2000 qed_wr(p_hwfn, p_hwfn->p_main_ptt,
2001 PGLUE_B_REG_PGL_ADDR_88_F0_BB, 0);
2002 qed_wr(p_hwfn, p_hwfn->p_main_ptt,
2003 PGLUE_B_REG_PGL_ADDR_8C_F0_BB, 0);
2004 qed_wr(p_hwfn, p_hwfn->p_main_ptt,
2005 PGLUE_B_REG_PGL_ADDR_90_F0_BB, 0);
2006 qed_wr(p_hwfn, p_hwfn->p_main_ptt,
2007 PGLUE_B_REG_PGL_ADDR_94_F0_BB, 0);
2008 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002009
2010 /* Clean Previous errors if such exist */
2011 qed_wr(p_hwfn, p_hwfn->p_main_ptt,
Yuval Mintz1a635e42016-08-15 10:42:43 +03002012 PGLUE_B_REG_WAS_ERROR_PF_31_0_CLR, 1 << p_hwfn->abs_pf_id);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002013
2014 /* enable internal target-read */
2015 qed_wr(p_hwfn, p_hwfn->p_main_ptt,
2016 PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002017}
2018
2019static void get_function_id(struct qed_hwfn *p_hwfn)
2020{
2021 /* ME Register */
Yuval Mintz1a635e42016-08-15 10:42:43 +03002022 p_hwfn->hw_info.opaque_fid = (u16) REG_RD(p_hwfn,
2023 PXP_PF_ME_OPAQUE_ADDR);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002024
2025 p_hwfn->hw_info.concrete_fid = REG_RD(p_hwfn, PXP_PF_ME_CONCRETE_ADDR);
2026
2027 p_hwfn->abs_pf_id = (p_hwfn->hw_info.concrete_fid >> 16) & 0xf;
2028 p_hwfn->rel_pf_id = GET_FIELD(p_hwfn->hw_info.concrete_fid,
2029 PXP_CONCRETE_FID_PFID);
2030 p_hwfn->port_id = GET_FIELD(p_hwfn->hw_info.concrete_fid,
2031 PXP_CONCRETE_FID_PORT);
Yuval Mintz525ef5c2016-08-15 10:42:45 +03002032
2033 DP_VERBOSE(p_hwfn, NETIF_MSG_PROBE,
2034 "Read ME register: Concrete 0x%08x Opaque 0x%04x\n",
2035 p_hwfn->hw_info.concrete_fid, p_hwfn->hw_info.opaque_fid);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002036}
2037
Yuval Mintz25c089d2015-10-26 11:02:26 +02002038static void qed_hw_set_feat(struct qed_hwfn *p_hwfn)
2039{
2040 u32 *feat_num = p_hwfn->hw_info.feat_num;
Mintz, Yuvalebbdcc62017-06-01 15:29:10 +03002041 struct qed_sb_cnt_info sb_cnt;
Mintz, Yuval810bb1f2017-03-23 15:50:19 +02002042 u32 non_l2_sbs = 0;
Yuval Mintz25c089d2015-10-26 11:02:26 +02002043
Mintz, Yuvalebbdcc62017-06-01 15:29:10 +03002044 memset(&sb_cnt, 0, sizeof(sb_cnt));
2045 qed_int_get_num_sbs(p_hwfn, &sb_cnt);
2046
Yuval Mintz0189efb2016-10-13 22:57:02 +03002047 if (IS_ENABLED(CONFIG_QED_RDMA) &&
2048 p_hwfn->hw_info.personality == QED_PCI_ETH_ROCE) {
2049 /* Roce CNQ each requires: 1 status block + 1 CNQ. We divide
2050 * the status blocks equally between L2 / RoCE but with
2051 * consideration as to how many l2 queues / cnqs we have.
2052 */
Ram Amrani51ff1722016-10-01 21:59:57 +03002053 feat_num[QED_RDMA_CNQ] =
Mintz, Yuvalebbdcc62017-06-01 15:29:10 +03002054 min_t(u32, sb_cnt.cnt / 2,
Ram Amrani51ff1722016-10-01 21:59:57 +03002055 RESC_NUM(p_hwfn, QED_RDMA_CNQ_RAM));
Mintz, Yuval810bb1f2017-03-23 15:50:19 +02002056
2057 non_l2_sbs = feat_num[QED_RDMA_CNQ];
Ram Amrani51ff1722016-10-01 21:59:57 +03002058 }
Yuval Mintz0189efb2016-10-13 22:57:02 +03002059
Mintz, Yuvaldec26532017-03-23 15:50:20 +02002060 if (p_hwfn->hw_info.personality == QED_PCI_ETH_ROCE ||
2061 p_hwfn->hw_info.personality == QED_PCI_ETH) {
2062 /* Start by allocating VF queues, then PF's */
Mintz, Yuvaldec26532017-03-23 15:50:20 +02002063 feat_num[QED_VF_L2_QUE] = min_t(u32,
2064 RESC_NUM(p_hwfn, QED_L2_QUEUE),
Mintz, Yuvalebbdcc62017-06-01 15:29:10 +03002065 sb_cnt.iov_cnt);
Mintz, Yuvaldec26532017-03-23 15:50:20 +02002066 feat_num[QED_PF_L2_QUE] = min_t(u32,
Mintz, Yuvalebbdcc62017-06-01 15:29:10 +03002067 sb_cnt.cnt - non_l2_sbs,
Mintz, Yuvaldec26532017-03-23 15:50:20 +02002068 RESC_NUM(p_hwfn,
2069 QED_L2_QUEUE) -
2070 FEAT_NUM(p_hwfn,
2071 QED_VF_L2_QUE));
2072 }
Mintz, Yuval5a1f9652016-10-31 07:14:26 +02002073
Mintz, Yuval08737a32017-04-06 15:58:33 +03002074 if (p_hwfn->hw_info.personality == QED_PCI_ISCSI)
Mintz, Yuvalebbdcc62017-06-01 15:29:10 +03002075 feat_num[QED_ISCSI_CQ] = min_t(u32, sb_cnt.cnt,
Mintz, Yuval08737a32017-04-06 15:58:33 +03002076 RESC_NUM(p_hwfn,
2077 QED_CMDQS_CQS));
Mintz, Yuval5a1f9652016-10-31 07:14:26 +02002078 DP_VERBOSE(p_hwfn,
2079 NETIF_MSG_PROBE,
Mintz, Yuval08737a32017-04-06 15:58:33 +03002080 "#PF_L2_QUEUES=%d VF_L2_QUEUES=%d #ROCE_CNQ=%d ISCSI_CQ=%d #SBS=%d\n",
Mintz, Yuval5a1f9652016-10-31 07:14:26 +02002081 (int)FEAT_NUM(p_hwfn, QED_PF_L2_QUE),
2082 (int)FEAT_NUM(p_hwfn, QED_VF_L2_QUE),
2083 (int)FEAT_NUM(p_hwfn, QED_RDMA_CNQ),
Mintz, Yuval08737a32017-04-06 15:58:33 +03002084 (int)FEAT_NUM(p_hwfn, QED_ISCSI_CQ),
Mintz, Yuvalebbdcc62017-06-01 15:29:10 +03002085 (int)sb_cnt.cnt);
Yuval Mintz25c089d2015-10-26 11:02:26 +02002086}
2087
Tomer Tayar9c8517c2017-03-28 15:12:55 +03002088const char *qed_hw_get_resc_name(enum qed_resources res_id)
Tomer Tayar2edbff82016-10-31 07:14:27 +02002089{
2090 switch (res_id) {
Tomer Tayar2edbff82016-10-31 07:14:27 +02002091 case QED_L2_QUEUE:
2092 return "L2_QUEUE";
2093 case QED_VPORT:
2094 return "VPORT";
2095 case QED_RSS_ENG:
2096 return "RSS_ENG";
2097 case QED_PQ:
2098 return "PQ";
2099 case QED_RL:
2100 return "RL";
2101 case QED_MAC:
2102 return "MAC";
2103 case QED_VLAN:
2104 return "VLAN";
2105 case QED_RDMA_CNQ_RAM:
2106 return "RDMA_CNQ_RAM";
2107 case QED_ILT:
2108 return "ILT";
2109 case QED_LL2_QUEUE:
2110 return "LL2_QUEUE";
2111 case QED_CMDQS_CQS:
2112 return "CMDQS_CQS";
2113 case QED_RDMA_STATS_QUEUE:
2114 return "RDMA_STATS_QUEUE";
Tomer Tayar9c8517c2017-03-28 15:12:55 +03002115 case QED_BDQ:
2116 return "BDQ";
2117 case QED_SB:
2118 return "SB";
Tomer Tayar2edbff82016-10-31 07:14:27 +02002119 default:
2120 return "UNKNOWN_RESOURCE";
2121 }
2122}
2123
Tomer Tayar9c8517c2017-03-28 15:12:55 +03002124static int
2125__qed_hw_set_soft_resc_size(struct qed_hwfn *p_hwfn,
2126 struct qed_ptt *p_ptt,
2127 enum qed_resources res_id,
2128 u32 resc_max_val, u32 *p_mcp_resp)
Tomer Tayar2edbff82016-10-31 07:14:27 +02002129{
Tomer Tayar9c8517c2017-03-28 15:12:55 +03002130 int rc;
2131
2132 rc = qed_mcp_set_resc_max_val(p_hwfn, p_ptt, res_id,
2133 resc_max_val, p_mcp_resp);
2134 if (rc) {
2135 DP_NOTICE(p_hwfn,
2136 "MFW response failure for a max value setting of resource %d [%s]\n",
2137 res_id, qed_hw_get_resc_name(res_id));
2138 return rc;
2139 }
2140
2141 if (*p_mcp_resp != FW_MSG_CODE_RESOURCE_ALLOC_OK)
2142 DP_INFO(p_hwfn,
2143 "Failed to set the max value of resource %d [%s]. mcp_resp = 0x%08x.\n",
2144 res_id, qed_hw_get_resc_name(res_id), *p_mcp_resp);
2145
2146 return 0;
2147}
2148
2149static int
2150qed_hw_set_soft_resc_size(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
2151{
2152 bool b_ah = QED_IS_AH(p_hwfn->cdev);
2153 u32 resc_max_val, mcp_resp;
2154 u8 res_id;
2155 int rc;
2156
2157 for (res_id = 0; res_id < QED_MAX_RESC; res_id++) {
2158 switch (res_id) {
2159 case QED_LL2_QUEUE:
2160 resc_max_val = MAX_NUM_LL2_RX_QUEUES;
2161 break;
2162 case QED_RDMA_CNQ_RAM:
2163 /* No need for a case for QED_CMDQS_CQS since
2164 * CNQ/CMDQS are the same resource.
2165 */
2166 resc_max_val = NUM_OF_CMDQS_CQS;
2167 break;
2168 case QED_RDMA_STATS_QUEUE:
2169 resc_max_val = b_ah ? RDMA_NUM_STATISTIC_COUNTERS_K2
2170 : RDMA_NUM_STATISTIC_COUNTERS_BB;
2171 break;
2172 case QED_BDQ:
2173 resc_max_val = BDQ_NUM_RESOURCES;
2174 break;
2175 default:
2176 continue;
2177 }
2178
2179 rc = __qed_hw_set_soft_resc_size(p_hwfn, p_ptt, res_id,
2180 resc_max_val, &mcp_resp);
2181 if (rc)
2182 return rc;
2183
2184 /* There's no point to continue to the next resource if the
2185 * command is not supported by the MFW.
2186 * We do continue if the command is supported but the resource
2187 * is unknown to the MFW. Such a resource will be later
2188 * configured with the default allocation values.
2189 */
2190 if (mcp_resp == FW_MSG_CODE_UNSUPPORTED)
2191 return -EINVAL;
2192 }
2193
2194 return 0;
2195}
2196
2197static
2198int qed_hw_get_dflt_resc(struct qed_hwfn *p_hwfn,
2199 enum qed_resources res_id,
2200 u32 *p_resc_num, u32 *p_resc_start)
2201{
2202 u8 num_funcs = p_hwfn->num_funcs_on_engine;
2203 bool b_ah = QED_IS_AH(p_hwfn->cdev);
Tomer Tayar9c8517c2017-03-28 15:12:55 +03002204
2205 switch (res_id) {
2206 case QED_L2_QUEUE:
2207 *p_resc_num = (b_ah ? MAX_NUM_L2_QUEUES_K2 :
2208 MAX_NUM_L2_QUEUES_BB) / num_funcs;
2209 break;
2210 case QED_VPORT:
2211 *p_resc_num = (b_ah ? MAX_NUM_VPORTS_K2 :
2212 MAX_NUM_VPORTS_BB) / num_funcs;
2213 break;
2214 case QED_RSS_ENG:
2215 *p_resc_num = (b_ah ? ETH_RSS_ENGINE_NUM_K2 :
2216 ETH_RSS_ENGINE_NUM_BB) / num_funcs;
2217 break;
2218 case QED_PQ:
2219 *p_resc_num = (b_ah ? MAX_QM_TX_QUEUES_K2 :
2220 MAX_QM_TX_QUEUES_BB) / num_funcs;
2221 *p_resc_num &= ~0x7; /* The granularity of the PQs is 8 */
2222 break;
2223 case QED_RL:
2224 *p_resc_num = MAX_QM_GLOBAL_RLS / num_funcs;
2225 break;
2226 case QED_MAC:
2227 case QED_VLAN:
2228 /* Each VFC resource can accommodate both a MAC and a VLAN */
2229 *p_resc_num = ETH_NUM_MAC_FILTERS / num_funcs;
2230 break;
2231 case QED_ILT:
2232 *p_resc_num = (b_ah ? PXP_NUM_ILT_RECORDS_K2 :
2233 PXP_NUM_ILT_RECORDS_BB) / num_funcs;
2234 break;
2235 case QED_LL2_QUEUE:
2236 *p_resc_num = MAX_NUM_LL2_RX_QUEUES / num_funcs;
2237 break;
2238 case QED_RDMA_CNQ_RAM:
2239 case QED_CMDQS_CQS:
2240 /* CNQ/CMDQS are the same resource */
2241 *p_resc_num = NUM_OF_CMDQS_CQS / num_funcs;
2242 break;
2243 case QED_RDMA_STATS_QUEUE:
2244 *p_resc_num = (b_ah ? RDMA_NUM_STATISTIC_COUNTERS_K2 :
2245 RDMA_NUM_STATISTIC_COUNTERS_BB) / num_funcs;
2246 break;
2247 case QED_BDQ:
2248 if (p_hwfn->hw_info.personality != QED_PCI_ISCSI &&
2249 p_hwfn->hw_info.personality != QED_PCI_FCOE)
2250 *p_resc_num = 0;
2251 else
2252 *p_resc_num = 1;
2253 break;
2254 case QED_SB:
Mintz, Yuvalebbdcc62017-06-01 15:29:10 +03002255 /* Since we want its value to reflect whether MFW supports
2256 * the new scheme, have a default of 0.
2257 */
2258 *p_resc_num = 0;
Tomer Tayar9c8517c2017-03-28 15:12:55 +03002259 break;
2260 default:
2261 return -EINVAL;
2262 }
2263
2264 switch (res_id) {
2265 case QED_BDQ:
2266 if (!*p_resc_num)
2267 *p_resc_start = 0;
Tomer Tayar78cea9f2017-05-23 09:41:22 +03002268 else if (p_hwfn->cdev->num_ports_in_engine == 4)
Tomer Tayar9c8517c2017-03-28 15:12:55 +03002269 *p_resc_start = p_hwfn->port_id;
2270 else if (p_hwfn->hw_info.personality == QED_PCI_ISCSI)
2271 *p_resc_start = p_hwfn->port_id;
2272 else if (p_hwfn->hw_info.personality == QED_PCI_FCOE)
2273 *p_resc_start = p_hwfn->port_id + 2;
2274 break;
2275 default:
2276 *p_resc_start = *p_resc_num * p_hwfn->enabled_func_idx;
2277 break;
2278 }
2279
2280 return 0;
2281}
2282
2283static int __qed_hw_set_resc_info(struct qed_hwfn *p_hwfn,
2284 enum qed_resources res_id)
2285{
2286 u32 dflt_resc_num = 0, dflt_resc_start = 0;
2287 u32 mcp_resp, *p_resc_num, *p_resc_start;
Tomer Tayar2edbff82016-10-31 07:14:27 +02002288 int rc;
2289
2290 p_resc_num = &RESC_NUM(p_hwfn, res_id);
2291 p_resc_start = &RESC_START(p_hwfn, res_id);
2292
Tomer Tayar9c8517c2017-03-28 15:12:55 +03002293 rc = qed_hw_get_dflt_resc(p_hwfn, res_id, &dflt_resc_num,
2294 &dflt_resc_start);
2295 if (rc) {
Tomer Tayar2edbff82016-10-31 07:14:27 +02002296 DP_ERR(p_hwfn,
2297 "Failed to get default amount for resource %d [%s]\n",
2298 res_id, qed_hw_get_resc_name(res_id));
Tomer Tayar9c8517c2017-03-28 15:12:55 +03002299 return rc;
Tomer Tayar2edbff82016-10-31 07:14:27 +02002300 }
2301
Tomer Tayar9c8517c2017-03-28 15:12:55 +03002302 rc = qed_mcp_get_resc_info(p_hwfn, p_hwfn->p_main_ptt, res_id,
2303 &mcp_resp, p_resc_num, p_resc_start);
Tomer Tayar2edbff82016-10-31 07:14:27 +02002304 if (rc) {
2305 DP_NOTICE(p_hwfn,
2306 "MFW response failure for an allocation request for resource %d [%s]\n",
2307 res_id, qed_hw_get_resc_name(res_id));
2308 return rc;
2309 }
2310
2311 /* Default driver values are applied in the following cases:
2312 * - The resource allocation MB command is not supported by the MFW
2313 * - There is an internal error in the MFW while processing the request
2314 * - The resource ID is unknown to the MFW
2315 */
Tomer Tayar9c8517c2017-03-28 15:12:55 +03002316 if (mcp_resp != FW_MSG_CODE_RESOURCE_ALLOC_OK) {
2317 DP_INFO(p_hwfn,
2318 "Failed to receive allocation info for resource %d [%s]. mcp_resp = 0x%x. Applying default values [%d,%d].\n",
2319 res_id,
2320 qed_hw_get_resc_name(res_id),
2321 mcp_resp, dflt_resc_num, dflt_resc_start);
Tomer Tayar2edbff82016-10-31 07:14:27 +02002322 *p_resc_num = dflt_resc_num;
2323 *p_resc_start = dflt_resc_start;
2324 goto out;
2325 }
2326
Tomer Tayar2edbff82016-10-31 07:14:27 +02002327out:
2328 /* PQs have to divide by 8 [that's the HW granularity].
2329 * Reduce number so it would fit.
2330 */
2331 if ((res_id == QED_PQ) && ((*p_resc_num % 8) || (*p_resc_start % 8))) {
2332 DP_INFO(p_hwfn,
2333 "PQs need to align by 8; Number %08x --> %08x, Start %08x --> %08x\n",
2334 *p_resc_num,
2335 (*p_resc_num) & ~0x7,
2336 *p_resc_start, (*p_resc_start) & ~0x7);
2337 *p_resc_num &= ~0x7;
2338 *p_resc_start &= ~0x7;
2339 }
2340
2341 return 0;
2342}
2343
Tomer Tayar9c8517c2017-03-28 15:12:55 +03002344static int qed_hw_set_resc_info(struct qed_hwfn *p_hwfn)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002345{
Tomer Tayar9c8517c2017-03-28 15:12:55 +03002346 int rc;
2347 u8 res_id;
2348
2349 for (res_id = 0; res_id < QED_MAX_RESC; res_id++) {
2350 rc = __qed_hw_set_resc_info(p_hwfn, res_id);
2351 if (rc)
2352 return rc;
2353 }
2354
2355 return 0;
2356}
2357
Tomer Tayar9c8517c2017-03-28 15:12:55 +03002358static int qed_hw_get_resc(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
2359{
2360 struct qed_resc_unlock_params resc_unlock_params;
2361 struct qed_resc_lock_params resc_lock_params;
Mintz, Yuval9c79dda2017-03-14 16:23:54 +02002362 bool b_ah = QED_IS_AH(p_hwfn->cdev);
Tomer Tayar2edbff82016-10-31 07:14:27 +02002363 u8 res_id;
2364 int rc;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002365
Tomer Tayar9c8517c2017-03-28 15:12:55 +03002366 /* Setting the max values of the soft resources and the following
2367 * resources allocation queries should be atomic. Since several PFs can
2368 * run in parallel - a resource lock is needed.
2369 * If either the resource lock or resource set value commands are not
2370 * supported - skip the the max values setting, release the lock if
2371 * needed, and proceed to the queries. Other failures, including a
2372 * failure to acquire the lock, will cause this function to fail.
2373 */
sudarsana.kalluru@cavium.comf470f222017-04-26 09:00:49 -07002374 qed_mcp_resc_lock_default_init(&resc_lock_params, &resc_unlock_params,
2375 QED_RESC_LOCK_RESC_ALLOC, false);
Tomer Tayar9c8517c2017-03-28 15:12:55 +03002376
2377 rc = qed_mcp_resc_lock(p_hwfn, p_ptt, &resc_lock_params);
2378 if (rc && rc != -EINVAL) {
2379 return rc;
2380 } else if (rc == -EINVAL) {
2381 DP_INFO(p_hwfn,
2382 "Skip the max values setting of the soft resources since the resource lock is not supported by the MFW\n");
2383 } else if (!rc && !resc_lock_params.b_granted) {
2384 DP_NOTICE(p_hwfn,
2385 "Failed to acquire the resource lock for the resource allocation commands\n");
2386 return -EBUSY;
2387 } else {
2388 rc = qed_hw_set_soft_resc_size(p_hwfn, p_ptt);
2389 if (rc && rc != -EINVAL) {
2390 DP_NOTICE(p_hwfn,
2391 "Failed to set the max values of the soft resources\n");
2392 goto unlock_and_exit;
2393 } else if (rc == -EINVAL) {
2394 DP_INFO(p_hwfn,
2395 "Skip the max values setting of the soft resources since it is not supported by the MFW\n");
2396 rc = qed_mcp_resc_unlock(p_hwfn, p_ptt,
2397 &resc_unlock_params);
2398 if (rc)
2399 DP_INFO(p_hwfn,
2400 "Failed to release the resource lock for the resource allocation commands\n");
2401 }
2402 }
2403
2404 rc = qed_hw_set_resc_info(p_hwfn);
2405 if (rc)
2406 goto unlock_and_exit;
2407
2408 if (resc_lock_params.b_granted && !resc_unlock_params.b_released) {
2409 rc = qed_mcp_resc_unlock(p_hwfn, p_ptt, &resc_unlock_params);
Tomer Tayar2edbff82016-10-31 07:14:27 +02002410 if (rc)
Tomer Tayar9c8517c2017-03-28 15:12:55 +03002411 DP_INFO(p_hwfn,
2412 "Failed to release the resource lock for the resource allocation commands\n");
Tomer Tayar2edbff82016-10-31 07:14:27 +02002413 }
Yuval Mintzdbb799c2016-06-03 14:35:35 +03002414
2415 /* Sanity for ILT */
Mintz, Yuval9c79dda2017-03-14 16:23:54 +02002416 if ((b_ah && (RESC_END(p_hwfn, QED_ILT) > PXP_NUM_ILT_RECORDS_K2)) ||
2417 (!b_ah && (RESC_END(p_hwfn, QED_ILT) > PXP_NUM_ILT_RECORDS_BB))) {
Yuval Mintzdbb799c2016-06-03 14:35:35 +03002418 DP_NOTICE(p_hwfn, "Can't assign ILT pages [%08x,...,%08x]\n",
2419 RESC_START(p_hwfn, QED_ILT),
2420 RESC_END(p_hwfn, QED_ILT) - 1);
2421 return -EINVAL;
2422 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002423
Mintz, Yuvalebbdcc62017-06-01 15:29:10 +03002424 /* This will also learn the number of SBs from MFW */
2425 if (qed_int_igu_reset_cam(p_hwfn, p_ptt))
2426 return -EINVAL;
2427
Yuval Mintz25c089d2015-10-26 11:02:26 +02002428 qed_hw_set_feat(p_hwfn);
2429
Tomer Tayar2edbff82016-10-31 07:14:27 +02002430 for (res_id = 0; res_id < QED_MAX_RESC; res_id++)
2431 DP_VERBOSE(p_hwfn, NETIF_MSG_PROBE, "%s = %d start = %d\n",
2432 qed_hw_get_resc_name(res_id),
2433 RESC_NUM(p_hwfn, res_id),
2434 RESC_START(p_hwfn, res_id));
Yuval Mintzdbb799c2016-06-03 14:35:35 +03002435
2436 return 0;
Tomer Tayar9c8517c2017-03-28 15:12:55 +03002437
2438unlock_and_exit:
2439 if (resc_lock_params.b_granted && !resc_unlock_params.b_released)
2440 qed_mcp_resc_unlock(p_hwfn, p_ptt, &resc_unlock_params);
2441 return rc;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002442}
2443
Yuval Mintz1a635e42016-08-15 10:42:43 +03002444static int qed_hw_get_nvm_info(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002445{
Yuval Mintzfc48b7a2016-02-15 13:22:35 -05002446 u32 port_cfg_addr, link_temp, nvm_cfg_addr, device_capabilities;
Arun Easi1e128c82017-02-15 06:28:22 -08002447 u32 nvm_cfg1_offset, mf_mode, addr, generic_cont0, core_cfg;
Yuval Mintzcc875c22015-10-26 11:02:31 +02002448 struct qed_mcp_link_params *link;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002449
2450 /* Read global nvm_cfg address */
2451 nvm_cfg_addr = qed_rd(p_hwfn, p_ptt, MISC_REG_GEN_PURP_CR0);
2452
2453 /* Verify MCP has initialized it */
2454 if (!nvm_cfg_addr) {
2455 DP_NOTICE(p_hwfn, "Shared memory not initialized\n");
2456 return -EINVAL;
2457 }
2458
2459 /* Read nvm_cfg1 (Notice this is just offset, and not offsize (TBD) */
2460 nvm_cfg1_offset = qed_rd(p_hwfn, p_ptt, nvm_cfg_addr + 4);
2461
Yuval Mintzcc875c22015-10-26 11:02:31 +02002462 addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
2463 offsetof(struct nvm_cfg1, glob) +
2464 offsetof(struct nvm_cfg1_glob, core_cfg);
2465
2466 core_cfg = qed_rd(p_hwfn, p_ptt, addr);
2467
2468 switch ((core_cfg & NVM_CFG1_GLOB_NETWORK_PORT_MODE_MASK) >>
2469 NVM_CFG1_GLOB_NETWORK_PORT_MODE_OFFSET) {
Yuval Mintz351a4ded2016-06-02 10:23:29 +03002470 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_2X40G:
Yuval Mintzcc875c22015-10-26 11:02:31 +02002471 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_2X40G;
2472 break;
Yuval Mintz351a4ded2016-06-02 10:23:29 +03002473 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_2X50G:
Yuval Mintzcc875c22015-10-26 11:02:31 +02002474 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_2X50G;
2475 break;
Yuval Mintz351a4ded2016-06-02 10:23:29 +03002476 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_1X100G:
Yuval Mintzcc875c22015-10-26 11:02:31 +02002477 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_1X100G;
2478 break;
Yuval Mintz351a4ded2016-06-02 10:23:29 +03002479 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_4X10G_F:
Yuval Mintzcc875c22015-10-26 11:02:31 +02002480 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_4X10G_F;
2481 break;
Yuval Mintz351a4ded2016-06-02 10:23:29 +03002482 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_4X10G_E:
Yuval Mintzcc875c22015-10-26 11:02:31 +02002483 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_4X10G_E;
2484 break;
Yuval Mintz351a4ded2016-06-02 10:23:29 +03002485 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_4X20G:
Yuval Mintzcc875c22015-10-26 11:02:31 +02002486 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_4X20G;
2487 break;
Yuval Mintz351a4ded2016-06-02 10:23:29 +03002488 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_1X40G:
Yuval Mintzcc875c22015-10-26 11:02:31 +02002489 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_1X40G;
2490 break;
Yuval Mintz351a4ded2016-06-02 10:23:29 +03002491 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_2X25G:
Yuval Mintzcc875c22015-10-26 11:02:31 +02002492 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_2X25G;
2493 break;
Mintz, Yuval9c79dda2017-03-14 16:23:54 +02002494 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_2X10G:
2495 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_2X10G;
2496 break;
Yuval Mintz351a4ded2016-06-02 10:23:29 +03002497 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_1X25G:
Yuval Mintzcc875c22015-10-26 11:02:31 +02002498 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_1X25G;
2499 break;
Mintz, Yuval9c79dda2017-03-14 16:23:54 +02002500 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_4X25G:
2501 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_4X25G;
2502 break;
Yuval Mintzcc875c22015-10-26 11:02:31 +02002503 default:
Yuval Mintz1a635e42016-08-15 10:42:43 +03002504 DP_NOTICE(p_hwfn, "Unknown port mode in 0x%08x\n", core_cfg);
Yuval Mintzcc875c22015-10-26 11:02:31 +02002505 break;
2506 }
2507
Yuval Mintzcc875c22015-10-26 11:02:31 +02002508 /* Read default link configuration */
2509 link = &p_hwfn->mcp_info->link_input;
2510 port_cfg_addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
2511 offsetof(struct nvm_cfg1, port[MFW_PORT(p_hwfn)]);
2512 link_temp = qed_rd(p_hwfn, p_ptt,
2513 port_cfg_addr +
2514 offsetof(struct nvm_cfg1_port, speed_cap_mask));
Yuval Mintz83aeb932016-08-15 10:42:44 +03002515 link_temp &= NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_MASK;
2516 link->speed.advertised_speeds = link_temp;
Yuval Mintzcc875c22015-10-26 11:02:31 +02002517
Yuval Mintz83aeb932016-08-15 10:42:44 +03002518 link_temp = link->speed.advertised_speeds;
2519 p_hwfn->mcp_info->link_capabilities.speed_capabilities = link_temp;
Yuval Mintzcc875c22015-10-26 11:02:31 +02002520
2521 link_temp = qed_rd(p_hwfn, p_ptt,
2522 port_cfg_addr +
2523 offsetof(struct nvm_cfg1_port, link_settings));
2524 switch ((link_temp & NVM_CFG1_PORT_DRV_LINK_SPEED_MASK) >>
2525 NVM_CFG1_PORT_DRV_LINK_SPEED_OFFSET) {
2526 case NVM_CFG1_PORT_DRV_LINK_SPEED_AUTONEG:
2527 link->speed.autoneg = true;
2528 break;
2529 case NVM_CFG1_PORT_DRV_LINK_SPEED_1G:
2530 link->speed.forced_speed = 1000;
2531 break;
2532 case NVM_CFG1_PORT_DRV_LINK_SPEED_10G:
2533 link->speed.forced_speed = 10000;
2534 break;
2535 case NVM_CFG1_PORT_DRV_LINK_SPEED_25G:
2536 link->speed.forced_speed = 25000;
2537 break;
2538 case NVM_CFG1_PORT_DRV_LINK_SPEED_40G:
2539 link->speed.forced_speed = 40000;
2540 break;
2541 case NVM_CFG1_PORT_DRV_LINK_SPEED_50G:
2542 link->speed.forced_speed = 50000;
2543 break;
Yuval Mintz351a4ded2016-06-02 10:23:29 +03002544 case NVM_CFG1_PORT_DRV_LINK_SPEED_BB_100G:
Yuval Mintzcc875c22015-10-26 11:02:31 +02002545 link->speed.forced_speed = 100000;
2546 break;
2547 default:
Yuval Mintz1a635e42016-08-15 10:42:43 +03002548 DP_NOTICE(p_hwfn, "Unknown Speed in 0x%08x\n", link_temp);
Yuval Mintzcc875c22015-10-26 11:02:31 +02002549 }
2550
sudarsana.kalluru@cavium.com34f91992017-05-04 08:15:04 -07002551 p_hwfn->mcp_info->link_capabilities.default_speed_autoneg =
2552 link->speed.autoneg;
2553
Yuval Mintzcc875c22015-10-26 11:02:31 +02002554 link_temp &= NVM_CFG1_PORT_DRV_FLOW_CONTROL_MASK;
2555 link_temp >>= NVM_CFG1_PORT_DRV_FLOW_CONTROL_OFFSET;
2556 link->pause.autoneg = !!(link_temp &
2557 NVM_CFG1_PORT_DRV_FLOW_CONTROL_AUTONEG);
2558 link->pause.forced_rx = !!(link_temp &
2559 NVM_CFG1_PORT_DRV_FLOW_CONTROL_RX);
2560 link->pause.forced_tx = !!(link_temp &
2561 NVM_CFG1_PORT_DRV_FLOW_CONTROL_TX);
2562 link->loopback_mode = 0;
2563
2564 DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
2565 "Read default link: Speed 0x%08x, Adv. Speed 0x%08x, AN: 0x%02x, PAUSE AN: 0x%02x\n",
2566 link->speed.forced_speed, link->speed.advertised_speeds,
2567 link->speed.autoneg, link->pause.autoneg);
2568
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002569 /* Read Multi-function information from shmem */
2570 addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
2571 offsetof(struct nvm_cfg1, glob) +
2572 offsetof(struct nvm_cfg1_glob, generic_cont0);
2573
2574 generic_cont0 = qed_rd(p_hwfn, p_ptt, addr);
2575
2576 mf_mode = (generic_cont0 & NVM_CFG1_GLOB_MF_MODE_MASK) >>
2577 NVM_CFG1_GLOB_MF_MODE_OFFSET;
2578
2579 switch (mf_mode) {
2580 case NVM_CFG1_GLOB_MF_MODE_MF_ALLOWED:
Yuval Mintzfc48b7a2016-02-15 13:22:35 -05002581 p_hwfn->cdev->mf_mode = QED_MF_OVLAN;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002582 break;
2583 case NVM_CFG1_GLOB_MF_MODE_NPAR1_0:
Yuval Mintzfc48b7a2016-02-15 13:22:35 -05002584 p_hwfn->cdev->mf_mode = QED_MF_NPAR;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002585 break;
Yuval Mintzfc48b7a2016-02-15 13:22:35 -05002586 case NVM_CFG1_GLOB_MF_MODE_DEFAULT:
2587 p_hwfn->cdev->mf_mode = QED_MF_DEFAULT;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002588 break;
2589 }
2590 DP_INFO(p_hwfn, "Multi function mode is %08x\n",
2591 p_hwfn->cdev->mf_mode);
2592
Yuval Mintzfc48b7a2016-02-15 13:22:35 -05002593 /* Read Multi-function information from shmem */
2594 addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
2595 offsetof(struct nvm_cfg1, glob) +
2596 offsetof(struct nvm_cfg1_glob, device_capabilities);
2597
2598 device_capabilities = qed_rd(p_hwfn, p_ptt, addr);
2599 if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_ETHERNET)
2600 __set_bit(QED_DEV_CAP_ETH,
2601 &p_hwfn->hw_info.device_capabilities);
Arun Easi1e128c82017-02-15 06:28:22 -08002602 if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_FCOE)
2603 __set_bit(QED_DEV_CAP_FCOE,
2604 &p_hwfn->hw_info.device_capabilities);
Yuval Mintzc5ac9312016-06-03 14:35:34 +03002605 if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_ISCSI)
2606 __set_bit(QED_DEV_CAP_ISCSI,
2607 &p_hwfn->hw_info.device_capabilities);
2608 if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_ROCE)
2609 __set_bit(QED_DEV_CAP_ROCE,
2610 &p_hwfn->hw_info.device_capabilities);
Yuval Mintzfc48b7a2016-02-15 13:22:35 -05002611
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002612 return qed_mcp_fill_shmem_func_info(p_hwfn, p_ptt);
2613}
2614
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03002615static void qed_get_num_funcs(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
2616{
Yuval Mintzdbb799c2016-06-03 14:35:35 +03002617 u8 num_funcs, enabled_func_idx = p_hwfn->rel_pf_id;
2618 u32 reg_function_hide, tmp, eng_mask, low_pfs_mask;
Mintz, Yuval9c79dda2017-03-14 16:23:54 +02002619 struct qed_dev *cdev = p_hwfn->cdev;
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03002620
Mintz, Yuval9c79dda2017-03-14 16:23:54 +02002621 num_funcs = QED_IS_AH(cdev) ? MAX_NUM_PFS_K2 : MAX_NUM_PFS_BB;
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03002622
2623 /* Bit 0 of MISCS_REG_FUNCTION_HIDE indicates whether the bypass values
2624 * in the other bits are selected.
2625 * Bits 1-15 are for functions 1-15, respectively, and their value is
2626 * '0' only for enabled functions (function 0 always exists and
2627 * enabled).
2628 * In case of CMT, only the "even" functions are enabled, and thus the
2629 * number of functions for both hwfns is learnt from the same bits.
2630 */
2631 reg_function_hide = qed_rd(p_hwfn, p_ptt, MISCS_REG_FUNCTION_HIDE);
2632
2633 if (reg_function_hide & 0x1) {
Mintz, Yuval9c79dda2017-03-14 16:23:54 +02002634 if (QED_IS_BB(cdev)) {
2635 if (QED_PATH_ID(p_hwfn) && cdev->num_hwfns == 1) {
2636 num_funcs = 0;
2637 eng_mask = 0xaaaa;
2638 } else {
2639 num_funcs = 1;
2640 eng_mask = 0x5554;
2641 }
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03002642 } else {
2643 num_funcs = 1;
Mintz, Yuval9c79dda2017-03-14 16:23:54 +02002644 eng_mask = 0xfffe;
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03002645 }
2646
2647 /* Get the number of the enabled functions on the engine */
2648 tmp = (reg_function_hide ^ 0xffffffff) & eng_mask;
2649 while (tmp) {
2650 if (tmp & 0x1)
2651 num_funcs++;
2652 tmp >>= 0x1;
2653 }
Yuval Mintzdbb799c2016-06-03 14:35:35 +03002654
2655 /* Get the PF index within the enabled functions */
2656 low_pfs_mask = (0x1 << p_hwfn->abs_pf_id) - 1;
2657 tmp = reg_function_hide & eng_mask & low_pfs_mask;
2658 while (tmp) {
2659 if (tmp & 0x1)
2660 enabled_func_idx--;
2661 tmp >>= 0x1;
2662 }
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03002663 }
2664
2665 p_hwfn->num_funcs_on_engine = num_funcs;
Yuval Mintzdbb799c2016-06-03 14:35:35 +03002666 p_hwfn->enabled_func_idx = enabled_func_idx;
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03002667
2668 DP_VERBOSE(p_hwfn,
2669 NETIF_MSG_PROBE,
Yuval Mintz525ef5c2016-08-15 10:42:45 +03002670 "PF [rel_id %d, abs_id %d] occupies index %d within the %d enabled functions on the engine\n",
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03002671 p_hwfn->rel_pf_id,
2672 p_hwfn->abs_pf_id,
Yuval Mintz525ef5c2016-08-15 10:42:45 +03002673 p_hwfn->enabled_func_idx, p_hwfn->num_funcs_on_engine);
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03002674}
2675
Mintz, Yuval9c79dda2017-03-14 16:23:54 +02002676static void qed_hw_info_port_num_bb(struct qed_hwfn *p_hwfn,
2677 struct qed_ptt *p_ptt)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002678{
2679 u32 port_mode;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002680
Mintz, Yuval9c79dda2017-03-14 16:23:54 +02002681 port_mode = qed_rd(p_hwfn, p_ptt, CNIG_REG_NW_PORT_MODE_BB_B0);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002682
2683 if (port_mode < 3) {
Tomer Tayar78cea9f2017-05-23 09:41:22 +03002684 p_hwfn->cdev->num_ports_in_engine = 1;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002685 } else if (port_mode <= 5) {
Tomer Tayar78cea9f2017-05-23 09:41:22 +03002686 p_hwfn->cdev->num_ports_in_engine = 2;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002687 } else {
2688 DP_NOTICE(p_hwfn, "PORT MODE: %d not supported\n",
Tomer Tayar78cea9f2017-05-23 09:41:22 +03002689 p_hwfn->cdev->num_ports_in_engine);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002690
Tomer Tayar78cea9f2017-05-23 09:41:22 +03002691 /* Default num_ports_in_engine to something */
2692 p_hwfn->cdev->num_ports_in_engine = 1;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002693 }
Mintz, Yuval9c79dda2017-03-14 16:23:54 +02002694}
2695
2696static void qed_hw_info_port_num_ah(struct qed_hwfn *p_hwfn,
2697 struct qed_ptt *p_ptt)
2698{
2699 u32 port;
2700 int i;
2701
Tomer Tayar78cea9f2017-05-23 09:41:22 +03002702 p_hwfn->cdev->num_ports_in_engine = 0;
Mintz, Yuval9c79dda2017-03-14 16:23:54 +02002703
2704 for (i = 0; i < MAX_NUM_PORTS_K2; i++) {
2705 port = qed_rd(p_hwfn, p_ptt,
2706 CNIG_REG_NIG_PORT0_CONF_K2 + (i * 4));
2707 if (port & 1)
Tomer Tayar78cea9f2017-05-23 09:41:22 +03002708 p_hwfn->cdev->num_ports_in_engine++;
Mintz, Yuval9c79dda2017-03-14 16:23:54 +02002709 }
2710
Tomer Tayar78cea9f2017-05-23 09:41:22 +03002711 if (!p_hwfn->cdev->num_ports_in_engine) {
Mintz, Yuval9c79dda2017-03-14 16:23:54 +02002712 DP_NOTICE(p_hwfn, "All NIG ports are inactive\n");
2713
2714 /* Default num_ports_in_engine to something */
Tomer Tayar78cea9f2017-05-23 09:41:22 +03002715 p_hwfn->cdev->num_ports_in_engine = 1;
Mintz, Yuval9c79dda2017-03-14 16:23:54 +02002716 }
2717}
2718
2719static void qed_hw_info_port_num(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
2720{
2721 if (QED_IS_BB(p_hwfn->cdev))
2722 qed_hw_info_port_num_bb(p_hwfn, p_ptt);
2723 else
2724 qed_hw_info_port_num_ah(p_hwfn, p_ptt);
2725}
2726
2727static int
2728qed_get_hw_info(struct qed_hwfn *p_hwfn,
2729 struct qed_ptt *p_ptt,
2730 enum qed_pci_personality personality)
2731{
2732 int rc;
2733
2734 /* Since all information is common, only first hwfns should do this */
2735 if (IS_LEAD_HWFN(p_hwfn)) {
2736 rc = qed_iov_hw_info(p_hwfn);
2737 if (rc)
2738 return rc;
2739 }
2740
2741 qed_hw_info_port_num(p_hwfn, p_ptt);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002742
2743 qed_hw_get_nvm_info(p_hwfn, p_ptt);
2744
2745 rc = qed_int_igu_read_cam(p_hwfn, p_ptt);
2746 if (rc)
2747 return rc;
2748
2749 if (qed_mcp_is_init(p_hwfn))
2750 ether_addr_copy(p_hwfn->hw_info.hw_mac_addr,
2751 p_hwfn->mcp_info->func_info.mac);
2752 else
2753 eth_random_addr(p_hwfn->hw_info.hw_mac_addr);
2754
2755 if (qed_mcp_is_init(p_hwfn)) {
2756 if (p_hwfn->mcp_info->func_info.ovlan != QED_MCP_VLAN_UNSET)
2757 p_hwfn->hw_info.ovlan =
2758 p_hwfn->mcp_info->func_info.ovlan;
2759
2760 qed_mcp_cmd_port_init(p_hwfn, p_ptt);
2761 }
2762
2763 if (qed_mcp_is_init(p_hwfn)) {
2764 enum qed_pci_personality protocol;
2765
2766 protocol = p_hwfn->mcp_info->func_info.protocol;
2767 p_hwfn->hw_info.personality = protocol;
2768 }
2769
Ariel Eliorb5a9ee72017-04-03 12:21:09 +03002770 p_hwfn->hw_info.num_hw_tc = NUM_PHYS_TCS_4PORT_K2;
2771 p_hwfn->hw_info.num_active_tc = 1;
2772
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03002773 qed_get_num_funcs(p_hwfn, p_ptt);
2774
Sudarsana Kalluru0fefbfb2016-10-31 07:14:21 +02002775 if (qed_mcp_is_init(p_hwfn))
2776 p_hwfn->hw_info.mtu = p_hwfn->mcp_info->func_info.mtu;
2777
Tomer Tayar9c8517c2017-03-28 15:12:55 +03002778 return qed_hw_get_resc(p_hwfn, p_ptt);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002779}
2780
Rahul Verma15582962017-04-06 15:58:29 +03002781static int qed_get_dev_info(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002782{
Rahul Verma15582962017-04-06 15:58:29 +03002783 struct qed_dev *cdev = p_hwfn->cdev;
Mintz, Yuval9c79dda2017-03-14 16:23:54 +02002784 u16 device_id_mask;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002785 u32 tmp;
2786
Yuval Mintzfc48b7a2016-02-15 13:22:35 -05002787 /* Read Vendor Id / Device Id */
Yuval Mintz1a635e42016-08-15 10:42:43 +03002788 pci_read_config_word(cdev->pdev, PCI_VENDOR_ID, &cdev->vendor_id);
2789 pci_read_config_word(cdev->pdev, PCI_DEVICE_ID, &cdev->device_id);
2790
Mintz, Yuval9c79dda2017-03-14 16:23:54 +02002791 /* Determine type */
2792 device_id_mask = cdev->device_id & QED_DEV_ID_MASK;
2793 switch (device_id_mask) {
2794 case QED_DEV_ID_MASK_BB:
2795 cdev->type = QED_DEV_TYPE_BB;
2796 break;
2797 case QED_DEV_ID_MASK_AH:
2798 cdev->type = QED_DEV_TYPE_AH;
2799 break;
2800 default:
2801 DP_NOTICE(p_hwfn, "Unknown device id 0x%x\n", cdev->device_id);
2802 return -EBUSY;
2803 }
2804
Rahul Verma15582962017-04-06 15:58:29 +03002805 cdev->chip_num = (u16)qed_rd(p_hwfn, p_ptt, MISCS_REG_CHIP_NUM);
2806 cdev->chip_rev = (u16)qed_rd(p_hwfn, p_ptt, MISCS_REG_CHIP_REV);
2807
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002808 MASK_FIELD(CHIP_REV, cdev->chip_rev);
2809
2810 /* Learn number of HW-functions */
Rahul Verma15582962017-04-06 15:58:29 +03002811 tmp = qed_rd(p_hwfn, p_ptt, MISCS_REG_CMT_ENABLED_FOR_PAIR);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002812
Yuval Mintzfc48b7a2016-02-15 13:22:35 -05002813 if (tmp & (1 << p_hwfn->rel_pf_id)) {
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002814 DP_NOTICE(cdev->hwfns, "device in CMT mode\n");
2815 cdev->num_hwfns = 2;
2816 } else {
2817 cdev->num_hwfns = 1;
2818 }
2819
Rahul Verma15582962017-04-06 15:58:29 +03002820 cdev->chip_bond_id = qed_rd(p_hwfn, p_ptt,
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002821 MISCS_REG_CHIP_TEST_REG) >> 4;
2822 MASK_FIELD(CHIP_BOND_ID, cdev->chip_bond_id);
Rahul Verma15582962017-04-06 15:58:29 +03002823 cdev->chip_metal = (u16)qed_rd(p_hwfn, p_ptt, MISCS_REG_CHIP_METAL);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002824 MASK_FIELD(CHIP_METAL, cdev->chip_metal);
2825
2826 DP_INFO(cdev->hwfns,
Mintz, Yuval9c79dda2017-03-14 16:23:54 +02002827 "Chip details - %s %c%d, Num: %04x Rev: %04x Bond id: %04x Metal: %04x\n",
2828 QED_IS_BB(cdev) ? "BB" : "AH",
2829 'A' + cdev->chip_rev,
2830 (int)cdev->chip_metal,
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002831 cdev->chip_num, cdev->chip_rev,
2832 cdev->chip_bond_id, cdev->chip_metal);
Yuval Mintz12e09c62016-03-02 20:26:01 +02002833
Yuval Mintz12e09c62016-03-02 20:26:01 +02002834 return 0;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002835}
2836
2837static int qed_hw_prepare_single(struct qed_hwfn *p_hwfn,
2838 void __iomem *p_regview,
2839 void __iomem *p_doorbells,
2840 enum qed_pci_personality personality)
2841{
2842 int rc = 0;
2843
2844 /* Split PCI bars evenly between hwfns */
2845 p_hwfn->regview = p_regview;
2846 p_hwfn->doorbells = p_doorbells;
2847
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03002848 if (IS_VF(p_hwfn->cdev))
2849 return qed_vf_hw_prepare(p_hwfn);
2850
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002851 /* Validate that chip access is feasible */
2852 if (REG_RD(p_hwfn, PXP_PF_ME_OPAQUE_ADDR) == 0xffffffff) {
2853 DP_ERR(p_hwfn,
2854 "Reading the ME register returns all Fs; Preventing further chip access\n");
2855 return -EINVAL;
2856 }
2857
2858 get_function_id(p_hwfn);
2859
Yuval Mintz12e09c62016-03-02 20:26:01 +02002860 /* Allocate PTT pool */
2861 rc = qed_ptt_pool_alloc(p_hwfn);
Joe Perches2591c282016-09-04 14:24:03 -07002862 if (rc)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002863 goto err0;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002864
Yuval Mintz12e09c62016-03-02 20:26:01 +02002865 /* Allocate the main PTT */
2866 p_hwfn->p_main_ptt = qed_get_reserved_ptt(p_hwfn, RESERVED_PTT_MAIN);
2867
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002868 /* First hwfn learns basic information, e.g., number of hwfns */
Yuval Mintz12e09c62016-03-02 20:26:01 +02002869 if (!p_hwfn->my_id) {
Rahul Verma15582962017-04-06 15:58:29 +03002870 rc = qed_get_dev_info(p_hwfn, p_hwfn->p_main_ptt);
Yuval Mintz1a635e42016-08-15 10:42:43 +03002871 if (rc)
Yuval Mintz12e09c62016-03-02 20:26:01 +02002872 goto err1;
2873 }
2874
2875 qed_hw_hwfn_prepare(p_hwfn);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002876
2877 /* Initialize MCP structure */
2878 rc = qed_mcp_cmd_init(p_hwfn, p_hwfn->p_main_ptt);
2879 if (rc) {
2880 DP_NOTICE(p_hwfn, "Failed initializing mcp command\n");
2881 goto err1;
2882 }
2883
2884 /* Read the device configuration information from the HW and SHMEM */
2885 rc = qed_get_hw_info(p_hwfn, p_hwfn->p_main_ptt, personality);
2886 if (rc) {
2887 DP_NOTICE(p_hwfn, "Failed to get HW information\n");
2888 goto err2;
2889 }
2890
Mintz, Yuval18a69e32017-03-28 15:12:53 +03002891 /* Sending a mailbox to the MFW should be done after qed_get_hw_info()
2892 * is called as it sets the ports number in an engine.
2893 */
2894 if (IS_LEAD_HWFN(p_hwfn)) {
2895 rc = qed_mcp_initiate_pf_flr(p_hwfn, p_hwfn->p_main_ptt);
2896 if (rc)
2897 DP_NOTICE(p_hwfn, "Failed to initiate PF FLR\n");
2898 }
2899
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002900 /* Allocate the init RT array and initialize the init-ops engine */
2901 rc = qed_init_alloc(p_hwfn);
Joe Perches2591c282016-09-04 14:24:03 -07002902 if (rc)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002903 goto err2;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002904
2905 return rc;
2906err2:
Yuval Mintz32a47e72016-05-11 16:36:12 +03002907 if (IS_LEAD_HWFN(p_hwfn))
2908 qed_iov_free_hw_info(p_hwfn->cdev);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002909 qed_mcp_free(p_hwfn);
2910err1:
2911 qed_hw_hwfn_free(p_hwfn);
2912err0:
2913 return rc;
2914}
2915
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002916int qed_hw_prepare(struct qed_dev *cdev,
2917 int personality)
2918{
Ariel Eliorc78df142015-12-07 06:25:58 -05002919 struct qed_hwfn *p_hwfn = QED_LEADING_HWFN(cdev);
2920 int rc;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002921
2922 /* Store the precompiled init data ptrs */
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03002923 if (IS_PF(cdev))
2924 qed_init_iro_array(cdev);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002925
2926 /* Initialize the first hwfn - will learn number of hwfns */
Ariel Eliorc78df142015-12-07 06:25:58 -05002927 rc = qed_hw_prepare_single(p_hwfn,
2928 cdev->regview,
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002929 cdev->doorbells, personality);
2930 if (rc)
2931 return rc;
2932
Ariel Eliorc78df142015-12-07 06:25:58 -05002933 personality = p_hwfn->hw_info.personality;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002934
2935 /* Initialize the rest of the hwfns */
Ariel Eliorc78df142015-12-07 06:25:58 -05002936 if (cdev->num_hwfns > 1) {
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002937 void __iomem *p_regview, *p_doorbell;
Ariel Eliorc78df142015-12-07 06:25:58 -05002938 u8 __iomem *addr;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002939
Ariel Eliorc78df142015-12-07 06:25:58 -05002940 /* adjust bar offset for second engine */
Rahul Verma15582962017-04-06 15:58:29 +03002941 addr = cdev->regview +
2942 qed_hw_bar_size(p_hwfn, p_hwfn->p_main_ptt,
2943 BAR_ID_0) / 2;
Ariel Eliorc78df142015-12-07 06:25:58 -05002944 p_regview = addr;
2945
Rahul Verma15582962017-04-06 15:58:29 +03002946 addr = cdev->doorbells +
2947 qed_hw_bar_size(p_hwfn, p_hwfn->p_main_ptt,
2948 BAR_ID_1) / 2;
Ariel Eliorc78df142015-12-07 06:25:58 -05002949 p_doorbell = addr;
2950
2951 /* prepare second hw function */
2952 rc = qed_hw_prepare_single(&cdev->hwfns[1], p_regview,
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002953 p_doorbell, personality);
Ariel Eliorc78df142015-12-07 06:25:58 -05002954
2955 /* in case of error, need to free the previously
2956 * initiliazed hwfn 0.
2957 */
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002958 if (rc) {
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03002959 if (IS_PF(cdev)) {
2960 qed_init_free(p_hwfn);
2961 qed_mcp_free(p_hwfn);
2962 qed_hw_hwfn_free(p_hwfn);
2963 }
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002964 }
2965 }
2966
Ariel Eliorc78df142015-12-07 06:25:58 -05002967 return rc;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002968}
2969
2970void qed_hw_remove(struct qed_dev *cdev)
2971{
Sudarsana Kalluru0fefbfb2016-10-31 07:14:21 +02002972 struct qed_hwfn *p_hwfn = QED_LEADING_HWFN(cdev);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002973 int i;
2974
Sudarsana Kalluru0fefbfb2016-10-31 07:14:21 +02002975 if (IS_PF(cdev))
2976 qed_mcp_ov_update_driver_state(p_hwfn, p_hwfn->p_main_ptt,
2977 QED_OV_DRIVER_STATE_NOT_LOADED);
2978
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002979 for_each_hwfn(cdev, i) {
2980 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
2981
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03002982 if (IS_VF(cdev)) {
Yuval Mintz0b55e272016-05-11 16:36:15 +03002983 qed_vf_pf_release(p_hwfn);
Yuval Mintz1408cc1f2016-05-11 16:36:14 +03002984 continue;
2985 }
2986
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002987 qed_init_free(p_hwfn);
2988 qed_hw_hwfn_free(p_hwfn);
2989 qed_mcp_free(p_hwfn);
2990 }
Yuval Mintz32a47e72016-05-11 16:36:12 +03002991
2992 qed_iov_free_hw_info(cdev);
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02002993}
2994
Yuval Mintza91eb522016-06-03 14:35:32 +03002995static void qed_chain_free_next_ptr(struct qed_dev *cdev,
2996 struct qed_chain *p_chain)
2997{
2998 void *p_virt = p_chain->p_virt_addr, *p_virt_next = NULL;
2999 dma_addr_t p_phys = p_chain->p_phys_addr, p_phys_next = 0;
3000 struct qed_chain_next *p_next;
3001 u32 size, i;
3002
3003 if (!p_virt)
3004 return;
3005
3006 size = p_chain->elem_size * p_chain->usable_per_page;
3007
3008 for (i = 0; i < p_chain->page_cnt; i++) {
3009 if (!p_virt)
3010 break;
3011
3012 p_next = (struct qed_chain_next *)((u8 *)p_virt + size);
3013 p_virt_next = p_next->next_virt;
3014 p_phys_next = HILO_DMA_REGPAIR(p_next->next_phys);
3015
3016 dma_free_coherent(&cdev->pdev->dev,
3017 QED_CHAIN_PAGE_SIZE, p_virt, p_phys);
3018
3019 p_virt = p_virt_next;
3020 p_phys = p_phys_next;
3021 }
3022}
3023
3024static void qed_chain_free_single(struct qed_dev *cdev,
3025 struct qed_chain *p_chain)
3026{
3027 if (!p_chain->p_virt_addr)
3028 return;
3029
3030 dma_free_coherent(&cdev->pdev->dev,
3031 QED_CHAIN_PAGE_SIZE,
3032 p_chain->p_virt_addr, p_chain->p_phys_addr);
3033}
3034
3035static void qed_chain_free_pbl(struct qed_dev *cdev, struct qed_chain *p_chain)
3036{
3037 void **pp_virt_addr_tbl = p_chain->pbl.pp_virt_addr_tbl;
3038 u32 page_cnt = p_chain->page_cnt, i, pbl_size;
Mintz, Yuval6d937ac2016-11-29 16:47:01 +02003039 u8 *p_pbl_virt = p_chain->pbl_sp.p_virt_table;
Yuval Mintza91eb522016-06-03 14:35:32 +03003040
3041 if (!pp_virt_addr_tbl)
3042 return;
3043
Mintz, Yuval6d937ac2016-11-29 16:47:01 +02003044 if (!p_pbl_virt)
Yuval Mintza91eb522016-06-03 14:35:32 +03003045 goto out;
3046
3047 for (i = 0; i < page_cnt; i++) {
3048 if (!pp_virt_addr_tbl[i])
3049 break;
3050
3051 dma_free_coherent(&cdev->pdev->dev,
3052 QED_CHAIN_PAGE_SIZE,
3053 pp_virt_addr_tbl[i],
3054 *(dma_addr_t *)p_pbl_virt);
3055
3056 p_pbl_virt += QED_CHAIN_PBL_ENTRY_SIZE;
3057 }
3058
3059 pbl_size = page_cnt * QED_CHAIN_PBL_ENTRY_SIZE;
3060 dma_free_coherent(&cdev->pdev->dev,
3061 pbl_size,
Mintz, Yuval6d937ac2016-11-29 16:47:01 +02003062 p_chain->pbl_sp.p_virt_table,
3063 p_chain->pbl_sp.p_phys_table);
Yuval Mintza91eb522016-06-03 14:35:32 +03003064out:
3065 vfree(p_chain->pbl.pp_virt_addr_tbl);
3066}
3067
3068void qed_chain_free(struct qed_dev *cdev, struct qed_chain *p_chain)
3069{
3070 switch (p_chain->mode) {
3071 case QED_CHAIN_MODE_NEXT_PTR:
3072 qed_chain_free_next_ptr(cdev, p_chain);
3073 break;
3074 case QED_CHAIN_MODE_SINGLE:
3075 qed_chain_free_single(cdev, p_chain);
3076 break;
3077 case QED_CHAIN_MODE_PBL:
3078 qed_chain_free_pbl(cdev, p_chain);
3079 break;
3080 }
3081}
3082
3083static int
3084qed_chain_alloc_sanity_check(struct qed_dev *cdev,
3085 enum qed_chain_cnt_type cnt_type,
3086 size_t elem_size, u32 page_cnt)
3087{
3088 u64 chain_size = ELEMS_PER_PAGE(elem_size) * page_cnt;
3089
3090 /* The actual chain size can be larger than the maximal possible value
3091 * after rounding up the requested elements number to pages, and after
3092 * taking into acount the unusuable elements (next-ptr elements).
3093 * The size of a "u16" chain can be (U16_MAX + 1) since the chain
3094 * size/capacity fields are of a u32 type.
3095 */
3096 if ((cnt_type == QED_CHAIN_CNT_TYPE_U16 &&
Tomer Tayar3ef310a2017-03-14 15:25:59 +02003097 chain_size > ((u32)U16_MAX + 1)) ||
3098 (cnt_type == QED_CHAIN_CNT_TYPE_U32 && chain_size > U32_MAX)) {
Yuval Mintza91eb522016-06-03 14:35:32 +03003099 DP_NOTICE(cdev,
3100 "The actual chain size (0x%llx) is larger than the maximal possible value\n",
3101 chain_size);
3102 return -EINVAL;
3103 }
3104
3105 return 0;
3106}
3107
3108static int
3109qed_chain_alloc_next_ptr(struct qed_dev *cdev, struct qed_chain *p_chain)
3110{
3111 void *p_virt = NULL, *p_virt_prev = NULL;
3112 dma_addr_t p_phys = 0;
3113 u32 i;
3114
3115 for (i = 0; i < p_chain->page_cnt; i++) {
3116 p_virt = dma_alloc_coherent(&cdev->pdev->dev,
3117 QED_CHAIN_PAGE_SIZE,
3118 &p_phys, GFP_KERNEL);
Joe Perches2591c282016-09-04 14:24:03 -07003119 if (!p_virt)
Yuval Mintza91eb522016-06-03 14:35:32 +03003120 return -ENOMEM;
Yuval Mintza91eb522016-06-03 14:35:32 +03003121
3122 if (i == 0) {
3123 qed_chain_init_mem(p_chain, p_virt, p_phys);
3124 qed_chain_reset(p_chain);
3125 } else {
3126 qed_chain_init_next_ptr_elem(p_chain, p_virt_prev,
3127 p_virt, p_phys);
3128 }
3129
3130 p_virt_prev = p_virt;
3131 }
3132 /* Last page's next element should point to the beginning of the
3133 * chain.
3134 */
3135 qed_chain_init_next_ptr_elem(p_chain, p_virt_prev,
3136 p_chain->p_virt_addr,
3137 p_chain->p_phys_addr);
3138
3139 return 0;
3140}
3141
3142static int
3143qed_chain_alloc_single(struct qed_dev *cdev, struct qed_chain *p_chain)
3144{
3145 dma_addr_t p_phys = 0;
3146 void *p_virt = NULL;
3147
3148 p_virt = dma_alloc_coherent(&cdev->pdev->dev,
3149 QED_CHAIN_PAGE_SIZE, &p_phys, GFP_KERNEL);
Joe Perches2591c282016-09-04 14:24:03 -07003150 if (!p_virt)
Yuval Mintza91eb522016-06-03 14:35:32 +03003151 return -ENOMEM;
Yuval Mintza91eb522016-06-03 14:35:32 +03003152
3153 qed_chain_init_mem(p_chain, p_virt, p_phys);
3154 qed_chain_reset(p_chain);
3155
3156 return 0;
3157}
3158
3159static int qed_chain_alloc_pbl(struct qed_dev *cdev, struct qed_chain *p_chain)
3160{
3161 u32 page_cnt = p_chain->page_cnt, size, i;
3162 dma_addr_t p_phys = 0, p_pbl_phys = 0;
3163 void **pp_virt_addr_tbl = NULL;
3164 u8 *p_pbl_virt = NULL;
3165 void *p_virt = NULL;
3166
3167 size = page_cnt * sizeof(*pp_virt_addr_tbl);
Joe Perches2591c282016-09-04 14:24:03 -07003168 pp_virt_addr_tbl = vzalloc(size);
3169 if (!pp_virt_addr_tbl)
Yuval Mintza91eb522016-06-03 14:35:32 +03003170 return -ENOMEM;
Yuval Mintza91eb522016-06-03 14:35:32 +03003171
3172 /* The allocation of the PBL table is done with its full size, since it
3173 * is expected to be successive.
3174 * qed_chain_init_pbl_mem() is called even in a case of an allocation
3175 * failure, since pp_virt_addr_tbl was previously allocated, and it
3176 * should be saved to allow its freeing during the error flow.
3177 */
3178 size = page_cnt * QED_CHAIN_PBL_ENTRY_SIZE;
3179 p_pbl_virt = dma_alloc_coherent(&cdev->pdev->dev,
3180 size, &p_pbl_phys, GFP_KERNEL);
3181 qed_chain_init_pbl_mem(p_chain, p_pbl_virt, p_pbl_phys,
3182 pp_virt_addr_tbl);
Joe Perches2591c282016-09-04 14:24:03 -07003183 if (!p_pbl_virt)
Yuval Mintza91eb522016-06-03 14:35:32 +03003184 return -ENOMEM;
Yuval Mintza91eb522016-06-03 14:35:32 +03003185
3186 for (i = 0; i < page_cnt; i++) {
3187 p_virt = dma_alloc_coherent(&cdev->pdev->dev,
3188 QED_CHAIN_PAGE_SIZE,
3189 &p_phys, GFP_KERNEL);
Joe Perches2591c282016-09-04 14:24:03 -07003190 if (!p_virt)
Yuval Mintza91eb522016-06-03 14:35:32 +03003191 return -ENOMEM;
Yuval Mintza91eb522016-06-03 14:35:32 +03003192
3193 if (i == 0) {
3194 qed_chain_init_mem(p_chain, p_virt, p_phys);
3195 qed_chain_reset(p_chain);
3196 }
3197
3198 /* Fill the PBL table with the physical address of the page */
3199 *(dma_addr_t *)p_pbl_virt = p_phys;
3200 /* Keep the virtual address of the page */
3201 p_chain->pbl.pp_virt_addr_tbl[i] = p_virt;
3202
3203 p_pbl_virt += QED_CHAIN_PBL_ENTRY_SIZE;
3204 }
3205
3206 return 0;
3207}
3208
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02003209int qed_chain_alloc(struct qed_dev *cdev,
3210 enum qed_chain_use_mode intended_use,
3211 enum qed_chain_mode mode,
Yuval Mintza91eb522016-06-03 14:35:32 +03003212 enum qed_chain_cnt_type cnt_type,
3213 u32 num_elems, size_t elem_size, struct qed_chain *p_chain)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02003214{
Yuval Mintza91eb522016-06-03 14:35:32 +03003215 u32 page_cnt;
3216 int rc = 0;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02003217
3218 if (mode == QED_CHAIN_MODE_SINGLE)
3219 page_cnt = 1;
3220 else
3221 page_cnt = QED_CHAIN_PAGE_CNT(num_elems, elem_size, mode);
3222
Yuval Mintza91eb522016-06-03 14:35:32 +03003223 rc = qed_chain_alloc_sanity_check(cdev, cnt_type, elem_size, page_cnt);
3224 if (rc) {
3225 DP_NOTICE(cdev,
Joe Perches2591c282016-09-04 14:24:03 -07003226 "Cannot allocate a chain with the given arguments:\n");
3227 DP_NOTICE(cdev,
Yuval Mintza91eb522016-06-03 14:35:32 +03003228 "[use_mode %d, mode %d, cnt_type %d, num_elems %d, elem_size %zu]\n",
3229 intended_use, mode, cnt_type, num_elems, elem_size);
3230 return rc;
3231 }
3232
3233 qed_chain_init_params(p_chain, page_cnt, (u8) elem_size, intended_use,
3234 mode, cnt_type);
3235
3236 switch (mode) {
3237 case QED_CHAIN_MODE_NEXT_PTR:
3238 rc = qed_chain_alloc_next_ptr(cdev, p_chain);
3239 break;
3240 case QED_CHAIN_MODE_SINGLE:
3241 rc = qed_chain_alloc_single(cdev, p_chain);
3242 break;
3243 case QED_CHAIN_MODE_PBL:
3244 rc = qed_chain_alloc_pbl(cdev, p_chain);
3245 break;
3246 }
3247 if (rc)
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02003248 goto nomem;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02003249
3250 return 0;
3251
3252nomem:
Yuval Mintza91eb522016-06-03 14:35:32 +03003253 qed_chain_free(cdev, p_chain);
3254 return rc;
Yuval Mintzfe56b9e2015-10-26 11:02:25 +02003255}
3256
Yuval Mintza91eb522016-06-03 14:35:32 +03003257int qed_fw_l2_queue(struct qed_hwfn *p_hwfn, u16 src_id, u16 *dst_id)
Manish Chopracee4d262015-10-26 11:02:28 +02003258{
3259 if (src_id >= RESC_NUM(p_hwfn, QED_L2_QUEUE)) {
3260 u16 min, max;
3261
Yuval Mintza91eb522016-06-03 14:35:32 +03003262 min = (u16) RESC_START(p_hwfn, QED_L2_QUEUE);
Manish Chopracee4d262015-10-26 11:02:28 +02003263 max = min + RESC_NUM(p_hwfn, QED_L2_QUEUE);
3264 DP_NOTICE(p_hwfn,
3265 "l2_queue id [%d] is not valid, available indices [%d - %d]\n",
3266 src_id, min, max);
3267
3268 return -EINVAL;
3269 }
3270
3271 *dst_id = RESC_START(p_hwfn, QED_L2_QUEUE) + src_id;
3272
3273 return 0;
3274}
3275
Yuval Mintz1a635e42016-08-15 10:42:43 +03003276int qed_fw_vport(struct qed_hwfn *p_hwfn, u8 src_id, u8 *dst_id)
Manish Chopracee4d262015-10-26 11:02:28 +02003277{
3278 if (src_id >= RESC_NUM(p_hwfn, QED_VPORT)) {
3279 u8 min, max;
3280
3281 min = (u8)RESC_START(p_hwfn, QED_VPORT);
3282 max = min + RESC_NUM(p_hwfn, QED_VPORT);
3283 DP_NOTICE(p_hwfn,
3284 "vport id [%d] is not valid, available indices [%d - %d]\n",
3285 src_id, min, max);
3286
3287 return -EINVAL;
3288 }
3289
3290 *dst_id = RESC_START(p_hwfn, QED_VPORT) + src_id;
3291
3292 return 0;
3293}
3294
Yuval Mintz1a635e42016-08-15 10:42:43 +03003295int qed_fw_rss_eng(struct qed_hwfn *p_hwfn, u8 src_id, u8 *dst_id)
Manish Chopracee4d262015-10-26 11:02:28 +02003296{
3297 if (src_id >= RESC_NUM(p_hwfn, QED_RSS_ENG)) {
3298 u8 min, max;
3299
3300 min = (u8)RESC_START(p_hwfn, QED_RSS_ENG);
3301 max = min + RESC_NUM(p_hwfn, QED_RSS_ENG);
3302 DP_NOTICE(p_hwfn,
3303 "rss_eng id [%d] is not valid, available indices [%d - %d]\n",
3304 src_id, min, max);
3305
3306 return -EINVAL;
3307 }
3308
3309 *dst_id = RESC_START(p_hwfn, QED_RSS_ENG) + src_id;
3310
3311 return 0;
3312}
Manish Choprabcd197c2016-04-26 10:56:08 -04003313
Yuval Mintz0a7fb112016-10-01 21:59:55 +03003314static void qed_llh_mac_to_filter(u32 *p_high, u32 *p_low,
3315 u8 *p_filter)
3316{
3317 *p_high = p_filter[1] | (p_filter[0] << 8);
3318 *p_low = p_filter[5] | (p_filter[4] << 8) |
3319 (p_filter[3] << 16) | (p_filter[2] << 24);
3320}
3321
3322int qed_llh_add_mac_filter(struct qed_hwfn *p_hwfn,
3323 struct qed_ptt *p_ptt, u8 *p_filter)
3324{
3325 u32 high = 0, low = 0, en;
3326 int i;
3327
3328 if (!(IS_MF_SI(p_hwfn) || IS_MF_DEFAULT(p_hwfn)))
3329 return 0;
3330
3331 qed_llh_mac_to_filter(&high, &low, p_filter);
3332
3333 /* Find a free entry and utilize it */
3334 for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) {
3335 en = qed_rd(p_hwfn, p_ptt,
3336 NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32));
3337 if (en)
3338 continue;
3339 qed_wr(p_hwfn, p_ptt,
3340 NIG_REG_LLH_FUNC_FILTER_VALUE +
3341 2 * i * sizeof(u32), low);
3342 qed_wr(p_hwfn, p_ptt,
3343 NIG_REG_LLH_FUNC_FILTER_VALUE +
3344 (2 * i + 1) * sizeof(u32), high);
3345 qed_wr(p_hwfn, p_ptt,
3346 NIG_REG_LLH_FUNC_FILTER_MODE + i * sizeof(u32), 0);
3347 qed_wr(p_hwfn, p_ptt,
3348 NIG_REG_LLH_FUNC_FILTER_PROTOCOL_TYPE +
3349 i * sizeof(u32), 0);
3350 qed_wr(p_hwfn, p_ptt,
3351 NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32), 1);
3352 break;
3353 }
3354 if (i >= NIG_REG_LLH_FUNC_FILTER_EN_SIZE) {
3355 DP_NOTICE(p_hwfn,
3356 "Failed to find an empty LLH filter to utilize\n");
3357 return -EINVAL;
3358 }
3359
3360 DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
3361 "mac: %pM is added at %d\n",
3362 p_filter, i);
3363
3364 return 0;
3365}
3366
3367void qed_llh_remove_mac_filter(struct qed_hwfn *p_hwfn,
3368 struct qed_ptt *p_ptt, u8 *p_filter)
3369{
3370 u32 high = 0, low = 0;
3371 int i;
3372
3373 if (!(IS_MF_SI(p_hwfn) || IS_MF_DEFAULT(p_hwfn)))
3374 return;
3375
3376 qed_llh_mac_to_filter(&high, &low, p_filter);
3377
3378 /* Find the entry and clean it */
3379 for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) {
3380 if (qed_rd(p_hwfn, p_ptt,
3381 NIG_REG_LLH_FUNC_FILTER_VALUE +
3382 2 * i * sizeof(u32)) != low)
3383 continue;
3384 if (qed_rd(p_hwfn, p_ptt,
3385 NIG_REG_LLH_FUNC_FILTER_VALUE +
3386 (2 * i + 1) * sizeof(u32)) != high)
3387 continue;
3388
3389 qed_wr(p_hwfn, p_ptt,
3390 NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32), 0);
3391 qed_wr(p_hwfn, p_ptt,
3392 NIG_REG_LLH_FUNC_FILTER_VALUE + 2 * i * sizeof(u32), 0);
3393 qed_wr(p_hwfn, p_ptt,
3394 NIG_REG_LLH_FUNC_FILTER_VALUE +
3395 (2 * i + 1) * sizeof(u32), 0);
3396
3397 DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
3398 "mac: %pM is removed from %d\n",
3399 p_filter, i);
3400 break;
3401 }
3402 if (i >= NIG_REG_LLH_FUNC_FILTER_EN_SIZE)
3403 DP_NOTICE(p_hwfn, "Tried to remove a non-configured filter\n");
3404}
3405
Arun Easi1e128c82017-02-15 06:28:22 -08003406int
3407qed_llh_add_protocol_filter(struct qed_hwfn *p_hwfn,
3408 struct qed_ptt *p_ptt,
3409 u16 source_port_or_eth_type,
3410 u16 dest_port, enum qed_llh_port_filter_type_t type)
3411{
3412 u32 high = 0, low = 0, en;
3413 int i;
3414
3415 if (!(IS_MF_SI(p_hwfn) || IS_MF_DEFAULT(p_hwfn)))
3416 return 0;
3417
3418 switch (type) {
3419 case QED_LLH_FILTER_ETHERTYPE:
3420 high = source_port_or_eth_type;
3421 break;
3422 case QED_LLH_FILTER_TCP_SRC_PORT:
3423 case QED_LLH_FILTER_UDP_SRC_PORT:
3424 low = source_port_or_eth_type << 16;
3425 break;
3426 case QED_LLH_FILTER_TCP_DEST_PORT:
3427 case QED_LLH_FILTER_UDP_DEST_PORT:
3428 low = dest_port;
3429 break;
3430 case QED_LLH_FILTER_TCP_SRC_AND_DEST_PORT:
3431 case QED_LLH_FILTER_UDP_SRC_AND_DEST_PORT:
3432 low = (source_port_or_eth_type << 16) | dest_port;
3433 break;
3434 default:
3435 DP_NOTICE(p_hwfn,
3436 "Non valid LLH protocol filter type %d\n", type);
3437 return -EINVAL;
3438 }
3439 /* Find a free entry and utilize it */
3440 for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) {
3441 en = qed_rd(p_hwfn, p_ptt,
3442 NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32));
3443 if (en)
3444 continue;
3445 qed_wr(p_hwfn, p_ptt,
3446 NIG_REG_LLH_FUNC_FILTER_VALUE +
3447 2 * i * sizeof(u32), low);
3448 qed_wr(p_hwfn, p_ptt,
3449 NIG_REG_LLH_FUNC_FILTER_VALUE +
3450 (2 * i + 1) * sizeof(u32), high);
3451 qed_wr(p_hwfn, p_ptt,
3452 NIG_REG_LLH_FUNC_FILTER_MODE + i * sizeof(u32), 1);
3453 qed_wr(p_hwfn, p_ptt,
3454 NIG_REG_LLH_FUNC_FILTER_PROTOCOL_TYPE +
3455 i * sizeof(u32), 1 << type);
3456 qed_wr(p_hwfn, p_ptt,
3457 NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32), 1);
3458 break;
3459 }
3460 if (i >= NIG_REG_LLH_FUNC_FILTER_EN_SIZE) {
3461 DP_NOTICE(p_hwfn,
3462 "Failed to find an empty LLH filter to utilize\n");
3463 return -EINVAL;
3464 }
3465 switch (type) {
3466 case QED_LLH_FILTER_ETHERTYPE:
3467 DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
3468 "ETH type %x is added at %d\n",
3469 source_port_or_eth_type, i);
3470 break;
3471 case QED_LLH_FILTER_TCP_SRC_PORT:
3472 DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
3473 "TCP src port %x is added at %d\n",
3474 source_port_or_eth_type, i);
3475 break;
3476 case QED_LLH_FILTER_UDP_SRC_PORT:
3477 DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
3478 "UDP src port %x is added at %d\n",
3479 source_port_or_eth_type, i);
3480 break;
3481 case QED_LLH_FILTER_TCP_DEST_PORT:
3482 DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
3483 "TCP dst port %x is added at %d\n", dest_port, i);
3484 break;
3485 case QED_LLH_FILTER_UDP_DEST_PORT:
3486 DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
3487 "UDP dst port %x is added at %d\n", dest_port, i);
3488 break;
3489 case QED_LLH_FILTER_TCP_SRC_AND_DEST_PORT:
3490 DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
3491 "TCP src/dst ports %x/%x are added at %d\n",
3492 source_port_or_eth_type, dest_port, i);
3493 break;
3494 case QED_LLH_FILTER_UDP_SRC_AND_DEST_PORT:
3495 DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
3496 "UDP src/dst ports %x/%x are added at %d\n",
3497 source_port_or_eth_type, dest_port, i);
3498 break;
3499 }
3500 return 0;
3501}
3502
3503void
3504qed_llh_remove_protocol_filter(struct qed_hwfn *p_hwfn,
3505 struct qed_ptt *p_ptt,
3506 u16 source_port_or_eth_type,
3507 u16 dest_port,
3508 enum qed_llh_port_filter_type_t type)
3509{
3510 u32 high = 0, low = 0;
3511 int i;
3512
3513 if (!(IS_MF_SI(p_hwfn) || IS_MF_DEFAULT(p_hwfn)))
3514 return;
3515
3516 switch (type) {
3517 case QED_LLH_FILTER_ETHERTYPE:
3518 high = source_port_or_eth_type;
3519 break;
3520 case QED_LLH_FILTER_TCP_SRC_PORT:
3521 case QED_LLH_FILTER_UDP_SRC_PORT:
3522 low = source_port_or_eth_type << 16;
3523 break;
3524 case QED_LLH_FILTER_TCP_DEST_PORT:
3525 case QED_LLH_FILTER_UDP_DEST_PORT:
3526 low = dest_port;
3527 break;
3528 case QED_LLH_FILTER_TCP_SRC_AND_DEST_PORT:
3529 case QED_LLH_FILTER_UDP_SRC_AND_DEST_PORT:
3530 low = (source_port_or_eth_type << 16) | dest_port;
3531 break;
3532 default:
3533 DP_NOTICE(p_hwfn,
3534 "Non valid LLH protocol filter type %d\n", type);
3535 return;
3536 }
3537
3538 for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) {
3539 if (!qed_rd(p_hwfn, p_ptt,
3540 NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32)))
3541 continue;
3542 if (!qed_rd(p_hwfn, p_ptt,
3543 NIG_REG_LLH_FUNC_FILTER_MODE + i * sizeof(u32)))
3544 continue;
3545 if (!(qed_rd(p_hwfn, p_ptt,
3546 NIG_REG_LLH_FUNC_FILTER_PROTOCOL_TYPE +
3547 i * sizeof(u32)) & BIT(type)))
3548 continue;
3549 if (qed_rd(p_hwfn, p_ptt,
3550 NIG_REG_LLH_FUNC_FILTER_VALUE +
3551 2 * i * sizeof(u32)) != low)
3552 continue;
3553 if (qed_rd(p_hwfn, p_ptt,
3554 NIG_REG_LLH_FUNC_FILTER_VALUE +
3555 (2 * i + 1) * sizeof(u32)) != high)
3556 continue;
3557
3558 qed_wr(p_hwfn, p_ptt,
3559 NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32), 0);
3560 qed_wr(p_hwfn, p_ptt,
3561 NIG_REG_LLH_FUNC_FILTER_MODE + i * sizeof(u32), 0);
3562 qed_wr(p_hwfn, p_ptt,
3563 NIG_REG_LLH_FUNC_FILTER_PROTOCOL_TYPE +
3564 i * sizeof(u32), 0);
3565 qed_wr(p_hwfn, p_ptt,
3566 NIG_REG_LLH_FUNC_FILTER_VALUE + 2 * i * sizeof(u32), 0);
3567 qed_wr(p_hwfn, p_ptt,
3568 NIG_REG_LLH_FUNC_FILTER_VALUE +
3569 (2 * i + 1) * sizeof(u32), 0);
3570 break;
3571 }
3572
3573 if (i >= NIG_REG_LLH_FUNC_FILTER_EN_SIZE)
3574 DP_NOTICE(p_hwfn, "Tried to remove a non-configured filter\n");
3575}
3576
Sudarsana Reddy Kalluru722003a2016-06-21 09:36:21 -04003577static int qed_set_coalesce(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
3578 u32 hw_addr, void *p_eth_qzone,
3579 size_t eth_qzone_size, u8 timeset)
3580{
3581 struct coalescing_timeset *p_coal_timeset;
3582
3583 if (p_hwfn->cdev->int_coalescing_mode != QED_COAL_MODE_ENABLE) {
3584 DP_NOTICE(p_hwfn, "Coalescing configuration not enabled\n");
3585 return -EINVAL;
3586 }
3587
3588 p_coal_timeset = p_eth_qzone;
3589 memset(p_coal_timeset, 0, eth_qzone_size);
3590 SET_FIELD(p_coal_timeset->value, COALESCING_TIMESET_TIMESET, timeset);
3591 SET_FIELD(p_coal_timeset->value, COALESCING_TIMESET_VALID, 1);
3592 qed_memcpy_to(p_hwfn, p_ptt, hw_addr, p_eth_qzone, eth_qzone_size);
3593
3594 return 0;
3595}
3596
3597int qed_set_rxq_coalesce(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
sudarsana.kalluru@cavium.comf870a3c2017-05-04 08:15:03 -07003598 u16 coalesce, u16 qid, u16 sb_id)
Sudarsana Reddy Kalluru722003a2016-06-21 09:36:21 -04003599{
3600 struct ustorm_eth_queue_zone eth_qzone;
3601 u8 timeset, timer_res;
3602 u16 fw_qid = 0;
3603 u32 address;
3604 int rc;
3605
3606 /* Coalesce = (timeset << timer-resolution), timeset is 7bit wide */
3607 if (coalesce <= 0x7F) {
3608 timer_res = 0;
3609 } else if (coalesce <= 0xFF) {
3610 timer_res = 1;
3611 } else if (coalesce <= 0x1FF) {
3612 timer_res = 2;
3613 } else {
3614 DP_ERR(p_hwfn, "Invalid coalesce value - %d\n", coalesce);
3615 return -EINVAL;
3616 }
3617 timeset = (u8)(coalesce >> timer_res);
3618
sudarsana.kalluru@cavium.comf870a3c2017-05-04 08:15:03 -07003619 rc = qed_fw_l2_queue(p_hwfn, qid, &fw_qid);
Sudarsana Reddy Kalluru722003a2016-06-21 09:36:21 -04003620 if (rc)
3621 return rc;
3622
3623 rc = qed_int_set_timer_res(p_hwfn, p_ptt, timer_res, sb_id, false);
3624 if (rc)
3625 goto out;
3626
3627 address = BAR0_MAP_REG_USDM_RAM + USTORM_ETH_QUEUE_ZONE_OFFSET(fw_qid);
3628
3629 rc = qed_set_coalesce(p_hwfn, p_ptt, address, &eth_qzone,
3630 sizeof(struct ustorm_eth_queue_zone), timeset);
3631 if (rc)
3632 goto out;
3633
3634 p_hwfn->cdev->rx_coalesce_usecs = coalesce;
3635out:
3636 return rc;
3637}
3638
3639int qed_set_txq_coalesce(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
sudarsana.kalluru@cavium.comf870a3c2017-05-04 08:15:03 -07003640 u16 coalesce, u16 qid, u16 sb_id)
Sudarsana Reddy Kalluru722003a2016-06-21 09:36:21 -04003641{
3642 struct xstorm_eth_queue_zone eth_qzone;
3643 u8 timeset, timer_res;
3644 u16 fw_qid = 0;
3645 u32 address;
3646 int rc;
3647
3648 /* Coalesce = (timeset << timer-resolution), timeset is 7bit wide */
3649 if (coalesce <= 0x7F) {
3650 timer_res = 0;
3651 } else if (coalesce <= 0xFF) {
3652 timer_res = 1;
3653 } else if (coalesce <= 0x1FF) {
3654 timer_res = 2;
3655 } else {
3656 DP_ERR(p_hwfn, "Invalid coalesce value - %d\n", coalesce);
3657 return -EINVAL;
3658 }
3659 timeset = (u8)(coalesce >> timer_res);
3660
sudarsana.kalluru@cavium.comf870a3c2017-05-04 08:15:03 -07003661 rc = qed_fw_l2_queue(p_hwfn, qid, &fw_qid);
Sudarsana Reddy Kalluru722003a2016-06-21 09:36:21 -04003662 if (rc)
3663 return rc;
3664
3665 rc = qed_int_set_timer_res(p_hwfn, p_ptt, timer_res, sb_id, true);
3666 if (rc)
3667 goto out;
3668
3669 address = BAR0_MAP_REG_XSDM_RAM + XSTORM_ETH_QUEUE_ZONE_OFFSET(fw_qid);
3670
3671 rc = qed_set_coalesce(p_hwfn, p_ptt, address, &eth_qzone,
3672 sizeof(struct xstorm_eth_queue_zone), timeset);
3673 if (rc)
3674 goto out;
3675
3676 p_hwfn->cdev->tx_coalesce_usecs = coalesce;
3677out:
3678 return rc;
3679}
3680
Manish Choprabcd197c2016-04-26 10:56:08 -04003681/* Calculate final WFQ values for all vports and configure them.
3682 * After this configuration each vport will have
3683 * approx min rate = min_pf_rate * (vport_wfq / QED_WFQ_UNIT)
3684 */
3685static void qed_configure_wfq_for_all_vports(struct qed_hwfn *p_hwfn,
3686 struct qed_ptt *p_ptt,
3687 u32 min_pf_rate)
3688{
3689 struct init_qm_vport_params *vport_params;
3690 int i;
3691
3692 vport_params = p_hwfn->qm_info.qm_vport_params;
3693
3694 for (i = 0; i < p_hwfn->qm_info.num_vports; i++) {
3695 u32 wfq_speed = p_hwfn->qm_info.wfq_data[i].min_speed;
3696
3697 vport_params[i].vport_wfq = (wfq_speed * QED_WFQ_UNIT) /
3698 min_pf_rate;
3699 qed_init_vport_wfq(p_hwfn, p_ptt,
3700 vport_params[i].first_tx_pq_id,
3701 vport_params[i].vport_wfq);
3702 }
3703}
3704
3705static void qed_init_wfq_default_param(struct qed_hwfn *p_hwfn,
3706 u32 min_pf_rate)
3707
3708{
3709 int i;
3710
3711 for (i = 0; i < p_hwfn->qm_info.num_vports; i++)
3712 p_hwfn->qm_info.qm_vport_params[i].vport_wfq = 1;
3713}
3714
3715static void qed_disable_wfq_for_all_vports(struct qed_hwfn *p_hwfn,
3716 struct qed_ptt *p_ptt,
3717 u32 min_pf_rate)
3718{
3719 struct init_qm_vport_params *vport_params;
3720 int i;
3721
3722 vport_params = p_hwfn->qm_info.qm_vport_params;
3723
3724 for (i = 0; i < p_hwfn->qm_info.num_vports; i++) {
3725 qed_init_wfq_default_param(p_hwfn, min_pf_rate);
3726 qed_init_vport_wfq(p_hwfn, p_ptt,
3727 vport_params[i].first_tx_pq_id,
3728 vport_params[i].vport_wfq);
3729 }
3730}
3731
3732/* This function performs several validations for WFQ
3733 * configuration and required min rate for a given vport
3734 * 1. req_rate must be greater than one percent of min_pf_rate.
3735 * 2. req_rate should not cause other vports [not configured for WFQ explicitly]
3736 * rates to get less than one percent of min_pf_rate.
3737 * 3. total_req_min_rate [all vports min rate sum] shouldn't exceed min_pf_rate.
3738 */
3739static int qed_init_wfq_param(struct qed_hwfn *p_hwfn,
Yuval Mintz1a635e42016-08-15 10:42:43 +03003740 u16 vport_id, u32 req_rate, u32 min_pf_rate)
Manish Choprabcd197c2016-04-26 10:56:08 -04003741{
3742 u32 total_req_min_rate = 0, total_left_rate = 0, left_rate_per_vp = 0;
3743 int non_requested_count = 0, req_count = 0, i, num_vports;
3744
3745 num_vports = p_hwfn->qm_info.num_vports;
3746
3747 /* Accounting for the vports which are configured for WFQ explicitly */
3748 for (i = 0; i < num_vports; i++) {
3749 u32 tmp_speed;
3750
3751 if ((i != vport_id) &&
3752 p_hwfn->qm_info.wfq_data[i].configured) {
3753 req_count++;
3754 tmp_speed = p_hwfn->qm_info.wfq_data[i].min_speed;
3755 total_req_min_rate += tmp_speed;
3756 }
3757 }
3758
3759 /* Include current vport data as well */
3760 req_count++;
3761 total_req_min_rate += req_rate;
3762 non_requested_count = num_vports - req_count;
3763
3764 if (req_rate < min_pf_rate / QED_WFQ_UNIT) {
3765 DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
3766 "Vport [%d] - Requested rate[%d Mbps] is less than one percent of configured PF min rate[%d Mbps]\n",
3767 vport_id, req_rate, min_pf_rate);
3768 return -EINVAL;
3769 }
3770
3771 if (num_vports > QED_WFQ_UNIT) {
3772 DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
3773 "Number of vports is greater than %d\n",
3774 QED_WFQ_UNIT);
3775 return -EINVAL;
3776 }
3777
3778 if (total_req_min_rate > min_pf_rate) {
3779 DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
3780 "Total requested min rate for all vports[%d Mbps] is greater than configured PF min rate[%d Mbps]\n",
3781 total_req_min_rate, min_pf_rate);
3782 return -EINVAL;
3783 }
3784
3785 total_left_rate = min_pf_rate - total_req_min_rate;
3786
3787 left_rate_per_vp = total_left_rate / non_requested_count;
3788 if (left_rate_per_vp < min_pf_rate / QED_WFQ_UNIT) {
3789 DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
3790 "Non WFQ configured vports rate [%d Mbps] is less than one percent of configured PF min rate[%d Mbps]\n",
3791 left_rate_per_vp, min_pf_rate);
3792 return -EINVAL;
3793 }
3794
3795 p_hwfn->qm_info.wfq_data[vport_id].min_speed = req_rate;
3796 p_hwfn->qm_info.wfq_data[vport_id].configured = true;
3797
3798 for (i = 0; i < num_vports; i++) {
3799 if (p_hwfn->qm_info.wfq_data[i].configured)
3800 continue;
3801
3802 p_hwfn->qm_info.wfq_data[i].min_speed = left_rate_per_vp;
3803 }
3804
3805 return 0;
3806}
3807
Yuval Mintz733def62016-05-11 16:36:22 +03003808static int __qed_configure_vport_wfq(struct qed_hwfn *p_hwfn,
3809 struct qed_ptt *p_ptt, u16 vp_id, u32 rate)
3810{
3811 struct qed_mcp_link_state *p_link;
3812 int rc = 0;
3813
3814 p_link = &p_hwfn->cdev->hwfns[0].mcp_info->link_output;
3815
3816 if (!p_link->min_pf_rate) {
3817 p_hwfn->qm_info.wfq_data[vp_id].min_speed = rate;
3818 p_hwfn->qm_info.wfq_data[vp_id].configured = true;
3819 return rc;
3820 }
3821
3822 rc = qed_init_wfq_param(p_hwfn, vp_id, rate, p_link->min_pf_rate);
3823
Yuval Mintz1a635e42016-08-15 10:42:43 +03003824 if (!rc)
Yuval Mintz733def62016-05-11 16:36:22 +03003825 qed_configure_wfq_for_all_vports(p_hwfn, p_ptt,
3826 p_link->min_pf_rate);
3827 else
3828 DP_NOTICE(p_hwfn,
3829 "Validation failed while configuring min rate\n");
3830
3831 return rc;
3832}
3833
Manish Choprabcd197c2016-04-26 10:56:08 -04003834static int __qed_configure_vp_wfq_on_link_change(struct qed_hwfn *p_hwfn,
3835 struct qed_ptt *p_ptt,
3836 u32 min_pf_rate)
3837{
3838 bool use_wfq = false;
3839 int rc = 0;
3840 u16 i;
3841
3842 /* Validate all pre configured vports for wfq */
3843 for (i = 0; i < p_hwfn->qm_info.num_vports; i++) {
3844 u32 rate;
3845
3846 if (!p_hwfn->qm_info.wfq_data[i].configured)
3847 continue;
3848
3849 rate = p_hwfn->qm_info.wfq_data[i].min_speed;
3850 use_wfq = true;
3851
3852 rc = qed_init_wfq_param(p_hwfn, i, rate, min_pf_rate);
3853 if (rc) {
3854 DP_NOTICE(p_hwfn,
3855 "WFQ validation failed while configuring min rate\n");
3856 break;
3857 }
3858 }
3859
3860 if (!rc && use_wfq)
3861 qed_configure_wfq_for_all_vports(p_hwfn, p_ptt, min_pf_rate);
3862 else
3863 qed_disable_wfq_for_all_vports(p_hwfn, p_ptt, min_pf_rate);
3864
3865 return rc;
3866}
3867
Yuval Mintz733def62016-05-11 16:36:22 +03003868/* Main API for qed clients to configure vport min rate.
3869 * vp_id - vport id in PF Range[0 - (total_num_vports_per_pf - 1)]
3870 * rate - Speed in Mbps needs to be assigned to a given vport.
3871 */
3872int qed_configure_vport_wfq(struct qed_dev *cdev, u16 vp_id, u32 rate)
3873{
3874 int i, rc = -EINVAL;
3875
3876 /* Currently not supported; Might change in future */
3877 if (cdev->num_hwfns > 1) {
3878 DP_NOTICE(cdev,
3879 "WFQ configuration is not supported for this device\n");
3880 return rc;
3881 }
3882
3883 for_each_hwfn(cdev, i) {
3884 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
3885 struct qed_ptt *p_ptt;
3886
3887 p_ptt = qed_ptt_acquire(p_hwfn);
3888 if (!p_ptt)
3889 return -EBUSY;
3890
3891 rc = __qed_configure_vport_wfq(p_hwfn, p_ptt, vp_id, rate);
3892
Yuval Mintzd572c432016-07-27 14:45:23 +03003893 if (rc) {
Yuval Mintz733def62016-05-11 16:36:22 +03003894 qed_ptt_release(p_hwfn, p_ptt);
3895 return rc;
3896 }
3897
3898 qed_ptt_release(p_hwfn, p_ptt);
3899 }
3900
3901 return rc;
3902}
3903
Manish Choprabcd197c2016-04-26 10:56:08 -04003904/* API to configure WFQ from mcp link change */
Mintz, Yuval6f437d42017-02-27 11:06:33 +02003905void qed_configure_vp_wfq_on_link_change(struct qed_dev *cdev,
3906 struct qed_ptt *p_ptt, u32 min_pf_rate)
Manish Choprabcd197c2016-04-26 10:56:08 -04003907{
3908 int i;
3909
Yuval Mintz3e7cfce2016-05-26 11:01:24 +03003910 if (cdev->num_hwfns > 1) {
3911 DP_VERBOSE(cdev,
3912 NETIF_MSG_LINK,
3913 "WFQ configuration is not supported for this device\n");
3914 return;
3915 }
3916
Manish Choprabcd197c2016-04-26 10:56:08 -04003917 for_each_hwfn(cdev, i) {
3918 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
3919
Mintz, Yuval6f437d42017-02-27 11:06:33 +02003920 __qed_configure_vp_wfq_on_link_change(p_hwfn, p_ptt,
Manish Choprabcd197c2016-04-26 10:56:08 -04003921 min_pf_rate);
3922 }
3923}
Manish Chopra4b01e512016-04-26 10:56:09 -04003924
3925int __qed_configure_pf_max_bandwidth(struct qed_hwfn *p_hwfn,
3926 struct qed_ptt *p_ptt,
3927 struct qed_mcp_link_state *p_link,
3928 u8 max_bw)
3929{
3930 int rc = 0;
3931
3932 p_hwfn->mcp_info->func_info.bandwidth_max = max_bw;
3933
3934 if (!p_link->line_speed && (max_bw != 100))
3935 return rc;
3936
3937 p_link->speed = (p_link->line_speed * max_bw) / 100;
3938 p_hwfn->qm_info.pf_rl = p_link->speed;
3939
3940 /* Since the limiter also affects Tx-switched traffic, we don't want it
3941 * to limit such traffic in case there's no actual limit.
3942 * In that case, set limit to imaginary high boundary.
3943 */
3944 if (max_bw == 100)
3945 p_hwfn->qm_info.pf_rl = 100000;
3946
3947 rc = qed_init_pf_rl(p_hwfn, p_ptt, p_hwfn->rel_pf_id,
3948 p_hwfn->qm_info.pf_rl);
3949
3950 DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
3951 "Configured MAX bandwidth to be %08x Mb/sec\n",
3952 p_link->speed);
3953
3954 return rc;
3955}
3956
3957/* Main API to configure PF max bandwidth where bw range is [1 - 100] */
3958int qed_configure_pf_max_bandwidth(struct qed_dev *cdev, u8 max_bw)
3959{
3960 int i, rc = -EINVAL;
3961
3962 if (max_bw < 1 || max_bw > 100) {
3963 DP_NOTICE(cdev, "PF max bw valid range is [1-100]\n");
3964 return rc;
3965 }
3966
3967 for_each_hwfn(cdev, i) {
3968 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
3969 struct qed_hwfn *p_lead = QED_LEADING_HWFN(cdev);
3970 struct qed_mcp_link_state *p_link;
3971 struct qed_ptt *p_ptt;
3972
3973 p_link = &p_lead->mcp_info->link_output;
3974
3975 p_ptt = qed_ptt_acquire(p_hwfn);
3976 if (!p_ptt)
3977 return -EBUSY;
3978
3979 rc = __qed_configure_pf_max_bandwidth(p_hwfn, p_ptt,
3980 p_link, max_bw);
3981
3982 qed_ptt_release(p_hwfn, p_ptt);
3983
3984 if (rc)
3985 break;
3986 }
3987
3988 return rc;
3989}
Manish Chopraa64b02d2016-04-26 10:56:10 -04003990
3991int __qed_configure_pf_min_bandwidth(struct qed_hwfn *p_hwfn,
3992 struct qed_ptt *p_ptt,
3993 struct qed_mcp_link_state *p_link,
3994 u8 min_bw)
3995{
3996 int rc = 0;
3997
3998 p_hwfn->mcp_info->func_info.bandwidth_min = min_bw;
3999 p_hwfn->qm_info.pf_wfq = min_bw;
4000
4001 if (!p_link->line_speed)
4002 return rc;
4003
4004 p_link->min_pf_rate = (p_link->line_speed * min_bw) / 100;
4005
4006 rc = qed_init_pf_wfq(p_hwfn, p_ptt, p_hwfn->rel_pf_id, min_bw);
4007
4008 DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
4009 "Configured MIN bandwidth to be %d Mb/sec\n",
4010 p_link->min_pf_rate);
4011
4012 return rc;
4013}
4014
4015/* Main API to configure PF min bandwidth where bw range is [1-100] */
4016int qed_configure_pf_min_bandwidth(struct qed_dev *cdev, u8 min_bw)
4017{
4018 int i, rc = -EINVAL;
4019
4020 if (min_bw < 1 || min_bw > 100) {
4021 DP_NOTICE(cdev, "PF min bw valid range is [1-100]\n");
4022 return rc;
4023 }
4024
4025 for_each_hwfn(cdev, i) {
4026 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
4027 struct qed_hwfn *p_lead = QED_LEADING_HWFN(cdev);
4028 struct qed_mcp_link_state *p_link;
4029 struct qed_ptt *p_ptt;
4030
4031 p_link = &p_lead->mcp_info->link_output;
4032
4033 p_ptt = qed_ptt_acquire(p_hwfn);
4034 if (!p_ptt)
4035 return -EBUSY;
4036
4037 rc = __qed_configure_pf_min_bandwidth(p_hwfn, p_ptt,
4038 p_link, min_bw);
4039 if (rc) {
4040 qed_ptt_release(p_hwfn, p_ptt);
4041 return rc;
4042 }
4043
4044 if (p_link->min_pf_rate) {
4045 u32 min_rate = p_link->min_pf_rate;
4046
4047 rc = __qed_configure_vp_wfq_on_link_change(p_hwfn,
4048 p_ptt,
4049 min_rate);
4050 }
4051
4052 qed_ptt_release(p_hwfn, p_ptt);
4053 }
4054
4055 return rc;
4056}
Yuval Mintz733def62016-05-11 16:36:22 +03004057
4058void qed_clean_wfq_db(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
4059{
4060 struct qed_mcp_link_state *p_link;
4061
4062 p_link = &p_hwfn->mcp_info->link_output;
4063
4064 if (p_link->min_pf_rate)
4065 qed_disable_wfq_for_all_vports(p_hwfn, p_ptt,
4066 p_link->min_pf_rate);
4067
4068 memset(p_hwfn->qm_info.wfq_data, 0,
4069 sizeof(*p_hwfn->qm_info.wfq_data) * p_hwfn->qm_info.num_vports);
4070}
Mintz, Yuval9c79dda2017-03-14 16:23:54 +02004071
4072int qed_device_num_engines(struct qed_dev *cdev)
4073{
4074 return QED_IS_BB(cdev) ? 2 : 1;
4075}
sudarsana.kalluru@cavium.comdb82f702017-04-26 09:00:50 -07004076
4077static int qed_device_num_ports(struct qed_dev *cdev)
4078{
4079 /* in CMT always only one port */
4080 if (cdev->num_hwfns > 1)
4081 return 1;
4082
Tomer Tayar78cea9f2017-05-23 09:41:22 +03004083 return cdev->num_ports_in_engine * qed_device_num_engines(cdev);
sudarsana.kalluru@cavium.comdb82f702017-04-26 09:00:50 -07004084}
4085
4086int qed_device_get_port_id(struct qed_dev *cdev)
4087{
4088 return (QED_LEADING_HWFN(cdev)->abs_pf_id) % qed_device_num_ports(cdev);
4089}