xref: /freebsd/sys/dev/cxgbe/common/t4_hw.c (revision a172f9e5b3cf41882f087f6c5311dc068d9d6b54)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2012, 2016, 2025 Chelsio Communications.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  */
27 
28 #include <sys/cdefs.h>
29 #include "opt_inet.h"
30 
31 #include <sys/param.h>
32 #include <sys/eventhandler.h>
33 
34 #include "common.h"
35 #include "t4_regs.h"
36 #include "t4_regs_values.h"
37 #include "firmware/t4fw_interface.h"
38 
39 #undef msleep
40 #define msleep(x) do { \
41 	if (cold) \
42 		DELAY((x) * 1000); \
43 	else \
44 		pause("t4hw", (x) * hz / 1000); \
45 } while (0)
46 
47 /**
48  *	t4_wait_op_done_val - wait until an operation is completed
49  *	@adapter: the adapter performing the operation
50  *	@reg: the register to check for completion
51  *	@mask: a single-bit field within @reg that indicates completion
52  *	@polarity: the value of the field when the operation is completed
53  *	@attempts: number of check iterations
54  *	@delay: delay in usecs between iterations
55  *	@valp: where to store the value of the register at completion time
56  *
57  *	Wait until an operation is completed by checking a bit in a register
58  *	up to @attempts times.  If @valp is not NULL the value of the register
59  *	at the time it indicated completion is stored there.  Returns 0 if the
60  *	operation completes and	-EAGAIN	otherwise.
61  */
t4_wait_op_done_val(struct adapter * adapter,int reg,u32 mask,int polarity,int attempts,int delay,u32 * valp)62 static int t4_wait_op_done_val(struct adapter *adapter, int reg, u32 mask,
63 			       int polarity, int attempts, int delay, u32 *valp)
64 {
65 	while (1) {
66 		u32 val = t4_read_reg(adapter, reg);
67 
68 		if (!!(val & mask) == polarity) {
69 			if (valp)
70 				*valp = val;
71 			return 0;
72 		}
73 		if (--attempts == 0)
74 			return -EAGAIN;
75 		if (delay)
76 			udelay(delay);
77 	}
78 }
79 
t4_wait_op_done(struct adapter * adapter,int reg,u32 mask,int polarity,int attempts,int delay)80 static inline int t4_wait_op_done(struct adapter *adapter, int reg, u32 mask,
81 				  int polarity, int attempts, int delay)
82 {
83 	return t4_wait_op_done_val(adapter, reg, mask, polarity, attempts,
84 				   delay, NULL);
85 }
86 
87  /**
88  *	t7_wait_sram_done - wait until an operation is completed
89  *	@adapter: the adapter performing the operation
90  *	@reg: the register to check for completion
91  *	@result_reg: register that holds the result value
92  *	@attempts: number of check iterations
93  *	@delay: delay in usecs between iterations
94  *	@valp: where to store the value of the result register at completion time
95  *
96  *	Waits until a specific bit in @reg is cleared, checking up to
97  *	@attempts times.Once the bit is cleared, reads from @result_reg
98  *	and stores the value in @valp if it is not NULL. Returns 0 if the
99  *	operation completes successfully and -EAGAIN if it times out.
100  */
t7_wait_sram_done(struct adapter * adap,int reg,int result_reg,int attempts,int delay,u32 * valp)101 static int t7_wait_sram_done(struct adapter *adap, int reg, int result_reg,
102 			     int attempts, int delay, u32 *valp)
103 {
104 	while (1) {
105 		u32 val = t4_read_reg(adap, reg);
106 
107 		/* Check if SramStart (bit 19) is cleared */
108 		if (!(val & (1 << 19))) {
109 			if (valp)
110 				*valp  = t4_read_reg(adap, result_reg);
111 			return 0;
112 		}
113 
114 		if (--attempts == 0)
115 			return -EAGAIN;
116 
117 		if (delay)
118 			udelay(delay);
119 	}
120 }
121 
122 /**
123  *	t4_set_reg_field - set a register field to a value
124  *	@adapter: the adapter to program
125  *	@addr: the register address
126  *	@mask: specifies the portion of the register to modify
127  *	@val: the new value for the register field
128  *
129  *	Sets a register field specified by the supplied mask to the
130  *	given value.
131  */
t4_set_reg_field(struct adapter * adapter,unsigned int addr,u32 mask,u32 val)132 void t4_set_reg_field(struct adapter *adapter, unsigned int addr, u32 mask,
133 		      u32 val)
134 {
135 	u32 v = t4_read_reg(adapter, addr) & ~mask;
136 
137 	t4_write_reg(adapter, addr, v | val);
138 	(void) t4_read_reg(adapter, addr);      /* flush */
139 }
140 
141 /**
142  *	t4_read_indirect - read indirectly addressed registers
143  *	@adap: the adapter
144  *	@addr_reg: register holding the indirect address
145  *	@data_reg: register holding the value of the indirect register
146  *	@vals: where the read register values are stored
147  *	@nregs: how many indirect registers to read
148  *	@start_idx: index of first indirect register to read
149  *
150  *	Reads registers that are accessed indirectly through an address/data
151  *	register pair.
152  */
t4_read_indirect(struct adapter * adap,unsigned int addr_reg,unsigned int data_reg,u32 * vals,unsigned int nregs,unsigned int start_idx)153 void t4_read_indirect(struct adapter *adap, unsigned int addr_reg,
154 			     unsigned int data_reg, u32 *vals,
155 			     unsigned int nregs, unsigned int start_idx)
156 {
157 	while (nregs--) {
158 		t4_write_reg(adap, addr_reg, start_idx);
159 		*vals++ = t4_read_reg(adap, data_reg);
160 		start_idx++;
161 	}
162 }
163 
164 /**
165  *	t4_write_indirect - write indirectly addressed registers
166  *	@adap: the adapter
167  *	@addr_reg: register holding the indirect addresses
168  *	@data_reg: register holding the value for the indirect registers
169  *	@vals: values to write
170  *	@nregs: how many indirect registers to write
171  *	@start_idx: address of first indirect register to write
172  *
173  *	Writes a sequential block of registers that are accessed indirectly
174  *	through an address/data register pair.
175  */
t4_write_indirect(struct adapter * adap,unsigned int addr_reg,unsigned int data_reg,const u32 * vals,unsigned int nregs,unsigned int start_idx)176 void t4_write_indirect(struct adapter *adap, unsigned int addr_reg,
177 		       unsigned int data_reg, const u32 *vals,
178 		       unsigned int nregs, unsigned int start_idx)
179 {
180 	while (nregs--) {
181 		t4_write_reg(adap, addr_reg, start_idx++);
182 		t4_write_reg(adap, data_reg, *vals++);
183 	}
184 }
185 
186 /*
187  * Read a 32-bit PCI Configuration Space register via the PCI-E backdoor
188  * mechanism.  This guarantees that we get the real value even if we're
189  * operating within a Virtual Machine and the Hypervisor is trapping our
190  * Configuration Space accesses.
191  *
192  * N.B. This routine should only be used as a last resort: the firmware uses
193  *      the backdoor registers on a regular basis and we can end up
194  *      conflicting with it's uses!
195  */
t4_hw_pci_read_cfg4(adapter_t * adap,int reg)196 u32 t4_hw_pci_read_cfg4(adapter_t *adap, int reg)
197 {
198 	u32 req = V_FUNCTION(adap->pf) | V_REGISTER(reg);
199 	u32 val;
200 
201 	if (chip_id(adap) <= CHELSIO_T5)
202 		req |= F_ENABLE;
203 	else
204 		req |= F_T6_ENABLE;
205 
206 	if (is_t4(adap))
207 		req |= F_LOCALCFG;
208 
209 	t4_write_reg(adap, A_PCIE_CFG_SPACE_REQ, req);
210 	val = t4_read_reg(adap, A_PCIE_CFG_SPACE_DATA);
211 
212 	/*
213 	 * Reset F_ENABLE to 0 so reads of PCIE_CFG_SPACE_DATA won't cause a
214 	 * Configuration Space read.  (None of the other fields matter when
215 	 * F_ENABLE is 0 so a simple register write is easier than a
216 	 * read-modify-write via t4_set_reg_field().)
217 	 */
218 	t4_write_reg(adap, A_PCIE_CFG_SPACE_REQ, 0);
219 
220 	return val;
221 }
222 
223 /*
224  * t4_report_fw_error - report firmware error
225  * @adap: the adapter
226  *
227  * The adapter firmware can indicate error conditions to the host.
228  * If the firmware has indicated an error, print out the reason for
229  * the firmware error.
230  */
t4_report_fw_error(struct adapter * adap)231 void t4_report_fw_error(struct adapter *adap)
232 {
233 	static const char *const reason[] = {
234 		"Crash",			/* PCIE_FW_EVAL_CRASH */
235 		"During Device Preparation",	/* PCIE_FW_EVAL_PREP */
236 		"During Device Configuration",	/* PCIE_FW_EVAL_CONF */
237 		"During Device Initialization",	/* PCIE_FW_EVAL_INIT */
238 		"Unexpected Event",		/* PCIE_FW_EVAL_UNEXPECTEDEVENT */
239 		"Insufficient Airflow",		/* PCIE_FW_EVAL_OVERHEAT */
240 		"Device Shutdown",		/* PCIE_FW_EVAL_DEVICESHUTDOWN */
241 		"Reserved",			/* reserved */
242 	};
243 	u32 pcie_fw;
244 
245 	pcie_fw = t4_read_reg(adap, A_PCIE_FW);
246 	if (pcie_fw & F_PCIE_FW_ERR) {
247 		CH_ERR(adap, "firmware reports adapter error: %s (0x%08x)\n",
248 		    reason[G_PCIE_FW_EVAL(pcie_fw)], pcie_fw);
249 	}
250 }
251 
252 /*
253  * Get the reply to a mailbox command and store it in @rpl in big-endian order.
254  */
get_mbox_rpl(struct adapter * adap,__be64 * rpl,int nflit,u32 mbox_addr)255 static void get_mbox_rpl(struct adapter *adap, __be64 *rpl, int nflit,
256 			 u32 mbox_addr)
257 {
258 	for ( ; nflit; nflit--, mbox_addr += 8)
259 		*rpl++ = cpu_to_be64(t4_read_reg64(adap, mbox_addr));
260 }
261 
262 /*
263  * Handle a FW assertion reported in a mailbox.
264  */
fw_asrt(struct adapter * adap,struct fw_debug_cmd * asrt)265 static void fw_asrt(struct adapter *adap, struct fw_debug_cmd *asrt)
266 {
267 	CH_ALERT(adap,
268 		  "FW assertion at %.16s:%u, val0 %#x, val1 %#x\n",
269 		  asrt->u.assert.filename_0_7,
270 		  be32_to_cpu(asrt->u.assert.line),
271 		  be32_to_cpu(asrt->u.assert.x),
272 		  be32_to_cpu(asrt->u.assert.y));
273 }
274 
275 struct port_tx_state {
276 	uint64_t rx_pause;
277 	uint64_t tx_frames;
278 };
279 
280 u32
t4_port_reg(struct adapter * adap,u8 port,u32 reg)281 t4_port_reg(struct adapter *adap, u8 port, u32 reg)
282 {
283 	if (chip_id(adap) > CHELSIO_T6)
284 		return T7_PORT_REG(port, reg);
285 	if (chip_id(adap) > CHELSIO_T4)
286 		return T5_PORT_REG(port, reg);
287 	return PORT_REG(port, reg);
288 }
289 
290 static void
read_tx_state_one(struct adapter * sc,int i,struct port_tx_state * tx_state)291 read_tx_state_one(struct adapter *sc, int i, struct port_tx_state *tx_state)
292 {
293 	uint32_t rx_pause_reg, tx_frames_reg;
294 
295 	rx_pause_reg = t4_port_reg(sc, i, A_MPS_PORT_STAT_RX_PORT_PAUSE_L);
296 	tx_frames_reg = t4_port_reg(sc, i, A_MPS_PORT_STAT_TX_PORT_FRAMES_L);
297 
298 	tx_state->rx_pause = t4_read_reg64(sc, rx_pause_reg);
299 	tx_state->tx_frames = t4_read_reg64(sc, tx_frames_reg);
300 }
301 
302 static void
read_tx_state(struct adapter * sc,struct port_tx_state * tx_state)303 read_tx_state(struct adapter *sc, struct port_tx_state *tx_state)
304 {
305 	int i;
306 
307 	for (i = 0; i < MAX_NCHAN; i++) {
308 		if (sc->chan_map[i] != 0xff)
309 			read_tx_state_one(sc, i, &tx_state[i]);
310 	}
311 }
312 
313 static void
check_tx_state(struct adapter * sc,struct port_tx_state * tx_state)314 check_tx_state(struct adapter *sc, struct port_tx_state *tx_state)
315 {
316 	uint32_t port_ctl_reg;
317 	uint64_t tx_frames, rx_pause;
318 	int i;
319 
320 	for (i = 0; i < MAX_NCHAN; i++) {
321 		if (sc->chan_map[i] == 0xff)
322 			continue;
323 		rx_pause = tx_state[i].rx_pause;
324 		tx_frames = tx_state[i].tx_frames;
325 		read_tx_state_one(sc, i, &tx_state[i]);	/* update */
326 
327 		port_ctl_reg = t4_port_reg(sc, i, A_MPS_PORT_CTL);
328 		if (t4_read_reg(sc, port_ctl_reg) & F_PORTTXEN &&
329 		    rx_pause != tx_state[i].rx_pause &&
330 		    tx_frames == tx_state[i].tx_frames) {
331 			t4_set_reg_field(sc, port_ctl_reg, F_PORTTXEN, 0);
332 			mdelay(1);
333 			t4_set_reg_field(sc, port_ctl_reg, F_PORTTXEN, F_PORTTXEN);
334 		}
335 	}
336 }
337 
338 #define X_CIM_PF_NOACCESS 0xeeeeeeee
339 /**
340  *	t4_wr_mbox_meat_timeout - send a command to FW through the given mailbox
341  *	@adap: the adapter
342  *	@mbox: index of the mailbox to use
343  *	@cmd: the command to write
344  *	@size: command length in bytes
345  *	@rpl: where to optionally store the reply
346  *	@sleep_ok: if true we may sleep while awaiting command completion
347  *	@timeout: time to wait for command to finish before timing out
348  *		(negative implies @sleep_ok=false)
349  *
350  *	Sends the given command to FW through the selected mailbox and waits
351  *	for the FW to execute the command.  If @rpl is not %NULL it is used to
352  *	store the FW's reply to the command.  The command and its optional
353  *	reply are of the same length.  Some FW commands like RESET and
354  *	INITIALIZE can take a considerable amount of time to execute.
355  *	@sleep_ok determines whether we may sleep while awaiting the response.
356  *	If sleeping is allowed we use progressive backoff otherwise we spin.
357  *	Note that passing in a negative @timeout is an alternate mechanism
358  *	for specifying @sleep_ok=false.  This is useful when a higher level
359  *	interface allows for specification of @timeout but not @sleep_ok ...
360  *
361  *	The return value is 0 on success or a negative errno on failure.  A
362  *	failure can happen either because we are not able to execute the
363  *	command or FW executes it but signals an error.  In the latter case
364  *	the return value is the error code indicated by FW (negated).
365  */
t4_wr_mbox_meat_timeout(struct adapter * adap,int mbox,const void * cmd,int size,void * rpl,bool sleep_ok,int timeout)366 int t4_wr_mbox_meat_timeout(struct adapter *adap, int mbox, const void *cmd,
367 			    int size, void *rpl, bool sleep_ok, int timeout)
368 {
369 	/*
370 	 * We delay in small increments at first in an effort to maintain
371 	 * responsiveness for simple, fast executing commands but then back
372 	 * off to larger delays to a maximum retry delay.
373 	 */
374 	static const int delay[] = {
375 		1, 1, 3, 5, 10, 10, 20, 50, 100
376 	};
377 	u32 v;
378 	u64 res;
379 	int i, ms, delay_idx, ret, next_tx_check;
380 	u32 data_reg = PF_REG(mbox, A_CIM_PF_MAILBOX_DATA);
381 	u32 ctl_reg = PF_REG(mbox, A_CIM_PF_MAILBOX_CTRL);
382 	u32 ctl;
383 	__be64 cmd_rpl[MBOX_LEN/8];
384 	u32 pcie_fw;
385 	struct port_tx_state tx_state[MAX_NPORTS];
386 
387 	if (adap->flags & CHK_MBOX_ACCESS)
388 		ASSERT_SYNCHRONIZED_OP(adap);
389 
390 	if (size <= 0 || (size & 15) || size > MBOX_LEN)
391 		return -EINVAL;
392 
393 	if (adap->flags & IS_VF) {
394 		if (chip_id(adap) >= CHELSIO_T6)
395 			data_reg = FW_T6VF_MBDATA_BASE_ADDR;
396 		else
397 			data_reg = FW_T4VF_MBDATA_BASE_ADDR;
398 		ctl_reg = VF_CIM_REG(A_CIM_VF_EXT_MAILBOX_CTRL);
399 	}
400 
401 	/*
402 	 * If we have a negative timeout, that implies that we can't sleep.
403 	 */
404 	if (timeout < 0) {
405 		sleep_ok = false;
406 		timeout = -timeout;
407 	}
408 
409 	/*
410 	 * Attempt to gain access to the mailbox.
411 	 */
412 	pcie_fw = 0;
413 	if (!(adap->flags & IS_VF)) {
414 		pcie_fw = t4_read_reg(adap, A_PCIE_FW);
415 		if (pcie_fw & F_PCIE_FW_ERR)
416 			goto failed;
417 	}
418 	for (i = 0; i < 4; i++) {
419 		ctl = t4_read_reg(adap, ctl_reg);
420 		v = G_MBOWNER(ctl);
421 		if (v != X_MBOWNER_NONE)
422 			break;
423 	}
424 
425 	/*
426 	 * If we were unable to gain access, report the error to our caller.
427 	 */
428 	if (v != X_MBOWNER_PL) {
429 		if (!(adap->flags & IS_VF)) {
430 			pcie_fw = t4_read_reg(adap, A_PCIE_FW);
431 			if (pcie_fw & F_PCIE_FW_ERR)
432 				goto failed;
433 		}
434 		ret = (v == X_MBOWNER_FW) ? -EBUSY : -ETIMEDOUT;
435 		return ret;
436 	}
437 
438 	/*
439 	 * If we gain ownership of the mailbox and there's a "valid" message
440 	 * in it, this is likely an asynchronous error message from the
441 	 * firmware.  So we'll report that and then proceed on with attempting
442 	 * to issue our own command ... which may well fail if the error
443 	 * presaged the firmware crashing ...
444 	 */
445 	if (ctl & F_MBMSGVALID) {
446 		CH_DUMP_MBOX(adap, mbox, data_reg, "VLD", NULL, true);
447 	}
448 
449 	/*
450 	 * Copy in the new mailbox command and send it on its way ...
451 	 */
452 	memset(cmd_rpl, 0, sizeof(cmd_rpl));
453 	memcpy(cmd_rpl, cmd, size);
454 	CH_DUMP_MBOX(adap, mbox, 0, "cmd", cmd_rpl, false);
455 	for (i = 0; i < ARRAY_SIZE(cmd_rpl); i++)
456 		t4_write_reg64(adap, data_reg + i * 8, be64_to_cpu(cmd_rpl[i]));
457 
458 	if (adap->flags & IS_VF) {
459 		/*
460 		 * For the VFs, the Mailbox Data "registers" are
461 		 * actually backed by T4's "MA" interface rather than
462 		 * PL Registers (as is the case for the PFs).  Because
463 		 * these are in different coherency domains, the write
464 		 * to the VF's PL-register-backed Mailbox Control can
465 		 * race in front of the writes to the MA-backed VF
466 		 * Mailbox Data "registers".  So we need to do a
467 		 * read-back on at least one byte of the VF Mailbox
468 		 * Data registers before doing the write to the VF
469 		 * Mailbox Control register.
470 		 */
471 		t4_read_reg(adap, data_reg);
472 	}
473 
474 	t4_write_reg(adap, ctl_reg, F_MBMSGVALID | V_MBOWNER(X_MBOWNER_FW));
475 	read_tx_state(adap, &tx_state[0]);	/* also flushes the write_reg */
476 	next_tx_check = 1000;
477 	delay_idx = 0;
478 	ms = delay[0];
479 
480 	/*
481 	 * Loop waiting for the reply; bail out if we time out or the firmware
482 	 * reports an error.
483 	 */
484 	for (i = 0; i < timeout; i += ms) {
485 		if (!(adap->flags & IS_VF)) {
486 			pcie_fw = t4_read_reg(adap, A_PCIE_FW);
487 			if (pcie_fw & F_PCIE_FW_ERR)
488 				break;
489 		}
490 
491 		if (i >= next_tx_check) {
492 			check_tx_state(adap, &tx_state[0]);
493 			next_tx_check = i + 1000;
494 		}
495 
496 		if (sleep_ok) {
497 			ms = delay[delay_idx];  /* last element may repeat */
498 			if (delay_idx < ARRAY_SIZE(delay) - 1)
499 				delay_idx++;
500 			msleep(ms);
501 		} else {
502 			mdelay(ms);
503 		}
504 
505 		v = t4_read_reg(adap, ctl_reg);
506 		if (v == X_CIM_PF_NOACCESS)
507 			continue;
508 		if (G_MBOWNER(v) == X_MBOWNER_PL) {
509 			if (!(v & F_MBMSGVALID)) {
510 				t4_write_reg(adap, ctl_reg,
511 					     V_MBOWNER(X_MBOWNER_NONE));
512 				continue;
513 			}
514 
515 			/*
516 			 * Retrieve the command reply and release the mailbox.
517 			 */
518 			get_mbox_rpl(adap, cmd_rpl, MBOX_LEN/8, data_reg);
519 			CH_DUMP_MBOX(adap, mbox, 0, "rpl", cmd_rpl, false);
520 			t4_write_reg(adap, ctl_reg, V_MBOWNER(X_MBOWNER_NONE));
521 
522 			res = be64_to_cpu(cmd_rpl[0]);
523 			if (G_FW_CMD_OP(res >> 32) == FW_DEBUG_CMD) {
524 				fw_asrt(adap, (struct fw_debug_cmd *)cmd_rpl);
525 				res = V_FW_CMD_RETVAL(EIO);
526 			} else if (rpl)
527 				memcpy(rpl, cmd_rpl, size);
528 			return -G_FW_CMD_RETVAL((int)res);
529 		}
530 	}
531 
532 	/*
533 	 * We timed out waiting for a reply to our mailbox command.  Report
534 	 * the error and also check to see if the firmware reported any
535 	 * errors ...
536 	 */
537 	CH_ERR(adap, "command %#x in mbox %d timed out (0x%08x).\n",
538 	    *(const u8 *)cmd, mbox, pcie_fw);
539 	CH_DUMP_MBOX(adap, mbox, 0, "cmdsent", cmd_rpl, true);
540 	CH_DUMP_MBOX(adap, mbox, data_reg, "current", NULL, true);
541 failed:
542 	adap->flags &= ~FW_OK;
543 	ret = pcie_fw & F_PCIE_FW_ERR ? -ENXIO : -ETIMEDOUT;
544 	t4_fatal_err(adap, true);
545 	return ret;
546 }
547 
t4_wr_mbox_meat(struct adapter * adap,int mbox,const void * cmd,int size,void * rpl,bool sleep_ok)548 int t4_wr_mbox_meat(struct adapter *adap, int mbox, const void *cmd, int size,
549 		    void *rpl, bool sleep_ok)
550 {
551 	return t4_wr_mbox_meat_timeout(adap, mbox, cmd, size, rpl,
552 				       sleep_ok, FW_CMD_MAX_TIMEOUT);
553 }
554 
t4_edc_err_read(struct adapter * adap,int idx)555 static int t4_edc_err_read(struct adapter *adap, int idx)
556 {
557 	u32 edc_ecc_err_addr_reg;
558 	u32 edc_bist_status_rdata_reg;
559 
560 	if (is_t4(adap)) {
561 		CH_WARN(adap, "%s: T4 NOT supported.\n", __func__);
562 		return 0;
563 	}
564 	if (idx != MEM_EDC0 && idx != MEM_EDC1) {
565 		CH_WARN(adap, "%s: idx %d NOT supported.\n", __func__, idx);
566 		return 0;
567 	}
568 
569 	edc_ecc_err_addr_reg = EDC_T5_REG(A_EDC_H_ECC_ERR_ADDR, idx);
570 	edc_bist_status_rdata_reg = EDC_T5_REG(A_EDC_H_BIST_STATUS_RDATA, idx);
571 
572 	CH_WARN(adap,
573 		"  edc%d err addr 0x%x: 0x%x.\n",
574 		idx, edc_ecc_err_addr_reg,
575 		t4_read_reg(adap, edc_ecc_err_addr_reg));
576 	CH_WARN(adap,
577 		"  bist: 0x%x, status %llx %llx %llx %llx %llx %llx %llx %llx %llx.\n",
578 		edc_bist_status_rdata_reg,
579 		(unsigned long long)t4_read_reg64(adap, edc_bist_status_rdata_reg),
580 		(unsigned long long)t4_read_reg64(adap, edc_bist_status_rdata_reg + 8),
581 		(unsigned long long)t4_read_reg64(adap, edc_bist_status_rdata_reg + 16),
582 		(unsigned long long)t4_read_reg64(adap, edc_bist_status_rdata_reg + 24),
583 		(unsigned long long)t4_read_reg64(adap, edc_bist_status_rdata_reg + 32),
584 		(unsigned long long)t4_read_reg64(adap, edc_bist_status_rdata_reg + 40),
585 		(unsigned long long)t4_read_reg64(adap, edc_bist_status_rdata_reg + 48),
586 		(unsigned long long)t4_read_reg64(adap, edc_bist_status_rdata_reg + 56),
587 		(unsigned long long)t4_read_reg64(adap, edc_bist_status_rdata_reg + 64));
588 
589 	return 0;
590 }
591 
592 /**
593  *	t4_mc_read - read from MC through backdoor accesses
594  *	@adap: the adapter
595  *	@idx: which MC to access
596  *	@addr: address of first byte requested
597  *	@data: 64 bytes of data containing the requested address
598  *	@ecc: where to store the corresponding 64-bit ECC word
599  *
600  *	Read 64 bytes of data from MC starting at a 64-byte-aligned address
601  *	that covers the requested address @addr.  If @parity is not %NULL it
602  *	is assigned the 64-bit ECC word for the read data.
603  */
t4_mc_read(struct adapter * adap,int idx,u32 addr,__be32 * data,u64 * ecc)604 int t4_mc_read(struct adapter *adap, int idx, u32 addr, __be32 *data, u64 *ecc)
605 {
606 	int i;
607 	u32 mc_bist_cmd_reg, mc_bist_cmd_addr_reg, mc_bist_cmd_len_reg;
608 	u32 mc_bist_status_rdata_reg, mc_bist_data_pattern_reg;
609 
610 	if (is_t4(adap)) {
611 		mc_bist_cmd_reg = A_MC_BIST_CMD;
612 		mc_bist_cmd_addr_reg = A_MC_BIST_CMD_ADDR;
613 		mc_bist_cmd_len_reg = A_MC_BIST_CMD_LEN;
614 		mc_bist_status_rdata_reg = A_MC_BIST_STATUS_RDATA;
615 		mc_bist_data_pattern_reg = A_MC_BIST_DATA_PATTERN;
616 	} else if (chip_id(adap) < CHELSIO_T7) {
617 		mc_bist_cmd_reg = MC_REG(A_MC_P_BIST_CMD, idx);
618 		mc_bist_cmd_addr_reg = MC_REG(A_MC_P_BIST_CMD_ADDR, idx);
619 		mc_bist_cmd_len_reg = MC_REG(A_MC_P_BIST_CMD_LEN, idx);
620 		mc_bist_status_rdata_reg = MC_REG(A_MC_P_BIST_STATUS_RDATA, idx);
621 		mc_bist_data_pattern_reg = MC_REG(A_MC_P_BIST_DATA_PATTERN, idx);
622 	} else {
623 		/* Need to figure out split mode and the rest. */
624 		return (-ENOTSUP);
625 	}
626 
627 	if (t4_read_reg(adap, mc_bist_cmd_reg) & F_START_BIST)
628 		return -EBUSY;
629 	t4_write_reg(adap, mc_bist_cmd_addr_reg, addr & ~0x3fU);
630 	t4_write_reg(adap, mc_bist_cmd_len_reg, 64);
631 	t4_write_reg(adap, mc_bist_data_pattern_reg, 0xc);
632 	t4_write_reg(adap, mc_bist_cmd_reg, V_BIST_OPCODE(1) |
633 		     F_START_BIST | V_BIST_CMD_GAP(1));
634 	i = t4_wait_op_done(adap, mc_bist_cmd_reg, F_START_BIST, 0, 10, 1);
635 	if (i)
636 		return i;
637 
638 #define MC_DATA(i) MC_BIST_STATUS_REG(mc_bist_status_rdata_reg, i)
639 
640 	for (i = 15; i >= 0; i--)
641 		*data++ = ntohl(t4_read_reg(adap, MC_DATA(i)));
642 	if (ecc)
643 		*ecc = t4_read_reg64(adap, MC_DATA(16));
644 #undef MC_DATA
645 	return 0;
646 }
647 
648 /**
649  *	t4_edc_read - read from EDC through backdoor accesses
650  *	@adap: the adapter
651  *	@idx: which EDC to access
652  *	@addr: address of first byte requested
653  *	@data: 64 bytes of data containing the requested address
654  *	@ecc: where to store the corresponding 64-bit ECC word
655  *
656  *	Read 64 bytes of data from EDC starting at a 64-byte-aligned address
657  *	that covers the requested address @addr.  If @parity is not %NULL it
658  *	is assigned the 64-bit ECC word for the read data.
659  */
t4_edc_read(struct adapter * adap,int idx,u32 addr,__be32 * data,u64 * ecc)660 int t4_edc_read(struct adapter *adap, int idx, u32 addr, __be32 *data, u64 *ecc)
661 {
662 	int i;
663 	u32 edc_bist_cmd_reg, edc_bist_cmd_addr_reg, edc_bist_cmd_len_reg;
664 	u32 edc_bist_cmd_data_pattern, edc_bist_status_rdata_reg;
665 
666 	if (is_t4(adap)) {
667 		edc_bist_cmd_reg = EDC_REG(A_EDC_BIST_CMD, idx);
668 		edc_bist_cmd_addr_reg = EDC_REG(A_EDC_BIST_CMD_ADDR, idx);
669 		edc_bist_cmd_len_reg = EDC_REG(A_EDC_BIST_CMD_LEN, idx);
670 		edc_bist_cmd_data_pattern = EDC_REG(A_EDC_BIST_DATA_PATTERN,
671 						    idx);
672 		edc_bist_status_rdata_reg = EDC_REG(A_EDC_BIST_STATUS_RDATA,
673 						    idx);
674 	} else {
675 		edc_bist_cmd_reg = EDC_T5_REG(A_EDC_H_BIST_CMD, idx);
676 		edc_bist_cmd_addr_reg = EDC_T5_REG(A_EDC_H_BIST_CMD_ADDR, idx);
677 		edc_bist_cmd_len_reg = EDC_T5_REG(A_EDC_H_BIST_CMD_LEN, idx);
678 		edc_bist_cmd_data_pattern = EDC_T5_REG(A_EDC_H_BIST_DATA_PATTERN,
679 						    idx);
680 		edc_bist_status_rdata_reg = EDC_T5_REG(A_EDC_H_BIST_STATUS_RDATA,
681 						    idx);
682 	}
683 
684 	if (t4_read_reg(adap, edc_bist_cmd_reg) & F_START_BIST)
685 		return -EBUSY;
686 	t4_write_reg(adap, edc_bist_cmd_addr_reg, addr & ~0x3fU);
687 	t4_write_reg(adap, edc_bist_cmd_len_reg, 64);
688 	t4_write_reg(adap, edc_bist_cmd_data_pattern, 0xc);
689 	t4_write_reg(adap, edc_bist_cmd_reg,
690 		     V_BIST_OPCODE(1) | V_BIST_CMD_GAP(1) | F_START_BIST);
691 	i = t4_wait_op_done(adap, edc_bist_cmd_reg, F_START_BIST, 0, 10, 1);
692 	if (i)
693 		return i;
694 
695 #define EDC_DATA(i) EDC_BIST_STATUS_REG(edc_bist_status_rdata_reg, i)
696 
697 	for (i = 15; i >= 0; i--)
698 		*data++ = ntohl(t4_read_reg(adap, EDC_DATA(i)));
699 	if (ecc)
700 		*ecc = t4_read_reg64(adap, EDC_DATA(16));
701 #undef EDC_DATA
702 	return 0;
703 }
704 
705 /**
706  *	t4_mem_read - read EDC 0, EDC 1 or MC into buffer
707  *	@adap: the adapter
708  *	@mtype: memory type: MEM_EDC0, MEM_EDC1 or MEM_MC
709  *	@addr: address within indicated memory type
710  *	@len: amount of memory to read
711  *	@buf: host memory buffer
712  *
713  *	Reads an [almost] arbitrary memory region in the firmware: the
714  *	firmware memory address, length and host buffer must be aligned on
715  *	32-bit boudaries.  The memory is returned as a raw byte sequence from
716  *	the firmware's memory.  If this memory contains data structures which
717  *	contain multi-byte integers, it's the callers responsibility to
718  *	perform appropriate byte order conversions.
719  */
t4_mem_read(struct adapter * adap,int mtype,u32 addr,u32 len,__be32 * buf)720 int t4_mem_read(struct adapter *adap, int mtype, u32 addr, u32 len,
721 		__be32 *buf)
722 {
723 	u32 pos, start, end, offset;
724 	int ret;
725 
726 	/*
727 	 * Argument sanity checks ...
728 	 */
729 	if ((addr & 0x3) || (len & 0x3))
730 		return -EINVAL;
731 
732 	/*
733 	 * The underlaying EDC/MC read routines read 64 bytes at a time so we
734 	 * need to round down the start and round up the end.  We'll start
735 	 * copying out of the first line at (addr - start) a word at a time.
736 	 */
737 	start = rounddown2(addr, 64);
738 	end = roundup2(addr + len, 64);
739 	offset = (addr - start)/sizeof(__be32);
740 
741 	for (pos = start; pos < end; pos += 64, offset = 0) {
742 		__be32 data[16];
743 
744 		/*
745 		 * Read the chip's memory block and bail if there's an error.
746 		 */
747 		if ((mtype == MEM_MC) || (mtype == MEM_MC1))
748 			ret = t4_mc_read(adap, mtype - MEM_MC, pos, data, NULL);
749 		else
750 			ret = t4_edc_read(adap, mtype, pos, data, NULL);
751 		if (ret)
752 			return ret;
753 
754 		/*
755 		 * Copy the data into the caller's memory buffer.
756 		 */
757 		while (offset < 16 && len > 0) {
758 			*buf++ = data[offset++];
759 			len -= sizeof(__be32);
760 		}
761 	}
762 
763 	return 0;
764 }
765 
766 /*
767  * Return the specified PCI-E Configuration Space register from our Physical
768  * Function.  We try first via a Firmware LDST Command (if fw_attach != 0)
769  * since we prefer to let the firmware own all of these registers, but if that
770  * fails we go for it directly ourselves.
771  */
t4_read_pcie_cfg4(struct adapter * adap,int reg,int drv_fw_attach)772 u32 t4_read_pcie_cfg4(struct adapter *adap, int reg, int drv_fw_attach)
773 {
774 
775 	/*
776 	 * If fw_attach != 0, construct and send the Firmware LDST Command to
777 	 * retrieve the specified PCI-E Configuration Space register.
778 	 */
779 	if (drv_fw_attach != 0) {
780 		struct fw_ldst_cmd ldst_cmd;
781 		int ret;
782 
783 		memset(&ldst_cmd, 0, sizeof(ldst_cmd));
784 		ldst_cmd.op_to_addrspace =
785 			cpu_to_be32(V_FW_CMD_OP(FW_LDST_CMD) |
786 				    F_FW_CMD_REQUEST |
787 				    F_FW_CMD_READ |
788 				    V_FW_LDST_CMD_ADDRSPACE(FW_LDST_ADDRSPC_FUNC_PCIE));
789 		ldst_cmd.cycles_to_len16 = cpu_to_be32(FW_LEN16(ldst_cmd));
790 		ldst_cmd.u.pcie.select_naccess = V_FW_LDST_CMD_NACCESS(1);
791 		ldst_cmd.u.pcie.ctrl_to_fn =
792 			(F_FW_LDST_CMD_LC | V_FW_LDST_CMD_FN(adap->pf));
793 		ldst_cmd.u.pcie.r = reg;
794 
795 		/*
796 		 * If the LDST Command succeeds, return the result, otherwise
797 		 * fall through to reading it directly ourselves ...
798 		 */
799 		ret = t4_wr_mbox(adap, adap->mbox, &ldst_cmd, sizeof(ldst_cmd),
800 				 &ldst_cmd);
801 		if (ret == 0)
802 			return be32_to_cpu(ldst_cmd.u.pcie.data[0]);
803 
804 		CH_WARN(adap, "Firmware failed to return "
805 			"Configuration Space register %d, err = %d\n",
806 			reg, -ret);
807 	}
808 
809 	/*
810 	 * Read the desired Configuration Space register via the PCI-E
811 	 * Backdoor mechanism.
812 	 */
813 	return t4_hw_pci_read_cfg4(adap, reg);
814 }
815 
816 /**
817  *	t4_get_regs_len - return the size of the chips register set
818  *	@adapter: the adapter
819  *
820  *	Returns the size of the chip's BAR0 register space.
821  */
t4_get_regs_len(struct adapter * adapter)822 unsigned int t4_get_regs_len(struct adapter *adapter)
823 {
824 	unsigned int chip_version = chip_id(adapter);
825 
826 	switch (chip_version) {
827 	case CHELSIO_T4:
828 		if (adapter->flags & IS_VF)
829 			return FW_T4VF_REGMAP_SIZE;
830 		return T4_REGMAP_SIZE;
831 
832 	case CHELSIO_T5:
833 	case CHELSIO_T6:
834 	case CHELSIO_T7:
835 		if (adapter->flags & IS_VF)
836 			return FW_T4VF_REGMAP_SIZE;
837 		return T5_REGMAP_SIZE;
838 	}
839 
840 	CH_ERR(adapter,
841 		"Unsupported chip version %d\n", chip_version);
842 	return 0;
843 }
844 
845 /**
846  *	t4_get_regs - read chip registers into provided buffer
847  *	@adap: the adapter
848  *	@buf: register buffer
849  *	@buf_size: size (in bytes) of register buffer
850  *
851  *	If the provided register buffer isn't large enough for the chip's
852  *	full register range, the register dump will be truncated to the
853  *	register buffer's size.
854  */
t4_get_regs(struct adapter * adap,u8 * buf,size_t buf_size)855 void t4_get_regs(struct adapter *adap, u8 *buf, size_t buf_size)
856 {
857 	static const unsigned int t4_reg_ranges[] = {
858 		0x1008, 0x1108,
859 		0x1180, 0x1184,
860 		0x1190, 0x1194,
861 		0x11a0, 0x11a4,
862 		0x11b0, 0x11b4,
863 		0x11fc, 0x123c,
864 		0x1300, 0x173c,
865 		0x1800, 0x18fc,
866 		0x3000, 0x30d8,
867 		0x30e0, 0x30e4,
868 		0x30ec, 0x5910,
869 		0x5920, 0x5924,
870 		0x5960, 0x5960,
871 		0x5968, 0x5968,
872 		0x5970, 0x5970,
873 		0x5978, 0x5978,
874 		0x5980, 0x5980,
875 		0x5988, 0x5988,
876 		0x5990, 0x5990,
877 		0x5998, 0x5998,
878 		0x59a0, 0x59d4,
879 		0x5a00, 0x5ae0,
880 		0x5ae8, 0x5ae8,
881 		0x5af0, 0x5af0,
882 		0x5af8, 0x5af8,
883 		0x6000, 0x6098,
884 		0x6100, 0x6150,
885 		0x6200, 0x6208,
886 		0x6240, 0x6248,
887 		0x6280, 0x62b0,
888 		0x62c0, 0x6338,
889 		0x6370, 0x638c,
890 		0x6400, 0x643c,
891 		0x6500, 0x6524,
892 		0x6a00, 0x6a04,
893 		0x6a14, 0x6a38,
894 		0x6a60, 0x6a70,
895 		0x6a78, 0x6a78,
896 		0x6b00, 0x6b0c,
897 		0x6b1c, 0x6b84,
898 		0x6bf0, 0x6bf8,
899 		0x6c00, 0x6c0c,
900 		0x6c1c, 0x6c84,
901 		0x6cf0, 0x6cf8,
902 		0x6d00, 0x6d0c,
903 		0x6d1c, 0x6d84,
904 		0x6df0, 0x6df8,
905 		0x6e00, 0x6e0c,
906 		0x6e1c, 0x6e84,
907 		0x6ef0, 0x6ef8,
908 		0x6f00, 0x6f0c,
909 		0x6f1c, 0x6f84,
910 		0x6ff0, 0x6ff8,
911 		0x7000, 0x700c,
912 		0x701c, 0x7084,
913 		0x70f0, 0x70f8,
914 		0x7100, 0x710c,
915 		0x711c, 0x7184,
916 		0x71f0, 0x71f8,
917 		0x7200, 0x720c,
918 		0x721c, 0x7284,
919 		0x72f0, 0x72f8,
920 		0x7300, 0x730c,
921 		0x731c, 0x7384,
922 		0x73f0, 0x73f8,
923 		0x7400, 0x7450,
924 		0x7500, 0x7530,
925 		0x7600, 0x760c,
926 		0x7614, 0x761c,
927 		0x7680, 0x76cc,
928 		0x7700, 0x7798,
929 		0x77c0, 0x77fc,
930 		0x7900, 0x79fc,
931 		0x7b00, 0x7b58,
932 		0x7b60, 0x7b84,
933 		0x7b8c, 0x7c38,
934 		0x7d00, 0x7d38,
935 		0x7d40, 0x7d80,
936 		0x7d8c, 0x7ddc,
937 		0x7de4, 0x7e04,
938 		0x7e10, 0x7e1c,
939 		0x7e24, 0x7e38,
940 		0x7e40, 0x7e44,
941 		0x7e4c, 0x7e78,
942 		0x7e80, 0x7ea4,
943 		0x7eac, 0x7edc,
944 		0x7ee8, 0x7efc,
945 		0x8dc0, 0x8e04,
946 		0x8e10, 0x8e1c,
947 		0x8e30, 0x8e78,
948 		0x8ea0, 0x8eb8,
949 		0x8ec0, 0x8f6c,
950 		0x8fc0, 0x9008,
951 		0x9010, 0x9058,
952 		0x9060, 0x9060,
953 		0x9068, 0x9074,
954 		0x90fc, 0x90fc,
955 		0x9400, 0x9408,
956 		0x9410, 0x9458,
957 		0x9600, 0x9600,
958 		0x9608, 0x9638,
959 		0x9640, 0x96bc,
960 		0x9800, 0x9808,
961 		0x9820, 0x983c,
962 		0x9850, 0x9864,
963 		0x9c00, 0x9c6c,
964 		0x9c80, 0x9cec,
965 		0x9d00, 0x9d6c,
966 		0x9d80, 0x9dec,
967 		0x9e00, 0x9e6c,
968 		0x9e80, 0x9eec,
969 		0x9f00, 0x9f6c,
970 		0x9f80, 0x9fec,
971 		0xd004, 0xd004,
972 		0xd010, 0xd03c,
973 		0xdfc0, 0xdfe0,
974 		0xe000, 0xea7c,
975 		0xf000, 0x11110,
976 		0x11118, 0x11190,
977 		0x19040, 0x1906c,
978 		0x19078, 0x19080,
979 		0x1908c, 0x190e4,
980 		0x190f0, 0x190f8,
981 		0x19100, 0x19110,
982 		0x19120, 0x19124,
983 		0x19150, 0x19194,
984 		0x1919c, 0x191b0,
985 		0x191d0, 0x191e8,
986 		0x19238, 0x1924c,
987 		0x193f8, 0x1943c,
988 		0x1944c, 0x19474,
989 		0x19490, 0x194e0,
990 		0x194f0, 0x194f8,
991 		0x19800, 0x19c08,
992 		0x19c10, 0x19c90,
993 		0x19ca0, 0x19ce4,
994 		0x19cf0, 0x19d40,
995 		0x19d50, 0x19d94,
996 		0x19da0, 0x19de8,
997 		0x19df0, 0x19e40,
998 		0x19e50, 0x19e90,
999 		0x19ea0, 0x19f4c,
1000 		0x1a000, 0x1a004,
1001 		0x1a010, 0x1a06c,
1002 		0x1a0b0, 0x1a0e4,
1003 		0x1a0ec, 0x1a0f4,
1004 		0x1a100, 0x1a108,
1005 		0x1a114, 0x1a120,
1006 		0x1a128, 0x1a130,
1007 		0x1a138, 0x1a138,
1008 		0x1a190, 0x1a1c4,
1009 		0x1a1fc, 0x1a1fc,
1010 		0x1e040, 0x1e04c,
1011 		0x1e284, 0x1e28c,
1012 		0x1e2c0, 0x1e2c0,
1013 		0x1e2e0, 0x1e2e0,
1014 		0x1e300, 0x1e384,
1015 		0x1e3c0, 0x1e3c8,
1016 		0x1e440, 0x1e44c,
1017 		0x1e684, 0x1e68c,
1018 		0x1e6c0, 0x1e6c0,
1019 		0x1e6e0, 0x1e6e0,
1020 		0x1e700, 0x1e784,
1021 		0x1e7c0, 0x1e7c8,
1022 		0x1e840, 0x1e84c,
1023 		0x1ea84, 0x1ea8c,
1024 		0x1eac0, 0x1eac0,
1025 		0x1eae0, 0x1eae0,
1026 		0x1eb00, 0x1eb84,
1027 		0x1ebc0, 0x1ebc8,
1028 		0x1ec40, 0x1ec4c,
1029 		0x1ee84, 0x1ee8c,
1030 		0x1eec0, 0x1eec0,
1031 		0x1eee0, 0x1eee0,
1032 		0x1ef00, 0x1ef84,
1033 		0x1efc0, 0x1efc8,
1034 		0x1f040, 0x1f04c,
1035 		0x1f284, 0x1f28c,
1036 		0x1f2c0, 0x1f2c0,
1037 		0x1f2e0, 0x1f2e0,
1038 		0x1f300, 0x1f384,
1039 		0x1f3c0, 0x1f3c8,
1040 		0x1f440, 0x1f44c,
1041 		0x1f684, 0x1f68c,
1042 		0x1f6c0, 0x1f6c0,
1043 		0x1f6e0, 0x1f6e0,
1044 		0x1f700, 0x1f784,
1045 		0x1f7c0, 0x1f7c8,
1046 		0x1f840, 0x1f84c,
1047 		0x1fa84, 0x1fa8c,
1048 		0x1fac0, 0x1fac0,
1049 		0x1fae0, 0x1fae0,
1050 		0x1fb00, 0x1fb84,
1051 		0x1fbc0, 0x1fbc8,
1052 		0x1fc40, 0x1fc4c,
1053 		0x1fe84, 0x1fe8c,
1054 		0x1fec0, 0x1fec0,
1055 		0x1fee0, 0x1fee0,
1056 		0x1ff00, 0x1ff84,
1057 		0x1ffc0, 0x1ffc8,
1058 		0x20000, 0x2002c,
1059 		0x20100, 0x2013c,
1060 		0x20190, 0x201a0,
1061 		0x201a8, 0x201b8,
1062 		0x201c4, 0x201c8,
1063 		0x20200, 0x20318,
1064 		0x20400, 0x204b4,
1065 		0x204c0, 0x20528,
1066 		0x20540, 0x20614,
1067 		0x21000, 0x21040,
1068 		0x2104c, 0x21060,
1069 		0x210c0, 0x210ec,
1070 		0x21200, 0x21268,
1071 		0x21270, 0x21284,
1072 		0x212fc, 0x21388,
1073 		0x21400, 0x21404,
1074 		0x21500, 0x21500,
1075 		0x21510, 0x21518,
1076 		0x2152c, 0x21530,
1077 		0x2153c, 0x2153c,
1078 		0x21550, 0x21554,
1079 		0x21600, 0x21600,
1080 		0x21608, 0x2161c,
1081 		0x21624, 0x21628,
1082 		0x21630, 0x21634,
1083 		0x2163c, 0x2163c,
1084 		0x21700, 0x2171c,
1085 		0x21780, 0x2178c,
1086 		0x21800, 0x21818,
1087 		0x21820, 0x21828,
1088 		0x21830, 0x21848,
1089 		0x21850, 0x21854,
1090 		0x21860, 0x21868,
1091 		0x21870, 0x21870,
1092 		0x21878, 0x21898,
1093 		0x218a0, 0x218a8,
1094 		0x218b0, 0x218c8,
1095 		0x218d0, 0x218d4,
1096 		0x218e0, 0x218e8,
1097 		0x218f0, 0x218f0,
1098 		0x218f8, 0x21a18,
1099 		0x21a20, 0x21a28,
1100 		0x21a30, 0x21a48,
1101 		0x21a50, 0x21a54,
1102 		0x21a60, 0x21a68,
1103 		0x21a70, 0x21a70,
1104 		0x21a78, 0x21a98,
1105 		0x21aa0, 0x21aa8,
1106 		0x21ab0, 0x21ac8,
1107 		0x21ad0, 0x21ad4,
1108 		0x21ae0, 0x21ae8,
1109 		0x21af0, 0x21af0,
1110 		0x21af8, 0x21c18,
1111 		0x21c20, 0x21c20,
1112 		0x21c28, 0x21c30,
1113 		0x21c38, 0x21c38,
1114 		0x21c80, 0x21c98,
1115 		0x21ca0, 0x21ca8,
1116 		0x21cb0, 0x21cc8,
1117 		0x21cd0, 0x21cd4,
1118 		0x21ce0, 0x21ce8,
1119 		0x21cf0, 0x21cf0,
1120 		0x21cf8, 0x21d7c,
1121 		0x21e00, 0x21e04,
1122 		0x22000, 0x2202c,
1123 		0x22100, 0x2213c,
1124 		0x22190, 0x221a0,
1125 		0x221a8, 0x221b8,
1126 		0x221c4, 0x221c8,
1127 		0x22200, 0x22318,
1128 		0x22400, 0x224b4,
1129 		0x224c0, 0x22528,
1130 		0x22540, 0x22614,
1131 		0x23000, 0x23040,
1132 		0x2304c, 0x23060,
1133 		0x230c0, 0x230ec,
1134 		0x23200, 0x23268,
1135 		0x23270, 0x23284,
1136 		0x232fc, 0x23388,
1137 		0x23400, 0x23404,
1138 		0x23500, 0x23500,
1139 		0x23510, 0x23518,
1140 		0x2352c, 0x23530,
1141 		0x2353c, 0x2353c,
1142 		0x23550, 0x23554,
1143 		0x23600, 0x23600,
1144 		0x23608, 0x2361c,
1145 		0x23624, 0x23628,
1146 		0x23630, 0x23634,
1147 		0x2363c, 0x2363c,
1148 		0x23700, 0x2371c,
1149 		0x23780, 0x2378c,
1150 		0x23800, 0x23818,
1151 		0x23820, 0x23828,
1152 		0x23830, 0x23848,
1153 		0x23850, 0x23854,
1154 		0x23860, 0x23868,
1155 		0x23870, 0x23870,
1156 		0x23878, 0x23898,
1157 		0x238a0, 0x238a8,
1158 		0x238b0, 0x238c8,
1159 		0x238d0, 0x238d4,
1160 		0x238e0, 0x238e8,
1161 		0x238f0, 0x238f0,
1162 		0x238f8, 0x23a18,
1163 		0x23a20, 0x23a28,
1164 		0x23a30, 0x23a48,
1165 		0x23a50, 0x23a54,
1166 		0x23a60, 0x23a68,
1167 		0x23a70, 0x23a70,
1168 		0x23a78, 0x23a98,
1169 		0x23aa0, 0x23aa8,
1170 		0x23ab0, 0x23ac8,
1171 		0x23ad0, 0x23ad4,
1172 		0x23ae0, 0x23ae8,
1173 		0x23af0, 0x23af0,
1174 		0x23af8, 0x23c18,
1175 		0x23c20, 0x23c20,
1176 		0x23c28, 0x23c30,
1177 		0x23c38, 0x23c38,
1178 		0x23c80, 0x23c98,
1179 		0x23ca0, 0x23ca8,
1180 		0x23cb0, 0x23cc8,
1181 		0x23cd0, 0x23cd4,
1182 		0x23ce0, 0x23ce8,
1183 		0x23cf0, 0x23cf0,
1184 		0x23cf8, 0x23d7c,
1185 		0x23e00, 0x23e04,
1186 		0x24000, 0x2402c,
1187 		0x24100, 0x2413c,
1188 		0x24190, 0x241a0,
1189 		0x241a8, 0x241b8,
1190 		0x241c4, 0x241c8,
1191 		0x24200, 0x24318,
1192 		0x24400, 0x244b4,
1193 		0x244c0, 0x24528,
1194 		0x24540, 0x24614,
1195 		0x25000, 0x25040,
1196 		0x2504c, 0x25060,
1197 		0x250c0, 0x250ec,
1198 		0x25200, 0x25268,
1199 		0x25270, 0x25284,
1200 		0x252fc, 0x25388,
1201 		0x25400, 0x25404,
1202 		0x25500, 0x25500,
1203 		0x25510, 0x25518,
1204 		0x2552c, 0x25530,
1205 		0x2553c, 0x2553c,
1206 		0x25550, 0x25554,
1207 		0x25600, 0x25600,
1208 		0x25608, 0x2561c,
1209 		0x25624, 0x25628,
1210 		0x25630, 0x25634,
1211 		0x2563c, 0x2563c,
1212 		0x25700, 0x2571c,
1213 		0x25780, 0x2578c,
1214 		0x25800, 0x25818,
1215 		0x25820, 0x25828,
1216 		0x25830, 0x25848,
1217 		0x25850, 0x25854,
1218 		0x25860, 0x25868,
1219 		0x25870, 0x25870,
1220 		0x25878, 0x25898,
1221 		0x258a0, 0x258a8,
1222 		0x258b0, 0x258c8,
1223 		0x258d0, 0x258d4,
1224 		0x258e0, 0x258e8,
1225 		0x258f0, 0x258f0,
1226 		0x258f8, 0x25a18,
1227 		0x25a20, 0x25a28,
1228 		0x25a30, 0x25a48,
1229 		0x25a50, 0x25a54,
1230 		0x25a60, 0x25a68,
1231 		0x25a70, 0x25a70,
1232 		0x25a78, 0x25a98,
1233 		0x25aa0, 0x25aa8,
1234 		0x25ab0, 0x25ac8,
1235 		0x25ad0, 0x25ad4,
1236 		0x25ae0, 0x25ae8,
1237 		0x25af0, 0x25af0,
1238 		0x25af8, 0x25c18,
1239 		0x25c20, 0x25c20,
1240 		0x25c28, 0x25c30,
1241 		0x25c38, 0x25c38,
1242 		0x25c80, 0x25c98,
1243 		0x25ca0, 0x25ca8,
1244 		0x25cb0, 0x25cc8,
1245 		0x25cd0, 0x25cd4,
1246 		0x25ce0, 0x25ce8,
1247 		0x25cf0, 0x25cf0,
1248 		0x25cf8, 0x25d7c,
1249 		0x25e00, 0x25e04,
1250 		0x26000, 0x2602c,
1251 		0x26100, 0x2613c,
1252 		0x26190, 0x261a0,
1253 		0x261a8, 0x261b8,
1254 		0x261c4, 0x261c8,
1255 		0x26200, 0x26318,
1256 		0x26400, 0x264b4,
1257 		0x264c0, 0x26528,
1258 		0x26540, 0x26614,
1259 		0x27000, 0x27040,
1260 		0x2704c, 0x27060,
1261 		0x270c0, 0x270ec,
1262 		0x27200, 0x27268,
1263 		0x27270, 0x27284,
1264 		0x272fc, 0x27388,
1265 		0x27400, 0x27404,
1266 		0x27500, 0x27500,
1267 		0x27510, 0x27518,
1268 		0x2752c, 0x27530,
1269 		0x2753c, 0x2753c,
1270 		0x27550, 0x27554,
1271 		0x27600, 0x27600,
1272 		0x27608, 0x2761c,
1273 		0x27624, 0x27628,
1274 		0x27630, 0x27634,
1275 		0x2763c, 0x2763c,
1276 		0x27700, 0x2771c,
1277 		0x27780, 0x2778c,
1278 		0x27800, 0x27818,
1279 		0x27820, 0x27828,
1280 		0x27830, 0x27848,
1281 		0x27850, 0x27854,
1282 		0x27860, 0x27868,
1283 		0x27870, 0x27870,
1284 		0x27878, 0x27898,
1285 		0x278a0, 0x278a8,
1286 		0x278b0, 0x278c8,
1287 		0x278d0, 0x278d4,
1288 		0x278e0, 0x278e8,
1289 		0x278f0, 0x278f0,
1290 		0x278f8, 0x27a18,
1291 		0x27a20, 0x27a28,
1292 		0x27a30, 0x27a48,
1293 		0x27a50, 0x27a54,
1294 		0x27a60, 0x27a68,
1295 		0x27a70, 0x27a70,
1296 		0x27a78, 0x27a98,
1297 		0x27aa0, 0x27aa8,
1298 		0x27ab0, 0x27ac8,
1299 		0x27ad0, 0x27ad4,
1300 		0x27ae0, 0x27ae8,
1301 		0x27af0, 0x27af0,
1302 		0x27af8, 0x27c18,
1303 		0x27c20, 0x27c20,
1304 		0x27c28, 0x27c30,
1305 		0x27c38, 0x27c38,
1306 		0x27c80, 0x27c98,
1307 		0x27ca0, 0x27ca8,
1308 		0x27cb0, 0x27cc8,
1309 		0x27cd0, 0x27cd4,
1310 		0x27ce0, 0x27ce8,
1311 		0x27cf0, 0x27cf0,
1312 		0x27cf8, 0x27d7c,
1313 		0x27e00, 0x27e04,
1314 	};
1315 
1316 	static const unsigned int t4vf_reg_ranges[] = {
1317 		VF_SGE_REG(A_SGE_VF_KDOORBELL), VF_SGE_REG(A_SGE_VF_GTS),
1318 		VF_MPS_REG(A_MPS_VF_CTL),
1319 		VF_MPS_REG(A_MPS_VF_STAT_RX_VF_ERR_FRAMES_H),
1320 		VF_PL_REG(A_PL_VF_WHOAMI), VF_PL_REG(A_PL_VF_WHOAMI),
1321 		VF_CIM_REG(A_CIM_VF_EXT_MAILBOX_CTRL),
1322 		VF_CIM_REG(A_CIM_VF_EXT_MAILBOX_STATUS),
1323 		FW_T4VF_MBDATA_BASE_ADDR,
1324 		FW_T4VF_MBDATA_BASE_ADDR +
1325 		((NUM_CIM_PF_MAILBOX_DATA_INSTANCES - 1) * 4),
1326 	};
1327 
1328 	static const unsigned int t5_reg_ranges[] = {
1329 		0x1008, 0x10c0,
1330 		0x10cc, 0x10f8,
1331 		0x1100, 0x1100,
1332 		0x110c, 0x1148,
1333 		0x1180, 0x1184,
1334 		0x1190, 0x1194,
1335 		0x11a0, 0x11a4,
1336 		0x11b0, 0x11b4,
1337 		0x11fc, 0x123c,
1338 		0x1280, 0x173c,
1339 		0x1800, 0x18fc,
1340 		0x3000, 0x3028,
1341 		0x3060, 0x30b0,
1342 		0x30b8, 0x30d8,
1343 		0x30e0, 0x30fc,
1344 		0x3140, 0x357c,
1345 		0x35a8, 0x35cc,
1346 		0x35ec, 0x35ec,
1347 		0x3600, 0x5624,
1348 		0x56cc, 0x56ec,
1349 		0x56f4, 0x5720,
1350 		0x5728, 0x575c,
1351 		0x580c, 0x5814,
1352 		0x5890, 0x589c,
1353 		0x58a4, 0x58ac,
1354 		0x58b8, 0x58bc,
1355 		0x5940, 0x59c8,
1356 		0x59d0, 0x59dc,
1357 		0x59fc, 0x5a18,
1358 		0x5a60, 0x5a70,
1359 		0x5a80, 0x5a9c,
1360 		0x5b94, 0x5bfc,
1361 		0x6000, 0x6020,
1362 		0x6028, 0x6040,
1363 		0x6058, 0x609c,
1364 		0x60a8, 0x614c,
1365 		0x7700, 0x7798,
1366 		0x77c0, 0x78fc,
1367 		0x7b00, 0x7b58,
1368 		0x7b60, 0x7b84,
1369 		0x7b8c, 0x7c54,
1370 		0x7d00, 0x7d38,
1371 		0x7d40, 0x7d80,
1372 		0x7d8c, 0x7ddc,
1373 		0x7de4, 0x7e04,
1374 		0x7e10, 0x7e1c,
1375 		0x7e24, 0x7e38,
1376 		0x7e40, 0x7e44,
1377 		0x7e4c, 0x7e78,
1378 		0x7e80, 0x7edc,
1379 		0x7ee8, 0x7efc,
1380 		0x8dc0, 0x8de0,
1381 		0x8df8, 0x8e04,
1382 		0x8e10, 0x8e84,
1383 		0x8ea0, 0x8f84,
1384 		0x8fc0, 0x9058,
1385 		0x9060, 0x9060,
1386 		0x9068, 0x90f8,
1387 		0x9400, 0x9408,
1388 		0x9410, 0x9470,
1389 		0x9600, 0x9600,
1390 		0x9608, 0x9638,
1391 		0x9640, 0x96f4,
1392 		0x9800, 0x9808,
1393 		0x9810, 0x9864,
1394 		0x9c00, 0x9c6c,
1395 		0x9c80, 0x9cec,
1396 		0x9d00, 0x9d6c,
1397 		0x9d80, 0x9dec,
1398 		0x9e00, 0x9e6c,
1399 		0x9e80, 0x9eec,
1400 		0x9f00, 0x9f6c,
1401 		0x9f80, 0xa020,
1402 		0xd000, 0xd004,
1403 		0xd010, 0xd03c,
1404 		0xdfc0, 0xdfe0,
1405 		0xe000, 0x1106c,
1406 		0x11074, 0x11088,
1407 		0x1109c, 0x11110,
1408 		0x11118, 0x1117c,
1409 		0x11190, 0x11204,
1410 		0x19040, 0x1906c,
1411 		0x19078, 0x19080,
1412 		0x1908c, 0x190e8,
1413 		0x190f0, 0x190f8,
1414 		0x19100, 0x19110,
1415 		0x19120, 0x19124,
1416 		0x19150, 0x19194,
1417 		0x1919c, 0x191b0,
1418 		0x191d0, 0x191e8,
1419 		0x19238, 0x19290,
1420 		0x193f8, 0x19428,
1421 		0x19430, 0x19444,
1422 		0x1944c, 0x1946c,
1423 		0x19474, 0x19474,
1424 		0x19490, 0x194cc,
1425 		0x194f0, 0x194f8,
1426 		0x19c00, 0x19c08,
1427 		0x19c10, 0x19c60,
1428 		0x19c94, 0x19ce4,
1429 		0x19cf0, 0x19d40,
1430 		0x19d50, 0x19d94,
1431 		0x19da0, 0x19de8,
1432 		0x19df0, 0x19e10,
1433 		0x19e50, 0x19e90,
1434 		0x19ea0, 0x19f24,
1435 		0x19f34, 0x19f34,
1436 		0x19f40, 0x19f50,
1437 		0x19f90, 0x19fb4,
1438 		0x19fc4, 0x19fe4,
1439 		0x1a000, 0x1a004,
1440 		0x1a010, 0x1a06c,
1441 		0x1a0b0, 0x1a0e4,
1442 		0x1a0ec, 0x1a0f8,
1443 		0x1a100, 0x1a108,
1444 		0x1a114, 0x1a130,
1445 		0x1a138, 0x1a1c4,
1446 		0x1a1fc, 0x1a1fc,
1447 		0x1e008, 0x1e00c,
1448 		0x1e040, 0x1e044,
1449 		0x1e04c, 0x1e04c,
1450 		0x1e284, 0x1e290,
1451 		0x1e2c0, 0x1e2c0,
1452 		0x1e2e0, 0x1e2e0,
1453 		0x1e300, 0x1e384,
1454 		0x1e3c0, 0x1e3c8,
1455 		0x1e408, 0x1e40c,
1456 		0x1e440, 0x1e444,
1457 		0x1e44c, 0x1e44c,
1458 		0x1e684, 0x1e690,
1459 		0x1e6c0, 0x1e6c0,
1460 		0x1e6e0, 0x1e6e0,
1461 		0x1e700, 0x1e784,
1462 		0x1e7c0, 0x1e7c8,
1463 		0x1e808, 0x1e80c,
1464 		0x1e840, 0x1e844,
1465 		0x1e84c, 0x1e84c,
1466 		0x1ea84, 0x1ea90,
1467 		0x1eac0, 0x1eac0,
1468 		0x1eae0, 0x1eae0,
1469 		0x1eb00, 0x1eb84,
1470 		0x1ebc0, 0x1ebc8,
1471 		0x1ec08, 0x1ec0c,
1472 		0x1ec40, 0x1ec44,
1473 		0x1ec4c, 0x1ec4c,
1474 		0x1ee84, 0x1ee90,
1475 		0x1eec0, 0x1eec0,
1476 		0x1eee0, 0x1eee0,
1477 		0x1ef00, 0x1ef84,
1478 		0x1efc0, 0x1efc8,
1479 		0x1f008, 0x1f00c,
1480 		0x1f040, 0x1f044,
1481 		0x1f04c, 0x1f04c,
1482 		0x1f284, 0x1f290,
1483 		0x1f2c0, 0x1f2c0,
1484 		0x1f2e0, 0x1f2e0,
1485 		0x1f300, 0x1f384,
1486 		0x1f3c0, 0x1f3c8,
1487 		0x1f408, 0x1f40c,
1488 		0x1f440, 0x1f444,
1489 		0x1f44c, 0x1f44c,
1490 		0x1f684, 0x1f690,
1491 		0x1f6c0, 0x1f6c0,
1492 		0x1f6e0, 0x1f6e0,
1493 		0x1f700, 0x1f784,
1494 		0x1f7c0, 0x1f7c8,
1495 		0x1f808, 0x1f80c,
1496 		0x1f840, 0x1f844,
1497 		0x1f84c, 0x1f84c,
1498 		0x1fa84, 0x1fa90,
1499 		0x1fac0, 0x1fac0,
1500 		0x1fae0, 0x1fae0,
1501 		0x1fb00, 0x1fb84,
1502 		0x1fbc0, 0x1fbc8,
1503 		0x1fc08, 0x1fc0c,
1504 		0x1fc40, 0x1fc44,
1505 		0x1fc4c, 0x1fc4c,
1506 		0x1fe84, 0x1fe90,
1507 		0x1fec0, 0x1fec0,
1508 		0x1fee0, 0x1fee0,
1509 		0x1ff00, 0x1ff84,
1510 		0x1ffc0, 0x1ffc8,
1511 		0x30000, 0x30030,
1512 		0x30100, 0x30144,
1513 		0x30190, 0x301a0,
1514 		0x301a8, 0x301b8,
1515 		0x301c4, 0x301c8,
1516 		0x301d0, 0x301d0,
1517 		0x30200, 0x30318,
1518 		0x30400, 0x304b4,
1519 		0x304c0, 0x3052c,
1520 		0x30540, 0x3061c,
1521 		0x30800, 0x30828,
1522 		0x30834, 0x30834,
1523 		0x308c0, 0x30908,
1524 		0x30910, 0x309ac,
1525 		0x30a00, 0x30a14,
1526 		0x30a1c, 0x30a2c,
1527 		0x30a44, 0x30a50,
1528 		0x30a74, 0x30a74,
1529 		0x30a7c, 0x30afc,
1530 		0x30b08, 0x30c24,
1531 		0x30d00, 0x30d00,
1532 		0x30d08, 0x30d14,
1533 		0x30d1c, 0x30d20,
1534 		0x30d3c, 0x30d3c,
1535 		0x30d48, 0x30d50,
1536 		0x31200, 0x3120c,
1537 		0x31220, 0x31220,
1538 		0x31240, 0x31240,
1539 		0x31600, 0x3160c,
1540 		0x31a00, 0x31a1c,
1541 		0x31e00, 0x31e20,
1542 		0x31e38, 0x31e3c,
1543 		0x31e80, 0x31e80,
1544 		0x31e88, 0x31ea8,
1545 		0x31eb0, 0x31eb4,
1546 		0x31ec8, 0x31ed4,
1547 		0x31fb8, 0x32004,
1548 		0x32200, 0x32200,
1549 		0x32208, 0x32240,
1550 		0x32248, 0x32280,
1551 		0x32288, 0x322c0,
1552 		0x322c8, 0x322fc,
1553 		0x32600, 0x32630,
1554 		0x32a00, 0x32abc,
1555 		0x32b00, 0x32b10,
1556 		0x32b20, 0x32b30,
1557 		0x32b40, 0x32b50,
1558 		0x32b60, 0x32b70,
1559 		0x33000, 0x33028,
1560 		0x33030, 0x33048,
1561 		0x33060, 0x33068,
1562 		0x33070, 0x3309c,
1563 		0x330f0, 0x33128,
1564 		0x33130, 0x33148,
1565 		0x33160, 0x33168,
1566 		0x33170, 0x3319c,
1567 		0x331f0, 0x33238,
1568 		0x33240, 0x33240,
1569 		0x33248, 0x33250,
1570 		0x3325c, 0x33264,
1571 		0x33270, 0x332b8,
1572 		0x332c0, 0x332e4,
1573 		0x332f8, 0x33338,
1574 		0x33340, 0x33340,
1575 		0x33348, 0x33350,
1576 		0x3335c, 0x33364,
1577 		0x33370, 0x333b8,
1578 		0x333c0, 0x333e4,
1579 		0x333f8, 0x33428,
1580 		0x33430, 0x33448,
1581 		0x33460, 0x33468,
1582 		0x33470, 0x3349c,
1583 		0x334f0, 0x33528,
1584 		0x33530, 0x33548,
1585 		0x33560, 0x33568,
1586 		0x33570, 0x3359c,
1587 		0x335f0, 0x33638,
1588 		0x33640, 0x33640,
1589 		0x33648, 0x33650,
1590 		0x3365c, 0x33664,
1591 		0x33670, 0x336b8,
1592 		0x336c0, 0x336e4,
1593 		0x336f8, 0x33738,
1594 		0x33740, 0x33740,
1595 		0x33748, 0x33750,
1596 		0x3375c, 0x33764,
1597 		0x33770, 0x337b8,
1598 		0x337c0, 0x337e4,
1599 		0x337f8, 0x337fc,
1600 		0x33814, 0x33814,
1601 		0x3382c, 0x3382c,
1602 		0x33880, 0x3388c,
1603 		0x338e8, 0x338ec,
1604 		0x33900, 0x33928,
1605 		0x33930, 0x33948,
1606 		0x33960, 0x33968,
1607 		0x33970, 0x3399c,
1608 		0x339f0, 0x33a38,
1609 		0x33a40, 0x33a40,
1610 		0x33a48, 0x33a50,
1611 		0x33a5c, 0x33a64,
1612 		0x33a70, 0x33ab8,
1613 		0x33ac0, 0x33ae4,
1614 		0x33af8, 0x33b10,
1615 		0x33b28, 0x33b28,
1616 		0x33b3c, 0x33b50,
1617 		0x33bf0, 0x33c10,
1618 		0x33c28, 0x33c28,
1619 		0x33c3c, 0x33c50,
1620 		0x33cf0, 0x33cfc,
1621 		0x34000, 0x34030,
1622 		0x34100, 0x34144,
1623 		0x34190, 0x341a0,
1624 		0x341a8, 0x341b8,
1625 		0x341c4, 0x341c8,
1626 		0x341d0, 0x341d0,
1627 		0x34200, 0x34318,
1628 		0x34400, 0x344b4,
1629 		0x344c0, 0x3452c,
1630 		0x34540, 0x3461c,
1631 		0x34800, 0x34828,
1632 		0x34834, 0x34834,
1633 		0x348c0, 0x34908,
1634 		0x34910, 0x349ac,
1635 		0x34a00, 0x34a14,
1636 		0x34a1c, 0x34a2c,
1637 		0x34a44, 0x34a50,
1638 		0x34a74, 0x34a74,
1639 		0x34a7c, 0x34afc,
1640 		0x34b08, 0x34c24,
1641 		0x34d00, 0x34d00,
1642 		0x34d08, 0x34d14,
1643 		0x34d1c, 0x34d20,
1644 		0x34d3c, 0x34d3c,
1645 		0x34d48, 0x34d50,
1646 		0x35200, 0x3520c,
1647 		0x35220, 0x35220,
1648 		0x35240, 0x35240,
1649 		0x35600, 0x3560c,
1650 		0x35a00, 0x35a1c,
1651 		0x35e00, 0x35e20,
1652 		0x35e38, 0x35e3c,
1653 		0x35e80, 0x35e80,
1654 		0x35e88, 0x35ea8,
1655 		0x35eb0, 0x35eb4,
1656 		0x35ec8, 0x35ed4,
1657 		0x35fb8, 0x36004,
1658 		0x36200, 0x36200,
1659 		0x36208, 0x36240,
1660 		0x36248, 0x36280,
1661 		0x36288, 0x362c0,
1662 		0x362c8, 0x362fc,
1663 		0x36600, 0x36630,
1664 		0x36a00, 0x36abc,
1665 		0x36b00, 0x36b10,
1666 		0x36b20, 0x36b30,
1667 		0x36b40, 0x36b50,
1668 		0x36b60, 0x36b70,
1669 		0x37000, 0x37028,
1670 		0x37030, 0x37048,
1671 		0x37060, 0x37068,
1672 		0x37070, 0x3709c,
1673 		0x370f0, 0x37128,
1674 		0x37130, 0x37148,
1675 		0x37160, 0x37168,
1676 		0x37170, 0x3719c,
1677 		0x371f0, 0x37238,
1678 		0x37240, 0x37240,
1679 		0x37248, 0x37250,
1680 		0x3725c, 0x37264,
1681 		0x37270, 0x372b8,
1682 		0x372c0, 0x372e4,
1683 		0x372f8, 0x37338,
1684 		0x37340, 0x37340,
1685 		0x37348, 0x37350,
1686 		0x3735c, 0x37364,
1687 		0x37370, 0x373b8,
1688 		0x373c0, 0x373e4,
1689 		0x373f8, 0x37428,
1690 		0x37430, 0x37448,
1691 		0x37460, 0x37468,
1692 		0x37470, 0x3749c,
1693 		0x374f0, 0x37528,
1694 		0x37530, 0x37548,
1695 		0x37560, 0x37568,
1696 		0x37570, 0x3759c,
1697 		0x375f0, 0x37638,
1698 		0x37640, 0x37640,
1699 		0x37648, 0x37650,
1700 		0x3765c, 0x37664,
1701 		0x37670, 0x376b8,
1702 		0x376c0, 0x376e4,
1703 		0x376f8, 0x37738,
1704 		0x37740, 0x37740,
1705 		0x37748, 0x37750,
1706 		0x3775c, 0x37764,
1707 		0x37770, 0x377b8,
1708 		0x377c0, 0x377e4,
1709 		0x377f8, 0x377fc,
1710 		0x37814, 0x37814,
1711 		0x3782c, 0x3782c,
1712 		0x37880, 0x3788c,
1713 		0x378e8, 0x378ec,
1714 		0x37900, 0x37928,
1715 		0x37930, 0x37948,
1716 		0x37960, 0x37968,
1717 		0x37970, 0x3799c,
1718 		0x379f0, 0x37a38,
1719 		0x37a40, 0x37a40,
1720 		0x37a48, 0x37a50,
1721 		0x37a5c, 0x37a64,
1722 		0x37a70, 0x37ab8,
1723 		0x37ac0, 0x37ae4,
1724 		0x37af8, 0x37b10,
1725 		0x37b28, 0x37b28,
1726 		0x37b3c, 0x37b50,
1727 		0x37bf0, 0x37c10,
1728 		0x37c28, 0x37c28,
1729 		0x37c3c, 0x37c50,
1730 		0x37cf0, 0x37cfc,
1731 		0x38000, 0x38030,
1732 		0x38100, 0x38144,
1733 		0x38190, 0x381a0,
1734 		0x381a8, 0x381b8,
1735 		0x381c4, 0x381c8,
1736 		0x381d0, 0x381d0,
1737 		0x38200, 0x38318,
1738 		0x38400, 0x384b4,
1739 		0x384c0, 0x3852c,
1740 		0x38540, 0x3861c,
1741 		0x38800, 0x38828,
1742 		0x38834, 0x38834,
1743 		0x388c0, 0x38908,
1744 		0x38910, 0x389ac,
1745 		0x38a00, 0x38a14,
1746 		0x38a1c, 0x38a2c,
1747 		0x38a44, 0x38a50,
1748 		0x38a74, 0x38a74,
1749 		0x38a7c, 0x38afc,
1750 		0x38b08, 0x38c24,
1751 		0x38d00, 0x38d00,
1752 		0x38d08, 0x38d14,
1753 		0x38d1c, 0x38d20,
1754 		0x38d3c, 0x38d3c,
1755 		0x38d48, 0x38d50,
1756 		0x39200, 0x3920c,
1757 		0x39220, 0x39220,
1758 		0x39240, 0x39240,
1759 		0x39600, 0x3960c,
1760 		0x39a00, 0x39a1c,
1761 		0x39e00, 0x39e20,
1762 		0x39e38, 0x39e3c,
1763 		0x39e80, 0x39e80,
1764 		0x39e88, 0x39ea8,
1765 		0x39eb0, 0x39eb4,
1766 		0x39ec8, 0x39ed4,
1767 		0x39fb8, 0x3a004,
1768 		0x3a200, 0x3a200,
1769 		0x3a208, 0x3a240,
1770 		0x3a248, 0x3a280,
1771 		0x3a288, 0x3a2c0,
1772 		0x3a2c8, 0x3a2fc,
1773 		0x3a600, 0x3a630,
1774 		0x3aa00, 0x3aabc,
1775 		0x3ab00, 0x3ab10,
1776 		0x3ab20, 0x3ab30,
1777 		0x3ab40, 0x3ab50,
1778 		0x3ab60, 0x3ab70,
1779 		0x3b000, 0x3b028,
1780 		0x3b030, 0x3b048,
1781 		0x3b060, 0x3b068,
1782 		0x3b070, 0x3b09c,
1783 		0x3b0f0, 0x3b128,
1784 		0x3b130, 0x3b148,
1785 		0x3b160, 0x3b168,
1786 		0x3b170, 0x3b19c,
1787 		0x3b1f0, 0x3b238,
1788 		0x3b240, 0x3b240,
1789 		0x3b248, 0x3b250,
1790 		0x3b25c, 0x3b264,
1791 		0x3b270, 0x3b2b8,
1792 		0x3b2c0, 0x3b2e4,
1793 		0x3b2f8, 0x3b338,
1794 		0x3b340, 0x3b340,
1795 		0x3b348, 0x3b350,
1796 		0x3b35c, 0x3b364,
1797 		0x3b370, 0x3b3b8,
1798 		0x3b3c0, 0x3b3e4,
1799 		0x3b3f8, 0x3b428,
1800 		0x3b430, 0x3b448,
1801 		0x3b460, 0x3b468,
1802 		0x3b470, 0x3b49c,
1803 		0x3b4f0, 0x3b528,
1804 		0x3b530, 0x3b548,
1805 		0x3b560, 0x3b568,
1806 		0x3b570, 0x3b59c,
1807 		0x3b5f0, 0x3b638,
1808 		0x3b640, 0x3b640,
1809 		0x3b648, 0x3b650,
1810 		0x3b65c, 0x3b664,
1811 		0x3b670, 0x3b6b8,
1812 		0x3b6c0, 0x3b6e4,
1813 		0x3b6f8, 0x3b738,
1814 		0x3b740, 0x3b740,
1815 		0x3b748, 0x3b750,
1816 		0x3b75c, 0x3b764,
1817 		0x3b770, 0x3b7b8,
1818 		0x3b7c0, 0x3b7e4,
1819 		0x3b7f8, 0x3b7fc,
1820 		0x3b814, 0x3b814,
1821 		0x3b82c, 0x3b82c,
1822 		0x3b880, 0x3b88c,
1823 		0x3b8e8, 0x3b8ec,
1824 		0x3b900, 0x3b928,
1825 		0x3b930, 0x3b948,
1826 		0x3b960, 0x3b968,
1827 		0x3b970, 0x3b99c,
1828 		0x3b9f0, 0x3ba38,
1829 		0x3ba40, 0x3ba40,
1830 		0x3ba48, 0x3ba50,
1831 		0x3ba5c, 0x3ba64,
1832 		0x3ba70, 0x3bab8,
1833 		0x3bac0, 0x3bae4,
1834 		0x3baf8, 0x3bb10,
1835 		0x3bb28, 0x3bb28,
1836 		0x3bb3c, 0x3bb50,
1837 		0x3bbf0, 0x3bc10,
1838 		0x3bc28, 0x3bc28,
1839 		0x3bc3c, 0x3bc50,
1840 		0x3bcf0, 0x3bcfc,
1841 		0x3c000, 0x3c030,
1842 		0x3c100, 0x3c144,
1843 		0x3c190, 0x3c1a0,
1844 		0x3c1a8, 0x3c1b8,
1845 		0x3c1c4, 0x3c1c8,
1846 		0x3c1d0, 0x3c1d0,
1847 		0x3c200, 0x3c318,
1848 		0x3c400, 0x3c4b4,
1849 		0x3c4c0, 0x3c52c,
1850 		0x3c540, 0x3c61c,
1851 		0x3c800, 0x3c828,
1852 		0x3c834, 0x3c834,
1853 		0x3c8c0, 0x3c908,
1854 		0x3c910, 0x3c9ac,
1855 		0x3ca00, 0x3ca14,
1856 		0x3ca1c, 0x3ca2c,
1857 		0x3ca44, 0x3ca50,
1858 		0x3ca74, 0x3ca74,
1859 		0x3ca7c, 0x3cafc,
1860 		0x3cb08, 0x3cc24,
1861 		0x3cd00, 0x3cd00,
1862 		0x3cd08, 0x3cd14,
1863 		0x3cd1c, 0x3cd20,
1864 		0x3cd3c, 0x3cd3c,
1865 		0x3cd48, 0x3cd50,
1866 		0x3d200, 0x3d20c,
1867 		0x3d220, 0x3d220,
1868 		0x3d240, 0x3d240,
1869 		0x3d600, 0x3d60c,
1870 		0x3da00, 0x3da1c,
1871 		0x3de00, 0x3de20,
1872 		0x3de38, 0x3de3c,
1873 		0x3de80, 0x3de80,
1874 		0x3de88, 0x3dea8,
1875 		0x3deb0, 0x3deb4,
1876 		0x3dec8, 0x3ded4,
1877 		0x3dfb8, 0x3e004,
1878 		0x3e200, 0x3e200,
1879 		0x3e208, 0x3e240,
1880 		0x3e248, 0x3e280,
1881 		0x3e288, 0x3e2c0,
1882 		0x3e2c8, 0x3e2fc,
1883 		0x3e600, 0x3e630,
1884 		0x3ea00, 0x3eabc,
1885 		0x3eb00, 0x3eb10,
1886 		0x3eb20, 0x3eb30,
1887 		0x3eb40, 0x3eb50,
1888 		0x3eb60, 0x3eb70,
1889 		0x3f000, 0x3f028,
1890 		0x3f030, 0x3f048,
1891 		0x3f060, 0x3f068,
1892 		0x3f070, 0x3f09c,
1893 		0x3f0f0, 0x3f128,
1894 		0x3f130, 0x3f148,
1895 		0x3f160, 0x3f168,
1896 		0x3f170, 0x3f19c,
1897 		0x3f1f0, 0x3f238,
1898 		0x3f240, 0x3f240,
1899 		0x3f248, 0x3f250,
1900 		0x3f25c, 0x3f264,
1901 		0x3f270, 0x3f2b8,
1902 		0x3f2c0, 0x3f2e4,
1903 		0x3f2f8, 0x3f338,
1904 		0x3f340, 0x3f340,
1905 		0x3f348, 0x3f350,
1906 		0x3f35c, 0x3f364,
1907 		0x3f370, 0x3f3b8,
1908 		0x3f3c0, 0x3f3e4,
1909 		0x3f3f8, 0x3f428,
1910 		0x3f430, 0x3f448,
1911 		0x3f460, 0x3f468,
1912 		0x3f470, 0x3f49c,
1913 		0x3f4f0, 0x3f528,
1914 		0x3f530, 0x3f548,
1915 		0x3f560, 0x3f568,
1916 		0x3f570, 0x3f59c,
1917 		0x3f5f0, 0x3f638,
1918 		0x3f640, 0x3f640,
1919 		0x3f648, 0x3f650,
1920 		0x3f65c, 0x3f664,
1921 		0x3f670, 0x3f6b8,
1922 		0x3f6c0, 0x3f6e4,
1923 		0x3f6f8, 0x3f738,
1924 		0x3f740, 0x3f740,
1925 		0x3f748, 0x3f750,
1926 		0x3f75c, 0x3f764,
1927 		0x3f770, 0x3f7b8,
1928 		0x3f7c0, 0x3f7e4,
1929 		0x3f7f8, 0x3f7fc,
1930 		0x3f814, 0x3f814,
1931 		0x3f82c, 0x3f82c,
1932 		0x3f880, 0x3f88c,
1933 		0x3f8e8, 0x3f8ec,
1934 		0x3f900, 0x3f928,
1935 		0x3f930, 0x3f948,
1936 		0x3f960, 0x3f968,
1937 		0x3f970, 0x3f99c,
1938 		0x3f9f0, 0x3fa38,
1939 		0x3fa40, 0x3fa40,
1940 		0x3fa48, 0x3fa50,
1941 		0x3fa5c, 0x3fa64,
1942 		0x3fa70, 0x3fab8,
1943 		0x3fac0, 0x3fae4,
1944 		0x3faf8, 0x3fb10,
1945 		0x3fb28, 0x3fb28,
1946 		0x3fb3c, 0x3fb50,
1947 		0x3fbf0, 0x3fc10,
1948 		0x3fc28, 0x3fc28,
1949 		0x3fc3c, 0x3fc50,
1950 		0x3fcf0, 0x3fcfc,
1951 		0x40000, 0x4000c,
1952 		0x40040, 0x40050,
1953 		0x40060, 0x40068,
1954 		0x4007c, 0x4008c,
1955 		0x40094, 0x400b0,
1956 		0x400c0, 0x40144,
1957 		0x40180, 0x4018c,
1958 		0x40200, 0x40254,
1959 		0x40260, 0x40264,
1960 		0x40270, 0x40288,
1961 		0x40290, 0x40298,
1962 		0x402ac, 0x402c8,
1963 		0x402d0, 0x402e0,
1964 		0x402f0, 0x402f0,
1965 		0x40300, 0x4033c,
1966 		0x403f8, 0x403fc,
1967 		0x41304, 0x413c4,
1968 		0x41400, 0x4140c,
1969 		0x41414, 0x4141c,
1970 		0x41480, 0x414d0,
1971 		0x44000, 0x44054,
1972 		0x4405c, 0x44078,
1973 		0x440c0, 0x44174,
1974 		0x44180, 0x441ac,
1975 		0x441b4, 0x441b8,
1976 		0x441c0, 0x44254,
1977 		0x4425c, 0x44278,
1978 		0x442c0, 0x44374,
1979 		0x44380, 0x443ac,
1980 		0x443b4, 0x443b8,
1981 		0x443c0, 0x44454,
1982 		0x4445c, 0x44478,
1983 		0x444c0, 0x44574,
1984 		0x44580, 0x445ac,
1985 		0x445b4, 0x445b8,
1986 		0x445c0, 0x44654,
1987 		0x4465c, 0x44678,
1988 		0x446c0, 0x44774,
1989 		0x44780, 0x447ac,
1990 		0x447b4, 0x447b8,
1991 		0x447c0, 0x44854,
1992 		0x4485c, 0x44878,
1993 		0x448c0, 0x44974,
1994 		0x44980, 0x449ac,
1995 		0x449b4, 0x449b8,
1996 		0x449c0, 0x449fc,
1997 		0x45000, 0x45004,
1998 		0x45010, 0x45030,
1999 		0x45040, 0x45060,
2000 		0x45068, 0x45068,
2001 		0x45080, 0x45084,
2002 		0x450a0, 0x450b0,
2003 		0x45200, 0x45204,
2004 		0x45210, 0x45230,
2005 		0x45240, 0x45260,
2006 		0x45268, 0x45268,
2007 		0x45280, 0x45284,
2008 		0x452a0, 0x452b0,
2009 		0x460c0, 0x460e4,
2010 		0x47000, 0x4703c,
2011 		0x47044, 0x4708c,
2012 		0x47200, 0x47250,
2013 		0x47400, 0x47408,
2014 		0x47414, 0x47420,
2015 		0x47600, 0x47618,
2016 		0x47800, 0x47814,
2017 		0x48000, 0x4800c,
2018 		0x48040, 0x48050,
2019 		0x48060, 0x48068,
2020 		0x4807c, 0x4808c,
2021 		0x48094, 0x480b0,
2022 		0x480c0, 0x48144,
2023 		0x48180, 0x4818c,
2024 		0x48200, 0x48254,
2025 		0x48260, 0x48264,
2026 		0x48270, 0x48288,
2027 		0x48290, 0x48298,
2028 		0x482ac, 0x482c8,
2029 		0x482d0, 0x482e0,
2030 		0x482f0, 0x482f0,
2031 		0x48300, 0x4833c,
2032 		0x483f8, 0x483fc,
2033 		0x49304, 0x493c4,
2034 		0x49400, 0x4940c,
2035 		0x49414, 0x4941c,
2036 		0x49480, 0x494d0,
2037 		0x4c000, 0x4c054,
2038 		0x4c05c, 0x4c078,
2039 		0x4c0c0, 0x4c174,
2040 		0x4c180, 0x4c1ac,
2041 		0x4c1b4, 0x4c1b8,
2042 		0x4c1c0, 0x4c254,
2043 		0x4c25c, 0x4c278,
2044 		0x4c2c0, 0x4c374,
2045 		0x4c380, 0x4c3ac,
2046 		0x4c3b4, 0x4c3b8,
2047 		0x4c3c0, 0x4c454,
2048 		0x4c45c, 0x4c478,
2049 		0x4c4c0, 0x4c574,
2050 		0x4c580, 0x4c5ac,
2051 		0x4c5b4, 0x4c5b8,
2052 		0x4c5c0, 0x4c654,
2053 		0x4c65c, 0x4c678,
2054 		0x4c6c0, 0x4c774,
2055 		0x4c780, 0x4c7ac,
2056 		0x4c7b4, 0x4c7b8,
2057 		0x4c7c0, 0x4c854,
2058 		0x4c85c, 0x4c878,
2059 		0x4c8c0, 0x4c974,
2060 		0x4c980, 0x4c9ac,
2061 		0x4c9b4, 0x4c9b8,
2062 		0x4c9c0, 0x4c9fc,
2063 		0x4d000, 0x4d004,
2064 		0x4d010, 0x4d030,
2065 		0x4d040, 0x4d060,
2066 		0x4d068, 0x4d068,
2067 		0x4d080, 0x4d084,
2068 		0x4d0a0, 0x4d0b0,
2069 		0x4d200, 0x4d204,
2070 		0x4d210, 0x4d230,
2071 		0x4d240, 0x4d260,
2072 		0x4d268, 0x4d268,
2073 		0x4d280, 0x4d284,
2074 		0x4d2a0, 0x4d2b0,
2075 		0x4e0c0, 0x4e0e4,
2076 		0x4f000, 0x4f03c,
2077 		0x4f044, 0x4f08c,
2078 		0x4f200, 0x4f250,
2079 		0x4f400, 0x4f408,
2080 		0x4f414, 0x4f420,
2081 		0x4f600, 0x4f618,
2082 		0x4f800, 0x4f814,
2083 		0x50000, 0x50084,
2084 		0x50090, 0x500cc,
2085 		0x50400, 0x50400,
2086 		0x50800, 0x50884,
2087 		0x50890, 0x508cc,
2088 		0x50c00, 0x50c00,
2089 		0x51000, 0x5101c,
2090 		0x51300, 0x51308,
2091 	};
2092 
2093 	static const unsigned int t5vf_reg_ranges[] = {
2094 		VF_SGE_REG(A_SGE_VF_KDOORBELL), VF_SGE_REG(A_SGE_VF_GTS),
2095 		VF_MPS_REG(A_MPS_VF_CTL),
2096 		VF_MPS_REG(A_MPS_VF_STAT_RX_VF_ERR_FRAMES_H),
2097 		VF_PL_REG(A_PL_VF_WHOAMI), VF_PL_REG(A_PL_VF_REVISION),
2098 		VF_CIM_REG(A_CIM_VF_EXT_MAILBOX_CTRL),
2099 		VF_CIM_REG(A_CIM_VF_EXT_MAILBOX_STATUS),
2100 		FW_T4VF_MBDATA_BASE_ADDR,
2101 		FW_T4VF_MBDATA_BASE_ADDR +
2102 		((NUM_CIM_PF_MAILBOX_DATA_INSTANCES - 1) * 4),
2103 	};
2104 
2105 	static const unsigned int t6_reg_ranges[] = {
2106 		0x1008, 0x101c,
2107 		0x1024, 0x10a8,
2108 		0x10b4, 0x10f8,
2109 		0x1100, 0x1114,
2110 		0x111c, 0x112c,
2111 		0x1138, 0x113c,
2112 		0x1144, 0x114c,
2113 		0x1180, 0x1184,
2114 		0x1190, 0x1194,
2115 		0x11a0, 0x11a4,
2116 		0x11b0, 0x11c4,
2117 		0x11fc, 0x123c,
2118 		0x1254, 0x1274,
2119 		0x1280, 0x133c,
2120 		0x1800, 0x18fc,
2121 		0x3000, 0x302c,
2122 		0x3060, 0x30b0,
2123 		0x30b8, 0x30d8,
2124 		0x30e0, 0x30fc,
2125 		0x3140, 0x357c,
2126 		0x35a8, 0x35cc,
2127 		0x35ec, 0x35ec,
2128 		0x3600, 0x5624,
2129 		0x56cc, 0x56ec,
2130 		0x56f4, 0x5720,
2131 		0x5728, 0x575c,
2132 		0x580c, 0x5814,
2133 		0x5890, 0x589c,
2134 		0x58a4, 0x58ac,
2135 		0x58b8, 0x58bc,
2136 		0x5940, 0x595c,
2137 		0x5980, 0x598c,
2138 		0x59b0, 0x59c8,
2139 		0x59d0, 0x59dc,
2140 		0x59fc, 0x5a18,
2141 		0x5a60, 0x5a6c,
2142 		0x5a80, 0x5a8c,
2143 		0x5a94, 0x5a9c,
2144 		0x5b94, 0x5bfc,
2145 		0x5c10, 0x5e48,
2146 		0x5e50, 0x5e94,
2147 		0x5ea0, 0x5eb0,
2148 		0x5ec0, 0x5ec0,
2149 		0x5ec8, 0x5ed0,
2150 		0x5ee0, 0x5ee0,
2151 		0x5ef0, 0x5ef0,
2152 		0x5f00, 0x5f00,
2153 		0x6000, 0x6020,
2154 		0x6028, 0x6040,
2155 		0x6058, 0x609c,
2156 		0x60a8, 0x619c,
2157 		0x7700, 0x7798,
2158 		0x77c0, 0x7880,
2159 		0x78cc, 0x78fc,
2160 		0x7b00, 0x7b58,
2161 		0x7b60, 0x7b84,
2162 		0x7b8c, 0x7c54,
2163 		0x7d00, 0x7d38,
2164 		0x7d40, 0x7d84,
2165 		0x7d8c, 0x7ddc,
2166 		0x7de4, 0x7e04,
2167 		0x7e10, 0x7e1c,
2168 		0x7e24, 0x7e38,
2169 		0x7e40, 0x7e44,
2170 		0x7e4c, 0x7e78,
2171 		0x7e80, 0x7edc,
2172 		0x7ee8, 0x7efc,
2173 		0x8dc0, 0x8de0,
2174 		0x8df8, 0x8e04,
2175 		0x8e10, 0x8e84,
2176 		0x8ea0, 0x8f88,
2177 		0x8fb8, 0x9058,
2178 		0x9060, 0x9060,
2179 		0x9068, 0x90f8,
2180 		0x9100, 0x9124,
2181 		0x9400, 0x9470,
2182 		0x9600, 0x9600,
2183 		0x9608, 0x9638,
2184 		0x9640, 0x9704,
2185 		0x9710, 0x971c,
2186 		0x9800, 0x9808,
2187 		0x9810, 0x9864,
2188 		0x9c00, 0x9c6c,
2189 		0x9c80, 0x9cec,
2190 		0x9d00, 0x9d6c,
2191 		0x9d80, 0x9dec,
2192 		0x9e00, 0x9e6c,
2193 		0x9e80, 0x9eec,
2194 		0x9f00, 0x9f6c,
2195 		0x9f80, 0xa020,
2196 		0xd000, 0xd03c,
2197 		0xd100, 0xd118,
2198 		0xd200, 0xd214,
2199 		0xd220, 0xd234,
2200 		0xd240, 0xd254,
2201 		0xd260, 0xd274,
2202 		0xd280, 0xd294,
2203 		0xd2a0, 0xd2b4,
2204 		0xd2c0, 0xd2d4,
2205 		0xd2e0, 0xd2f4,
2206 		0xd300, 0xd31c,
2207 		0xdfc0, 0xdfe0,
2208 		0xe000, 0xf008,
2209 		0xf010, 0xf018,
2210 		0xf020, 0xf028,
2211 		0x11000, 0x11014,
2212 		0x11048, 0x1106c,
2213 		0x11074, 0x11088,
2214 		0x11098, 0x11120,
2215 		0x1112c, 0x1117c,
2216 		0x11190, 0x112e0,
2217 		0x11300, 0x1130c,
2218 		0x12000, 0x1206c,
2219 		0x19040, 0x1906c,
2220 		0x19078, 0x19080,
2221 		0x1908c, 0x190e8,
2222 		0x190f0, 0x190f8,
2223 		0x19100, 0x19110,
2224 		0x19120, 0x19124,
2225 		0x19150, 0x19194,
2226 		0x1919c, 0x191b0,
2227 		0x191d0, 0x191e8,
2228 		0x19238, 0x19290,
2229 		0x192a4, 0x192b0,
2230 		0x19348, 0x1934c,
2231 		0x193f8, 0x19418,
2232 		0x19420, 0x19428,
2233 		0x19430, 0x19444,
2234 		0x1944c, 0x1946c,
2235 		0x19474, 0x19474,
2236 		0x19490, 0x194cc,
2237 		0x194f0, 0x194f8,
2238 		0x19c00, 0x19c48,
2239 		0x19c50, 0x19c80,
2240 		0x19c94, 0x19c98,
2241 		0x19ca0, 0x19cbc,
2242 		0x19ce4, 0x19ce4,
2243 		0x19cf0, 0x19cf8,
2244 		0x19d00, 0x19d28,
2245 		0x19d50, 0x19d78,
2246 		0x19d94, 0x19d98,
2247 		0x19da0, 0x19de0,
2248 		0x19df0, 0x19e10,
2249 		0x19e50, 0x19e6c,
2250 		0x19ea0, 0x19ebc,
2251 		0x19ec4, 0x19ef4,
2252 		0x19f04, 0x19f2c,
2253 		0x19f34, 0x19f34,
2254 		0x19f40, 0x19f50,
2255 		0x19f90, 0x19fac,
2256 		0x19fc4, 0x19fc8,
2257 		0x19fd0, 0x19fe4,
2258 		0x1a000, 0x1a004,
2259 		0x1a010, 0x1a06c,
2260 		0x1a0b0, 0x1a0e4,
2261 		0x1a0ec, 0x1a0f8,
2262 		0x1a100, 0x1a108,
2263 		0x1a114, 0x1a130,
2264 		0x1a138, 0x1a1c4,
2265 		0x1a1fc, 0x1a1fc,
2266 		0x1e008, 0x1e00c,
2267 		0x1e040, 0x1e044,
2268 		0x1e04c, 0x1e04c,
2269 		0x1e284, 0x1e290,
2270 		0x1e2c0, 0x1e2c0,
2271 		0x1e2e0, 0x1e2e0,
2272 		0x1e300, 0x1e384,
2273 		0x1e3c0, 0x1e3c8,
2274 		0x1e408, 0x1e40c,
2275 		0x1e440, 0x1e444,
2276 		0x1e44c, 0x1e44c,
2277 		0x1e684, 0x1e690,
2278 		0x1e6c0, 0x1e6c0,
2279 		0x1e6e0, 0x1e6e0,
2280 		0x1e700, 0x1e784,
2281 		0x1e7c0, 0x1e7c8,
2282 		0x1e808, 0x1e80c,
2283 		0x1e840, 0x1e844,
2284 		0x1e84c, 0x1e84c,
2285 		0x1ea84, 0x1ea90,
2286 		0x1eac0, 0x1eac0,
2287 		0x1eae0, 0x1eae0,
2288 		0x1eb00, 0x1eb84,
2289 		0x1ebc0, 0x1ebc8,
2290 		0x1ec08, 0x1ec0c,
2291 		0x1ec40, 0x1ec44,
2292 		0x1ec4c, 0x1ec4c,
2293 		0x1ee84, 0x1ee90,
2294 		0x1eec0, 0x1eec0,
2295 		0x1eee0, 0x1eee0,
2296 		0x1ef00, 0x1ef84,
2297 		0x1efc0, 0x1efc8,
2298 		0x1f008, 0x1f00c,
2299 		0x1f040, 0x1f044,
2300 		0x1f04c, 0x1f04c,
2301 		0x1f284, 0x1f290,
2302 		0x1f2c0, 0x1f2c0,
2303 		0x1f2e0, 0x1f2e0,
2304 		0x1f300, 0x1f384,
2305 		0x1f3c0, 0x1f3c8,
2306 		0x1f408, 0x1f40c,
2307 		0x1f440, 0x1f444,
2308 		0x1f44c, 0x1f44c,
2309 		0x1f684, 0x1f690,
2310 		0x1f6c0, 0x1f6c0,
2311 		0x1f6e0, 0x1f6e0,
2312 		0x1f700, 0x1f784,
2313 		0x1f7c0, 0x1f7c8,
2314 		0x1f808, 0x1f80c,
2315 		0x1f840, 0x1f844,
2316 		0x1f84c, 0x1f84c,
2317 		0x1fa84, 0x1fa90,
2318 		0x1fac0, 0x1fac0,
2319 		0x1fae0, 0x1fae0,
2320 		0x1fb00, 0x1fb84,
2321 		0x1fbc0, 0x1fbc8,
2322 		0x1fc08, 0x1fc0c,
2323 		0x1fc40, 0x1fc44,
2324 		0x1fc4c, 0x1fc4c,
2325 		0x1fe84, 0x1fe90,
2326 		0x1fec0, 0x1fec0,
2327 		0x1fee0, 0x1fee0,
2328 		0x1ff00, 0x1ff84,
2329 		0x1ffc0, 0x1ffc8,
2330 		0x30000, 0x30030,
2331 		0x30100, 0x30168,
2332 		0x30190, 0x301a0,
2333 		0x301a8, 0x301b8,
2334 		0x301c4, 0x301c8,
2335 		0x301d0, 0x301d0,
2336 		0x30200, 0x30320,
2337 		0x30400, 0x304b4,
2338 		0x304c0, 0x3052c,
2339 		0x30540, 0x3061c,
2340 		0x30800, 0x308a0,
2341 		0x308c0, 0x30908,
2342 		0x30910, 0x309b8,
2343 		0x30a00, 0x30a04,
2344 		0x30a0c, 0x30a14,
2345 		0x30a1c, 0x30a2c,
2346 		0x30a44, 0x30a50,
2347 		0x30a74, 0x30a74,
2348 		0x30a7c, 0x30afc,
2349 		0x30b08, 0x30c24,
2350 		0x30d00, 0x30d14,
2351 		0x30d1c, 0x30d3c,
2352 		0x30d44, 0x30d4c,
2353 		0x30d54, 0x30d74,
2354 		0x30d7c, 0x30d7c,
2355 		0x30de0, 0x30de0,
2356 		0x30e00, 0x30ed4,
2357 		0x30f00, 0x30fa4,
2358 		0x30fc0, 0x30fc4,
2359 		0x31000, 0x31004,
2360 		0x31080, 0x310fc,
2361 		0x31208, 0x31220,
2362 		0x3123c, 0x31254,
2363 		0x31300, 0x31300,
2364 		0x31308, 0x3131c,
2365 		0x31338, 0x3133c,
2366 		0x31380, 0x31380,
2367 		0x31388, 0x313a8,
2368 		0x313b4, 0x313b4,
2369 		0x31400, 0x31420,
2370 		0x31438, 0x3143c,
2371 		0x31480, 0x31480,
2372 		0x314a8, 0x314a8,
2373 		0x314b0, 0x314b4,
2374 		0x314c8, 0x314d4,
2375 		0x31a40, 0x31a4c,
2376 		0x31af0, 0x31b20,
2377 		0x31b38, 0x31b3c,
2378 		0x31b80, 0x31b80,
2379 		0x31ba8, 0x31ba8,
2380 		0x31bb0, 0x31bb4,
2381 		0x31bc8, 0x31bd4,
2382 		0x32140, 0x3218c,
2383 		0x321f0, 0x321f4,
2384 		0x32200, 0x32200,
2385 		0x32218, 0x32218,
2386 		0x32400, 0x32400,
2387 		0x32408, 0x3241c,
2388 		0x32618, 0x32620,
2389 		0x32664, 0x32664,
2390 		0x326a8, 0x326a8,
2391 		0x326ec, 0x326ec,
2392 		0x32a00, 0x32abc,
2393 		0x32b00, 0x32b18,
2394 		0x32b20, 0x32b38,
2395 		0x32b40, 0x32b58,
2396 		0x32b60, 0x32b78,
2397 		0x32c00, 0x32c00,
2398 		0x32c08, 0x32c3c,
2399 		0x33000, 0x3302c,
2400 		0x33034, 0x33050,
2401 		0x33058, 0x33058,
2402 		0x33060, 0x3308c,
2403 		0x3309c, 0x330ac,
2404 		0x330c0, 0x330c0,
2405 		0x330c8, 0x330d0,
2406 		0x330d8, 0x330e0,
2407 		0x330ec, 0x3312c,
2408 		0x33134, 0x33150,
2409 		0x33158, 0x33158,
2410 		0x33160, 0x3318c,
2411 		0x3319c, 0x331ac,
2412 		0x331c0, 0x331c0,
2413 		0x331c8, 0x331d0,
2414 		0x331d8, 0x331e0,
2415 		0x331ec, 0x33290,
2416 		0x33298, 0x332c4,
2417 		0x332e4, 0x33390,
2418 		0x33398, 0x333c4,
2419 		0x333e4, 0x3342c,
2420 		0x33434, 0x33450,
2421 		0x33458, 0x33458,
2422 		0x33460, 0x3348c,
2423 		0x3349c, 0x334ac,
2424 		0x334c0, 0x334c0,
2425 		0x334c8, 0x334d0,
2426 		0x334d8, 0x334e0,
2427 		0x334ec, 0x3352c,
2428 		0x33534, 0x33550,
2429 		0x33558, 0x33558,
2430 		0x33560, 0x3358c,
2431 		0x3359c, 0x335ac,
2432 		0x335c0, 0x335c0,
2433 		0x335c8, 0x335d0,
2434 		0x335d8, 0x335e0,
2435 		0x335ec, 0x33690,
2436 		0x33698, 0x336c4,
2437 		0x336e4, 0x33790,
2438 		0x33798, 0x337c4,
2439 		0x337e4, 0x337fc,
2440 		0x33814, 0x33814,
2441 		0x33854, 0x33868,
2442 		0x33880, 0x3388c,
2443 		0x338c0, 0x338d0,
2444 		0x338e8, 0x338ec,
2445 		0x33900, 0x3392c,
2446 		0x33934, 0x33950,
2447 		0x33958, 0x33958,
2448 		0x33960, 0x3398c,
2449 		0x3399c, 0x339ac,
2450 		0x339c0, 0x339c0,
2451 		0x339c8, 0x339d0,
2452 		0x339d8, 0x339e0,
2453 		0x339ec, 0x33a90,
2454 		0x33a98, 0x33ac4,
2455 		0x33ae4, 0x33b10,
2456 		0x33b24, 0x33b28,
2457 		0x33b38, 0x33b50,
2458 		0x33bf0, 0x33c10,
2459 		0x33c24, 0x33c28,
2460 		0x33c38, 0x33c50,
2461 		0x33cf0, 0x33cfc,
2462 		0x34000, 0x34030,
2463 		0x34100, 0x34168,
2464 		0x34190, 0x341a0,
2465 		0x341a8, 0x341b8,
2466 		0x341c4, 0x341c8,
2467 		0x341d0, 0x341d0,
2468 		0x34200, 0x34320,
2469 		0x34400, 0x344b4,
2470 		0x344c0, 0x3452c,
2471 		0x34540, 0x3461c,
2472 		0x34800, 0x348a0,
2473 		0x348c0, 0x34908,
2474 		0x34910, 0x349b8,
2475 		0x34a00, 0x34a04,
2476 		0x34a0c, 0x34a14,
2477 		0x34a1c, 0x34a2c,
2478 		0x34a44, 0x34a50,
2479 		0x34a74, 0x34a74,
2480 		0x34a7c, 0x34afc,
2481 		0x34b08, 0x34c24,
2482 		0x34d00, 0x34d14,
2483 		0x34d1c, 0x34d3c,
2484 		0x34d44, 0x34d4c,
2485 		0x34d54, 0x34d74,
2486 		0x34d7c, 0x34d7c,
2487 		0x34de0, 0x34de0,
2488 		0x34e00, 0x34ed4,
2489 		0x34f00, 0x34fa4,
2490 		0x34fc0, 0x34fc4,
2491 		0x35000, 0x35004,
2492 		0x35080, 0x350fc,
2493 		0x35208, 0x35220,
2494 		0x3523c, 0x35254,
2495 		0x35300, 0x35300,
2496 		0x35308, 0x3531c,
2497 		0x35338, 0x3533c,
2498 		0x35380, 0x35380,
2499 		0x35388, 0x353a8,
2500 		0x353b4, 0x353b4,
2501 		0x35400, 0x35420,
2502 		0x35438, 0x3543c,
2503 		0x35480, 0x35480,
2504 		0x354a8, 0x354a8,
2505 		0x354b0, 0x354b4,
2506 		0x354c8, 0x354d4,
2507 		0x35a40, 0x35a4c,
2508 		0x35af0, 0x35b20,
2509 		0x35b38, 0x35b3c,
2510 		0x35b80, 0x35b80,
2511 		0x35ba8, 0x35ba8,
2512 		0x35bb0, 0x35bb4,
2513 		0x35bc8, 0x35bd4,
2514 		0x36140, 0x3618c,
2515 		0x361f0, 0x361f4,
2516 		0x36200, 0x36200,
2517 		0x36218, 0x36218,
2518 		0x36400, 0x36400,
2519 		0x36408, 0x3641c,
2520 		0x36618, 0x36620,
2521 		0x36664, 0x36664,
2522 		0x366a8, 0x366a8,
2523 		0x366ec, 0x366ec,
2524 		0x36a00, 0x36abc,
2525 		0x36b00, 0x36b18,
2526 		0x36b20, 0x36b38,
2527 		0x36b40, 0x36b58,
2528 		0x36b60, 0x36b78,
2529 		0x36c00, 0x36c00,
2530 		0x36c08, 0x36c3c,
2531 		0x37000, 0x3702c,
2532 		0x37034, 0x37050,
2533 		0x37058, 0x37058,
2534 		0x37060, 0x3708c,
2535 		0x3709c, 0x370ac,
2536 		0x370c0, 0x370c0,
2537 		0x370c8, 0x370d0,
2538 		0x370d8, 0x370e0,
2539 		0x370ec, 0x3712c,
2540 		0x37134, 0x37150,
2541 		0x37158, 0x37158,
2542 		0x37160, 0x3718c,
2543 		0x3719c, 0x371ac,
2544 		0x371c0, 0x371c0,
2545 		0x371c8, 0x371d0,
2546 		0x371d8, 0x371e0,
2547 		0x371ec, 0x37290,
2548 		0x37298, 0x372c4,
2549 		0x372e4, 0x37390,
2550 		0x37398, 0x373c4,
2551 		0x373e4, 0x3742c,
2552 		0x37434, 0x37450,
2553 		0x37458, 0x37458,
2554 		0x37460, 0x3748c,
2555 		0x3749c, 0x374ac,
2556 		0x374c0, 0x374c0,
2557 		0x374c8, 0x374d0,
2558 		0x374d8, 0x374e0,
2559 		0x374ec, 0x3752c,
2560 		0x37534, 0x37550,
2561 		0x37558, 0x37558,
2562 		0x37560, 0x3758c,
2563 		0x3759c, 0x375ac,
2564 		0x375c0, 0x375c0,
2565 		0x375c8, 0x375d0,
2566 		0x375d8, 0x375e0,
2567 		0x375ec, 0x37690,
2568 		0x37698, 0x376c4,
2569 		0x376e4, 0x37790,
2570 		0x37798, 0x377c4,
2571 		0x377e4, 0x377fc,
2572 		0x37814, 0x37814,
2573 		0x37854, 0x37868,
2574 		0x37880, 0x3788c,
2575 		0x378c0, 0x378d0,
2576 		0x378e8, 0x378ec,
2577 		0x37900, 0x3792c,
2578 		0x37934, 0x37950,
2579 		0x37958, 0x37958,
2580 		0x37960, 0x3798c,
2581 		0x3799c, 0x379ac,
2582 		0x379c0, 0x379c0,
2583 		0x379c8, 0x379d0,
2584 		0x379d8, 0x379e0,
2585 		0x379ec, 0x37a90,
2586 		0x37a98, 0x37ac4,
2587 		0x37ae4, 0x37b10,
2588 		0x37b24, 0x37b28,
2589 		0x37b38, 0x37b50,
2590 		0x37bf0, 0x37c10,
2591 		0x37c24, 0x37c28,
2592 		0x37c38, 0x37c50,
2593 		0x37cf0, 0x37cfc,
2594 		0x40040, 0x40040,
2595 		0x40080, 0x40084,
2596 		0x40100, 0x40100,
2597 		0x40140, 0x401bc,
2598 		0x40200, 0x40214,
2599 		0x40228, 0x40228,
2600 		0x40240, 0x40258,
2601 		0x40280, 0x40280,
2602 		0x40304, 0x40304,
2603 		0x40330, 0x4033c,
2604 		0x41304, 0x413c8,
2605 		0x413d0, 0x413dc,
2606 		0x413f0, 0x413f0,
2607 		0x41400, 0x4140c,
2608 		0x41414, 0x4141c,
2609 		0x41480, 0x414d0,
2610 		0x44000, 0x4407c,
2611 		0x440c0, 0x441ac,
2612 		0x441b4, 0x4427c,
2613 		0x442c0, 0x443ac,
2614 		0x443b4, 0x4447c,
2615 		0x444c0, 0x445ac,
2616 		0x445b4, 0x4467c,
2617 		0x446c0, 0x447ac,
2618 		0x447b4, 0x4487c,
2619 		0x448c0, 0x449ac,
2620 		0x449b4, 0x44a7c,
2621 		0x44ac0, 0x44bac,
2622 		0x44bb4, 0x44c7c,
2623 		0x44cc0, 0x44dac,
2624 		0x44db4, 0x44e7c,
2625 		0x44ec0, 0x44fac,
2626 		0x44fb4, 0x4507c,
2627 		0x450c0, 0x451ac,
2628 		0x451b4, 0x451fc,
2629 		0x45800, 0x45804,
2630 		0x45810, 0x45830,
2631 		0x45840, 0x45860,
2632 		0x45868, 0x45868,
2633 		0x45880, 0x45884,
2634 		0x458a0, 0x458b0,
2635 		0x45a00, 0x45a04,
2636 		0x45a10, 0x45a30,
2637 		0x45a40, 0x45a60,
2638 		0x45a68, 0x45a68,
2639 		0x45a80, 0x45a84,
2640 		0x45aa0, 0x45ab0,
2641 		0x460c0, 0x460e4,
2642 		0x47000, 0x4703c,
2643 		0x47044, 0x4708c,
2644 		0x47200, 0x47250,
2645 		0x47400, 0x47408,
2646 		0x47414, 0x47420,
2647 		0x47600, 0x47618,
2648 		0x47800, 0x47814,
2649 		0x47820, 0x4782c,
2650 		0x50000, 0x50084,
2651 		0x50090, 0x500cc,
2652 		0x50300, 0x50384,
2653 		0x50400, 0x50400,
2654 		0x50800, 0x50884,
2655 		0x50890, 0x508cc,
2656 		0x50b00, 0x50b84,
2657 		0x50c00, 0x50c00,
2658 		0x51000, 0x51020,
2659 		0x51028, 0x510b0,
2660 		0x51300, 0x51324,
2661 	};
2662 
2663 	static const unsigned int t6vf_reg_ranges[] = {
2664 		VF_SGE_REG(A_SGE_VF_KDOORBELL), VF_SGE_REG(A_SGE_VF_GTS),
2665 		VF_MPS_REG(A_MPS_VF_CTL),
2666 		VF_MPS_REG(A_MPS_VF_STAT_RX_VF_ERR_FRAMES_H),
2667 		VF_PL_REG(A_PL_VF_WHOAMI), VF_PL_REG(A_PL_VF_REVISION),
2668 		VF_CIM_REG(A_CIM_VF_EXT_MAILBOX_CTRL),
2669 		VF_CIM_REG(A_CIM_VF_EXT_MAILBOX_STATUS),
2670 		FW_T6VF_MBDATA_BASE_ADDR,
2671 		FW_T6VF_MBDATA_BASE_ADDR +
2672 		((NUM_CIM_PF_MAILBOX_DATA_INSTANCES - 1) * 4),
2673 	};
2674 
2675 	static const unsigned int t7_reg_ranges[] = {
2676 		0x1008, 0x101c,
2677 		0x1024, 0x10a8,
2678 		0x10b4, 0x10f8,
2679 		0x1100, 0x1114,
2680 		0x111c, 0x112c,
2681 		0x1138, 0x113c,
2682 		0x1144, 0x115c,
2683 		0x1180, 0x1184,
2684 		0x1190, 0x1194,
2685 		0x11a0, 0x11a4,
2686 		0x11b0, 0x11d0,
2687 		0x11fc, 0x1278,
2688 		0x1280, 0x1368,
2689 		0x1700, 0x172c,
2690 		0x173c, 0x1760,
2691 		0x1800, 0x18fc,
2692 		0x3000, 0x3044,
2693 		0x30a4, 0x30b0,
2694 		0x30b8, 0x30d8,
2695 		0x30e0, 0x30e8,
2696 		0x3140, 0x357c,
2697 		0x35a8, 0x35cc,
2698 		0x35e0, 0x35ec,
2699 		0x3600, 0x37fc,
2700 		0x3804, 0x3818,
2701 		0x3880, 0x388c,
2702 		0x3900, 0x3904,
2703 		0x3910, 0x3978,
2704 		0x3980, 0x399c,
2705 		0x4700, 0x4720,
2706 		0x4728, 0x475c,
2707 		0x480c, 0x4814,
2708 		0x4890, 0x489c,
2709 		0x48a4, 0x48ac,
2710 		0x48b8, 0x48bc,
2711 		0x4900, 0x4924,
2712 		0x4ffc, 0x4ffc,
2713 		0x5500, 0x5624,
2714 		0x56c4, 0x56ec,
2715 		0x56f4, 0x5720,
2716 		0x5728, 0x575c,
2717 		0x580c, 0x5814,
2718 		0x5890, 0x589c,
2719 		0x58a4, 0x58ac,
2720 		0x58b8, 0x58bc,
2721 		0x5940, 0x598c,
2722 		0x59b0, 0x59c8,
2723 		0x59d0, 0x59dc,
2724 		0x59fc, 0x5a18,
2725 		0x5a60, 0x5a6c,
2726 		0x5a80, 0x5a8c,
2727 		0x5a94, 0x5a9c,
2728 		0x5b94, 0x5bec,
2729 		0x5bf8, 0x5bfc,
2730 		0x5c10, 0x5c40,
2731 		0x5c4c, 0x5e48,
2732 		0x5e50, 0x5e94,
2733 		0x5ea0, 0x5eb0,
2734 		0x5ec0, 0x5ec0,
2735 		0x5ec8, 0x5ed0,
2736 		0x5ee0, 0x5ee0,
2737 		0x5ef0, 0x5ef0,
2738 		0x5f00, 0x5f04,
2739 		0x5f0c, 0x5f10,
2740 		0x5f20, 0x5f78,
2741 		0x5f84, 0x5f88,
2742 		0x5f90, 0x5fd8,
2743 		0x6000, 0x6020,
2744 		0x6028, 0x6030,
2745 		0x6044, 0x609c,
2746 		0x60a8, 0x60ac,
2747 		0x60b8, 0x60ec,
2748 		0x6100, 0x6104,
2749 		0x6118, 0x611c,
2750 		0x6150, 0x6150,
2751 		0x6180, 0x61b8,
2752 		0x7700, 0x77a8,
2753 		0x77b0, 0x7888,
2754 		0x78cc, 0x7970,
2755 		0x7b00, 0x7b00,
2756 		0x7b08, 0x7b0c,
2757 		0x7b24, 0x7b84,
2758 		0x7b8c, 0x7c2c,
2759 		0x7c34, 0x7c40,
2760 		0x7c48, 0x7c68,
2761 		0x7c70, 0x7c7c,
2762 		0x7d00, 0x7ddc,
2763 		0x7de4, 0x7e38,
2764 		0x7e40, 0x7e44,
2765 		0x7e4c, 0x7e74,
2766 		0x7e80, 0x7ee0,
2767 		0x7ee8, 0x7f0c,
2768 		0x7f20, 0x7f5c,
2769 		0x8dc0, 0x8de8,
2770 		0x8df8, 0x8e04,
2771 		0x8e10, 0x8e30,
2772 		0x8e7c, 0x8ee8,
2773 		0x8f88, 0x8f88,
2774 		0x8f90, 0x8fb0,
2775 		0x8fb8, 0x9058,
2776 		0x9074, 0x90f8,
2777 		0x9100, 0x912c,
2778 		0x9138, 0x9188,
2779 		0x9400, 0x9414,
2780 		0x9430, 0x9440,
2781 		0x9454, 0x9454,
2782 		0x945c, 0x947c,
2783 		0x9498, 0x94b8,
2784 		0x9600, 0x9600,
2785 		0x9608, 0x9638,
2786 		0x9640, 0x9704,
2787 		0x9710, 0x971c,
2788 		0x9800, 0x9804,
2789 		0x9854, 0x9854,
2790 		0x9c00, 0x9c6c,
2791 		0x9c80, 0x9cec,
2792 		0x9d00, 0x9d6c,
2793 		0x9d80, 0x9dec,
2794 		0x9e00, 0x9e6c,
2795 		0x9e80, 0x9eec,
2796 		0x9f00, 0x9f6c,
2797 		0x9f80, 0x9fec,
2798 		0xa000, 0xa06c,
2799 		0xa080, 0xa0ec,
2800 		0xa100, 0xa16c,
2801 		0xa180, 0xa1ec,
2802 		0xa200, 0xa26c,
2803 		0xa280, 0xa2ec,
2804 		0xa300, 0xa36c,
2805 		0xa380, 0xa458,
2806 		0xa460, 0xa4f8,
2807 		0xd000, 0xd03c,
2808 		0xd100, 0xd134,
2809 		0xd200, 0xd214,
2810 		0xd220, 0xd234,
2811 		0xd240, 0xd254,
2812 		0xd260, 0xd274,
2813 		0xd280, 0xd294,
2814 		0xd2a0, 0xd2b4,
2815 		0xd2c0, 0xd2d4,
2816 		0xd2e0, 0xd2f4,
2817 		0xd300, 0xd31c,
2818 		0xdfc0, 0xdfe0,
2819 		0xe000, 0xe00c,
2820 		0xf000, 0xf008,
2821 		0xf010, 0xf06c,
2822 		0x11000, 0x11014,
2823 		0x11048, 0x11120,
2824 		0x11130, 0x11144,
2825 		0x11174, 0x11178,
2826 		0x11190, 0x111a0,
2827 		0x111e4, 0x112f0,
2828 		0x11300, 0x1133c,
2829 		0x11408, 0x1146c,
2830 		0x12000, 0x12004,
2831 		0x12060, 0x122c4,
2832 		0x19040, 0x1906c,
2833 		0x19078, 0x19080,
2834 		0x1908c, 0x190e8,
2835 		0x190f0, 0x190f8,
2836 		0x19100, 0x19110,
2837 		0x19120, 0x19124,
2838 		0x19150, 0x19194,
2839 		0x1919c, 0x191a0,
2840 		0x191ac, 0x191c8,
2841 		0x191d0, 0x191e4,
2842 		0x19250, 0x19250,
2843 		0x19258, 0x19268,
2844 		0x19278, 0x19278,
2845 		0x19280, 0x192b0,
2846 		0x192bc, 0x192f0,
2847 		0x19300, 0x19308,
2848 		0x19310, 0x19318,
2849 		0x19320, 0x19328,
2850 		0x19330, 0x19330,
2851 		0x19348, 0x1934c,
2852 		0x193f8, 0x19428,
2853 		0x19430, 0x19444,
2854 		0x1944c, 0x1946c,
2855 		0x19474, 0x1947c,
2856 		0x19488, 0x194cc,
2857 		0x194f0, 0x194f8,
2858 		0x19c00, 0x19c48,
2859 		0x19c50, 0x19c80,
2860 		0x19c94, 0x19c98,
2861 		0x19ca0, 0x19cdc,
2862 		0x19ce4, 0x19cf8,
2863 		0x19d00, 0x19d30,
2864 		0x19d50, 0x19d80,
2865 		0x19d94, 0x19d98,
2866 		0x19da0, 0x19de0,
2867 		0x19df0, 0x19e10,
2868 		0x19e50, 0x19e6c,
2869 		0x19ea0, 0x19ebc,
2870 		0x19ec4, 0x19ef4,
2871 		0x19f04, 0x19f2c,
2872 		0x19f34, 0x19f34,
2873 		0x19f40, 0x19f50,
2874 		0x19f90, 0x19fb4,
2875 		0x19fbc, 0x19fbc,
2876 		0x19fc4, 0x19fc8,
2877 		0x19fd0, 0x19fe4,
2878 		0x1a000, 0x1a004,
2879 		0x1a010, 0x1a06c,
2880 		0x1a0b0, 0x1a0e4,
2881 		0x1a0ec, 0x1a108,
2882 		0x1a114, 0x1a130,
2883 		0x1a138, 0x1a1c4,
2884 		0x1a1fc, 0x1a29c,
2885 		0x1a2a8, 0x1a2b8,
2886 		0x1a2c0, 0x1a388,
2887 		0x1a398, 0x1a3ac,
2888 		0x1e008, 0x1e00c,
2889 		0x1e040, 0x1e044,
2890 		0x1e04c, 0x1e04c,
2891 		0x1e284, 0x1e290,
2892 		0x1e2c0, 0x1e2c0,
2893 		0x1e2e0, 0x1e2e4,
2894 		0x1e300, 0x1e384,
2895 		0x1e3c0, 0x1e3c8,
2896 		0x1e408, 0x1e40c,
2897 		0x1e440, 0x1e444,
2898 		0x1e44c, 0x1e44c,
2899 		0x1e684, 0x1e690,
2900 		0x1e6c0, 0x1e6c0,
2901 		0x1e6e0, 0x1e6e4,
2902 		0x1e700, 0x1e784,
2903 		0x1e7c0, 0x1e7c8,
2904 		0x1e808, 0x1e80c,
2905 		0x1e840, 0x1e844,
2906 		0x1e84c, 0x1e84c,
2907 		0x1ea84, 0x1ea90,
2908 		0x1eac0, 0x1eac0,
2909 		0x1eae0, 0x1eae4,
2910 		0x1eb00, 0x1eb84,
2911 		0x1ebc0, 0x1ebc8,
2912 		0x1ec08, 0x1ec0c,
2913 		0x1ec40, 0x1ec44,
2914 		0x1ec4c, 0x1ec4c,
2915 		0x1ee84, 0x1ee90,
2916 		0x1eec0, 0x1eec0,
2917 		0x1eee0, 0x1eee4,
2918 		0x1ef00, 0x1ef84,
2919 		0x1efc0, 0x1efc8,
2920 		0x1f008, 0x1f00c,
2921 		0x1f040, 0x1f044,
2922 		0x1f04c, 0x1f04c,
2923 		0x1f284, 0x1f290,
2924 		0x1f2c0, 0x1f2c0,
2925 		0x1f2e0, 0x1f2e4,
2926 		0x1f300, 0x1f384,
2927 		0x1f3c0, 0x1f3c8,
2928 		0x1f408, 0x1f40c,
2929 		0x1f440, 0x1f444,
2930 		0x1f44c, 0x1f44c,
2931 		0x1f684, 0x1f690,
2932 		0x1f6c0, 0x1f6c0,
2933 		0x1f6e0, 0x1f6e4,
2934 		0x1f700, 0x1f784,
2935 		0x1f7c0, 0x1f7c8,
2936 		0x1f808, 0x1f80c,
2937 		0x1f840, 0x1f844,
2938 		0x1f84c, 0x1f84c,
2939 		0x1fa84, 0x1fa90,
2940 		0x1fac0, 0x1fac0,
2941 		0x1fae0, 0x1fae4,
2942 		0x1fb00, 0x1fb84,
2943 		0x1fbc0, 0x1fbc8,
2944 		0x1fc08, 0x1fc0c,
2945 		0x1fc40, 0x1fc44,
2946 		0x1fc4c, 0x1fc4c,
2947 		0x1fe84, 0x1fe90,
2948 		0x1fec0, 0x1fec0,
2949 		0x1fee0, 0x1fee4,
2950 		0x1ff00, 0x1ff84,
2951 		0x1ffc0, 0x1ffc8,
2952 		0x30000, 0x30038,
2953 		0x30100, 0x3017c,
2954 		0x30190, 0x301a0,
2955 		0x301a8, 0x301b8,
2956 		0x301c4, 0x301c8,
2957 		0x301d0, 0x301e0,
2958 		0x30200, 0x30344,
2959 		0x30400, 0x304b4,
2960 		0x304c0, 0x3052c,
2961 		0x30540, 0x3065c,
2962 		0x30800, 0x30848,
2963 		0x30850, 0x308a8,
2964 		0x308b8, 0x308c0,
2965 		0x308cc, 0x308dc,
2966 		0x30900, 0x30904,
2967 		0x3090c, 0x30914,
2968 		0x3091c, 0x30928,
2969 		0x30930, 0x3093c,
2970 		0x30944, 0x30948,
2971 		0x30954, 0x30974,
2972 		0x3097c, 0x30980,
2973 		0x30a00, 0x30a20,
2974 		0x30a38, 0x30a3c,
2975 		0x30a50, 0x30a50,
2976 		0x30a80, 0x30a80,
2977 		0x30a88, 0x30aa8,
2978 		0x30ab0, 0x30ab4,
2979 		0x30ac8, 0x30ad4,
2980 		0x30b28, 0x30b84,
2981 		0x30b98, 0x30bb8,
2982 		0x30c98, 0x30d14,
2983 		0x31000, 0x31020,
2984 		0x31038, 0x3103c,
2985 		0x31050, 0x31050,
2986 		0x31080, 0x31080,
2987 		0x31088, 0x310a8,
2988 		0x310b0, 0x310b4,
2989 		0x310c8, 0x310d4,
2990 		0x31128, 0x31184,
2991 		0x31198, 0x311b8,
2992 		0x32000, 0x32038,
2993 		0x32100, 0x3217c,
2994 		0x32190, 0x321a0,
2995 		0x321a8, 0x321b8,
2996 		0x321c4, 0x321c8,
2997 		0x321d0, 0x321e0,
2998 		0x32200, 0x32344,
2999 		0x32400, 0x324b4,
3000 		0x324c0, 0x3252c,
3001 		0x32540, 0x3265c,
3002 		0x32800, 0x32848,
3003 		0x32850, 0x328a8,
3004 		0x328b8, 0x328c0,
3005 		0x328cc, 0x328dc,
3006 		0x32900, 0x32904,
3007 		0x3290c, 0x32914,
3008 		0x3291c, 0x32928,
3009 		0x32930, 0x3293c,
3010 		0x32944, 0x32948,
3011 		0x32954, 0x32974,
3012 		0x3297c, 0x32980,
3013 		0x32a00, 0x32a20,
3014 		0x32a38, 0x32a3c,
3015 		0x32a50, 0x32a50,
3016 		0x32a80, 0x32a80,
3017 		0x32a88, 0x32aa8,
3018 		0x32ab0, 0x32ab4,
3019 		0x32ac8, 0x32ad4,
3020 		0x32b28, 0x32b84,
3021 		0x32b98, 0x32bb8,
3022 		0x32c98, 0x32d14,
3023 		0x33000, 0x33020,
3024 		0x33038, 0x3303c,
3025 		0x33050, 0x33050,
3026 		0x33080, 0x33080,
3027 		0x33088, 0x330a8,
3028 		0x330b0, 0x330b4,
3029 		0x330c8, 0x330d4,
3030 		0x33128, 0x33184,
3031 		0x33198, 0x331b8,
3032 		0x34000, 0x34038,
3033 		0x34100, 0x3417c,
3034 		0x34190, 0x341a0,
3035 		0x341a8, 0x341b8,
3036 		0x341c4, 0x341c8,
3037 		0x341d0, 0x341e0,
3038 		0x34200, 0x34344,
3039 		0x34400, 0x344b4,
3040 		0x344c0, 0x3452c,
3041 		0x34540, 0x3465c,
3042 		0x34800, 0x34848,
3043 		0x34850, 0x348a8,
3044 		0x348b8, 0x348c0,
3045 		0x348cc, 0x348dc,
3046 		0x34900, 0x34904,
3047 		0x3490c, 0x34914,
3048 		0x3491c, 0x34928,
3049 		0x34930, 0x3493c,
3050 		0x34944, 0x34948,
3051 		0x34954, 0x34974,
3052 		0x3497c, 0x34980,
3053 		0x34a00, 0x34a20,
3054 		0x34a38, 0x34a3c,
3055 		0x34a50, 0x34a50,
3056 		0x34a80, 0x34a80,
3057 		0x34a88, 0x34aa8,
3058 		0x34ab0, 0x34ab4,
3059 		0x34ac8, 0x34ad4,
3060 		0x34b28, 0x34b84,
3061 		0x34b98, 0x34bb8,
3062 		0x34c98, 0x34d14,
3063 		0x35000, 0x35020,
3064 		0x35038, 0x3503c,
3065 		0x35050, 0x35050,
3066 		0x35080, 0x35080,
3067 		0x35088, 0x350a8,
3068 		0x350b0, 0x350b4,
3069 		0x350c8, 0x350d4,
3070 		0x35128, 0x35184,
3071 		0x35198, 0x351b8,
3072 		0x36000, 0x36038,
3073 		0x36100, 0x3617c,
3074 		0x36190, 0x361a0,
3075 		0x361a8, 0x361b8,
3076 		0x361c4, 0x361c8,
3077 		0x361d0, 0x361e0,
3078 		0x36200, 0x36344,
3079 		0x36400, 0x364b4,
3080 		0x364c0, 0x3652c,
3081 		0x36540, 0x3665c,
3082 		0x36800, 0x36848,
3083 		0x36850, 0x368a8,
3084 		0x368b8, 0x368c0,
3085 		0x368cc, 0x368dc,
3086 		0x36900, 0x36904,
3087 		0x3690c, 0x36914,
3088 		0x3691c, 0x36928,
3089 		0x36930, 0x3693c,
3090 		0x36944, 0x36948,
3091 		0x36954, 0x36974,
3092 		0x3697c, 0x36980,
3093 		0x36a00, 0x36a20,
3094 		0x36a38, 0x36a3c,
3095 		0x36a50, 0x36a50,
3096 		0x36a80, 0x36a80,
3097 		0x36a88, 0x36aa8,
3098 		0x36ab0, 0x36ab4,
3099 		0x36ac8, 0x36ad4,
3100 		0x36b28, 0x36b84,
3101 		0x36b98, 0x36bb8,
3102 		0x36c98, 0x36d14,
3103 		0x37000, 0x37020,
3104 		0x37038, 0x3703c,
3105 		0x37050, 0x37050,
3106 		0x37080, 0x37080,
3107 		0x37088, 0x370a8,
3108 		0x370b0, 0x370b4,
3109 		0x370c8, 0x370d4,
3110 		0x37128, 0x37184,
3111 		0x37198, 0x371b8,
3112 		0x38000, 0x380b0,
3113 		0x380b8, 0x38130,
3114 		0x38140, 0x38140,
3115 		0x38150, 0x38154,
3116 		0x38160, 0x381c4,
3117 		0x381d0, 0x38204,
3118 		0x3820c, 0x38214,
3119 		0x3821c, 0x3822c,
3120 		0x38244, 0x38244,
3121 		0x38254, 0x38274,
3122 		0x3827c, 0x38280,
3123 		0x38300, 0x38304,
3124 		0x3830c, 0x38314,
3125 		0x3831c, 0x3832c,
3126 		0x38344, 0x38344,
3127 		0x38354, 0x38374,
3128 		0x3837c, 0x38380,
3129 		0x38400, 0x38424,
3130 		0x38438, 0x3843c,
3131 		0x38480, 0x38480,
3132 		0x384a8, 0x384a8,
3133 		0x384b0, 0x384b4,
3134 		0x384c8, 0x38514,
3135 		0x38600, 0x3860c,
3136 		0x3861c, 0x38624,
3137 		0x38900, 0x38924,
3138 		0x38938, 0x3893c,
3139 		0x38980, 0x38980,
3140 		0x389a8, 0x389a8,
3141 		0x389b0, 0x389b4,
3142 		0x389c8, 0x38a14,
3143 		0x38b00, 0x38b0c,
3144 		0x38b1c, 0x38b24,
3145 		0x38e00, 0x38e00,
3146 		0x38e18, 0x38e20,
3147 		0x38e38, 0x38e40,
3148 		0x38e58, 0x38e60,
3149 		0x38e78, 0x38e80,
3150 		0x38e98, 0x38ea0,
3151 		0x38eb8, 0x38ec0,
3152 		0x38ed8, 0x38ee0,
3153 		0x38ef8, 0x38f08,
3154 		0x38f10, 0x38f2c,
3155 		0x38f80, 0x38ffc,
3156 		0x39080, 0x39080,
3157 		0x39088, 0x39090,
3158 		0x39100, 0x39108,
3159 		0x39120, 0x39128,
3160 		0x39140, 0x39148,
3161 		0x39160, 0x39168,
3162 		0x39180, 0x39188,
3163 		0x391a0, 0x391a8,
3164 		0x391c0, 0x391c8,
3165 		0x391e0, 0x391e8,
3166 		0x39200, 0x39200,
3167 		0x39208, 0x39240,
3168 		0x39300, 0x39300,
3169 		0x39308, 0x39340,
3170 		0x39400, 0x39400,
3171 		0x39408, 0x39440,
3172 		0x39500, 0x39500,
3173 		0x39508, 0x39540,
3174 		0x39600, 0x39600,
3175 		0x39608, 0x39640,
3176 		0x39700, 0x39700,
3177 		0x39708, 0x39740,
3178 		0x39800, 0x39800,
3179 		0x39808, 0x39840,
3180 		0x39900, 0x39900,
3181 		0x39908, 0x39940,
3182 		0x39a00, 0x39a04,
3183 		0x39a10, 0x39a14,
3184 		0x39a1c, 0x39aa8,
3185 		0x39b00, 0x39ecc,
3186 		0x3a000, 0x3a004,
3187 		0x3a050, 0x3a084,
3188 		0x3a090, 0x3a09c,
3189 		0x3a93c, 0x3a93c,
3190 		0x3b93c, 0x3b93c,
3191 		0x3c93c, 0x3c93c,
3192 		0x3d93c, 0x3d93c,
3193 		0x3e000, 0x3e020,
3194 		0x3e03c, 0x3e05c,
3195 		0x3e100, 0x3e120,
3196 		0x3e13c, 0x3e15c,
3197 		0x3e200, 0x3e220,
3198 		0x3e23c, 0x3e25c,
3199 		0x3e300, 0x3e320,
3200 		0x3e33c, 0x3e35c,
3201 		0x3f000, 0x3f034,
3202 		0x3f100, 0x3f130,
3203 		0x3f200, 0x3f218,
3204 		0x44000, 0x44014,
3205 		0x44020, 0x44028,
3206 		0x44030, 0x44030,
3207 		0x44100, 0x44114,
3208 		0x44120, 0x44128,
3209 		0x44130, 0x44130,
3210 		0x44200, 0x44214,
3211 		0x44220, 0x44228,
3212 		0x44230, 0x44230,
3213 		0x44300, 0x44314,
3214 		0x44320, 0x44328,
3215 		0x44330, 0x44330,
3216 		0x44400, 0x44414,
3217 		0x44420, 0x44428,
3218 		0x44430, 0x44430,
3219 		0x44500, 0x44514,
3220 		0x44520, 0x44528,
3221 		0x44530, 0x44530,
3222 		0x44714, 0x44718,
3223 		0x44730, 0x44730,
3224 		0x447c0, 0x447c0,
3225 		0x447f0, 0x447f0,
3226 		0x447f8, 0x447fc,
3227 		0x45000, 0x45014,
3228 		0x45020, 0x45028,
3229 		0x45030, 0x45030,
3230 		0x45100, 0x45114,
3231 		0x45120, 0x45128,
3232 		0x45130, 0x45130,
3233 		0x45200, 0x45214,
3234 		0x45220, 0x45228,
3235 		0x45230, 0x45230,
3236 		0x45300, 0x45314,
3237 		0x45320, 0x45328,
3238 		0x45330, 0x45330,
3239 		0x45400, 0x45414,
3240 		0x45420, 0x45428,
3241 		0x45430, 0x45430,
3242 		0x45500, 0x45514,
3243 		0x45520, 0x45528,
3244 		0x45530, 0x45530,
3245 		0x45714, 0x45718,
3246 		0x45730, 0x45730,
3247 		0x457c0, 0x457c0,
3248 		0x457f0, 0x457f0,
3249 		0x457f8, 0x457fc,
3250 		0x46000, 0x46010,
3251 		0x46020, 0x46034,
3252 		0x46040, 0x46050,
3253 		0x46060, 0x46088,
3254 		0x47000, 0x4709c,
3255 		0x470c0, 0x470d4,
3256 		0x47100, 0x471a8,
3257 		0x471b0, 0x471e8,
3258 		0x47200, 0x47210,
3259 		0x4721c, 0x47230,
3260 		0x47238, 0x47238,
3261 		0x47240, 0x472ac,
3262 		0x472d0, 0x472f4,
3263 		0x47300, 0x47310,
3264 		0x47318, 0x47348,
3265 		0x47350, 0x47354,
3266 		0x47380, 0x47388,
3267 		0x47390, 0x47394,
3268 		0x47400, 0x47448,
3269 		0x47450, 0x47458,
3270 		0x47500, 0x4751c,
3271 		0x47530, 0x4754c,
3272 		0x47560, 0x4757c,
3273 		0x47590, 0x475ac,
3274 		0x47600, 0x47630,
3275 		0x47640, 0x47644,
3276 		0x47660, 0x4769c,
3277 		0x47700, 0x47710,
3278 		0x47740, 0x47750,
3279 		0x4775c, 0x4779c,
3280 		0x477b0, 0x477bc,
3281 		0x477c4, 0x477c8,
3282 		0x477d4, 0x477fc,
3283 		0x48000, 0x48004,
3284 		0x48018, 0x4801c,
3285 		0x49304, 0x49320,
3286 		0x4932c, 0x4932c,
3287 		0x49334, 0x493f0,
3288 		0x49400, 0x49410,
3289 		0x49460, 0x494f4,
3290 		0x50000, 0x50084,
3291 		0x50090, 0x500cc,
3292 		0x50300, 0x50384,
3293 		0x50400, 0x50404,
3294 		0x50800, 0x50884,
3295 		0x50890, 0x508cc,
3296 		0x50b00, 0x50b84,
3297 		0x50c00, 0x50c04,
3298 		0x51000, 0x51020,
3299 		0x51028, 0x510c4,
3300 		0x51104, 0x51108,
3301 		0x51200, 0x51274,
3302 		0x51300, 0x51324,
3303 		0x51400, 0x51548,
3304 		0x51550, 0x51554,
3305 		0x5155c, 0x51584,
3306 		0x5158c, 0x515c8,
3307 		0x515f0, 0x515f4,
3308 		0x58000, 0x58004,
3309 		0x58018, 0x5801c,
3310 		0x59304, 0x59320,
3311 		0x5932c, 0x5932c,
3312 		0x59334, 0x593f0,
3313 		0x59400, 0x59410,
3314 		0x59460, 0x594f4,
3315 	};
3316 
3317 	u32 *buf_end = (u32 *)(buf + buf_size);
3318 	const unsigned int *reg_ranges;
3319 	int reg_ranges_size, range;
3320 	unsigned int chip_version = chip_id(adap);
3321 
3322 	/*
3323 	 * Select the right set of register ranges to dump depending on the
3324 	 * adapter chip type.
3325 	 */
3326 	switch (chip_version) {
3327 	case CHELSIO_T4:
3328 		if (adap->flags & IS_VF) {
3329 			reg_ranges = t4vf_reg_ranges;
3330 			reg_ranges_size = ARRAY_SIZE(t4vf_reg_ranges);
3331 		} else {
3332 			reg_ranges = t4_reg_ranges;
3333 			reg_ranges_size = ARRAY_SIZE(t4_reg_ranges);
3334 		}
3335 		break;
3336 
3337 	case CHELSIO_T5:
3338 		if (adap->flags & IS_VF) {
3339 			reg_ranges = t5vf_reg_ranges;
3340 			reg_ranges_size = ARRAY_SIZE(t5vf_reg_ranges);
3341 		} else {
3342 			reg_ranges = t5_reg_ranges;
3343 			reg_ranges_size = ARRAY_SIZE(t5_reg_ranges);
3344 		}
3345 		break;
3346 
3347 	case CHELSIO_T6:
3348 		if (adap->flags & IS_VF) {
3349 			reg_ranges = t6vf_reg_ranges;
3350 			reg_ranges_size = ARRAY_SIZE(t6vf_reg_ranges);
3351 		} else {
3352 			reg_ranges = t6_reg_ranges;
3353 			reg_ranges_size = ARRAY_SIZE(t6_reg_ranges);
3354 		}
3355 		break;
3356 
3357 	case CHELSIO_T7:
3358 		if (adap->flags & IS_VF) {
3359 			reg_ranges = t6vf_reg_ranges;
3360 			reg_ranges_size = ARRAY_SIZE(t6vf_reg_ranges);
3361 		} else {
3362 			reg_ranges = t7_reg_ranges;
3363 			reg_ranges_size = ARRAY_SIZE(t7_reg_ranges);
3364 		}
3365 		break;
3366 
3367 	default:
3368 		CH_ERR(adap,
3369 			"Unsupported chip version %d\n", chip_version);
3370 		return;
3371 	}
3372 
3373 	/*
3374 	 * Clear the register buffer and insert the appropriate register
3375 	 * values selected by the above register ranges.
3376 	 */
3377 	memset(buf, 0, buf_size);
3378 	for (range = 0; range < reg_ranges_size; range += 2) {
3379 		unsigned int reg = reg_ranges[range];
3380 		unsigned int last_reg = reg_ranges[range + 1];
3381 		u32 *bufp = (u32 *)(buf + reg);
3382 
3383 		/*
3384 		 * Iterate across the register range filling in the register
3385 		 * buffer but don't write past the end of the register buffer.
3386 		 */
3387 		while (reg <= last_reg && bufp < buf_end) {
3388 			*bufp++ = t4_read_reg(adap, reg);
3389 			reg += sizeof(u32);
3390 		}
3391 	}
3392 }
3393 
3394 /*
3395  * Partial EEPROM Vital Product Data structure.  The VPD starts with one ID
3396  * header followed by one or more VPD-R sections, each with its own header.
3397  */
3398 struct t4_vpd_hdr {
3399 	u8  id_tag;
3400 	u8  id_len[2];
3401 	u8  id_data[ID_LEN];
3402 };
3403 
3404 struct t4_vpdr_hdr {
3405 	u8  vpdr_tag;
3406 	u8  vpdr_len[2];
3407 };
3408 
3409 /*
3410  * EEPROM reads take a few tens of us while writes can take a bit over 5 ms.
3411  */
3412 #define EEPROM_DELAY		10		/* 10us per poll spin */
3413 #define EEPROM_MAX_POLL		5000		/* x 5000 == 50ms */
3414 
3415 #define EEPROM_STAT_ADDR	0x7bfc
3416 #define VPD_SIZE		0x800
3417 #define VPD_BASE		0x400
3418 #define VPD_BASE_OLD		0
3419 #define VPD_LEN			1024
3420 #define VPD_INFO_FLD_HDR_SIZE	3
3421 #define CHELSIO_VPD_UNIQUE_ID	0x82
3422 
3423 /*
3424  * Small utility function to wait till any outstanding VPD Access is complete.
3425  * We have a per-adapter state variable "VPD Busy" to indicate when we have a
3426  * VPD Access in flight.  This allows us to handle the problem of having a
3427  * previous VPD Access time out and prevent an attempt to inject a new VPD
3428  * Request before any in-flight VPD reguest has completed.
3429  */
t4_seeprom_wait(struct adapter * adapter)3430 static int t4_seeprom_wait(struct adapter *adapter)
3431 {
3432 	unsigned int base = adapter->params.pci.vpd_cap_addr;
3433 	int max_poll;
3434 
3435 	/*
3436 	 * If no VPD Access is in flight, we can just return success right
3437 	 * away.
3438 	 */
3439 	if (!adapter->vpd_busy)
3440 		return 0;
3441 
3442 	/*
3443 	 * Poll the VPD Capability Address/Flag register waiting for it
3444 	 * to indicate that the operation is complete.
3445 	 */
3446 	max_poll = EEPROM_MAX_POLL;
3447 	do {
3448 		u16 val;
3449 
3450 		udelay(EEPROM_DELAY);
3451 		t4_os_pci_read_cfg2(adapter, base + PCI_VPD_ADDR, &val);
3452 
3453 		/*
3454 		 * If the operation is complete, mark the VPD as no longer
3455 		 * busy and return success.
3456 		 */
3457 		if ((val & PCI_VPD_ADDR_F) == adapter->vpd_flag) {
3458 			adapter->vpd_busy = 0;
3459 			return 0;
3460 		}
3461 	} while (--max_poll);
3462 
3463 	/*
3464 	 * Failure!  Note that we leave the VPD Busy status set in order to
3465 	 * avoid pushing a new VPD Access request into the VPD Capability till
3466 	 * the current operation eventually succeeds.  It's a bug to issue a
3467 	 * new request when an existing request is in flight and will result
3468 	 * in corrupt hardware state.
3469 	 */
3470 	return -ETIMEDOUT;
3471 }
3472 
3473 /**
3474  *	t4_seeprom_read - read a serial EEPROM location
3475  *	@adapter: adapter to read
3476  *	@addr: EEPROM virtual address
3477  *	@data: where to store the read data
3478  *
3479  *	Read a 32-bit word from a location in serial EEPROM using the card's PCI
3480  *	VPD capability.  Note that this function must be called with a virtual
3481  *	address.
3482  */
t4_seeprom_read(struct adapter * adapter,u32 addr,u32 * data)3483 int t4_seeprom_read(struct adapter *adapter, u32 addr, u32 *data)
3484 {
3485 	unsigned int base = adapter->params.pci.vpd_cap_addr;
3486 	int ret;
3487 
3488 	/*
3489 	 * VPD Accesses must alway be 4-byte aligned!
3490 	 */
3491 	if (addr >= EEPROMVSIZE || (addr & 3))
3492 		return -EINVAL;
3493 
3494 	/*
3495 	 * Wait for any previous operation which may still be in flight to
3496 	 * complete.
3497 	 */
3498 	ret = t4_seeprom_wait(adapter);
3499 	if (ret) {
3500 		CH_ERR(adapter, "VPD still busy from previous operation\n");
3501 		return ret;
3502 	}
3503 
3504 	/*
3505 	 * Issue our new VPD Read request, mark the VPD as being busy and wait
3506 	 * for our request to complete.  If it doesn't complete, note the
3507 	 * error and return it to our caller.  Note that we do not reset the
3508 	 * VPD Busy status!
3509 	 */
3510 	t4_os_pci_write_cfg2(adapter, base + PCI_VPD_ADDR, (u16)addr);
3511 	adapter->vpd_busy = 1;
3512 	adapter->vpd_flag = PCI_VPD_ADDR_F;
3513 	ret = t4_seeprom_wait(adapter);
3514 	if (ret) {
3515 		CH_ERR(adapter, "VPD read of address %#x failed\n", addr);
3516 		return ret;
3517 	}
3518 
3519 	/*
3520 	 * Grab the returned data, swizzle it into our endianness and
3521 	 * return success.
3522 	 */
3523 	t4_os_pci_read_cfg4(adapter, base + PCI_VPD_DATA, data);
3524 	*data = le32_to_cpu(*data);
3525 	return 0;
3526 }
3527 
3528 /**
3529  *	t4_seeprom_write - write a serial EEPROM location
3530  *	@adapter: adapter to write
3531  *	@addr: virtual EEPROM address
3532  *	@data: value to write
3533  *
3534  *	Write a 32-bit word to a location in serial EEPROM using the card's PCI
3535  *	VPD capability.  Note that this function must be called with a virtual
3536  *	address.
3537  */
t4_seeprom_write(struct adapter * adapter,u32 addr,u32 data)3538 int t4_seeprom_write(struct adapter *adapter, u32 addr, u32 data)
3539 {
3540 	unsigned int base = adapter->params.pci.vpd_cap_addr;
3541 	int ret;
3542 	u32 stats_reg;
3543 	int max_poll;
3544 
3545 	/*
3546 	 * VPD Accesses must alway be 4-byte aligned!
3547 	 */
3548 	if (addr >= EEPROMVSIZE || (addr & 3))
3549 		return -EINVAL;
3550 
3551 	/*
3552 	 * Wait for any previous operation which may still be in flight to
3553 	 * complete.
3554 	 */
3555 	ret = t4_seeprom_wait(adapter);
3556 	if (ret) {
3557 		CH_ERR(adapter, "VPD still busy from previous operation\n");
3558 		return ret;
3559 	}
3560 
3561 	/*
3562 	 * Issue our new VPD Read request, mark the VPD as being busy and wait
3563 	 * for our request to complete.  If it doesn't complete, note the
3564 	 * error and return it to our caller.  Note that we do not reset the
3565 	 * VPD Busy status!
3566 	 */
3567 	t4_os_pci_write_cfg4(adapter, base + PCI_VPD_DATA,
3568 				 cpu_to_le32(data));
3569 	t4_os_pci_write_cfg2(adapter, base + PCI_VPD_ADDR,
3570 				 (u16)addr | PCI_VPD_ADDR_F);
3571 	adapter->vpd_busy = 1;
3572 	adapter->vpd_flag = 0;
3573 	ret = t4_seeprom_wait(adapter);
3574 	if (ret) {
3575 		CH_ERR(adapter, "VPD write of address %#x failed\n", addr);
3576 		return ret;
3577 	}
3578 
3579 	/*
3580 	 * Reset PCI_VPD_DATA register after a transaction and wait for our
3581 	 * request to complete. If it doesn't complete, return error.
3582 	 */
3583 	t4_os_pci_write_cfg4(adapter, base + PCI_VPD_DATA, 0);
3584 	max_poll = EEPROM_MAX_POLL;
3585 	do {
3586 		udelay(EEPROM_DELAY);
3587 		t4_seeprom_read(adapter, EEPROM_STAT_ADDR, &stats_reg);
3588 	} while ((stats_reg & 0x1) && --max_poll);
3589 	if (!max_poll)
3590 		return -ETIMEDOUT;
3591 
3592 	/* Return success! */
3593 	return 0;
3594 }
3595 
3596 /**
3597  *	t4_eeprom_ptov - translate a physical EEPROM address to virtual
3598  *	@phys_addr: the physical EEPROM address
3599  *	@fn: the PCI function number
3600  *	@sz: size of function-specific area
3601  *
3602  *	Translate a physical EEPROM address to virtual.  The first 1K is
3603  *	accessed through virtual addresses starting at 31K, the rest is
3604  *	accessed through virtual addresses starting at 0.
3605  *
3606  *	The mapping is as follows:
3607  *	[0..1K) -> [31K..32K)
3608  *	[1K..1K+A) -> [ES-A..ES)
3609  *	[1K+A..ES) -> [0..ES-A-1K)
3610  *
3611  *	where A = @fn * @sz, and ES = EEPROM size.
3612  */
t4_eeprom_ptov(unsigned int phys_addr,unsigned int fn,unsigned int sz)3613 int t4_eeprom_ptov(unsigned int phys_addr, unsigned int fn, unsigned int sz)
3614 {
3615 	fn *= sz;
3616 	if (phys_addr < 1024)
3617 		return phys_addr + (31 << 10);
3618 	if (phys_addr < 1024 + fn)
3619 		return EEPROMSIZE - fn + phys_addr - 1024;
3620 	if (phys_addr < EEPROMSIZE)
3621 		return phys_addr - 1024 - fn;
3622 	return -EINVAL;
3623 }
3624 
3625 /**
3626  *	t4_seeprom_wp - enable/disable EEPROM write protection
3627  *	@adapter: the adapter
3628  *	@enable: whether to enable or disable write protection
3629  *
3630  *	Enables or disables write protection on the serial EEPROM.
3631  */
t4_seeprom_wp(struct adapter * adapter,int enable)3632 int t4_seeprom_wp(struct adapter *adapter, int enable)
3633 {
3634 	return t4_seeprom_write(adapter, EEPROM_STAT_ADDR, enable ? 0xc : 0);
3635 }
3636 
3637 /**
3638  *	get_vpd_keyword_val - Locates an information field keyword in the VPD
3639  *	@vpd: Pointer to buffered vpd data structure
3640  *	@kw: The keyword to search for
3641  *	@region: VPD region to search (starting from 0)
3642  *
3643  *	Returns the value of the information field keyword or
3644  *	-ENOENT otherwise.
3645  */
get_vpd_keyword_val(const u8 * vpd,const char * kw,int region)3646 static int get_vpd_keyword_val(const u8 *vpd, const char *kw, int region)
3647 {
3648 	int i, tag;
3649 	unsigned int offset, len;
3650 	const struct t4_vpdr_hdr *vpdr;
3651 
3652 	offset = sizeof(struct t4_vpd_hdr);
3653 	vpdr = (const void *)(vpd + offset);
3654 	tag = vpdr->vpdr_tag;
3655 	len = (u16)vpdr->vpdr_len[0] + ((u16)vpdr->vpdr_len[1] << 8);
3656 	while (region--) {
3657 		offset += sizeof(struct t4_vpdr_hdr) + len;
3658 		vpdr = (const void *)(vpd + offset);
3659 		if (++tag != vpdr->vpdr_tag)
3660 			return -ENOENT;
3661 		len = (u16)vpdr->vpdr_len[0] + ((u16)vpdr->vpdr_len[1] << 8);
3662 	}
3663 	offset += sizeof(struct t4_vpdr_hdr);
3664 
3665 	if (offset + len > VPD_LEN) {
3666 		return -ENOENT;
3667 	}
3668 
3669 	for (i = offset; i + VPD_INFO_FLD_HDR_SIZE <= offset + len;) {
3670 		if (memcmp(vpd + i , kw , 2) == 0){
3671 			i += VPD_INFO_FLD_HDR_SIZE;
3672 			return i;
3673 		}
3674 
3675 		i += VPD_INFO_FLD_HDR_SIZE + vpd[i+2];
3676 	}
3677 
3678 	return -ENOENT;
3679 }
3680 
3681 
3682 /**
3683  *	get_vpd_params - read VPD parameters from VPD EEPROM
3684  *	@adapter: adapter to read
3685  *	@p: where to store the parameters
3686  *	@vpd: caller provided temporary space to read the VPD into
3687  *
3688  *	Reads card parameters stored in VPD EEPROM.
3689  */
get_vpd_params(struct adapter * adapter,struct vpd_params * p,uint16_t device_id,u32 * buf)3690 static int get_vpd_params(struct adapter *adapter, struct vpd_params *p,
3691     uint16_t device_id, u32 *buf)
3692 {
3693 	int i, ret, addr;
3694 	int ec, sn, pn, na, md;
3695 	u8 csum;
3696 	const u8 *vpd = (const u8 *)buf;
3697 
3698 	/*
3699 	 * Card information normally starts at VPD_BASE but early cards had
3700 	 * it at 0.
3701 	 */
3702 	ret = t4_seeprom_read(adapter, VPD_BASE, buf);
3703 	if (ret)
3704 		return (ret);
3705 
3706 	/*
3707 	 * The VPD shall have a unique identifier specified by the PCI SIG.
3708 	 * For chelsio adapters, the identifier is 0x82. The first byte of a VPD
3709 	 * shall be CHELSIO_VPD_UNIQUE_ID (0x82). The VPD programming software
3710 	 * is expected to automatically put this entry at the
3711 	 * beginning of the VPD.
3712 	 */
3713 	addr = *vpd == CHELSIO_VPD_UNIQUE_ID ? VPD_BASE : VPD_BASE_OLD;
3714 
3715 	for (i = 0; i < VPD_LEN; i += 4) {
3716 		ret = t4_seeprom_read(adapter, addr + i, buf++);
3717 		if (ret)
3718 			return ret;
3719 	}
3720 
3721 #define FIND_VPD_KW(var,name) do { \
3722 	var = get_vpd_keyword_val(vpd, name, 0); \
3723 	if (var < 0) { \
3724 		CH_ERR(adapter, "missing VPD keyword " name "\n"); \
3725 		return -EINVAL; \
3726 	} \
3727 } while (0)
3728 
3729 	FIND_VPD_KW(i, "RV");
3730 	for (csum = 0; i >= 0; i--)
3731 		csum += vpd[i];
3732 
3733 	if (csum) {
3734 		CH_ERR(adapter,
3735 			"corrupted VPD EEPROM, actual csum %u\n", csum);
3736 		return -EINVAL;
3737 	}
3738 
3739 	FIND_VPD_KW(ec, "EC");
3740 	FIND_VPD_KW(sn, "SN");
3741 	FIND_VPD_KW(pn, "PN");
3742 	FIND_VPD_KW(na, "NA");
3743 #undef FIND_VPD_KW
3744 
3745 	memcpy(p->id, vpd + offsetof(struct t4_vpd_hdr, id_data), ID_LEN);
3746 	strstrip(p->id);
3747 	memcpy(p->ec, vpd + ec, EC_LEN);
3748 	strstrip(p->ec);
3749 	i = vpd[sn - VPD_INFO_FLD_HDR_SIZE + 2];
3750 	memcpy(p->sn, vpd + sn, min(i, SERNUM_LEN));
3751 	strstrip(p->sn);
3752 	i = vpd[pn - VPD_INFO_FLD_HDR_SIZE + 2];
3753 	memcpy(p->pn, vpd + pn, min(i, PN_LEN));
3754 	strstrip((char *)p->pn);
3755 	i = vpd[na - VPD_INFO_FLD_HDR_SIZE + 2];
3756 	memcpy(p->na, vpd + na, min(i, MACADDR_LEN));
3757 	strstrip((char *)p->na);
3758 
3759 	if (device_id & 0x80)
3760 		return 0;	/* Custom card */
3761 
3762 	md = get_vpd_keyword_val(vpd, "VF", 1);
3763 	if (md < 0) {
3764 		snprintf(p->md, sizeof(p->md), "unknown");
3765 	} else {
3766 		i = vpd[md - VPD_INFO_FLD_HDR_SIZE + 2];
3767 		memcpy(p->md, vpd + md, min(i, MD_LEN));
3768 		strstrip((char *)p->md);
3769 	}
3770 
3771 	return 0;
3772 }
3773 
3774 /* Flash Layout {start sector, # of sectors} for T4/T5/T6 adapters */
3775 static const struct t4_flash_loc_entry t4_flash_loc_arr[] = {
3776 	[FLASH_LOC_EXP_ROM] = { 0, 6 },
3777 	[FLASH_LOC_IBFT] = { 6, 1 },
3778 	[FLASH_LOC_BOOTCFG] = { 7, 1 },
3779 	[FLASH_LOC_FW] = { 8, 16 },
3780 	[FLASH_LOC_FWBOOTSTRAP] = { 27, 1 },
3781 	[FLASH_LOC_ISCSI_CRASH] = { 29, 1 },
3782 	[FLASH_LOC_FCOE_CRASH] = { 30, 1 },
3783 	[FLASH_LOC_CFG] = { 31, 1 },
3784 	[FLASH_LOC_CUDBG] = { 32, 32 },
3785 	[FLASH_LOC_BOOT_AREA] = { 0, 8 }, /* Spans complete Boot Area */
3786 	[FLASH_LOC_END] = { 64, 0 },
3787 };
3788 
3789 /* Flash Layout {start sector, # of sectors} for T7 adapters */
3790 static const struct t4_flash_loc_entry t7_flash_loc_arr[] = {
3791 	[FLASH_LOC_VPD] = { 0, 1 },
3792 	[FLASH_LOC_FWBOOTSTRAP] = { 1, 1 },
3793 	[FLASH_LOC_FW] = { 2, 29 },
3794 	[FLASH_LOC_CFG] = { 31, 1 },
3795 	[FLASH_LOC_EXP_ROM] = { 32, 15 },
3796 	[FLASH_LOC_IBFT] = { 47, 1 },
3797 	[FLASH_LOC_BOOTCFG] = { 48, 1 },
3798 	[FLASH_LOC_DPU_BOOT] = { 49, 13 },
3799 	[FLASH_LOC_ISCSI_CRASH] = { 62, 1 },
3800 	[FLASH_LOC_FCOE_CRASH] = { 63, 1 },
3801 	[FLASH_LOC_VPD_BACKUP] = { 64, 1 },
3802 	[FLASH_LOC_FWBOOTSTRAP_BACKUP] = { 65, 1 },
3803 	[FLASH_LOC_FW_BACKUP] = { 66, 29 },
3804 	[FLASH_LOC_CFG_BACK] = { 95, 1 },
3805 	[FLASH_LOC_CUDBG] = { 96, 48 },
3806 	[FLASH_LOC_CHIP_DUMP] = { 144, 48 },
3807 	[FLASH_LOC_DPU_AREA] = { 192, 64 },
3808 	[FLASH_LOC_BOOT_AREA] = { 32, 17 }, /* Spans complete UEFI/PXE Boot Area */
3809 	[FLASH_LOC_END] = { 256, 0 },
3810 };
3811 
3812 int
t4_flash_loc_start(struct adapter * adap,enum t4_flash_loc loc,unsigned int * lenp)3813 t4_flash_loc_start(struct adapter *adap, enum t4_flash_loc loc,
3814     unsigned int *lenp)
3815 {
3816 	const struct t4_flash_loc_entry *l = chip_id(adap) >= CHELSIO_T7 ?
3817 	    &t7_flash_loc_arr[loc] : &t4_flash_loc_arr[loc];
3818 
3819 	if (lenp != NULL)
3820 		*lenp = FLASH_MAX_SIZE(l->nsecs);
3821 	return (FLASH_START(l->start_sec));
3822 }
3823 
3824 /* serial flash and firmware constants and flash config file constants */
3825 enum {
3826 	SF_ATTEMPTS = 10,	/* max retries for SF operations */
3827 
3828 	/* flash command opcodes */
3829 	SF_PROG_PAGE    = 2,	/* program 256B page */
3830 	SF_WR_DISABLE   = 4,	/* disable writes */
3831 	SF_RD_STATUS    = 5,	/* read status register */
3832 	SF_WR_ENABLE    = 6,	/* enable writes */
3833 	SF_RD_DATA_FAST = 0xb,	/* read flash */
3834 	SF_RD_ID	= 0x9f,	/* read ID */
3835 	SF_ERASE_SECTOR = 0xd8,	/* erase 64KB sector */
3836 };
3837 
3838 /**
3839  *	sf1_read - read data from the serial flash
3840  *	@adapter: the adapter
3841  *	@byte_cnt: number of bytes to read
3842  *	@cont: whether another operation will be chained
3843  *	@lock: whether to lock SF for PL access only
3844  *	@valp: where to store the read data
3845  *
3846  *	Reads up to 4 bytes of data from the serial flash.  The location of
3847  *	the read needs to be specified prior to calling this by issuing the
3848  *	appropriate commands to the serial flash.
3849  */
sf1_read(struct adapter * adapter,unsigned int byte_cnt,int cont,int lock,u32 * valp)3850 static int sf1_read(struct adapter *adapter, unsigned int byte_cnt, int cont,
3851 		    int lock, u32 *valp)
3852 {
3853 	int ret;
3854 	uint32_t op;
3855 
3856 	if (!byte_cnt || byte_cnt > 4)
3857 		return -EINVAL;
3858 	if (t4_read_reg(adapter, A_SF_OP) & F_BUSY)
3859 		return -EBUSY;
3860 	op = V_SF_LOCK(lock) | V_CONT(cont) | V_BYTECNT(byte_cnt - 1);
3861 	if (chip_id(adapter) >= CHELSIO_T7)
3862 		op |= F_QUADREADDISABLE;
3863 	t4_write_reg(adapter, A_SF_OP, op);
3864 	ret = t4_wait_op_done(adapter, A_SF_OP, F_BUSY, 0, SF_ATTEMPTS, 5);
3865 	if (!ret)
3866 		*valp = t4_read_reg(adapter, A_SF_DATA);
3867 	return ret;
3868 }
3869 
3870 /**
3871  *	sf1_write - write data to the serial flash
3872  *	@adapter: the adapter
3873  *	@byte_cnt: number of bytes to write
3874  *	@cont: whether another operation will be chained
3875  *	@lock: whether to lock SF for PL access only
3876  *	@val: value to write
3877  *
3878  *	Writes up to 4 bytes of data to the serial flash.  The location of
3879  *	the write needs to be specified prior to calling this by issuing the
3880  *	appropriate commands to the serial flash.
3881  */
sf1_write(struct adapter * adapter,unsigned int byte_cnt,int cont,int lock,u32 val)3882 static int sf1_write(struct adapter *adapter, unsigned int byte_cnt, int cont,
3883 		     int lock, u32 val)
3884 {
3885 	if (!byte_cnt || byte_cnt > 4)
3886 		return -EINVAL;
3887 	if (t4_read_reg(adapter, A_SF_OP) & F_BUSY)
3888 		return -EBUSY;
3889 	t4_write_reg(adapter, A_SF_DATA, val);
3890 	t4_write_reg(adapter, A_SF_OP, V_SF_LOCK(lock) |
3891 		     V_CONT(cont) | V_BYTECNT(byte_cnt - 1) | V_OP(1));
3892 	return t4_wait_op_done(adapter, A_SF_OP, F_BUSY, 0, SF_ATTEMPTS, 5);
3893 }
3894 
3895 /**
3896  *	flash_wait_op - wait for a flash operation to complete
3897  *	@adapter: the adapter
3898  *	@attempts: max number of polls of the status register
3899  *	@delay: delay between polls in ms
3900  *
3901  *	Wait for a flash operation to complete by polling the status register.
3902  */
flash_wait_op(struct adapter * adapter,int attempts,int delay)3903 static int flash_wait_op(struct adapter *adapter, int attempts, int delay)
3904 {
3905 	int ret;
3906 	u32 status;
3907 
3908 	while (1) {
3909 		if ((ret = sf1_write(adapter, 1, 1, 1, SF_RD_STATUS)) != 0 ||
3910 		    (ret = sf1_read(adapter, 1, 0, 1, &status)) != 0)
3911 			return ret;
3912 		if (!(status & 1))
3913 			return 0;
3914 		if (--attempts == 0)
3915 			return -EAGAIN;
3916 		if (delay)
3917 			msleep(delay);
3918 	}
3919 }
3920 
3921 /**
3922  *	t4_read_flash - read words from serial flash
3923  *	@adapter: the adapter
3924  *	@addr: the start address for the read
3925  *	@nwords: how many 32-bit words to read
3926  *	@data: where to store the read data
3927  *	@byte_oriented: whether to store data as bytes or as words
3928  *
3929  *	Read the specified number of 32-bit words from the serial flash.
3930  *	If @byte_oriented is set the read data is stored as a byte array
3931  *	(i.e., big-endian), otherwise as 32-bit words in the platform's
3932  *	natural endianness.
3933  */
t4_read_flash(struct adapter * adapter,unsigned int addr,unsigned int nwords,u32 * data,int byte_oriented)3934 int t4_read_flash(struct adapter *adapter, unsigned int addr,
3935 		  unsigned int nwords, u32 *data, int byte_oriented)
3936 {
3937 	int ret;
3938 
3939 	if (addr + nwords * sizeof(u32) > adapter->params.sf_size || (addr & 3))
3940 		return -EINVAL;
3941 
3942 	addr = swab32(addr) | SF_RD_DATA_FAST;
3943 
3944 	if ((ret = sf1_write(adapter, 4, 1, 0, addr)) != 0 ||
3945 	    (ret = sf1_read(adapter, 1, 1, 0, data)) != 0)
3946 		return ret;
3947 
3948 	for ( ; nwords; nwords--, data++) {
3949 		ret = sf1_read(adapter, 4, nwords > 1, nwords == 1, data);
3950 		if (nwords == 1)
3951 			t4_write_reg(adapter, A_SF_OP, 0);    /* unlock SF */
3952 		if (ret)
3953 			return ret;
3954 		if (byte_oriented)
3955 			*data = (__force __u32)(cpu_to_be32(*data));
3956 	}
3957 	return 0;
3958 }
3959 
3960 /**
3961  *	t4_write_flash - write up to a page of data to the serial flash
3962  *	@adapter: the adapter
3963  *	@addr: the start address to write
3964  *	@n: length of data to write in bytes
3965  *	@data: the data to write
3966  *	@byte_oriented: whether to store data as bytes or as words
3967  *
3968  *	Writes up to a page of data (256 bytes) to the serial flash starting
3969  *	at the given address.  All the data must be written to the same page.
3970  *	If @byte_oriented is set the write data is stored as byte stream
3971  *	(i.e. matches what on disk), otherwise in big-endian.
3972  */
t4_write_flash(struct adapter * adapter,unsigned int addr,unsigned int n,const u8 * data,int byte_oriented)3973 int t4_write_flash(struct adapter *adapter, unsigned int addr,
3974 			  unsigned int n, const u8 *data, int byte_oriented)
3975 {
3976 	int ret;
3977 	u32 buf[SF_PAGE_SIZE / 4];
3978 	unsigned int i, c, left, val, offset = addr & 0xff;
3979 
3980 	if (addr >= adapter->params.sf_size || offset + n > SF_PAGE_SIZE)
3981 		return -EINVAL;
3982 
3983 	val = swab32(addr) | SF_PROG_PAGE;
3984 
3985 	if ((ret = sf1_write(adapter, 1, 0, 1, SF_WR_ENABLE)) != 0 ||
3986 	    (ret = sf1_write(adapter, 4, 1, 1, val)) != 0)
3987 		goto unlock;
3988 
3989 	for (left = n; left; left -= c) {
3990 		c = min(left, 4U);
3991 		for (val = 0, i = 0; i < c; ++i)
3992 			val = (val << 8) + *data++;
3993 
3994 		if (!byte_oriented)
3995 			val = cpu_to_be32(val);
3996 
3997 		ret = sf1_write(adapter, c, c != left, 1, val);
3998 		if (ret)
3999 			goto unlock;
4000 	}
4001 	ret = flash_wait_op(adapter, 8, 1);
4002 	if (ret)
4003 		goto unlock;
4004 
4005 	t4_write_reg(adapter, A_SF_OP, 0);    /* unlock SF */
4006 
4007 	/* Read the page to verify the write succeeded */
4008 	ret = t4_read_flash(adapter, addr & ~0xff, ARRAY_SIZE(buf), buf,
4009 			    byte_oriented);
4010 	if (ret)
4011 		return ret;
4012 
4013 	if (memcmp(data - n, (u8 *)buf + offset, n)) {
4014 		CH_ERR(adapter,
4015 			"failed to correctly write the flash page at %#x\n",
4016 			addr);
4017 		return -EIO;
4018 	}
4019 	return 0;
4020 
4021 unlock:
4022 	t4_write_reg(adapter, A_SF_OP, 0);    /* unlock SF */
4023 	return ret;
4024 }
4025 
4026 /**
4027  *	t4_get_fw_version - read the firmware version
4028  *	@adapter: the adapter
4029  *	@vers: where to place the version
4030  *
4031  *	Reads the FW version from flash.
4032  */
t4_get_fw_version(struct adapter * adapter,u32 * vers)4033 int t4_get_fw_version(struct adapter *adapter, u32 *vers)
4034 {
4035 	const int start = t4_flash_loc_start(adapter, FLASH_LOC_FW, NULL);
4036 
4037 	return t4_read_flash(adapter, start + offsetof(struct fw_hdr, fw_ver),
4038 	    1, vers, 0);
4039 }
4040 
4041 /**
4042  *	t4_get_fw_hdr - read the firmware header
4043  *	@adapter: the adapter
4044  *	@hdr: where to place the version
4045  *
4046  *	Reads the FW header from flash into caller provided buffer.
4047  */
t4_get_fw_hdr(struct adapter * adapter,struct fw_hdr * hdr)4048 int t4_get_fw_hdr(struct adapter *adapter, struct fw_hdr *hdr)
4049 {
4050 	const int start = t4_flash_loc_start(adapter, FLASH_LOC_FW, NULL);
4051 
4052 	return t4_read_flash(adapter, start, sizeof (*hdr) / sizeof (uint32_t),
4053 	    (uint32_t *)hdr, 1);
4054 }
4055 
4056 /**
4057  *	t4_get_bs_version - read the firmware bootstrap version
4058  *	@adapter: the adapter
4059  *	@vers: where to place the version
4060  *
4061  *	Reads the FW Bootstrap version from flash.
4062  */
t4_get_bs_version(struct adapter * adapter,u32 * vers)4063 int t4_get_bs_version(struct adapter *adapter, u32 *vers)
4064 {
4065 	const int start = t4_flash_loc_start(adapter, FLASH_LOC_FWBOOTSTRAP,
4066 	    NULL);
4067 
4068 	return t4_read_flash(adapter, start + offsetof(struct fw_hdr, fw_ver),
4069 	    1, vers, 0);
4070 }
4071 
4072 /**
4073  *	t4_get_tp_version - read the TP microcode version
4074  *	@adapter: the adapter
4075  *	@vers: where to place the version
4076  *
4077  *	Reads the TP microcode version from flash.
4078  */
t4_get_tp_version(struct adapter * adapter,u32 * vers)4079 int t4_get_tp_version(struct adapter *adapter, u32 *vers)
4080 {
4081 	const int start = t4_flash_loc_start(adapter, FLASH_LOC_FW, NULL);
4082 
4083 	return t4_read_flash(adapter, start +
4084 	    offsetof(struct fw_hdr, tp_microcode_ver), 1, vers, 0);
4085 }
4086 
4087 /**
4088  *	t4_get_exprom_version - return the Expansion ROM version (if any)
4089  *	@adapter: the adapter
4090  *	@vers: where to place the version
4091  *
4092  *	Reads the Expansion ROM header from FLASH and returns the version
4093  *	number (if present) through the @vers return value pointer.  We return
4094  *	this in the Firmware Version Format since it's convenient.  Return
4095  *	0 on success, -ENOENT if no Expansion ROM is present.
4096  */
t4_get_exprom_version(struct adapter * adapter,u32 * vers)4097 int t4_get_exprom_version(struct adapter *adapter, u32 *vers)
4098 {
4099 	struct exprom_header {
4100 		unsigned char hdr_arr[16];	/* must start with 0x55aa */
4101 		unsigned char hdr_ver[4];	/* Expansion ROM version */
4102 	} *hdr;
4103 	u32 exprom_header_buf[DIV_ROUND_UP(sizeof(struct exprom_header),
4104 					   sizeof(u32))];
4105 	int ret;
4106 	const int start = t4_flash_loc_start(adapter, FLASH_LOC_EXP_ROM, NULL);
4107 
4108 	ret = t4_read_flash(adapter, start, ARRAY_SIZE(exprom_header_buf),
4109 	    exprom_header_buf, 0);
4110 	if (ret)
4111 		return ret;
4112 
4113 	hdr = (struct exprom_header *)exprom_header_buf;
4114 	if (hdr->hdr_arr[0] != 0x55 || hdr->hdr_arr[1] != 0xaa)
4115 		return -ENOENT;
4116 
4117 	*vers = (V_FW_HDR_FW_VER_MAJOR(hdr->hdr_ver[0]) |
4118 		 V_FW_HDR_FW_VER_MINOR(hdr->hdr_ver[1]) |
4119 		 V_FW_HDR_FW_VER_MICRO(hdr->hdr_ver[2]) |
4120 		 V_FW_HDR_FW_VER_BUILD(hdr->hdr_ver[3]));
4121 	return 0;
4122 }
4123 
4124 /**
4125  *	t4_get_scfg_version - return the Serial Configuration version
4126  *	@adapter: the adapter
4127  *	@vers: where to place the version
4128  *
4129  *	Reads the Serial Configuration Version via the Firmware interface
4130  *	(thus this can only be called once we're ready to issue Firmware
4131  *	commands).  The format of the Serial Configuration version is
4132  *	adapter specific.  Returns 0 on success, an error on failure.
4133  *
4134  *	Note that early versions of the Firmware didn't include the ability
4135  *	to retrieve the Serial Configuration version, so we zero-out the
4136  *	return-value parameter in that case to avoid leaving it with
4137  *	garbage in it.
4138  *
4139  *	Also note that the Firmware will return its cached copy of the Serial
4140  *	Initialization Revision ID, not the actual Revision ID as written in
4141  *	the Serial EEPROM.  This is only an issue if a new VPD has been written
4142  *	and the Firmware/Chip haven't yet gone through a RESET sequence.  So
4143  *	it's best to defer calling this routine till after a FW_RESET_CMD has
4144  *	been issued if the Host Driver will be performing a full adapter
4145  *	initialization.
4146  */
t4_get_scfg_version(struct adapter * adapter,u32 * vers)4147 int t4_get_scfg_version(struct adapter *adapter, u32 *vers)
4148 {
4149 	u32 scfgrev_param;
4150 	int ret;
4151 
4152 	scfgrev_param = (V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
4153 			 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_SCFGREV));
4154 	ret = t4_query_params(adapter, adapter->mbox, adapter->pf, 0,
4155 			      1, &scfgrev_param, vers);
4156 	if (ret)
4157 		*vers = 0;
4158 	return ret;
4159 }
4160 
4161 /**
4162  *	t4_get_vpd_version - return the VPD version
4163  *	@adapter: the adapter
4164  *	@vers: where to place the version
4165  *
4166  *	Reads the VPD via the Firmware interface (thus this can only be called
4167  *	once we're ready to issue Firmware commands).  The format of the
4168  *	VPD version is adapter specific.  Returns 0 on success, an error on
4169  *	failure.
4170  *
4171  *	Note that early versions of the Firmware didn't include the ability
4172  *	to retrieve the VPD version, so we zero-out the return-value parameter
4173  *	in that case to avoid leaving it with garbage in it.
4174  *
4175  *	Also note that the Firmware will return its cached copy of the VPD
4176  *	Revision ID, not the actual Revision ID as written in the Serial
4177  *	EEPROM.  This is only an issue if a new VPD has been written and the
4178  *	Firmware/Chip haven't yet gone through a RESET sequence.  So it's best
4179  *	to defer calling this routine till after a FW_RESET_CMD has been issued
4180  *	if the Host Driver will be performing a full adapter initialization.
4181  */
t4_get_vpd_version(struct adapter * adapter,u32 * vers)4182 int t4_get_vpd_version(struct adapter *adapter, u32 *vers)
4183 {
4184 	u32 vpdrev_param;
4185 	int ret;
4186 
4187 	vpdrev_param = (V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
4188 			V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_VPDREV));
4189 	ret = t4_query_params(adapter, adapter->mbox, adapter->pf, 0,
4190 			      1, &vpdrev_param, vers);
4191 	if (ret)
4192 		*vers = 0;
4193 	return ret;
4194 }
4195 
4196 /**
4197  *	t4_get_version_info - extract various chip/firmware version information
4198  *	@adapter: the adapter
4199  *
4200  *	Reads various chip/firmware version numbers and stores them into the
4201  *	adapter Adapter Parameters structure.  If any of the efforts fails
4202  *	the first failure will be returned, but all of the version numbers
4203  *	will be read.
4204  */
t4_get_version_info(struct adapter * adapter)4205 int t4_get_version_info(struct adapter *adapter)
4206 {
4207 	int ret = 0;
4208 
4209 	#define FIRST_RET(__getvinfo) \
4210 	do { \
4211 		int __ret = __getvinfo; \
4212 		if (__ret && !ret) \
4213 			ret = __ret; \
4214 	} while (0)
4215 
4216 	FIRST_RET(t4_get_fw_version(adapter, &adapter->params.fw_vers));
4217 	FIRST_RET(t4_get_bs_version(adapter, &adapter->params.bs_vers));
4218 	FIRST_RET(t4_get_tp_version(adapter, &adapter->params.tp_vers));
4219 	FIRST_RET(t4_get_exprom_version(adapter, &adapter->params.er_vers));
4220 	FIRST_RET(t4_get_scfg_version(adapter, &adapter->params.scfg_vers));
4221 	FIRST_RET(t4_get_vpd_version(adapter, &adapter->params.vpd_vers));
4222 
4223 	#undef FIRST_RET
4224 
4225 	return ret;
4226 }
4227 
4228 /**
4229  *	t4_flash_erase_sectors - erase a range of flash sectors
4230  *	@adapter: the adapter
4231  *	@start: the first sector to erase
4232  *	@end: the last sector to erase
4233  *
4234  *	Erases the sectors in the given inclusive range.
4235  */
t4_flash_erase_sectors(struct adapter * adapter,int start,int end)4236 int t4_flash_erase_sectors(struct adapter *adapter, int start, int end)
4237 {
4238 	int ret = 0;
4239 
4240 	if (end >= adapter->params.sf_nsec)
4241 		return -EINVAL;
4242 
4243 	while (start <= end) {
4244 		if ((ret = sf1_write(adapter, 1, 0, 1, SF_WR_ENABLE)) != 0 ||
4245 		    (ret = sf1_write(adapter, 4, 0, 1,
4246 				     SF_ERASE_SECTOR | (start << 8))) != 0 ||
4247 		    (ret = flash_wait_op(adapter, 14, 500)) != 0) {
4248 			CH_ERR(adapter,
4249 				"erase of flash sector %d failed, error %d\n",
4250 				start, ret);
4251 			break;
4252 		}
4253 		start++;
4254 	}
4255 	t4_write_reg(adapter, A_SF_OP, 0);    /* unlock SF */
4256 	return ret;
4257 }
4258 
4259 /**
4260  *	t4_flash_cfg_addr - return the address of the flash configuration file
4261  *	@adapter: the adapter
4262  *
4263  *	Return the address within the flash where the Firmware Configuration
4264  *	File is stored, or an error if the device FLASH is too small to contain
4265  *	a Firmware Configuration File.
4266  */
t4_flash_cfg_addr(struct adapter * adapter,unsigned int * lenp)4267 int t4_flash_cfg_addr(struct adapter *adapter, unsigned int *lenp)
4268 {
4269 	unsigned int len = 0;
4270 	const int cfg_start = t4_flash_loc_start(adapter, FLASH_LOC_CFG, &len);
4271 
4272 	/*
4273 	 * If the device FLASH isn't large enough to hold a Firmware
4274 	 * Configuration File, return an error.
4275 	 */
4276 	if (adapter->params.sf_size < cfg_start + len)
4277 		return -ENOSPC;
4278 	if (lenp != NULL)
4279 		*lenp = len;
4280 	return (cfg_start);
4281 }
4282 
4283 /*
4284  * Return TRUE if the specified firmware matches the adapter.  I.e. T4
4285  * firmware for T4 adapters, T5 firmware for T5 adapters, etc.  We go ahead
4286  * and emit an error message for mismatched firmware to save our caller the
4287  * effort ...
4288  */
t4_fw_matches_chip(struct adapter * adap,const struct fw_hdr * hdr)4289 static int t4_fw_matches_chip(struct adapter *adap,
4290 			      const struct fw_hdr *hdr)
4291 {
4292 	/*
4293 	 * The expression below will return FALSE for any unsupported adapter
4294 	 * which will keep us "honest" in the future ...
4295 	 */
4296 	if ((is_t4(adap) && hdr->chip == FW_HDR_CHIP_T4) ||
4297 	    (is_t5(adap) && hdr->chip == FW_HDR_CHIP_T5) ||
4298 	    (is_t6(adap) && hdr->chip == FW_HDR_CHIP_T6) ||
4299 	    (is_t7(adap) && hdr->chip == FW_HDR_CHIP_T7))
4300 		return 1;
4301 
4302 	CH_ERR(adap,
4303 		"FW image (%d) is not suitable for this adapter (%d)\n",
4304 		hdr->chip, chip_id(adap));
4305 	return 0;
4306 }
4307 
4308 /**
4309  *	t4_load_fw - download firmware
4310  *	@adap: the adapter
4311  *	@fw_data: the firmware image to write
4312  *	@size: image size
4313  *
4314  *	Write the supplied firmware image to the card's serial flash.
4315  */
t4_load_fw(struct adapter * adap,const u8 * fw_data,unsigned int size)4316 int t4_load_fw(struct adapter *adap, const u8 *fw_data, unsigned int size)
4317 {
4318 	u32 csum;
4319 	int ret, addr;
4320 	unsigned int i;
4321 	u8 first_page[SF_PAGE_SIZE];
4322 	const u32 *p = (const u32 *)fw_data;
4323 	const struct fw_hdr *hdr = (const struct fw_hdr *)fw_data;
4324 	unsigned int fw_start_sec;
4325 	unsigned int fw_start;
4326 	unsigned int fw_size;
4327 	enum t4_flash_loc loc;
4328 
4329 	loc = ntohl(hdr->magic) == FW_HDR_MAGIC_BOOTSTRAP ?
4330 	    FLASH_LOC_FWBOOTSTRAP : FLASH_LOC_FW;
4331 	fw_start = t4_flash_loc_start(adap, loc, &fw_size);
4332 	fw_start_sec = fw_start / SF_SEC_SIZE;
4333 
4334 	if (!size) {
4335 		CH_ERR(adap, "FW image has no data\n");
4336 		return -EINVAL;
4337 	}
4338 	if (size & 511) {
4339 		CH_ERR(adap,
4340 			"FW image size not multiple of 512 bytes\n");
4341 		return -EINVAL;
4342 	}
4343 	if ((unsigned int) be16_to_cpu(hdr->len512) * 512 != size) {
4344 		CH_ERR(adap,
4345 			"FW image size differs from size in FW header\n");
4346 		return -EINVAL;
4347 	}
4348 	if (size > fw_size) {
4349 		CH_ERR(adap, "FW image too large, max is %u bytes\n",
4350 			fw_size);
4351 		return -EFBIG;
4352 	}
4353 	if (!t4_fw_matches_chip(adap, hdr))
4354 		return -EINVAL;
4355 
4356 	for (csum = 0, i = 0; i < size / sizeof(csum); i++)
4357 		csum += be32_to_cpu(p[i]);
4358 
4359 	if (csum != 0xffffffff) {
4360 		CH_ERR(adap,
4361 			"corrupted firmware image, checksum %#x\n", csum);
4362 		return -EINVAL;
4363 	}
4364 
4365 	i = DIV_ROUND_UP(size, SF_SEC_SIZE);	/* # of sectors spanned */
4366 	ret = t4_flash_erase_sectors(adap, fw_start_sec, fw_start_sec + i - 1);
4367 	if (ret)
4368 		goto out;
4369 
4370 	/*
4371 	 * We write the correct version at the end so the driver can see a bad
4372 	 * version if the FW write fails.  Start by writing a copy of the
4373 	 * first page with a bad version.
4374 	 */
4375 	memcpy(first_page, fw_data, SF_PAGE_SIZE);
4376 	((struct fw_hdr *)first_page)->fw_ver = cpu_to_be32(0xffffffff);
4377 	ret = t4_write_flash(adap, fw_start, SF_PAGE_SIZE, first_page, 1);
4378 	if (ret)
4379 		goto out;
4380 
4381 	addr = fw_start;
4382 	for (size -= SF_PAGE_SIZE; size; size -= SF_PAGE_SIZE) {
4383 		addr += SF_PAGE_SIZE;
4384 		fw_data += SF_PAGE_SIZE;
4385 		ret = t4_write_flash(adap, addr, SF_PAGE_SIZE, fw_data, 1);
4386 		if (ret)
4387 			goto out;
4388 	}
4389 
4390 	ret = t4_write_flash(adap,
4391 			     fw_start + offsetof(struct fw_hdr, fw_ver),
4392 			     sizeof(hdr->fw_ver), (const u8 *)&hdr->fw_ver, 1);
4393 out:
4394 	if (ret)
4395 		CH_ERR(adap, "firmware download failed, error %d\n",
4396 			ret);
4397 	return ret;
4398 }
4399 
4400 /**
4401  *	t4_fwcache - firmware cache operation
4402  *	@adap: the adapter
4403  *	@op  : the operation (flush or flush and invalidate)
4404  */
t4_fwcache(struct adapter * adap,enum fw_params_param_dev_fwcache op)4405 int t4_fwcache(struct adapter *adap, enum fw_params_param_dev_fwcache op)
4406 {
4407 	struct fw_params_cmd c;
4408 
4409 	memset(&c, 0, sizeof(c));
4410 	c.op_to_vfn =
4411 	    cpu_to_be32(V_FW_CMD_OP(FW_PARAMS_CMD) |
4412 			    F_FW_CMD_REQUEST | F_FW_CMD_WRITE |
4413 				V_FW_PARAMS_CMD_PFN(adap->pf) |
4414 				V_FW_PARAMS_CMD_VFN(0));
4415 	c.retval_len16 = cpu_to_be32(FW_LEN16(c));
4416 	c.param[0].mnem =
4417 	    cpu_to_be32(V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
4418 			    V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_FWCACHE));
4419 	c.param[0].val = cpu_to_be32(op);
4420 
4421 	return t4_wr_mbox(adap, adap->mbox, &c, sizeof(c), NULL);
4422 }
4423 
t4_cim_read_pif_la(struct adapter * adap,u32 * pif_req,u32 * pif_rsp,unsigned int * pif_req_wrptr,unsigned int * pif_rsp_wrptr)4424 void t4_cim_read_pif_la(struct adapter *adap, u32 *pif_req, u32 *pif_rsp,
4425 			unsigned int *pif_req_wrptr,
4426 			unsigned int *pif_rsp_wrptr)
4427 {
4428 	int i, j;
4429 	u32 cfg, val, req, rsp;
4430 
4431 	cfg = t4_read_reg(adap, A_CIM_DEBUGCFG);
4432 	if (cfg & F_LADBGEN)
4433 		t4_write_reg(adap, A_CIM_DEBUGCFG, cfg ^ F_LADBGEN);
4434 
4435 	val = t4_read_reg(adap, A_CIM_DEBUGSTS);
4436 	req = G_POLADBGWRPTR(val);
4437 	rsp = G_PILADBGWRPTR(val);
4438 	if (pif_req_wrptr)
4439 		*pif_req_wrptr = req;
4440 	if (pif_rsp_wrptr)
4441 		*pif_rsp_wrptr = rsp;
4442 
4443 	for (i = 0; i < CIM_PIFLA_SIZE; i++) {
4444 		for (j = 0; j < 6; j++) {
4445 			t4_write_reg(adap, A_CIM_DEBUGCFG, V_POLADBGRDPTR(req) |
4446 				     V_PILADBGRDPTR(rsp));
4447 			*pif_req++ = t4_read_reg(adap, A_CIM_PO_LA_DEBUGDATA);
4448 			*pif_rsp++ = t4_read_reg(adap, A_CIM_PI_LA_DEBUGDATA);
4449 			req++;
4450 			rsp++;
4451 		}
4452 		req = (req + 2) & M_POLADBGRDPTR;
4453 		rsp = (rsp + 2) & M_PILADBGRDPTR;
4454 	}
4455 	t4_write_reg(adap, A_CIM_DEBUGCFG, cfg);
4456 }
4457 
t4_cim_read_ma_la(struct adapter * adap,u32 * ma_req,u32 * ma_rsp)4458 void t4_cim_read_ma_la(struct adapter *adap, u32 *ma_req, u32 *ma_rsp)
4459 {
4460 	u32 cfg;
4461 	int i, j, idx;
4462 
4463 	cfg = t4_read_reg(adap, A_CIM_DEBUGCFG);
4464 	if (cfg & F_LADBGEN)
4465 		t4_write_reg(adap, A_CIM_DEBUGCFG, cfg ^ F_LADBGEN);
4466 
4467 	for (i = 0; i < CIM_MALA_SIZE; i++) {
4468 		for (j = 0; j < 5; j++) {
4469 			idx = 8 * i + j;
4470 			t4_write_reg(adap, A_CIM_DEBUGCFG, V_POLADBGRDPTR(idx) |
4471 				     V_PILADBGRDPTR(idx));
4472 			*ma_req++ = t4_read_reg(adap, A_CIM_PO_LA_MADEBUGDATA);
4473 			*ma_rsp++ = t4_read_reg(adap, A_CIM_PI_LA_MADEBUGDATA);
4474 		}
4475 	}
4476 	t4_write_reg(adap, A_CIM_DEBUGCFG, cfg);
4477 }
4478 
t4_ulprx_read_la(struct adapter * adap,u32 * la_buf)4479 void t4_ulprx_read_la(struct adapter *adap, u32 *la_buf)
4480 {
4481 	unsigned int i, j;
4482 
4483 	for (i = 0; i < 8; i++) {
4484 		u32 *p = la_buf + i;
4485 
4486 		t4_write_reg(adap, A_ULP_RX_LA_CTL, i);
4487 		j = t4_read_reg(adap, A_ULP_RX_LA_WRPTR);
4488 		t4_write_reg(adap, A_ULP_RX_LA_RDPTR, j);
4489 		for (j = 0; j < ULPRX_LA_SIZE; j++, p += 8)
4490 			*p = t4_read_reg(adap, A_ULP_RX_LA_RDDATA);
4491 	}
4492 }
4493 
4494 /**
4495  *	fwcaps16_to_caps32 - convert 16-bit Port Capabilities to 32-bits
4496  *	@caps16: a 16-bit Port Capabilities value
4497  *
4498  *	Returns the equivalent 32-bit Port Capabilities value.
4499  */
fwcaps16_to_caps32(uint16_t caps16)4500 static uint32_t fwcaps16_to_caps32(uint16_t caps16)
4501 {
4502 	uint32_t caps32 = 0;
4503 
4504 	#define CAP16_TO_CAP32(__cap) \
4505 		do { \
4506 			if (caps16 & FW_PORT_CAP_##__cap) \
4507 				caps32 |= FW_PORT_CAP32_##__cap; \
4508 		} while (0)
4509 
4510 	CAP16_TO_CAP32(SPEED_100M);
4511 	CAP16_TO_CAP32(SPEED_1G);
4512 	CAP16_TO_CAP32(SPEED_25G);
4513 	CAP16_TO_CAP32(SPEED_10G);
4514 	CAP16_TO_CAP32(SPEED_40G);
4515 	CAP16_TO_CAP32(SPEED_100G);
4516 	CAP16_TO_CAP32(FC_RX);
4517 	CAP16_TO_CAP32(FC_TX);
4518 	CAP16_TO_CAP32(ANEG);
4519 	CAP16_TO_CAP32(FORCE_PAUSE);
4520 	CAP16_TO_CAP32(MDIAUTO);
4521 	CAP16_TO_CAP32(MDISTRAIGHT);
4522 	CAP16_TO_CAP32(FEC_RS);
4523 	CAP16_TO_CAP32(FEC_BASER_RS);
4524 	CAP16_TO_CAP32(802_3_PAUSE);
4525 	CAP16_TO_CAP32(802_3_ASM_DIR);
4526 
4527 	#undef CAP16_TO_CAP32
4528 
4529 	return caps32;
4530 }
4531 
4532 /**
4533  *	fwcaps32_to_caps16 - convert 32-bit Port Capabilities to 16-bits
4534  *	@caps32: a 32-bit Port Capabilities value
4535  *
4536  *	Returns the equivalent 16-bit Port Capabilities value.  Note that
4537  *	not all 32-bit Port Capabilities can be represented in the 16-bit
4538  *	Port Capabilities and some fields/values may not make it.
4539  */
fwcaps32_to_caps16(uint32_t caps32)4540 static uint16_t fwcaps32_to_caps16(uint32_t caps32)
4541 {
4542 	uint16_t caps16 = 0;
4543 
4544 	#define CAP32_TO_CAP16(__cap) \
4545 		do { \
4546 			if (caps32 & FW_PORT_CAP32_##__cap) \
4547 				caps16 |= FW_PORT_CAP_##__cap; \
4548 		} while (0)
4549 
4550 	CAP32_TO_CAP16(SPEED_100M);
4551 	CAP32_TO_CAP16(SPEED_1G);
4552 	CAP32_TO_CAP16(SPEED_10G);
4553 	CAP32_TO_CAP16(SPEED_25G);
4554 	CAP32_TO_CAP16(SPEED_40G);
4555 	CAP32_TO_CAP16(SPEED_100G);
4556 	CAP32_TO_CAP16(FC_RX);
4557 	CAP32_TO_CAP16(FC_TX);
4558 	CAP32_TO_CAP16(802_3_PAUSE);
4559 	CAP32_TO_CAP16(802_3_ASM_DIR);
4560 	CAP32_TO_CAP16(ANEG);
4561 	CAP32_TO_CAP16(FORCE_PAUSE);
4562 	CAP32_TO_CAP16(MDIAUTO);
4563 	CAP32_TO_CAP16(MDISTRAIGHT);
4564 	CAP32_TO_CAP16(FEC_RS);
4565 	CAP32_TO_CAP16(FEC_BASER_RS);
4566 
4567 	#undef CAP32_TO_CAP16
4568 
4569 	return caps16;
4570 }
4571 
fwcap_to_fec(uint32_t caps,bool unset_means_none)4572 static int8_t fwcap_to_fec(uint32_t caps, bool unset_means_none)
4573 {
4574 	int8_t fec = 0;
4575 
4576 	if ((caps & V_FW_PORT_CAP32_FEC(M_FW_PORT_CAP32_FEC)) == 0)
4577 		return (unset_means_none ? FEC_NONE : 0);
4578 
4579 	if (caps & FW_PORT_CAP32_FEC_RS)
4580 		fec |= FEC_RS;
4581 	if (caps & FW_PORT_CAP32_FEC_BASER_RS)
4582 		fec |= FEC_BASER_RS;
4583 	if (caps & FW_PORT_CAP32_FEC_NO_FEC)
4584 		fec |= FEC_NONE;
4585 
4586 	return (fec);
4587 }
4588 
4589 /*
4590  * Note that 0 is not translated to NO_FEC.
4591  */
fec_to_fwcap(int8_t fec)4592 static uint32_t fec_to_fwcap(int8_t fec)
4593 {
4594 	uint32_t caps = 0;
4595 
4596 	/* Only real FECs allowed. */
4597 	MPASS((fec & ~M_FW_PORT_CAP32_FEC) == 0);
4598 
4599 	if (fec & FEC_RS)
4600 		caps |= FW_PORT_CAP32_FEC_RS;
4601 	if (fec & FEC_BASER_RS)
4602 		caps |= FW_PORT_CAP32_FEC_BASER_RS;
4603 	if (fec & FEC_NONE)
4604 		caps |= FW_PORT_CAP32_FEC_NO_FEC;
4605 
4606 	return (caps);
4607 }
4608 
4609 /**
4610  *	t4_link_l1cfg - apply link configuration to MAC/PHY
4611  *	@phy: the PHY to setup
4612  *	@mac: the MAC to setup
4613  *	@lc: the requested link configuration
4614  *
4615  *	Set up a port's MAC and PHY according to a desired link configuration.
4616  *	- If the PHY can auto-negotiate first decide what to advertise, then
4617  *	  enable/disable auto-negotiation as desired, and reset.
4618  *	- If the PHY does not auto-negotiate just reset it.
4619  *	- If auto-negotiation is off set the MAC to the proper speed/duplex/FC,
4620  *	  otherwise do it later based on the outcome of auto-negotiation.
4621  */
t4_link_l1cfg(struct adapter * adap,unsigned int mbox,unsigned int port,struct link_config * lc)4622 int t4_link_l1cfg(struct adapter *adap, unsigned int mbox, unsigned int port,
4623 		  struct link_config *lc)
4624 {
4625 	struct fw_port_cmd c;
4626 	unsigned int mdi = V_FW_PORT_CAP32_MDI(FW_PORT_CAP32_MDI_AUTO);
4627 	unsigned int aneg, fc, fec, speed, rcap;
4628 
4629 	fc = 0;
4630 	if (lc->requested_fc & PAUSE_RX)
4631 		fc |= FW_PORT_CAP32_FC_RX;
4632 	if (lc->requested_fc & PAUSE_TX)
4633 		fc |= FW_PORT_CAP32_FC_TX;
4634 	if (!(lc->requested_fc & PAUSE_AUTONEG))
4635 		fc |= FW_PORT_CAP32_FORCE_PAUSE;
4636 
4637 	if (lc->requested_aneg == AUTONEG_DISABLE)
4638 		aneg = 0;
4639 	else if (lc->requested_aneg == AUTONEG_ENABLE)
4640 		aneg = FW_PORT_CAP32_ANEG;
4641 	else
4642 		aneg = lc->pcaps & FW_PORT_CAP32_ANEG;
4643 
4644 	if (aneg) {
4645 		speed = lc->pcaps &
4646 		    V_FW_PORT_CAP32_SPEED(M_FW_PORT_CAP32_SPEED);
4647 	} else if (lc->requested_speed != 0)
4648 		speed = speed_to_fwcap(lc->requested_speed);
4649 	else
4650 		speed = fwcap_top_speed(lc->pcaps);
4651 
4652 	fec = 0;
4653 	if (fec_supported(speed)) {
4654 		int force_fec;
4655 
4656 		if (lc->pcaps & FW_PORT_CAP32_FORCE_FEC)
4657 			force_fec = lc->force_fec;
4658 		else
4659 			force_fec = 0;
4660 
4661 		if (lc->requested_fec == FEC_AUTO) {
4662 			if (force_fec > 0) {
4663 				/*
4664 				 * Must use FORCE_FEC even though requested FEC
4665 				 * is AUTO. Set all the FEC bits valid for the
4666 				 * speed and let the firmware pick one.
4667 				 */
4668 				fec |= FW_PORT_CAP32_FORCE_FEC;
4669 				if (speed & FW_PORT_CAP32_SPEED_25G) {
4670 					fec |= FW_PORT_CAP32_FEC_RS;
4671 					fec |= FW_PORT_CAP32_FEC_BASER_RS;
4672 					fec |= FW_PORT_CAP32_FEC_NO_FEC;
4673 				} else {
4674 					fec |= FW_PORT_CAP32_FEC_RS;
4675 					fec |= FW_PORT_CAP32_FEC_NO_FEC;
4676 				}
4677 			} else {
4678 				/*
4679 				 * Set only 1b. Old firmwares can't deal with
4680 				 * multiple bits and new firmwares are free to
4681 				 * ignore this and try whatever FECs they want
4682 				 * because we aren't setting FORCE_FEC here.
4683 				 */
4684 				fec |= fec_to_fwcap(lc->fec_hint);
4685 				MPASS(powerof2(fec));
4686 
4687 				/*
4688 				 * Override the hint if the FEC is not valid for
4689 				 * the potential top speed.  Request the best
4690 				 * FEC at that speed instead.
4691 				 */
4692 				if ((speed & FW_PORT_CAP32_SPEED_25G) == 0 &&
4693 				    fec == FW_PORT_CAP32_FEC_BASER_RS) {
4694 					fec = FW_PORT_CAP32_FEC_RS;
4695 				}
4696 			}
4697 		} else {
4698 			/*
4699 			 * User has explicitly requested some FEC(s). Set
4700 			 * FORCE_FEC unless prohibited from using it.
4701 			 */
4702 			if (force_fec != 0)
4703 				fec |= FW_PORT_CAP32_FORCE_FEC;
4704 			fec |= fec_to_fwcap(lc->requested_fec &
4705 			    M_FW_PORT_CAP32_FEC);
4706 			if (lc->requested_fec & FEC_MODULE)
4707 				fec |= fec_to_fwcap(lc->fec_hint);
4708 		}
4709 
4710 		/*
4711 		 * This is for compatibility with old firmwares. The original
4712 		 * way to request NO_FEC was to not set any of the FEC bits. New
4713 		 * firmwares understand this too.
4714 		 */
4715 		if (fec == FW_PORT_CAP32_FEC_NO_FEC)
4716 			fec = 0;
4717 	}
4718 
4719 	/* Force AN on for BT cards. */
4720 	if (isset(&adap->bt_map, port))
4721 		aneg = lc->pcaps & FW_PORT_CAP32_ANEG;
4722 
4723 	rcap = aneg | speed | fc | fec;
4724 	if ((rcap | lc->pcaps) != lc->pcaps) {
4725 #ifdef INVARIANTS
4726 		CH_WARN(adap, "rcap 0x%08x, pcap 0x%08x, removed 0x%x\n", rcap,
4727 		    lc->pcaps, rcap & (rcap ^ lc->pcaps));
4728 #endif
4729 		rcap &= lc->pcaps;
4730 	}
4731 	rcap |= mdi;
4732 
4733 	memset(&c, 0, sizeof(c));
4734 	c.op_to_portid = cpu_to_be32(V_FW_CMD_OP(FW_PORT_CMD) |
4735 				     F_FW_CMD_REQUEST | F_FW_CMD_EXEC |
4736 				     V_FW_PORT_CMD_PORTID(port));
4737 	if (adap->params.port_caps32) {
4738 		c.action_to_len16 =
4739 		    cpu_to_be32(V_FW_PORT_CMD_ACTION(FW_PORT_ACTION_L1_CFG32) |
4740 			FW_LEN16(c));
4741 		c.u.l1cfg32.rcap32 = cpu_to_be32(rcap);
4742 	} else {
4743 		c.action_to_len16 =
4744 		    cpu_to_be32(V_FW_PORT_CMD_ACTION(FW_PORT_ACTION_L1_CFG) |
4745 			    FW_LEN16(c));
4746 		c.u.l1cfg.rcap = cpu_to_be32(fwcaps32_to_caps16(rcap));
4747 	}
4748 
4749 	lc->requested_caps = rcap;
4750 	return t4_wr_mbox_ns(adap, mbox, &c, sizeof(c), NULL);
4751 }
4752 
4753 /**
4754  *	t4_restart_aneg - restart autonegotiation
4755  *	@adap: the adapter
4756  *	@mbox: mbox to use for the FW command
4757  *	@port: the port id
4758  *
4759  *	Restarts autonegotiation for the selected port.
4760  */
t4_restart_aneg(struct adapter * adap,unsigned int mbox,unsigned int port)4761 int t4_restart_aneg(struct adapter *adap, unsigned int mbox, unsigned int port)
4762 {
4763 	struct fw_port_cmd c;
4764 
4765 	memset(&c, 0, sizeof(c));
4766 	c.op_to_portid = cpu_to_be32(V_FW_CMD_OP(FW_PORT_CMD) |
4767 				     F_FW_CMD_REQUEST | F_FW_CMD_EXEC |
4768 				     V_FW_PORT_CMD_PORTID(port));
4769 	c.action_to_len16 =
4770 		cpu_to_be32(V_FW_PORT_CMD_ACTION(FW_PORT_ACTION_L1_CFG) |
4771 			    FW_LEN16(c));
4772 	c.u.l1cfg.rcap = cpu_to_be32(FW_PORT_CAP_ANEG);
4773 	return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
4774 }
4775 
4776 struct intr_details {
4777 	u32 mask;
4778 	const char *msg;
4779 };
4780 
4781 struct intr_action {
4782 	u32 mask;
4783 	int arg;
4784 	bool (*action)(struct adapter *, int, int);
4785 };
4786 
4787 struct intr_info {
4788 	const char *name;	/* name of the INT_CAUSE register */
4789 	int cause_reg;		/* INT_CAUSE register */
4790 	int enable_reg;		/* INT_ENABLE register */
4791 	u32 fatal;		/* bits that are fatal */
4792 	int flags;		/* hints */
4793 	const struct intr_details *details;
4794 	const struct intr_action *actions;
4795 };
4796 
4797 /* Helper to clear interrupts that have IHF_CLR_DELAYED. */
4798 static void
clear_int_cause_reg(struct adapter * sc,const struct intr_info * ii,int flags)4799 clear_int_cause_reg(struct adapter *sc, const struct intr_info *ii, int flags)
4800 {
4801 	u32 cause, ucause;
4802 
4803 	cause = ucause = t4_read_reg(sc, ii->cause_reg);
4804 	if (cause == 0)
4805 		return;
4806 	flags |= ii->flags;
4807 	if (flags & IHF_IGNORE_IF_DISABLED)
4808 		ucause &= t4_read_reg(sc, ii->enable_reg);
4809 	if (flags & IHF_CLR_ALL_SET) {
4810 		t4_write_reg(sc, ii->cause_reg, cause);
4811 		(void)t4_read_reg(sc, ii->cause_reg);
4812 	} else if (ucause != 0 && flags & IHF_CLR_ALL_UNIGNORED) {
4813 		t4_write_reg(sc, ii->cause_reg, ucause);
4814 		(void)t4_read_reg(sc, ii->cause_reg);
4815 	}
4816 }
4817 
4818 static inline char
intr_alert_char(u32 cause,u32 enable,u32 fatal)4819 intr_alert_char(u32 cause, u32 enable, u32 fatal)
4820 {
4821 	if (cause & fatal)
4822 		return ('!');
4823 	if (cause & enable)
4824 		return ('*');
4825 	return ('-');
4826 }
4827 
4828 static void
show_intr_info(struct adapter * sc,const struct intr_info * ii,uint32_t cause,uint32_t ucause,uint32_t enabled,uint32_t fatal,int flags)4829 show_intr_info(struct adapter *sc, const struct intr_info *ii, uint32_t cause,
4830     uint32_t ucause, uint32_t enabled, uint32_t fatal, int flags)
4831 {
4832 	uint32_t leftover, msgbits;
4833 	const struct intr_details *details;
4834 	char alert;
4835 	const bool verbose = flags & IHF_VERBOSE;
4836 
4837 	if (verbose || ucause != 0 || flags & IHF_RUN_ALL_ACTIONS) {
4838 		alert = intr_alert_char(cause, enabled, fatal);
4839 		CH_ALERT(sc, "%c %s 0x%x = 0x%08x, E 0x%08x, F 0x%08x\n", alert,
4840 		    ii->name, ii->cause_reg, cause, enabled, ii->fatal);
4841 	}
4842 
4843 	leftover = verbose ? cause : ucause;
4844 	for (details = ii->details; details && details->mask != 0; details++) {
4845 		msgbits = details->mask & leftover;
4846 		if (msgbits == 0)
4847 			continue;
4848 		alert = intr_alert_char(msgbits, enabled, fatal);
4849 		CH_ALERT(sc, "  %c [0x%08x] %s\n", alert, msgbits, details->msg);
4850 		leftover &= ~msgbits;
4851 	}
4852 	if (leftover != 0 && leftover != (verbose ? cause : ucause)) {
4853 		alert = intr_alert_char(leftover, enabled, fatal);
4854 		CH_ALERT(sc, "  %c [0x%08x]\n", alert, leftover);
4855 	}
4856 }
4857 
4858 /*
4859  * Returns true for fatal error.
4860  */
4861 static bool
t4_handle_intr(struct adapter * sc,const struct intr_info * ii,uint32_t acause,int flags)4862 t4_handle_intr(struct adapter *sc, const struct intr_info *ii, uint32_t acause,
4863     int flags)
4864 {
4865 	uint32_t cause, ucause, enabled, fatal;
4866 	bool rc;
4867 	const struct intr_action *action;
4868 
4869 	cause = t4_read_reg(sc, ii->cause_reg);
4870 	enabled = t4_read_reg(sc, ii->enable_reg);
4871 	flags |= ii->flags;
4872 	fatal = ii->fatal & cause;
4873 	if (flags & IHF_FATAL_IFF_ENABLED)
4874 		fatal &= enabled;
4875 	ucause = cause;
4876 	if (flags & IHF_IGNORE_IF_DISABLED)
4877 		ucause &= enabled;
4878 	if (!(flags & IHF_NO_SHOW))
4879 		show_intr_info(sc, ii, cause, ucause, enabled, fatal, flags);
4880 
4881 	rc = fatal != 0;
4882 	for (action = ii->actions; action && action->mask != 0; action++) {
4883 		if (action->action == NULL)
4884 			continue;
4885 		if (action->mask & (ucause | acause) ||
4886 		    flags & IHF_RUN_ALL_ACTIONS) {
4887 			bool rc1 = (action->action)(sc, action->arg, flags);
4888 			if (action->mask & ucause)
4889 				rc |= rc1;
4890 		}
4891 	}
4892 
4893 	/* Clear here unless delayed clear is requested. */
4894 	if (cause != 0 && (flags & IHF_CLR_DELAYED) == 0) {
4895 		if (flags & IHF_CLR_ALL_SET) {
4896 			t4_write_reg(sc, ii->cause_reg, cause);
4897 			(void)t4_read_reg(sc, ii->cause_reg);
4898 		} else if (ucause != 0 && flags & IHF_CLR_ALL_UNIGNORED) {
4899 			t4_write_reg(sc, ii->cause_reg, ucause);
4900 			(void)t4_read_reg(sc, ii->cause_reg);
4901 		}
4902 	}
4903 
4904 	return (rc);
4905 }
4906 
4907 /*
4908  * Interrupt handler for the PCIE module.
4909  */
pcie_intr_handler(struct adapter * adap,int arg,int flags)4910 static bool pcie_intr_handler(struct adapter *adap, int arg, int flags)
4911 {
4912 	static const struct intr_details sysbus_intr_details[] = {
4913 		{ F_RNPP, "RXNP array parity error" },
4914 		{ F_RPCP, "RXPC array parity error" },
4915 		{ F_RCIP, "RXCIF array parity error" },
4916 		{ F_RCCP, "Rx completions control array parity error" },
4917 		{ F_RFTP, "RXFT array parity error" },
4918 		{ 0 }
4919 	};
4920 	static const struct intr_info sysbus_intr_info = {
4921 		.name = "PCIE_CORE_UTL_SYSTEM_BUS_AGENT_STATUS",
4922 		.cause_reg = A_PCIE_CORE_UTL_SYSTEM_BUS_AGENT_STATUS,
4923 		.enable_reg = A_PCIE_CORE_UTL_SYSTEM_BUS_AGENT_INTERRUPT_ENABLE,
4924 		.fatal = F_RFTP | F_RCCP | F_RCIP | F_RPCP | F_RNPP,
4925 		.flags = 0,
4926 		.details = sysbus_intr_details,
4927 		.actions = NULL,
4928 	};
4929 	static const struct intr_details pcie_port_intr_details[] = {
4930 		{ F_TPCP, "TXPC array parity error" },
4931 		{ F_TNPP, "TXNP array parity error" },
4932 		{ F_TFTP, "TXFT array parity error" },
4933 		{ F_TCAP, "TXCA array parity error" },
4934 		{ F_TCIP, "TXCIF array parity error" },
4935 		{ F_RCAP, "RXCA array parity error" },
4936 		{ F_OTDD, "outbound request TLP discarded" },
4937 		{ F_RDPE, "Rx data parity error" },
4938 		{ F_TDUE, "Tx uncorrectable data error" },
4939 		{ 0 }
4940 	};
4941 	static const struct intr_info pcie_port_intr_info = {
4942 		.name = "PCIE_CORE_UTL_PCI_EXPRESS_PORT_STATUS",
4943 		.cause_reg = A_PCIE_CORE_UTL_PCI_EXPRESS_PORT_STATUS,
4944 		.enable_reg = A_PCIE_CORE_UTL_PCI_EXPRESS_PORT_INTERRUPT_ENABLE,
4945 		.fatal = F_TPCP | F_TNPP | F_TFTP | F_TCAP | F_TCIP | F_RCAP |
4946 		    F_OTDD | F_RDPE | F_TDUE,
4947 		.flags = 0,
4948 		.details = pcie_port_intr_details,
4949 		.actions = NULL,
4950 	};
4951 	static const struct intr_details pcie_intr_details[] = {
4952 		{ F_MSIADDRLPERR, "MSI AddrL parity error" },
4953 		{ F_MSIADDRHPERR, "MSI AddrH parity error" },
4954 		{ F_MSIDATAPERR, "MSI data parity error" },
4955 		{ F_MSIXADDRLPERR, "MSI-X AddrL parity error" },
4956 		{ F_MSIXADDRHPERR, "MSI-X AddrH parity error" },
4957 		{ F_MSIXDATAPERR, "MSI-X data parity error" },
4958 		{ F_MSIXDIPERR, "MSI-X DI parity error" },
4959 		{ F_PIOCPLPERR, "PCIe PIO completion FIFO parity error" },
4960 		{ F_PIOREQPERR, "PCIe PIO request FIFO parity error" },
4961 		{ F_TARTAGPERR, "PCIe target tag FIFO parity error" },
4962 		{ F_CCNTPERR, "PCIe CMD channel count parity error" },
4963 		{ F_CREQPERR, "PCIe CMD channel request parity error" },
4964 		{ F_CRSPPERR, "PCIe CMD channel response parity error" },
4965 		{ F_DCNTPERR, "PCIe DMA channel count parity error" },
4966 		{ F_DREQPERR, "PCIe DMA channel request parity error" },
4967 		{ F_DRSPPERR, "PCIe DMA channel response parity error" },
4968 		{ F_HCNTPERR, "PCIe HMA channel count parity error" },
4969 		{ F_HREQPERR, "PCIe HMA channel request parity error" },
4970 		{ F_HRSPPERR, "PCIe HMA channel response parity error" },
4971 		{ F_CFGSNPPERR, "PCIe config snoop FIFO parity error" },
4972 		{ F_FIDPERR, "PCIe FID parity error" },
4973 		{ F_INTXCLRPERR, "PCIe INTx clear parity error" },
4974 		{ F_MATAGPERR, "PCIe MA tag parity error" },
4975 		{ F_PIOTAGPERR, "PCIe PIO tag parity error" },
4976 		{ F_RXCPLPERR, "PCIe Rx completion parity error" },
4977 		{ F_RXWRPERR, "PCIe Rx write parity error" },
4978 		{ F_RPLPERR, "PCIe replay buffer parity error" },
4979 		{ F_PCIESINT, "PCIe core secondary fault" },
4980 		{ F_PCIEPINT, "PCIe core primary fault" },
4981 		{ F_UNXSPLCPLERR, "PCIe unexpected split completion error" },
4982 		{ 0 }
4983 	};
4984 	static const struct intr_details t5_pcie_intr_details[] = {
4985 		{ F_IPGRPPERR, "Parity errors observed by IP" },
4986 		{ F_NONFATALERR, "PCIe non-fatal error" },
4987 		{ F_READRSPERR, "Outbound read error" },
4988 		{ F_TRGT1GRPPERR, "PCIe TRGT1 group FIFOs parity error" },
4989 		{ F_IPSOTPERR, "PCIe IP SOT buffer SRAM parity error" },
4990 		{ F_IPRETRYPERR, "PCIe IP replay buffer parity error" },
4991 		{ F_IPRXDATAGRPPERR, "PCIe IP Rx data group SRAMs parity error" },
4992 		{ F_IPRXHDRGRPPERR, "PCIe IP Rx header group SRAMs parity error" },
4993 		{ F_PIOTAGQPERR, "PIO tag queue FIFO parity error" },
4994 		{ F_MAGRPPERR, "MA group FIFO parity error" },
4995 		{ F_VFIDPERR, "VFID SRAM parity error" },
4996 		{ F_FIDPERR, "FID SRAM parity error" },
4997 		{ F_CFGSNPPERR, "config snoop FIFO parity error" },
4998 		{ F_HRSPPERR, "HMA channel response data SRAM parity error" },
4999 		{ F_HREQRDPERR, "HMA channel read request SRAM parity error" },
5000 		{ F_HREQWRPERR, "HMA channel write request SRAM parity error" },
5001 		{ F_DRSPPERR, "DMA channel response data SRAM parity error" },
5002 		{ F_DREQRDPERR, "DMA channel write request SRAM parity error" },
5003 		{ F_CRSPPERR, "CMD channel response data SRAM parity error" },
5004 		{ F_CREQRDPERR, "CMD channel read request SRAM parity error" },
5005 		{ F_MSTTAGQPERR, "PCIe master tag queue SRAM parity error" },
5006 		{ F_TGTTAGQPERR, "PCIe target tag queue FIFO parity error" },
5007 		{ F_PIOREQGRPPERR, "PIO request group FIFOs parity error" },
5008 		{ F_PIOCPLGRPPERR, "PIO completion group FIFOs parity error" },
5009 		{ F_MSIXDIPERR, "MSI-X DI SRAM parity error" },
5010 		{ F_MSIXDATAPERR, "MSI-X data SRAM parity error" },
5011 		{ F_MSIXADDRHPERR, "MSI-X AddrH SRAM parity error" },
5012 		{ F_MSIXADDRLPERR, "MSI-X AddrL SRAM parity error" },
5013 		{ F_MSIXSTIPERR, "MSI-X STI SRAM parity error" },
5014 		{ F_MSTTIMEOUTPERR, "Master timeout FIFO parity error" },
5015 		{ F_MSTGRPPERR, "Master response read queue SRAM parity error" },
5016 		{ 0 }
5017 	};
5018 	struct intr_info pcie_intr_info = {
5019 		.name = "PCIE_INT_CAUSE",
5020 		.cause_reg = A_PCIE_INT_CAUSE,
5021 		.enable_reg = A_PCIE_INT_ENABLE,
5022 		.fatal = 0xffffffff,
5023 		.flags = IHF_FATAL_IFF_ENABLED,
5024 		.details = NULL,
5025 		.actions = NULL,
5026 	};
5027 	static const struct intr_details pcie_intr_cause_ext_details[] = {
5028 		{ F_IPFORMQPERR, "PCIe IP FormQ Buffer PERR" },
5029 		{ F_IPFORMQCERR, "PCIe IP FormQ Buffer CERR" },
5030 		{ F_TRGT1GRPCERR, "TRGT1 Group FIFOs CERR" },
5031 		{ F_IPSOTCERR, "PCIe IP SOT Buffer SRAM CERR" },
5032 		{ F_IPRETRYCERR, "PCIe IP Replay Buffer CERR" },
5033 		{ F_IPRXDATAGRPCERR, "PCIe IP Rx Data Group SRAMs CERR" },
5034 		{ F_IPRXHDRGRPCERR, "PCIe IP Rx Header Group SRAMs CERR" },
5035 		{ F_A0ARBRSPORDFIFOPERR, "A0 Arbiter Response Order FIFO Parity Error" },
5036 		{ F_HRSPCERR, "Master HMA Channel Response Data SRAM CERR" },
5037 		{ F_HREQRDCERR, "Master HMA Channel Read Request SRAM CERR" },
5038 		{ F_HREQWRCERR, "Master HMA Channel Write Request SRAM CERR" },
5039 		{ F_DRSPCERR, "Master DMA Channel Response Data SRAM CERR" },
5040 		{ F_DREQRDCERR, "Master DMA Channel Read Request SRAM CERR" },
5041 		{ F_DREQWRCERR, "Master DMA Channel Write Request SRAM CERR" },
5042 		{ F_CRSPCERR, "Master CMD Channel Response Data SRAM CERR" },
5043 		{ F_ARSPPERR, "Master ARM Channel Response Data SRAM PERR" },
5044 		{ F_AREQRDPERR, "Master ARM Channel Read Request SRAM PERR" },
5045 		{ F_AREQWRPERR, "Master ARM Channel Write Request SRAM PERR" },
5046 		{ F_PIOREQGRPCERR, "PIO Request Group FIFOs CERR" },
5047 		{ F_ARSPCERR, "Master ARM Channel Response Data SRAM CERR" },
5048 		{ F_AREQRDCERR, "Master ARM Channel Read Request SRAM CERR" },
5049 		{ F_AREQWRCERR, "Master ARM Channel Write Request SRAM CERR" },
5050 		{ F_MARSPPERR, "INIC MA Ctrl and Data Rsp Perr" },
5051 		{ F_INICMAWDATAORDPERR, "INIC Ma Arb Write Ord Data Fifo Perr" },
5052 		{ F_EMUPERR, "CFG EMU SRAM PERR" },
5053 		{ F_ERRSPPERR, "CFG EMU SRAM CERR" },
5054 		{ F_MSTGRPCERR, "Master Data Path and Response Read Queue SRAM CERR" },
5055 		{ 0 }
5056 	};
5057 	struct intr_info pcie_int_cause_ext = {
5058 		.name = "PCIE_INT_CAUSE_EXT",
5059 		.cause_reg = A_PCIE_INT_CAUSE_EXT,
5060 		.enable_reg = A_PCIE_INT_ENABLE_EXT,
5061 		.fatal = 0,
5062 		.flags = 0,
5063 		.details = pcie_intr_cause_ext_details,
5064 		.actions = NULL,
5065 	};
5066 	static const struct intr_details pcie_intr_cause_x8_details[] = {
5067 		{ F_X8TGTGRPPERR, "x8 TGT Group FIFOs parity error" },
5068 		{ F_X8IPSOTPERR, "PCIe x8 IP SOT Buffer SRAM PERR" },
5069 		{ F_X8IPRETRYPERR, "PCIe x8 IP Replay Buffer PERR" },
5070 		{ F_X8IPRXDATAGRPPERR, "PCIe x8 IP Rx Data Group SRAMs PERR" },
5071 		{ F_X8IPRXHDRGRPPERR, "PCIe x8 IP Rx Header Group SRAMs PERR" },
5072 		{ F_X8IPCORECERR, "x8 IP SOT, Retry, RxData, RxHdr SRAM CERR" },
5073 		{ F_X8MSTGRPPERR, "x8 Master Data Path and Response Read Queue SRAM PERR" },
5074 		{ F_X8MSTGRPCERR, "x8 Master Data Path and Response Read Queue SRAM CERR" },
5075 		{ 0 }
5076 	};
5077 	struct intr_info pcie_int_cause_x8 = {
5078 		.name = "PCIE_INT_CAUSE_X8",
5079 		.cause_reg = A_PCIE_INT_CAUSE_X8,
5080 		.enable_reg = A_PCIE_INT_ENABLE_X8,
5081 		.fatal = 0,
5082 		.flags = 0,
5083 		.details = pcie_intr_cause_x8_details,
5084 		.actions = NULL,
5085 	};
5086 	bool fatal = false;
5087 
5088 	if (is_t4(adap)) {
5089 		fatal |= t4_handle_intr(adap, &sysbus_intr_info, 0, flags);
5090 		fatal |= t4_handle_intr(adap, &pcie_port_intr_info, 0, flags);
5091 
5092 		pcie_intr_info.details = pcie_intr_details;
5093 	} else {
5094 		pcie_intr_info.details = t5_pcie_intr_details;
5095 	}
5096 	fatal |= t4_handle_intr(adap, &pcie_intr_info, 0, flags);
5097 	if (chip_id(adap) > CHELSIO_T6) {
5098 		fatal |= t4_handle_intr(adap, &pcie_int_cause_ext, 0, flags);
5099 		fatal |= t4_handle_intr(adap, &pcie_int_cause_x8, 0, flags);
5100 	}
5101 
5102 	return (fatal);
5103 }
5104 
5105 /*
5106  * TP interrupt handler.
5107  */
tp_intr_handler(struct adapter * adap,int arg,int flags)5108 static bool tp_intr_handler(struct adapter *adap, int arg, int flags)
5109 {
5110 	static const struct intr_details tp_intr_details[] = {
5111 		{ 0x3fffffff, "TP parity error" },
5112 		{ F_FLMTXFLSTEMPTY, "TP out of Tx pages" },
5113 		{ 0 }
5114 	};
5115 	static const struct intr_details t7_tp_intr_details[] = {
5116 		{ F_FLMTXFLSTEMPTY, "Offload memory manager Tx free list empty" },
5117 		{ F_TPCERR, "TP modules flagged Correctable Error" },
5118 		{ F_OTHERPERR, "TP Other modules (Core, TM, FLM, MMGR, DB) Parity Error" },
5119 		{ F_TPEING1PERR, "TP-ESide Ingress1 Parity Error" },
5120 		{ F_TPEING0PERR, "TP-ESide Ingress0 Parity Error" },
5121 		{ F_TPEEGPERR, "TP-ESide Egress Parity Error" },
5122 		{ F_TPCPERR, "TP-CSide Parity Error" },
5123 		{ 0 }
5124 	};
5125 	struct intr_info tp_intr_info = {
5126 		.name = "TP_INT_CAUSE",
5127 		.cause_reg = A_TP_INT_CAUSE,
5128 		.enable_reg = A_TP_INT_ENABLE,
5129 		.fatal = 0x7fffffff,
5130 		.flags = IHF_FATAL_IFF_ENABLED | IHF_CLR_DELAYED,
5131 		.details = NULL,
5132 		.actions = NULL,
5133 	};
5134 	static const struct intr_details tp_cerr_cause_details[] = {
5135 		{ F_TPCEGDATAFIFO, "TPCSide Egress Data FIFO" },
5136 		{ F_TPCLBKDATAFIFO, "TPCSide Loopback Data FIFO" },
5137 		{ F_RSSLKPSRAM, "RSS Lookup SRAM" },
5138 		{ F_SRQSRAM, "SRQ SRAM" },
5139 		{ F_ARPDASRAM, "ARP DA SRAM" },
5140 		{ F_ARPSASRAM, "ARP SA SRAM" },
5141 		{ F_ARPGRESRAM, "ARP GRE SRAM" },
5142 		{ F_ARPIPSECSRAM1, "ARP IPSec SRAM0" },
5143 		{ F_ARPIPSECSRAM0, "ARP IPSec SRAM1" },
5144 		{ 0 }
5145 	};
5146 	static const struct intr_info tp_cerr_cause = {
5147 		.name = "TP_CERR_CAUSE",
5148 		.cause_reg = A_TP_CERR_CAUSE,
5149 		.enable_reg = A_TP_CERR_ENABLE,
5150 		.fatal = 0xffffffff,
5151 		.flags = IHF_FATAL_IFF_ENABLED,
5152 		.details = tp_cerr_cause_details,
5153 		.actions = NULL,
5154 	};
5155 	static const struct intr_details tp_c_perr_details[] = {
5156 		{ F_DMXFIFOOVFL, "Demux FIFO Overflow" },
5157 		{ F_URX2TPCDDPINTF, "ULPRX to TPC DDP Interface and FIFO" },
5158 		{ F_TPCDISPTOKENFIFO, "TPC Dispatch Token FIFO" },
5159 		{ F_TPCDISPCPLFIFO3, "TPC Dispatch CPL FIFO Ch3" },
5160 		{ F_TPCDISPCPLFIFO2, "TPC Dispatch CPL FIFO Ch2" },
5161 		{ F_TPCDISPCPLFIFO1, "TPC Dispatch CPL FIFO Ch1" },
5162 		{ F_TPCDISPCPLFIFO0, "TPC Dispatch CPL FIFO Ch0" },
5163 		{ F_URXPLDINTFCRC3, "ULPRX to TPC Payload Interface CRC Error Ch3" },
5164 		{ F_URXPLDINTFCRC2, "ULPRX to TPC Payload Interface CRC Error Ch2" },
5165 		{ F_URXPLDINTFCRC1, "ULPRX to TPC Payload Interface CRC Error Ch1" },
5166 		{ F_URXPLDINTFCRC0, "ULPRX to TPC Payload Interface CRC Error Ch0" },
5167 		{ F_DMXDBFIFO, "Demux DB FIFO" },
5168 		{ F_DMXDBSRAM, "Demux DB SRAM" },
5169 		{ F_DMXCPLFIFO, "Demux CPL FIFO" },
5170 		{ F_DMXCPLSRAM, "Demux CPL SRAM" },
5171 		{ F_DMXCSUMFIFO, "Demux Checksum FIFO" },
5172 		{ F_DMXLENFIFO, "Demux Length FIFO" },
5173 		{ F_DMXCHECKFIFO, "Demux Check CRC16 FIFO" },
5174 		{ F_DMXWINFIFO, "Demux Winner FIFO" },
5175 		{ F_EGTOKENFIFO, "Egress Token FIFO Parity Error" },
5176 		{ F_EGDATAFIFO, "Egress FIFO Parity Error" },
5177 		{ F_UTX2TPCINTF3, "ULPTX to TPC Interface Parity Error Ch3" },
5178 		{ F_UTX2TPCINTF2, "ULPTX to TPC Interface Parity Error Ch2" },
5179 		{ F_UTX2TPCINTF1, "ULPTX to TPC Interface Parity Error Ch1" },
5180 		{ F_UTX2TPCINTF0, "ULPTX to TPC Interface Parity Error Ch0" },
5181 		{ F_LBKTOKENFIFO, "Loopback Token FIFO Parity Error" },
5182 		{ F_LBKDATAFIFO, "Loopback FIFO Parity Error" },
5183 		{ 0 }
5184 	};
5185 	static const struct intr_info tp_c_perr_cause = {
5186 		.name = "TP_C_PERR_CAUSE",
5187 		.cause_reg = A_TP_C_PERR_CAUSE,
5188 		.enable_reg = A_TP_C_PERR_ENABLE,
5189 		.fatal = 0xffffffff,
5190 		.flags = IHF_FATAL_IFF_ENABLED,
5191 		.details = tp_c_perr_details,
5192 		.actions = NULL,
5193 	};
5194 	static const struct intr_details tp_e_eg_perr_details[] = {
5195 		{ F_MPSLPBKTOKENFIFO, "MPS Loopback Token FIFO parity error" },
5196 		{ F_MPSMACTOKENFIFO, "MPS MAC Token FIFO parity error" },
5197 		{ F_DISPIPSECFIFO3, "Ch3 Dispatch IPSec FIFO parity error" },
5198 		{ F_DISPTCPFIFO3, "Ch3 Dispatch TCP FIFO parity error" },
5199 		{ F_DISPIPFIFO3, "Ch3 Dispatch IP FIFO parity error" },
5200 		{ F_DISPETHFIFO3, "Ch3 Dispatch ETH FIFO parity error" },
5201 		{ F_DISPGREFIFO3, "Ch3 Dispatch GRE FIFO parity error" },
5202 		{ F_DISPCPL5FIFO3, "Ch3 Dispatch CPL5 FIFO parity error" },
5203 		{ F_DISPIPSECFIFO2, "Ch2 Dispatch IPSec FIFO parity error" },
5204 		{ F_DISPTCPFIFO2, "Ch2 Dispatch TCP FIFO parity error" },
5205 		{ F_DISPIPFIFO2, "Ch2 Dispatch IP FIFO parity error" },
5206 		{ F_DISPETHFIFO2, "Ch2 Dispatch ETH FIFO parity error" },
5207 		{ F_DISPGREFIFO2, "Ch2 Dispatch GRE FIFO parity error" },
5208 		{ F_DISPCPL5FIFO2, "Ch2 Dispatch CPL5 FIFO parity error" },
5209 		{ F_DISPIPSECFIFO1, "Ch1 Dispatch IPSec FIFO parity error" },
5210 		{ F_DISPTCPFIFO1, "Ch1 Dispatch TCP FIFO parity error" },
5211 		{ F_DISPIPFIFO1, "Ch1 Dispatch IP FIFO parity error" },
5212 		{ F_DISPETHFIFO1, "Ch1 Dispatch ETH FIFO parity error" },
5213 		{ F_DISPGREFIFO1, "Ch1 Dispatch GRE FIFO parity error" },
5214 		{ F_DISPCPL5FIFO1, "Ch1 Dispatch CPL5 FIFO parity error" },
5215 		{ F_DISPIPSECFIFO0, "Ch0 Dispatch IPSec FIFO parity error" },
5216 		{ F_DISPTCPFIFO0, "Ch0 Dispatch TCP FIFO parity error" },
5217 		{ F_DISPIPFIFO0, "Ch0 Dispatch IP FIFO parity error" },
5218 		{ F_DISPETHFIFO0, "Ch0 Dispatch ETH FIFO parity error" },
5219 		{ F_DISPGREFIFO0, "Ch0 Dispatch GRE FIFO parity error" },
5220 		{ F_DISPCPL5FIFO0, "Ch0 Dispatch CPL5 FIFO parity error" },
5221 		{ 0 }
5222 	};
5223 	static const struct intr_info tp_e_eg_perr_cause = {
5224 		.name = "TP_E_EG_PERR_CAUSE",
5225 		.cause_reg = A_TP_E_EG_PERR_CAUSE,
5226 		.enable_reg = A_TP_E_EG_PERR_ENABLE,
5227 		.fatal = 0xffffffff,
5228 		.flags = IHF_FATAL_IFF_ENABLED,
5229 		.details = tp_e_eg_perr_details,
5230 		.actions = NULL,
5231 	};
5232 	static const struct intr_details tp_e_in0_perr_details[] = {
5233 		{ F_DMXISSFIFO, "Demux ISS FIFO parity error" },
5234 		{ F_DMXERRFIFO, "Demux Error FIFO parity error" },
5235 		{ F_DMXATTFIFO, "Demux Attributes FIFO parity error" },
5236 		{ F_DMXTCPFIFO, "Demux TCP Fields FIFO parity error" },
5237 		{ F_DMXMPAFIFO, "Demux MPA FIFO parity error" },
5238 		{ F_DMXOPTFIFO, "Demux TCP Options FIFO parity error" },
5239 		{ F_INGTOKENFIFO, "Demux Ingress Token FIFO parity error" },
5240 		{ F_DMXPLDCHKOVFL1, "Ch1 PLD TxCheck FIFO Overflow" },
5241 		{ F_DMXPLDCHKFIFO1, "Ch1 PLD TxCheck FIFO parity error" },
5242 		{ F_DMXOPTFIFO1, "Ch1 Options buffer parity error" },
5243 		{ F_DMXMPAFIFO1, "Ch1 MPA FIFO parity error" },
5244 		{ F_DMXDBFIFO1, "Ch1 DB FIFO parity error" },
5245 		{ F_DMXATTFIFO1, "Ch1 Attribute FIFO parity error" },
5246 		{ F_DMXISSFIFO1, "Ch1 ISS FIFO parity error" },
5247 		{ F_DMXTCPFIFO1, "Ch1 TCP Fields FIFO parity error" },
5248 		{ F_DMXERRFIFO1, "Ch1 Error FIFO parity error" },
5249 		{ F_MPS2TPINTF1, "Ch1 MPS2TP Interface parity error" },
5250 		{ F_DMXPLDCHKOVFL0, "Ch0 PLD TxCheck FIFO Overflow" },
5251 		{ F_DMXPLDCHKFIFO0, "Ch0 PLD TxCheck FIFO parity error" },
5252 		{ F_DMXOPTFIFO0, "Ch0 Options buffer parity error" },
5253 		{ F_DMXMPAFIFO0, "Ch0 MPA FIFO parity error" },
5254 		{ F_DMXDBFIFO0, "Ch0 DB FIFO parity error" },
5255 		{ F_DMXATTFIFO0, "Ch0 Attribute FIFO parity error" },
5256 		{ F_DMXISSFIFO0, "Ch0 ISS FIFO parity error" },
5257 		{ F_DMXTCPFIFO0, "Ch0 TCP Fields FIFO parity error" },
5258 		{ F_DMXERRFIFO0, "Ch0 Error FIFO parity error" },
5259 		{ F_MPS2TPINTF0, "Ch0 MPS2TP Interface parity error" },
5260 		{ 0 }
5261 	};
5262 	static const struct intr_info tp_e_in0_perr_cause = {
5263 		.name = "TP_E_IN0_PERR_CAUSE",
5264 		.cause_reg = A_TP_E_IN0_PERR_CAUSE,
5265 		.enable_reg = A_TP_E_IN0_PERR_ENABLE,
5266 		.fatal = 0xffffffff,
5267 		.flags = IHF_FATAL_IFF_ENABLED,
5268 		.details = tp_e_in0_perr_details,
5269 		.actions = NULL,
5270 	};
5271 	static const struct intr_details tp_e_in1_perr_details[] = {
5272 		{ F_DMXPLDCHKOVFL3, "Ch3 PLD TxCheck FIFO Overflow" },
5273 		{ F_DMXPLDCHKFIFO3, "Ch3 PLD TxCheck FIFO parity error" },
5274 		{ F_DMXOPTFIFO3, "Ch3 Options buffer parity error" },
5275 		{ F_DMXMPAFIFO3, "Ch3 MPA FIFO parity error" },
5276 		{ F_DMXDBFIFO3, "Ch3 DB FIFO parity error" },
5277 		{ F_DMXATTFIFO3, "Ch3 Attribute FIFO parity error" },
5278 		{ F_DMXISSFIFO3, "Ch3 ISS FIFO parity error" },
5279 		{ F_DMXTCPFIFO3, "Ch3 TCP Fields FIFO parity error" },
5280 		{ F_DMXERRFIFO3, "Ch3 Error FIFO parity error" },
5281 		{ F_MPS2TPINTF3, "Ch3 MPS2TP Interface parity error" },
5282 		{ F_DMXPLDCHKOVFL2, "Ch2 PLD TxCheck FIFO Overflow" },
5283 		{ F_DMXPLDCHKFIFO2, "Ch2 PLD TxCheck FIFO parity error" },
5284 		{ F_DMXOPTFIFO2, "Ch2 Options buffer parity error" },
5285 		{ F_DMXMPAFIFO2, "Ch2 MPA FIFO parity error" },
5286 		{ F_DMXDBFIFO2, "Ch2 DB FIFO parity error" },
5287 		{ F_DMXATTFIFO2, "Ch2 Attribute FIFO parity error" },
5288 		{ F_DMXISSFIFO2, "Ch2 ISS FIFO parity error" },
5289 		{ F_DMXTCPFIFO2, "Ch2 TCP Fields FIFO parity error" },
5290 		{ F_DMXERRFIFO2, "Ch2 Error FIFO parity error" },
5291 		{ F_MPS2TPINTF2, "Ch2 MPS2TP Interface parity error" },
5292 		{ 0 }
5293 	};
5294 	static const struct intr_info tp_e_in1_perr_cause = {
5295 		.name = "TP_E_IN1_PERR_CAUSE",
5296 		.cause_reg = A_TP_E_IN1_PERR_CAUSE,
5297 		.enable_reg = A_TP_E_IN1_PERR_ENABLE,
5298 		.fatal = 0xffffffff,
5299 		.flags = IHF_FATAL_IFF_ENABLED,
5300 		.details = tp_e_in1_perr_details,
5301 		.actions = NULL,
5302 	};
5303 	static const struct intr_details tp_other_perr_details[] = {
5304 		{ F_DMARBTPERR, "DMARBT MA Rsp Interface parity Error" },
5305 		{ F_MMGRCACHEDATASRAM, "TP MMGR Cache Data SRAM" },
5306 		{ F_MMGRCACHETAGFIFO, "TP MMGR Cache Tag FIFO" },
5307 		{ F_DBL2TLUTPERR, "TP DB Lookup Table" },
5308 		{ F_DBTXTIDPERR, "TP DB FIFOs" },
5309 		{ F_DBEXTPERR, "TP DB Extended Opcode FIFO" },
5310 		{ F_DBOPPERR, "TP DB Opcode FIFO" },
5311 		{ F_TMCACHEPERR, "TP TM Cache SRAM" },
5312 		{ F_TPPROTOSRAM, "TP Protocol SRAM" },
5313 		{ F_HSPSRAM, "HighSpeed SRAM" },
5314 		{ F_RATEGRPSRAM, "Rate Group SRAM" },
5315 		{ F_TXFBSEQFIFO, "Tx Feedback Sequence Number FIFO" },
5316 		{ F_CMDATASRAM, "Cache Data SRAM" },
5317 		{ F_CMTAGFIFO, "Cache Tag FIFO" },
5318 		{ F_RFCOPFIFO, "RCF Opcode FIFO" },
5319 		{ F_DELINVFIFO, "Delete Invalid FIFO" },
5320 		{ F_RSSCFGSRAM, "RSS Config or Round-Robin SRAM" },
5321 		{ F_RSSKEYSRAM, "RSS Key SRAM" },
5322 		{ F_RSSLKPSRAM, "RSS Lookup SRAM" },
5323 		{ F_SRQSRAM, "SRQ SRAM" },
5324 		{ F_ARPDASRAM, "ARP DA SRAM" },
5325 		{ F_ARPSASRAM, "ARP SA SRAM" },
5326 		{ F_ARPGRESRAM, "ARP GRE SRAM" },
5327 		{ F_ARPIPSECSRAM1, "ARP IPSec SRAM0" },
5328 		{ F_ARPIPSECSRAM0, "ARP IPSec SRAM1" },
5329 		{ 0 }
5330 	};
5331 	static const struct intr_info tp_o_perr_cause = {
5332 		.name = "TP_O_PERR_CAUSE",
5333 		.cause_reg = A_TP_O_PERR_CAUSE,
5334 		.enable_reg = A_TP_O_PERR_ENABLE,
5335 		.fatal = 0xffffffff,
5336 		.flags = IHF_FATAL_IFF_ENABLED,
5337 		.details = tp_other_perr_details,
5338 		.actions = NULL,
5339 	};
5340 	bool fatal;
5341 
5342 	if (chip_id(adap) > CHELSIO_T6) {
5343 		tp_intr_info.details = t7_tp_intr_details;
5344 		fatal = t4_handle_intr(adap, &tp_intr_info, 0, flags);
5345 		fatal |= t4_handle_intr(adap, &tp_cerr_cause, 0, flags);
5346 		fatal |= t4_handle_intr(adap, &tp_c_perr_cause, 0, flags);
5347 		fatal |= t4_handle_intr(adap, &tp_e_eg_perr_cause, 0, flags);
5348 		fatal |= t4_handle_intr(adap, &tp_e_in0_perr_cause, 0, flags);
5349 		fatal |= t4_handle_intr(adap, &tp_e_in1_perr_cause, 0, flags);
5350 		fatal |= t4_handle_intr(adap, &tp_o_perr_cause, 0, flags);
5351 	} else {
5352 		tp_intr_info.details = tp_intr_details;
5353 		fatal = t4_handle_intr(adap, &tp_intr_info, 0, flags);
5354 	}
5355 	clear_int_cause_reg(adap, &tp_intr_info, flags);
5356 
5357 	return (fatal);
5358 }
5359 
5360 /*
5361  * SGE interrupt handler.
5362  */
sge_intr_handler(struct adapter * adap,int arg,int flags)5363 static bool sge_intr_handler(struct adapter *adap, int arg, int flags)
5364 {
5365 	static const struct intr_details sge_int1_details[] = {
5366 		{ F_PERR_FLM_CREDITFIFO, "SGE FLM credit FIFO parity error" },
5367 		{ F_PERR_IMSG_HINT_FIFO, "SGE IMSG hint FIFO parity error" },
5368 		{ F_PERR_HEADERSPLIT_FIFO3 | F_PERR_HEADERSPLIT_FIFO2,
5369 			"SGE header split FIFO parity error" },
5370 		{ F_PERR_PAYLOAD_FIFO3 | F_PERR_PAYLOAD_FIFO2,
5371 			"SGE payload FIFO parity error" },
5372 		{ F_PERR_PC_RSP, "SGE PC response parity error" },
5373 		{ F_PERR_PC_REQ, "SGE PC request parity error" },
5374 		{ 0x003c0000, "SGE DBP PC response FIFO parity error" },
5375 		{ F_PERR_DMARBT, "SGE DMA RBT parity error" },
5376 		{ F_PERR_FLM_DBPFIFO, "SGE FLM DBP FIFO parity error" },
5377 		{ F_PERR_FLM_MCREQ_FIFO, "SGE FLM MC request FIFO parity error" },
5378 		{ F_PERR_FLM_HINTFIFO, "SGE FLM hint FIFO parity error" },
5379 		{ 0x00003c00, "SGE align control FIFO parity error" },
5380 		{ 0x000003c0, "SGE EDMA FIFO parity error" },
5381 		{ 0x0000003c, "SGE PD FIFO parity error" },
5382 		{ F_PERR_ING_CTXT_MIFRSP, "SGE Ingress context MIF response parity error" },
5383 		{ F_PERR_EGR_CTXT_MIFRSP, "SGE Egress context MIF response parity error" },
5384 		{ 0 }
5385 	};
5386 	static const struct intr_info sge_int1_info = {
5387 		.name = "SGE_INT_CAUSE1",
5388 		.cause_reg = A_SGE_INT_CAUSE1,
5389 		.enable_reg = A_SGE_INT_ENABLE1,
5390 		.fatal = 0xffffffff,
5391 		.flags = IHF_FATAL_IFF_ENABLED,
5392 		.details = sge_int1_details,
5393 		.actions = NULL,
5394 	};
5395 	static const struct intr_details t7_sge_int2_details[] = {
5396 		{ F_TF_FIFO_PERR, "SGE TF FIFO parity error" },
5397 		{ F_PERR_EGR_DBP_TX_COAL, "SGE egress DBP TX coal parity error" },
5398 		{ F_PERR_DBP_FL_FIFO, "SGE DBP FL FIFO parity error" },
5399 		{ F_DEQ_LL_PERR, "SGE linked list SRAM parity error" },
5400 		{ F_ENQ_PERR, "SGE enq tag SRAM parity error" },
5401 		{ F_DEQ_OUT_PERR, "SGE tbuf deq output FIFO parity error" },
5402 		{ F_BUF_PERR, "SGE tbuf main buffer parity error" },
5403 		{ F_PERR_CONM_SRAM, "SGE CONM SRAM parity error" },
5404 		{ F_PERR_ISW_IDMA3_FIFO | F_PERR_ISW_IDMA2_FIFO |
5405 		  F_PERR_ISW_IDMA1_FIFO | F_PERR_ISW_IDMA0_FIFO,
5406 		  "SGE ISW IDMA FIFO parity error" },
5407 		{ F_PERR_ISW_DBP_FIFO, "SGE ISW DBP FIFO parity error" },
5408 		{ F_PERR_ISW_GTS_FIFO, "SGE ISW GTS FIFO parity error" },
5409 		{ F_PERR_ITP_EVR, "SGE ITP EVR parity error" },
5410 		{ F_PERR_FLM_CNTXMEM, "SGE FLM context memory parity error" },
5411 		{ F_PERR_FLM_L1CACHE, "SGE FLM L1 cache parity error" },
5412 		{ F_SGE_IPP_FIFO_PERR, "SGE IPP FIFO parity error" },
5413 		{ F_PERR_DBP_HP_FIFO, "SGE DBP HP FIFO parity error" },
5414 		{ F_PERR_DB_FIFO, "SGE doorbell FIFO parity error" },
5415 		{ F_PERR_ING_CTXT_CACHE | F_PERR_EGR_CTXT_CACHE,
5416 		  "SGE context cache parity error" },
5417 		{ F_PERR_BASE_SIZE, "SGE base size parity error" },
5418 		{ 0 }
5419 	};
5420 	static const struct intr_details t6_sge_int2_details[] = {
5421 		{ F_PERR_DBP_HINT_FL_FIFO, "SGE DBP hint FL FIFO parity error" },
5422 		{ F_PERR_EGR_DBP_TX_COAL, "SGE egress DBP TX coal parity error" },
5423 		{ F_PERR_DBP_FL_FIFO, "SGE DBP FL FIFO parity error" },
5424 		{ F_DEQ_LL_PERR, "SGE tbuf dequeue linked list SRAM parity error" },
5425 		{ F_ENQ_PERR, "SGE tbuf enqueue tag SRAM parity error" },
5426 		{ F_DEQ_OUT_PERR, "SGE tbuf dequeue output FIFO parity error" },
5427 		{ F_BUF_PERR, "SGE tbuf main buffer parity error" },
5428 		{ F_PERR_CONM_SRAM, "SGE CONM SRAM parity error" },
5429 		{ F_PERR_ISW_IDMA1_FIFO, "SGE ISW IDMA FIFO parity error" },
5430 		{ F_PERR_ISW_IDMA0_FIFO, "SGE ISW IDMA FIFO parity error" },
5431 		{ F_PERR_ISW_DBP_FIFO, "SGE ISW DBP FIFO parity error" },
5432 		{ F_PERR_ISW_GTS_FIFO, "SGE ISW GTS FIFO parity error" },
5433 		{ F_PERR_ITP_EVR, "SGE ITP EVR parity error" },
5434 		{ F_PERR_FLM_CNTXMEM, "SGE FLM context memory parity error" },
5435 		{ F_PERR_FLM_L1CACHE, "SGE FLM L1 cache parity error" },
5436 		{ F_PERR_DBP_HINT_FIFO, "SGE DBP hint FIFO parity error" },
5437 		{ F_PERR_DBP_HP_FIFO, "SGE DBP high priority FIFO parity error" },
5438 		{ F_PERR_DB_FIFO, "SGE DBP merge DB FIFO parity error" },
5439 		{ F_PERR_ING_CTXT_CACHE, "SGE ingress context cache parity error" },
5440 		{ F_PERR_EGR_CTXT_CACHE, "SGE egress context cache parity error" },
5441 		{ F_PERR_BASE_SIZE, "SGE base size parity error" },
5442 		{ 0 }
5443 	};
5444 	struct intr_info sge_int2_info = {
5445 		.name = "SGE_INT_CAUSE2",
5446 		.cause_reg = A_SGE_INT_CAUSE2,
5447 		.enable_reg = A_SGE_INT_ENABLE2,
5448 		.fatal = 0xffffffff,
5449 		.flags = IHF_FATAL_IFF_ENABLED,
5450 		.details = NULL,
5451 		.actions = NULL,
5452 	};
5453 	static const struct intr_details sge_int3_details[] = {
5454 		{ F_ERR_FLM_DBP,
5455 			"DBP pointer delivery for invalid context or QID" },
5456 		{ F_ERR_FLM_IDMA1 | F_ERR_FLM_IDMA0,
5457 			"Invalid QID or header request by IDMA" },
5458 		{ F_ERR_FLM_HINT, "FLM hint is for invalid context or QID" },
5459 		{ F_ERR_PCIE_ERROR3, "SGE PCIe error for DBP thread 3" },
5460 		{ F_ERR_PCIE_ERROR2, "SGE PCIe error for DBP thread 2" },
5461 		{ F_ERR_PCIE_ERROR1, "SGE PCIe error for DBP thread 1" },
5462 		{ F_ERR_PCIE_ERROR0, "SGE PCIe error for DBP thread 0" },
5463 		{ F_ERR_TIMER_ABOVE_MAX_QID,
5464 			"SGE GTS with timer 0-5 for IQID > 1023" },
5465 		{ F_ERR_CPL_EXCEED_IQE_SIZE,
5466 			"SGE received CPL exceeding IQE size" },
5467 		{ F_ERR_INVALID_CIDX_INC, "SGE GTS CIDX increment too large" },
5468 		{ F_ERR_ITP_TIME_PAUSED, "SGE ITP error" },
5469 		{ F_ERR_CPL_OPCODE_0, "SGE received 0-length CPL" },
5470 		{ F_ERR_DROPPED_DB, "SGE DB dropped" },
5471 		{ F_ERR_DATA_CPL_ON_HIGH_QID1 | F_ERR_DATA_CPL_ON_HIGH_QID0,
5472 		  "SGE IQID > 1023 received CPL for FL" },
5473 		{ F_ERR_BAD_DB_PIDX3 | F_ERR_BAD_DB_PIDX2 | F_ERR_BAD_DB_PIDX1 |
5474 			F_ERR_BAD_DB_PIDX0, "SGE DBP pidx increment too large" },
5475 		{ F_ERR_ING_PCIE_CHAN, "SGE Ingress PCIe channel mismatch" },
5476 		{ F_ERR_ING_CTXT_PRIO,
5477 			"Ingress context manager priority user error" },
5478 		{ F_ERR_EGR_CTXT_PRIO,
5479 			"Egress context manager priority user error" },
5480 		{ F_DBFIFO_HP_INT, "High priority DB FIFO threshold reached" },
5481 		{ F_DBFIFO_LP_INT, "Low priority DB FIFO threshold reached" },
5482 		{ F_REG_ADDRESS_ERR, "Undefined SGE register accessed" },
5483 		{ F_INGRESS_SIZE_ERR, "SGE illegal ingress QID" },
5484 		{ F_EGRESS_SIZE_ERR, "SGE illegal egress QID" },
5485 		{ 0x0000000f, "SGE context access for invalid queue" },
5486 		{ 0 }
5487 	};
5488 	static const struct intr_details t6_sge_int3_details[] = {
5489 		{ F_ERR_FLM_DBP,
5490 			"DBP pointer delivery for invalid context or QID" },
5491 		{ F_ERR_FLM_IDMA1 | F_ERR_FLM_IDMA0,
5492 			"Invalid QID or header request by IDMA" },
5493 		{ F_ERR_FLM_HINT, "FLM hint is for invalid context or QID" },
5494 		{ F_ERR_PCIE_ERROR3, "SGE PCIe error for DBP thread 3" },
5495 		{ F_ERR_PCIE_ERROR2, "SGE PCIe error for DBP thread 2" },
5496 		{ F_ERR_PCIE_ERROR1, "SGE PCIe error for DBP thread 1" },
5497 		{ F_ERR_PCIE_ERROR0, "SGE PCIe error for DBP thread 0" },
5498 		{ F_ERR_TIMER_ABOVE_MAX_QID,
5499 			"SGE GTS with timer 0-5 for IQID > 1023" },
5500 		{ F_ERR_CPL_EXCEED_IQE_SIZE,
5501 			"SGE received CPL exceeding IQE size" },
5502 		{ F_ERR_INVALID_CIDX_INC, "SGE GTS CIDX increment too large" },
5503 		{ F_ERR_ITP_TIME_PAUSED, "SGE ITP error" },
5504 		{ F_ERR_CPL_OPCODE_0, "SGE received 0-length CPL" },
5505 		{ F_ERR_DROPPED_DB, "SGE DB dropped" },
5506 		{ F_ERR_DATA_CPL_ON_HIGH_QID1 | F_ERR_DATA_CPL_ON_HIGH_QID0,
5507 			"SGE IQID > 1023 received CPL for FL" },
5508 		{ F_ERR_BAD_DB_PIDX3 | F_ERR_BAD_DB_PIDX2 | F_ERR_BAD_DB_PIDX1 |
5509 			F_ERR_BAD_DB_PIDX0, "SGE DBP pidx increment too large" },
5510 		{ F_ERR_ING_PCIE_CHAN, "SGE Ingress PCIe channel mismatch" },
5511 		{ F_ERR_ING_CTXT_PRIO,
5512 			"Ingress context manager priority user error" },
5513 		{ F_ERR_EGR_CTXT_PRIO,
5514 			"Egress context manager priority user error" },
5515 		{ F_DBP_TBUF_FULL, "SGE DBP tbuf full" },
5516 		{ F_FATAL_WRE_LEN,
5517 			"SGE WRE packet less than advertized length" },
5518 		{ F_REG_ADDRESS_ERR, "Undefined SGE register accessed" },
5519 		{ F_INGRESS_SIZE_ERR, "SGE illegal ingress QID" },
5520 		{ F_EGRESS_SIZE_ERR, "SGE illegal egress QID" },
5521 		{ 0x0000000f, "SGE context access for invalid queue" },
5522 		{ 0 }
5523 	};
5524 	struct intr_info sge_int3_info = {
5525 		.name = "SGE_INT_CAUSE3",
5526 		.cause_reg = A_SGE_INT_CAUSE3,
5527 		.enable_reg = A_SGE_INT_ENABLE3,
5528 		.fatal = F_ERR_CPL_EXCEED_IQE_SIZE,
5529 		.flags = 0,
5530 		.details = NULL,
5531 		.actions = NULL,
5532 	};
5533 	static const struct intr_details sge_int4_details[] = {
5534 		{ F_ERR_ISHIFT_UR1 | F_ERR_ISHIFT_UR0, "SGE ishift underrun" },
5535 		{ F_BAR2_EGRESS_LEN_OR_ADDR_ERR, "SGE BAR2 PL access length or alignment error" },
5536 		{ F_ERR_CPL_EXCEED_MAX_IQE_SIZE1 | F_ERR_CPL_EXCEED_MAX_IQE_SIZE0,
5537 		  "SGE CPL exceeds max IQE size" },
5538 		{ F_ERR_WR_LEN_TOO_LARGE3 | F_ERR_WR_LEN_TOO_LARGE2 |
5539 		  F_ERR_WR_LEN_TOO_LARGE1 | F_ERR_WR_LEN_TOO_LARGE0,
5540 		  "SGE WR length too large" },
5541 		{ F_ERR_LARGE_MINFETCH_WITH_TXCOAL3 | F_ERR_LARGE_MINFETCH_WITH_TXCOAL2 |
5542 		  F_ERR_LARGE_MINFETCH_WITH_TXCOAL1 | F_ERR_LARGE_MINFETCH_WITH_TXCOAL0,
5543 		  "SGE invalid MinFetchBurst with TxCoalesce" },
5544 		{ F_COAL_WITH_HP_DISABLE_ERR, "SGE coalesce with HP disable error" },
5545 		{ F_BAR2_EGRESS_COAL0_ERR, "SGE BAR2 PL access addr offset 0" },
5546 		{ F_BAR2_EGRESS_SIZE_ERR, "SGE BAR2 illegal egress QID access" },
5547 		{ F_FLM_PC_RSP_ERR, "SGE FLM PC response error" },
5548 		{ F_ERR_TH3_MAX_FETCH | F_ERR_TH2_MAX_FETCH |
5549 		  F_ERR_TH1_MAX_FETCH | F_ERR_TH0_MAX_FETCH,
5550 		  "SGE max fetch violation" },
5551 		{ F_ERR_RX_CPL_PACKET_SIZE1 | F_ERR_RX_CPL_PACKET_SIZE0,
5552 		  "SGE CPL length mismatch error" },
5553 		{ F_ERR_BAD_UPFL_INC_CREDIT3 | F_ERR_BAD_UPFL_INC_CREDIT2 |
5554 		  F_ERR_BAD_UPFL_INC_CREDIT1 | F_ERR_BAD_UPFL_INC_CREDIT0,
5555 		  "SGE upfl credit wrap error" },
5556 		{ F_ERR_PHYSADDR_LEN0_IDMA1 | F_ERR_PHYSADDR_LEN0_IDMA0,
5557 		  "SGE CPL_RX_PHYS_ADDR length 0 error" },
5558 		{ F_ERR_FLM_INVALID_PKT_DROP1 | F_ERR_FLM_INVALID_PKT_DROP0,
5559 		  "SGE IDMA packet drop due to invalid FLM context" },
5560 		{ F_ERR_UNEXPECTED_TIMER, "SGE unexpected timer error" },
5561 		{ 0 }
5562 	};
5563 	static const struct intr_info sge_int4_info = {
5564 		.name = "SGE_INT_CAUSE4",
5565 		.cause_reg = A_SGE_INT_CAUSE4,
5566 		.enable_reg = A_SGE_INT_ENABLE4,
5567 		.fatal = 0,
5568 		.flags = 0,
5569 		.details = sge_int4_details,
5570 		.actions = NULL,
5571 	};
5572 	static const struct intr_details t7_sge_int5_details[] = {
5573 		{ F_ERR_T_RXCRC, "SGE RxCRC error" },
5574 		{ F_PERR_MC_RSPDATA, "SGE MC response data parity error" },
5575 		{ F_PERR_PC_RSPDATA, "SGE PC response data parity error" },
5576 		{ F_PERR_PD_RDRSPDATA, "SGE PD read response data parity error" },
5577 		{ F_PERR_U_RXDATA, "SGE U Rx data parity error" },
5578 		{ F_PERR_UD_RXDATA, "SGE UD Rx data parity error" },
5579 		{ F_PERR_UP_DATA, "SGE uP data parity error" },
5580 		{ F_PERR_CIM2SGE_RXDATA, "SGE CIM2SGE Rx data parity error" },
5581 		{ F_PERR_IMSG_PD_FIFO, "SGE IMSG PD FIFO parity error" },
5582 		{ F_PERR_ULPTX_FIFO1 | F_PERR_ULPTX_FIFO0, "SGE ULPTX FIFO parity error" },
5583 		{ F_PERR_IDMA2IMSG_FIFO3 | F_PERR_IDMA2IMSG_FIFO2 |
5584 		  F_PERR_IDMA2IMSG_FIFO1 | F_PERR_IDMA2IMSG_FIFO0,
5585 		  "SGE IDMA2IMSG FIFO parity error" },
5586 		{ F_PERR_POINTER_DATA_FIFO3 | F_PERR_POINTER_DATA_FIFO2 |
5587 		  F_PERR_POINTER_DATA_FIFO1 | F_PERR_POINTER_DATA_FIFO0,
5588 		  "SGE pointer data FIFO parity error" },
5589 		{ F_PERR_POINTER_HDR_FIFO3 | F_PERR_POINTER_HDR_FIFO2 |
5590 		  F_PERR_POINTER_HDR_FIFO1 | F_PERR_POINTER_HDR_FIFO0,
5591 		  "SGE pointer header FIFO parity error" },
5592 		{ F_PERR_PAYLOAD_FIFO1 | F_PERR_PAYLOAD_FIFO0,
5593 		  "SGE payload FIFO parity error" },
5594 		{ F_PERR_MGT_BAR2_FIFO, "SGE MGT BAR2 FIFO parity error" },
5595 		{ F_PERR_HEADERSPLIT_FIFO1 | F_PERR_HEADERSPLIT_FIFO0,
5596 		  "SGE header split FIFO parity error" },
5597 		{ F_PERR_HINT_DELAY_FIFO, "SGE hint delay FIFO parity error" },
5598 		{ 0 }
5599 	};
5600 	static const struct intr_details t6_sge_int5_details[] = {
5601 		{ F_ERR_T_RXCRC, "SGE T RxCRC parity error" },
5602 		{ F_PERR_MC_RSPDATA, "SGE MC response data parity error" },
5603 		{ F_PERR_PC_RSPDATA, "SGE PC response data parity error" },
5604 		{ F_PERR_U_RXDATA | F_PERR_UD_RXDATA, "SGE ULP Rx data parity error" },
5605 		{ F_PERR_UP_DATA, "SGE uP data parity error" },
5606 		{ F_PERR_CIM2SGE_RXDATA, "SGE CIM2SGE Rx data parity error" },
5607 		{ F_PERR_HINT_DELAY_FIFO1 | F_PERR_HINT_DELAY_FIFO0,
5608 		  "SGE hint delay FIFO parity error" },
5609 		{ F_PERR_IMSG_PD_FIFO, "SGE IMSG PD FIFO parity error" },
5610 		{ F_PERR_ULPTX_FIFO1 | F_PERR_ULPTX_FIFO0,
5611 		  "SGE ULPTX FIFO parity error" },
5612 		{ F_PERR_IDMA2IMSG_FIFO1 | F_PERR_IDMA2IMSG_FIFO0,
5613 		  "SGE IDMA2IMSG FIFO parity error" },
5614 		{ F_PERR_POINTER_DATA_FIFO1 | F_PERR_POINTER_DATA_FIFO0,
5615 		  "SGE pointer data FIFO parity error" },
5616 		{ F_PERR_POINTER_HDR_FIFO1 | F_PERR_POINTER_HDR_FIFO0,
5617 		  "SGE pointer header FIFO parity error" },
5618 		{ F_PERR_PAYLOAD_FIFO1 | F_PERR_PAYLOAD_FIFO0,
5619 		  "SGE payload FIFO parity error" },
5620 		{ F_PERR_EDMA_INPUT_FIFO3 | F_PERR_EDMA_INPUT_FIFO2 |
5621 		  F_PERR_EDMA_INPUT_FIFO1 | F_PERR_EDMA_INPUT_FIFO0,
5622 		  "SGE EDMA input FIFO parity error" },
5623 		{ F_PERR_MGT_BAR2_FIFO, "SGE MGT BAR2 FIFO parity error" },
5624 		{ F_PERR_HEADERSPLIT_FIFO1 | F_PERR_HEADERSPLIT_FIFO0,
5625 		  "SGE header split FIFO parity error" },
5626 		{ F_PERR_CIM_FIFO1 | F_PERR_CIM_FIFO0, "SGE CIM FIFO parity error" },
5627 		{ F_PERR_IDMA_SWITCH_OUTPUT_FIFO1 | F_PERR_IDMA_SWITCH_OUTPUT_FIFO0,
5628 		  "SGE IDMA switch output FIFO parity error" },
5629 		{ 0 }
5630 	};
5631 	struct intr_info sge_int5_info = {
5632 		.name = "SGE_INT_CAUSE5",
5633 		.cause_reg = A_SGE_INT_CAUSE5,
5634 		.enable_reg = A_SGE_INT_ENABLE5,
5635 		.fatal = 0xffffffff,
5636 		.flags = IHF_FATAL_IFF_ENABLED,
5637 		.details = NULL,
5638 		.actions = NULL,
5639 	};
5640 	static const struct intr_details sge_int6_details[] = {
5641 		/* T7+ */
5642 		{ 0xe0000000, "SGE fatal DEQ0 DRDY error" },
5643 		{ 0x1c000000, "SGE fatal OUT0 DRDY error" },
5644 		{ F_IMSG_DBG3_STUCK | F_IMSG_DBG2_STUCK |
5645 		  F_IMSG_DBG1_STUCK | F_IMSG_DBG0_STUCK,
5646 		  "SGE IMSG stuck due to insufficient credits" },
5647 		/* T6 + */
5648 		{ F_ERR_DB_SYNC, "SGE doorbell sync failed" },
5649 		{ F_ERR_GTS_SYNC, "SGE GTS sync failed" },
5650 		{ F_FATAL_LARGE_COAL, "SGE BAR2 payload too large" },
5651 		{ F_PL_BAR2_FRM_ERR, "SGE BAR2 framing error" },
5652 		{ F_SILENT_DROP_TX_COAL, "SGE silent drop of Tx coal WR" },
5653 		{ F_ERR_INV_CTXT4, "SGE context access for invalid queue thread 4" },
5654 		{ F_ERR_BAD_DB_PIDX4, "SGE doorbell pidx too large thread 4" },
5655 		{ F_ERR_BAD_UPFL_INC_CREDIT4, "SGE upfl credit wrap thread 4" },
5656 		{ F_FATAL_TAG_MISMATCH, "SGE doorbell tag mismatch" },
5657 		{ F_FATAL_ENQ_CTL_RDY, "SGE enq_ctl_fifo overflow" },
5658 		{ F_ERR_PC_RSP_LEN3 | F_ERR_PC_RSP_LEN2 |
5659 		  F_ERR_PC_RSP_LEN1 | F_ERR_PC_RSP_LEN0,
5660 		  "SGE PCIe response error for DBP threads" },
5661 		{ F_FATAL_ENQ2LL_VLD, "SGE tbuf fatal_enq2ll_vld" },
5662 		{ F_FATAL_LL_EMPTY, "SGE tbuf fatal_ll_empty" },
5663 		{ F_FATAL_OFF_WDENQ, "SGE tbuf fatal_off_wdenq" },
5664 		{ 0x00000018, "SGE tbuf fatal_deq1_drdy" },
5665 		{ 0x00000006, "SGE tbuf fatal_out1_drdy" },
5666 		{ F_FATAL_DEQ, "SGE tbuf fatal_deq" },
5667 		{ 0 }
5668 	};
5669 	static const struct intr_info sge_int6_info = {
5670 		.name = "SGE_INT_CAUSE6",
5671 		.cause_reg = A_SGE_INT_CAUSE6,
5672 		.enable_reg = A_SGE_INT_ENABLE6,
5673 		.fatal = 0,
5674 		.flags = 0,
5675 		.details = sge_int6_details,
5676 		.actions = NULL,
5677 	};
5678 	static const struct intr_details sge_int7_details[] = {
5679 		{ F_HINT_FIFO_FULL, "SGE hint FIFO full" },
5680 		{ F_CERR_HINT_DELAY_FIFO, "SGE hint delay FIFO ECC error" },
5681 		{ F_COAL_TIMER_FIFO_PERR, "SGE coalescing timer FIFO parity error" },
5682 		{ F_CMP_FIFO_PERR, "SGE CMP FIFO parity error" },
5683 		{ F_SGE_IPP_FIFO_CERR, "SGE IPP FIFO ECC error" },
5684 		{ F_CERR_ING_CTXT_CACHE | F_CERR_EGR_CTXT_CACHE,
5685 		  "SGE context cache ECC error" },
5686 		{ F_IMSG_CNTX_PERR, "SGE IMSG context parity error" },
5687 		{ F_PD_FIFO_PERR, "SGE PD FIFO parity error" },
5688 		{ F_IMSG_512_FIFO_PERR, "SGE IMSG 512 FIFO parity error" },
5689 		{ F_CPLSW_FIFO_PERR, "SGE CPLSW FIFO parity error" },
5690 		{ F_IMSG_FIFO_PERR, "SGE IMSG FIFO parity error" },
5691 		{ F_CERR_ITP_EVR, "SGE ITP EVR ECC error" },
5692 		{ F_CERR_CONM_SRAM, "SGE CONM SRAM ECC error" },
5693 		{ F_CERR_FLM_CNTXMEM, "SGE FLM context memory ECC error" },
5694 		{ F_CERR_FUNC_QBASE, "SGE function queue base ECC error" },
5695 		{ F_IMSG_CNTX_CERR, "SGE IMSG context ECC error" },
5696 		{ F_PD_FIFO_CERR, "SGE PD FIFO ECC error" },
5697 		{ F_IMSG_512_FIFO_CERR, "SGE IMSG 512 FIFO ECC error" },
5698 		{ F_CPLSW_FIFO_CERR, "SGE CPLSW FIFO ECC error" },
5699 		{ F_IMSG_FIFO_CERR, "SGE IMSG FIFO ECC error" },
5700 		{ 0x0000001e, "SGE header split FIFO ECC error" }, // Bits 4:1
5701 		{ F_CERR_FLM_L1CACHE, "SGE FLM L1 cache ECC error" },
5702 		{ 0 }
5703 	};
5704 	static const struct intr_info sge_int7_info = {
5705 		.name = "SGE_INT_CAUSE7",
5706 		.cause_reg = A_SGE_INT_CAUSE7,
5707 		.enable_reg = A_SGE_INT_ENABLE7,
5708 		.fatal = 0,
5709 		.flags = 0,
5710 		.details = sge_int7_details,
5711 		.actions = NULL,
5712 	};
5713 	static const struct intr_details sge_int8_details[] = {
5714 		{ F_TRACE_RXPERR, "SGE trace packet parity error" },
5715 		{ F_U3_RXPERR | F_U2_RXPERR | F_U1_RXPERR | F_U0_RXPERR,
5716 		  "SGE ULP interface parity error" },
5717 		{ F_T3_RXPERR | F_T2_RXPERR | F_T1_RXPERR | F_T0_RXPERR,
5718 		  "SGE TP interface parity error" },
5719 		{ 0 }
5720 	};
5721 	static const struct intr_info sge_int8_info = {
5722 		.name = "SGE_INT_CAUSE8",
5723 		.cause_reg = A_SGE_INT_CAUSE8,
5724 		.enable_reg = A_SGE_INT_ENABLE8,
5725 		.fatal = 0,
5726 		.flags = 0,
5727 		.details = sge_int8_details,
5728 		.actions = NULL,
5729 	};
5730 	bool fatal;
5731 	u32 v;
5732 
5733 	if (chip_id(adap) <= CHELSIO_T5) {
5734 		sge_int3_info.details = sge_int3_details;
5735 	} else if (chip_id(adap) == CHELSIO_T6) {
5736 		sge_int3_info.details = t6_sge_int3_details;
5737 		sge_int2_info.details = t6_sge_int2_details;
5738 		sge_int5_info.details = t6_sge_int5_details;
5739 	} else {
5740 		sge_int3_info.details = t6_sge_int3_details;
5741 		sge_int2_info.details = t7_sge_int2_details;
5742 		sge_int5_info.details = t7_sge_int5_details;
5743 	}
5744 
5745 	fatal = false;
5746 	fatal |= t4_handle_intr(adap, &sge_int1_info, 0, flags);
5747 	fatal |= t4_handle_intr(adap, &sge_int2_info, 0, flags);
5748 	fatal |= t4_handle_intr(adap, &sge_int3_info, 0, flags);
5749 	fatal |= t4_handle_intr(adap, &sge_int4_info, 0, flags);
5750 	if (chip_id(adap) >= CHELSIO_T5)
5751 		fatal |= t4_handle_intr(adap, &sge_int5_info, 0, flags);
5752 	if (chip_id(adap) >= CHELSIO_T6)
5753 		fatal |= t4_handle_intr(adap, &sge_int6_info, 0, flags);
5754 	if (chip_id(adap) >= CHELSIO_T7) {
5755 		fatal |= t4_handle_intr(adap, &sge_int7_info, 0, flags);
5756 		fatal |= t4_handle_intr(adap, &sge_int8_info, 0, flags);
5757 	}
5758 
5759 	v = t4_read_reg(adap, A_SGE_ERROR_STATS);
5760 	if (v & F_ERROR_QID_VALID) {
5761 		CH_ERR(adap, "SGE error for QID %u\n", G_ERROR_QID(v));
5762 		if (v & F_UNCAPTURED_ERROR)
5763 			CH_ERR(adap, "SGE UNCAPTURED_ERROR set (clearing)\n");
5764 		t4_write_reg(adap, A_SGE_ERROR_STATS,
5765 		    F_ERROR_QID_VALID | F_UNCAPTURED_ERROR);
5766 	}
5767 
5768 	return (fatal);
5769 }
5770 
5771 /*
5772  * CIM interrupt handler.
5773  */
cim_intr_handler(struct adapter * adap,int arg,int flags)5774 static bool cim_intr_handler(struct adapter *adap, int arg, int flags)
5775 {
5776 	static const struct intr_details cim_host_t7_intr_details[] = {
5777 		{ F_CORE7ACCINT, "CIM slave core 7 access interrupt "},
5778 		{ F_CORE6ACCINT, "CIM slave core 6 access interrupt "},
5779 		{ F_CORE5ACCINT, "CIM slave core 5 access interrupt "},
5780 		{ F_CORE4ACCINT, "CIM slave core 4 access interrupt "},
5781 		{ F_CORE3ACCINT, "CIM slave core 3 access interrupt "},
5782 		{ F_CORE2ACCINT, "CIM slave core 2 access interrupt "},
5783 		{ F_CORE1ACCINT, "CIM slave core 1 access interrupt "},
5784 		{ F_TIMER1INT, "CIM TIMER0 interrupt" },
5785 		{ F_TIMER0INT, "CIM TIMER0 interrupt" },
5786 		{ F_PREFDROPINT, "CIM control register prefetch drop" },
5787 		{ 0}
5788 	};
5789 	static const struct intr_details cim_host_intr_details[] = {
5790 		/* T6+ */
5791 		{ F_PCIE2CIMINTFPARERR, "CIM IBQ PCIe interface parity error" },
5792 
5793 		/* T5+ */
5794 		{ F_MA_CIM_INTFPERR, "MA2CIM interface parity error" },
5795 		{ F_PLCIM_MSTRSPDATAPARERR,
5796 			"PL2CIM master response data parity error" },
5797 		{ F_NCSI2CIMINTFPARERR, "CIM IBQ NC-SI interface parity error" },
5798 		{ F_SGE2CIMINTFPARERR, "CIM IBQ SGE interface parity error" },
5799 		{ F_ULP2CIMINTFPARERR, "CIM IBQ ULP_TX interface parity error" },
5800 		{ F_TP2CIMINTFPARERR, "CIM IBQ TP interface parity error" },
5801 		{ F_OBQSGERX1PARERR, "CIM OBQ PCIE_RX parity error" },
5802 		{ F_OBQSGERX0PARERR, "CIM OBQ SGE_RX parity error" },
5803 
5804 		/* T4+ */
5805 		{ F_TIEQOUTPARERRINT, "CIM TIEQ outgoing FIFO parity error" },
5806 		{ F_TIEQINPARERRINT, "CIM TIEQ incoming FIFO parity error" },
5807 		{ F_MBHOSTPARERR, "CIM mailbox host read parity error" },
5808 		{ F_MBUPPARERR, "CIM mailbox uP parity error" },
5809 		{ F_IBQTP0PARERR, "CIM IBQ TP0 parity error" },
5810 		{ F_IBQTP1PARERR, "CIM IBQ TP1 parity error" },
5811 		{ F_IBQULPPARERR, "CIM IBQ ULP parity error" },
5812 		{ F_IBQSGELOPARERR, "CIM IBQ SGE_LO parity error" },
5813 		{ F_IBQSGEHIPARERR | F_IBQPCIEPARERR,	/* same bit */
5814 			"CIM IBQ PCIe/SGE_HI parity error" },
5815 		{ F_IBQNCSIPARERR, "CIM IBQ NC-SI parity error" },
5816 		{ F_OBQULP0PARERR, "CIM OBQ ULP0 parity error" },
5817 		{ F_OBQULP1PARERR, "CIM OBQ ULP1 parity error" },
5818 		{ F_OBQULP2PARERR, "CIM OBQ ULP2 parity error" },
5819 		{ F_OBQULP3PARERR, "CIM OBQ ULP3 parity error" },
5820 		{ F_OBQSGEPARERR, "CIM OBQ SGE parity error" },
5821 		{ F_OBQNCSIPARERR, "CIM OBQ NC-SI parity error" },
5822 		{ F_TIMER1INT, "CIM TIMER0 interrupt" },
5823 		{ F_TIMER0INT, "CIM TIMER0 interrupt" },
5824 		{ F_PREFDROPINT, "CIM control register prefetch drop" },
5825 		{ 0}
5826 	};
5827 	struct intr_info cim_host_intr_info = {
5828 		.name = "CIM_HOST_INT_CAUSE",
5829 		.cause_reg = A_CIM_HOST_INT_CAUSE,
5830 		.enable_reg = A_CIM_HOST_INT_ENABLE,
5831 		.fatal = 0x007fffe6,
5832 		.flags = IHF_FATAL_IFF_ENABLED,
5833 		.details = NULL,
5834 		.actions = NULL,
5835 	};
5836 	static const struct intr_details cim_host_upacc_intr_details[] = {
5837 		{ F_CONWRERRINT, "CIM condition write error "},
5838 		{ F_EEPROMWRINT, "CIM EEPROM came out of busy state" },
5839 		{ F_TIMEOUTMAINT, "CIM PIF MA timeout" },
5840 		{ F_TIMEOUTINT, "CIM PIF timeout" },
5841 		{ F_RSPOVRLOOKUPINT, "CIM response FIFO overwrite" },
5842 		{ F_REQOVRLOOKUPINT, "CIM request FIFO overwrite" },
5843 		{ F_BLKWRPLINT, "CIM block write to PL space" },
5844 		{ F_BLKRDPLINT, "CIM block read from PL space" },
5845 		{ F_SGLWRPLINT,
5846 			"CIM single write to PL space with illegal BEs" },
5847 		{ F_SGLRDPLINT,
5848 			"CIM single read from PL space with illegal BEs" },
5849 		{ F_BLKWRCTLINT, "CIM block write to CTL space" },
5850 		{ F_BLKRDCTLINT, "CIM block read from CTL space" },
5851 		{ F_SGLWRCTLINT,
5852 			"CIM single write to CTL space with illegal BEs" },
5853 		{ F_SGLRDCTLINT,
5854 			"CIM single read from CTL space with illegal BEs" },
5855 		{ F_BLKWREEPROMINT, "CIM block write to EEPROM space" },
5856 		{ F_BLKRDEEPROMINT, "CIM block read from EEPROM space" },
5857 		{ F_SGLWREEPROMINT,
5858 			"CIM single write to EEPROM space with illegal BEs" },
5859 		{ F_SGLRDEEPROMINT,
5860 			"CIM single read from EEPROM space with illegal BEs" },
5861 		{ F_BLKWRFLASHINT, "CIM block write to flash space" },
5862 		{ F_BLKRDFLASHINT, "CIM block read from flash space" },
5863 		{ F_SGLWRFLASHINT, "CIM single write to flash space" },
5864 		{ F_SGLRDFLASHINT,
5865 			"CIM single read from flash space with illegal BEs" },
5866 		{ F_BLKWRBOOTINT, "CIM block write to boot space" },
5867 		{ F_BLKRDBOOTINT, "CIM block read from boot space" },
5868 		{ F_SGLWRBOOTINT, "CIM single write to boot space" },
5869 		{ F_SGLRDBOOTINT,
5870 			"CIM single read from boot space with illegal BEs" },
5871 		{ F_ILLWRBEINT, "CIM illegal write BEs" },
5872 		{ F_ILLRDBEINT, "CIM illegal read BEs" },
5873 		{ F_ILLRDINT, "CIM illegal read" },
5874 		{ F_ILLWRINT, "CIM illegal write" },
5875 		{ F_ILLTRANSINT, "CIM illegal transaction" },
5876 		{ F_RSVDSPACEINT, "CIM reserved space access" },
5877 		{0}
5878 	};
5879 	static const struct intr_info cim_host_upacc_intr_info = {
5880 		.name = "CIM_HOST_UPACC_INT_CAUSE",
5881 		.cause_reg = A_CIM_HOST_UPACC_INT_CAUSE,
5882 		.enable_reg = A_CIM_HOST_UPACC_INT_ENABLE,
5883 		.fatal = 0x3fffeeff,
5884 		.flags = IHF_FATAL_IFF_ENABLED,
5885 		.details = cim_host_upacc_intr_details,
5886 		.actions = NULL,
5887 	};
5888 	static const struct intr_info cim_pf_host_intr_info = {
5889 		.name = "CIM_PF_HOST_INT_CAUSE",
5890 		.cause_reg = MYPF_REG(A_CIM_PF_HOST_INT_CAUSE),
5891 		.enable_reg = MYPF_REG(A_CIM_PF_HOST_INT_ENABLE),
5892 		.fatal = 0,
5893 		.flags = 0,
5894 		.details = NULL,
5895 		.actions = NULL,
5896 	};
5897 	static const struct intr_details cim_perr_cause_details[] = {
5898 		{ F_T7_MA_CIM_INTFPERR, "MA2CIM interface parity error" },
5899 		{ F_T7_MBHOSTPARERR, "Mailbox Host Read parity error" },
5900 		{ F_MAARBINVRSPTAG, "MA Arbiter Invalid Response Tag (Fatal)" },
5901 		{ F_MAARBFIFOPARERR, "MA Arbiter FIFO Parity Error" },
5902 		{ F_SEMSRAMPARERR, "Semaphore logic SRAM Parity Error" },
5903 		{ F_RSACPARERR, "RSA Code SRAM Parity Error" },
5904 		{ F_RSADPARERR, "RSA Data SRAM Parity Error" },
5905 		{ F_T7_PLCIM_MSTRSPDATAPARERR, "PL2CIM Master response data parity error" },
5906 		{ F_T7_PCIE2CIMINTFPARERR, "IBQ PCIE intf parity error" },
5907 		{ F_T7_NCSI2CIMINTFPARERR, "IBQ NCSI intf parity error" },
5908 		{ F_T7_SGE2CIMINTFPARERR, "IBQ SGE Intf Parity error" },
5909 		{ F_T7_ULP2CIMINTFPARERR, "IBQ ULP_TX intf parity error" },
5910 		{ F_T7_TP2CIMINTFPARERR, "IBQ TP intf parity error" },
5911 		{ F_CORE7PARERR, "Slave Core7 parity error" },
5912 		{ F_CORE6PARERR, "Slave Core6 parity error" },
5913 		{ F_CORE5PARERR, "Slave Core5 parity error" },
5914 		{ F_CORE4PARERR, "Slave Core4 parity error" },
5915 		{ F_CORE3PARERR, "Slave Core3 parity error" },
5916 		{ F_CORE2PARERR, "Slave Core2 parity error" },
5917 		{ F_CORE1PARERR, "Slave Core1 parity error" },
5918 		{ F_GFTPARERR, "GFT block Memory parity error" },
5919 		{ F_MPSRSPDATAPARERR, "MPS lookup interface Response parity error" },
5920 		{ F_ER_RSPDATAPARERR, "Expansion ROM/Flash Interface Response Parity Error" },
5921 		{ F_FLOWFIFOPARERR, "SGE FlowID Prefetch FIFO Parity Error" },
5922 		{ F_OBQSRAMPARERR, "OBQ SRAM Parity Error" },
5923 		{ F_TIEQOUTPARERR, "TIE Queue Outgoing FIFO parity error" },
5924 		{ F_TIEQINPARERR, "TIE Queue Incoming FIFO parity error" },
5925 		{ F_PIFRSPPARERR, "PIF Response interface FIFO Parity error" },
5926 		{ F_PIFREQPARERR, "PIF Request interface FIFO Parity error" },
5927 		{ 0 }
5928 	};
5929 	static const struct intr_info cim_perr_cause = {
5930 		.name = "CIM_PERR_CAUSE",
5931 		.cause_reg = A_CIM_PERR_CAUSE,
5932 		.enable_reg = A_CIM_PERR_ENABLE,
5933 		.fatal = 0xffffffff,
5934 		.flags = IHF_FATAL_IFF_ENABLED,
5935 		.details = cim_perr_cause_details,
5936 		.actions = NULL,
5937 	};
5938 	u32 val, fw_err;
5939 	bool fatal;
5940 
5941 	if (chip_id(adap) >= CHELSIO_T7)
5942 		cim_host_intr_info.details = cim_host_t7_intr_details;
5943 	else
5944 		cim_host_intr_info.details = cim_host_intr_details;
5945 	/*
5946 	 * When the Firmware detects an internal error which normally wouldn't
5947 	 * raise a Host Interrupt, it forces a CIM Timer0 interrupt in order
5948 	 * to make sure the Host sees the Firmware Crash.  So if we have a
5949 	 * Timer0 interrupt and don't see a Firmware Crash, ignore the Timer0
5950 	 * interrupt.
5951 	 */
5952 	fw_err = t4_read_reg(adap, A_PCIE_FW);
5953 	val = t4_read_reg(adap, A_CIM_HOST_INT_CAUSE);
5954 	if (val & F_TIMER0INT && (!(fw_err & F_PCIE_FW_ERR) ||
5955 	    G_PCIE_FW_EVAL(fw_err) != PCIE_FW_EVAL_CRASH)) {
5956 		t4_write_reg(adap, A_CIM_HOST_INT_CAUSE, F_TIMER0INT);
5957 	}
5958 
5959 	fatal = (fw_err & F_PCIE_FW_ERR) != 0;
5960 	fatal |= t4_handle_intr(adap, &cim_host_intr_info, 0, flags);
5961 	fatal |= t4_handle_intr(adap, &cim_host_upacc_intr_info, 0, flags);
5962 	fatal |= t4_handle_intr(adap, &cim_pf_host_intr_info, 0, flags);
5963 	if (chip_id(adap) > CHELSIO_T6)
5964 		fatal |= t4_handle_intr(adap, &cim_perr_cause, 0, flags);
5965 	if (fatal)
5966 		t4_os_cim_err(adap);
5967 
5968 	return (fatal);
5969 }
5970 
5971 /*
5972  * ULP RX interrupt handler.
5973  */
ulprx_intr_handler(struct adapter * adap,int arg,int flags)5974 static bool ulprx_intr_handler(struct adapter *adap, int arg, int flags)
5975 {
5976 	static const struct intr_details ulprx_intr_details[] = {
5977 		/* T5+ */
5978 		{ F_SE_CNT_MISMATCH_1, "ULPRX SE count mismatch in channel 1" },
5979 		{ F_SE_CNT_MISMATCH_0, "ULPRX SE count mismatch in channel 0" },
5980 
5981 		/* T4+ */
5982 		{ F_CAUSE_CTX_1, "ULPRX channel 1 context error" },
5983 		{ F_CAUSE_CTX_0, "ULPRX channel 0 context error" },
5984 		{ 0x007fffff, "ULPRX parity error" },
5985 		{ 0 }
5986 	};
5987 	static const struct intr_details t6_ulprx_int_cause_details[] = {
5988 		{ F_SE_CNT_MISMATCH_1, "SE count mismatch in channel1" },
5989 		{ F_SE_CNT_MISMATCH_0, "SE count mismatch in channel 0" },
5990 		{ F_CAUSE_CTX_1, "Context access error on channel 1" },
5991 		{ F_CAUSE_CTX_0, "Context access error on channel 0" },
5992 		{ F_CAUSE_FF, "filp-flop based fifos" },
5993 		{ F_CAUSE_APF_1, "Arb prefetch memory, channel 1" },
5994 		{ F_CAUSE_APF_0, "Arb prefetch memory, channel 0" },
5995 		{ F_CAUSE_AF_1, "Arb fetch memory, channel 1" },
5996 		{ F_CAUSE_AF_0, "Arb fetch memory, channel 0" },
5997 		{ F_CAUSE_DDPDF_1, "ddp_data_fifo Fifo, channel 1" },
5998 		{ F_CAUSE_DDPMF_1, "ddp_msg_fifo Fifo, channel 1" },
5999 		{ F_CAUSE_MEMRF_1, "mem_req_fifo_d Fifo, channel 1" },
6000 		{ F_CAUSE_PRSDF_1, "prsr_data_fifo Fifo, channel 1" },
6001 		{ F_CAUSE_DDPDF_0, "ddp_data_fifo Fifo, channel 0" },
6002 		{ F_CAUSE_DDPMF_0, "ddp_msg_fifo Fifo, channel 0" },
6003 		{ F_CAUSE_MEMRF_0, "mem_req_fifo_d Fifo, channel 0" },
6004 		{ F_CAUSE_PRSDF_0, "prsr_data_fifo Fifo, channel 0" },
6005 		{ F_CAUSE_PCMDF_1, "Pcmd Fifo, channel 1" },
6006 		{ F_CAUSE_TPTCF_1, "tpt_ctl_fifo Fifo, channel 1" },
6007 		{ F_CAUSE_DDPCF_1, "ddp_ctl_fifo Fifo, channel 1" },
6008 		{ F_CAUSE_MPARF_1, "mpar_ctl_fifo Fifo, channel 1" },
6009 		{ F_CAUSE_MPARC_1, "mpac_ctl_fifo Fifo, channel 1" },
6010 		{ F_CAUSE_PCMDF_0, "Pcmd Fifo, channel 0" },
6011 		{ F_CAUSE_TPTCF_0, "tpt_ctl_fifo Fifo, channel 0" },
6012 		{ F_CAUSE_DDPCF_0, "ddp_ctl_fifo Fifo, channel 0" },
6013 		{ F_CAUSE_MPARF_0, "mpar_ctl_fifo Fifo, channel 0" },
6014 		{ F_CAUSE_MPARC_0, "mpac_ctl_fifo Fifo, channel 0" },
6015 		{ 0 }
6016 	};
6017 	static const struct intr_details t7_ulprx_int_cause_details[] = {
6018 		{ F_CERR_PCMD_FIFO_3, "PCMD FIFO correctable Error3" },
6019 		{ F_CERR_PCMD_FIFO_2, "PCMD FIFO correctable Error2" },
6020 		{ F_CERR_PCMD_FIFO_1, "PCMD FIFO correctable Error1" },
6021 		{ F_CERR_PCMD_FIFO_0, "PCMD FIFO correctable Error0" },
6022 		{ F_CERR_DATA_FIFO_3, "DDP Data FIFO correctable Error3" },
6023 		{ F_CERR_DATA_FIFO_2, "DDP Data FIFO correctable Error2" },
6024 		{ F_CERR_DATA_FIFO_1, "DDP Data FIFO correctable Error1" },
6025 		{ F_CERR_DATA_FIFO_0, "DDP Data FIFO correctable Error0" },
6026 		{ F_SE_CNT_MISMATCH_3, "SE count mismatch in channel3" },
6027 		{ F_SE_CNT_MISMATCH_2, "SE count mismatch in channel2" },
6028 		{ F_T7_SE_CNT_MISMATCH_1, "SE count mismatch in channel1" },
6029 		{ F_T7_SE_CNT_MISMATCH_0, "SE count mismatch in channel 0" },
6030 		{ F_T7_ENABLE_CTX_3, "Context access error on channel 3" },
6031 		{ F_T7_ENABLE_CTX_2, "Context access error on channel 2" },
6032 		{ F_T7_ENABLE_CTX_1, "Context access error on channel 1" },
6033 		{ F_T7_ENABLE_CTX_0, "Context access error on channel 0" },
6034 		{ F_T7_ENABLE_ALN_SDC_ERR_3, "SDC error reported by aligner in channel3" },
6035 		{ F_T7_ENABLE_ALN_SDC_ERR_2, "SDC error reported by aligner in channel2" },
6036 		{ F_T7_ENABLE_ALN_SDC_ERR_1, "SDC error reported by aligner in channel1" },
6037 		{ F_T7_ENABLE_ALN_SDC_ERR_0, "SDC error reported by aligner in channel0" },
6038 		{ 0 }
6039 	};
6040 	struct intr_info ulprx_intr_info = {
6041 		.name = "ULP_RX_INT_CAUSE",
6042 		.cause_reg = A_ULP_RX_INT_CAUSE,
6043 		.enable_reg = A_ULP_RX_INT_ENABLE,
6044 		.fatal = 0x07ffffff,
6045 		.flags = IHF_FATAL_IFF_ENABLED,
6046 		.details = NULL,
6047 		.actions = NULL,
6048 	};
6049 	static const struct intr_details ulprx_int_cause_2_details[] = {
6050 		{ F_ULPRX2MA_INTFPERR, "SDC error reported by ULPRX2MA interface parity checker" },
6051 		{ F_ALN_SDC_ERR_1, "SDC error reported by aligner in channel 1" },
6052 		{ F_ALN_SDC_ERR_0, "SDC error reported by aligner in channel 0" },
6053 		{ F_PF_UNTAGGED_TPT_1, "Parity error from Untagged TPT prefetch fifo channel 1" },
6054 		{ F_PF_UNTAGGED_TPT_0, "Parity error from Untagged TPT prefetch fifo channel 0" },
6055 		{ F_PF_PBL_1, "Parity error from PBL prefetch fifo channel 1" },
6056 		{ F_PF_PBL_0, "Parity error from PBL prefetch fifo channel 0" },
6057 		{ F_DDP_HINT_1, "DDP hint fifo Perr in channel 1" },
6058 		{ F_DDP_HINT_0, "DDP hint fifo Perr in channel 0" },
6059 		{ 0 }
6060 	};
6061 	static const struct intr_info ulprx_intr2_info = {
6062 		.name = "ULP_RX_INT_CAUSE_2",
6063 		.cause_reg = A_ULP_RX_INT_CAUSE_2,
6064 		.enable_reg = A_ULP_RX_INT_ENABLE_2,
6065 		.fatal = 0,
6066 		.flags = 0,
6067 		.details = ulprx_int_cause_2_details,
6068 		.actions = NULL,
6069 	};
6070 	static const struct intr_details ulprx_int_cause_pcmd_details[] = {
6071 		{ F_CAUSE_PCMD_SFIFO_3, "Small FIFOs, channel 3" },
6072 		{ F_CAUSE_PCMD_FIFO_3, "pcmd_ctl_fifo, channel 3" },
6073 		{ F_CAUSE_PCMD_DDP_HINT_3, "ddp_hint_ctl_fifo FIFO, channel 3" },
6074 		{ F_CAUSE_PCMD_TPT_3, "tpt_ctl_fifo FIFO, channel 3" },
6075 		{ F_CAUSE_PCMD_DDP_3, "ddp_ctl_fifo FIFO, channel 3" },
6076 		{ F_CAUSE_PCMD_MPAR_3, "mpar_ctl_fifo FIFO, channel 3" },
6077 		{ F_CAUSE_PCMD_MPAC_3, "mpac_ctl_fifo FIFO, channel 3" },
6078 		{ F_CAUSE_PCMD_SFIFO_2, "Small FIFOs, channel 2" },
6079 		{ F_CAUSE_PCMD_FIFO_2, "pcmd_ctl_fifo, channel 2" },
6080 		{ F_CAUSE_PCMD_DDP_HINT_2, "ddp_hint_ctl_fifo FIFO, channel 2" },
6081 		{ F_CAUSE_PCMD_TPT_2, "tpt_ctl_fifo FIFO, channel 2" },
6082 		{ F_CAUSE_PCMD_DDP_2, "ddp_ctl_fifo FIFO, channel 2" },
6083 		{ F_CAUSE_PCMD_MPAR_2, "mpar_ctl_fifo FIFO, channel 2" },
6084 		{ F_CAUSE_PCMD_MPAC_2, "mpac_ctl_fifo FIFO, channel 2" },
6085 		{ F_CAUSE_PCMD_SFIFO_1, "Small FIFOs, channel 1" },
6086 		{ F_CAUSE_PCMD_FIFO_1, "pcmd_ctl_fifo, channel 1" },
6087 		{ F_CAUSE_PCMD_DDP_HINT_1, "ddp_hint_ctl_fifo FIFO, channel 1" },
6088 		{ F_CAUSE_PCMD_TPT_1, "tpt_ctl_fifo FIFO, channel 1" },
6089 		{ F_CAUSE_PCMD_DDP_1, "ddp_ctl_fifo FIFO, channel 1" },
6090 		{ F_CAUSE_PCMD_MPAR_1, "mpar_ctl_fifo FIFO, channel 1" },
6091 		{ F_CAUSE_PCMD_MPAC_1, "mpac_ctl_fifo FIFO, channel 1" },
6092 		{ F_CAUSE_PCMD_SFIFO_0, "Small FIFOs, channel 0" },
6093 		{ F_CAUSE_PCMD_FIFO_0, "pcmd_ctl_fifo, channel 0" },
6094 		{ F_CAUSE_PCMD_DDP_HINT_0, "ddp_hint_ctl_fifo FIFO, channel 0" },
6095 		{ F_CAUSE_PCMD_TPT_0, "tpt_ctl_fifo FIFO, channel 0" },
6096 		{ F_CAUSE_PCMD_DDP_0, "ddp_ctl_fifo FIFO, channel 0" },
6097 		{ F_CAUSE_PCMD_MPAR_0, "mpar_ctl_fifo FIFO, channel 0" },
6098 		{ F_CAUSE_PCMD_MPAC_0, "mpac_ctl_fifo FIFO, channel 0" },
6099 		{ 0 }
6100 	};
6101 	static const struct intr_info ulprx_int_cause_pcmd = {
6102 		.name = "ULP_RX_INT_CAUSE_PCMD",
6103 		.cause_reg = A_ULP_RX_INT_CAUSE_PCMD,
6104 		.enable_reg = A_ULP_RX_INT_ENABLE_PCMD,
6105 		.fatal = 0,
6106 		.flags = 0,
6107 		.details = ulprx_int_cause_pcmd_details,
6108 		.actions = NULL,
6109 	};
6110 	static const struct intr_details ulprx_int_cause_data_details[] = {
6111 		{ F_CAUSE_DATA_SNOOP_3, "Snoop FIFO, channel 3" },
6112 		{ F_CAUSE_DATA_SFIFO_3, "Small FIFO, channel 3" },
6113 		{ F_CAUSE_DATA_FIFO_3, "data_ctl_fifo FIFO, channel 3" },
6114 		{ F_CAUSE_DATA_DDP_3, "ddp_ctl_fifo FIFO, channel 3" },
6115 		{ F_CAUSE_DATA_CTX_3, "ctx_ctl_fifo FIFO, channel 3" },
6116 		{ F_CAUSE_DATA_PARSER_3, "parser_ctl_fifo FIFO, channel 3" },
6117 		{ F_CAUSE_DATA_SNOOP_2, "Snoop FIFO, channel 2" },
6118 		{ F_CAUSE_DATA_SFIFO_2, "Small FIFO, channel 2" },
6119 		{ F_CAUSE_DATA_FIFO_2, "data_ctl_fifo FIFO, channel 2" },
6120 		{ F_CAUSE_DATA_DDP_2, "ddp_ctl_fifo FIFO, channel 2" },
6121 		{ F_CAUSE_DATA_CTX_2, "ctx_ctl_fifo FIFO, channel 2" },
6122 		{ F_CAUSE_DATA_PARSER_2, "parser_ctl_fifo FIFO, channel 2" },
6123 		{ F_CAUSE_DATA_SNOOP_1, "Snoop FIFO, channel 1" },
6124 		{ F_CAUSE_DATA_SFIFO_1, "Small FIFO, channel 1" },
6125 		{ F_CAUSE_DATA_FIFO_1, "data_ctl_fifo FIFO, channel 1" },
6126 		{ F_CAUSE_DATA_DDP_1, "ddp_ctl_fifo FIFO, channel 1" },
6127 		{ F_CAUSE_DATA_CTX_1, "ctx_ctl_fifo FIFO, channel 1" },
6128 		{ F_CAUSE_DATA_PARSER_1, "parser_ctl_fifo FIFO, channel 1" },
6129 		{ F_CAUSE_DATA_SNOOP_0, "Snoop FIFO, channel 0" },
6130 		{ F_CAUSE_DATA_SFIFO_0, "Small FIFO, channel 0" },
6131 		{ F_CAUSE_DATA_FIFO_0, "data_ctl_fifo FIFO, channel 0" },
6132 		{ F_CAUSE_DATA_DDP_0, "ddp_ctl_fifo FIFO, channel 0" },
6133 		{ F_CAUSE_DATA_CTX_0, "ctx_ctl_fifo FIFO, channel 0" },
6134 		{ F_CAUSE_DATA_PARSER_0, "parser_ctl_fifo FIFO, channel 0" },
6135 		{ 0 }
6136 	};
6137 	static const struct intr_info ulprx_int_cause_data = {
6138 		.name = "ULP_RX_INT_CAUSE_DATA",
6139 		.cause_reg = A_ULP_RX_INT_CAUSE_DATA,
6140 		.enable_reg = A_ULP_RX_INT_ENABLE_DATA,
6141 		.fatal = 0,
6142 		.flags = 0,
6143 		.details = ulprx_int_cause_data_details,
6144 		.actions = NULL,
6145 	};
6146 	static const struct intr_details ulprx_int_cause_arb_details[] = {
6147 		{ F_CAUSE_ARB_PBL_PF_3, "pbl_pf_ctl_fifo FIFO, channel 3" },
6148 		{ F_CAUSE_ARB_PF_3, "pf_ctl_fifo FIFO, channel 3" },
6149 		{ F_CAUSE_ARB_TPT_PF_3, "tpt_pf_ctl_fifo FIFO, channel 3" },
6150 		{ F_CAUSE_ARB_F_3, "f_ctl_fifo FIFO, channel 3" },
6151 		{ F_CAUSE_ARB_PBL_PF_2, "pbl_pf_ctl_fifo FIFO, channel 2" },
6152 		{ F_CAUSE_ARB_PF_2, "pf_ctl_fifo FIFO, channel 2" },
6153 		{ F_CAUSE_ARB_TPT_PF_2, "tpt_pf_ctl_fifo FIFO, channel 2" },
6154 		{ F_CAUSE_ARB_F_2, "f_ctl_fifo FIFO, channel 2" },
6155 		{ F_CAUSE_ARB_PBL_PF_1, "pbl_pf_ctl_fifo FIFO, channel 1" },
6156 		{ F_CAUSE_ARB_PF_1, "pf_ctl_fifo FIFO, channel 1" },
6157 		{ F_CAUSE_ARB_TPT_PF_1, "tpt_pf_ctl_fifo FIFO, channel 1" },
6158 		{ F_CAUSE_ARB_F_1, "f_ctl_fifo FIFO, channel 1" },
6159 		{ F_CAUSE_ARB_PBL_PF_0, "pbl_pf_ctl_fifo FIFO, channel 0" },
6160 		{ F_CAUSE_ARB_PF_0, "pf_ctl_fifo FIFO, channel 0" },
6161 		{ F_CAUSE_ARB_TPT_PF_0, "tpt_pf_ctl_fifo FIFO, channel 0" },
6162 		{ F_CAUSE_ARB_F_0, "f_ctl_fifo FIFO, channel 0" },
6163 		{ 0 }
6164 	};
6165 	static const struct intr_info ulprx_int_cause_arb = {
6166 		.name = "ULP_RX_INT_CAUSE_ARB",
6167 		.cause_reg = A_ULP_RX_INT_CAUSE_ARB,
6168 		.enable_reg = A_ULP_RX_INT_ENABLE_ARB,
6169 		.fatal = 0,
6170 		.flags = 0,
6171 		.details = ulprx_int_cause_arb_details,
6172 		.actions = NULL,
6173 	};
6174 	static const struct intr_details ulprx_int_cause_interface_details[] = {
6175 		{ F_CAUSE_ULPRX2SBT_RSPPERR, "ULPRX2SBT_RspPerr" },
6176 		{ F_CAUSE_ULPRX2MA_RSPPERR, "ULPRX2MA_RspPerr" },
6177 		{ F_CAUSE_PIO_BUS_PERR, "Pio_Bus_Perr" },
6178 		{ F_CAUSE_PM2ULP_SNOOPDATA_3, "PM2ULP_SnoopData, channel 3" },
6179 		{ F_CAUSE_PM2ULP_SNOOPDATA_2, "PM2ULP_SnoopData, channel 2" },
6180 		{ F_CAUSE_PM2ULP_SNOOPDATA_1, "PM2ULP_SnoopData, channel 1" },
6181 		{ F_CAUSE_PM2ULP_SNOOPDATA_0, "PM2ULP_SnoopData, channel 0" },
6182 		{ F_CAUSE_TLS2ULP_DATA_3, "TLS2ULP_Data, channel 3" },
6183 		{ F_CAUSE_TLS2ULP_DATA_2, "TLS2ULP_Data, channel 2" },
6184 		{ F_CAUSE_TLS2ULP_DATA_1, "TLS2ULP_Data, channel 1" },
6185 		{ F_CAUSE_TLS2ULP_DATA_0, "TLS2ULP_Data, channel 0" },
6186 		{ F_CAUSE_TLS2ULP_PLENDATA_3, "TLS2ULP_PLenData, channel 3" },
6187 		{ F_CAUSE_TLS2ULP_PLENDATA_2, "TLS2ULP_PLenData, channel 2" },
6188 		{ F_CAUSE_TLS2ULP_PLENDATA_1, "TLS2ULP_PLenData, channel 1" },
6189 		{ F_CAUSE_TLS2ULP_PLENDATA_0, "TLS2ULP_PLenData, channel 0" },
6190 		{ F_CAUSE_PM2ULP_DATA_3, "Pm2Ulp_Data, channel 3" },
6191 		{ F_CAUSE_PM2ULP_DATA_2, "Pm2Ulp_Data, channel 2" },
6192 		{ F_CAUSE_PM2ULP_DATA_1, "Pm2Ulp_Data, channel 1" },
6193 		{ F_CAUSE_PM2ULP_DATA_0, "Pm2Ulp_Data, channel 0" },
6194 		{ F_CAUSE_TP2ULP_PCMD_3, "Tp2Ulp_Pcmd, channel 3" },
6195 		{ F_CAUSE_TP2ULP_PCMD_2, "Tp2Ulp_Pcmd, channel 2" },
6196 		{ F_CAUSE_TP2ULP_PCMD_1, "Tp2Ulp_Pcmd, channel 1" },
6197 		{ F_CAUSE_TP2ULP_PCMD_0, "Tp2Ulp_Pcmd, channel 0" },
6198 		{ 0 }
6199 	};
6200 	static const struct intr_info ulprx_int_cause_intf = {
6201 		.name = "ULP_RX_INT_CAUSE_INTERFACE",
6202 		.cause_reg = A_ULP_RX_INT_CAUSE_INTERFACE,
6203 		.enable_reg = A_ULP_RX_INT_ENABLE_INTERFACE,
6204 		.fatal = 0,
6205 		.flags = 0,
6206 		.details = ulprx_int_cause_interface_details,
6207 		.actions = NULL,
6208 	};
6209 	bool fatal = false;
6210 
6211 	if (chip_id(adap) <= CHELSIO_T5)
6212 		ulprx_intr_info.details = ulprx_intr_details;
6213 	else if (chip_id(adap) <= CHELSIO_T6)
6214 		ulprx_intr_info.details =  t6_ulprx_int_cause_details;
6215 	else
6216 		ulprx_intr_info.details = t7_ulprx_int_cause_details;
6217 
6218 	fatal |= t4_handle_intr(adap, &ulprx_intr_info, 0, flags);
6219 	if (chip_id(adap) < CHELSIO_T7)
6220 		fatal |= t4_handle_intr(adap, &ulprx_intr2_info, 0, flags);
6221 	else {
6222 		fatal |= t4_handle_intr(adap, &ulprx_int_cause_pcmd, 0, flags);
6223 		fatal |= t4_handle_intr(adap, &ulprx_int_cause_data, 0, flags);
6224 		fatal |= t4_handle_intr(adap, &ulprx_int_cause_arb, 0, flags);
6225 		fatal |= t4_handle_intr(adap, &ulprx_int_cause_intf, 0, flags);
6226 	}
6227 
6228 	return (fatal);
6229 }
6230 
6231 /*
6232  * ULP TX interrupt handler.
6233  */
ulptx_intr_handler(struct adapter * adap,int arg,int flags)6234 static bool ulptx_intr_handler(struct adapter *adap, int arg, int flags)
6235 {
6236 	static const struct intr_details ulptx_intr_details[] = {
6237 		{ F_PBL_BOUND_ERR_CH3, "ULPTX channel 3 PBL out of bounds" },
6238 		{ F_PBL_BOUND_ERR_CH2, "ULPTX channel 2 PBL out of bounds" },
6239 		{ F_PBL_BOUND_ERR_CH1, "ULPTX channel 1 PBL out of bounds" },
6240 		{ F_PBL_BOUND_ERR_CH0, "ULPTX channel 0 PBL out of bounds" },
6241 		{ 0x0fffffff, "ULPTX parity error" },
6242 		{ 0 }
6243 	};
6244 	static const struct intr_details t6_ulptx_int_cause_details[] = {
6245 		{ F_PBL_BOUND_ERR_CH3 | F_PBL_BOUND_ERR_CH2 |
6246 		  F_PBL_BOUND_ERR_CH1 | F_PBL_BOUND_ERR_CH0,
6247 		  "PBL address out of bounds" },
6248 		{ F_SGE2ULP_FIFO_PERR_SET3 | F_SGE2ULP_FIFO_PERR_SET2 |
6249 		  F_SGE2ULP_FIFO_PERR_SET1 | F_SGE2ULP_FIFO_PERR_SET0,
6250 		  "SGE2ULP fifo parity error" },
6251 		{ F_CIM2ULP_FIFO_PERR_SET3 | F_CIM2ULP_FIFO_PERR_SET2 |
6252 		  F_CIM2ULP_FIFO_PERR_SET1 | F_CIM2ULP_FIFO_PERR_SET0,
6253 		  "CIM2ULP fifo parity error" },
6254 		{ F_CQE_FIFO_PERR_SET3 | F_CQE_FIFO_PERR_SET2 |
6255 		  F_CQE_FIFO_PERR_SET1 | F_CQE_FIFO_PERR_SET0,
6256 		  "CQE fifo parity error" },
6257 		{ F_PBL_FIFO_PERR_SET3 | F_PBL_FIFO_PERR_SET2 |
6258 		  F_PBL_FIFO_PERR_SET1 | F_PBL_FIFO_PERR_SET0,
6259 		  "PBL fifo parity error" },
6260 		{ F_CMD_FIFO_PERR_SET3 | F_CMD_FIFO_PERR_SET2 |
6261 		  F_CMD_FIFO_PERR_SET1 | F_CMD_FIFO_PERR_SET0,
6262 		  "Command fifo parity error" },
6263 		{ F_LSO_HDR_SRAM_PERR_SET3 | F_LSO_HDR_SRAM_PERR_SET2 |
6264 		  F_LSO_HDR_SRAM_PERR_SET1 | F_LSO_HDR_SRAM_PERR_SET0,
6265 		  "LSO hdr parity error" },
6266 		{ 0 }
6267 	};
6268 	struct intr_info ulptx_intr_info = {
6269 		.name = "ULP_TX_INT_CAUSE",
6270 		.cause_reg = A_ULP_TX_INT_CAUSE,
6271 		.enable_reg = A_ULP_TX_INT_ENABLE,
6272 		.fatal = 0x0fffffff,
6273 		.flags = IHF_FATAL_IFF_ENABLED,
6274 		.details = NULL,
6275 		.actions = NULL,
6276 	};
6277 	static const struct intr_details ulptx_int_cause_1_details[] = {
6278 		{ F_PBL_BOUND_ERR_CH3 | F_PBL_BOUND_ERR_CH2 |
6279 		  F_PBL_BOUND_ERR_CH1 | F_PBL_BOUND_ERR_CH0,
6280 		  "PBL address out of bounds (configured PBL_ULIMIT/LLIMIT)" },
6281 		{ F_SGE2ULP_FIFO_PERR_SET3 | F_SGE2ULP_FIFO_PERR_SET2 |
6282 		  F_SGE2ULP_FIFO_PERR_SET1 | F_SGE2ULP_FIFO_PERR_SET0,
6283 		  "SGE2ULP FIFO parity error" },
6284 		{ F_CIM2ULP_FIFO_PERR_SET3 | F_CIM2ULP_FIFO_PERR_SET2 |
6285 		  F_CIM2ULP_FIFO_PERR_SET1 | F_CIM2ULP_FIFO_PERR_SET0,
6286 		  "CIM2ULP FIFO parity error" },
6287 		{ F_CQE_FIFO_PERR_SET3 | F_CQE_FIFO_PERR_SET2 |
6288 		  F_CQE_FIFO_PERR_SET1 | F_CQE_FIFO_PERR_SET0,
6289 		  "CQE FIFO parity error" },
6290 		{ F_PBL_FIFO_PERR_SET3 | F_PBL_FIFO_PERR_SET2 |
6291 		  F_PBL_FIFO_PERR_SET1 | F_PBL_FIFO_PERR_SET0,
6292 		  "PBL FIFO parity error" },
6293 		{ F_CMD_FIFO_PERR_SET3 | F_CMD_FIFO_PERR_SET2 |
6294 		  F_CMD_FIFO_PERR_SET1 | F_CMD_FIFO_PERR_SET0,
6295 		  "Command FIFO parity error" },
6296 		{ F_LSO_HDR_SRAM_PERR_SET3 | F_LSO_HDR_SRAM_PERR_SET2 |
6297 		  F_LSO_HDR_SRAM_PERR_SET1 | F_LSO_HDR_SRAM_PERR_SET0,
6298 		  "LSO HDR parity error" },
6299 		{ F_TLS_DSGL_PARERR3 | F_TLS_DSGL_PARERR2 |
6300 		  F_TLS_DSGL_PARERR1 | F_TLS_DSGL_PARERR0,
6301 		  "TLS Glue DSGL FIFO parity error" },
6302 		{ 0 }
6303 	};
6304 	static const struct intr_info ulptx_intr_info1 = {
6305 		.name = "ULP_TX_INT_CAUSE_1",
6306 		.cause_reg = A_ULP_TX_INT_CAUSE_1,
6307 		.enable_reg = A_ULP_TX_INT_ENABLE_1,
6308 		.fatal = 0x0fffffff,
6309 		.flags = IHF_FATAL_IFF_ENABLED,
6310 		.details = ulptx_int_cause_1_details,
6311 		.actions = NULL,
6312 	};
6313 	static const struct intr_details ulptx_int_cause_2_details[] = {
6314 		{ F_EDMA_IN_FIFO_PERR_SET3 | F_EDMA_IN_FIFO_PERR_SET2 |
6315 		  F_EDMA_IN_FIFO_PERR_SET1 | F_EDMA_IN_FIFO_PERR_SET0,
6316 		  "EDMA input FIFO parity error" },
6317 		{ F_ALIGN_CTL_FIFO_PERR_SET3 | F_ALIGN_CTL_FIFO_PERR_SET2 |
6318 		  F_ALIGN_CTL_FIFO_PERR_SET1 | F_ALIGN_CTL_FIFO_PERR_SET0,
6319 		  "Align control FIFO parity error" },
6320 		{ F_SGE_FIFO_PERR_SET3 | F_SGE_FIFO_PERR_SET2 |
6321 		  F_SGE_FIFO_PERR_SET1 | F_SGE_FIFO_PERR_SET0,
6322 		  "SGE FIFO parity error" },
6323 		{ F_STAG_FIFO_PERR_SET3 | F_STAG_FIFO_PERR_SET2 |
6324 		  F_STAG_FIFO_PERR_SET1 | F_STAG_FIFO_PERR_SET0,
6325 		  "STAG FIFO parity error" },
6326 		{ F_MAP_FIFO_PERR_SET3 | F_MAP_FIFO_PERR_SET2 |
6327 		  F_MAP_FIFO_PERR_SET1 | F_MAP_FIFO_PERR_SET0,
6328 		  "MAP FIFO parity error" },
6329 		{ F_DMA_FIFO_PERR_SET3 | F_DMA_FIFO_PERR_SET2 |
6330 		  F_DMA_FIFO_PERR_SET1 | F_DMA_FIFO_PERR_SET0,
6331 		  "DMA FIFO parity error" },
6332 		{ F_FSO_HDR_SRAM_PERR_SET3 | F_FSO_HDR_SRAM_PERR_SET2 |
6333 		  F_FSO_HDR_SRAM_PERR_SET1 | F_FSO_HDR_SRAM_PERR_SET0,
6334 		  "FSO HDR memory parity error" },
6335 		{ F_T10_PI_SRAM_PERR_SET3 | F_T10_PI_SRAM_PERR_SET2 |
6336 		  F_T10_PI_SRAM_PERR_SET1 | F_T10_PI_SRAM_PERR_SET0,
6337 		  "T10 PI memory parity error" },
6338 		{ 0 }
6339 	};
6340 	static const struct intr_info ulptx_intr_info2 = {
6341 		.name = "ULP_TX_INT_CAUSE_2",
6342 		.cause_reg = A_ULP_TX_INT_CAUSE_2,
6343 		.enable_reg = A_ULP_TX_INT_ENABLE_2,
6344 		.fatal = 0xffffffff,
6345 		.flags = IHF_FATAL_IFF_ENABLED,
6346 		.details = ulptx_int_cause_2_details,
6347 		.actions = NULL,
6348 	};
6349 	static const struct intr_details ulptx_int_cause_3_details[] = {
6350 		{ F_GF_SGE_FIFO_PARERR3 | F_GF_SGE_FIFO_PARERR2 |
6351 		  F_GF_SGE_FIFO_PARERR1 | F_GF_SGE_FIFO_PARERR0,
6352 		  "GF SGE interface FIFO parity error" },
6353 		{ F_DEDUPE_SGE_FIFO_PARERR3 | F_DEDUPE_SGE_FIFO_PARERR2 |
6354 		  F_DEDUPE_SGE_FIFO_PARERR1 | F_DEDUPE_SGE_FIFO_PARERR0,
6355 		  "DeDupe SGE interface FIFO parity error" },
6356 		{ F_GF3_DSGL_FIFO_PARERR | F_GF2_DSGL_FIFO_PARERR |
6357 		  F_GF1_DSGL_FIFO_PARERR | F_GF0_DSGL_FIFO_PARERR,
6358 		  "GF DSGL FIFO parity error" },
6359 		{ F_DEDUPE3_DSGL_FIFO_PARERR | F_DEDUPE2_DSGL_FIFO_PARERR |
6360 		  F_DEDUPE1_DSGL_FIFO_PARERR | F_DEDUPE0_DSGL_FIFO_PARERR,
6361 		  "DeDupe DSGL FIFO parity error" },
6362 		{ F_XP10_SGE_FIFO_PARERR, "XP10 SGE FIFO parity error (Ch0)" },
6363 		{ F_DSGL_PAR_ERR, "XP10 DSGL interface parity error" },
6364 		{ F_CDDIP_INT, "XP10 decompression interrupt" },
6365 		{ F_CCEIP_INT, "XP10 compression interrupt" },
6366 		{ F_TLS_SGE_FIFO_PARERR3 | F_TLS_SGE_FIFO_PARERR2 |
6367 		  F_TLS_SGE_FIFO_PARERR1 | F_TLS_SGE_FIFO_PARERR0,
6368 		  "TLS Glue SGE FIFO parity error" },
6369 		{ F_ULP2SMARBT_RSP_PERR, "ULP2SMARBT response data/CTL parity error" },
6370 		{ F_ULPTX2MA_RSP_PERR, "ULP2MA response data/CTL parity error" },
6371 		{ F_PCIE2ULP_PERR3 | F_PCIE2ULP_PERR2 |
6372 		  F_PCIE2ULP_PERR1 | F_PCIE2ULP_PERR0,
6373 		  "PCIE2ULP EDMA response parity error" },
6374 		{ F_CIM2ULP_PERR, "CIM2ULP command parity error (all ports)" },
6375 		{ 0 }
6376 	};
6377 	static const struct intr_info ulptx_intr_info3 = {
6378 		.name = "ULP_TX_INT_CAUSE_3",
6379 		.cause_reg = A_ULP_TX_INT_CAUSE_3,
6380 		.enable_reg = A_ULP_TX_INT_ENABLE_3,
6381 		.fatal = 0xffffffff,
6382 		.flags = IHF_FATAL_IFF_ENABLED,
6383 		.details = ulptx_int_cause_3_details,
6384 		.actions = NULL,
6385 	};
6386 	static const struct intr_details ulptx_int_cause_4_details[] = {
6387 		{ F_XP10_2_ULP_PERR, "XP10 to ULP parity error" },
6388 		{ F_ULP_2_XP10_PERR, "ULP to XP10 parity error" },
6389 		{ F_CMD_FIFO_LB1 | F_CMD_FIFO_LB0,
6390 		  "Command FIFO LB error" },
6391 		{ F_TF_TP_PERR, "TF TP parity error" },
6392 		{ F_TF_SGE_PERR, "TF SGE parity error" },
6393 		{ F_TF_MEM_PERR, "TF memory parity error" },
6394 		{ F_TF_MP_PERR, "TF MP parity error" },
6395 		{ 0 }
6396 	};
6397 	static const struct intr_info ulptx_intr_info4 = {
6398 		.name = "ULP_TX_INT_CAUSE_4",
6399 		.cause_reg = A_ULP_TX_INT_CAUSE_4,
6400 		.enable_reg = A_ULP_TX_INT_ENABLE_4,
6401 		.fatal = 0xffffffff,
6402 		.flags = IHF_FATAL_IFF_ENABLED,
6403 		.details = ulptx_int_cause_4_details,
6404 		.actions = NULL,
6405 	};
6406 	static const struct intr_details ulptx_int_cause_5_details[] = {
6407 		{ F_DEDUPE_PERR3 | F_DEDUPE_PERR2 |
6408 		  F_DEDUPE_PERR1 | F_DEDUPE_PERR0,
6409 		  "DeDupe parity error" },
6410 		{ F_GF_PERR3 | F_GF_PERR2 |
6411 		  F_GF_PERR1 | F_GF_PERR0,
6412 		  "GF parity error" },
6413 		{ F_SGE2ULP_INV_PERR, "SGE2ULP invalid parity error" },
6414 		{ F_T7_PL_BUSPERR, "PL bus parity error" },
6415 		{ F_TLSTX2ULPTX_PERR3 | F_TLSTX2ULPTX_PERR2 |
6416 		  F_TLSTX2ULPTX_PERR1 | F_TLSTX2ULPTX_PERR0,
6417 		  "TLS to ULP parity error" },
6418 		{ F_XP10_2_ULP_PL_PERR, "XP10 to ULP PL parity error" },
6419 		{ F_ULP_2_XP10_PL_PERR, "ULP to XP10 PL parity error" },
6420 		{ 0 }
6421 	};
6422 	static const struct intr_info ulptx_intr_info5 = {
6423 		.name = "ULP_TX_INT_CAUSE_5",
6424 		.cause_reg = A_ULP_TX_INT_CAUSE_5,
6425 		.enable_reg = A_ULP_TX_INT_ENABLE_5,
6426 		.fatal = 0xffffffff,
6427 		.flags = IHF_FATAL_IFF_ENABLED,
6428 		.details = ulptx_int_cause_5_details,
6429 		.actions = NULL,
6430 	};
6431 	static const struct intr_details ulptx_int_cause_6_details[] = {
6432 		{ F_DDR_HDR_FIFO_PERR_SET3 | F_DDR_HDR_FIFO_PERR_SET2 |
6433 		  F_DDR_HDR_FIFO_PERR_SET1 | F_DDR_HDR_FIFO_PERR_SET0,
6434 		  "DDR HDR FIFO parity error" },
6435 		{ F_PRE_MP_RSP_PERR_SET3 | F_PRE_MP_RSP_PERR_SET2 |
6436 		  F_PRE_MP_RSP_PERR_SET1 | F_PRE_MP_RSP_PERR_SET0,
6437 		  "Pre-MP response parity error" },
6438 		{ F_PRE_CQE_FIFO_PERR_SET3 | F_PRE_CQE_FIFO_PERR_SET2 |
6439 		  F_PRE_CQE_FIFO_PERR_SET1 | F_PRE_CQE_FIFO_PERR_SET0,
6440 		  "Pre-CQE FIFO parity error" },
6441 		{ F_RSP_FIFO_PERR_SET, "Response FIFO parity error" },
6442 		{ 0 }
6443 	};
6444 	static const struct intr_info ulptx_intr_info6 = {
6445 		.name = "ULP_TX_INT_CAUSE_6",
6446 		.cause_reg = A_ULP_TX_INT_CAUSE_6,
6447 		.enable_reg = A_ULP_TX_INT_ENABLE_6,
6448 		.fatal = 0xffffffff,
6449 		.flags = IHF_FATAL_IFF_ENABLED,
6450 		.details = ulptx_int_cause_6_details,
6451 		.actions = NULL,
6452 	};
6453 	static const struct intr_details ulptx_int_cause_7_details[] = {
6454 		{ F_TLS_SGE_FIFO_CORERR3 | F_TLS_SGE_FIFO_CORERR2 |
6455 		  F_TLS_SGE_FIFO_CORERR1 | F_TLS_SGE_FIFO_CORERR0,
6456 		  "TLS SGE FIFO correctable error" },
6457 		{ F_LSO_HDR_SRAM_CERR_SET3 | F_LSO_HDR_SRAM_CERR_SET2 |
6458 		  F_LSO_HDR_SRAM_CERR_SET1 | F_LSO_HDR_SRAM_CERR_SET0,
6459 		  "LSO HDR SRAM correctable error" },
6460 		{ F_CORE_CMD_FIFO_CERR_SET_CH3_LB1 | F_CORE_CMD_FIFO_CERR_SET_CH2_LB1 |
6461 		  F_CORE_CMD_FIFO_CERR_SET_CH1_LB1 | F_CORE_CMD_FIFO_CERR_SET_CH0_LB1,
6462 		  "Core command FIFO LB1 correctable error" },
6463 		{ F_CORE_CMD_FIFO_CERR_SET_CH3_LB0 | F_CORE_CMD_FIFO_CERR_SET_CH2_LB0 |
6464 		  F_CORE_CMD_FIFO_CERR_SET_CH1_LB0 | F_CORE_CMD_FIFO_CERR_SET_CH0_LB0,
6465 		  "Core command FIFO LB0 correctable error" },
6466 		{ F_CQE_FIFO_CERR_SET3 | F_CQE_FIFO_CERR_SET2 |
6467 		  F_CQE_FIFO_CERR_SET1 | F_CQE_FIFO_CERR_SET0,
6468 		  "CQE FIFO correctable error" },
6469 		{ F_PRE_CQE_FIFO_CERR_SET3 | F_PRE_CQE_FIFO_CERR_SET2 |
6470 		  F_PRE_CQE_FIFO_CERR_SET1 | F_PRE_CQE_FIFO_CERR_SET0,
6471 		  "Pre-CQE FIFO correctable error" },
6472 		{ 0 }
6473 	};
6474 	static const struct intr_info ulptx_intr_info7 = {
6475 		.name = "ULP_TX_INT_CAUSE_7",
6476 		.cause_reg = A_ULP_TX_INT_CAUSE_7,
6477 		.enable_reg = A_ULP_TX_INT_ENABLE_7,
6478 		.fatal = 0,
6479 		.flags = 0,
6480 		.details = ulptx_int_cause_7_details,
6481 		.actions = NULL,
6482 	};
6483 	static const struct intr_details ulptx_int_cause_8_details[] = {
6484 		{ F_MEM_RSP_FIFO_CERR_SET3 | F_MEM_RSP_FIFO_CERR_SET2 |
6485 		  F_MEM_RSP_FIFO_CERR_SET1 | F_MEM_RSP_FIFO_CERR_SET0,
6486 		  "Memory response FIFO correctable error" },
6487 		{ F_PI_SRAM_CERR_SET3 | F_PI_SRAM_CERR_SET2 |
6488 		  F_PI_SRAM_CERR_SET1 | F_PI_SRAM_CERR_SET0,
6489 		  "PI SRAM correctable error" },
6490 		{ F_PRE_MP_RSP_CERR_SET3 | F_PRE_MP_RSP_CERR_SET2 |
6491 		  F_PRE_MP_RSP_CERR_SET1 | F_PRE_MP_RSP_CERR_SET0,
6492 		  "Pre-MP response correctable error" },
6493 		{ F_DDR_HDR_FIFO_CERR_SET3 | F_DDR_HDR_FIFO_CERR_SET2 |
6494 		  F_DDR_HDR_FIFO_CERR_SET1 | F_DDR_HDR_FIFO_CERR_SET0,
6495 		  "DDR HDR FIFO correctable error" },
6496 		{ F_CMD_FIFO_CERR_SET3 | F_CMD_FIFO_CERR_SET2 |
6497 		  F_CMD_FIFO_CERR_SET1 | F_CMD_FIFO_CERR_SET0,
6498 		  "Command FIFO correctable error" },
6499 		{ F_GF_SGE_FIFO_CORERR3 | F_GF_SGE_FIFO_CORERR2 |
6500 		  F_GF_SGE_FIFO_CORERR1 | F_GF_SGE_FIFO_CORERR0,
6501 		  "GF SGE FIFO correctable error" },
6502 		{ F_DEDUPE_SGE_FIFO_CORERR3 | F_DEDUPE_SGE_FIFO_CORERR2 |
6503 		  F_DEDUPE_SGE_FIFO_CORERR1 | F_DEDUPE_SGE_FIFO_CORERR0,
6504 		  "DeDupe SGE FIFO correctable error" },
6505 		{ F_RSP_FIFO_CERR_SET, "Response FIFO correctable error" },
6506 		{ 0 }
6507 	};
6508 	static const struct intr_info ulptx_intr_info8 = {
6509 		.name = "ULP_TX_INT_CAUSE_8",
6510 		.cause_reg = A_ULP_TX_INT_CAUSE_8,
6511 		.enable_reg = A_ULP_TX_INT_ENABLE_8,
6512 		.fatal = 0,
6513 		.flags = 0,
6514 		.details = ulptx_int_cause_8_details,
6515 		.actions = NULL,
6516 	};
6517 	bool fatal = false;
6518 
6519 	if (chip_id(adap) > CHELSIO_T6) {
6520 		fatal |= t4_handle_intr(adap, &ulptx_intr_info1, 0, flags);
6521 		fatal |= t4_handle_intr(adap, &ulptx_intr_info2, 0, flags);
6522 		fatal |= t4_handle_intr(adap, &ulptx_intr_info3, 0, flags);
6523 		fatal |= t4_handle_intr(adap, &ulptx_intr_info4, 0, flags);
6524 		fatal |= t4_handle_intr(adap, &ulptx_intr_info5, 0, flags);
6525 		fatal |= t4_handle_intr(adap, &ulptx_intr_info6, 0, flags);
6526 		fatal |= t4_handle_intr(adap, &ulptx_intr_info7, 0, flags);
6527 		fatal |= t4_handle_intr(adap, &ulptx_intr_info8, 0, flags);
6528 	} else {
6529 		if (chip_id(adap) == CHELSIO_T6)
6530 			ulptx_intr_info.details = t6_ulptx_int_cause_details;
6531 		else
6532 			ulptx_intr_info.details = ulptx_intr_details;
6533 		fatal |= t4_handle_intr(adap, &ulptx_intr_info, 0, flags);
6534 		if (chip_id(adap) > CHELSIO_T4)
6535 			fatal |= t4_handle_intr(adap, &ulptx_intr_info2, 0, flags);
6536 	}
6537 
6538 	return (fatal);
6539 }
6540 
pmtx_dump_dbg_stats(struct adapter * adap,int arg,int flags)6541 static bool pmtx_dump_dbg_stats(struct adapter *adap, int arg, int flags)
6542 {
6543 	int i;
6544 	u32 data[17];
6545 
6546 	if (flags & IHF_NO_SHOW)
6547 		return (false);
6548 
6549 	t4_read_indirect(adap, A_PM_TX_DBG_CTRL, A_PM_TX_DBG_DATA, &data[0],
6550 	    ARRAY_SIZE(data), A_PM_TX_DBG_STAT0);
6551 	for (i = 0; i < ARRAY_SIZE(data); i++) {
6552 		CH_ALERT(adap, "  - PM_TX_DBG_STAT%u (0x%x) = 0x%08x\n", i,
6553 		    A_PM_TX_DBG_STAT0 + i, data[i]);
6554 	}
6555 
6556 	return (false);
6557 }
6558 
6559 /*
6560  * PM TX interrupt handler.
6561  */
pmtx_intr_handler(struct adapter * adap,int arg,int flags)6562 static bool pmtx_intr_handler(struct adapter *adap, int arg, int flags)
6563 {
6564 	static const struct intr_details t7_pmtx_int_cause_fields[] = {
6565 		{ F_MASTER_PERR, "PM_TX master parity error" },
6566 		{ F_T7_ZERO_C_CMD_ERROR, "PM_TX PCMD with zero length error" },
6567 		{ F_OESPI_COR_ERR, " oespi FIFO Correctable Error" },
6568 		{ F_ICSPI_COR_ERR, " icspi FIFO Correctable Error" },
6569 		{ F_ICSPI_OVFL, " icspi FIFO overflow" },
6570 		{ F_T7_PCMD_LEN_OVFL0, "PMTX channel 0 pcmd too large" },
6571 		{ F_T7_PCMD_LEN_OVFL1, "PMTX channel 1 pcmd too large" },
6572 		{ F_T7_PCMD_LEN_OVFL2, "PMTX channel 2 pcmd too large" },
6573 		{ F_PCMD_LEN_OVFL3, "PMTX channel 2 pcmd too large" },
6574 		{ F_T7_ZERO_C_CMD_ERROR, "PMTX 0-length pcmd" },
6575 		{ 0x00f00000, "PM_TX PCMD length larger than oespi capacity" },
6576 		{ 0x000f0000, "PM_TX icspi 2x FIFO Rx framing error" },
6577 		{ 0x0000f000, "PM_TX icspi FIFO Tx framing error" },
6578 		{ 0x00000f00, "PM_TX oespi FIFO Rx framing error" },
6579 		{ 0x000000f0, "PM_TX oespi FIFO Tx framing error" },
6580 		{ 0x0000000f, "PM_TX oespi 2x FIFO Tx framing error" },
6581 		{ 0 }
6582 	};
6583 	static const struct intr_details pmtx_int_cause_fields[] = {
6584 		{ F_PCMD_LEN_OVFL0, "PMTX channel 0 pcmd too large" },
6585 		{ F_PCMD_LEN_OVFL1, "PMTX channel 1 pcmd too large" },
6586 		{ F_PCMD_LEN_OVFL2, "PMTX channel 2 pcmd too large" },
6587 		{ F_ZERO_C_CMD_ERROR, "PMTX 0-length pcmd" },
6588 		{ 0x0f000000, "PMTX icspi FIFO2X Rx framing error" },
6589 		{ 0x00f00000, "PMTX icspi FIFO Rx framing error" },
6590 		{ 0x000f0000, "PMTX icspi FIFO Tx framing error" },
6591 		{ 0x0000f000, "PMTX oespi FIFO Rx framing error" },
6592 		{ 0x00000f00, "PMTX oespi FIFO Tx framing error" },
6593 		{ 0x000000f0, "PMTX oespi FIFO2X Tx framing error" },
6594 		{ F_OESPI_PAR_ERROR, "PMTX oespi parity error" },
6595 		{ F_DB_OPTIONS_PAR_ERROR, "PMTX db_options parity error" },
6596 		{ F_ICSPI_PAR_ERROR, "PMTX icspi parity error" },
6597 		{ F_C_PCMD_PAR_ERROR, "PMTX c_pcmd parity error" },
6598 		{ 0 }
6599 	};
6600 	static const struct intr_action pmtx_int_cause_actions[] = {
6601 		{ 0xffffffff, -1, pmtx_dump_dbg_stats },
6602 		{ 0 },
6603 	};
6604 	struct intr_info pmtx_int_cause = {
6605 		.name = "PM_TX_INT_CAUSE",
6606 		.cause_reg = A_PM_TX_INT_CAUSE,
6607 		.enable_reg = A_PM_TX_INT_ENABLE,
6608 		.fatal = 0xffffffff,
6609 		.flags = IHF_CLR_DELAYED,
6610 		.details = NULL,
6611 		.actions = pmtx_int_cause_actions,
6612 	};
6613 	static const struct intr_details pmtx_perr_cause_details[] = {
6614 		{ F_ICSPI_OVFL, "icspi FIFO Overflow" },
6615 		{ F_OSPI_OVERFLOW3_TX, " OSPI overflow on channel 3 error." },
6616 		{ F_OSPI_OVERFLOW2_TX, " OSPI overflow on channel 2 error." },
6617 		{ F_OSPI_OVERFLOW1_TX, " OSPI overflow on channel 1 error." },
6618 		{ F_OSPI_OVERFLOW0_TX, " OSPI overflow on channel 0 error." },
6619 		{ F_T7_BUNDLE_LEN_OVFL_EN, "This bit indicates bundle_len_ovfl_err." },
6620 		{ F_T7_M_INTFPERREN, "This bit indicates Parity error from MA interfaces." },
6621 		{ F_T7_1_SDC_ERR,
6622 			"SDC Error reported by Check PCMD which carries CRC16 from TP-CSide." },
6623 		{ F_MC_WCNT_FIFO_PERR, "MC Interface Write count FIFO Parity error" },
6624 		{ F_MC_WDATA_FIFO_PERR, "MC Interface Write Data FIFO Parity error" },
6625 		{ F_MC_RCNT_FIFO_PERR, "MC Interface Read count FIFO Parity error" },
6626 		{ F_MC_RDATA_FIFO_PERR, "MC Interface Read Data FIFO Parity error" },
6627 		{ F_TOKEN_PAR_ERROR, "c_pcmd, Token FIFO par error" },
6628 		{ F_BUNDLE_LEN_PAR_ERROR, "oespi par error" },
6629 		{ F_OESPI_PAR_ERROR, "oespi par error" },
6630 		{ F_DB_OPTIONS_PAR_ERROR, "db_options par error" },
6631 		{ F_ICSPI_PAR_ERROR, "icspi par error" },
6632 		{ F_C_PCMD_TOKEN_PAR_ERROR, "c_pcmd par error" },
6633 		{ 0 }
6634 	};
6635 	static struct intr_info pmtx_perr_cause = {
6636 		.name = "PM_TX_PERR_CAUSE",
6637 		.cause_reg = A_PM_TX_PERR_CAUSE,
6638 		.enable_reg = A_PM_TX_PERR_ENABLE,
6639 		.fatal = 0xffffffff,
6640 		.flags = 0,
6641 		.details = pmtx_perr_cause_details,
6642 		.actions = NULL,
6643 	};
6644 	bool fatal;
6645 
6646 	if (chip_id(adap) >= CHELSIO_T7)
6647 		pmtx_int_cause.details = t7_pmtx_int_cause_fields;
6648 	else
6649 		pmtx_int_cause.details = pmtx_int_cause_fields;
6650 	fatal = t4_handle_intr(adap, &pmtx_int_cause, 0, flags);
6651 	if (chip_id(adap) >= CHELSIO_T7)
6652 		fatal |= t4_handle_intr(adap, &pmtx_perr_cause, 0, flags);
6653 	clear_int_cause_reg(adap, &pmtx_int_cause, flags);
6654 
6655 	return (fatal);
6656 }
6657 
6658 /*
6659  * PM RX interrupt handler.
6660  */
pmrx_intr_handler(struct adapter * adap,int arg,int flags)6661 static bool pmrx_intr_handler(struct adapter *adap, int arg, int flags)
6662 {
6663 	static const struct intr_details t7_pmrx_int_cause_fields[] = {
6664 		{ F_MASTER_PERR, "PM_RX master parity error" },
6665 		{ 0x18000000, "PMRX ospi overflow" },
6666 		{ F_BUNDLE_LEN_OVFL, "PMRX bundle len FIFO overflow" },
6667 		{ F_SDC_ERR, "PMRX SDC error" },
6668 		{ F_ZERO_E_CMD_ERROR, "PMRX 0-length pcmd" },
6669 		{ 0x003c0000, "PMRX iespi FIFO2X Rx framing error" },
6670 		{ 0x0003c000, "PMRX iespi Rx framing error" },
6671 		{ 0x00003c00, "PMRX iespi Tx framing error" },
6672 		{ 0x00000300, "PMRX ocspi Rx framing error" },
6673 		{ 0x000000c0, "PMRX ocspi Tx framing error" },
6674 		{ 0x00000030, "PMRX ocspi FIFO2X Tx framing error" },
6675 		{ 0 }
6676 	};
6677 	static const struct intr_details pmrx_int_cause_fields[] = {
6678 		/* T6+ */
6679 		{ 0x18000000, "PMRX ospi overflow" },
6680 		{ F_MA_INTF_SDC_ERR, "PMRX MA interface SDC parity error" },
6681 		{ F_BUNDLE_LEN_PARERR, "PMRX bundle len FIFO parity error" },
6682 		{ F_BUNDLE_LEN_OVFL, "PMRX bundle len FIFO overflow" },
6683 		{ F_SDC_ERR, "PMRX SDC error" },
6684 
6685 		/* T4+ */
6686 		{ F_ZERO_E_CMD_ERROR, "PMRX 0-length pcmd" },
6687 		{ 0x003c0000, "PMRX iespi FIFO2X Rx framing error" },
6688 		{ 0x0003c000, "PMRX iespi Rx framing error" },
6689 		{ 0x00003c00, "PMRX iespi Tx framing error" },
6690 		{ 0x00000300, "PMRX ocspi Rx framing error" },
6691 		{ 0x000000c0, "PMRX ocspi Tx framing error" },
6692 		{ 0x00000030, "PMRX ocspi FIFO2X Tx framing error" },
6693 		{ F_OCSPI_PAR_ERROR, "PMRX ocspi parity error" },
6694 		{ F_DB_OPTIONS_PAR_ERROR, "PMRX db_options parity error" },
6695 		{ F_IESPI_PAR_ERROR, "PMRX iespi parity error" },
6696 		{ F_E_PCMD_PAR_ERROR, "PMRX e_pcmd parity error"},
6697 		{ 0 }
6698 	};
6699 	struct intr_info pmrx_int_cause = {
6700 		.name = "PM_RX_INT_CAUSE",
6701 		.cause_reg = A_PM_RX_INT_CAUSE,
6702 		.enable_reg = A_PM_RX_INT_ENABLE,
6703 		.fatal = 0x1fffffff,
6704 		.flags = IHF_FATAL_IFF_ENABLED | IHF_CLR_DELAYED,
6705 		.details = NULL,
6706 		.actions = NULL,
6707 	};
6708 	static const struct intr_details pm_rx_int_cause_2_details[] = {
6709 		{ F_CACHE_SRAM_ODD_CERR, "Cache Data Odd SRAM Correctable Error" },
6710 		{ F_CACHE_SRAM_EVEN_CERR, "Cache Data Even SRAM Correctable Error" },
6711 		{ F_CACHE_LRU_LEFT_CERR, "Cache LRU Left SRAM Correctable Error" },
6712 		{ F_CACHE_LRU_RIGHT_CERR, "Cache LRU Right SRAM Correctable Error" },
6713 		{ F_CACHE_ISLAND_CERR, "Cache Island SRAM Correctable Error" },
6714 		{ F_OCSPI_CERR, "ocspi FIFO Correctable Error" },
6715 		{ F_IESPI_CERR, "iespi FIFO Correctable Error" },
6716 		{ F_OCSPI2_RX_FRAMING_ERROR, "ocspi FIFO channel 2 Rx/wr framing error" },
6717 		{ F_OCSPI3_RX_FRAMING_ERROR, "ocspi FIFO channel 3 Rx/wr framing error" },
6718 		{ F_OCSPI2_TX_FRAMING_ERROR, "ocspi FIFO channel 2 Tx/rd framing error" },
6719 		{ F_OCSPI3_TX_FRAMING_ERROR, "ocspi FIFO channel 3 Tx/rd framing error" },
6720 		{ F_OCSPI2_OFIFO2X_TX_FRAMING_ERROR, "ocspi 2x FIFO 2 Tx/rd framing error" },
6721 		{ F_OCSPI3_OFIFO2X_TX_FRAMING_ERROR, "ocspi 2x FIFO 3 Tx/rd framing error" },
6722 		{ 0 }
6723 	};
6724 	static struct intr_info pmrx_int_cause2 = {
6725 		.name = "PM_RX_INT_CAUSE_2",
6726 		.cause_reg = A_PM_RX_INT_CAUSE_2,
6727 		.enable_reg = A_PM_RX_INT_ENABLE_2,
6728 		.fatal = 0x1fffffff,
6729 		.flags = IHF_FATAL_IFF_ENABLED,
6730 		.details = pm_rx_int_cause_2_details,
6731 		.actions = NULL,
6732 	};
6733 	static const struct intr_details pm_rx_perr_cause_details[] = {
6734 		{ F_T7_SDC_ERR, "SDC error. CRC provided by TP and PM didn't match." },
6735 		{ F_T7_MA_INTF_SDC_ERR, "MA intf SDC perr" },
6736 		{ F_E_PCMD_PERR, "ulp_rx 2 pm_rx PCMD interface parity error." },
6737 		{ F_CACHE_RSP_DFIFO_PERR, "Cache Response Data FIFO Parity error" },
6738 		{ F_CACHE_SRAM_ODD_PERR, "Cache Odd SRAM error" },
6739 		{ F_CACHE_SRAM_EVEN_PERR, "Cache Even SRAM error" },
6740 		{ F_CACHE_RSVD_PERR, "Cache Reserved Parity error" },
6741 		{ F_CACHE_LRU_LEFT_PERR, "Cache LRU Left SRAM error" },
6742 		{ F_CACHE_LRU_RIGHT_PERR, "Cache LRU Rigth SRAM error" },
6743 		{ F_CACHE_RSP_CMD_PERR, "Cache Response Command FIFO error" },
6744 		{ F_CACHE_SRAM_CMD_PERR, "Cache SRAM Command FIFO error" },
6745 		{ F_CACHE_MA_CMD_PERR, "Cache MA Command FIFO error" },
6746 		{ F_CACHE_TCAM_PERR, "Cache TCAM Parity error" },
6747 		{ F_CACHE_ISLAND_PERR, "Cache island SRAM Parity error" },
6748 		{ F_MC_WCNT_FIFO_PERR, "MC Interface Write count FIFO Parity error" },
6749 		{ F_MC_WDATA_FIFO_PERR, "MC Interface Write Data FIFO Parity error" },
6750 		{ F_MC_RCNT_FIFO_PERR, "MC Interface Read count FIFO Parity error" },
6751 		{ F_MC_RDATA_FIFO_PERR, "MC Interface Read Data FIFO Parity error" },
6752 		{ F_TOKEN_FIFO_PERR, "Token FIFO Parity error" },
6753 		{ F_T7_BUNDLE_LEN_PARERR, "Bundle len fifo had parity error." },
6754 		{ F_OCSPI_PAR_ERROR, "ocspi par error vector" },
6755 		{ F_DB_OPTIONS_PAR_ERROR, "db_options par error" },
6756 		{ F_IESPI_PAR_ERROR, "iespi par error" },
6757 		{ F_E_PCMD_PAR_ERROR, "e_pcmd par error" },
6758 		{ 0 }
6759 	};
6760 	static struct intr_info pmrx_perr_cause = {
6761 		.name = "PM_RX_PERR_CAUSE",
6762 		.cause_reg = A_PM_RX_PERR_CAUSE,
6763 		.enable_reg = A_PM_RX_PERR_ENABLE,
6764 		.fatal = 0x1fffffff,
6765 		.flags = IHF_FATAL_IFF_ENABLED,
6766 		.details = pm_rx_perr_cause_details,
6767 		.actions = NULL,
6768 	};
6769 	bool fatal;
6770 
6771 	if (chip_id(adap) >= CHELSIO_T7) {
6772 		pmrx_int_cause.details = t7_pmrx_int_cause_fields;
6773 		fatal = t4_handle_intr(adap, &pmrx_int_cause, 0, flags);
6774 		fatal |= t4_handle_intr(adap, &pmrx_int_cause2, 0, flags);
6775 		fatal |= t4_handle_intr(adap, &pmrx_perr_cause, 0, flags);
6776 	} else {
6777 		pmrx_int_cause.details = pmrx_int_cause_fields;
6778 		fatal = t4_handle_intr(adap, &pmrx_int_cause, 0, flags);
6779 	}
6780 	clear_int_cause_reg(adap, &pmrx_int_cause, flags);
6781 
6782 	return (fatal);
6783 }
6784 
6785 /*
6786  * CPL switch interrupt handler.
6787  */
cplsw_intr_handler(struct adapter * adap,int arg,int flags)6788 static bool cplsw_intr_handler(struct adapter *adap, int arg, int flags)
6789 {
6790 	static const struct intr_details cplsw_int_cause_fields[] = {
6791 		/* T7+ */
6792 		{ F_PERR_CPL_128TO128_3, "CPLSW 128TO128 FIFO3 parity error" },
6793 		{ F_PERR_CPL_128TO128_2, "CPLSW 128TO128 FIFO2 parity error" },
6794 		/* T5+ */
6795 		{ F_PERR_CPL_128TO128_1, "CPLSW 128TO128 FIFO1 parity error" },
6796 		{ F_PERR_CPL_128TO128_0, "CPLSW 128TO128 FIFO0 parity error" },
6797 
6798 		/* T4+ */
6799 		{ F_CIM_OP_MAP_PERR, "CPLSW CIM op_map parity error" },
6800 		{ F_CIM_OVFL_ERROR, "CPLSW CIM overflow" },
6801 		{ F_TP_FRAMING_ERROR, "CPLSW TP framing error" },
6802 		{ F_SGE_FRAMING_ERROR, "CPLSW SGE framing error" },
6803 		{ F_CIM_FRAMING_ERROR, "CPLSW CIM framing error" },
6804 		{ F_ZERO_SWITCH_ERROR, "CPLSW no-switch error" },
6805 		{ 0 }
6806 	};
6807 	static const struct intr_info cplsw_int_cause = {
6808 		.name = "CPL_INTR_CAUSE",
6809 		.cause_reg = A_CPL_INTR_CAUSE,
6810 		.enable_reg = A_CPL_INTR_ENABLE,
6811 		.fatal = 0xffffffff,
6812 		.flags = IHF_FATAL_IFF_ENABLED,
6813 		.details = cplsw_int_cause_fields,
6814 		.actions = NULL,
6815 	};
6816 
6817 	return (t4_handle_intr(adap, &cplsw_int_cause, 0, flags));
6818 }
6819 
6820 #define T4_LE_FATAL_MASK (F_PARITYERR | F_UNKNOWNCMD | F_REQQPARERR)
6821 #define T5_LE_FATAL_MASK (T4_LE_FATAL_MASK | F_VFPARERR)
6822 #define T6_LE_PERRCRC_MASK (F_PIPELINEERR | F_CLIPTCAMACCFAIL | \
6823     F_SRVSRAMACCFAIL | F_CLCAMCRCPARERR | F_CLCAMINTPERR | F_SSRAMINTPERR | \
6824     F_SRVSRAMPERR | F_VFSRAMPERR | F_TCAMINTPERR | F_TCAMCRCERR | \
6825     F_HASHTBLMEMACCERR | F_MAIFWRINTPERR | F_HASHTBLMEMCRCERR)
6826 #define T6_LE_FATAL_MASK (T6_LE_PERRCRC_MASK | F_T6_UNKNOWNCMD | \
6827     F_TCAMACCFAIL | F_HASHTBLACCFAIL | F_CMDTIDERR | F_CMDPRSRINTERR | \
6828     F_TOTCNTERR | F_CLCAMFIFOERR | F_CLIPSUBERR)
6829 #define T7_LE_FATAL_MASK (T6_LE_FATAL_MASK | F_CACHESRAMPERR | F_CACHEINTPERR)
6830 
6831 /*
6832  * LE interrupt handler.
6833  */
le_intr_handler(struct adapter * adap,int arg,int flags)6834 static bool le_intr_handler(struct adapter *adap, int arg, int flags)
6835 {
6836 	static const struct intr_details le_intr_details[] = {
6837 		{ F_REQQPARERR, "LE request queue parity error" },
6838 		{ F_UNKNOWNCMD, "LE unknown command" },
6839 		{ F_ACTRGNFULL, "LE active region full" },
6840 		{ F_PARITYERR, "LE parity error" },
6841 		{ F_LIPMISS, "LE LIP miss" },
6842 		{ F_LIP0, "LE 0 LIP error" },
6843 		{ 0 }
6844 	};
6845 	static const struct intr_details t6_le_intr_details[] = {
6846 		{ F_CACHEINTPERR, "Parity error in cache module" },
6847 		{ F_CACHESRAMPERR, "Parity error in data sram " },
6848 		{ F_CLIPSUBERR, "LE CLIP CAM reverse substitution error" },
6849 		{ F_CLCAMFIFOERR, "LE CLIP CAM internal FIFO error" },
6850 		{ F_CTCAMINVLDENT, "Invalid IPv6 CLIP TCAM entry" },
6851 		{ F_TCAMINVLDENT, "Invalid IPv6 TCAM entry" },
6852 		{ F_TOTCNTERR, "LE total active < TCAM count" },
6853 		{ F_CMDPRSRINTERR, "LE internal error in parser" },
6854 		{ F_CMDTIDERR, "Incorrect tid in LE command" },
6855 		{ F_T6_ACTRGNFULL, "LE active region full" },
6856 		{ F_T6_ACTCNTIPV6TZERO, "LE IPv6 active open TCAM counter -ve" },
6857 		{ F_T6_ACTCNTIPV4TZERO, "LE IPv4 active open TCAM counter -ve" },
6858 		{ F_T6_ACTCNTIPV6ZERO, "LE IPv6 active open counter -ve" },
6859 		{ F_T6_ACTCNTIPV4ZERO, "LE IPv4 active open counter -ve" },
6860 		{ F_HASHTBLACCFAIL, "Hash table read error (proto conflict)" },
6861 		{ F_TCAMACCFAIL, "LE TCAM access failure" },
6862 		{ F_T6_UNKNOWNCMD, "LE unknown command" },
6863 		{ F_T6_LIP0, "LE found 0 LIP during CLIP substitution" },
6864 		{ F_T6_LIPMISS, "LE CLIP lookup miss" },
6865 		{ T6_LE_PERRCRC_MASK, "LE parity/CRC error" },
6866 		{ 0 }
6867 	};
6868 	struct intr_info le_intr_info = {
6869 		.name = "LE_DB_INT_CAUSE",
6870 		.cause_reg = A_LE_DB_INT_CAUSE,
6871 		.enable_reg = A_LE_DB_INT_ENABLE,
6872 		.fatal = 0,
6873 		.flags = IHF_FATAL_IFF_ENABLED,
6874 		.details = NULL,
6875 		.actions = NULL,
6876 	};
6877 
6878 	if (chip_id(adap) <= CHELSIO_T5) {
6879 		le_intr_info.details = le_intr_details;
6880 		le_intr_info.fatal = T5_LE_FATAL_MASK;
6881 	} else {
6882 		le_intr_info.details = t6_le_intr_details;
6883 		if (chip_id(adap) < CHELSIO_T7)
6884 			le_intr_info.fatal = T6_LE_FATAL_MASK;
6885 		else
6886 			le_intr_info.fatal = T7_LE_FATAL_MASK;
6887 	}
6888 
6889 	return (t4_handle_intr(adap, &le_intr_info, 0, flags));
6890 }
6891 
6892 /*
6893  * MPS interrupt handler.
6894  */
mps_intr_handler(struct adapter * adap,int arg,int flags)6895 static bool mps_intr_handler(struct adapter *adap, int arg, int flags)
6896 {
6897 	static const struct intr_details mps_rx_perr_intr_details[] = {
6898 		{ 0xffffffff, "MPS Rx parity error" },
6899 		{ 0 }
6900 	};
6901 	static const struct intr_info mps_rx_perr_intr_info = {
6902 		.name = "MPS_RX_PERR_INT_CAUSE",
6903 		.cause_reg = A_MPS_RX_PERR_INT_CAUSE,
6904 		.enable_reg = A_MPS_RX_PERR_INT_ENABLE,
6905 		.fatal = 0xffffffff,
6906 		.flags = IHF_FATAL_IFF_ENABLED,
6907 		.details = mps_rx_perr_intr_details,
6908 		.actions = NULL,
6909 	};
6910 	static const struct intr_details mps_rx_func_intr_details[] = {
6911 		{ F_MTU_ERR3, "MTU error interrupt enable bit for loopback group 3" },
6912 		{ F_MTU_ERR2, "MTU error interrupt enable bit for loopback group 2" },
6913 		{ F_MTU_ERR1, "MTU error interrupt enable bit for loopback group 1" },
6914 		{ F_MTU_ERR0, "MTU error interrupt enable bit for loopback group 0" },
6915 		{ F_DBG_LEN_ERR, "Oring of len error in traffic transfer b/w internal modules" },
6916 		{ F_DBG_SPI_ERR, "Oring of spi error in traffic transfer b/w internal modules" },
6917 		{ F_DBG_SE_CNT_ERR, "Oring of se cnt error in traffic transfer" },
6918 		{ F_DBG_SPI_LEN_SE_CNT_ERR, "Oring of all se_cnt|len|spi errors" },
6919 		{ 0 }
6920 	};
6921 	static const struct intr_info mps_rx_func_intr_info = {
6922 		.name = "MPS_RX_FUNC_INT_CAUSE",
6923 		.cause_reg = A_MPS_RX_FUNC_INT_CAUSE,
6924 		.enable_reg = A_MPS_RX_FUNC_INT_ENABLE,
6925 		.fatal = 0xffffffff,
6926 		.flags = IHF_FATAL_IFF_ENABLED,
6927 		.details = mps_rx_func_intr_details,
6928 		.actions = NULL,
6929 	};
6930 	static const struct intr_details mpsrx_int_cause_2_details[] = {
6931 		{ F_CRYPTO2MPS_RX0_PERR | F_CRYPTO2MPS_RX1_PERR |
6932 			F_CRYPTO2MPS_RX2_PERR | F_CRYPTO2MPS_RX3_PERR,
6933 			"Crypto to MPS RX interface parity error" },
6934 		{ F_INIC2MPS_TX1_PERR | F_INIC2MPS_TX0_PERR,
6935 			"INIC to MPS TX interface parity error" },
6936 		{ F_XGMAC2MPS_RX1_PERR | F_XGMAC2MPS_RX0_PERR,
6937 			"XGMAC to MPS RX interface parity error" },
6938 		{ F_RX_FINAL_TF_FIFO_PERR,
6939 			"Final RX token FIFO output parity error" },
6940 		{ F_MPS_DWRR_FIFO_PERR,
6941 			"MPS DWRR MTU FIFO parity error" },
6942 		{ F_MAC_TF_FIFO_PERR,
6943 			"MAC token FIFO parity error" },
6944 		{ F_MAC2MPS_PT3_PERR | F_MAC2MPS_PT2_PERR |
6945 			F_MAC2MPS_PT1_PERR | F_MAC2MPS_PT0_PERR,
6946 			"MAC to MPS interface parity error" },
6947 		{ F_TP_LPBK_FIFO_PERR, "TP loopback FIFO parity error" },
6948 		{ F_TP_LPBK_TF_PERR, "Loopback token FIFO parity error" },
6949 		{ 0 }
6950 	};
6951 	static const struct intr_info mps_rx_perr_intr_info2 = {
6952 		.name = "MPS_RX_PERR_INT_CAUSE2",
6953 		.cause_reg = A_MPS_RX_PERR_INT_CAUSE2,
6954 		.enable_reg = A_MPS_RX_PERR_INT_ENABLE2,
6955 		.fatal = 0xffffffff,
6956 		.flags = IHF_FATAL_IFF_ENABLED,
6957 		.details = mpsrx_int_cause_2_details,
6958 		.actions = NULL,
6959 	};
6960 	static const struct intr_details mpsrx_int_cause_3_details[] = {
6961 		{ F_FIFO_REPL_CH3_CERR | F_FIFO_REPL_CH2_CERR |
6962 		  F_FIFO_REPL_CH1_CERR | F_FIFO_REPL_CH0_CERR,
6963 		  "Replication FIFO ECC error" },
6964 		{ F_VLAN_FILTER_RAM_CERR, "VLAN filter SRAM ECC error" },
6965 		{ F_MPS_RX_TD_STAT_FIFO_PERR_CH3 | F_MPS_RX_TD_STAT_FIFO_PERR_CH2 |
6966 		  F_MPS_RX_TD_STAT_FIFO_PERR_CH1 | F_MPS_RX_TD_STAT_FIFO_PERR_CH0,
6967 		  "MPS RX TD status descriptor FIFO parity error" },
6968 		{ F_RPLCT_HDR_FIFO_IN_PERR_CH3 | F_RPLCT_HDR_FIFO_IN_PERR_CH2 |
6969 		  F_RPLCT_HDR_FIFO_IN_PERR_CH1 | F_RPLCT_HDR_FIFO_IN_PERR_CH0,
6970 		  "MPS RX replication header input FIFO parity error" },
6971 		{ F_ID_FIFO_IN_PERR_CH3 | F_ID_FIFO_IN_PERR_CH2 |
6972 		  F_ID_FIFO_IN_PERR_CH1 | F_ID_FIFO_IN_PERR_CH0,
6973 		  "MPS RX replication ID input FIFO parity error" },
6974 		{ F_DESC_HDR2_PERR_CH3 | F_DESC_HDR2_PERR_CH2 |
6975 		  F_DESC_HDR2_PERR_CH1 | F_DESC_HDR2_PERR_CH0,
6976 		  "MPS RX replication descriptor/header2 FIFO parity error" },
6977 		{ F_FIFO_REPL_PERR_CH3 | F_FIFO_REPL_PERR_CH2 |
6978 		  F_FIFO_REPL_PERR_CH1 | F_FIFO_REPL_PERR_CH0,
6979 		  "Replication FIFO parity error" },
6980 		{ F_MPS_RX_TD_PERR_CH3 | F_MPS_RX_TD_PERR_CH2 |
6981 		  F_MPS_RX_TD_PERR_CH1 | F_MPS_RX_TD_PERR_CH0,
6982 		  "MPS RX TD input FIFO parity error" },
6983 		{ 0 }
6984 	};
6985 	static const struct intr_info mps_rx_perr_intr_info3 = {
6986 		.name = "MPS_RX_PERR_INT_CAUSE3",
6987 		.cause_reg = A_MPS_RX_PERR_INT_CAUSE3,
6988 		.enable_reg = A_MPS_RX_PERR_INT_ENABLE3,
6989 		.fatal = 0xffffffff,
6990 		.flags = IHF_FATAL_IFF_ENABLED,
6991 		.details = mpsrx_int_cause_3_details,
6992 		.actions = NULL,
6993 	};
6994 	static const struct intr_details mpsrx_int_cause_4_details[] = {
6995 		{ F_VNI_MULTICAST_FIFO_ECC_ERR_CH3 | F_VNI_MULTICAST_FIFO_ECC_ERR_CH2,
6996 		  "RX out VNI multicast SRAM ECC error" },
6997 		{ F_HASH_SRAM_CLS_ENG1 | F_HASH_SRAM_CLS_ENG0,
6998 		  "Classification engine hash SRAM ECC error" },
6999 		{ F_CLS_TCAM_SRAM_CLS_ENG1 | F_CLS_TCAM_SRAM_CLS_ENG0,
7000 		  "Classification engine TCAM SRAM ECC error" },
7001 		{ F_CLS_TCAM_CRC_SRAM_CLS_ENG1 | F_CLS_TCAM_CRC_SRAM_CLS_ENG0,
7002 		  "Classification engine TCAM CRC SRAM ECC error" },
7003 		{ F_DWRR_CH_FIFO_ECC_ERR, "DWRR output FIFO ECC error" },
7004 		{ F_MAC_RX_FIFO_ECC_ERR, "MAC RX FIFO ECC error" },
7005 		{ F_LPBK_RX_FIFO_ECC_ERR, "Loopback RX FIFO ECC error" },
7006 		{ F_CRS_DATA_STORE_N_FWD_CH3 | F_CRS_DATA_STORE_N_FWD_CH2 |
7007 		  F_CRS_DATA_STORE_N_FWD_CH1 | F_CRS_DATA_STORE_N_FWD_CH0,
7008 		  "CRS store and forward FIFO ECC error" },
7009 		{ F_TRACE_FWD_FIFO_CERR_CH3 | F_TRACE_FWD_FIFO_CERR_CH2 |
7010 		  F_TRACE_FWD_FIFO_CERR_CH1 | F_TRACE_FWD_FIFO_CERR_CH0,
7011 		  "Trace packet forward FIFO ECC error" },
7012 		{ F_TRANSPARENT_ENCAP_FWD_FIFO_CERR_CH3 | F_TRANSPARENT_ENCAP_FWD_FIFO_CERR_CH2 |
7013 		  F_TRANSPARENT_ENCAP_FWD_FIFO_CERR_CH1 | F_TRANSPARENT_ENCAP_FWD_FIFO_CERR_CH0,
7014 		  "Transparent encap forward FIFO ECC error" },
7015 		{ F_PTP_TRACE_FWD_FIFO_CERR_CH3 | F_PTP_TRACE_FWD_FIFO_CERR_CH2 |
7016 		  F_PTP_TRACE_FWD_FIFO_CERR_CH1 | F_PTP_TRACE_FWD_FIFO_CERR_CH0,
7017 		  "PTP packet forward FIFO ECC error" },
7018 		{ 0 }
7019 	};
7020 	static const struct intr_info mps_rx_perr_intr_info4 = {
7021 		.name = "MPS_RX_PERR_INT_CAUSE4",
7022 		.cause_reg = A_MPS_RX_PERR_INT_CAUSE4,
7023 		.enable_reg = A_MPS_RX_PERR_INT_ENABLE4,
7024 		.fatal = 0xffffffff,
7025 		.flags = IHF_FATAL_IFF_ENABLED,
7026 		.details = mpsrx_int_cause_4_details,
7027 		.actions = NULL,
7028 	};
7029 	static const struct intr_details mpsrx_int_cause_5_details[] = {
7030 		{ F_MPS2CRYP_RX_FIFO3_PERR | F_MPS2CRYP_RX_FIFO2_PERR |
7031 		  F_MPS2CRYP_RX_FIFO1_PERR | F_MPS2CRYP_RX_FIFO0_PERR,
7032 		  "MPS to Crypto RX interface FIFO parity error" },
7033 		{ F_VNI_MULTICAST_SRAM2_PERR | F_VNI_MULTICAST_SRAM1_PERR |
7034 		  F_VNI_MULTICAST_SRAM0_PERR,
7035 		  "VNI multicast SRAM parity error" },
7036 		{ F_MAC_MULTICAST_SRAM4_PERR | F_MAC_MULTICAST_SRAM3_PERR |
7037 		  F_MAC_MULTICAST_SRAM2_PERR | F_MAC_MULTICAST_SRAM1_PERR |
7038 		  F_MAC_MULTICAST_SRAM0_PERR,
7039 		  "MAC multicast SRAM parity error" },
7040 		{ F_MEM_WRAP_IPSEC_HDR_UPD_FIFO3_PERR | F_MEM_WRAP_IPSEC_HDR_UPD_FIFO2_PERR |
7041 		  F_MEM_WRAP_IPSEC_HDR_UPD_FIFO1_PERR | F_MEM_WRAP_IPSEC_HDR_UPD_FIFO0_PERR,
7042 		  "IPsec header update storing FIFO parity error" },
7043 		{ F_MEM_WRAP_CR2MPS_RX_FIFO3_PERR | F_MEM_WRAP_CR2MPS_RX_FIFO2_PERR |
7044 		  F_MEM_WRAP_CR2MPS_RX_FIFO1_PERR | F_MEM_WRAP_CR2MPS_RX_FIFO0_PERR,
7045 		  "IPsec storing FIFO parity error" },
7046 		{ F_MEM_WRAP_NON_IPSEC_FIFO3_PERR | F_MEM_WRAP_NON_IPSEC_FIFO2_PERR |
7047 		  F_MEM_WRAP_NON_IPSEC_FIFO1_PERR | F_MEM_WRAP_NON_IPSEC_FIFO0_PERR,
7048 		  "Non-IPsec storing FIFO parity error" },
7049 		{ F_MEM_WRAP_TP_DB_REQ_FIFO3_PERR | F_MEM_WRAP_TP_DB_REQ_FIFO2_PERR |
7050 		  F_MEM_WRAP_TP_DB_REQ_FIFO1_PERR | F_MEM_WRAP_TP_DB_REQ_FIFO0_PERR,
7051 		  "TP DB request storing FIFO parity error" },
7052 		{ F_MEM_WRAP_CNTRL_FIFO3_PERR | F_MEM_WRAP_CNTRL_FIFO2_PERR |
7053 		  F_MEM_WRAP_CNTRL_FIFO1_PERR | F_MEM_WRAP_CNTRL_FIFO0_PERR,
7054 		  "Header flit storing FIFO parity error" },
7055 		{ 0 }
7056 	};
7057 	static const struct intr_info mps_rx_perr_intr_info5 = {
7058 		.name = "MPS_RX_PERR_INT_CAUSE5",
7059 		.cause_reg = A_MPS_RX_PERR_INT_CAUSE5,
7060 		.enable_reg = A_MPS_RX_PERR_INT_ENABLE5,
7061 		.fatal = 0xffffffff,
7062 		.flags = IHF_FATAL_IFF_ENABLED,
7063 		.details = mpsrx_int_cause_5_details,
7064 		.actions = NULL,
7065 	};
7066 	static const struct intr_details mpsrx_int_cause_6_details[] = {
7067 		{ F_T7_MEM_WRAP_IPSEC_HDR_UPD_FIFO3_PERR | F_T7_MEM_WRAP_IPSEC_HDR_UPD_FIFO2_PERR |
7068 		  F_T7_MEM_WRAP_IPSEC_HDR_UPD_FIFO1_PERR | F_T7_MEM_WRAP_IPSEC_HDR_UPD_FIFO0_PERR,
7069 		  "IPsec header update storing FIFO parity error" },
7070 		{ F_MEM_WRAP_CR2MPS_UPDTD_HDR_FIFO3_PERR | F_MEM_WRAP_CR2MPS_UPDTD_HDR_FIFO2_PERR |
7071 		  F_MEM_WRAP_CR2MPS_UPDTD_HDR_FIFO1_PERR | F_MEM_WRAP_CR2MPS_UPDTD_HDR_FIFO0_PERR,
7072 		  "IPsec updated header only storing FIFO parity error" },
7073 		{ F_MEM_WRAP_CR2MPS_RX_FIFO3_PERR | F_MEM_WRAP_CR2MPS_RX_FIFO2_PERR |
7074 		  F_MEM_WRAP_CR2MPS_RX_FIFO1_PERR | F_MEM_WRAP_CR2MPS_RX_FIFO0_PERR,
7075 		  "IPsec storing FIFO parity error" },
7076 		{ F_MEM_WRAP_NON_IPSEC_FIFO3_PERR | F_MEM_WRAP_NON_IPSEC_FIFO2_PERR |
7077 		  F_MEM_WRAP_NON_IPSEC_FIFO1_PERR | F_MEM_WRAP_NON_IPSEC_FIFO0_PERR,
7078 		  "Non-IPsec storing FIFO parity error" },
7079 		{ F_MEM_WRAP_TP_DB_REQ_FIFO3_PERR | F_MEM_WRAP_TP_DB_REQ_FIFO2_PERR |
7080 		  F_MEM_WRAP_TP_DB_REQ_FIFO1_PERR | F_MEM_WRAP_TP_DB_REQ_FIFO0_PERR,
7081 		  "TP DB request storing FIFO parity error" },
7082 		{ F_MEM_WRAP_CNTRL_FIFO3_PERR | F_MEM_WRAP_CNTRL_FIFO2_PERR |
7083 		  F_MEM_WRAP_CNTRL_FIFO1_PERR | F_MEM_WRAP_CNTRL_FIFO0_PERR,
7084 		  "Header flit storing FIFO parity error" },
7085 		{ 0 }
7086 	};
7087 	static const struct intr_info mps_rx_perr_intr_info6 = {
7088 		.name = "MPS_RX_PERR_INT_CAUSE6",
7089 		.cause_reg = A_MPS_RX_PERR_INT_CAUSE6,
7090 		.enable_reg = A_MPS_RX_PERR_INT_ENABLE6,
7091 		.fatal = 0xffffffff,
7092 		.flags = IHF_FATAL_IFF_ENABLED,
7093 		.details = mpsrx_int_cause_6_details,
7094 		.actions = NULL,
7095 	};
7096 	static const struct intr_details t7_mpstx_int_cause_details[] = {
7097 		{ F_T7_PORTERR, "Tx received a frame for TP destined to a disable port" },
7098 		{ F_T7_FRMERR, "Framing error in received Data from TP or  Data to MAC" },
7099 		{ F_T7_SECNTERR, "SOP-EOP count error in received Data from TP or Data to MAC" },
7100 		{ F_T7_BUBBLE, "Valid is deasserted between SOP and EOP" },
7101 		{ F_TX_TF_FIFO_PERR, "Parity error of TX token fifo" },
7102 		{ F_TX_FIFO_PERR, "Parity error of TX MPS2MAC underrun fifo" },
7103 		{ 0x0003c000, "Parity error of fifo storing non-ipsec +1 flit ipsec pkt" },
7104 		{ 0x00003fc0, "Interface parity error on TP/Crypto to MPS TX" },
7105 		{ F_NCSI2MPS, "interface Parity Error on ncsi2mps_tx_ch3" },
7106 		{ F_NCSIFIFO, "Parity Error in mps_tx_arbiter input FIFO (from NCSI)" },
7107 		{ 0x0000000f, "Parity Error in mps_tx_arbiter input FIFO (from TP)" },
7108 		{ 0 }
7109 	};
7110 	static const struct intr_details mps_tx_intr_details[] = {
7111 		{ F_PORTERR, "MPS Tx destination port is disabled" },
7112 		{ F_FRMERR, "MPS Tx framing error" },
7113 		{ F_SECNTERR, "MPS Tx SOP/EOP error" },
7114 		{ F_BUBBLE, "MPS Tx underflow" },
7115 		{ V_TXDESCFIFO(M_TXDESCFIFO), "MPS Tx desc FIFO parity error" },
7116 		{ V_TXDATAFIFO(M_TXDATAFIFO), "MPS Tx data FIFO parity error" },
7117 		{ F_NCSIFIFO, "MPS Tx NC-SI FIFO parity error" },
7118 		{ V_TPFIFO(M_TPFIFO), "MPS Tx TP FIFO parity error" },
7119 		{ 0 }
7120 	};
7121 	struct intr_info mps_tx_intr_info = {
7122 		.name = "MPS_TX_INT_CAUSE",
7123 		.cause_reg = A_MPS_TX_INT_CAUSE,
7124 		.enable_reg = A_MPS_TX_INT_ENABLE,
7125 		.fatal = 0x1ffff,
7126 		.flags = IHF_FATAL_IFF_ENABLED,
7127 		.details = NULL,
7128 		.actions = NULL,
7129 	};
7130 	static const struct intr_details mpstx_int_cause_2_details[] = {
7131 		{ F_TX_FIFO_PERR, "ECC error of TX MPS2MAC underrun fifo" },
7132 		{ 0x0000000f, "ECC error of fifo storing non-ipsec +1 flit ipsec pkt" },
7133 		{ 0 }
7134 	};
7135 	static const struct intr_info mps_tx_intr_info2 = {
7136 		.name = "MPS_TX_INT2_CAUSE",
7137 		.cause_reg = A_MPS_TX_INT2_CAUSE,
7138 		.enable_reg = A_MPS_TX_INT2_ENABLE,
7139 		.fatal = 0xffffffff,
7140 		.flags = IHF_FATAL_IFF_ENABLED,
7141 		.details = mpstx_int_cause_2_details,
7142 		.actions = NULL,
7143 	};
7144 	static const struct intr_info mps_tx_intr_info3 = {
7145 		.name = "MPS_TX_INT3_CAUSE",
7146 		.cause_reg = A_MPS_TX_INT3_CAUSE,
7147 		.enable_reg = A_MPS_TX_INT3_ENABLE,
7148 		.fatal = 0xffffffff,
7149 		.flags = IHF_FATAL_IFF_ENABLED,
7150 		.details = NULL,
7151 		.actions = NULL,
7152 	};
7153 	static const struct intr_info mps_tx_intr_info4 = {
7154 		.name = "MPS_TX_INT4_CAUSE",
7155 		.cause_reg = A_MPS_TX_INT4_CAUSE,
7156 		.enable_reg = A_MPS_TX_INT4_ENABLE,
7157 		.fatal = 0xffffffff,
7158 		.flags = IHF_FATAL_IFF_ENABLED,
7159 		.details = NULL,
7160 		.actions = NULL,
7161 	};
7162 	static const struct intr_details mps_trc_intr_details[] = {
7163 		{ F_MISCPERR, "MPS TRC misc parity error" },
7164 		{ V_PKTFIFO(M_PKTFIFO), "MPS TRC packet FIFO parity error" },
7165 		{ V_FILTMEM(M_FILTMEM), "MPS TRC filter parity error" },
7166 		{ 0 }
7167 	};
7168 	static const struct intr_info mps_trc_intr_info = {
7169 		.name = "MPS_TRC_INT_CAUSE",
7170 		.cause_reg = A_MPS_TRC_INT_CAUSE,
7171 		.enable_reg = A_MPS_TRC_INT_ENABLE,
7172 		.fatal = F_MISCPERR | V_PKTFIFO(M_PKTFIFO) | V_FILTMEM(M_FILTMEM),
7173 		.flags = 0,
7174 		.details = mps_trc_intr_details,
7175 		.actions = NULL,
7176 	};
7177 	static const struct intr_details t7_mps_trc_intr_details[] = {
7178 		{ F_T7_TRCPLERRENB, "TRC PL error" },
7179 		{ F_T7_MISCPERR, "TRC header register parity error" },
7180 		{ 0x0000ff00, "TRC packet FIFO parity error" },
7181 		{ 0x000000ff, "TRC filter memory parity error" },
7182 		{ 0 }
7183 	};
7184 	static const struct intr_info t7_mps_trc_intr_info = {
7185 		.name = "MPS_TRC_INT_CAUSE",
7186 		.cause_reg = A_T7_MPS_TRC_INT_CAUSE,
7187 		.enable_reg = A_T7_MPS_TRC_INT_ENABLE,
7188 		.fatal = 0xffffffff,
7189 		.flags = IHF_FATAL_IFF_ENABLED,
7190 		.details = t7_mps_trc_intr_details,
7191 		.actions = NULL,
7192 	};
7193 	static const struct intr_details t7_trc_int_cause2_details[] = {
7194 		{ 0x0001e000, "TRC Tx2Rx down-converter correctable error" },
7195 		{ 0x00001800, "TRC MPS2MAC down-converter correctable error" },
7196 		{ 0x00000600, "TRC MAC2MPS down-converter correctable error" },
7197 		{ 0x000001e0, "TRC Tx2Rx down-converter parity error" },
7198 		{ 0x00000018, "TRC MAC2MPS down-converter parity error" },
7199 		{ 0x00000006, "TRC MPS2MAC down-converter parity error" },
7200 		{ 0 }
7201 	};
7202 	static const struct intr_info t7_mps_trc_intr_info2 = {
7203 		.name = "MPS_TRC_INT_CAUSE2",
7204 		.cause_reg = A_MPS_TRC_INT_CAUSE2,
7205 		.enable_reg = A_MPS_TRC_INT_ENABLE2,
7206 		.fatal = 0xffffffff,
7207 		.flags = IHF_FATAL_IFF_ENABLED,
7208 		.details = t7_trc_int_cause2_details,
7209 		.actions = NULL,
7210 	};
7211 	static const struct intr_details mps_stat_intr_details[] = {
7212 		{ F_PLREADSYNCERR, "MPS pl read sync error" },
7213 		{ 0 }
7214 	};
7215 	static const struct intr_info mps_stat_intr_info = {
7216 		.name = "MPS_STAT_INT_CAUSE",
7217 		.cause_reg = A_MPS_STAT_INT_CAUSE,
7218 		.enable_reg = A_MPS_STAT_INT_ENABLE,
7219 		.fatal = 0xf,
7220 		.flags = IHF_FATAL_IFF_ENABLED,
7221 		.details = mps_stat_intr_details,
7222 		.actions = NULL,
7223 	};
7224 	static const struct intr_details mps_stat_sram_intr_details[] = {
7225 		{ 0xffffffff, "MPS statistics SRAM parity error" },
7226 		{ 0 }
7227 	};
7228 	static const struct intr_info mps_stat_sram_intr_info = {
7229 		.name = "MPS_STAT_PERR_INT_CAUSE_SRAM",
7230 		.cause_reg = A_MPS_STAT_PERR_INT_CAUSE_SRAM,
7231 		.enable_reg = A_MPS_STAT_PERR_INT_ENABLE_SRAM,
7232 		.fatal = 0x1fffffff,
7233 		.flags = IHF_FATAL_IFF_ENABLED,
7234 		.details = mps_stat_sram_intr_details,
7235 		.actions = NULL,
7236 	};
7237 	static const struct intr_details mps_stat_tx_intr_details[] = {
7238 		{ 0xffffff, "MPS statistics Tx FIFO parity error" },
7239 		{ 0 }
7240 	};
7241 	static const struct intr_info mps_stat_tx_intr_info = {
7242 		.name = "MPS_STAT_PERR_INT_CAUSE_TX_FIFO",
7243 		.cause_reg = A_MPS_STAT_PERR_INT_CAUSE_TX_FIFO,
7244 		.enable_reg = A_MPS_STAT_PERR_INT_ENABLE_TX_FIFO,
7245 		.fatal =  0xffffff,
7246 		.flags = IHF_FATAL_IFF_ENABLED,
7247 		.details = mps_stat_tx_intr_details,
7248 		.actions = NULL,
7249 	};
7250 	static const struct intr_details mps_stat_rx_intr_details[] = {
7251 		{ 0xffffff, "MPS statistics Rx FIFO parity error" },
7252 		{ 0 }
7253 	};
7254 	static const struct intr_info mps_stat_rx_intr_info = {
7255 		.name = "MPS_STAT_PERR_INT_CAUSE_RX_FIFO",
7256 		.cause_reg = A_MPS_STAT_PERR_INT_CAUSE_RX_FIFO,
7257 		.enable_reg = A_MPS_STAT_PERR_INT_ENABLE_RX_FIFO,
7258 		.fatal =  0xffffff,
7259 		.flags = 0,
7260 		.details = mps_stat_rx_intr_details,
7261 		.actions = NULL,
7262 	};
7263 	static const struct intr_details mps_cls_intr_details[] = {
7264 		{ F_T7_PLERRENB, "PL error"},
7265 		{ F_CIM2MPS_INTF_PAR, "cim2mps interface parity"},
7266 		{ F_TCAM_CRC_SRAM, "tcam crc sram parity error"},
7267 		{ F_HASHSRAM, "MPS hash SRAM parity error" },
7268 		{ F_MATCHTCAM, "MPS match TCAM parity error" },
7269 		{ F_MATCHSRAM, "MPS match SRAM parity error" },
7270 		{ 0 }
7271 	};
7272 	static const struct intr_info mps_cls_intr_info = {
7273 		.name = "MPS_CLS_INT_CAUSE",
7274 		.cause_reg = A_MPS_CLS_INT_CAUSE,
7275 		.enable_reg = A_MPS_CLS_INT_ENABLE,
7276 		.fatal =  F_MATCHSRAM | F_MATCHTCAM | F_HASHSRAM,
7277 		.flags = 0,
7278 		.details = mps_cls_intr_details,
7279 		.actions = NULL,
7280 	};
7281 	static const struct intr_details mps_stat_sram1_intr_details[] = {
7282 		{ 0xff, "MPS statistics SRAM1 parity error" },
7283 		{ 0 }
7284 	};
7285 	static const struct intr_info mps_stat_sram1_intr_info = {
7286 		.name = "MPS_STAT_PERR_INT_CAUSE_SRAM1",
7287 		.cause_reg = A_MPS_STAT_PERR_INT_CAUSE_SRAM1,
7288 		.enable_reg = A_MPS_STAT_PERR_INT_ENABLE_SRAM1,
7289 		.fatal = 0xff,
7290 		.flags = 0,
7291 		.details = mps_stat_sram1_intr_details,
7292 		.actions = NULL,
7293 	};
7294 	bool fatal = false;
7295 	if (chip_id(adap) >= CHELSIO_T7)
7296 		mps_tx_intr_info.details = t7_mpstx_int_cause_details;
7297 	else
7298 		mps_tx_intr_info.details = mps_tx_intr_details;
7299 
7300 	fatal |= t4_handle_intr(adap, &mps_rx_perr_intr_info, 0, flags);
7301 	if (chip_id(adap) > CHELSIO_T6) {
7302 		fatal |= t4_handle_intr(adap, &mps_rx_func_intr_info, 0, flags);
7303 		fatal |= t4_handle_intr(adap, &mps_rx_perr_intr_info2, 0, flags);
7304 		fatal |= t4_handle_intr(adap, &mps_rx_perr_intr_info3, 0, flags);
7305 		fatal |= t4_handle_intr(adap, &mps_rx_perr_intr_info4, 0, flags);
7306 		fatal |= t4_handle_intr(adap, &mps_rx_perr_intr_info5, 0, flags);
7307 		fatal |= t4_handle_intr(adap, &mps_rx_perr_intr_info6, 0, flags);
7308 	}
7309 	fatal |= t4_handle_intr(adap, &mps_tx_intr_info, 0, flags);
7310 	if (chip_id(adap) > CHELSIO_T6) {
7311 		fatal |= t4_handle_intr(adap, &mps_tx_intr_info2, 0, flags);
7312 		fatal |= t4_handle_intr(adap, &mps_tx_intr_info3, 0, flags);
7313 		fatal |= t4_handle_intr(adap, &mps_tx_intr_info4, 0, flags);
7314 		fatal |= t4_handle_intr(adap, &t7_mps_trc_intr_info, 0, flags);
7315 		fatal |= t4_handle_intr(adap, &t7_mps_trc_intr_info2, 0, flags);
7316 	} else
7317 		fatal |= t4_handle_intr(adap, &mps_trc_intr_info, 0, flags);
7318 	fatal |= t4_handle_intr(adap, &mps_stat_intr_info, 0, flags);
7319 	fatal |= t4_handle_intr(adap, &mps_stat_sram_intr_info, 0, flags);
7320 	fatal |= t4_handle_intr(adap, &mps_stat_tx_intr_info, 0, flags);
7321 	fatal |= t4_handle_intr(adap, &mps_stat_rx_intr_info, 0, flags);
7322 	fatal |= t4_handle_intr(adap, &mps_cls_intr_info, 0, flags);
7323 	if (chip_id(adap) > CHELSIO_T4)
7324 		fatal |= t4_handle_intr(adap, &mps_stat_sram1_intr_info, 0, flags);
7325 
7326 	t4_write_reg(adap, A_MPS_INT_CAUSE, is_t4(adap) ? 0 : 0xffffffff);
7327 	t4_read_reg(adap, A_MPS_INT_CAUSE);	/* flush */
7328 
7329 	return (fatal);
7330 }
7331 
7332 /*
7333  * EDC/MC interrupt handler.
7334  */
mem_intr_handler(struct adapter * adap,int idx,int flags)7335 static bool mem_intr_handler(struct adapter *adap, int idx, int flags)
7336 {
7337 	static const char name[4][5] = { "EDC0", "EDC1", "MC0", "MC1" };
7338 	unsigned int count_reg = 0, v;
7339 	static const struct intr_details mem_intr_details[] = {
7340 		{ F_ECC_UE_INT_CAUSE, "Uncorrectable ECC data error(s)" },
7341 		{ F_ECC_CE_INT_CAUSE, "Correctable ECC data error(s)" },
7342 		{ F_PERR_INT_CAUSE, "FIFO parity error" },
7343 		{ 0 }
7344 	};
7345 	static const struct intr_details t7_mem_intr_details[] = {
7346 		{ F_DDRPHY_INT_CAUSE, "DDR PHY" },
7347 		{ F_DDRCTL_INT_CAUSE, "DDR Controller" },
7348 		{ F_T7_ECC_UE_INT_CAUSE, "Uncorrectable ECC data error(s)" },
7349 		{ F_T7_ECC_CE_INT_CAUSE, "Correctable ECC data error(s)" },
7350 		{ F_PERR_INT_CAUSE, "FIFO parity error" },
7351 		{ 0 }
7352 	};
7353 	char rname[32];
7354 	struct intr_info ii = {
7355 		.name = &rname[0],
7356 		.fatal = F_PERR_INT_CAUSE | F_ECC_UE_INT_CAUSE,
7357 		.flags = IHF_CLR_DELAYED,
7358 		.details = mem_intr_details,
7359 		.actions = NULL,
7360 	};
7361 	bool fatal = false;
7362 	int i = 0;
7363 
7364 	switch (idx) {
7365 	case MEM_EDC1: i = 1;
7366 		       /* fall through */
7367 	case MEM_EDC0:
7368 		snprintf(rname, sizeof(rname), "EDC%u_INT_CAUSE", i);
7369 		if (is_t4(adap)) {
7370 			ii.cause_reg = EDC_REG(A_EDC_INT_CAUSE, i);
7371 			ii.enable_reg = EDC_REG(A_EDC_INT_ENABLE, i);
7372 			count_reg = EDC_REG(A_EDC_ECC_STATUS, i);
7373 		} else {
7374 			ii.cause_reg = EDC_T5_REG(A_EDC_H_INT_CAUSE, i);
7375 			ii.enable_reg = EDC_T5_REG(A_EDC_H_INT_ENABLE, i);
7376 			count_reg = EDC_T5_REG(A_EDC_H_ECC_STATUS, i);
7377 		}
7378 		fatal |= t4_handle_intr(adap, &ii, 0, flags);
7379 		break;
7380 	case MEM_MC1:
7381 		if (is_t4(adap) || is_t6(adap))
7382 			return (false);
7383 		i = 1;
7384 	       /* fall through */
7385 	case MEM_MC0:
7386 		snprintf(rname, sizeof(rname), "MC%u_INT_CAUSE", i);
7387 		if (is_t4(adap)) {
7388 			ii.cause_reg = A_MC_INT_CAUSE;
7389 			ii.enable_reg = A_MC_INT_ENABLE;
7390 			count_reg = A_MC_ECC_STATUS;
7391 		} else if (chip_id(adap) < CHELSIO_T7) {
7392 			ii.cause_reg = MC_REG(A_MC_P_INT_CAUSE, i);
7393 			ii.enable_reg = MC_REG(A_MC_P_INT_ENABLE, i);
7394 			count_reg = MC_REG(A_MC_P_ECC_STATUS, i);
7395 		} else {
7396 			ii.cause_reg = MC_T7_REG(A_T7_MC_P_INT_CAUSE, i);
7397 			ii.enable_reg = MC_T7_REG(A_T7_MC_P_INT_ENABLE, i);
7398 			ii.fatal = F_PERR_INT_CAUSE | F_T7_ECC_UE_INT_CAUSE;
7399 			ii.details = t7_mem_intr_details;
7400 		}
7401 		fatal |= t4_handle_intr(adap, &ii, 0, flags);
7402 		break;
7403 	}
7404 
7405 	if (count_reg != 0) {
7406 		v = t4_read_reg(adap, count_reg);
7407 		if (v != 0) {
7408 			if (G_ECC_UECNT(v) != 0 && !(flags & IHF_NO_SHOW)) {
7409 				CH_ALERT(adap,
7410 				    "  %s: %u uncorrectable ECC data error(s)\n",
7411 				    name[idx], G_ECC_UECNT(v));
7412 			}
7413 			if (G_ECC_CECNT(v) != 0 && !(flags & IHF_NO_SHOW)) {
7414 				if (idx <= MEM_EDC1)
7415 					t4_edc_err_read(adap, idx);
7416 				CH_WARN_RATELIMIT(adap,
7417 				    "  %s: %u correctable ECC data error(s)\n",
7418 				    name[idx], G_ECC_CECNT(v));
7419 			}
7420 			t4_write_reg(adap, count_reg, 0xffffffff);
7421 		}
7422 	}
7423 	clear_int_cause_reg(adap, &ii, flags);
7424 	return (fatal);
7425 }
7426 
ma_wrap_status(struct adapter * adap,int arg,int flags)7427 static bool ma_wrap_status(struct adapter *adap, int arg, int flags)
7428 {
7429 	u32 v;
7430 
7431 	v = t4_read_reg(adap, A_MA_INT_WRAP_STATUS);
7432 	if (!(flags & IHF_NO_SHOW)) {
7433 		CH_ALERT(adap,
7434 		    "  MA address wrap-around by client %u to address %#x\n",
7435 		    G_MEM_WRAP_CLIENT_NUM(v), G_MEM_WRAP_ADDRESS(v) << 4);
7436 	}
7437 	t4_write_reg(adap, A_MA_INT_WRAP_STATUS, v);
7438 
7439 	return (false);
7440 }
7441 
7442 /*
7443  * MA interrupt handler.
7444  */
ma_intr_handler(struct adapter * adap,int arg,int flags)7445 static bool ma_intr_handler(struct adapter *adap, int arg, int flags)
7446 {
7447 	static const struct intr_action ma_intr_actions[] = {
7448 		{ F_MEM_WRAP_INT_CAUSE, -1, ma_wrap_status },
7449 		{ 0 },
7450 	};
7451 	static const struct intr_info ma_intr_info = {
7452 		.name = "MA_INT_CAUSE",
7453 		.cause_reg = A_MA_INT_CAUSE,
7454 		.enable_reg = A_MA_INT_ENABLE,
7455 		.fatal = F_MEM_PERR_INT_CAUSE | F_MEM_TO_INT_CAUSE,
7456 		.flags = IHF_FATAL_IFF_ENABLED,
7457 		.details = NULL,
7458 		.actions = ma_intr_actions,
7459 	};
7460 	static const struct intr_info ma_perr_status1 = {
7461 		.name = "MA_PARITY_ERROR_STATUS1",
7462 		.cause_reg = A_MA_PARITY_ERROR_STATUS1,
7463 		.enable_reg = A_MA_PARITY_ERROR_ENABLE1,
7464 		.fatal = 0xffffffff,
7465 		.flags = 0,
7466 		.details = NULL,
7467 		.actions = NULL,
7468 	};
7469 	static const struct intr_info ma_perr_status2 = {
7470 		.name = "MA_PARITY_ERROR_STATUS2",
7471 		.cause_reg = A_MA_PARITY_ERROR_STATUS2,
7472 		.enable_reg = A_MA_PARITY_ERROR_ENABLE2,
7473 		.fatal = 0xffffffff,
7474 		.flags = 0,
7475 		.details = NULL,
7476 		.actions = NULL,
7477 	};
7478 	bool fatal;
7479 
7480 	fatal = false;
7481 	fatal |= t4_handle_intr(adap, &ma_intr_info, 0, flags);
7482 	fatal |= t4_handle_intr(adap, &ma_perr_status1, 0, flags);
7483 	if (chip_id(adap) > CHELSIO_T4)
7484 		fatal |= t4_handle_intr(adap, &ma_perr_status2, 0, flags);
7485 
7486 	return (fatal);
7487 }
7488 
7489 /*
7490  * SMB interrupt handler.
7491  */
smb_intr_handler(struct adapter * adap,int arg,int flags)7492 static bool smb_intr_handler(struct adapter *adap, int arg, int flags)
7493 {
7494 	static const struct intr_details smb_int_cause_details[] = {
7495 		{ F_MSTTXFIFOPARINT, "Master has Parity Error in Tx Fifo" },
7496 		{ F_MSTRXFIFOPARINT, "Master has Parity Error in Rx Fifo" },
7497 		{ F_SLVFIFOPARINT, "Slave  has Parity Error in Fifo" },
7498 		{ F_SLVUNEXPBUSSTOPINT, "Slave get Unexpected BusStop" },
7499 		{ F_SLVUNEXPBUSSTARTINT, "Slave get Unexpected BusStart" },
7500 		{ F_SLVCOMMANDCODEINVINT, "Slave get Invalid Command Code" },
7501 		{ F_SLVBYTECNTERRINT, "Slave get Erroneous ByteCount value" },
7502 		{ F_SLVUNEXPACKMSTINT, "Slave get Unexpected Ack from Master" },
7503 		{ F_SLVUNEXPNACKMSTINT, "Slave get Unexpected Nack from Master" },
7504 		{ F_SLVNOBUSSTOPINT, "Slave did not get Bus Stop" },
7505 		{ F_SLVNOREPSTARTINT, "Slave has no Repeated Start" },
7506 		{ F_SLVRXADDRINT, "Slave has Address Error" },
7507 		{ F_SLVRXPECERRINT, "Slave has Pec Error" },
7508 		{ F_SLVPREPTOARPINT, "PL has invalid request" },
7509 		{ F_SLVTIMEOUTINT, "Slave has timed out" },
7510 		{ F_SLVERRINT, "Slave detected error during the current transfer" },
7511 		{ F_SLVDONEINT, "Slave has completed the current transaction" },
7512 		{ F_SLVRXRDYINT, "Slave has received bytes to be processed by uP" },
7513 		{ F_MSTTIMEOUTINT, "Master has timed out" },
7514 		{ F_MSTNACKINT, "Master has detected a NAck on the transfer" },
7515 		{ F_MSTLOSTARBINT, "Master has lost arbitration all the timeline" },
7516 		{ F_MSTDONEINT, "Master has completed the current transaction" },
7517 		{ 0 }
7518 	};
7519 	static const struct intr_info smb_int_cause = {
7520 		.name = "SMB_INT_CAUSE",
7521 		.cause_reg = A_SMB_INT_CAUSE,
7522 		.enable_reg = A_SMB_INT_ENABLE,
7523 		.fatal = F_SLVFIFOPARINT | F_MSTRXFIFOPARINT | F_MSTTXFIFOPARINT,
7524 		.flags = 0,
7525 		.details = smb_int_cause_details,
7526 		.actions = NULL,
7527 	};
7528 
7529 	return (t4_handle_intr(adap, &smb_int_cause, 0, flags));
7530 }
7531 
7532 /*
7533  * NC-SI interrupt handler.
7534  */
ncsi_intr_handler(struct adapter * adap,int arg,int flags)7535 static bool ncsi_intr_handler(struct adapter *adap, int arg, int flags)
7536 {
7537 	static const struct intr_details ncsi_int_cause_fields[] = {
7538 		{ F_CIM2NC_PERR, " CIM to NC parity error" },
7539 		{ F_CIM_DM_PRTY_ERR, "NC-SI CIM parity error" },
7540 		{ F_MPS_DM_PRTY_ERR, "NC-SI MPS parity error" },
7541 		{ F_TXFIFO_PRTY_ERR, "NC-SI Tx FIFO parity error" },
7542 		{ F_RXFIFO_PRTY_ERR, "NC-SI Rx FIFO parity error" },
7543 		{ 0 }
7544 	};
7545 	static const struct intr_info ncsi_int_cause = {
7546 		.name = "NCSI_INT_CAUSE",
7547 		.cause_reg = A_NCSI_INT_CAUSE,
7548 		.enable_reg = A_NCSI_INT_ENABLE,
7549 		.fatal = F_RXFIFO_PRTY_ERR | F_TXFIFO_PRTY_ERR |
7550 		    F_MPS_DM_PRTY_ERR | F_CIM_DM_PRTY_ERR,
7551 		.flags = 0,
7552 		.details = ncsi_int_cause_fields,
7553 		.actions = NULL,
7554 	};
7555 	static const struct intr_details ncsi_xgmac0_int_cause_details[] = {
7556 		{ F_XAUIPCSDECERR, "RGMII PCS DEC Error" },
7557 		{ F_RGMIIRXFIFOOVERFLOW, "RGMII receive FIFO over flow" },
7558 		{ F_RGMIIRXFIFOUNDERFLOW, "RGMII receive FIFO under flow" },
7559 		{ F_RXPKTSIZEERROR, "Receive over size packet" },
7560 		{ F_WOLPATDETECTED, "WOL pattern detected" },
7561 		{ 0x000e0000, "Tx FIFO parity error" },
7562 		{ 0x0001c000, "Rx FIFO parity error" },
7563 		{ F_TXFIFO_UNDERRUN, "Tx FIFO underrun" },
7564 		{ F_RXFIFO_OVERFLOW, "Rx FIFO overflow" },
7565 		{ 0x00000f00, "XAUI SERDES BIST error" },
7566 		{ 0x000000f0, "XAUI SERDES receive low signal change" },
7567 		{ F_XAUIPCSCTCERR, "XAUI PCS CTC FIFO error" },
7568 		{ F_XAUIPCSALIGNCHANGE, "XAUI PCS alignment change" },
7569 		{ F_RGMIILINKSTSCHANGE, "RGMII link status change" },
7570 		{ F_XGM_INT, "XGM Core embedded interrupt (2nd level)" },
7571 		{ 0 }
7572 	};
7573 	static const struct intr_info ncsi_xgmac0_int_cause = {
7574 		.name = "NCSI_XGMAC0_INT_CAUSE",
7575 		.cause_reg = A_NCSI_XGMAC0_INT_CAUSE,
7576 		.enable_reg = A_NCSI_XGMAC0_INT_ENABLE,
7577 		.fatal = 0,
7578 		.flags = 0,
7579 		.details = ncsi_xgmac0_int_cause_details,
7580 		.actions = NULL,
7581 	};
7582 	bool fatal = false;
7583 
7584 	fatal |= t4_handle_intr(adap, &ncsi_int_cause, 0, flags);
7585 	if (chip_id(adap) > CHELSIO_T6)
7586 		fatal |= t4_handle_intr(adap, &ncsi_xgmac0_int_cause, 0, flags);
7587 	return (fatal);
7588 }
7589 
7590 /*
7591  * MAC interrupt handler.
7592  */
mac_intr_handler(struct adapter * adap,int port,int flags)7593 static bool mac_intr_handler(struct adapter *adap, int port, int flags)
7594 {
7595 	static const struct intr_details mac_int_cause_cmn_details[] = {
7596 		{ 0x3fffc0, "HSS PLL lock error " },
7597 		{ F_FLOCK_ASSERTED, "frequency lock coming out of DPLL sub-block is asserted" },
7598 		{ F_FLOCK_LOST, "frequency lock coming out of DPLL sub-blocki is lost." },
7599 		{ F_PHASE_LOCK_ASSERTED, "PHASE LOCK from DPLL sub-block is asserted" },
7600 		{ F_PHASE_LOCK_LOST, "PHASE LOCK from DPLL sub-block is lost." },
7601 		{ F_LOCK_ASSERTED, "Lock from frac_n PLL inside t7_clk module is asserted" },
7602 		{ F_LOCK_LOST, "Lock from frac_n PLL inside t7_clk module is lost " },
7603 		{ 0 }
7604 	};
7605 	static const struct intr_info mac_int_cause_cmn = {
7606 		.name = "MAC_INT_CAUSE_CMN",
7607 		.cause_reg = A_MAC_INT_CAUSE_CMN,
7608 		.enable_reg = A_MAC_INT_EN_CMN,
7609 		.fatal = 0,
7610 		.flags = 0,
7611 		.details = mac_int_cause_cmn_details,
7612 		.actions = NULL,
7613 	};
7614 	static const struct intr_details mac_perr_int_cause_mtip_details[] = {
7615 		{ F_PERR_MAC0_TX, "MTIP MAC TX memory for MAC 0 (the 200G MAC for port 0)" },
7616 		{ F_PERR_MAC1_TX, "MTIP MAC TX memory for MAC 1 (the 200G MAC for port 1)" },
7617 		{ F_PERR_MAC2_TX, "MTIP MAC TX memory for MAC 2 (the 10-100G MAC for port 0)" },
7618 		{ F_PERR_MAC3_TX, "MTIP MAC TX memory for MAC 3 (the 10-100G MAC for port 1)" },
7619 		{ F_PERR_MAC4_TX, "MTIP MAC TX memory for MAC 4 (the 10-100G MAC for port 2)" },
7620 		{ F_PERR_MAC5_TX, "MTIP MAC TX memory for MAC 5 (the 10-100G MAC for port 3)" },
7621 		{ F_PERR_MAC0_RX, "MTIP MAC RX memory for MAC 0 (the 200G MAC for port 0)" },
7622 		{ F_PERR_MAC1_RX, "MTIP MAC RX memory for MAC 1 (the 200G MAC for port 1)" },
7623 		{ F_PERR_MAC2_RX, "MTIP MAC RX memory for MAC 2 (the 10-100G MAC for port 0)" },
7624 		{ F_PERR_MAC3_RX, "MTIP MAC RX memory for MAC 3 (the 10-100G MAC for port 1)" },
7625 		{ F_PERR_MAC4_RX, "MTIP MAC RX memory for MAC 4 (the 10-100G MAC for port 2)" },
7626 		{ F_PERR_MAC5_RX, "MTIP MAC RX memory for MAC 5 (the 10-100G MAC for port 3)" },
7627 		{ F_PERR_MAC_STAT_RX, "MTIP MAC RX statistics memory (1 for all 4 10-100G MACs)" },
7628 		{ F_PERR_MAC_STAT_TX, "MTIP MAC TX statistics memory (1 for all 4 10-100G MACs)" },
7629 		{ F_PERR_MAC_STAT_CAP, "MTIP MAC stat capture memory (1 for all 4 100G MACs)" },
7630 		{ 0 }
7631 	};
7632 	static const struct intr_info mac_perr_cause_mtip = {
7633 		.name = "MAC_PERR_INT_CAUSE_MTIP",
7634 		.cause_reg = A_MAC_PERR_INT_CAUSE_MTIP,
7635 		.enable_reg = A_MAC_PERR_INT_EN_MTIP,
7636 		.fatal = 0xffffffff,
7637 		.flags = IHF_FATAL_IFF_ENABLED | IHF_IGNORE_IF_DISABLED,
7638 		.details = mac_perr_int_cause_mtip_details,
7639 		.actions = NULL,
7640 	};
7641 	static const struct intr_details ios_intr_cause_quad0_details[] = {
7642 		{ F_Q0_MAILBOX_INT_ASSERT, "Etopus Quad0 Mailbox interrupt cause" },
7643 		{ 0x00f00000, "Etopus Quad0 training failure" },
7644 		{ 0x000f0000, "Etopus Quad0 training complete" },
7645 		{ 0x0000f000, "Etopus Quad0 AN TX interrupt" },
7646 		{ 0x00000f00, "Etopus Quad0 signal detect assertion" },
7647 		{ 0x000000f0, "Etopus Quad0 CDR LOL assertion" },
7648 		{ 0x0000000f, "Etopus Quad0 LOS signal assertion" },
7649 		{ 0 }
7650 	};
7651 	static const struct intr_details ios_intr_cause_quad1_details[] = {
7652 		{ F_Q1_MAILBOX_INT_ASSERT, "Etopus Quad1 Mailbox interrupt cause" },
7653 		{ 0x00f00000, "Etopus Quad1 training failure" },
7654 		{ 0x000f0000, "Etopus Quad1 training complete" },
7655 		{ 0x0000f000, "Etopus Quad1 AN TX interrupt" },
7656 		{ 0x00000f00, "Etopus Quad1 signal detect assertion" },
7657 		{ 0x000000f0, "Etopus Quad1 CDR LOL assertion" },
7658 		{ 0x0000000f, "Etopus Quad1 LOS signal assertion" },
7659 		{ 0 }
7660 	};
7661 	static const struct intr_info mac_ios_int_cause_quad0 = {
7662 		.name = "MAC_IOS_INTR_CAUSE_QUAD0",
7663 		.cause_reg = A_MAC_IOS_INTR_CAUSE_QUAD0,
7664 		.enable_reg = A_MAC_IOS_INTR_EN_QUAD0,
7665 		.fatal = 0,
7666 		.flags = 0,
7667 		.details = ios_intr_cause_quad0_details,
7668 		.actions = NULL,
7669 	};
7670 	static const struct intr_info mac_ios_int_cause_quad1 = {
7671 		.name = "MAC_IOS_INTR_CAUSE_QUAD1",
7672 		.cause_reg = A_MAC_IOS_INTR_CAUSE_QUAD1,
7673 		.enable_reg = A_MAC_IOS_INTR_EN_QUAD1,
7674 		.fatal = 0,
7675 		.flags = 0,
7676 		.details = ios_intr_cause_quad1_details,
7677 		.actions = NULL,
7678 	};
7679 	static const struct intr_details mac_intr_details[] = {
7680 		{ F_TXFIFO_PRTY_ERR, "MAC Tx FIFO parity error" },
7681 		{ F_RXFIFO_PRTY_ERR, "MAC Rx FIFO parity error" },
7682 		{ 0 }
7683 	};
7684 	static const struct intr_details t7_mac_int_cause_details[] = {
7685 		{ F_MAC2MPS_PERR_CAUSE, "MPS2MAC Data parity error per port" },
7686 		{ F_MAC_PPS_INT_CAUSE, "One second interrupt based on PTP timer" },
7687 		{ F_MAC_TX_TS_AVAIL_INT_CAUSE,
7688 			"Time stamp is available for the last IEEE 1588 event frame" },
7689 		{ F_MAC_PATDETWAKE_INT_CAUSE, "Wake up pattern match packet received" },
7690 		{ F_MAC_MAGIC_WAKE_INT_CAUSE, "Magic packet received" },
7691 		{ F_MAC_SIGDETCHG_INT_CAUSE, "Signal Detect Change" },
7692 		{ F_MAC_PCS_LINK_GOOD_CAUSE, "PCS link good (xaui pcsr or 1g)" },
7693 		{ F_MAC_PCS_LINK_FAIL_CAUSE, "PCS Failure (xaui pcsr or 1g)" },
7694 		{ F_RXFIFOOVERFLOW, "RX Fifo Over flow error" },
7695 		{ F_MAC_REM_FAULT_INT_CAUSE, "Remote fault received by XGMAC" },
7696 		{ F_MAC_LOC_FAULT_INT_CAUSE, "Local fault received by XGMAC" },
7697 		{ F_MAC_LINK_DOWN_INT_CAUSE, "Link is down" },
7698 		{ F_MAC_LINK_UP_INT_CAUSE, "Link is up" },
7699 		{ F_MAC_AN_DONE_INT_CAUSE, "Autonegotiation complete" },
7700 		{ F_MAC_AN_PGRD_INT_CAUSE, "An page received" },
7701 		{ F_MAC_TXFIFO_ERR_INT_CAUSE, "Tx FIFO parity error" },
7702 		{ F_MAC_RXFIFO_ERR_INT_CAUSE, "Rx FIFO parity error" },
7703 		{ 0 }
7704 	};
7705 	static const struct intr_details mac_perr_int_cause_details[] = {
7706 		{ F_T6_PERR_PKT_RAM, "WoL packet data memory" },
7707 		{ F_T6_PERR_MASK_RAM, "WoL mask memory" },
7708 		{ F_T6_PERR_CRC_RAM, "WoL CRC memory" },
7709 		{ 0 }
7710 	};
7711 	char name[32];
7712 	struct intr_info ii;
7713 	bool fatal = false;
7714 
7715 	if (port > 1 && is_t6(adap))
7716 		return (false);
7717 
7718 	if (is_t4(adap)) {
7719 		snprintf(name, sizeof(name), "XGMAC_PORT%u_INT_CAUSE", port);
7720 		ii.name = &name[0];
7721 		ii.cause_reg = PORT_REG(port, A_XGMAC_PORT_INT_CAUSE);
7722 		ii.enable_reg = PORT_REG(port, A_XGMAC_PORT_INT_EN);
7723 		ii.fatal = F_TXFIFO_PRTY_ERR | F_RXFIFO_PRTY_ERR;
7724 		ii.flags = 0;
7725 		ii.details = mac_intr_details;
7726 		ii.actions = NULL;
7727 	} else if (chip_id(adap) < CHELSIO_T7) {
7728 		snprintf(name, sizeof(name), "MAC_PORT%u_INT_CAUSE", port);
7729 		ii.name = &name[0];
7730 		ii.cause_reg = T5_PORT_REG(port, A_MAC_PORT_INT_CAUSE);
7731 		ii.enable_reg = T5_PORT_REG(port, A_MAC_PORT_INT_EN);
7732 		ii.fatal = F_TXFIFO_PRTY_ERR | F_RXFIFO_PRTY_ERR;
7733 		ii.flags = 0;
7734 		ii.details = mac_intr_details;
7735 		ii.actions = NULL;
7736 	} else {
7737 		snprintf(name, sizeof(name), "MAC_PORT%u_INT_CAUSE", port);
7738 		ii.name = &name[0];
7739 		ii.cause_reg = T7_PORT_REG(port, A_T7_MAC_PORT_INT_CAUSE);
7740 		ii.enable_reg = T7_PORT_REG(port, A_T7_MAC_PORT_INT_EN);
7741 		ii.fatal = 0xffffffff;
7742 		ii.flags = IHF_FATAL_IFF_ENABLED;
7743 		ii.details = t7_mac_int_cause_details;
7744 		ii.actions = NULL;
7745 	}
7746 	fatal |= t4_handle_intr(adap, &ii, 0, flags);
7747 	if (is_t4(adap))
7748 		return (fatal);
7749 
7750 	MPASS(chip_id(adap) >= CHELSIO_T5);
7751 	snprintf(name, sizeof(name), "MAC_PORT%u_PERR_INT_CAUSE", port);
7752 	if (chip_id(adap) > CHELSIO_T6) {
7753 		ii.name = &name[0];
7754 		ii.cause_reg = T7_PORT_REG(port, A_T7_MAC_PORT_PERR_INT_CAUSE);
7755 		ii.enable_reg = T7_PORT_REG(port, A_T7_MAC_PORT_PERR_INT_EN);
7756 		ii.fatal = 0xffffffff;
7757 		ii.flags = IHF_FATAL_IFF_ENABLED;
7758 		ii.details = mac_perr_int_cause_details;
7759 		ii.actions = NULL;
7760 	} else {
7761 		ii.name = &name[0];
7762 		ii.cause_reg = T5_PORT_REG(port, A_MAC_PORT_PERR_INT_CAUSE);
7763 		ii.enable_reg = T5_PORT_REG(port, A_MAC_PORT_PERR_INT_EN);
7764 		ii.fatal = 0xffffffff;
7765 		ii.flags = IHF_FATAL_IFF_ENABLED;
7766 		ii.details = NULL;
7767 		ii.actions = NULL;
7768 	}
7769 	fatal |= t4_handle_intr(adap, &ii, 0, flags);
7770 	if (is_t5(adap))
7771 		return (fatal);
7772 
7773 	MPASS(chip_id(adap) >= CHELSIO_T6);
7774 	snprintf(name, sizeof(name), "MAC_PORT%u_PERR_INT_CAUSE_100G", port);
7775 	if (chip_id(adap) > CHELSIO_T6) {
7776 		ii.name = &name[0];
7777 		ii.cause_reg = T7_PORT_REG(port, A_T7_MAC_PORT_PERR_INT_CAUSE_100G);
7778 		ii.enable_reg = T7_PORT_REG(port, A_T7_MAC_PORT_PERR_INT_EN_100G);
7779 		ii.fatal = 0xffffffff;
7780 		ii.flags = IHF_FATAL_IFF_ENABLED;
7781 		ii.details = NULL;
7782 		ii.actions = NULL;
7783 	} else {
7784 		ii.name = &name[0];
7785 		ii.cause_reg = T5_PORT_REG(port, A_MAC_PORT_PERR_INT_CAUSE_100G);
7786 		ii.enable_reg = T5_PORT_REG(port, A_MAC_PORT_PERR_INT_EN_100G);
7787 		ii.fatal = 0xffffffff;
7788 		ii.flags = IHF_FATAL_IFF_ENABLED;
7789 		ii.details = NULL;
7790 		ii.actions = NULL;
7791 	}
7792 	fatal |= t4_handle_intr(adap, &ii, 0, flags);
7793 	if (is_t6(adap))
7794 		return (fatal);
7795 
7796 	MPASS(chip_id(adap) >= CHELSIO_T7);
7797 	fatal |= t4_handle_intr(adap, &mac_int_cause_cmn, 0, flags);
7798 	fatal |= t4_handle_intr(adap, &mac_perr_cause_mtip, 0, flags);
7799 	fatal |= t4_handle_intr(adap, &mac_ios_int_cause_quad0, 0, flags);
7800 	fatal |= t4_handle_intr(adap, &mac_ios_int_cause_quad1, 0, flags);
7801 
7802 	return (fatal);
7803 }
7804 
pl_timeout_status(struct adapter * adap,int arg,int flags)7805 static bool pl_timeout_status(struct adapter *adap, int arg, int flags)
7806 {
7807 	if (flags & IHF_NO_SHOW)
7808 		return (false);
7809 
7810 	CH_ALERT(adap, "    PL_TIMEOUT_STATUS 0x%08x 0x%08x\n",
7811 	    t4_read_reg(adap, A_PL_TIMEOUT_STATUS0),
7812 	    t4_read_reg(adap, A_PL_TIMEOUT_STATUS1));
7813 
7814 	return (false);
7815 }
7816 
plpl_intr_handler(struct adapter * adap,int arg,int flags)7817 static bool plpl_intr_handler(struct adapter *adap, int arg, int flags)
7818 {
7819 	static const struct intr_details plpl_int_cause_fields[] = {
7820 		{ F_FATALPERR, "Fatal parity error" },
7821 		{ F_PERRVFID, "VFID_MAP parity error" },
7822 		{ 0 }
7823 	};
7824 	static const struct intr_details t5_plpl_int_cause_fields[] = {
7825 		{ F_PL_BUSPERR, "Bus parity error" },
7826 		{ F_FATALPERR, "Fatal parity error" },
7827 		{ F_INVALIDACCESS, "Global reserved memory access" },
7828 		{ F_TIMEOUT,  "Bus timeout" },
7829 		{ F_PLERR, "Module reserved access" },
7830 		{ 0 }
7831 	};
7832 	static const struct intr_action plpl_int_cause_actions[] = {
7833 		{ F_TIMEOUT, -1, pl_timeout_status },
7834 		{ 0 },
7835 	};
7836 	struct intr_info plpl_int_cause = {
7837 		.name = "PL_PL_INT_CAUSE",
7838 		.cause_reg = A_PL_PL_INT_CAUSE,
7839 		.enable_reg = A_PL_PL_INT_ENABLE,
7840 		.fatal = F_FATALPERR,
7841 		.flags = IHF_FATAL_IFF_ENABLED,
7842 		.details = NULL,
7843 		.actions = NULL,
7844 	};
7845 
7846 	if (is_t4(adap)) {
7847 		plpl_int_cause.fatal |= F_PERRVFID;
7848 		plpl_int_cause.details = plpl_int_cause_fields;
7849 	} else {
7850 		plpl_int_cause.fatal |= F_INVALIDACCESS;
7851 		plpl_int_cause.details = t5_plpl_int_cause_fields;
7852 		plpl_int_cause.actions = plpl_int_cause_actions;
7853 	}
7854 	return (t4_handle_intr(adap, &plpl_int_cause, 0, flags));
7855 }
7856 
7857 /* similar to t4_port_reg */
7858 static inline u32
t7_tlstx_reg(u8 instance,u8 channel,u32 reg)7859 t7_tlstx_reg(u8 instance, u8 channel, u32 reg)
7860 {
7861 	MPASS(instance <= 1);
7862 	MPASS(channel < NUM_TLS_TX_CH_INSTANCES);
7863 	return (instance * (CRYPTO_1_BASE_ADDR - CRYPTO_0_BASE_ADDR) +
7864 	    TLS_TX_CH_REG(reg, channel));
7865 }
7866 
7867 /*
7868  * CRYPTO (aka TLS_TX) interrupt handler.
7869  */
tlstx_intr_handler(struct adapter * adap,int idx,int flags)7870 static bool tlstx_intr_handler(struct adapter *adap, int idx, int flags)
7871 {
7872 	static const struct intr_details tlstx_int_cause_fields[] = {
7873 		{ F_KEX_CERR, "KEX SRAM Correctable error" },
7874 		{ F_KEYLENERR, "IPsec Key length error" },
7875 		{ F_INTF1_PERR, "Input Interface1 parity error" },
7876 		{ F_INTF0_PERR, "Input Interface0 parity error" },
7877 		{ F_KEX_PERR, "KEX SRAM Parity error" },
7878 		{ 0 }
7879 	};
7880 	struct intr_info ii = {
7881 		.fatal = F_KEX_PERR | F_INTF0_PERR | F_INTF1_PERR,
7882 		.flags = IHF_FATAL_IFF_ENABLED,
7883 		.details = tlstx_int_cause_fields,
7884 		.actions = NULL,
7885 	};
7886 	char name[32];
7887 	int ch;
7888 	bool fatal = false;
7889 
7890 	for (ch = 0; ch < NUM_TLS_TX_CH_INSTANCES; ch++) {
7891 		snprintf(name, sizeof(name), "TLSTX%u_CH%u_INT_CAUSE", idx, ch);
7892 		ii.name = &name[0];
7893 		ii.cause_reg = t7_tlstx_reg(idx, ch, A_TLS_TX_CH_INT_CAUSE);
7894 		ii.enable_reg = t7_tlstx_reg(idx, ch, A_TLS_TX_CH_INT_ENABLE);
7895 		fatal |= t4_handle_intr(adap, &ii, 0, flags);
7896 	}
7897 
7898 	return (fatal);
7899 }
7900 
7901 /*
7902  * HMA interrupt handler.
7903  */
hma_intr_handler(struct adapter * adap,int idx,int flags)7904 static bool hma_intr_handler(struct adapter *adap, int idx, int flags)
7905 {
7906 	static const struct intr_details hma_int_cause_fields[] = {
7907 		{ F_GK_UF_INT_CAUSE, "Gatekeeper underflow" },
7908 		{ F_IDTF_INT_CAUSE, "Invalid descriptor fault" },
7909 		{ F_OTF_INT_CAUSE, "Offset translation fault" },
7910 		{ F_RTF_INT_CAUSE, "Region translation fault" },
7911 		{ F_PCIEMST_INT_CAUSE, "PCIe master access error" },
7912 		{ F_MAMST_INT_CAUSE, "MA master access error" },
7913 		{ F_PERR_INT_CAUSE, "FIFO parity error" },
7914 		{ 0 }
7915 	};
7916 	static const struct intr_info hma_int_cause = {
7917 		.name = "HMA_INT_CAUSE",
7918 		.cause_reg = A_HMA_INT_CAUSE,
7919 		.enable_reg = A_HMA_INT_ENABLE,
7920 		.fatal = 7,
7921 		.flags = 0,
7922 		.details = hma_int_cause_fields,
7923 		.actions = NULL,
7924 	};
7925 
7926 	return (t4_handle_intr(adap, &hma_int_cause, 0, flags));
7927 }
7928 
7929 /*
7930  * CRYPTO_KEY interrupt handler.
7931  */
cryptokey_intr_handler(struct adapter * adap,int idx,int flags)7932 static bool cryptokey_intr_handler(struct adapter *adap, int idx, int flags)
7933 {
7934 	static const struct intr_details cryptokey_int_cause_fields[] = {
7935 		{ F_MA_FIFO_PERR, "MA arbiter FIFO parity error" },
7936 		{ F_MA_RSP_PERR, "MA response IF parity error" },
7937 		{ F_ING_CACHE_DATA_PERR, "Ingress key cache data parity error" },
7938 		{ F_ING_CACHE_TAG_PERR, "Ingress key cache tag parity error" },
7939 		{ F_LKP_KEY_REQ_PERR, "Ingress key req parity error" },
7940 		{ F_LKP_CLIP_TCAM_PERR, "Ingress LKP CLIP TCAM parity error" },
7941 		{ F_LKP_MAIN_TCAM_PERR, "Ingress LKP main TCAM parity error" },
7942 		{ F_EGR_KEY_REQ_PERR, "Egress key req or FIFO3 parity error" },
7943 		{ F_EGR_CACHE_DATA_PERR, "Egress key cache data parity error" },
7944 		{ F_EGR_CACHE_TAG_PERR, "Egress key cache tag parity error" },
7945 		{ F_CIM_PERR, "CIM interface parity error" },
7946 		{ F_MA_INV_RSP_TAG, "MA invalid response tag" },
7947 		{ F_ING_KEY_RANGE_ERR, "Ingress key range error" },
7948 		{ F_ING_MFIFO_OVFL, "Ingress MFIFO overflow" },
7949 		{ F_LKP_REQ_OVFL, "Ingress lookup FIFO overflow" },
7950 		{ F_EOK_WAIT_ERR, "EOK wait error" },
7951 		{ F_EGR_KEY_RANGE_ERR, "Egress key range error" },
7952 		{ F_EGR_MFIFO_OVFL, "Egress MFIFO overflow" },
7953 		{ F_SEQ_WRAP_HP_OVFL, "Sequence wrap (hi-pri)" },
7954 		{ F_SEQ_WRAP_LP_OVFL, "Sequence wrap (lo-pri)" },
7955 		{ F_EGR_SEQ_WRAP_HP, "Egress sequence wrap (hi-pri)" },
7956 		{ F_EGR_SEQ_WRAP_LP, "Egress sequence wrap (lo-pri)" },
7957 		{ 0 }
7958 	};
7959 	static const struct intr_info cryptokey_int_cause = {
7960 		.name = "CRYPTO_KEY_INT_CAUSE",
7961 		.cause_reg = A_CRYPTO_KEY_INT_CAUSE,
7962 		.enable_reg = A_CRYPTO_KEY_INT_ENABLE,
7963 		.fatal = 0xffffffff,
7964 		.flags = IHF_FATAL_IFF_ENABLED,
7965 		.details = cryptokey_int_cause_fields,
7966 		.actions = NULL,
7967 	};
7968 
7969 	return (t4_handle_intr(adap, &cryptokey_int_cause, 0, flags));
7970 }
7971 
7972 /*
7973  * GCACHE interrupt handler.
7974  */
gcache_intr_handler(struct adapter * adap,int idx,int flags)7975 static bool gcache_intr_handler(struct adapter *adap, int idx, int flags)
7976 {
7977 	static const struct intr_details gcache_int_cause_fields[] = {
7978 		{ F_GC1_SRAM_RSP_DATAQ_PERR_INT_CAUSE, "GC1 SRAM rsp dataq perr" },
7979 		{ F_GC0_SRAM_RSP_DATAQ_PERR_INT_CAUSE, "GC0 SRAM rsp dataq perr" },
7980 		{ F_GC1_WQDATA_FIFO_PERR_INT_CAUSE, "GC1 wqdata FIFO perr" },
7981 		{ F_GC0_WQDATA_FIFO_PERR_INT_CAUSE, "GC0 wqdata FIFO perr" },
7982 		{ F_GC1_RDTAG_QUEUE_PERR_INT_CAUSE, "GC1 rdtag queue perr" },
7983 		{ F_GC0_RDTAG_QUEUE_PERR_INT_CAUSE, "GC0 rdtag queue perr" },
7984 		{ F_GC1_SRAM_RDTAG_QUEUE_PERR_INT_CAUSE, "GC1 SRAM rdtag queue perr" },
7985 		{ F_GC0_SRAM_RDTAG_QUEUE_PERR_INT_CAUSE, "GC0 SRAM rdtag queue perr" },
7986 		{ F_GC1_RSP_PERR_INT_CAUSE, "GC1 rsp perr" },
7987 		{ F_GC0_RSP_PERR_INT_CAUSE, "GC0 rsp perr" },
7988 		{ F_GC1_LRU_UERR_INT_CAUSE, "GC1 lru uerr" },
7989 		{ F_GC0_LRU_UERR_INT_CAUSE, "GC0 lru uerr" },
7990 		{ F_GC1_TAG_UERR_INT_CAUSE, "GC1 tag uerr" },
7991 		{ F_GC0_TAG_UERR_INT_CAUSE, "GC0 tag uerr" },
7992 		{ F_GC1_LRU_CERR_INT_CAUSE, "GC1 lru cerr" },
7993 		{ F_GC0_LRU_CERR_INT_CAUSE, "GC0 lru cerr" },
7994 		{ F_GC1_TAG_CERR_INT_CAUSE, "GC1 tag cerr" },
7995 		{ F_GC0_TAG_CERR_INT_CAUSE, "GC0 tag cerr" },
7996 		{ F_GC1_CE_INT_CAUSE, "GC1 correctable error" },
7997 		{ F_GC0_CE_INT_CAUSE, "GC0 correctable error" },
7998 		{ F_GC1_UE_INT_CAUSE, "GC1 uncorrectable error" },
7999 		{ F_GC0_UE_INT_CAUSE, "GC0 uncorrectable error" },
8000 		{ F_GC1_CMD_PAR_INT_CAUSE, "GC1 cmd perr" },
8001 		{ F_GC1_DATA_PAR_INT_CAUSE, "GC1 data perr" },
8002 		{ F_GC0_CMD_PAR_INT_CAUSE, "GC0 cmd perr" },
8003 		{ F_GC0_DATA_PAR_INT_CAUSE, "GC0 data perr" },
8004 		{ F_ILLADDRACCESS1_INT_CAUSE, "GC1 illegal address access" },
8005 		{ F_ILLADDRACCESS0_INT_CAUSE, "GC0 illegal address access" },
8006 		{ 0 }
8007 	};
8008 	static const struct intr_info gcache_int_cause = {
8009 		.name = "GCACHE_INT_CAUSE",
8010 		.cause_reg = A_GCACHE_INT_CAUSE,
8011 		.enable_reg = A_GCACHE_INT_ENABLE,
8012 		.fatal = 0,
8013 		.flags = 0,
8014 		.details = gcache_int_cause_fields,
8015 		.actions = NULL,
8016 	};
8017 	return (t4_handle_intr(adap, &gcache_int_cause, 0, flags));
8018 }
8019 
8020 /*
8021  * ARM interrupt handler.
8022  */
arm_intr_handler(struct adapter * adap,int idx,int flags)8023 static bool arm_intr_handler(struct adapter *adap, int idx, int flags)
8024 {
8025 	static const struct intr_details arm_perr_int_cause0_details[] = {
8026 		{ F_INIC_WRDATA_FIFO_PERR, "INT CAUSE for INIC Write Data Fifo Parity Error" },
8027 		{ F_INIC_RDATA_FIFO_PERR, "INT CAUSE for INIC Read Data Fifo Parity Error" },
8028 		{ F_MSI_MEM_PERR, "INT CAUSE for MSI Memory Parity Error" },
8029 		{ 0x18000000, "INT CAUSE for ARM Doorbell SRAM Parity Error" },
8030 		{ F_EMMC_FIFOPARINT, "INT CAUSE for EMMC Fifo Parity Interrupt" },
8031 		{ F_ICB_RAM_PERR, "INT CAUSE for ICB SRAM Parity Error" },
8032 		{ F_MESS2AXI4_WRFIFO_PERR, "INT CAUSE for Message2AXI4 Write FIFO Parity Error" },
8033 		{ F_RC_WFIFO_OUTPERR, "INT CAUSE for AXI2RC Write FIFO Parity Error" },
8034 		{ 0x00600000, "INT CAUSE for AXI2RC SRAM Parity Error" },
8035 		{ F_MSI_FIFO_PAR_ERR, "INT CAUSE for APB2MSI FIFO Parity Error" },
8036 		{ F_INIC2MA_INTFPERR, "INT CAUSE for INIC to MA Interface Parity Error" },
8037 		{ F_RDATAFIFO0_PERR, "INT CAUSE for AXI2MA M0 Read Data Fifo Parity Error" },
8038 		{ F_RDATAFIFO1_PERR, "INT CAUSE for AXI2MA M1 Read Data Fifo Parity Error" },
8039 		{ F_WRDATAFIFO0_PERR, "INT CAUSE for AXI2MA M0 Write Data Fifo Parity Error" },
8040 		{ F_WRDATAFIFO1_PERR, "INT CAUSE for AXI2MA M1 Write Data Fifo Parity Error" },
8041 		{ F_WR512DATAFIFO0_PERR,
8042 			"INT CAUSE for AXI2MA M0 Write Data 512b Fifo Parity Error" },
8043 		{ F_WR512DATAFIFO1_PERR,
8044 			"INT CAUSE for AXI2MA M1 Write Data 512b Fifo Parity Error" },
8045 		{ F_ROBUFF_PARERR3, "INT CAUSE for Reorder Buffer Parity Error" },
8046 		{ F_ROBUFF_PARERR2, "INT CAUSE for Reorder Buffer Parity Error" },
8047 		{ F_ROBUFF_PARERR1, "INT CAUSE for Reorder Buffer Parity Error" },
8048 		{ F_ROBUFF_PARERR0, "INT CAUSE for Reorder Buffer Parity Error" },
8049 		{ F_MA2AXI_REQDATAPARERR, "INT CAUSE for MA2AXI Request Data Parity Error" },
8050 		{ F_MA2AXI_REQCTLPARERR, "INT CAUSE for MA2AXI Request Control Parity Error" },
8051 		{ F_MA_RSPPERR, "INT CAUSE for MA Response Parity Error" },
8052 		{ F_PCIE2MA_REQCTLPARERR, "INT CAUSE for PCIe to MA Control Parity Error" },
8053 		{ F_PCIE2MA_REQDATAPARERR, "INT CAUSE for PCIe to MA Data Parity Error" },
8054 		{ F_INIC2MA_REQCTLPARERR, "INT CAUSE for INIC to MA Control Parity Error" },
8055 		{ F_INIC2MA_REQDATAPARERR, "INT CAUSE for INIC to MA Data Parity Error" },
8056 		{ F_MA_RSPUE, "INT CAUSE for MA Response Uncorrectable Error" },
8057 		{ F_APB2PL_RSPDATAPERR, "INT CAUSE for APB2PL Response Data Parity Error" },
8058 		{ 0 }
8059 	};
8060 	static const struct intr_info arm_perr_cause0 = {
8061 		.name = "ARM_PERR_INT_CAUSE0",
8062 		.cause_reg = A_ARM_PERR_INT_CAUSE0,
8063 		.enable_reg = A_ARM_PERR_INT_ENB0,
8064 		.fatal = 0xffffffff,
8065 		.flags = IHF_IGNORE_IF_DISABLED | IHF_FATAL_IFF_ENABLED,
8066 		.details = arm_perr_int_cause0_details,
8067 		.actions = NULL,
8068 	};
8069 	static const struct intr_details arm_perr_int_cause1_details[] = {
8070 		{ F_ARWFIFO0_PERR, "AXI2MA M0 Read-Write FIFO Parity Error" },
8071 		{ F_ARWFIFO1_PERR, "AXI2MA M1 Read-Write FIFO Parity Error" },
8072 		{ F_ARWIDFIFO0_PERR, "AXI2MA M0 Read-Write ID FIFO Parity Error" },
8073 		{ F_ARWIDFIFO1_PERR, "AXI2MA M1 Read-Write ID FIFO Parity Error" },
8074 		{ F_ARIDFIFO0_PERR, "AXI2MA M0 Read FIFO Parity Error" },
8075 		{ F_ARIDFIFO1_PERR, "AXI2MA M1 Read FIFO Parity Error" },
8076 		{ F_RRSPADDR_FIFO0_PERR, "AXI2MA M0 Read Response Address FIFO Parity Error" },
8077 		{ F_RRSPADDR_FIFO1_PERR, "AXI2MA M1 Read Response Address FIFO Parity Error" },
8078 		{ F_WRSTRB_FIFO0_PERR, "AXI2MA M0 Write Strobe FIFO Parity Error" },
8079 		{ F_WRSTRB_FIFO1_PERR, "AXI2MA M1 Write Strobe FIFO Parity Error" },
8080 		{ F_MA2AXI_RSPDATAPARERR, "MA2AXI Response FIFO Parity Error" },
8081 		{ F_MA2AXI_DATA_PAR_ERR, "MA2AXI Write Data FIFO Parity Error" },
8082 		{ F_MA2AXI_WR_ORD_FIFO_PARERR, "MA2AXI Ordered Write Data FIFO Parity Error" },
8083 		{ F_NVME_DB_EMU_TRACKER_FIFO_PERR, "NVMe DB Emulation Tracker FIFO Parity Error" },
8084 		{ F_NVME_DB_EMU_QUEUE_AW_ADDR_FIFO_PERR,
8085 			"NVMe DB Emulation Queue AW Addr Parity Error" },
8086 		{ F_NVME_DB_EMU_INTERRUPT_OFFSET_FIFO_PERR,
8087 			"NVMe DB Emulation Interrupt Offset FIFO Parity Error" },
8088 		{ F_NVME_DB_EMU_ID_FIFO0_PERR, "NVMe DB Emulation ID FIFO0 Parity Error" },
8089 		{ F_NVME_DB_EMU_ID_FIFO1_PERR, "NVMe DB Emulation ID FIFO1 Parity Error" },
8090 		{ F_RC_ARWFIFO_PERR, "AXI2RC Read-Write FIFO Parity Error" },
8091 		{ F_RC_ARIDBURSTADDRFIFO_PERR,
8092 			"AXI2RC Read ID, Burst and Address FIFO Parity Error" },
8093 		{ F_RC_CFG_FIFO_PERR, "AXI2RC Config FIFO Parity Error" },
8094 		{ F_RC_RSPFIFO_PERR, "AXI2RC Response Parity Error" },
8095 		{ F_INIC_ARIDFIFO_PERR, "CCI2INIC Read ID FIFO Parity Error" },
8096 		{ F_INIC_ARWFIFO_PERR, "CCI2INIC Read-Write FIFO ontrol Parity Error" },
8097 		{ F_AXI2MA_128_RD_ADDR_SIZE_FIFO_PERR,
8098 			"AXI2MA(CCI2INIC) Read Address Size FIFO Parity Error" },
8099 		{ F_AXI2RC_128_RD_ADDR_SIZE_FIFO_PERR,
8100 			"AXI2RC Read Address Size FIFO Parity Error" },
8101 		{ F_ARM_MA_512B_RD_ADDR_SIZE_FIFO0_PERR,
8102 			"ARM_MA_512b Read Address Size FIFO0 Parity Error" },
8103 		{ F_ARM_MA_512B_RD_ADDR_SIZE_FIFO1_PERR,
8104 			"ARM_MA_512b Read Address Size FIFO1 Parity Error" },
8105 		{ F_ARM_MA_512B_ARB_FIFO_PERR, "ARM_MA_512b Arbiter FIFO Parity Error" },
8106 		{ F_PCIE_INIC_MA_ARB_FIFO_PERR, "PCIe-INIC Arbiter FIFO Parity Error" },
8107 		{ F_PCIE_INIC_ARB_RSPPERR, "PCIe-INIC Arbiter Response Parity Error" },
8108 		{ F_ITE_CACHE_PERR, "GIC500 ITE Cache SRAM Parity Error" },
8109 		{ 0 }
8110 	};
8111 	static const struct intr_info arm_perr_cause1 = {
8112 		.name = "ARM_PERR_INT_CAUSE1",
8113 		.cause_reg = A_ARM_PERR_INT_CAUSE1,
8114 		.enable_reg = A_ARM_PERR_INT_ENB1,
8115 		.fatal = 0xffffffff,
8116 		.flags = IHF_IGNORE_IF_DISABLED | IHF_FATAL_IFF_ENABLED,
8117 		.details = arm_perr_int_cause1_details,
8118 		.actions = NULL,
8119 	};
8120 	static const struct intr_details arm_perr_int_cause2_details[] = {
8121 		{ F_INIC_WSTRB_FIFO_PERR, "AXI2MA_128 INIC Write Strobe FIFO Parity Error" },
8122 		{ F_INIC_BID_FIFO_PERR, "AXI2MA_128 INIC bID FIFO Parity Error" },
8123 		{ F_CC_SRAM_PKA_PERR, "CryptoCell ram_pka_wrapper FIFO Parity Error" },
8124 		{ F_CC_SRAM_SEC_PERR, "CryptoCell sec_sram_wrapper FIFO Parity Error" },
8125 		{ F_MESS2AXI4_PARERR, "Message2AXI4 IBQ I/P Interface Parity Error" },
8126 		{ F_CCI2INIC_INTF_PARERR, "CCI2INIC Response Interface Parity Error" },
8127 		{ 0 }
8128 	};
8129 	static const struct intr_info arm_perr_cause2 = {
8130 		.name = "ARM_PERR_INT_CAUSE2",
8131 		.cause_reg = A_ARM_PERR_INT_CAUSE2,
8132 		.enable_reg = A_ARM_PERR_INT_ENB2,
8133 		.fatal = 0xffffffff,
8134 		.flags = IHF_IGNORE_IF_DISABLED | IHF_FATAL_IFF_ENABLED,
8135 		.details = arm_perr_int_cause2_details,
8136 		.actions = NULL,
8137 	};
8138 	static const struct intr_details arm_cerr_int_cause0_details[] = {
8139 		{ F_WRDATA_FIFO0_CERR, "AXI2MA M0 Write Data FIFO Correctable Error" },
8140 		{ F_WRDATA_FIFO1_CERR, "AXI2MA M1 Write Data FIFO Correctable Error" },
8141 		{ F_WR512DATAFIFO0_CERR, "AXI2MA M0 Write Data 512b FIFO Correctable Error" },
8142 		{ F_WR512DATAFIFO1_CERR, "AXI2MA M1 Write Data 512b FIFO Correctable Error" },
8143 		{ F_RDATAFIFO0_CERR, "AXI2MA M0 Read Data FIFO Correctable Error" },
8144 		{ F_RDATAFIFO1_CERR, "AXI2MA M1 Read Data FIFO Correctable Error" },
8145 		{ F_ROBUFF_CORERR0, "Reorder Buffer Correctable Error" },
8146 		{ F_ROBUFF_CORERR1, "Reorder Buffer Correctable Error" },
8147 		{ F_ROBUFF_CORERR2, "Reorder Buffer Correctable Error" },
8148 		{ F_ROBUFF_CORERR3, "Reorder Buffer Correctable Error" },
8149 		{ F_MA2AXI_RSPDATACORERR, "MA2AXI Response FIFO Correctable Error" },
8150 		{ 0x00180000, "AXI2RC SRAM Correctable Error" },
8151 		{ F_RC_WFIFO_OUTCERR, "AXI2RC Write FIFO Correctable Error" },
8152 		{ F_RC_RSPFIFO_CERR, "AXI2RC Response Correctable Error" },
8153 		{ F_MSI_MEM_CERR, "MSI Memory FIFO Correctable Error" },
8154 		{ F_INIC_WRDATA_FIFO_CERR, "INIC Write Data FIFO Correctable Error" },
8155 		{ F_INIC_RDATAFIFO_CERR, "INIC Read Data FIFO Correctable Error" },
8156 		{ 0x00003000, "ARM Doorbell SRAM Correctable Error" },
8157 		{ F_ICB_RAM_CERR, "ICB SRAM Parity Error" },
8158 		{ F_CC_SRAM_PKA_CERR, "CryptoCell ram_pka_wrapper FIFO Correctable Error" },
8159 		{ F_CC_SRAM_SEC_CERR, "CryptoCell sec_sram_wrapper FIFO Correctable Error" },
8160 		{ 0 }
8161 	};
8162 	static const struct intr_info arm_cerr_cause0 = {
8163 		.name = "ARM_CERR_INT_CAUSE0",
8164 		.cause_reg = A_ARM_CERR_INT_CAUSE0,
8165 		.enable_reg = A_ARM_CERR_INT_ENB0,
8166 		.fatal = 0,
8167 		.flags = IHF_IGNORE_IF_DISABLED | IHF_FATAL_IFF_ENABLED,
8168 		.details = arm_cerr_int_cause0_details,
8169 		.actions = NULL,
8170 	};
8171 	static const struct intr_details arm_err_int_cause0_details[] = {
8172 		{ F_STRB0_ERROR, "Strobe Error from AXI2MA 0" },
8173 		{ F_STRB1_ERROR, "Strobe Error from AXI2MA 1" },
8174 		{ F_PCIE_INIC_MA_ARB_INV_RSP_TAG, "Invalid Response Tag for PCIE-INIc MA ARB" },
8175 		{ F_ERROR0_NOCMD_DATA, "AXI2MA 0 No Command Data Error" },
8176 		{ F_ERROR1_NOCMD_DATA, "AXI2MA 1 No Command Data Error" },
8177 		{ F_INIC_STRB_ERROR, "AXI2MA_128b INIC Strobe Error" },
8178 		{ 0 }
8179 	};
8180 	static const struct intr_info arm_err_cause0 = {
8181 		.name = "ARM_ERR_INT_CAUSE0",
8182 		.cause_reg = A_ARM_ERR_INT_CAUSE0,
8183 		.enable_reg = A_ARM_ERR_INT_ENB0,
8184 		.fatal = 0,
8185 		.flags = IHF_IGNORE_IF_DISABLED | IHF_FATAL_IFF_ENABLED,
8186 		.details = arm_err_int_cause0_details,
8187 		.actions = NULL,
8188 	};
8189 
8190 	static const struct intr_details arm_peripheral_int_cause_details[] = {
8191 		{ F_TIMER_INT, "TIMER_INT" },
8192 		{ F_NVME_INT, "NVME_INT" },
8193 		{ F_EMMC_WAKEUP_INT, "EMMC_WAKEUP_INT" },
8194 		{ F_EMMC_INT, "EMMC_INT" },
8195 		{ F_USB_MC_INT, "USB_MC_INT" },
8196 		{ F_USB_DMA_INT, "USB_DMA_INT" },
8197 		{ 0 }
8198 	};
8199 	static const struct intr_info arm_periph_cause = {
8200 		.name = "ARM_PERIPHERAL_INT_CAUSE",
8201 		.cause_reg = A_ARM_PERIPHERAL_INT_CAUSE,
8202 		.enable_reg = A_ARM_PERIPHERAL_INT_ENB,
8203 		.fatal = 0,
8204 		.flags = IHF_IGNORE_IF_DISABLED | IHF_FATAL_IFF_ENABLED,
8205 		.details = arm_peripheral_int_cause_details,
8206 		.actions = NULL,
8207 	};
8208 	static const struct intr_details arm_arm_uart_int_cause_details[] = {
8209 		{ F_RX_FIFO_NOT_EMPTY, "intcause for uart rx fifo" },
8210 		{ F_TX_FIFO_EMPTY, "intcause for uart tx fifo" },
8211 		{ 0 }
8212 	};
8213 	static const struct intr_info arm_uart_cause = {
8214 		.name = "ARM_ARM_UART_INT_CAUSE",
8215 		.cause_reg = A_ARM_ARM_UART_INT_CAUSE,
8216 		.enable_reg = A_ARM_ARM_UART_INT_EN,
8217 		.fatal = 0,
8218 		.flags = IHF_FATAL_IFF_ENABLED,
8219 		.details = arm_arm_uart_int_cause_details,
8220 		.actions = NULL,
8221 	};
8222 	static const struct intr_details arm_nvme_db_emu_int_cause_details[] = {
8223 		{ F_INVALID_BRESP, "Invalid CCI Write Response" },
8224 		{ F_DATA_LEN_OF,
8225 			"Incorrect Write Request to be written to incorrect Devices/Regions" },
8226 		{ F_INVALID_EMU_ADDR, "Invalid Emulation Address Range Configuration" },
8227 		{ F_INVALID_AXI_ADDR_CFG, "Invalid AXI Address Configuration" },
8228 		{ 0 }
8229 	};
8230 	static const struct intr_info arm_nvme_db_emu_cause = {
8231 		.name = "ARM_NVME_DB_EMU_INT_CAUSE",
8232 		.cause_reg = A_ARM_NVME_DB_EMU_INT_CAUSE,
8233 		.enable_reg = A_ARM_NVME_DB_EMU_INT_ENABLE,
8234 		.fatal = 0,
8235 		.flags = IHF_IGNORE_IF_DISABLED | IHF_FATAL_IFF_ENABLED,
8236 		.details = arm_nvme_db_emu_int_cause_details,
8237 		.actions = NULL,
8238 	};
8239 	bool fatal = false;
8240 
8241 	fatal |= t4_handle_intr(adap, &arm_perr_cause0, 0, flags);
8242 	fatal |= t4_handle_intr(adap, &arm_perr_cause1, 0, flags);
8243 	fatal |= t4_handle_intr(adap, &arm_perr_cause2, 0, flags);
8244 	fatal |= t4_handle_intr(adap, &arm_cerr_cause0, 0, flags);
8245 	fatal |= t4_handle_intr(adap, &arm_err_cause0, 0, flags);
8246 	fatal |= t4_handle_intr(adap, &arm_periph_cause, 0, flags);
8247 	fatal |= t4_handle_intr(adap, &arm_nvme_db_emu_cause, 0, flags);
8248 	fatal |= t4_handle_intr(adap, &arm_uart_cause, 0, flags);
8249 
8250 	return (fatal);
8251 }
8252 
8253 static inline uint32_t
get_ucause(struct adapter * sc,const struct intr_info * ii)8254 get_ucause(struct adapter *sc, const struct intr_info *ii)
8255 {
8256 	uint32_t cause;
8257 
8258 	cause = t4_read_reg(sc, ii->cause_reg);
8259 	if (ii->flags & IHF_IGNORE_IF_DISABLED)
8260 		cause &= t4_read_reg(sc, ii->enable_reg);
8261 	return (cause);
8262 }
8263 
8264 static uint32_t
t4_perr_to_ic(struct adapter * adap,uint32_t perr)8265 t4_perr_to_ic(struct adapter *adap, uint32_t perr)
8266 {
8267 	uint32_t mask;
8268 
8269 	if (adap->chip_params->nchan > 2)
8270 		mask = F_MAC0 | F_MAC1 | F_MAC2 | F_MAC3;
8271 	else
8272 		mask = F_MAC0 | F_MAC1;
8273 	return (perr & mask ? perr | mask : perr);
8274 }
8275 
8276 static uint32_t
t7_perr_to_ic1(uint32_t perr)8277 t7_perr_to_ic1(uint32_t perr)
8278 {
8279 	uint32_t cause = 0;
8280 
8281 	if (perr & F_T7_PL_PERR_ULP_TX)
8282 		cause |= F_T7_ULP_TX;
8283 	if (perr & F_T7_PL_PERR_SGE)
8284 		cause |= F_T7_SGE;
8285 	if (perr & F_T7_PL_PERR_HMA)
8286 		cause |= F_T7_HMA;
8287 	if (perr & F_T7_PL_PERR_CPL_SWITCH)
8288 		cause |= F_T7_CPL_SWITCH;
8289 	if (perr & F_T7_PL_PERR_ULP_RX)
8290 		cause |= F_T7_ULP_RX;
8291 	if (perr & F_T7_PL_PERR_PM_RX)
8292 		cause |= F_T7_PM_RX;
8293 	if (perr & F_T7_PL_PERR_PM_TX)
8294 		cause |= F_T7_PM_TX;
8295 	if (perr & F_T7_PL_PERR_MA)
8296 		cause |= F_T7_MA;
8297 	if (perr & F_T7_PL_PERR_TP)
8298 		cause |= F_T7_TP;
8299 	if (perr & F_T7_PL_PERR_LE)
8300 		cause |= F_T7_LE;
8301 	if (perr & F_T7_PL_PERR_EDC1)
8302 		cause |= F_T7_EDC1;
8303 	if (perr & F_T7_PL_PERR_EDC0)
8304 		cause |= F_T7_EDC0;
8305 	if (perr & F_T7_PL_PERR_MC1)
8306 		cause |= F_T7_MC1;
8307 	if (perr & F_T7_PL_PERR_MC0)
8308 		cause |= F_T7_MC0;
8309 	if (perr & F_T7_PL_PERR_PCIE)
8310 		cause |= F_T7_PCIE;
8311 	if (perr & F_T7_PL_PERR_UART)
8312 		cause |= F_T7_UART;
8313 	if (perr & F_T7_PL_PERR_PMU)
8314 		cause |= F_PMU;
8315 	if (perr & F_T7_PL_PERR_MAC)
8316 		cause |= F_MAC0 | F_MAC1 | F_MAC2 | F_MAC3;
8317 	if (perr & F_T7_PL_PERR_SMB)
8318 		cause |= F_SMB;
8319 	if (perr & F_T7_PL_PERR_SF)
8320 		cause |= F_SF;
8321 	if (perr & F_T7_PL_PERR_PL)
8322 		cause |= F_PL;
8323 	if (perr & F_T7_PL_PERR_NCSI)
8324 		cause |= F_NCSI;
8325 	if (perr & F_T7_PL_PERR_MPS)
8326 		cause |= F_MPS;
8327 	if (perr & F_T7_PL_PERR_MI)
8328 		cause |= F_MI;
8329 	if (perr & F_T7_PL_PERR_DBG)
8330 		cause |= F_DBG;
8331 	if (perr & F_T7_PL_PERR_I2CM)
8332 		cause |= F_I2CM;
8333 	if (perr & F_T7_PL_PERR_CIM)
8334 		cause |= F_CIM;
8335 
8336 	return (cause);
8337 }
8338 
8339 static uint32_t
t7_perr_to_ic2(uint32_t perr)8340 t7_perr_to_ic2(uint32_t perr)
8341 {
8342 	uint32_t cause = 0;
8343 
8344 	if (perr & F_T7_PL_PERR_CRYPTO_KEY)
8345 		cause |= F_CRYPTO_KEY;
8346 	if (perr & F_T7_PL_PERR_CRYPTO1)
8347 		cause |= F_CRYPTO1;
8348 	if (perr & F_T7_PL_PERR_CRYPTO0)
8349 		cause |= F_CRYPTO0;
8350 	if (perr & F_T7_PL_PERR_GCACHE)
8351 		cause |= F_GCACHE;
8352 	if (perr & F_T7_PL_PERR_ARM)
8353 		cause |= F_ARM;
8354 
8355 	return (cause);
8356 }
8357 
8358 /**
8359  *	t4_slow_intr_handler - control path interrupt handler
8360  *	@adap: the adapter
8361  *
8362  *	T4 interrupt handler for non-data global interrupt events, e.g., errors.
8363  *	The designation 'slow' is because it involves register reads, while
8364  *	data interrupts typically don't involve any MMIOs.
8365  */
t4_slow_intr_handler(struct adapter * adap,int flags)8366 bool t4_slow_intr_handler(struct adapter *adap, int flags)
8367 {
8368 	static const struct intr_details pl_int_cause_fields[] = {
8369 		{ F_MC1, "MC1" },
8370 		{ F_UART, "UART" },
8371 		{ F_ULP_TX, "ULP TX" },
8372 		{ F_SGE, "SGE" },
8373 		{ F_HMA, "HMA" },
8374 		{ F_CPL_SWITCH, "CPL Switch" },
8375 		{ F_ULP_RX, "ULP RX" },
8376 		{ F_PM_RX, "PM RX" },
8377 		{ F_PM_TX, "PM TX" },
8378 		{ F_MA, "MA" },
8379 		{ F_TP, "TP" },
8380 		{ F_LE, "LE" },
8381 		{ F_EDC1, "EDC1" },
8382 		{ F_EDC0, "EDC0" },
8383 		{ F_MC, "MC0" },
8384 		{ F_PCIE, "PCIE" },
8385 		{ F_PMU, "PMU" },
8386 		{ F_MAC3, "MAC3" },
8387 		{ F_MAC2, "MAC2" },
8388 		{ F_MAC1, "MAC1" },
8389 		{ F_MAC0, "MAC0" },
8390 		{ F_SMB, "SMB" },
8391 		{ F_SF, "SF" },
8392 		{ F_PL, "PL" },
8393 		{ F_NCSI, "NC-SI" },
8394 		{ F_MPS, "MPS" },
8395 		{ F_MI, "MI" },
8396 		{ F_DBG, "DBG" },
8397 		{ F_I2CM, "I2CM" },
8398 		{ F_CIM, "CIM" },
8399 		{ 0 }
8400 	};
8401 	static const struct intr_action pl_int_cause_actions[] = {
8402 		{ F_ULP_TX, -1, ulptx_intr_handler },
8403 		{ F_SGE, -1, sge_intr_handler },
8404 		{ F_CPL_SWITCH, -1, cplsw_intr_handler },
8405 		{ F_ULP_RX, -1, ulprx_intr_handler },
8406 		{ F_PM_RX, -1, pmtx_intr_handler },
8407 		{ F_PM_TX, -1, pmtx_intr_handler },
8408 		{ F_MA, -1, ma_intr_handler },
8409 		{ F_TP, -1, tp_intr_handler },
8410 		{ F_LE, -1, le_intr_handler },
8411 		{ F_EDC0, MEM_EDC0, mem_intr_handler },
8412 		{ F_EDC1, MEM_EDC1, mem_intr_handler },
8413 		{ F_MC0, MEM_MC0, mem_intr_handler },
8414 		{ F_MC1, MEM_MC1, mem_intr_handler },
8415 		{ F_PCIE, -1, pcie_intr_handler },
8416 		{ F_MAC0, 0, mac_intr_handler },
8417 		{ F_MAC1, 1, mac_intr_handler },
8418 		{ F_MAC2, 2, mac_intr_handler },
8419 		{ F_MAC3, 3, mac_intr_handler },
8420 		{ F_SMB, -1, smb_intr_handler },
8421 		{ F_PL, -1, plpl_intr_handler },
8422 		{ F_NCSI, -1, ncsi_intr_handler },
8423 		{ F_MPS, -1, mps_intr_handler },
8424 		{ F_CIM, -1, cim_intr_handler },
8425 		{ 0 }
8426 	};
8427 	static const struct intr_info pl_int_cause = {
8428 		.name = "PL_INT_CAUSE",
8429 		.cause_reg = A_PL_INT_CAUSE,
8430 		.enable_reg = A_PL_INT_ENABLE,
8431 		.fatal = 0,
8432 		.flags = IHF_IGNORE_IF_DISABLED,
8433 		.details = pl_int_cause_fields,
8434 		.actions = pl_int_cause_actions,
8435 	};
8436 	static const struct intr_info pl_perr_cause = {
8437 		.name = "PL_PERR_CAUSE",
8438 		.cause_reg = A_PL_PERR_CAUSE,
8439 		.enable_reg = A_PL_PERR_ENABLE,
8440 		.fatal = 0xffffffff,
8441 		.flags = IHF_IGNORE_IF_DISABLED | IHF_FATAL_IFF_ENABLED |
8442 		    IHF_CLR_DELAYED,
8443 		.details = pl_int_cause_fields,
8444 		.actions = NULL,
8445 	};
8446 	static const struct intr_details t7_pl_int_cause_fields[] = {
8447 		{ F_T7_FLR, "FLR" },
8448 		{ F_T7_SW_CIM, "SW CIM" },
8449 		{ F_T7_ULP_TX, "ULP TX" },
8450 		{ F_T7_SGE, "SGE" },
8451 		{ F_T7_HMA, "HMA" },
8452 		{ F_T7_CPL_SWITCH, "CPL Switch" },
8453 		{ F_T7_ULP_RX, "ULP RX" },
8454 		{ F_T7_PM_RX, "PM RX" },
8455 		{ F_T7_PM_TX, "PM TX" },
8456 		{ F_T7_MA, "MA" },
8457 		{ F_T7_TP, "TP" },
8458 		{ F_T7_LE, "LE" },
8459 		{ F_T7_EDC1, "EDC1" },
8460 		{ F_T7_EDC0, "EDC0" },
8461 		{ F_T7_MC1, "MC1" },
8462 		{ F_T7_MC0, "MC0" },
8463 		{ F_T7_PCIE, "PCIE" },
8464 		{ F_T7_UART, "UART" },
8465 		{ F_PMU, "PMU" },
8466 		{ F_MAC3, "MAC3" },
8467 		{ F_MAC2, "MAC2" },
8468 		{ F_MAC1, "MAC1" },
8469 		{ F_MAC0, "MAC0" },
8470 		{ F_SMB, "SMB" },
8471 		{ F_SF, "SF" },
8472 		{ F_PL, "PL" },
8473 		{ F_NCSI, "NC-SI" },
8474 		{ F_MPS, "MPS" },
8475 		{ F_MI, "MI" },
8476 		{ F_DBG, "DBG" },
8477 		{ F_I2CM, "I2CM" },
8478 		{ F_CIM, "CIM" },
8479 		{ 0 }
8480 	};
8481 	static const struct intr_action t7_pl_int_cause_actions[] = {
8482 		{ F_T7_ULP_TX, -1, ulptx_intr_handler },
8483 		{ F_T7_SGE, -1, sge_intr_handler },
8484 		{ F_T7_HMA, -1, hma_intr_handler },
8485 		{ F_T7_CPL_SWITCH, -1, cplsw_intr_handler },
8486 		{ F_T7_ULP_RX, -1, ulprx_intr_handler },
8487 		{ F_T7_PM_RX, -1, pmrx_intr_handler },
8488 		{ F_T7_PM_TX, -1, pmtx_intr_handler },
8489 		{ F_T7_MA, -1, ma_intr_handler },
8490 		{ F_T7_TP, -1, tp_intr_handler },
8491 		{ F_T7_LE, -1, le_intr_handler },
8492 		{ F_T7_EDC0, MEM_EDC0, mem_intr_handler },
8493 		{ F_T7_EDC1, MEM_EDC1, mem_intr_handler },
8494 		{ F_T7_MC0, MEM_MC0, mem_intr_handler },
8495 		{ F_T7_MC1, MEM_MC1, mem_intr_handler },
8496 		{ F_T7_PCIE, -1, pcie_intr_handler },
8497 		{ F_MAC0, 0, mac_intr_handler },
8498 		{ F_MAC1, 1, mac_intr_handler },
8499 		{ F_MAC2, 2, mac_intr_handler },
8500 		{ F_MAC3, 3, mac_intr_handler },
8501 		{ F_SMB, -1, smb_intr_handler },
8502 		{ F_PL, -1, plpl_intr_handler },
8503 		{ F_NCSI, -1, ncsi_intr_handler },
8504 		{ F_MPS, -1, mps_intr_handler },
8505 		{ F_CIM, -1, cim_intr_handler },
8506 		{ 0 }
8507 	};
8508 	static const struct intr_info t7_pl_int_cause = {
8509 		.name = "PL_INT_CAUSE",
8510 		.cause_reg = A_PL_INT_CAUSE,
8511 		.enable_reg = A_PL_INT_ENABLE,
8512 		.fatal = 0,
8513 		.flags = IHF_IGNORE_IF_DISABLED,
8514 		.details = t7_pl_int_cause_fields,
8515 		.actions = t7_pl_int_cause_actions,
8516 	};
8517 	static const struct intr_details t7_pl_int_cause2_fields[] = {
8518 		{ F_CRYPTO_KEY, "CRYPTO KEY" },
8519 		{ F_CRYPTO1, "CRYPTO1" },
8520 		{ F_CRYPTO0, "CRYPTO0" },
8521 		{ F_GCACHE, "GCACHE" },
8522 		{ F_ARM, "ARM" },
8523 		{ 0 }
8524 	};
8525 	static const struct intr_action t7_pl_int_cause2_actions[] = {
8526 		{ F_CRYPTO_KEY, -1, cryptokey_intr_handler },
8527 		{ F_CRYPTO1, 1, tlstx_intr_handler },
8528 		{ F_CRYPTO0, 0, tlstx_intr_handler },
8529 		{ F_GCACHE, -1, gcache_intr_handler },
8530 		{ F_ARM, -1, arm_intr_handler },
8531 		{ 0 }
8532 	};
8533 	static const struct intr_info t7_pl_int_cause2 = {
8534 		.name = "PL_INT_CAUSE2",
8535 		.cause_reg = A_PL_INT_CAUSE2,
8536 		.enable_reg = A_PL_INT_ENABLE2,
8537 		.fatal = 0,
8538 		.flags = IHF_IGNORE_IF_DISABLED,
8539 		.details = t7_pl_int_cause2_fields,
8540 		.actions = t7_pl_int_cause2_actions,
8541 	};
8542 	static const struct intr_details t7_pl_perr_cause_fields[] = {
8543 		{ F_T7_PL_PERR_CRYPTO_KEY, "CRYPTO KEY" },
8544 		{ F_T7_PL_PERR_CRYPTO1, "CRYPTO1" },
8545 		{ F_T7_PL_PERR_CRYPTO0, "CRYPTO0" },
8546 		{ F_T7_PL_PERR_GCACHE, "GCACHE" },
8547 		{ F_T7_PL_PERR_ARM, "ARM" },
8548 		{ F_T7_PL_PERR_ULP_TX, "ULP TX" },
8549 		{ F_T7_PL_PERR_SGE, "SGE" },
8550 		{ F_T7_PL_PERR_HMA, "HMA" },
8551 		{ F_T7_PL_PERR_CPL_SWITCH, "CPL Switch" },
8552 		{ F_T7_PL_PERR_ULP_RX, "ULP RX" },
8553 		{ F_T7_PL_PERR_PM_RX, "PM RX" },
8554 		{ F_T7_PL_PERR_PM_TX, "PM TX" },
8555 		{ F_T7_PL_PERR_MA, "MA" },
8556 		{ F_T7_PL_PERR_TP, "TP" },
8557 		{ F_T7_PL_PERR_LE, "LE" },
8558 		{ F_T7_PL_PERR_EDC1, "EDC1" },
8559 		{ F_T7_PL_PERR_EDC0, "EDC0" },
8560 		{ F_T7_PL_PERR_MC1, "MC1" },
8561 		{ F_T7_PL_PERR_MC0, "MC0" },
8562 		{ F_T7_PL_PERR_PCIE, "PCIE" },
8563 		{ F_T7_PL_PERR_UART, "UART" },
8564 		{ F_T7_PL_PERR_PMU, "PMU" },
8565 		{ F_T7_PL_PERR_MAC, "MAC" },
8566 		{ F_T7_PL_PERR_SMB, "SMB" },
8567 		{ F_T7_PL_PERR_SF, "SF" },
8568 		{ F_T7_PL_PERR_PL, "PL" },
8569 		{ F_T7_PL_PERR_NCSI, "NC-SI" },
8570 		{ F_T7_PL_PERR_MPS, "MPS" },
8571 		{ F_T7_PL_PERR_MI, "MI" },
8572 		{ F_T7_PL_PERR_DBG, "DBG" },
8573 		{ F_T7_PL_PERR_I2CM, "I2CM" },
8574 		{ F_T7_PL_PERR_CIM, "CIM" },
8575 		{ 0 }
8576 	};
8577 	static const struct intr_info t7_pl_perr_cause = {
8578 		.name = "PL_PERR_CAUSE",
8579 		.cause_reg = A_PL_PERR_CAUSE,
8580 		.enable_reg = A_PL_PERR_ENABLE,
8581 		.fatal = 0xffffffff,
8582 		.flags = IHF_IGNORE_IF_DISABLED | IHF_FATAL_IFF_ENABLED |
8583 		    IHF_CLR_DELAYED,
8584 		.details = t7_pl_perr_cause_fields,
8585 		.actions = NULL,
8586 	};
8587 	bool fatal = false;
8588 	uint32_t perr;
8589 
8590 	if (chip_id(adap) < CHELSIO_T7) {
8591 		perr = get_ucause(adap, &pl_perr_cause);
8592 		fatal |= t4_handle_intr(adap, &pl_perr_cause, 0, flags);
8593 		fatal |= t4_handle_intr(adap, &pl_int_cause,
8594 		    t4_perr_to_ic(adap, perr), flags);
8595 		clear_int_cause_reg(adap, &pl_perr_cause, flags);
8596 	} else {
8597 		perr = get_ucause(adap, &t7_pl_perr_cause);
8598 		fatal |= t4_handle_intr(adap, &t7_pl_perr_cause, 0, flags);
8599 		fatal |= t4_handle_intr(adap, &t7_pl_int_cause,
8600 		    t7_perr_to_ic1(perr), flags);
8601 		fatal |= t4_handle_intr(adap, &t7_pl_int_cause2,
8602 		    t7_perr_to_ic2(perr), flags);
8603 		clear_int_cause_reg(adap, &t7_pl_perr_cause, flags);
8604 	}
8605 	return (fatal);
8606 }
8607 
t4_intr_clear(struct adapter * adap)8608 void t4_intr_clear(struct adapter *adap)
8609 {
8610 #if 1
8611 	if (chip_id(adap) >= CHELSIO_T7)
8612 		t4_write_reg(adap, A_SGE_INT_CAUSE8, 0xffffffff);
8613 #endif
8614 	(void)t4_slow_intr_handler(adap,
8615 	    IHF_NO_SHOW | IHF_RUN_ALL_ACTIONS | IHF_CLR_ALL_SET);
8616 }
8617 
8618 /**
8619  *	t4_intr_enable - enable interrupts
8620  *	@adapter: the adapter whose interrupts should be enabled
8621  *
8622  *	Enable PF-specific interrupts for the calling function and the top-level
8623  *	interrupt concentrator for global interrupts.  Interrupts are already
8624  *	enabled at each module,	here we just enable the roots of the interrupt
8625  *	hierarchies.
8626  *
8627  *	Note: this function should be called only when the driver manages
8628  *	non PF-specific interrupts from the various HW modules.  Only one PCI
8629  *	function at a time should be doing this.
8630  */
t4_intr_enable(struct adapter * adap)8631 void t4_intr_enable(struct adapter *adap)
8632 {
8633 	u32 mask, val;
8634 
8635 	if (adap->intr_flags & IHF_INTR_CLEAR_ON_INIT)
8636 		t4_intr_clear(adap);
8637 	if (chip_id(adap) <= CHELSIO_T5)
8638 		val = F_ERR_DROPPED_DB | F_ERR_EGR_CTXT_PRIO | F_DBFIFO_HP_INT |
8639 		    F_DBFIFO_LP_INT;
8640 	else
8641 		val = F_ERR_PCIE_ERROR0 | F_ERR_PCIE_ERROR1 | F_FATAL_WRE_LEN;
8642 	val |= F_ERR_CPL_EXCEED_IQE_SIZE | F_ERR_INVALID_CIDX_INC |
8643 	    F_ERR_CPL_OPCODE_0 | F_ERR_DATA_CPL_ON_HIGH_QID1 |
8644 	    F_INGRESS_SIZE_ERR | F_ERR_DATA_CPL_ON_HIGH_QID0 |
8645 	    F_ERR_BAD_DB_PIDX3 | F_ERR_BAD_DB_PIDX2 | F_ERR_BAD_DB_PIDX1 |
8646 	    F_ERR_BAD_DB_PIDX0 | F_ERR_ING_CTXT_PRIO | F_EGRESS_SIZE_ERR;
8647 	mask = val;
8648 	t4_set_reg_field(adap, A_SGE_INT_ENABLE3, mask, val);
8649 	if (chip_id(adap) >= CHELSIO_T7)
8650 		t4_write_reg(adap, A_SGE_INT_ENABLE4, 0xffffffff);
8651 	t4_write_reg(adap, MYPF_REG(A_PL_PF_INT_ENABLE), F_PFSW | F_PFCIM);
8652 	t4_set_reg_field(adap, A_PL_INT_ENABLE, F_SF | F_I2CM, 0);
8653 #if 1
8654 	if (chip_id(adap) >= CHELSIO_T7)
8655 		t4_set_reg_field(adap, A_PL_INT_ENABLE, F_MAC0 | F_MAC1 | F_MAC2 | F_MAC3, 0);
8656 #endif
8657 	t4_set_reg_field(adap, A_PL_INT_MAP0, 0, 1 << adap->pf);
8658 }
8659 
8660 /**
8661  *	t4_intr_disable - disable interrupts
8662  *	@adap: the adapter whose interrupts should be disabled
8663  *
8664  *	Disable interrupts.  We only disable the top-level interrupt
8665  *	concentrators.  The caller must be a PCI function managing global
8666  *	interrupts.
8667  */
t4_intr_disable(struct adapter * adap)8668 void t4_intr_disable(struct adapter *adap)
8669 {
8670 
8671 	t4_write_reg(adap, MYPF_REG(A_PL_PF_INT_ENABLE), 0);
8672 	t4_set_reg_field(adap, A_PL_INT_MAP0, 1 << adap->pf, 0);
8673 }
8674 
8675 /**
8676  *	hash_mac_addr - return the hash value of a MAC address
8677  *	@addr: the 48-bit Ethernet MAC address
8678  *
8679  *	Hashes a MAC address according to the hash function used by HW inexact
8680  *	(hash) address matching.
8681  */
hash_mac_addr(const u8 * addr)8682 static int hash_mac_addr(const u8 *addr)
8683 {
8684 	u32 a = ((u32)addr[0] << 16) | ((u32)addr[1] << 8) | addr[2];
8685 	u32 b = ((u32)addr[3] << 16) | ((u32)addr[4] << 8) | addr[5];
8686 	a ^= b;
8687 	a ^= (a >> 12);
8688 	a ^= (a >> 6);
8689 	return a & 0x3f;
8690 }
8691 
8692 /**
8693  *	t4_config_rss_range - configure a portion of the RSS mapping table
8694  *	@adapter: the adapter
8695  *	@mbox: mbox to use for the FW command
8696  *	@viid: virtual interface whose RSS subtable is to be written
8697  *	@start: start entry in the table to write
8698  *	@n: how many table entries to write
8699  *	@rspq: values for the "response queue" (Ingress Queue) lookup table
8700  *	@nrspq: number of values in @rspq
8701  *
8702  *	Programs the selected part of the VI's RSS mapping table with the
8703  *	provided values.  If @nrspq < @n the supplied values are used repeatedly
8704  *	until the full table range is populated.
8705  *
8706  *	The caller must ensure the values in @rspq are in the range allowed for
8707  *	@viid.
8708  */
t4_config_rss_range(struct adapter * adapter,int mbox,unsigned int viid,int start,int n,const u16 * rspq,unsigned int nrspq)8709 int t4_config_rss_range(struct adapter *adapter, int mbox, unsigned int viid,
8710 			int start, int n, const u16 *rspq, unsigned int nrspq)
8711 {
8712 	int ret;
8713 	const u16 *rsp = rspq;
8714 	const u16 *rsp_end = rspq + nrspq;
8715 	struct fw_rss_ind_tbl_cmd cmd;
8716 
8717 	memset(&cmd, 0, sizeof(cmd));
8718 	cmd.op_to_viid = cpu_to_be32(V_FW_CMD_OP(FW_RSS_IND_TBL_CMD) |
8719 				     F_FW_CMD_REQUEST | F_FW_CMD_WRITE |
8720 				     V_FW_RSS_IND_TBL_CMD_VIID(viid));
8721 	cmd.retval_len16 = cpu_to_be32(FW_LEN16(cmd));
8722 
8723 	/*
8724 	 * Each firmware RSS command can accommodate up to 32 RSS Ingress
8725 	 * Queue Identifiers.  These Ingress Queue IDs are packed three to
8726 	 * a 32-bit word as 10-bit values with the upper remaining 2 bits
8727 	 * reserved.
8728 	 */
8729 	while (n > 0) {
8730 		int nq = min(n, 32);
8731 		int nq_packed = 0;
8732 		__be32 *qp = &cmd.iq0_to_iq2;
8733 
8734 		/*
8735 		 * Set up the firmware RSS command header to send the next
8736 		 * "nq" Ingress Queue IDs to the firmware.
8737 		 */
8738 		cmd.niqid = cpu_to_be16(nq);
8739 		cmd.startidx = cpu_to_be16(start);
8740 
8741 		/*
8742 		 * "nq" more done for the start of the next loop.
8743 		 */
8744 		start += nq;
8745 		n -= nq;
8746 
8747 		/*
8748 		 * While there are still Ingress Queue IDs to stuff into the
8749 		 * current firmware RSS command, retrieve them from the
8750 		 * Ingress Queue ID array and insert them into the command.
8751 		 */
8752 		while (nq > 0) {
8753 			/*
8754 			 * Grab up to the next 3 Ingress Queue IDs (wrapping
8755 			 * around the Ingress Queue ID array if necessary) and
8756 			 * insert them into the firmware RSS command at the
8757 			 * current 3-tuple position within the commad.
8758 			 */
8759 			u16 qbuf[3];
8760 			u16 *qbp = qbuf;
8761 			int nqbuf = min(3, nq);
8762 
8763 			nq -= nqbuf;
8764 			qbuf[0] = qbuf[1] = qbuf[2] = 0;
8765 			while (nqbuf && nq_packed < 32) {
8766 				nqbuf--;
8767 				nq_packed++;
8768 				*qbp++ = *rsp++;
8769 				if (rsp >= rsp_end)
8770 					rsp = rspq;
8771 			}
8772 			*qp++ = cpu_to_be32(V_FW_RSS_IND_TBL_CMD_IQ0(qbuf[0]) |
8773 					    V_FW_RSS_IND_TBL_CMD_IQ1(qbuf[1]) |
8774 					    V_FW_RSS_IND_TBL_CMD_IQ2(qbuf[2]));
8775 		}
8776 
8777 		/*
8778 		 * Send this portion of the RRS table update to the firmware;
8779 		 * bail out on any errors.
8780 		 */
8781 		ret = t4_wr_mbox(adapter, mbox, &cmd, sizeof(cmd), NULL);
8782 		if (ret)
8783 			return ret;
8784 	}
8785 	return 0;
8786 }
8787 
8788 /**
8789  *	t4_config_glbl_rss - configure the global RSS mode
8790  *	@adapter: the adapter
8791  *	@mbox: mbox to use for the FW command
8792  *	@mode: global RSS mode
8793  *	@flags: mode-specific flags
8794  *
8795  *	Sets the global RSS mode.
8796  */
t4_config_glbl_rss(struct adapter * adapter,int mbox,unsigned int mode,unsigned int flags)8797 int t4_config_glbl_rss(struct adapter *adapter, int mbox, unsigned int mode,
8798 		       unsigned int flags)
8799 {
8800 	struct fw_rss_glb_config_cmd c;
8801 
8802 	memset(&c, 0, sizeof(c));
8803 	c.op_to_write = cpu_to_be32(V_FW_CMD_OP(FW_RSS_GLB_CONFIG_CMD) |
8804 				    F_FW_CMD_REQUEST | F_FW_CMD_WRITE);
8805 	c.retval_len16 = cpu_to_be32(FW_LEN16(c));
8806 	if (mode == FW_RSS_GLB_CONFIG_CMD_MODE_MANUAL) {
8807 		c.u.manual.mode_pkd =
8808 			cpu_to_be32(V_FW_RSS_GLB_CONFIG_CMD_MODE(mode));
8809 	} else if (mode == FW_RSS_GLB_CONFIG_CMD_MODE_BASICVIRTUAL) {
8810 		c.u.basicvirtual.mode_keymode =
8811 			cpu_to_be32(V_FW_RSS_GLB_CONFIG_CMD_MODE(mode));
8812 		c.u.basicvirtual.synmapen_to_hashtoeplitz = cpu_to_be32(flags);
8813 	} else
8814 		return -EINVAL;
8815 	return t4_wr_mbox(adapter, mbox, &c, sizeof(c), NULL);
8816 }
8817 
8818 /**
8819  *	t4_config_vi_rss - configure per VI RSS settings
8820  *	@adapter: the adapter
8821  *	@mbox: mbox to use for the FW command
8822  *	@viid: the VI id
8823  *	@flags: RSS flags
8824  *	@defq: id of the default RSS queue for the VI.
8825  *	@skeyidx: RSS secret key table index for non-global mode
8826  *	@skey: RSS vf_scramble key for VI.
8827  *
8828  *	Configures VI-specific RSS properties.
8829  */
t4_config_vi_rss(struct adapter * adapter,int mbox,unsigned int viid,unsigned int flags,unsigned int defq,unsigned int skeyidx,unsigned int skey)8830 int t4_config_vi_rss(struct adapter *adapter, int mbox, unsigned int viid,
8831 		     unsigned int flags, unsigned int defq, unsigned int skeyidx,
8832 		     unsigned int skey)
8833 {
8834 	struct fw_rss_vi_config_cmd c;
8835 
8836 	memset(&c, 0, sizeof(c));
8837 	c.op_to_viid = cpu_to_be32(V_FW_CMD_OP(FW_RSS_VI_CONFIG_CMD) |
8838 				   F_FW_CMD_REQUEST | F_FW_CMD_WRITE |
8839 				   V_FW_RSS_VI_CONFIG_CMD_VIID(viid));
8840 	c.retval_len16 = cpu_to_be32(FW_LEN16(c));
8841 	c.u.basicvirtual.defaultq_to_udpen = cpu_to_be32(flags |
8842 					V_FW_RSS_VI_CONFIG_CMD_DEFAULTQ(defq));
8843 	c.u.basicvirtual.secretkeyidx_pkd = cpu_to_be32(
8844 					V_FW_RSS_VI_CONFIG_CMD_SECRETKEYIDX(skeyidx));
8845 	c.u.basicvirtual.secretkeyxor = cpu_to_be32(skey);
8846 
8847 	return t4_wr_mbox(adapter, mbox, &c, sizeof(c), NULL);
8848 }
8849 
8850 /* Read an RSS table row */
rd_rss_row(struct adapter * adap,int row,u32 * val)8851 static int rd_rss_row(struct adapter *adap, int row, u32 *val)
8852 {
8853 	if (chip_id(adap) < CHELSIO_T7) {
8854 		t4_write_reg(adap, A_TP_RSS_LKP_TABLE, 0xfff00000 | row);
8855 		return t4_wait_op_done_val(adap, A_TP_RSS_LKP_TABLE,
8856 					   F_LKPTBLROWVLD, 1, 5, 0, val);
8857 	} else {
8858 		t4_write_reg(adap, A_TP_RSS_CONFIG_SRAM, 0xB0000 | row);
8859 		return t7_wait_sram_done(adap, A_TP_RSS_CONFIG_SRAM,
8860 					 A_TP_RSS_LKP_TABLE, 5, 0, val);
8861 	}
8862 }
8863 
8864 /**
8865  *	t4_read_rss - read the contents of the RSS mapping table
8866  *	@adapter: the adapter
8867  *	@map: holds the contents of the RSS mapping table
8868  *
8869  *	Reads the contents of the RSS hash->queue mapping table.
8870  */
t4_read_rss(struct adapter * adapter,u16 * map)8871 int t4_read_rss(struct adapter *adapter, u16 *map)
8872 {
8873 	u32 val;
8874 	int i, ret;
8875 	int rss_nentries = adapter->chip_params->rss_nentries;
8876 
8877 	for (i = 0; i < rss_nentries / 2; ++i) {
8878 		ret = rd_rss_row(adapter, i, &val);
8879 		if (ret)
8880 			return ret;
8881 		*map++ = G_LKPTBLQUEUE0(val);
8882 		*map++ = G_LKPTBLQUEUE1(val);
8883 	}
8884 	return 0;
8885 }
8886 
8887 /**
8888  * t4_tp_fw_ldst_rw - Access TP indirect register through LDST
8889  * @adap: the adapter
8890  * @cmd: TP fw ldst address space type
8891  * @vals: where the indirect register values are stored/written
8892  * @nregs: how many indirect registers to read/write
8893  * @start_idx: index of first indirect register to read/write
8894  * @rw: Read (1) or Write (0)
8895  * @sleep_ok: if true we may sleep while awaiting command completion
8896  *
8897  * Access TP indirect registers through LDST
8898  **/
t4_tp_fw_ldst_rw(struct adapter * adap,int cmd,u32 * vals,unsigned int nregs,unsigned int start_index,unsigned int rw,bool sleep_ok)8899 static int t4_tp_fw_ldst_rw(struct adapter *adap, int cmd, u32 *vals,
8900 			    unsigned int nregs, unsigned int start_index,
8901 			    unsigned int rw, bool sleep_ok)
8902 {
8903 	int ret = 0;
8904 	unsigned int i;
8905 	struct fw_ldst_cmd c;
8906 
8907 	for (i = 0; i < nregs; i++) {
8908 		memset(&c, 0, sizeof(c));
8909 		c.op_to_addrspace = cpu_to_be32(V_FW_CMD_OP(FW_LDST_CMD) |
8910 						F_FW_CMD_REQUEST |
8911 						(rw ? F_FW_CMD_READ :
8912 						      F_FW_CMD_WRITE) |
8913 						V_FW_LDST_CMD_ADDRSPACE(cmd));
8914 		c.cycles_to_len16 = cpu_to_be32(FW_LEN16(c));
8915 
8916 		c.u.addrval.addr = cpu_to_be32(start_index + i);
8917 		c.u.addrval.val  = rw ? 0 : cpu_to_be32(vals[i]);
8918 		ret = t4_wr_mbox_meat(adap, adap->mbox, &c, sizeof(c), &c,
8919 				      sleep_ok);
8920 		if (ret)
8921 			return ret;
8922 
8923 		if (rw)
8924 			vals[i] = be32_to_cpu(c.u.addrval.val);
8925 	}
8926 	return 0;
8927 }
8928 
8929 /**
8930  * t4_tp_indirect_rw - Read/Write TP indirect register through LDST or backdoor
8931  * @adap: the adapter
8932  * @reg_addr: Address Register
8933  * @reg_data: Data register
8934  * @buff: where the indirect register values are stored/written
8935  * @nregs: how many indirect registers to read/write
8936  * @start_index: index of first indirect register to read/write
8937  * @rw: READ(1) or WRITE(0)
8938  * @sleep_ok: if true we may sleep while awaiting command completion
8939  *
8940  * Read/Write TP indirect registers through LDST if possible.
8941  * Else, use backdoor access
8942  **/
t4_tp_indirect_rw(struct adapter * adap,u32 reg_addr,u32 reg_data,u32 * buff,u32 nregs,u32 start_index,int rw,bool sleep_ok)8943 static void t4_tp_indirect_rw(struct adapter *adap, u32 reg_addr, u32 reg_data,
8944 			      u32 *buff, u32 nregs, u32 start_index, int rw,
8945 			      bool sleep_ok)
8946 {
8947 	int rc = -EINVAL;
8948 	int cmd;
8949 
8950 	switch (reg_addr) {
8951 	case A_TP_PIO_ADDR:
8952 		cmd = FW_LDST_ADDRSPC_TP_PIO;
8953 		break;
8954 	case A_TP_TM_PIO_ADDR:
8955 		cmd = FW_LDST_ADDRSPC_TP_TM_PIO;
8956 		break;
8957 	case A_TP_MIB_INDEX:
8958 		cmd = FW_LDST_ADDRSPC_TP_MIB;
8959 		break;
8960 	default:
8961 		goto indirect_access;
8962 	}
8963 
8964 	if (t4_use_ldst(adap))
8965 		rc = t4_tp_fw_ldst_rw(adap, cmd, buff, nregs, start_index, rw,
8966 				      sleep_ok);
8967 
8968 indirect_access:
8969 
8970 	if (rc) {
8971 		if (rw)
8972 			t4_read_indirect(adap, reg_addr, reg_data, buff, nregs,
8973 					 start_index);
8974 		else
8975 			t4_write_indirect(adap, reg_addr, reg_data, buff, nregs,
8976 					  start_index);
8977 	}
8978 }
8979 
8980 /**
8981  * t4_tp_pio_read - Read TP PIO registers
8982  * @adap: the adapter
8983  * @buff: where the indirect register values are written
8984  * @nregs: how many indirect registers to read
8985  * @start_index: index of first indirect register to read
8986  * @sleep_ok: if true we may sleep while awaiting command completion
8987  *
8988  * Read TP PIO Registers
8989  **/
t4_tp_pio_read(struct adapter * adap,u32 * buff,u32 nregs,u32 start_index,bool sleep_ok)8990 void t4_tp_pio_read(struct adapter *adap, u32 *buff, u32 nregs,
8991 		    u32 start_index, bool sleep_ok)
8992 {
8993 	t4_tp_indirect_rw(adap, A_TP_PIO_ADDR, A_TP_PIO_DATA, buff, nregs,
8994 			  start_index, 1, sleep_ok);
8995 }
8996 
8997 /**
8998  * t4_tp_pio_write - Write TP PIO registers
8999  * @adap: the adapter
9000  * @buff: where the indirect register values are stored
9001  * @nregs: how many indirect registers to write
9002  * @start_index: index of first indirect register to write
9003  * @sleep_ok: if true we may sleep while awaiting command completion
9004  *
9005  * Write TP PIO Registers
9006  **/
t4_tp_pio_write(struct adapter * adap,const u32 * buff,u32 nregs,u32 start_index,bool sleep_ok)9007 void t4_tp_pio_write(struct adapter *adap, const u32 *buff, u32 nregs,
9008 		     u32 start_index, bool sleep_ok)
9009 {
9010 	t4_tp_indirect_rw(adap, A_TP_PIO_ADDR, A_TP_PIO_DATA,
9011 	    __DECONST(u32 *, buff), nregs, start_index, 0, sleep_ok);
9012 }
9013 
9014 /**
9015  * t4_tp_tm_pio_read - Read TP TM PIO registers
9016  * @adap: the adapter
9017  * @buff: where the indirect register values are written
9018  * @nregs: how many indirect registers to read
9019  * @start_index: index of first indirect register to read
9020  * @sleep_ok: if true we may sleep while awaiting command completion
9021  *
9022  * Read TP TM PIO Registers
9023  **/
t4_tp_tm_pio_read(struct adapter * adap,u32 * buff,u32 nregs,u32 start_index,bool sleep_ok)9024 void t4_tp_tm_pio_read(struct adapter *adap, u32 *buff, u32 nregs,
9025 		       u32 start_index, bool sleep_ok)
9026 {
9027 	t4_tp_indirect_rw(adap, A_TP_TM_PIO_ADDR, A_TP_TM_PIO_DATA, buff,
9028 			  nregs, start_index, 1, sleep_ok);
9029 }
9030 
9031 /**
9032  * t4_tp_mib_read - Read TP MIB registers
9033  * @adap: the adapter
9034  * @buff: where the indirect register values are written
9035  * @nregs: how many indirect registers to read
9036  * @start_index: index of first indirect register to read
9037  * @sleep_ok: if true we may sleep while awaiting command completion
9038  *
9039  * Read TP MIB Registers
9040  **/
t4_tp_mib_read(struct adapter * adap,u32 * buff,u32 nregs,u32 start_index,bool sleep_ok)9041 void t4_tp_mib_read(struct adapter *adap, u32 *buff, u32 nregs, u32 start_index,
9042 		    bool sleep_ok)
9043 {
9044 	t4_tp_indirect_rw(adap, A_TP_MIB_INDEX, A_TP_MIB_DATA, buff, nregs,
9045 			  start_index, 1, sleep_ok);
9046 }
9047 
9048 /**
9049  *	t4_read_rss_key - read the global RSS key
9050  *	@adap: the adapter
9051  *	@key: 10-entry array holding the 320-bit RSS key
9052  * 	@sleep_ok: if true we may sleep while awaiting command completion
9053  *
9054  *	Reads the global 320-bit RSS key.
9055  */
t4_read_rss_key(struct adapter * adap,u32 * key,bool sleep_ok)9056 void t4_read_rss_key(struct adapter *adap, u32 *key, bool sleep_ok)
9057 {
9058 	t4_tp_pio_read(adap, key, 10, A_TP_RSS_SECRET_KEY0, sleep_ok);
9059 }
9060 
9061 /**
9062  *	t4_write_rss_key - program one of the RSS keys
9063  *	@adap: the adapter
9064  *	@key: 10-entry array holding the 320-bit RSS key
9065  *	@idx: which RSS key to write
9066  * 	@sleep_ok: if true we may sleep while awaiting command completion
9067  *
9068  *	Writes one of the RSS keys with the given 320-bit value.  If @idx is
9069  *	0..15 the corresponding entry in the RSS key table is written,
9070  *	otherwise the global RSS key is written.
9071  */
t4_write_rss_key(struct adapter * adap,const u32 * key,int idx,bool sleep_ok)9072 void t4_write_rss_key(struct adapter *adap, const u32 *key, int idx,
9073 		      bool sleep_ok)
9074 {
9075 	u8 rss_key_addr_cnt = 16;
9076 	u32 vrt = t4_read_reg(adap, A_TP_RSS_CONFIG_VRT);
9077 
9078 	/*
9079 	 * T6 and later: for KeyMode 3 (per-vf and per-vf scramble),
9080 	 * allows access to key addresses 16-63 by using KeyWrAddrX
9081 	 * as index[5:4](upper 2) into key table
9082 	 */
9083 	if ((chip_id(adap) > CHELSIO_T5) &&
9084 	    (vrt & F_KEYEXTEND) && (G_KEYMODE(vrt) == 3))
9085 		rss_key_addr_cnt = 32;
9086 
9087 	t4_tp_pio_write(adap, key, 10, A_TP_RSS_SECRET_KEY0, sleep_ok);
9088 
9089 	if (idx >= 0 && idx < rss_key_addr_cnt) {
9090 		if (rss_key_addr_cnt > 16)
9091 			t4_write_reg(adap, A_TP_RSS_CONFIG_VRT,
9092 				     vrt | V_KEYWRADDRX(idx >> 4) |
9093 				     V_T6_VFWRADDR(idx) | F_KEYWREN);
9094 		else
9095 			t4_write_reg(adap, A_TP_RSS_CONFIG_VRT,
9096 				     vrt| V_KEYWRADDR(idx) | F_KEYWREN);
9097 	}
9098 }
9099 
9100 /**
9101  *	t4_read_rss_pf_config - read PF RSS Configuration Table
9102  *	@adapter: the adapter
9103  *	@index: the entry in the PF RSS table to read
9104  *	@valp: where to store the returned value
9105  * 	@sleep_ok: if true we may sleep while awaiting command completion
9106  *
9107  *	Reads the PF RSS Configuration Table at the specified index and returns
9108  *	the value found there.
9109  */
t4_read_rss_pf_config(struct adapter * adapter,unsigned int index,u32 * valp,bool sleep_ok)9110 void t4_read_rss_pf_config(struct adapter *adapter, unsigned int index,
9111 			   u32 *valp, bool sleep_ok)
9112 {
9113 	t4_tp_pio_read(adapter, valp, 1, A_TP_RSS_PF0_CONFIG + index, sleep_ok);
9114 }
9115 
9116 /**
9117  *	t4_write_rss_pf_config - write PF RSS Configuration Table
9118  *	@adapter: the adapter
9119  *	@index: the entry in the VF RSS table to read
9120  *	@val: the value to store
9121  * 	@sleep_ok: if true we may sleep while awaiting command completion
9122  *
9123  *	Writes the PF RSS Configuration Table at the specified index with the
9124  *	specified value.
9125  */
t4_write_rss_pf_config(struct adapter * adapter,unsigned int index,u32 val,bool sleep_ok)9126 void t4_write_rss_pf_config(struct adapter *adapter, unsigned int index,
9127 			    u32 val, bool sleep_ok)
9128 {
9129 	t4_tp_pio_write(adapter, &val, 1, A_TP_RSS_PF0_CONFIG + index,
9130 			sleep_ok);
9131 }
9132 
9133 /**
9134  *	t4_read_rss_vf_config - read VF RSS Configuration Table
9135  *	@adapter: the adapter
9136  *	@index: the entry in the VF RSS table to read
9137  *	@vfl: where to store the returned VFL
9138  *	@vfh: where to store the returned VFH
9139  * 	@sleep_ok: if true we may sleep while awaiting command completion
9140  *
9141  *	Reads the VF RSS Configuration Table at the specified index and returns
9142  *	the (VFL, VFH) values found there.
9143  */
t4_read_rss_vf_config(struct adapter * adapter,unsigned int index,u32 * vfl,u32 * vfh,bool sleep_ok)9144 void t4_read_rss_vf_config(struct adapter *adapter, unsigned int index,
9145 			   u32 *vfl, u32 *vfh, bool sleep_ok)
9146 {
9147 	u32 vrt, mask, data;
9148 
9149 	if (chip_id(adapter) <= CHELSIO_T5) {
9150 		mask = V_VFWRADDR(M_VFWRADDR);
9151 		data = V_VFWRADDR(index);
9152 	} else {
9153 		 mask =  V_T6_VFWRADDR(M_T6_VFWRADDR);
9154 		 data = V_T6_VFWRADDR(index);
9155 	}
9156 	/*
9157 	 * Request that the index'th VF Table values be read into VFL/VFH.
9158 	 */
9159 	vrt = t4_read_reg(adapter, A_TP_RSS_CONFIG_VRT);
9160 	vrt &= ~(F_VFRDRG | F_VFWREN | F_KEYWREN | mask);
9161 	vrt |= data | F_VFRDEN;
9162 	t4_write_reg(adapter, A_TP_RSS_CONFIG_VRT, vrt);
9163 
9164 	/*
9165 	 * Grab the VFL/VFH values ...
9166 	 */
9167 	t4_tp_pio_read(adapter, vfl, 1, A_TP_RSS_VFL_CONFIG, sleep_ok);
9168 	t4_tp_pio_read(adapter, vfh, 1, A_TP_RSS_VFH_CONFIG, sleep_ok);
9169 }
9170 
9171 /**
9172  *	t4_write_rss_vf_config - write VF RSS Configuration Table
9173  *
9174  *	@adapter: the adapter
9175  *	@index: the entry in the VF RSS table to write
9176  *	@vfl: the VFL to store
9177  *	@vfh: the VFH to store
9178  *
9179  *	Writes the VF RSS Configuration Table at the specified index with the
9180  *	specified (VFL, VFH) values.
9181  */
t4_write_rss_vf_config(struct adapter * adapter,unsigned int index,u32 vfl,u32 vfh,bool sleep_ok)9182 void t4_write_rss_vf_config(struct adapter *adapter, unsigned int index,
9183 			    u32 vfl, u32 vfh, bool sleep_ok)
9184 {
9185 	u32 vrt, mask, data;
9186 
9187 	if (chip_id(adapter) <= CHELSIO_T5) {
9188 		mask = V_VFWRADDR(M_VFWRADDR);
9189 		data = V_VFWRADDR(index);
9190 	} else {
9191 		mask =  V_T6_VFWRADDR(M_T6_VFWRADDR);
9192 		data = V_T6_VFWRADDR(index);
9193 	}
9194 
9195 	/*
9196 	 * Load up VFL/VFH with the values to be written ...
9197 	 */
9198 	t4_tp_pio_write(adapter, &vfl, 1, A_TP_RSS_VFL_CONFIG, sleep_ok);
9199 	t4_tp_pio_write(adapter, &vfh, 1, A_TP_RSS_VFH_CONFIG, sleep_ok);
9200 
9201 	/*
9202 	 * Write the VFL/VFH into the VF Table at index'th location.
9203 	 */
9204 	vrt = t4_read_reg(adapter, A_TP_RSS_CONFIG_VRT);
9205 	vrt &= ~(F_VFRDRG | F_VFWREN | F_KEYWREN | mask);
9206 	vrt |= data | F_VFRDEN;
9207 	t4_write_reg(adapter, A_TP_RSS_CONFIG_VRT, vrt);
9208 }
9209 
9210 /**
9211  *	t4_read_rss_pf_map - read PF RSS Map
9212  *	@adapter: the adapter
9213  * 	@sleep_ok: if true we may sleep while awaiting command completion
9214  *
9215  *	Reads the PF RSS Map register and returns its value.
9216  */
t4_read_rss_pf_map(struct adapter * adapter,bool sleep_ok)9217 u32 t4_read_rss_pf_map(struct adapter *adapter, bool sleep_ok)
9218 {
9219 	u32 pfmap;
9220 
9221 	t4_tp_pio_read(adapter, &pfmap, 1, A_TP_RSS_PF_MAP, sleep_ok);
9222 
9223 	return pfmap;
9224 }
9225 
9226 /**
9227  *	t4_write_rss_pf_map - write PF RSS Map
9228  *	@adapter: the adapter
9229  *	@pfmap: PF RSS Map value
9230  *
9231  *	Writes the specified value to the PF RSS Map register.
9232  */
t4_write_rss_pf_map(struct adapter * adapter,u32 pfmap,bool sleep_ok)9233 void t4_write_rss_pf_map(struct adapter *adapter, u32 pfmap, bool sleep_ok)
9234 {
9235 	t4_tp_pio_write(adapter, &pfmap, 1, A_TP_RSS_PF_MAP, sleep_ok);
9236 }
9237 
9238 /**
9239  *	t4_read_rss_pf_mask - read PF RSS Mask
9240  *	@adapter: the adapter
9241  * 	@sleep_ok: if true we may sleep while awaiting command completion
9242  *
9243  *	Reads the PF RSS Mask register and returns its value.
9244  */
t4_read_rss_pf_mask(struct adapter * adapter,bool sleep_ok)9245 u32 t4_read_rss_pf_mask(struct adapter *adapter, bool sleep_ok)
9246 {
9247 	u32 pfmask;
9248 
9249 	t4_tp_pio_read(adapter, &pfmask, 1, A_TP_RSS_PF_MSK, sleep_ok);
9250 
9251 	return pfmask;
9252 }
9253 
9254 /**
9255  *	t4_write_rss_pf_mask - write PF RSS Mask
9256  *	@adapter: the adapter
9257  *	@pfmask: PF RSS Mask value
9258  *
9259  *	Writes the specified value to the PF RSS Mask register.
9260  */
t4_write_rss_pf_mask(struct adapter * adapter,u32 pfmask,bool sleep_ok)9261 void t4_write_rss_pf_mask(struct adapter *adapter, u32 pfmask, bool sleep_ok)
9262 {
9263 	t4_tp_pio_write(adapter, &pfmask, 1, A_TP_RSS_PF_MSK, sleep_ok);
9264 }
9265 
9266 /**
9267  *	t4_tp_get_tcp_stats - read TP's TCP MIB counters
9268  *	@adap: the adapter
9269  *	@v4: holds the TCP/IP counter values
9270  *	@v6: holds the TCP/IPv6 counter values
9271  * 	@sleep_ok: if true we may sleep while awaiting command completion
9272  *
9273  *	Returns the values of TP's TCP/IP and TCP/IPv6 MIB counters.
9274  *	Either @v4 or @v6 may be %NULL to skip the corresponding stats.
9275  */
t4_tp_get_tcp_stats(struct adapter * adap,struct tp_tcp_stats * v4,struct tp_tcp_stats * v6,bool sleep_ok)9276 void t4_tp_get_tcp_stats(struct adapter *adap, struct tp_tcp_stats *v4,
9277 			 struct tp_tcp_stats *v6, bool sleep_ok)
9278 {
9279 	u32 val[A_TP_MIB_TCP_RXT_SEG_LO - A_TP_MIB_TCP_OUT_RST + 1];
9280 
9281 #define STAT_IDX(x) ((A_TP_MIB_TCP_##x) - A_TP_MIB_TCP_OUT_RST)
9282 #define STAT(x)     val[STAT_IDX(x)]
9283 #define STAT64(x)   (((u64)STAT(x##_HI) << 32) | STAT(x##_LO))
9284 
9285 	if (v4) {
9286 		t4_tp_mib_read(adap, val, ARRAY_SIZE(val),
9287 			       A_TP_MIB_TCP_OUT_RST, sleep_ok);
9288 		v4->tcp_out_rsts = STAT(OUT_RST);
9289 		v4->tcp_in_segs  = STAT64(IN_SEG);
9290 		v4->tcp_out_segs = STAT64(OUT_SEG);
9291 		v4->tcp_retrans_segs = STAT64(RXT_SEG);
9292 	}
9293 	if (v6) {
9294 		t4_tp_mib_read(adap, val, ARRAY_SIZE(val),
9295 			       A_TP_MIB_TCP_V6OUT_RST, sleep_ok);
9296 		v6->tcp_out_rsts = STAT(OUT_RST);
9297 		v6->tcp_in_segs  = STAT64(IN_SEG);
9298 		v6->tcp_out_segs = STAT64(OUT_SEG);
9299 		v6->tcp_retrans_segs = STAT64(RXT_SEG);
9300 	}
9301 #undef STAT64
9302 #undef STAT
9303 #undef STAT_IDX
9304 }
9305 
9306 /**
9307  *	t4_tp_get_err_stats - read TP's error MIB counters
9308  *	@adap: the adapter
9309  *	@st: holds the counter values
9310  * 	@sleep_ok: if true we may sleep while awaiting command completion
9311  *
9312  *	Returns the values of TP's error counters.
9313  */
t4_tp_get_err_stats(struct adapter * adap,struct tp_err_stats * st,bool sleep_ok)9314 void t4_tp_get_err_stats(struct adapter *adap, struct tp_err_stats *st,
9315 			 bool sleep_ok)
9316 {
9317 	int nchan = adap->chip_params->nchan;
9318 
9319 	t4_tp_mib_read(adap, st->mac_in_errs, nchan, A_TP_MIB_MAC_IN_ERR_0,
9320 		       sleep_ok);
9321 
9322 	t4_tp_mib_read(adap, st->hdr_in_errs, nchan, A_TP_MIB_HDR_IN_ERR_0,
9323 		       sleep_ok);
9324 
9325 	t4_tp_mib_read(adap, st->tcp_in_errs, nchan, A_TP_MIB_TCP_IN_ERR_0,
9326 		       sleep_ok);
9327 
9328 	t4_tp_mib_read(adap, st->tnl_cong_drops, nchan,
9329 		       A_TP_MIB_TNL_CNG_DROP_0, sleep_ok);
9330 
9331 	t4_tp_mib_read(adap, st->ofld_chan_drops, nchan,
9332 		       A_TP_MIB_OFD_CHN_DROP_0, sleep_ok);
9333 
9334 	t4_tp_mib_read(adap, st->tnl_tx_drops, nchan, A_TP_MIB_TNL_DROP_0,
9335 		       sleep_ok);
9336 
9337 	t4_tp_mib_read(adap, st->ofld_vlan_drops, nchan,
9338 		       A_TP_MIB_OFD_VLN_DROP_0, sleep_ok);
9339 
9340 	t4_tp_mib_read(adap, st->tcp6_in_errs, nchan,
9341 		       A_TP_MIB_TCP_V6IN_ERR_0, sleep_ok);
9342 
9343 	t4_tp_mib_read(adap, &st->ofld_no_neigh, 2, A_TP_MIB_OFD_ARP_DROP,
9344 		       sleep_ok);
9345 }
9346 
9347 /**
9348  *	t4_tp_get_err_stats - read TP's error MIB counters
9349  *	@adap: the adapter
9350  *	@st: holds the counter values
9351  * 	@sleep_ok: if true we may sleep while awaiting command completion
9352  *
9353  *	Returns the values of TP's error counters.
9354  */
t4_tp_get_tnl_stats(struct adapter * adap,struct tp_tnl_stats * st,bool sleep_ok)9355 void t4_tp_get_tnl_stats(struct adapter *adap, struct tp_tnl_stats *st,
9356 			 bool sleep_ok)
9357 {
9358 	int nchan = adap->chip_params->nchan;
9359 
9360 	t4_tp_mib_read(adap, st->out_pkt, nchan, A_TP_MIB_TNL_OUT_PKT_0,
9361 		       sleep_ok);
9362 	t4_tp_mib_read(adap, st->in_pkt, nchan, A_TP_MIB_TNL_IN_PKT_0,
9363 		       sleep_ok);
9364 }
9365 
9366 /**
9367  *	t4_tp_get_proxy_stats - read TP's proxy MIB counters
9368  *	@adap: the adapter
9369  *	@st: holds the counter values
9370  *
9371  *	Returns the values of TP's proxy counters.
9372  */
t4_tp_get_proxy_stats(struct adapter * adap,struct tp_proxy_stats * st,bool sleep_ok)9373 void t4_tp_get_proxy_stats(struct adapter *adap, struct tp_proxy_stats *st,
9374     bool sleep_ok)
9375 {
9376 	int nchan = adap->chip_params->nchan;
9377 
9378 	t4_tp_mib_read(adap, st->proxy, nchan, A_TP_MIB_TNL_LPBK_0, sleep_ok);
9379 }
9380 
9381 /**
9382  *	t4_tp_get_cpl_stats - read TP's CPL MIB counters
9383  *	@adap: the adapter
9384  *	@st: holds the counter values
9385  * 	@sleep_ok: if true we may sleep while awaiting command completion
9386  *
9387  *	Returns the values of TP's CPL counters.
9388  */
t4_tp_get_cpl_stats(struct adapter * adap,struct tp_cpl_stats * st,bool sleep_ok)9389 void t4_tp_get_cpl_stats(struct adapter *adap, struct tp_cpl_stats *st,
9390 			 bool sleep_ok)
9391 {
9392 	int nchan = adap->chip_params->nchan;
9393 
9394 	t4_tp_mib_read(adap, st->req, nchan, A_TP_MIB_CPL_IN_REQ_0, sleep_ok);
9395 
9396 	t4_tp_mib_read(adap, st->rsp, nchan, A_TP_MIB_CPL_OUT_RSP_0, sleep_ok);
9397 }
9398 
9399 /**
9400  *	t4_tp_get_rdma_stats - read TP's RDMA MIB counters
9401  *	@adap: the adapter
9402  *	@st: holds the counter values
9403  *
9404  *	Returns the values of TP's RDMA counters.
9405  */
t4_tp_get_rdma_stats(struct adapter * adap,struct tp_rdma_stats * st,bool sleep_ok)9406 void t4_tp_get_rdma_stats(struct adapter *adap, struct tp_rdma_stats *st,
9407 			  bool sleep_ok)
9408 {
9409 	t4_tp_mib_read(adap, &st->rqe_dfr_pkt, 2, A_TP_MIB_RQE_DFR_PKT,
9410 		       sleep_ok);
9411 
9412 	if (chip_id(adap) >= CHELSIO_T7)
9413 		/* read RDMA stats IN and OUT for all ports at once */
9414 		t4_tp_mib_read(adap, &st->pkts_in[0], 28, A_TP_MIB_RDMA_IN_PKT_0,
9415 			       sleep_ok);
9416 }
9417 
9418 /**
9419  *	t4_get_fcoe_stats - read TP's FCoE MIB counters for a port
9420  *	@adap: the adapter
9421  *	@idx: the port index
9422  *	@st: holds the counter values
9423  * 	@sleep_ok: if true we may sleep while awaiting command completion
9424  *
9425  *	Returns the values of TP's FCoE counters for the selected port.
9426  */
t4_get_fcoe_stats(struct adapter * adap,unsigned int idx,struct tp_fcoe_stats * st,bool sleep_ok)9427 void t4_get_fcoe_stats(struct adapter *adap, unsigned int idx,
9428 		       struct tp_fcoe_stats *st, bool sleep_ok)
9429 {
9430 	u32 val[2];
9431 
9432 	t4_tp_mib_read(adap, &st->frames_ddp, 1, A_TP_MIB_FCOE_DDP_0 + idx,
9433 		       sleep_ok);
9434 
9435 	t4_tp_mib_read(adap, &st->frames_drop, 1,
9436 		       A_TP_MIB_FCOE_DROP_0 + idx, sleep_ok);
9437 
9438 	t4_tp_mib_read(adap, val, 2, A_TP_MIB_FCOE_BYTE_0_HI + 2 * idx,
9439 		       sleep_ok);
9440 
9441 	st->octets_ddp = ((u64)val[0] << 32) | val[1];
9442 }
9443 
9444 /**
9445  *	t4_get_usm_stats - read TP's non-TCP DDP MIB counters
9446  *	@adap: the adapter
9447  *	@st: holds the counter values
9448  * 	@sleep_ok: if true we may sleep while awaiting command completion
9449  *
9450  *	Returns the values of TP's counters for non-TCP directly-placed packets.
9451  */
t4_get_usm_stats(struct adapter * adap,struct tp_usm_stats * st,bool sleep_ok)9452 void t4_get_usm_stats(struct adapter *adap, struct tp_usm_stats *st,
9453 		      bool sleep_ok)
9454 {
9455 	u32 val[4];
9456 
9457 	t4_tp_mib_read(adap, val, 4, A_TP_MIB_USM_PKTS, sleep_ok);
9458 
9459 	st->frames = val[0];
9460 	st->drops = val[1];
9461 	st->octets = ((u64)val[2] << 32) | val[3];
9462 }
9463 
9464 /**
9465  *	t4_tp_get_tid_stats - read TP's tid MIB counters.
9466  *	@adap: the adapter
9467  *	@st: holds the counter values
9468  * 	@sleep_ok: if true we may sleep while awaiting command completion
9469  *
9470  *	Returns the values of TP's counters for tids.
9471  */
t4_tp_get_tid_stats(struct adapter * adap,struct tp_tid_stats * st,bool sleep_ok)9472 void t4_tp_get_tid_stats(struct adapter *adap, struct tp_tid_stats *st,
9473 		      bool sleep_ok)
9474 {
9475 
9476 	t4_tp_mib_read(adap, &st->del, 4, A_TP_MIB_TID_DEL, sleep_ok);
9477 }
9478 
9479 /**
9480  *	t4_read_mtu_tbl - returns the values in the HW path MTU table
9481  *	@adap: the adapter
9482  *	@mtus: where to store the MTU values
9483  *	@mtu_log: where to store the MTU base-2 log (may be %NULL)
9484  *
9485  *	Reads the HW path MTU table.
9486  */
t4_read_mtu_tbl(struct adapter * adap,u16 * mtus,u8 * mtu_log)9487 void t4_read_mtu_tbl(struct adapter *adap, u16 *mtus, u8 *mtu_log)
9488 {
9489 	u32 v;
9490 	int i;
9491 
9492 	for (i = 0; i < NMTUS; ++i) {
9493 		t4_write_reg(adap, A_TP_MTU_TABLE,
9494 			     V_MTUINDEX(0xff) | V_MTUVALUE(i));
9495 		v = t4_read_reg(adap, A_TP_MTU_TABLE);
9496 		mtus[i] = G_MTUVALUE(v);
9497 		if (mtu_log)
9498 			mtu_log[i] = G_MTUWIDTH(v);
9499 	}
9500 }
9501 
9502 /**
9503  *	t4_read_cong_tbl - reads the congestion control table
9504  *	@adap: the adapter
9505  *	@incr: where to store the alpha values
9506  *
9507  *	Reads the additive increments programmed into the HW congestion
9508  *	control table.
9509  */
t4_read_cong_tbl(struct adapter * adap,u16 incr[NMTUS][NCCTRL_WIN])9510 void t4_read_cong_tbl(struct adapter *adap, u16 incr[NMTUS][NCCTRL_WIN])
9511 {
9512 	unsigned int mtu, w;
9513 
9514 	for (mtu = 0; mtu < NMTUS; ++mtu)
9515 		for (w = 0; w < NCCTRL_WIN; ++w) {
9516 			t4_write_reg(adap, A_TP_CCTRL_TABLE,
9517 				     V_ROWINDEX(0xffff) | (mtu << 5) | w);
9518 			incr[mtu][w] = (u16)t4_read_reg(adap,
9519 						A_TP_CCTRL_TABLE) & 0x1fff;
9520 		}
9521 }
9522 
9523 /**
9524  *	t4_tp_wr_bits_indirect - set/clear bits in an indirect TP register
9525  *	@adap: the adapter
9526  *	@addr: the indirect TP register address
9527  *	@mask: specifies the field within the register to modify
9528  *	@val: new value for the field
9529  *
9530  *	Sets a field of an indirect TP register to the given value.
9531  */
t4_tp_wr_bits_indirect(struct adapter * adap,unsigned int addr,unsigned int mask,unsigned int val)9532 void t4_tp_wr_bits_indirect(struct adapter *adap, unsigned int addr,
9533 			    unsigned int mask, unsigned int val)
9534 {
9535 	t4_write_reg(adap, A_TP_PIO_ADDR, addr);
9536 	val |= t4_read_reg(adap, A_TP_PIO_DATA) & ~mask;
9537 	t4_write_reg(adap, A_TP_PIO_DATA, val);
9538 }
9539 
9540 /**
9541  *	init_cong_ctrl - initialize congestion control parameters
9542  *	@a: the alpha values for congestion control
9543  *	@b: the beta values for congestion control
9544  *
9545  *	Initialize the congestion control parameters.
9546  */
init_cong_ctrl(unsigned short * a,unsigned short * b)9547 static void init_cong_ctrl(unsigned short *a, unsigned short *b)
9548 {
9549 	a[0] = a[1] = a[2] = a[3] = a[4] = a[5] = a[6] = a[7] = a[8] = 1;
9550 	a[9] = 2;
9551 	a[10] = 3;
9552 	a[11] = 4;
9553 	a[12] = 5;
9554 	a[13] = 6;
9555 	a[14] = 7;
9556 	a[15] = 8;
9557 	a[16] = 9;
9558 	a[17] = 10;
9559 	a[18] = 14;
9560 	a[19] = 17;
9561 	a[20] = 21;
9562 	a[21] = 25;
9563 	a[22] = 30;
9564 	a[23] = 35;
9565 	a[24] = 45;
9566 	a[25] = 60;
9567 	a[26] = 80;
9568 	a[27] = 100;
9569 	a[28] = 200;
9570 	a[29] = 300;
9571 	a[30] = 400;
9572 	a[31] = 500;
9573 
9574 	b[0] = b[1] = b[2] = b[3] = b[4] = b[5] = b[6] = b[7] = b[8] = 0;
9575 	b[9] = b[10] = 1;
9576 	b[11] = b[12] = 2;
9577 	b[13] = b[14] = b[15] = b[16] = 3;
9578 	b[17] = b[18] = b[19] = b[20] = b[21] = 4;
9579 	b[22] = b[23] = b[24] = b[25] = b[26] = b[27] = 5;
9580 	b[28] = b[29] = 6;
9581 	b[30] = b[31] = 7;
9582 }
9583 
9584 /* The minimum additive increment value for the congestion control table */
9585 #define CC_MIN_INCR 2U
9586 
9587 /**
9588  *	t4_load_mtus - write the MTU and congestion control HW tables
9589  *	@adap: the adapter
9590  *	@mtus: the values for the MTU table
9591  *	@alpha: the values for the congestion control alpha parameter
9592  *	@beta: the values for the congestion control beta parameter
9593  *
9594  *	Write the HW MTU table with the supplied MTUs and the high-speed
9595  *	congestion control table with the supplied alpha, beta, and MTUs.
9596  *	We write the two tables together because the additive increments
9597  *	depend on the MTUs.
9598  */
t4_load_mtus(struct adapter * adap,const unsigned short * mtus,const unsigned short * alpha,const unsigned short * beta)9599 void t4_load_mtus(struct adapter *adap, const unsigned short *mtus,
9600 		  const unsigned short *alpha, const unsigned short *beta)
9601 {
9602 	static const unsigned int avg_pkts[NCCTRL_WIN] = {
9603 		2, 6, 10, 14, 20, 28, 40, 56, 80, 112, 160, 224, 320, 448, 640,
9604 		896, 1281, 1792, 2560, 3584, 5120, 7168, 10240, 14336, 20480,
9605 		28672, 40960, 57344, 81920, 114688, 163840, 229376
9606 	};
9607 
9608 	unsigned int i, w;
9609 
9610 	for (i = 0; i < NMTUS; ++i) {
9611 		unsigned int mtu = mtus[i];
9612 		unsigned int log2 = fls(mtu);
9613 
9614 		if (!(mtu & ((1 << log2) >> 2)))     /* round */
9615 			log2--;
9616 		t4_write_reg(adap, A_TP_MTU_TABLE, V_MTUINDEX(i) |
9617 			     V_MTUWIDTH(log2) | V_MTUVALUE(mtu));
9618 
9619 		for (w = 0; w < NCCTRL_WIN; ++w) {
9620 			unsigned int inc;
9621 
9622 			inc = max(((mtu - 40) * alpha[w]) / avg_pkts[w],
9623 				  CC_MIN_INCR);
9624 
9625 			t4_write_reg(adap, A_TP_CCTRL_TABLE, (i << 21) |
9626 				     (w << 16) | (beta[w] << 13) | inc);
9627 		}
9628 	}
9629 }
9630 
9631 /**
9632  *	t4_set_pace_tbl - set the pace table
9633  *	@adap: the adapter
9634  *	@pace_vals: the pace values in microseconds
9635  *	@start: index of the first entry in the HW pace table to set
9636  *	@n: how many entries to set
9637  *
9638  *	Sets (a subset of the) HW pace table.
9639  */
t4_set_pace_tbl(struct adapter * adap,const unsigned int * pace_vals,unsigned int start,unsigned int n)9640 int t4_set_pace_tbl(struct adapter *adap, const unsigned int *pace_vals,
9641 		     unsigned int start, unsigned int n)
9642 {
9643 	unsigned int vals[NTX_SCHED], i;
9644 	unsigned int tick_ns = dack_ticks_to_usec(adap, 1000);
9645 
9646 	if (n > NTX_SCHED)
9647 	    return -ERANGE;
9648 
9649 	/* convert values from us to dack ticks, rounding to closest value */
9650 	for (i = 0; i < n; i++, pace_vals++) {
9651 		vals[i] = (1000 * *pace_vals + tick_ns / 2) / tick_ns;
9652 		if (vals[i] > 0x7ff)
9653 			return -ERANGE;
9654 		if (*pace_vals && vals[i] == 0)
9655 			return -ERANGE;
9656 	}
9657 	for (i = 0; i < n; i++, start++)
9658 		t4_write_reg(adap, A_TP_PACE_TABLE, (start << 16) | vals[i]);
9659 	return 0;
9660 }
9661 
9662 /**
9663  *	t4_set_sched_bps - set the bit rate for a HW traffic scheduler
9664  *	@adap: the adapter
9665  *	@kbps: target rate in Kbps
9666  *	@sched: the scheduler index
9667  *
9668  *	Configure a Tx HW scheduler for the target rate.
9669  */
t4_set_sched_bps(struct adapter * adap,int sched,unsigned int kbps)9670 int t4_set_sched_bps(struct adapter *adap, int sched, unsigned int kbps)
9671 {
9672 	unsigned int v, tps, cpt, bpt, delta, mindelta = ~0;
9673 	unsigned int clk = adap->params.vpd.cclk * 1000;
9674 	unsigned int selected_cpt = 0, selected_bpt = 0;
9675 
9676 	if (kbps > 0) {
9677 		kbps *= 125;     /* -> bytes */
9678 		for (cpt = 1; cpt <= 255; cpt++) {
9679 			tps = clk / cpt;
9680 			bpt = (kbps + tps / 2) / tps;
9681 			if (bpt > 0 && bpt <= 255) {
9682 				v = bpt * tps;
9683 				delta = v >= kbps ? v - kbps : kbps - v;
9684 				if (delta < mindelta) {
9685 					mindelta = delta;
9686 					selected_cpt = cpt;
9687 					selected_bpt = bpt;
9688 				}
9689 			} else if (selected_cpt)
9690 				break;
9691 		}
9692 		if (!selected_cpt)
9693 			return -EINVAL;
9694 	}
9695 	t4_write_reg(adap, A_TP_TM_PIO_ADDR,
9696 		     A_TP_TX_MOD_Q1_Q0_RATE_LIMIT - sched / 2);
9697 	v = t4_read_reg(adap, A_TP_TM_PIO_DATA);
9698 	if (sched & 1)
9699 		v = (v & 0xffff) | (selected_cpt << 16) | (selected_bpt << 24);
9700 	else
9701 		v = (v & 0xffff0000) | selected_cpt | (selected_bpt << 8);
9702 	t4_write_reg(adap, A_TP_TM_PIO_DATA, v);
9703 	return 0;
9704 }
9705 
9706 /**
9707  *	t4_set_sched_ipg - set the IPG for a Tx HW packet rate scheduler
9708  *	@adap: the adapter
9709  *	@sched: the scheduler index
9710  *	@ipg: the interpacket delay in tenths of nanoseconds
9711  *
9712  *	Set the interpacket delay for a HW packet rate scheduler.
9713  */
t4_set_sched_ipg(struct adapter * adap,int sched,unsigned int ipg)9714 int t4_set_sched_ipg(struct adapter *adap, int sched, unsigned int ipg)
9715 {
9716 	unsigned int v, addr = A_TP_TX_MOD_Q1_Q0_TIMER_SEPARATOR - sched / 2;
9717 
9718 	/* convert ipg to nearest number of core clocks */
9719 	ipg *= core_ticks_per_usec(adap);
9720 	ipg = (ipg + 5000) / 10000;
9721 	if (ipg > M_TXTIMERSEPQ0)
9722 		return -EINVAL;
9723 
9724 	t4_write_reg(adap, A_TP_TM_PIO_ADDR, addr);
9725 	v = t4_read_reg(adap, A_TP_TM_PIO_DATA);
9726 	if (sched & 1)
9727 		v = (v & V_TXTIMERSEPQ0(M_TXTIMERSEPQ0)) | V_TXTIMERSEPQ1(ipg);
9728 	else
9729 		v = (v & V_TXTIMERSEPQ1(M_TXTIMERSEPQ1)) | V_TXTIMERSEPQ0(ipg);
9730 	t4_write_reg(adap, A_TP_TM_PIO_DATA, v);
9731 	t4_read_reg(adap, A_TP_TM_PIO_DATA);
9732 	return 0;
9733 }
9734 
9735 /*
9736  * Calculates a rate in bytes/s given the number of 256-byte units per 4K core
9737  * clocks.  The formula is
9738  *
9739  * bytes/s = bytes256 * 256 * ClkFreq / 4096
9740  *
9741  * which is equivalent to
9742  *
9743  * bytes/s = 62.5 * bytes256 * ClkFreq_ms
9744  */
chan_rate(struct adapter * adap,unsigned int bytes256)9745 static u64 chan_rate(struct adapter *adap, unsigned int bytes256)
9746 {
9747 	u64 v = (u64)bytes256 * adap->params.vpd.cclk;
9748 
9749 	return v * 62 + v / 2;
9750 }
9751 
9752 /**
9753  *	t4_get_chan_txrate - get the current per channel Tx rates
9754  *	@adap: the adapter
9755  *	@nic_rate: rates for NIC traffic
9756  *	@ofld_rate: rates for offloaded traffic
9757  *
9758  *	Return the current Tx rates in bytes/s for NIC and offloaded traffic
9759  *	for each channel.
9760  */
t4_get_chan_txrate(struct adapter * adap,u64 * nic_rate,u64 * ofld_rate)9761 void t4_get_chan_txrate(struct adapter *adap, u64 *nic_rate, u64 *ofld_rate)
9762 {
9763 	u32 v;
9764 
9765 	v = t4_read_reg(adap, A_TP_TX_TRATE);
9766 	nic_rate[0] = chan_rate(adap, G_TNLRATE0(v));
9767 	nic_rate[1] = chan_rate(adap, G_TNLRATE1(v));
9768 	if (adap->chip_params->nchan > 2) {
9769 		nic_rate[2] = chan_rate(adap, G_TNLRATE2(v));
9770 		nic_rate[3] = chan_rate(adap, G_TNLRATE3(v));
9771 	}
9772 
9773 	v = t4_read_reg(adap, A_TP_TX_ORATE);
9774 	ofld_rate[0] = chan_rate(adap, G_OFDRATE0(v));
9775 	ofld_rate[1] = chan_rate(adap, G_OFDRATE1(v));
9776 	if (adap->chip_params->nchan > 2) {
9777 		ofld_rate[2] = chan_rate(adap, G_OFDRATE2(v));
9778 		ofld_rate[3] = chan_rate(adap, G_OFDRATE3(v));
9779 	}
9780 }
9781 
9782 /**
9783  *	t4_set_trace_filter - configure one of the tracing filters
9784  *	@adap: the adapter
9785  *	@tp: the desired trace filter parameters
9786  *	@idx: which filter to configure
9787  *	@enable: whether to enable or disable the filter
9788  *
9789  *	Configures one of the tracing filters available in HW.  If @tp is %NULL
9790  *	it indicates that the filter is already written in the register and it
9791  *	just needs to be enabled or disabled.
9792  */
t4_set_trace_filter(struct adapter * adap,const struct trace_params * tp,int idx,int enable)9793 int t4_set_trace_filter(struct adapter *adap, const struct trace_params *tp,
9794     int idx, int enable)
9795 {
9796 	int i, ofst;
9797 	u32 match_ctl_a, match_ctl_b;
9798 	u32 data_reg, mask_reg, cfg;
9799 	u32 en = is_t4(adap) ? F_TFEN : F_T5_TFEN;
9800 
9801 	if (idx < 0 || idx >= NTRACE)
9802 		return -EINVAL;
9803 
9804 	if (chip_id(adap) >= CHELSIO_T7) {
9805 		match_ctl_a = T7_MPS_TRC_FILTER_MATCH_CTL_A(idx);
9806 		match_ctl_b = T7_MPS_TRC_FILTER_MATCH_CTL_B(idx);
9807 	} else {
9808 		match_ctl_a = MPS_TRC_FILTER_MATCH_CTL_A(idx);
9809 		match_ctl_b = MPS_TRC_FILTER_MATCH_CTL_B(idx);
9810 	}
9811 
9812 	if (tp == NULL || !enable) {
9813 		t4_set_reg_field(adap, match_ctl_a, en, enable ? en : 0);
9814 		return 0;
9815 	}
9816 
9817 	/*
9818 	 * TODO - After T4 data book is updated, specify the exact
9819 	 * section below.
9820 	 *
9821 	 * See T4 data book - MPS section for a complete description
9822 	 * of the below if..else handling of A_MPS_TRC_CFG register
9823 	 * value.
9824 	 */
9825 	cfg = t4_read_reg(adap, A_MPS_TRC_CFG);
9826 	if (cfg & F_TRCMULTIFILTER) {
9827 		/*
9828 		 * If multiple tracers are enabled, then maximum
9829 		 * capture size is 2.5KB (FIFO size of a single channel)
9830 		 * minus 2 flits for CPL_TRACE_PKT header.
9831 		 */
9832 		if (tp->snap_len > ((10 * 1024 / 4) - (2 * 8)))
9833 			return -EINVAL;
9834 	} else {
9835 		/*
9836 		 * If multiple tracers are disabled, to avoid deadlocks
9837 		 * maximum packet capture size of 9600 bytes is recommended.
9838 		 * Also in this mode, only trace0 can be enabled and running.
9839 		 */
9840 		if (tp->snap_len > 9600 || idx)
9841 			return -EINVAL;
9842 	}
9843 
9844 	if (tp->port > (is_t4(adap) ? 11 : 19) || tp->invert > 1 ||
9845 	    tp->skip_len > M_TFLENGTH || tp->skip_ofst > M_TFOFFSET ||
9846 	    tp->min_len > M_TFMINPKTSIZE)
9847 		return -EINVAL;
9848 
9849 	/* stop the tracer we'll be changing */
9850 	t4_set_reg_field(adap, match_ctl_a, en, 0);
9851 
9852 	ofst = (A_MPS_TRC_FILTER1_MATCH - A_MPS_TRC_FILTER0_MATCH) * idx;
9853 	data_reg = A_MPS_TRC_FILTER0_MATCH + ofst;
9854 	mask_reg = A_MPS_TRC_FILTER0_DONT_CARE + ofst;
9855 
9856 	for (i = 0; i < TRACE_LEN / 4; i++, data_reg += 4, mask_reg += 4) {
9857 		t4_write_reg(adap, data_reg, tp->data[i]);
9858 		t4_write_reg(adap, mask_reg, ~tp->mask[i]);
9859 	}
9860 	t4_write_reg(adap, match_ctl_b, V_TFCAPTUREMAX(tp->snap_len) |
9861 		     V_TFMINPKTSIZE(tp->min_len));
9862 	t4_write_reg(adap, match_ctl_a, V_TFOFFSET(tp->skip_ofst) |
9863 		     V_TFLENGTH(tp->skip_len) | en | (is_t4(adap) ?
9864 		     V_TFPORT(tp->port) | V_TFINVERTMATCH(tp->invert) :
9865 		     V_T5_TFPORT(tp->port) | V_T5_TFINVERTMATCH(tp->invert)));
9866 
9867 	return 0;
9868 }
9869 
9870 /**
9871  *	t4_get_trace_filter - query one of the tracing filters
9872  *	@adap: the adapter
9873  *	@tp: the current trace filter parameters
9874  *	@idx: which trace filter to query
9875  *	@enabled: non-zero if the filter is enabled
9876  *
9877  *	Returns the current settings of one of the HW tracing filters.
9878  */
t4_get_trace_filter(struct adapter * adap,struct trace_params * tp,int idx,int * enabled)9879 void t4_get_trace_filter(struct adapter *adap, struct trace_params *tp, int idx,
9880 			 int *enabled)
9881 {
9882 	u32 ctla, ctlb;
9883 	int i, ofst;
9884 	u32 data_reg, mask_reg;
9885 
9886 	if (chip_id(adap) >= CHELSIO_T7) {
9887 		ctla = t4_read_reg(adap, T7_MPS_TRC_FILTER_MATCH_CTL_A(idx));
9888 		ctlb = t4_read_reg(adap, T7_MPS_TRC_FILTER_MATCH_CTL_B(idx));
9889 	} else {
9890 		ctla = t4_read_reg(adap, MPS_TRC_FILTER_MATCH_CTL_A(idx));
9891 		ctlb = t4_read_reg(adap, MPS_TRC_FILTER_MATCH_CTL_B(idx));
9892 	}
9893 
9894 	if (is_t4(adap)) {
9895 		*enabled = !!(ctla & F_TFEN);
9896 		tp->port =  G_TFPORT(ctla);
9897 		tp->invert = !!(ctla & F_TFINVERTMATCH);
9898 	} else {
9899 		*enabled = !!(ctla & F_T5_TFEN);
9900 		tp->port = G_T5_TFPORT(ctla);
9901 		tp->invert = !!(ctla & F_T5_TFINVERTMATCH);
9902 	}
9903 	tp->snap_len = G_TFCAPTUREMAX(ctlb);
9904 	tp->min_len = G_TFMINPKTSIZE(ctlb);
9905 	tp->skip_ofst = G_TFOFFSET(ctla);
9906 	tp->skip_len = G_TFLENGTH(ctla);
9907 
9908 	ofst = (A_MPS_TRC_FILTER1_MATCH - A_MPS_TRC_FILTER0_MATCH) * idx;
9909 	data_reg = A_MPS_TRC_FILTER0_MATCH + ofst;
9910 	mask_reg = A_MPS_TRC_FILTER0_DONT_CARE + ofst;
9911 
9912 	for (i = 0; i < TRACE_LEN / 4; i++, data_reg += 4, mask_reg += 4) {
9913 		tp->mask[i] = ~t4_read_reg(adap, mask_reg);
9914 		tp->data[i] = t4_read_reg(adap, data_reg) & tp->mask[i];
9915 	}
9916 }
9917 
9918 /**
9919  *	t4_set_trace_rss_control - configure the trace rss control register
9920  *	@adap: the adapter
9921  *	@chan: the channel number for RSS control
9922  *	@qid: queue number
9923  *
9924  *	Configures the MPS tracing RSS control parameter for specified
9925  *	@chan channel and @qid queue number.
9926  */
t4_set_trace_rss_control(struct adapter * adap,u8 chan,u16 qid)9927 void t4_set_trace_rss_control(struct adapter *adap, u8 chan, u16 qid)
9928 {
9929 	u32 mps_trc_rss_control;
9930 
9931 	switch (chip_id(adap)) {
9932 	case CHELSIO_T4:
9933 		mps_trc_rss_control = A_MPS_TRC_RSS_CONTROL;
9934 		break;
9935 	case CHELSIO_T5:
9936 	case CHELSIO_T6:
9937 		mps_trc_rss_control = A_MPS_T5_TRC_RSS_CONTROL;
9938 		break;
9939 	case CHELSIO_T7:
9940 	default:
9941 		mps_trc_rss_control = A_T7_MPS_T5_TRC_RSS_CONTROL;
9942 		break;
9943 	}
9944 
9945 	t4_write_reg(adap, mps_trc_rss_control,
9946 		     V_RSSCONTROL(chan) | V_QUEUENUMBER(qid));
9947 }
9948 
9949 /**
9950  *	t4_pmtx_get_stats - returns the HW stats from PMTX
9951  *	@adap: the adapter
9952  *	@cnt: where to store the count statistics
9953  *	@cycles: where to store the cycle statistics
9954  *
9955  *	Returns performance statistics from PMTX.
9956  */
t4_pmtx_get_stats(struct adapter * adap,u32 cnt[],u64 cycles[])9957 void t4_pmtx_get_stats(struct adapter *adap, u32 cnt[], u64 cycles[])
9958 {
9959 	int i;
9960 	u32 data[2];
9961 
9962 	for (i = 0; i < adap->chip_params->pm_stats_cnt; i++) {
9963 		t4_write_reg(adap, A_PM_TX_STAT_CONFIG, i + 1);
9964 		cnt[i] = t4_read_reg(adap, A_PM_TX_STAT_COUNT);
9965 		if (is_t4(adap))
9966 			cycles[i] = t4_read_reg64(adap, A_PM_TX_STAT_LSB);
9967 		else {
9968 			t4_read_indirect(adap, A_PM_TX_DBG_CTRL,
9969 					 A_PM_TX_DBG_DATA, data, 2,
9970 					 chip_id(adap) >= CHELSIO_T7 ?
9971 					 A_T7_PM_TX_DBG_STAT_MSB :
9972 					 A_PM_TX_DBG_STAT_MSB);
9973 			cycles[i] = (((u64)data[0] << 32) | data[1]);
9974 		}
9975 	}
9976 }
9977 
9978 /**
9979  *	t4_pmrx_get_stats - returns the HW stats from PMRX
9980  *	@adap: the adapter
9981  *	@cnt: where to store the count statistics
9982  *	@cycles: where to store the cycle statistics
9983  *
9984  *	Returns performance statistics from PMRX.
9985  */
t4_pmrx_get_stats(struct adapter * adap,u32 cnt[],u64 cycles[])9986 void t4_pmrx_get_stats(struct adapter *adap, u32 cnt[], u64 cycles[])
9987 {
9988 	int i;
9989 	u32 data[2];
9990 
9991 	for (i = 0; i < adap->chip_params->pm_stats_cnt; i++) {
9992 		t4_write_reg(adap, A_PM_RX_STAT_CONFIG, i + 1);
9993 		cnt[i] = t4_read_reg(adap, A_PM_RX_STAT_COUNT);
9994 		if (is_t4(adap)) {
9995 			cycles[i] = t4_read_reg64(adap, A_PM_RX_STAT_LSB);
9996 		} else {
9997 			t4_read_indirect(adap, A_PM_RX_DBG_CTRL,
9998 					 A_PM_RX_DBG_DATA, data, 2,
9999 					 A_PM_RX_DBG_STAT_MSB);
10000 			cycles[i] = (((u64)data[0] << 32) | data[1]);
10001 		}
10002 	}
10003 }
10004 
10005 /**
10006  * t4_pmrx_cache_get_stats - returns the HW PMRX cache stats
10007  * @adap: the adapter
10008  * @stats: where to store the statistics
10009  *
10010  * Returns performance statistics of PMRX cache.
10011  */
t4_pmrx_cache_get_stats(struct adapter * adap,u32 stats[])10012 void t4_pmrx_cache_get_stats(struct adapter *adap, u32 stats[])
10013 {
10014 	u8 i, j;
10015 
10016 	for (i = 0, j = 0; i < T7_PM_RX_CACHE_NSTATS / 3; i++, j += 3) {
10017 		t4_write_reg(adap, A_PM_RX_STAT_CONFIG, 0x100 + i);
10018 		stats[j] = t4_read_reg(adap, A_PM_RX_STAT_COUNT);
10019 		t4_read_indirect(adap, A_PM_RX_DBG_CTRL, A_PM_RX_DBG_DATA,
10020 				 &stats[j + 1], 2, A_PM_RX_DBG_STAT_MSB);
10021 	}
10022 }
10023 
10024 /**
10025  *	t4_get_mps_bg_map - return the buffer groups associated with a port
10026  *	@adap: the adapter
10027  *	@idx: the port index
10028  *
10029  *	Returns a bitmap indicating which MPS buffer groups are associated
10030  *	with the given port.  Bit i is set if buffer group i is used by the
10031  *	port.
10032  */
t4_get_mps_bg_map(struct adapter * adap,int idx)10033 static unsigned int t4_get_mps_bg_map(struct adapter *adap, int idx)
10034 {
10035 	u32 n;
10036 
10037 	if (adap->params.mps_bg_map != UINT32_MAX)
10038 		return ((adap->params.mps_bg_map >> (idx << 3)) & 0xff);
10039 
10040 	n = adap->params.nports;
10041 	MPASS(n > 0 && n <= MAX_NPORTS);
10042 	if (n == 1)
10043 		return idx == 0 ? 0xf : 0;
10044 	if (n == 2 && chip_id(adap) <= CHELSIO_T5)
10045 		return idx < 2 ? (3 << (2 * idx)) : 0;
10046 	return 1 << idx;
10047 }
10048 
10049 /*
10050  * TP RX e-channels associated with the port.
10051  */
t4_get_rx_e_chan_map(struct adapter * adap,int idx)10052 static unsigned int t4_get_rx_e_chan_map(struct adapter *adap, int idx)
10053 {
10054 	const u32 n = adap->params.nports;
10055 	const u32 all_chan = (1 << adap->chip_params->nchan) - 1;
10056 
10057 	switch (adap->params.tp.lb_mode) {
10058 	case 0:
10059 		if (n == 1)
10060 			return (all_chan);
10061 		if (n == 2 && chip_id(adap) <= CHELSIO_T5)
10062 			return (3 << (2 * idx));
10063 		return (1 << idx);
10064 	case 1:
10065 		MPASS(n == 1);
10066 		return (all_chan);
10067 	case 2:
10068 		MPASS(n <= 2);
10069 		return (3 << (2 * idx));
10070 	default:
10071 		CH_ERR(adap, "Unsupported LB mode %d\n",
10072 		    adap->params.tp.lb_mode);
10073 		return (0);
10074 	}
10075 }
10076 
10077 /*
10078  * TP RX c-channel associated with the port.
10079  */
t4_get_rx_c_chan(struct adapter * adap,int idx)10080 static unsigned int t4_get_rx_c_chan(struct adapter *adap, int idx)
10081 {
10082 	if (adap->params.tp_ch_map != UINT32_MAX)
10083 		return (adap->params.tp_ch_map >> (8 * idx)) & 0xff;
10084         return 0;
10085 }
10086 
10087 /*
10088  * TP TX c-channel associated with the port.
10089  */
t4_get_tx_c_chan(struct adapter * adap,int idx)10090 static unsigned int t4_get_tx_c_chan(struct adapter *adap, int idx)
10091 {
10092 	if (adap->params.tx_tp_ch_map != UINT32_MAX)
10093 		return (adap->params.tx_tp_ch_map >> (8 * idx)) & 0xff;
10094 	return idx;
10095 }
10096 
10097 /**
10098  *      t4_get_port_type_description - return Port Type string description
10099  *      @port_type: firmware Port Type enumeration
10100  */
t4_get_port_type_description(enum fw_port_type port_type)10101 const char *t4_get_port_type_description(enum fw_port_type port_type)
10102 {
10103 	static const char *const port_type_description[] = {
10104 		"Fiber_XFI",
10105 		"Fiber_XAUI",
10106 		"BT_SGMII",
10107 		"BT_XFI",
10108 		"BT_XAUI",
10109 		"KX4",
10110 		"CX4",
10111 		"KX",
10112 		"KR",
10113 		"SFP",
10114 		"BP_AP",
10115 		"BP4_AP",
10116 		"QSFP_10G",
10117 		"QSA",
10118 		"QSFP",
10119 		"BP40_BA",
10120 		"KR4_100G",
10121 		"CR4_QSFP",
10122 		"CR_QSFP",
10123 		"CR2_QSFP",
10124 		"SFP28",
10125 		"KR_SFP28",
10126 		"KR_XLAUI",
10127 	};
10128 
10129 	if (port_type < ARRAY_SIZE(port_type_description))
10130 		return port_type_description[port_type];
10131 	return "UNKNOWN";
10132 }
10133 
10134 /**
10135  *      t4_get_port_stats_offset - collect port stats relative to a previous
10136  *				   snapshot
10137  *      @adap: The adapter
10138  *      @idx: The port
10139  *      @stats: Current stats to fill
10140  *      @offset: Previous stats snapshot
10141  */
t4_get_port_stats_offset(struct adapter * adap,int idx,struct port_stats * stats,struct port_stats * offset)10142 void t4_get_port_stats_offset(struct adapter *adap, int idx,
10143 		struct port_stats *stats,
10144 		struct port_stats *offset)
10145 {
10146 	u64 *s, *o;
10147 	int i;
10148 
10149 	t4_get_port_stats(adap, idx, stats);
10150 	for (i = 0, s = (u64 *)stats, o = (u64 *)offset ;
10151 			i < (sizeof(struct port_stats)/sizeof(u64)) ;
10152 			i++, s++, o++)
10153 		*s -= *o;
10154 }
10155 
10156 /**
10157  *	t4_get_port_stats - collect port statistics
10158  *	@adap: the adapter
10159  *	@idx: the port index
10160  *	@p: the stats structure to fill
10161  *
10162  *	Collect statistics related to the given port from HW.
10163  */
t4_get_port_stats(struct adapter * adap,int idx,struct port_stats * p)10164 void t4_get_port_stats(struct adapter *adap, int idx, struct port_stats *p)
10165 {
10166 	struct port_info *pi;
10167 	int port_id, tx_chan;
10168 	u32 bgmap, stat_ctl;
10169 
10170 	port_id  = adap->port_map[idx];
10171 	MPASS(port_id >= 0 && port_id <= adap->params.nports);
10172 	pi = adap->port[port_id];
10173 
10174 #define GET_STAT(name) \
10175 	t4_read_reg64(adap, \
10176 	    t4_port_reg(adap, tx_chan, A_MPS_PORT_STAT_##name##_L));
10177 	memset(p, 0, sizeof(*p));
10178 	for (tx_chan = pi->tx_chan;
10179 	    tx_chan < pi->tx_chan + adap->params.tp.lb_nchan; tx_chan++) {
10180 		p->tx_pause		+= GET_STAT(TX_PORT_PAUSE);
10181 		p->tx_octets		+= GET_STAT(TX_PORT_BYTES);
10182 		p->tx_frames		+= GET_STAT(TX_PORT_FRAMES);
10183 		p->tx_bcast_frames	+= GET_STAT(TX_PORT_BCAST);
10184 		p->tx_mcast_frames	+= GET_STAT(TX_PORT_MCAST);
10185 		p->tx_ucast_frames	+= GET_STAT(TX_PORT_UCAST);
10186 		p->tx_error_frames	+= GET_STAT(TX_PORT_ERROR);
10187 		p->tx_frames_64		+= GET_STAT(TX_PORT_64B);
10188 		p->tx_frames_65_127	+= GET_STAT(TX_PORT_65B_127B);
10189 		p->tx_frames_128_255	+= GET_STAT(TX_PORT_128B_255B);
10190 		p->tx_frames_256_511	+= GET_STAT(TX_PORT_256B_511B);
10191 		p->tx_frames_512_1023	+= GET_STAT(TX_PORT_512B_1023B);
10192 		p->tx_frames_1024_1518	+= GET_STAT(TX_PORT_1024B_1518B);
10193 		p->tx_frames_1519_max	+= GET_STAT(TX_PORT_1519B_MAX);
10194 		p->tx_drop		+= GET_STAT(TX_PORT_DROP);
10195 		p->tx_ppp0		+= GET_STAT(TX_PORT_PPP0);
10196 		p->tx_ppp1		+= GET_STAT(TX_PORT_PPP1);
10197 		p->tx_ppp2		+= GET_STAT(TX_PORT_PPP2);
10198 		p->tx_ppp3		+= GET_STAT(TX_PORT_PPP3);
10199 		p->tx_ppp4		+= GET_STAT(TX_PORT_PPP4);
10200 		p->tx_ppp5		+= GET_STAT(TX_PORT_PPP5);
10201 		p->tx_ppp6		+= GET_STAT(TX_PORT_PPP6);
10202 		p->tx_ppp7		+= GET_STAT(TX_PORT_PPP7);
10203 
10204 		p->rx_pause		+= GET_STAT(RX_PORT_PAUSE);
10205 		p->rx_octets		+= GET_STAT(RX_PORT_BYTES);
10206 		p->rx_frames		+= GET_STAT(RX_PORT_FRAMES);
10207 		p->rx_bcast_frames	+= GET_STAT(RX_PORT_BCAST);
10208 		p->rx_mcast_frames	+= GET_STAT(RX_PORT_MCAST);
10209 		p->rx_ucast_frames	+= GET_STAT(RX_PORT_UCAST);
10210 		p->rx_too_long		+= GET_STAT(RX_PORT_MTU_ERROR);
10211 		p->rx_jabber		+= GET_STAT(RX_PORT_MTU_CRC_ERROR);
10212 		p->rx_len_err		+= GET_STAT(RX_PORT_LEN_ERROR);
10213 		p->rx_symbol_err	+= GET_STAT(RX_PORT_SYM_ERROR);
10214 		p->rx_runt		+= GET_STAT(RX_PORT_LESS_64B);
10215 		p->rx_frames_64		+= GET_STAT(RX_PORT_64B);
10216 		p->rx_frames_65_127	+= GET_STAT(RX_PORT_65B_127B);
10217 		p->rx_frames_128_255	+= GET_STAT(RX_PORT_128B_255B);
10218 		p->rx_frames_256_511	+= GET_STAT(RX_PORT_256B_511B);
10219 		p->rx_frames_512_1023	+= GET_STAT(RX_PORT_512B_1023B);
10220 		p->rx_frames_1024_1518	+= GET_STAT(RX_PORT_1024B_1518B);
10221 		p->rx_frames_1519_max	+= GET_STAT(RX_PORT_1519B_MAX);
10222 		p->rx_ppp0		+= GET_STAT(RX_PORT_PPP0);
10223 		p->rx_ppp1		+= GET_STAT(RX_PORT_PPP1);
10224 		p->rx_ppp2		+= GET_STAT(RX_PORT_PPP2);
10225 		p->rx_ppp3		+= GET_STAT(RX_PORT_PPP3);
10226 		p->rx_ppp4		+= GET_STAT(RX_PORT_PPP4);
10227 		p->rx_ppp5		+= GET_STAT(RX_PORT_PPP5);
10228 		p->rx_ppp6		+= GET_STAT(RX_PORT_PPP6);
10229 		p->rx_ppp7		+= GET_STAT(RX_PORT_PPP7);
10230 		if (!is_t6(adap)) {
10231 			MPASS(pi->fcs_reg == A_MPS_PORT_STAT_RX_PORT_CRC_ERROR_L);
10232 			p->rx_fcs_err	+= GET_STAT(RX_PORT_CRC_ERROR);
10233 		}
10234 	}
10235 #undef GET_STAT
10236 
10237 	if (is_t6(adap) && pi->fcs_reg != -1)
10238 		p->rx_fcs_err = t4_read_reg64(adap,
10239 		    t4_port_reg(adap, pi->tx_chan, pi->fcs_reg)) - pi->fcs_base;
10240 
10241 	if (chip_id(adap) >= CHELSIO_T5) {
10242 		stat_ctl = t4_read_reg(adap, A_MPS_STAT_CTL);
10243 		if (stat_ctl & F_COUNTPAUSESTATTX) {
10244 			p->tx_frames -= p->tx_pause;
10245 			p->tx_octets -= p->tx_pause * 64;
10246 		}
10247 		if (stat_ctl & F_COUNTPAUSEMCTX)
10248 			p->tx_mcast_frames -= p->tx_pause;
10249 		if (stat_ctl & F_COUNTPAUSESTATRX) {
10250 			p->rx_frames -= p->rx_pause;
10251 			p->rx_octets -= p->rx_pause * 64;
10252 		}
10253 		if (stat_ctl & F_COUNTPAUSEMCRX)
10254 			p->rx_mcast_frames -= p->rx_pause;
10255 	}
10256 
10257 #define GET_STAT_COM(name) t4_read_reg64(adap, A_MPS_STAT_##name##_L)
10258 	bgmap = pi->mps_bg_map;
10259 	p->rx_ovflow0 = (bgmap & 1) ? GET_STAT_COM(RX_BG_0_MAC_DROP_FRAME) : 0;
10260 	p->rx_ovflow1 = (bgmap & 2) ? GET_STAT_COM(RX_BG_1_MAC_DROP_FRAME) : 0;
10261 	p->rx_ovflow2 = (bgmap & 4) ? GET_STAT_COM(RX_BG_2_MAC_DROP_FRAME) : 0;
10262 	p->rx_ovflow3 = (bgmap & 8) ? GET_STAT_COM(RX_BG_3_MAC_DROP_FRAME) : 0;
10263 	p->rx_trunc0 = (bgmap & 1) ? GET_STAT_COM(RX_BG_0_MAC_TRUNC_FRAME) : 0;
10264 	p->rx_trunc1 = (bgmap & 2) ? GET_STAT_COM(RX_BG_1_MAC_TRUNC_FRAME) : 0;
10265 	p->rx_trunc2 = (bgmap & 4) ? GET_STAT_COM(RX_BG_2_MAC_TRUNC_FRAME) : 0;
10266 	p->rx_trunc3 = (bgmap & 8) ? GET_STAT_COM(RX_BG_3_MAC_TRUNC_FRAME) : 0;
10267 #undef GET_STAT_COM
10268 }
10269 
10270 /**
10271  *	t4_get_lb_stats - collect loopback port statistics
10272  *	@adap: the adapter
10273  *	@idx: the loopback port index
10274  *	@p: the stats structure to fill
10275  *
10276  *	Return HW statistics for the given loopback port.
10277  */
t4_get_lb_stats(struct adapter * adap,int idx,struct lb_port_stats * p)10278 void t4_get_lb_stats(struct adapter *adap, int idx, struct lb_port_stats *p)
10279 {
10280 
10281 #define GET_STAT(name) \
10282 	t4_read_reg64(adap, \
10283 	    t4_port_reg(adap, idx, A_MPS_PORT_STAT_LB_PORT_##name##_L))
10284 #define GET_STAT_COM(name) t4_read_reg64(adap, A_MPS_STAT_##name##_L)
10285 
10286 	p->octets	= GET_STAT(BYTES);
10287 	p->frames	= GET_STAT(FRAMES);
10288 	p->bcast_frames	= GET_STAT(BCAST);
10289 	p->mcast_frames	= GET_STAT(MCAST);
10290 	p->ucast_frames	= GET_STAT(UCAST);
10291 	p->error_frames	= GET_STAT(ERROR);
10292 
10293 	p->frames_64		= GET_STAT(64B);
10294 	p->frames_65_127	= GET_STAT(65B_127B);
10295 	p->frames_128_255	= GET_STAT(128B_255B);
10296 	p->frames_256_511	= GET_STAT(256B_511B);
10297 	p->frames_512_1023	= GET_STAT(512B_1023B);
10298 	p->frames_1024_1518	= GET_STAT(1024B_1518B);
10299 	p->frames_1519_max	= GET_STAT(1519B_MAX);
10300 	p->drop			= GET_STAT(DROP_FRAMES);
10301 
10302 	if (idx < adap->params.nports) {
10303 		u32 bg = adap2pinfo(adap, idx)->mps_bg_map;
10304 
10305 		p->ovflow0 = (bg & 1) ? GET_STAT_COM(RX_BG_0_LB_DROP_FRAME) : 0;
10306 		p->ovflow1 = (bg & 2) ? GET_STAT_COM(RX_BG_1_LB_DROP_FRAME) : 0;
10307 		p->ovflow2 = (bg & 4) ? GET_STAT_COM(RX_BG_2_LB_DROP_FRAME) : 0;
10308 		p->ovflow3 = (bg & 8) ? GET_STAT_COM(RX_BG_3_LB_DROP_FRAME) : 0;
10309 		p->trunc0 = (bg & 1) ? GET_STAT_COM(RX_BG_0_LB_TRUNC_FRAME) : 0;
10310 		p->trunc1 = (bg & 2) ? GET_STAT_COM(RX_BG_1_LB_TRUNC_FRAME) : 0;
10311 		p->trunc2 = (bg & 4) ? GET_STAT_COM(RX_BG_2_LB_TRUNC_FRAME) : 0;
10312 		p->trunc3 = (bg & 8) ? GET_STAT_COM(RX_BG_3_LB_TRUNC_FRAME) : 0;
10313 	}
10314 
10315 #undef GET_STAT
10316 #undef GET_STAT_COM
10317 }
10318 
10319 /**
10320  *	t4_wol_magic_enable - enable/disable magic packet WoL
10321  *	@adap: the adapter
10322  *	@port: the physical port index
10323  *	@addr: MAC address expected in magic packets, %NULL to disable
10324  *
10325  *	Enables/disables magic packet wake-on-LAN for the selected port.
10326  */
t4_wol_magic_enable(struct adapter * adap,unsigned int port,const u8 * addr)10327 void t4_wol_magic_enable(struct adapter *adap, unsigned int port,
10328 			 const u8 *addr)
10329 {
10330 	u32 mag_id_reg_l, mag_id_reg_h, port_cfg_reg;
10331 
10332 	if (is_t4(adap)) {
10333 		mag_id_reg_l = PORT_REG(port, A_XGMAC_PORT_MAGIC_MACID_LO);
10334 		mag_id_reg_h = PORT_REG(port, A_XGMAC_PORT_MAGIC_MACID_HI);
10335 		port_cfg_reg = PORT_REG(port, A_XGMAC_PORT_CFG2);
10336 	} else if (chip_id(adap) < CHELSIO_T7) {
10337 		mag_id_reg_l = T5_PORT_REG(port, A_MAC_PORT_MAGIC_MACID_LO);
10338 		mag_id_reg_h = T5_PORT_REG(port, A_MAC_PORT_MAGIC_MACID_HI);
10339 		port_cfg_reg = T5_PORT_REG(port, A_MAC_PORT_CFG2);
10340 	} else {
10341 		mag_id_reg_l = T7_PORT_REG(port, A_T7_MAC_PORT_MAGIC_MACID_LO);
10342 		mag_id_reg_h = T7_PORT_REG(port, A_T7_MAC_PORT_MAGIC_MACID_HI);
10343 		port_cfg_reg = T7_PORT_REG(port, A_MAC_PORT_CFG2);
10344 	}
10345 
10346 	if (addr) {
10347 		t4_write_reg(adap, mag_id_reg_l,
10348 			     (addr[2] << 24) | (addr[3] << 16) |
10349 			     (addr[4] << 8) | addr[5]);
10350 		t4_write_reg(adap, mag_id_reg_h,
10351 			     (addr[0] << 8) | addr[1]);
10352 	}
10353 	t4_set_reg_field(adap, port_cfg_reg, F_MAGICEN,
10354 			 V_MAGICEN(addr != NULL));
10355 }
10356 
10357 /**
10358  *	t4_wol_pat_enable - enable/disable pattern-based WoL
10359  *	@adap: the adapter
10360  *	@port: the physical port index
10361  *	@map: bitmap of which HW pattern filters to set
10362  *	@mask0: byte mask for bytes 0-63 of a packet
10363  *	@mask1: byte mask for bytes 64-127 of a packet
10364  *	@crc: Ethernet CRC for selected bytes
10365  *	@enable: enable/disable switch
10366  *
10367  *	Sets the pattern filters indicated in @map to mask out the bytes
10368  *	specified in @mask0/@mask1 in received packets and compare the CRC of
10369  *	the resulting packet against @crc.  If @enable is %true pattern-based
10370  *	WoL is enabled, otherwise disabled.
10371  */
t4_wol_pat_enable(struct adapter * adap,unsigned int port,unsigned int map,u64 mask0,u64 mask1,unsigned int crc,bool enable)10372 int t4_wol_pat_enable(struct adapter *adap, unsigned int port, unsigned int map,
10373 		      u64 mask0, u64 mask1, unsigned int crc, bool enable)
10374 {
10375 	int i;
10376 	u32 port_cfg_reg;
10377 
10378 	if (is_t4(adap))
10379 		port_cfg_reg = PORT_REG(port, A_XGMAC_PORT_CFG2);
10380 	else if (chip_id(adap) < CHELSIO_T7)
10381 		port_cfg_reg = T5_PORT_REG(port, A_MAC_PORT_CFG2);
10382 	else
10383 		port_cfg_reg = T7_PORT_REG(port, A_MAC_PORT_CFG2);
10384 
10385 	if (!enable) {
10386 		t4_set_reg_field(adap, port_cfg_reg, F_PATEN, 0);
10387 		return 0;
10388 	}
10389 	if (map > 0xff)
10390 		return -EINVAL;
10391 
10392 #define EPIO_REG(name) \
10393 	(is_t4(adap) ? PORT_REG(port, A_XGMAC_PORT_EPIO_##name) : \
10394 	T5_PORT_REG(port, A_MAC_PORT_EPIO_##name))
10395 
10396 	t4_write_reg(adap, EPIO_REG(DATA1), mask0 >> 32);
10397 	t4_write_reg(adap, EPIO_REG(DATA2), mask1);
10398 	t4_write_reg(adap, EPIO_REG(DATA3), mask1 >> 32);
10399 
10400 	for (i = 0; i < NWOL_PAT; i++, map >>= 1) {
10401 		if (!(map & 1))
10402 			continue;
10403 
10404 		/* write byte masks */
10405 		t4_write_reg(adap, EPIO_REG(DATA0), mask0);
10406 		t4_write_reg(adap, EPIO_REG(OP), V_ADDRESS(i) | F_EPIOWR);
10407 		t4_read_reg(adap, EPIO_REG(OP));                /* flush */
10408 		if (t4_read_reg(adap, EPIO_REG(OP)) & F_BUSY)
10409 			return -ETIMEDOUT;
10410 
10411 		/* write CRC */
10412 		t4_write_reg(adap, EPIO_REG(DATA0), crc);
10413 		t4_write_reg(adap, EPIO_REG(OP), V_ADDRESS(i + 32) | F_EPIOWR);
10414 		t4_read_reg(adap, EPIO_REG(OP));                /* flush */
10415 		if (t4_read_reg(adap, EPIO_REG(OP)) & F_BUSY)
10416 			return -ETIMEDOUT;
10417 	}
10418 #undef EPIO_REG
10419 
10420 	t4_set_reg_field(adap, port_cfg_reg, 0, F_PATEN);
10421 	return 0;
10422 }
10423 
10424 /*     t4_mk_filtdelwr - create a delete filter WR
10425  *     @ftid: the filter ID
10426  *     @wr: the filter work request to populate
10427  *     @qid: ingress queue to receive the delete notification
10428  *
10429  *     Creates a filter work request to delete the supplied filter.  If @qid is
10430  *     negative the delete notification is suppressed.
10431  */
t4_mk_filtdelwr(unsigned int ftid,struct fw_filter_wr * wr,int qid)10432 void t4_mk_filtdelwr(unsigned int ftid, struct fw_filter_wr *wr, int qid)
10433 {
10434 	memset(wr, 0, sizeof(*wr));
10435 	wr->op_pkd = cpu_to_be32(V_FW_WR_OP(FW_FILTER_WR));
10436 	wr->len16_pkd = cpu_to_be32(V_FW_WR_LEN16(sizeof(*wr) / 16));
10437 	wr->tid_to_iq = cpu_to_be32(V_FW_FILTER_WR_TID(ftid) |
10438 				    V_FW_FILTER_WR_NOREPLY(qid < 0));
10439 	wr->del_filter_to_l2tix = cpu_to_be32(F_FW_FILTER_WR_DEL_FILTER);
10440 	if (qid >= 0)
10441 		wr->rx_chan_rx_rpl_iq =
10442 				cpu_to_be16(V_FW_FILTER_WR_RX_RPL_IQ(qid));
10443 }
10444 
10445 #define INIT_CMD(var, cmd, rd_wr) do { \
10446 	(var).op_to_write = cpu_to_be32(V_FW_CMD_OP(FW_##cmd##_CMD) | \
10447 					F_FW_CMD_REQUEST | \
10448 					F_FW_CMD_##rd_wr); \
10449 	(var).retval_len16 = cpu_to_be32(FW_LEN16(var)); \
10450 } while (0)
10451 
t4_fwaddrspace_write(struct adapter * adap,unsigned int mbox,u32 addr,u32 val)10452 int t4_fwaddrspace_write(struct adapter *adap, unsigned int mbox,
10453 			  u32 addr, u32 val)
10454 {
10455 	u32 ldst_addrspace;
10456 	struct fw_ldst_cmd c;
10457 
10458 	memset(&c, 0, sizeof(c));
10459 	ldst_addrspace = V_FW_LDST_CMD_ADDRSPACE(FW_LDST_ADDRSPC_FIRMWARE);
10460 	c.op_to_addrspace = cpu_to_be32(V_FW_CMD_OP(FW_LDST_CMD) |
10461 					F_FW_CMD_REQUEST |
10462 					F_FW_CMD_WRITE |
10463 					ldst_addrspace);
10464 	c.cycles_to_len16 = cpu_to_be32(FW_LEN16(c));
10465 	c.u.addrval.addr = cpu_to_be32(addr);
10466 	c.u.addrval.val = cpu_to_be32(val);
10467 
10468 	return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
10469 }
10470 
10471 /**
10472  *	t4_mdio_rd - read a PHY register through MDIO
10473  *	@adap: the adapter
10474  *	@mbox: mailbox to use for the FW command
10475  *	@phy_addr: the PHY address
10476  *	@mmd: the PHY MMD to access (0 for clause 22 PHYs)
10477  *	@reg: the register to read
10478  *	@valp: where to store the value
10479  *
10480  *	Issues a FW command through the given mailbox to read a PHY register.
10481  */
t4_mdio_rd(struct adapter * adap,unsigned int mbox,unsigned int phy_addr,unsigned int mmd,unsigned int reg,unsigned int * valp)10482 int t4_mdio_rd(struct adapter *adap, unsigned int mbox, unsigned int phy_addr,
10483 	       unsigned int mmd, unsigned int reg, unsigned int *valp)
10484 {
10485 	int ret;
10486 	u32 ldst_addrspace;
10487 	struct fw_ldst_cmd c;
10488 
10489 	memset(&c, 0, sizeof(c));
10490 	ldst_addrspace = V_FW_LDST_CMD_ADDRSPACE(FW_LDST_ADDRSPC_MDIO);
10491 	c.op_to_addrspace = cpu_to_be32(V_FW_CMD_OP(FW_LDST_CMD) |
10492 					F_FW_CMD_REQUEST | F_FW_CMD_READ |
10493 					ldst_addrspace);
10494 	c.cycles_to_len16 = cpu_to_be32(FW_LEN16(c));
10495 	c.u.mdio.paddr_mmd = cpu_to_be16(V_FW_LDST_CMD_PADDR(phy_addr) |
10496 					 V_FW_LDST_CMD_MMD(mmd));
10497 	c.u.mdio.raddr = cpu_to_be16(reg);
10498 
10499 	ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
10500 	if (ret == 0)
10501 		*valp = be16_to_cpu(c.u.mdio.rval);
10502 	return ret;
10503 }
10504 
10505 /**
10506  *	t4_mdio_wr - write a PHY register through MDIO
10507  *	@adap: the adapter
10508  *	@mbox: mailbox to use for the FW command
10509  *	@phy_addr: the PHY address
10510  *	@mmd: the PHY MMD to access (0 for clause 22 PHYs)
10511  *	@reg: the register to write
10512  *	@valp: value to write
10513  *
10514  *	Issues a FW command through the given mailbox to write a PHY register.
10515  */
t4_mdio_wr(struct adapter * adap,unsigned int mbox,unsigned int phy_addr,unsigned int mmd,unsigned int reg,unsigned int val)10516 int t4_mdio_wr(struct adapter *adap, unsigned int mbox, unsigned int phy_addr,
10517 	       unsigned int mmd, unsigned int reg, unsigned int val)
10518 {
10519 	u32 ldst_addrspace;
10520 	struct fw_ldst_cmd c;
10521 
10522 	memset(&c, 0, sizeof(c));
10523 	ldst_addrspace = V_FW_LDST_CMD_ADDRSPACE(FW_LDST_ADDRSPC_MDIO);
10524 	c.op_to_addrspace = cpu_to_be32(V_FW_CMD_OP(FW_LDST_CMD) |
10525 					F_FW_CMD_REQUEST | F_FW_CMD_WRITE |
10526 					ldst_addrspace);
10527 	c.cycles_to_len16 = cpu_to_be32(FW_LEN16(c));
10528 	c.u.mdio.paddr_mmd = cpu_to_be16(V_FW_LDST_CMD_PADDR(phy_addr) |
10529 					 V_FW_LDST_CMD_MMD(mmd));
10530 	c.u.mdio.raddr = cpu_to_be16(reg);
10531 	c.u.mdio.rval = cpu_to_be16(val);
10532 
10533 	return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
10534 }
10535 
10536 /**
10537  *
10538  *	t4_sge_decode_idma_state - decode the idma state
10539  *	@adap: the adapter
10540  *	@state: the state idma is stuck in
10541  */
t4_sge_decode_idma_state(struct adapter * adapter,int state)10542 void t4_sge_decode_idma_state(struct adapter *adapter, int state)
10543 {
10544 	static const char * const t4_decode[] = {
10545 		"IDMA_IDLE",
10546 		"IDMA_PUSH_MORE_CPL_FIFO",
10547 		"IDMA_PUSH_CPL_MSG_HEADER_TO_FIFO",
10548 		"Not used",
10549 		"IDMA_PHYSADDR_SEND_PCIEHDR",
10550 		"IDMA_PHYSADDR_SEND_PAYLOAD_FIRST",
10551 		"IDMA_PHYSADDR_SEND_PAYLOAD",
10552 		"IDMA_SEND_FIFO_TO_IMSG",
10553 		"IDMA_FL_REQ_DATA_FL_PREP",
10554 		"IDMA_FL_REQ_DATA_FL",
10555 		"IDMA_FL_DROP",
10556 		"IDMA_FL_H_REQ_HEADER_FL",
10557 		"IDMA_FL_H_SEND_PCIEHDR",
10558 		"IDMA_FL_H_PUSH_CPL_FIFO",
10559 		"IDMA_FL_H_SEND_CPL",
10560 		"IDMA_FL_H_SEND_IP_HDR_FIRST",
10561 		"IDMA_FL_H_SEND_IP_HDR",
10562 		"IDMA_FL_H_REQ_NEXT_HEADER_FL",
10563 		"IDMA_FL_H_SEND_NEXT_PCIEHDR",
10564 		"IDMA_FL_H_SEND_IP_HDR_PADDING",
10565 		"IDMA_FL_D_SEND_PCIEHDR",
10566 		"IDMA_FL_D_SEND_CPL_AND_IP_HDR",
10567 		"IDMA_FL_D_REQ_NEXT_DATA_FL",
10568 		"IDMA_FL_SEND_PCIEHDR",
10569 		"IDMA_FL_PUSH_CPL_FIFO",
10570 		"IDMA_FL_SEND_CPL",
10571 		"IDMA_FL_SEND_PAYLOAD_FIRST",
10572 		"IDMA_FL_SEND_PAYLOAD",
10573 		"IDMA_FL_REQ_NEXT_DATA_FL",
10574 		"IDMA_FL_SEND_NEXT_PCIEHDR",
10575 		"IDMA_FL_SEND_PADDING",
10576 		"IDMA_FL_SEND_COMPLETION_TO_IMSG",
10577 		"IDMA_FL_SEND_FIFO_TO_IMSG",
10578 		"IDMA_FL_REQ_DATAFL_DONE",
10579 		"IDMA_FL_REQ_HEADERFL_DONE",
10580 	};
10581 	static const char * const t5_decode[] = {
10582 		"IDMA_IDLE",
10583 		"IDMA_ALMOST_IDLE",
10584 		"IDMA_PUSH_MORE_CPL_FIFO",
10585 		"IDMA_PUSH_CPL_MSG_HEADER_TO_FIFO",
10586 		"IDMA_SGEFLRFLUSH_SEND_PCIEHDR",
10587 		"IDMA_PHYSADDR_SEND_PCIEHDR",
10588 		"IDMA_PHYSADDR_SEND_PAYLOAD_FIRST",
10589 		"IDMA_PHYSADDR_SEND_PAYLOAD",
10590 		"IDMA_SEND_FIFO_TO_IMSG",
10591 		"IDMA_FL_REQ_DATA_FL",
10592 		"IDMA_FL_DROP",
10593 		"IDMA_FL_DROP_SEND_INC",
10594 		"IDMA_FL_H_REQ_HEADER_FL",
10595 		"IDMA_FL_H_SEND_PCIEHDR",
10596 		"IDMA_FL_H_PUSH_CPL_FIFO",
10597 		"IDMA_FL_H_SEND_CPL",
10598 		"IDMA_FL_H_SEND_IP_HDR_FIRST",
10599 		"IDMA_FL_H_SEND_IP_HDR",
10600 		"IDMA_FL_H_REQ_NEXT_HEADER_FL",
10601 		"IDMA_FL_H_SEND_NEXT_PCIEHDR",
10602 		"IDMA_FL_H_SEND_IP_HDR_PADDING",
10603 		"IDMA_FL_D_SEND_PCIEHDR",
10604 		"IDMA_FL_D_SEND_CPL_AND_IP_HDR",
10605 		"IDMA_FL_D_REQ_NEXT_DATA_FL",
10606 		"IDMA_FL_SEND_PCIEHDR",
10607 		"IDMA_FL_PUSH_CPL_FIFO",
10608 		"IDMA_FL_SEND_CPL",
10609 		"IDMA_FL_SEND_PAYLOAD_FIRST",
10610 		"IDMA_FL_SEND_PAYLOAD",
10611 		"IDMA_FL_REQ_NEXT_DATA_FL",
10612 		"IDMA_FL_SEND_NEXT_PCIEHDR",
10613 		"IDMA_FL_SEND_PADDING",
10614 		"IDMA_FL_SEND_COMPLETION_TO_IMSG",
10615 	};
10616 	static const char * const t6_decode[] = {
10617 		"IDMA_IDLE",
10618 		"IDMA_PUSH_MORE_CPL_FIFO",
10619 		"IDMA_PUSH_CPL_MSG_HEADER_TO_FIFO",
10620 		"IDMA_SGEFLRFLUSH_SEND_PCIEHDR",
10621 		"IDMA_PHYSADDR_SEND_PCIEHDR",
10622 		"IDMA_PHYSADDR_SEND_PAYLOAD_FIRST",
10623 		"IDMA_PHYSADDR_SEND_PAYLOAD",
10624 		"IDMA_FL_REQ_DATA_FL",
10625 		"IDMA_FL_DROP",
10626 		"IDMA_FL_DROP_SEND_INC",
10627 		"IDMA_FL_H_REQ_HEADER_FL",
10628 		"IDMA_FL_H_SEND_PCIEHDR",
10629 		"IDMA_FL_H_PUSH_CPL_FIFO",
10630 		"IDMA_FL_H_SEND_CPL",
10631 		"IDMA_FL_H_SEND_IP_HDR_FIRST",
10632 		"IDMA_FL_H_SEND_IP_HDR",
10633 		"IDMA_FL_H_REQ_NEXT_HEADER_FL",
10634 		"IDMA_FL_H_SEND_NEXT_PCIEHDR",
10635 		"IDMA_FL_H_SEND_IP_HDR_PADDING",
10636 		"IDMA_FL_D_SEND_PCIEHDR",
10637 		"IDMA_FL_D_SEND_CPL_AND_IP_HDR",
10638 		"IDMA_FL_D_REQ_NEXT_DATA_FL",
10639 		"IDMA_FL_SEND_PCIEHDR",
10640 		"IDMA_FL_PUSH_CPL_FIFO",
10641 		"IDMA_FL_SEND_CPL",
10642 		"IDMA_FL_SEND_PAYLOAD_FIRST",
10643 		"IDMA_FL_SEND_PAYLOAD",
10644 		"IDMA_FL_REQ_NEXT_DATA_FL",
10645 		"IDMA_FL_SEND_NEXT_PCIEHDR",
10646 		"IDMA_FL_SEND_PADDING",
10647 		"IDMA_FL_SEND_COMPLETION_TO_IMSG",
10648 	};
10649 	static const u32 sge_regs[] = {
10650 		A_SGE_DEBUG_DATA_LOW_INDEX_2,
10651 		A_SGE_DEBUG_DATA_LOW_INDEX_3,
10652 		A_SGE_DEBUG_DATA_HIGH_INDEX_10,
10653 	};
10654 	const char * const *sge_idma_decode;
10655 	int sge_idma_decode_nstates;
10656 	int i;
10657 	unsigned int chip_version = chip_id(adapter);
10658 
10659 	/* Select the right set of decode strings to dump depending on the
10660 	 * adapter chip type.
10661 	 */
10662 	switch (chip_version) {
10663 	case CHELSIO_T4:
10664 		sge_idma_decode = (const char * const *)t4_decode;
10665 		sge_idma_decode_nstates = ARRAY_SIZE(t4_decode);
10666 		break;
10667 
10668 	case CHELSIO_T5:
10669 		sge_idma_decode = (const char * const *)t5_decode;
10670 		sge_idma_decode_nstates = ARRAY_SIZE(t5_decode);
10671 		break;
10672 
10673 	case CHELSIO_T6:
10674 	case CHELSIO_T7:
10675 		sge_idma_decode = (const char * const *)t6_decode;
10676 		sge_idma_decode_nstates = ARRAY_SIZE(t6_decode);
10677 		break;
10678 
10679 	default:
10680 		CH_ERR(adapter,	"Unsupported chip version %d\n", chip_version);
10681 		return;
10682 	}
10683 
10684 	if (state < sge_idma_decode_nstates)
10685 		CH_WARN(adapter, "idma state %s\n", sge_idma_decode[state]);
10686 	else
10687 		CH_WARN(adapter, "idma state %d unknown\n", state);
10688 
10689 	for (i = 0; i < ARRAY_SIZE(sge_regs); i++)
10690 		CH_WARN(adapter, "SGE register %#x value %#x\n",
10691 			sge_regs[i], t4_read_reg(adapter, sge_regs[i]));
10692 }
10693 
10694 /**
10695  *      t4_sge_ctxt_flush - flush the SGE context cache
10696  *      @adap: the adapter
10697  *      @mbox: mailbox to use for the FW command
10698  *
10699  *      Issues a FW command through the given mailbox to flush the
10700  *      SGE context cache.
10701  */
t4_sge_ctxt_flush(struct adapter * adap,unsigned int mbox,int ctxt_type)10702 int t4_sge_ctxt_flush(struct adapter *adap, unsigned int mbox, int ctxt_type)
10703 {
10704 	int ret;
10705 	u32 ldst_addrspace;
10706 	struct fw_ldst_cmd c;
10707 
10708 	memset(&c, 0, sizeof(c));
10709 	ldst_addrspace = V_FW_LDST_CMD_ADDRSPACE(ctxt_type == CTXT_EGRESS ?
10710 						 FW_LDST_ADDRSPC_SGE_EGRC :
10711 						 FW_LDST_ADDRSPC_SGE_INGC);
10712 	c.op_to_addrspace = cpu_to_be32(V_FW_CMD_OP(FW_LDST_CMD) |
10713 					F_FW_CMD_REQUEST | F_FW_CMD_READ |
10714 					ldst_addrspace);
10715 	c.cycles_to_len16 = cpu_to_be32(FW_LEN16(c));
10716 	c.u.idctxt.msg_ctxtflush = cpu_to_be32(F_FW_LDST_CMD_CTXTFLUSH);
10717 
10718 	ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
10719 	return ret;
10720 }
10721 
10722 /**
10723  *      t4_fw_hello - establish communication with FW
10724  *      @adap: the adapter
10725  *      @mbox: mailbox to use for the FW command
10726  *      @evt_mbox: mailbox to receive async FW events
10727  *      @master: specifies the caller's willingness to be the device master
10728  *	@state: returns the current device state (if non-NULL)
10729  *
10730  *	Issues a command to establish communication with FW.  Returns either
10731  *	an error (negative integer) or the mailbox of the Master PF.
10732  */
t4_fw_hello(struct adapter * adap,unsigned int mbox,unsigned int evt_mbox,enum dev_master master,enum dev_state * state)10733 int t4_fw_hello(struct adapter *adap, unsigned int mbox, unsigned int evt_mbox,
10734 		enum dev_master master, enum dev_state *state)
10735 {
10736 	int ret;
10737 	struct fw_hello_cmd c;
10738 	u32 v;
10739 	unsigned int master_mbox;
10740 	int retries = FW_CMD_HELLO_RETRIES;
10741 
10742 retry:
10743 	memset(&c, 0, sizeof(c));
10744 	INIT_CMD(c, HELLO, WRITE);
10745 	c.err_to_clearinit = cpu_to_be32(
10746 		V_FW_HELLO_CMD_MASTERDIS(master == MASTER_CANT) |
10747 		V_FW_HELLO_CMD_MASTERFORCE(master == MASTER_MUST) |
10748 		V_FW_HELLO_CMD_MBMASTER(master == MASTER_MUST ?
10749 					mbox : M_FW_HELLO_CMD_MBMASTER) |
10750 		V_FW_HELLO_CMD_MBASYNCNOT(evt_mbox) |
10751 		V_FW_HELLO_CMD_STAGE(FW_HELLO_CMD_STAGE_OS) |
10752 		F_FW_HELLO_CMD_CLEARINIT);
10753 
10754 	/*
10755 	 * Issue the HELLO command to the firmware.  If it's not successful
10756 	 * but indicates that we got a "busy" or "timeout" condition, retry
10757 	 * the HELLO until we exhaust our retry limit.  If we do exceed our
10758 	 * retry limit, check to see if the firmware left us any error
10759 	 * information and report that if so ...
10760 	 */
10761 	ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
10762 	if (ret != FW_SUCCESS) {
10763 		if ((ret == -EBUSY || ret == -ETIMEDOUT) && retries-- > 0)
10764 			goto retry;
10765 		return ret;
10766 	}
10767 
10768 	v = be32_to_cpu(c.err_to_clearinit);
10769 	master_mbox = G_FW_HELLO_CMD_MBMASTER(v);
10770 	if (state) {
10771 		if (v & F_FW_HELLO_CMD_ERR)
10772 			*state = DEV_STATE_ERR;
10773 		else if (v & F_FW_HELLO_CMD_INIT)
10774 			*state = DEV_STATE_INIT;
10775 		else
10776 			*state = DEV_STATE_UNINIT;
10777 	}
10778 
10779 	/*
10780 	 * If we're not the Master PF then we need to wait around for the
10781 	 * Master PF Driver to finish setting up the adapter.
10782 	 *
10783 	 * Note that we also do this wait if we're a non-Master-capable PF and
10784 	 * there is no current Master PF; a Master PF may show up momentarily
10785 	 * and we wouldn't want to fail pointlessly.  (This can happen when an
10786 	 * OS loads lots of different drivers rapidly at the same time).  In
10787 	 * this case, the Master PF returned by the firmware will be
10788 	 * M_PCIE_FW_MASTER so the test below will work ...
10789 	 */
10790 	if ((v & (F_FW_HELLO_CMD_ERR|F_FW_HELLO_CMD_INIT)) == 0 &&
10791 	    master_mbox != mbox) {
10792 		int waiting = FW_CMD_HELLO_TIMEOUT;
10793 
10794 		/*
10795 		 * Wait for the firmware to either indicate an error or
10796 		 * initialized state.  If we see either of these we bail out
10797 		 * and report the issue to the caller.  If we exhaust the
10798 		 * "hello timeout" and we haven't exhausted our retries, try
10799 		 * again.  Otherwise bail with a timeout error.
10800 		 */
10801 		for (;;) {
10802 			u32 pcie_fw;
10803 
10804 			msleep(50);
10805 			waiting -= 50;
10806 
10807 			/*
10808 			 * If neither Error nor Initialialized are indicated
10809 			 * by the firmware keep waiting till we exhaust our
10810 			 * timeout ... and then retry if we haven't exhausted
10811 			 * our retries ...
10812 			 */
10813 			pcie_fw = t4_read_reg(adap, A_PCIE_FW);
10814 			if (!(pcie_fw & (F_PCIE_FW_ERR|F_PCIE_FW_INIT))) {
10815 				if (waiting <= 0) {
10816 					if (retries-- > 0)
10817 						goto retry;
10818 
10819 					return -ETIMEDOUT;
10820 				}
10821 				continue;
10822 			}
10823 
10824 			/*
10825 			 * We either have an Error or Initialized condition
10826 			 * report errors preferentially.
10827 			 */
10828 			if (state) {
10829 				if (pcie_fw & F_PCIE_FW_ERR)
10830 					*state = DEV_STATE_ERR;
10831 				else if (pcie_fw & F_PCIE_FW_INIT)
10832 					*state = DEV_STATE_INIT;
10833 			}
10834 
10835 			/*
10836 			 * If we arrived before a Master PF was selected and
10837 			 * there's not a valid Master PF, grab its identity
10838 			 * for our caller.
10839 			 */
10840 			if (master_mbox == M_PCIE_FW_MASTER &&
10841 			    (pcie_fw & F_PCIE_FW_MASTER_VLD))
10842 				master_mbox = G_PCIE_FW_MASTER(pcie_fw);
10843 			break;
10844 		}
10845 	}
10846 
10847 	return master_mbox;
10848 }
10849 
10850 /**
10851  *	t4_fw_bye - end communication with FW
10852  *	@adap: the adapter
10853  *	@mbox: mailbox to use for the FW command
10854  *
10855  *	Issues a command to terminate communication with FW.
10856  */
t4_fw_bye(struct adapter * adap,unsigned int mbox)10857 int t4_fw_bye(struct adapter *adap, unsigned int mbox)
10858 {
10859 	struct fw_bye_cmd c;
10860 
10861 	memset(&c, 0, sizeof(c));
10862 	INIT_CMD(c, BYE, WRITE);
10863 	return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
10864 }
10865 
10866 /**
10867  *	t4_fw_reset - issue a reset to FW
10868  *	@adap: the adapter
10869  *	@mbox: mailbox to use for the FW command
10870  *	@reset: specifies the type of reset to perform
10871  *
10872  *	Issues a reset command of the specified type to FW.
10873  */
t4_fw_reset(struct adapter * adap,unsigned int mbox,int reset)10874 int t4_fw_reset(struct adapter *adap, unsigned int mbox, int reset)
10875 {
10876 	struct fw_reset_cmd c;
10877 
10878 	memset(&c, 0, sizeof(c));
10879 	INIT_CMD(c, RESET, WRITE);
10880 	c.val = cpu_to_be32(reset);
10881 	return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
10882 }
10883 
10884 /**
10885  *	t4_fw_halt - issue a reset/halt to FW and put uP into RESET
10886  *	@adap: the adapter
10887  *	@mbox: mailbox to use for the FW RESET command (if desired)
10888  *	@force: force uP into RESET even if FW RESET command fails
10889  *
10890  *	Issues a RESET command to firmware (if desired) with a HALT indication
10891  *	and then puts the microprocessor into RESET state.  The RESET command
10892  *	will only be issued if a legitimate mailbox is provided (mbox <=
10893  *	M_PCIE_FW_MASTER).
10894  *
10895  *	This is generally used in order for the host to safely manipulate the
10896  *	adapter without fear of conflicting with whatever the firmware might
10897  *	be doing.  The only way out of this state is to RESTART the firmware
10898  *	...
10899  */
t4_fw_halt(struct adapter * adap,unsigned int mbox,int force)10900 int t4_fw_halt(struct adapter *adap, unsigned int mbox, int force)
10901 {
10902 	int ret = 0;
10903 
10904 	/*
10905 	 * If a legitimate mailbox is provided, issue a RESET command
10906 	 * with a HALT indication.
10907 	 */
10908 	if (adap->flags & FW_OK && mbox <= M_PCIE_FW_MASTER) {
10909 		struct fw_reset_cmd c;
10910 
10911 		memset(&c, 0, sizeof(c));
10912 		INIT_CMD(c, RESET, WRITE);
10913 		c.val = cpu_to_be32(F_PIORST | F_PIORSTMODE);
10914 		c.halt_pkd = cpu_to_be32(F_FW_RESET_CMD_HALT);
10915 		ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
10916 	}
10917 
10918 	/*
10919 	 * Normally we won't complete the operation if the firmware RESET
10920 	 * command fails but if our caller insists we'll go ahead and put the
10921 	 * uP into RESET.  This can be useful if the firmware is hung or even
10922 	 * missing ...  We'll have to take the risk of putting the uP into
10923 	 * RESET without the cooperation of firmware in that case.
10924 	 *
10925 	 * We also force the firmware's HALT flag to be on in case we bypassed
10926 	 * the firmware RESET command above or we're dealing with old firmware
10927 	 * which doesn't have the HALT capability.  This will serve as a flag
10928 	 * for the incoming firmware to know that it's coming out of a HALT
10929 	 * rather than a RESET ... if it's new enough to understand that ...
10930 	 */
10931 	if (ret == 0 || force) {
10932 		t4_set_reg_field(adap, A_CIM_BOOT_CFG, F_UPCRST, F_UPCRST);
10933 		t4_set_reg_field(adap, A_PCIE_FW, F_PCIE_FW_HALT,
10934 				 F_PCIE_FW_HALT);
10935 	}
10936 
10937 	/*
10938 	 * And we always return the result of the firmware RESET command
10939 	 * even when we force the uP into RESET ...
10940 	 */
10941 	return ret;
10942 }
10943 
10944 /**
10945  *	t4_fw_restart - restart the firmware by taking the uP out of RESET
10946  *	@adap: the adapter
10947  *
10948  *	Restart firmware previously halted by t4_fw_halt().  On successful
10949  *	return the previous PF Master remains as the new PF Master and there
10950  *	is no need to issue a new HELLO command, etc.
10951  */
t4_fw_restart(struct adapter * adap,unsigned int mbox)10952 int t4_fw_restart(struct adapter *adap, unsigned int mbox)
10953 {
10954 	int ms;
10955 
10956 	t4_set_reg_field(adap, A_CIM_BOOT_CFG, F_UPCRST, 0);
10957 	for (ms = 0; ms < FW_CMD_MAX_TIMEOUT; ) {
10958 		if (!(t4_read_reg(adap, A_PCIE_FW) & F_PCIE_FW_HALT))
10959 			return FW_SUCCESS;
10960 		msleep(100);
10961 		ms += 100;
10962 	}
10963 
10964 	return -ETIMEDOUT;
10965 }
10966 
10967 /**
10968  *	t4_fw_upgrade - perform all of the steps necessary to upgrade FW
10969  *	@adap: the adapter
10970  *	@mbox: mailbox to use for the FW RESET command (if desired)
10971  *	@fw_data: the firmware image to write
10972  *	@size: image size
10973  *	@force: force upgrade even if firmware doesn't cooperate
10974  *
10975  *	Perform all of the steps necessary for upgrading an adapter's
10976  *	firmware image.  Normally this requires the cooperation of the
10977  *	existing firmware in order to halt all existing activities
10978  *	but if an invalid mailbox token is passed in we skip that step
10979  *	(though we'll still put the adapter microprocessor into RESET in
10980  *	that case).
10981  *
10982  *	On successful return the new firmware will have been loaded and
10983  *	the adapter will have been fully RESET losing all previous setup
10984  *	state.  On unsuccessful return the adapter may be completely hosed ...
10985  *	positive errno indicates that the adapter is ~probably~ intact, a
10986  *	negative errno indicates that things are looking bad ...
10987  */
t4_fw_upgrade(struct adapter * adap,unsigned int mbox,const u8 * fw_data,unsigned int size,int force)10988 int t4_fw_upgrade(struct adapter *adap, unsigned int mbox,
10989 		  const u8 *fw_data, unsigned int size, int force)
10990 {
10991 	const struct fw_hdr *fw_hdr = (const struct fw_hdr *)fw_data;
10992 	unsigned int bootstrap =
10993 	    be32_to_cpu(fw_hdr->magic) == FW_HDR_MAGIC_BOOTSTRAP;
10994 	int ret;
10995 
10996 	if (!t4_fw_matches_chip(adap, fw_hdr))
10997 		return -EINVAL;
10998 
10999 	if (!bootstrap) {
11000 		ret = t4_fw_halt(adap, mbox, force);
11001 		if (ret < 0 && !force)
11002 			return ret;
11003 	}
11004 
11005 	ret = t4_load_fw(adap, fw_data, size);
11006 	if (ret < 0 || bootstrap)
11007 		return ret;
11008 
11009 	return t4_fw_restart(adap, mbox);
11010 }
11011 
11012 /**
11013  *	t4_fw_initialize - ask FW to initialize the device
11014  *	@adap: the adapter
11015  *	@mbox: mailbox to use for the FW command
11016  *
11017  *	Issues a command to FW to partially initialize the device.  This
11018  *	performs initialization that generally doesn't depend on user input.
11019  */
t4_fw_initialize(struct adapter * adap,unsigned int mbox)11020 int t4_fw_initialize(struct adapter *adap, unsigned int mbox)
11021 {
11022 	struct fw_initialize_cmd c;
11023 
11024 	memset(&c, 0, sizeof(c));
11025 	INIT_CMD(c, INITIALIZE, WRITE);
11026 	return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
11027 }
11028 
11029 /**
11030  *	t4_query_params_rw - query FW or device parameters
11031  *	@adap: the adapter
11032  *	@mbox: mailbox to use for the FW command
11033  *	@pf: the PF
11034  *	@vf: the VF
11035  *	@nparams: the number of parameters
11036  *	@params: the parameter names
11037  *	@val: the parameter values
11038  *	@rw: Write and read flag
11039  *
11040  *	Reads the value of FW or device parameters.  Up to 7 parameters can be
11041  *	queried at once.
11042  */
t4_query_params_rw(struct adapter * adap,unsigned int mbox,unsigned int pf,unsigned int vf,unsigned int nparams,const u32 * params,u32 * val,int rw)11043 int t4_query_params_rw(struct adapter *adap, unsigned int mbox, unsigned int pf,
11044 		       unsigned int vf, unsigned int nparams, const u32 *params,
11045 		       u32 *val, int rw)
11046 {
11047 	int i, ret;
11048 	struct fw_params_cmd c;
11049 	__be32 *p = &c.param[0].mnem;
11050 
11051 	if (nparams > 7)
11052 		return -EINVAL;
11053 
11054 	memset(&c, 0, sizeof(c));
11055 	c.op_to_vfn = cpu_to_be32(V_FW_CMD_OP(FW_PARAMS_CMD) |
11056 				  F_FW_CMD_REQUEST | F_FW_CMD_READ |
11057 				  V_FW_PARAMS_CMD_PFN(pf) |
11058 				  V_FW_PARAMS_CMD_VFN(vf));
11059 	c.retval_len16 = cpu_to_be32(FW_LEN16(c));
11060 
11061 	for (i = 0; i < nparams; i++) {
11062 		*p++ = cpu_to_be32(*params++);
11063 		if (rw)
11064 			*p = cpu_to_be32(*(val + i));
11065 		p++;
11066 	}
11067 
11068 	ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
11069 
11070 	/*
11071 	 * We always copy back the results, even if there's an error.  We'll
11072 	 * get an error if any of the parameters was unknown to the Firmware,
11073 	 * but there will be results for the others ...  (Older Firmware
11074 	 * stopped at the first unknown parameter; newer Firmware processes
11075 	 * them all and flags the unknown parameters with a return value of
11076 	 * ~0UL.)
11077 	 */
11078 	for (i = 0, p = &c.param[0].val; i < nparams; i++, p += 2)
11079 		*val++ = be32_to_cpu(*p);
11080 
11081 	return ret;
11082 }
11083 
t4_query_params(struct adapter * adap,unsigned int mbox,unsigned int pf,unsigned int vf,unsigned int nparams,const u32 * params,u32 * val)11084 int t4_query_params(struct adapter *adap, unsigned int mbox, unsigned int pf,
11085 		    unsigned int vf, unsigned int nparams, const u32 *params,
11086 		    u32 *val)
11087 {
11088 	return t4_query_params_rw(adap, mbox, pf, vf, nparams, params, val, 0);
11089 }
11090 
11091 /**
11092  *      t4_set_params_timeout - sets FW or device parameters
11093  *      @adap: the adapter
11094  *      @mbox: mailbox to use for the FW command
11095  *      @pf: the PF
11096  *      @vf: the VF
11097  *      @nparams: the number of parameters
11098  *      @params: the parameter names
11099  *      @val: the parameter values
11100  *      @timeout: the timeout time
11101  *
11102  *      Sets the value of FW or device parameters.  Up to 7 parameters can be
11103  *      specified at once.
11104  */
t4_set_params_timeout(struct adapter * adap,unsigned int mbox,unsigned int pf,unsigned int vf,unsigned int nparams,const u32 * params,const u32 * val,int timeout)11105 int t4_set_params_timeout(struct adapter *adap, unsigned int mbox,
11106 			  unsigned int pf, unsigned int vf,
11107 			  unsigned int nparams, const u32 *params,
11108 			  const u32 *val, int timeout)
11109 {
11110 	struct fw_params_cmd c;
11111 	__be32 *p = &c.param[0].mnem;
11112 
11113 	if (nparams > 7)
11114 		return -EINVAL;
11115 
11116 	memset(&c, 0, sizeof(c));
11117 	c.op_to_vfn = cpu_to_be32(V_FW_CMD_OP(FW_PARAMS_CMD) |
11118 				  F_FW_CMD_REQUEST | F_FW_CMD_WRITE |
11119 				  V_FW_PARAMS_CMD_PFN(pf) |
11120 				  V_FW_PARAMS_CMD_VFN(vf));
11121 	c.retval_len16 = cpu_to_be32(FW_LEN16(c));
11122 
11123 	while (nparams--) {
11124 		*p++ = cpu_to_be32(*params++);
11125 		*p++ = cpu_to_be32(*val++);
11126 	}
11127 
11128 	return t4_wr_mbox_timeout(adap, mbox, &c, sizeof(c), NULL, timeout);
11129 }
11130 
11131 /**
11132  *	t4_set_params - sets FW or device parameters
11133  *	@adap: the adapter
11134  *	@mbox: mailbox to use for the FW command
11135  *	@pf: the PF
11136  *	@vf: the VF
11137  *	@nparams: the number of parameters
11138  *	@params: the parameter names
11139  *	@val: the parameter values
11140  *
11141  *	Sets the value of FW or device parameters.  Up to 7 parameters can be
11142  *	specified at once.
11143  */
t4_set_params(struct adapter * adap,unsigned int mbox,unsigned int pf,unsigned int vf,unsigned int nparams,const u32 * params,const u32 * val)11144 int t4_set_params(struct adapter *adap, unsigned int mbox, unsigned int pf,
11145 		  unsigned int vf, unsigned int nparams, const u32 *params,
11146 		  const u32 *val)
11147 {
11148 	return t4_set_params_timeout(adap, mbox, pf, vf, nparams, params, val,
11149 				     FW_CMD_MAX_TIMEOUT);
11150 }
11151 
11152 /**
11153  *	t4_cfg_pfvf - configure PF/VF resource limits
11154  *	@adap: the adapter
11155  *	@mbox: mailbox to use for the FW command
11156  *	@pf: the PF being configured
11157  *	@vf: the VF being configured
11158  *	@txq: the max number of egress queues
11159  *	@txq_eth_ctrl: the max number of egress Ethernet or control queues
11160  *	@rxqi: the max number of interrupt-capable ingress queues
11161  *	@rxq: the max number of interruptless ingress queues
11162  *	@tc: the PCI traffic class
11163  *	@vi: the max number of virtual interfaces
11164  *	@cmask: the channel access rights mask for the PF/VF
11165  *	@pmask: the port access rights mask for the PF/VF
11166  *	@nexact: the maximum number of exact MPS filters
11167  *	@rcaps: read capabilities
11168  *	@wxcaps: write/execute capabilities
11169  *
11170  *	Configures resource limits and capabilities for a physical or virtual
11171  *	function.
11172  */
t4_cfg_pfvf(struct adapter * adap,unsigned int mbox,unsigned int pf,unsigned int vf,unsigned int txq,unsigned int txq_eth_ctrl,unsigned int rxqi,unsigned int rxq,unsigned int tc,unsigned int vi,unsigned int cmask,unsigned int pmask,unsigned int nexact,unsigned int rcaps,unsigned int wxcaps)11173 int t4_cfg_pfvf(struct adapter *adap, unsigned int mbox, unsigned int pf,
11174 		unsigned int vf, unsigned int txq, unsigned int txq_eth_ctrl,
11175 		unsigned int rxqi, unsigned int rxq, unsigned int tc,
11176 		unsigned int vi, unsigned int cmask, unsigned int pmask,
11177 		unsigned int nexact, unsigned int rcaps, unsigned int wxcaps)
11178 {
11179 	struct fw_pfvf_cmd c;
11180 
11181 	memset(&c, 0, sizeof(c));
11182 	c.op_to_vfn = cpu_to_be32(V_FW_CMD_OP(FW_PFVF_CMD) | F_FW_CMD_REQUEST |
11183 				  F_FW_CMD_WRITE | V_FW_PFVF_CMD_PFN(pf) |
11184 				  V_FW_PFVF_CMD_VFN(vf));
11185 	c.retval_len16 = cpu_to_be32(FW_LEN16(c));
11186 	c.niqflint_niq = cpu_to_be32(V_FW_PFVF_CMD_NIQFLINT(rxqi) |
11187 				     V_FW_PFVF_CMD_NIQ(rxq));
11188 	c.type_to_neq = cpu_to_be32(V_FW_PFVF_CMD_CMASK(cmask) |
11189 				    V_FW_PFVF_CMD_PMASK(pmask) |
11190 				    V_FW_PFVF_CMD_NEQ(txq));
11191 	c.tc_to_nexactf = cpu_to_be32(V_FW_PFVF_CMD_TC(tc) |
11192 				      V_FW_PFVF_CMD_NVI(vi) |
11193 				      V_FW_PFVF_CMD_NEXACTF(nexact));
11194 	c.r_caps_to_nethctrl = cpu_to_be32(V_FW_PFVF_CMD_R_CAPS(rcaps) |
11195 				     V_FW_PFVF_CMD_WX_CAPS(wxcaps) |
11196 				     V_FW_PFVF_CMD_NETHCTRL(txq_eth_ctrl));
11197 	return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
11198 }
11199 
11200 /**
11201  *	t4_alloc_vi_func - allocate a virtual interface
11202  *	@adap: the adapter
11203  *	@mbox: mailbox to use for the FW command
11204  *	@port: physical port associated with the VI
11205  *	@pf: the PF owning the VI
11206  *	@vf: the VF owning the VI
11207  *	@nmac: number of MAC addresses needed (1 to 5)
11208  *	@mac: the MAC addresses of the VI
11209  *	@rss_size: size of RSS table slice associated with this VI
11210  *	@portfunc: which Port Application Function MAC Address is desired
11211  *	@idstype: Intrusion Detection Type
11212  *
11213  *	Allocates a virtual interface for the given physical port.  If @mac is
11214  *	not %NULL it contains the MAC addresses of the VI as assigned by FW.
11215  *	If @rss_size is %NULL the VI is not assigned any RSS slice by FW.
11216  *	@mac should be large enough to hold @nmac Ethernet addresses, they are
11217  *	stored consecutively so the space needed is @nmac * 6 bytes.
11218  *	Returns a negative error number or the non-negative VI id.
11219  */
t4_alloc_vi_func(struct adapter * adap,unsigned int mbox,unsigned int port,unsigned int pf,unsigned int vf,unsigned int nmac,u8 * mac,u16 * rss_size,uint8_t * vfvld,uint16_t * vin,unsigned int portfunc,unsigned int idstype)11220 int t4_alloc_vi_func(struct adapter *adap, unsigned int mbox,
11221 		     unsigned int port, unsigned int pf, unsigned int vf,
11222 		     unsigned int nmac, u8 *mac, u16 *rss_size,
11223 		     uint8_t *vfvld, uint16_t *vin,
11224 		     unsigned int portfunc, unsigned int idstype)
11225 {
11226 	int ret;
11227 	struct fw_vi_cmd c;
11228 
11229 	memset(&c, 0, sizeof(c));
11230 	c.op_to_vfn = cpu_to_be32(V_FW_CMD_OP(FW_VI_CMD) | F_FW_CMD_REQUEST |
11231 				  F_FW_CMD_WRITE | F_FW_CMD_EXEC |
11232 				  V_FW_VI_CMD_PFN(pf) | V_FW_VI_CMD_VFN(vf));
11233 	c.alloc_to_len16 = cpu_to_be32(F_FW_VI_CMD_ALLOC | FW_LEN16(c));
11234 	c.type_to_viid = cpu_to_be16(V_FW_VI_CMD_TYPE(idstype) |
11235 				     V_FW_VI_CMD_FUNC(portfunc));
11236 	c.portid_pkd = V_FW_VI_CMD_PORTID(port);
11237 	c.nmac = nmac - 1;
11238 	if(!rss_size)
11239 		c.norss_rsssize = F_FW_VI_CMD_NORSS;
11240 
11241 	ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
11242 	if (ret)
11243 		return ret;
11244 	ret = G_FW_VI_CMD_VIID(be16_to_cpu(c.type_to_viid));
11245 
11246 	if (mac) {
11247 		memcpy(mac, c.mac, sizeof(c.mac));
11248 		switch (nmac) {
11249 		case 5:
11250 			memcpy(mac + 24, c.nmac3, sizeof(c.nmac3));
11251 		case 4:
11252 			memcpy(mac + 18, c.nmac2, sizeof(c.nmac2));
11253 		case 3:
11254 			memcpy(mac + 12, c.nmac1, sizeof(c.nmac1));
11255 		case 2:
11256 			memcpy(mac + 6,  c.nmac0, sizeof(c.nmac0));
11257 		}
11258 	}
11259 	if (rss_size)
11260 		*rss_size = G_FW_VI_CMD_RSSSIZE(be16_to_cpu(c.norss_rsssize));
11261 	if (vfvld) {
11262 		*vfvld = adap->params.viid_smt_extn_support ?
11263 		    G_FW_VI_CMD_VFVLD(be32_to_cpu(c.alloc_to_len16)) :
11264 		    G_FW_VIID_VIVLD(ret);
11265 	}
11266 	if (vin) {
11267 		*vin = adap->params.viid_smt_extn_support ?
11268 		    G_FW_VI_CMD_VIN(be32_to_cpu(c.alloc_to_len16)) :
11269 		    G_FW_VIID_VIN(ret);
11270 	}
11271 
11272 	return ret;
11273 }
11274 
11275 /**
11276  *      t4_alloc_vi - allocate an [Ethernet Function] virtual interface
11277  *      @adap: the adapter
11278  *      @mbox: mailbox to use for the FW command
11279  *      @port: physical port associated with the VI
11280  *      @pf: the PF owning the VI
11281  *      @vf: the VF owning the VI
11282  *      @nmac: number of MAC addresses needed (1 to 5)
11283  *      @mac: the MAC addresses of the VI
11284  *      @rss_size: size of RSS table slice associated with this VI
11285  *
11286  *	backwards compatible and convieniance routine to allocate a Virtual
11287  *	Interface with a Ethernet Port Application Function and Intrustion
11288  *	Detection System disabled.
11289  */
t4_alloc_vi(struct adapter * adap,unsigned int mbox,unsigned int port,unsigned int pf,unsigned int vf,unsigned int nmac,u8 * mac,u16 * rss_size,uint8_t * vfvld,uint16_t * vin)11290 int t4_alloc_vi(struct adapter *adap, unsigned int mbox, unsigned int port,
11291 		unsigned int pf, unsigned int vf, unsigned int nmac, u8 *mac,
11292 		u16 *rss_size, uint8_t *vfvld, uint16_t *vin)
11293 {
11294 	return t4_alloc_vi_func(adap, mbox, port, pf, vf, nmac, mac, rss_size,
11295 				vfvld, vin, FW_VI_FUNC_ETH, 0);
11296 }
11297 
11298 /**
11299  * 	t4_free_vi - free a virtual interface
11300  * 	@adap: the adapter
11301  * 	@mbox: mailbox to use for the FW command
11302  * 	@pf: the PF owning the VI
11303  * 	@vf: the VF owning the VI
11304  * 	@viid: virtual interface identifiler
11305  *
11306  * 	Free a previously allocated virtual interface.
11307  */
t4_free_vi(struct adapter * adap,unsigned int mbox,unsigned int pf,unsigned int vf,unsigned int viid)11308 int t4_free_vi(struct adapter *adap, unsigned int mbox, unsigned int pf,
11309 	       unsigned int vf, unsigned int viid)
11310 {
11311 	struct fw_vi_cmd c;
11312 
11313 	memset(&c, 0, sizeof(c));
11314 	c.op_to_vfn = cpu_to_be32(V_FW_CMD_OP(FW_VI_CMD) |
11315 				  F_FW_CMD_REQUEST |
11316 				  F_FW_CMD_EXEC |
11317 				  V_FW_VI_CMD_PFN(pf) |
11318 				  V_FW_VI_CMD_VFN(vf));
11319 	c.alloc_to_len16 = cpu_to_be32(F_FW_VI_CMD_FREE | FW_LEN16(c));
11320 	c.type_to_viid = cpu_to_be16(V_FW_VI_CMD_VIID(viid));
11321 
11322 	return t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
11323 }
11324 
11325 /**
11326  *	t4_set_rxmode - set Rx properties of a virtual interface
11327  *	@adap: the adapter
11328  *	@mbox: mailbox to use for the FW command
11329  *	@viid: the VI id
11330  *	@mtu: the new MTU or -1
11331  *	@promisc: 1 to enable promiscuous mode, 0 to disable it, -1 no change
11332  *	@all_multi: 1 to enable all-multi mode, 0 to disable it, -1 no change
11333  *	@bcast: 1 to enable broadcast Rx, 0 to disable it, -1 no change
11334  *	@vlanex: 1 to enable HW VLAN extraction, 0 to disable it, -1 no change
11335  *	@sleep_ok: if true we may sleep while awaiting command completion
11336  *
11337  *	Sets Rx properties of a virtual interface.
11338  */
t4_set_rxmode(struct adapter * adap,unsigned int mbox,unsigned int viid,int mtu,int promisc,int all_multi,int bcast,int vlanex,bool sleep_ok)11339 int t4_set_rxmode(struct adapter *adap, unsigned int mbox, unsigned int viid,
11340 		  int mtu, int promisc, int all_multi, int bcast, int vlanex,
11341 		  bool sleep_ok)
11342 {
11343 	struct fw_vi_rxmode_cmd c;
11344 
11345 	/* convert to FW values */
11346 	if (mtu < 0)
11347 		mtu = M_FW_VI_RXMODE_CMD_MTU;
11348 	if (promisc < 0)
11349 		promisc = M_FW_VI_RXMODE_CMD_PROMISCEN;
11350 	if (all_multi < 0)
11351 		all_multi = M_FW_VI_RXMODE_CMD_ALLMULTIEN;
11352 	if (bcast < 0)
11353 		bcast = M_FW_VI_RXMODE_CMD_BROADCASTEN;
11354 	if (vlanex < 0)
11355 		vlanex = M_FW_VI_RXMODE_CMD_VLANEXEN;
11356 
11357 	memset(&c, 0, sizeof(c));
11358 	c.op_to_viid = cpu_to_be32(V_FW_CMD_OP(FW_VI_RXMODE_CMD) |
11359 				   F_FW_CMD_REQUEST | F_FW_CMD_WRITE |
11360 				   V_FW_VI_RXMODE_CMD_VIID(viid));
11361 	c.retval_len16 = cpu_to_be32(FW_LEN16(c));
11362 	c.mtu_to_vlanexen =
11363 		cpu_to_be32(V_FW_VI_RXMODE_CMD_MTU(mtu) |
11364 			    V_FW_VI_RXMODE_CMD_PROMISCEN(promisc) |
11365 			    V_FW_VI_RXMODE_CMD_ALLMULTIEN(all_multi) |
11366 			    V_FW_VI_RXMODE_CMD_BROADCASTEN(bcast) |
11367 			    V_FW_VI_RXMODE_CMD_VLANEXEN(vlanex));
11368 	return t4_wr_mbox_meat(adap, mbox, &c, sizeof(c), NULL, sleep_ok);
11369 }
11370 
11371 /**
11372  *	t4_alloc_encap_mac_filt - Adds a mac entry in mps tcam with VNI support
11373  *	@adap: the adapter
11374  *	@viid: the VI id
11375  *	@mac: the MAC address
11376  *	@mask: the mask
11377  *	@vni: the VNI id for the tunnel protocol
11378  *	@vni_mask: mask for the VNI id
11379  *	@dip_hit: to enable DIP match for the MPS entry
11380  *	@lookup_type: MAC address for inner (1) or outer (0) header
11381  *	@sleep_ok: call is allowed to sleep
11382  *
11383  *	Allocates an MPS entry with specified MAC address and VNI value.
11384  *
11385  *	Returns a negative error number or the allocated index for this mac.
11386  */
t4_alloc_encap_mac_filt(struct adapter * adap,unsigned int viid,const u8 * addr,const u8 * mask,unsigned int vni,unsigned int vni_mask,u8 dip_hit,u8 lookup_type,bool sleep_ok)11387 int t4_alloc_encap_mac_filt(struct adapter *adap, unsigned int viid,
11388 			    const u8 *addr, const u8 *mask, unsigned int vni,
11389 			    unsigned int vni_mask, u8 dip_hit, u8 lookup_type,
11390 			    bool sleep_ok)
11391 {
11392 	struct fw_vi_mac_cmd c;
11393 	struct fw_vi_mac_vni *p = c.u.exact_vni;
11394 	int ret = 0;
11395 	u32 val;
11396 
11397 	memset(&c, 0, sizeof(c));
11398 	c.op_to_viid = cpu_to_be32(V_FW_CMD_OP(FW_VI_MAC_CMD) |
11399 				   F_FW_CMD_REQUEST | F_FW_CMD_WRITE |
11400 				   V_FW_VI_MAC_CMD_VIID(viid));
11401 	val = V_FW_CMD_LEN16(1) |
11402 	      V_FW_VI_MAC_CMD_ENTRY_TYPE(FW_VI_MAC_TYPE_EXACTMAC_VNI);
11403 	c.freemacs_to_len16 = cpu_to_be32(val);
11404 	p->valid_to_idx = cpu_to_be16(F_FW_VI_MAC_CMD_VALID |
11405 				      V_FW_VI_MAC_CMD_IDX(FW_VI_MAC_ADD_MAC));
11406 	memcpy(p->macaddr, addr, sizeof(p->macaddr));
11407 	memcpy(p->macaddr_mask, mask, sizeof(p->macaddr_mask));
11408 
11409 	p->lookup_type_to_vni = cpu_to_be32(V_FW_VI_MAC_CMD_VNI(vni) |
11410 					    V_FW_VI_MAC_CMD_DIP_HIT(dip_hit) |
11411 					    V_FW_VI_MAC_CMD_LOOKUP_TYPE(lookup_type));
11412 	p->vni_mask_pkd = cpu_to_be32(V_FW_VI_MAC_CMD_VNI_MASK(vni_mask));
11413 
11414 	ret = t4_wr_mbox_meat(adap, adap->mbox, &c, sizeof(c), &c, sleep_ok);
11415 	if (ret == 0)
11416 		ret = G_FW_VI_MAC_CMD_IDX(be16_to_cpu(p->valid_to_idx));
11417 	return ret;
11418 }
11419 
11420 /**
11421  *	t4_alloc_raw_mac_filt - Adds a mac entry in mps tcam
11422  *	@adap: the adapter
11423  *	@viid: the VI id
11424  *	@mac: the MAC address
11425  *	@mask: the mask
11426  *	@idx: index at which to add this entry
11427  *	@port_id: the port index
11428  *	@lookup_type: MAC address for inner (1) or outer (0) header
11429  *	@sleep_ok: call is allowed to sleep
11430  *
11431  *	Adds the mac entry at the specified index using raw mac interface.
11432  *
11433  *	Returns a negative error number or the allocated index for this mac.
11434  */
t4_alloc_raw_mac_filt(struct adapter * adap,unsigned int viid,const u8 * addr,const u8 * mask,unsigned int idx,u8 lookup_type,u8 port_id,bool sleep_ok)11435 int t4_alloc_raw_mac_filt(struct adapter *adap, unsigned int viid,
11436 			  const u8 *addr, const u8 *mask, unsigned int idx,
11437 			  u8 lookup_type, u8 port_id, bool sleep_ok)
11438 {
11439 	int ret = 0;
11440 	struct fw_vi_mac_cmd c;
11441 	struct fw_vi_mac_raw *p = &c.u.raw;
11442 	u32 val;
11443 
11444 	memset(&c, 0, sizeof(c));
11445 	c.op_to_viid = cpu_to_be32(V_FW_CMD_OP(FW_VI_MAC_CMD) |
11446 				   F_FW_CMD_REQUEST | F_FW_CMD_WRITE |
11447 				   V_FW_VI_MAC_CMD_VIID(viid));
11448 	val = V_FW_CMD_LEN16(1) |
11449 	      V_FW_VI_MAC_CMD_ENTRY_TYPE(FW_VI_MAC_TYPE_RAW);
11450 	c.freemacs_to_len16 = cpu_to_be32(val);
11451 
11452 	/* Specify that this is an inner mac address */
11453 	p->raw_idx_pkd = cpu_to_be32(V_FW_VI_MAC_CMD_RAW_IDX(idx));
11454 
11455 	/* Lookup Type. Outer header: 0, Inner header: 1 */
11456 	p->data0_pkd = cpu_to_be32(V_DATALKPTYPE(lookup_type) |
11457 				   V_DATAPORTNUM(port_id));
11458 	/* Lookup mask and port mask */
11459 	p->data0m_pkd = cpu_to_be64(V_DATALKPTYPE(M_DATALKPTYPE) |
11460 				    V_DATAPORTNUM(M_DATAPORTNUM));
11461 
11462 	/* Copy the address and the mask */
11463 	memcpy((u8 *)&p->data1[0] + 2, addr, ETHER_ADDR_LEN);
11464 	memcpy((u8 *)&p->data1m[0] + 2, mask, ETHER_ADDR_LEN);
11465 
11466 	ret = t4_wr_mbox_meat(adap, adap->mbox, &c, sizeof(c), &c, sleep_ok);
11467 	if (ret == 0) {
11468 		ret = G_FW_VI_MAC_CMD_RAW_IDX(be32_to_cpu(p->raw_idx_pkd));
11469 		if (ret != idx)
11470 			ret = -ENOMEM;
11471 	}
11472 
11473 	return ret;
11474 }
11475 
11476 /**
11477  *	t4_alloc_mac_filt - allocates exact-match filters for MAC addresses
11478  *	@adap: the adapter
11479  *	@mbox: mailbox to use for the FW command
11480  *	@viid: the VI id
11481  *	@free: if true any existing filters for this VI id are first removed
11482  *	@naddr: the number of MAC addresses to allocate filters for (up to 7)
11483  *	@addr: the MAC address(es)
11484  *	@idx: where to store the index of each allocated filter
11485  *	@hash: pointer to hash address filter bitmap
11486  *	@sleep_ok: call is allowed to sleep
11487  *
11488  *	Allocates an exact-match filter for each of the supplied addresses and
11489  *	sets it to the corresponding address.  If @idx is not %NULL it should
11490  *	have at least @naddr entries, each of which will be set to the index of
11491  *	the filter allocated for the corresponding MAC address.  If a filter
11492  *	could not be allocated for an address its index is set to 0xffff.
11493  *	If @hash is not %NULL addresses that fail to allocate an exact filter
11494  *	are hashed and update the hash filter bitmap pointed at by @hash.
11495  *
11496  *	Returns a negative error number or the number of filters allocated.
11497  */
t4_alloc_mac_filt(struct adapter * adap,unsigned int mbox,unsigned int viid,bool free,unsigned int naddr,const u8 ** addr,u16 * idx,u64 * hash,bool sleep_ok)11498 int t4_alloc_mac_filt(struct adapter *adap, unsigned int mbox,
11499 		      unsigned int viid, bool free, unsigned int naddr,
11500 		      const u8 **addr, u16 *idx, u64 *hash, bool sleep_ok)
11501 {
11502 	int offset, ret = 0;
11503 	struct fw_vi_mac_cmd c;
11504 	unsigned int nfilters = 0;
11505 	unsigned int max_naddr = adap->chip_params->mps_tcam_size;
11506 	unsigned int rem = naddr;
11507 
11508 	if (naddr > max_naddr)
11509 		return -EINVAL;
11510 
11511 	for (offset = 0; offset < naddr ; /**/) {
11512 		unsigned int fw_naddr = (rem < ARRAY_SIZE(c.u.exact)
11513 					 ? rem
11514 					 : ARRAY_SIZE(c.u.exact));
11515 		size_t len16 = DIV_ROUND_UP(offsetof(struct fw_vi_mac_cmd,
11516 						     u.exact[fw_naddr]), 16);
11517 		struct fw_vi_mac_exact *p;
11518 		int i;
11519 
11520 		memset(&c, 0, sizeof(c));
11521 		c.op_to_viid = cpu_to_be32(V_FW_CMD_OP(FW_VI_MAC_CMD) |
11522 					   F_FW_CMD_REQUEST |
11523 					   F_FW_CMD_WRITE |
11524 					   V_FW_CMD_EXEC(free) |
11525 					   V_FW_VI_MAC_CMD_VIID(viid));
11526 		c.freemacs_to_len16 = cpu_to_be32(V_FW_VI_MAC_CMD_FREEMACS(free) |
11527 						  V_FW_CMD_LEN16(len16));
11528 
11529 		for (i = 0, p = c.u.exact; i < fw_naddr; i++, p++) {
11530 			p->valid_to_idx =
11531 				cpu_to_be16(F_FW_VI_MAC_CMD_VALID |
11532 					    V_FW_VI_MAC_CMD_IDX(FW_VI_MAC_ADD_MAC));
11533 			memcpy(p->macaddr, addr[offset+i], sizeof(p->macaddr));
11534 		}
11535 
11536 		/*
11537 		 * It's okay if we run out of space in our MAC address arena.
11538 		 * Some of the addresses we submit may get stored so we need
11539 		 * to run through the reply to see what the results were ...
11540 		 */
11541 		ret = t4_wr_mbox_meat(adap, mbox, &c, sizeof(c), &c, sleep_ok);
11542 		if (ret && ret != -FW_ENOMEM)
11543 			break;
11544 
11545 		for (i = 0, p = c.u.exact; i < fw_naddr; i++, p++) {
11546 			u16 index = G_FW_VI_MAC_CMD_IDX(
11547 						be16_to_cpu(p->valid_to_idx));
11548 
11549 			if (idx)
11550 				idx[offset+i] = (index >=  max_naddr
11551 						 ? 0xffff
11552 						 : index);
11553 			if (index < max_naddr)
11554 				nfilters++;
11555 			else if (hash)
11556 				*hash |= (1ULL << hash_mac_addr(addr[offset+i]));
11557 		}
11558 
11559 		free = false;
11560 		offset += fw_naddr;
11561 		rem -= fw_naddr;
11562 	}
11563 
11564 	if (ret == 0 || ret == -FW_ENOMEM)
11565 		ret = nfilters;
11566 	return ret;
11567 }
11568 
11569 /**
11570  *	t4_free_encap_mac_filt - frees MPS entry at given index
11571  *	@adap: the adapter
11572  *	@viid: the VI id
11573  *	@idx: index of MPS entry to be freed
11574  *	@sleep_ok: call is allowed to sleep
11575  *
11576  *	Frees the MPS entry at supplied index
11577  *
11578  *	Returns a negative error number or zero on success
11579  */
t4_free_encap_mac_filt(struct adapter * adap,unsigned int viid,int idx,bool sleep_ok)11580 int t4_free_encap_mac_filt(struct adapter *adap, unsigned int viid,
11581 			   int idx, bool sleep_ok)
11582 {
11583 	struct fw_vi_mac_exact *p;
11584 	struct fw_vi_mac_cmd c;
11585 	u8 addr[] = {0,0,0,0,0,0};
11586 	int ret = 0;
11587 	u32 exact;
11588 
11589 	memset(&c, 0, sizeof(c));
11590 	c.op_to_viid = cpu_to_be32(V_FW_CMD_OP(FW_VI_MAC_CMD) |
11591 				   F_FW_CMD_REQUEST |
11592 				   F_FW_CMD_WRITE |
11593 				   V_FW_CMD_EXEC(0) |
11594 				   V_FW_VI_MAC_CMD_VIID(viid));
11595 	exact = V_FW_VI_MAC_CMD_ENTRY_TYPE(FW_VI_MAC_TYPE_EXACTMAC);
11596 	c.freemacs_to_len16 = cpu_to_be32(V_FW_VI_MAC_CMD_FREEMACS(0) |
11597 					  exact |
11598 					  V_FW_CMD_LEN16(1));
11599 	p = c.u.exact;
11600 	p->valid_to_idx = cpu_to_be16(F_FW_VI_MAC_CMD_VALID |
11601 				      V_FW_VI_MAC_CMD_IDX(idx));
11602 	memcpy(p->macaddr, addr, sizeof(p->macaddr));
11603 
11604 	ret = t4_wr_mbox_meat(adap, adap->mbox, &c, sizeof(c), &c, sleep_ok);
11605 	return ret;
11606 }
11607 
11608 /**
11609  *	t4_free_raw_mac_filt - Frees a raw mac entry in mps tcam
11610  *	@adap: the adapter
11611  *	@viid: the VI id
11612  *	@addr: the MAC address
11613  *	@mask: the mask
11614  *	@idx: index of the entry in mps tcam
11615  *	@lookup_type: MAC address for inner (1) or outer (0) header
11616  *	@port_id: the port index
11617  *	@sleep_ok: call is allowed to sleep
11618  *
11619  *	Removes the mac entry at the specified index using raw mac interface.
11620  *
11621  *	Returns a negative error number on failure.
11622  */
t4_free_raw_mac_filt(struct adapter * adap,unsigned int viid,const u8 * addr,const u8 * mask,unsigned int idx,u8 lookup_type,u8 port_id,bool sleep_ok)11623 int t4_free_raw_mac_filt(struct adapter *adap, unsigned int viid,
11624 			 const u8 *addr, const u8 *mask, unsigned int idx,
11625 			 u8 lookup_type, u8 port_id, bool sleep_ok)
11626 {
11627 	struct fw_vi_mac_cmd c;
11628 	struct fw_vi_mac_raw *p = &c.u.raw;
11629 	u32 raw;
11630 
11631 	memset(&c, 0, sizeof(c));
11632 	c.op_to_viid = cpu_to_be32(V_FW_CMD_OP(FW_VI_MAC_CMD) |
11633 				   F_FW_CMD_REQUEST | F_FW_CMD_WRITE |
11634 				   V_FW_CMD_EXEC(0) |
11635 				   V_FW_VI_MAC_CMD_VIID(viid));
11636 	raw = V_FW_VI_MAC_CMD_ENTRY_TYPE(FW_VI_MAC_TYPE_RAW);
11637 	c.freemacs_to_len16 = cpu_to_be32(V_FW_VI_MAC_CMD_FREEMACS(0) |
11638 					  raw |
11639 					  V_FW_CMD_LEN16(1));
11640 
11641 	p->raw_idx_pkd = cpu_to_be32(V_FW_VI_MAC_CMD_RAW_IDX(idx) |
11642 				     FW_VI_MAC_ID_BASED_FREE);
11643 
11644 	/* Lookup Type. Outer header: 0, Inner header: 1 */
11645 	p->data0_pkd = cpu_to_be32(V_DATALKPTYPE(lookup_type) |
11646 				   V_DATAPORTNUM(port_id));
11647 	/* Lookup mask and port mask */
11648 	p->data0m_pkd = cpu_to_be64(V_DATALKPTYPE(M_DATALKPTYPE) |
11649 				    V_DATAPORTNUM(M_DATAPORTNUM));
11650 
11651 	/* Copy the address and the mask */
11652 	memcpy((u8 *)&p->data1[0] + 2, addr, ETHER_ADDR_LEN);
11653 	memcpy((u8 *)&p->data1m[0] + 2, mask, ETHER_ADDR_LEN);
11654 
11655 	return t4_wr_mbox_meat(adap, adap->mbox, &c, sizeof(c), &c, sleep_ok);
11656 }
11657 
11658 /**
11659  *	t4_free_mac_filt - frees exact-match filters of given MAC addresses
11660  *	@adap: the adapter
11661  *	@mbox: mailbox to use for the FW command
11662  *	@viid: the VI id
11663  *	@naddr: the number of MAC addresses to allocate filters for (up to 7)
11664  *	@addr: the MAC address(es)
11665  *	@sleep_ok: call is allowed to sleep
11666  *
11667  *	Frees the exact-match filter for each of the supplied addresses
11668  *
11669  *	Returns a negative error number or the number of filters freed.
11670  */
t4_free_mac_filt(struct adapter * adap,unsigned int mbox,unsigned int viid,unsigned int naddr,const u8 ** addr,bool sleep_ok)11671 int t4_free_mac_filt(struct adapter *adap, unsigned int mbox,
11672 		      unsigned int viid, unsigned int naddr,
11673 		      const u8 **addr, bool sleep_ok)
11674 {
11675 	int offset, ret = 0;
11676 	struct fw_vi_mac_cmd c;
11677 	unsigned int nfilters = 0;
11678 	unsigned int max_naddr = adap->chip_params->mps_tcam_size;
11679 	unsigned int rem = naddr;
11680 
11681 	if (naddr > max_naddr)
11682 		return -EINVAL;
11683 
11684 	for (offset = 0; offset < (int)naddr ; /**/) {
11685 		unsigned int fw_naddr = (rem < ARRAY_SIZE(c.u.exact)
11686 					 ? rem
11687 					 : ARRAY_SIZE(c.u.exact));
11688 		size_t len16 = DIV_ROUND_UP(offsetof(struct fw_vi_mac_cmd,
11689 						     u.exact[fw_naddr]), 16);
11690 		struct fw_vi_mac_exact *p;
11691 		int i;
11692 
11693 		memset(&c, 0, sizeof(c));
11694 		c.op_to_viid = cpu_to_be32(V_FW_CMD_OP(FW_VI_MAC_CMD) |
11695 				     F_FW_CMD_REQUEST |
11696 				     F_FW_CMD_WRITE |
11697 				     V_FW_CMD_EXEC(0) |
11698 				     V_FW_VI_MAC_CMD_VIID(viid));
11699 		c.freemacs_to_len16 =
11700 				cpu_to_be32(V_FW_VI_MAC_CMD_FREEMACS(0) |
11701 					    V_FW_CMD_LEN16(len16));
11702 
11703 		for (i = 0, p = c.u.exact; i < (int)fw_naddr; i++, p++) {
11704 			p->valid_to_idx = cpu_to_be16(
11705 				F_FW_VI_MAC_CMD_VALID |
11706 				V_FW_VI_MAC_CMD_IDX(FW_VI_MAC_MAC_BASED_FREE));
11707 			memcpy(p->macaddr, addr[offset+i], sizeof(p->macaddr));
11708 		}
11709 
11710 		ret = t4_wr_mbox_meat(adap, mbox, &c, sizeof(c), &c, sleep_ok);
11711 		if (ret)
11712 			break;
11713 
11714 		for (i = 0, p = c.u.exact; i < fw_naddr; i++, p++) {
11715 			u16 index = G_FW_VI_MAC_CMD_IDX(
11716 						be16_to_cpu(p->valid_to_idx));
11717 
11718 			if (index < max_naddr)
11719 				nfilters++;
11720 		}
11721 
11722 		offset += fw_naddr;
11723 		rem -= fw_naddr;
11724 	}
11725 
11726 	if (ret == 0)
11727 		ret = nfilters;
11728 	return ret;
11729 }
11730 
11731 /**
11732  *	t4_change_mac - modifies the exact-match filter for a MAC address
11733  *	@adap: the adapter
11734  *	@mbox: mailbox to use for the FW command
11735  *	@viid: the VI id
11736  *	@idx: index of existing filter for old value of MAC address, or -1
11737  *	@addr: the new MAC address value
11738  *	@persist: whether a new MAC allocation should be persistent
11739  *	@smt_idx: add MAC to SMT and return its index, or NULL
11740  *
11741  *	Modifies an exact-match filter and sets it to the new MAC address if
11742  *	@idx >= 0, or adds the MAC address to a new filter if @idx < 0.  In the
11743  *	latter case the address is added persistently if @persist is %true.
11744  *
11745  *	Note that in general it is not possible to modify the value of a given
11746  *	filter so the generic way to modify an address filter is to free the one
11747  *	being used by the old address value and allocate a new filter for the
11748  *	new address value.
11749  *
11750  *	Returns a negative error number or the index of the filter with the new
11751  *	MAC value.  Note that this index may differ from @idx.
11752  */
t4_change_mac(struct adapter * adap,unsigned int mbox,unsigned int viid,int idx,const u8 * addr,bool persist,uint16_t * smt_idx)11753 int t4_change_mac(struct adapter *adap, unsigned int mbox, unsigned int viid,
11754 		  int idx, const u8 *addr, bool persist, uint16_t *smt_idx)
11755 {
11756 	int ret, mode;
11757 	struct fw_vi_mac_cmd c;
11758 	struct fw_vi_mac_exact *p = c.u.exact;
11759 	unsigned int max_mac_addr = adap->chip_params->mps_tcam_size;
11760 
11761 	if (idx < 0)		/* new allocation */
11762 		idx = persist ? FW_VI_MAC_ADD_PERSIST_MAC : FW_VI_MAC_ADD_MAC;
11763 	mode = smt_idx ? FW_VI_MAC_SMT_AND_MPSTCAM : FW_VI_MAC_MPS_TCAM_ENTRY;
11764 
11765 	memset(&c, 0, sizeof(c));
11766 	c.op_to_viid = cpu_to_be32(V_FW_CMD_OP(FW_VI_MAC_CMD) |
11767 				   F_FW_CMD_REQUEST | F_FW_CMD_WRITE |
11768 				   V_FW_VI_MAC_CMD_VIID(viid));
11769 	c.freemacs_to_len16 = cpu_to_be32(V_FW_CMD_LEN16(1));
11770 	p->valid_to_idx = cpu_to_be16(F_FW_VI_MAC_CMD_VALID |
11771 				      V_FW_VI_MAC_CMD_SMAC_RESULT(mode) |
11772 				      V_FW_VI_MAC_CMD_IDX(idx));
11773 	memcpy(p->macaddr, addr, sizeof(p->macaddr));
11774 
11775 	ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
11776 	if (ret == 0) {
11777 		ret = G_FW_VI_MAC_CMD_IDX(be16_to_cpu(p->valid_to_idx));
11778 		if (ret >= max_mac_addr)
11779 			ret = -ENOMEM;
11780 		if (smt_idx) {
11781 			if (adap->params.viid_smt_extn_support)
11782 				*smt_idx = G_FW_VI_MAC_CMD_SMTID(be32_to_cpu(c.op_to_viid));
11783 			else {
11784 				if (chip_id(adap) <= CHELSIO_T5)
11785 					*smt_idx = (viid & M_FW_VIID_VIN) << 1;
11786 				else
11787 					*smt_idx = viid & M_FW_VIID_VIN;
11788 			}
11789 		}
11790 	}
11791 	return ret;
11792 }
11793 
11794 /**
11795  *	t4_set_addr_hash - program the MAC inexact-match hash filter
11796  *	@adap: the adapter
11797  *	@mbox: mailbox to use for the FW command
11798  *	@viid: the VI id
11799  *	@ucast: whether the hash filter should also match unicast addresses
11800  *	@vec: the value to be written to the hash filter
11801  *	@sleep_ok: call is allowed to sleep
11802  *
11803  *	Sets the 64-bit inexact-match hash filter for a virtual interface.
11804  */
t4_set_addr_hash(struct adapter * adap,unsigned int mbox,unsigned int viid,bool ucast,u64 vec,bool sleep_ok)11805 int t4_set_addr_hash(struct adapter *adap, unsigned int mbox, unsigned int viid,
11806 		     bool ucast, u64 vec, bool sleep_ok)
11807 {
11808 	struct fw_vi_mac_cmd c;
11809 	u32 val;
11810 
11811 	memset(&c, 0, sizeof(c));
11812 	c.op_to_viid = cpu_to_be32(V_FW_CMD_OP(FW_VI_MAC_CMD) |
11813 				   F_FW_CMD_REQUEST | F_FW_CMD_WRITE |
11814 				   V_FW_VI_ENABLE_CMD_VIID(viid));
11815 	val = V_FW_VI_MAC_CMD_ENTRY_TYPE(FW_VI_MAC_TYPE_HASHVEC) |
11816 	      V_FW_VI_MAC_CMD_HASHUNIEN(ucast) | V_FW_CMD_LEN16(1);
11817 	c.freemacs_to_len16 = cpu_to_be32(val);
11818 	c.u.hash.hashvec = cpu_to_be64(vec);
11819 	return t4_wr_mbox_meat(adap, mbox, &c, sizeof(c), NULL, sleep_ok);
11820 }
11821 
11822 /**
11823  *      t4_enable_vi_params - enable/disable a virtual interface
11824  *      @adap: the adapter
11825  *      @mbox: mailbox to use for the FW command
11826  *      @viid: the VI id
11827  *      @rx_en: 1=enable Rx, 0=disable Rx
11828  *      @tx_en: 1=enable Tx, 0=disable Tx
11829  *      @dcb_en: 1=enable delivery of Data Center Bridging messages.
11830  *
11831  *      Enables/disables a virtual interface.  Note that setting DCB Enable
11832  *      only makes sense when enabling a Virtual Interface ...
11833  */
t4_enable_vi_params(struct adapter * adap,unsigned int mbox,unsigned int viid,bool rx_en,bool tx_en,bool dcb_en)11834 int t4_enable_vi_params(struct adapter *adap, unsigned int mbox,
11835 			unsigned int viid, bool rx_en, bool tx_en, bool dcb_en)
11836 {
11837 	struct fw_vi_enable_cmd c;
11838 
11839 	memset(&c, 0, sizeof(c));
11840 	c.op_to_viid = cpu_to_be32(V_FW_CMD_OP(FW_VI_ENABLE_CMD) |
11841 				   F_FW_CMD_REQUEST | F_FW_CMD_EXEC |
11842 				   V_FW_VI_ENABLE_CMD_VIID(viid));
11843 	c.ien_to_len16 = cpu_to_be32(V_FW_VI_ENABLE_CMD_IEN(rx_en) |
11844 				     V_FW_VI_ENABLE_CMD_EEN(tx_en) |
11845 				     V_FW_VI_ENABLE_CMD_DCB_INFO(dcb_en) |
11846 				     FW_LEN16(c));
11847 	return t4_wr_mbox_ns(adap, mbox, &c, sizeof(c), NULL);
11848 }
11849 
11850 /**
11851  *	t4_enable_vi - enable/disable a virtual interface
11852  *	@adap: the adapter
11853  *	@mbox: mailbox to use for the FW command
11854  *	@viid: the VI id
11855  *	@rx_en: 1=enable Rx, 0=disable Rx
11856  *	@tx_en: 1=enable Tx, 0=disable Tx
11857  *
11858  *	Enables/disables a virtual interface.  Note that setting DCB Enable
11859  *	only makes sense when enabling a Virtual Interface ...
11860  */
t4_enable_vi(struct adapter * adap,unsigned int mbox,unsigned int viid,bool rx_en,bool tx_en)11861 int t4_enable_vi(struct adapter *adap, unsigned int mbox, unsigned int viid,
11862 		 bool rx_en, bool tx_en)
11863 {
11864 	return t4_enable_vi_params(adap, mbox, viid, rx_en, tx_en, 0);
11865 }
11866 
11867 /**
11868  *	t4_identify_port - identify a VI's port by blinking its LED
11869  *	@adap: the adapter
11870  *	@mbox: mailbox to use for the FW command
11871  *	@viid: the VI id
11872  *	@nblinks: how many times to blink LED at 2.5 Hz
11873  *
11874  *	Identifies a VI's port by blinking its LED.
11875  */
t4_identify_port(struct adapter * adap,unsigned int mbox,unsigned int viid,unsigned int nblinks)11876 int t4_identify_port(struct adapter *adap, unsigned int mbox, unsigned int viid,
11877 		     unsigned int nblinks)
11878 {
11879 	struct fw_vi_enable_cmd c;
11880 
11881 	memset(&c, 0, sizeof(c));
11882 	c.op_to_viid = cpu_to_be32(V_FW_CMD_OP(FW_VI_ENABLE_CMD) |
11883 				   F_FW_CMD_REQUEST | F_FW_CMD_EXEC |
11884 				   V_FW_VI_ENABLE_CMD_VIID(viid));
11885 	c.ien_to_len16 = cpu_to_be32(F_FW_VI_ENABLE_CMD_LED | FW_LEN16(c));
11886 	c.blinkdur = cpu_to_be16(nblinks);
11887 	return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
11888 }
11889 
11890 /**
11891  *	t4_iq_stop - stop an ingress queue and its FLs
11892  *	@adap: the adapter
11893  *	@mbox: mailbox to use for the FW command
11894  *	@pf: the PF owning the queues
11895  *	@vf: the VF owning the queues
11896  *	@iqtype: the ingress queue type (FW_IQ_TYPE_FL_INT_CAP, etc.)
11897  *	@iqid: ingress queue id
11898  *	@fl0id: FL0 queue id or 0xffff if no attached FL0
11899  *	@fl1id: FL1 queue id or 0xffff if no attached FL1
11900  *
11901  *	Stops an ingress queue and its associated FLs, if any.  This causes
11902  *	any current or future data/messages destined for these queues to be
11903  *	tossed.
11904  */
t4_iq_stop(struct adapter * adap,unsigned int mbox,unsigned int pf,unsigned int vf,unsigned int iqtype,unsigned int iqid,unsigned int fl0id,unsigned int fl1id)11905 int t4_iq_stop(struct adapter *adap, unsigned int mbox, unsigned int pf,
11906 	       unsigned int vf, unsigned int iqtype, unsigned int iqid,
11907 	       unsigned int fl0id, unsigned int fl1id)
11908 {
11909 	struct fw_iq_cmd c;
11910 
11911 	memset(&c, 0, sizeof(c));
11912 	c.op_to_vfn = cpu_to_be32(V_FW_CMD_OP(FW_IQ_CMD) | F_FW_CMD_REQUEST |
11913 				  F_FW_CMD_EXEC | V_FW_IQ_CMD_PFN(pf) |
11914 				  V_FW_IQ_CMD_VFN(vf));
11915 	c.alloc_to_len16 = cpu_to_be32(F_FW_IQ_CMD_IQSTOP | FW_LEN16(c));
11916 	c.type_to_iqandstindex = cpu_to_be32(V_FW_IQ_CMD_TYPE(iqtype));
11917 	c.iqid = cpu_to_be16(iqid);
11918 	c.fl0id = cpu_to_be16(fl0id);
11919 	c.fl1id = cpu_to_be16(fl1id);
11920 	return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
11921 }
11922 
11923 /**
11924  *	t4_iq_free - free an ingress queue and its FLs
11925  *	@adap: the adapter
11926  *	@mbox: mailbox to use for the FW command
11927  *	@pf: the PF owning the queues
11928  *	@vf: the VF owning the queues
11929  *	@iqtype: the ingress queue type (FW_IQ_TYPE_FL_INT_CAP, etc.)
11930  *	@iqid: ingress queue id
11931  *	@fl0id: FL0 queue id or 0xffff if no attached FL0
11932  *	@fl1id: FL1 queue id or 0xffff if no attached FL1
11933  *
11934  *	Frees an ingress queue and its associated FLs, if any.
11935  */
t4_iq_free(struct adapter * adap,unsigned int mbox,unsigned int pf,unsigned int vf,unsigned int iqtype,unsigned int iqid,unsigned int fl0id,unsigned int fl1id)11936 int t4_iq_free(struct adapter *adap, unsigned int mbox, unsigned int pf,
11937 	       unsigned int vf, unsigned int iqtype, unsigned int iqid,
11938 	       unsigned int fl0id, unsigned int fl1id)
11939 {
11940 	struct fw_iq_cmd c;
11941 
11942 	memset(&c, 0, sizeof(c));
11943 	c.op_to_vfn = cpu_to_be32(V_FW_CMD_OP(FW_IQ_CMD) | F_FW_CMD_REQUEST |
11944 				  F_FW_CMD_EXEC | V_FW_IQ_CMD_PFN(pf) |
11945 				  V_FW_IQ_CMD_VFN(vf));
11946 	c.alloc_to_len16 = cpu_to_be32(F_FW_IQ_CMD_FREE | FW_LEN16(c));
11947 	c.type_to_iqandstindex = cpu_to_be32(V_FW_IQ_CMD_TYPE(iqtype));
11948 	c.iqid = cpu_to_be16(iqid);
11949 	c.fl0id = cpu_to_be16(fl0id);
11950 	c.fl1id = cpu_to_be16(fl1id);
11951 	return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
11952 }
11953 
11954 /**
11955  *	t4_eth_eq_stop - stop an Ethernet egress queue
11956  *	@adap: the adapter
11957  *	@mbox: mailbox to use for the FW command
11958  *	@pf: the PF owning the queues
11959  *	@vf: the VF owning the queues
11960  *	@eqid: egress queue id
11961  *
11962  *	Stops an Ethernet egress queue.  The queue can be reinitialized or
11963  *	freed but is not otherwise functional after this call.
11964  */
t4_eth_eq_stop(struct adapter * adap,unsigned int mbox,unsigned int pf,unsigned int vf,unsigned int eqid)11965 int t4_eth_eq_stop(struct adapter *adap, unsigned int mbox, unsigned int pf,
11966                    unsigned int vf, unsigned int eqid)
11967 {
11968 	struct fw_eq_eth_cmd c;
11969 
11970 	memset(&c, 0, sizeof(c));
11971 	c.op_to_vfn = cpu_to_be32(V_FW_CMD_OP(FW_EQ_ETH_CMD) |
11972 				  F_FW_CMD_REQUEST | F_FW_CMD_EXEC |
11973 				  V_FW_EQ_ETH_CMD_PFN(pf) |
11974 				  V_FW_EQ_ETH_CMD_VFN(vf));
11975 	c.alloc_to_len16 = cpu_to_be32(F_FW_EQ_ETH_CMD_EQSTOP | FW_LEN16(c));
11976 	c.eqid_pkd = cpu_to_be32(V_FW_EQ_ETH_CMD_EQID(eqid));
11977 	return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
11978 }
11979 
11980 /**
11981  *	t4_eth_eq_free - free an Ethernet egress queue
11982  *	@adap: the adapter
11983  *	@mbox: mailbox to use for the FW command
11984  *	@pf: the PF owning the queue
11985  *	@vf: the VF owning the queue
11986  *	@eqid: egress queue id
11987  *
11988  *	Frees an Ethernet egress queue.
11989  */
t4_eth_eq_free(struct adapter * adap,unsigned int mbox,unsigned int pf,unsigned int vf,unsigned int eqid)11990 int t4_eth_eq_free(struct adapter *adap, unsigned int mbox, unsigned int pf,
11991 		   unsigned int vf, unsigned int eqid)
11992 {
11993 	struct fw_eq_eth_cmd c;
11994 
11995 	memset(&c, 0, sizeof(c));
11996 	c.op_to_vfn = cpu_to_be32(V_FW_CMD_OP(FW_EQ_ETH_CMD) |
11997 				  F_FW_CMD_REQUEST | F_FW_CMD_EXEC |
11998 				  V_FW_EQ_ETH_CMD_PFN(pf) |
11999 				  V_FW_EQ_ETH_CMD_VFN(vf));
12000 	c.alloc_to_len16 = cpu_to_be32(F_FW_EQ_ETH_CMD_FREE | FW_LEN16(c));
12001 	c.eqid_pkd = cpu_to_be32(V_FW_EQ_ETH_CMD_EQID(eqid));
12002 	return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
12003 }
12004 
12005 /**
12006  *	t4_ctrl_eq_free - free a control egress queue
12007  *	@adap: the adapter
12008  *	@mbox: mailbox to use for the FW command
12009  *	@pf: the PF owning the queue
12010  *	@vf: the VF owning the queue
12011  *	@eqid: egress queue id
12012  *
12013  *	Frees a control egress queue.
12014  */
t4_ctrl_eq_free(struct adapter * adap,unsigned int mbox,unsigned int pf,unsigned int vf,unsigned int eqid)12015 int t4_ctrl_eq_free(struct adapter *adap, unsigned int mbox, unsigned int pf,
12016 		    unsigned int vf, unsigned int eqid)
12017 {
12018 	struct fw_eq_ctrl_cmd c;
12019 
12020 	memset(&c, 0, sizeof(c));
12021 	c.op_to_vfn = cpu_to_be32(V_FW_CMD_OP(FW_EQ_CTRL_CMD) |
12022 				  F_FW_CMD_REQUEST | F_FW_CMD_EXEC |
12023 				  V_FW_EQ_CTRL_CMD_PFN(pf) |
12024 				  V_FW_EQ_CTRL_CMD_VFN(vf));
12025 	c.alloc_to_len16 = cpu_to_be32(F_FW_EQ_CTRL_CMD_FREE | FW_LEN16(c));
12026 	c.cmpliqid_eqid = cpu_to_be32(V_FW_EQ_CTRL_CMD_EQID(eqid));
12027 	return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
12028 }
12029 
12030 /**
12031  *	t4_ofld_eq_free - free an offload egress queue
12032  *	@adap: the adapter
12033  *	@mbox: mailbox to use for the FW command
12034  *	@pf: the PF owning the queue
12035  *	@vf: the VF owning the queue
12036  *	@eqid: egress queue id
12037  *
12038  *	Frees a control egress queue.
12039  */
t4_ofld_eq_free(struct adapter * adap,unsigned int mbox,unsigned int pf,unsigned int vf,unsigned int eqid)12040 int t4_ofld_eq_free(struct adapter *adap, unsigned int mbox, unsigned int pf,
12041 		    unsigned int vf, unsigned int eqid)
12042 {
12043 	struct fw_eq_ofld_cmd c;
12044 
12045 	memset(&c, 0, sizeof(c));
12046 	c.op_to_vfn = cpu_to_be32(V_FW_CMD_OP(FW_EQ_OFLD_CMD) |
12047 				  F_FW_CMD_REQUEST | F_FW_CMD_EXEC |
12048 				  V_FW_EQ_OFLD_CMD_PFN(pf) |
12049 				  V_FW_EQ_OFLD_CMD_VFN(vf));
12050 	c.alloc_to_len16 = cpu_to_be32(F_FW_EQ_OFLD_CMD_FREE | FW_LEN16(c));
12051 	c.eqid_pkd = cpu_to_be32(V_FW_EQ_OFLD_CMD_EQID(eqid));
12052 	return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
12053 }
12054 
12055 /**
12056  *	t4_link_down_rc_str - return a string for a Link Down Reason Code
12057  *	@link_down_rc: Link Down Reason Code
12058  *
12059  *	Returns a string representation of the Link Down Reason Code.
12060  */
t4_link_down_rc_str(unsigned char link_down_rc)12061 const char *t4_link_down_rc_str(unsigned char link_down_rc)
12062 {
12063 	static const char *reason[] = {
12064 		"Link Down",
12065 		"Remote Fault",
12066 		"Auto-negotiation Failure",
12067 		"Reserved3",
12068 		"Insufficient Airflow",
12069 		"Unable To Determine Reason",
12070 		"No RX Signal Detected",
12071 		"Reserved7",
12072 	};
12073 
12074 	if (link_down_rc >= ARRAY_SIZE(reason))
12075 		return "Bad Reason Code";
12076 
12077 	return reason[link_down_rc];
12078 }
12079 
12080 /*
12081  * Return the highest speed set in the port capabilities, in Mb/s.
12082  */
fwcap_to_speed(uint32_t caps)12083 unsigned int fwcap_to_speed(uint32_t caps)
12084 {
12085 	#define TEST_SPEED_RETURN(__caps_speed, __speed) \
12086 		do { \
12087 			if (caps & FW_PORT_CAP32_SPEED_##__caps_speed) \
12088 				return __speed; \
12089 		} while (0)
12090 
12091 	TEST_SPEED_RETURN(400G, 400000);
12092 	TEST_SPEED_RETURN(200G, 200000);
12093 	TEST_SPEED_RETURN(100G, 100000);
12094 	TEST_SPEED_RETURN(50G,   50000);
12095 	TEST_SPEED_RETURN(40G,   40000);
12096 	TEST_SPEED_RETURN(25G,   25000);
12097 	TEST_SPEED_RETURN(10G,   10000);
12098 	TEST_SPEED_RETURN(1G,     1000);
12099 	TEST_SPEED_RETURN(100M,    100);
12100 
12101 	#undef TEST_SPEED_RETURN
12102 
12103 	return 0;
12104 }
12105 
12106 /*
12107  * Return the port capabilities bit for the given speed, which is in Mb/s.
12108  */
speed_to_fwcap(unsigned int speed)12109 uint32_t speed_to_fwcap(unsigned int speed)
12110 {
12111 	#define TEST_SPEED_RETURN(__caps_speed, __speed) \
12112 		do { \
12113 			if (speed == __speed) \
12114 				return FW_PORT_CAP32_SPEED_##__caps_speed; \
12115 		} while (0)
12116 
12117 	TEST_SPEED_RETURN(400G, 400000);
12118 	TEST_SPEED_RETURN(200G, 200000);
12119 	TEST_SPEED_RETURN(100G, 100000);
12120 	TEST_SPEED_RETURN(50G,   50000);
12121 	TEST_SPEED_RETURN(40G,   40000);
12122 	TEST_SPEED_RETURN(25G,   25000);
12123 	TEST_SPEED_RETURN(10G,   10000);
12124 	TEST_SPEED_RETURN(1G,     1000);
12125 	TEST_SPEED_RETURN(100M,    100);
12126 
12127 	#undef TEST_SPEED_RETURN
12128 
12129 	return 0;
12130 }
12131 
12132 /*
12133  * Return the port capabilities bit for the highest speed in the capabilities.
12134  */
fwcap_top_speed(uint32_t caps)12135 uint32_t fwcap_top_speed(uint32_t caps)
12136 {
12137 	#define TEST_SPEED_RETURN(__caps_speed) \
12138 		do { \
12139 			if (caps & FW_PORT_CAP32_SPEED_##__caps_speed) \
12140 				return FW_PORT_CAP32_SPEED_##__caps_speed; \
12141 		} while (0)
12142 
12143 	TEST_SPEED_RETURN(400G);
12144 	TEST_SPEED_RETURN(200G);
12145 	TEST_SPEED_RETURN(100G);
12146 	TEST_SPEED_RETURN(50G);
12147 	TEST_SPEED_RETURN(40G);
12148 	TEST_SPEED_RETURN(25G);
12149 	TEST_SPEED_RETURN(10G);
12150 	TEST_SPEED_RETURN(1G);
12151 	TEST_SPEED_RETURN(100M);
12152 
12153 	#undef TEST_SPEED_RETURN
12154 
12155 	return 0;
12156 }
12157 
12158 /**
12159  *	lstatus_to_fwcap - translate old lstatus to 32-bit Port Capabilities
12160  *	@lstatus: old FW_PORT_ACTION_GET_PORT_INFO lstatus value
12161  *
12162  *	Translates old FW_PORT_ACTION_GET_PORT_INFO lstatus field into new
12163  *	32-bit Port Capabilities value.
12164  */
lstatus_to_fwcap(u32 lstatus)12165 static uint32_t lstatus_to_fwcap(u32 lstatus)
12166 {
12167 	uint32_t linkattr = 0;
12168 
12169 	/*
12170 	 * Unfortunately the format of the Link Status in the old
12171 	 * 16-bit Port Information message isn't the same as the
12172 	 * 16-bit Port Capabilities bitfield used everywhere else ...
12173 	 */
12174 	if (lstatus & F_FW_PORT_CMD_RXPAUSE)
12175 		linkattr |= FW_PORT_CAP32_FC_RX;
12176 	if (lstatus & F_FW_PORT_CMD_TXPAUSE)
12177 		linkattr |= FW_PORT_CAP32_FC_TX;
12178 	if (lstatus & V_FW_PORT_CMD_LSPEED(FW_PORT_CAP_SPEED_100M))
12179 		linkattr |= FW_PORT_CAP32_SPEED_100M;
12180 	if (lstatus & V_FW_PORT_CMD_LSPEED(FW_PORT_CAP_SPEED_1G))
12181 		linkattr |= FW_PORT_CAP32_SPEED_1G;
12182 	if (lstatus & V_FW_PORT_CMD_LSPEED(FW_PORT_CAP_SPEED_10G))
12183 		linkattr |= FW_PORT_CAP32_SPEED_10G;
12184 	if (lstatus & V_FW_PORT_CMD_LSPEED(FW_PORT_CAP_SPEED_25G))
12185 		linkattr |= FW_PORT_CAP32_SPEED_25G;
12186 	if (lstatus & V_FW_PORT_CMD_LSPEED(FW_PORT_CAP_SPEED_40G))
12187 		linkattr |= FW_PORT_CAP32_SPEED_40G;
12188 	if (lstatus & V_FW_PORT_CMD_LSPEED(FW_PORT_CAP_SPEED_100G))
12189 		linkattr |= FW_PORT_CAP32_SPEED_100G;
12190 
12191 	return linkattr;
12192 }
12193 
12194 /*
12195  * Updates all fields owned by the common code in port_info and link_config
12196  * based on information provided by the firmware.  Does not touch any
12197  * requested_* field.
12198  */
handle_port_info(struct port_info * pi,const struct fw_port_cmd * p,enum fw_port_action action,bool * mod_changed,bool * link_changed)12199 static void handle_port_info(struct port_info *pi, const struct fw_port_cmd *p,
12200     enum fw_port_action action, bool *mod_changed, bool *link_changed)
12201 {
12202 	struct link_config old_lc, *lc = &pi->link_cfg;
12203 	unsigned char fc;
12204 	u32 stat, linkattr;
12205 	int old_ptype, old_mtype;
12206 
12207 	old_ptype = pi->port_type;
12208 	old_mtype = pi->mod_type;
12209 	old_lc = *lc;
12210 	if (action == FW_PORT_ACTION_GET_PORT_INFO) {
12211 		stat = be32_to_cpu(p->u.info.lstatus_to_modtype);
12212 
12213 		pi->port_type = G_FW_PORT_CMD_PTYPE(stat);
12214 		pi->mod_type = G_FW_PORT_CMD_MODTYPE(stat);
12215 		pi->mdio_addr = stat & F_FW_PORT_CMD_MDIOCAP ?
12216 		    G_FW_PORT_CMD_MDIOADDR(stat) : -1;
12217 
12218 		lc->pcaps = fwcaps16_to_caps32(be16_to_cpu(p->u.info.pcap));
12219 		lc->acaps = fwcaps16_to_caps32(be16_to_cpu(p->u.info.acap));
12220 		lc->lpacaps = fwcaps16_to_caps32(be16_to_cpu(p->u.info.lpacap));
12221 		lc->link_ok = (stat & F_FW_PORT_CMD_LSTATUS) != 0;
12222 		lc->link_down_rc = G_FW_PORT_CMD_LINKDNRC(stat);
12223 
12224 		linkattr = lstatus_to_fwcap(stat);
12225 	} else if (action == FW_PORT_ACTION_GET_PORT_INFO32) {
12226 		stat = be32_to_cpu(p->u.info32.lstatus32_to_cbllen32);
12227 
12228 		pi->port_type = G_FW_PORT_CMD_PORTTYPE32(stat);
12229 		pi->mod_type = G_FW_PORT_CMD_MODTYPE32(stat);
12230 		pi->mdio_addr = stat & F_FW_PORT_CMD_MDIOCAP32 ?
12231 		    G_FW_PORT_CMD_MDIOADDR32(stat) : -1;
12232 
12233 		lc->pcaps = be32_to_cpu(p->u.info32.pcaps32);
12234 		lc->acaps = be32_to_cpu(p->u.info32.acaps32);
12235 		lc->lpacaps = be32_to_cpu(p->u.info32.lpacaps32);
12236 		lc->link_ok = (stat & F_FW_PORT_CMD_LSTATUS32) != 0;
12237 		lc->link_down_rc = G_FW_PORT_CMD_LINKDNRC32(stat);
12238 
12239 		linkattr = be32_to_cpu(p->u.info32.linkattr32);
12240 	} else {
12241 		CH_ERR(pi->adapter, "bad port_info action 0x%x\n", action);
12242 		return;
12243 	}
12244 
12245 	lc->speed = fwcap_to_speed(linkattr);
12246 	lc->fec = fwcap_to_fec(linkattr, true);
12247 
12248 	fc = 0;
12249 	if (linkattr & FW_PORT_CAP32_FC_RX)
12250 		fc |= PAUSE_RX;
12251 	if (linkattr & FW_PORT_CAP32_FC_TX)
12252 		fc |= PAUSE_TX;
12253 	lc->fc = fc;
12254 
12255 	if (mod_changed != NULL)
12256 		*mod_changed = false;
12257 	if (link_changed != NULL)
12258 		*link_changed = false;
12259 	if (old_ptype != pi->port_type || old_mtype != pi->mod_type ||
12260 	    old_lc.pcaps != lc->pcaps) {
12261 		if (pi->mod_type != FW_PORT_MOD_TYPE_NONE)
12262 			lc->fec_hint = fwcap_to_fec(lc->acaps, true);
12263 		if (mod_changed != NULL)
12264 			*mod_changed = true;
12265 	}
12266 	if (old_lc.link_ok != lc->link_ok || old_lc.speed != lc->speed ||
12267 	    old_lc.fec != lc->fec || old_lc.fc != lc->fc) {
12268 		if (link_changed != NULL)
12269 			*link_changed = true;
12270 	}
12271 }
12272 
12273 /**
12274  *	t4_update_port_info - retrieve and update port information if changed
12275  *	@pi: the port_info
12276  *
12277  *	We issue a Get Port Information Command to the Firmware and, if
12278  *	successful, we check to see if anything is different from what we
12279  *	last recorded and update things accordingly.
12280  */
t4_update_port_info(struct port_info * pi)12281  int t4_update_port_info(struct port_info *pi)
12282  {
12283 	struct adapter *sc = pi->adapter;
12284 	struct fw_port_cmd cmd;
12285 	enum fw_port_action action;
12286 	int ret;
12287 
12288 	memset(&cmd, 0, sizeof(cmd));
12289 	cmd.op_to_portid = cpu_to_be32(V_FW_CMD_OP(FW_PORT_CMD) |
12290 	    F_FW_CMD_REQUEST | F_FW_CMD_READ |
12291 	    V_FW_PORT_CMD_PORTID(pi->hw_port));
12292 	action = sc->params.port_caps32 ? FW_PORT_ACTION_GET_PORT_INFO32 :
12293 	    FW_PORT_ACTION_GET_PORT_INFO;
12294 	cmd.action_to_len16 = cpu_to_be32(V_FW_PORT_CMD_ACTION(action) |
12295 	    FW_LEN16(cmd));
12296 	ret = t4_wr_mbox_ns(sc, sc->mbox, &cmd, sizeof(cmd), &cmd);
12297 	if (ret)
12298 		return ret;
12299 
12300 	handle_port_info(pi, &cmd, action, NULL, NULL);
12301 	return 0;
12302 }
12303 
12304 /**
12305  *	t4_handle_fw_rpl - process a FW reply message
12306  *	@adap: the adapter
12307  *	@rpl: start of the FW message
12308  *
12309  *	Processes a FW message, such as link state change messages.
12310  */
t4_handle_fw_rpl(struct adapter * adap,const __be64 * rpl)12311 int t4_handle_fw_rpl(struct adapter *adap, const __be64 *rpl)
12312 {
12313 	u8 opcode = *(const u8 *)rpl;
12314 	const struct fw_port_cmd *p = (const void *)rpl;
12315 	enum fw_port_action action =
12316 	    G_FW_PORT_CMD_ACTION(be32_to_cpu(p->action_to_len16));
12317 	bool mod_changed, link_changed;
12318 
12319 	if (opcode == FW_PORT_CMD &&
12320 	    (action == FW_PORT_ACTION_GET_PORT_INFO ||
12321 	    action == FW_PORT_ACTION_GET_PORT_INFO32)) {
12322 		/* link/module state change message */
12323 		int hw_port = G_FW_PORT_CMD_PORTID(be32_to_cpu(p->op_to_portid));
12324 		int port_id = adap->port_map[hw_port];
12325 		struct port_info *pi;
12326 
12327 		MPASS(port_id >= 0 && port_id < adap->params.nports);
12328 		pi = adap->port[port_id];
12329 		PORT_LOCK(pi);
12330 		handle_port_info(pi, p, action, &mod_changed, &link_changed);
12331 		PORT_UNLOCK(pi);
12332 		if (mod_changed)
12333 			t4_os_portmod_changed(pi);
12334 		if (link_changed) {
12335 			PORT_LOCK(pi);
12336 			t4_os_link_changed(pi);
12337 			PORT_UNLOCK(pi);
12338 		}
12339 	} else {
12340 		CH_WARN_RATELIMIT(adap, "Unknown firmware reply %d\n", opcode);
12341 		return -EINVAL;
12342 	}
12343 	return 0;
12344 }
12345 
12346 /**
12347  *	get_pci_mode - determine a card's PCI mode
12348  *	@adapter: the adapter
12349  *	@p: where to store the PCI settings
12350  *
12351  *	Determines a card's PCI mode and associated parameters, such as speed
12352  *	and width.
12353  */
get_pci_mode(struct adapter * adapter,struct pci_params * p)12354 static void get_pci_mode(struct adapter *adapter,
12355 				   struct pci_params *p)
12356 {
12357 	u16 val;
12358 	u32 pcie_cap;
12359 
12360 	pcie_cap = t4_os_find_pci_capability(adapter, PCI_CAP_ID_EXP);
12361 	if (pcie_cap) {
12362 		t4_os_pci_read_cfg2(adapter, pcie_cap + PCI_EXP_LNKSTA, &val);
12363 		p->speed = val & PCI_EXP_LNKSTA_CLS;
12364 		p->width = (val & PCI_EXP_LNKSTA_NLW) >> 4;
12365 	}
12366 }
12367 
12368 struct flash_desc {
12369 	u32 vendor_and_model_id;
12370 	u32 size_mb;
12371 };
12372 
t4_get_flash_params(struct adapter * adapter)12373 int t4_get_flash_params(struct adapter *adapter)
12374 {
12375 	/*
12376 	 * Table for non-standard supported Flash parts.  Note, all Flash
12377 	 * parts must have 64KB sectors.
12378 	 */
12379 	static struct flash_desc supported_flash[] = {
12380 		{ 0x00150201, 4 << 20 },	/* Spansion 4MB S25FL032P */
12381 	};
12382 
12383 	int ret;
12384 	u32 flashid = 0;
12385 	unsigned int part, manufacturer;
12386 	unsigned int density, size = 0;
12387 
12388 
12389 	/*
12390 	 * Issue a Read ID Command to the Flash part.  We decode supported
12391 	 * Flash parts and their sizes from this.  There's a newer Query
12392 	 * Command which can retrieve detailed geometry information but many
12393 	 * Flash parts don't support it.
12394 	 */
12395 	ret = sf1_write(adapter, 1, 1, 0, SF_RD_ID);
12396 	if (!ret)
12397 		ret = sf1_read(adapter, 3, 0, 1, &flashid);
12398 	t4_write_reg(adapter, A_SF_OP, 0);	/* unlock SF */
12399 	if (ret < 0)
12400 		return ret;
12401 
12402 	/*
12403 	 * Check to see if it's one of our non-standard supported Flash parts.
12404 	 */
12405 	for (part = 0; part < ARRAY_SIZE(supported_flash); part++)
12406 		if (supported_flash[part].vendor_and_model_id == flashid) {
12407 			adapter->params.sf_size =
12408 				supported_flash[part].size_mb;
12409 			adapter->params.sf_nsec =
12410 				adapter->params.sf_size / SF_SEC_SIZE;
12411 			goto found;
12412 		}
12413 
12414 	/*
12415 	 * Decode Flash part size.  The code below looks repetative with
12416 	 * common encodings, but that's not guaranteed in the JEDEC
12417 	 * specification for the Read JADEC ID command.  The only thing that
12418 	 * we're guaranteed by the JADEC specification is where the
12419 	 * Manufacturer ID is in the returned result.  After that each
12420 	 * Manufacturer ~could~ encode things completely differently.
12421 	 * Note, all Flash parts must have 64KB sectors.
12422 	 */
12423 	manufacturer = flashid & 0xff;
12424 	switch (manufacturer) {
12425 	case 0x20: /* Micron/Numonix */
12426 		/*
12427 		 * This Density -> Size decoding table is taken from Micron
12428 		 * Data Sheets.
12429 		 */
12430 		density = (flashid >> 16) & 0xff;
12431 		switch (density) {
12432 		case 0x14: size = 1 << 20; break; /*   1MB */
12433 		case 0x15: size = 1 << 21; break; /*   2MB */
12434 		case 0x16: size = 1 << 22; break; /*   4MB */
12435 		case 0x17: size = 1 << 23; break; /*   8MB */
12436 		case 0x18: size = 1 << 24; break; /*  16MB */
12437 		case 0x19: size = 1 << 25; break; /*  32MB */
12438 		case 0x20: size = 1 << 26; break; /*  64MB */
12439 		case 0x21: size = 1 << 27; break; /* 128MB */
12440 		case 0x22: size = 1 << 28; break; /* 256MB */
12441 		}
12442 		break;
12443 
12444 	case 0x9d: /* ISSI -- Integrated Silicon Solution, Inc. */
12445 		/*
12446 		 * This Density -> Size decoding table is taken from ISSI
12447 		 * Data Sheets.
12448 		 */
12449 		density = (flashid >> 16) & 0xff;
12450 		switch (density) {
12451 		case 0x16: size = 1 << 25; break; /*  32MB */
12452 		case 0x17: size = 1 << 26; break; /*  64MB */
12453 		}
12454 		break;
12455 
12456 	case 0xc2: /* Macronix */
12457 		/*
12458 		 * This Density -> Size decoding table is taken from Macronix
12459 		 * Data Sheets.
12460 		 */
12461 		density = (flashid >> 16) & 0xff;
12462 		switch (density) {
12463 		case 0x17: size = 1 << 23; break; /*   8MB */
12464 		case 0x18: size = 1 << 24; break; /*  16MB */
12465 		}
12466 		break;
12467 
12468 	case 0xef: /* Winbond */
12469 		/*
12470 		 * This Density -> Size decoding table is taken from Winbond
12471 		 * Data Sheets.
12472 		 */
12473 		density = (flashid >> 16) & 0xff;
12474 		switch (density) {
12475 		case 0x17: size = 1 << 23; break; /*   8MB */
12476 		case 0x18: size = 1 << 24; break; /*  16MB */
12477 		}
12478 		break;
12479 	}
12480 
12481 	/* If we didn't recognize the FLASH part, that's no real issue: the
12482 	 * Hardware/Software contract says that Hardware will _*ALWAYS*_ use a
12483 	 * FLASH part which has 64KB sectors and is at least 4MB or 16MB in
12484 	 * size, depending on the board.
12485 	 */
12486 	if (size == 0) {
12487 		size = chip_id(adapter) >= CHELSIO_T7 ? 16 : 4;
12488 		CH_WARN(adapter, "Unknown Flash Part %#x, assuming %uMB\n",
12489 		    flashid, size);
12490 		size <<= 20;
12491 	}
12492 
12493 	/*
12494 	 * Store decoded Flash size and fall through into vetting code.
12495 	 */
12496 	adapter->params.sf_size = size;
12497 	adapter->params.sf_nsec = size / SF_SEC_SIZE;
12498 
12499  found:
12500 	/*
12501 	 * We should ~probably~ reject adapters with FLASHes which are too
12502 	 * small but we have some legacy FPGAs with small FLASHes that we'd
12503 	 * still like to use.  So instead we emit a scary message ...
12504 	 */
12505 	if (adapter->params.sf_size < FLASH_MIN_SIZE)
12506 		CH_WARN(adapter, "WARNING: Flash Part ID %#x, size %#x < %#x\n",
12507 			flashid, adapter->params.sf_size, FLASH_MIN_SIZE);
12508 
12509 	return 0;
12510 }
12511 
set_pcie_completion_timeout(struct adapter * adapter,u8 range)12512 static void set_pcie_completion_timeout(struct adapter *adapter,
12513 						  u8 range)
12514 {
12515 	u16 val;
12516 	u32 pcie_cap;
12517 
12518 	pcie_cap = t4_os_find_pci_capability(adapter, PCI_CAP_ID_EXP);
12519 	if (pcie_cap) {
12520 		t4_os_pci_read_cfg2(adapter, pcie_cap + PCI_EXP_DEVCTL2, &val);
12521 		val &= 0xfff0;
12522 		val |= range ;
12523 		t4_os_pci_write_cfg2(adapter, pcie_cap + PCI_EXP_DEVCTL2, val);
12524 	}
12525 }
12526 
t4_get_chip_params(int chipid)12527 const struct chip_params *t4_get_chip_params(int chipid)
12528 {
12529 	static const struct chip_params chip_params[] = {
12530 		{
12531 			/* T4 */
12532 			.nchan = NCHAN,
12533 			.pm_stats_cnt = PM_NSTATS,
12534 			.cng_ch_bits_log = 2,
12535 			.nsched_cls = 15,
12536 			.cim_num_ibq = CIM_NUM_IBQ,
12537 			.cim_num_obq = CIM_NUM_OBQ,
12538 			.filter_opt_len = FILTER_OPT_LEN,
12539 			.filter_num_opt = S_FT_LAST + 1,
12540 			.mps_rplc_size = 128,
12541 			.vfcount = 128,
12542 			.sge_fl_db = F_DBPRIO,
12543 			.sge_ctxt_size = SGE_CTXT_SIZE,
12544 			.mps_tcam_size = NUM_MPS_CLS_SRAM_L_INSTANCES,
12545 			.rss_nentries = RSS_NENTRIES,
12546 			.cim_la_size = CIMLA_SIZE,
12547 		},
12548 		{
12549 			/* T5 */
12550 			.nchan = NCHAN,
12551 			.pm_stats_cnt = PM_NSTATS,
12552 			.cng_ch_bits_log = 2,
12553 			.nsched_cls = 16,
12554 			.cim_num_ibq = CIM_NUM_IBQ,
12555 			.cim_num_obq = CIM_NUM_OBQ_T5,
12556 			.filter_opt_len = T5_FILTER_OPT_LEN,
12557 			.filter_num_opt = S_FT_LAST + 1,
12558 			.mps_rplc_size = 128,
12559 			.vfcount = 128,
12560 			.sge_fl_db = F_DBPRIO | F_DBTYPE,
12561 			.sge_ctxt_size = SGE_CTXT_SIZE,
12562 			.mps_tcam_size = NUM_MPS_T5_CLS_SRAM_L_INSTANCES,
12563 			.rss_nentries = RSS_NENTRIES,
12564 			.cim_la_size = CIMLA_SIZE,
12565 		},
12566 		{
12567 			/* T6 */
12568 			.nchan = T6_NCHAN,
12569 			.pm_stats_cnt = T6_PM_NSTATS,
12570 			.cng_ch_bits_log = 3,
12571 			.nsched_cls = 16,
12572 			.cim_num_ibq = CIM_NUM_IBQ,
12573 			.cim_num_obq = CIM_NUM_OBQ_T5,
12574 			.filter_opt_len = T5_FILTER_OPT_LEN,
12575 			.filter_num_opt = S_FT_LAST + 1,
12576 			.mps_rplc_size = 256,
12577 			.vfcount = 256,
12578 			.sge_fl_db = 0,
12579 			.sge_ctxt_size = SGE_CTXT_SIZE,
12580 			.mps_tcam_size = NUM_MPS_T5_CLS_SRAM_L_INSTANCES,
12581 			.rss_nentries = T6_RSS_NENTRIES,
12582 			.cim_la_size = CIMLA_SIZE_T6,
12583 		},
12584 		{
12585 			/* T7 */
12586 			.nchan = NCHAN,
12587 			.pm_stats_cnt = T6_PM_NSTATS,
12588 			.cng_ch_bits_log = 2,
12589 			.nsched_cls = 16,
12590 			.cim_num_ibq = CIM_NUM_IBQ_T7,
12591 			.cim_num_obq = CIM_NUM_OBQ_T7,
12592 			.filter_opt_len = T7_FILTER_OPT_LEN,
12593 			.filter_num_opt = S_T7_FT_LAST + 1,
12594 			.mps_rplc_size = 256,
12595 			.vfcount = 256,
12596 			.sge_fl_db = 0,
12597 			.sge_ctxt_size = SGE_CTXT_SIZE_T7,
12598 			.mps_tcam_size = NUM_MPS_T5_CLS_SRAM_L_INSTANCES * 3,
12599 			.rss_nentries = T7_RSS_NENTRIES,
12600 			.cim_la_size = CIMLA_SIZE_T6,
12601 		},
12602 	};
12603 
12604 	chipid -= CHELSIO_T4;
12605 	if (chipid < 0 || chipid >= ARRAY_SIZE(chip_params))
12606 		return NULL;
12607 
12608 	return &chip_params[chipid];
12609 }
12610 
12611 /**
12612  *	t4_prep_adapter - prepare SW and HW for operation
12613  *	@adapter: the adapter
12614  *	@buf: temporary space of at least VPD_LEN size provided by the caller.
12615  *
12616  *	Initialize adapter SW state for the various HW modules, set initial
12617  *	values for some adapter tunables, take PHYs out of reset, and
12618  *	initialize the MDIO interface.
12619  */
t4_prep_adapter(struct adapter * adapter,u32 * buf)12620 int t4_prep_adapter(struct adapter *adapter, u32 *buf)
12621 {
12622 	int ret;
12623 	uint16_t device_id;
12624 	uint32_t pl_rev;
12625 
12626 	get_pci_mode(adapter, &adapter->params.pci);
12627 
12628 	pl_rev = t4_read_reg(adapter, A_PL_REV);
12629 	adapter->params.chipid = G_CHIPID(pl_rev);
12630 	adapter->params.rev = G_REV(pl_rev);
12631 	if (adapter->params.chipid == 0) {
12632 		/* T4 did not have chipid in PL_REV (T5 onwards do) */
12633 		adapter->params.chipid = CHELSIO_T4;
12634 
12635 		/* T4A1 chip is not supported */
12636 		if (adapter->params.rev == 1) {
12637 			CH_ALERT(adapter, "T4 rev 1 chip is not supported.\n");
12638 			return -EINVAL;
12639 		}
12640 	}
12641 
12642 	adapter->chip_params = t4_get_chip_params(chip_id(adapter));
12643 	if (adapter->chip_params == NULL)
12644 		return -EINVAL;
12645 
12646 	adapter->params.pci.vpd_cap_addr =
12647 	    t4_os_find_pci_capability(adapter, PCI_CAP_ID_VPD);
12648 
12649 	ret = t4_get_flash_params(adapter);
12650 	if (ret < 0)
12651 		return ret;
12652 
12653 	/* Cards with real ASICs have the chipid in the PCIe device id */
12654 	t4_os_pci_read_cfg2(adapter, PCI_DEVICE_ID, &device_id);
12655 	if (device_id >> 12 == chip_id(adapter))
12656 		adapter->params.cim_la_size = adapter->chip_params->cim_la_size;
12657 	else {
12658 		/* FPGA */
12659 		adapter->params.fpga = 1;
12660 		adapter->params.cim_la_size = 2 * adapter->chip_params->cim_la_size;
12661 	}
12662 
12663 	ret = get_vpd_params(adapter, &adapter->params.vpd, device_id, buf);
12664 	if (ret < 0)
12665 		return ret;
12666 
12667 	init_cong_ctrl(adapter->params.a_wnd, adapter->params.b_wnd);
12668 
12669 	/*
12670 	 * Default port and clock for debugging in case we can't reach FW.
12671 	 */
12672 	adapter->params.nports = 1;
12673 	adapter->params.portvec = 1;
12674 	adapter->params.vpd.cclk = 50000;
12675 
12676 	/* Set pci completion timeout value to 4 seconds. */
12677 	set_pcie_completion_timeout(adapter, 0xd);
12678 	return 0;
12679 }
12680 
12681 /**
12682  *	t4_shutdown_adapter - shut down adapter, host & wire
12683  *	@adapter: the adapter
12684  *
12685  *	Perform an emergency shutdown of the adapter and stop it from
12686  *	continuing any further communication on the ports or DMA to the
12687  *	host.  This is typically used when the adapter and/or firmware
12688  *	have crashed and we want to prevent any further accidental
12689  *	communication with the rest of the world.  This will also force
12690  *	the port Link Status to go down -- if register writes work --
12691  *	which should help our peers figure out that we're down.
12692  */
t4_shutdown_adapter(struct adapter * adapter)12693 int t4_shutdown_adapter(struct adapter *adapter)
12694 {
12695 	int port;
12696 	const bool bt = adapter->bt_map != 0;
12697 
12698 	t4_intr_disable(adapter);
12699 	if (bt)
12700 		t4_write_reg(adapter, A_DBG_GPIO_EN, 0xffff0000);
12701 	for_each_port(adapter, port) {
12702 		u32 a_port_cfg = is_t4(adapter) ?
12703 		    t4_port_reg(adapter, port, A_XGMAC_PORT_CFG) :
12704 		    t4_port_reg(adapter, port, A_MAC_PORT_CFG);
12705 
12706 		t4_write_reg(adapter, a_port_cfg,
12707 			     t4_read_reg(adapter, a_port_cfg)
12708 			     & ~V_SIGNAL_DET(1));
12709 		if (!bt) {
12710 			u32 hss_cfg0 = is_t4(adapter) ?
12711 			    t4_port_reg(adapter, port, A_XGMAC_PORT_HSS_CFG0) :
12712 			    t4_port_reg(adapter, port, A_MAC_PORT_HSS_CFG0);
12713 			t4_set_reg_field(adapter, hss_cfg0, F_HSSPDWNPLLB |
12714 			    F_HSSPDWNPLLA | F_HSSPLLBYPB | F_HSSPLLBYPA,
12715 			    F_HSSPDWNPLLB | F_HSSPDWNPLLA | F_HSSPLLBYPB |
12716 			    F_HSSPLLBYPA);
12717 		}
12718 	}
12719 	t4_set_reg_field(adapter, A_SGE_CONTROL, F_GLOBALENABLE, 0);
12720 
12721 	return 0;
12722 }
12723 
12724 /**
12725  *	t4_bar2_sge_qregs - return BAR2 SGE Queue register information
12726  *	@adapter: the adapter
12727  *	@qid: the Queue ID
12728  *	@qtype: the Ingress or Egress type for @qid
12729  *	@user: true if this request is for a user mode queue
12730  *	@pbar2_qoffset: BAR2 Queue Offset
12731  *	@pbar2_qid: BAR2 Queue ID or 0 for Queue ID inferred SGE Queues
12732  *
12733  *	Returns the BAR2 SGE Queue Registers information associated with the
12734  *	indicated Absolute Queue ID.  These are passed back in return value
12735  *	pointers.  @qtype should be T4_BAR2_QTYPE_EGRESS for Egress Queue
12736  *	and T4_BAR2_QTYPE_INGRESS for Ingress Queues.
12737  *
12738  *	This may return an error which indicates that BAR2 SGE Queue
12739  *	registers aren't available.  If an error is not returned, then the
12740  *	following values are returned:
12741  *
12742  *	  *@pbar2_qoffset: the BAR2 Offset of the @qid Registers
12743  *	  *@pbar2_qid: the BAR2 SGE Queue ID or 0 of @qid
12744  *
12745  *	If the returned BAR2 Queue ID is 0, then BAR2 SGE registers which
12746  *	require the "Inferred Queue ID" ability may be used.  E.g. the
12747  *	Write Combining Doorbell Buffer. If the BAR2 Queue ID is not 0,
12748  *	then these "Inferred Queue ID" register may not be used.
12749  */
t4_bar2_sge_qregs(struct adapter * adapter,unsigned int qid,enum t4_bar2_qtype qtype,int user,u64 * pbar2_qoffset,unsigned int * pbar2_qid)12750 int t4_bar2_sge_qregs(struct adapter *adapter,
12751 		      unsigned int qid,
12752 		      enum t4_bar2_qtype qtype,
12753 		      int user,
12754 		      u64 *pbar2_qoffset,
12755 		      unsigned int *pbar2_qid)
12756 {
12757 	unsigned int page_shift, page_size, qpp_shift, qpp_mask;
12758 	u64 bar2_page_offset, bar2_qoffset;
12759 	unsigned int bar2_qid, bar2_qid_offset, bar2_qinferred;
12760 
12761 	/* T4 doesn't support BAR2 SGE Queue registers for kernel
12762 	 * mode queues.
12763 	 */
12764 	if (!user && is_t4(adapter))
12765 		return -EINVAL;
12766 
12767 	/* Get our SGE Page Size parameters.
12768 	 */
12769 	page_shift = adapter->params.sge.page_shift;
12770 	page_size = 1 << page_shift;
12771 
12772 	/* Get the right Queues per Page parameters for our Queue.
12773 	 */
12774 	qpp_shift = (qtype == T4_BAR2_QTYPE_EGRESS
12775 		     ? adapter->params.sge.eq_s_qpp
12776 		     : adapter->params.sge.iq_s_qpp);
12777 	qpp_mask = (1 << qpp_shift) - 1;
12778 
12779 	/* Calculate the basics of the BAR2 SGE Queue register area:
12780 	 *  o The BAR2 page the Queue registers will be in.
12781 	 *  o The BAR2 Queue ID.
12782 	 *  o The BAR2 Queue ID Offset into the BAR2 page.
12783 	 */
12784 	bar2_page_offset = ((u64)(qid >> qpp_shift) << page_shift);
12785 	bar2_qid = qid & qpp_mask;
12786 	bar2_qid_offset = bar2_qid * SGE_UDB_SIZE;
12787 
12788 	/* If the BAR2 Queue ID Offset is less than the Page Size, then the
12789 	 * hardware will infer the Absolute Queue ID simply from the writes to
12790 	 * the BAR2 Queue ID Offset within the BAR2 Page (and we need to use a
12791 	 * BAR2 Queue ID of 0 for those writes).  Otherwise, we'll simply
12792 	 * write to the first BAR2 SGE Queue Area within the BAR2 Page with
12793 	 * the BAR2 Queue ID and the hardware will infer the Absolute Queue ID
12794 	 * from the BAR2 Page and BAR2 Queue ID.
12795 	 *
12796 	 * One important censequence of this is that some BAR2 SGE registers
12797 	 * have a "Queue ID" field and we can write the BAR2 SGE Queue ID
12798 	 * there.  But other registers synthesize the SGE Queue ID purely
12799 	 * from the writes to the registers -- the Write Combined Doorbell
12800 	 * Buffer is a good example.  These BAR2 SGE Registers are only
12801 	 * available for those BAR2 SGE Register areas where the SGE Absolute
12802 	 * Queue ID can be inferred from simple writes.
12803 	 */
12804 	bar2_qoffset = bar2_page_offset;
12805 	bar2_qinferred = (bar2_qid_offset < page_size);
12806 	if (bar2_qinferred) {
12807 		bar2_qoffset += bar2_qid_offset;
12808 		bar2_qid = 0;
12809 	}
12810 
12811 	*pbar2_qoffset = bar2_qoffset;
12812 	*pbar2_qid = bar2_qid;
12813 	return 0;
12814 }
12815 
12816 /**
12817  *	t4_init_devlog_ncores_params - initialize adap->params.devlog and ncores
12818  *	@adap: the adapter
12819  *	@fw_attach: whether we can talk to the firmware
12820  */
t4_init_devlog_ncores_params(struct adapter * adap,int fw_attach)12821 int t4_init_devlog_ncores_params(struct adapter *adap, int fw_attach)
12822 {
12823 	struct devlog_params *dparams = &adap->params.devlog;
12824 	u32 pf_dparams;
12825 	unsigned int devlog_meminfo;
12826 	struct fw_devlog_cmd devlog_cmd;
12827 	int ret;
12828 
12829 	/* If we're dealing with newer firmware, the Device Log Paramerters
12830 	 * are stored in a designated register which allows us to access the
12831 	 * Device Log even if we can't talk to the firmware.
12832 	 */
12833 	pf_dparams =
12834 		t4_read_reg(adap, PCIE_FW_REG(A_PCIE_FW_PF, PCIE_FW_PF_DEVLOG));
12835 	if (pf_dparams && pf_dparams != UINT32_MAX) {
12836 		unsigned int nentries, nentries128, ncore_shift;
12837 
12838 		ncore_shift = (G_PCIE_FW_PF_DEVLOG_COUNT_MSB(pf_dparams) << 1) |
12839 		    G_PCIE_FW_PF_DEVLOG_COUNT_LSB(pf_dparams);
12840 		adap->params.ncores = 1 << ncore_shift;
12841 
12842 		dparams->memtype = G_PCIE_FW_PF_DEVLOG_MEMTYPE(pf_dparams);
12843 		dparams->start = G_PCIE_FW_PF_DEVLOG_ADDR16(pf_dparams) << 4;
12844 		nentries128 = G_PCIE_FW_PF_DEVLOG_NENTRIES128(pf_dparams);
12845 		nentries = (nentries128 + 1) * 128;
12846 		dparams->size = nentries * sizeof(struct fw_devlog_e);
12847 
12848 		return 0;
12849 	}
12850 
12851 	/*
12852 	 * For any failing returns ...
12853 	 */
12854 	adap->params.ncores = 1;
12855 	memset(dparams, 0, sizeof *dparams);
12856 
12857 	/*
12858 	 * If we can't talk to the firmware, there's really nothing we can do
12859 	 * at this point.
12860 	 */
12861 	if (!fw_attach)
12862 		return -ENXIO;
12863 
12864 	/* Otherwise, ask the firmware for it's Device Log Parameters.
12865 	 */
12866 	memset(&devlog_cmd, 0, sizeof devlog_cmd);
12867 	devlog_cmd.op_to_write = cpu_to_be32(V_FW_CMD_OP(FW_DEVLOG_CMD) |
12868 					     F_FW_CMD_REQUEST | F_FW_CMD_READ);
12869 	devlog_cmd.retval_len16 = cpu_to_be32(FW_LEN16(devlog_cmd));
12870 	ret = t4_wr_mbox(adap, adap->mbox, &devlog_cmd, sizeof(devlog_cmd),
12871 			 &devlog_cmd);
12872 	if (ret)
12873 		return ret;
12874 
12875 	devlog_meminfo =
12876 		be32_to_cpu(devlog_cmd.memtype_devlog_memaddr16_devlog);
12877 	dparams->memtype = G_FW_DEVLOG_CMD_MEMTYPE_DEVLOG(devlog_meminfo);
12878 	dparams->start = G_FW_DEVLOG_CMD_MEMADDR16_DEVLOG(devlog_meminfo) << 4;
12879 	dparams->size = be32_to_cpu(devlog_cmd.memsize_devlog);
12880 
12881 	return 0;
12882 }
12883 
12884 /**
12885  *	t4_init_sge_params - initialize adap->params.sge
12886  *	@adapter: the adapter
12887  *
12888  *	Initialize various fields of the adapter's SGE Parameters structure.
12889  */
t4_init_sge_params(struct adapter * adapter)12890 int t4_init_sge_params(struct adapter *adapter)
12891 {
12892 	u32 r;
12893 	struct sge_params *sp = &adapter->params.sge;
12894 	unsigned i, tscale = 1;
12895 
12896 	r = t4_read_reg(adapter, A_SGE_INGRESS_RX_THRESHOLD);
12897 	sp->counter_val[0] = G_THRESHOLD_0(r);
12898 	sp->counter_val[1] = G_THRESHOLD_1(r);
12899 	sp->counter_val[2] = G_THRESHOLD_2(r);
12900 	sp->counter_val[3] = G_THRESHOLD_3(r);
12901 
12902 	if (chip_id(adapter) >= CHELSIO_T6) {
12903 		r = t4_read_reg(adapter, A_SGE_ITP_CONTROL);
12904 		tscale = G_TSCALE(r);
12905 		if (tscale == 0)
12906 			tscale = 1;
12907 		else
12908 			tscale += 2;
12909 	}
12910 
12911 	r = t4_read_reg(adapter, A_SGE_TIMER_VALUE_0_AND_1);
12912 	sp->timer_val[0] = core_ticks_to_us(adapter, G_TIMERVALUE0(r)) * tscale;
12913 	sp->timer_val[1] = core_ticks_to_us(adapter, G_TIMERVALUE1(r)) * tscale;
12914 	r = t4_read_reg(adapter, A_SGE_TIMER_VALUE_2_AND_3);
12915 	sp->timer_val[2] = core_ticks_to_us(adapter, G_TIMERVALUE2(r)) * tscale;
12916 	sp->timer_val[3] = core_ticks_to_us(adapter, G_TIMERVALUE3(r)) * tscale;
12917 	r = t4_read_reg(adapter, A_SGE_TIMER_VALUE_4_AND_5);
12918 	sp->timer_val[4] = core_ticks_to_us(adapter, G_TIMERVALUE4(r)) * tscale;
12919 	sp->timer_val[5] = core_ticks_to_us(adapter, G_TIMERVALUE5(r)) * tscale;
12920 
12921 	r = t4_read_reg(adapter, A_SGE_CONM_CTRL);
12922 	sp->fl_starve_threshold = G_EGRTHRESHOLD(r) * 2 + 1;
12923 	if (is_t4(adapter))
12924 		sp->fl_starve_threshold2 = sp->fl_starve_threshold;
12925 	else if (is_t5(adapter))
12926 		sp->fl_starve_threshold2 = G_EGRTHRESHOLDPACKING(r) * 2 + 1;
12927 	else
12928 		sp->fl_starve_threshold2 = G_T6_EGRTHRESHOLDPACKING(r) * 2 + 1;
12929 
12930 	/* egress queues: log2 of # of doorbells per BAR2 page */
12931 	r = t4_read_reg(adapter, A_SGE_EGRESS_QUEUES_PER_PAGE_PF);
12932 	r >>= S_QUEUESPERPAGEPF0 +
12933 	    (S_QUEUESPERPAGEPF1 - S_QUEUESPERPAGEPF0) * adapter->pf;
12934 	sp->eq_s_qpp = r & M_QUEUESPERPAGEPF0;
12935 
12936 	/* ingress queues: log2 of # of doorbells per BAR2 page */
12937 	r = t4_read_reg(adapter, A_SGE_INGRESS_QUEUES_PER_PAGE_PF);
12938 	r >>= S_QUEUESPERPAGEPF0 +
12939 	    (S_QUEUESPERPAGEPF1 - S_QUEUESPERPAGEPF0) * adapter->pf;
12940 	sp->iq_s_qpp = r & M_QUEUESPERPAGEPF0;
12941 
12942 	r = t4_read_reg(adapter, A_SGE_HOST_PAGE_SIZE);
12943 	r >>= S_HOSTPAGESIZEPF0 +
12944 	    (S_HOSTPAGESIZEPF1 - S_HOSTPAGESIZEPF0) * adapter->pf;
12945 	sp->page_shift = (r & M_HOSTPAGESIZEPF0) + 10;
12946 
12947 	r = t4_read_reg(adapter, A_SGE_CONTROL);
12948 	sp->sge_control = r;
12949 	sp->spg_len = r & F_EGRSTATUSPAGESIZE ? 128 : 64;
12950 	sp->fl_pktshift = G_PKTSHIFT(r);
12951 	if (chip_id(adapter) <= CHELSIO_T5) {
12952 		sp->pad_boundary = 1 << (G_INGPADBOUNDARY(r) +
12953 		    X_INGPADBOUNDARY_SHIFT);
12954 	} else {
12955 		sp->pad_boundary = 1 << (G_INGPADBOUNDARY(r) +
12956 		    X_T6_INGPADBOUNDARY_SHIFT);
12957 	}
12958 	if (is_t4(adapter))
12959 		sp->pack_boundary = sp->pad_boundary;
12960 	else {
12961 		r = t4_read_reg(adapter, A_SGE_CONTROL2);
12962 		if (G_INGPACKBOUNDARY(r) == 0)
12963 			sp->pack_boundary = 16;
12964 		else
12965 			sp->pack_boundary = 1 << (G_INGPACKBOUNDARY(r) + 5);
12966 	}
12967 	for (i = 0; i < SGE_FLBUF_SIZES; i++)
12968 		sp->sge_fl_buffer_size[i] = t4_read_reg(adapter,
12969 		    A_SGE_FL_BUFFER_SIZE0 + (4 * i));
12970 
12971 	return 0;
12972 }
12973 
12974 /* Convert the LE's hardware hash mask to a shorter filter mask. */
12975 static inline uint16_t
hashmask_to_filtermask(struct adapter * adap,uint64_t hashmask,uint16_t filter_mode)12976 hashmask_to_filtermask(struct adapter *adap, uint64_t hashmask, uint16_t filter_mode)
12977 {
12978 	int first, last, i;
12979 	uint16_t filter_mask;
12980 	uint64_t mask;          /* field mask */
12981 
12982 
12983 	if (chip_id(adap) >= CHELSIO_T7) {
12984 		first = S_T7_FT_FIRST;
12985 		last = S_T7_FT_LAST;
12986 	} else {
12987 		first = S_FT_FIRST;
12988 		last = S_FT_LAST;
12989 	}
12990 
12991 	for (filter_mask = 0, i = first; i <= last; i++) {
12992 		if ((filter_mode & (1 << i)) == 0)
12993 			continue;
12994 		mask = (1 << t4_filter_field_width(adap, i)) - 1;
12995 		if ((hashmask & mask) == mask)
12996 			filter_mask |= 1 << i;
12997 		hashmask >>= t4_filter_field_width(adap, i);
12998 	}
12999 
13000 	return (filter_mask);
13001 }
13002 
13003 /*
13004  * Read and cache the adapter's compressed filter mode and ingress config.
13005  */
13006 static void
read_filter_mode_and_ingress_config(struct adapter * adap)13007 read_filter_mode_and_ingress_config(struct adapter *adap)
13008 {
13009 	int rc;
13010 	uint32_t v, param[2], val[2];
13011 	struct tp_params *tpp = &adap->params.tp;
13012 	uint64_t hash_mask;
13013 
13014 	param[0] = V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
13015 	    V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_FILTER) |
13016 	    V_FW_PARAMS_PARAM_Y(FW_PARAM_DEV_FILTER_MODE_MASK);
13017 	param[1] = V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
13018 	    V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_FILTER) |
13019 	    V_FW_PARAMS_PARAM_Y(FW_PARAM_DEV_FILTER_VNIC_MODE);
13020 	rc = -t4_query_params(adap, adap->mbox, adap->pf, 0, 2, param, val);
13021 	if (rc == 0) {
13022 		tpp->filter_mode = G_FW_PARAMS_PARAM_FILTER_MODE(val[0]);
13023 		tpp->filter_mask = G_FW_PARAMS_PARAM_FILTER_MASK(val[0]);
13024 		tpp->vnic_mode = val[1];
13025 	} else {
13026 		/*
13027 		 * Old firmware.  Read filter mode/mask and ingress config
13028 		 * straight from the hardware.
13029 		 */
13030 		t4_tp_pio_read(adap, &v, 1, A_TP_VLAN_PRI_MAP, true);
13031 		tpp->filter_mode = v & 0xffff;
13032 
13033 		hash_mask = 0;
13034 		if (chip_id(adap) > CHELSIO_T4) {
13035 			v = t4_read_reg(adap, LE_HASH_MASK_GEN_IPV4T5(3));
13036 			hash_mask = v;
13037 			v = t4_read_reg(adap, LE_HASH_MASK_GEN_IPV4T5(4));
13038 			hash_mask |= (u64)v << 32;
13039 		}
13040 		if (chip_id(adap) >= CHELSIO_T7) {
13041 			/*
13042 			 * This param came before T7 so T7+ firmwares should
13043 			 * always support this query.
13044 			 */
13045 			CH_WARN(adap, "query for filter mode/mask failed: %d\n",
13046 			    rc);
13047 		}
13048 		tpp->filter_mask = hashmask_to_filtermask(adap, hash_mask,
13049 		    tpp->filter_mode);
13050 
13051 		t4_tp_pio_read(adap, &v, 1, A_TP_INGRESS_CONFIG, true);
13052 		if (v & F_VNIC)
13053 			tpp->vnic_mode = FW_VNIC_MODE_PF_VF;
13054 		else
13055 			tpp->vnic_mode = FW_VNIC_MODE_OUTER_VLAN;
13056 	}
13057 
13058 	/*
13059 	 * Now that we have TP_VLAN_PRI_MAP cached, we can calculate the field
13060 	 * shift positions of several elements of the Compressed Filter Tuple
13061 	 * for this adapter which we need frequently ...
13062 	 */
13063 	if (chip_id(adap) >= CHELSIO_T7) {
13064 		tpp->ipsecidx_shift = t4_filter_field_shift(adap, F_IPSECIDX);
13065 		tpp->fcoe_shift = t4_filter_field_shift(adap, F_T7_FCOE);
13066 		tpp->port_shift = t4_filter_field_shift(adap, F_T7_PORT);
13067 		tpp->vnic_shift = t4_filter_field_shift(adap, F_T7_VNIC_ID);
13068 		tpp->vlan_shift = t4_filter_field_shift(adap, F_T7_VLAN);
13069 		tpp->tos_shift = t4_filter_field_shift(adap, F_T7_TOS);
13070 		tpp->protocol_shift = t4_filter_field_shift(adap, F_T7_PROTOCOL);
13071 		tpp->ethertype_shift = t4_filter_field_shift(adap, F_T7_ETHERTYPE);
13072 		tpp->macmatch_shift = t4_filter_field_shift(adap, F_T7_MACMATCH);
13073 		tpp->matchtype_shift = t4_filter_field_shift(adap, F_T7_MPSHITTYPE);
13074 		tpp->frag_shift = t4_filter_field_shift(adap, F_T7_FRAGMENTATION);
13075 		tpp->roce_shift = t4_filter_field_shift(adap, F_ROCE);
13076 		tpp->synonly_shift = t4_filter_field_shift(adap, F_SYNONLY);
13077 		tpp->tcpflags_shift = t4_filter_field_shift(adap, F_TCPFLAGS);
13078 	} else {
13079 		tpp->ipsecidx_shift = -1;
13080 		tpp->fcoe_shift = t4_filter_field_shift(adap, F_FCOE);
13081 		tpp->port_shift = t4_filter_field_shift(adap, F_PORT);
13082 		tpp->vnic_shift = t4_filter_field_shift(adap, F_VNIC_ID);
13083 		tpp->vlan_shift = t4_filter_field_shift(adap, F_VLAN);
13084 		tpp->tos_shift = t4_filter_field_shift(adap, F_TOS);
13085 		tpp->protocol_shift = t4_filter_field_shift(adap, F_PROTOCOL);
13086 		tpp->ethertype_shift = t4_filter_field_shift(adap, F_ETHERTYPE);
13087 		tpp->macmatch_shift = t4_filter_field_shift(adap, F_MACMATCH);
13088 		tpp->matchtype_shift = t4_filter_field_shift(adap, F_MPSHITTYPE);
13089 		tpp->frag_shift = t4_filter_field_shift(adap, F_FRAGMENTATION);
13090 		tpp->roce_shift = -1;
13091 		tpp->synonly_shift = -1;
13092 		tpp->tcpflags_shift = -1;
13093 	}
13094 }
13095 
13096 /**
13097  *      t4_init_tp_params - initialize adap->params.tp
13098  *      @adap: the adapter
13099  *
13100  *      Initialize various fields of the adapter's TP Parameters structure.
13101  */
t4_init_tp_params(struct adapter * adap)13102 int t4_init_tp_params(struct adapter *adap)
13103 {
13104 	u32 tx_len, rx_len, r, v;
13105 	struct tp_params *tpp = &adap->params.tp;
13106 
13107 	v = t4_read_reg(adap, A_TP_TIMER_RESOLUTION);
13108 	tpp->tre = G_TIMERRESOLUTION(v);
13109 	tpp->dack_re = G_DELAYEDACKRESOLUTION(v);
13110 
13111 	read_filter_mode_and_ingress_config(adap);
13112 
13113 	tpp->rx_pkt_encap = false;
13114 	tpp->lb_mode = 0;
13115 	tpp->lb_nchan = 1;
13116 	if (chip_id(adap) > CHELSIO_T5) {
13117 		v = t4_read_reg(adap, A_TP_OUT_CONFIG);
13118 		tpp->rx_pkt_encap = v & F_CRXPKTENC;
13119 		if (chip_id(adap) >= CHELSIO_T7) {
13120 			t4_tp_pio_read(adap, &v, 1, A_TP_CHANNEL_MAP, true);
13121 			tpp->lb_mode = G_T7_LB_MODE(v);
13122 			if (tpp->lb_mode == 1)
13123 				tpp->lb_nchan = 4;
13124 			else if (tpp->lb_mode == 2)
13125 				tpp->lb_nchan = 2;
13126 		}
13127 	}
13128 
13129 	rx_len = t4_read_reg(adap, A_TP_PMM_RX_PAGE_SIZE);
13130 	tx_len = t4_read_reg(adap, A_TP_PMM_TX_PAGE_SIZE);
13131 
13132 	r = t4_read_reg(adap, A_TP_PARA_REG2);
13133 	rx_len = min(rx_len, G_MAXRXDATA(r));
13134 	tx_len = min(tx_len, G_MAXRXDATA(r));
13135 
13136 	r = t4_read_reg(adap, A_TP_PARA_REG7);
13137 	v = min(G_PMMAXXFERLEN0(r), G_PMMAXXFERLEN1(r));
13138 	rx_len = min(rx_len, v);
13139 	tx_len = min(tx_len, v);
13140 
13141 	tpp->max_tx_pdu = tx_len;
13142 	tpp->max_rx_pdu = rx_len;
13143 
13144 	return 0;
13145 }
13146 
13147 /**
13148  *      t4_filter_field_width - returns the width of a filter field
13149  *      @adap: the adapter
13150  *      @filter_field: the filter field whose width is being requested
13151  *
13152  *      Return the shift position of a filter field within the Compressed
13153  *      Filter Tuple.  The filter field is specified via its selection bit
13154  *      within TP_VLAN_PRI_MAL (filter mode).  E.g. F_VLAN.
13155  */
t4_filter_field_width(const struct adapter * adap,int filter_field)13156 int t4_filter_field_width(const struct adapter *adap, int filter_field)
13157 {
13158 	const int nopt = adap->chip_params->filter_num_opt;
13159 	static const uint8_t width_t7[] = {
13160 		W_FT_IPSECIDX,
13161 		W_FT_FCOE,
13162 		W_FT_PORT,
13163 		W_FT_VNIC_ID,
13164 		W_FT_VLAN,
13165 		W_FT_TOS,
13166 		W_FT_PROTOCOL,
13167 		W_FT_ETHERTYPE,
13168 		W_FT_MACMATCH,
13169 		W_FT_MPSHITTYPE,
13170 		W_FT_FRAGMENTATION,
13171 		W_FT_ROCE,
13172 		W_FT_SYNONLY,
13173 		W_FT_TCPFLAGS
13174 	};
13175 	static const uint8_t width_t4[] = {
13176 		W_FT_FCOE,
13177 		W_FT_PORT,
13178 		W_FT_VNIC_ID,
13179 		W_FT_VLAN,
13180 		W_FT_TOS,
13181 		W_FT_PROTOCOL,
13182 		W_FT_ETHERTYPE,
13183 		W_FT_MACMATCH,
13184 		W_FT_MPSHITTYPE,
13185 		W_FT_FRAGMENTATION
13186 	};
13187 	const uint8_t *width = chip_id(adap) >= CHELSIO_T7 ? width_t7 : width_t4;
13188 
13189 	if (filter_field < 0 || filter_field >= nopt)
13190 		return (0);
13191 	return (width[filter_field]);
13192 }
13193 
13194 /**
13195  *      t4_filter_field_shift - calculate filter field shift
13196  *      @adap: the adapter
13197  *      @filter_sel: the desired field (from TP_VLAN_PRI_MAP bits)
13198  *
13199  *      Return the shift position of a filter field within the Compressed
13200  *      Filter Tuple.  The filter field is specified via its selection bit
13201  *      within TP_VLAN_PRI_MAL (filter mode).  E.g. F_VLAN.
13202  */
t4_filter_field_shift(const struct adapter * adap,int filter_sel)13203 int t4_filter_field_shift(const struct adapter *adap, int filter_sel)
13204 {
13205 	const unsigned int filter_mode = adap->params.tp.filter_mode;
13206 	unsigned int sel;
13207 	int field_shift;
13208 
13209 	if ((filter_mode & filter_sel) == 0)
13210 		return -1;
13211 
13212 	if (chip_id(adap) >= CHELSIO_T7) {
13213 		for (sel = 1, field_shift = 0; sel < filter_sel; sel <<= 1) {
13214 			switch (filter_mode & sel) {
13215 			case F_IPSECIDX:
13216 				field_shift += W_FT_IPSECIDX;
13217 				break;
13218 			case F_T7_FCOE:
13219 				field_shift += W_FT_FCOE;
13220 				break;
13221 			case F_T7_PORT:
13222 				field_shift += W_FT_PORT;
13223 				break;
13224 			case F_T7_VNIC_ID:
13225 				field_shift += W_FT_VNIC_ID;
13226 				break;
13227 			case F_T7_VLAN:
13228 				field_shift += W_FT_VLAN;
13229 				break;
13230 			case F_T7_TOS:
13231 				field_shift += W_FT_TOS;
13232 				break;
13233 			case F_T7_PROTOCOL:
13234 				field_shift += W_FT_PROTOCOL;
13235 				break;
13236 			case F_T7_ETHERTYPE:
13237 				field_shift += W_FT_ETHERTYPE;
13238 				break;
13239 			case F_T7_MACMATCH:
13240 				field_shift += W_FT_MACMATCH;
13241 				break;
13242 			case F_T7_MPSHITTYPE:
13243 				field_shift += W_FT_MPSHITTYPE;
13244 				break;
13245 			case F_T7_FRAGMENTATION:
13246 				field_shift += W_FT_FRAGMENTATION;
13247 				break;
13248 			case F_ROCE:
13249 				field_shift += W_FT_ROCE;
13250 				break;
13251 			case F_SYNONLY:
13252 				field_shift += W_FT_SYNONLY;
13253 				break;
13254 			case F_TCPFLAGS:
13255 				field_shift += W_FT_TCPFLAGS;
13256 				break;
13257 			}
13258 		}
13259 		return field_shift;
13260 	}
13261 
13262 	for (sel = 1, field_shift = 0; sel < filter_sel; sel <<= 1) {
13263 		switch (filter_mode & sel) {
13264 		case F_FCOE:
13265 			field_shift += W_FT_FCOE;
13266 			break;
13267 		case F_PORT:
13268 			field_shift += W_FT_PORT;
13269 			break;
13270 		case F_VNIC_ID:
13271 			field_shift += W_FT_VNIC_ID;
13272 			break;
13273 		case F_VLAN:
13274 			field_shift += W_FT_VLAN;
13275 			break;
13276 		case F_TOS:
13277 			field_shift += W_FT_TOS;
13278 			break;
13279 		case F_PROTOCOL:
13280 			field_shift += W_FT_PROTOCOL;
13281 			break;
13282 		case F_ETHERTYPE:
13283 			field_shift += W_FT_ETHERTYPE;
13284 			break;
13285 		case F_MACMATCH:
13286 			field_shift += W_FT_MACMATCH;
13287 			break;
13288 		case F_MPSHITTYPE:
13289 			field_shift += W_FT_MPSHITTYPE;
13290 			break;
13291 		case F_FRAGMENTATION:
13292 			field_shift += W_FT_FRAGMENTATION;
13293 			break;
13294 		}
13295 	}
13296 	return field_shift;
13297 }
13298 
t4_port_init(struct adapter * adap,int mbox,int pf,int vf,int port_id)13299 int t4_port_init(struct adapter *adap, int mbox, int pf, int vf, int port_id)
13300 {
13301 	u8 addr[6];
13302 	int ret, i, j;
13303 	struct port_info *p = adap2pinfo(adap, port_id);
13304 	u32 param, val;
13305 	struct vi_info *vi = &p->vi[0];
13306 
13307 	for (i = 0, j = -1; i <= p->port_id; i++) {
13308 		do {
13309 			j++;
13310 		} while ((adap->params.portvec & (1 << j)) == 0);
13311 	}
13312 
13313 	p->hw_port = j;
13314 	p->tx_chan = t4_get_tx_c_chan(adap, j);
13315 	p->rx_chan = t4_get_rx_c_chan(adap, j);
13316 	p->mps_bg_map = t4_get_mps_bg_map(adap, j);
13317 	p->rx_e_chan_map = t4_get_rx_e_chan_map(adap, j);
13318 
13319 	if (!(adap->flags & IS_VF) ||
13320 	    adap->params.vfres.r_caps & FW_CMD_CAP_PORT) {
13321  		t4_update_port_info(p);
13322 	}
13323 
13324 	ret = t4_alloc_vi(adap, mbox, j, pf, vf, 1, addr, &vi->rss_size,
13325 	    &vi->vfvld, &vi->vin);
13326 	if (ret < 0)
13327 		return ret;
13328 
13329 	vi->viid = ret;
13330 	t4_os_set_hw_addr(p, addr);
13331 
13332 	param = V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
13333 	    V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_RSSINFO) |
13334 	    V_FW_PARAMS_PARAM_YZ(vi->viid);
13335 	ret = t4_query_params(adap, mbox, pf, vf, 1, &param, &val);
13336 	if (ret)
13337 		vi->rss_base = 0xffff;
13338 	else {
13339 		/* MPASS((val >> 16) == rss_size); */
13340 		vi->rss_base = val & 0xffff;
13341 	}
13342 
13343 	return 0;
13344 }
13345 
t4_read_cimq_cfg_ibq_core(struct adapter * adap,u8 coreid,u32 qid,u16 * base,u16 * size,u16 * thres)13346 static void t4_read_cimq_cfg_ibq_core(struct adapter *adap, u8 coreid, u32 qid,
13347 				      u16 *base, u16 *size, u16 *thres)
13348 {
13349 	unsigned int v, m;
13350 
13351 	if (chip_id(adap) > CHELSIO_T6) {
13352 		v = F_T7_IBQSELECT | V_T7_QUENUMSELECT(qid) |
13353 		    V_CORESELECT(coreid);
13354 		/* value is in 512-byte units */
13355 		m = 512;
13356 	} else {
13357 		v = F_IBQSELECT | V_QUENUMSELECT(qid);
13358 		/* value is in 256-byte units */
13359 		m = 256;
13360 	}
13361 
13362 	t4_write_reg(adap, A_CIM_QUEUE_CONFIG_REF, v);
13363 	v = t4_read_reg(adap, A_CIM_QUEUE_CONFIG_CTRL);
13364 	if (base)
13365 		*base = G_CIMQBASE(v) * m;
13366 	if (size)
13367 		*size = G_CIMQSIZE(v) * m;
13368 	if (thres)
13369 		*thres = G_QUEFULLTHRSH(v) * 8; /* 8-byte unit */
13370 }
13371 
t4_read_cimq_cfg_obq_core(struct adapter * adap,u8 coreid,u32 qid,u16 * base,u16 * size)13372 static void t4_read_cimq_cfg_obq_core(struct adapter *adap, u8 coreid, u32 qid,
13373 				      u16 *base, u16 *size)
13374 {
13375 	unsigned int v, m;
13376 
13377 	if (chip_id(adap) > CHELSIO_T6) {
13378 		v = F_T7_OBQSELECT | V_T7_QUENUMSELECT(qid) |
13379 		    V_CORESELECT(coreid);
13380 		/* value is in 512-byte units */
13381 		m = 512;
13382 	} else {
13383 		v = F_OBQSELECT | V_QUENUMSELECT(qid);
13384 		/* value is in 256-byte units */
13385 		m = 256;
13386 	}
13387 
13388 	t4_write_reg(adap, A_CIM_QUEUE_CONFIG_REF, v);
13389 	v = t4_read_reg(adap, A_CIM_QUEUE_CONFIG_CTRL);
13390 	if (base)
13391 		*base = G_CIMQBASE(v) * m;
13392 	if (size)
13393 		*size = G_CIMQSIZE(v) * m;
13394 }
13395 
13396 /**
13397  *	t4_read_cimq_cfg_core - read CIM queue configuration on specific core
13398  *	@adap: the adapter
13399  *	@coreid: the uP coreid
13400  *	@base: holds the queue base addresses in bytes
13401  *	@size: holds the queue sizes in bytes
13402  *	@thres: holds the queue full thresholds in bytes
13403  *
13404  *	Returns the current configuration of the CIM queues, starting with
13405  *	the IBQs, then the OBQs, on a specific @coreid.
13406  */
t4_read_cimq_cfg_core(struct adapter * adap,u8 coreid,u16 * base,u16 * size,u16 * thres)13407 void t4_read_cimq_cfg_core(struct adapter *adap, u8 coreid, u16 *base,
13408 			   u16 *size, u16 *thres)
13409 {
13410 	unsigned int cim_num_ibq = adap->chip_params->cim_num_ibq;
13411 	unsigned int cim_num_obq = adap->chip_params->cim_num_obq;
13412 	unsigned int i;
13413 
13414 	for (i = 0; i < cim_num_ibq; i++, base++, size++, thres++)
13415 		t4_read_cimq_cfg_ibq_core(adap, coreid, i, base, size, thres);
13416 
13417 	for (i = 0; i < cim_num_obq; i++, base++, size++)
13418 		t4_read_cimq_cfg_obq_core(adap, coreid, i, base, size);
13419 }
13420 
t4_read_cim_ibq_data_core(struct adapter * adap,u8 coreid,u32 addr,u32 * data)13421 static int t4_read_cim_ibq_data_core(struct adapter *adap, u8 coreid, u32 addr,
13422 				     u32 *data)
13423 {
13424 	int ret, attempts;
13425 	unsigned int v;
13426 
13427 	/* It might take 3-10ms before the IBQ debug read access is allowed.
13428 	 * Wait for 1 Sec with a delay of 1 usec.
13429 	 */
13430 	attempts = 1000000;
13431 
13432 	if (chip_id(adap) > CHELSIO_T6)
13433 		v = V_T7_IBQDBGADDR(addr) | V_IBQDBGCORE(coreid);
13434 	else
13435 		v = V_IBQDBGADDR(addr);
13436 
13437 	t4_write_reg(adap, A_CIM_IBQ_DBG_CFG, v | F_IBQDBGEN);
13438 	ret = t4_wait_op_done(adap, A_CIM_IBQ_DBG_CFG, F_IBQDBGBUSY, 0,
13439 			      attempts, 1);
13440 	if (ret)
13441 		return ret;
13442 
13443 	*data = t4_read_reg(adap, A_CIM_IBQ_DBG_DATA);
13444 	return 0;
13445 }
13446 
13447 /**
13448  *	t4_read_cim_ibq_core - read the contents of a CIM inbound queue on
13449  *	specific core
13450  *	@adap: the adapter
13451  *	@coreid: the uP coreid
13452  *	@qid: the queue index
13453  *	@data: where to store the queue contents
13454  *	@n: capacity of @data in 32-bit words
13455  *
13456  *	Reads the contents of the selected CIM queue starting at address 0 up
13457  *	to the capacity of @data on a specific @coreid.  @n must be a multiple
13458  *	of 4.  Returns < 0 on error and the number of 32-bit words actually
13459  *	read on success.
13460  */
t4_read_cim_ibq_core(struct adapter * adap,u8 coreid,u32 qid,u32 * data,size_t n)13461 int t4_read_cim_ibq_core(struct adapter *adap, u8 coreid, u32 qid, u32 *data,
13462 			 size_t n)
13463 {
13464 	unsigned int cim_num_ibq = adap->chip_params->cim_num_ibq;
13465 	u16 i, addr, nwords;
13466 	int ret;
13467 
13468 	if (qid > (cim_num_ibq - 1) || (n & 3))
13469 		return -EINVAL;
13470 
13471 	t4_read_cimq_cfg_ibq_core(adap, coreid, qid, &addr, &nwords, NULL);
13472 	addr >>= sizeof(u16);
13473 	nwords >>= sizeof(u16);
13474 	if (n > nwords)
13475 		n = nwords;
13476 
13477 	for (i = 0; i < n; i++, addr++, data++) {
13478 		ret = t4_read_cim_ibq_data_core(adap, coreid, addr, data);
13479 		if (ret < 0)
13480 			return ret;
13481 	}
13482 
13483 	t4_write_reg(adap, A_CIM_IBQ_DBG_CFG, 0);
13484 	return i;
13485 }
13486 
t4_read_cim_obq_data_core(struct adapter * adap,u8 coreid,u32 addr,u32 * data)13487 static int t4_read_cim_obq_data_core(struct adapter *adap, u8 coreid, u32 addr,
13488 				     u32 *data)
13489 {
13490 	unsigned int v;
13491 	int ret;
13492 
13493 	if (chip_id(adap) > CHELSIO_T6)
13494 		v = V_T7_OBQDBGADDR(addr) | V_OBQDBGCORE(coreid);
13495 	else
13496 		v = V_OBQDBGADDR(addr);
13497 
13498 	t4_write_reg(adap, A_CIM_OBQ_DBG_CFG, v | F_OBQDBGEN);
13499 	ret = t4_wait_op_done(adap, A_CIM_OBQ_DBG_CFG, F_OBQDBGBUSY, 0, 2, 1);
13500 	if (ret)
13501 		return ret;
13502 
13503 	*data = t4_read_reg(adap, A_CIM_OBQ_DBG_DATA);
13504 	return 0;
13505 }
13506 
13507 /**
13508  *	t4_read_cim_obq_core - read the contents of a CIM outbound queue on
13509  *	specific core
13510  *	@adap: the adapter
13511  *	@coreid: the uP coreid
13512  *	@qid: the queue index
13513  *	@data: where to store the queue contents
13514  *	@n: capacity of @data in 32-bit words
13515  *
13516  *	Reads the contents of the selected CIM queue starting at address 0 up
13517  *	to the capacity of @data on specific @coreid.  @n must be a multiple
13518  *	of 4.  Returns < 0 on error and the number of 32-bit words actually
13519  *	read on success.
13520  */
t4_read_cim_obq_core(struct adapter * adap,u8 coreid,u32 qid,u32 * data,size_t n)13521 int t4_read_cim_obq_core(struct adapter *adap, u8 coreid, u32 qid, u32 *data,
13522 			 size_t n)
13523 {
13524 	unsigned int cim_num_obq = adap->chip_params->cim_num_obq;
13525 	u16 i, addr, nwords;
13526 	int ret;
13527 
13528 	if ((qid > (cim_num_obq - 1)) || (n & 3))
13529 		return -EINVAL;
13530 
13531 	t4_read_cimq_cfg_obq_core(adap, coreid, qid, &addr, &nwords);
13532 	addr >>= sizeof(u16);
13533 	nwords >>= sizeof(u16);
13534 	if (n > nwords)
13535 		n = nwords;
13536 
13537 	for (i = 0; i < n; i++, addr++, data++) {
13538 		ret = t4_read_cim_obq_data_core(adap, coreid, addr, data);
13539 		if (ret < 0)
13540 			return ret;
13541 	}
13542 
13543 	t4_write_reg(adap, A_CIM_OBQ_DBG_CFG, 0);
13544  	return i;
13545 }
13546 
13547 /**
13548  *	t4_cim_read_core - read a block from CIM internal address space
13549  *	of a control register group on specific core.
13550  *	@adap: the adapter
13551  *	@group: the control register group to select for read
13552  *	@coreid: the uP coreid
13553  *	@addr: the start address within the CIM address space
13554  *	@n: number of words to read
13555  *	@valp: where to store the result
13556  *
13557  *	Reads a block of 4-byte words from the CIM intenal address space
13558  *	of a control register @group on a specific @coreid.
13559  */
t4_cim_read_core(struct adapter * adap,u8 group,u8 coreid,unsigned int addr,unsigned int n,unsigned int * valp)13560 int t4_cim_read_core(struct adapter *adap, u8 group, u8 coreid,
13561 		     unsigned int addr, unsigned int n,
13562 		     unsigned int *valp)
13563 {
13564 	unsigned int hostbusy, v = 0;
13565 	int ret = 0;
13566 
13567 	if (chip_id(adap) > CHELSIO_T6) {
13568 		hostbusy = F_T7_HOSTBUSY;
13569 		v = V_HOSTGRPSEL(group) | V_HOSTCORESEL(coreid);
13570 	} else {
13571 		hostbusy = F_HOSTBUSY;
13572 	}
13573 
13574 	if (t4_read_reg(adap, A_CIM_HOST_ACC_CTRL) & hostbusy)
13575 		return -EBUSY;
13576 
13577 	for ( ; !ret && n--; addr += 4) {
13578 		t4_write_reg(adap, A_CIM_HOST_ACC_CTRL, addr | v);
13579 		ret = t4_wait_op_done(adap, A_CIM_HOST_ACC_CTRL, hostbusy,
13580 				      0, 5, 2);
13581 		if (!ret)
13582 			*valp++ = t4_read_reg(adap, A_CIM_HOST_ACC_DATA);
13583 	}
13584 
13585 	return ret;
13586 }
13587 
13588 /**
13589  *	t4_cim_write_core - write a block into CIM internal address space
13590  *	of a control register group on specific core.
13591  *	@adap: the adapter
13592  *	@group: the control register group to select for write
13593  *	@coreid: the uP coreid
13594  *	@addr: the start address within the CIM address space
13595  *	@n: number of words to write
13596  *	@valp: set of values to write
13597  *
13598  *	Writes a block of 4-byte words into the CIM intenal address space
13599  *	of a control register @group on a specific @coreid.
13600  */
t4_cim_write_core(struct adapter * adap,u8 group,u8 coreid,unsigned int addr,unsigned int n,const unsigned int * valp)13601 int t4_cim_write_core(struct adapter *adap, u8 group, u8 coreid,
13602 		      unsigned int addr, unsigned int n,
13603 		      const unsigned int *valp)
13604 {
13605 	unsigned int hostbusy, v;
13606 	int ret = 0;
13607 
13608 	if (chip_id(adap) > CHELSIO_T6) {
13609 		hostbusy = F_T7_HOSTBUSY;
13610 		v = F_T7_HOSTWRITE | V_HOSTGRPSEL(group) |
13611 		    V_HOSTCORESEL(coreid);
13612 	} else {
13613 		hostbusy = F_HOSTBUSY;
13614 		v = F_HOSTWRITE;
13615 	}
13616 
13617 	if (t4_read_reg(adap, A_CIM_HOST_ACC_CTRL) & hostbusy)
13618 		return -EBUSY;
13619 
13620 	for ( ; !ret && n--; addr += 4) {
13621 		t4_write_reg(adap, A_CIM_HOST_ACC_DATA, *valp++);
13622 		t4_write_reg(adap, A_CIM_HOST_ACC_CTRL, addr | v);
13623 		ret = t4_wait_op_done(adap, A_CIM_HOST_ACC_CTRL, hostbusy,
13624 				      0, 5, 2);
13625 	}
13626 
13627 	return ret;
13628 }
13629 
13630 /**
13631  *	t4_cim_read_la_core - read CIM LA capture buffer on specific core
13632  *	@adap: the adapter
13633  *	@coreid: uP coreid
13634  *	@la_buf: where to store the LA data
13635  *	@wrptr: the HW write pointer within the capture buffer
13636  *
13637  *	Reads the contents of the CIM LA buffer on a specific @coreid
13638  *	with the most recent entry at the end of the returned data
13639  *	and with the entry at @wrptr first. We try to leave the LA
13640  *	in the running state we find it in.
13641  */
t4_cim_read_la_core(struct adapter * adap,u8 coreid,u32 * la_buf,u32 * wrptr)13642 int t4_cim_read_la_core(struct adapter *adap, u8 coreid, u32 *la_buf,
13643 			u32 *wrptr)
13644 {
13645 	unsigned int cfg, val, idx;
13646 	int i, ret;
13647 
13648 	ret = t4_cim_read_core(adap, 1, coreid, A_UP_UP_DBG_LA_CFG, 1, &cfg);
13649 	if (ret)
13650 		return ret;
13651 
13652 	if (cfg & F_UPDBGLAEN) {	/* LA is running, freeze it */
13653 		val = 0;
13654 		ret = t4_cim_write_core(adap, 1, coreid, A_UP_UP_DBG_LA_CFG, 1,
13655 					&val);
13656 		if (ret)
13657 			return ret;
13658 	}
13659 
13660 	ret = t4_cim_read_core(adap, 1, coreid, A_UP_UP_DBG_LA_CFG, 1, &val);
13661 	if (ret)
13662 		goto restart;
13663 
13664 	idx = G_UPDBGLAWRPTR(val);
13665 	if (wrptr)
13666 		*wrptr = idx;
13667 
13668 	for (i = 0; i < adap->params.cim_la_size; i++) {
13669 		val = V_UPDBGLARDPTR(idx) | F_UPDBGLARDEN;
13670 		ret = t4_cim_write_core(adap, 1, coreid, A_UP_UP_DBG_LA_CFG, 1,
13671 					&val);
13672 		if (ret)
13673 			break;
13674 		ret = t4_cim_read_core(adap, 1, coreid, A_UP_UP_DBG_LA_CFG, 1,
13675 				       &val);
13676 		if (ret)
13677 			break;
13678 		if (val & F_UPDBGLARDEN) {
13679 			ret = -ETIMEDOUT;
13680 			break;
13681 		}
13682 		ret = t4_cim_read_core(adap, 1, coreid, A_UP_UP_DBG_LA_DATA, 1,
13683 				       &la_buf[i]);
13684 		if (ret)
13685 			break;
13686 
13687 		/* Bits 0-3 of UpDbgLaRdPtr can be between 0000 to 1001 to
13688 		 * identify the 32-bit portion of the full 312-bit data
13689 		 */
13690 		if ((chip_id(adap) > CHELSIO_T5) && (idx & 0xf) >= 9)
13691 			idx = (idx & 0xff0) + 0x10;
13692 		else
13693 			idx++;
13694 		/* address can't exceed 0xfff */
13695 		idx &= M_UPDBGLARDPTR;
13696 	}
13697 restart:
13698 	if (cfg & F_UPDBGLAEN) {
13699 		int r;
13700 
13701 		val = cfg & ~F_UPDBGLARDEN;
13702 		r = t4_cim_write_core(adap, 1, coreid, A_UP_UP_DBG_LA_CFG, 1,
13703 				      &val);
13704 		if (!ret)
13705 			ret = r;
13706 	}
13707 
13708 	return ret;
13709 }
13710 
13711 /**
13712  *	t4_tp_read_la - read TP LA capture buffer
13713  *	@adap: the adapter
13714  *	@la_buf: where to store the LA data
13715  *	@wrptr: the HW write pointer within the capture buffer
13716  *
13717  *	Reads the contents of the TP LA buffer with the most recent entry at
13718  *	the end	of the returned data and with the entry at @wrptr first.
13719  *	We leave the LA in the running state we find it in.
13720  */
t4_tp_read_la(struct adapter * adap,u64 * la_buf,unsigned int * wrptr)13721 void t4_tp_read_la(struct adapter *adap, u64 *la_buf, unsigned int *wrptr)
13722 {
13723 	bool last_incomplete;
13724 	unsigned int i, cfg, val, idx;
13725 
13726 	cfg = t4_read_reg(adap, A_TP_DBG_LA_CONFIG) & 0xffff;
13727 	if (cfg & F_DBGLAENABLE)			/* freeze LA */
13728 		t4_write_reg(adap, A_TP_DBG_LA_CONFIG,
13729 			     adap->params.tp.la_mask | (cfg ^ F_DBGLAENABLE));
13730 
13731 	val = t4_read_reg(adap, A_TP_DBG_LA_CONFIG);
13732 	idx = G_DBGLAWPTR(val);
13733 	last_incomplete = G_DBGLAMODE(val) >= 2 && (val & F_DBGLAWHLF) == 0;
13734 	if (last_incomplete)
13735 		idx = (idx + 1) & M_DBGLARPTR;
13736 	if (wrptr)
13737 		*wrptr = idx;
13738 
13739 	val &= 0xffff;
13740 	val &= ~V_DBGLARPTR(M_DBGLARPTR);
13741 	val |= adap->params.tp.la_mask;
13742 
13743 	for (i = 0; i < TPLA_SIZE; i++) {
13744 		t4_write_reg(adap, A_TP_DBG_LA_CONFIG, V_DBGLARPTR(idx) | val);
13745 		la_buf[i] = t4_read_reg64(adap, A_TP_DBG_LA_DATAL);
13746 		idx = (idx + 1) & M_DBGLARPTR;
13747 	}
13748 
13749 	/* Wipe out last entry if it isn't valid */
13750 	if (last_incomplete)
13751 		la_buf[TPLA_SIZE - 1] = ~0ULL;
13752 
13753 	if (cfg & F_DBGLAENABLE)		/* restore running state */
13754 		t4_write_reg(adap, A_TP_DBG_LA_CONFIG,
13755 			     cfg | adap->params.tp.la_mask);
13756 }
13757 
13758 /*
13759  * SGE Hung Ingress DMA Warning Threshold time and Warning Repeat Rate (in
13760  * seconds).  If we find one of the SGE Ingress DMA State Machines in the same
13761  * state for more than the Warning Threshold then we'll issue a warning about
13762  * a potential hang.  We'll repeat the warning as the SGE Ingress DMA Channel
13763  * appears to be hung every Warning Repeat second till the situation clears.
13764  * If the situation clears, we'll note that as well.
13765  */
13766 #define SGE_IDMA_WARN_THRESH 1
13767 #define SGE_IDMA_WARN_REPEAT 300
13768 
13769 /**
13770  *	t4_idma_monitor_init - initialize SGE Ingress DMA Monitor
13771  *	@adapter: the adapter
13772  *	@idma: the adapter IDMA Monitor state
13773  *
13774  *	Initialize the state of an SGE Ingress DMA Monitor.
13775  */
t4_idma_monitor_init(struct adapter * adapter,struct sge_idma_monitor_state * idma)13776 void t4_idma_monitor_init(struct adapter *adapter,
13777 			  struct sge_idma_monitor_state *idma)
13778 {
13779 	/* Initialize the state variables for detecting an SGE Ingress DMA
13780 	 * hang.  The SGE has internal counters which count up on each clock
13781 	 * tick whenever the SGE finds its Ingress DMA State Engines in the
13782 	 * same state they were on the previous clock tick.  The clock used is
13783 	 * the Core Clock so we have a limit on the maximum "time" they can
13784 	 * record; typically a very small number of seconds.  For instance,
13785 	 * with a 600MHz Core Clock, we can only count up to a bit more than
13786 	 * 7s.  So we'll synthesize a larger counter in order to not run the
13787 	 * risk of having the "timers" overflow and give us the flexibility to
13788 	 * maintain a Hung SGE State Machine of our own which operates across
13789 	 * a longer time frame.
13790 	 */
13791 	idma->idma_1s_thresh = core_ticks_per_usec(adapter) * 1000000; /* 1s */
13792 	idma->idma_stalled[0] = idma->idma_stalled[1] = 0;
13793 }
13794 
13795 /**
13796  *	t4_idma_monitor - monitor SGE Ingress DMA state
13797  *	@adapter: the adapter
13798  *	@idma: the adapter IDMA Monitor state
13799  *	@hz: number of ticks/second
13800  *	@ticks: number of ticks since the last IDMA Monitor call
13801  */
t4_idma_monitor(struct adapter * adapter,struct sge_idma_monitor_state * idma,int hz,int ticks)13802 void t4_idma_monitor(struct adapter *adapter,
13803 		     struct sge_idma_monitor_state *idma,
13804 		     int hz, int ticks)
13805 {
13806 	int i, idma_same_state_cnt[2];
13807 
13808 	 /* Read the SGE Debug Ingress DMA Same State Count registers.  These
13809 	  * are counters inside the SGE which count up on each clock when the
13810 	  * SGE finds its Ingress DMA State Engines in the same states they
13811 	  * were in the previous clock.  The counters will peg out at
13812 	  * 0xffffffff without wrapping around so once they pass the 1s
13813 	  * threshold they'll stay above that till the IDMA state changes.
13814 	  */
13815 	t4_write_reg(adapter, A_SGE_DEBUG_INDEX, 13);
13816 	idma_same_state_cnt[0] = t4_read_reg(adapter, A_SGE_DEBUG_DATA_HIGH);
13817 	idma_same_state_cnt[1] = t4_read_reg(adapter, A_SGE_DEBUG_DATA_LOW);
13818 
13819 	for (i = 0; i < 2; i++) {
13820 		u32 debug0, debug11;
13821 
13822 		/* If the Ingress DMA Same State Counter ("timer") is less
13823 		 * than 1s, then we can reset our synthesized Stall Timer and
13824 		 * continue.  If we have previously emitted warnings about a
13825 		 * potential stalled Ingress Queue, issue a note indicating
13826 		 * that the Ingress Queue has resumed forward progress.
13827 		 */
13828 		if (idma_same_state_cnt[i] < idma->idma_1s_thresh) {
13829 			if (idma->idma_stalled[i] >= SGE_IDMA_WARN_THRESH*hz)
13830 				CH_WARN(adapter, "SGE idma%d, queue %u, "
13831 					"resumed after %d seconds\n",
13832 					i, idma->idma_qid[i],
13833 					idma->idma_stalled[i]/hz);
13834 			idma->idma_stalled[i] = 0;
13835 			continue;
13836 		}
13837 
13838 		/* Synthesize an SGE Ingress DMA Same State Timer in the Hz
13839 		 * domain.  The first time we get here it'll be because we
13840 		 * passed the 1s Threshold; each additional time it'll be
13841 		 * because the RX Timer Callback is being fired on its regular
13842 		 * schedule.
13843 		 *
13844 		 * If the stall is below our Potential Hung Ingress Queue
13845 		 * Warning Threshold, continue.
13846 		 */
13847 		if (idma->idma_stalled[i] == 0) {
13848 			idma->idma_stalled[i] = hz;
13849 			idma->idma_warn[i] = 0;
13850 		} else {
13851 			idma->idma_stalled[i] += ticks;
13852 			idma->idma_warn[i] -= ticks;
13853 		}
13854 
13855 		if (idma->idma_stalled[i] < SGE_IDMA_WARN_THRESH*hz)
13856 			continue;
13857 
13858 		/* We'll issue a warning every SGE_IDMA_WARN_REPEAT seconds.
13859 		 */
13860 		if (idma->idma_warn[i] > 0)
13861 			continue;
13862 		idma->idma_warn[i] = SGE_IDMA_WARN_REPEAT*hz;
13863 
13864 		/* Read and save the SGE IDMA State and Queue ID information.
13865 		 * We do this every time in case it changes across time ...
13866 		 * can't be too careful ...
13867 		 */
13868 		t4_write_reg(adapter, A_SGE_DEBUG_INDEX, 0);
13869 		debug0 = t4_read_reg(adapter, A_SGE_DEBUG_DATA_LOW);
13870 		idma->idma_state[i] = (debug0 >> (i * 9)) & 0x3f;
13871 
13872 		t4_write_reg(adapter, A_SGE_DEBUG_INDEX, 11);
13873 		debug11 = t4_read_reg(adapter, A_SGE_DEBUG_DATA_LOW);
13874 		idma->idma_qid[i] = (debug11 >> (i * 16)) & 0xffff;
13875 
13876 		CH_WARN(adapter, "SGE idma%u, queue %u, potentially stuck in "
13877 			" state %u for %d seconds (debug0=%#x, debug11=%#x)\n",
13878 			i, idma->idma_qid[i], idma->idma_state[i],
13879 			idma->idma_stalled[i]/hz,
13880 			debug0, debug11);
13881 		t4_sge_decode_idma_state(adapter, idma->idma_state[i]);
13882 	}
13883 }
13884 
13885 /**
13886  *     t4_set_vf_mac - Set MAC address for the specified VF
13887  *     @adapter: The adapter
13888  *     @pf: the PF used to instantiate the VFs
13889  *     @vf: one of the VFs instantiated by the specified PF
13890  *     @naddr: the number of MAC addresses
13891  *     @addr: the MAC address(es) to be set to the specified VF
13892  */
t4_set_vf_mac(struct adapter * adapter,unsigned int pf,unsigned int vf,unsigned int naddr,u8 * addr)13893 int t4_set_vf_mac(struct adapter *adapter, unsigned int pf, unsigned int vf,
13894 		  unsigned int naddr, u8 *addr)
13895 {
13896 	struct fw_acl_mac_cmd cmd;
13897 
13898 	memset(&cmd, 0, sizeof(cmd));
13899 	cmd.op_to_vfn = cpu_to_be32(V_FW_CMD_OP(FW_ACL_MAC_CMD) |
13900 				    F_FW_CMD_REQUEST |
13901 				    F_FW_CMD_WRITE |
13902 				    V_FW_ACL_MAC_CMD_PFN(pf) |
13903 				    V_FW_ACL_MAC_CMD_VFN(vf));
13904 
13905 	/* Note: Do not enable the ACL */
13906 	cmd.en_to_len16 = cpu_to_be32((unsigned int)FW_LEN16(cmd));
13907 	cmd.nmac = naddr;
13908 
13909 	switch (pf) {
13910 	case 3:
13911 		memcpy(cmd.macaddr3, addr, sizeof(cmd.macaddr3));
13912 		break;
13913 	case 2:
13914 		memcpy(cmd.macaddr2, addr, sizeof(cmd.macaddr2));
13915 		break;
13916 	case 1:
13917 		memcpy(cmd.macaddr1, addr, sizeof(cmd.macaddr1));
13918 		break;
13919 	case 0:
13920 		memcpy(cmd.macaddr0, addr, sizeof(cmd.macaddr0));
13921 		break;
13922 	}
13923 
13924 	return t4_wr_mbox(adapter, adapter->mbox, &cmd, sizeof(cmd), &cmd);
13925 }
13926 
13927 /**
13928  *	t4_read_pace_tbl - read the pace table
13929  *	@adap: the adapter
13930  *	@pace_vals: holds the returned values
13931  *
13932  *	Returns the values of TP's pace table in microseconds.
13933  */
t4_read_pace_tbl(struct adapter * adap,unsigned int pace_vals[NTX_SCHED])13934 void t4_read_pace_tbl(struct adapter *adap, unsigned int pace_vals[NTX_SCHED])
13935 {
13936 	unsigned int i, v;
13937 
13938 	for (i = 0; i < NTX_SCHED; i++) {
13939 		t4_write_reg(adap, A_TP_PACE_TABLE, 0xffff0000 + i);
13940 		v = t4_read_reg(adap, A_TP_PACE_TABLE);
13941 		pace_vals[i] = dack_ticks_to_usec(adap, v);
13942 	}
13943 }
13944 
13945 /**
13946  *	t4_get_tx_sched - get the configuration of a Tx HW traffic scheduler
13947  *	@adap: the adapter
13948  *	@sched: the scheduler index
13949  *	@kbps: the byte rate in Kbps
13950  *	@ipg: the interpacket delay in tenths of nanoseconds
13951  *
13952  *	Return the current configuration of a HW Tx scheduler.
13953  */
t4_get_tx_sched(struct adapter * adap,unsigned int sched,unsigned int * kbps,unsigned int * ipg,bool sleep_ok)13954 void t4_get_tx_sched(struct adapter *adap, unsigned int sched, unsigned int *kbps,
13955 		     unsigned int *ipg, bool sleep_ok)
13956 {
13957 	unsigned int v, addr, bpt, cpt;
13958 
13959 	if (kbps) {
13960 		addr = A_TP_TX_MOD_Q1_Q0_RATE_LIMIT - sched / 2;
13961 		t4_tp_tm_pio_read(adap, &v, 1, addr, sleep_ok);
13962 		if (sched & 1)
13963 			v >>= 16;
13964 		bpt = (v >> 8) & 0xff;
13965 		cpt = v & 0xff;
13966 		if (!cpt)
13967 			*kbps = 0;	/* scheduler disabled */
13968 		else {
13969 			v = (adap->params.vpd.cclk * 1000) / cpt; /* ticks/s */
13970 			*kbps = (v * bpt) / 125;
13971 		}
13972 	}
13973 	if (ipg) {
13974 		addr = A_TP_TX_MOD_Q1_Q0_TIMER_SEPARATOR - sched / 2;
13975 		t4_tp_tm_pio_read(adap, &v, 1, addr, sleep_ok);
13976 		if (sched & 1)
13977 			v >>= 16;
13978 		v &= 0xffff;
13979 		*ipg = (10000 * v) / core_ticks_per_usec(adap);
13980 	}
13981 }
13982 
13983 /**
13984  *	t4_load_cfg - download config file
13985  *	@adap: the adapter
13986  *	@cfg_data: the cfg text file to write
13987  *	@size: text file size
13988  *
13989  *	Write the supplied config text file to the card's serial flash.
13990  */
t4_load_cfg(struct adapter * adap,const u8 * cfg_data,unsigned int size)13991 int t4_load_cfg(struct adapter *adap, const u8 *cfg_data, unsigned int size)
13992 {
13993 	int ret, i, n, cfg_addr;
13994 	unsigned int addr, len;
13995 	unsigned int flash_cfg_start_sec;
13996 
13997 	cfg_addr = t4_flash_cfg_addr(adap, &len);
13998 	if (cfg_addr < 0)
13999 		return cfg_addr;
14000 
14001 	if (size > len) {
14002 		CH_ERR(adap, "cfg file too large, max is %u bytes\n", len);
14003 		return -EFBIG;
14004 	}
14005 
14006 	flash_cfg_start_sec = cfg_addr / SF_SEC_SIZE;
14007 	i = DIV_ROUND_UP(len, SF_SEC_SIZE);
14008 	ret = t4_flash_erase_sectors(adap, flash_cfg_start_sec,
14009 				     flash_cfg_start_sec + i - 1);
14010 	/*
14011 	 * If size == 0 then we're simply erasing the FLASH sectors associated
14012 	 * with the on-adapter Firmware Configuration File.
14013 	 */
14014 	if (ret || size == 0)
14015 		goto out;
14016 
14017 	/* this will write to the flash up to SF_PAGE_SIZE at a time */
14018 	addr = cfg_addr;
14019 	for (i = 0; i < size; i += SF_PAGE_SIZE) {
14020 		n = min(size - i, SF_PAGE_SIZE);
14021 		ret = t4_write_flash(adap, addr, n, cfg_data, 1);
14022 		if (ret)
14023 			goto out;
14024 		addr += SF_PAGE_SIZE;
14025 		cfg_data += SF_PAGE_SIZE;
14026 	}
14027 
14028 out:
14029 	if (ret)
14030 		CH_ERR(adap, "config file %s failed %d\n",
14031 		       (size == 0 ? "clear" : "download"), ret);
14032 	return ret;
14033 }
14034 
14035 /**
14036  *	t5_fw_init_extern_mem - initialize the external memory
14037  *	@adap: the adapter
14038  *
14039  *	Initializes the external memory on T5.
14040  */
t5_fw_init_extern_mem(struct adapter * adap)14041 int t5_fw_init_extern_mem(struct adapter *adap)
14042 {
14043 	u32 params[1], val[1];
14044 	int ret;
14045 
14046 	if (!is_t5(adap))
14047 		return 0;
14048 
14049 	val[0] = 0xff; /* Initialize all MCs */
14050 	params[0] = (V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
14051 			V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_MCINIT));
14052 	ret = t4_set_params_timeout(adap, adap->mbox, adap->pf, 0, 1, params, val,
14053 			FW_CMD_MAX_TIMEOUT);
14054 
14055 	return ret;
14056 }
14057 
14058 /* BIOS boot headers */
14059 typedef struct pci_expansion_rom_header {
14060 	u8	signature[2]; /* ROM Signature. Should be 0xaa55 */
14061 	u8	reserved[22]; /* Reserved per processor Architecture data */
14062 	u8	pcir_offset[2]; /* Offset to PCI Data Structure */
14063 } pci_exp_rom_header_t; /* PCI_EXPANSION_ROM_HEADER */
14064 
14065 /* Legacy PCI Expansion ROM Header */
14066 typedef struct legacy_pci_expansion_rom_header {
14067 	u8	signature[2]; /* ROM Signature. Should be 0xaa55 */
14068 	u8	size512; /* Current Image Size in units of 512 bytes */
14069 	u8	initentry_point[4];
14070 	u8	cksum; /* Checksum computed on the entire Image */
14071 	u8	reserved[16]; /* Reserved */
14072 	u8	pcir_offset[2]; /* Offset to PCI Data Struture */
14073 } legacy_pci_exp_rom_header_t; /* LEGACY_PCI_EXPANSION_ROM_HEADER */
14074 
14075 /* EFI PCI Expansion ROM Header */
14076 typedef struct efi_pci_expansion_rom_header {
14077 	u8	signature[2]; // ROM signature. The value 0xaa55
14078 	u8	initialization_size[2]; /* Units 512. Includes this header */
14079 	u8	efi_signature[4]; /* Signature from EFI image header. 0x0EF1 */
14080 	u8	efi_subsystem[2]; /* Subsystem value for EFI image header */
14081 	u8	efi_machine_type[2]; /* Machine type from EFI image header */
14082 	u8	compression_type[2]; /* Compression type. */
14083 		/*
14084 		 * Compression type definition
14085 		 * 0x0: uncompressed
14086 		 * 0x1: Compressed
14087 		 * 0x2-0xFFFF: Reserved
14088 		 */
14089 	u8	reserved[8]; /* Reserved */
14090 	u8	efi_image_header_offset[2]; /* Offset to EFI Image */
14091 	u8	pcir_offset[2]; /* Offset to PCI Data Structure */
14092 } efi_pci_exp_rom_header_t; /* EFI PCI Expansion ROM Header */
14093 
14094 /* PCI Data Structure Format */
14095 typedef struct pcir_data_structure { /* PCI Data Structure */
14096 	u8	signature[4]; /* Signature. The string "PCIR" */
14097 	u8	vendor_id[2]; /* Vendor Identification */
14098 	u8	device_id[2]; /* Device Identification */
14099 	u8	vital_product[2]; /* Pointer to Vital Product Data */
14100 	u8	length[2]; /* PCIR Data Structure Length */
14101 	u8	revision; /* PCIR Data Structure Revision */
14102 	u8	class_code[3]; /* Class Code */
14103 	u8	image_length[2]; /* Image Length. Multiple of 512B */
14104 	u8	code_revision[2]; /* Revision Level of Code/Data */
14105 	u8	code_type; /* Code Type. */
14106 		/*
14107 		 * PCI Expansion ROM Code Types
14108 		 * 0x00: Intel IA-32, PC-AT compatible. Legacy
14109 		 * 0x01: Open Firmware standard for PCI. FCODE
14110 		 * 0x02: Hewlett-Packard PA RISC. HP reserved
14111 		 * 0x03: EFI Image. EFI
14112 		 * 0x04-0xFF: Reserved.
14113 		 */
14114 	u8	indicator; /* Indicator. Identifies the last image in the ROM */
14115 	u8	reserved[2]; /* Reserved */
14116 } pcir_data_t; /* PCI__DATA_STRUCTURE */
14117 
14118 /* BOOT constants */
14119 enum {
14120 	BOOT_FLASH_BOOT_ADDR = 0x0,/* start address of boot image in flash */
14121 	BOOT_SIGNATURE = 0xaa55,   /* signature of BIOS boot ROM */
14122 	BOOT_SIZE_INC = 512,       /* image size measured in 512B chunks */
14123 	BOOT_MIN_SIZE = sizeof(pci_exp_rom_header_t), /* basic header */
14124 	BOOT_MAX_SIZE = 1024*BOOT_SIZE_INC, /* 1 byte * length increment  */
14125 	VENDOR_ID = 0x1425, /* Vendor ID */
14126 	PCIR_SIGNATURE = 0x52494350 /* PCIR signature */
14127 };
14128 
14129 /*
14130  *	modify_device_id - Modifies the device ID of the Boot BIOS image
14131  *	@adatper: the device ID to write.
14132  *	@boot_data: the boot image to modify.
14133  *
14134  *	Write the supplied device ID to the boot BIOS image.
14135  */
modify_device_id(int device_id,u8 * boot_data)14136 static void modify_device_id(int device_id, u8 *boot_data)
14137 {
14138 	legacy_pci_exp_rom_header_t *header;
14139 	pcir_data_t *pcir_header;
14140 	u32 cur_header = 0;
14141 
14142 	/*
14143 	 * Loop through all chained images and change the device ID's
14144 	 */
14145 	while (1) {
14146 		header = (legacy_pci_exp_rom_header_t *) &boot_data[cur_header];
14147 		pcir_header = (pcir_data_t *) &boot_data[cur_header +
14148 			      le16_to_cpu(*(u16*)header->pcir_offset)];
14149 
14150 		/*
14151 		 * Only modify the Device ID if code type is Legacy or HP.
14152 		 * 0x00: Okay to modify
14153 		 * 0x01: FCODE. Do not be modify
14154 		 * 0x03: Okay to modify
14155 		 * 0x04-0xFF: Do not modify
14156 		 */
14157 		if (pcir_header->code_type == 0x00) {
14158 			u8 csum = 0;
14159 			int i;
14160 
14161 			/*
14162 			 * Modify Device ID to match current adatper
14163 			 */
14164 			*(u16*) pcir_header->device_id = device_id;
14165 
14166 			/*
14167 			 * Set checksum temporarily to 0.
14168 			 * We will recalculate it later.
14169 			 */
14170 			header->cksum = 0x0;
14171 
14172 			/*
14173 			 * Calculate and update checksum
14174 			 */
14175 			for (i = 0; i < (header->size512 * 512); i++)
14176 				csum += (u8)boot_data[cur_header + i];
14177 
14178 			/*
14179 			 * Invert summed value to create the checksum
14180 			 * Writing new checksum value directly to the boot data
14181 			 */
14182 			boot_data[cur_header + 7] = -csum;
14183 
14184 		} else if (pcir_header->code_type == 0x03) {
14185 
14186 			/*
14187 			 * Modify Device ID to match current adatper
14188 			 */
14189 			*(u16*) pcir_header->device_id = device_id;
14190 
14191 		}
14192 
14193 
14194 		/*
14195 		 * Check indicator element to identify if this is the last
14196 		 * image in the ROM.
14197 		 */
14198 		if (pcir_header->indicator & 0x80)
14199 			break;
14200 
14201 		/*
14202 		 * Move header pointer up to the next image in the ROM.
14203 		 */
14204 		cur_header += header->size512 * 512;
14205 	}
14206 }
14207 
14208 /*
14209  *	t4_load_boot - download boot flash
14210  *	@adapter: the adapter
14211  *	@boot_data: the boot image to write
14212  *	@boot_addr: offset in flash to write boot_data
14213  *	@size: image size
14214  *
14215  *	Write the supplied boot image to the card's serial flash.
14216  *	The boot image has the following sections: a 28-byte header and the
14217  *	boot image.
14218  */
t4_load_boot(struct adapter * adap,u8 * boot_data,unsigned int boot_addr,unsigned int size)14219 int t4_load_boot(struct adapter *adap, u8 *boot_data,
14220 		 unsigned int boot_addr, unsigned int size)
14221 {
14222 	pci_exp_rom_header_t *header;
14223 	int pcir_offset ;
14224 	pcir_data_t *pcir_header;
14225 	int ret, addr;
14226 	uint16_t device_id;
14227 	unsigned int i, start, len;
14228 	unsigned int boot_sector = boot_addr * 1024;
14229 
14230 	/*
14231 	 * Make sure the boot image does not exceed its available space.
14232 	 */
14233 	len = 0;
14234 	start = t4_flash_loc_start(adap, FLASH_LOC_BOOT_AREA, &len);
14235 	if (boot_sector + size > start + len) {
14236 		CH_ERR(adap, "boot data is larger than available BOOT area\n");
14237 		return -EFBIG;
14238 	}
14239 
14240 	/*
14241 	 * The boot sector is comprised of the Expansion-ROM boot, iSCSI boot,
14242 	 * and Boot configuration data sections. These 3 boot sections span
14243 	 * the entire FLASH_LOC_BOOT_AREA.
14244 	 */
14245 	i = DIV_ROUND_UP(size ? size : len, SF_SEC_SIZE);
14246 	ret = t4_flash_erase_sectors(adap, boot_sector >> 16,
14247 				     (boot_sector >> 16) + i - 1);
14248 
14249 	/*
14250 	 * If size == 0 then we're simply erasing the FLASH sectors associated
14251 	 * with the on-adapter option ROM file
14252 	 */
14253 	if (ret || (size == 0))
14254 		goto out;
14255 
14256 	/* Get boot header */
14257 	header = (pci_exp_rom_header_t *)boot_data;
14258 	pcir_offset = le16_to_cpu(*(u16 *)header->pcir_offset);
14259 	/* PCIR Data Structure */
14260 	pcir_header = (pcir_data_t *) &boot_data[pcir_offset];
14261 
14262 	/*
14263 	 * Perform some primitive sanity testing to avoid accidentally
14264 	 * writing garbage over the boot sectors.  We ought to check for
14265 	 * more but it's not worth it for now ...
14266 	 */
14267 	if (size < BOOT_MIN_SIZE || size > BOOT_MAX_SIZE) {
14268 		CH_ERR(adap, "boot image too small/large\n");
14269 		return -EFBIG;
14270 	}
14271 
14272 #ifndef CHELSIO_T4_DIAGS
14273 	/*
14274 	 * Check BOOT ROM header signature
14275 	 */
14276 	if (le16_to_cpu(*(u16*)header->signature) != BOOT_SIGNATURE ) {
14277 		CH_ERR(adap, "Boot image missing signature\n");
14278 		return -EINVAL;
14279 	}
14280 
14281 	/*
14282 	 * Check PCI header signature
14283 	 */
14284 	if (le32_to_cpu(*(u32*)pcir_header->signature) != PCIR_SIGNATURE) {
14285 		CH_ERR(adap, "PCI header missing signature\n");
14286 		return -EINVAL;
14287 	}
14288 
14289 	/*
14290 	 * Check Vendor ID matches Chelsio ID
14291 	 */
14292 	if (le16_to_cpu(*(u16*)pcir_header->vendor_id) != VENDOR_ID) {
14293 		CH_ERR(adap, "Vendor ID missing signature\n");
14294 		return -EINVAL;
14295 	}
14296 #endif
14297 
14298 	/*
14299 	 * Retrieve adapter's device ID
14300 	 */
14301 	t4_os_pci_read_cfg2(adap, PCI_DEVICE_ID, &device_id);
14302 	/* Want to deal with PF 0 so I strip off PF 4 indicator */
14303 	device_id = device_id & 0xf0ff;
14304 
14305 	/*
14306 	 * Check PCIE Device ID
14307 	 */
14308 	if (le16_to_cpu(*(u16*)pcir_header->device_id) != device_id) {
14309 		/*
14310 		 * Change the device ID in the Boot BIOS image to match
14311 		 * the Device ID of the current adapter.
14312 		 */
14313 		modify_device_id(device_id, boot_data);
14314 	}
14315 
14316 	/*
14317 	 * Skip over the first SF_PAGE_SIZE worth of data and write it after
14318 	 * we finish copying the rest of the boot image. This will ensure
14319 	 * that the BIOS boot header will only be written if the boot image
14320 	 * was written in full.
14321 	 */
14322 	addr = boot_sector;
14323 	for (size -= SF_PAGE_SIZE; size; size -= SF_PAGE_SIZE) {
14324 		addr += SF_PAGE_SIZE;
14325 		boot_data += SF_PAGE_SIZE;
14326 		ret = t4_write_flash(adap, addr, SF_PAGE_SIZE, boot_data, 0);
14327 		if (ret)
14328 			goto out;
14329 	}
14330 
14331 	ret = t4_write_flash(adap, boot_sector, SF_PAGE_SIZE,
14332 			     (const u8 *)header, 0);
14333 
14334 out:
14335 	if (ret)
14336 		CH_ERR(adap, "boot image download failed, error %d\n", ret);
14337 	return ret;
14338 }
14339 
14340 /*
14341  *	t4_flash_bootcfg_addr - return the address of the flash optionrom configuration
14342  *	@adapter: the adapter
14343  *
14344  *	Return the address within the flash where the OptionROM Configuration
14345  *	is stored, or an error if the device FLASH is too small to contain
14346  *	a OptionROM Configuration.
14347  */
t4_flash_bootcfg_addr(struct adapter * adapter,unsigned int * lenp)14348 static int t4_flash_bootcfg_addr(struct adapter *adapter, unsigned int *lenp)
14349 {
14350 	unsigned int len = 0;
14351 	const int start = t4_flash_loc_start(adapter, FLASH_LOC_BOOTCFG, &len);
14352 
14353 	/*
14354 	 * If the device FLASH isn't large enough to hold a Firmware
14355 	 * Configuration File, return an error.
14356 	 */
14357 	if (adapter->params.sf_size < start + len)
14358 		return -ENOSPC;
14359 	if (lenp != NULL)
14360 		*lenp = len;
14361 	return (start);
14362 }
14363 
t4_load_bootcfg(struct adapter * adap,const u8 * cfg_data,unsigned int size)14364 int t4_load_bootcfg(struct adapter *adap,const u8 *cfg_data, unsigned int size)
14365 {
14366 	int ret, i, n, cfg_addr;
14367 	unsigned int addr, len;
14368 	unsigned int flash_cfg_start_sec;
14369 
14370 	cfg_addr = t4_flash_bootcfg_addr(adap, &len);
14371 	if (cfg_addr < 0)
14372 		return cfg_addr;
14373 
14374 	if (size > len) {
14375 		CH_ERR(adap, "bootcfg file too large, max is %u bytes\n", len);
14376 		return -EFBIG;
14377 	}
14378 
14379 	flash_cfg_start_sec = cfg_addr / SF_SEC_SIZE;
14380 	i = DIV_ROUND_UP(len, SF_SEC_SIZE);
14381 	ret = t4_flash_erase_sectors(adap, flash_cfg_start_sec,
14382 					flash_cfg_start_sec + i - 1);
14383 
14384 	/*
14385 	 * If size == 0 then we're simply erasing the FLASH sectors associated
14386 	 * with the on-adapter OptionROM Configuration File.
14387 	 */
14388 	if (ret || size == 0)
14389 		goto out;
14390 
14391 	/* this will write to the flash up to SF_PAGE_SIZE at a time */
14392 	addr = cfg_addr;
14393 	for (i = 0; i < size; i += SF_PAGE_SIZE) {
14394 		n = min(size - i, SF_PAGE_SIZE);
14395 		ret = t4_write_flash(adap, addr, n, cfg_data, 0);
14396 		if (ret)
14397 			goto out;
14398 		addr += SF_PAGE_SIZE;
14399 		cfg_data += SF_PAGE_SIZE;
14400 	}
14401 
14402 out:
14403 	if (ret)
14404 		CH_ERR(adap, "boot config data %s failed %d\n",
14405 				(size == 0 ? "clear" : "download"), ret);
14406 	return ret;
14407 }
14408 
14409 /**
14410  *	t4_set_filter_cfg - set up filter mode/mask and ingress config.
14411  *	@adap: the adapter
14412  *	@mode: a bitmap selecting which optional filter components to enable
14413  *	@mask: a bitmap selecting which components to enable in filter mask
14414  *	@vnic_mode: the ingress config/vnic mode setting
14415  *
14416  *	Sets the filter mode and mask by selecting the optional components to
14417  *	enable in filter tuples.  Returns 0 on success and a negative error if
14418  *	the requested mode needs more bits than are available for optional
14419  *	components.  The filter mask must be a subset of the filter mode.
14420  */
t4_set_filter_cfg(struct adapter * adap,int mode,int mask,int vnic_mode)14421 int t4_set_filter_cfg(struct adapter *adap, int mode, int mask, int vnic_mode)
14422 {
14423 	int i, nbits, rc;
14424 	uint32_t param, val;
14425 	uint16_t fmode, fmask;
14426 	const int maxbits = adap->chip_params->filter_opt_len;
14427 	const int nopt = adap->chip_params->filter_num_opt;
14428 	int width;
14429 
14430 	if (mode != -1 || mask != -1) {
14431 		if (mode != -1) {
14432 			fmode = mode;
14433 			nbits = 0;
14434 			for (i = 0; i < nopt; i++) {
14435 				if (fmode & (1 << i))
14436 					nbits += t4_filter_field_width(adap, i);
14437 			}
14438 			if (nbits > maxbits) {
14439 				CH_ERR(adap, "optional fields in the filter "
14440 				    "mode (0x%x) add up to %d bits "
14441 				    "(must be <= %db).  Remove some fields and "
14442 				    "try again.\n", fmode, nbits, maxbits);
14443 				return -E2BIG;
14444 			}
14445 
14446 			/*
14447 			 * Hardware < T7 wants the bits to be maxed out.  Keep
14448 			 * setting them until there's no room for more.
14449 			 */
14450 			if (chip_id(adap) < CHELSIO_T7) {
14451 				for (i = 0; i < nopt; i++) {
14452 					if (fmode & (1 << i))
14453 						continue;
14454 					width = t4_filter_field_width(adap, i);
14455 					if (nbits + width <= maxbits) {
14456 						fmode |= 1 << i;
14457 						nbits += width;
14458 						if (nbits == maxbits)
14459 							break;
14460 					}
14461 				}
14462 			}
14463 
14464 			fmask = fmode & adap->params.tp.filter_mask;
14465 			if (fmask != adap->params.tp.filter_mask) {
14466 				CH_WARN(adap,
14467 				    "filter mask will be changed from 0x%x to "
14468 				    "0x%x to comply with the filter mode (0x%x).\n",
14469 				    adap->params.tp.filter_mask, fmask, fmode);
14470 			}
14471 		} else {
14472 			fmode = adap->params.tp.filter_mode;
14473 			fmask = mask;
14474 			if ((fmode | fmask) != fmode) {
14475 				CH_ERR(adap,
14476 				    "filter mask (0x%x) must be a subset of "
14477 				    "the filter mode (0x%x).\n", fmask, fmode);
14478 				return -EINVAL;
14479 			}
14480 		}
14481 
14482 		param = V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
14483 		    V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_FILTER) |
14484 		    V_FW_PARAMS_PARAM_Y(FW_PARAM_DEV_FILTER_MODE_MASK);
14485 		val = V_FW_PARAMS_PARAM_FILTER_MODE(fmode) |
14486 		    V_FW_PARAMS_PARAM_FILTER_MASK(fmask);
14487 		rc = t4_set_params(adap, adap->mbox, adap->pf, 0, 1, &param,
14488 		    &val);
14489 		if (rc < 0)
14490 			return rc;
14491 	}
14492 
14493 	if (vnic_mode != -1) {
14494 		param = V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
14495 		    V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_FILTER) |
14496 		    V_FW_PARAMS_PARAM_Y(FW_PARAM_DEV_FILTER_VNIC_MODE);
14497 		val = vnic_mode;
14498 		rc = t4_set_params(adap, adap->mbox, adap->pf, 0, 1, &param,
14499 		    &val);
14500 		if (rc < 0)
14501 			return rc;
14502 	}
14503 
14504 	/* Refresh. */
14505 	read_filter_mode_and_ingress_config(adap);
14506 
14507 	return 0;
14508 }
14509 
14510 /**
14511  *	t4_clr_port_stats - clear port statistics
14512  *	@adap: the adapter
14513  *	@idx: the port index
14514  *
14515  *	Clear HW statistics for the given port.
14516  */
t4_clr_port_stats(struct adapter * adap,int idx)14517 void t4_clr_port_stats(struct adapter *adap, int idx)
14518 {
14519 	struct port_info *pi;
14520 	int i, port_id, tx_chan;
14521 	u32 bgmap, port_base_addr;
14522 
14523 	port_id  = adap->port_map[idx];
14524 	MPASS(port_id >= 0 && port_id <= adap->params.nports);
14525 	pi = adap->port[port_id];
14526 
14527 	for (tx_chan = pi->tx_chan;
14528 	    tx_chan < pi->tx_chan + adap->params.tp.lb_nchan; tx_chan++) {
14529 		port_base_addr = t4_port_reg(adap, tx_chan, 0);
14530 
14531 		for (i = A_MPS_PORT_STAT_TX_PORT_BYTES_L;
14532 				i <= A_MPS_PORT_STAT_TX_PORT_PPP7_H; i += 8)
14533 			t4_write_reg(adap, port_base_addr + i, 0);
14534 		for (i = A_MPS_PORT_STAT_RX_PORT_BYTES_L;
14535 				i <= A_MPS_PORT_STAT_RX_PORT_LESS_64B_H; i += 8)
14536 			t4_write_reg(adap, port_base_addr + i, 0);
14537 	}
14538 	bgmap = pi->mps_bg_map;
14539 	for (i = 0; i < 4; i++)
14540 		if (bgmap & (1 << i)) {
14541 			t4_write_reg(adap,
14542 			A_MPS_STAT_RX_BG_0_MAC_DROP_FRAME_L + i * 8, 0);
14543 			t4_write_reg(adap,
14544 			A_MPS_STAT_RX_BG_0_MAC_TRUNC_FRAME_L + i * 8, 0);
14545 		}
14546 }
14547 
14548 /**
14549  *	t4_i2c_io - read/write I2C data from adapter
14550  *	@adap: the adapter
14551  *	@port: Port number if per-port device; <0 if not
14552  *	@devid: per-port device ID or absolute device ID
14553  *	@offset: byte offset into device I2C space
14554  *	@len: byte length of I2C space data
14555  *	@buf: buffer in which to return I2C data for read
14556  *	      buffer which holds the I2C data for write
14557  *	@write: if true, do a write; else do a read
14558  *	Reads/Writes the I2C data from/to the indicated device and location.
14559  */
t4_i2c_io(struct adapter * adap,unsigned int mbox,int port,unsigned int devid,unsigned int offset,unsigned int len,u8 * buf,bool write)14560 int t4_i2c_io(struct adapter *adap, unsigned int mbox,
14561 	      int port, unsigned int devid,
14562 	      unsigned int offset, unsigned int len,
14563 	      u8 *buf, bool write)
14564 {
14565 	struct fw_ldst_cmd ldst_cmd, ldst_rpl;
14566 	unsigned int i2c_max = sizeof(ldst_cmd.u.i2c.data);
14567 	int ret = 0;
14568 
14569 	if (len > I2C_PAGE_SIZE)
14570 		return -EINVAL;
14571 
14572 	/* Dont allow reads that spans multiple pages */
14573 	if (offset < I2C_PAGE_SIZE && offset + len > I2C_PAGE_SIZE)
14574 		return -EINVAL;
14575 
14576 	memset(&ldst_cmd, 0, sizeof(ldst_cmd));
14577 	ldst_cmd.op_to_addrspace =
14578 		cpu_to_be32(V_FW_CMD_OP(FW_LDST_CMD) |
14579 			    F_FW_CMD_REQUEST |
14580 			    (write ? F_FW_CMD_WRITE : F_FW_CMD_READ) |
14581 			    V_FW_LDST_CMD_ADDRSPACE(FW_LDST_ADDRSPC_I2C));
14582 	ldst_cmd.cycles_to_len16 = cpu_to_be32(FW_LEN16(ldst_cmd));
14583 	ldst_cmd.u.i2c.pid = (port < 0 ? 0xff : port);
14584 	ldst_cmd.u.i2c.did = devid;
14585 
14586 	while (len > 0) {
14587 		unsigned int i2c_len = (len < i2c_max) ? len : i2c_max;
14588 
14589 		ldst_cmd.u.i2c.boffset = offset;
14590 		ldst_cmd.u.i2c.blen = i2c_len;
14591 
14592 		if (write)
14593 			memcpy(ldst_cmd.u.i2c.data, buf, i2c_len);
14594 
14595 		ret = t4_wr_mbox(adap, mbox, &ldst_cmd, sizeof(ldst_cmd),
14596 				 write ? NULL : &ldst_rpl);
14597 		if (ret)
14598 			break;
14599 
14600 		if (!write)
14601 			memcpy(buf, ldst_rpl.u.i2c.data, i2c_len);
14602 		offset += i2c_len;
14603 		buf += i2c_len;
14604 		len -= i2c_len;
14605 	}
14606 
14607 	return ret;
14608 }
14609 
t4_i2c_rd(struct adapter * adap,unsigned int mbox,int port,unsigned int devid,unsigned int offset,unsigned int len,u8 * buf)14610 int t4_i2c_rd(struct adapter *adap, unsigned int mbox,
14611 	      int port, unsigned int devid,
14612 	      unsigned int offset, unsigned int len,
14613 	      u8 *buf)
14614 {
14615 	return t4_i2c_io(adap, mbox, port, devid, offset, len, buf, false);
14616 }
14617 
t4_i2c_wr(struct adapter * adap,unsigned int mbox,int port,unsigned int devid,unsigned int offset,unsigned int len,u8 * buf)14618 int t4_i2c_wr(struct adapter *adap, unsigned int mbox,
14619 	      int port, unsigned int devid,
14620 	      unsigned int offset, unsigned int len,
14621 	      u8 *buf)
14622 {
14623 	return t4_i2c_io(adap, mbox, port, devid, offset, len, buf, true);
14624 }
14625 
14626 /**
14627  * 	t4_sge_ctxt_rd - read an SGE context through FW
14628  * 	@adap: the adapter
14629  * 	@mbox: mailbox to use for the FW command
14630  * 	@cid: the context id
14631  * 	@ctype: the context type
14632  * 	@data: where to store the context data
14633  *
14634  * 	Issues a FW command through the given mailbox to read an SGE context.
14635  */
t4_sge_ctxt_rd(struct adapter * adap,unsigned int mbox,unsigned int cid,enum ctxt_type ctype,u32 * data)14636 int t4_sge_ctxt_rd(struct adapter *adap, unsigned int mbox, unsigned int cid,
14637 		   enum ctxt_type ctype, u32 *data)
14638 {
14639 	int ret;
14640 	struct fw_ldst_cmd c;
14641 
14642 	if (ctype == CTXT_EGRESS)
14643 		ret = FW_LDST_ADDRSPC_SGE_EGRC;
14644 	else if (ctype == CTXT_INGRESS)
14645 		ret = FW_LDST_ADDRSPC_SGE_INGC;
14646 	else if (ctype == CTXT_FLM)
14647 		ret = FW_LDST_ADDRSPC_SGE_FLMC;
14648 	else
14649 		ret = FW_LDST_ADDRSPC_SGE_CONMC;
14650 
14651 	memset(&c, 0, sizeof(c));
14652 	c.op_to_addrspace = cpu_to_be32(V_FW_CMD_OP(FW_LDST_CMD) |
14653 					F_FW_CMD_REQUEST | F_FW_CMD_READ |
14654 					V_FW_LDST_CMD_ADDRSPACE(ret));
14655 	c.cycles_to_len16 = cpu_to_be32(FW_LEN16(c));
14656 	c.u.idctxt.physid = cpu_to_be32(cid);
14657 
14658 	ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
14659 	if (ret == 0) {
14660 		data[0] = be32_to_cpu(c.u.idctxt.ctxt_data0);
14661 		data[1] = be32_to_cpu(c.u.idctxt.ctxt_data1);
14662 		data[2] = be32_to_cpu(c.u.idctxt.ctxt_data2);
14663 		data[3] = be32_to_cpu(c.u.idctxt.ctxt_data3);
14664 		data[4] = be32_to_cpu(c.u.idctxt.ctxt_data4);
14665 		data[5] = be32_to_cpu(c.u.idctxt.ctxt_data5);
14666 		if (chip_id(adap) > CHELSIO_T6)
14667 			data[6] = be32_to_cpu(c.u.idctxt.ctxt_data6);
14668 	}
14669 	return ret;
14670 }
14671 
14672 /**
14673  * 	t4_sge_ctxt_rd_bd - read an SGE context bypassing FW
14674  * 	@adap: the adapter
14675  * 	@cid: the context id
14676  * 	@ctype: the context type
14677  * 	@data: where to store the context data
14678  *
14679  * 	Reads an SGE context directly, bypassing FW.  This is only for
14680  * 	debugging when FW is unavailable.
14681  */
t4_sge_ctxt_rd_bd(struct adapter * adap,unsigned int cid,enum ctxt_type ctype,u32 * data)14682 int t4_sge_ctxt_rd_bd(struct adapter *adap, unsigned int cid, enum ctxt_type ctype,
14683 		      u32 *data)
14684 {
14685 	int i, ret;
14686 
14687 	t4_write_reg(adap, A_SGE_CTXT_CMD, V_CTXTQID(cid) | V_CTXTTYPE(ctype));
14688 	ret = t4_wait_op_done(adap, A_SGE_CTXT_CMD, F_BUSY, 0, 3, 1);
14689 	if (!ret) {
14690 		for (i = A_SGE_CTXT_DATA0; i <= A_SGE_CTXT_DATA5; i += 4)
14691 			*data++ = t4_read_reg(adap, i);
14692 		if (chip_id(adap) > CHELSIO_T6)
14693 			*data++ = t4_read_reg(adap, i);
14694 	}
14695 	return ret;
14696 }
14697 
t4_sched_config(struct adapter * adapter,int type,int minmaxen,int sleep_ok)14698 int t4_sched_config(struct adapter *adapter, int type, int minmaxen,
14699     int sleep_ok)
14700 {
14701 	struct fw_sched_cmd cmd;
14702 
14703 	memset(&cmd, 0, sizeof(cmd));
14704 	cmd.op_to_write = cpu_to_be32(V_FW_CMD_OP(FW_SCHED_CMD) |
14705 				      F_FW_CMD_REQUEST |
14706 				      F_FW_CMD_WRITE);
14707 	cmd.retval_len16 = cpu_to_be32(FW_LEN16(cmd));
14708 
14709 	cmd.u.config.sc = FW_SCHED_SC_CONFIG;
14710 	cmd.u.config.type = type;
14711 	cmd.u.config.minmaxen = minmaxen;
14712 
14713 	return t4_wr_mbox_meat(adapter,adapter->mbox, &cmd, sizeof(cmd),
14714 			       NULL, sleep_ok);
14715 }
14716 
t4_sched_params(struct adapter * adapter,int type,int level,int mode,int rateunit,int ratemode,int channel,int cl,int minrate,int maxrate,int weight,int pktsize,int burstsize,int sleep_ok)14717 int t4_sched_params(struct adapter *adapter, int type, int level, int mode,
14718 		    int rateunit, int ratemode, int channel, int cl,
14719 		    int minrate, int maxrate, int weight, int pktsize,
14720 		    int burstsize, int sleep_ok)
14721 {
14722 	struct fw_sched_cmd cmd;
14723 
14724 	memset(&cmd, 0, sizeof(cmd));
14725 	cmd.op_to_write = cpu_to_be32(V_FW_CMD_OP(FW_SCHED_CMD) |
14726 				      F_FW_CMD_REQUEST |
14727 				      F_FW_CMD_WRITE);
14728 	cmd.retval_len16 = cpu_to_be32(FW_LEN16(cmd));
14729 
14730 	cmd.u.params.sc = FW_SCHED_SC_PARAMS;
14731 	cmd.u.params.type = type;
14732 	cmd.u.params.level = level;
14733 	cmd.u.params.mode = mode;
14734 	cmd.u.params.ch = channel;
14735 	cmd.u.params.cl = cl;
14736 	cmd.u.params.unit = rateunit;
14737 	cmd.u.params.rate = ratemode;
14738 	cmd.u.params.min = cpu_to_be32(minrate);
14739 	cmd.u.params.max = cpu_to_be32(maxrate);
14740 	cmd.u.params.weight = cpu_to_be16(weight);
14741 	cmd.u.params.pktsize = cpu_to_be16(pktsize);
14742 	cmd.u.params.burstsize = cpu_to_be16(burstsize);
14743 
14744 	return t4_wr_mbox_meat(adapter,adapter->mbox, &cmd, sizeof(cmd),
14745 			       NULL, sleep_ok);
14746 }
14747 
t4_sched_params_ch_rl(struct adapter * adapter,int channel,int ratemode,unsigned int maxrate,int sleep_ok)14748 int t4_sched_params_ch_rl(struct adapter *adapter, int channel, int ratemode,
14749     unsigned int maxrate, int sleep_ok)
14750 {
14751 	struct fw_sched_cmd cmd;
14752 
14753 	memset(&cmd, 0, sizeof(cmd));
14754 	cmd.op_to_write = cpu_to_be32(V_FW_CMD_OP(FW_SCHED_CMD) |
14755 				      F_FW_CMD_REQUEST |
14756 				      F_FW_CMD_WRITE);
14757 	cmd.retval_len16 = cpu_to_be32(FW_LEN16(cmd));
14758 
14759 	cmd.u.params.sc = FW_SCHED_SC_PARAMS;
14760 	cmd.u.params.type = FW_SCHED_TYPE_PKTSCHED;
14761 	cmd.u.params.level = FW_SCHED_PARAMS_LEVEL_CH_RL;
14762 	cmd.u.params.ch = channel;
14763 	cmd.u.params.rate = ratemode;		/* REL or ABS */
14764 	cmd.u.params.max = cpu_to_be32(maxrate);/*  %  or kbps */
14765 
14766 	return t4_wr_mbox_meat(adapter,adapter->mbox, &cmd, sizeof(cmd),
14767 			       NULL, sleep_ok);
14768 }
14769 
t4_sched_params_cl_wrr(struct adapter * adapter,int channel,int cl,int weight,int sleep_ok)14770 int t4_sched_params_cl_wrr(struct adapter *adapter, int channel, int cl,
14771     int weight, int sleep_ok)
14772 {
14773 	struct fw_sched_cmd cmd;
14774 
14775 	if (weight < 0 || weight > 100)
14776 		return -EINVAL;
14777 
14778 	memset(&cmd, 0, sizeof(cmd));
14779 	cmd.op_to_write = cpu_to_be32(V_FW_CMD_OP(FW_SCHED_CMD) |
14780 				      F_FW_CMD_REQUEST |
14781 				      F_FW_CMD_WRITE);
14782 	cmd.retval_len16 = cpu_to_be32(FW_LEN16(cmd));
14783 
14784 	cmd.u.params.sc = FW_SCHED_SC_PARAMS;
14785 	cmd.u.params.type = FW_SCHED_TYPE_PKTSCHED;
14786 	cmd.u.params.level = FW_SCHED_PARAMS_LEVEL_CL_WRR;
14787 	cmd.u.params.ch = channel;
14788 	cmd.u.params.cl = cl;
14789 	cmd.u.params.weight = cpu_to_be16(weight);
14790 
14791 	return t4_wr_mbox_meat(adapter,adapter->mbox, &cmd, sizeof(cmd),
14792 			       NULL, sleep_ok);
14793 }
14794 
t4_sched_params_cl_rl_kbps(struct adapter * adapter,int channel,int cl,int mode,unsigned int maxrate,int pktsize,int sleep_ok)14795 int t4_sched_params_cl_rl_kbps(struct adapter *adapter, int channel, int cl,
14796     int mode, unsigned int maxrate, int pktsize, int sleep_ok)
14797 {
14798 	struct fw_sched_cmd cmd;
14799 
14800 	memset(&cmd, 0, sizeof(cmd));
14801 	cmd.op_to_write = cpu_to_be32(V_FW_CMD_OP(FW_SCHED_CMD) |
14802 				      F_FW_CMD_REQUEST |
14803 				      F_FW_CMD_WRITE);
14804 	cmd.retval_len16 = cpu_to_be32(FW_LEN16(cmd));
14805 
14806 	cmd.u.params.sc = FW_SCHED_SC_PARAMS;
14807 	cmd.u.params.type = FW_SCHED_TYPE_PKTSCHED;
14808 	cmd.u.params.level = FW_SCHED_PARAMS_LEVEL_CL_RL;
14809 	cmd.u.params.mode = mode;
14810 	cmd.u.params.ch = channel;
14811 	cmd.u.params.cl = cl;
14812 	cmd.u.params.unit = FW_SCHED_PARAMS_UNIT_BITRATE;
14813 	cmd.u.params.rate = FW_SCHED_PARAMS_RATE_ABS;
14814 	cmd.u.params.max = cpu_to_be32(maxrate);
14815 	cmd.u.params.pktsize = cpu_to_be16(pktsize);
14816 
14817 	return t4_wr_mbox_meat(adapter,adapter->mbox, &cmd, sizeof(cmd),
14818 			       NULL, sleep_ok);
14819 }
14820 
14821 /*
14822  *	t4_config_watchdog - configure (enable/disable) a watchdog timer
14823  *	@adapter: the adapter
14824  * 	@mbox: mailbox to use for the FW command
14825  * 	@pf: the PF owning the queue
14826  * 	@vf: the VF owning the queue
14827  *	@timeout: watchdog timeout in ms
14828  *	@action: watchdog timer / action
14829  *
14830  *	There are separate watchdog timers for each possible watchdog
14831  *	action.  Configure one of the watchdog timers by setting a non-zero
14832  *	timeout.  Disable a watchdog timer by using a timeout of zero.
14833  */
t4_config_watchdog(struct adapter * adapter,unsigned int mbox,unsigned int pf,unsigned int vf,unsigned int timeout,unsigned int action)14834 int t4_config_watchdog(struct adapter *adapter, unsigned int mbox,
14835 		       unsigned int pf, unsigned int vf,
14836 		       unsigned int timeout, unsigned int action)
14837 {
14838 	struct fw_watchdog_cmd wdog;
14839 	unsigned int ticks;
14840 
14841 	/*
14842 	 * The watchdog command expects a timeout in units of 10ms so we need
14843 	 * to convert it here (via rounding) and force a minimum of one 10ms
14844 	 * "tick" if the timeout is non-zero but the conversion results in 0
14845 	 * ticks.
14846 	 */
14847 	ticks = (timeout + 5)/10;
14848 	if (timeout && !ticks)
14849 		ticks = 1;
14850 
14851 	memset(&wdog, 0, sizeof wdog);
14852 	wdog.op_to_vfn = cpu_to_be32(V_FW_CMD_OP(FW_WATCHDOG_CMD) |
14853 				     F_FW_CMD_REQUEST |
14854 				     F_FW_CMD_WRITE |
14855 				     V_FW_PARAMS_CMD_PFN(pf) |
14856 				     V_FW_PARAMS_CMD_VFN(vf));
14857 	wdog.retval_len16 = cpu_to_be32(FW_LEN16(wdog));
14858 	wdog.timeout = cpu_to_be32(ticks);
14859 	wdog.action = cpu_to_be32(action);
14860 
14861 	return t4_wr_mbox(adapter, mbox, &wdog, sizeof wdog, NULL);
14862 }
14863 
t4_get_devlog_level(struct adapter * adapter,unsigned int * level)14864 int t4_get_devlog_level(struct adapter *adapter, unsigned int *level)
14865 {
14866 	struct fw_devlog_cmd devlog_cmd;
14867 	int ret;
14868 
14869 	memset(&devlog_cmd, 0, sizeof(devlog_cmd));
14870 	devlog_cmd.op_to_write = cpu_to_be32(V_FW_CMD_OP(FW_DEVLOG_CMD) |
14871 					     F_FW_CMD_REQUEST | F_FW_CMD_READ);
14872 	devlog_cmd.retval_len16 = cpu_to_be32(FW_LEN16(devlog_cmd));
14873 	ret = t4_wr_mbox(adapter, adapter->mbox, &devlog_cmd,
14874 			 sizeof(devlog_cmd), &devlog_cmd);
14875 	if (ret)
14876 		return ret;
14877 
14878 	*level = devlog_cmd.level;
14879 	return 0;
14880 }
14881 
t4_set_devlog_level(struct adapter * adapter,unsigned int level)14882 int t4_set_devlog_level(struct adapter *adapter, unsigned int level)
14883 {
14884 	struct fw_devlog_cmd devlog_cmd;
14885 
14886 	memset(&devlog_cmd, 0, sizeof(devlog_cmd));
14887 	devlog_cmd.op_to_write = cpu_to_be32(V_FW_CMD_OP(FW_DEVLOG_CMD) |
14888 					     F_FW_CMD_REQUEST |
14889 					     F_FW_CMD_WRITE);
14890 	devlog_cmd.level = level;
14891 	devlog_cmd.retval_len16 = cpu_to_be32(FW_LEN16(devlog_cmd));
14892 	return t4_wr_mbox(adapter, adapter->mbox, &devlog_cmd,
14893 			  sizeof(devlog_cmd), &devlog_cmd);
14894 }
14895 
t4_configure_add_smac(struct adapter * adap)14896 int t4_configure_add_smac(struct adapter *adap)
14897 {
14898 	unsigned int param, val;
14899 	int ret = 0;
14900 
14901 	adap->params.smac_add_support = 0;
14902 	param = (V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
14903 		  V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_ADD_SMAC));
14904 	/* Query FW to check if FW supports adding source mac address
14905 	 * to TCAM feature or not.
14906 	 * If FW returns 1, driver can use this feature and driver need to send
14907 	 * FW_PARAMS_PARAM_DEV_ADD_SMAC write command with value 1 to
14908 	 * enable adding smac to TCAM.
14909 	 */
14910 	ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1, &param, &val);
14911 	if (ret)
14912 		return ret;
14913 
14914 	if (val == 1) {
14915 		ret = t4_set_params(adap, adap->mbox, adap->pf, 0, 1,
14916 				    &param, &val);
14917 		if (!ret)
14918 			/* Firmware allows adding explicit TCAM entries.
14919 			 * Save this internally.
14920 			 */
14921 			adap->params.smac_add_support = 1;
14922 	}
14923 
14924 	return ret;
14925 }
14926 
t4_configure_ringbb(struct adapter * adap)14927 int t4_configure_ringbb(struct adapter *adap)
14928 {
14929 	unsigned int param, val;
14930 	int ret = 0;
14931 
14932 	param = (V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
14933 		  V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_RING_BACKBONE));
14934 	/* Query FW to check if FW supports ring switch feature or not.
14935 	 * If FW returns 1, driver can use this feature and driver need to send
14936 	 * FW_PARAMS_PARAM_DEV_RING_BACKBONE write command with value 1 to
14937 	 * enable the ring backbone configuration.
14938 	 */
14939 	ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1, &param, &val);
14940 	if (ret < 0) {
14941 		CH_ERR(adap, "Querying FW using Ring backbone params command failed, err=%d\n",
14942 			ret);
14943 		goto out;
14944 	}
14945 
14946 	if (val != 1) {
14947 		CH_ERR(adap, "FW doesnot support ringbackbone features\n");
14948 		goto out;
14949 	}
14950 
14951 	ret = t4_set_params(adap, adap->mbox, adap->pf, 0, 1, &param, &val);
14952 	if (ret < 0) {
14953 		CH_ERR(adap, "Could not set Ringbackbone, err= %d\n",
14954 			ret);
14955 		goto out;
14956 	}
14957 
14958 out:
14959 	return ret;
14960 }
14961 
14962 /*
14963  *	t4_set_vlan_acl - Set a VLAN id for the specified VF
14964  *	@adapter: the adapter
14965  *	@mbox: mailbox to use for the FW command
14966  *	@vf: one of the VFs instantiated by the specified PF
14967  *	@vlan: The vlanid to be set
14968  *
14969  */
t4_set_vlan_acl(struct adapter * adap,unsigned int pf,unsigned int vf,u16 vlan)14970 int t4_set_vlan_acl(struct adapter *adap, unsigned int pf, unsigned int vf,
14971 		    u16 vlan)
14972 {
14973 	struct fw_acl_vlan_cmd vlan_cmd;
14974 	unsigned int enable;
14975 
14976 	enable = (vlan ? F_FW_ACL_VLAN_CMD_EN : 0);
14977 	memset(&vlan_cmd, 0, sizeof(vlan_cmd));
14978 	vlan_cmd.op_to_vfn = cpu_to_be32(V_FW_CMD_OP(FW_ACL_VLAN_CMD) |
14979 					 F_FW_CMD_REQUEST |
14980 					 F_FW_CMD_WRITE |
14981 					 F_FW_CMD_EXEC |
14982 					 V_FW_ACL_VLAN_CMD_PFN(pf) |
14983 					 V_FW_ACL_VLAN_CMD_VFN(vf));
14984 	vlan_cmd.en_to_len16 = cpu_to_be32(enable | FW_LEN16(vlan_cmd) |
14985 					   V_FW_ACL_VLAN_CMD_PMASK(1 << pf));
14986 	/* Drop all packets that donot match vlan id */
14987 	vlan_cmd.dropnovlan_fm = (enable
14988 				  ? (F_FW_ACL_VLAN_CMD_DROPNOVLAN |
14989 				     F_FW_ACL_VLAN_CMD_FM)
14990 				  : 0);
14991 	if (enable != 0) {
14992 		vlan_cmd.nvlan = 1;
14993 		vlan_cmd.vlanid[0] = cpu_to_be16(vlan);
14994 	}
14995 
14996 	return t4_wr_mbox(adap, adap->mbox, &vlan_cmd, sizeof(vlan_cmd), NULL);
14997 }
14998 
14999 /**
15000  *	t4_del_mac - Removes the exact-match filter for a MAC address
15001  *	@adap: the adapter
15002  *	@mbox: mailbox to use for the FW command
15003  *	@viid: the VI id
15004  *	@addr: the MAC address value
15005  *	@smac: if true, delete from only the smac region of MPS
15006  *
15007  *	Modifies an exact-match filter and sets it to the new MAC address if
15008  *	@idx >= 0, or adds the MAC address to a new filter if @idx < 0.  In the
15009  *	latter case the address is added persistently if @persist is %true.
15010  *
15011  *	Returns a negative error number or the index of the filter with the new
15012  *	MAC value.  Note that this index may differ from @idx.
15013  */
t4_del_mac(struct adapter * adap,unsigned int mbox,unsigned int viid,const u8 * addr,bool smac)15014 int t4_del_mac(struct adapter *adap, unsigned int mbox, unsigned int viid,
15015 	       const u8 *addr, bool smac)
15016 {
15017 	int ret;
15018 	struct fw_vi_mac_cmd c;
15019 	struct fw_vi_mac_exact *p = c.u.exact;
15020 	unsigned int max_mac_addr = adap->chip_params->mps_tcam_size;
15021 
15022 	memset(&c, 0, sizeof(c));
15023 	c.op_to_viid = cpu_to_be32(V_FW_CMD_OP(FW_VI_MAC_CMD) |
15024 				   F_FW_CMD_REQUEST | F_FW_CMD_WRITE |
15025 				   V_FW_VI_MAC_CMD_VIID(viid));
15026 	c.freemacs_to_len16 = cpu_to_be32(
15027 					V_FW_CMD_LEN16(1) |
15028 					(smac ? F_FW_VI_MAC_CMD_IS_SMAC : 0));
15029 
15030 	memcpy(p->macaddr, addr, sizeof(p->macaddr));
15031 	p->valid_to_idx = cpu_to_be16(
15032 				F_FW_VI_MAC_CMD_VALID |
15033 				V_FW_VI_MAC_CMD_IDX(FW_VI_MAC_MAC_BASED_FREE));
15034 
15035 	ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
15036 	if (ret == 0) {
15037 		ret = G_FW_VI_MAC_CMD_IDX(be16_to_cpu(p->valid_to_idx));
15038 		if (ret < max_mac_addr)
15039 			return -ENOMEM;
15040 	}
15041 
15042 	return ret;
15043 }
15044 
15045 /**
15046  *	t4_add_mac - Adds an exact-match filter for a MAC address
15047  *	@adap: the adapter
15048  *	@mbox: mailbox to use for the FW command
15049  *	@viid: the VI id
15050  *	@idx: index of existing filter for old value of MAC address, or -1
15051  *	@addr: the new MAC address value
15052  *	@persist: whether a new MAC allocation should be persistent
15053  *	@add_smt: if true also add the address to the HW SMT
15054  *	@smac: if true, update only the smac region of MPS
15055  *
15056  *	Modifies an exact-match filter and sets it to the new MAC address if
15057  *	@idx >= 0, or adds the MAC address to a new filter if @idx < 0.  In the
15058  *	latter case the address is added persistently if @persist is %true.
15059  *
15060  *	Returns a negative error number or the index of the filter with the new
15061  *	MAC value.  Note that this index may differ from @idx.
15062  */
t4_add_mac(struct adapter * adap,unsigned int mbox,unsigned int viid,int idx,const u8 * addr,bool persist,u8 * smt_idx,bool smac)15063 int t4_add_mac(struct adapter *adap, unsigned int mbox, unsigned int viid,
15064 	       int idx, const u8 *addr, bool persist, u8 *smt_idx, bool smac)
15065 {
15066 	int ret, mode;
15067 	struct fw_vi_mac_cmd c;
15068 	struct fw_vi_mac_exact *p = c.u.exact;
15069 	unsigned int max_mac_addr = adap->chip_params->mps_tcam_size;
15070 
15071 	if (idx < 0)		/* new allocation */
15072 		idx = persist ? FW_VI_MAC_ADD_PERSIST_MAC : FW_VI_MAC_ADD_MAC;
15073 	mode = smt_idx ? FW_VI_MAC_SMT_AND_MPSTCAM : FW_VI_MAC_MPS_TCAM_ENTRY;
15074 
15075 	memset(&c, 0, sizeof(c));
15076 	c.op_to_viid = cpu_to_be32(V_FW_CMD_OP(FW_VI_MAC_CMD) |
15077 				   F_FW_CMD_REQUEST | F_FW_CMD_WRITE |
15078 				   V_FW_VI_MAC_CMD_VIID(viid));
15079 	c.freemacs_to_len16 = cpu_to_be32(
15080 				V_FW_CMD_LEN16(1) |
15081 				(smac ? F_FW_VI_MAC_CMD_IS_SMAC : 0));
15082 	p->valid_to_idx = cpu_to_be16(F_FW_VI_MAC_CMD_VALID |
15083 				      V_FW_VI_MAC_CMD_SMAC_RESULT(mode) |
15084 				      V_FW_VI_MAC_CMD_IDX(idx));
15085 	memcpy(p->macaddr, addr, sizeof(p->macaddr));
15086 
15087 	ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
15088 	if (ret == 0) {
15089 		ret = G_FW_VI_MAC_CMD_IDX(be16_to_cpu(p->valid_to_idx));
15090 		if (ret >= max_mac_addr)
15091 			return -ENOMEM;
15092 		if (smt_idx) {
15093 			/* Does fw supports returning smt_idx? */
15094 			if (adap->params.viid_smt_extn_support)
15095 				*smt_idx = G_FW_VI_MAC_CMD_SMTID(be32_to_cpu(c.op_to_viid));
15096 			else {
15097 				/* In T4/T5, SMT contains 256 SMAC entries
15098 				 * organized in 128 rows of 2 entries each.
15099 				 * In T6, SMT contains 256 SMAC entries in
15100 				 * 256 rows.
15101 				 */
15102 				if (chip_id(adap) <= CHELSIO_T5)
15103 					*smt_idx = ((viid & M_FW_VIID_VIN) << 1);
15104 				else
15105 					*smt_idx = (viid & M_FW_VIID_VIN);
15106 			}
15107 		}
15108 	}
15109 
15110 	return ret;
15111 }
15112