1*4ad79e13SYuval Mintz /* bnx2x_init.h: Qlogic Everest network driver.
2adfc5217SJeff Kirsher * Structures and macroes needed during the initialization.
3adfc5217SJeff Kirsher *
4247fa82bSYuval Mintz * Copyright (c) 2007-2013 Broadcom Corporation
5*4ad79e13SYuval Mintz * Copyright (c) 2014 QLogic Corporation
6*4ad79e13SYuval Mintz All rights reserved
7adfc5217SJeff Kirsher *
8adfc5217SJeff Kirsher * This program is free software; you can redistribute it and/or modify
9adfc5217SJeff Kirsher * it under the terms of the GNU General Public License as published by
10adfc5217SJeff Kirsher * the Free Software Foundation.
11adfc5217SJeff Kirsher *
1208f6dd89SAriel Elior * Maintained by: Ariel Elior <ariel.elior@qlogic.com>
13adfc5217SJeff Kirsher * Written by: Eliezer Tamir
1408f6dd89SAriel Elior * Modified by: Vladislav Zolotarov
15adfc5217SJeff Kirsher */
16adfc5217SJeff Kirsher
17adfc5217SJeff Kirsher #ifndef BNX2X_INIT_H
18adfc5217SJeff Kirsher #define BNX2X_INIT_H
19adfc5217SJeff Kirsher
20adfc5217SJeff Kirsher /* Init operation types and structures */
21adfc5217SJeff Kirsher enum {
22adfc5217SJeff Kirsher OP_RD = 0x1, /* read a single register */
23adfc5217SJeff Kirsher OP_WR, /* write a single register */
24adfc5217SJeff Kirsher OP_SW, /* copy a string to the device */
25adfc5217SJeff Kirsher OP_ZR, /* clear memory */
26adfc5217SJeff Kirsher OP_ZP, /* unzip then copy with DMAE */
27adfc5217SJeff Kirsher OP_WR_64, /* write 64 bit pattern */
28adfc5217SJeff Kirsher OP_WB, /* copy a string using DMAE */
29adfc5217SJeff Kirsher OP_WB_ZR, /* Clear a string using DMAE or indirect-wr */
30adfc5217SJeff Kirsher /* Skip the following ops if all of the init modes don't match */
31adfc5217SJeff Kirsher OP_IF_MODE_OR,
32adfc5217SJeff Kirsher /* Skip the following ops if any of the init modes don't match */
33adfc5217SJeff Kirsher OP_IF_MODE_AND,
34adfc5217SJeff Kirsher OP_MAX
35adfc5217SJeff Kirsher };
36adfc5217SJeff Kirsher
37adfc5217SJeff Kirsher enum {
38adfc5217SJeff Kirsher STAGE_START,
39adfc5217SJeff Kirsher STAGE_END,
40adfc5217SJeff Kirsher };
41adfc5217SJeff Kirsher
42adfc5217SJeff Kirsher /* Returns the index of start or end of a specific block stage in ops array*/
43adfc5217SJeff Kirsher #define BLOCK_OPS_IDX(block, stage, end) \
44adfc5217SJeff Kirsher (2*(((block)*NUM_OF_INIT_PHASES) + (stage)) + (end))
45adfc5217SJeff Kirsher
46adfc5217SJeff Kirsher
47adfc5217SJeff Kirsher /* structs for the various opcodes */
48adfc5217SJeff Kirsher struct raw_op {
49adfc5217SJeff Kirsher u32 op:8;
50adfc5217SJeff Kirsher u32 offset:24;
51adfc5217SJeff Kirsher u32 raw_data;
52adfc5217SJeff Kirsher };
53adfc5217SJeff Kirsher
54adfc5217SJeff Kirsher struct op_read {
55adfc5217SJeff Kirsher u32 op:8;
56adfc5217SJeff Kirsher u32 offset:24;
57adfc5217SJeff Kirsher u32 val;
58adfc5217SJeff Kirsher };
59adfc5217SJeff Kirsher
60adfc5217SJeff Kirsher struct op_write {
61adfc5217SJeff Kirsher u32 op:8;
62adfc5217SJeff Kirsher u32 offset:24;
63adfc5217SJeff Kirsher u32 val;
64adfc5217SJeff Kirsher };
65adfc5217SJeff Kirsher
66adfc5217SJeff Kirsher struct op_arr_write {
67adfc5217SJeff Kirsher u32 op:8;
68adfc5217SJeff Kirsher u32 offset:24;
69adfc5217SJeff Kirsher #ifdef __BIG_ENDIAN
70adfc5217SJeff Kirsher u16 data_len;
71adfc5217SJeff Kirsher u16 data_off;
72adfc5217SJeff Kirsher #else /* __LITTLE_ENDIAN */
73adfc5217SJeff Kirsher u16 data_off;
74adfc5217SJeff Kirsher u16 data_len;
75adfc5217SJeff Kirsher #endif
76adfc5217SJeff Kirsher };
77adfc5217SJeff Kirsher
78adfc5217SJeff Kirsher struct op_zero {
79adfc5217SJeff Kirsher u32 op:8;
80adfc5217SJeff Kirsher u32 offset:24;
81adfc5217SJeff Kirsher u32 len;
82adfc5217SJeff Kirsher };
83adfc5217SJeff Kirsher
84adfc5217SJeff Kirsher struct op_if_mode {
85adfc5217SJeff Kirsher u32 op:8;
86adfc5217SJeff Kirsher u32 cmd_offset:24;
87adfc5217SJeff Kirsher u32 mode_bit_map;
88adfc5217SJeff Kirsher };
89adfc5217SJeff Kirsher
90adfc5217SJeff Kirsher
91adfc5217SJeff Kirsher union init_op {
92adfc5217SJeff Kirsher struct op_read read;
93adfc5217SJeff Kirsher struct op_write write;
94adfc5217SJeff Kirsher struct op_arr_write arr_wr;
95adfc5217SJeff Kirsher struct op_zero zero;
96adfc5217SJeff Kirsher struct raw_op raw;
97adfc5217SJeff Kirsher struct op_if_mode if_mode;
98adfc5217SJeff Kirsher };
99adfc5217SJeff Kirsher
100adfc5217SJeff Kirsher
101adfc5217SJeff Kirsher /* Init Phases */
102adfc5217SJeff Kirsher enum {
103adfc5217SJeff Kirsher PHASE_COMMON,
104adfc5217SJeff Kirsher PHASE_PORT0,
105adfc5217SJeff Kirsher PHASE_PORT1,
106adfc5217SJeff Kirsher PHASE_PF0,
107adfc5217SJeff Kirsher PHASE_PF1,
108adfc5217SJeff Kirsher PHASE_PF2,
109adfc5217SJeff Kirsher PHASE_PF3,
110adfc5217SJeff Kirsher PHASE_PF4,
111adfc5217SJeff Kirsher PHASE_PF5,
112adfc5217SJeff Kirsher PHASE_PF6,
113adfc5217SJeff Kirsher PHASE_PF7,
114adfc5217SJeff Kirsher NUM_OF_INIT_PHASES
115adfc5217SJeff Kirsher };
116adfc5217SJeff Kirsher
117adfc5217SJeff Kirsher /* Init Modes */
118adfc5217SJeff Kirsher enum {
119adfc5217SJeff Kirsher MODE_ASIC = 0x00000001,
120adfc5217SJeff Kirsher MODE_FPGA = 0x00000002,
121adfc5217SJeff Kirsher MODE_EMUL = 0x00000004,
122adfc5217SJeff Kirsher MODE_E2 = 0x00000008,
123adfc5217SJeff Kirsher MODE_E3 = 0x00000010,
124adfc5217SJeff Kirsher MODE_PORT2 = 0x00000020,
125adfc5217SJeff Kirsher MODE_PORT4 = 0x00000040,
126adfc5217SJeff Kirsher MODE_SF = 0x00000080,
127adfc5217SJeff Kirsher MODE_MF = 0x00000100,
128adfc5217SJeff Kirsher MODE_MF_SD = 0x00000200,
129adfc5217SJeff Kirsher MODE_MF_SI = 0x00000400,
130a3348722SBarak Witkowski MODE_MF_AFEX = 0x00000800,
131adfc5217SJeff Kirsher MODE_E3_A0 = 0x00001000,
132adfc5217SJeff Kirsher MODE_E3_B0 = 0x00002000,
133adfc5217SJeff Kirsher MODE_COS3 = 0x00004000,
134adfc5217SJeff Kirsher MODE_COS6 = 0x00008000,
135adfc5217SJeff Kirsher MODE_LITTLE_ENDIAN = 0x00010000,
136adfc5217SJeff Kirsher MODE_BIG_ENDIAN = 0x00020000,
137adfc5217SJeff Kirsher };
138adfc5217SJeff Kirsher
139adfc5217SJeff Kirsher /* Init Blocks */
140adfc5217SJeff Kirsher enum {
141adfc5217SJeff Kirsher BLOCK_ATC,
142adfc5217SJeff Kirsher BLOCK_BRB1,
143adfc5217SJeff Kirsher BLOCK_CCM,
144adfc5217SJeff Kirsher BLOCK_CDU,
145adfc5217SJeff Kirsher BLOCK_CFC,
146adfc5217SJeff Kirsher BLOCK_CSDM,
147adfc5217SJeff Kirsher BLOCK_CSEM,
148adfc5217SJeff Kirsher BLOCK_DBG,
149adfc5217SJeff Kirsher BLOCK_DMAE,
150adfc5217SJeff Kirsher BLOCK_DORQ,
151adfc5217SJeff Kirsher BLOCK_HC,
152adfc5217SJeff Kirsher BLOCK_IGU,
153adfc5217SJeff Kirsher BLOCK_MISC,
154adfc5217SJeff Kirsher BLOCK_NIG,
155adfc5217SJeff Kirsher BLOCK_PBF,
156adfc5217SJeff Kirsher BLOCK_PGLUE_B,
157adfc5217SJeff Kirsher BLOCK_PRS,
158adfc5217SJeff Kirsher BLOCK_PXP2,
159adfc5217SJeff Kirsher BLOCK_PXP,
160adfc5217SJeff Kirsher BLOCK_QM,
161adfc5217SJeff Kirsher BLOCK_SRC,
162adfc5217SJeff Kirsher BLOCK_TCM,
163adfc5217SJeff Kirsher BLOCK_TM,
164adfc5217SJeff Kirsher BLOCK_TSDM,
165adfc5217SJeff Kirsher BLOCK_TSEM,
166adfc5217SJeff Kirsher BLOCK_UCM,
167adfc5217SJeff Kirsher BLOCK_UPB,
168adfc5217SJeff Kirsher BLOCK_USDM,
169adfc5217SJeff Kirsher BLOCK_USEM,
170adfc5217SJeff Kirsher BLOCK_XCM,
171adfc5217SJeff Kirsher BLOCK_XPB,
172adfc5217SJeff Kirsher BLOCK_XSDM,
173adfc5217SJeff Kirsher BLOCK_XSEM,
174adfc5217SJeff Kirsher BLOCK_MISC_AEU,
175adfc5217SJeff Kirsher NUM_OF_INIT_BLOCKS
176adfc5217SJeff Kirsher };
177adfc5217SJeff Kirsher
178adfc5217SJeff Kirsher /* QM queue numbers */
179adfc5217SJeff Kirsher #define BNX2X_ETH_Q 0
180adfc5217SJeff Kirsher #define BNX2X_TOE_Q 3
181adfc5217SJeff Kirsher #define BNX2X_TOE_ACK_Q 6
182adfc5217SJeff Kirsher #define BNX2X_ISCSI_Q 9
183adfc5217SJeff Kirsher #define BNX2X_ISCSI_ACK_Q 11
184adfc5217SJeff Kirsher #define BNX2X_FCOE_Q 10
185adfc5217SJeff Kirsher
186adfc5217SJeff Kirsher /* Vnics per mode */
187adfc5217SJeff Kirsher #define BNX2X_PORT2_MODE_NUM_VNICS 4
188adfc5217SJeff Kirsher #define BNX2X_PORT4_MODE_NUM_VNICS 2
189adfc5217SJeff Kirsher
190adfc5217SJeff Kirsher /* COS offset for port1 in E3 B0 4port mode */
191adfc5217SJeff Kirsher #define BNX2X_E3B0_PORT1_COS_OFFSET 3
192adfc5217SJeff Kirsher
193adfc5217SJeff Kirsher /* QM Register addresses */
194adfc5217SJeff Kirsher #define BNX2X_Q_VOQ_REG_ADDR(pf_q_num)\
195adfc5217SJeff Kirsher (QM_REG_QVOQIDX_0 + 4 * (pf_q_num))
196adfc5217SJeff Kirsher #define BNX2X_VOQ_Q_REG_ADDR(cos, pf_q_num)\
197adfc5217SJeff Kirsher (QM_REG_VOQQMASK_0_LSB + 4 * ((cos) * 2 + ((pf_q_num) >> 5)))
198adfc5217SJeff Kirsher #define BNX2X_Q_CMDQ_REG_ADDR(pf_q_num)\
199adfc5217SJeff Kirsher (QM_REG_BYTECRDCMDQ_0 + 4 * ((pf_q_num) >> 4))
200adfc5217SJeff Kirsher
201adfc5217SJeff Kirsher /* extracts the QM queue number for the specified port and vnic */
202adfc5217SJeff Kirsher #define BNX2X_PF_Q_NUM(q_num, port, vnic)\
203adfc5217SJeff Kirsher ((((port) << 1) | (vnic)) * 16 + (q_num))
204adfc5217SJeff Kirsher
205adfc5217SJeff Kirsher
206adfc5217SJeff Kirsher /* Maps the specified queue to the specified COS */
bnx2x_map_q_cos(struct bnx2x * bp,u32 q_num,u32 new_cos)207adfc5217SJeff Kirsher static inline void bnx2x_map_q_cos(struct bnx2x *bp, u32 q_num, u32 new_cos)
208adfc5217SJeff Kirsher {
209adfc5217SJeff Kirsher /* find current COS mapping */
210adfc5217SJeff Kirsher u32 curr_cos = REG_RD(bp, QM_REG_QVOQIDX_0 + q_num * 4);
211adfc5217SJeff Kirsher
212adfc5217SJeff Kirsher /* check if queue->COS mapping has changed */
213adfc5217SJeff Kirsher if (curr_cos != new_cos) {
214adfc5217SJeff Kirsher u32 num_vnics = BNX2X_PORT2_MODE_NUM_VNICS;
215adfc5217SJeff Kirsher u32 reg_addr, reg_bit_map, vnic;
216adfc5217SJeff Kirsher
217adfc5217SJeff Kirsher /* update parameters for 4port mode */
218adfc5217SJeff Kirsher if (INIT_MODE_FLAGS(bp) & MODE_PORT4) {
219adfc5217SJeff Kirsher num_vnics = BNX2X_PORT4_MODE_NUM_VNICS;
220adfc5217SJeff Kirsher if (BP_PORT(bp)) {
221adfc5217SJeff Kirsher curr_cos += BNX2X_E3B0_PORT1_COS_OFFSET;
222adfc5217SJeff Kirsher new_cos += BNX2X_E3B0_PORT1_COS_OFFSET;
223adfc5217SJeff Kirsher }
224adfc5217SJeff Kirsher }
225adfc5217SJeff Kirsher
226adfc5217SJeff Kirsher /* change queue mapping for each VNIC */
227adfc5217SJeff Kirsher for (vnic = 0; vnic < num_vnics; vnic++) {
228adfc5217SJeff Kirsher u32 pf_q_num =
229adfc5217SJeff Kirsher BNX2X_PF_Q_NUM(q_num, BP_PORT(bp), vnic);
230adfc5217SJeff Kirsher u32 q_bit_map = 1 << (pf_q_num & 0x1f);
231adfc5217SJeff Kirsher
232adfc5217SJeff Kirsher /* overwrite queue->VOQ mapping */
233adfc5217SJeff Kirsher REG_WR(bp, BNX2X_Q_VOQ_REG_ADDR(pf_q_num), new_cos);
234adfc5217SJeff Kirsher
235adfc5217SJeff Kirsher /* clear queue bit from current COS bit map */
236adfc5217SJeff Kirsher reg_addr = BNX2X_VOQ_Q_REG_ADDR(curr_cos, pf_q_num);
237adfc5217SJeff Kirsher reg_bit_map = REG_RD(bp, reg_addr);
238adfc5217SJeff Kirsher REG_WR(bp, reg_addr, reg_bit_map & (~q_bit_map));
239adfc5217SJeff Kirsher
240adfc5217SJeff Kirsher /* set queue bit in new COS bit map */
241adfc5217SJeff Kirsher reg_addr = BNX2X_VOQ_Q_REG_ADDR(new_cos, pf_q_num);
242adfc5217SJeff Kirsher reg_bit_map = REG_RD(bp, reg_addr);
243adfc5217SJeff Kirsher REG_WR(bp, reg_addr, reg_bit_map | q_bit_map);
244adfc5217SJeff Kirsher
245adfc5217SJeff Kirsher /* set/clear queue bit in command-queue bit map
246b475d78fSYuval Mintz * (E2/E3A0 only, valid COS values are 0/1)
247b475d78fSYuval Mintz */
248adfc5217SJeff Kirsher if (!(INIT_MODE_FLAGS(bp) & MODE_E3_B0)) {
249adfc5217SJeff Kirsher reg_addr = BNX2X_Q_CMDQ_REG_ADDR(pf_q_num);
250adfc5217SJeff Kirsher reg_bit_map = REG_RD(bp, reg_addr);
251adfc5217SJeff Kirsher q_bit_map = 1 << (2 * (pf_q_num & 0xf));
252adfc5217SJeff Kirsher reg_bit_map = new_cos ?
253adfc5217SJeff Kirsher (reg_bit_map | q_bit_map) :
254adfc5217SJeff Kirsher (reg_bit_map & (~q_bit_map));
255adfc5217SJeff Kirsher REG_WR(bp, reg_addr, reg_bit_map);
256adfc5217SJeff Kirsher }
257adfc5217SJeff Kirsher }
258adfc5217SJeff Kirsher }
259adfc5217SJeff Kirsher }
260adfc5217SJeff Kirsher
261adfc5217SJeff Kirsher /* Configures the QM according to the specified per-traffic-type COSes */
bnx2x_dcb_config_qm(struct bnx2x * bp,enum cos_mode mode,struct priority_cos * traffic_cos)262adfc5217SJeff Kirsher static inline void bnx2x_dcb_config_qm(struct bnx2x *bp, enum cos_mode mode,
263adfc5217SJeff Kirsher struct priority_cos *traffic_cos)
264adfc5217SJeff Kirsher {
265adfc5217SJeff Kirsher bnx2x_map_q_cos(bp, BNX2X_FCOE_Q,
266adfc5217SJeff Kirsher traffic_cos[LLFC_TRAFFIC_TYPE_FCOE].cos);
267adfc5217SJeff Kirsher bnx2x_map_q_cos(bp, BNX2X_ISCSI_Q,
268adfc5217SJeff Kirsher traffic_cos[LLFC_TRAFFIC_TYPE_ISCSI].cos);
269adfc5217SJeff Kirsher bnx2x_map_q_cos(bp, BNX2X_ISCSI_ACK_Q,
270adfc5217SJeff Kirsher traffic_cos[LLFC_TRAFFIC_TYPE_ISCSI].cos);
271adfc5217SJeff Kirsher if (mode != STATIC_COS) {
272adfc5217SJeff Kirsher /* required only in backward compatible COS mode */
273adfc5217SJeff Kirsher bnx2x_map_q_cos(bp, BNX2X_ETH_Q,
274adfc5217SJeff Kirsher traffic_cos[LLFC_TRAFFIC_TYPE_NW].cos);
275adfc5217SJeff Kirsher bnx2x_map_q_cos(bp, BNX2X_TOE_Q,
276adfc5217SJeff Kirsher traffic_cos[LLFC_TRAFFIC_TYPE_NW].cos);
277adfc5217SJeff Kirsher bnx2x_map_q_cos(bp, BNX2X_TOE_ACK_Q,
278adfc5217SJeff Kirsher traffic_cos[LLFC_TRAFFIC_TYPE_NW].cos);
279adfc5217SJeff Kirsher }
280adfc5217SJeff Kirsher }
281adfc5217SJeff Kirsher
282adfc5217SJeff Kirsher
283dbedd44eSJoe Perches /* congestion management port init api description
284b475d78fSYuval Mintz * the api works as follows:
285b475d78fSYuval Mintz * the driver should pass the cmng_init_input struct, the port_init function
286b475d78fSYuval Mintz * will prepare the required internal ram structure which will be passed back
287b475d78fSYuval Mintz * to the driver (cmng_init) that will write it into the internal ram.
288b475d78fSYuval Mintz *
289b475d78fSYuval Mintz * IMPORTANT REMARKS:
290b475d78fSYuval Mintz * 1. the cmng_init struct does not represent the contiguous internal ram
291b475d78fSYuval Mintz * structure. the driver should use the XSTORM_CMNG_PERPORT_VARS_OFFSET
292b475d78fSYuval Mintz * offset in order to write the port sub struct and the
293b475d78fSYuval Mintz * PFID_FROM_PORT_AND_VNIC offset for writing the vnic sub struct (in other
294b475d78fSYuval Mintz * words - don't use memcpy!).
295b475d78fSYuval Mintz * 2. although the cmng_init struct is filled for the maximal vnic number
296b475d78fSYuval Mintz * possible, the driver should only write the valid vnics into the internal
297b475d78fSYuval Mintz * ram according to the appropriate port mode.
298b475d78fSYuval Mintz */
299b475d78fSYuval Mintz
300b475d78fSYuval Mintz /* CMNG constants, as derived from system spec calculations */
301b475d78fSYuval Mintz
302b475d78fSYuval Mintz /* default MIN rate in case VNIC min rate is configured to zero- 100Mbps */
303b475d78fSYuval Mintz #define DEF_MIN_RATE 100
304b475d78fSYuval Mintz
305b475d78fSYuval Mintz /* resolution of the rate shaping timer - 400 usec */
306b475d78fSYuval Mintz #define RS_PERIODIC_TIMEOUT_USEC 400
307b475d78fSYuval Mintz
308b475d78fSYuval Mintz /* number of bytes in single QM arbitration cycle -
309b475d78fSYuval Mintz * coefficient for calculating the fairness timer
310b475d78fSYuval Mintz */
311b475d78fSYuval Mintz #define QM_ARB_BYTES 160000
312b475d78fSYuval Mintz
313b475d78fSYuval Mintz /* resolution of Min algorithm 1:100 */
314b475d78fSYuval Mintz #define MIN_RES 100
315b475d78fSYuval Mintz
316b475d78fSYuval Mintz /* how many bytes above threshold for
317b475d78fSYuval Mintz * the minimal credit of Min algorithm
318b475d78fSYuval Mintz */
319b475d78fSYuval Mintz #define MIN_ABOVE_THRESH 32768
320b475d78fSYuval Mintz
321b475d78fSYuval Mintz /* Fairness algorithm integration time coefficient -
322b475d78fSYuval Mintz * for calculating the actual Tfair
323b475d78fSYuval Mintz */
324b475d78fSYuval Mintz #define T_FAIR_COEF ((MIN_ABOVE_THRESH + QM_ARB_BYTES) * 8 * MIN_RES)
325b475d78fSYuval Mintz
326b475d78fSYuval Mintz /* Memory of fairness algorithm - 2 cycles */
327b475d78fSYuval Mintz #define FAIR_MEM 2
328b475d78fSYuval Mintz #define SAFC_TIMEOUT_USEC 52
329b475d78fSYuval Mintz
330b475d78fSYuval Mintz #define SDM_TICKS 4
331b475d78fSYuval Mintz
332b475d78fSYuval Mintz
bnx2x_init_max(const struct cmng_init_input * input_data,u32 r_param,struct cmng_init * ram_data)333b475d78fSYuval Mintz static inline void bnx2x_init_max(const struct cmng_init_input *input_data,
334b475d78fSYuval Mintz u32 r_param, struct cmng_init *ram_data)
335b475d78fSYuval Mintz {
336b475d78fSYuval Mintz u32 vnic;
337b475d78fSYuval Mintz struct cmng_vnic *vdata = &ram_data->vnic;
338b475d78fSYuval Mintz struct cmng_struct_per_port *pdata = &ram_data->port;
339b475d78fSYuval Mintz /* rate shaping per-port variables
340b475d78fSYuval Mintz * 100 micro seconds in SDM ticks = 25
341b475d78fSYuval Mintz * since each tick is 4 microSeconds
342b475d78fSYuval Mintz */
343b475d78fSYuval Mintz
344b475d78fSYuval Mintz pdata->rs_vars.rs_periodic_timeout =
345b475d78fSYuval Mintz RS_PERIODIC_TIMEOUT_USEC / SDM_TICKS;
346b475d78fSYuval Mintz
347b475d78fSYuval Mintz /* this is the threshold below which no timer arming will occur.
348b475d78fSYuval Mintz * 1.25 coefficient is for the threshold to be a little bigger
349b475d78fSYuval Mintz * then the real time to compensate for timer in-accuracy
350b475d78fSYuval Mintz */
351b475d78fSYuval Mintz pdata->rs_vars.rs_threshold =
352b475d78fSYuval Mintz (5 * RS_PERIODIC_TIMEOUT_USEC * r_param)/4;
353b475d78fSYuval Mintz
354b475d78fSYuval Mintz /* rate shaping per-vnic variables */
355b475d78fSYuval Mintz for (vnic = 0; vnic < BNX2X_PORT2_MODE_NUM_VNICS; vnic++) {
356b475d78fSYuval Mintz /* global vnic counter */
357b475d78fSYuval Mintz vdata->vnic_max_rate[vnic].vn_counter.rate =
358b475d78fSYuval Mintz input_data->vnic_max_rate[vnic];
359b475d78fSYuval Mintz /* maximal Mbps for this vnic
360b475d78fSYuval Mintz * the quota in each timer period - number of bytes
361b475d78fSYuval Mintz * transmitted in this period
362b475d78fSYuval Mintz */
363b475d78fSYuval Mintz vdata->vnic_max_rate[vnic].vn_counter.quota =
364b475d78fSYuval Mintz RS_PERIODIC_TIMEOUT_USEC *
365b475d78fSYuval Mintz (u32)vdata->vnic_max_rate[vnic].vn_counter.rate / 8;
366b475d78fSYuval Mintz }
367b475d78fSYuval Mintz
368b475d78fSYuval Mintz }
369b475d78fSYuval Mintz
bnx2x_init_min(const struct cmng_init_input * input_data,u32 r_param,struct cmng_init * ram_data)370b475d78fSYuval Mintz static inline void bnx2x_init_min(const struct cmng_init_input *input_data,
371b475d78fSYuval Mintz u32 r_param, struct cmng_init *ram_data)
372b475d78fSYuval Mintz {
373b475d78fSYuval Mintz u32 vnic, fair_periodic_timeout_usec, vnicWeightSum, tFair;
374b475d78fSYuval Mintz struct cmng_vnic *vdata = &ram_data->vnic;
375b475d78fSYuval Mintz struct cmng_struct_per_port *pdata = &ram_data->port;
376b475d78fSYuval Mintz
377b475d78fSYuval Mintz /* this is the resolution of the fairness timer */
378b475d78fSYuval Mintz fair_periodic_timeout_usec = QM_ARB_BYTES / r_param;
379b475d78fSYuval Mintz
380b475d78fSYuval Mintz /* fairness per-port variables
381b475d78fSYuval Mintz * for 10G it is 1000usec. for 1G it is 10000usec.
382b475d78fSYuval Mintz */
383b475d78fSYuval Mintz tFair = T_FAIR_COEF / input_data->port_rate;
384b475d78fSYuval Mintz
385b475d78fSYuval Mintz /* this is the threshold below which we won't arm the timer anymore */
386b475d78fSYuval Mintz pdata->fair_vars.fair_threshold = QM_ARB_BYTES;
387b475d78fSYuval Mintz
388b475d78fSYuval Mintz /* we multiply by 1e3/8 to get bytes/msec. We don't want the credits
389b475d78fSYuval Mintz * to pass a credit of the T_FAIR*FAIR_MEM (algorithm resolution)
390b475d78fSYuval Mintz */
391b475d78fSYuval Mintz pdata->fair_vars.upper_bound = r_param * tFair * FAIR_MEM;
392b475d78fSYuval Mintz
393b475d78fSYuval Mintz /* since each tick is 4 microSeconds */
394b475d78fSYuval Mintz pdata->fair_vars.fairness_timeout =
395b475d78fSYuval Mintz fair_periodic_timeout_usec / SDM_TICKS;
396b475d78fSYuval Mintz
397b475d78fSYuval Mintz /* calculate sum of weights */
398b475d78fSYuval Mintz vnicWeightSum = 0;
399b475d78fSYuval Mintz
400b475d78fSYuval Mintz for (vnic = 0; vnic < BNX2X_PORT2_MODE_NUM_VNICS; vnic++)
401b475d78fSYuval Mintz vnicWeightSum += input_data->vnic_min_rate[vnic];
402b475d78fSYuval Mintz
403b475d78fSYuval Mintz /* global vnic counter */
404b475d78fSYuval Mintz if (vnicWeightSum > 0) {
405b475d78fSYuval Mintz /* fairness per-vnic variables */
406b475d78fSYuval Mintz for (vnic = 0; vnic < BNX2X_PORT2_MODE_NUM_VNICS; vnic++) {
407b475d78fSYuval Mintz /* this is the credit for each period of the fairness
408b475d78fSYuval Mintz * algorithm - number of bytes in T_FAIR (this vnic
409b475d78fSYuval Mintz * share of the port rate)
410b475d78fSYuval Mintz */
411b475d78fSYuval Mintz vdata->vnic_min_rate[vnic].vn_credit_delta =
412b475d78fSYuval Mintz (u32)input_data->vnic_min_rate[vnic] * 100 *
413cfcadc97SDmitry Kravkov (T_FAIR_COEF / (8 * 100 * vnicWeightSum));
414b475d78fSYuval Mintz if (vdata->vnic_min_rate[vnic].vn_credit_delta <
415b475d78fSYuval Mintz pdata->fair_vars.fair_threshold +
416b475d78fSYuval Mintz MIN_ABOVE_THRESH) {
417b475d78fSYuval Mintz vdata->vnic_min_rate[vnic].vn_credit_delta =
418b475d78fSYuval Mintz pdata->fair_vars.fair_threshold +
419b475d78fSYuval Mintz MIN_ABOVE_THRESH;
420b475d78fSYuval Mintz }
421b475d78fSYuval Mintz }
422b475d78fSYuval Mintz }
423b475d78fSYuval Mintz }
424b475d78fSYuval Mintz
bnx2x_init_fw_wrr(const struct cmng_init_input * input_data,u32 r_param,struct cmng_init * ram_data)425b475d78fSYuval Mintz static inline void bnx2x_init_fw_wrr(const struct cmng_init_input *input_data,
426b475d78fSYuval Mintz u32 r_param, struct cmng_init *ram_data)
427b475d78fSYuval Mintz {
428b475d78fSYuval Mintz u32 vnic, cos;
429b475d78fSYuval Mintz u32 cosWeightSum = 0;
430b475d78fSYuval Mintz struct cmng_vnic *vdata = &ram_data->vnic;
431b475d78fSYuval Mintz struct cmng_struct_per_port *pdata = &ram_data->port;
432b475d78fSYuval Mintz
433b475d78fSYuval Mintz for (cos = 0; cos < MAX_COS_NUMBER; cos++)
434b475d78fSYuval Mintz cosWeightSum += input_data->cos_min_rate[cos];
435b475d78fSYuval Mintz
436b475d78fSYuval Mintz if (cosWeightSum > 0) {
437b475d78fSYuval Mintz
438b475d78fSYuval Mintz for (vnic = 0; vnic < BNX2X_PORT2_MODE_NUM_VNICS; vnic++) {
439b475d78fSYuval Mintz /* Since cos and vnic shouldn't work together the rate
440b475d78fSYuval Mintz * to divide between the coses is the port rate.
441b475d78fSYuval Mintz */
442b475d78fSYuval Mintz u32 *ccd = vdata->vnic_min_rate[vnic].cos_credit_delta;
443b475d78fSYuval Mintz for (cos = 0; cos < MAX_COS_NUMBER; cos++) {
444b475d78fSYuval Mintz /* this is the credit for each period of
445b475d78fSYuval Mintz * the fairness algorithm - number of bytes
446b475d78fSYuval Mintz * in T_FAIR (this cos share of the vnic rate)
447b475d78fSYuval Mintz */
448b475d78fSYuval Mintz ccd[cos] =
449b475d78fSYuval Mintz (u32)input_data->cos_min_rate[cos] * 100 *
450cfcadc97SDmitry Kravkov (T_FAIR_COEF / (8 * 100 * cosWeightSum));
451b475d78fSYuval Mintz if (ccd[cos] < pdata->fair_vars.fair_threshold
452b475d78fSYuval Mintz + MIN_ABOVE_THRESH) {
453b475d78fSYuval Mintz ccd[cos] =
454b475d78fSYuval Mintz pdata->fair_vars.fair_threshold +
455b475d78fSYuval Mintz MIN_ABOVE_THRESH;
456b475d78fSYuval Mintz }
457b475d78fSYuval Mintz }
458b475d78fSYuval Mintz }
459b475d78fSYuval Mintz }
460b475d78fSYuval Mintz }
461b475d78fSYuval Mintz
bnx2x_init_safc(const struct cmng_init_input * input_data,struct cmng_init * ram_data)462b475d78fSYuval Mintz static inline void bnx2x_init_safc(const struct cmng_init_input *input_data,
463b475d78fSYuval Mintz struct cmng_init *ram_data)
464b475d78fSYuval Mintz {
465b475d78fSYuval Mintz /* in microSeconds */
466b475d78fSYuval Mintz ram_data->port.safc_vars.safc_timeout_usec = SAFC_TIMEOUT_USEC;
467b475d78fSYuval Mintz }
468b475d78fSYuval Mintz
469b475d78fSYuval Mintz /* Congestion management port init */
bnx2x_init_cmng(const struct cmng_init_input * input_data,struct cmng_init * ram_data)470b475d78fSYuval Mintz static inline void bnx2x_init_cmng(const struct cmng_init_input *input_data,
471b475d78fSYuval Mintz struct cmng_init *ram_data)
472b475d78fSYuval Mintz {
473b475d78fSYuval Mintz u32 r_param;
474b475d78fSYuval Mintz memset(ram_data, 0, sizeof(struct cmng_init));
475b475d78fSYuval Mintz
476b475d78fSYuval Mintz ram_data->port.flags = input_data->flags;
477b475d78fSYuval Mintz
478b475d78fSYuval Mintz /* number of bytes transmitted in a rate of 10Gbps
479b475d78fSYuval Mintz * in one usec = 1.25KB.
480b475d78fSYuval Mintz */
481b475d78fSYuval Mintz r_param = BITS_TO_BYTES(input_data->port_rate);
482b475d78fSYuval Mintz bnx2x_init_max(input_data, r_param, ram_data);
483b475d78fSYuval Mintz bnx2x_init_min(input_data, r_param, ram_data);
484b475d78fSYuval Mintz bnx2x_init_fw_wrr(input_data, r_param, ram_data);
485b475d78fSYuval Mintz bnx2x_init_safc(input_data, ram_data);
486b475d78fSYuval Mintz }
487b475d78fSYuval Mintz
488b475d78fSYuval Mintz
489b475d78fSYuval Mintz
490adfc5217SJeff Kirsher /* Returns the index of start or end of a specific block stage in ops array */
491adfc5217SJeff Kirsher #define BLOCK_OPS_IDX(block, stage, end) \
492adfc5217SJeff Kirsher (2*(((block)*NUM_OF_INIT_PHASES) + (stage)) + (end))
493adfc5217SJeff Kirsher
494adfc5217SJeff Kirsher
495adfc5217SJeff Kirsher #define INITOP_SET 0 /* set the HW directly */
496adfc5217SJeff Kirsher #define INITOP_CLEAR 1 /* clear the HW directly */
497adfc5217SJeff Kirsher #define INITOP_INIT 2 /* set the init-value array */
498adfc5217SJeff Kirsher
499adfc5217SJeff Kirsher /****************************************************************************
500adfc5217SJeff Kirsher * ILT management
501adfc5217SJeff Kirsher ****************************************************************************/
502adfc5217SJeff Kirsher struct ilt_line {
503adfc5217SJeff Kirsher dma_addr_t page_mapping;
504adfc5217SJeff Kirsher void *page;
505adfc5217SJeff Kirsher u32 size;
506adfc5217SJeff Kirsher };
507adfc5217SJeff Kirsher
508adfc5217SJeff Kirsher struct ilt_client_info {
509adfc5217SJeff Kirsher u32 page_size;
510adfc5217SJeff Kirsher u16 start;
511adfc5217SJeff Kirsher u16 end;
512adfc5217SJeff Kirsher u16 client_num;
513adfc5217SJeff Kirsher u16 flags;
514adfc5217SJeff Kirsher #define ILT_CLIENT_SKIP_INIT 0x1
515adfc5217SJeff Kirsher #define ILT_CLIENT_SKIP_MEM 0x2
516adfc5217SJeff Kirsher };
517adfc5217SJeff Kirsher
518adfc5217SJeff Kirsher struct bnx2x_ilt {
519adfc5217SJeff Kirsher u32 start_line;
520adfc5217SJeff Kirsher struct ilt_line *lines;
521adfc5217SJeff Kirsher struct ilt_client_info clients[4];
522adfc5217SJeff Kirsher #define ILT_CLIENT_CDU 0
523adfc5217SJeff Kirsher #define ILT_CLIENT_QM 1
524adfc5217SJeff Kirsher #define ILT_CLIENT_SRC 2
525adfc5217SJeff Kirsher #define ILT_CLIENT_TM 3
526adfc5217SJeff Kirsher };
527adfc5217SJeff Kirsher
528adfc5217SJeff Kirsher /****************************************************************************
529adfc5217SJeff Kirsher * SRC configuration
530adfc5217SJeff Kirsher ****************************************************************************/
531adfc5217SJeff Kirsher struct src_ent {
532adfc5217SJeff Kirsher u8 opaque[56];
533adfc5217SJeff Kirsher u64 next;
534adfc5217SJeff Kirsher };
535adfc5217SJeff Kirsher
536adfc5217SJeff Kirsher /****************************************************************************
537adfc5217SJeff Kirsher * Parity configuration
538adfc5217SJeff Kirsher ****************************************************************************/
539adfc5217SJeff Kirsher #define BLOCK_PRTY_INFO(block, en_mask, m1, m1h, m2, m3) \
540adfc5217SJeff Kirsher { \
541adfc5217SJeff Kirsher block##_REG_##block##_PRTY_MASK, \
542adfc5217SJeff Kirsher block##_REG_##block##_PRTY_STS_CLR, \
543adfc5217SJeff Kirsher en_mask, {m1, m1h, m2, m3}, #block \
544adfc5217SJeff Kirsher }
545adfc5217SJeff Kirsher
546adfc5217SJeff Kirsher #define BLOCK_PRTY_INFO_0(block, en_mask, m1, m1h, m2, m3) \
547adfc5217SJeff Kirsher { \
548adfc5217SJeff Kirsher block##_REG_##block##_PRTY_MASK_0, \
549adfc5217SJeff Kirsher block##_REG_##block##_PRTY_STS_CLR_0, \
550adfc5217SJeff Kirsher en_mask, {m1, m1h, m2, m3}, #block"_0" \
551adfc5217SJeff Kirsher }
552adfc5217SJeff Kirsher
553adfc5217SJeff Kirsher #define BLOCK_PRTY_INFO_1(block, en_mask, m1, m1h, m2, m3) \
554adfc5217SJeff Kirsher { \
555adfc5217SJeff Kirsher block##_REG_##block##_PRTY_MASK_1, \
556adfc5217SJeff Kirsher block##_REG_##block##_PRTY_STS_CLR_1, \
557adfc5217SJeff Kirsher en_mask, {m1, m1h, m2, m3}, #block"_1" \
558adfc5217SJeff Kirsher }
559adfc5217SJeff Kirsher
560adfc5217SJeff Kirsher static const struct {
561adfc5217SJeff Kirsher u32 mask_addr;
562adfc5217SJeff Kirsher u32 sts_clr_addr;
563adfc5217SJeff Kirsher u32 en_mask; /* Mask to enable parity attentions */
564adfc5217SJeff Kirsher struct {
565adfc5217SJeff Kirsher u32 e1; /* 57710 */
566adfc5217SJeff Kirsher u32 e1h; /* 57711 */
567adfc5217SJeff Kirsher u32 e2; /* 57712 */
568adfc5217SJeff Kirsher u32 e3; /* 578xx */
569adfc5217SJeff Kirsher } reg_mask; /* Register mask (all valid bits) */
57096bed4b9SYuval Mintz char name[8]; /* Block's longest name is 7 characters long
571adfc5217SJeff Kirsher * (name + suffix)
572adfc5217SJeff Kirsher */
573adfc5217SJeff Kirsher } bnx2x_blocks_parity_data[] = {
574adfc5217SJeff Kirsher /* bit 19 masked */
575adfc5217SJeff Kirsher /* REG_WR(bp, PXP_REG_PXP_PRTY_MASK, 0x80000); */
576adfc5217SJeff Kirsher /* bit 5,18,20-31 */
577adfc5217SJeff Kirsher /* REG_WR(bp, PXP2_REG_PXP2_PRTY_MASK_0, 0xfff40020); */
578adfc5217SJeff Kirsher /* bit 5 */
579adfc5217SJeff Kirsher /* REG_WR(bp, PXP2_REG_PXP2_PRTY_MASK_1, 0x20); */
580adfc5217SJeff Kirsher /* REG_WR(bp, HC_REG_HC_PRTY_MASK, 0x0); */
581adfc5217SJeff Kirsher /* REG_WR(bp, MISC_REG_MISC_PRTY_MASK, 0x0); */
582adfc5217SJeff Kirsher
583adfc5217SJeff Kirsher /* Block IGU, MISC, PXP and PXP2 parity errors as long as we don't
584adfc5217SJeff Kirsher * want to handle "system kill" flow at the moment.
585adfc5217SJeff Kirsher */
586adfc5217SJeff Kirsher BLOCK_PRTY_INFO(PXP, 0x7ffffff, 0x3ffffff, 0x3ffffff, 0x7ffffff,
587adfc5217SJeff Kirsher 0x7ffffff),
588adfc5217SJeff Kirsher BLOCK_PRTY_INFO_0(PXP2, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
589adfc5217SJeff Kirsher 0xffffffff),
590adfc5217SJeff Kirsher BLOCK_PRTY_INFO_1(PXP2, 0x1ffffff, 0x7f, 0x7f, 0x7ff, 0x1ffffff),
591adfc5217SJeff Kirsher BLOCK_PRTY_INFO(HC, 0x7, 0x7, 0x7, 0, 0),
592adfc5217SJeff Kirsher BLOCK_PRTY_INFO(NIG, 0xffffffff, 0x3fffffff, 0xffffffff, 0, 0),
593adfc5217SJeff Kirsher BLOCK_PRTY_INFO_0(NIG, 0xffffffff, 0, 0, 0xffffffff, 0xffffffff),
594adfc5217SJeff Kirsher BLOCK_PRTY_INFO_1(NIG, 0xffff, 0, 0, 0xff, 0xffff),
595adfc5217SJeff Kirsher BLOCK_PRTY_INFO(IGU, 0x7ff, 0, 0, 0x7ff, 0x7ff),
596adfc5217SJeff Kirsher BLOCK_PRTY_INFO(MISC, 0x1, 0x1, 0x1, 0x1, 0x1),
597adfc5217SJeff Kirsher BLOCK_PRTY_INFO(QM, 0, 0x1ff, 0xfff, 0xfff, 0xfff),
598adfc5217SJeff Kirsher BLOCK_PRTY_INFO(ATC, 0x1f, 0, 0, 0x1f, 0x1f),
599adfc5217SJeff Kirsher BLOCK_PRTY_INFO(PGLUE_B, 0x3, 0, 0, 0x3, 0x3),
600adfc5217SJeff Kirsher BLOCK_PRTY_INFO(DORQ, 0, 0x3, 0x3, 0x3, 0x3),
601adfc5217SJeff Kirsher {GRCBASE_UPB + PB_REG_PB_PRTY_MASK,
602adfc5217SJeff Kirsher GRCBASE_UPB + PB_REG_PB_PRTY_STS_CLR, 0xf,
603adfc5217SJeff Kirsher {0xf, 0xf, 0xf, 0xf}, "UPB"},
604adfc5217SJeff Kirsher {GRCBASE_XPB + PB_REG_PB_PRTY_MASK,
605adfc5217SJeff Kirsher GRCBASE_XPB + PB_REG_PB_PRTY_STS_CLR, 0,
606adfc5217SJeff Kirsher {0xf, 0xf, 0xf, 0xf}, "XPB"},
607adfc5217SJeff Kirsher BLOCK_PRTY_INFO(SRC, 0x4, 0x7, 0x7, 0x7, 0x7),
608adfc5217SJeff Kirsher BLOCK_PRTY_INFO(CDU, 0, 0x1f, 0x1f, 0x1f, 0x1f),
609adfc5217SJeff Kirsher BLOCK_PRTY_INFO(CFC, 0, 0xf, 0xf, 0xf, 0x3f),
610adfc5217SJeff Kirsher BLOCK_PRTY_INFO(DBG, 0, 0x1, 0x1, 0x1, 0x1),
611adfc5217SJeff Kirsher BLOCK_PRTY_INFO(DMAE, 0, 0xf, 0xf, 0xf, 0xf),
612adfc5217SJeff Kirsher BLOCK_PRTY_INFO(BRB1, 0, 0xf, 0xf, 0xf, 0xf),
613adfc5217SJeff Kirsher BLOCK_PRTY_INFO(PRS, (1<<6), 0xff, 0xff, 0xff, 0xff),
614adfc5217SJeff Kirsher BLOCK_PRTY_INFO(PBF, 0, 0, 0x3ffff, 0xfffff, 0xfffffff),
615adfc5217SJeff Kirsher BLOCK_PRTY_INFO(TM, 0, 0, 0x7f, 0x7f, 0x7f),
616adfc5217SJeff Kirsher BLOCK_PRTY_INFO(TSDM, 0x18, 0x7ff, 0x7ff, 0x7ff, 0x7ff),
617adfc5217SJeff Kirsher BLOCK_PRTY_INFO(CSDM, 0x8, 0x7ff, 0x7ff, 0x7ff, 0x7ff),
618adfc5217SJeff Kirsher BLOCK_PRTY_INFO(USDM, 0x38, 0x7ff, 0x7ff, 0x7ff, 0x7ff),
619adfc5217SJeff Kirsher BLOCK_PRTY_INFO(XSDM, 0x8, 0x7ff, 0x7ff, 0x7ff, 0x7ff),
620adfc5217SJeff Kirsher BLOCK_PRTY_INFO(TCM, 0, 0, 0x7ffffff, 0x7ffffff, 0x7ffffff),
621adfc5217SJeff Kirsher BLOCK_PRTY_INFO(CCM, 0, 0, 0x7ffffff, 0x7ffffff, 0x7ffffff),
622adfc5217SJeff Kirsher BLOCK_PRTY_INFO(UCM, 0, 0, 0x7ffffff, 0x7ffffff, 0x7ffffff),
623adfc5217SJeff Kirsher BLOCK_PRTY_INFO(XCM, 0, 0, 0x3fffffff, 0x3fffffff, 0x3fffffff),
624adfc5217SJeff Kirsher BLOCK_PRTY_INFO_0(TSEM, 0, 0xffffffff, 0xffffffff, 0xffffffff,
625adfc5217SJeff Kirsher 0xffffffff),
626adfc5217SJeff Kirsher BLOCK_PRTY_INFO_1(TSEM, 0, 0x3, 0x1f, 0x3f, 0x3f),
627adfc5217SJeff Kirsher BLOCK_PRTY_INFO_0(USEM, 0, 0xffffffff, 0xffffffff, 0xffffffff,
628adfc5217SJeff Kirsher 0xffffffff),
629adfc5217SJeff Kirsher BLOCK_PRTY_INFO_1(USEM, 0, 0x3, 0x1f, 0x1f, 0x1f),
630adfc5217SJeff Kirsher BLOCK_PRTY_INFO_0(CSEM, 0, 0xffffffff, 0xffffffff, 0xffffffff,
631adfc5217SJeff Kirsher 0xffffffff),
632adfc5217SJeff Kirsher BLOCK_PRTY_INFO_1(CSEM, 0, 0x3, 0x1f, 0x1f, 0x1f),
633adfc5217SJeff Kirsher BLOCK_PRTY_INFO_0(XSEM, 0, 0xffffffff, 0xffffffff, 0xffffffff,
634adfc5217SJeff Kirsher 0xffffffff),
635adfc5217SJeff Kirsher BLOCK_PRTY_INFO_1(XSEM, 0, 0x3, 0x1f, 0x3f, 0x3f),
636adfc5217SJeff Kirsher };
637adfc5217SJeff Kirsher
638adfc5217SJeff Kirsher
639adfc5217SJeff Kirsher /* [28] MCP Latched rom_parity
640adfc5217SJeff Kirsher * [29] MCP Latched ump_rx_parity
641adfc5217SJeff Kirsher * [30] MCP Latched ump_tx_parity
642adfc5217SJeff Kirsher * [31] MCP Latched scpad_parity
643adfc5217SJeff Kirsher */
6444293b9f5SDmitry Kravkov #define MISC_AEU_ENABLE_MCP_PRTY_SUB_BITS \
645adfc5217SJeff Kirsher (AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY | \
646adfc5217SJeff Kirsher AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY | \
6474293b9f5SDmitry Kravkov AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY)
6484293b9f5SDmitry Kravkov
6494293b9f5SDmitry Kravkov #define MISC_AEU_ENABLE_MCP_PRTY_BITS \
6504293b9f5SDmitry Kravkov (MISC_AEU_ENABLE_MCP_PRTY_SUB_BITS | \
651adfc5217SJeff Kirsher AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY)
652adfc5217SJeff Kirsher
653adfc5217SJeff Kirsher /* Below registers control the MCP parity attention output. When
654adfc5217SJeff Kirsher * MISC_AEU_ENABLE_MCP_PRTY_BITS are set - attentions are
655adfc5217SJeff Kirsher * enabled, when cleared - disabled.
656adfc5217SJeff Kirsher */
6574293b9f5SDmitry Kravkov static const struct {
6584293b9f5SDmitry Kravkov u32 addr;
6594293b9f5SDmitry Kravkov u32 bits;
6604293b9f5SDmitry Kravkov } mcp_attn_ctl_regs[] = {
6614293b9f5SDmitry Kravkov { MISC_REG_AEU_ENABLE4_FUNC_0_OUT_0,
6624293b9f5SDmitry Kravkov MISC_AEU_ENABLE_MCP_PRTY_BITS },
6634293b9f5SDmitry Kravkov { MISC_REG_AEU_ENABLE4_NIG_0,
6644293b9f5SDmitry Kravkov MISC_AEU_ENABLE_MCP_PRTY_SUB_BITS },
6654293b9f5SDmitry Kravkov { MISC_REG_AEU_ENABLE4_PXP_0,
6664293b9f5SDmitry Kravkov MISC_AEU_ENABLE_MCP_PRTY_SUB_BITS },
6674293b9f5SDmitry Kravkov { MISC_REG_AEU_ENABLE4_FUNC_1_OUT_0,
6684293b9f5SDmitry Kravkov MISC_AEU_ENABLE_MCP_PRTY_BITS },
6694293b9f5SDmitry Kravkov { MISC_REG_AEU_ENABLE4_NIG_1,
6704293b9f5SDmitry Kravkov MISC_AEU_ENABLE_MCP_PRTY_SUB_BITS },
6714293b9f5SDmitry Kravkov { MISC_REG_AEU_ENABLE4_PXP_1,
6724293b9f5SDmitry Kravkov MISC_AEU_ENABLE_MCP_PRTY_SUB_BITS }
673adfc5217SJeff Kirsher };
674adfc5217SJeff Kirsher
bnx2x_set_mcp_parity(struct bnx2x * bp,u8 enable)675adfc5217SJeff Kirsher static inline void bnx2x_set_mcp_parity(struct bnx2x *bp, u8 enable)
676adfc5217SJeff Kirsher {
677adfc5217SJeff Kirsher int i;
678adfc5217SJeff Kirsher u32 reg_val;
679adfc5217SJeff Kirsher
680adfc5217SJeff Kirsher for (i = 0; i < ARRAY_SIZE(mcp_attn_ctl_regs); i++) {
6814293b9f5SDmitry Kravkov reg_val = REG_RD(bp, mcp_attn_ctl_regs[i].addr);
682adfc5217SJeff Kirsher
683adfc5217SJeff Kirsher if (enable)
6844293b9f5SDmitry Kravkov reg_val |= mcp_attn_ctl_regs[i].bits;
685adfc5217SJeff Kirsher else
6864293b9f5SDmitry Kravkov reg_val &= ~mcp_attn_ctl_regs[i].bits;
687adfc5217SJeff Kirsher
6884293b9f5SDmitry Kravkov REG_WR(bp, mcp_attn_ctl_regs[i].addr, reg_val);
689adfc5217SJeff Kirsher }
690adfc5217SJeff Kirsher }
691adfc5217SJeff Kirsher
bnx2x_parity_reg_mask(struct bnx2x * bp,int idx)692adfc5217SJeff Kirsher static inline u32 bnx2x_parity_reg_mask(struct bnx2x *bp, int idx)
693adfc5217SJeff Kirsher {
694adfc5217SJeff Kirsher if (CHIP_IS_E1(bp))
695adfc5217SJeff Kirsher return bnx2x_blocks_parity_data[idx].reg_mask.e1;
696adfc5217SJeff Kirsher else if (CHIP_IS_E1H(bp))
697adfc5217SJeff Kirsher return bnx2x_blocks_parity_data[idx].reg_mask.e1h;
698adfc5217SJeff Kirsher else if (CHIP_IS_E2(bp))
699adfc5217SJeff Kirsher return bnx2x_blocks_parity_data[idx].reg_mask.e2;
700adfc5217SJeff Kirsher else /* CHIP_IS_E3 */
701adfc5217SJeff Kirsher return bnx2x_blocks_parity_data[idx].reg_mask.e3;
702adfc5217SJeff Kirsher }
703adfc5217SJeff Kirsher
bnx2x_disable_blocks_parity(struct bnx2x * bp)704adfc5217SJeff Kirsher static inline void bnx2x_disable_blocks_parity(struct bnx2x *bp)
705adfc5217SJeff Kirsher {
706adfc5217SJeff Kirsher int i;
707adfc5217SJeff Kirsher
708adfc5217SJeff Kirsher for (i = 0; i < ARRAY_SIZE(bnx2x_blocks_parity_data); i++) {
709adfc5217SJeff Kirsher u32 dis_mask = bnx2x_parity_reg_mask(bp, i);
710adfc5217SJeff Kirsher
711adfc5217SJeff Kirsher if (dis_mask) {
712adfc5217SJeff Kirsher REG_WR(bp, bnx2x_blocks_parity_data[i].mask_addr,
713adfc5217SJeff Kirsher dis_mask);
714adfc5217SJeff Kirsher DP(NETIF_MSG_HW, "Setting parity mask "
715adfc5217SJeff Kirsher "for %s to\t\t0x%x\n",
716adfc5217SJeff Kirsher bnx2x_blocks_parity_data[i].name, dis_mask);
717adfc5217SJeff Kirsher }
718adfc5217SJeff Kirsher }
719adfc5217SJeff Kirsher
720adfc5217SJeff Kirsher /* Disable MCP parity attentions */
721adfc5217SJeff Kirsher bnx2x_set_mcp_parity(bp, false);
722adfc5217SJeff Kirsher }
723adfc5217SJeff Kirsher
724b475d78fSYuval Mintz /* Clear the parity error status registers. */
bnx2x_clear_blocks_parity(struct bnx2x * bp)725adfc5217SJeff Kirsher static inline void bnx2x_clear_blocks_parity(struct bnx2x *bp)
726adfc5217SJeff Kirsher {
727adfc5217SJeff Kirsher int i;
728adfc5217SJeff Kirsher u32 reg_val, mcp_aeu_bits =
729adfc5217SJeff Kirsher AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY |
730adfc5217SJeff Kirsher AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY |
731adfc5217SJeff Kirsher AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY |
732adfc5217SJeff Kirsher AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY;
733adfc5217SJeff Kirsher
734adfc5217SJeff Kirsher /* Clear SEM_FAST parities */
735adfc5217SJeff Kirsher REG_WR(bp, XSEM_REG_FAST_MEMORY + SEM_FAST_REG_PARITY_RST, 0x1);
736adfc5217SJeff Kirsher REG_WR(bp, TSEM_REG_FAST_MEMORY + SEM_FAST_REG_PARITY_RST, 0x1);
737adfc5217SJeff Kirsher REG_WR(bp, USEM_REG_FAST_MEMORY + SEM_FAST_REG_PARITY_RST, 0x1);
738adfc5217SJeff Kirsher REG_WR(bp, CSEM_REG_FAST_MEMORY + SEM_FAST_REG_PARITY_RST, 0x1);
739adfc5217SJeff Kirsher
740adfc5217SJeff Kirsher for (i = 0; i < ARRAY_SIZE(bnx2x_blocks_parity_data); i++) {
741adfc5217SJeff Kirsher u32 reg_mask = bnx2x_parity_reg_mask(bp, i);
742adfc5217SJeff Kirsher
743adfc5217SJeff Kirsher if (reg_mask) {
744adfc5217SJeff Kirsher reg_val = REG_RD(bp, bnx2x_blocks_parity_data[i].
745adfc5217SJeff Kirsher sts_clr_addr);
746adfc5217SJeff Kirsher if (reg_val & reg_mask)
747adfc5217SJeff Kirsher DP(NETIF_MSG_HW,
748adfc5217SJeff Kirsher "Parity errors in %s: 0x%x\n",
749adfc5217SJeff Kirsher bnx2x_blocks_parity_data[i].name,
750adfc5217SJeff Kirsher reg_val & reg_mask);
751adfc5217SJeff Kirsher }
752adfc5217SJeff Kirsher }
753adfc5217SJeff Kirsher
754adfc5217SJeff Kirsher /* Check if there were parity attentions in MCP */
755adfc5217SJeff Kirsher reg_val = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_MCP);
756adfc5217SJeff Kirsher if (reg_val & mcp_aeu_bits)
757adfc5217SJeff Kirsher DP(NETIF_MSG_HW, "Parity error in MCP: 0x%x\n",
758adfc5217SJeff Kirsher reg_val & mcp_aeu_bits);
759adfc5217SJeff Kirsher
760adfc5217SJeff Kirsher /* Clear parity attentions in MCP:
761adfc5217SJeff Kirsher * [7] clears Latched rom_parity
762adfc5217SJeff Kirsher * [8] clears Latched ump_rx_parity
763adfc5217SJeff Kirsher * [9] clears Latched ump_tx_parity
764adfc5217SJeff Kirsher * [10] clears Latched scpad_parity (both ports)
765adfc5217SJeff Kirsher */
766adfc5217SJeff Kirsher REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x780);
767adfc5217SJeff Kirsher }
768adfc5217SJeff Kirsher
bnx2x_enable_blocks_parity(struct bnx2x * bp)769adfc5217SJeff Kirsher static inline void bnx2x_enable_blocks_parity(struct bnx2x *bp)
770adfc5217SJeff Kirsher {
771adfc5217SJeff Kirsher int i;
772adfc5217SJeff Kirsher
773adfc5217SJeff Kirsher for (i = 0; i < ARRAY_SIZE(bnx2x_blocks_parity_data); i++) {
774adfc5217SJeff Kirsher u32 reg_mask = bnx2x_parity_reg_mask(bp, i);
775adfc5217SJeff Kirsher
776adfc5217SJeff Kirsher if (reg_mask)
777adfc5217SJeff Kirsher REG_WR(bp, bnx2x_blocks_parity_data[i].mask_addr,
778adfc5217SJeff Kirsher bnx2x_blocks_parity_data[i].en_mask & reg_mask);
779adfc5217SJeff Kirsher }
780adfc5217SJeff Kirsher
781adfc5217SJeff Kirsher /* Enable MCP parity attentions */
782adfc5217SJeff Kirsher bnx2x_set_mcp_parity(bp, true);
783adfc5217SJeff Kirsher }
784adfc5217SJeff Kirsher
785adfc5217SJeff Kirsher
786adfc5217SJeff Kirsher #endif /* BNX2X_INIT_H */
787adfc5217SJeff Kirsher
788