xref: /src/sys/dev/cxgbe/common/t4_hw.c (revision 8f41ee95f9e05b3848d793deaacd591ee2387f0e)
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 static inline char
intr_alert_char(u32 cause,u32 enable,u32 fatal)4798 intr_alert_char(u32 cause, u32 enable, u32 fatal)
4799 {
4800 	if (cause & fatal)
4801 		return ('!');
4802 	if (cause & enable)
4803 		return ('*');
4804 	return ('-');
4805 }
4806 
4807 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)4808 show_intr_info(struct adapter *sc, const struct intr_info *ii, uint32_t cause,
4809     uint32_t ucause, uint32_t enabled, uint32_t fatal, int flags)
4810 {
4811 	uint32_t leftover, msgbits;
4812 	const struct intr_details *details;
4813 	char alert;
4814 	const bool verbose = flags & IHF_VERBOSE;
4815 
4816 	if (verbose || ucause != 0 || flags & IHF_RUN_ALL_ACTIONS) {
4817 		alert = intr_alert_char(cause, enabled, fatal);
4818 		CH_ALERT(sc, "%c %s 0x%x = 0x%08x, E 0x%08x, F 0x%08x\n", alert,
4819 		    ii->name, ii->cause_reg, cause, enabled, ii->fatal);
4820 	}
4821 
4822 	leftover = verbose ? cause : ucause;
4823 	for (details = ii->details; details && details->mask != 0; details++) {
4824 		msgbits = details->mask & leftover;
4825 		if (msgbits == 0)
4826 			continue;
4827 		alert = intr_alert_char(msgbits, enabled, fatal);
4828 		CH_ALERT(sc, "  %c [0x%08x] %s\n", alert, msgbits, details->msg);
4829 		leftover &= ~msgbits;
4830 	}
4831 	if (leftover != 0 && leftover != (verbose ? cause : ucause)) {
4832 		alert = intr_alert_char(leftover, enabled, fatal);
4833 		CH_ALERT(sc, "  %c [0x%08x]\n", alert, leftover);
4834 	}
4835 }
4836 
4837 /*
4838  * Returns true for fatal error.
4839  */
4840 static bool
t4_handle_intr(struct adapter * sc,const struct intr_info * ii,uint32_t acause,int flags)4841 t4_handle_intr(struct adapter *sc, const struct intr_info *ii, uint32_t acause,
4842     int flags)
4843 {
4844 	uint32_t cause, ucause, enabled, fatal;
4845 	bool rc;
4846 	const struct intr_action *action;
4847 
4848 	cause = t4_read_reg(sc, ii->cause_reg);
4849 	enabled = t4_read_reg(sc, ii->enable_reg);
4850 	flags |= ii->flags;
4851 	fatal = ii->fatal & cause;
4852 	if (flags & IHF_FATAL_IFF_ENABLED)
4853 		fatal &= enabled;
4854 	ucause = cause;
4855 	if (flags & IHF_IGNORE_IF_DISABLED)
4856 		ucause &= enabled;
4857 	if (!(flags & IHF_NO_SHOW))
4858 		show_intr_info(sc, ii, cause, ucause, enabled, fatal, flags);
4859 
4860 	rc = fatal != 0;
4861 	for (action = ii->actions; action && action->mask != 0; action++) {
4862 		if (action->action == NULL)
4863 			continue;
4864 		if (action->mask & (ucause | acause) ||
4865 		    flags & IHF_RUN_ALL_ACTIONS) {
4866 			bool rc1 = (action->action)(sc, action->arg, flags);
4867 			if (action->mask & ucause)
4868 				rc |= rc1;
4869 		}
4870 	}
4871 
4872 	/* clear */
4873 	if (cause != 0) {
4874 		if (flags & IHF_CLR_ALL_SET) {
4875 			t4_write_reg(sc, ii->cause_reg, cause);
4876 			(void)t4_read_reg(sc, ii->cause_reg);
4877 		} else if (ucause != 0 && flags & IHF_CLR_ALL_UNIGNORED) {
4878 			t4_write_reg(sc, ii->cause_reg, ucause);
4879 			(void)t4_read_reg(sc, ii->cause_reg);
4880 		}
4881 	}
4882 
4883 	return (rc);
4884 }
4885 
4886 /*
4887  * Interrupt handler for the PCIE module.
4888  */
pcie_intr_handler(struct adapter * adap,int arg,int flags)4889 static bool pcie_intr_handler(struct adapter *adap, int arg, int flags)
4890 {
4891 	static const struct intr_details sysbus_intr_details[] = {
4892 		{ F_RNPP, "RXNP array parity error" },
4893 		{ F_RPCP, "RXPC array parity error" },
4894 		{ F_RCIP, "RXCIF array parity error" },
4895 		{ F_RCCP, "Rx completions control array parity error" },
4896 		{ F_RFTP, "RXFT array parity error" },
4897 		{ 0 }
4898 	};
4899 	static const struct intr_info sysbus_intr_info = {
4900 		.name = "PCIE_CORE_UTL_SYSTEM_BUS_AGENT_STATUS",
4901 		.cause_reg = A_PCIE_CORE_UTL_SYSTEM_BUS_AGENT_STATUS,
4902 		.enable_reg = A_PCIE_CORE_UTL_SYSTEM_BUS_AGENT_INTERRUPT_ENABLE,
4903 		.fatal = F_RFTP | F_RCCP | F_RCIP | F_RPCP | F_RNPP,
4904 		.flags = 0,
4905 		.details = sysbus_intr_details,
4906 		.actions = NULL,
4907 	};
4908 	static const struct intr_details pcie_port_intr_details[] = {
4909 		{ F_TPCP, "TXPC array parity error" },
4910 		{ F_TNPP, "TXNP array parity error" },
4911 		{ F_TFTP, "TXFT array parity error" },
4912 		{ F_TCAP, "TXCA array parity error" },
4913 		{ F_TCIP, "TXCIF array parity error" },
4914 		{ F_RCAP, "RXCA array parity error" },
4915 		{ F_OTDD, "outbound request TLP discarded" },
4916 		{ F_RDPE, "Rx data parity error" },
4917 		{ F_TDUE, "Tx uncorrectable data error" },
4918 		{ 0 }
4919 	};
4920 	static const struct intr_info pcie_port_intr_info = {
4921 		.name = "PCIE_CORE_UTL_PCI_EXPRESS_PORT_STATUS",
4922 		.cause_reg = A_PCIE_CORE_UTL_PCI_EXPRESS_PORT_STATUS,
4923 		.enable_reg = A_PCIE_CORE_UTL_PCI_EXPRESS_PORT_INTERRUPT_ENABLE,
4924 		.fatal = F_TPCP | F_TNPP | F_TFTP | F_TCAP | F_TCIP | F_RCAP |
4925 		    F_OTDD | F_RDPE | F_TDUE,
4926 		.flags = 0,
4927 		.details = pcie_port_intr_details,
4928 		.actions = NULL,
4929 	};
4930 	static const struct intr_details pcie_intr_details[] = {
4931 		{ F_MSIADDRLPERR, "MSI AddrL parity error" },
4932 		{ F_MSIADDRHPERR, "MSI AddrH parity error" },
4933 		{ F_MSIDATAPERR, "MSI data parity error" },
4934 		{ F_MSIXADDRLPERR, "MSI-X AddrL parity error" },
4935 		{ F_MSIXADDRHPERR, "MSI-X AddrH parity error" },
4936 		{ F_MSIXDATAPERR, "MSI-X data parity error" },
4937 		{ F_MSIXDIPERR, "MSI-X DI parity error" },
4938 		{ F_PIOCPLPERR, "PCIe PIO completion FIFO parity error" },
4939 		{ F_PIOREQPERR, "PCIe PIO request FIFO parity error" },
4940 		{ F_TARTAGPERR, "PCIe target tag FIFO parity error" },
4941 		{ F_CCNTPERR, "PCIe CMD channel count parity error" },
4942 		{ F_CREQPERR, "PCIe CMD channel request parity error" },
4943 		{ F_CRSPPERR, "PCIe CMD channel response parity error" },
4944 		{ F_DCNTPERR, "PCIe DMA channel count parity error" },
4945 		{ F_DREQPERR, "PCIe DMA channel request parity error" },
4946 		{ F_DRSPPERR, "PCIe DMA channel response parity error" },
4947 		{ F_HCNTPERR, "PCIe HMA channel count parity error" },
4948 		{ F_HREQPERR, "PCIe HMA channel request parity error" },
4949 		{ F_HRSPPERR, "PCIe HMA channel response parity error" },
4950 		{ F_CFGSNPPERR, "PCIe config snoop FIFO parity error" },
4951 		{ F_FIDPERR, "PCIe FID parity error" },
4952 		{ F_INTXCLRPERR, "PCIe INTx clear parity error" },
4953 		{ F_MATAGPERR, "PCIe MA tag parity error" },
4954 		{ F_PIOTAGPERR, "PCIe PIO tag parity error" },
4955 		{ F_RXCPLPERR, "PCIe Rx completion parity error" },
4956 		{ F_RXWRPERR, "PCIe Rx write parity error" },
4957 		{ F_RPLPERR, "PCIe replay buffer parity error" },
4958 		{ F_PCIESINT, "PCIe core secondary fault" },
4959 		{ F_PCIEPINT, "PCIe core primary fault" },
4960 		{ F_UNXSPLCPLERR, "PCIe unexpected split completion error" },
4961 		{ 0 }
4962 	};
4963 	static const struct intr_details t5_pcie_intr_details[] = {
4964 		{ F_IPGRPPERR, "Parity errors observed by IP" },
4965 		{ F_NONFATALERR, "PCIe non-fatal error" },
4966 		{ F_READRSPERR, "Outbound read error" },
4967 		{ F_TRGT1GRPPERR, "PCIe TRGT1 group FIFOs parity error" },
4968 		{ F_IPSOTPERR, "PCIe IP SOT buffer SRAM parity error" },
4969 		{ F_IPRETRYPERR, "PCIe IP replay buffer parity error" },
4970 		{ F_IPRXDATAGRPPERR, "PCIe IP Rx data group SRAMs parity error" },
4971 		{ F_IPRXHDRGRPPERR, "PCIe IP Rx header group SRAMs parity error" },
4972 		{ F_PIOTAGQPERR, "PIO tag queue FIFO parity error" },
4973 		{ F_MAGRPPERR, "MA group FIFO parity error" },
4974 		{ F_VFIDPERR, "VFID SRAM parity error" },
4975 		{ F_FIDPERR, "FID SRAM parity error" },
4976 		{ F_CFGSNPPERR, "config snoop FIFO parity error" },
4977 		{ F_HRSPPERR, "HMA channel response data SRAM parity error" },
4978 		{ F_HREQRDPERR, "HMA channel read request SRAM parity error" },
4979 		{ F_HREQWRPERR, "HMA channel write request SRAM parity error" },
4980 		{ F_DRSPPERR, "DMA channel response data SRAM parity error" },
4981 		{ F_DREQRDPERR, "DMA channel write request SRAM parity error" },
4982 		{ F_CRSPPERR, "CMD channel response data SRAM parity error" },
4983 		{ F_CREQRDPERR, "CMD channel read request SRAM parity error" },
4984 		{ F_MSTTAGQPERR, "PCIe master tag queue SRAM parity error" },
4985 		{ F_TGTTAGQPERR, "PCIe target tag queue FIFO parity error" },
4986 		{ F_PIOREQGRPPERR, "PIO request group FIFOs parity error" },
4987 		{ F_PIOCPLGRPPERR, "PIO completion group FIFOs parity error" },
4988 		{ F_MSIXDIPERR, "MSI-X DI SRAM parity error" },
4989 		{ F_MSIXDATAPERR, "MSI-X data SRAM parity error" },
4990 		{ F_MSIXADDRHPERR, "MSI-X AddrH SRAM parity error" },
4991 		{ F_MSIXADDRLPERR, "MSI-X AddrL SRAM parity error" },
4992 		{ F_MSIXSTIPERR, "MSI-X STI SRAM parity error" },
4993 		{ F_MSTTIMEOUTPERR, "Master timeout FIFO parity error" },
4994 		{ F_MSTGRPPERR, "Master response read queue SRAM parity error" },
4995 		{ 0 }
4996 	};
4997 	struct intr_info pcie_intr_info = {
4998 		.name = "PCIE_INT_CAUSE",
4999 		.cause_reg = A_PCIE_INT_CAUSE,
5000 		.enable_reg = A_PCIE_INT_ENABLE,
5001 		.fatal = 0xffffffff,
5002 		.flags = IHF_FATAL_IFF_ENABLED,
5003 		.details = NULL,
5004 		.actions = NULL,
5005 	};
5006 	struct intr_info pcie_int_cause_ext = {
5007 		.name = "PCIE_INT_CAUSE_EXT",
5008 		.cause_reg = A_PCIE_INT_CAUSE_EXT,
5009 		.enable_reg = A_PCIE_INT_ENABLE_EXT,
5010 		.fatal = 0,
5011 		.flags = 0,
5012 		.details = NULL,
5013 		.actions = NULL,
5014 	};
5015 	struct intr_info pcie_int_cause_x8 = {
5016 		.name = "PCIE_INT_CAUSE_X8",
5017 		.cause_reg = A_PCIE_INT_CAUSE_X8,
5018 		.enable_reg = A_PCIE_INT_ENABLE_X8,
5019 		.fatal = 0,
5020 		.flags = 0,
5021 		.details = NULL,
5022 		.actions = NULL,
5023 	};
5024 	bool fatal = false;
5025 
5026 	if (is_t4(adap)) {
5027 		fatal |= t4_handle_intr(adap, &sysbus_intr_info, 0, flags);
5028 		fatal |= t4_handle_intr(adap, &pcie_port_intr_info, 0, flags);
5029 
5030 		pcie_intr_info.details = pcie_intr_details;
5031 	} else {
5032 		pcie_intr_info.details = t5_pcie_intr_details;
5033 	}
5034 	fatal |= t4_handle_intr(adap, &pcie_intr_info, 0, flags);
5035 	if (chip_id(adap) > CHELSIO_T6) {
5036 		fatal |= t4_handle_intr(adap, &pcie_int_cause_ext, 0, flags);
5037 		fatal |= t4_handle_intr(adap, &pcie_int_cause_x8, 0, flags);
5038 	}
5039 
5040 	return (fatal);
5041 }
5042 
5043 /*
5044  * TP interrupt handler.
5045  */
tp_intr_handler(struct adapter * adap,int arg,int flags)5046 static bool tp_intr_handler(struct adapter *adap, int arg, int flags)
5047 {
5048 	static const struct intr_details tp_intr_details[] = {
5049 		{ 0x3fffffff, "TP parity error" },
5050 		{ F_FLMTXFLSTEMPTY, "TP out of Tx pages" },
5051 		{ 0 }
5052 	};
5053 	static const struct intr_info tp_intr_info = {
5054 		.name = "TP_INT_CAUSE",
5055 		.cause_reg = A_TP_INT_CAUSE,
5056 		.enable_reg = A_TP_INT_ENABLE,
5057 		.fatal = 0x7fffffff,
5058 		.flags = IHF_FATAL_IFF_ENABLED,
5059 		.details = tp_intr_details,
5060 		.actions = NULL,
5061 	};
5062 	static const struct intr_info tp_inic_perr_cause = {
5063 		.name = "TP_INIC_PERR_CAUSE",
5064 		.cause_reg = A_TP_INIC_PERR_CAUSE,
5065 		.enable_reg = A_TP_INIC_PERR_ENABLE,
5066 		.fatal = 0xffffffff,
5067 		.flags = IHF_FATAL_IFF_ENABLED,
5068 		.details = NULL,
5069 		.actions = NULL,
5070 	};
5071 	static const struct intr_info tp_c_perr_cause = {
5072 		.name = "TP_C_PERR_CAUSE",
5073 		.cause_reg = A_TP_C_PERR_CAUSE,
5074 		.enable_reg = A_TP_C_PERR_ENABLE,
5075 		.fatal = 0xffffffff,
5076 		.flags = IHF_FATAL_IFF_ENABLED,
5077 		.details = NULL,
5078 		.actions = NULL,
5079 	};
5080 	static const struct intr_info tp_e_eg_perr_cause = {
5081 		.name = "TP_E_EG_PERR_CAUSE",
5082 		.cause_reg = A_TP_E_EG_PERR_CAUSE,
5083 		.enable_reg = A_TP_E_EG_PERR_ENABLE,
5084 		.fatal = 0xffffffff,
5085 		.flags = IHF_FATAL_IFF_ENABLED,
5086 		.details = NULL,
5087 		.actions = NULL,
5088 	};
5089 	static const struct intr_info tp_e_in0_perr_cause = {
5090 		.name = "TP_E_IN0_PERR_CAUSE",
5091 		.cause_reg = A_TP_E_IN0_PERR_CAUSE,
5092 		.enable_reg = A_TP_E_IN0_PERR_ENABLE,
5093 		.fatal = 0xffffffff,
5094 		.flags = IHF_FATAL_IFF_ENABLED,
5095 		.details = NULL,
5096 		.actions = NULL,
5097 	};
5098 	static const struct intr_info tp_e_in1_perr_cause = {
5099 		.name = "TP_E_IN1_PERR_CAUSE",
5100 		.cause_reg = A_TP_E_IN1_PERR_CAUSE,
5101 		.enable_reg = A_TP_E_IN1_PERR_ENABLE,
5102 		.fatal = 0xffffffff,
5103 		.flags = IHF_FATAL_IFF_ENABLED,
5104 		.details = NULL,
5105 		.actions = NULL,
5106 	};
5107 	static const struct intr_info tp_o_perr_cause = {
5108 		.name = "TP_O_PERR_CAUSE",
5109 		.cause_reg = A_TP_O_PERR_CAUSE,
5110 		.enable_reg = A_TP_O_PERR_ENABLE,
5111 		.fatal = 0xffffffff,
5112 		.flags = IHF_FATAL_IFF_ENABLED,
5113 		.details = NULL,
5114 		.actions = NULL,
5115 	};
5116 	bool fatal;
5117 
5118 	fatal = t4_handle_intr(adap, &tp_intr_info, 0, flags);
5119 	if (chip_id(adap) > CHELSIO_T6) {
5120 		fatal |= t4_handle_intr(adap, &tp_inic_perr_cause, 0, flags);
5121 		fatal |= t4_handle_intr(adap, &tp_c_perr_cause, 0, flags);
5122 		fatal |= t4_handle_intr(adap, &tp_e_eg_perr_cause, 0, flags);
5123 		fatal |= t4_handle_intr(adap, &tp_e_in0_perr_cause, 0, flags);
5124 		fatal |= t4_handle_intr(adap, &tp_e_in1_perr_cause, 0, flags);
5125 		fatal |= t4_handle_intr(adap, &tp_o_perr_cause, 0, flags);
5126 	}
5127 
5128 	return (fatal);
5129 }
5130 
5131 /*
5132  * SGE interrupt handler.
5133  */
sge_intr_handler(struct adapter * adap,int arg,int flags)5134 static bool sge_intr_handler(struct adapter *adap, int arg, int flags)
5135 {
5136 	static const struct intr_info sge_int1_info = {
5137 		.name = "SGE_INT_CAUSE1",
5138 		.cause_reg = A_SGE_INT_CAUSE1,
5139 		.enable_reg = A_SGE_INT_ENABLE1,
5140 		.fatal = 0xffffffff,
5141 		.flags = IHF_FATAL_IFF_ENABLED,
5142 		.details = NULL,
5143 		.actions = NULL,
5144 	};
5145 	static const struct intr_info sge_int2_info = {
5146 		.name = "SGE_INT_CAUSE2",
5147 		.cause_reg = A_SGE_INT_CAUSE2,
5148 		.enable_reg = A_SGE_INT_ENABLE2,
5149 		.fatal = 0xffffffff,
5150 		.flags = IHF_FATAL_IFF_ENABLED,
5151 		.details = NULL,
5152 		.actions = NULL,
5153 	};
5154 	static const struct intr_details sge_int3_details[] = {
5155 		{ F_ERR_FLM_DBP,
5156 			"DBP pointer delivery for invalid context or QID" },
5157 		{ F_ERR_FLM_IDMA1 | F_ERR_FLM_IDMA0,
5158 			"Invalid QID or header request by IDMA" },
5159 		{ F_ERR_FLM_HINT, "FLM hint is for invalid context or QID" },
5160 		{ F_ERR_PCIE_ERROR3, "SGE PCIe error for DBP thread 3" },
5161 		{ F_ERR_PCIE_ERROR2, "SGE PCIe error for DBP thread 2" },
5162 		{ F_ERR_PCIE_ERROR1, "SGE PCIe error for DBP thread 1" },
5163 		{ F_ERR_PCIE_ERROR0, "SGE PCIe error for DBP thread 0" },
5164 		{ F_ERR_TIMER_ABOVE_MAX_QID,
5165 			"SGE GTS with timer 0-5 for IQID > 1023" },
5166 		{ F_ERR_CPL_EXCEED_IQE_SIZE,
5167 			"SGE received CPL exceeding IQE size" },
5168 		{ F_ERR_INVALID_CIDX_INC, "SGE GTS CIDX increment too large" },
5169 		{ F_ERR_ITP_TIME_PAUSED, "SGE ITP error" },
5170 		{ F_ERR_CPL_OPCODE_0, "SGE received 0-length CPL" },
5171 		{ F_ERR_DROPPED_DB, "SGE DB dropped" },
5172 		{ F_ERR_DATA_CPL_ON_HIGH_QID1 | F_ERR_DATA_CPL_ON_HIGH_QID0,
5173 		  "SGE IQID > 1023 received CPL for FL" },
5174 		{ F_ERR_BAD_DB_PIDX3 | F_ERR_BAD_DB_PIDX2 | F_ERR_BAD_DB_PIDX1 |
5175 			F_ERR_BAD_DB_PIDX0, "SGE DBP pidx increment too large" },
5176 		{ F_ERR_ING_PCIE_CHAN, "SGE Ingress PCIe channel mismatch" },
5177 		{ F_ERR_ING_CTXT_PRIO,
5178 			"Ingress context manager priority user error" },
5179 		{ F_ERR_EGR_CTXT_PRIO,
5180 			"Egress context manager priority user error" },
5181 		{ F_DBFIFO_HP_INT, "High priority DB FIFO threshold reached" },
5182 		{ F_DBFIFO_LP_INT, "Low priority DB FIFO threshold reached" },
5183 		{ F_REG_ADDRESS_ERR, "Undefined SGE register accessed" },
5184 		{ F_INGRESS_SIZE_ERR, "SGE illegal ingress QID" },
5185 		{ F_EGRESS_SIZE_ERR, "SGE illegal egress QID" },
5186 		{ 0x0000000f, "SGE context access for invalid queue" },
5187 		{ 0 }
5188 	};
5189 	static const struct intr_details t6_sge_int3_details[] = {
5190 		{ F_ERR_FLM_DBP,
5191 			"DBP pointer delivery for invalid context or QID" },
5192 		{ F_ERR_FLM_IDMA1 | F_ERR_FLM_IDMA0,
5193 			"Invalid QID or header request by IDMA" },
5194 		{ F_ERR_FLM_HINT, "FLM hint is for invalid context or QID" },
5195 		{ F_ERR_PCIE_ERROR3, "SGE PCIe error for DBP thread 3" },
5196 		{ F_ERR_PCIE_ERROR2, "SGE PCIe error for DBP thread 2" },
5197 		{ F_ERR_PCIE_ERROR1, "SGE PCIe error for DBP thread 1" },
5198 		{ F_ERR_PCIE_ERROR0, "SGE PCIe error for DBP thread 0" },
5199 		{ F_ERR_TIMER_ABOVE_MAX_QID,
5200 			"SGE GTS with timer 0-5 for IQID > 1023" },
5201 		{ F_ERR_CPL_EXCEED_IQE_SIZE,
5202 			"SGE received CPL exceeding IQE size" },
5203 		{ F_ERR_INVALID_CIDX_INC, "SGE GTS CIDX increment too large" },
5204 		{ F_ERR_ITP_TIME_PAUSED, "SGE ITP error" },
5205 		{ F_ERR_CPL_OPCODE_0, "SGE received 0-length CPL" },
5206 		{ F_ERR_DROPPED_DB, "SGE DB dropped" },
5207 		{ F_ERR_DATA_CPL_ON_HIGH_QID1 | F_ERR_DATA_CPL_ON_HIGH_QID0,
5208 			"SGE IQID > 1023 received CPL for FL" },
5209 		{ F_ERR_BAD_DB_PIDX3 | F_ERR_BAD_DB_PIDX2 | F_ERR_BAD_DB_PIDX1 |
5210 			F_ERR_BAD_DB_PIDX0, "SGE DBP pidx increment too large" },
5211 		{ F_ERR_ING_PCIE_CHAN, "SGE Ingress PCIe channel mismatch" },
5212 		{ F_ERR_ING_CTXT_PRIO,
5213 			"Ingress context manager priority user error" },
5214 		{ F_ERR_EGR_CTXT_PRIO,
5215 			"Egress context manager priority user error" },
5216 		{ F_DBP_TBUF_FULL, "SGE DBP tbuf full" },
5217 		{ F_FATAL_WRE_LEN,
5218 			"SGE WRE packet less than advertized length" },
5219 		{ F_REG_ADDRESS_ERR, "Undefined SGE register accessed" },
5220 		{ F_INGRESS_SIZE_ERR, "SGE illegal ingress QID" },
5221 		{ F_EGRESS_SIZE_ERR, "SGE illegal egress QID" },
5222 		{ 0x0000000f, "SGE context access for invalid queue" },
5223 		{ 0 }
5224 	};
5225 	struct intr_info sge_int3_info = {
5226 		.name = "SGE_INT_CAUSE3",
5227 		.cause_reg = A_SGE_INT_CAUSE3,
5228 		.enable_reg = A_SGE_INT_ENABLE3,
5229 		.fatal = F_ERR_CPL_EXCEED_IQE_SIZE,
5230 		.flags = 0,
5231 		.details = NULL,
5232 		.actions = NULL,
5233 	};
5234 	static const struct intr_info sge_int4_info = {
5235 		.name = "SGE_INT_CAUSE4",
5236 		.cause_reg = A_SGE_INT_CAUSE4,
5237 		.enable_reg = A_SGE_INT_ENABLE4,
5238 		.fatal = 0,
5239 		.flags = 0,
5240 		.details = NULL,
5241 		.actions = NULL,
5242 	};
5243 	static const struct intr_info sge_int5_info = {
5244 		.name = "SGE_INT_CAUSE5",
5245 		.cause_reg = A_SGE_INT_CAUSE5,
5246 		.enable_reg = A_SGE_INT_ENABLE5,
5247 		.fatal = 0xffffffff,
5248 		.flags = IHF_FATAL_IFF_ENABLED,
5249 		.details = NULL,
5250 		.actions = NULL,
5251 	};
5252 	static const struct intr_info sge_int6_info = {
5253 		.name = "SGE_INT_CAUSE6",
5254 		.cause_reg = A_SGE_INT_CAUSE6,
5255 		.enable_reg = A_SGE_INT_ENABLE6,
5256 		.fatal = 0,
5257 		.flags = 0,
5258 		.details = NULL,
5259 		.actions = NULL,
5260 	};
5261 	static const struct intr_info sge_int7_info = {
5262 		.name = "SGE_INT_CAUSE7",
5263 		.cause_reg = A_SGE_INT_CAUSE7,
5264 		.enable_reg = A_SGE_INT_ENABLE7,
5265 		.fatal = 0,
5266 		.flags = 0,
5267 		.details = NULL,
5268 		.actions = NULL,
5269 	};
5270 	static const struct intr_info sge_int8_info = {
5271 		.name = "SGE_INT_CAUSE8",
5272 		.cause_reg = A_SGE_INT_CAUSE8,
5273 		.enable_reg = A_SGE_INT_ENABLE8,
5274 		.fatal = 0,
5275 		.flags = 0,
5276 		.details = NULL,
5277 		.actions = NULL,
5278 	};
5279 	bool fatal;
5280 	u32 v;
5281 
5282 	if (chip_id(adap) <= CHELSIO_T5) {
5283 		sge_int3_info.details = sge_int3_details;
5284 	} else {
5285 		sge_int3_info.details = t6_sge_int3_details;
5286 	}
5287 
5288 	fatal = false;
5289 	fatal |= t4_handle_intr(adap, &sge_int1_info, 0, flags);
5290 	fatal |= t4_handle_intr(adap, &sge_int2_info, 0, flags);
5291 	fatal |= t4_handle_intr(adap, &sge_int3_info, 0, flags);
5292 	fatal |= t4_handle_intr(adap, &sge_int4_info, 0, flags);
5293 	if (chip_id(adap) >= CHELSIO_T5)
5294 		fatal |= t4_handle_intr(adap, &sge_int5_info, 0, flags);
5295 	if (chip_id(adap) >= CHELSIO_T6)
5296 		fatal |= t4_handle_intr(adap, &sge_int6_info, 0, flags);
5297 	if (chip_id(adap) >= CHELSIO_T7) {
5298 		fatal |= t4_handle_intr(adap, &sge_int7_info, 0, flags);
5299 		fatal |= t4_handle_intr(adap, &sge_int8_info, 0, flags);
5300 	}
5301 
5302 	v = t4_read_reg(adap, A_SGE_ERROR_STATS);
5303 	if (v & F_ERROR_QID_VALID) {
5304 		CH_ERR(adap, "SGE error for QID %u\n", G_ERROR_QID(v));
5305 		if (v & F_UNCAPTURED_ERROR)
5306 			CH_ERR(adap, "SGE UNCAPTURED_ERROR set (clearing)\n");
5307 		t4_write_reg(adap, A_SGE_ERROR_STATS,
5308 		    F_ERROR_QID_VALID | F_UNCAPTURED_ERROR);
5309 	}
5310 
5311 	return (fatal);
5312 }
5313 
5314 /*
5315  * CIM interrupt handler.
5316  */
cim_intr_handler(struct adapter * adap,int arg,int flags)5317 static bool cim_intr_handler(struct adapter *adap, int arg, int flags)
5318 {
5319 	static const struct intr_details cim_host_intr_details[] = {
5320 		/* T6+ */
5321 		{ F_PCIE2CIMINTFPARERR, "CIM IBQ PCIe interface parity error" },
5322 
5323 		/* T5+ */
5324 		{ F_MA_CIM_INTFPERR, "MA2CIM interface parity error" },
5325 		{ F_PLCIM_MSTRSPDATAPARERR,
5326 			"PL2CIM master response data parity error" },
5327 		{ F_NCSI2CIMINTFPARERR, "CIM IBQ NC-SI interface parity error" },
5328 		{ F_SGE2CIMINTFPARERR, "CIM IBQ SGE interface parity error" },
5329 		{ F_ULP2CIMINTFPARERR, "CIM IBQ ULP_TX interface parity error" },
5330 		{ F_TP2CIMINTFPARERR, "CIM IBQ TP interface parity error" },
5331 		{ F_OBQSGERX1PARERR, "CIM OBQ SGE1_RX parity error" },
5332 		{ F_OBQSGERX0PARERR, "CIM OBQ SGE0_RX parity error" },
5333 
5334 		/* T4+ */
5335 		{ F_TIEQOUTPARERRINT, "CIM TIEQ outgoing FIFO parity error" },
5336 		{ F_TIEQINPARERRINT, "CIM TIEQ incoming FIFO parity error" },
5337 		{ F_MBHOSTPARERR, "CIM mailbox host read parity error" },
5338 		{ F_MBUPPARERR, "CIM mailbox uP parity error" },
5339 		{ F_IBQTP0PARERR, "CIM IBQ TP0 parity error" },
5340 		{ F_IBQTP1PARERR, "CIM IBQ TP1 parity error" },
5341 		{ F_IBQULPPARERR, "CIM IBQ ULP parity error" },
5342 		{ F_IBQSGELOPARERR, "CIM IBQ SGE_LO parity error" },
5343 		{ F_IBQSGEHIPARERR | F_IBQPCIEPARERR,	/* same bit */
5344 			"CIM IBQ PCIe/SGE_HI parity error" },
5345 		{ F_IBQNCSIPARERR, "CIM IBQ NC-SI parity error" },
5346 		{ F_OBQULP0PARERR, "CIM OBQ ULP0 parity error" },
5347 		{ F_OBQULP1PARERR, "CIM OBQ ULP1 parity error" },
5348 		{ F_OBQULP2PARERR, "CIM OBQ ULP2 parity error" },
5349 		{ F_OBQULP3PARERR, "CIM OBQ ULP3 parity error" },
5350 		{ F_OBQSGEPARERR, "CIM OBQ SGE parity error" },
5351 		{ F_OBQNCSIPARERR, "CIM OBQ NC-SI parity error" },
5352 		{ F_TIMER1INT, "CIM TIMER0 interrupt" },
5353 		{ F_TIMER0INT, "CIM TIMER0 interrupt" },
5354 		{ F_PREFDROPINT, "CIM control register prefetch drop" },
5355 		{ 0}
5356 	};
5357 	static const struct intr_info cim_host_intr_info = {
5358 		.name = "CIM_HOST_INT_CAUSE",
5359 		.cause_reg = A_CIM_HOST_INT_CAUSE,
5360 		.enable_reg = A_CIM_HOST_INT_ENABLE,
5361 		.fatal = 0x007fffe6,
5362 		.flags = IHF_FATAL_IFF_ENABLED,
5363 		.details = cim_host_intr_details,
5364 		.actions = NULL,
5365 	};
5366 	static const struct intr_details cim_host_upacc_intr_details[] = {
5367 		{ F_EEPROMWRINT, "CIM EEPROM came out of busy state" },
5368 		{ F_TIMEOUTMAINT, "CIM PIF MA timeout" },
5369 		{ F_TIMEOUTINT, "CIM PIF timeout" },
5370 		{ F_RSPOVRLOOKUPINT, "CIM response FIFO overwrite" },
5371 		{ F_REQOVRLOOKUPINT, "CIM request FIFO overwrite" },
5372 		{ F_BLKWRPLINT, "CIM block write to PL space" },
5373 		{ F_BLKRDPLINT, "CIM block read from PL space" },
5374 		{ F_SGLWRPLINT,
5375 			"CIM single write to PL space with illegal BEs" },
5376 		{ F_SGLRDPLINT,
5377 			"CIM single read from PL space with illegal BEs" },
5378 		{ F_BLKWRCTLINT, "CIM block write to CTL space" },
5379 		{ F_BLKRDCTLINT, "CIM block read from CTL space" },
5380 		{ F_SGLWRCTLINT,
5381 			"CIM single write to CTL space with illegal BEs" },
5382 		{ F_SGLRDCTLINT,
5383 			"CIM single read from CTL space with illegal BEs" },
5384 		{ F_BLKWREEPROMINT, "CIM block write to EEPROM space" },
5385 		{ F_BLKRDEEPROMINT, "CIM block read from EEPROM space" },
5386 		{ F_SGLWREEPROMINT,
5387 			"CIM single write to EEPROM space with illegal BEs" },
5388 		{ F_SGLRDEEPROMINT,
5389 			"CIM single read from EEPROM space with illegal BEs" },
5390 		{ F_BLKWRFLASHINT, "CIM block write to flash space" },
5391 		{ F_BLKRDFLASHINT, "CIM block read from flash space" },
5392 		{ F_SGLWRFLASHINT, "CIM single write to flash space" },
5393 		{ F_SGLRDFLASHINT,
5394 			"CIM single read from flash space with illegal BEs" },
5395 		{ F_BLKWRBOOTINT, "CIM block write to boot space" },
5396 		{ F_BLKRDBOOTINT, "CIM block read from boot space" },
5397 		{ F_SGLWRBOOTINT, "CIM single write to boot space" },
5398 		{ F_SGLRDBOOTINT,
5399 			"CIM single read from boot space with illegal BEs" },
5400 		{ F_ILLWRBEINT, "CIM illegal write BEs" },
5401 		{ F_ILLRDBEINT, "CIM illegal read BEs" },
5402 		{ F_ILLRDINT, "CIM illegal read" },
5403 		{ F_ILLWRINT, "CIM illegal write" },
5404 		{ F_ILLTRANSINT, "CIM illegal transaction" },
5405 		{ F_RSVDSPACEINT, "CIM reserved space access" },
5406 		{0}
5407 	};
5408 	static const struct intr_info cim_host_upacc_intr_info = {
5409 		.name = "CIM_HOST_UPACC_INT_CAUSE",
5410 		.cause_reg = A_CIM_HOST_UPACC_INT_CAUSE,
5411 		.enable_reg = A_CIM_HOST_UPACC_INT_ENABLE,
5412 		.fatal = 0x3fffeeff,
5413 		.flags = IHF_FATAL_IFF_ENABLED,
5414 		.details = cim_host_upacc_intr_details,
5415 		.actions = NULL,
5416 	};
5417 	static const struct intr_info cim_pf_host_intr_info = {
5418 		.name = "CIM_PF_HOST_INT_CAUSE",
5419 		.cause_reg = MYPF_REG(A_CIM_PF_HOST_INT_CAUSE),
5420 		.enable_reg = MYPF_REG(A_CIM_PF_HOST_INT_ENABLE),
5421 		.fatal = 0,
5422 		.flags = 0,
5423 		.details = NULL,
5424 		.actions = NULL,
5425 	};
5426 	static const struct intr_info cim_perr_cause = {
5427 		.name = "CIM_PERR_CAUSE",
5428 		.cause_reg = A_CIM_PERR_CAUSE,
5429 		.enable_reg = A_CIM_PERR_ENABLE,
5430 		.fatal = 0xffffffff,
5431 		.flags = IHF_FATAL_IFF_ENABLED,
5432 		.details = NULL,
5433 		.actions = NULL,
5434 	};
5435 	u32 val, fw_err;
5436 	bool fatal;
5437 
5438 	/*
5439 	 * When the Firmware detects an internal error which normally wouldn't
5440 	 * raise a Host Interrupt, it forces a CIM Timer0 interrupt in order
5441 	 * to make sure the Host sees the Firmware Crash.  So if we have a
5442 	 * Timer0 interrupt and don't see a Firmware Crash, ignore the Timer0
5443 	 * interrupt.
5444 	 */
5445 	fw_err = t4_read_reg(adap, A_PCIE_FW);
5446 	val = t4_read_reg(adap, A_CIM_HOST_INT_CAUSE);
5447 	if (val & F_TIMER0INT && (!(fw_err & F_PCIE_FW_ERR) ||
5448 	    G_PCIE_FW_EVAL(fw_err) != PCIE_FW_EVAL_CRASH)) {
5449 		t4_write_reg(adap, A_CIM_HOST_INT_CAUSE, F_TIMER0INT);
5450 	}
5451 
5452 	fatal = (fw_err & F_PCIE_FW_ERR) != 0;
5453 	fatal |= t4_handle_intr(adap, &cim_host_intr_info, 0, flags);
5454 	fatal |= t4_handle_intr(adap, &cim_host_upacc_intr_info, 0, flags);
5455 	fatal |= t4_handle_intr(adap, &cim_pf_host_intr_info, 0, flags);
5456 	if (chip_id(adap) > CHELSIO_T6)
5457 		fatal |= t4_handle_intr(adap, &cim_perr_cause, 0, flags);
5458 	if (fatal)
5459 		t4_os_cim_err(adap);
5460 
5461 	return (fatal);
5462 }
5463 
5464 /*
5465  * ULP RX interrupt handler.
5466  */
ulprx_intr_handler(struct adapter * adap,int arg,int flags)5467 static bool ulprx_intr_handler(struct adapter *adap, int arg, int flags)
5468 {
5469 	static const struct intr_details ulprx_intr_details[] = {
5470 		/* T5+ */
5471 		{ F_SE_CNT_MISMATCH_1, "ULPRX SE count mismatch in channel 1" },
5472 		{ F_SE_CNT_MISMATCH_0, "ULPRX SE count mismatch in channel 0" },
5473 
5474 		/* T4+ */
5475 		{ F_CAUSE_CTX_1, "ULPRX channel 1 context error" },
5476 		{ F_CAUSE_CTX_0, "ULPRX channel 0 context error" },
5477 		{ 0x007fffff, "ULPRX parity error" },
5478 		{ 0 }
5479 	};
5480 	static const struct intr_info ulprx_intr_info = {
5481 		.name = "ULP_RX_INT_CAUSE",
5482 		.cause_reg = A_ULP_RX_INT_CAUSE,
5483 		.enable_reg = A_ULP_RX_INT_ENABLE,
5484 		.fatal = 0x07ffffff,
5485 		.flags = IHF_FATAL_IFF_ENABLED,
5486 		.details = ulprx_intr_details,
5487 		.actions = NULL,
5488 	};
5489 	static const struct intr_info ulprx_intr2_info = {
5490 		.name = "ULP_RX_INT_CAUSE_2",
5491 		.cause_reg = A_ULP_RX_INT_CAUSE_2,
5492 		.enable_reg = A_ULP_RX_INT_ENABLE_2,
5493 		.fatal = 0,
5494 		.flags = 0,
5495 		.details = NULL,
5496 		.actions = NULL,
5497 	};
5498 	static const struct intr_info ulprx_int_cause_pcmd = {
5499 		.name = "ULP_RX_INT_CAUSE_PCMD",
5500 		.cause_reg = A_ULP_RX_INT_CAUSE_PCMD,
5501 		.enable_reg = A_ULP_RX_INT_ENABLE_PCMD,
5502 		.fatal = 0,
5503 		.flags = 0,
5504 		.details = NULL,
5505 		.actions = NULL,
5506 	};
5507 	static const struct intr_info ulprx_int_cause_data = {
5508 		.name = "ULP_RX_INT_CAUSE_DATA",
5509 		.cause_reg = A_ULP_RX_INT_CAUSE_DATA,
5510 		.enable_reg = A_ULP_RX_INT_ENABLE_DATA,
5511 		.fatal = 0,
5512 		.flags = 0,
5513 		.details = NULL,
5514 		.actions = NULL,
5515 	};
5516 	static const struct intr_info ulprx_int_cause_arb = {
5517 		.name = "ULP_RX_INT_CAUSE_ARB",
5518 		.cause_reg = A_ULP_RX_INT_CAUSE_ARB,
5519 		.enable_reg = A_ULP_RX_INT_ENABLE_ARB,
5520 		.fatal = 0,
5521 		.flags = 0,
5522 		.details = NULL,
5523 		.actions = NULL,
5524 	};
5525 	static const struct intr_info ulprx_int_cause_intf = {
5526 		.name = "ULP_RX_INT_CAUSE_INTERFACE",
5527 		.cause_reg = A_ULP_RX_INT_CAUSE_INTERFACE,
5528 		.enable_reg = A_ULP_RX_INT_ENABLE_INTERFACE,
5529 		.fatal = 0,
5530 		.flags = 0,
5531 		.details = NULL,
5532 		.actions = NULL,
5533 	};
5534 	bool fatal = false;
5535 
5536 	fatal |= t4_handle_intr(adap, &ulprx_intr_info, 0, flags);
5537 	if (chip_id(adap) < CHELSIO_T7)
5538 		fatal |= t4_handle_intr(adap, &ulprx_intr2_info, 0, flags);
5539 	else {
5540 		fatal |= t4_handle_intr(adap, &ulprx_int_cause_pcmd, 0, flags);
5541 		fatal |= t4_handle_intr(adap, &ulprx_int_cause_data, 0, flags);
5542 		fatal |= t4_handle_intr(adap, &ulprx_int_cause_arb, 0, flags);
5543 		fatal |= t4_handle_intr(adap, &ulprx_int_cause_intf, 0, flags);
5544 	}
5545 
5546 	return (fatal);
5547 }
5548 
5549 /*
5550  * ULP TX interrupt handler.
5551  */
ulptx_intr_handler(struct adapter * adap,int arg,int flags)5552 static bool ulptx_intr_handler(struct adapter *adap, int arg, int flags)
5553 {
5554 	static const struct intr_details ulptx_intr_details[] = {
5555 		{ F_PBL_BOUND_ERR_CH3, "ULPTX channel 3 PBL out of bounds" },
5556 		{ F_PBL_BOUND_ERR_CH2, "ULPTX channel 2 PBL out of bounds" },
5557 		{ F_PBL_BOUND_ERR_CH1, "ULPTX channel 1 PBL out of bounds" },
5558 		{ F_PBL_BOUND_ERR_CH0, "ULPTX channel 0 PBL out of bounds" },
5559 		{ 0x0fffffff, "ULPTX parity error" },
5560 		{ 0 }
5561 	};
5562 	static const struct intr_info ulptx_intr_info = {
5563 		.name = "ULP_TX_INT_CAUSE",
5564 		.cause_reg = A_ULP_TX_INT_CAUSE,
5565 		.enable_reg = A_ULP_TX_INT_ENABLE,
5566 		.fatal = 0x0fffffff,
5567 		.flags = IHF_FATAL_IFF_ENABLED,
5568 		.details = ulptx_intr_details,
5569 		.actions = NULL,
5570 	};
5571 	static const struct intr_info ulptx_intr_info2 = {
5572 		.name = "ULP_TX_INT_CAUSE_2",
5573 		.cause_reg = A_ULP_TX_INT_CAUSE_2,
5574 		.enable_reg = A_ULP_TX_INT_ENABLE_2,
5575 		.fatal = 0xffffffff,
5576 		.flags = IHF_FATAL_IFF_ENABLED,
5577 		.details = NULL,
5578 		.actions = NULL,
5579 	};
5580 	static const struct intr_info ulptx_intr_info3 = {
5581 		.name = "ULP_TX_INT_CAUSE_3",
5582 		.cause_reg = A_ULP_TX_INT_CAUSE_3,
5583 		.enable_reg = A_ULP_TX_INT_ENABLE_3,
5584 		.fatal = 0xffffffff,
5585 		.flags = IHF_FATAL_IFF_ENABLED,
5586 		.details = NULL,
5587 		.actions = NULL,
5588 	};
5589 	static const struct intr_info ulptx_intr_info4 = {
5590 		.name = "ULP_TX_INT_CAUSE_4",
5591 		.cause_reg = A_ULP_TX_INT_CAUSE_4,
5592 		.enable_reg = A_ULP_TX_INT_ENABLE_4,
5593 		.fatal = 0xffffffff,
5594 		.flags = IHF_FATAL_IFF_ENABLED,
5595 		.details = NULL,
5596 		.actions = NULL,
5597 	};
5598 	static const struct intr_info ulptx_intr_info5 = {
5599 		.name = "ULP_TX_INT_CAUSE_5",
5600 		.cause_reg = A_ULP_TX_INT_CAUSE_5,
5601 		.enable_reg = A_ULP_TX_INT_ENABLE_5,
5602 		.fatal = 0xffffffff,
5603 		.flags = IHF_FATAL_IFF_ENABLED,
5604 		.details = NULL,
5605 		.actions = NULL,
5606 	};
5607 	static const struct intr_info ulptx_intr_info6 = {
5608 		.name = "ULP_TX_INT_CAUSE_6",
5609 		.cause_reg = A_ULP_TX_INT_CAUSE_6,
5610 		.enable_reg = A_ULP_TX_INT_ENABLE_6,
5611 		.fatal = 0xffffffff,
5612 		.flags = IHF_FATAL_IFF_ENABLED,
5613 		.details = NULL,
5614 		.actions = NULL,
5615 	};
5616 	static const struct intr_info ulptx_intr_info7 = {
5617 		.name = "ULP_TX_INT_CAUSE_7",
5618 		.cause_reg = A_ULP_TX_INT_CAUSE_7,
5619 		.enable_reg = A_ULP_TX_INT_ENABLE_7,
5620 		.fatal = 0,
5621 		.flags = 0,
5622 		.details = NULL,
5623 		.actions = NULL,
5624 	};
5625 	static const struct intr_info ulptx_intr_info8 = {
5626 		.name = "ULP_TX_INT_CAUSE_8",
5627 		.cause_reg = A_ULP_TX_INT_CAUSE_8,
5628 		.enable_reg = A_ULP_TX_INT_ENABLE_8,
5629 		.fatal = 0,
5630 		.flags = 0,
5631 		.details = NULL,
5632 		.actions = NULL,
5633 	};
5634 	bool fatal = false;
5635 
5636 	fatal |= t4_handle_intr(adap, &ulptx_intr_info, 0, flags);
5637 	if (chip_id(adap) > CHELSIO_T4)
5638 		fatal |= t4_handle_intr(adap, &ulptx_intr_info2, 0, flags);
5639 	if (chip_id(adap) > CHELSIO_T6) {
5640 		fatal |= t4_handle_intr(adap, &ulptx_intr_info3, 0, flags);
5641 		fatal |= t4_handle_intr(adap, &ulptx_intr_info4, 0, flags);
5642 		fatal |= t4_handle_intr(adap, &ulptx_intr_info5, 0, flags);
5643 		fatal |= t4_handle_intr(adap, &ulptx_intr_info6, 0, flags);
5644 		fatal |= t4_handle_intr(adap, &ulptx_intr_info7, 0, flags);
5645 		fatal |= t4_handle_intr(adap, &ulptx_intr_info8, 0, flags);
5646 	}
5647 
5648 	return (fatal);
5649 }
5650 
pmtx_dump_dbg_stats(struct adapter * adap,int arg,int flags)5651 static bool pmtx_dump_dbg_stats(struct adapter *adap, int arg, int flags)
5652 {
5653 	int i;
5654 	u32 data[17];
5655 
5656 	if (flags & IHF_NO_SHOW)
5657 		return (false);
5658 
5659 	t4_read_indirect(adap, A_PM_TX_DBG_CTRL, A_PM_TX_DBG_DATA, &data[0],
5660 	    ARRAY_SIZE(data), A_PM_TX_DBG_STAT0);
5661 	for (i = 0; i < ARRAY_SIZE(data); i++) {
5662 		CH_ALERT(adap, "  - PM_TX_DBG_STAT%u (0x%x) = 0x%08x\n", i,
5663 		    A_PM_TX_DBG_STAT0 + i, data[i]);
5664 	}
5665 
5666 	return (false);
5667 }
5668 
5669 /*
5670  * PM TX interrupt handler.
5671  */
pmtx_intr_handler(struct adapter * adap,int arg,int flags)5672 static bool pmtx_intr_handler(struct adapter *adap, int arg, int flags)
5673 {
5674 	static const struct intr_details pmtx_int_cause_fields[] = {
5675 		{ F_PCMD_LEN_OVFL0, "PMTX channel 0 pcmd too large" },
5676 		{ F_PCMD_LEN_OVFL1, "PMTX channel 1 pcmd too large" },
5677 		{ F_PCMD_LEN_OVFL2, "PMTX channel 2 pcmd too large" },
5678 		{ F_ZERO_C_CMD_ERROR, "PMTX 0-length pcmd" },
5679 		{ 0x0f000000, "PMTX icspi FIFO2X Rx framing error" },
5680 		{ 0x00f00000, "PMTX icspi FIFO Rx framing error" },
5681 		{ 0x000f0000, "PMTX icspi FIFO Tx framing error" },
5682 		{ 0x0000f000, "PMTX oespi FIFO Rx framing error" },
5683 		{ 0x00000f00, "PMTX oespi FIFO Tx framing error" },
5684 		{ 0x000000f0, "PMTX oespi FIFO2X Tx framing error" },
5685 		{ F_OESPI_PAR_ERROR, "PMTX oespi parity error" },
5686 		{ F_DB_OPTIONS_PAR_ERROR, "PMTX db_options parity error" },
5687 		{ F_ICSPI_PAR_ERROR, "PMTX icspi parity error" },
5688 		{ F_C_PCMD_PAR_ERROR, "PMTX c_pcmd parity error" },
5689 		{ 0 }
5690 	};
5691 	static const struct intr_action pmtx_int_cause_actions[] = {
5692 		{ 0xffffffff, -1, pmtx_dump_dbg_stats },
5693 		{ 0 },
5694 	};
5695 	static const struct intr_info pmtx_int_cause = {
5696 		.name = "PM_TX_INT_CAUSE",
5697 		.cause_reg = A_PM_TX_INT_CAUSE,
5698 		.enable_reg = A_PM_TX_INT_ENABLE,
5699 		.fatal = 0xffffffff,
5700 		.flags = 0,
5701 		.details = pmtx_int_cause_fields,
5702 		.actions = pmtx_int_cause_actions,
5703 	};
5704 
5705 	return (t4_handle_intr(adap, &pmtx_int_cause, 0, flags));
5706 }
5707 
5708 /*
5709  * PM RX interrupt handler.
5710  */
pmrx_intr_handler(struct adapter * adap,int arg,int flags)5711 static bool pmrx_intr_handler(struct adapter *adap, int arg, int flags)
5712 {
5713 	static const struct intr_details pmrx_int_cause_fields[] = {
5714 		/* T6+ */
5715 		{ 0x18000000, "PMRX ospi overflow" },
5716 		{ F_MA_INTF_SDC_ERR, "PMRX MA interface SDC parity error" },
5717 		{ F_BUNDLE_LEN_PARERR, "PMRX bundle len FIFO parity error" },
5718 		{ F_BUNDLE_LEN_OVFL, "PMRX bundle len FIFO overflow" },
5719 		{ F_SDC_ERR, "PMRX SDC error" },
5720 
5721 		/* T4+ */
5722 		{ F_ZERO_E_CMD_ERROR, "PMRX 0-length pcmd" },
5723 		{ 0x003c0000, "PMRX iespi FIFO2X Rx framing error" },
5724 		{ 0x0003c000, "PMRX iespi Rx framing error" },
5725 		{ 0x00003c00, "PMRX iespi Tx framing error" },
5726 		{ 0x00000300, "PMRX ocspi Rx framing error" },
5727 		{ 0x000000c0, "PMRX ocspi Tx framing error" },
5728 		{ 0x00000030, "PMRX ocspi FIFO2X Tx framing error" },
5729 		{ F_OCSPI_PAR_ERROR, "PMRX ocspi parity error" },
5730 		{ F_DB_OPTIONS_PAR_ERROR, "PMRX db_options parity error" },
5731 		{ F_IESPI_PAR_ERROR, "PMRX iespi parity error" },
5732 		{ F_E_PCMD_PAR_ERROR, "PMRX e_pcmd parity error"},
5733 		{ 0 }
5734 	};
5735 	static const struct intr_info pmrx_int_cause = {
5736 		.name = "PM_RX_INT_CAUSE",
5737 		.cause_reg = A_PM_RX_INT_CAUSE,
5738 		.enable_reg = A_PM_RX_INT_ENABLE,
5739 		.fatal = 0x1fffffff,
5740 		.flags = IHF_FATAL_IFF_ENABLED,
5741 		.details = pmrx_int_cause_fields,
5742 		.actions = NULL,
5743 	};
5744 
5745 	return (t4_handle_intr(adap, &pmrx_int_cause, 0, flags));
5746 }
5747 
5748 /*
5749  * CPL switch interrupt handler.
5750  */
cplsw_intr_handler(struct adapter * adap,int arg,int flags)5751 static bool cplsw_intr_handler(struct adapter *adap, int arg, int flags)
5752 {
5753 	static const struct intr_details cplsw_int_cause_fields[] = {
5754 		/* T5+ */
5755 		{ F_PERR_CPL_128TO128_1, "CPLSW 128TO128 FIFO1 parity error" },
5756 		{ F_PERR_CPL_128TO128_0, "CPLSW 128TO128 FIFO0 parity error" },
5757 
5758 		/* T4+ */
5759 		{ F_CIM_OP_MAP_PERR, "CPLSW CIM op_map parity error" },
5760 		{ F_CIM_OVFL_ERROR, "CPLSW CIM overflow" },
5761 		{ F_TP_FRAMING_ERROR, "CPLSW TP framing error" },
5762 		{ F_SGE_FRAMING_ERROR, "CPLSW SGE framing error" },
5763 		{ F_CIM_FRAMING_ERROR, "CPLSW CIM framing error" },
5764 		{ F_ZERO_SWITCH_ERROR, "CPLSW no-switch error" },
5765 		{ 0 }
5766 	};
5767 	static const struct intr_info cplsw_int_cause = {
5768 		.name = "CPL_INTR_CAUSE",
5769 		.cause_reg = A_CPL_INTR_CAUSE,
5770 		.enable_reg = A_CPL_INTR_ENABLE,
5771 		.fatal = 0xffffffff,
5772 		.flags = IHF_FATAL_IFF_ENABLED,
5773 		.details = cplsw_int_cause_fields,
5774 		.actions = NULL,
5775 	};
5776 
5777 	return (t4_handle_intr(adap, &cplsw_int_cause, 0, flags));
5778 }
5779 
5780 #define T4_LE_FATAL_MASK (F_PARITYERR | F_UNKNOWNCMD | F_REQQPARERR)
5781 #define T5_LE_FATAL_MASK (T4_LE_FATAL_MASK | F_VFPARERR)
5782 #define T6_LE_PERRCRC_MASK (F_PIPELINEERR | F_CLIPTCAMACCFAIL | \
5783     F_SRVSRAMACCFAIL | F_CLCAMCRCPARERR | F_CLCAMINTPERR | F_SSRAMINTPERR | \
5784     F_SRVSRAMPERR | F_VFSRAMPERR | F_TCAMINTPERR | F_TCAMCRCERR | \
5785     F_HASHTBLMEMACCERR | F_MAIFWRINTPERR | F_HASHTBLMEMCRCERR)
5786 #define T6_LE_FATAL_MASK (T6_LE_PERRCRC_MASK | F_T6_UNKNOWNCMD | \
5787     F_TCAMACCFAIL | F_HASHTBLACCFAIL | F_CMDTIDERR | F_CMDPRSRINTERR | \
5788     F_TOTCNTERR | F_CLCAMFIFOERR | F_CLIPSUBERR)
5789 #define T7_LE_FATAL_MASK (T6_LE_FATAL_MASK | F_CACHESRAMPERR | F_CACHEINTPERR)
5790 
5791 /*
5792  * LE interrupt handler.
5793  */
le_intr_handler(struct adapter * adap,int arg,int flags)5794 static bool le_intr_handler(struct adapter *adap, int arg, int flags)
5795 {
5796 	static const struct intr_details le_intr_details[] = {
5797 		{ F_REQQPARERR, "LE request queue parity error" },
5798 		{ F_UNKNOWNCMD, "LE unknown command" },
5799 		{ F_ACTRGNFULL, "LE active region full" },
5800 		{ F_PARITYERR, "LE parity error" },
5801 		{ F_LIPMISS, "LE LIP miss" },
5802 		{ F_LIP0, "LE 0 LIP error" },
5803 		{ 0 }
5804 	};
5805 	static const struct intr_details t6_le_intr_details[] = {
5806 		{ F_CLIPSUBERR, "LE CLIP CAM reverse substitution error" },
5807 		{ F_CLCAMFIFOERR, "LE CLIP CAM internal FIFO error" },
5808 		{ F_CTCAMINVLDENT, "Invalid IPv6 CLIP TCAM entry" },
5809 		{ F_TCAMINVLDENT, "Invalid IPv6 TCAM entry" },
5810 		{ F_TOTCNTERR, "LE total active < TCAM count" },
5811 		{ F_CMDPRSRINTERR, "LE internal error in parser" },
5812 		{ F_CMDTIDERR, "Incorrect tid in LE command" },
5813 		{ F_T6_ACTRGNFULL, "LE active region full" },
5814 		{ F_T6_ACTCNTIPV6TZERO, "LE IPv6 active open TCAM counter -ve" },
5815 		{ F_T6_ACTCNTIPV4TZERO, "LE IPv4 active open TCAM counter -ve" },
5816 		{ F_T6_ACTCNTIPV6ZERO, "LE IPv6 active open counter -ve" },
5817 		{ F_T6_ACTCNTIPV4ZERO, "LE IPv4 active open counter -ve" },
5818 		{ F_HASHTBLACCFAIL, "Hash table read error (proto conflict)" },
5819 		{ F_TCAMACCFAIL, "LE TCAM access failure" },
5820 		{ F_T6_UNKNOWNCMD, "LE unknown command" },
5821 		{ F_T6_LIP0, "LE found 0 LIP during CLIP substitution" },
5822 		{ F_T6_LIPMISS, "LE CLIP lookup miss" },
5823 		{ T6_LE_PERRCRC_MASK, "LE parity/CRC error" },
5824 		{ 0 }
5825 	};
5826 	struct intr_info le_intr_info = {
5827 		.name = "LE_DB_INT_CAUSE",
5828 		.cause_reg = A_LE_DB_INT_CAUSE,
5829 		.enable_reg = A_LE_DB_INT_ENABLE,
5830 		.fatal = 0,
5831 		.flags = IHF_FATAL_IFF_ENABLED,
5832 		.details = NULL,
5833 		.actions = NULL,
5834 	};
5835 
5836 	if (chip_id(adap) <= CHELSIO_T5) {
5837 		le_intr_info.details = le_intr_details;
5838 		le_intr_info.fatal = T5_LE_FATAL_MASK;
5839 	} else {
5840 		le_intr_info.details = t6_le_intr_details;
5841 		if (chip_id(adap) < CHELSIO_T7)
5842 			le_intr_info.fatal = T6_LE_FATAL_MASK;
5843 		else
5844 			le_intr_info.fatal = T7_LE_FATAL_MASK;
5845 	}
5846 
5847 	return (t4_handle_intr(adap, &le_intr_info, 0, flags));
5848 }
5849 
5850 /*
5851  * MPS interrupt handler.
5852  */
mps_intr_handler(struct adapter * adap,int arg,int flags)5853 static bool mps_intr_handler(struct adapter *adap, int arg, int flags)
5854 {
5855 	static const struct intr_details mps_rx_perr_intr_details[] = {
5856 		{ 0xffffffff, "MPS Rx parity error" },
5857 		{ 0 }
5858 	};
5859 	static const struct intr_info mps_rx_perr_intr_info = {
5860 		.name = "MPS_RX_PERR_INT_CAUSE",
5861 		.cause_reg = A_MPS_RX_PERR_INT_CAUSE,
5862 		.enable_reg = A_MPS_RX_PERR_INT_ENABLE,
5863 		.fatal = 0xffffffff,
5864 		.flags = IHF_FATAL_IFF_ENABLED,
5865 		.details = mps_rx_perr_intr_details,
5866 		.actions = NULL,
5867 	};
5868 	static const struct intr_info mps_rx_perr_intr_info2 = {
5869 		.name = "MPS_RX_PERR_INT_CAUSE2",
5870 		.cause_reg = A_MPS_RX_PERR_INT_CAUSE2,
5871 		.enable_reg = A_MPS_RX_PERR_INT_ENABLE2,
5872 		.fatal = 0xffffffff,
5873 		.flags = IHF_FATAL_IFF_ENABLED,
5874 		.details = NULL,
5875 		.actions = NULL,
5876 	};
5877 	static const struct intr_info mps_rx_perr_intr_info3 = {
5878 		.name = "MPS_RX_PERR_INT_CAUSE3",
5879 		.cause_reg = A_MPS_RX_PERR_INT_CAUSE3,
5880 		.enable_reg = A_MPS_RX_PERR_INT_ENABLE3,
5881 		.fatal = 0xffffffff,
5882 		.flags = IHF_FATAL_IFF_ENABLED,
5883 		.details = NULL,
5884 		.actions = NULL,
5885 	};
5886 	static const struct intr_info mps_rx_perr_intr_info4 = {
5887 		.name = "MPS_RX_PERR_INT_CAUSE4",
5888 		.cause_reg = A_MPS_RX_PERR_INT_CAUSE4,
5889 		.enable_reg = A_MPS_RX_PERR_INT_ENABLE4,
5890 		.fatal = 0xffffffff,
5891 		.flags = IHF_FATAL_IFF_ENABLED,
5892 		.details = NULL,
5893 		.actions = NULL,
5894 	};
5895 	static const struct intr_info mps_rx_perr_intr_info5 = {
5896 		.name = "MPS_RX_PERR_INT_CAUSE5",
5897 		.cause_reg = A_MPS_RX_PERR_INT_CAUSE5,
5898 		.enable_reg = A_MPS_RX_PERR_INT_ENABLE5,
5899 		.fatal = 0xffffffff,
5900 		.flags = IHF_FATAL_IFF_ENABLED,
5901 		.details = NULL,
5902 		.actions = NULL,
5903 	};
5904 	static const struct intr_info mps_rx_perr_intr_info6 = {
5905 		.name = "MPS_RX_PERR_INT_CAUSE6",
5906 		.cause_reg = A_MPS_RX_PERR_INT_CAUSE6,
5907 		.enable_reg = A_MPS_RX_PERR_INT_ENABLE6,
5908 		.fatal = 0xffffffff,
5909 		.flags = IHF_FATAL_IFF_ENABLED,
5910 		.details = NULL,
5911 		.actions = NULL,
5912 	};
5913 	static const struct intr_details mps_tx_intr_details[] = {
5914 		{ F_PORTERR, "MPS Tx destination port is disabled" },
5915 		{ F_FRMERR, "MPS Tx framing error" },
5916 		{ F_SECNTERR, "MPS Tx SOP/EOP error" },
5917 		{ F_BUBBLE, "MPS Tx underflow" },
5918 		{ V_TXDESCFIFO(M_TXDESCFIFO), "MPS Tx desc FIFO parity error" },
5919 		{ V_TXDATAFIFO(M_TXDATAFIFO), "MPS Tx data FIFO parity error" },
5920 		{ F_NCSIFIFO, "MPS Tx NC-SI FIFO parity error" },
5921 		{ V_TPFIFO(M_TPFIFO), "MPS Tx TP FIFO parity error" },
5922 		{ 0 }
5923 	};
5924 	static const struct intr_info mps_tx_intr_info = {
5925 		.name = "MPS_TX_INT_CAUSE",
5926 		.cause_reg = A_MPS_TX_INT_CAUSE,
5927 		.enable_reg = A_MPS_TX_INT_ENABLE,
5928 		.fatal = 0x1ffff,
5929 		.flags = IHF_FATAL_IFF_ENABLED,
5930 		.details = mps_tx_intr_details,
5931 		.actions = NULL,
5932 	};
5933 	static const struct intr_info mps_tx_intr_info2 = {
5934 		.name = "MPS_TX_INT2_CAUSE",
5935 		.cause_reg = A_MPS_TX_INT2_CAUSE,
5936 		.enable_reg = A_MPS_TX_INT2_ENABLE,
5937 		.fatal = 0xffffffff,
5938 		.flags = IHF_FATAL_IFF_ENABLED,
5939 		.details = NULL,
5940 		.actions = NULL,
5941 	};
5942 	static const struct intr_info mps_tx_intr_info3 = {
5943 		.name = "MPS_TX_INT3_CAUSE",
5944 		.cause_reg = A_MPS_TX_INT3_CAUSE,
5945 		.enable_reg = A_MPS_TX_INT3_ENABLE,
5946 		.fatal = 0xffffffff,
5947 		.flags = IHF_FATAL_IFF_ENABLED,
5948 		.details = NULL,
5949 		.actions = NULL,
5950 	};
5951 	static const struct intr_info mps_tx_intr_info4 = {
5952 		.name = "MPS_TX_INT4_CAUSE",
5953 		.cause_reg = A_MPS_TX_INT4_CAUSE,
5954 		.enable_reg = A_MPS_TX_INT4_ENABLE,
5955 		.fatal = 0xffffffff,
5956 		.flags = IHF_FATAL_IFF_ENABLED,
5957 		.details = NULL,
5958 		.actions = NULL,
5959 	};
5960 	static const struct intr_details mps_trc_intr_details[] = {
5961 		{ F_MISCPERR, "MPS TRC misc parity error" },
5962 		{ V_PKTFIFO(M_PKTFIFO), "MPS TRC packet FIFO parity error" },
5963 		{ V_FILTMEM(M_FILTMEM), "MPS TRC filter parity error" },
5964 		{ 0 }
5965 	};
5966 	static const struct intr_info mps_trc_intr_info = {
5967 		.name = "MPS_TRC_INT_CAUSE",
5968 		.cause_reg = A_MPS_TRC_INT_CAUSE,
5969 		.enable_reg = A_MPS_TRC_INT_ENABLE,
5970 		.fatal = F_MISCPERR | V_PKTFIFO(M_PKTFIFO) | V_FILTMEM(M_FILTMEM),
5971 		.flags = 0,
5972 		.details = mps_trc_intr_details,
5973 		.actions = NULL,
5974 	};
5975 	static const struct intr_info t7_mps_trc_intr_info = {
5976 		.name = "MPS_TRC_INT_CAUSE",
5977 		.cause_reg = A_T7_MPS_TRC_INT_CAUSE,
5978 		.enable_reg = A_T7_MPS_TRC_INT_ENABLE,
5979 		.fatal = 0xffffffff,
5980 		.flags = IHF_FATAL_IFF_ENABLED,
5981 		.details = mps_trc_intr_details,
5982 		.actions = NULL,
5983 	};
5984 	static const struct intr_info t7_mps_trc_intr_info2 = {
5985 		.name = "MPS_TRC_INT_CAUSE2",
5986 		.cause_reg = A_MPS_TRC_INT_CAUSE2,
5987 		.enable_reg = A_MPS_TRC_INT_ENABLE2,
5988 		.fatal = 0xffffffff,
5989 		.flags = IHF_FATAL_IFF_ENABLED,
5990 		.details = NULL,
5991 		.actions = NULL,
5992 	};
5993 	static const struct intr_details mps_stat_sram_intr_details[] = {
5994 		{ 0xffffffff, "MPS statistics SRAM parity error" },
5995 		{ 0 }
5996 	};
5997 	static const struct intr_info mps_stat_sram_intr_info = {
5998 		.name = "MPS_STAT_PERR_INT_CAUSE_SRAM",
5999 		.cause_reg = A_MPS_STAT_PERR_INT_CAUSE_SRAM,
6000 		.enable_reg = A_MPS_STAT_PERR_INT_ENABLE_SRAM,
6001 		.fatal = 0x1fffffff,
6002 		.flags = IHF_FATAL_IFF_ENABLED,
6003 		.details = mps_stat_sram_intr_details,
6004 		.actions = NULL,
6005 	};
6006 	static const struct intr_details mps_stat_tx_intr_details[] = {
6007 		{ 0xffffff, "MPS statistics Tx FIFO parity error" },
6008 		{ 0 }
6009 	};
6010 	static const struct intr_info mps_stat_tx_intr_info = {
6011 		.name = "MPS_STAT_PERR_INT_CAUSE_TX_FIFO",
6012 		.cause_reg = A_MPS_STAT_PERR_INT_CAUSE_TX_FIFO,
6013 		.enable_reg = A_MPS_STAT_PERR_INT_ENABLE_TX_FIFO,
6014 		.fatal =  0xffffff,
6015 		.flags = IHF_FATAL_IFF_ENABLED,
6016 		.details = mps_stat_tx_intr_details,
6017 		.actions = NULL,
6018 	};
6019 	static const struct intr_details mps_stat_rx_intr_details[] = {
6020 		{ 0xffffff, "MPS statistics Rx FIFO parity error" },
6021 		{ 0 }
6022 	};
6023 	static const struct intr_info mps_stat_rx_intr_info = {
6024 		.name = "MPS_STAT_PERR_INT_CAUSE_RX_FIFO",
6025 		.cause_reg = A_MPS_STAT_PERR_INT_CAUSE_RX_FIFO,
6026 		.enable_reg = A_MPS_STAT_PERR_INT_ENABLE_RX_FIFO,
6027 		.fatal =  0xffffff,
6028 		.flags = 0,
6029 		.details = mps_stat_rx_intr_details,
6030 		.actions = NULL,
6031 	};
6032 	static const struct intr_details mps_cls_intr_details[] = {
6033 		{ F_HASHSRAM, "MPS hash SRAM parity error" },
6034 		{ F_MATCHTCAM, "MPS match TCAM parity error" },
6035 		{ F_MATCHSRAM, "MPS match SRAM parity error" },
6036 		{ 0 }
6037 	};
6038 	static const struct intr_info mps_cls_intr_info = {
6039 		.name = "MPS_CLS_INT_CAUSE",
6040 		.cause_reg = A_MPS_CLS_INT_CAUSE,
6041 		.enable_reg = A_MPS_CLS_INT_ENABLE,
6042 		.fatal =  F_MATCHSRAM | F_MATCHTCAM | F_HASHSRAM,
6043 		.flags = 0,
6044 		.details = mps_cls_intr_details,
6045 		.actions = NULL,
6046 	};
6047 	static const struct intr_details mps_stat_sram1_intr_details[] = {
6048 		{ 0xff, "MPS statistics SRAM1 parity error" },
6049 		{ 0 }
6050 	};
6051 	static const struct intr_info mps_stat_sram1_intr_info = {
6052 		.name = "MPS_STAT_PERR_INT_CAUSE_SRAM1",
6053 		.cause_reg = A_MPS_STAT_PERR_INT_CAUSE_SRAM1,
6054 		.enable_reg = A_MPS_STAT_PERR_INT_ENABLE_SRAM1,
6055 		.fatal = 0xff,
6056 		.flags = 0,
6057 		.details = mps_stat_sram1_intr_details,
6058 		.actions = NULL,
6059 	};
6060 	bool fatal = false;
6061 
6062 	fatal |= t4_handle_intr(adap, &mps_rx_perr_intr_info, 0, flags);
6063 	if (chip_id(adap) > CHELSIO_T6) {
6064 		fatal |= t4_handle_intr(adap, &mps_rx_perr_intr_info2, 0, flags);
6065 		fatal |= t4_handle_intr(adap, &mps_rx_perr_intr_info3, 0, flags);
6066 		fatal |= t4_handle_intr(adap, &mps_rx_perr_intr_info4, 0, flags);
6067 		fatal |= t4_handle_intr(adap, &mps_rx_perr_intr_info5, 0, flags);
6068 		fatal |= t4_handle_intr(adap, &mps_rx_perr_intr_info6, 0, flags);
6069 	}
6070 	fatal |= t4_handle_intr(adap, &mps_tx_intr_info, 0, flags);
6071 	if (chip_id(adap) > CHELSIO_T6) {
6072 		fatal |= t4_handle_intr(adap, &mps_tx_intr_info2, 0, flags);
6073 		fatal |= t4_handle_intr(adap, &mps_tx_intr_info3, 0, flags);
6074 		fatal |= t4_handle_intr(adap, &mps_tx_intr_info4, 0, flags);
6075 		fatal |= t4_handle_intr(adap, &t7_mps_trc_intr_info, 0, flags);
6076 		fatal |= t4_handle_intr(adap, &t7_mps_trc_intr_info2, 0, flags);
6077 	} else
6078 		fatal |= t4_handle_intr(adap, &mps_trc_intr_info, 0, flags);
6079 	fatal |= t4_handle_intr(adap, &mps_stat_sram_intr_info, 0, flags);
6080 	fatal |= t4_handle_intr(adap, &mps_stat_tx_intr_info, 0, flags);
6081 	fatal |= t4_handle_intr(adap, &mps_stat_rx_intr_info, 0, flags);
6082 	fatal |= t4_handle_intr(adap, &mps_cls_intr_info, 0, flags);
6083 	if (chip_id(adap) > CHELSIO_T4)
6084 		fatal |= t4_handle_intr(adap, &mps_stat_sram1_intr_info, 0, flags);
6085 
6086 	t4_write_reg(adap, A_MPS_INT_CAUSE, is_t4(adap) ? 0 : 0xffffffff);
6087 	t4_read_reg(adap, A_MPS_INT_CAUSE);	/* flush */
6088 
6089 	return (fatal);
6090 
6091 }
6092 
6093 /*
6094  * EDC/MC interrupt handler.
6095  */
mem_intr_handler(struct adapter * adap,int idx,int flags)6096 static bool mem_intr_handler(struct adapter *adap, int idx, int flags)
6097 {
6098 	static const char name[4][5] = { "EDC0", "EDC1", "MC0", "MC1" };
6099 	unsigned int count_reg, v;
6100 	static const struct intr_details mem_intr_details[] = {
6101 		{ F_ECC_UE_INT_CAUSE, "Uncorrectable ECC data error(s)" },
6102 		{ F_ECC_CE_INT_CAUSE, "Correctable ECC data error(s)" },
6103 		{ F_PERR_INT_CAUSE, "FIFO parity error" },
6104 		{ 0 }
6105 	};
6106 	static const struct intr_details t7_mem_intr_details[] = {
6107 		{ F_DDRPHY_INT_CAUSE, "DDRPHY" },
6108 		{ F_DDRCTL_INT_CAUSE, "DDRCTL" },
6109 		{ F_T7_ECC_CE_INT_CAUSE, "Correctable ECC data error(s)" },
6110 		{ F_T7_ECC_UE_INT_CAUSE, "Uncorrectable ECC data error(s)" },
6111 		{ F_PERR_INT_CAUSE, "FIFO parity error" },
6112 		{ 0 }
6113 	};
6114 	char rname[32];
6115 	struct intr_info ii = {
6116 		.name = &rname[0],
6117 		.fatal = F_PERR_INT_CAUSE | F_ECC_UE_INT_CAUSE,
6118 		.details = mem_intr_details,
6119 		.flags = 0,
6120 		.actions = NULL,
6121 	};
6122 	bool fatal = false;
6123 	int i = 0;
6124 
6125 	switch (idx) {
6126 	case MEM_EDC1: i = 1;
6127 		       /* fall through */
6128 	case MEM_EDC0:
6129 		snprintf(rname, sizeof(rname), "EDC%u_INT_CAUSE", i);
6130 		if (is_t4(adap)) {
6131 			ii.cause_reg = EDC_REG(A_EDC_INT_CAUSE, i);
6132 			ii.enable_reg = EDC_REG(A_EDC_INT_ENABLE, i);
6133 			count_reg = EDC_REG(A_EDC_ECC_STATUS, i);
6134 		} else {
6135 			ii.cause_reg = EDC_T5_REG(A_EDC_H_INT_CAUSE, i);
6136 			ii.enable_reg = EDC_T5_REG(A_EDC_H_INT_ENABLE, i);
6137 			count_reg = EDC_T5_REG(A_EDC_H_ECC_STATUS, i);
6138 		}
6139 		fatal |= t4_handle_intr(adap, &ii, 0, flags);
6140 		if (chip_id(adap) > CHELSIO_T6) {
6141 			snprintf(rname, sizeof(rname), "EDC%u_PAR_CAUSE", i);
6142 			ii.cause_reg = EDC_T5_REG(A_EDC_H_PAR_CAUSE, i);
6143 			ii.enable_reg = EDC_T5_REG(A_EDC_H_PAR_ENABLE, i);
6144 			ii.fatal = 0xffffffff;
6145 			ii.details = NULL;
6146 			ii.flags = IHF_FATAL_IFF_ENABLED;
6147 			fatal |= t4_handle_intr(adap, &ii, 0, flags);
6148 		}
6149 		break;
6150 	case MEM_MC1:
6151 		if (is_t4(adap) || is_t6(adap))
6152 			return (false);
6153 		i = 1;
6154 	       /* fall through */
6155 	case MEM_MC0:
6156 		snprintf(rname, sizeof(rname), "MC%u_INT_CAUSE", i);
6157 		if (is_t4(adap)) {
6158 			ii.cause_reg = A_MC_INT_CAUSE;
6159 			ii.enable_reg = A_MC_INT_ENABLE;
6160 			count_reg = A_MC_ECC_STATUS;
6161 		} else if (chip_id(adap) < CHELSIO_T7) {
6162 			ii.cause_reg = MC_REG(A_MC_P_INT_CAUSE, i);
6163 			ii.enable_reg = MC_REG(A_MC_P_INT_ENABLE, i);
6164 			count_reg = MC_REG(A_MC_P_ECC_STATUS, i);
6165 		} else {
6166 			ii.cause_reg = MC_T7_REG(A_T7_MC_P_INT_CAUSE, i);
6167 			ii.enable_reg = MC_T7_REG(A_T7_MC_P_INT_ENABLE, i);
6168 			ii.fatal = F_PERR_INT_CAUSE | F_T7_ECC_UE_INT_CAUSE;
6169 			ii.details = t7_mem_intr_details;
6170 			count_reg = MC_T7_REG(A_T7_MC_P_ECC_STATUS, i);
6171 		}
6172 		fatal |= t4_handle_intr(adap, &ii, 0, flags);
6173 
6174 		snprintf(rname, sizeof(rname), "MC%u_PAR_CAUSE", i);
6175 		if (is_t4(adap)) {
6176 			ii.cause_reg = A_MC_PAR_CAUSE;
6177 			ii.enable_reg = A_MC_PAR_ENABLE;
6178 		} else if (chip_id(adap) < CHELSIO_T7) {
6179 			ii.cause_reg = MC_REG(A_MC_P_PAR_CAUSE, i);
6180 			ii.enable_reg = MC_REG(A_MC_P_PAR_ENABLE, i);
6181 		} else {
6182 			ii.cause_reg = MC_T7_REG(A_T7_MC_P_PAR_CAUSE, i);
6183 			ii.enable_reg = MC_T7_REG(A_T7_MC_P_PAR_ENABLE, i);
6184 		}
6185 		ii.fatal = 0xffffffff;
6186 		ii.details = NULL;
6187 		ii.flags = IHF_FATAL_IFF_ENABLED;
6188 		fatal |= t4_handle_intr(adap, &ii, 0, flags);
6189 
6190 		if (chip_id(adap) > CHELSIO_T6) {
6191 			snprintf(rname, sizeof(rname), "MC%u_DDRCTL_INT_CAUSE", i);
6192 			ii.cause_reg = MC_T7_REG(A_MC_P_DDRCTL_INT_CAUSE, i);
6193 			ii.enable_reg = MC_T7_REG(A_MC_P_DDRCTL_INT_ENABLE, i);
6194 			fatal |= t4_handle_intr(adap, &ii, 0, flags);
6195 		}
6196 		break;
6197 	}
6198 
6199 	v = t4_read_reg(adap, count_reg);
6200 	if (v != 0) {
6201 		if (G_ECC_UECNT(v) != 0 && !(flags & IHF_NO_SHOW)) {
6202 			CH_ALERT(adap,
6203 			    "  %s: %u uncorrectable ECC data error(s)\n",
6204 			    name[idx], G_ECC_UECNT(v));
6205 		}
6206 		if (G_ECC_CECNT(v) != 0 && !(flags & IHF_NO_SHOW)) {
6207 			if (idx <= MEM_EDC1)
6208 				t4_edc_err_read(adap, idx);
6209 			CH_WARN_RATELIMIT(adap,
6210 			    "  %s: %u correctable ECC data error(s)\n",
6211 			    name[idx], G_ECC_CECNT(v));
6212 		}
6213 		t4_write_reg(adap, count_reg, 0xffffffff);
6214 	}
6215 
6216 	return (fatal);
6217 }
6218 
ma_wrap_status(struct adapter * adap,int arg,int flags)6219 static bool ma_wrap_status(struct adapter *adap, int arg, int flags)
6220 {
6221 	u32 v;
6222 
6223 	v = t4_read_reg(adap, A_MA_INT_WRAP_STATUS);
6224 	if (!(flags & IHF_NO_SHOW)) {
6225 		CH_ALERT(adap,
6226 		    "  MA address wrap-around by client %u to address %#x\n",
6227 		    G_MEM_WRAP_CLIENT_NUM(v), G_MEM_WRAP_ADDRESS(v) << 4);
6228 	}
6229 	t4_write_reg(adap, A_MA_INT_WRAP_STATUS, v);
6230 
6231 	return (false);
6232 }
6233 
6234 
6235 /*
6236  * MA interrupt handler.
6237  */
ma_intr_handler(struct adapter * adap,int arg,int flags)6238 static bool ma_intr_handler(struct adapter *adap, int arg, int flags)
6239 {
6240 	static const struct intr_action ma_intr_actions[] = {
6241 		{ F_MEM_WRAP_INT_CAUSE, 0, ma_wrap_status },
6242 		{ 0 },
6243 	};
6244 	static const struct intr_info ma_intr_info = {
6245 		.name = "MA_INT_CAUSE",
6246 		.cause_reg = A_MA_INT_CAUSE,
6247 		.enable_reg = A_MA_INT_ENABLE,
6248 		.fatal = F_MEM_PERR_INT_CAUSE | F_MEM_TO_INT_CAUSE,
6249 		.flags = IHF_FATAL_IFF_ENABLED,
6250 		.details = NULL,
6251 		.actions = ma_intr_actions,
6252 	};
6253 	static const struct intr_info ma_perr_status1 = {
6254 		.name = "MA_PARITY_ERROR_STATUS1",
6255 		.cause_reg = A_MA_PARITY_ERROR_STATUS1,
6256 		.enable_reg = A_MA_PARITY_ERROR_ENABLE1,
6257 		.fatal = 0xffffffff,
6258 		.flags = 0,
6259 		.details = NULL,
6260 		.actions = NULL,
6261 	};
6262 	static const struct intr_info ma_perr_status2 = {
6263 		.name = "MA_PARITY_ERROR_STATUS2",
6264 		.cause_reg = A_MA_PARITY_ERROR_STATUS2,
6265 		.enable_reg = A_MA_PARITY_ERROR_ENABLE2,
6266 		.fatal = 0xffffffff,
6267 		.flags = 0,
6268 		.details = NULL,
6269 		.actions = NULL,
6270 	};
6271 	bool fatal;
6272 
6273 	fatal = false;
6274 	fatal |= t4_handle_intr(adap, &ma_intr_info, 0, flags);
6275 	fatal |= t4_handle_intr(adap, &ma_perr_status1, 0, flags);
6276 	if (chip_id(adap) > CHELSIO_T4)
6277 		fatal |= t4_handle_intr(adap, &ma_perr_status2, 0, flags);
6278 
6279 	return (fatal);
6280 }
6281 
6282 /*
6283  * SMB interrupt handler.
6284  */
smb_intr_handler(struct adapter * adap,int arg,int flags)6285 static bool smb_intr_handler(struct adapter *adap, int arg, int flags)
6286 {
6287 	static const struct intr_details smb_int_cause_fields[] = {
6288 		{ F_MSTTXFIFOPARINT, "SMB master Tx FIFO parity error" },
6289 		{ F_MSTRXFIFOPARINT, "SMB master Rx FIFO parity error" },
6290 		{ F_SLVFIFOPARINT, "SMB slave FIFO parity error" },
6291 		{ 0 }
6292 	};
6293 	static const struct intr_info smb_int_cause = {
6294 		.name = "SMB_INT_CAUSE",
6295 		.cause_reg = A_SMB_INT_CAUSE,
6296 		.enable_reg = A_SMB_INT_ENABLE,
6297 		.fatal = F_SLVFIFOPARINT | F_MSTRXFIFOPARINT | F_MSTTXFIFOPARINT,
6298 		.flags = 0,
6299 		.details = smb_int_cause_fields,
6300 		.actions = NULL,
6301 	};
6302 	return (t4_handle_intr(adap, &smb_int_cause, 0, flags));
6303 }
6304 
6305 /*
6306  * NC-SI interrupt handler.
6307  */
ncsi_intr_handler(struct adapter * adap,int arg,int flags)6308 static bool ncsi_intr_handler(struct adapter *adap, int arg, int flags)
6309 {
6310 	static const struct intr_details ncsi_int_cause_fields[] = {
6311 		{ F_CIM_DM_PRTY_ERR, "NC-SI CIM parity error" },
6312 		{ F_MPS_DM_PRTY_ERR, "NC-SI MPS parity error" },
6313 		{ F_TXFIFO_PRTY_ERR, "NC-SI Tx FIFO parity error" },
6314 		{ F_RXFIFO_PRTY_ERR, "NC-SI Rx FIFO parity error" },
6315 		{ 0 }
6316 	};
6317 	static const struct intr_info ncsi_int_cause = {
6318 		.name = "NCSI_INT_CAUSE",
6319 		.cause_reg = A_NCSI_INT_CAUSE,
6320 		.enable_reg = A_NCSI_INT_ENABLE,
6321 		.fatal = F_RXFIFO_PRTY_ERR | F_TXFIFO_PRTY_ERR |
6322 		    F_MPS_DM_PRTY_ERR | F_CIM_DM_PRTY_ERR,
6323 		.flags = 0,
6324 		.details = ncsi_int_cause_fields,
6325 		.actions = NULL,
6326 	};
6327 	static const struct intr_info ncsi_xgmac0_int_cause = {
6328 		.name = "NCSI_XGMAC0_INT_CAUSE",
6329 		.cause_reg = A_NCSI_XGMAC0_INT_CAUSE,
6330 		.enable_reg = A_NCSI_XGMAC0_INT_ENABLE,
6331 		.fatal = 0,
6332 		.flags = 0,
6333 		.details = NULL,
6334 		.actions = NULL,
6335 	};
6336 	bool fatal = false;
6337 
6338 	fatal |= t4_handle_intr(adap, &ncsi_int_cause, 0, flags);
6339 	if (chip_id(adap) > CHELSIO_T6)
6340 		fatal |= t4_handle_intr(adap, &ncsi_xgmac0_int_cause, 0, flags);
6341 	return (fatal);
6342 }
6343 
6344 /*
6345  * MAC interrupt handler.
6346  */
mac_intr_handler(struct adapter * adap,int port,int flags)6347 static bool mac_intr_handler(struct adapter *adap, int port, int flags)
6348 {
6349 	static const struct intr_info mac_int_cause_cmn = {
6350 		.name = "MAC_INT_CAUSE_CMN",
6351 		.cause_reg = A_MAC_INT_CAUSE_CMN,
6352 		.enable_reg = A_MAC_INT_EN_CMN,
6353 		.fatal = 0,
6354 		.flags = 0,
6355 		.details = NULL,
6356 		.actions = NULL,
6357 	};
6358 	static const struct intr_info mac_perr_cause_mtip = {
6359 		.name = "MAC_PERR_INT_CAUSE_MTIP",
6360 		.cause_reg = A_MAC_PERR_INT_CAUSE_MTIP,
6361 		.enable_reg = A_MAC_PERR_INT_EN_MTIP,
6362 		.fatal = 0xffffffff,
6363 		.flags = IHF_FATAL_IFF_ENABLED | IHF_IGNORE_IF_DISABLED,
6364 		.details = NULL,
6365 		.actions = NULL,
6366 	};
6367 	static const struct intr_info mac_cerr_cause_mtip = {
6368 		.name = "MAC_CERR_INT_CAUSE_MTIP",
6369 		.cause_reg = A_MAC_CERR_INT_CAUSE_MTIP,
6370 		.enable_reg = A_MAC_CERR_INT_EN_MTIP,
6371 		.fatal = 0,
6372 		.flags = 0,
6373 		.details = NULL,
6374 		.actions = NULL,
6375 	};
6376 	static const struct intr_info mac_ios_int_cause_quad0 = {
6377 		.name = "MAC_IOS_INTR_CAUSE_QUAD0",
6378 		.cause_reg = A_MAC_IOS_INTR_CAUSE_QUAD0,
6379 		.enable_reg = A_MAC_IOS_INTR_EN_QUAD0,
6380 		.fatal = 0,
6381 		.flags = 0,
6382 		.details = NULL,
6383 		.actions = NULL,
6384 	};
6385 	static const struct intr_info mac_ios_int_cause_quad1 = {
6386 		.name = "MAC_IOS_INTR_CAUSE_QUAD1",
6387 		.cause_reg = A_MAC_IOS_INTR_CAUSE_QUAD1,
6388 		.enable_reg = A_MAC_IOS_INTR_EN_QUAD1,
6389 		.fatal = 0,
6390 		.flags = 0,
6391 		.details = NULL,
6392 		.actions = NULL,
6393 	};
6394 	static const struct intr_details mac_intr_details[] = {
6395 		{ F_TXFIFO_PRTY_ERR, "MAC Tx FIFO parity error" },
6396 		{ F_RXFIFO_PRTY_ERR, "MAC Rx FIFO parity error" },
6397 		{ 0 }
6398 	};
6399 	char name[32];
6400 	struct intr_info ii;
6401 	bool fatal = false;
6402 
6403 	if (port > 1 && is_t6(adap))
6404 		return (false);
6405 
6406 	if (is_t4(adap)) {
6407 		snprintf(name, sizeof(name), "XGMAC_PORT%u_INT_CAUSE", port);
6408 		ii.name = &name[0];
6409 		ii.cause_reg = PORT_REG(port, A_XGMAC_PORT_INT_CAUSE);
6410 		ii.enable_reg = PORT_REG(port, A_XGMAC_PORT_INT_EN);
6411 		ii.fatal = F_TXFIFO_PRTY_ERR | F_RXFIFO_PRTY_ERR;
6412 		ii.flags = 0;
6413 		ii.details = mac_intr_details;
6414 		ii.actions = NULL;
6415 	} else if (chip_id(adap) < CHELSIO_T7) {
6416 		snprintf(name, sizeof(name), "MAC_PORT%u_INT_CAUSE", port);
6417 		ii.name = &name[0];
6418 		ii.cause_reg = T5_PORT_REG(port, A_MAC_PORT_INT_CAUSE);
6419 		ii.enable_reg = T5_PORT_REG(port, A_MAC_PORT_INT_EN);
6420 		ii.fatal = F_TXFIFO_PRTY_ERR | F_RXFIFO_PRTY_ERR;
6421 		ii.flags = 0;
6422 		ii.details = mac_intr_details;
6423 		ii.actions = NULL;
6424 	} else {
6425 		snprintf(name, sizeof(name), "MAC_PORT%u_INT_CAUSE", port);
6426 		ii.name = &name[0];
6427 		ii.cause_reg = T7_PORT_REG(port, A_T7_MAC_PORT_INT_CAUSE);
6428 		ii.enable_reg = T7_PORT_REG(port, A_T7_MAC_PORT_INT_EN);
6429 		ii.fatal = 0xffffffff;
6430 		ii.flags = IHF_FATAL_IFF_ENABLED;
6431 		ii.details = NULL;
6432 		ii.actions = NULL;
6433 	}
6434 	fatal |= t4_handle_intr(adap, &ii, 0, flags);
6435 	if (is_t4(adap))
6436 		return (fatal);
6437 
6438 	MPASS(chip_id(adap) >= CHELSIO_T5);
6439 	snprintf(name, sizeof(name), "MAC_PORT%u_PERR_INT_CAUSE", port);
6440 	if (chip_id(adap) > CHELSIO_T6) {
6441 		ii.name = &name[0];
6442 		ii.cause_reg = T7_PORT_REG(port, A_T7_MAC_PORT_PERR_INT_CAUSE);
6443 		ii.enable_reg = T7_PORT_REG(port, A_T7_MAC_PORT_PERR_INT_EN);
6444 		ii.fatal = 0xffffffff;
6445 		ii.flags = IHF_FATAL_IFF_ENABLED;
6446 		ii.details = NULL;
6447 		ii.actions = NULL;
6448 	} else {
6449 		ii.name = &name[0];
6450 		ii.cause_reg = T5_PORT_REG(port, A_MAC_PORT_PERR_INT_CAUSE);
6451 		ii.enable_reg = T5_PORT_REG(port, A_MAC_PORT_PERR_INT_EN);
6452 		ii.fatal = 0xffffffff;
6453 		ii.flags = IHF_FATAL_IFF_ENABLED;
6454 		ii.details = NULL;
6455 		ii.actions = NULL;
6456 	}
6457 	fatal |= t4_handle_intr(adap, &ii, 0, flags);
6458 	if (is_t5(adap))
6459 		return (fatal);
6460 
6461 	MPASS(chip_id(adap) >= CHELSIO_T6);
6462 	snprintf(name, sizeof(name), "MAC_PORT%u_PERR_INT_CAUSE_100G", port);
6463 	if (chip_id(adap) > CHELSIO_T6) {
6464 		ii.name = &name[0];
6465 		ii.cause_reg = T7_PORT_REG(port, A_T7_MAC_PORT_PERR_INT_CAUSE_100G);
6466 		ii.enable_reg = T7_PORT_REG(port, A_T7_MAC_PORT_PERR_INT_EN_100G);
6467 		ii.fatal = 0xffffffff;
6468 		ii.flags = IHF_FATAL_IFF_ENABLED;
6469 		ii.details = NULL;
6470 		ii.actions = NULL;
6471 	} else {
6472 		ii.name = &name[0];
6473 		ii.cause_reg = T5_PORT_REG(port, A_MAC_PORT_PERR_INT_CAUSE_100G);
6474 		ii.enable_reg = T5_PORT_REG(port, A_MAC_PORT_PERR_INT_EN_100G);
6475 		ii.fatal = 0xffffffff;
6476 		ii.flags = IHF_FATAL_IFF_ENABLED;
6477 		ii.details = NULL;
6478 		ii.actions = NULL;
6479 	}
6480 	fatal |= t4_handle_intr(adap, &ii, 0, flags);
6481 	if (is_t6(adap))
6482 		return (fatal);
6483 
6484 	MPASS(chip_id(adap) >= CHELSIO_T7);
6485 	fatal |= t4_handle_intr(adap, &mac_int_cause_cmn, 0, flags);
6486 	fatal |= t4_handle_intr(adap, &mac_perr_cause_mtip, 0, flags);
6487 	fatal |= t4_handle_intr(adap, &mac_cerr_cause_mtip, 0, flags);
6488 	fatal |= t4_handle_intr(adap, &mac_ios_int_cause_quad0, 0, flags);
6489 	fatal |= t4_handle_intr(adap, &mac_ios_int_cause_quad1, 0, flags);
6490 
6491 	return (fatal);
6492 }
6493 
pl_timeout_status(struct adapter * adap,int arg,int flags)6494 static bool pl_timeout_status(struct adapter *adap, int arg, int flags)
6495 {
6496 	if (flags & IHF_NO_SHOW)
6497 		return (false);
6498 
6499 	CH_ALERT(adap, "    PL_TIMEOUT_STATUS 0x%08x 0x%08x\n",
6500 	    t4_read_reg(adap, A_PL_TIMEOUT_STATUS0),
6501 	    t4_read_reg(adap, A_PL_TIMEOUT_STATUS1));
6502 
6503 	return (false);
6504 }
6505 
plpl_intr_handler(struct adapter * adap,int arg,int flags)6506 static bool plpl_intr_handler(struct adapter *adap, int arg, int flags)
6507 {
6508 	static const struct intr_details plpl_int_cause_fields[] = {
6509 		{ F_PL_BUSPERR, "Bus parity error" },
6510 		{ F_FATALPERR, "Fatal parity error" },
6511 		{ F_INVALIDACCESS, "Global reserved memory access" },
6512 		{ F_TIMEOUT,  "Bus timeout" },
6513 		{ F_PLERR, "Module reserved access" },
6514 		{ F_PERRVFID, "VFID_MAP parity error" },
6515 		{ 0 }
6516 	};
6517 	static const struct intr_action plpl_int_cause_actions[] = {
6518 		{ F_TIMEOUT, -1, pl_timeout_status },
6519 		{ 0 },
6520 	};
6521 	static const struct intr_info plpl_int_cause = {
6522 		.name = "PL_PL_INT_CAUSE",
6523 		.cause_reg = A_PL_PL_INT_CAUSE,
6524 		.enable_reg = A_PL_PL_INT_ENABLE,
6525 		.fatal = F_FATALPERR | F_PERRVFID,
6526 		.flags = IHF_FATAL_IFF_ENABLED | IHF_IGNORE_IF_DISABLED,
6527 		.details = plpl_int_cause_fields,
6528 		.actions = plpl_int_cause_actions,
6529 	};
6530 
6531 	return (t4_handle_intr(adap, &plpl_int_cause, 0, flags));
6532 }
6533 
6534 /* similar to t4_port_reg */
6535 static inline u32
t7_tlstx_reg(u8 instance,u8 channel,u32 reg)6536 t7_tlstx_reg(u8 instance, u8 channel, u32 reg)
6537 {
6538 	MPASS(instance <= 1);
6539 	MPASS(channel < NUM_TLS_TX_CH_INSTANCES);
6540 	return (instance * (CRYPTO_1_BASE_ADDR - CRYPTO_0_BASE_ADDR) +
6541 	    TLS_TX_CH_REG(reg, channel));
6542 }
6543 
6544 /*
6545  * CRYPTO (aka TLS_TX) interrupt handler.
6546  */
tlstx_intr_handler(struct adapter * adap,int idx,int flags)6547 static bool tlstx_intr_handler(struct adapter *adap, int idx, int flags)
6548 {
6549 	static const struct intr_details tlstx_int_cause_fields[] = {
6550 		{ F_KEX_CERR, "KEX SRAM Correctable error" },
6551 		{ F_KEYLENERR, "IPsec Key length error" },
6552 		{ F_INTF1_PERR, "Input Interface1 parity error" },
6553 		{ F_INTF0_PERR, "Input Interface0 parity error" },
6554 		{ F_KEX_PERR, "KEX SRAM Parity error" },
6555 		{ 0 }
6556 	};
6557 	struct intr_info ii = {
6558 		.fatal = F_KEX_PERR | F_INTF0_PERR | F_INTF1_PERR,
6559 		.flags = IHF_FATAL_IFF_ENABLED,
6560 		.details = tlstx_int_cause_fields,
6561 		.actions = NULL,
6562 	};
6563 	char name[32];
6564 	int ch;
6565 	bool fatal = false;
6566 
6567 	for (ch = 0; ch < NUM_TLS_TX_CH_INSTANCES; ch++) {
6568 		snprintf(name, sizeof(name), "TLSTX%u_CH%u_INT_CAUSE", idx, ch);
6569 		ii.name = &name[0];
6570 		ii.cause_reg = t7_tlstx_reg(idx, ch, A_TLS_TX_CH_INT_CAUSE);
6571 		ii.enable_reg = t7_tlstx_reg(idx, ch, A_TLS_TX_CH_INT_ENABLE);
6572 		fatal |= t4_handle_intr(adap, &ii, 0, flags);
6573 	}
6574 
6575 	return (fatal);
6576 }
6577 
6578 /*
6579  * HMA interrupt handler.
6580  */
hma_intr_handler(struct adapter * adap,int idx,int flags)6581 static bool hma_intr_handler(struct adapter *adap, int idx, int flags)
6582 {
6583 	static const struct intr_details hma_int_cause_fields[] = {
6584 		{ F_GK_UF_INT_CAUSE, "Gatekeeper underflow" },
6585 		{ F_IDTF_INT_CAUSE, "Invalid descriptor fault" },
6586 		{ F_OTF_INT_CAUSE, "Offset translation fault" },
6587 		{ F_RTF_INT_CAUSE, "Region translation fault" },
6588 		{ F_PCIEMST_INT_CAUSE, "PCIe master access error" },
6589 		{ F_MAMST_INT_CAUSE, "MA master access error" },
6590 		{ 1, "FIFO parity error" },
6591 		{ 0 }
6592 	};
6593 	static const struct intr_info hma_int_cause = {
6594 		.name = "HMA_INT_CAUSE",
6595 		.cause_reg = A_HMA_INT_CAUSE,
6596 		.enable_reg = A_HMA_INT_ENABLE,
6597 		.fatal = 7,
6598 		.flags = 0,
6599 		.details = hma_int_cause_fields,
6600 		.actions = NULL,
6601 	};
6602 
6603 	return (t4_handle_intr(adap, &hma_int_cause, 0, flags));
6604 }
6605 
6606 /*
6607  * CRYPTO_KEY interrupt handler.
6608  */
cryptokey_intr_handler(struct adapter * adap,int idx,int flags)6609 static bool cryptokey_intr_handler(struct adapter *adap, int idx, int flags)
6610 {
6611 	static const struct intr_details cryptokey_int_cause_fields[] = {
6612 		{ F_MA_FIFO_PERR, "MA arbiter FIFO parity error" },
6613 		{ F_MA_RSP_PERR, "MA response IF parity error" },
6614 		{ F_ING_CACHE_DATA_PERR, "Ingress key cache data parity error" },
6615 		{ F_ING_CACHE_TAG_PERR, "Ingress key cache tag parity error" },
6616 		{ F_LKP_KEY_REQ_PERR, "Ingress key req parity error" },
6617 		{ F_LKP_CLIP_TCAM_PERR, "Ingress LKP CLIP TCAM parity error" },
6618 		{ F_LKP_MAIN_TCAM_PERR, "Ingress LKP main TCAM parity error" },
6619 		{ F_EGR_KEY_REQ_PERR, "Egress key req or FIFO3 parity error" },
6620 		{ F_EGR_CACHE_DATA_PERR, "Egress key cache data parity error" },
6621 		{ F_EGR_CACHE_TAG_PERR, "Egress key cache tag parity error" },
6622 		{ F_CIM_PERR, "CIM interface parity error" },
6623 		{ F_MA_INV_RSP_TAG, "MA invalid response tag" },
6624 		{ F_ING_KEY_RANGE_ERR, "Ingress key range error" },
6625 		{ F_ING_MFIFO_OVFL, "Ingress MFIFO overflow" },
6626 		{ F_LKP_REQ_OVFL, "Ingress lookup FIFO overflow" },
6627 		{ F_EOK_WAIT_ERR, "EOK wait error" },
6628 		{ F_EGR_KEY_RANGE_ERR, "Egress key range error" },
6629 		{ F_EGR_MFIFO_OVFL, "Egress MFIFO overflow" },
6630 		{ F_SEQ_WRAP_HP_OVFL, "Sequence wrap (hi-pri)" },
6631 		{ F_SEQ_WRAP_LP_OVFL, "Sequence wrap (lo-pri)" },
6632 		{ F_EGR_SEQ_WRAP_HP, "Egress sequence wrap (hi-pri)" },
6633 		{ F_EGR_SEQ_WRAP_LP, "Egress sequence wrap (lo-pri)" },
6634 		{ 0 }
6635 	};
6636 	static const struct intr_info cryptokey_int_cause = {
6637 		.name = "CRYPTO_KEY_INT_CAUSE",
6638 		.cause_reg = A_CRYPTO_KEY_INT_CAUSE,
6639 		.enable_reg = A_CRYPTO_KEY_INT_ENABLE,
6640 		.fatal = 0xffffffff,
6641 		.flags = IHF_FATAL_IFF_ENABLED,
6642 		.details = cryptokey_int_cause_fields,
6643 		.actions = NULL,
6644 	};
6645 
6646 	return (t4_handle_intr(adap, &cryptokey_int_cause, 0, flags));
6647 }
6648 
6649 /*
6650  * GCACHE interrupt handler.
6651  */
gcache_intr_handler(struct adapter * adap,int idx,int flags)6652 static bool gcache_intr_handler(struct adapter *adap, int idx, int flags)
6653 {
6654 	static const struct intr_details gcache_int_cause_fields[] = {
6655 		{ F_GC1_SRAM_RSP_DATAQ_PERR_INT_CAUSE, "GC1 SRAM rsp dataq perr" },
6656 		{ F_GC0_SRAM_RSP_DATAQ_PERR_INT_CAUSE, "GC0 SRAM rsp dataq perr" },
6657 		{ F_GC1_WQDATA_FIFO_PERR_INT_CAUSE, "GC1 wqdata FIFO perr" },
6658 		{ F_GC0_WQDATA_FIFO_PERR_INT_CAUSE, "GC0 wqdata FIFO perr" },
6659 		{ F_GC1_RDTAG_QUEUE_PERR_INT_CAUSE, "GC1 rdtag queue perr" },
6660 		{ F_GC0_RDTAG_QUEUE_PERR_INT_CAUSE, "GC0 rdtag queue perr" },
6661 		{ F_GC1_SRAM_RDTAG_QUEUE_PERR_INT_CAUSE, "GC1 SRAM rdtag queue perr" },
6662 		{ F_GC0_SRAM_RDTAG_QUEUE_PERR_INT_CAUSE, "GC0 SRAM rdtag queue perr" },
6663 		{ F_GC1_RSP_PERR_INT_CAUSE, "GC1 rsp perr" },
6664 		{ F_GC0_RSP_PERR_INT_CAUSE, "GC0 rsp perr" },
6665 		{ F_GC1_LRU_UERR_INT_CAUSE, "GC1 lru uerr" },
6666 		{ F_GC0_LRU_UERR_INT_CAUSE, "GC0 lru uerr" },
6667 		{ F_GC1_TAG_UERR_INT_CAUSE, "GC1 tag uerr" },
6668 		{ F_GC0_TAG_UERR_INT_CAUSE, "GC0 tag uerr" },
6669 		{ F_GC1_LRU_CERR_INT_CAUSE, "GC1 lru cerr" },
6670 		{ F_GC0_LRU_CERR_INT_CAUSE, "GC0 lru cerr" },
6671 		{ F_GC1_TAG_CERR_INT_CAUSE, "GC1 tag cerr" },
6672 		{ F_GC0_TAG_CERR_INT_CAUSE, "GC0 tag cerr" },
6673 		{ F_GC1_CE_INT_CAUSE, "GC1 correctable error" },
6674 		{ F_GC0_CE_INT_CAUSE, "GC0 correctable error" },
6675 		{ F_GC1_UE_INT_CAUSE, "GC1 uncorrectable error" },
6676 		{ F_GC0_UE_INT_CAUSE, "GC0 uncorrectable error" },
6677 		{ F_GC1_CMD_PAR_INT_CAUSE, "GC1 cmd perr" },
6678 		{ F_GC1_DATA_PAR_INT_CAUSE, "GC1 data perr" },
6679 		{ F_GC0_CMD_PAR_INT_CAUSE, "GC0 cmd perr" },
6680 		{ F_GC0_DATA_PAR_INT_CAUSE, "GC0 data perr" },
6681 		{ F_ILLADDRACCESS1_INT_CAUSE, "GC1 illegal address access" },
6682 		{ F_ILLADDRACCESS0_INT_CAUSE, "GC0 illegal address access" },
6683 		{ 0 }
6684 	};
6685 	static const struct intr_info gcache_perr_cause = {
6686 		.name = "GCACHE_PAR_CAUSE",
6687 		.cause_reg = A_GCACHE_PAR_CAUSE,
6688 		.enable_reg = A_GCACHE_PAR_ENABLE,
6689 		.fatal = 0xffffffff,
6690 		.flags = IHF_FATAL_IFF_ENABLED,
6691 		.details = NULL,
6692 		.actions = NULL,
6693 	};
6694 	static const struct intr_info gcache_int_cause = {
6695 		.name = "GCACHE_INT_CAUSE",
6696 		.cause_reg = A_GCACHE_INT_CAUSE,
6697 		.enable_reg = A_GCACHE_INT_ENABLE,
6698 		.fatal = 0,
6699 		.flags = 0,
6700 		.details = gcache_int_cause_fields,
6701 		.actions = NULL,
6702 	};
6703 	bool fatal = false;
6704 
6705 	fatal |= t4_handle_intr(adap, &gcache_int_cause, 0, flags);
6706 	fatal |= t4_handle_intr(adap, &gcache_perr_cause, 0, flags);
6707 
6708 	return (fatal);
6709 }
6710 
6711 /*
6712  * ARM interrupt handler.
6713  */
arm_intr_handler(struct adapter * adap,int idx,int flags)6714 static bool arm_intr_handler(struct adapter *adap, int idx, int flags)
6715 {
6716 	static const struct intr_info arm_perr_cause0 = {
6717 		.name = "ARM_PERR_INT_CAUSE0",
6718 		.cause_reg = A_ARM_PERR_INT_CAUSE0,
6719 		.enable_reg = A_ARM_PERR_INT_ENB0,
6720 		.fatal = 0xffffffff,
6721 		.flags = IHF_IGNORE_IF_DISABLED | IHF_FATAL_IFF_ENABLED,
6722 		.details = NULL,
6723 		.actions = NULL,
6724 	};
6725 	static const struct intr_info arm_perr_cause1 = {
6726 		.name = "ARM_PERR_INT_CAUSE1",
6727 		.cause_reg = A_ARM_PERR_INT_CAUSE1,
6728 		.enable_reg = A_ARM_PERR_INT_ENB1,
6729 		.fatal = 0xffffffff,
6730 		.flags = IHF_IGNORE_IF_DISABLED | IHF_FATAL_IFF_ENABLED,
6731 		.details = NULL,
6732 		.actions = NULL,
6733 	};
6734 	static const struct intr_info arm_perr_cause2 = {
6735 		.name = "ARM_PERR_INT_CAUSE2",
6736 		.cause_reg = A_ARM_PERR_INT_CAUSE2,
6737 		.enable_reg = A_ARM_PERR_INT_ENB2,
6738 		.fatal = 0xffffffff,
6739 		.flags = IHF_IGNORE_IF_DISABLED | IHF_FATAL_IFF_ENABLED,
6740 		.details = NULL,
6741 		.actions = NULL,
6742 	};
6743 	static const struct intr_info arm_cerr_cause0 = {
6744 		.name = "ARM_CERR_INT_CAUSE",
6745 		.cause_reg = A_ARM_CERR_INT_CAUSE0,
6746 		.enable_reg = A_ARM_CERR_INT_ENB0,
6747 		.fatal = 0,
6748 		.flags = IHF_IGNORE_IF_DISABLED | IHF_FATAL_IFF_ENABLED,
6749 		.details = NULL,
6750 		.actions = NULL,
6751 	};
6752 	static const struct intr_info arm_err_cause0 = {
6753 		.name = "ARM_ERR_INT_CAUSE",
6754 		.cause_reg = A_ARM_ERR_INT_CAUSE0,
6755 		.enable_reg = A_ARM_ERR_INT_ENB0,
6756 		.fatal = 0,
6757 		.flags = IHF_IGNORE_IF_DISABLED | IHF_FATAL_IFF_ENABLED,
6758 		.details = NULL,
6759 		.actions = NULL,
6760 	};
6761 	static const struct intr_info arm_periph_cause = {
6762 		.name = "ARM_PERIPHERAL_INT_CAUSE",
6763 		.cause_reg = A_ARM_PERIPHERAL_INT_CAUSE,
6764 		.enable_reg = A_ARM_PERIPHERAL_INT_ENB,
6765 		.fatal = 0,
6766 		.flags = IHF_IGNORE_IF_DISABLED | IHF_FATAL_IFF_ENABLED,
6767 		.details = NULL,
6768 		.actions = NULL,
6769 	};
6770 	static const struct intr_info arm_nvme_db_emu_cause = {
6771 		.name = "ARM_NVME_DB_EMU_INT_CAUSE",
6772 		.cause_reg = A_ARM_NVME_DB_EMU_INT_CAUSE,
6773 		.enable_reg = A_ARM_NVME_DB_EMU_INT_ENABLE,
6774 		.fatal = 0,
6775 		.flags = IHF_IGNORE_IF_DISABLED | IHF_FATAL_IFF_ENABLED,
6776 		.details = NULL,
6777 		.actions = NULL,
6778 	};
6779 	bool fatal = false;
6780 
6781 	fatal |= t4_handle_intr(adap, &arm_perr_cause0, 0, flags);
6782 	fatal |= t4_handle_intr(adap, &arm_perr_cause1, 0, flags);
6783 	fatal |= t4_handle_intr(adap, &arm_perr_cause2, 0, flags);
6784 	fatal |= t4_handle_intr(adap, &arm_cerr_cause0, 0, flags);
6785 	fatal |= t4_handle_intr(adap, &arm_err_cause0, 0, flags);
6786 	fatal |= t4_handle_intr(adap, &arm_periph_cause, 0, flags);
6787 	fatal |= t4_handle_intr(adap, &arm_nvme_db_emu_cause, 0, flags);
6788 
6789 	return (fatal);
6790 }
6791 
6792 static inline uint32_t
get_perr_ucause(struct adapter * sc,const struct intr_info * ii)6793 get_perr_ucause(struct adapter *sc, const struct intr_info *ii)
6794 {
6795 	uint32_t cause;
6796 
6797 	cause = t4_read_reg(sc, ii->cause_reg);
6798 	if (ii->flags & IHF_IGNORE_IF_DISABLED)
6799 		cause &= t4_read_reg(sc, ii->enable_reg);
6800 	return (cause);
6801 }
6802 
6803 static uint32_t
t4_perr_to_ic(struct adapter * adap,uint32_t perr)6804 t4_perr_to_ic(struct adapter *adap, uint32_t perr)
6805 {
6806 	uint32_t mask;
6807 
6808 	if (adap->chip_params->nchan > 2)
6809 		mask = F_MAC0 | F_MAC1 | F_MAC2 | F_MAC3;
6810 	else
6811 		mask = F_MAC0 | F_MAC1;
6812 	return (perr & mask ? perr | mask : perr);
6813 }
6814 
6815 static uint32_t
t7_perr_to_ic1(uint32_t perr)6816 t7_perr_to_ic1(uint32_t perr)
6817 {
6818 	uint32_t cause = 0;
6819 
6820 	if (perr & F_T7_PL_PERR_ULP_TX)
6821 		cause |= F_T7_ULP_TX;
6822 	if (perr & F_T7_PL_PERR_SGE)
6823 		cause |= F_T7_SGE;
6824 	if (perr & F_T7_PL_PERR_HMA)
6825 		cause |= F_T7_HMA;
6826 	if (perr & F_T7_PL_PERR_CPL_SWITCH)
6827 		cause |= F_T7_CPL_SWITCH;
6828 	if (perr & F_T7_PL_PERR_ULP_RX)
6829 		cause |= F_T7_ULP_RX;
6830 	if (perr & F_T7_PL_PERR_PM_RX)
6831 		cause |= F_T7_PM_RX;
6832 	if (perr & F_T7_PL_PERR_PM_TX)
6833 		cause |= F_T7_PM_TX;
6834 	if (perr & F_T7_PL_PERR_MA)
6835 		cause |= F_T7_MA;
6836 	if (perr & F_T7_PL_PERR_TP)
6837 		cause |= F_T7_TP;
6838 	if (perr & F_T7_PL_PERR_LE)
6839 		cause |= F_T7_LE;
6840 	if (perr & F_T7_PL_PERR_EDC1)
6841 		cause |= F_T7_EDC1;
6842 	if (perr & F_T7_PL_PERR_EDC0)
6843 		cause |= F_T7_EDC0;
6844 	if (perr & F_T7_PL_PERR_MC1)
6845 		cause |= F_T7_MC1;
6846 	if (perr & F_T7_PL_PERR_MC0)
6847 		cause |= F_T7_MC0;
6848 	if (perr & F_T7_PL_PERR_PCIE)
6849 		cause |= F_T7_PCIE;
6850 	if (perr & F_T7_PL_PERR_UART)
6851 		cause |= F_T7_UART;
6852 	if (perr & F_T7_PL_PERR_PMU)
6853 		cause |= F_PMU;
6854 	if (perr & F_T7_PL_PERR_MAC)
6855 		cause |= F_MAC0 | F_MAC1 | F_MAC2 | F_MAC3;
6856 	if (perr & F_T7_PL_PERR_SMB)
6857 		cause |= F_SMB;
6858 	if (perr & F_T7_PL_PERR_SF)
6859 		cause |= F_SF;
6860 	if (perr & F_T7_PL_PERR_PL)
6861 		cause |= F_PL;
6862 	if (perr & F_T7_PL_PERR_NCSI)
6863 		cause |= F_NCSI;
6864 	if (perr & F_T7_PL_PERR_MPS)
6865 		cause |= F_MPS;
6866 	if (perr & F_T7_PL_PERR_MI)
6867 		cause |= F_MI;
6868 	if (perr & F_T7_PL_PERR_DBG)
6869 		cause |= F_DBG;
6870 	if (perr & F_T7_PL_PERR_I2CM)
6871 		cause |= F_I2CM;
6872 	if (perr & F_T7_PL_PERR_CIM)
6873 		cause |= F_CIM;
6874 
6875 	return (cause);
6876 }
6877 
6878 static uint32_t
t7_perr_to_ic2(uint32_t perr)6879 t7_perr_to_ic2(uint32_t perr)
6880 {
6881 	uint32_t cause = 0;
6882 
6883 	if (perr & F_T7_PL_PERR_CRYPTO_KEY)
6884 		cause |= F_CRYPTO_KEY;
6885 	if (perr & F_T7_PL_PERR_CRYPTO1)
6886 		cause |= F_CRYPTO1;
6887 	if (perr & F_T7_PL_PERR_CRYPTO0)
6888 		cause |= F_CRYPTO0;
6889 	if (perr & F_T7_PL_PERR_GCACHE)
6890 		cause |= F_GCACHE;
6891 	if (perr & F_T7_PL_PERR_ARM)
6892 		cause |= F_ARM;
6893 
6894 	return (cause);
6895 }
6896 
6897 /**
6898  *	t4_slow_intr_handler - control path interrupt handler
6899  *	@adap: the adapter
6900  *
6901  *	T4 interrupt handler for non-data global interrupt events, e.g., errors.
6902  *	The designation 'slow' is because it involves register reads, while
6903  *	data interrupts typically don't involve any MMIOs.
6904  */
t4_slow_intr_handler(struct adapter * adap,int flags)6905 bool t4_slow_intr_handler(struct adapter *adap, int flags)
6906 {
6907 	static const struct intr_details pl_int_cause_fields[] = {
6908 		{ F_MC1, "MC1" },
6909 		{ F_UART, "UART" },
6910 		{ F_ULP_TX, "ULP TX" },
6911 		{ F_SGE, "SGE" },
6912 		{ F_HMA, "HMA" },
6913 		{ F_CPL_SWITCH, "CPL Switch" },
6914 		{ F_ULP_RX, "ULP RX" },
6915 		{ F_PM_RX, "PM RX" },
6916 		{ F_PM_TX, "PM TX" },
6917 		{ F_MA, "MA" },
6918 		{ F_TP, "TP" },
6919 		{ F_LE, "LE" },
6920 		{ F_EDC1, "EDC1" },
6921 		{ F_EDC0, "EDC0" },
6922 		{ F_MC, "MC0" },
6923 		{ F_PCIE, "PCIE" },
6924 		{ F_PMU, "PMU" },
6925 		{ F_MAC3, "MAC3" },
6926 		{ F_MAC2, "MAC2" },
6927 		{ F_MAC1, "MAC1" },
6928 		{ F_MAC0, "MAC0" },
6929 		{ F_SMB, "SMB" },
6930 		{ F_SF, "SF" },
6931 		{ F_PL, "PL" },
6932 		{ F_NCSI, "NC-SI" },
6933 		{ F_MPS, "MPS" },
6934 		{ F_MI, "MI" },
6935 		{ F_DBG, "DBG" },
6936 		{ F_I2CM, "I2CM" },
6937 		{ F_CIM, "CIM" },
6938 		{ 0 }
6939 	};
6940 	static const struct intr_action pl_int_cause_actions[] = {
6941 		{ F_ULP_TX, -1, ulptx_intr_handler },
6942 		{ F_SGE, -1, sge_intr_handler },
6943 		{ F_CPL_SWITCH, -1, cplsw_intr_handler },
6944 		{ F_ULP_RX, -1, ulprx_intr_handler },
6945 		{ F_PM_RX, -1, pmtx_intr_handler },
6946 		{ F_PM_TX, -1, pmtx_intr_handler },
6947 		{ F_MA, -1, ma_intr_handler },
6948 		{ F_TP, -1, tp_intr_handler },
6949 		{ F_LE, -1, le_intr_handler },
6950 		{ F_EDC0, MEM_EDC0, mem_intr_handler },
6951 		{ F_EDC1, MEM_EDC1, mem_intr_handler },
6952 		{ F_MC0, MEM_MC0, mem_intr_handler },
6953 		{ F_MC1, MEM_MC1, mem_intr_handler },
6954 		{ F_PCIE, -1, pcie_intr_handler },
6955 		{ F_MAC0, 0, mac_intr_handler },
6956 		{ F_MAC1, 1, mac_intr_handler },
6957 		{ F_MAC2, 2, mac_intr_handler },
6958 		{ F_MAC3, 3, mac_intr_handler },
6959 		{ F_SMB, -1, smb_intr_handler },
6960 		{ F_PL, -1, plpl_intr_handler },
6961 		{ F_NCSI, -1, ncsi_intr_handler },
6962 		{ F_MPS, -1, mps_intr_handler },
6963 		{ F_CIM, -1, cim_intr_handler },
6964 		{ 0 }
6965 	};
6966 	static const struct intr_info pl_int_cause = {
6967 		.name = "PL_INT_CAUSE",
6968 		.cause_reg = A_PL_INT_CAUSE,
6969 		.enable_reg = A_PL_INT_ENABLE,
6970 		.fatal = 0,
6971 		.flags = IHF_IGNORE_IF_DISABLED,
6972 		.details = pl_int_cause_fields,
6973 		.actions = pl_int_cause_actions,
6974 	};
6975 	static const struct intr_info pl_perr_cause = {
6976 		.name = "PL_PERR_CAUSE",
6977 		.cause_reg = A_PL_PERR_CAUSE,
6978 		.enable_reg = A_PL_PERR_ENABLE,
6979 		.fatal = 0xffffffff,
6980 		.flags = IHF_IGNORE_IF_DISABLED | IHF_FATAL_IFF_ENABLED,
6981 		.details = pl_int_cause_fields,
6982 		.actions = NULL,
6983 	};
6984 	static const struct intr_details t7_pl_int_cause_fields[] = {
6985 		{ F_T7_FLR, "FLR" },
6986 		{ F_T7_SW_CIM, "SW CIM" },
6987 		{ F_T7_ULP_TX, "ULP TX" },
6988 		{ F_T7_SGE, "SGE" },
6989 		{ F_T7_HMA, "HMA" },
6990 		{ F_T7_CPL_SWITCH, "CPL Switch" },
6991 		{ F_T7_ULP_RX, "ULP RX" },
6992 		{ F_T7_PM_RX, "PM RX" },
6993 		{ F_T7_PM_TX, "PM TX" },
6994 		{ F_T7_MA, "MA" },
6995 		{ F_T7_TP, "TP" },
6996 		{ F_T7_LE, "LE" },
6997 		{ F_T7_EDC1, "EDC1" },
6998 		{ F_T7_EDC0, "EDC0" },
6999 		{ F_T7_MC1, "MC1" },
7000 		{ F_T7_MC0, "MC0" },
7001 		{ F_T7_PCIE, "PCIE" },
7002 		{ F_T7_UART, "UART" },
7003 		{ F_PMU, "PMU" },
7004 		{ F_MAC3, "MAC3" },
7005 		{ F_MAC2, "MAC2" },
7006 		{ F_MAC1, "MAC1" },
7007 		{ F_MAC0, "MAC0" },
7008 		{ F_SMB, "SMB" },
7009 		{ F_SF, "SF" },
7010 		{ F_PL, "PL" },
7011 		{ F_NCSI, "NC-SI" },
7012 		{ F_MPS, "MPS" },
7013 		{ F_MI, "MI" },
7014 		{ F_DBG, "DBG" },
7015 		{ F_I2CM, "I2CM" },
7016 		{ F_CIM, "CIM" },
7017 		{ 0 }
7018 	};
7019 	static const struct intr_action t7_pl_int_cause_actions[] = {
7020 		{ F_T7_ULP_TX, -1, ulptx_intr_handler },
7021 		{ F_T7_SGE, -1, sge_intr_handler },
7022 		{ F_T7_HMA, -1, hma_intr_handler },
7023 		{ F_T7_CPL_SWITCH, -1, cplsw_intr_handler },
7024 		{ F_T7_ULP_RX, -1, ulprx_intr_handler },
7025 		{ F_T7_PM_RX, -1, pmrx_intr_handler },
7026 		{ F_T7_PM_TX, -1, pmtx_intr_handler },
7027 		{ F_T7_MA, -1, ma_intr_handler },
7028 		{ F_T7_TP, -1, tp_intr_handler },
7029 		{ F_T7_LE, -1, le_intr_handler },
7030 		{ F_T7_EDC0, MEM_EDC0, mem_intr_handler },
7031 		{ F_T7_EDC1, MEM_EDC1, mem_intr_handler },
7032 		{ F_T7_MC0, MEM_MC0, mem_intr_handler },
7033 		{ F_T7_MC1, MEM_MC1, mem_intr_handler },
7034 		{ F_T7_PCIE, -1, pcie_intr_handler },
7035 		{ F_MAC0, 0, mac_intr_handler },
7036 		{ F_MAC1, 1, mac_intr_handler },
7037 		{ F_MAC2, 2, mac_intr_handler },
7038 		{ F_MAC3, 3, mac_intr_handler },
7039 		{ F_SMB, -1, smb_intr_handler },
7040 		{ F_PL, -1, plpl_intr_handler },
7041 		{ F_NCSI, -1, ncsi_intr_handler },
7042 		{ F_MPS, -1, mps_intr_handler },
7043 		{ F_CIM, -1, cim_intr_handler },
7044 		{ 0 }
7045 	};
7046 	static const struct intr_info t7_pl_int_cause = {
7047 		.name = "PL_INT_CAUSE",
7048 		.cause_reg = A_PL_INT_CAUSE,
7049 		.enable_reg = A_PL_INT_ENABLE,
7050 		.fatal = 0,
7051 		.flags = IHF_IGNORE_IF_DISABLED,
7052 		.details = t7_pl_int_cause_fields,
7053 		.actions = t7_pl_int_cause_actions,
7054 	};
7055 	static const struct intr_details t7_pl_int_cause2_fields[] = {
7056 		{ F_CRYPTO_KEY, "CRYPTO KEY" },
7057 		{ F_CRYPTO1, "CRYPTO1" },
7058 		{ F_CRYPTO0, "CRYPTO0" },
7059 		{ F_GCACHE, "GCACHE" },
7060 		{ F_ARM, "ARM" },
7061 		{ 0 }
7062 	};
7063 	static const struct intr_action t7_pl_int_cause2_actions[] = {
7064 		{ F_CRYPTO_KEY, -1, cryptokey_intr_handler },
7065 		{ F_CRYPTO1, 1, tlstx_intr_handler },
7066 		{ F_CRYPTO0, 0, tlstx_intr_handler },
7067 		{ F_GCACHE, -1, gcache_intr_handler },
7068 		{ F_ARM, -1, arm_intr_handler },
7069 		{ 0 }
7070 	};
7071 	static const struct intr_info t7_pl_int_cause2 = {
7072 		.name = "PL_INT_CAUSE2",
7073 		.cause_reg = A_PL_INT_CAUSE2,
7074 		.enable_reg = A_PL_INT_ENABLE2,
7075 		.fatal = 0,
7076 		.flags = IHF_IGNORE_IF_DISABLED,
7077 		.details = t7_pl_int_cause2_fields,
7078 		.actions = t7_pl_int_cause2_actions,
7079 	};
7080 	static const struct intr_details t7_pl_perr_cause_fields[] = {
7081 		{ F_T7_PL_PERR_CRYPTO_KEY, "CRYPTO KEY" },
7082 		{ F_T7_PL_PERR_CRYPTO1, "CRYPTO1" },
7083 		{ F_T7_PL_PERR_CRYPTO0, "CRYPTO0" },
7084 		{ F_T7_PL_PERR_GCACHE, "GCACHE" },
7085 		{ F_T7_PL_PERR_ARM, "ARM" },
7086 		{ F_T7_PL_PERR_ULP_TX, "ULP TX" },
7087 		{ F_T7_PL_PERR_SGE, "SGE" },
7088 		{ F_T7_PL_PERR_HMA, "HMA" },
7089 		{ F_T7_PL_PERR_CPL_SWITCH, "CPL Switch" },
7090 		{ F_T7_PL_PERR_ULP_RX, "ULP RX" },
7091 		{ F_T7_PL_PERR_PM_RX, "PM RX" },
7092 		{ F_T7_PL_PERR_PM_TX, "PM TX" },
7093 		{ F_T7_PL_PERR_MA, "MA" },
7094 		{ F_T7_PL_PERR_TP, "TP" },
7095 		{ F_T7_PL_PERR_LE, "LE" },
7096 		{ F_T7_PL_PERR_EDC1, "EDC1" },
7097 		{ F_T7_PL_PERR_EDC0, "EDC0" },
7098 		{ F_T7_PL_PERR_MC1, "MC1" },
7099 		{ F_T7_PL_PERR_MC0, "MC0" },
7100 		{ F_T7_PL_PERR_PCIE, "PCIE" },
7101 		{ F_T7_PL_PERR_UART, "UART" },
7102 		{ F_T7_PL_PERR_PMU, "PMU" },
7103 		{ F_T7_PL_PERR_MAC, "MAC" },
7104 		{ F_T7_PL_PERR_SMB, "SMB" },
7105 		{ F_T7_PL_PERR_SF, "SF" },
7106 		{ F_T7_PL_PERR_PL, "PL" },
7107 		{ F_T7_PL_PERR_NCSI, "NC-SI" },
7108 		{ F_T7_PL_PERR_MPS, "MPS" },
7109 		{ F_T7_PL_PERR_MI, "MI" },
7110 		{ F_T7_PL_PERR_DBG, "DBG" },
7111 		{ F_T7_PL_PERR_I2CM, "I2CM" },
7112 		{ F_T7_PL_PERR_CIM, "CIM" },
7113 		{ 0 }
7114 	};
7115 	static const struct intr_info t7_pl_perr_cause = {
7116 		.name = "PL_PERR_CAUSE",
7117 		.cause_reg = A_PL_PERR_CAUSE,
7118 		.enable_reg = A_PL_PERR_ENABLE,
7119 		.fatal = 0xffffffff,
7120 		.flags = IHF_IGNORE_IF_DISABLED | IHF_FATAL_IFF_ENABLED,
7121 		.details = t7_pl_perr_cause_fields,
7122 		.actions = NULL,
7123 	};
7124 	bool fatal = false;
7125 	uint32_t perr;
7126 
7127 	if (chip_id(adap) < CHELSIO_T7) {
7128 		perr = get_perr_ucause(adap, &pl_perr_cause);
7129 		fatal |= t4_handle_intr(adap, &pl_perr_cause, 0,
7130 		    flags & ~(IHF_CLR_ALL_SET | IHF_CLR_ALL_UNIGNORED));
7131 		fatal |= t4_handle_intr(adap, &pl_int_cause,
7132 		    t4_perr_to_ic(adap, perr), flags);
7133 		t4_write_reg(adap, pl_perr_cause.cause_reg, perr);
7134 		(void)t4_read_reg(adap, pl_perr_cause.cause_reg);
7135 	} else {
7136 		perr = get_perr_ucause(adap, &t7_pl_perr_cause);
7137 		fatal |= t4_handle_intr(adap, &t7_pl_perr_cause, 0,
7138 		    flags & ~(IHF_CLR_ALL_SET | IHF_CLR_ALL_UNIGNORED));
7139 		fatal |= t4_handle_intr(adap, &t7_pl_int_cause,
7140 		    t7_perr_to_ic1(perr), flags);
7141 		fatal |= t4_handle_intr(adap, &t7_pl_int_cause2,
7142 		    t7_perr_to_ic2(perr), flags);
7143 		t4_write_reg(adap, t7_pl_perr_cause.cause_reg, perr);
7144 		(void)t4_read_reg(adap, t7_pl_perr_cause.cause_reg);
7145 	}
7146 	return (fatal);
7147 }
7148 
t4_intr_clear(struct adapter * adap)7149 void t4_intr_clear(struct adapter *adap)
7150 {
7151 #if 1
7152 	if (chip_id(adap) >= CHELSIO_T7)
7153 		t4_write_reg(adap, A_SGE_INT_CAUSE8, 0xffffffff);
7154 #endif
7155 	(void)t4_slow_intr_handler(adap,
7156 	    IHF_NO_SHOW | IHF_RUN_ALL_ACTIONS | IHF_CLR_ALL_SET);
7157 }
7158 
7159 /**
7160  *	t4_intr_enable - enable interrupts
7161  *	@adapter: the adapter whose interrupts should be enabled
7162  *
7163  *	Enable PF-specific interrupts for the calling function and the top-level
7164  *	interrupt concentrator for global interrupts.  Interrupts are already
7165  *	enabled at each module,	here we just enable the roots of the interrupt
7166  *	hierarchies.
7167  *
7168  *	Note: this function should be called only when the driver manages
7169  *	non PF-specific interrupts from the various HW modules.  Only one PCI
7170  *	function at a time should be doing this.
7171  */
t4_intr_enable(struct adapter * adap)7172 void t4_intr_enable(struct adapter *adap)
7173 {
7174 	u32 mask, val;
7175 
7176 	if (adap->intr_flags & IHF_INTR_CLEAR_ON_INIT)
7177 		t4_intr_clear(adap);
7178 	if (chip_id(adap) <= CHELSIO_T5)
7179 		val = F_ERR_DROPPED_DB | F_ERR_EGR_CTXT_PRIO | F_DBFIFO_HP_INT |
7180 		    F_DBFIFO_LP_INT;
7181 	else
7182 		val = F_ERR_PCIE_ERROR0 | F_ERR_PCIE_ERROR1 | F_FATAL_WRE_LEN;
7183 	val |= F_ERR_CPL_EXCEED_IQE_SIZE | F_ERR_INVALID_CIDX_INC |
7184 	    F_ERR_CPL_OPCODE_0 | F_ERR_DATA_CPL_ON_HIGH_QID1 |
7185 	    F_INGRESS_SIZE_ERR | F_ERR_DATA_CPL_ON_HIGH_QID0 |
7186 	    F_ERR_BAD_DB_PIDX3 | F_ERR_BAD_DB_PIDX2 | F_ERR_BAD_DB_PIDX1 |
7187 	    F_ERR_BAD_DB_PIDX0 | F_ERR_ING_CTXT_PRIO | F_EGRESS_SIZE_ERR;
7188 	mask = val;
7189 	t4_set_reg_field(adap, A_SGE_INT_ENABLE3, mask, val);
7190 	if (chip_id(adap) >= CHELSIO_T7)
7191 		t4_write_reg(adap, A_SGE_INT_ENABLE4, 0xffffffff);
7192 	t4_write_reg(adap, MYPF_REG(A_PL_PF_INT_ENABLE), F_PFSW | F_PFCIM);
7193 	t4_set_reg_field(adap, A_PL_INT_ENABLE, F_SF | F_I2CM, 0);
7194 #if 1
7195 	if (chip_id(adap) >= CHELSIO_T7)
7196 		t4_set_reg_field(adap, A_PL_INT_ENABLE, F_MAC0 | F_MAC1 | F_MAC2 | F_MAC3, 0);
7197 #endif
7198 	t4_set_reg_field(adap, A_PL_INT_MAP0, 0, 1 << adap->pf);
7199 }
7200 
7201 /**
7202  *	t4_intr_disable - disable interrupts
7203  *	@adap: the adapter whose interrupts should be disabled
7204  *
7205  *	Disable interrupts.  We only disable the top-level interrupt
7206  *	concentrators.  The caller must be a PCI function managing global
7207  *	interrupts.
7208  */
t4_intr_disable(struct adapter * adap)7209 void t4_intr_disable(struct adapter *adap)
7210 {
7211 
7212 	t4_write_reg(adap, MYPF_REG(A_PL_PF_INT_ENABLE), 0);
7213 	t4_set_reg_field(adap, A_PL_INT_MAP0, 1 << adap->pf, 0);
7214 }
7215 
7216 /**
7217  *	hash_mac_addr - return the hash value of a MAC address
7218  *	@addr: the 48-bit Ethernet MAC address
7219  *
7220  *	Hashes a MAC address according to the hash function used by HW inexact
7221  *	(hash) address matching.
7222  */
hash_mac_addr(const u8 * addr)7223 static int hash_mac_addr(const u8 *addr)
7224 {
7225 	u32 a = ((u32)addr[0] << 16) | ((u32)addr[1] << 8) | addr[2];
7226 	u32 b = ((u32)addr[3] << 16) | ((u32)addr[4] << 8) | addr[5];
7227 	a ^= b;
7228 	a ^= (a >> 12);
7229 	a ^= (a >> 6);
7230 	return a & 0x3f;
7231 }
7232 
7233 /**
7234  *	t4_config_rss_range - configure a portion of the RSS mapping table
7235  *	@adapter: the adapter
7236  *	@mbox: mbox to use for the FW command
7237  *	@viid: virtual interface whose RSS subtable is to be written
7238  *	@start: start entry in the table to write
7239  *	@n: how many table entries to write
7240  *	@rspq: values for the "response queue" (Ingress Queue) lookup table
7241  *	@nrspq: number of values in @rspq
7242  *
7243  *	Programs the selected part of the VI's RSS mapping table with the
7244  *	provided values.  If @nrspq < @n the supplied values are used repeatedly
7245  *	until the full table range is populated.
7246  *
7247  *	The caller must ensure the values in @rspq are in the range allowed for
7248  *	@viid.
7249  */
t4_config_rss_range(struct adapter * adapter,int mbox,unsigned int viid,int start,int n,const u16 * rspq,unsigned int nrspq)7250 int t4_config_rss_range(struct adapter *adapter, int mbox, unsigned int viid,
7251 			int start, int n, const u16 *rspq, unsigned int nrspq)
7252 {
7253 	int ret;
7254 	const u16 *rsp = rspq;
7255 	const u16 *rsp_end = rspq + nrspq;
7256 	struct fw_rss_ind_tbl_cmd cmd;
7257 
7258 	memset(&cmd, 0, sizeof(cmd));
7259 	cmd.op_to_viid = cpu_to_be32(V_FW_CMD_OP(FW_RSS_IND_TBL_CMD) |
7260 				     F_FW_CMD_REQUEST | F_FW_CMD_WRITE |
7261 				     V_FW_RSS_IND_TBL_CMD_VIID(viid));
7262 	cmd.retval_len16 = cpu_to_be32(FW_LEN16(cmd));
7263 
7264 	/*
7265 	 * Each firmware RSS command can accommodate up to 32 RSS Ingress
7266 	 * Queue Identifiers.  These Ingress Queue IDs are packed three to
7267 	 * a 32-bit word as 10-bit values with the upper remaining 2 bits
7268 	 * reserved.
7269 	 */
7270 	while (n > 0) {
7271 		int nq = min(n, 32);
7272 		int nq_packed = 0;
7273 		__be32 *qp = &cmd.iq0_to_iq2;
7274 
7275 		/*
7276 		 * Set up the firmware RSS command header to send the next
7277 		 * "nq" Ingress Queue IDs to the firmware.
7278 		 */
7279 		cmd.niqid = cpu_to_be16(nq);
7280 		cmd.startidx = cpu_to_be16(start);
7281 
7282 		/*
7283 		 * "nq" more done for the start of the next loop.
7284 		 */
7285 		start += nq;
7286 		n -= nq;
7287 
7288 		/*
7289 		 * While there are still Ingress Queue IDs to stuff into the
7290 		 * current firmware RSS command, retrieve them from the
7291 		 * Ingress Queue ID array and insert them into the command.
7292 		 */
7293 		while (nq > 0) {
7294 			/*
7295 			 * Grab up to the next 3 Ingress Queue IDs (wrapping
7296 			 * around the Ingress Queue ID array if necessary) and
7297 			 * insert them into the firmware RSS command at the
7298 			 * current 3-tuple position within the commad.
7299 			 */
7300 			u16 qbuf[3];
7301 			u16 *qbp = qbuf;
7302 			int nqbuf = min(3, nq);
7303 
7304 			nq -= nqbuf;
7305 			qbuf[0] = qbuf[1] = qbuf[2] = 0;
7306 			while (nqbuf && nq_packed < 32) {
7307 				nqbuf--;
7308 				nq_packed++;
7309 				*qbp++ = *rsp++;
7310 				if (rsp >= rsp_end)
7311 					rsp = rspq;
7312 			}
7313 			*qp++ = cpu_to_be32(V_FW_RSS_IND_TBL_CMD_IQ0(qbuf[0]) |
7314 					    V_FW_RSS_IND_TBL_CMD_IQ1(qbuf[1]) |
7315 					    V_FW_RSS_IND_TBL_CMD_IQ2(qbuf[2]));
7316 		}
7317 
7318 		/*
7319 		 * Send this portion of the RRS table update to the firmware;
7320 		 * bail out on any errors.
7321 		 */
7322 		ret = t4_wr_mbox(adapter, mbox, &cmd, sizeof(cmd), NULL);
7323 		if (ret)
7324 			return ret;
7325 	}
7326 	return 0;
7327 }
7328 
7329 /**
7330  *	t4_config_glbl_rss - configure the global RSS mode
7331  *	@adapter: the adapter
7332  *	@mbox: mbox to use for the FW command
7333  *	@mode: global RSS mode
7334  *	@flags: mode-specific flags
7335  *
7336  *	Sets the global RSS mode.
7337  */
t4_config_glbl_rss(struct adapter * adapter,int mbox,unsigned int mode,unsigned int flags)7338 int t4_config_glbl_rss(struct adapter *adapter, int mbox, unsigned int mode,
7339 		       unsigned int flags)
7340 {
7341 	struct fw_rss_glb_config_cmd c;
7342 
7343 	memset(&c, 0, sizeof(c));
7344 	c.op_to_write = cpu_to_be32(V_FW_CMD_OP(FW_RSS_GLB_CONFIG_CMD) |
7345 				    F_FW_CMD_REQUEST | F_FW_CMD_WRITE);
7346 	c.retval_len16 = cpu_to_be32(FW_LEN16(c));
7347 	if (mode == FW_RSS_GLB_CONFIG_CMD_MODE_MANUAL) {
7348 		c.u.manual.mode_pkd =
7349 			cpu_to_be32(V_FW_RSS_GLB_CONFIG_CMD_MODE(mode));
7350 	} else if (mode == FW_RSS_GLB_CONFIG_CMD_MODE_BASICVIRTUAL) {
7351 		c.u.basicvirtual.mode_keymode =
7352 			cpu_to_be32(V_FW_RSS_GLB_CONFIG_CMD_MODE(mode));
7353 		c.u.basicvirtual.synmapen_to_hashtoeplitz = cpu_to_be32(flags);
7354 	} else
7355 		return -EINVAL;
7356 	return t4_wr_mbox(adapter, mbox, &c, sizeof(c), NULL);
7357 }
7358 
7359 /**
7360  *	t4_config_vi_rss - configure per VI RSS settings
7361  *	@adapter: the adapter
7362  *	@mbox: mbox to use for the FW command
7363  *	@viid: the VI id
7364  *	@flags: RSS flags
7365  *	@defq: id of the default RSS queue for the VI.
7366  *	@skeyidx: RSS secret key table index for non-global mode
7367  *	@skey: RSS vf_scramble key for VI.
7368  *
7369  *	Configures VI-specific RSS properties.
7370  */
t4_config_vi_rss(struct adapter * adapter,int mbox,unsigned int viid,unsigned int flags,unsigned int defq,unsigned int skeyidx,unsigned int skey)7371 int t4_config_vi_rss(struct adapter *adapter, int mbox, unsigned int viid,
7372 		     unsigned int flags, unsigned int defq, unsigned int skeyidx,
7373 		     unsigned int skey)
7374 {
7375 	struct fw_rss_vi_config_cmd c;
7376 
7377 	memset(&c, 0, sizeof(c));
7378 	c.op_to_viid = cpu_to_be32(V_FW_CMD_OP(FW_RSS_VI_CONFIG_CMD) |
7379 				   F_FW_CMD_REQUEST | F_FW_CMD_WRITE |
7380 				   V_FW_RSS_VI_CONFIG_CMD_VIID(viid));
7381 	c.retval_len16 = cpu_to_be32(FW_LEN16(c));
7382 	c.u.basicvirtual.defaultq_to_udpen = cpu_to_be32(flags |
7383 					V_FW_RSS_VI_CONFIG_CMD_DEFAULTQ(defq));
7384 	c.u.basicvirtual.secretkeyidx_pkd = cpu_to_be32(
7385 					V_FW_RSS_VI_CONFIG_CMD_SECRETKEYIDX(skeyidx));
7386 	c.u.basicvirtual.secretkeyxor = cpu_to_be32(skey);
7387 
7388 	return t4_wr_mbox(adapter, mbox, &c, sizeof(c), NULL);
7389 }
7390 
7391 /* Read an RSS table row */
rd_rss_row(struct adapter * adap,int row,u32 * val)7392 static int rd_rss_row(struct adapter *adap, int row, u32 *val)
7393 {
7394 	if (chip_id(adap) < CHELSIO_T7) {
7395 		t4_write_reg(adap, A_TP_RSS_LKP_TABLE, 0xfff00000 | row);
7396 		return t4_wait_op_done_val(adap, A_TP_RSS_LKP_TABLE,
7397 					   F_LKPTBLROWVLD, 1, 5, 0, val);
7398 	} else {
7399 		t4_write_reg(adap, A_TP_RSS_CONFIG_SRAM, 0xB0000 | row);
7400 		return t7_wait_sram_done(adap, A_TP_RSS_CONFIG_SRAM,
7401 					 A_TP_RSS_LKP_TABLE, 5, 0, val);
7402 	}
7403 }
7404 
7405 /**
7406  *	t4_read_rss - read the contents of the RSS mapping table
7407  *	@adapter: the adapter
7408  *	@map: holds the contents of the RSS mapping table
7409  *
7410  *	Reads the contents of the RSS hash->queue mapping table.
7411  */
t4_read_rss(struct adapter * adapter,u16 * map)7412 int t4_read_rss(struct adapter *adapter, u16 *map)
7413 {
7414 	u32 val;
7415 	int i, ret;
7416 	int rss_nentries = adapter->chip_params->rss_nentries;
7417 
7418 	for (i = 0; i < rss_nentries / 2; ++i) {
7419 		ret = rd_rss_row(adapter, i, &val);
7420 		if (ret)
7421 			return ret;
7422 		*map++ = G_LKPTBLQUEUE0(val);
7423 		*map++ = G_LKPTBLQUEUE1(val);
7424 	}
7425 	return 0;
7426 }
7427 
7428 /**
7429  * t4_tp_fw_ldst_rw - Access TP indirect register through LDST
7430  * @adap: the adapter
7431  * @cmd: TP fw ldst address space type
7432  * @vals: where the indirect register values are stored/written
7433  * @nregs: how many indirect registers to read/write
7434  * @start_idx: index of first indirect register to read/write
7435  * @rw: Read (1) or Write (0)
7436  * @sleep_ok: if true we may sleep while awaiting command completion
7437  *
7438  * Access TP indirect registers through LDST
7439  **/
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)7440 static int t4_tp_fw_ldst_rw(struct adapter *adap, int cmd, u32 *vals,
7441 			    unsigned int nregs, unsigned int start_index,
7442 			    unsigned int rw, bool sleep_ok)
7443 {
7444 	int ret = 0;
7445 	unsigned int i;
7446 	struct fw_ldst_cmd c;
7447 
7448 	for (i = 0; i < nregs; i++) {
7449 		memset(&c, 0, sizeof(c));
7450 		c.op_to_addrspace = cpu_to_be32(V_FW_CMD_OP(FW_LDST_CMD) |
7451 						F_FW_CMD_REQUEST |
7452 						(rw ? F_FW_CMD_READ :
7453 						      F_FW_CMD_WRITE) |
7454 						V_FW_LDST_CMD_ADDRSPACE(cmd));
7455 		c.cycles_to_len16 = cpu_to_be32(FW_LEN16(c));
7456 
7457 		c.u.addrval.addr = cpu_to_be32(start_index + i);
7458 		c.u.addrval.val  = rw ? 0 : cpu_to_be32(vals[i]);
7459 		ret = t4_wr_mbox_meat(adap, adap->mbox, &c, sizeof(c), &c,
7460 				      sleep_ok);
7461 		if (ret)
7462 			return ret;
7463 
7464 		if (rw)
7465 			vals[i] = be32_to_cpu(c.u.addrval.val);
7466 	}
7467 	return 0;
7468 }
7469 
7470 /**
7471  * t4_tp_indirect_rw - Read/Write TP indirect register through LDST or backdoor
7472  * @adap: the adapter
7473  * @reg_addr: Address Register
7474  * @reg_data: Data register
7475  * @buff: where the indirect register values are stored/written
7476  * @nregs: how many indirect registers to read/write
7477  * @start_index: index of first indirect register to read/write
7478  * @rw: READ(1) or WRITE(0)
7479  * @sleep_ok: if true we may sleep while awaiting command completion
7480  *
7481  * Read/Write TP indirect registers through LDST if possible.
7482  * Else, use backdoor access
7483  **/
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)7484 static void t4_tp_indirect_rw(struct adapter *adap, u32 reg_addr, u32 reg_data,
7485 			      u32 *buff, u32 nregs, u32 start_index, int rw,
7486 			      bool sleep_ok)
7487 {
7488 	int rc = -EINVAL;
7489 	int cmd;
7490 
7491 	switch (reg_addr) {
7492 	case A_TP_PIO_ADDR:
7493 		cmd = FW_LDST_ADDRSPC_TP_PIO;
7494 		break;
7495 	case A_TP_TM_PIO_ADDR:
7496 		cmd = FW_LDST_ADDRSPC_TP_TM_PIO;
7497 		break;
7498 	case A_TP_MIB_INDEX:
7499 		cmd = FW_LDST_ADDRSPC_TP_MIB;
7500 		break;
7501 	default:
7502 		goto indirect_access;
7503 	}
7504 
7505 	if (t4_use_ldst(adap))
7506 		rc = t4_tp_fw_ldst_rw(adap, cmd, buff, nregs, start_index, rw,
7507 				      sleep_ok);
7508 
7509 indirect_access:
7510 
7511 	if (rc) {
7512 		if (rw)
7513 			t4_read_indirect(adap, reg_addr, reg_data, buff, nregs,
7514 					 start_index);
7515 		else
7516 			t4_write_indirect(adap, reg_addr, reg_data, buff, nregs,
7517 					  start_index);
7518 	}
7519 }
7520 
7521 /**
7522  * t4_tp_pio_read - Read TP PIO registers
7523  * @adap: the adapter
7524  * @buff: where the indirect register values are written
7525  * @nregs: how many indirect registers to read
7526  * @start_index: index of first indirect register to read
7527  * @sleep_ok: if true we may sleep while awaiting command completion
7528  *
7529  * Read TP PIO Registers
7530  **/
t4_tp_pio_read(struct adapter * adap,u32 * buff,u32 nregs,u32 start_index,bool sleep_ok)7531 void t4_tp_pio_read(struct adapter *adap, u32 *buff, u32 nregs,
7532 		    u32 start_index, bool sleep_ok)
7533 {
7534 	t4_tp_indirect_rw(adap, A_TP_PIO_ADDR, A_TP_PIO_DATA, buff, nregs,
7535 			  start_index, 1, sleep_ok);
7536 }
7537 
7538 /**
7539  * t4_tp_pio_write - Write TP PIO registers
7540  * @adap: the adapter
7541  * @buff: where the indirect register values are stored
7542  * @nregs: how many indirect registers to write
7543  * @start_index: index of first indirect register to write
7544  * @sleep_ok: if true we may sleep while awaiting command completion
7545  *
7546  * Write TP PIO Registers
7547  **/
t4_tp_pio_write(struct adapter * adap,const u32 * buff,u32 nregs,u32 start_index,bool sleep_ok)7548 void t4_tp_pio_write(struct adapter *adap, const u32 *buff, u32 nregs,
7549 		     u32 start_index, bool sleep_ok)
7550 {
7551 	t4_tp_indirect_rw(adap, A_TP_PIO_ADDR, A_TP_PIO_DATA,
7552 	    __DECONST(u32 *, buff), nregs, start_index, 0, sleep_ok);
7553 }
7554 
7555 /**
7556  * t4_tp_tm_pio_read - Read TP TM PIO registers
7557  * @adap: the adapter
7558  * @buff: where the indirect register values are written
7559  * @nregs: how many indirect registers to read
7560  * @start_index: index of first indirect register to read
7561  * @sleep_ok: if true we may sleep while awaiting command completion
7562  *
7563  * Read TP TM PIO Registers
7564  **/
t4_tp_tm_pio_read(struct adapter * adap,u32 * buff,u32 nregs,u32 start_index,bool sleep_ok)7565 void t4_tp_tm_pio_read(struct adapter *adap, u32 *buff, u32 nregs,
7566 		       u32 start_index, bool sleep_ok)
7567 {
7568 	t4_tp_indirect_rw(adap, A_TP_TM_PIO_ADDR, A_TP_TM_PIO_DATA, buff,
7569 			  nregs, start_index, 1, sleep_ok);
7570 }
7571 
7572 /**
7573  * t4_tp_mib_read - Read TP MIB registers
7574  * @adap: the adapter
7575  * @buff: where the indirect register values are written
7576  * @nregs: how many indirect registers to read
7577  * @start_index: index of first indirect register to read
7578  * @sleep_ok: if true we may sleep while awaiting command completion
7579  *
7580  * Read TP MIB Registers
7581  **/
t4_tp_mib_read(struct adapter * adap,u32 * buff,u32 nregs,u32 start_index,bool sleep_ok)7582 void t4_tp_mib_read(struct adapter *adap, u32 *buff, u32 nregs, u32 start_index,
7583 		    bool sleep_ok)
7584 {
7585 	t4_tp_indirect_rw(adap, A_TP_MIB_INDEX, A_TP_MIB_DATA, buff, nregs,
7586 			  start_index, 1, sleep_ok);
7587 }
7588 
7589 /**
7590  *	t4_read_rss_key - read the global RSS key
7591  *	@adap: the adapter
7592  *	@key: 10-entry array holding the 320-bit RSS key
7593  * 	@sleep_ok: if true we may sleep while awaiting command completion
7594  *
7595  *	Reads the global 320-bit RSS key.
7596  */
t4_read_rss_key(struct adapter * adap,u32 * key,bool sleep_ok)7597 void t4_read_rss_key(struct adapter *adap, u32 *key, bool sleep_ok)
7598 {
7599 	t4_tp_pio_read(adap, key, 10, A_TP_RSS_SECRET_KEY0, sleep_ok);
7600 }
7601 
7602 /**
7603  *	t4_write_rss_key - program one of the RSS keys
7604  *	@adap: the adapter
7605  *	@key: 10-entry array holding the 320-bit RSS key
7606  *	@idx: which RSS key to write
7607  * 	@sleep_ok: if true we may sleep while awaiting command completion
7608  *
7609  *	Writes one of the RSS keys with the given 320-bit value.  If @idx is
7610  *	0..15 the corresponding entry in the RSS key table is written,
7611  *	otherwise the global RSS key is written.
7612  */
t4_write_rss_key(struct adapter * adap,const u32 * key,int idx,bool sleep_ok)7613 void t4_write_rss_key(struct adapter *adap, const u32 *key, int idx,
7614 		      bool sleep_ok)
7615 {
7616 	u8 rss_key_addr_cnt = 16;
7617 	u32 vrt = t4_read_reg(adap, A_TP_RSS_CONFIG_VRT);
7618 
7619 	/*
7620 	 * T6 and later: for KeyMode 3 (per-vf and per-vf scramble),
7621 	 * allows access to key addresses 16-63 by using KeyWrAddrX
7622 	 * as index[5:4](upper 2) into key table
7623 	 */
7624 	if ((chip_id(adap) > CHELSIO_T5) &&
7625 	    (vrt & F_KEYEXTEND) && (G_KEYMODE(vrt) == 3))
7626 		rss_key_addr_cnt = 32;
7627 
7628 	t4_tp_pio_write(adap, key, 10, A_TP_RSS_SECRET_KEY0, sleep_ok);
7629 
7630 	if (idx >= 0 && idx < rss_key_addr_cnt) {
7631 		if (rss_key_addr_cnt > 16)
7632 			t4_write_reg(adap, A_TP_RSS_CONFIG_VRT,
7633 				     vrt | V_KEYWRADDRX(idx >> 4) |
7634 				     V_T6_VFWRADDR(idx) | F_KEYWREN);
7635 		else
7636 			t4_write_reg(adap, A_TP_RSS_CONFIG_VRT,
7637 				     vrt| V_KEYWRADDR(idx) | F_KEYWREN);
7638 	}
7639 }
7640 
7641 /**
7642  *	t4_read_rss_pf_config - read PF RSS Configuration Table
7643  *	@adapter: the adapter
7644  *	@index: the entry in the PF RSS table to read
7645  *	@valp: where to store the returned value
7646  * 	@sleep_ok: if true we may sleep while awaiting command completion
7647  *
7648  *	Reads the PF RSS Configuration Table at the specified index and returns
7649  *	the value found there.
7650  */
t4_read_rss_pf_config(struct adapter * adapter,unsigned int index,u32 * valp,bool sleep_ok)7651 void t4_read_rss_pf_config(struct adapter *adapter, unsigned int index,
7652 			   u32 *valp, bool sleep_ok)
7653 {
7654 	t4_tp_pio_read(adapter, valp, 1, A_TP_RSS_PF0_CONFIG + index, sleep_ok);
7655 }
7656 
7657 /**
7658  *	t4_write_rss_pf_config - write PF RSS Configuration Table
7659  *	@adapter: the adapter
7660  *	@index: the entry in the VF RSS table to read
7661  *	@val: the value to store
7662  * 	@sleep_ok: if true we may sleep while awaiting command completion
7663  *
7664  *	Writes the PF RSS Configuration Table at the specified index with the
7665  *	specified value.
7666  */
t4_write_rss_pf_config(struct adapter * adapter,unsigned int index,u32 val,bool sleep_ok)7667 void t4_write_rss_pf_config(struct adapter *adapter, unsigned int index,
7668 			    u32 val, bool sleep_ok)
7669 {
7670 	t4_tp_pio_write(adapter, &val, 1, A_TP_RSS_PF0_CONFIG + index,
7671 			sleep_ok);
7672 }
7673 
7674 /**
7675  *	t4_read_rss_vf_config - read VF RSS Configuration Table
7676  *	@adapter: the adapter
7677  *	@index: the entry in the VF RSS table to read
7678  *	@vfl: where to store the returned VFL
7679  *	@vfh: where to store the returned VFH
7680  * 	@sleep_ok: if true we may sleep while awaiting command completion
7681  *
7682  *	Reads the VF RSS Configuration Table at the specified index and returns
7683  *	the (VFL, VFH) values found there.
7684  */
t4_read_rss_vf_config(struct adapter * adapter,unsigned int index,u32 * vfl,u32 * vfh,bool sleep_ok)7685 void t4_read_rss_vf_config(struct adapter *adapter, unsigned int index,
7686 			   u32 *vfl, u32 *vfh, bool sleep_ok)
7687 {
7688 	u32 vrt, mask, data;
7689 
7690 	if (chip_id(adapter) <= CHELSIO_T5) {
7691 		mask = V_VFWRADDR(M_VFWRADDR);
7692 		data = V_VFWRADDR(index);
7693 	} else {
7694 		 mask =  V_T6_VFWRADDR(M_T6_VFWRADDR);
7695 		 data = V_T6_VFWRADDR(index);
7696 	}
7697 	/*
7698 	 * Request that the index'th VF Table values be read into VFL/VFH.
7699 	 */
7700 	vrt = t4_read_reg(adapter, A_TP_RSS_CONFIG_VRT);
7701 	vrt &= ~(F_VFRDRG | F_VFWREN | F_KEYWREN | mask);
7702 	vrt |= data | F_VFRDEN;
7703 	t4_write_reg(adapter, A_TP_RSS_CONFIG_VRT, vrt);
7704 
7705 	/*
7706 	 * Grab the VFL/VFH values ...
7707 	 */
7708 	t4_tp_pio_read(adapter, vfl, 1, A_TP_RSS_VFL_CONFIG, sleep_ok);
7709 	t4_tp_pio_read(adapter, vfh, 1, A_TP_RSS_VFH_CONFIG, sleep_ok);
7710 }
7711 
7712 /**
7713  *	t4_write_rss_vf_config - write VF RSS Configuration Table
7714  *
7715  *	@adapter: the adapter
7716  *	@index: the entry in the VF RSS table to write
7717  *	@vfl: the VFL to store
7718  *	@vfh: the VFH to store
7719  *
7720  *	Writes the VF RSS Configuration Table at the specified index with the
7721  *	specified (VFL, VFH) values.
7722  */
t4_write_rss_vf_config(struct adapter * adapter,unsigned int index,u32 vfl,u32 vfh,bool sleep_ok)7723 void t4_write_rss_vf_config(struct adapter *adapter, unsigned int index,
7724 			    u32 vfl, u32 vfh, bool sleep_ok)
7725 {
7726 	u32 vrt, mask, data;
7727 
7728 	if (chip_id(adapter) <= CHELSIO_T5) {
7729 		mask = V_VFWRADDR(M_VFWRADDR);
7730 		data = V_VFWRADDR(index);
7731 	} else {
7732 		mask =  V_T6_VFWRADDR(M_T6_VFWRADDR);
7733 		data = V_T6_VFWRADDR(index);
7734 	}
7735 
7736 	/*
7737 	 * Load up VFL/VFH with the values to be written ...
7738 	 */
7739 	t4_tp_pio_write(adapter, &vfl, 1, A_TP_RSS_VFL_CONFIG, sleep_ok);
7740 	t4_tp_pio_write(adapter, &vfh, 1, A_TP_RSS_VFH_CONFIG, sleep_ok);
7741 
7742 	/*
7743 	 * Write the VFL/VFH into the VF Table at index'th location.
7744 	 */
7745 	vrt = t4_read_reg(adapter, A_TP_RSS_CONFIG_VRT);
7746 	vrt &= ~(F_VFRDRG | F_VFWREN | F_KEYWREN | mask);
7747 	vrt |= data | F_VFRDEN;
7748 	t4_write_reg(adapter, A_TP_RSS_CONFIG_VRT, vrt);
7749 }
7750 
7751 /**
7752  *	t4_read_rss_pf_map - read PF RSS Map
7753  *	@adapter: the adapter
7754  * 	@sleep_ok: if true we may sleep while awaiting command completion
7755  *
7756  *	Reads the PF RSS Map register and returns its value.
7757  */
t4_read_rss_pf_map(struct adapter * adapter,bool sleep_ok)7758 u32 t4_read_rss_pf_map(struct adapter *adapter, bool sleep_ok)
7759 {
7760 	u32 pfmap;
7761 
7762 	t4_tp_pio_read(adapter, &pfmap, 1, A_TP_RSS_PF_MAP, sleep_ok);
7763 
7764 	return pfmap;
7765 }
7766 
7767 /**
7768  *	t4_write_rss_pf_map - write PF RSS Map
7769  *	@adapter: the adapter
7770  *	@pfmap: PF RSS Map value
7771  *
7772  *	Writes the specified value to the PF RSS Map register.
7773  */
t4_write_rss_pf_map(struct adapter * adapter,u32 pfmap,bool sleep_ok)7774 void t4_write_rss_pf_map(struct adapter *adapter, u32 pfmap, bool sleep_ok)
7775 {
7776 	t4_tp_pio_write(adapter, &pfmap, 1, A_TP_RSS_PF_MAP, sleep_ok);
7777 }
7778 
7779 /**
7780  *	t4_read_rss_pf_mask - read PF RSS Mask
7781  *	@adapter: the adapter
7782  * 	@sleep_ok: if true we may sleep while awaiting command completion
7783  *
7784  *	Reads the PF RSS Mask register and returns its value.
7785  */
t4_read_rss_pf_mask(struct adapter * adapter,bool sleep_ok)7786 u32 t4_read_rss_pf_mask(struct adapter *adapter, bool sleep_ok)
7787 {
7788 	u32 pfmask;
7789 
7790 	t4_tp_pio_read(adapter, &pfmask, 1, A_TP_RSS_PF_MSK, sleep_ok);
7791 
7792 	return pfmask;
7793 }
7794 
7795 /**
7796  *	t4_write_rss_pf_mask - write PF RSS Mask
7797  *	@adapter: the adapter
7798  *	@pfmask: PF RSS Mask value
7799  *
7800  *	Writes the specified value to the PF RSS Mask register.
7801  */
t4_write_rss_pf_mask(struct adapter * adapter,u32 pfmask,bool sleep_ok)7802 void t4_write_rss_pf_mask(struct adapter *adapter, u32 pfmask, bool sleep_ok)
7803 {
7804 	t4_tp_pio_write(adapter, &pfmask, 1, A_TP_RSS_PF_MSK, sleep_ok);
7805 }
7806 
7807 /**
7808  *	t4_tp_get_tcp_stats - read TP's TCP MIB counters
7809  *	@adap: the adapter
7810  *	@v4: holds the TCP/IP counter values
7811  *	@v6: holds the TCP/IPv6 counter values
7812  * 	@sleep_ok: if true we may sleep while awaiting command completion
7813  *
7814  *	Returns the values of TP's TCP/IP and TCP/IPv6 MIB counters.
7815  *	Either @v4 or @v6 may be %NULL to skip the corresponding stats.
7816  */
t4_tp_get_tcp_stats(struct adapter * adap,struct tp_tcp_stats * v4,struct tp_tcp_stats * v6,bool sleep_ok)7817 void t4_tp_get_tcp_stats(struct adapter *adap, struct tp_tcp_stats *v4,
7818 			 struct tp_tcp_stats *v6, bool sleep_ok)
7819 {
7820 	u32 val[A_TP_MIB_TCP_RXT_SEG_LO - A_TP_MIB_TCP_OUT_RST + 1];
7821 
7822 #define STAT_IDX(x) ((A_TP_MIB_TCP_##x) - A_TP_MIB_TCP_OUT_RST)
7823 #define STAT(x)     val[STAT_IDX(x)]
7824 #define STAT64(x)   (((u64)STAT(x##_HI) << 32) | STAT(x##_LO))
7825 
7826 	if (v4) {
7827 		t4_tp_mib_read(adap, val, ARRAY_SIZE(val),
7828 			       A_TP_MIB_TCP_OUT_RST, sleep_ok);
7829 		v4->tcp_out_rsts = STAT(OUT_RST);
7830 		v4->tcp_in_segs  = STAT64(IN_SEG);
7831 		v4->tcp_out_segs = STAT64(OUT_SEG);
7832 		v4->tcp_retrans_segs = STAT64(RXT_SEG);
7833 	}
7834 	if (v6) {
7835 		t4_tp_mib_read(adap, val, ARRAY_SIZE(val),
7836 			       A_TP_MIB_TCP_V6OUT_RST, sleep_ok);
7837 		v6->tcp_out_rsts = STAT(OUT_RST);
7838 		v6->tcp_in_segs  = STAT64(IN_SEG);
7839 		v6->tcp_out_segs = STAT64(OUT_SEG);
7840 		v6->tcp_retrans_segs = STAT64(RXT_SEG);
7841 	}
7842 #undef STAT64
7843 #undef STAT
7844 #undef STAT_IDX
7845 }
7846 
7847 /**
7848  *	t4_tp_get_err_stats - read TP's error MIB counters
7849  *	@adap: the adapter
7850  *	@st: holds the counter values
7851  * 	@sleep_ok: if true we may sleep while awaiting command completion
7852  *
7853  *	Returns the values of TP's error counters.
7854  */
t4_tp_get_err_stats(struct adapter * adap,struct tp_err_stats * st,bool sleep_ok)7855 void t4_tp_get_err_stats(struct adapter *adap, struct tp_err_stats *st,
7856 			 bool sleep_ok)
7857 {
7858 	int nchan = adap->chip_params->nchan;
7859 
7860 	t4_tp_mib_read(adap, st->mac_in_errs, nchan, A_TP_MIB_MAC_IN_ERR_0,
7861 		       sleep_ok);
7862 
7863 	t4_tp_mib_read(adap, st->hdr_in_errs, nchan, A_TP_MIB_HDR_IN_ERR_0,
7864 		       sleep_ok);
7865 
7866 	t4_tp_mib_read(adap, st->tcp_in_errs, nchan, A_TP_MIB_TCP_IN_ERR_0,
7867 		       sleep_ok);
7868 
7869 	t4_tp_mib_read(adap, st->tnl_cong_drops, nchan,
7870 		       A_TP_MIB_TNL_CNG_DROP_0, sleep_ok);
7871 
7872 	t4_tp_mib_read(adap, st->ofld_chan_drops, nchan,
7873 		       A_TP_MIB_OFD_CHN_DROP_0, sleep_ok);
7874 
7875 	t4_tp_mib_read(adap, st->tnl_tx_drops, nchan, A_TP_MIB_TNL_DROP_0,
7876 		       sleep_ok);
7877 
7878 	t4_tp_mib_read(adap, st->ofld_vlan_drops, nchan,
7879 		       A_TP_MIB_OFD_VLN_DROP_0, sleep_ok);
7880 
7881 	t4_tp_mib_read(adap, st->tcp6_in_errs, nchan,
7882 		       A_TP_MIB_TCP_V6IN_ERR_0, sleep_ok);
7883 
7884 	t4_tp_mib_read(adap, &st->ofld_no_neigh, 2, A_TP_MIB_OFD_ARP_DROP,
7885 		       sleep_ok);
7886 }
7887 
7888 /**
7889  *	t4_tp_get_err_stats - read TP's error MIB counters
7890  *	@adap: the adapter
7891  *	@st: holds the counter values
7892  * 	@sleep_ok: if true we may sleep while awaiting command completion
7893  *
7894  *	Returns the values of TP's error counters.
7895  */
t4_tp_get_tnl_stats(struct adapter * adap,struct tp_tnl_stats * st,bool sleep_ok)7896 void t4_tp_get_tnl_stats(struct adapter *adap, struct tp_tnl_stats *st,
7897 			 bool sleep_ok)
7898 {
7899 	int nchan = adap->chip_params->nchan;
7900 
7901 	t4_tp_mib_read(adap, st->out_pkt, nchan, A_TP_MIB_TNL_OUT_PKT_0,
7902 		       sleep_ok);
7903 	t4_tp_mib_read(adap, st->in_pkt, nchan, A_TP_MIB_TNL_IN_PKT_0,
7904 		       sleep_ok);
7905 }
7906 
7907 /**
7908  *	t4_tp_get_proxy_stats - read TP's proxy MIB counters
7909  *	@adap: the adapter
7910  *	@st: holds the counter values
7911  *
7912  *	Returns the values of TP's proxy counters.
7913  */
t4_tp_get_proxy_stats(struct adapter * adap,struct tp_proxy_stats * st,bool sleep_ok)7914 void t4_tp_get_proxy_stats(struct adapter *adap, struct tp_proxy_stats *st,
7915     bool sleep_ok)
7916 {
7917 	int nchan = adap->chip_params->nchan;
7918 
7919 	t4_tp_mib_read(adap, st->proxy, nchan, A_TP_MIB_TNL_LPBK_0, sleep_ok);
7920 }
7921 
7922 /**
7923  *	t4_tp_get_cpl_stats - read TP's CPL MIB counters
7924  *	@adap: the adapter
7925  *	@st: holds the counter values
7926  * 	@sleep_ok: if true we may sleep while awaiting command completion
7927  *
7928  *	Returns the values of TP's CPL counters.
7929  */
t4_tp_get_cpl_stats(struct adapter * adap,struct tp_cpl_stats * st,bool sleep_ok)7930 void t4_tp_get_cpl_stats(struct adapter *adap, struct tp_cpl_stats *st,
7931 			 bool sleep_ok)
7932 {
7933 	int nchan = adap->chip_params->nchan;
7934 
7935 	t4_tp_mib_read(adap, st->req, nchan, A_TP_MIB_CPL_IN_REQ_0, sleep_ok);
7936 
7937 	t4_tp_mib_read(adap, st->rsp, nchan, A_TP_MIB_CPL_OUT_RSP_0, sleep_ok);
7938 }
7939 
7940 /**
7941  *	t4_tp_get_rdma_stats - read TP's RDMA MIB counters
7942  *	@adap: the adapter
7943  *	@st: holds the counter values
7944  *
7945  *	Returns the values of TP's RDMA counters.
7946  */
t4_tp_get_rdma_stats(struct adapter * adap,struct tp_rdma_stats * st,bool sleep_ok)7947 void t4_tp_get_rdma_stats(struct adapter *adap, struct tp_rdma_stats *st,
7948 			  bool sleep_ok)
7949 {
7950 	t4_tp_mib_read(adap, &st->rqe_dfr_pkt, 2, A_TP_MIB_RQE_DFR_PKT,
7951 		       sleep_ok);
7952 
7953 	if (chip_id(adap) >= CHELSIO_T7)
7954 		/* read RDMA stats IN and OUT for all ports at once */
7955 		t4_tp_mib_read(adap, &st->pkts_in[0], 28, A_TP_MIB_RDMA_IN_PKT_0,
7956 			       sleep_ok);
7957 }
7958 
7959 /**
7960  *	t4_get_fcoe_stats - read TP's FCoE MIB counters for a port
7961  *	@adap: the adapter
7962  *	@idx: the port index
7963  *	@st: holds the counter values
7964  * 	@sleep_ok: if true we may sleep while awaiting command completion
7965  *
7966  *	Returns the values of TP's FCoE counters for the selected port.
7967  */
t4_get_fcoe_stats(struct adapter * adap,unsigned int idx,struct tp_fcoe_stats * st,bool sleep_ok)7968 void t4_get_fcoe_stats(struct adapter *adap, unsigned int idx,
7969 		       struct tp_fcoe_stats *st, bool sleep_ok)
7970 {
7971 	u32 val[2];
7972 
7973 	t4_tp_mib_read(adap, &st->frames_ddp, 1, A_TP_MIB_FCOE_DDP_0 + idx,
7974 		       sleep_ok);
7975 
7976 	t4_tp_mib_read(adap, &st->frames_drop, 1,
7977 		       A_TP_MIB_FCOE_DROP_0 + idx, sleep_ok);
7978 
7979 	t4_tp_mib_read(adap, val, 2, A_TP_MIB_FCOE_BYTE_0_HI + 2 * idx,
7980 		       sleep_ok);
7981 
7982 	st->octets_ddp = ((u64)val[0] << 32) | val[1];
7983 }
7984 
7985 /**
7986  *	t4_get_usm_stats - read TP's non-TCP DDP MIB counters
7987  *	@adap: the adapter
7988  *	@st: holds the counter values
7989  * 	@sleep_ok: if true we may sleep while awaiting command completion
7990  *
7991  *	Returns the values of TP's counters for non-TCP directly-placed packets.
7992  */
t4_get_usm_stats(struct adapter * adap,struct tp_usm_stats * st,bool sleep_ok)7993 void t4_get_usm_stats(struct adapter *adap, struct tp_usm_stats *st,
7994 		      bool sleep_ok)
7995 {
7996 	u32 val[4];
7997 
7998 	t4_tp_mib_read(adap, val, 4, A_TP_MIB_USM_PKTS, sleep_ok);
7999 
8000 	st->frames = val[0];
8001 	st->drops = val[1];
8002 	st->octets = ((u64)val[2] << 32) | val[3];
8003 }
8004 
8005 /**
8006  *	t4_tp_get_tid_stats - read TP's tid MIB counters.
8007  *	@adap: the adapter
8008  *	@st: holds the counter values
8009  * 	@sleep_ok: if true we may sleep while awaiting command completion
8010  *
8011  *	Returns the values of TP's counters for tids.
8012  */
t4_tp_get_tid_stats(struct adapter * adap,struct tp_tid_stats * st,bool sleep_ok)8013 void t4_tp_get_tid_stats(struct adapter *adap, struct tp_tid_stats *st,
8014 		      bool sleep_ok)
8015 {
8016 
8017 	t4_tp_mib_read(adap, &st->del, 4, A_TP_MIB_TID_DEL, sleep_ok);
8018 }
8019 
8020 /**
8021  *	t4_read_mtu_tbl - returns the values in the HW path MTU table
8022  *	@adap: the adapter
8023  *	@mtus: where to store the MTU values
8024  *	@mtu_log: where to store the MTU base-2 log (may be %NULL)
8025  *
8026  *	Reads the HW path MTU table.
8027  */
t4_read_mtu_tbl(struct adapter * adap,u16 * mtus,u8 * mtu_log)8028 void t4_read_mtu_tbl(struct adapter *adap, u16 *mtus, u8 *mtu_log)
8029 {
8030 	u32 v;
8031 	int i;
8032 
8033 	for (i = 0; i < NMTUS; ++i) {
8034 		t4_write_reg(adap, A_TP_MTU_TABLE,
8035 			     V_MTUINDEX(0xff) | V_MTUVALUE(i));
8036 		v = t4_read_reg(adap, A_TP_MTU_TABLE);
8037 		mtus[i] = G_MTUVALUE(v);
8038 		if (mtu_log)
8039 			mtu_log[i] = G_MTUWIDTH(v);
8040 	}
8041 }
8042 
8043 /**
8044  *	t4_read_cong_tbl - reads the congestion control table
8045  *	@adap: the adapter
8046  *	@incr: where to store the alpha values
8047  *
8048  *	Reads the additive increments programmed into the HW congestion
8049  *	control table.
8050  */
t4_read_cong_tbl(struct adapter * adap,u16 incr[NMTUS][NCCTRL_WIN])8051 void t4_read_cong_tbl(struct adapter *adap, u16 incr[NMTUS][NCCTRL_WIN])
8052 {
8053 	unsigned int mtu, w;
8054 
8055 	for (mtu = 0; mtu < NMTUS; ++mtu)
8056 		for (w = 0; w < NCCTRL_WIN; ++w) {
8057 			t4_write_reg(adap, A_TP_CCTRL_TABLE,
8058 				     V_ROWINDEX(0xffff) | (mtu << 5) | w);
8059 			incr[mtu][w] = (u16)t4_read_reg(adap,
8060 						A_TP_CCTRL_TABLE) & 0x1fff;
8061 		}
8062 }
8063 
8064 /**
8065  *	t4_tp_wr_bits_indirect - set/clear bits in an indirect TP register
8066  *	@adap: the adapter
8067  *	@addr: the indirect TP register address
8068  *	@mask: specifies the field within the register to modify
8069  *	@val: new value for the field
8070  *
8071  *	Sets a field of an indirect TP register to the given value.
8072  */
t4_tp_wr_bits_indirect(struct adapter * adap,unsigned int addr,unsigned int mask,unsigned int val)8073 void t4_tp_wr_bits_indirect(struct adapter *adap, unsigned int addr,
8074 			    unsigned int mask, unsigned int val)
8075 {
8076 	t4_write_reg(adap, A_TP_PIO_ADDR, addr);
8077 	val |= t4_read_reg(adap, A_TP_PIO_DATA) & ~mask;
8078 	t4_write_reg(adap, A_TP_PIO_DATA, val);
8079 }
8080 
8081 /**
8082  *	init_cong_ctrl - initialize congestion control parameters
8083  *	@a: the alpha values for congestion control
8084  *	@b: the beta values for congestion control
8085  *
8086  *	Initialize the congestion control parameters.
8087  */
init_cong_ctrl(unsigned short * a,unsigned short * b)8088 static void init_cong_ctrl(unsigned short *a, unsigned short *b)
8089 {
8090 	a[0] = a[1] = a[2] = a[3] = a[4] = a[5] = a[6] = a[7] = a[8] = 1;
8091 	a[9] = 2;
8092 	a[10] = 3;
8093 	a[11] = 4;
8094 	a[12] = 5;
8095 	a[13] = 6;
8096 	a[14] = 7;
8097 	a[15] = 8;
8098 	a[16] = 9;
8099 	a[17] = 10;
8100 	a[18] = 14;
8101 	a[19] = 17;
8102 	a[20] = 21;
8103 	a[21] = 25;
8104 	a[22] = 30;
8105 	a[23] = 35;
8106 	a[24] = 45;
8107 	a[25] = 60;
8108 	a[26] = 80;
8109 	a[27] = 100;
8110 	a[28] = 200;
8111 	a[29] = 300;
8112 	a[30] = 400;
8113 	a[31] = 500;
8114 
8115 	b[0] = b[1] = b[2] = b[3] = b[4] = b[5] = b[6] = b[7] = b[8] = 0;
8116 	b[9] = b[10] = 1;
8117 	b[11] = b[12] = 2;
8118 	b[13] = b[14] = b[15] = b[16] = 3;
8119 	b[17] = b[18] = b[19] = b[20] = b[21] = 4;
8120 	b[22] = b[23] = b[24] = b[25] = b[26] = b[27] = 5;
8121 	b[28] = b[29] = 6;
8122 	b[30] = b[31] = 7;
8123 }
8124 
8125 /* The minimum additive increment value for the congestion control table */
8126 #define CC_MIN_INCR 2U
8127 
8128 /**
8129  *	t4_load_mtus - write the MTU and congestion control HW tables
8130  *	@adap: the adapter
8131  *	@mtus: the values for the MTU table
8132  *	@alpha: the values for the congestion control alpha parameter
8133  *	@beta: the values for the congestion control beta parameter
8134  *
8135  *	Write the HW MTU table with the supplied MTUs and the high-speed
8136  *	congestion control table with the supplied alpha, beta, and MTUs.
8137  *	We write the two tables together because the additive increments
8138  *	depend on the MTUs.
8139  */
t4_load_mtus(struct adapter * adap,const unsigned short * mtus,const unsigned short * alpha,const unsigned short * beta)8140 void t4_load_mtus(struct adapter *adap, const unsigned short *mtus,
8141 		  const unsigned short *alpha, const unsigned short *beta)
8142 {
8143 	static const unsigned int avg_pkts[NCCTRL_WIN] = {
8144 		2, 6, 10, 14, 20, 28, 40, 56, 80, 112, 160, 224, 320, 448, 640,
8145 		896, 1281, 1792, 2560, 3584, 5120, 7168, 10240, 14336, 20480,
8146 		28672, 40960, 57344, 81920, 114688, 163840, 229376
8147 	};
8148 
8149 	unsigned int i, w;
8150 
8151 	for (i = 0; i < NMTUS; ++i) {
8152 		unsigned int mtu = mtus[i];
8153 		unsigned int log2 = fls(mtu);
8154 
8155 		if (!(mtu & ((1 << log2) >> 2)))     /* round */
8156 			log2--;
8157 		t4_write_reg(adap, A_TP_MTU_TABLE, V_MTUINDEX(i) |
8158 			     V_MTUWIDTH(log2) | V_MTUVALUE(mtu));
8159 
8160 		for (w = 0; w < NCCTRL_WIN; ++w) {
8161 			unsigned int inc;
8162 
8163 			inc = max(((mtu - 40) * alpha[w]) / avg_pkts[w],
8164 				  CC_MIN_INCR);
8165 
8166 			t4_write_reg(adap, A_TP_CCTRL_TABLE, (i << 21) |
8167 				     (w << 16) | (beta[w] << 13) | inc);
8168 		}
8169 	}
8170 }
8171 
8172 /**
8173  *	t4_set_pace_tbl - set the pace table
8174  *	@adap: the adapter
8175  *	@pace_vals: the pace values in microseconds
8176  *	@start: index of the first entry in the HW pace table to set
8177  *	@n: how many entries to set
8178  *
8179  *	Sets (a subset of the) HW pace table.
8180  */
t4_set_pace_tbl(struct adapter * adap,const unsigned int * pace_vals,unsigned int start,unsigned int n)8181 int t4_set_pace_tbl(struct adapter *adap, const unsigned int *pace_vals,
8182 		     unsigned int start, unsigned int n)
8183 {
8184 	unsigned int vals[NTX_SCHED], i;
8185 	unsigned int tick_ns = dack_ticks_to_usec(adap, 1000);
8186 
8187 	if (n > NTX_SCHED)
8188 	    return -ERANGE;
8189 
8190 	/* convert values from us to dack ticks, rounding to closest value */
8191 	for (i = 0; i < n; i++, pace_vals++) {
8192 		vals[i] = (1000 * *pace_vals + tick_ns / 2) / tick_ns;
8193 		if (vals[i] > 0x7ff)
8194 			return -ERANGE;
8195 		if (*pace_vals && vals[i] == 0)
8196 			return -ERANGE;
8197 	}
8198 	for (i = 0; i < n; i++, start++)
8199 		t4_write_reg(adap, A_TP_PACE_TABLE, (start << 16) | vals[i]);
8200 	return 0;
8201 }
8202 
8203 /**
8204  *	t4_set_sched_bps - set the bit rate for a HW traffic scheduler
8205  *	@adap: the adapter
8206  *	@kbps: target rate in Kbps
8207  *	@sched: the scheduler index
8208  *
8209  *	Configure a Tx HW scheduler for the target rate.
8210  */
t4_set_sched_bps(struct adapter * adap,int sched,unsigned int kbps)8211 int t4_set_sched_bps(struct adapter *adap, int sched, unsigned int kbps)
8212 {
8213 	unsigned int v, tps, cpt, bpt, delta, mindelta = ~0;
8214 	unsigned int clk = adap->params.vpd.cclk * 1000;
8215 	unsigned int selected_cpt = 0, selected_bpt = 0;
8216 
8217 	if (kbps > 0) {
8218 		kbps *= 125;     /* -> bytes */
8219 		for (cpt = 1; cpt <= 255; cpt++) {
8220 			tps = clk / cpt;
8221 			bpt = (kbps + tps / 2) / tps;
8222 			if (bpt > 0 && bpt <= 255) {
8223 				v = bpt * tps;
8224 				delta = v >= kbps ? v - kbps : kbps - v;
8225 				if (delta < mindelta) {
8226 					mindelta = delta;
8227 					selected_cpt = cpt;
8228 					selected_bpt = bpt;
8229 				}
8230 			} else if (selected_cpt)
8231 				break;
8232 		}
8233 		if (!selected_cpt)
8234 			return -EINVAL;
8235 	}
8236 	t4_write_reg(adap, A_TP_TM_PIO_ADDR,
8237 		     A_TP_TX_MOD_Q1_Q0_RATE_LIMIT - sched / 2);
8238 	v = t4_read_reg(adap, A_TP_TM_PIO_DATA);
8239 	if (sched & 1)
8240 		v = (v & 0xffff) | (selected_cpt << 16) | (selected_bpt << 24);
8241 	else
8242 		v = (v & 0xffff0000) | selected_cpt | (selected_bpt << 8);
8243 	t4_write_reg(adap, A_TP_TM_PIO_DATA, v);
8244 	return 0;
8245 }
8246 
8247 /**
8248  *	t4_set_sched_ipg - set the IPG for a Tx HW packet rate scheduler
8249  *	@adap: the adapter
8250  *	@sched: the scheduler index
8251  *	@ipg: the interpacket delay in tenths of nanoseconds
8252  *
8253  *	Set the interpacket delay for a HW packet rate scheduler.
8254  */
t4_set_sched_ipg(struct adapter * adap,int sched,unsigned int ipg)8255 int t4_set_sched_ipg(struct adapter *adap, int sched, unsigned int ipg)
8256 {
8257 	unsigned int v, addr = A_TP_TX_MOD_Q1_Q0_TIMER_SEPARATOR - sched / 2;
8258 
8259 	/* convert ipg to nearest number of core clocks */
8260 	ipg *= core_ticks_per_usec(adap);
8261 	ipg = (ipg + 5000) / 10000;
8262 	if (ipg > M_TXTIMERSEPQ0)
8263 		return -EINVAL;
8264 
8265 	t4_write_reg(adap, A_TP_TM_PIO_ADDR, addr);
8266 	v = t4_read_reg(adap, A_TP_TM_PIO_DATA);
8267 	if (sched & 1)
8268 		v = (v & V_TXTIMERSEPQ0(M_TXTIMERSEPQ0)) | V_TXTIMERSEPQ1(ipg);
8269 	else
8270 		v = (v & V_TXTIMERSEPQ1(M_TXTIMERSEPQ1)) | V_TXTIMERSEPQ0(ipg);
8271 	t4_write_reg(adap, A_TP_TM_PIO_DATA, v);
8272 	t4_read_reg(adap, A_TP_TM_PIO_DATA);
8273 	return 0;
8274 }
8275 
8276 /*
8277  * Calculates a rate in bytes/s given the number of 256-byte units per 4K core
8278  * clocks.  The formula is
8279  *
8280  * bytes/s = bytes256 * 256 * ClkFreq / 4096
8281  *
8282  * which is equivalent to
8283  *
8284  * bytes/s = 62.5 * bytes256 * ClkFreq_ms
8285  */
chan_rate(struct adapter * adap,unsigned int bytes256)8286 static u64 chan_rate(struct adapter *adap, unsigned int bytes256)
8287 {
8288 	u64 v = (u64)bytes256 * adap->params.vpd.cclk;
8289 
8290 	return v * 62 + v / 2;
8291 }
8292 
8293 /**
8294  *	t4_get_chan_txrate - get the current per channel Tx rates
8295  *	@adap: the adapter
8296  *	@nic_rate: rates for NIC traffic
8297  *	@ofld_rate: rates for offloaded traffic
8298  *
8299  *	Return the current Tx rates in bytes/s for NIC and offloaded traffic
8300  *	for each channel.
8301  */
t4_get_chan_txrate(struct adapter * adap,u64 * nic_rate,u64 * ofld_rate)8302 void t4_get_chan_txrate(struct adapter *adap, u64 *nic_rate, u64 *ofld_rate)
8303 {
8304 	u32 v;
8305 
8306 	v = t4_read_reg(adap, A_TP_TX_TRATE);
8307 	nic_rate[0] = chan_rate(adap, G_TNLRATE0(v));
8308 	nic_rate[1] = chan_rate(adap, G_TNLRATE1(v));
8309 	if (adap->chip_params->nchan > 2) {
8310 		nic_rate[2] = chan_rate(adap, G_TNLRATE2(v));
8311 		nic_rate[3] = chan_rate(adap, G_TNLRATE3(v));
8312 	}
8313 
8314 	v = t4_read_reg(adap, A_TP_TX_ORATE);
8315 	ofld_rate[0] = chan_rate(adap, G_OFDRATE0(v));
8316 	ofld_rate[1] = chan_rate(adap, G_OFDRATE1(v));
8317 	if (adap->chip_params->nchan > 2) {
8318 		ofld_rate[2] = chan_rate(adap, G_OFDRATE2(v));
8319 		ofld_rate[3] = chan_rate(adap, G_OFDRATE3(v));
8320 	}
8321 }
8322 
8323 /**
8324  *	t4_set_trace_filter - configure one of the tracing filters
8325  *	@adap: the adapter
8326  *	@tp: the desired trace filter parameters
8327  *	@idx: which filter to configure
8328  *	@enable: whether to enable or disable the filter
8329  *
8330  *	Configures one of the tracing filters available in HW.  If @tp is %NULL
8331  *	it indicates that the filter is already written in the register and it
8332  *	just needs to be enabled or disabled.
8333  */
t4_set_trace_filter(struct adapter * adap,const struct trace_params * tp,int idx,int enable)8334 int t4_set_trace_filter(struct adapter *adap, const struct trace_params *tp,
8335     int idx, int enable)
8336 {
8337 	int i, ofst;
8338 	u32 match_ctl_a, match_ctl_b;
8339 	u32 data_reg, mask_reg, cfg;
8340 	u32 en = is_t4(adap) ? F_TFEN : F_T5_TFEN;
8341 
8342 	if (idx < 0 || idx >= NTRACE)
8343 		return -EINVAL;
8344 
8345 	if (chip_id(adap) >= CHELSIO_T7) {
8346 		match_ctl_a = T7_MPS_TRC_FILTER_MATCH_CTL_A(idx);
8347 		match_ctl_b = T7_MPS_TRC_FILTER_MATCH_CTL_B(idx);
8348 	} else {
8349 		match_ctl_a = MPS_TRC_FILTER_MATCH_CTL_A(idx);
8350 		match_ctl_b = MPS_TRC_FILTER_MATCH_CTL_B(idx);
8351 	}
8352 
8353 	if (tp == NULL || !enable) {
8354 		t4_set_reg_field(adap, match_ctl_a, en, enable ? en : 0);
8355 		return 0;
8356 	}
8357 
8358 	/*
8359 	 * TODO - After T4 data book is updated, specify the exact
8360 	 * section below.
8361 	 *
8362 	 * See T4 data book - MPS section for a complete description
8363 	 * of the below if..else handling of A_MPS_TRC_CFG register
8364 	 * value.
8365 	 */
8366 	cfg = t4_read_reg(adap, A_MPS_TRC_CFG);
8367 	if (cfg & F_TRCMULTIFILTER) {
8368 		/*
8369 		 * If multiple tracers are enabled, then maximum
8370 		 * capture size is 2.5KB (FIFO size of a single channel)
8371 		 * minus 2 flits for CPL_TRACE_PKT header.
8372 		 */
8373 		if (tp->snap_len > ((10 * 1024 / 4) - (2 * 8)))
8374 			return -EINVAL;
8375 	} else {
8376 		/*
8377 		 * If multiple tracers are disabled, to avoid deadlocks
8378 		 * maximum packet capture size of 9600 bytes is recommended.
8379 		 * Also in this mode, only trace0 can be enabled and running.
8380 		 */
8381 		if (tp->snap_len > 9600 || idx)
8382 			return -EINVAL;
8383 	}
8384 
8385 	if (tp->port > (is_t4(adap) ? 11 : 19) || tp->invert > 1 ||
8386 	    tp->skip_len > M_TFLENGTH || tp->skip_ofst > M_TFOFFSET ||
8387 	    tp->min_len > M_TFMINPKTSIZE)
8388 		return -EINVAL;
8389 
8390 	/* stop the tracer we'll be changing */
8391 	t4_set_reg_field(adap, match_ctl_a, en, 0);
8392 
8393 	ofst = (A_MPS_TRC_FILTER1_MATCH - A_MPS_TRC_FILTER0_MATCH) * idx;
8394 	data_reg = A_MPS_TRC_FILTER0_MATCH + ofst;
8395 	mask_reg = A_MPS_TRC_FILTER0_DONT_CARE + ofst;
8396 
8397 	for (i = 0; i < TRACE_LEN / 4; i++, data_reg += 4, mask_reg += 4) {
8398 		t4_write_reg(adap, data_reg, tp->data[i]);
8399 		t4_write_reg(adap, mask_reg, ~tp->mask[i]);
8400 	}
8401 	t4_write_reg(adap, match_ctl_b, V_TFCAPTUREMAX(tp->snap_len) |
8402 		     V_TFMINPKTSIZE(tp->min_len));
8403 	t4_write_reg(adap, match_ctl_a, V_TFOFFSET(tp->skip_ofst) |
8404 		     V_TFLENGTH(tp->skip_len) | en | (is_t4(adap) ?
8405 		     V_TFPORT(tp->port) | V_TFINVERTMATCH(tp->invert) :
8406 		     V_T5_TFPORT(tp->port) | V_T5_TFINVERTMATCH(tp->invert)));
8407 
8408 	return 0;
8409 }
8410 
8411 /**
8412  *	t4_get_trace_filter - query one of the tracing filters
8413  *	@adap: the adapter
8414  *	@tp: the current trace filter parameters
8415  *	@idx: which trace filter to query
8416  *	@enabled: non-zero if the filter is enabled
8417  *
8418  *	Returns the current settings of one of the HW tracing filters.
8419  */
t4_get_trace_filter(struct adapter * adap,struct trace_params * tp,int idx,int * enabled)8420 void t4_get_trace_filter(struct adapter *adap, struct trace_params *tp, int idx,
8421 			 int *enabled)
8422 {
8423 	u32 ctla, ctlb;
8424 	int i, ofst;
8425 	u32 data_reg, mask_reg;
8426 
8427 	if (chip_id(adap) >= CHELSIO_T7) {
8428 		ctla = t4_read_reg(adap, T7_MPS_TRC_FILTER_MATCH_CTL_A(idx));
8429 		ctlb = t4_read_reg(adap, T7_MPS_TRC_FILTER_MATCH_CTL_B(idx));
8430 	} else {
8431 		ctla = t4_read_reg(adap, MPS_TRC_FILTER_MATCH_CTL_A(idx));
8432 		ctlb = t4_read_reg(adap, MPS_TRC_FILTER_MATCH_CTL_B(idx));
8433 	}
8434 
8435 	if (is_t4(adap)) {
8436 		*enabled = !!(ctla & F_TFEN);
8437 		tp->port =  G_TFPORT(ctla);
8438 		tp->invert = !!(ctla & F_TFINVERTMATCH);
8439 	} else {
8440 		*enabled = !!(ctla & F_T5_TFEN);
8441 		tp->port = G_T5_TFPORT(ctla);
8442 		tp->invert = !!(ctla & F_T5_TFINVERTMATCH);
8443 	}
8444 	tp->snap_len = G_TFCAPTUREMAX(ctlb);
8445 	tp->min_len = G_TFMINPKTSIZE(ctlb);
8446 	tp->skip_ofst = G_TFOFFSET(ctla);
8447 	tp->skip_len = G_TFLENGTH(ctla);
8448 
8449 	ofst = (A_MPS_TRC_FILTER1_MATCH - A_MPS_TRC_FILTER0_MATCH) * idx;
8450 	data_reg = A_MPS_TRC_FILTER0_MATCH + ofst;
8451 	mask_reg = A_MPS_TRC_FILTER0_DONT_CARE + ofst;
8452 
8453 	for (i = 0; i < TRACE_LEN / 4; i++, data_reg += 4, mask_reg += 4) {
8454 		tp->mask[i] = ~t4_read_reg(adap, mask_reg);
8455 		tp->data[i] = t4_read_reg(adap, data_reg) & tp->mask[i];
8456 	}
8457 }
8458 
8459 /**
8460  *	t4_set_trace_rss_control - configure the trace rss control register
8461  *	@adap: the adapter
8462  *	@chan: the channel number for RSS control
8463  *	@qid: queue number
8464  *
8465  *	Configures the MPS tracing RSS control parameter for specified
8466  *	@chan channel and @qid queue number.
8467  */
t4_set_trace_rss_control(struct adapter * adap,u8 chan,u16 qid)8468 void t4_set_trace_rss_control(struct adapter *adap, u8 chan, u16 qid)
8469 {
8470 	u32 mps_trc_rss_control;
8471 
8472 	switch (chip_id(adap)) {
8473 	case CHELSIO_T4:
8474 		mps_trc_rss_control = A_MPS_TRC_RSS_CONTROL;
8475 		break;
8476 	case CHELSIO_T5:
8477 	case CHELSIO_T6:
8478 		mps_trc_rss_control = A_MPS_T5_TRC_RSS_CONTROL;
8479 		break;
8480 	case CHELSIO_T7:
8481 	default:
8482 		mps_trc_rss_control = A_T7_MPS_T5_TRC_RSS_CONTROL;
8483 		break;
8484 	}
8485 
8486 	t4_write_reg(adap, mps_trc_rss_control,
8487 		     V_RSSCONTROL(chan) | V_QUEUENUMBER(qid));
8488 }
8489 
8490 /**
8491  *	t4_pmtx_get_stats - returns the HW stats from PMTX
8492  *	@adap: the adapter
8493  *	@cnt: where to store the count statistics
8494  *	@cycles: where to store the cycle statistics
8495  *
8496  *	Returns performance statistics from PMTX.
8497  */
t4_pmtx_get_stats(struct adapter * adap,u32 cnt[],u64 cycles[])8498 void t4_pmtx_get_stats(struct adapter *adap, u32 cnt[], u64 cycles[])
8499 {
8500 	int i;
8501 	u32 data[2];
8502 
8503 	for (i = 0; i < adap->chip_params->pm_stats_cnt; i++) {
8504 		t4_write_reg(adap, A_PM_TX_STAT_CONFIG, i + 1);
8505 		cnt[i] = t4_read_reg(adap, A_PM_TX_STAT_COUNT);
8506 		if (is_t4(adap))
8507 			cycles[i] = t4_read_reg64(adap, A_PM_TX_STAT_LSB);
8508 		else {
8509 			t4_read_indirect(adap, A_PM_TX_DBG_CTRL,
8510 					 A_PM_TX_DBG_DATA, data, 2,
8511 					 chip_id(adap) >= CHELSIO_T7 ?
8512 					 A_T7_PM_TX_DBG_STAT_MSB :
8513 					 A_PM_TX_DBG_STAT_MSB);
8514 			cycles[i] = (((u64)data[0] << 32) | data[1]);
8515 		}
8516 	}
8517 }
8518 
8519 /**
8520  *	t4_pmrx_get_stats - returns the HW stats from PMRX
8521  *	@adap: the adapter
8522  *	@cnt: where to store the count statistics
8523  *	@cycles: where to store the cycle statistics
8524  *
8525  *	Returns performance statistics from PMRX.
8526  */
t4_pmrx_get_stats(struct adapter * adap,u32 cnt[],u64 cycles[])8527 void t4_pmrx_get_stats(struct adapter *adap, u32 cnt[], u64 cycles[])
8528 {
8529 	int i;
8530 	u32 data[2];
8531 
8532 	for (i = 0; i < adap->chip_params->pm_stats_cnt; i++) {
8533 		t4_write_reg(adap, A_PM_RX_STAT_CONFIG, i + 1);
8534 		cnt[i] = t4_read_reg(adap, A_PM_RX_STAT_COUNT);
8535 		if (is_t4(adap)) {
8536 			cycles[i] = t4_read_reg64(adap, A_PM_RX_STAT_LSB);
8537 		} else {
8538 			t4_read_indirect(adap, A_PM_RX_DBG_CTRL,
8539 					 A_PM_RX_DBG_DATA, data, 2,
8540 					 A_PM_RX_DBG_STAT_MSB);
8541 			cycles[i] = (((u64)data[0] << 32) | data[1]);
8542 		}
8543 	}
8544 }
8545 
8546 /**
8547  * t4_pmrx_cache_get_stats - returns the HW PMRX cache stats
8548  * @adap: the adapter
8549  * @stats: where to store the statistics
8550  *
8551  * Returns performance statistics of PMRX cache.
8552  */
t4_pmrx_cache_get_stats(struct adapter * adap,u32 stats[])8553 void t4_pmrx_cache_get_stats(struct adapter *adap, u32 stats[])
8554 {
8555 	u8 i, j;
8556 
8557 	for (i = 0, j = 0; i < T7_PM_RX_CACHE_NSTATS / 3; i++, j += 3) {
8558 		t4_write_reg(adap, A_PM_RX_STAT_CONFIG, 0x100 + i);
8559 		stats[j] = t4_read_reg(adap, A_PM_RX_STAT_COUNT);
8560 		t4_read_indirect(adap, A_PM_RX_DBG_CTRL, A_PM_RX_DBG_DATA,
8561 				 &stats[j + 1], 2, A_PM_RX_DBG_STAT_MSB);
8562 	}
8563 }
8564 
8565 /**
8566  *	t4_get_mps_bg_map - return the buffer groups associated with a port
8567  *	@adap: the adapter
8568  *	@idx: the port index
8569  *
8570  *	Returns a bitmap indicating which MPS buffer groups are associated
8571  *	with the given port.  Bit i is set if buffer group i is used by the
8572  *	port.
8573  */
t4_get_mps_bg_map(struct adapter * adap,int idx)8574 static unsigned int t4_get_mps_bg_map(struct adapter *adap, int idx)
8575 {
8576 	u32 n;
8577 
8578 	if (adap->params.mps_bg_map != UINT32_MAX)
8579 		return ((adap->params.mps_bg_map >> (idx << 3)) & 0xff);
8580 
8581 	n = adap->params.nports;
8582 	MPASS(n > 0 && n <= MAX_NPORTS);
8583 	if (n == 1)
8584 		return idx == 0 ? 0xf : 0;
8585 	if (n == 2 && chip_id(adap) <= CHELSIO_T5)
8586 		return idx < 2 ? (3 << (2 * idx)) : 0;
8587 	return 1 << idx;
8588 }
8589 
8590 /*
8591  * TP RX e-channels associated with the port.
8592  */
t4_get_rx_e_chan_map(struct adapter * adap,int idx)8593 static unsigned int t4_get_rx_e_chan_map(struct adapter *adap, int idx)
8594 {
8595 	const u32 n = adap->params.nports;
8596 	const u32 all_chan = (1 << adap->chip_params->nchan) - 1;
8597 
8598 	switch (adap->params.tp.lb_mode) {
8599 	case 0:
8600 		if (n == 1)
8601 			return (all_chan);
8602 		if (n == 2 && chip_id(adap) <= CHELSIO_T5)
8603 			return (3 << (2 * idx));
8604 		return (1 << idx);
8605 	case 1:
8606 		MPASS(n == 1);
8607 		return (all_chan);
8608 	case 2:
8609 		MPASS(n <= 2);
8610 		return (3 << (2 * idx));
8611 	default:
8612 		CH_ERR(adap, "Unsupported LB mode %d\n",
8613 		    adap->params.tp.lb_mode);
8614 		return (0);
8615 	}
8616 }
8617 
8618 /*
8619  * TP RX c-channel associated with the port.
8620  */
t4_get_rx_c_chan(struct adapter * adap,int idx)8621 static unsigned int t4_get_rx_c_chan(struct adapter *adap, int idx)
8622 {
8623 	if (adap->params.tp_ch_map != UINT32_MAX)
8624 		return (adap->params.tp_ch_map >> (8 * idx)) & 0xff;
8625         return 0;
8626 }
8627 
8628 /*
8629  * TP TX c-channel associated with the port.
8630  */
t4_get_tx_c_chan(struct adapter * adap,int idx)8631 static unsigned int t4_get_tx_c_chan(struct adapter *adap, int idx)
8632 {
8633 	if (adap->params.tx_tp_ch_map != UINT32_MAX)
8634 		return (adap->params.tx_tp_ch_map >> (8 * idx)) & 0xff;
8635 	return idx;
8636 }
8637 
8638 /**
8639  *      t4_get_port_type_description - return Port Type string description
8640  *      @port_type: firmware Port Type enumeration
8641  */
t4_get_port_type_description(enum fw_port_type port_type)8642 const char *t4_get_port_type_description(enum fw_port_type port_type)
8643 {
8644 	static const char *const port_type_description[] = {
8645 		"Fiber_XFI",
8646 		"Fiber_XAUI",
8647 		"BT_SGMII",
8648 		"BT_XFI",
8649 		"BT_XAUI",
8650 		"KX4",
8651 		"CX4",
8652 		"KX",
8653 		"KR",
8654 		"SFP",
8655 		"BP_AP",
8656 		"BP4_AP",
8657 		"QSFP_10G",
8658 		"QSA",
8659 		"QSFP",
8660 		"BP40_BA",
8661 		"KR4_100G",
8662 		"CR4_QSFP",
8663 		"CR_QSFP",
8664 		"CR2_QSFP",
8665 		"SFP28",
8666 		"KR_SFP28",
8667 		"KR_XLAUI",
8668 	};
8669 
8670 	if (port_type < ARRAY_SIZE(port_type_description))
8671 		return port_type_description[port_type];
8672 	return "UNKNOWN";
8673 }
8674 
8675 /**
8676  *      t4_get_port_stats_offset - collect port stats relative to a previous
8677  *				   snapshot
8678  *      @adap: The adapter
8679  *      @idx: The port
8680  *      @stats: Current stats to fill
8681  *      @offset: Previous stats snapshot
8682  */
t4_get_port_stats_offset(struct adapter * adap,int idx,struct port_stats * stats,struct port_stats * offset)8683 void t4_get_port_stats_offset(struct adapter *adap, int idx,
8684 		struct port_stats *stats,
8685 		struct port_stats *offset)
8686 {
8687 	u64 *s, *o;
8688 	int i;
8689 
8690 	t4_get_port_stats(adap, idx, stats);
8691 	for (i = 0, s = (u64 *)stats, o = (u64 *)offset ;
8692 			i < (sizeof(struct port_stats)/sizeof(u64)) ;
8693 			i++, s++, o++)
8694 		*s -= *o;
8695 }
8696 
8697 /**
8698  *	t4_get_port_stats - collect port statistics
8699  *	@adap: the adapter
8700  *	@idx: the port index
8701  *	@p: the stats structure to fill
8702  *
8703  *	Collect statistics related to the given port from HW.
8704  */
t4_get_port_stats(struct adapter * adap,int idx,struct port_stats * p)8705 void t4_get_port_stats(struct adapter *adap, int idx, struct port_stats *p)
8706 {
8707 	struct port_info *pi;
8708 	int port_id, tx_chan;
8709 	u32 bgmap, stat_ctl;
8710 
8711 	port_id  = adap->port_map[idx];
8712 	MPASS(port_id >= 0 && port_id <= adap->params.nports);
8713 	pi = adap->port[port_id];
8714 
8715 #define GET_STAT(name) \
8716 	t4_read_reg64(adap, \
8717 	    t4_port_reg(adap, tx_chan, A_MPS_PORT_STAT_##name##_L));
8718 	memset(p, 0, sizeof(*p));
8719 	for (tx_chan = pi->tx_chan;
8720 	    tx_chan < pi->tx_chan + adap->params.tp.lb_nchan; tx_chan++) {
8721 		p->tx_pause		+= GET_STAT(TX_PORT_PAUSE);
8722 		p->tx_octets		+= GET_STAT(TX_PORT_BYTES);
8723 		p->tx_frames		+= GET_STAT(TX_PORT_FRAMES);
8724 		p->tx_bcast_frames	+= GET_STAT(TX_PORT_BCAST);
8725 		p->tx_mcast_frames	+= GET_STAT(TX_PORT_MCAST);
8726 		p->tx_ucast_frames	+= GET_STAT(TX_PORT_UCAST);
8727 		p->tx_error_frames	+= GET_STAT(TX_PORT_ERROR);
8728 		p->tx_frames_64		+= GET_STAT(TX_PORT_64B);
8729 		p->tx_frames_65_127	+= GET_STAT(TX_PORT_65B_127B);
8730 		p->tx_frames_128_255	+= GET_STAT(TX_PORT_128B_255B);
8731 		p->tx_frames_256_511	+= GET_STAT(TX_PORT_256B_511B);
8732 		p->tx_frames_512_1023	+= GET_STAT(TX_PORT_512B_1023B);
8733 		p->tx_frames_1024_1518	+= GET_STAT(TX_PORT_1024B_1518B);
8734 		p->tx_frames_1519_max	+= GET_STAT(TX_PORT_1519B_MAX);
8735 		p->tx_drop		+= GET_STAT(TX_PORT_DROP);
8736 		p->tx_ppp0		+= GET_STAT(TX_PORT_PPP0);
8737 		p->tx_ppp1		+= GET_STAT(TX_PORT_PPP1);
8738 		p->tx_ppp2		+= GET_STAT(TX_PORT_PPP2);
8739 		p->tx_ppp3		+= GET_STAT(TX_PORT_PPP3);
8740 		p->tx_ppp4		+= GET_STAT(TX_PORT_PPP4);
8741 		p->tx_ppp5		+= GET_STAT(TX_PORT_PPP5);
8742 		p->tx_ppp6		+= GET_STAT(TX_PORT_PPP6);
8743 		p->tx_ppp7		+= GET_STAT(TX_PORT_PPP7);
8744 
8745 		p->rx_pause		+= GET_STAT(RX_PORT_PAUSE);
8746 		p->rx_octets		+= GET_STAT(RX_PORT_BYTES);
8747 		p->rx_frames		+= GET_STAT(RX_PORT_FRAMES);
8748 		p->rx_bcast_frames	+= GET_STAT(RX_PORT_BCAST);
8749 		p->rx_mcast_frames	+= GET_STAT(RX_PORT_MCAST);
8750 		p->rx_ucast_frames	+= GET_STAT(RX_PORT_UCAST);
8751 		p->rx_too_long		+= GET_STAT(RX_PORT_MTU_ERROR);
8752 		p->rx_jabber		+= GET_STAT(RX_PORT_MTU_CRC_ERROR);
8753 		p->rx_len_err		+= GET_STAT(RX_PORT_LEN_ERROR);
8754 		p->rx_symbol_err	+= GET_STAT(RX_PORT_SYM_ERROR);
8755 		p->rx_runt		+= GET_STAT(RX_PORT_LESS_64B);
8756 		p->rx_frames_64		+= GET_STAT(RX_PORT_64B);
8757 		p->rx_frames_65_127	+= GET_STAT(RX_PORT_65B_127B);
8758 		p->rx_frames_128_255	+= GET_STAT(RX_PORT_128B_255B);
8759 		p->rx_frames_256_511	+= GET_STAT(RX_PORT_256B_511B);
8760 		p->rx_frames_512_1023	+= GET_STAT(RX_PORT_512B_1023B);
8761 		p->rx_frames_1024_1518	+= GET_STAT(RX_PORT_1024B_1518B);
8762 		p->rx_frames_1519_max	+= GET_STAT(RX_PORT_1519B_MAX);
8763 		p->rx_ppp0		+= GET_STAT(RX_PORT_PPP0);
8764 		p->rx_ppp1		+= GET_STAT(RX_PORT_PPP1);
8765 		p->rx_ppp2		+= GET_STAT(RX_PORT_PPP2);
8766 		p->rx_ppp3		+= GET_STAT(RX_PORT_PPP3);
8767 		p->rx_ppp4		+= GET_STAT(RX_PORT_PPP4);
8768 		p->rx_ppp5		+= GET_STAT(RX_PORT_PPP5);
8769 		p->rx_ppp6		+= GET_STAT(RX_PORT_PPP6);
8770 		p->rx_ppp7		+= GET_STAT(RX_PORT_PPP7);
8771 		if (!is_t6(adap)) {
8772 			MPASS(pi->fcs_reg == A_MPS_PORT_STAT_RX_PORT_CRC_ERROR_L);
8773 			p->rx_fcs_err	+= GET_STAT(RX_PORT_CRC_ERROR);
8774 		}
8775 	}
8776 #undef GET_STAT
8777 
8778 	if (is_t6(adap) && pi->fcs_reg != -1)
8779 		p->rx_fcs_err = t4_read_reg64(adap,
8780 		    t4_port_reg(adap, pi->tx_chan, pi->fcs_reg)) - pi->fcs_base;
8781 
8782 	if (chip_id(adap) >= CHELSIO_T5) {
8783 		stat_ctl = t4_read_reg(adap, A_MPS_STAT_CTL);
8784 		if (stat_ctl & F_COUNTPAUSESTATTX) {
8785 			p->tx_frames -= p->tx_pause;
8786 			p->tx_octets -= p->tx_pause * 64;
8787 		}
8788 		if (stat_ctl & F_COUNTPAUSEMCTX)
8789 			p->tx_mcast_frames -= p->tx_pause;
8790 		if (stat_ctl & F_COUNTPAUSESTATRX) {
8791 			p->rx_frames -= p->rx_pause;
8792 			p->rx_octets -= p->rx_pause * 64;
8793 		}
8794 		if (stat_ctl & F_COUNTPAUSEMCRX)
8795 			p->rx_mcast_frames -= p->rx_pause;
8796 	}
8797 
8798 #define GET_STAT_COM(name) t4_read_reg64(adap, A_MPS_STAT_##name##_L)
8799 	bgmap = pi->mps_bg_map;
8800 	p->rx_ovflow0 = (bgmap & 1) ? GET_STAT_COM(RX_BG_0_MAC_DROP_FRAME) : 0;
8801 	p->rx_ovflow1 = (bgmap & 2) ? GET_STAT_COM(RX_BG_1_MAC_DROP_FRAME) : 0;
8802 	p->rx_ovflow2 = (bgmap & 4) ? GET_STAT_COM(RX_BG_2_MAC_DROP_FRAME) : 0;
8803 	p->rx_ovflow3 = (bgmap & 8) ? GET_STAT_COM(RX_BG_3_MAC_DROP_FRAME) : 0;
8804 	p->rx_trunc0 = (bgmap & 1) ? GET_STAT_COM(RX_BG_0_MAC_TRUNC_FRAME) : 0;
8805 	p->rx_trunc1 = (bgmap & 2) ? GET_STAT_COM(RX_BG_1_MAC_TRUNC_FRAME) : 0;
8806 	p->rx_trunc2 = (bgmap & 4) ? GET_STAT_COM(RX_BG_2_MAC_TRUNC_FRAME) : 0;
8807 	p->rx_trunc3 = (bgmap & 8) ? GET_STAT_COM(RX_BG_3_MAC_TRUNC_FRAME) : 0;
8808 #undef GET_STAT_COM
8809 }
8810 
8811 /**
8812  *	t4_get_lb_stats - collect loopback port statistics
8813  *	@adap: the adapter
8814  *	@idx: the loopback port index
8815  *	@p: the stats structure to fill
8816  *
8817  *	Return HW statistics for the given loopback port.
8818  */
t4_get_lb_stats(struct adapter * adap,int idx,struct lb_port_stats * p)8819 void t4_get_lb_stats(struct adapter *adap, int idx, struct lb_port_stats *p)
8820 {
8821 
8822 #define GET_STAT(name) \
8823 	t4_read_reg64(adap, \
8824 	    t4_port_reg(adap, idx, A_MPS_PORT_STAT_LB_PORT_##name##_L))
8825 #define GET_STAT_COM(name) t4_read_reg64(adap, A_MPS_STAT_##name##_L)
8826 
8827 	p->octets	= GET_STAT(BYTES);
8828 	p->frames	= GET_STAT(FRAMES);
8829 	p->bcast_frames	= GET_STAT(BCAST);
8830 	p->mcast_frames	= GET_STAT(MCAST);
8831 	p->ucast_frames	= GET_STAT(UCAST);
8832 	p->error_frames	= GET_STAT(ERROR);
8833 
8834 	p->frames_64		= GET_STAT(64B);
8835 	p->frames_65_127	= GET_STAT(65B_127B);
8836 	p->frames_128_255	= GET_STAT(128B_255B);
8837 	p->frames_256_511	= GET_STAT(256B_511B);
8838 	p->frames_512_1023	= GET_STAT(512B_1023B);
8839 	p->frames_1024_1518	= GET_STAT(1024B_1518B);
8840 	p->frames_1519_max	= GET_STAT(1519B_MAX);
8841 	p->drop			= GET_STAT(DROP_FRAMES);
8842 
8843 	if (idx < adap->params.nports) {
8844 		u32 bg = adap2pinfo(adap, idx)->mps_bg_map;
8845 
8846 		p->ovflow0 = (bg & 1) ? GET_STAT_COM(RX_BG_0_LB_DROP_FRAME) : 0;
8847 		p->ovflow1 = (bg & 2) ? GET_STAT_COM(RX_BG_1_LB_DROP_FRAME) : 0;
8848 		p->ovflow2 = (bg & 4) ? GET_STAT_COM(RX_BG_2_LB_DROP_FRAME) : 0;
8849 		p->ovflow3 = (bg & 8) ? GET_STAT_COM(RX_BG_3_LB_DROP_FRAME) : 0;
8850 		p->trunc0 = (bg & 1) ? GET_STAT_COM(RX_BG_0_LB_TRUNC_FRAME) : 0;
8851 		p->trunc1 = (bg & 2) ? GET_STAT_COM(RX_BG_1_LB_TRUNC_FRAME) : 0;
8852 		p->trunc2 = (bg & 4) ? GET_STAT_COM(RX_BG_2_LB_TRUNC_FRAME) : 0;
8853 		p->trunc3 = (bg & 8) ? GET_STAT_COM(RX_BG_3_LB_TRUNC_FRAME) : 0;
8854 	}
8855 
8856 #undef GET_STAT
8857 #undef GET_STAT_COM
8858 }
8859 
8860 /**
8861  *	t4_wol_magic_enable - enable/disable magic packet WoL
8862  *	@adap: the adapter
8863  *	@port: the physical port index
8864  *	@addr: MAC address expected in magic packets, %NULL to disable
8865  *
8866  *	Enables/disables magic packet wake-on-LAN for the selected port.
8867  */
t4_wol_magic_enable(struct adapter * adap,unsigned int port,const u8 * addr)8868 void t4_wol_magic_enable(struct adapter *adap, unsigned int port,
8869 			 const u8 *addr)
8870 {
8871 	u32 mag_id_reg_l, mag_id_reg_h, port_cfg_reg;
8872 
8873 	if (is_t4(adap)) {
8874 		mag_id_reg_l = PORT_REG(port, A_XGMAC_PORT_MAGIC_MACID_LO);
8875 		mag_id_reg_h = PORT_REG(port, A_XGMAC_PORT_MAGIC_MACID_HI);
8876 		port_cfg_reg = PORT_REG(port, A_XGMAC_PORT_CFG2);
8877 	} else if (chip_id(adap) < CHELSIO_T7) {
8878 		mag_id_reg_l = T5_PORT_REG(port, A_MAC_PORT_MAGIC_MACID_LO);
8879 		mag_id_reg_h = T5_PORT_REG(port, A_MAC_PORT_MAGIC_MACID_HI);
8880 		port_cfg_reg = T5_PORT_REG(port, A_MAC_PORT_CFG2);
8881 	} else {
8882 		mag_id_reg_l = T7_PORT_REG(port, A_T7_MAC_PORT_MAGIC_MACID_LO);
8883 		mag_id_reg_h = T7_PORT_REG(port, A_T7_MAC_PORT_MAGIC_MACID_HI);
8884 		port_cfg_reg = T7_PORT_REG(port, A_MAC_PORT_CFG2);
8885 	}
8886 
8887 	if (addr) {
8888 		t4_write_reg(adap, mag_id_reg_l,
8889 			     (addr[2] << 24) | (addr[3] << 16) |
8890 			     (addr[4] << 8) | addr[5]);
8891 		t4_write_reg(adap, mag_id_reg_h,
8892 			     (addr[0] << 8) | addr[1]);
8893 	}
8894 	t4_set_reg_field(adap, port_cfg_reg, F_MAGICEN,
8895 			 V_MAGICEN(addr != NULL));
8896 }
8897 
8898 /**
8899  *	t4_wol_pat_enable - enable/disable pattern-based WoL
8900  *	@adap: the adapter
8901  *	@port: the physical port index
8902  *	@map: bitmap of which HW pattern filters to set
8903  *	@mask0: byte mask for bytes 0-63 of a packet
8904  *	@mask1: byte mask for bytes 64-127 of a packet
8905  *	@crc: Ethernet CRC for selected bytes
8906  *	@enable: enable/disable switch
8907  *
8908  *	Sets the pattern filters indicated in @map to mask out the bytes
8909  *	specified in @mask0/@mask1 in received packets and compare the CRC of
8910  *	the resulting packet against @crc.  If @enable is %true pattern-based
8911  *	WoL is enabled, otherwise disabled.
8912  */
t4_wol_pat_enable(struct adapter * adap,unsigned int port,unsigned int map,u64 mask0,u64 mask1,unsigned int crc,bool enable)8913 int t4_wol_pat_enable(struct adapter *adap, unsigned int port, unsigned int map,
8914 		      u64 mask0, u64 mask1, unsigned int crc, bool enable)
8915 {
8916 	int i;
8917 	u32 port_cfg_reg;
8918 
8919 	if (is_t4(adap))
8920 		port_cfg_reg = PORT_REG(port, A_XGMAC_PORT_CFG2);
8921 	else if (chip_id(adap) < CHELSIO_T7)
8922 		port_cfg_reg = T5_PORT_REG(port, A_MAC_PORT_CFG2);
8923 	else
8924 		port_cfg_reg = T7_PORT_REG(port, A_MAC_PORT_CFG2);
8925 
8926 	if (!enable) {
8927 		t4_set_reg_field(adap, port_cfg_reg, F_PATEN, 0);
8928 		return 0;
8929 	}
8930 	if (map > 0xff)
8931 		return -EINVAL;
8932 
8933 #define EPIO_REG(name) \
8934 	(is_t4(adap) ? PORT_REG(port, A_XGMAC_PORT_EPIO_##name) : \
8935 	T5_PORT_REG(port, A_MAC_PORT_EPIO_##name))
8936 
8937 	t4_write_reg(adap, EPIO_REG(DATA1), mask0 >> 32);
8938 	t4_write_reg(adap, EPIO_REG(DATA2), mask1);
8939 	t4_write_reg(adap, EPIO_REG(DATA3), mask1 >> 32);
8940 
8941 	for (i = 0; i < NWOL_PAT; i++, map >>= 1) {
8942 		if (!(map & 1))
8943 			continue;
8944 
8945 		/* write byte masks */
8946 		t4_write_reg(adap, EPIO_REG(DATA0), mask0);
8947 		t4_write_reg(adap, EPIO_REG(OP), V_ADDRESS(i) | F_EPIOWR);
8948 		t4_read_reg(adap, EPIO_REG(OP));                /* flush */
8949 		if (t4_read_reg(adap, EPIO_REG(OP)) & F_BUSY)
8950 			return -ETIMEDOUT;
8951 
8952 		/* write CRC */
8953 		t4_write_reg(adap, EPIO_REG(DATA0), crc);
8954 		t4_write_reg(adap, EPIO_REG(OP), V_ADDRESS(i + 32) | F_EPIOWR);
8955 		t4_read_reg(adap, EPIO_REG(OP));                /* flush */
8956 		if (t4_read_reg(adap, EPIO_REG(OP)) & F_BUSY)
8957 			return -ETIMEDOUT;
8958 	}
8959 #undef EPIO_REG
8960 
8961 	t4_set_reg_field(adap, port_cfg_reg, 0, F_PATEN);
8962 	return 0;
8963 }
8964 
8965 /*     t4_mk_filtdelwr - create a delete filter WR
8966  *     @ftid: the filter ID
8967  *     @wr: the filter work request to populate
8968  *     @qid: ingress queue to receive the delete notification
8969  *
8970  *     Creates a filter work request to delete the supplied filter.  If @qid is
8971  *     negative the delete notification is suppressed.
8972  */
t4_mk_filtdelwr(unsigned int ftid,struct fw_filter_wr * wr,int qid)8973 void t4_mk_filtdelwr(unsigned int ftid, struct fw_filter_wr *wr, int qid)
8974 {
8975 	memset(wr, 0, sizeof(*wr));
8976 	wr->op_pkd = cpu_to_be32(V_FW_WR_OP(FW_FILTER_WR));
8977 	wr->len16_pkd = cpu_to_be32(V_FW_WR_LEN16(sizeof(*wr) / 16));
8978 	wr->tid_to_iq = cpu_to_be32(V_FW_FILTER_WR_TID(ftid) |
8979 				    V_FW_FILTER_WR_NOREPLY(qid < 0));
8980 	wr->del_filter_to_l2tix = cpu_to_be32(F_FW_FILTER_WR_DEL_FILTER);
8981 	if (qid >= 0)
8982 		wr->rx_chan_rx_rpl_iq =
8983 				cpu_to_be16(V_FW_FILTER_WR_RX_RPL_IQ(qid));
8984 }
8985 
8986 #define INIT_CMD(var, cmd, rd_wr) do { \
8987 	(var).op_to_write = cpu_to_be32(V_FW_CMD_OP(FW_##cmd##_CMD) | \
8988 					F_FW_CMD_REQUEST | \
8989 					F_FW_CMD_##rd_wr); \
8990 	(var).retval_len16 = cpu_to_be32(FW_LEN16(var)); \
8991 } while (0)
8992 
t4_fwaddrspace_write(struct adapter * adap,unsigned int mbox,u32 addr,u32 val)8993 int t4_fwaddrspace_write(struct adapter *adap, unsigned int mbox,
8994 			  u32 addr, u32 val)
8995 {
8996 	u32 ldst_addrspace;
8997 	struct fw_ldst_cmd c;
8998 
8999 	memset(&c, 0, sizeof(c));
9000 	ldst_addrspace = V_FW_LDST_CMD_ADDRSPACE(FW_LDST_ADDRSPC_FIRMWARE);
9001 	c.op_to_addrspace = cpu_to_be32(V_FW_CMD_OP(FW_LDST_CMD) |
9002 					F_FW_CMD_REQUEST |
9003 					F_FW_CMD_WRITE |
9004 					ldst_addrspace);
9005 	c.cycles_to_len16 = cpu_to_be32(FW_LEN16(c));
9006 	c.u.addrval.addr = cpu_to_be32(addr);
9007 	c.u.addrval.val = cpu_to_be32(val);
9008 
9009 	return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
9010 }
9011 
9012 /**
9013  *	t4_mdio_rd - read a PHY register through MDIO
9014  *	@adap: the adapter
9015  *	@mbox: mailbox to use for the FW command
9016  *	@phy_addr: the PHY address
9017  *	@mmd: the PHY MMD to access (0 for clause 22 PHYs)
9018  *	@reg: the register to read
9019  *	@valp: where to store the value
9020  *
9021  *	Issues a FW command through the given mailbox to read a PHY register.
9022  */
t4_mdio_rd(struct adapter * adap,unsigned int mbox,unsigned int phy_addr,unsigned int mmd,unsigned int reg,unsigned int * valp)9023 int t4_mdio_rd(struct adapter *adap, unsigned int mbox, unsigned int phy_addr,
9024 	       unsigned int mmd, unsigned int reg, unsigned int *valp)
9025 {
9026 	int ret;
9027 	u32 ldst_addrspace;
9028 	struct fw_ldst_cmd c;
9029 
9030 	memset(&c, 0, sizeof(c));
9031 	ldst_addrspace = V_FW_LDST_CMD_ADDRSPACE(FW_LDST_ADDRSPC_MDIO);
9032 	c.op_to_addrspace = cpu_to_be32(V_FW_CMD_OP(FW_LDST_CMD) |
9033 					F_FW_CMD_REQUEST | F_FW_CMD_READ |
9034 					ldst_addrspace);
9035 	c.cycles_to_len16 = cpu_to_be32(FW_LEN16(c));
9036 	c.u.mdio.paddr_mmd = cpu_to_be16(V_FW_LDST_CMD_PADDR(phy_addr) |
9037 					 V_FW_LDST_CMD_MMD(mmd));
9038 	c.u.mdio.raddr = cpu_to_be16(reg);
9039 
9040 	ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
9041 	if (ret == 0)
9042 		*valp = be16_to_cpu(c.u.mdio.rval);
9043 	return ret;
9044 }
9045 
9046 /**
9047  *	t4_mdio_wr - write a PHY register through MDIO
9048  *	@adap: the adapter
9049  *	@mbox: mailbox to use for the FW command
9050  *	@phy_addr: the PHY address
9051  *	@mmd: the PHY MMD to access (0 for clause 22 PHYs)
9052  *	@reg: the register to write
9053  *	@valp: value to write
9054  *
9055  *	Issues a FW command through the given mailbox to write a PHY register.
9056  */
t4_mdio_wr(struct adapter * adap,unsigned int mbox,unsigned int phy_addr,unsigned int mmd,unsigned int reg,unsigned int val)9057 int t4_mdio_wr(struct adapter *adap, unsigned int mbox, unsigned int phy_addr,
9058 	       unsigned int mmd, unsigned int reg, unsigned int val)
9059 {
9060 	u32 ldst_addrspace;
9061 	struct fw_ldst_cmd c;
9062 
9063 	memset(&c, 0, sizeof(c));
9064 	ldst_addrspace = V_FW_LDST_CMD_ADDRSPACE(FW_LDST_ADDRSPC_MDIO);
9065 	c.op_to_addrspace = cpu_to_be32(V_FW_CMD_OP(FW_LDST_CMD) |
9066 					F_FW_CMD_REQUEST | F_FW_CMD_WRITE |
9067 					ldst_addrspace);
9068 	c.cycles_to_len16 = cpu_to_be32(FW_LEN16(c));
9069 	c.u.mdio.paddr_mmd = cpu_to_be16(V_FW_LDST_CMD_PADDR(phy_addr) |
9070 					 V_FW_LDST_CMD_MMD(mmd));
9071 	c.u.mdio.raddr = cpu_to_be16(reg);
9072 	c.u.mdio.rval = cpu_to_be16(val);
9073 
9074 	return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
9075 }
9076 
9077 /**
9078  *
9079  *	t4_sge_decode_idma_state - decode the idma state
9080  *	@adap: the adapter
9081  *	@state: the state idma is stuck in
9082  */
t4_sge_decode_idma_state(struct adapter * adapter,int state)9083 void t4_sge_decode_idma_state(struct adapter *adapter, int state)
9084 {
9085 	static const char * const t4_decode[] = {
9086 		"IDMA_IDLE",
9087 		"IDMA_PUSH_MORE_CPL_FIFO",
9088 		"IDMA_PUSH_CPL_MSG_HEADER_TO_FIFO",
9089 		"Not used",
9090 		"IDMA_PHYSADDR_SEND_PCIEHDR",
9091 		"IDMA_PHYSADDR_SEND_PAYLOAD_FIRST",
9092 		"IDMA_PHYSADDR_SEND_PAYLOAD",
9093 		"IDMA_SEND_FIFO_TO_IMSG",
9094 		"IDMA_FL_REQ_DATA_FL_PREP",
9095 		"IDMA_FL_REQ_DATA_FL",
9096 		"IDMA_FL_DROP",
9097 		"IDMA_FL_H_REQ_HEADER_FL",
9098 		"IDMA_FL_H_SEND_PCIEHDR",
9099 		"IDMA_FL_H_PUSH_CPL_FIFO",
9100 		"IDMA_FL_H_SEND_CPL",
9101 		"IDMA_FL_H_SEND_IP_HDR_FIRST",
9102 		"IDMA_FL_H_SEND_IP_HDR",
9103 		"IDMA_FL_H_REQ_NEXT_HEADER_FL",
9104 		"IDMA_FL_H_SEND_NEXT_PCIEHDR",
9105 		"IDMA_FL_H_SEND_IP_HDR_PADDING",
9106 		"IDMA_FL_D_SEND_PCIEHDR",
9107 		"IDMA_FL_D_SEND_CPL_AND_IP_HDR",
9108 		"IDMA_FL_D_REQ_NEXT_DATA_FL",
9109 		"IDMA_FL_SEND_PCIEHDR",
9110 		"IDMA_FL_PUSH_CPL_FIFO",
9111 		"IDMA_FL_SEND_CPL",
9112 		"IDMA_FL_SEND_PAYLOAD_FIRST",
9113 		"IDMA_FL_SEND_PAYLOAD",
9114 		"IDMA_FL_REQ_NEXT_DATA_FL",
9115 		"IDMA_FL_SEND_NEXT_PCIEHDR",
9116 		"IDMA_FL_SEND_PADDING",
9117 		"IDMA_FL_SEND_COMPLETION_TO_IMSG",
9118 		"IDMA_FL_SEND_FIFO_TO_IMSG",
9119 		"IDMA_FL_REQ_DATAFL_DONE",
9120 		"IDMA_FL_REQ_HEADERFL_DONE",
9121 	};
9122 	static const char * const t5_decode[] = {
9123 		"IDMA_IDLE",
9124 		"IDMA_ALMOST_IDLE",
9125 		"IDMA_PUSH_MORE_CPL_FIFO",
9126 		"IDMA_PUSH_CPL_MSG_HEADER_TO_FIFO",
9127 		"IDMA_SGEFLRFLUSH_SEND_PCIEHDR",
9128 		"IDMA_PHYSADDR_SEND_PCIEHDR",
9129 		"IDMA_PHYSADDR_SEND_PAYLOAD_FIRST",
9130 		"IDMA_PHYSADDR_SEND_PAYLOAD",
9131 		"IDMA_SEND_FIFO_TO_IMSG",
9132 		"IDMA_FL_REQ_DATA_FL",
9133 		"IDMA_FL_DROP",
9134 		"IDMA_FL_DROP_SEND_INC",
9135 		"IDMA_FL_H_REQ_HEADER_FL",
9136 		"IDMA_FL_H_SEND_PCIEHDR",
9137 		"IDMA_FL_H_PUSH_CPL_FIFO",
9138 		"IDMA_FL_H_SEND_CPL",
9139 		"IDMA_FL_H_SEND_IP_HDR_FIRST",
9140 		"IDMA_FL_H_SEND_IP_HDR",
9141 		"IDMA_FL_H_REQ_NEXT_HEADER_FL",
9142 		"IDMA_FL_H_SEND_NEXT_PCIEHDR",
9143 		"IDMA_FL_H_SEND_IP_HDR_PADDING",
9144 		"IDMA_FL_D_SEND_PCIEHDR",
9145 		"IDMA_FL_D_SEND_CPL_AND_IP_HDR",
9146 		"IDMA_FL_D_REQ_NEXT_DATA_FL",
9147 		"IDMA_FL_SEND_PCIEHDR",
9148 		"IDMA_FL_PUSH_CPL_FIFO",
9149 		"IDMA_FL_SEND_CPL",
9150 		"IDMA_FL_SEND_PAYLOAD_FIRST",
9151 		"IDMA_FL_SEND_PAYLOAD",
9152 		"IDMA_FL_REQ_NEXT_DATA_FL",
9153 		"IDMA_FL_SEND_NEXT_PCIEHDR",
9154 		"IDMA_FL_SEND_PADDING",
9155 		"IDMA_FL_SEND_COMPLETION_TO_IMSG",
9156 	};
9157 	static const char * const t6_decode[] = {
9158 		"IDMA_IDLE",
9159 		"IDMA_PUSH_MORE_CPL_FIFO",
9160 		"IDMA_PUSH_CPL_MSG_HEADER_TO_FIFO",
9161 		"IDMA_SGEFLRFLUSH_SEND_PCIEHDR",
9162 		"IDMA_PHYSADDR_SEND_PCIEHDR",
9163 		"IDMA_PHYSADDR_SEND_PAYLOAD_FIRST",
9164 		"IDMA_PHYSADDR_SEND_PAYLOAD",
9165 		"IDMA_FL_REQ_DATA_FL",
9166 		"IDMA_FL_DROP",
9167 		"IDMA_FL_DROP_SEND_INC",
9168 		"IDMA_FL_H_REQ_HEADER_FL",
9169 		"IDMA_FL_H_SEND_PCIEHDR",
9170 		"IDMA_FL_H_PUSH_CPL_FIFO",
9171 		"IDMA_FL_H_SEND_CPL",
9172 		"IDMA_FL_H_SEND_IP_HDR_FIRST",
9173 		"IDMA_FL_H_SEND_IP_HDR",
9174 		"IDMA_FL_H_REQ_NEXT_HEADER_FL",
9175 		"IDMA_FL_H_SEND_NEXT_PCIEHDR",
9176 		"IDMA_FL_H_SEND_IP_HDR_PADDING",
9177 		"IDMA_FL_D_SEND_PCIEHDR",
9178 		"IDMA_FL_D_SEND_CPL_AND_IP_HDR",
9179 		"IDMA_FL_D_REQ_NEXT_DATA_FL",
9180 		"IDMA_FL_SEND_PCIEHDR",
9181 		"IDMA_FL_PUSH_CPL_FIFO",
9182 		"IDMA_FL_SEND_CPL",
9183 		"IDMA_FL_SEND_PAYLOAD_FIRST",
9184 		"IDMA_FL_SEND_PAYLOAD",
9185 		"IDMA_FL_REQ_NEXT_DATA_FL",
9186 		"IDMA_FL_SEND_NEXT_PCIEHDR",
9187 		"IDMA_FL_SEND_PADDING",
9188 		"IDMA_FL_SEND_COMPLETION_TO_IMSG",
9189 	};
9190 	static const u32 sge_regs[] = {
9191 		A_SGE_DEBUG_DATA_LOW_INDEX_2,
9192 		A_SGE_DEBUG_DATA_LOW_INDEX_3,
9193 		A_SGE_DEBUG_DATA_HIGH_INDEX_10,
9194 	};
9195 	const char * const *sge_idma_decode;
9196 	int sge_idma_decode_nstates;
9197 	int i;
9198 	unsigned int chip_version = chip_id(adapter);
9199 
9200 	/* Select the right set of decode strings to dump depending on the
9201 	 * adapter chip type.
9202 	 */
9203 	switch (chip_version) {
9204 	case CHELSIO_T4:
9205 		sge_idma_decode = (const char * const *)t4_decode;
9206 		sge_idma_decode_nstates = ARRAY_SIZE(t4_decode);
9207 		break;
9208 
9209 	case CHELSIO_T5:
9210 		sge_idma_decode = (const char * const *)t5_decode;
9211 		sge_idma_decode_nstates = ARRAY_SIZE(t5_decode);
9212 		break;
9213 
9214 	case CHELSIO_T6:
9215 	case CHELSIO_T7:
9216 		sge_idma_decode = (const char * const *)t6_decode;
9217 		sge_idma_decode_nstates = ARRAY_SIZE(t6_decode);
9218 		break;
9219 
9220 	default:
9221 		CH_ERR(adapter,	"Unsupported chip version %d\n", chip_version);
9222 		return;
9223 	}
9224 
9225 	if (state < sge_idma_decode_nstates)
9226 		CH_WARN(adapter, "idma state %s\n", sge_idma_decode[state]);
9227 	else
9228 		CH_WARN(adapter, "idma state %d unknown\n", state);
9229 
9230 	for (i = 0; i < ARRAY_SIZE(sge_regs); i++)
9231 		CH_WARN(adapter, "SGE register %#x value %#x\n",
9232 			sge_regs[i], t4_read_reg(adapter, sge_regs[i]));
9233 }
9234 
9235 /**
9236  *      t4_sge_ctxt_flush - flush the SGE context cache
9237  *      @adap: the adapter
9238  *      @mbox: mailbox to use for the FW command
9239  *
9240  *      Issues a FW command through the given mailbox to flush the
9241  *      SGE context cache.
9242  */
t4_sge_ctxt_flush(struct adapter * adap,unsigned int mbox,int ctxt_type)9243 int t4_sge_ctxt_flush(struct adapter *adap, unsigned int mbox, int ctxt_type)
9244 {
9245 	int ret;
9246 	u32 ldst_addrspace;
9247 	struct fw_ldst_cmd c;
9248 
9249 	memset(&c, 0, sizeof(c));
9250 	ldst_addrspace = V_FW_LDST_CMD_ADDRSPACE(ctxt_type == CTXT_EGRESS ?
9251 						 FW_LDST_ADDRSPC_SGE_EGRC :
9252 						 FW_LDST_ADDRSPC_SGE_INGC);
9253 	c.op_to_addrspace = cpu_to_be32(V_FW_CMD_OP(FW_LDST_CMD) |
9254 					F_FW_CMD_REQUEST | F_FW_CMD_READ |
9255 					ldst_addrspace);
9256 	c.cycles_to_len16 = cpu_to_be32(FW_LEN16(c));
9257 	c.u.idctxt.msg_ctxtflush = cpu_to_be32(F_FW_LDST_CMD_CTXTFLUSH);
9258 
9259 	ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
9260 	return ret;
9261 }
9262 
9263 /**
9264  *      t4_fw_hello - establish communication with FW
9265  *      @adap: the adapter
9266  *      @mbox: mailbox to use for the FW command
9267  *      @evt_mbox: mailbox to receive async FW events
9268  *      @master: specifies the caller's willingness to be the device master
9269  *	@state: returns the current device state (if non-NULL)
9270  *
9271  *	Issues a command to establish communication with FW.  Returns either
9272  *	an error (negative integer) or the mailbox of the Master PF.
9273  */
t4_fw_hello(struct adapter * adap,unsigned int mbox,unsigned int evt_mbox,enum dev_master master,enum dev_state * state)9274 int t4_fw_hello(struct adapter *adap, unsigned int mbox, unsigned int evt_mbox,
9275 		enum dev_master master, enum dev_state *state)
9276 {
9277 	int ret;
9278 	struct fw_hello_cmd c;
9279 	u32 v;
9280 	unsigned int master_mbox;
9281 	int retries = FW_CMD_HELLO_RETRIES;
9282 
9283 retry:
9284 	memset(&c, 0, sizeof(c));
9285 	INIT_CMD(c, HELLO, WRITE);
9286 	c.err_to_clearinit = cpu_to_be32(
9287 		V_FW_HELLO_CMD_MASTERDIS(master == MASTER_CANT) |
9288 		V_FW_HELLO_CMD_MASTERFORCE(master == MASTER_MUST) |
9289 		V_FW_HELLO_CMD_MBMASTER(master == MASTER_MUST ?
9290 					mbox : M_FW_HELLO_CMD_MBMASTER) |
9291 		V_FW_HELLO_CMD_MBASYNCNOT(evt_mbox) |
9292 		V_FW_HELLO_CMD_STAGE(FW_HELLO_CMD_STAGE_OS) |
9293 		F_FW_HELLO_CMD_CLEARINIT);
9294 
9295 	/*
9296 	 * Issue the HELLO command to the firmware.  If it's not successful
9297 	 * but indicates that we got a "busy" or "timeout" condition, retry
9298 	 * the HELLO until we exhaust our retry limit.  If we do exceed our
9299 	 * retry limit, check to see if the firmware left us any error
9300 	 * information and report that if so ...
9301 	 */
9302 	ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
9303 	if (ret != FW_SUCCESS) {
9304 		if ((ret == -EBUSY || ret == -ETIMEDOUT) && retries-- > 0)
9305 			goto retry;
9306 		return ret;
9307 	}
9308 
9309 	v = be32_to_cpu(c.err_to_clearinit);
9310 	master_mbox = G_FW_HELLO_CMD_MBMASTER(v);
9311 	if (state) {
9312 		if (v & F_FW_HELLO_CMD_ERR)
9313 			*state = DEV_STATE_ERR;
9314 		else if (v & F_FW_HELLO_CMD_INIT)
9315 			*state = DEV_STATE_INIT;
9316 		else
9317 			*state = DEV_STATE_UNINIT;
9318 	}
9319 
9320 	/*
9321 	 * If we're not the Master PF then we need to wait around for the
9322 	 * Master PF Driver to finish setting up the adapter.
9323 	 *
9324 	 * Note that we also do this wait if we're a non-Master-capable PF and
9325 	 * there is no current Master PF; a Master PF may show up momentarily
9326 	 * and we wouldn't want to fail pointlessly.  (This can happen when an
9327 	 * OS loads lots of different drivers rapidly at the same time).  In
9328 	 * this case, the Master PF returned by the firmware will be
9329 	 * M_PCIE_FW_MASTER so the test below will work ...
9330 	 */
9331 	if ((v & (F_FW_HELLO_CMD_ERR|F_FW_HELLO_CMD_INIT)) == 0 &&
9332 	    master_mbox != mbox) {
9333 		int waiting = FW_CMD_HELLO_TIMEOUT;
9334 
9335 		/*
9336 		 * Wait for the firmware to either indicate an error or
9337 		 * initialized state.  If we see either of these we bail out
9338 		 * and report the issue to the caller.  If we exhaust the
9339 		 * "hello timeout" and we haven't exhausted our retries, try
9340 		 * again.  Otherwise bail with a timeout error.
9341 		 */
9342 		for (;;) {
9343 			u32 pcie_fw;
9344 
9345 			msleep(50);
9346 			waiting -= 50;
9347 
9348 			/*
9349 			 * If neither Error nor Initialialized are indicated
9350 			 * by the firmware keep waiting till we exhaust our
9351 			 * timeout ... and then retry if we haven't exhausted
9352 			 * our retries ...
9353 			 */
9354 			pcie_fw = t4_read_reg(adap, A_PCIE_FW);
9355 			if (!(pcie_fw & (F_PCIE_FW_ERR|F_PCIE_FW_INIT))) {
9356 				if (waiting <= 0) {
9357 					if (retries-- > 0)
9358 						goto retry;
9359 
9360 					return -ETIMEDOUT;
9361 				}
9362 				continue;
9363 			}
9364 
9365 			/*
9366 			 * We either have an Error or Initialized condition
9367 			 * report errors preferentially.
9368 			 */
9369 			if (state) {
9370 				if (pcie_fw & F_PCIE_FW_ERR)
9371 					*state = DEV_STATE_ERR;
9372 				else if (pcie_fw & F_PCIE_FW_INIT)
9373 					*state = DEV_STATE_INIT;
9374 			}
9375 
9376 			/*
9377 			 * If we arrived before a Master PF was selected and
9378 			 * there's not a valid Master PF, grab its identity
9379 			 * for our caller.
9380 			 */
9381 			if (master_mbox == M_PCIE_FW_MASTER &&
9382 			    (pcie_fw & F_PCIE_FW_MASTER_VLD))
9383 				master_mbox = G_PCIE_FW_MASTER(pcie_fw);
9384 			break;
9385 		}
9386 	}
9387 
9388 	return master_mbox;
9389 }
9390 
9391 /**
9392  *	t4_fw_bye - end communication with FW
9393  *	@adap: the adapter
9394  *	@mbox: mailbox to use for the FW command
9395  *
9396  *	Issues a command to terminate communication with FW.
9397  */
t4_fw_bye(struct adapter * adap,unsigned int mbox)9398 int t4_fw_bye(struct adapter *adap, unsigned int mbox)
9399 {
9400 	struct fw_bye_cmd c;
9401 
9402 	memset(&c, 0, sizeof(c));
9403 	INIT_CMD(c, BYE, WRITE);
9404 	return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
9405 }
9406 
9407 /**
9408  *	t4_fw_reset - issue a reset to FW
9409  *	@adap: the adapter
9410  *	@mbox: mailbox to use for the FW command
9411  *	@reset: specifies the type of reset to perform
9412  *
9413  *	Issues a reset command of the specified type to FW.
9414  */
t4_fw_reset(struct adapter * adap,unsigned int mbox,int reset)9415 int t4_fw_reset(struct adapter *adap, unsigned int mbox, int reset)
9416 {
9417 	struct fw_reset_cmd c;
9418 
9419 	memset(&c, 0, sizeof(c));
9420 	INIT_CMD(c, RESET, WRITE);
9421 	c.val = cpu_to_be32(reset);
9422 	return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
9423 }
9424 
9425 /**
9426  *	t4_fw_halt - issue a reset/halt to FW and put uP into RESET
9427  *	@adap: the adapter
9428  *	@mbox: mailbox to use for the FW RESET command (if desired)
9429  *	@force: force uP into RESET even if FW RESET command fails
9430  *
9431  *	Issues a RESET command to firmware (if desired) with a HALT indication
9432  *	and then puts the microprocessor into RESET state.  The RESET command
9433  *	will only be issued if a legitimate mailbox is provided (mbox <=
9434  *	M_PCIE_FW_MASTER).
9435  *
9436  *	This is generally used in order for the host to safely manipulate the
9437  *	adapter without fear of conflicting with whatever the firmware might
9438  *	be doing.  The only way out of this state is to RESTART the firmware
9439  *	...
9440  */
t4_fw_halt(struct adapter * adap,unsigned int mbox,int force)9441 int t4_fw_halt(struct adapter *adap, unsigned int mbox, int force)
9442 {
9443 	int ret = 0;
9444 
9445 	/*
9446 	 * If a legitimate mailbox is provided, issue a RESET command
9447 	 * with a HALT indication.
9448 	 */
9449 	if (adap->flags & FW_OK && mbox <= M_PCIE_FW_MASTER) {
9450 		struct fw_reset_cmd c;
9451 
9452 		memset(&c, 0, sizeof(c));
9453 		INIT_CMD(c, RESET, WRITE);
9454 		c.val = cpu_to_be32(F_PIORST | F_PIORSTMODE);
9455 		c.halt_pkd = cpu_to_be32(F_FW_RESET_CMD_HALT);
9456 		ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
9457 	}
9458 
9459 	/*
9460 	 * Normally we won't complete the operation if the firmware RESET
9461 	 * command fails but if our caller insists we'll go ahead and put the
9462 	 * uP into RESET.  This can be useful if the firmware is hung or even
9463 	 * missing ...  We'll have to take the risk of putting the uP into
9464 	 * RESET without the cooperation of firmware in that case.
9465 	 *
9466 	 * We also force the firmware's HALT flag to be on in case we bypassed
9467 	 * the firmware RESET command above or we're dealing with old firmware
9468 	 * which doesn't have the HALT capability.  This will serve as a flag
9469 	 * for the incoming firmware to know that it's coming out of a HALT
9470 	 * rather than a RESET ... if it's new enough to understand that ...
9471 	 */
9472 	if (ret == 0 || force) {
9473 		t4_set_reg_field(adap, A_CIM_BOOT_CFG, F_UPCRST, F_UPCRST);
9474 		t4_set_reg_field(adap, A_PCIE_FW, F_PCIE_FW_HALT,
9475 				 F_PCIE_FW_HALT);
9476 	}
9477 
9478 	/*
9479 	 * And we always return the result of the firmware RESET command
9480 	 * even when we force the uP into RESET ...
9481 	 */
9482 	return ret;
9483 }
9484 
9485 /**
9486  *	t4_fw_restart - restart the firmware by taking the uP out of RESET
9487  *	@adap: the adapter
9488  *
9489  *	Restart firmware previously halted by t4_fw_halt().  On successful
9490  *	return the previous PF Master remains as the new PF Master and there
9491  *	is no need to issue a new HELLO command, etc.
9492  */
t4_fw_restart(struct adapter * adap,unsigned int mbox)9493 int t4_fw_restart(struct adapter *adap, unsigned int mbox)
9494 {
9495 	int ms;
9496 
9497 	t4_set_reg_field(adap, A_CIM_BOOT_CFG, F_UPCRST, 0);
9498 	for (ms = 0; ms < FW_CMD_MAX_TIMEOUT; ) {
9499 		if (!(t4_read_reg(adap, A_PCIE_FW) & F_PCIE_FW_HALT))
9500 			return FW_SUCCESS;
9501 		msleep(100);
9502 		ms += 100;
9503 	}
9504 
9505 	return -ETIMEDOUT;
9506 }
9507 
9508 /**
9509  *	t4_fw_upgrade - perform all of the steps necessary to upgrade FW
9510  *	@adap: the adapter
9511  *	@mbox: mailbox to use for the FW RESET command (if desired)
9512  *	@fw_data: the firmware image to write
9513  *	@size: image size
9514  *	@force: force upgrade even if firmware doesn't cooperate
9515  *
9516  *	Perform all of the steps necessary for upgrading an adapter's
9517  *	firmware image.  Normally this requires the cooperation of the
9518  *	existing firmware in order to halt all existing activities
9519  *	but if an invalid mailbox token is passed in we skip that step
9520  *	(though we'll still put the adapter microprocessor into RESET in
9521  *	that case).
9522  *
9523  *	On successful return the new firmware will have been loaded and
9524  *	the adapter will have been fully RESET losing all previous setup
9525  *	state.  On unsuccessful return the adapter may be completely hosed ...
9526  *	positive errno indicates that the adapter is ~probably~ intact, a
9527  *	negative errno indicates that things are looking bad ...
9528  */
t4_fw_upgrade(struct adapter * adap,unsigned int mbox,const u8 * fw_data,unsigned int size,int force)9529 int t4_fw_upgrade(struct adapter *adap, unsigned int mbox,
9530 		  const u8 *fw_data, unsigned int size, int force)
9531 {
9532 	const struct fw_hdr *fw_hdr = (const struct fw_hdr *)fw_data;
9533 	unsigned int bootstrap =
9534 	    be32_to_cpu(fw_hdr->magic) == FW_HDR_MAGIC_BOOTSTRAP;
9535 	int ret;
9536 
9537 	if (!t4_fw_matches_chip(adap, fw_hdr))
9538 		return -EINVAL;
9539 
9540 	if (!bootstrap) {
9541 		ret = t4_fw_halt(adap, mbox, force);
9542 		if (ret < 0 && !force)
9543 			return ret;
9544 	}
9545 
9546 	ret = t4_load_fw(adap, fw_data, size);
9547 	if (ret < 0 || bootstrap)
9548 		return ret;
9549 
9550 	return t4_fw_restart(adap, mbox);
9551 }
9552 
9553 /**
9554  *	t4_fw_initialize - ask FW to initialize the device
9555  *	@adap: the adapter
9556  *	@mbox: mailbox to use for the FW command
9557  *
9558  *	Issues a command to FW to partially initialize the device.  This
9559  *	performs initialization that generally doesn't depend on user input.
9560  */
t4_fw_initialize(struct adapter * adap,unsigned int mbox)9561 int t4_fw_initialize(struct adapter *adap, unsigned int mbox)
9562 {
9563 	struct fw_initialize_cmd c;
9564 
9565 	memset(&c, 0, sizeof(c));
9566 	INIT_CMD(c, INITIALIZE, WRITE);
9567 	return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
9568 }
9569 
9570 /**
9571  *	t4_query_params_rw - query FW or device parameters
9572  *	@adap: the adapter
9573  *	@mbox: mailbox to use for the FW command
9574  *	@pf: the PF
9575  *	@vf: the VF
9576  *	@nparams: the number of parameters
9577  *	@params: the parameter names
9578  *	@val: the parameter values
9579  *	@rw: Write and read flag
9580  *
9581  *	Reads the value of FW or device parameters.  Up to 7 parameters can be
9582  *	queried at once.
9583  */
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)9584 int t4_query_params_rw(struct adapter *adap, unsigned int mbox, unsigned int pf,
9585 		       unsigned int vf, unsigned int nparams, const u32 *params,
9586 		       u32 *val, int rw)
9587 {
9588 	int i, ret;
9589 	struct fw_params_cmd c;
9590 	__be32 *p = &c.param[0].mnem;
9591 
9592 	if (nparams > 7)
9593 		return -EINVAL;
9594 
9595 	memset(&c, 0, sizeof(c));
9596 	c.op_to_vfn = cpu_to_be32(V_FW_CMD_OP(FW_PARAMS_CMD) |
9597 				  F_FW_CMD_REQUEST | F_FW_CMD_READ |
9598 				  V_FW_PARAMS_CMD_PFN(pf) |
9599 				  V_FW_PARAMS_CMD_VFN(vf));
9600 	c.retval_len16 = cpu_to_be32(FW_LEN16(c));
9601 
9602 	for (i = 0; i < nparams; i++) {
9603 		*p++ = cpu_to_be32(*params++);
9604 		if (rw)
9605 			*p = cpu_to_be32(*(val + i));
9606 		p++;
9607 	}
9608 
9609 	ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
9610 
9611 	/*
9612 	 * We always copy back the results, even if there's an error.  We'll
9613 	 * get an error if any of the parameters was unknown to the Firmware,
9614 	 * but there will be results for the others ...  (Older Firmware
9615 	 * stopped at the first unknown parameter; newer Firmware processes
9616 	 * them all and flags the unknown parameters with a return value of
9617 	 * ~0UL.)
9618 	 */
9619 	for (i = 0, p = &c.param[0].val; i < nparams; i++, p += 2)
9620 		*val++ = be32_to_cpu(*p);
9621 
9622 	return ret;
9623 }
9624 
t4_query_params(struct adapter * adap,unsigned int mbox,unsigned int pf,unsigned int vf,unsigned int nparams,const u32 * params,u32 * val)9625 int t4_query_params(struct adapter *adap, unsigned int mbox, unsigned int pf,
9626 		    unsigned int vf, unsigned int nparams, const u32 *params,
9627 		    u32 *val)
9628 {
9629 	return t4_query_params_rw(adap, mbox, pf, vf, nparams, params, val, 0);
9630 }
9631 
9632 /**
9633  *      t4_set_params_timeout - sets FW or device parameters
9634  *      @adap: the adapter
9635  *      @mbox: mailbox to use for the FW command
9636  *      @pf: the PF
9637  *      @vf: the VF
9638  *      @nparams: the number of parameters
9639  *      @params: the parameter names
9640  *      @val: the parameter values
9641  *      @timeout: the timeout time
9642  *
9643  *      Sets the value of FW or device parameters.  Up to 7 parameters can be
9644  *      specified at once.
9645  */
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)9646 int t4_set_params_timeout(struct adapter *adap, unsigned int mbox,
9647 			  unsigned int pf, unsigned int vf,
9648 			  unsigned int nparams, const u32 *params,
9649 			  const u32 *val, int timeout)
9650 {
9651 	struct fw_params_cmd c;
9652 	__be32 *p = &c.param[0].mnem;
9653 
9654 	if (nparams > 7)
9655 		return -EINVAL;
9656 
9657 	memset(&c, 0, sizeof(c));
9658 	c.op_to_vfn = cpu_to_be32(V_FW_CMD_OP(FW_PARAMS_CMD) |
9659 				  F_FW_CMD_REQUEST | F_FW_CMD_WRITE |
9660 				  V_FW_PARAMS_CMD_PFN(pf) |
9661 				  V_FW_PARAMS_CMD_VFN(vf));
9662 	c.retval_len16 = cpu_to_be32(FW_LEN16(c));
9663 
9664 	while (nparams--) {
9665 		*p++ = cpu_to_be32(*params++);
9666 		*p++ = cpu_to_be32(*val++);
9667 	}
9668 
9669 	return t4_wr_mbox_timeout(adap, mbox, &c, sizeof(c), NULL, timeout);
9670 }
9671 
9672 /**
9673  *	t4_set_params - sets FW or device parameters
9674  *	@adap: the adapter
9675  *	@mbox: mailbox to use for the FW command
9676  *	@pf: the PF
9677  *	@vf: the VF
9678  *	@nparams: the number of parameters
9679  *	@params: the parameter names
9680  *	@val: the parameter values
9681  *
9682  *	Sets the value of FW or device parameters.  Up to 7 parameters can be
9683  *	specified at once.
9684  */
t4_set_params(struct adapter * adap,unsigned int mbox,unsigned int pf,unsigned int vf,unsigned int nparams,const u32 * params,const u32 * val)9685 int t4_set_params(struct adapter *adap, unsigned int mbox, unsigned int pf,
9686 		  unsigned int vf, unsigned int nparams, const u32 *params,
9687 		  const u32 *val)
9688 {
9689 	return t4_set_params_timeout(adap, mbox, pf, vf, nparams, params, val,
9690 				     FW_CMD_MAX_TIMEOUT);
9691 }
9692 
9693 /**
9694  *	t4_cfg_pfvf - configure PF/VF resource limits
9695  *	@adap: the adapter
9696  *	@mbox: mailbox to use for the FW command
9697  *	@pf: the PF being configured
9698  *	@vf: the VF being configured
9699  *	@txq: the max number of egress queues
9700  *	@txq_eth_ctrl: the max number of egress Ethernet or control queues
9701  *	@rxqi: the max number of interrupt-capable ingress queues
9702  *	@rxq: the max number of interruptless ingress queues
9703  *	@tc: the PCI traffic class
9704  *	@vi: the max number of virtual interfaces
9705  *	@cmask: the channel access rights mask for the PF/VF
9706  *	@pmask: the port access rights mask for the PF/VF
9707  *	@nexact: the maximum number of exact MPS filters
9708  *	@rcaps: read capabilities
9709  *	@wxcaps: write/execute capabilities
9710  *
9711  *	Configures resource limits and capabilities for a physical or virtual
9712  *	function.
9713  */
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)9714 int t4_cfg_pfvf(struct adapter *adap, unsigned int mbox, unsigned int pf,
9715 		unsigned int vf, unsigned int txq, unsigned int txq_eth_ctrl,
9716 		unsigned int rxqi, unsigned int rxq, unsigned int tc,
9717 		unsigned int vi, unsigned int cmask, unsigned int pmask,
9718 		unsigned int nexact, unsigned int rcaps, unsigned int wxcaps)
9719 {
9720 	struct fw_pfvf_cmd c;
9721 
9722 	memset(&c, 0, sizeof(c));
9723 	c.op_to_vfn = cpu_to_be32(V_FW_CMD_OP(FW_PFVF_CMD) | F_FW_CMD_REQUEST |
9724 				  F_FW_CMD_WRITE | V_FW_PFVF_CMD_PFN(pf) |
9725 				  V_FW_PFVF_CMD_VFN(vf));
9726 	c.retval_len16 = cpu_to_be32(FW_LEN16(c));
9727 	c.niqflint_niq = cpu_to_be32(V_FW_PFVF_CMD_NIQFLINT(rxqi) |
9728 				     V_FW_PFVF_CMD_NIQ(rxq));
9729 	c.type_to_neq = cpu_to_be32(V_FW_PFVF_CMD_CMASK(cmask) |
9730 				    V_FW_PFVF_CMD_PMASK(pmask) |
9731 				    V_FW_PFVF_CMD_NEQ(txq));
9732 	c.tc_to_nexactf = cpu_to_be32(V_FW_PFVF_CMD_TC(tc) |
9733 				      V_FW_PFVF_CMD_NVI(vi) |
9734 				      V_FW_PFVF_CMD_NEXACTF(nexact));
9735 	c.r_caps_to_nethctrl = cpu_to_be32(V_FW_PFVF_CMD_R_CAPS(rcaps) |
9736 				     V_FW_PFVF_CMD_WX_CAPS(wxcaps) |
9737 				     V_FW_PFVF_CMD_NETHCTRL(txq_eth_ctrl));
9738 	return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
9739 }
9740 
9741 /**
9742  *	t4_alloc_vi_func - allocate a virtual interface
9743  *	@adap: the adapter
9744  *	@mbox: mailbox to use for the FW command
9745  *	@port: physical port associated with the VI
9746  *	@pf: the PF owning the VI
9747  *	@vf: the VF owning the VI
9748  *	@nmac: number of MAC addresses needed (1 to 5)
9749  *	@mac: the MAC addresses of the VI
9750  *	@rss_size: size of RSS table slice associated with this VI
9751  *	@portfunc: which Port Application Function MAC Address is desired
9752  *	@idstype: Intrusion Detection Type
9753  *
9754  *	Allocates a virtual interface for the given physical port.  If @mac is
9755  *	not %NULL it contains the MAC addresses of the VI as assigned by FW.
9756  *	If @rss_size is %NULL the VI is not assigned any RSS slice by FW.
9757  *	@mac should be large enough to hold @nmac Ethernet addresses, they are
9758  *	stored consecutively so the space needed is @nmac * 6 bytes.
9759  *	Returns a negative error number or the non-negative VI id.
9760  */
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)9761 int t4_alloc_vi_func(struct adapter *adap, unsigned int mbox,
9762 		     unsigned int port, unsigned int pf, unsigned int vf,
9763 		     unsigned int nmac, u8 *mac, u16 *rss_size,
9764 		     uint8_t *vfvld, uint16_t *vin,
9765 		     unsigned int portfunc, unsigned int idstype)
9766 {
9767 	int ret;
9768 	struct fw_vi_cmd c;
9769 
9770 	memset(&c, 0, sizeof(c));
9771 	c.op_to_vfn = cpu_to_be32(V_FW_CMD_OP(FW_VI_CMD) | F_FW_CMD_REQUEST |
9772 				  F_FW_CMD_WRITE | F_FW_CMD_EXEC |
9773 				  V_FW_VI_CMD_PFN(pf) | V_FW_VI_CMD_VFN(vf));
9774 	c.alloc_to_len16 = cpu_to_be32(F_FW_VI_CMD_ALLOC | FW_LEN16(c));
9775 	c.type_to_viid = cpu_to_be16(V_FW_VI_CMD_TYPE(idstype) |
9776 				     V_FW_VI_CMD_FUNC(portfunc));
9777 	c.portid_pkd = V_FW_VI_CMD_PORTID(port);
9778 	c.nmac = nmac - 1;
9779 	if(!rss_size)
9780 		c.norss_rsssize = F_FW_VI_CMD_NORSS;
9781 
9782 	ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
9783 	if (ret)
9784 		return ret;
9785 	ret = G_FW_VI_CMD_VIID(be16_to_cpu(c.type_to_viid));
9786 
9787 	if (mac) {
9788 		memcpy(mac, c.mac, sizeof(c.mac));
9789 		switch (nmac) {
9790 		case 5:
9791 			memcpy(mac + 24, c.nmac3, sizeof(c.nmac3));
9792 		case 4:
9793 			memcpy(mac + 18, c.nmac2, sizeof(c.nmac2));
9794 		case 3:
9795 			memcpy(mac + 12, c.nmac1, sizeof(c.nmac1));
9796 		case 2:
9797 			memcpy(mac + 6,  c.nmac0, sizeof(c.nmac0));
9798 		}
9799 	}
9800 	if (rss_size)
9801 		*rss_size = G_FW_VI_CMD_RSSSIZE(be16_to_cpu(c.norss_rsssize));
9802 	if (vfvld) {
9803 		*vfvld = adap->params.viid_smt_extn_support ?
9804 		    G_FW_VI_CMD_VFVLD(be32_to_cpu(c.alloc_to_len16)) :
9805 		    G_FW_VIID_VIVLD(ret);
9806 	}
9807 	if (vin) {
9808 		*vin = adap->params.viid_smt_extn_support ?
9809 		    G_FW_VI_CMD_VIN(be32_to_cpu(c.alloc_to_len16)) :
9810 		    G_FW_VIID_VIN(ret);
9811 	}
9812 
9813 	return ret;
9814 }
9815 
9816 /**
9817  *      t4_alloc_vi - allocate an [Ethernet Function] virtual interface
9818  *      @adap: the adapter
9819  *      @mbox: mailbox to use for the FW command
9820  *      @port: physical port associated with the VI
9821  *      @pf: the PF owning the VI
9822  *      @vf: the VF owning the VI
9823  *      @nmac: number of MAC addresses needed (1 to 5)
9824  *      @mac: the MAC addresses of the VI
9825  *      @rss_size: size of RSS table slice associated with this VI
9826  *
9827  *	backwards compatible and convieniance routine to allocate a Virtual
9828  *	Interface with a Ethernet Port Application Function and Intrustion
9829  *	Detection System disabled.
9830  */
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)9831 int t4_alloc_vi(struct adapter *adap, unsigned int mbox, unsigned int port,
9832 		unsigned int pf, unsigned int vf, unsigned int nmac, u8 *mac,
9833 		u16 *rss_size, uint8_t *vfvld, uint16_t *vin)
9834 {
9835 	return t4_alloc_vi_func(adap, mbox, port, pf, vf, nmac, mac, rss_size,
9836 				vfvld, vin, FW_VI_FUNC_ETH, 0);
9837 }
9838 
9839 /**
9840  * 	t4_free_vi - free a virtual interface
9841  * 	@adap: the adapter
9842  * 	@mbox: mailbox to use for the FW command
9843  * 	@pf: the PF owning the VI
9844  * 	@vf: the VF owning the VI
9845  * 	@viid: virtual interface identifiler
9846  *
9847  * 	Free a previously allocated virtual interface.
9848  */
t4_free_vi(struct adapter * adap,unsigned int mbox,unsigned int pf,unsigned int vf,unsigned int viid)9849 int t4_free_vi(struct adapter *adap, unsigned int mbox, unsigned int pf,
9850 	       unsigned int vf, unsigned int viid)
9851 {
9852 	struct fw_vi_cmd c;
9853 
9854 	memset(&c, 0, sizeof(c));
9855 	c.op_to_vfn = cpu_to_be32(V_FW_CMD_OP(FW_VI_CMD) |
9856 				  F_FW_CMD_REQUEST |
9857 				  F_FW_CMD_EXEC |
9858 				  V_FW_VI_CMD_PFN(pf) |
9859 				  V_FW_VI_CMD_VFN(vf));
9860 	c.alloc_to_len16 = cpu_to_be32(F_FW_VI_CMD_FREE | FW_LEN16(c));
9861 	c.type_to_viid = cpu_to_be16(V_FW_VI_CMD_VIID(viid));
9862 
9863 	return t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
9864 }
9865 
9866 /**
9867  *	t4_set_rxmode - set Rx properties of a virtual interface
9868  *	@adap: the adapter
9869  *	@mbox: mailbox to use for the FW command
9870  *	@viid: the VI id
9871  *	@mtu: the new MTU or -1
9872  *	@promisc: 1 to enable promiscuous mode, 0 to disable it, -1 no change
9873  *	@all_multi: 1 to enable all-multi mode, 0 to disable it, -1 no change
9874  *	@bcast: 1 to enable broadcast Rx, 0 to disable it, -1 no change
9875  *	@vlanex: 1 to enable HW VLAN extraction, 0 to disable it, -1 no change
9876  *	@sleep_ok: if true we may sleep while awaiting command completion
9877  *
9878  *	Sets Rx properties of a virtual interface.
9879  */
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)9880 int t4_set_rxmode(struct adapter *adap, unsigned int mbox, unsigned int viid,
9881 		  int mtu, int promisc, int all_multi, int bcast, int vlanex,
9882 		  bool sleep_ok)
9883 {
9884 	struct fw_vi_rxmode_cmd c;
9885 
9886 	/* convert to FW values */
9887 	if (mtu < 0)
9888 		mtu = M_FW_VI_RXMODE_CMD_MTU;
9889 	if (promisc < 0)
9890 		promisc = M_FW_VI_RXMODE_CMD_PROMISCEN;
9891 	if (all_multi < 0)
9892 		all_multi = M_FW_VI_RXMODE_CMD_ALLMULTIEN;
9893 	if (bcast < 0)
9894 		bcast = M_FW_VI_RXMODE_CMD_BROADCASTEN;
9895 	if (vlanex < 0)
9896 		vlanex = M_FW_VI_RXMODE_CMD_VLANEXEN;
9897 
9898 	memset(&c, 0, sizeof(c));
9899 	c.op_to_viid = cpu_to_be32(V_FW_CMD_OP(FW_VI_RXMODE_CMD) |
9900 				   F_FW_CMD_REQUEST | F_FW_CMD_WRITE |
9901 				   V_FW_VI_RXMODE_CMD_VIID(viid));
9902 	c.retval_len16 = cpu_to_be32(FW_LEN16(c));
9903 	c.mtu_to_vlanexen =
9904 		cpu_to_be32(V_FW_VI_RXMODE_CMD_MTU(mtu) |
9905 			    V_FW_VI_RXMODE_CMD_PROMISCEN(promisc) |
9906 			    V_FW_VI_RXMODE_CMD_ALLMULTIEN(all_multi) |
9907 			    V_FW_VI_RXMODE_CMD_BROADCASTEN(bcast) |
9908 			    V_FW_VI_RXMODE_CMD_VLANEXEN(vlanex));
9909 	return t4_wr_mbox_meat(adap, mbox, &c, sizeof(c), NULL, sleep_ok);
9910 }
9911 
9912 /**
9913  *	t4_alloc_encap_mac_filt - Adds a mac entry in mps tcam with VNI support
9914  *	@adap: the adapter
9915  *	@viid: the VI id
9916  *	@mac: the MAC address
9917  *	@mask: the mask
9918  *	@vni: the VNI id for the tunnel protocol
9919  *	@vni_mask: mask for the VNI id
9920  *	@dip_hit: to enable DIP match for the MPS entry
9921  *	@lookup_type: MAC address for inner (1) or outer (0) header
9922  *	@sleep_ok: call is allowed to sleep
9923  *
9924  *	Allocates an MPS entry with specified MAC address and VNI value.
9925  *
9926  *	Returns a negative error number or the allocated index for this mac.
9927  */
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)9928 int t4_alloc_encap_mac_filt(struct adapter *adap, unsigned int viid,
9929 			    const u8 *addr, const u8 *mask, unsigned int vni,
9930 			    unsigned int vni_mask, u8 dip_hit, u8 lookup_type,
9931 			    bool sleep_ok)
9932 {
9933 	struct fw_vi_mac_cmd c;
9934 	struct fw_vi_mac_vni *p = c.u.exact_vni;
9935 	int ret = 0;
9936 	u32 val;
9937 
9938 	memset(&c, 0, sizeof(c));
9939 	c.op_to_viid = cpu_to_be32(V_FW_CMD_OP(FW_VI_MAC_CMD) |
9940 				   F_FW_CMD_REQUEST | F_FW_CMD_WRITE |
9941 				   V_FW_VI_MAC_CMD_VIID(viid));
9942 	val = V_FW_CMD_LEN16(1) |
9943 	      V_FW_VI_MAC_CMD_ENTRY_TYPE(FW_VI_MAC_TYPE_EXACTMAC_VNI);
9944 	c.freemacs_to_len16 = cpu_to_be32(val);
9945 	p->valid_to_idx = cpu_to_be16(F_FW_VI_MAC_CMD_VALID |
9946 				      V_FW_VI_MAC_CMD_IDX(FW_VI_MAC_ADD_MAC));
9947 	memcpy(p->macaddr, addr, sizeof(p->macaddr));
9948 	memcpy(p->macaddr_mask, mask, sizeof(p->macaddr_mask));
9949 
9950 	p->lookup_type_to_vni = cpu_to_be32(V_FW_VI_MAC_CMD_VNI(vni) |
9951 					    V_FW_VI_MAC_CMD_DIP_HIT(dip_hit) |
9952 					    V_FW_VI_MAC_CMD_LOOKUP_TYPE(lookup_type));
9953 	p->vni_mask_pkd = cpu_to_be32(V_FW_VI_MAC_CMD_VNI_MASK(vni_mask));
9954 
9955 	ret = t4_wr_mbox_meat(adap, adap->mbox, &c, sizeof(c), &c, sleep_ok);
9956 	if (ret == 0)
9957 		ret = G_FW_VI_MAC_CMD_IDX(be16_to_cpu(p->valid_to_idx));
9958 	return ret;
9959 }
9960 
9961 /**
9962  *	t4_alloc_raw_mac_filt - Adds a mac entry in mps tcam
9963  *	@adap: the adapter
9964  *	@viid: the VI id
9965  *	@mac: the MAC address
9966  *	@mask: the mask
9967  *	@idx: index at which to add this entry
9968  *	@port_id: the port index
9969  *	@lookup_type: MAC address for inner (1) or outer (0) header
9970  *	@sleep_ok: call is allowed to sleep
9971  *
9972  *	Adds the mac entry at the specified index using raw mac interface.
9973  *
9974  *	Returns a negative error number or the allocated index for this mac.
9975  */
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)9976 int t4_alloc_raw_mac_filt(struct adapter *adap, unsigned int viid,
9977 			  const u8 *addr, const u8 *mask, unsigned int idx,
9978 			  u8 lookup_type, u8 port_id, bool sleep_ok)
9979 {
9980 	int ret = 0;
9981 	struct fw_vi_mac_cmd c;
9982 	struct fw_vi_mac_raw *p = &c.u.raw;
9983 	u32 val;
9984 
9985 	memset(&c, 0, sizeof(c));
9986 	c.op_to_viid = cpu_to_be32(V_FW_CMD_OP(FW_VI_MAC_CMD) |
9987 				   F_FW_CMD_REQUEST | F_FW_CMD_WRITE |
9988 				   V_FW_VI_MAC_CMD_VIID(viid));
9989 	val = V_FW_CMD_LEN16(1) |
9990 	      V_FW_VI_MAC_CMD_ENTRY_TYPE(FW_VI_MAC_TYPE_RAW);
9991 	c.freemacs_to_len16 = cpu_to_be32(val);
9992 
9993 	/* Specify that this is an inner mac address */
9994 	p->raw_idx_pkd = cpu_to_be32(V_FW_VI_MAC_CMD_RAW_IDX(idx));
9995 
9996 	/* Lookup Type. Outer header: 0, Inner header: 1 */
9997 	p->data0_pkd = cpu_to_be32(V_DATALKPTYPE(lookup_type) |
9998 				   V_DATAPORTNUM(port_id));
9999 	/* Lookup mask and port mask */
10000 	p->data0m_pkd = cpu_to_be64(V_DATALKPTYPE(M_DATALKPTYPE) |
10001 				    V_DATAPORTNUM(M_DATAPORTNUM));
10002 
10003 	/* Copy the address and the mask */
10004 	memcpy((u8 *)&p->data1[0] + 2, addr, ETHER_ADDR_LEN);
10005 	memcpy((u8 *)&p->data1m[0] + 2, mask, ETHER_ADDR_LEN);
10006 
10007 	ret = t4_wr_mbox_meat(adap, adap->mbox, &c, sizeof(c), &c, sleep_ok);
10008 	if (ret == 0) {
10009 		ret = G_FW_VI_MAC_CMD_RAW_IDX(be32_to_cpu(p->raw_idx_pkd));
10010 		if (ret != idx)
10011 			ret = -ENOMEM;
10012 	}
10013 
10014 	return ret;
10015 }
10016 
10017 /**
10018  *	t4_alloc_mac_filt - allocates exact-match filters for MAC addresses
10019  *	@adap: the adapter
10020  *	@mbox: mailbox to use for the FW command
10021  *	@viid: the VI id
10022  *	@free: if true any existing filters for this VI id are first removed
10023  *	@naddr: the number of MAC addresses to allocate filters for (up to 7)
10024  *	@addr: the MAC address(es)
10025  *	@idx: where to store the index of each allocated filter
10026  *	@hash: pointer to hash address filter bitmap
10027  *	@sleep_ok: call is allowed to sleep
10028  *
10029  *	Allocates an exact-match filter for each of the supplied addresses and
10030  *	sets it to the corresponding address.  If @idx is not %NULL it should
10031  *	have at least @naddr entries, each of which will be set to the index of
10032  *	the filter allocated for the corresponding MAC address.  If a filter
10033  *	could not be allocated for an address its index is set to 0xffff.
10034  *	If @hash is not %NULL addresses that fail to allocate an exact filter
10035  *	are hashed and update the hash filter bitmap pointed at by @hash.
10036  *
10037  *	Returns a negative error number or the number of filters allocated.
10038  */
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)10039 int t4_alloc_mac_filt(struct adapter *adap, unsigned int mbox,
10040 		      unsigned int viid, bool free, unsigned int naddr,
10041 		      const u8 **addr, u16 *idx, u64 *hash, bool sleep_ok)
10042 {
10043 	int offset, ret = 0;
10044 	struct fw_vi_mac_cmd c;
10045 	unsigned int nfilters = 0;
10046 	unsigned int max_naddr = adap->chip_params->mps_tcam_size;
10047 	unsigned int rem = naddr;
10048 
10049 	if (naddr > max_naddr)
10050 		return -EINVAL;
10051 
10052 	for (offset = 0; offset < naddr ; /**/) {
10053 		unsigned int fw_naddr = (rem < ARRAY_SIZE(c.u.exact)
10054 					 ? rem
10055 					 : ARRAY_SIZE(c.u.exact));
10056 		size_t len16 = DIV_ROUND_UP(offsetof(struct fw_vi_mac_cmd,
10057 						     u.exact[fw_naddr]), 16);
10058 		struct fw_vi_mac_exact *p;
10059 		int i;
10060 
10061 		memset(&c, 0, sizeof(c));
10062 		c.op_to_viid = cpu_to_be32(V_FW_CMD_OP(FW_VI_MAC_CMD) |
10063 					   F_FW_CMD_REQUEST |
10064 					   F_FW_CMD_WRITE |
10065 					   V_FW_CMD_EXEC(free) |
10066 					   V_FW_VI_MAC_CMD_VIID(viid));
10067 		c.freemacs_to_len16 = cpu_to_be32(V_FW_VI_MAC_CMD_FREEMACS(free) |
10068 						  V_FW_CMD_LEN16(len16));
10069 
10070 		for (i = 0, p = c.u.exact; i < fw_naddr; i++, p++) {
10071 			p->valid_to_idx =
10072 				cpu_to_be16(F_FW_VI_MAC_CMD_VALID |
10073 					    V_FW_VI_MAC_CMD_IDX(FW_VI_MAC_ADD_MAC));
10074 			memcpy(p->macaddr, addr[offset+i], sizeof(p->macaddr));
10075 		}
10076 
10077 		/*
10078 		 * It's okay if we run out of space in our MAC address arena.
10079 		 * Some of the addresses we submit may get stored so we need
10080 		 * to run through the reply to see what the results were ...
10081 		 */
10082 		ret = t4_wr_mbox_meat(adap, mbox, &c, sizeof(c), &c, sleep_ok);
10083 		if (ret && ret != -FW_ENOMEM)
10084 			break;
10085 
10086 		for (i = 0, p = c.u.exact; i < fw_naddr; i++, p++) {
10087 			u16 index = G_FW_VI_MAC_CMD_IDX(
10088 						be16_to_cpu(p->valid_to_idx));
10089 
10090 			if (idx)
10091 				idx[offset+i] = (index >=  max_naddr
10092 						 ? 0xffff
10093 						 : index);
10094 			if (index < max_naddr)
10095 				nfilters++;
10096 			else if (hash)
10097 				*hash |= (1ULL << hash_mac_addr(addr[offset+i]));
10098 		}
10099 
10100 		free = false;
10101 		offset += fw_naddr;
10102 		rem -= fw_naddr;
10103 	}
10104 
10105 	if (ret == 0 || ret == -FW_ENOMEM)
10106 		ret = nfilters;
10107 	return ret;
10108 }
10109 
10110 /**
10111  *	t4_free_encap_mac_filt - frees MPS entry at given index
10112  *	@adap: the adapter
10113  *	@viid: the VI id
10114  *	@idx: index of MPS entry to be freed
10115  *	@sleep_ok: call is allowed to sleep
10116  *
10117  *	Frees the MPS entry at supplied index
10118  *
10119  *	Returns a negative error number or zero on success
10120  */
t4_free_encap_mac_filt(struct adapter * adap,unsigned int viid,int idx,bool sleep_ok)10121 int t4_free_encap_mac_filt(struct adapter *adap, unsigned int viid,
10122 			   int idx, bool sleep_ok)
10123 {
10124 	struct fw_vi_mac_exact *p;
10125 	struct fw_vi_mac_cmd c;
10126 	u8 addr[] = {0,0,0,0,0,0};
10127 	int ret = 0;
10128 	u32 exact;
10129 
10130 	memset(&c, 0, sizeof(c));
10131 	c.op_to_viid = cpu_to_be32(V_FW_CMD_OP(FW_VI_MAC_CMD) |
10132 				   F_FW_CMD_REQUEST |
10133 				   F_FW_CMD_WRITE |
10134 				   V_FW_CMD_EXEC(0) |
10135 				   V_FW_VI_MAC_CMD_VIID(viid));
10136 	exact = V_FW_VI_MAC_CMD_ENTRY_TYPE(FW_VI_MAC_TYPE_EXACTMAC);
10137 	c.freemacs_to_len16 = cpu_to_be32(V_FW_VI_MAC_CMD_FREEMACS(0) |
10138 					  exact |
10139 					  V_FW_CMD_LEN16(1));
10140 	p = c.u.exact;
10141 	p->valid_to_idx = cpu_to_be16(F_FW_VI_MAC_CMD_VALID |
10142 				      V_FW_VI_MAC_CMD_IDX(idx));
10143 	memcpy(p->macaddr, addr, sizeof(p->macaddr));
10144 
10145 	ret = t4_wr_mbox_meat(adap, adap->mbox, &c, sizeof(c), &c, sleep_ok);
10146 	return ret;
10147 }
10148 
10149 /**
10150  *	t4_free_raw_mac_filt - Frees a raw mac entry in mps tcam
10151  *	@adap: the adapter
10152  *	@viid: the VI id
10153  *	@addr: the MAC address
10154  *	@mask: the mask
10155  *	@idx: index of the entry in mps tcam
10156  *	@lookup_type: MAC address for inner (1) or outer (0) header
10157  *	@port_id: the port index
10158  *	@sleep_ok: call is allowed to sleep
10159  *
10160  *	Removes the mac entry at the specified index using raw mac interface.
10161  *
10162  *	Returns a negative error number on failure.
10163  */
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)10164 int t4_free_raw_mac_filt(struct adapter *adap, unsigned int viid,
10165 			 const u8 *addr, const u8 *mask, unsigned int idx,
10166 			 u8 lookup_type, u8 port_id, bool sleep_ok)
10167 {
10168 	struct fw_vi_mac_cmd c;
10169 	struct fw_vi_mac_raw *p = &c.u.raw;
10170 	u32 raw;
10171 
10172 	memset(&c, 0, sizeof(c));
10173 	c.op_to_viid = cpu_to_be32(V_FW_CMD_OP(FW_VI_MAC_CMD) |
10174 				   F_FW_CMD_REQUEST | F_FW_CMD_WRITE |
10175 				   V_FW_CMD_EXEC(0) |
10176 				   V_FW_VI_MAC_CMD_VIID(viid));
10177 	raw = V_FW_VI_MAC_CMD_ENTRY_TYPE(FW_VI_MAC_TYPE_RAW);
10178 	c.freemacs_to_len16 = cpu_to_be32(V_FW_VI_MAC_CMD_FREEMACS(0) |
10179 					  raw |
10180 					  V_FW_CMD_LEN16(1));
10181 
10182 	p->raw_idx_pkd = cpu_to_be32(V_FW_VI_MAC_CMD_RAW_IDX(idx) |
10183 				     FW_VI_MAC_ID_BASED_FREE);
10184 
10185 	/* Lookup Type. Outer header: 0, Inner header: 1 */
10186 	p->data0_pkd = cpu_to_be32(V_DATALKPTYPE(lookup_type) |
10187 				   V_DATAPORTNUM(port_id));
10188 	/* Lookup mask and port mask */
10189 	p->data0m_pkd = cpu_to_be64(V_DATALKPTYPE(M_DATALKPTYPE) |
10190 				    V_DATAPORTNUM(M_DATAPORTNUM));
10191 
10192 	/* Copy the address and the mask */
10193 	memcpy((u8 *)&p->data1[0] + 2, addr, ETHER_ADDR_LEN);
10194 	memcpy((u8 *)&p->data1m[0] + 2, mask, ETHER_ADDR_LEN);
10195 
10196 	return t4_wr_mbox_meat(adap, adap->mbox, &c, sizeof(c), &c, sleep_ok);
10197 }
10198 
10199 /**
10200  *	t4_free_mac_filt - frees exact-match filters of given MAC addresses
10201  *	@adap: the adapter
10202  *	@mbox: mailbox to use for the FW command
10203  *	@viid: the VI id
10204  *	@naddr: the number of MAC addresses to allocate filters for (up to 7)
10205  *	@addr: the MAC address(es)
10206  *	@sleep_ok: call is allowed to sleep
10207  *
10208  *	Frees the exact-match filter for each of the supplied addresses
10209  *
10210  *	Returns a negative error number or the number of filters freed.
10211  */
t4_free_mac_filt(struct adapter * adap,unsigned int mbox,unsigned int viid,unsigned int naddr,const u8 ** addr,bool sleep_ok)10212 int t4_free_mac_filt(struct adapter *adap, unsigned int mbox,
10213 		      unsigned int viid, unsigned int naddr,
10214 		      const u8 **addr, bool sleep_ok)
10215 {
10216 	int offset, ret = 0;
10217 	struct fw_vi_mac_cmd c;
10218 	unsigned int nfilters = 0;
10219 	unsigned int max_naddr = adap->chip_params->mps_tcam_size;
10220 	unsigned int rem = naddr;
10221 
10222 	if (naddr > max_naddr)
10223 		return -EINVAL;
10224 
10225 	for (offset = 0; offset < (int)naddr ; /**/) {
10226 		unsigned int fw_naddr = (rem < ARRAY_SIZE(c.u.exact)
10227 					 ? rem
10228 					 : ARRAY_SIZE(c.u.exact));
10229 		size_t len16 = DIV_ROUND_UP(offsetof(struct fw_vi_mac_cmd,
10230 						     u.exact[fw_naddr]), 16);
10231 		struct fw_vi_mac_exact *p;
10232 		int i;
10233 
10234 		memset(&c, 0, sizeof(c));
10235 		c.op_to_viid = cpu_to_be32(V_FW_CMD_OP(FW_VI_MAC_CMD) |
10236 				     F_FW_CMD_REQUEST |
10237 				     F_FW_CMD_WRITE |
10238 				     V_FW_CMD_EXEC(0) |
10239 				     V_FW_VI_MAC_CMD_VIID(viid));
10240 		c.freemacs_to_len16 =
10241 				cpu_to_be32(V_FW_VI_MAC_CMD_FREEMACS(0) |
10242 					    V_FW_CMD_LEN16(len16));
10243 
10244 		for (i = 0, p = c.u.exact; i < (int)fw_naddr; i++, p++) {
10245 			p->valid_to_idx = cpu_to_be16(
10246 				F_FW_VI_MAC_CMD_VALID |
10247 				V_FW_VI_MAC_CMD_IDX(FW_VI_MAC_MAC_BASED_FREE));
10248 			memcpy(p->macaddr, addr[offset+i], sizeof(p->macaddr));
10249 		}
10250 
10251 		ret = t4_wr_mbox_meat(adap, mbox, &c, sizeof(c), &c, sleep_ok);
10252 		if (ret)
10253 			break;
10254 
10255 		for (i = 0, p = c.u.exact; i < fw_naddr; i++, p++) {
10256 			u16 index = G_FW_VI_MAC_CMD_IDX(
10257 						be16_to_cpu(p->valid_to_idx));
10258 
10259 			if (index < max_naddr)
10260 				nfilters++;
10261 		}
10262 
10263 		offset += fw_naddr;
10264 		rem -= fw_naddr;
10265 	}
10266 
10267 	if (ret == 0)
10268 		ret = nfilters;
10269 	return ret;
10270 }
10271 
10272 /**
10273  *	t4_change_mac - modifies the exact-match filter for a MAC address
10274  *	@adap: the adapter
10275  *	@mbox: mailbox to use for the FW command
10276  *	@viid: the VI id
10277  *	@idx: index of existing filter for old value of MAC address, or -1
10278  *	@addr: the new MAC address value
10279  *	@persist: whether a new MAC allocation should be persistent
10280  *	@smt_idx: add MAC to SMT and return its index, or NULL
10281  *
10282  *	Modifies an exact-match filter and sets it to the new MAC address if
10283  *	@idx >= 0, or adds the MAC address to a new filter if @idx < 0.  In the
10284  *	latter case the address is added persistently if @persist is %true.
10285  *
10286  *	Note that in general it is not possible to modify the value of a given
10287  *	filter so the generic way to modify an address filter is to free the one
10288  *	being used by the old address value and allocate a new filter for the
10289  *	new address value.
10290  *
10291  *	Returns a negative error number or the index of the filter with the new
10292  *	MAC value.  Note that this index may differ from @idx.
10293  */
t4_change_mac(struct adapter * adap,unsigned int mbox,unsigned int viid,int idx,const u8 * addr,bool persist,uint16_t * smt_idx)10294 int t4_change_mac(struct adapter *adap, unsigned int mbox, unsigned int viid,
10295 		  int idx, const u8 *addr, bool persist, uint16_t *smt_idx)
10296 {
10297 	int ret, mode;
10298 	struct fw_vi_mac_cmd c;
10299 	struct fw_vi_mac_exact *p = c.u.exact;
10300 	unsigned int max_mac_addr = adap->chip_params->mps_tcam_size;
10301 
10302 	if (idx < 0)		/* new allocation */
10303 		idx = persist ? FW_VI_MAC_ADD_PERSIST_MAC : FW_VI_MAC_ADD_MAC;
10304 	mode = smt_idx ? FW_VI_MAC_SMT_AND_MPSTCAM : FW_VI_MAC_MPS_TCAM_ENTRY;
10305 
10306 	memset(&c, 0, sizeof(c));
10307 	c.op_to_viid = cpu_to_be32(V_FW_CMD_OP(FW_VI_MAC_CMD) |
10308 				   F_FW_CMD_REQUEST | F_FW_CMD_WRITE |
10309 				   V_FW_VI_MAC_CMD_VIID(viid));
10310 	c.freemacs_to_len16 = cpu_to_be32(V_FW_CMD_LEN16(1));
10311 	p->valid_to_idx = cpu_to_be16(F_FW_VI_MAC_CMD_VALID |
10312 				      V_FW_VI_MAC_CMD_SMAC_RESULT(mode) |
10313 				      V_FW_VI_MAC_CMD_IDX(idx));
10314 	memcpy(p->macaddr, addr, sizeof(p->macaddr));
10315 
10316 	ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
10317 	if (ret == 0) {
10318 		ret = G_FW_VI_MAC_CMD_IDX(be16_to_cpu(p->valid_to_idx));
10319 		if (ret >= max_mac_addr)
10320 			ret = -ENOMEM;
10321 		if (smt_idx) {
10322 			if (adap->params.viid_smt_extn_support)
10323 				*smt_idx = G_FW_VI_MAC_CMD_SMTID(be32_to_cpu(c.op_to_viid));
10324 			else {
10325 				if (chip_id(adap) <= CHELSIO_T5)
10326 					*smt_idx = (viid & M_FW_VIID_VIN) << 1;
10327 				else
10328 					*smt_idx = viid & M_FW_VIID_VIN;
10329 			}
10330 		}
10331 	}
10332 	return ret;
10333 }
10334 
10335 /**
10336  *	t4_set_addr_hash - program the MAC inexact-match hash filter
10337  *	@adap: the adapter
10338  *	@mbox: mailbox to use for the FW command
10339  *	@viid: the VI id
10340  *	@ucast: whether the hash filter should also match unicast addresses
10341  *	@vec: the value to be written to the hash filter
10342  *	@sleep_ok: call is allowed to sleep
10343  *
10344  *	Sets the 64-bit inexact-match hash filter for a virtual interface.
10345  */
t4_set_addr_hash(struct adapter * adap,unsigned int mbox,unsigned int viid,bool ucast,u64 vec,bool sleep_ok)10346 int t4_set_addr_hash(struct adapter *adap, unsigned int mbox, unsigned int viid,
10347 		     bool ucast, u64 vec, bool sleep_ok)
10348 {
10349 	struct fw_vi_mac_cmd c;
10350 	u32 val;
10351 
10352 	memset(&c, 0, sizeof(c));
10353 	c.op_to_viid = cpu_to_be32(V_FW_CMD_OP(FW_VI_MAC_CMD) |
10354 				   F_FW_CMD_REQUEST | F_FW_CMD_WRITE |
10355 				   V_FW_VI_ENABLE_CMD_VIID(viid));
10356 	val = V_FW_VI_MAC_CMD_ENTRY_TYPE(FW_VI_MAC_TYPE_HASHVEC) |
10357 	      V_FW_VI_MAC_CMD_HASHUNIEN(ucast) | V_FW_CMD_LEN16(1);
10358 	c.freemacs_to_len16 = cpu_to_be32(val);
10359 	c.u.hash.hashvec = cpu_to_be64(vec);
10360 	return t4_wr_mbox_meat(adap, mbox, &c, sizeof(c), NULL, sleep_ok);
10361 }
10362 
10363 /**
10364  *      t4_enable_vi_params - enable/disable a virtual interface
10365  *      @adap: the adapter
10366  *      @mbox: mailbox to use for the FW command
10367  *      @viid: the VI id
10368  *      @rx_en: 1=enable Rx, 0=disable Rx
10369  *      @tx_en: 1=enable Tx, 0=disable Tx
10370  *      @dcb_en: 1=enable delivery of Data Center Bridging messages.
10371  *
10372  *      Enables/disables a virtual interface.  Note that setting DCB Enable
10373  *      only makes sense when enabling a Virtual Interface ...
10374  */
t4_enable_vi_params(struct adapter * adap,unsigned int mbox,unsigned int viid,bool rx_en,bool tx_en,bool dcb_en)10375 int t4_enable_vi_params(struct adapter *adap, unsigned int mbox,
10376 			unsigned int viid, bool rx_en, bool tx_en, bool dcb_en)
10377 {
10378 	struct fw_vi_enable_cmd c;
10379 
10380 	memset(&c, 0, sizeof(c));
10381 	c.op_to_viid = cpu_to_be32(V_FW_CMD_OP(FW_VI_ENABLE_CMD) |
10382 				   F_FW_CMD_REQUEST | F_FW_CMD_EXEC |
10383 				   V_FW_VI_ENABLE_CMD_VIID(viid));
10384 	c.ien_to_len16 = cpu_to_be32(V_FW_VI_ENABLE_CMD_IEN(rx_en) |
10385 				     V_FW_VI_ENABLE_CMD_EEN(tx_en) |
10386 				     V_FW_VI_ENABLE_CMD_DCB_INFO(dcb_en) |
10387 				     FW_LEN16(c));
10388 	return t4_wr_mbox_ns(adap, mbox, &c, sizeof(c), NULL);
10389 }
10390 
10391 /**
10392  *	t4_enable_vi - enable/disable a virtual interface
10393  *	@adap: the adapter
10394  *	@mbox: mailbox to use for the FW command
10395  *	@viid: the VI id
10396  *	@rx_en: 1=enable Rx, 0=disable Rx
10397  *	@tx_en: 1=enable Tx, 0=disable Tx
10398  *
10399  *	Enables/disables a virtual interface.  Note that setting DCB Enable
10400  *	only makes sense when enabling a Virtual Interface ...
10401  */
t4_enable_vi(struct adapter * adap,unsigned int mbox,unsigned int viid,bool rx_en,bool tx_en)10402 int t4_enable_vi(struct adapter *adap, unsigned int mbox, unsigned int viid,
10403 		 bool rx_en, bool tx_en)
10404 {
10405 	return t4_enable_vi_params(adap, mbox, viid, rx_en, tx_en, 0);
10406 }
10407 
10408 /**
10409  *	t4_identify_port - identify a VI's port by blinking its LED
10410  *	@adap: the adapter
10411  *	@mbox: mailbox to use for the FW command
10412  *	@viid: the VI id
10413  *	@nblinks: how many times to blink LED at 2.5 Hz
10414  *
10415  *	Identifies a VI's port by blinking its LED.
10416  */
t4_identify_port(struct adapter * adap,unsigned int mbox,unsigned int viid,unsigned int nblinks)10417 int t4_identify_port(struct adapter *adap, unsigned int mbox, unsigned int viid,
10418 		     unsigned int nblinks)
10419 {
10420 	struct fw_vi_enable_cmd c;
10421 
10422 	memset(&c, 0, sizeof(c));
10423 	c.op_to_viid = cpu_to_be32(V_FW_CMD_OP(FW_VI_ENABLE_CMD) |
10424 				   F_FW_CMD_REQUEST | F_FW_CMD_EXEC |
10425 				   V_FW_VI_ENABLE_CMD_VIID(viid));
10426 	c.ien_to_len16 = cpu_to_be32(F_FW_VI_ENABLE_CMD_LED | FW_LEN16(c));
10427 	c.blinkdur = cpu_to_be16(nblinks);
10428 	return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
10429 }
10430 
10431 /**
10432  *	t4_iq_stop - stop an ingress queue and its FLs
10433  *	@adap: the adapter
10434  *	@mbox: mailbox to use for the FW command
10435  *	@pf: the PF owning the queues
10436  *	@vf: the VF owning the queues
10437  *	@iqtype: the ingress queue type (FW_IQ_TYPE_FL_INT_CAP, etc.)
10438  *	@iqid: ingress queue id
10439  *	@fl0id: FL0 queue id or 0xffff if no attached FL0
10440  *	@fl1id: FL1 queue id or 0xffff if no attached FL1
10441  *
10442  *	Stops an ingress queue and its associated FLs, if any.  This causes
10443  *	any current or future data/messages destined for these queues to be
10444  *	tossed.
10445  */
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)10446 int t4_iq_stop(struct adapter *adap, unsigned int mbox, unsigned int pf,
10447 	       unsigned int vf, unsigned int iqtype, unsigned int iqid,
10448 	       unsigned int fl0id, unsigned int fl1id)
10449 {
10450 	struct fw_iq_cmd c;
10451 
10452 	memset(&c, 0, sizeof(c));
10453 	c.op_to_vfn = cpu_to_be32(V_FW_CMD_OP(FW_IQ_CMD) | F_FW_CMD_REQUEST |
10454 				  F_FW_CMD_EXEC | V_FW_IQ_CMD_PFN(pf) |
10455 				  V_FW_IQ_CMD_VFN(vf));
10456 	c.alloc_to_len16 = cpu_to_be32(F_FW_IQ_CMD_IQSTOP | FW_LEN16(c));
10457 	c.type_to_iqandstindex = cpu_to_be32(V_FW_IQ_CMD_TYPE(iqtype));
10458 	c.iqid = cpu_to_be16(iqid);
10459 	c.fl0id = cpu_to_be16(fl0id);
10460 	c.fl1id = cpu_to_be16(fl1id);
10461 	return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
10462 }
10463 
10464 /**
10465  *	t4_iq_free - free an ingress queue and its FLs
10466  *	@adap: the adapter
10467  *	@mbox: mailbox to use for the FW command
10468  *	@pf: the PF owning the queues
10469  *	@vf: the VF owning the queues
10470  *	@iqtype: the ingress queue type (FW_IQ_TYPE_FL_INT_CAP, etc.)
10471  *	@iqid: ingress queue id
10472  *	@fl0id: FL0 queue id or 0xffff if no attached FL0
10473  *	@fl1id: FL1 queue id or 0xffff if no attached FL1
10474  *
10475  *	Frees an ingress queue and its associated FLs, if any.
10476  */
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)10477 int t4_iq_free(struct adapter *adap, unsigned int mbox, unsigned int pf,
10478 	       unsigned int vf, unsigned int iqtype, unsigned int iqid,
10479 	       unsigned int fl0id, unsigned int fl1id)
10480 {
10481 	struct fw_iq_cmd c;
10482 
10483 	memset(&c, 0, sizeof(c));
10484 	c.op_to_vfn = cpu_to_be32(V_FW_CMD_OP(FW_IQ_CMD) | F_FW_CMD_REQUEST |
10485 				  F_FW_CMD_EXEC | V_FW_IQ_CMD_PFN(pf) |
10486 				  V_FW_IQ_CMD_VFN(vf));
10487 	c.alloc_to_len16 = cpu_to_be32(F_FW_IQ_CMD_FREE | FW_LEN16(c));
10488 	c.type_to_iqandstindex = cpu_to_be32(V_FW_IQ_CMD_TYPE(iqtype));
10489 	c.iqid = cpu_to_be16(iqid);
10490 	c.fl0id = cpu_to_be16(fl0id);
10491 	c.fl1id = cpu_to_be16(fl1id);
10492 	return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
10493 }
10494 
10495 /**
10496  *	t4_eth_eq_stop - stop an Ethernet egress queue
10497  *	@adap: the adapter
10498  *	@mbox: mailbox to use for the FW command
10499  *	@pf: the PF owning the queues
10500  *	@vf: the VF owning the queues
10501  *	@eqid: egress queue id
10502  *
10503  *	Stops an Ethernet egress queue.  The queue can be reinitialized or
10504  *	freed but is not otherwise functional after this call.
10505  */
t4_eth_eq_stop(struct adapter * adap,unsigned int mbox,unsigned int pf,unsigned int vf,unsigned int eqid)10506 int t4_eth_eq_stop(struct adapter *adap, unsigned int mbox, unsigned int pf,
10507                    unsigned int vf, unsigned int eqid)
10508 {
10509 	struct fw_eq_eth_cmd c;
10510 
10511 	memset(&c, 0, sizeof(c));
10512 	c.op_to_vfn = cpu_to_be32(V_FW_CMD_OP(FW_EQ_ETH_CMD) |
10513 				  F_FW_CMD_REQUEST | F_FW_CMD_EXEC |
10514 				  V_FW_EQ_ETH_CMD_PFN(pf) |
10515 				  V_FW_EQ_ETH_CMD_VFN(vf));
10516 	c.alloc_to_len16 = cpu_to_be32(F_FW_EQ_ETH_CMD_EQSTOP | FW_LEN16(c));
10517 	c.eqid_pkd = cpu_to_be32(V_FW_EQ_ETH_CMD_EQID(eqid));
10518 	return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
10519 }
10520 
10521 /**
10522  *	t4_eth_eq_free - free an Ethernet egress queue
10523  *	@adap: the adapter
10524  *	@mbox: mailbox to use for the FW command
10525  *	@pf: the PF owning the queue
10526  *	@vf: the VF owning the queue
10527  *	@eqid: egress queue id
10528  *
10529  *	Frees an Ethernet egress queue.
10530  */
t4_eth_eq_free(struct adapter * adap,unsigned int mbox,unsigned int pf,unsigned int vf,unsigned int eqid)10531 int t4_eth_eq_free(struct adapter *adap, unsigned int mbox, unsigned int pf,
10532 		   unsigned int vf, unsigned int eqid)
10533 {
10534 	struct fw_eq_eth_cmd c;
10535 
10536 	memset(&c, 0, sizeof(c));
10537 	c.op_to_vfn = cpu_to_be32(V_FW_CMD_OP(FW_EQ_ETH_CMD) |
10538 				  F_FW_CMD_REQUEST | F_FW_CMD_EXEC |
10539 				  V_FW_EQ_ETH_CMD_PFN(pf) |
10540 				  V_FW_EQ_ETH_CMD_VFN(vf));
10541 	c.alloc_to_len16 = cpu_to_be32(F_FW_EQ_ETH_CMD_FREE | FW_LEN16(c));
10542 	c.eqid_pkd = cpu_to_be32(V_FW_EQ_ETH_CMD_EQID(eqid));
10543 	return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
10544 }
10545 
10546 /**
10547  *	t4_ctrl_eq_free - free a control egress queue
10548  *	@adap: the adapter
10549  *	@mbox: mailbox to use for the FW command
10550  *	@pf: the PF owning the queue
10551  *	@vf: the VF owning the queue
10552  *	@eqid: egress queue id
10553  *
10554  *	Frees a control egress queue.
10555  */
t4_ctrl_eq_free(struct adapter * adap,unsigned int mbox,unsigned int pf,unsigned int vf,unsigned int eqid)10556 int t4_ctrl_eq_free(struct adapter *adap, unsigned int mbox, unsigned int pf,
10557 		    unsigned int vf, unsigned int eqid)
10558 {
10559 	struct fw_eq_ctrl_cmd c;
10560 
10561 	memset(&c, 0, sizeof(c));
10562 	c.op_to_vfn = cpu_to_be32(V_FW_CMD_OP(FW_EQ_CTRL_CMD) |
10563 				  F_FW_CMD_REQUEST | F_FW_CMD_EXEC |
10564 				  V_FW_EQ_CTRL_CMD_PFN(pf) |
10565 				  V_FW_EQ_CTRL_CMD_VFN(vf));
10566 	c.alloc_to_len16 = cpu_to_be32(F_FW_EQ_CTRL_CMD_FREE | FW_LEN16(c));
10567 	c.cmpliqid_eqid = cpu_to_be32(V_FW_EQ_CTRL_CMD_EQID(eqid));
10568 	return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
10569 }
10570 
10571 /**
10572  *	t4_ofld_eq_free - free an offload egress queue
10573  *	@adap: the adapter
10574  *	@mbox: mailbox to use for the FW command
10575  *	@pf: the PF owning the queue
10576  *	@vf: the VF owning the queue
10577  *	@eqid: egress queue id
10578  *
10579  *	Frees a control egress queue.
10580  */
t4_ofld_eq_free(struct adapter * adap,unsigned int mbox,unsigned int pf,unsigned int vf,unsigned int eqid)10581 int t4_ofld_eq_free(struct adapter *adap, unsigned int mbox, unsigned int pf,
10582 		    unsigned int vf, unsigned int eqid)
10583 {
10584 	struct fw_eq_ofld_cmd c;
10585 
10586 	memset(&c, 0, sizeof(c));
10587 	c.op_to_vfn = cpu_to_be32(V_FW_CMD_OP(FW_EQ_OFLD_CMD) |
10588 				  F_FW_CMD_REQUEST | F_FW_CMD_EXEC |
10589 				  V_FW_EQ_OFLD_CMD_PFN(pf) |
10590 				  V_FW_EQ_OFLD_CMD_VFN(vf));
10591 	c.alloc_to_len16 = cpu_to_be32(F_FW_EQ_OFLD_CMD_FREE | FW_LEN16(c));
10592 	c.eqid_pkd = cpu_to_be32(V_FW_EQ_OFLD_CMD_EQID(eqid));
10593 	return t4_wr_mbox(adap, mbox, &c, sizeof(c), NULL);
10594 }
10595 
10596 /**
10597  *	t4_link_down_rc_str - return a string for a Link Down Reason Code
10598  *	@link_down_rc: Link Down Reason Code
10599  *
10600  *	Returns a string representation of the Link Down Reason Code.
10601  */
t4_link_down_rc_str(unsigned char link_down_rc)10602 const char *t4_link_down_rc_str(unsigned char link_down_rc)
10603 {
10604 	static const char *reason[] = {
10605 		"Link Down",
10606 		"Remote Fault",
10607 		"Auto-negotiation Failure",
10608 		"Reserved3",
10609 		"Insufficient Airflow",
10610 		"Unable To Determine Reason",
10611 		"No RX Signal Detected",
10612 		"Reserved7",
10613 	};
10614 
10615 	if (link_down_rc >= ARRAY_SIZE(reason))
10616 		return "Bad Reason Code";
10617 
10618 	return reason[link_down_rc];
10619 }
10620 
10621 /*
10622  * Return the highest speed set in the port capabilities, in Mb/s.
10623  */
fwcap_to_speed(uint32_t caps)10624 unsigned int fwcap_to_speed(uint32_t caps)
10625 {
10626 	#define TEST_SPEED_RETURN(__caps_speed, __speed) \
10627 		do { \
10628 			if (caps & FW_PORT_CAP32_SPEED_##__caps_speed) \
10629 				return __speed; \
10630 		} while (0)
10631 
10632 	TEST_SPEED_RETURN(400G, 400000);
10633 	TEST_SPEED_RETURN(200G, 200000);
10634 	TEST_SPEED_RETURN(100G, 100000);
10635 	TEST_SPEED_RETURN(50G,   50000);
10636 	TEST_SPEED_RETURN(40G,   40000);
10637 	TEST_SPEED_RETURN(25G,   25000);
10638 	TEST_SPEED_RETURN(10G,   10000);
10639 	TEST_SPEED_RETURN(1G,     1000);
10640 	TEST_SPEED_RETURN(100M,    100);
10641 
10642 	#undef TEST_SPEED_RETURN
10643 
10644 	return 0;
10645 }
10646 
10647 /*
10648  * Return the port capabilities bit for the given speed, which is in Mb/s.
10649  */
speed_to_fwcap(unsigned int speed)10650 uint32_t speed_to_fwcap(unsigned int speed)
10651 {
10652 	#define TEST_SPEED_RETURN(__caps_speed, __speed) \
10653 		do { \
10654 			if (speed == __speed) \
10655 				return FW_PORT_CAP32_SPEED_##__caps_speed; \
10656 		} while (0)
10657 
10658 	TEST_SPEED_RETURN(400G, 400000);
10659 	TEST_SPEED_RETURN(200G, 200000);
10660 	TEST_SPEED_RETURN(100G, 100000);
10661 	TEST_SPEED_RETURN(50G,   50000);
10662 	TEST_SPEED_RETURN(40G,   40000);
10663 	TEST_SPEED_RETURN(25G,   25000);
10664 	TEST_SPEED_RETURN(10G,   10000);
10665 	TEST_SPEED_RETURN(1G,     1000);
10666 	TEST_SPEED_RETURN(100M,    100);
10667 
10668 	#undef TEST_SPEED_RETURN
10669 
10670 	return 0;
10671 }
10672 
10673 /*
10674  * Return the port capabilities bit for the highest speed in the capabilities.
10675  */
fwcap_top_speed(uint32_t caps)10676 uint32_t fwcap_top_speed(uint32_t caps)
10677 {
10678 	#define TEST_SPEED_RETURN(__caps_speed) \
10679 		do { \
10680 			if (caps & FW_PORT_CAP32_SPEED_##__caps_speed) \
10681 				return FW_PORT_CAP32_SPEED_##__caps_speed; \
10682 		} while (0)
10683 
10684 	TEST_SPEED_RETURN(400G);
10685 	TEST_SPEED_RETURN(200G);
10686 	TEST_SPEED_RETURN(100G);
10687 	TEST_SPEED_RETURN(50G);
10688 	TEST_SPEED_RETURN(40G);
10689 	TEST_SPEED_RETURN(25G);
10690 	TEST_SPEED_RETURN(10G);
10691 	TEST_SPEED_RETURN(1G);
10692 	TEST_SPEED_RETURN(100M);
10693 
10694 	#undef TEST_SPEED_RETURN
10695 
10696 	return 0;
10697 }
10698 
10699 /**
10700  *	lstatus_to_fwcap - translate old lstatus to 32-bit Port Capabilities
10701  *	@lstatus: old FW_PORT_ACTION_GET_PORT_INFO lstatus value
10702  *
10703  *	Translates old FW_PORT_ACTION_GET_PORT_INFO lstatus field into new
10704  *	32-bit Port Capabilities value.
10705  */
lstatus_to_fwcap(u32 lstatus)10706 static uint32_t lstatus_to_fwcap(u32 lstatus)
10707 {
10708 	uint32_t linkattr = 0;
10709 
10710 	/*
10711 	 * Unfortunately the format of the Link Status in the old
10712 	 * 16-bit Port Information message isn't the same as the
10713 	 * 16-bit Port Capabilities bitfield used everywhere else ...
10714 	 */
10715 	if (lstatus & F_FW_PORT_CMD_RXPAUSE)
10716 		linkattr |= FW_PORT_CAP32_FC_RX;
10717 	if (lstatus & F_FW_PORT_CMD_TXPAUSE)
10718 		linkattr |= FW_PORT_CAP32_FC_TX;
10719 	if (lstatus & V_FW_PORT_CMD_LSPEED(FW_PORT_CAP_SPEED_100M))
10720 		linkattr |= FW_PORT_CAP32_SPEED_100M;
10721 	if (lstatus & V_FW_PORT_CMD_LSPEED(FW_PORT_CAP_SPEED_1G))
10722 		linkattr |= FW_PORT_CAP32_SPEED_1G;
10723 	if (lstatus & V_FW_PORT_CMD_LSPEED(FW_PORT_CAP_SPEED_10G))
10724 		linkattr |= FW_PORT_CAP32_SPEED_10G;
10725 	if (lstatus & V_FW_PORT_CMD_LSPEED(FW_PORT_CAP_SPEED_25G))
10726 		linkattr |= FW_PORT_CAP32_SPEED_25G;
10727 	if (lstatus & V_FW_PORT_CMD_LSPEED(FW_PORT_CAP_SPEED_40G))
10728 		linkattr |= FW_PORT_CAP32_SPEED_40G;
10729 	if (lstatus & V_FW_PORT_CMD_LSPEED(FW_PORT_CAP_SPEED_100G))
10730 		linkattr |= FW_PORT_CAP32_SPEED_100G;
10731 
10732 	return linkattr;
10733 }
10734 
10735 /*
10736  * Updates all fields owned by the common code in port_info and link_config
10737  * based on information provided by the firmware.  Does not touch any
10738  * requested_* field.
10739  */
handle_port_info(struct port_info * pi,const struct fw_port_cmd * p,enum fw_port_action action,bool * mod_changed,bool * link_changed)10740 static void handle_port_info(struct port_info *pi, const struct fw_port_cmd *p,
10741     enum fw_port_action action, bool *mod_changed, bool *link_changed)
10742 {
10743 	struct link_config old_lc, *lc = &pi->link_cfg;
10744 	unsigned char fc;
10745 	u32 stat, linkattr;
10746 	int old_ptype, old_mtype;
10747 
10748 	old_ptype = pi->port_type;
10749 	old_mtype = pi->mod_type;
10750 	old_lc = *lc;
10751 	if (action == FW_PORT_ACTION_GET_PORT_INFO) {
10752 		stat = be32_to_cpu(p->u.info.lstatus_to_modtype);
10753 
10754 		pi->port_type = G_FW_PORT_CMD_PTYPE(stat);
10755 		pi->mod_type = G_FW_PORT_CMD_MODTYPE(stat);
10756 		pi->mdio_addr = stat & F_FW_PORT_CMD_MDIOCAP ?
10757 		    G_FW_PORT_CMD_MDIOADDR(stat) : -1;
10758 
10759 		lc->pcaps = fwcaps16_to_caps32(be16_to_cpu(p->u.info.pcap));
10760 		lc->acaps = fwcaps16_to_caps32(be16_to_cpu(p->u.info.acap));
10761 		lc->lpacaps = fwcaps16_to_caps32(be16_to_cpu(p->u.info.lpacap));
10762 		lc->link_ok = (stat & F_FW_PORT_CMD_LSTATUS) != 0;
10763 		lc->link_down_rc = G_FW_PORT_CMD_LINKDNRC(stat);
10764 
10765 		linkattr = lstatus_to_fwcap(stat);
10766 	} else if (action == FW_PORT_ACTION_GET_PORT_INFO32) {
10767 		stat = be32_to_cpu(p->u.info32.lstatus32_to_cbllen32);
10768 
10769 		pi->port_type = G_FW_PORT_CMD_PORTTYPE32(stat);
10770 		pi->mod_type = G_FW_PORT_CMD_MODTYPE32(stat);
10771 		pi->mdio_addr = stat & F_FW_PORT_CMD_MDIOCAP32 ?
10772 		    G_FW_PORT_CMD_MDIOADDR32(stat) : -1;
10773 
10774 		lc->pcaps = be32_to_cpu(p->u.info32.pcaps32);
10775 		lc->acaps = be32_to_cpu(p->u.info32.acaps32);
10776 		lc->lpacaps = be32_to_cpu(p->u.info32.lpacaps32);
10777 		lc->link_ok = (stat & F_FW_PORT_CMD_LSTATUS32) != 0;
10778 		lc->link_down_rc = G_FW_PORT_CMD_LINKDNRC32(stat);
10779 
10780 		linkattr = be32_to_cpu(p->u.info32.linkattr32);
10781 	} else {
10782 		CH_ERR(pi->adapter, "bad port_info action 0x%x\n", action);
10783 		return;
10784 	}
10785 
10786 	lc->speed = fwcap_to_speed(linkattr);
10787 	lc->fec = fwcap_to_fec(linkattr, true);
10788 
10789 	fc = 0;
10790 	if (linkattr & FW_PORT_CAP32_FC_RX)
10791 		fc |= PAUSE_RX;
10792 	if (linkattr & FW_PORT_CAP32_FC_TX)
10793 		fc |= PAUSE_TX;
10794 	lc->fc = fc;
10795 
10796 	if (mod_changed != NULL)
10797 		*mod_changed = false;
10798 	if (link_changed != NULL)
10799 		*link_changed = false;
10800 	if (old_ptype != pi->port_type || old_mtype != pi->mod_type ||
10801 	    old_lc.pcaps != lc->pcaps) {
10802 		if (pi->mod_type != FW_PORT_MOD_TYPE_NONE)
10803 			lc->fec_hint = fwcap_to_fec(lc->acaps, true);
10804 		if (mod_changed != NULL)
10805 			*mod_changed = true;
10806 	}
10807 	if (old_lc.link_ok != lc->link_ok || old_lc.speed != lc->speed ||
10808 	    old_lc.fec != lc->fec || old_lc.fc != lc->fc) {
10809 		if (link_changed != NULL)
10810 			*link_changed = true;
10811 	}
10812 }
10813 
10814 /**
10815  *	t4_update_port_info - retrieve and update port information if changed
10816  *	@pi: the port_info
10817  *
10818  *	We issue a Get Port Information Command to the Firmware and, if
10819  *	successful, we check to see if anything is different from what we
10820  *	last recorded and update things accordingly.
10821  */
t4_update_port_info(struct port_info * pi)10822  int t4_update_port_info(struct port_info *pi)
10823  {
10824 	struct adapter *sc = pi->adapter;
10825 	struct fw_port_cmd cmd;
10826 	enum fw_port_action action;
10827 	int ret;
10828 
10829 	memset(&cmd, 0, sizeof(cmd));
10830 	cmd.op_to_portid = cpu_to_be32(V_FW_CMD_OP(FW_PORT_CMD) |
10831 	    F_FW_CMD_REQUEST | F_FW_CMD_READ |
10832 	    V_FW_PORT_CMD_PORTID(pi->hw_port));
10833 	action = sc->params.port_caps32 ? FW_PORT_ACTION_GET_PORT_INFO32 :
10834 	    FW_PORT_ACTION_GET_PORT_INFO;
10835 	cmd.action_to_len16 = cpu_to_be32(V_FW_PORT_CMD_ACTION(action) |
10836 	    FW_LEN16(cmd));
10837 	ret = t4_wr_mbox_ns(sc, sc->mbox, &cmd, sizeof(cmd), &cmd);
10838 	if (ret)
10839 		return ret;
10840 
10841 	handle_port_info(pi, &cmd, action, NULL, NULL);
10842 	return 0;
10843 }
10844 
10845 /**
10846  *	t4_handle_fw_rpl - process a FW reply message
10847  *	@adap: the adapter
10848  *	@rpl: start of the FW message
10849  *
10850  *	Processes a FW message, such as link state change messages.
10851  */
t4_handle_fw_rpl(struct adapter * adap,const __be64 * rpl)10852 int t4_handle_fw_rpl(struct adapter *adap, const __be64 *rpl)
10853 {
10854 	u8 opcode = *(const u8 *)rpl;
10855 	const struct fw_port_cmd *p = (const void *)rpl;
10856 	enum fw_port_action action =
10857 	    G_FW_PORT_CMD_ACTION(be32_to_cpu(p->action_to_len16));
10858 	bool mod_changed, link_changed;
10859 
10860 	if (opcode == FW_PORT_CMD &&
10861 	    (action == FW_PORT_ACTION_GET_PORT_INFO ||
10862 	    action == FW_PORT_ACTION_GET_PORT_INFO32)) {
10863 		/* link/module state change message */
10864 		int hw_port = G_FW_PORT_CMD_PORTID(be32_to_cpu(p->op_to_portid));
10865 		int port_id = adap->port_map[hw_port];
10866 		struct port_info *pi;
10867 
10868 		MPASS(port_id >= 0 && port_id < adap->params.nports);
10869 		pi = adap->port[port_id];
10870 		PORT_LOCK(pi);
10871 		handle_port_info(pi, p, action, &mod_changed, &link_changed);
10872 		PORT_UNLOCK(pi);
10873 		if (mod_changed)
10874 			t4_os_portmod_changed(pi);
10875 		if (link_changed) {
10876 			PORT_LOCK(pi);
10877 			t4_os_link_changed(pi);
10878 			PORT_UNLOCK(pi);
10879 		}
10880 	} else {
10881 		CH_WARN_RATELIMIT(adap, "Unknown firmware reply %d\n", opcode);
10882 		return -EINVAL;
10883 	}
10884 	return 0;
10885 }
10886 
10887 /**
10888  *	get_pci_mode - determine a card's PCI mode
10889  *	@adapter: the adapter
10890  *	@p: where to store the PCI settings
10891  *
10892  *	Determines a card's PCI mode and associated parameters, such as speed
10893  *	and width.
10894  */
get_pci_mode(struct adapter * adapter,struct pci_params * p)10895 static void get_pci_mode(struct adapter *adapter,
10896 				   struct pci_params *p)
10897 {
10898 	u16 val;
10899 	u32 pcie_cap;
10900 
10901 	pcie_cap = t4_os_find_pci_capability(adapter, PCI_CAP_ID_EXP);
10902 	if (pcie_cap) {
10903 		t4_os_pci_read_cfg2(adapter, pcie_cap + PCI_EXP_LNKSTA, &val);
10904 		p->speed = val & PCI_EXP_LNKSTA_CLS;
10905 		p->width = (val & PCI_EXP_LNKSTA_NLW) >> 4;
10906 	}
10907 }
10908 
10909 struct flash_desc {
10910 	u32 vendor_and_model_id;
10911 	u32 size_mb;
10912 };
10913 
t4_get_flash_params(struct adapter * adapter)10914 int t4_get_flash_params(struct adapter *adapter)
10915 {
10916 	/*
10917 	 * Table for non-standard supported Flash parts.  Note, all Flash
10918 	 * parts must have 64KB sectors.
10919 	 */
10920 	static struct flash_desc supported_flash[] = {
10921 		{ 0x00150201, 4 << 20 },	/* Spansion 4MB S25FL032P */
10922 	};
10923 
10924 	int ret;
10925 	u32 flashid = 0;
10926 	unsigned int part, manufacturer;
10927 	unsigned int density, size = 0;
10928 
10929 
10930 	/*
10931 	 * Issue a Read ID Command to the Flash part.  We decode supported
10932 	 * Flash parts and their sizes from this.  There's a newer Query
10933 	 * Command which can retrieve detailed geometry information but many
10934 	 * Flash parts don't support it.
10935 	 */
10936 	ret = sf1_write(adapter, 1, 1, 0, SF_RD_ID);
10937 	if (!ret)
10938 		ret = sf1_read(adapter, 3, 0, 1, &flashid);
10939 	t4_write_reg(adapter, A_SF_OP, 0);	/* unlock SF */
10940 	if (ret < 0)
10941 		return ret;
10942 
10943 	/*
10944 	 * Check to see if it's one of our non-standard supported Flash parts.
10945 	 */
10946 	for (part = 0; part < ARRAY_SIZE(supported_flash); part++)
10947 		if (supported_flash[part].vendor_and_model_id == flashid) {
10948 			adapter->params.sf_size =
10949 				supported_flash[part].size_mb;
10950 			adapter->params.sf_nsec =
10951 				adapter->params.sf_size / SF_SEC_SIZE;
10952 			goto found;
10953 		}
10954 
10955 	/*
10956 	 * Decode Flash part size.  The code below looks repetative with
10957 	 * common encodings, but that's not guaranteed in the JEDEC
10958 	 * specification for the Read JADEC ID command.  The only thing that
10959 	 * we're guaranteed by the JADEC specification is where the
10960 	 * Manufacturer ID is in the returned result.  After that each
10961 	 * Manufacturer ~could~ encode things completely differently.
10962 	 * Note, all Flash parts must have 64KB sectors.
10963 	 */
10964 	manufacturer = flashid & 0xff;
10965 	switch (manufacturer) {
10966 	case 0x20: /* Micron/Numonix */
10967 		/*
10968 		 * This Density -> Size decoding table is taken from Micron
10969 		 * Data Sheets.
10970 		 */
10971 		density = (flashid >> 16) & 0xff;
10972 		switch (density) {
10973 		case 0x14: size = 1 << 20; break; /*   1MB */
10974 		case 0x15: size = 1 << 21; break; /*   2MB */
10975 		case 0x16: size = 1 << 22; break; /*   4MB */
10976 		case 0x17: size = 1 << 23; break; /*   8MB */
10977 		case 0x18: size = 1 << 24; break; /*  16MB */
10978 		case 0x19: size = 1 << 25; break; /*  32MB */
10979 		case 0x20: size = 1 << 26; break; /*  64MB */
10980 		case 0x21: size = 1 << 27; break; /* 128MB */
10981 		case 0x22: size = 1 << 28; break; /* 256MB */
10982 		}
10983 		break;
10984 
10985 	case 0x9d: /* ISSI -- Integrated Silicon Solution, Inc. */
10986 		/*
10987 		 * This Density -> Size decoding table is taken from ISSI
10988 		 * Data Sheets.
10989 		 */
10990 		density = (flashid >> 16) & 0xff;
10991 		switch (density) {
10992 		case 0x16: size = 1 << 25; break; /*  32MB */
10993 		case 0x17: size = 1 << 26; break; /*  64MB */
10994 		}
10995 		break;
10996 
10997 	case 0xc2: /* Macronix */
10998 		/*
10999 		 * This Density -> Size decoding table is taken from Macronix
11000 		 * Data Sheets.
11001 		 */
11002 		density = (flashid >> 16) & 0xff;
11003 		switch (density) {
11004 		case 0x17: size = 1 << 23; break; /*   8MB */
11005 		case 0x18: size = 1 << 24; break; /*  16MB */
11006 		}
11007 		break;
11008 
11009 	case 0xef: /* Winbond */
11010 		/*
11011 		 * This Density -> Size decoding table is taken from Winbond
11012 		 * Data Sheets.
11013 		 */
11014 		density = (flashid >> 16) & 0xff;
11015 		switch (density) {
11016 		case 0x17: size = 1 << 23; break; /*   8MB */
11017 		case 0x18: size = 1 << 24; break; /*  16MB */
11018 		}
11019 		break;
11020 	}
11021 
11022 	/* If we didn't recognize the FLASH part, that's no real issue: the
11023 	 * Hardware/Software contract says that Hardware will _*ALWAYS*_ use a
11024 	 * FLASH part which has 64KB sectors and is at least 4MB or 16MB in
11025 	 * size, depending on the board.
11026 	 */
11027 	if (size == 0) {
11028 		size = chip_id(adapter) >= CHELSIO_T7 ? 16 : 4;
11029 		CH_WARN(adapter, "Unknown Flash Part %#x, assuming %uMB\n",
11030 		    flashid, size);
11031 		size <<= 20;
11032 	}
11033 
11034 	/*
11035 	 * Store decoded Flash size and fall through into vetting code.
11036 	 */
11037 	adapter->params.sf_size = size;
11038 	adapter->params.sf_nsec = size / SF_SEC_SIZE;
11039 
11040  found:
11041 	/*
11042 	 * We should ~probably~ reject adapters with FLASHes which are too
11043 	 * small but we have some legacy FPGAs with small FLASHes that we'd
11044 	 * still like to use.  So instead we emit a scary message ...
11045 	 */
11046 	if (adapter->params.sf_size < FLASH_MIN_SIZE)
11047 		CH_WARN(adapter, "WARNING: Flash Part ID %#x, size %#x < %#x\n",
11048 			flashid, adapter->params.sf_size, FLASH_MIN_SIZE);
11049 
11050 	return 0;
11051 }
11052 
set_pcie_completion_timeout(struct adapter * adapter,u8 range)11053 static void set_pcie_completion_timeout(struct adapter *adapter,
11054 						  u8 range)
11055 {
11056 	u16 val;
11057 	u32 pcie_cap;
11058 
11059 	pcie_cap = t4_os_find_pci_capability(adapter, PCI_CAP_ID_EXP);
11060 	if (pcie_cap) {
11061 		t4_os_pci_read_cfg2(adapter, pcie_cap + PCI_EXP_DEVCTL2, &val);
11062 		val &= 0xfff0;
11063 		val |= range ;
11064 		t4_os_pci_write_cfg2(adapter, pcie_cap + PCI_EXP_DEVCTL2, val);
11065 	}
11066 }
11067 
t4_get_chip_params(int chipid)11068 const struct chip_params *t4_get_chip_params(int chipid)
11069 {
11070 	static const struct chip_params chip_params[] = {
11071 		{
11072 			/* T4 */
11073 			.nchan = NCHAN,
11074 			.pm_stats_cnt = PM_NSTATS,
11075 			.cng_ch_bits_log = 2,
11076 			.nsched_cls = 15,
11077 			.cim_num_ibq = CIM_NUM_IBQ,
11078 			.cim_num_obq = CIM_NUM_OBQ,
11079 			.filter_opt_len = FILTER_OPT_LEN,
11080 			.filter_num_opt = S_FT_LAST + 1,
11081 			.mps_rplc_size = 128,
11082 			.vfcount = 128,
11083 			.sge_fl_db = F_DBPRIO,
11084 			.sge_ctxt_size = SGE_CTXT_SIZE,
11085 			.mps_tcam_size = NUM_MPS_CLS_SRAM_L_INSTANCES,
11086 			.rss_nentries = RSS_NENTRIES,
11087 			.cim_la_size = CIMLA_SIZE,
11088 		},
11089 		{
11090 			/* T5 */
11091 			.nchan = NCHAN,
11092 			.pm_stats_cnt = PM_NSTATS,
11093 			.cng_ch_bits_log = 2,
11094 			.nsched_cls = 16,
11095 			.cim_num_ibq = CIM_NUM_IBQ,
11096 			.cim_num_obq = CIM_NUM_OBQ_T5,
11097 			.filter_opt_len = T5_FILTER_OPT_LEN,
11098 			.filter_num_opt = S_FT_LAST + 1,
11099 			.mps_rplc_size = 128,
11100 			.vfcount = 128,
11101 			.sge_fl_db = F_DBPRIO | F_DBTYPE,
11102 			.sge_ctxt_size = SGE_CTXT_SIZE,
11103 			.mps_tcam_size = NUM_MPS_T5_CLS_SRAM_L_INSTANCES,
11104 			.rss_nentries = RSS_NENTRIES,
11105 			.cim_la_size = CIMLA_SIZE,
11106 		},
11107 		{
11108 			/* T6 */
11109 			.nchan = T6_NCHAN,
11110 			.pm_stats_cnt = T6_PM_NSTATS,
11111 			.cng_ch_bits_log = 3,
11112 			.nsched_cls = 16,
11113 			.cim_num_ibq = CIM_NUM_IBQ,
11114 			.cim_num_obq = CIM_NUM_OBQ_T5,
11115 			.filter_opt_len = T5_FILTER_OPT_LEN,
11116 			.filter_num_opt = S_FT_LAST + 1,
11117 			.mps_rplc_size = 256,
11118 			.vfcount = 256,
11119 			.sge_fl_db = 0,
11120 			.sge_ctxt_size = SGE_CTXT_SIZE,
11121 			.mps_tcam_size = NUM_MPS_T5_CLS_SRAM_L_INSTANCES,
11122 			.rss_nentries = T6_RSS_NENTRIES,
11123 			.cim_la_size = CIMLA_SIZE_T6,
11124 		},
11125 		{
11126 			/* T7 */
11127 			.nchan = NCHAN,
11128 			.pm_stats_cnt = T6_PM_NSTATS,
11129 			.cng_ch_bits_log = 2,
11130 			.nsched_cls = 16,
11131 			.cim_num_ibq = CIM_NUM_IBQ_T7,
11132 			.cim_num_obq = CIM_NUM_OBQ_T7,
11133 			.filter_opt_len = T7_FILTER_OPT_LEN,
11134 			.filter_num_opt = S_T7_FT_LAST + 1,
11135 			.mps_rplc_size = 256,
11136 			.vfcount = 256,
11137 			.sge_fl_db = 0,
11138 			.sge_ctxt_size = SGE_CTXT_SIZE_T7,
11139 			.mps_tcam_size = NUM_MPS_T5_CLS_SRAM_L_INSTANCES * 3,
11140 			.rss_nentries = T7_RSS_NENTRIES,
11141 			.cim_la_size = CIMLA_SIZE_T6,
11142 		},
11143 	};
11144 
11145 	chipid -= CHELSIO_T4;
11146 	if (chipid < 0 || chipid >= ARRAY_SIZE(chip_params))
11147 		return NULL;
11148 
11149 	return &chip_params[chipid];
11150 }
11151 
11152 /**
11153  *	t4_prep_adapter - prepare SW and HW for operation
11154  *	@adapter: the adapter
11155  *	@buf: temporary space of at least VPD_LEN size provided by the caller.
11156  *
11157  *	Initialize adapter SW state for the various HW modules, set initial
11158  *	values for some adapter tunables, take PHYs out of reset, and
11159  *	initialize the MDIO interface.
11160  */
t4_prep_adapter(struct adapter * adapter,u32 * buf)11161 int t4_prep_adapter(struct adapter *adapter, u32 *buf)
11162 {
11163 	int ret;
11164 	uint16_t device_id;
11165 	uint32_t pl_rev;
11166 
11167 	get_pci_mode(adapter, &adapter->params.pci);
11168 
11169 	pl_rev = t4_read_reg(adapter, A_PL_REV);
11170 	adapter->params.chipid = G_CHIPID(pl_rev);
11171 	adapter->params.rev = G_REV(pl_rev);
11172 	if (adapter->params.chipid == 0) {
11173 		/* T4 did not have chipid in PL_REV (T5 onwards do) */
11174 		adapter->params.chipid = CHELSIO_T4;
11175 
11176 		/* T4A1 chip is not supported */
11177 		if (adapter->params.rev == 1) {
11178 			CH_ALERT(adapter, "T4 rev 1 chip is not supported.\n");
11179 			return -EINVAL;
11180 		}
11181 	}
11182 
11183 	adapter->chip_params = t4_get_chip_params(chip_id(adapter));
11184 	if (adapter->chip_params == NULL)
11185 		return -EINVAL;
11186 
11187 	adapter->params.pci.vpd_cap_addr =
11188 	    t4_os_find_pci_capability(adapter, PCI_CAP_ID_VPD);
11189 
11190 	ret = t4_get_flash_params(adapter);
11191 	if (ret < 0)
11192 		return ret;
11193 
11194 	/* Cards with real ASICs have the chipid in the PCIe device id */
11195 	t4_os_pci_read_cfg2(adapter, PCI_DEVICE_ID, &device_id);
11196 	if (device_id >> 12 == chip_id(adapter))
11197 		adapter->params.cim_la_size = adapter->chip_params->cim_la_size;
11198 	else {
11199 		/* FPGA */
11200 		adapter->params.fpga = 1;
11201 		adapter->params.cim_la_size = 2 * adapter->chip_params->cim_la_size;
11202 	}
11203 
11204 	ret = get_vpd_params(adapter, &adapter->params.vpd, device_id, buf);
11205 	if (ret < 0)
11206 		return ret;
11207 
11208 	init_cong_ctrl(adapter->params.a_wnd, adapter->params.b_wnd);
11209 
11210 	/*
11211 	 * Default port and clock for debugging in case we can't reach FW.
11212 	 */
11213 	adapter->params.nports = 1;
11214 	adapter->params.portvec = 1;
11215 	adapter->params.vpd.cclk = 50000;
11216 
11217 	/* Set pci completion timeout value to 4 seconds. */
11218 	set_pcie_completion_timeout(adapter, 0xd);
11219 	return 0;
11220 }
11221 
11222 /**
11223  *	t4_shutdown_adapter - shut down adapter, host & wire
11224  *	@adapter: the adapter
11225  *
11226  *	Perform an emergency shutdown of the adapter and stop it from
11227  *	continuing any further communication on the ports or DMA to the
11228  *	host.  This is typically used when the adapter and/or firmware
11229  *	have crashed and we want to prevent any further accidental
11230  *	communication with the rest of the world.  This will also force
11231  *	the port Link Status to go down -- if register writes work --
11232  *	which should help our peers figure out that we're down.
11233  */
t4_shutdown_adapter(struct adapter * adapter)11234 int t4_shutdown_adapter(struct adapter *adapter)
11235 {
11236 	int port;
11237 	const bool bt = adapter->bt_map != 0;
11238 
11239 	t4_intr_disable(adapter);
11240 	if (bt)
11241 		t4_write_reg(adapter, A_DBG_GPIO_EN, 0xffff0000);
11242 	for_each_port(adapter, port) {
11243 		u32 a_port_cfg = is_t4(adapter) ?
11244 		    t4_port_reg(adapter, port, A_XGMAC_PORT_CFG) :
11245 		    t4_port_reg(adapter, port, A_MAC_PORT_CFG);
11246 
11247 		t4_write_reg(adapter, a_port_cfg,
11248 			     t4_read_reg(adapter, a_port_cfg)
11249 			     & ~V_SIGNAL_DET(1));
11250 		if (!bt) {
11251 			u32 hss_cfg0 = is_t4(adapter) ?
11252 			    t4_port_reg(adapter, port, A_XGMAC_PORT_HSS_CFG0) :
11253 			    t4_port_reg(adapter, port, A_MAC_PORT_HSS_CFG0);
11254 			t4_set_reg_field(adapter, hss_cfg0, F_HSSPDWNPLLB |
11255 			    F_HSSPDWNPLLA | F_HSSPLLBYPB | F_HSSPLLBYPA,
11256 			    F_HSSPDWNPLLB | F_HSSPDWNPLLA | F_HSSPLLBYPB |
11257 			    F_HSSPLLBYPA);
11258 		}
11259 	}
11260 	t4_set_reg_field(adapter, A_SGE_CONTROL, F_GLOBALENABLE, 0);
11261 
11262 	return 0;
11263 }
11264 
11265 /**
11266  *	t4_bar2_sge_qregs - return BAR2 SGE Queue register information
11267  *	@adapter: the adapter
11268  *	@qid: the Queue ID
11269  *	@qtype: the Ingress or Egress type for @qid
11270  *	@user: true if this request is for a user mode queue
11271  *	@pbar2_qoffset: BAR2 Queue Offset
11272  *	@pbar2_qid: BAR2 Queue ID or 0 for Queue ID inferred SGE Queues
11273  *
11274  *	Returns the BAR2 SGE Queue Registers information associated with the
11275  *	indicated Absolute Queue ID.  These are passed back in return value
11276  *	pointers.  @qtype should be T4_BAR2_QTYPE_EGRESS for Egress Queue
11277  *	and T4_BAR2_QTYPE_INGRESS for Ingress Queues.
11278  *
11279  *	This may return an error which indicates that BAR2 SGE Queue
11280  *	registers aren't available.  If an error is not returned, then the
11281  *	following values are returned:
11282  *
11283  *	  *@pbar2_qoffset: the BAR2 Offset of the @qid Registers
11284  *	  *@pbar2_qid: the BAR2 SGE Queue ID or 0 of @qid
11285  *
11286  *	If the returned BAR2 Queue ID is 0, then BAR2 SGE registers which
11287  *	require the "Inferred Queue ID" ability may be used.  E.g. the
11288  *	Write Combining Doorbell Buffer. If the BAR2 Queue ID is not 0,
11289  *	then these "Inferred Queue ID" register may not be used.
11290  */
t4_bar2_sge_qregs(struct adapter * adapter,unsigned int qid,enum t4_bar2_qtype qtype,int user,u64 * pbar2_qoffset,unsigned int * pbar2_qid)11291 int t4_bar2_sge_qregs(struct adapter *adapter,
11292 		      unsigned int qid,
11293 		      enum t4_bar2_qtype qtype,
11294 		      int user,
11295 		      u64 *pbar2_qoffset,
11296 		      unsigned int *pbar2_qid)
11297 {
11298 	unsigned int page_shift, page_size, qpp_shift, qpp_mask;
11299 	u64 bar2_page_offset, bar2_qoffset;
11300 	unsigned int bar2_qid, bar2_qid_offset, bar2_qinferred;
11301 
11302 	/* T4 doesn't support BAR2 SGE Queue registers for kernel
11303 	 * mode queues.
11304 	 */
11305 	if (!user && is_t4(adapter))
11306 		return -EINVAL;
11307 
11308 	/* Get our SGE Page Size parameters.
11309 	 */
11310 	page_shift = adapter->params.sge.page_shift;
11311 	page_size = 1 << page_shift;
11312 
11313 	/* Get the right Queues per Page parameters for our Queue.
11314 	 */
11315 	qpp_shift = (qtype == T4_BAR2_QTYPE_EGRESS
11316 		     ? adapter->params.sge.eq_s_qpp
11317 		     : adapter->params.sge.iq_s_qpp);
11318 	qpp_mask = (1 << qpp_shift) - 1;
11319 
11320 	/* Calculate the basics of the BAR2 SGE Queue register area:
11321 	 *  o The BAR2 page the Queue registers will be in.
11322 	 *  o The BAR2 Queue ID.
11323 	 *  o The BAR2 Queue ID Offset into the BAR2 page.
11324 	 */
11325 	bar2_page_offset = ((u64)(qid >> qpp_shift) << page_shift);
11326 	bar2_qid = qid & qpp_mask;
11327 	bar2_qid_offset = bar2_qid * SGE_UDB_SIZE;
11328 
11329 	/* If the BAR2 Queue ID Offset is less than the Page Size, then the
11330 	 * hardware will infer the Absolute Queue ID simply from the writes to
11331 	 * the BAR2 Queue ID Offset within the BAR2 Page (and we need to use a
11332 	 * BAR2 Queue ID of 0 for those writes).  Otherwise, we'll simply
11333 	 * write to the first BAR2 SGE Queue Area within the BAR2 Page with
11334 	 * the BAR2 Queue ID and the hardware will infer the Absolute Queue ID
11335 	 * from the BAR2 Page and BAR2 Queue ID.
11336 	 *
11337 	 * One important censequence of this is that some BAR2 SGE registers
11338 	 * have a "Queue ID" field and we can write the BAR2 SGE Queue ID
11339 	 * there.  But other registers synthesize the SGE Queue ID purely
11340 	 * from the writes to the registers -- the Write Combined Doorbell
11341 	 * Buffer is a good example.  These BAR2 SGE Registers are only
11342 	 * available for those BAR2 SGE Register areas where the SGE Absolute
11343 	 * Queue ID can be inferred from simple writes.
11344 	 */
11345 	bar2_qoffset = bar2_page_offset;
11346 	bar2_qinferred = (bar2_qid_offset < page_size);
11347 	if (bar2_qinferred) {
11348 		bar2_qoffset += bar2_qid_offset;
11349 		bar2_qid = 0;
11350 	}
11351 
11352 	*pbar2_qoffset = bar2_qoffset;
11353 	*pbar2_qid = bar2_qid;
11354 	return 0;
11355 }
11356 
11357 /**
11358  *	t4_init_devlog_ncores_params - initialize adap->params.devlog and ncores
11359  *	@adap: the adapter
11360  *	@fw_attach: whether we can talk to the firmware
11361  */
t4_init_devlog_ncores_params(struct adapter * adap,int fw_attach)11362 int t4_init_devlog_ncores_params(struct adapter *adap, int fw_attach)
11363 {
11364 	struct devlog_params *dparams = &adap->params.devlog;
11365 	u32 pf_dparams;
11366 	unsigned int devlog_meminfo;
11367 	struct fw_devlog_cmd devlog_cmd;
11368 	int ret;
11369 
11370 	/* If we're dealing with newer firmware, the Device Log Paramerters
11371 	 * are stored in a designated register which allows us to access the
11372 	 * Device Log even if we can't talk to the firmware.
11373 	 */
11374 	pf_dparams =
11375 		t4_read_reg(adap, PCIE_FW_REG(A_PCIE_FW_PF, PCIE_FW_PF_DEVLOG));
11376 	if (pf_dparams && pf_dparams != UINT32_MAX) {
11377 		unsigned int nentries, nentries128, ncore_shift;
11378 
11379 		ncore_shift = (G_PCIE_FW_PF_DEVLOG_COUNT_MSB(pf_dparams) << 1) |
11380 		    G_PCIE_FW_PF_DEVLOG_COUNT_LSB(pf_dparams);
11381 		adap->params.ncores = 1 << ncore_shift;
11382 
11383 		dparams->memtype = G_PCIE_FW_PF_DEVLOG_MEMTYPE(pf_dparams);
11384 		dparams->start = G_PCIE_FW_PF_DEVLOG_ADDR16(pf_dparams) << 4;
11385 		nentries128 = G_PCIE_FW_PF_DEVLOG_NENTRIES128(pf_dparams);
11386 		nentries = (nentries128 + 1) * 128;
11387 		dparams->size = nentries * sizeof(struct fw_devlog_e);
11388 
11389 		return 0;
11390 	}
11391 
11392 	/*
11393 	 * For any failing returns ...
11394 	 */
11395 	adap->params.ncores = 1;
11396 	memset(dparams, 0, sizeof *dparams);
11397 
11398 	/*
11399 	 * If we can't talk to the firmware, there's really nothing we can do
11400 	 * at this point.
11401 	 */
11402 	if (!fw_attach)
11403 		return -ENXIO;
11404 
11405 	/* Otherwise, ask the firmware for it's Device Log Parameters.
11406 	 */
11407 	memset(&devlog_cmd, 0, sizeof devlog_cmd);
11408 	devlog_cmd.op_to_write = cpu_to_be32(V_FW_CMD_OP(FW_DEVLOG_CMD) |
11409 					     F_FW_CMD_REQUEST | F_FW_CMD_READ);
11410 	devlog_cmd.retval_len16 = cpu_to_be32(FW_LEN16(devlog_cmd));
11411 	ret = t4_wr_mbox(adap, adap->mbox, &devlog_cmd, sizeof(devlog_cmd),
11412 			 &devlog_cmd);
11413 	if (ret)
11414 		return ret;
11415 
11416 	devlog_meminfo =
11417 		be32_to_cpu(devlog_cmd.memtype_devlog_memaddr16_devlog);
11418 	dparams->memtype = G_FW_DEVLOG_CMD_MEMTYPE_DEVLOG(devlog_meminfo);
11419 	dparams->start = G_FW_DEVLOG_CMD_MEMADDR16_DEVLOG(devlog_meminfo) << 4;
11420 	dparams->size = be32_to_cpu(devlog_cmd.memsize_devlog);
11421 
11422 	return 0;
11423 }
11424 
11425 /**
11426  *	t4_init_sge_params - initialize adap->params.sge
11427  *	@adapter: the adapter
11428  *
11429  *	Initialize various fields of the adapter's SGE Parameters structure.
11430  */
t4_init_sge_params(struct adapter * adapter)11431 int t4_init_sge_params(struct adapter *adapter)
11432 {
11433 	u32 r;
11434 	struct sge_params *sp = &adapter->params.sge;
11435 	unsigned i, tscale = 1;
11436 
11437 	r = t4_read_reg(adapter, A_SGE_INGRESS_RX_THRESHOLD);
11438 	sp->counter_val[0] = G_THRESHOLD_0(r);
11439 	sp->counter_val[1] = G_THRESHOLD_1(r);
11440 	sp->counter_val[2] = G_THRESHOLD_2(r);
11441 	sp->counter_val[3] = G_THRESHOLD_3(r);
11442 
11443 	if (chip_id(adapter) >= CHELSIO_T6) {
11444 		r = t4_read_reg(adapter, A_SGE_ITP_CONTROL);
11445 		tscale = G_TSCALE(r);
11446 		if (tscale == 0)
11447 			tscale = 1;
11448 		else
11449 			tscale += 2;
11450 	}
11451 
11452 	r = t4_read_reg(adapter, A_SGE_TIMER_VALUE_0_AND_1);
11453 	sp->timer_val[0] = core_ticks_to_us(adapter, G_TIMERVALUE0(r)) * tscale;
11454 	sp->timer_val[1] = core_ticks_to_us(adapter, G_TIMERVALUE1(r)) * tscale;
11455 	r = t4_read_reg(adapter, A_SGE_TIMER_VALUE_2_AND_3);
11456 	sp->timer_val[2] = core_ticks_to_us(adapter, G_TIMERVALUE2(r)) * tscale;
11457 	sp->timer_val[3] = core_ticks_to_us(adapter, G_TIMERVALUE3(r)) * tscale;
11458 	r = t4_read_reg(adapter, A_SGE_TIMER_VALUE_4_AND_5);
11459 	sp->timer_val[4] = core_ticks_to_us(adapter, G_TIMERVALUE4(r)) * tscale;
11460 	sp->timer_val[5] = core_ticks_to_us(adapter, G_TIMERVALUE5(r)) * tscale;
11461 
11462 	r = t4_read_reg(adapter, A_SGE_CONM_CTRL);
11463 	sp->fl_starve_threshold = G_EGRTHRESHOLD(r) * 2 + 1;
11464 	if (is_t4(adapter))
11465 		sp->fl_starve_threshold2 = sp->fl_starve_threshold;
11466 	else if (is_t5(adapter))
11467 		sp->fl_starve_threshold2 = G_EGRTHRESHOLDPACKING(r) * 2 + 1;
11468 	else
11469 		sp->fl_starve_threshold2 = G_T6_EGRTHRESHOLDPACKING(r) * 2 + 1;
11470 
11471 	/* egress queues: log2 of # of doorbells per BAR2 page */
11472 	r = t4_read_reg(adapter, A_SGE_EGRESS_QUEUES_PER_PAGE_PF);
11473 	r >>= S_QUEUESPERPAGEPF0 +
11474 	    (S_QUEUESPERPAGEPF1 - S_QUEUESPERPAGEPF0) * adapter->pf;
11475 	sp->eq_s_qpp = r & M_QUEUESPERPAGEPF0;
11476 
11477 	/* ingress queues: log2 of # of doorbells per BAR2 page */
11478 	r = t4_read_reg(adapter, A_SGE_INGRESS_QUEUES_PER_PAGE_PF);
11479 	r >>= S_QUEUESPERPAGEPF0 +
11480 	    (S_QUEUESPERPAGEPF1 - S_QUEUESPERPAGEPF0) * adapter->pf;
11481 	sp->iq_s_qpp = r & M_QUEUESPERPAGEPF0;
11482 
11483 	r = t4_read_reg(adapter, A_SGE_HOST_PAGE_SIZE);
11484 	r >>= S_HOSTPAGESIZEPF0 +
11485 	    (S_HOSTPAGESIZEPF1 - S_HOSTPAGESIZEPF0) * adapter->pf;
11486 	sp->page_shift = (r & M_HOSTPAGESIZEPF0) + 10;
11487 
11488 	r = t4_read_reg(adapter, A_SGE_CONTROL);
11489 	sp->sge_control = r;
11490 	sp->spg_len = r & F_EGRSTATUSPAGESIZE ? 128 : 64;
11491 	sp->fl_pktshift = G_PKTSHIFT(r);
11492 	if (chip_id(adapter) <= CHELSIO_T5) {
11493 		sp->pad_boundary = 1 << (G_INGPADBOUNDARY(r) +
11494 		    X_INGPADBOUNDARY_SHIFT);
11495 	} else {
11496 		sp->pad_boundary = 1 << (G_INGPADBOUNDARY(r) +
11497 		    X_T6_INGPADBOUNDARY_SHIFT);
11498 	}
11499 	if (is_t4(adapter))
11500 		sp->pack_boundary = sp->pad_boundary;
11501 	else {
11502 		r = t4_read_reg(adapter, A_SGE_CONTROL2);
11503 		if (G_INGPACKBOUNDARY(r) == 0)
11504 			sp->pack_boundary = 16;
11505 		else
11506 			sp->pack_boundary = 1 << (G_INGPACKBOUNDARY(r) + 5);
11507 	}
11508 	for (i = 0; i < SGE_FLBUF_SIZES; i++)
11509 		sp->sge_fl_buffer_size[i] = t4_read_reg(adapter,
11510 		    A_SGE_FL_BUFFER_SIZE0 + (4 * i));
11511 
11512 	return 0;
11513 }
11514 
11515 /* Convert the LE's hardware hash mask to a shorter filter mask. */
11516 static inline uint16_t
hashmask_to_filtermask(struct adapter * adap,uint64_t hashmask,uint16_t filter_mode)11517 hashmask_to_filtermask(struct adapter *adap, uint64_t hashmask, uint16_t filter_mode)
11518 {
11519 	int first, last, i;
11520 	uint16_t filter_mask;
11521 	uint64_t mask;          /* field mask */
11522 
11523 
11524 	if (chip_id(adap) >= CHELSIO_T7) {
11525 		first = S_T7_FT_FIRST;
11526 		last = S_T7_FT_LAST;
11527 	} else {
11528 		first = S_FT_FIRST;
11529 		last = S_FT_LAST;
11530 	}
11531 
11532 	for (filter_mask = 0, i = first; i <= last; i++) {
11533 		if ((filter_mode & (1 << i)) == 0)
11534 			continue;
11535 		mask = (1 << t4_filter_field_width(adap, i)) - 1;
11536 		if ((hashmask & mask) == mask)
11537 			filter_mask |= 1 << i;
11538 		hashmask >>= t4_filter_field_width(adap, i);
11539 	}
11540 
11541 	return (filter_mask);
11542 }
11543 
11544 /*
11545  * Read and cache the adapter's compressed filter mode and ingress config.
11546  */
11547 static void
read_filter_mode_and_ingress_config(struct adapter * adap)11548 read_filter_mode_and_ingress_config(struct adapter *adap)
11549 {
11550 	int rc;
11551 	uint32_t v, param[2], val[2];
11552 	struct tp_params *tpp = &adap->params.tp;
11553 	uint64_t hash_mask;
11554 
11555 	param[0] = V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
11556 	    V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_FILTER) |
11557 	    V_FW_PARAMS_PARAM_Y(FW_PARAM_DEV_FILTER_MODE_MASK);
11558 	param[1] = V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
11559 	    V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_FILTER) |
11560 	    V_FW_PARAMS_PARAM_Y(FW_PARAM_DEV_FILTER_VNIC_MODE);
11561 	rc = -t4_query_params(adap, adap->mbox, adap->pf, 0, 2, param, val);
11562 	if (rc == 0) {
11563 		tpp->filter_mode = G_FW_PARAMS_PARAM_FILTER_MODE(val[0]);
11564 		tpp->filter_mask = G_FW_PARAMS_PARAM_FILTER_MASK(val[0]);
11565 		tpp->vnic_mode = val[1];
11566 	} else {
11567 		/*
11568 		 * Old firmware.  Read filter mode/mask and ingress config
11569 		 * straight from the hardware.
11570 		 */
11571 		t4_tp_pio_read(adap, &v, 1, A_TP_VLAN_PRI_MAP, true);
11572 		tpp->filter_mode = v & 0xffff;
11573 
11574 		hash_mask = 0;
11575 		if (chip_id(adap) > CHELSIO_T4) {
11576 			v = t4_read_reg(adap, LE_HASH_MASK_GEN_IPV4T5(3));
11577 			hash_mask = v;
11578 			v = t4_read_reg(adap, LE_HASH_MASK_GEN_IPV4T5(4));
11579 			hash_mask |= (u64)v << 32;
11580 		}
11581 		if (chip_id(adap) >= CHELSIO_T7) {
11582 			/*
11583 			 * This param came before T7 so T7+ firmwares should
11584 			 * always support this query.
11585 			 */
11586 			CH_WARN(adap, "query for filter mode/mask failed: %d\n",
11587 			    rc);
11588 		}
11589 		tpp->filter_mask = hashmask_to_filtermask(adap, hash_mask,
11590 		    tpp->filter_mode);
11591 
11592 		t4_tp_pio_read(adap, &v, 1, A_TP_INGRESS_CONFIG, true);
11593 		if (v & F_VNIC)
11594 			tpp->vnic_mode = FW_VNIC_MODE_PF_VF;
11595 		else
11596 			tpp->vnic_mode = FW_VNIC_MODE_OUTER_VLAN;
11597 	}
11598 
11599 	/*
11600 	 * Now that we have TP_VLAN_PRI_MAP cached, we can calculate the field
11601 	 * shift positions of several elements of the Compressed Filter Tuple
11602 	 * for this adapter which we need frequently ...
11603 	 */
11604 	if (chip_id(adap) >= CHELSIO_T7) {
11605 		tpp->ipsecidx_shift = t4_filter_field_shift(adap, F_IPSECIDX);
11606 		tpp->fcoe_shift = t4_filter_field_shift(adap, F_T7_FCOE);
11607 		tpp->port_shift = t4_filter_field_shift(adap, F_T7_PORT);
11608 		tpp->vnic_shift = t4_filter_field_shift(adap, F_T7_VNIC_ID);
11609 		tpp->vlan_shift = t4_filter_field_shift(adap, F_T7_VLAN);
11610 		tpp->tos_shift = t4_filter_field_shift(adap, F_T7_TOS);
11611 		tpp->protocol_shift = t4_filter_field_shift(adap, F_T7_PROTOCOL);
11612 		tpp->ethertype_shift = t4_filter_field_shift(adap, F_T7_ETHERTYPE);
11613 		tpp->macmatch_shift = t4_filter_field_shift(adap, F_T7_MACMATCH);
11614 		tpp->matchtype_shift = t4_filter_field_shift(adap, F_T7_MPSHITTYPE);
11615 		tpp->frag_shift = t4_filter_field_shift(adap, F_T7_FRAGMENTATION);
11616 		tpp->roce_shift = t4_filter_field_shift(adap, F_ROCE);
11617 		tpp->synonly_shift = t4_filter_field_shift(adap, F_SYNONLY);
11618 		tpp->tcpflags_shift = t4_filter_field_shift(adap, F_TCPFLAGS);
11619 	} else {
11620 		tpp->ipsecidx_shift = -1;
11621 		tpp->fcoe_shift = t4_filter_field_shift(adap, F_FCOE);
11622 		tpp->port_shift = t4_filter_field_shift(adap, F_PORT);
11623 		tpp->vnic_shift = t4_filter_field_shift(adap, F_VNIC_ID);
11624 		tpp->vlan_shift = t4_filter_field_shift(adap, F_VLAN);
11625 		tpp->tos_shift = t4_filter_field_shift(adap, F_TOS);
11626 		tpp->protocol_shift = t4_filter_field_shift(adap, F_PROTOCOL);
11627 		tpp->ethertype_shift = t4_filter_field_shift(adap, F_ETHERTYPE);
11628 		tpp->macmatch_shift = t4_filter_field_shift(adap, F_MACMATCH);
11629 		tpp->matchtype_shift = t4_filter_field_shift(adap, F_MPSHITTYPE);
11630 		tpp->frag_shift = t4_filter_field_shift(adap, F_FRAGMENTATION);
11631 		tpp->roce_shift = -1;
11632 		tpp->synonly_shift = -1;
11633 		tpp->tcpflags_shift = -1;
11634 	}
11635 }
11636 
11637 /**
11638  *      t4_init_tp_params - initialize adap->params.tp
11639  *      @adap: the adapter
11640  *
11641  *      Initialize various fields of the adapter's TP Parameters structure.
11642  */
t4_init_tp_params(struct adapter * adap)11643 int t4_init_tp_params(struct adapter *adap)
11644 {
11645 	u32 tx_len, rx_len, r, v;
11646 	struct tp_params *tpp = &adap->params.tp;
11647 
11648 	v = t4_read_reg(adap, A_TP_TIMER_RESOLUTION);
11649 	tpp->tre = G_TIMERRESOLUTION(v);
11650 	tpp->dack_re = G_DELAYEDACKRESOLUTION(v);
11651 
11652 	read_filter_mode_and_ingress_config(adap);
11653 
11654 	tpp->rx_pkt_encap = false;
11655 	tpp->lb_mode = 0;
11656 	tpp->lb_nchan = 1;
11657 	if (chip_id(adap) > CHELSIO_T5) {
11658 		v = t4_read_reg(adap, A_TP_OUT_CONFIG);
11659 		tpp->rx_pkt_encap = v & F_CRXPKTENC;
11660 		if (chip_id(adap) >= CHELSIO_T7) {
11661 			t4_tp_pio_read(adap, &v, 1, A_TP_CHANNEL_MAP, true);
11662 			tpp->lb_mode = G_T7_LB_MODE(v);
11663 			if (tpp->lb_mode == 1)
11664 				tpp->lb_nchan = 4;
11665 			else if (tpp->lb_mode == 2)
11666 				tpp->lb_nchan = 2;
11667 		}
11668 	}
11669 
11670 	rx_len = t4_read_reg(adap, A_TP_PMM_RX_PAGE_SIZE);
11671 	tx_len = t4_read_reg(adap, A_TP_PMM_TX_PAGE_SIZE);
11672 
11673 	r = t4_read_reg(adap, A_TP_PARA_REG2);
11674 	rx_len = min(rx_len, G_MAXRXDATA(r));
11675 	tx_len = min(tx_len, G_MAXRXDATA(r));
11676 
11677 	r = t4_read_reg(adap, A_TP_PARA_REG7);
11678 	v = min(G_PMMAXXFERLEN0(r), G_PMMAXXFERLEN1(r));
11679 	rx_len = min(rx_len, v);
11680 	tx_len = min(tx_len, v);
11681 
11682 	tpp->max_tx_pdu = tx_len;
11683 	tpp->max_rx_pdu = rx_len;
11684 
11685 	return 0;
11686 }
11687 
11688 /**
11689  *      t4_filter_field_width - returns the width of a filter field
11690  *      @adap: the adapter
11691  *      @filter_field: the filter field whose width is being requested
11692  *
11693  *      Return the shift position of a filter field within the Compressed
11694  *      Filter Tuple.  The filter field is specified via its selection bit
11695  *      within TP_VLAN_PRI_MAL (filter mode).  E.g. F_VLAN.
11696  */
t4_filter_field_width(const struct adapter * adap,int filter_field)11697 int t4_filter_field_width(const struct adapter *adap, int filter_field)
11698 {
11699 	const int nopt = adap->chip_params->filter_num_opt;
11700 	static const uint8_t width_t7[] = {
11701 		W_FT_IPSECIDX,
11702 		W_FT_FCOE,
11703 		W_FT_PORT,
11704 		W_FT_VNIC_ID,
11705 		W_FT_VLAN,
11706 		W_FT_TOS,
11707 		W_FT_PROTOCOL,
11708 		W_FT_ETHERTYPE,
11709 		W_FT_MACMATCH,
11710 		W_FT_MPSHITTYPE,
11711 		W_FT_FRAGMENTATION,
11712 		W_FT_ROCE,
11713 		W_FT_SYNONLY,
11714 		W_FT_TCPFLAGS
11715 	};
11716 	static const uint8_t width_t4[] = {
11717 		W_FT_FCOE,
11718 		W_FT_PORT,
11719 		W_FT_VNIC_ID,
11720 		W_FT_VLAN,
11721 		W_FT_TOS,
11722 		W_FT_PROTOCOL,
11723 		W_FT_ETHERTYPE,
11724 		W_FT_MACMATCH,
11725 		W_FT_MPSHITTYPE,
11726 		W_FT_FRAGMENTATION
11727 	};
11728 	const uint8_t *width = chip_id(adap) >= CHELSIO_T7 ? width_t7 : width_t4;
11729 
11730 	if (filter_field < 0 || filter_field >= nopt)
11731 		return (0);
11732 	return (width[filter_field]);
11733 }
11734 
11735 /**
11736  *      t4_filter_field_shift - calculate filter field shift
11737  *      @adap: the adapter
11738  *      @filter_sel: the desired field (from TP_VLAN_PRI_MAP bits)
11739  *
11740  *      Return the shift position of a filter field within the Compressed
11741  *      Filter Tuple.  The filter field is specified via its selection bit
11742  *      within TP_VLAN_PRI_MAL (filter mode).  E.g. F_VLAN.
11743  */
t4_filter_field_shift(const struct adapter * adap,int filter_sel)11744 int t4_filter_field_shift(const struct adapter *adap, int filter_sel)
11745 {
11746 	const unsigned int filter_mode = adap->params.tp.filter_mode;
11747 	unsigned int sel;
11748 	int field_shift;
11749 
11750 	if ((filter_mode & filter_sel) == 0)
11751 		return -1;
11752 
11753 	if (chip_id(adap) >= CHELSIO_T7) {
11754 		for (sel = 1, field_shift = 0; sel < filter_sel; sel <<= 1) {
11755 			switch (filter_mode & sel) {
11756 			case F_IPSECIDX:
11757 				field_shift += W_FT_IPSECIDX;
11758 				break;
11759 			case F_T7_FCOE:
11760 				field_shift += W_FT_FCOE;
11761 				break;
11762 			case F_T7_PORT:
11763 				field_shift += W_FT_PORT;
11764 				break;
11765 			case F_T7_VNIC_ID:
11766 				field_shift += W_FT_VNIC_ID;
11767 				break;
11768 			case F_T7_VLAN:
11769 				field_shift += W_FT_VLAN;
11770 				break;
11771 			case F_T7_TOS:
11772 				field_shift += W_FT_TOS;
11773 				break;
11774 			case F_T7_PROTOCOL:
11775 				field_shift += W_FT_PROTOCOL;
11776 				break;
11777 			case F_T7_ETHERTYPE:
11778 				field_shift += W_FT_ETHERTYPE;
11779 				break;
11780 			case F_T7_MACMATCH:
11781 				field_shift += W_FT_MACMATCH;
11782 				break;
11783 			case F_T7_MPSHITTYPE:
11784 				field_shift += W_FT_MPSHITTYPE;
11785 				break;
11786 			case F_T7_FRAGMENTATION:
11787 				field_shift += W_FT_FRAGMENTATION;
11788 				break;
11789 			case F_ROCE:
11790 				field_shift += W_FT_ROCE;
11791 				break;
11792 			case F_SYNONLY:
11793 				field_shift += W_FT_SYNONLY;
11794 				break;
11795 			case F_TCPFLAGS:
11796 				field_shift += W_FT_TCPFLAGS;
11797 				break;
11798 			}
11799 		}
11800 		return field_shift;
11801 	}
11802 
11803 	for (sel = 1, field_shift = 0; sel < filter_sel; sel <<= 1) {
11804 		switch (filter_mode & sel) {
11805 		case F_FCOE:
11806 			field_shift += W_FT_FCOE;
11807 			break;
11808 		case F_PORT:
11809 			field_shift += W_FT_PORT;
11810 			break;
11811 		case F_VNIC_ID:
11812 			field_shift += W_FT_VNIC_ID;
11813 			break;
11814 		case F_VLAN:
11815 			field_shift += W_FT_VLAN;
11816 			break;
11817 		case F_TOS:
11818 			field_shift += W_FT_TOS;
11819 			break;
11820 		case F_PROTOCOL:
11821 			field_shift += W_FT_PROTOCOL;
11822 			break;
11823 		case F_ETHERTYPE:
11824 			field_shift += W_FT_ETHERTYPE;
11825 			break;
11826 		case F_MACMATCH:
11827 			field_shift += W_FT_MACMATCH;
11828 			break;
11829 		case F_MPSHITTYPE:
11830 			field_shift += W_FT_MPSHITTYPE;
11831 			break;
11832 		case F_FRAGMENTATION:
11833 			field_shift += W_FT_FRAGMENTATION;
11834 			break;
11835 		}
11836 	}
11837 	return field_shift;
11838 }
11839 
t4_port_init(struct adapter * adap,int mbox,int pf,int vf,int port_id)11840 int t4_port_init(struct adapter *adap, int mbox, int pf, int vf, int port_id)
11841 {
11842 	u8 addr[6];
11843 	int ret, i, j;
11844 	struct port_info *p = adap2pinfo(adap, port_id);
11845 	u32 param, val;
11846 	struct vi_info *vi = &p->vi[0];
11847 
11848 	for (i = 0, j = -1; i <= p->port_id; i++) {
11849 		do {
11850 			j++;
11851 		} while ((adap->params.portvec & (1 << j)) == 0);
11852 	}
11853 
11854 	p->hw_port = j;
11855 	p->tx_chan = t4_get_tx_c_chan(adap, j);
11856 	p->rx_chan = t4_get_rx_c_chan(adap, j);
11857 	p->mps_bg_map = t4_get_mps_bg_map(adap, j);
11858 	p->rx_e_chan_map = t4_get_rx_e_chan_map(adap, j);
11859 
11860 	if (!(adap->flags & IS_VF) ||
11861 	    adap->params.vfres.r_caps & FW_CMD_CAP_PORT) {
11862  		t4_update_port_info(p);
11863 	}
11864 
11865 	ret = t4_alloc_vi(adap, mbox, j, pf, vf, 1, addr, &vi->rss_size,
11866 	    &vi->vfvld, &vi->vin);
11867 	if (ret < 0)
11868 		return ret;
11869 
11870 	vi->viid = ret;
11871 	t4_os_set_hw_addr(p, addr);
11872 
11873 	param = V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
11874 	    V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_RSSINFO) |
11875 	    V_FW_PARAMS_PARAM_YZ(vi->viid);
11876 	ret = t4_query_params(adap, mbox, pf, vf, 1, &param, &val);
11877 	if (ret)
11878 		vi->rss_base = 0xffff;
11879 	else {
11880 		/* MPASS((val >> 16) == rss_size); */
11881 		vi->rss_base = val & 0xffff;
11882 	}
11883 
11884 	return 0;
11885 }
11886 
t4_read_cimq_cfg_ibq_core(struct adapter * adap,u8 coreid,u32 qid,u16 * base,u16 * size,u16 * thres)11887 static void t4_read_cimq_cfg_ibq_core(struct adapter *adap, u8 coreid, u32 qid,
11888 				      u16 *base, u16 *size, u16 *thres)
11889 {
11890 	unsigned int v, m;
11891 
11892 	if (chip_id(adap) > CHELSIO_T6) {
11893 		v = F_T7_IBQSELECT | V_T7_QUENUMSELECT(qid) |
11894 		    V_CORESELECT(coreid);
11895 		/* value is in 512-byte units */
11896 		m = 512;
11897 	} else {
11898 		v = F_IBQSELECT | V_QUENUMSELECT(qid);
11899 		/* value is in 256-byte units */
11900 		m = 256;
11901 	}
11902 
11903 	t4_write_reg(adap, A_CIM_QUEUE_CONFIG_REF, v);
11904 	v = t4_read_reg(adap, A_CIM_QUEUE_CONFIG_CTRL);
11905 	if (base)
11906 		*base = G_CIMQBASE(v) * m;
11907 	if (size)
11908 		*size = G_CIMQSIZE(v) * m;
11909 	if (thres)
11910 		*thres = G_QUEFULLTHRSH(v) * 8; /* 8-byte unit */
11911 }
11912 
t4_read_cimq_cfg_obq_core(struct adapter * adap,u8 coreid,u32 qid,u16 * base,u16 * size)11913 static void t4_read_cimq_cfg_obq_core(struct adapter *adap, u8 coreid, u32 qid,
11914 				      u16 *base, u16 *size)
11915 {
11916 	unsigned int v, m;
11917 
11918 	if (chip_id(adap) > CHELSIO_T6) {
11919 		v = F_T7_OBQSELECT | V_T7_QUENUMSELECT(qid) |
11920 		    V_CORESELECT(coreid);
11921 		/* value is in 512-byte units */
11922 		m = 512;
11923 	} else {
11924 		v = F_OBQSELECT | V_QUENUMSELECT(qid);
11925 		/* value is in 256-byte units */
11926 		m = 256;
11927 	}
11928 
11929 	t4_write_reg(adap, A_CIM_QUEUE_CONFIG_REF, v);
11930 	v = t4_read_reg(adap, A_CIM_QUEUE_CONFIG_CTRL);
11931 	if (base)
11932 		*base = G_CIMQBASE(v) * m;
11933 	if (size)
11934 		*size = G_CIMQSIZE(v) * m;
11935 }
11936 
11937 /**
11938  *	t4_read_cimq_cfg_core - read CIM queue configuration on specific core
11939  *	@adap: the adapter
11940  *	@coreid: the uP coreid
11941  *	@base: holds the queue base addresses in bytes
11942  *	@size: holds the queue sizes in bytes
11943  *	@thres: holds the queue full thresholds in bytes
11944  *
11945  *	Returns the current configuration of the CIM queues, starting with
11946  *	the IBQs, then the OBQs, on a specific @coreid.
11947  */
t4_read_cimq_cfg_core(struct adapter * adap,u8 coreid,u16 * base,u16 * size,u16 * thres)11948 void t4_read_cimq_cfg_core(struct adapter *adap, u8 coreid, u16 *base,
11949 			   u16 *size, u16 *thres)
11950 {
11951 	unsigned int cim_num_ibq = adap->chip_params->cim_num_ibq;
11952 	unsigned int cim_num_obq = adap->chip_params->cim_num_obq;
11953 	unsigned int i;
11954 
11955 	for (i = 0; i < cim_num_ibq; i++, base++, size++, thres++)
11956 		t4_read_cimq_cfg_ibq_core(adap, coreid, i, base, size, thres);
11957 
11958 	for (i = 0; i < cim_num_obq; i++, base++, size++)
11959 		t4_read_cimq_cfg_obq_core(adap, coreid, i, base, size);
11960 }
11961 
t4_read_cim_ibq_data_core(struct adapter * adap,u8 coreid,u32 addr,u32 * data)11962 static int t4_read_cim_ibq_data_core(struct adapter *adap, u8 coreid, u32 addr,
11963 				     u32 *data)
11964 {
11965 	int ret, attempts;
11966 	unsigned int v;
11967 
11968 	/* It might take 3-10ms before the IBQ debug read access is allowed.
11969 	 * Wait for 1 Sec with a delay of 1 usec.
11970 	 */
11971 	attempts = 1000000;
11972 
11973 	if (chip_id(adap) > CHELSIO_T6)
11974 		v = V_T7_IBQDBGADDR(addr) | V_IBQDBGCORE(coreid);
11975 	else
11976 		v = V_IBQDBGADDR(addr);
11977 
11978 	t4_write_reg(adap, A_CIM_IBQ_DBG_CFG, v | F_IBQDBGEN);
11979 	ret = t4_wait_op_done(adap, A_CIM_IBQ_DBG_CFG, F_IBQDBGBUSY, 0,
11980 			      attempts, 1);
11981 	if (ret)
11982 		return ret;
11983 
11984 	*data = t4_read_reg(adap, A_CIM_IBQ_DBG_DATA);
11985 	return 0;
11986 }
11987 
11988 /**
11989  *	t4_read_cim_ibq_core - read the contents of a CIM inbound queue on
11990  *	specific core
11991  *	@adap: the adapter
11992  *	@coreid: the uP coreid
11993  *	@qid: the queue index
11994  *	@data: where to store the queue contents
11995  *	@n: capacity of @data in 32-bit words
11996  *
11997  *	Reads the contents of the selected CIM queue starting at address 0 up
11998  *	to the capacity of @data on a specific @coreid.  @n must be a multiple
11999  *	of 4.  Returns < 0 on error and the number of 32-bit words actually
12000  *	read on success.
12001  */
t4_read_cim_ibq_core(struct adapter * adap,u8 coreid,u32 qid,u32 * data,size_t n)12002 int t4_read_cim_ibq_core(struct adapter *adap, u8 coreid, u32 qid, u32 *data,
12003 			 size_t n)
12004 {
12005 	unsigned int cim_num_ibq = adap->chip_params->cim_num_ibq;
12006 	u16 i, addr, nwords;
12007 	int ret;
12008 
12009 	if (qid > (cim_num_ibq - 1) || (n & 3))
12010 		return -EINVAL;
12011 
12012 	t4_read_cimq_cfg_ibq_core(adap, coreid, qid, &addr, &nwords, NULL);
12013 	addr >>= sizeof(u16);
12014 	nwords >>= sizeof(u16);
12015 	if (n > nwords)
12016 		n = nwords;
12017 
12018 	for (i = 0; i < n; i++, addr++, data++) {
12019 		ret = t4_read_cim_ibq_data_core(adap, coreid, addr, data);
12020 		if (ret < 0)
12021 			return ret;
12022 	}
12023 
12024 	t4_write_reg(adap, A_CIM_IBQ_DBG_CFG, 0);
12025 	return i;
12026 }
12027 
t4_read_cim_obq_data_core(struct adapter * adap,u8 coreid,u32 addr,u32 * data)12028 static int t4_read_cim_obq_data_core(struct adapter *adap, u8 coreid, u32 addr,
12029 				     u32 *data)
12030 {
12031 	unsigned int v;
12032 	int ret;
12033 
12034 	if (chip_id(adap) > CHELSIO_T6)
12035 		v = V_T7_OBQDBGADDR(addr) | V_OBQDBGCORE(coreid);
12036 	else
12037 		v = V_OBQDBGADDR(addr);
12038 
12039 	t4_write_reg(adap, A_CIM_OBQ_DBG_CFG, v | F_OBQDBGEN);
12040 	ret = t4_wait_op_done(adap, A_CIM_OBQ_DBG_CFG, F_OBQDBGBUSY, 0, 2, 1);
12041 	if (ret)
12042 		return ret;
12043 
12044 	*data = t4_read_reg(adap, A_CIM_OBQ_DBG_DATA);
12045 	return 0;
12046 }
12047 
12048 /**
12049  *	t4_read_cim_obq_core - read the contents of a CIM outbound queue on
12050  *	specific core
12051  *	@adap: the adapter
12052  *	@coreid: the uP coreid
12053  *	@qid: the queue index
12054  *	@data: where to store the queue contents
12055  *	@n: capacity of @data in 32-bit words
12056  *
12057  *	Reads the contents of the selected CIM queue starting at address 0 up
12058  *	to the capacity of @data on specific @coreid.  @n must be a multiple
12059  *	of 4.  Returns < 0 on error and the number of 32-bit words actually
12060  *	read on success.
12061  */
t4_read_cim_obq_core(struct adapter * adap,u8 coreid,u32 qid,u32 * data,size_t n)12062 int t4_read_cim_obq_core(struct adapter *adap, u8 coreid, u32 qid, u32 *data,
12063 			 size_t n)
12064 {
12065 	unsigned int cim_num_obq = adap->chip_params->cim_num_obq;
12066 	u16 i, addr, nwords;
12067 	int ret;
12068 
12069 	if ((qid > (cim_num_obq - 1)) || (n & 3))
12070 		return -EINVAL;
12071 
12072 	t4_read_cimq_cfg_obq_core(adap, coreid, qid, &addr, &nwords);
12073 	addr >>= sizeof(u16);
12074 	nwords >>= sizeof(u16);
12075 	if (n > nwords)
12076 		n = nwords;
12077 
12078 	for (i = 0; i < n; i++, addr++, data++) {
12079 		ret = t4_read_cim_obq_data_core(adap, coreid, addr, data);
12080 		if (ret < 0)
12081 			return ret;
12082 	}
12083 
12084 	t4_write_reg(adap, A_CIM_OBQ_DBG_CFG, 0);
12085  	return i;
12086 }
12087 
12088 /**
12089  *	t4_cim_read_core - read a block from CIM internal address space
12090  *	of a control register group on specific core.
12091  *	@adap: the adapter
12092  *	@group: the control register group to select for read
12093  *	@coreid: the uP coreid
12094  *	@addr: the start address within the CIM address space
12095  *	@n: number of words to read
12096  *	@valp: where to store the result
12097  *
12098  *	Reads a block of 4-byte words from the CIM intenal address space
12099  *	of a control register @group on a specific @coreid.
12100  */
t4_cim_read_core(struct adapter * adap,u8 group,u8 coreid,unsigned int addr,unsigned int n,unsigned int * valp)12101 int t4_cim_read_core(struct adapter *adap, u8 group, u8 coreid,
12102 		     unsigned int addr, unsigned int n,
12103 		     unsigned int *valp)
12104 {
12105 	unsigned int hostbusy, v = 0;
12106 	int ret = 0;
12107 
12108 	if (chip_id(adap) > CHELSIO_T6) {
12109 		hostbusy = F_T7_HOSTBUSY;
12110 		v = V_HOSTGRPSEL(group) | V_HOSTCORESEL(coreid);
12111 	} else {
12112 		hostbusy = F_HOSTBUSY;
12113 	}
12114 
12115 	if (t4_read_reg(adap, A_CIM_HOST_ACC_CTRL) & hostbusy)
12116 		return -EBUSY;
12117 
12118 	for ( ; !ret && n--; addr += 4) {
12119 		t4_write_reg(adap, A_CIM_HOST_ACC_CTRL, addr | v);
12120 		ret = t4_wait_op_done(adap, A_CIM_HOST_ACC_CTRL, hostbusy,
12121 				      0, 5, 2);
12122 		if (!ret)
12123 			*valp++ = t4_read_reg(adap, A_CIM_HOST_ACC_DATA);
12124 	}
12125 
12126 	return ret;
12127 }
12128 
12129 /**
12130  *	t4_cim_write_core - write a block into CIM internal address space
12131  *	of a control register group on specific core.
12132  *	@adap: the adapter
12133  *	@group: the control register group to select for write
12134  *	@coreid: the uP coreid
12135  *	@addr: the start address within the CIM address space
12136  *	@n: number of words to write
12137  *	@valp: set of values to write
12138  *
12139  *	Writes a block of 4-byte words into the CIM intenal address space
12140  *	of a control register @group on a specific @coreid.
12141  */
t4_cim_write_core(struct adapter * adap,u8 group,u8 coreid,unsigned int addr,unsigned int n,const unsigned int * valp)12142 int t4_cim_write_core(struct adapter *adap, u8 group, u8 coreid,
12143 		      unsigned int addr, unsigned int n,
12144 		      const unsigned int *valp)
12145 {
12146 	unsigned int hostbusy, v;
12147 	int ret = 0;
12148 
12149 	if (chip_id(adap) > CHELSIO_T6) {
12150 		hostbusy = F_T7_HOSTBUSY;
12151 		v = F_T7_HOSTWRITE | V_HOSTGRPSEL(group) |
12152 		    V_HOSTCORESEL(coreid);
12153 	} else {
12154 		hostbusy = F_HOSTBUSY;
12155 		v = F_HOSTWRITE;
12156 	}
12157 
12158 	if (t4_read_reg(adap, A_CIM_HOST_ACC_CTRL) & hostbusy)
12159 		return -EBUSY;
12160 
12161 	for ( ; !ret && n--; addr += 4) {
12162 		t4_write_reg(adap, A_CIM_HOST_ACC_DATA, *valp++);
12163 		t4_write_reg(adap, A_CIM_HOST_ACC_CTRL, addr | v);
12164 		ret = t4_wait_op_done(adap, A_CIM_HOST_ACC_CTRL, hostbusy,
12165 				      0, 5, 2);
12166 	}
12167 
12168 	return ret;
12169 }
12170 
12171 /**
12172  *	t4_cim_read_la_core - read CIM LA capture buffer on specific core
12173  *	@adap: the adapter
12174  *	@coreid: uP coreid
12175  *	@la_buf: where to store the LA data
12176  *	@wrptr: the HW write pointer within the capture buffer
12177  *
12178  *	Reads the contents of the CIM LA buffer on a specific @coreid
12179  *	with the most recent entry at the end of the returned data
12180  *	and with the entry at @wrptr first. We try to leave the LA
12181  *	in the running state we find it in.
12182  */
t4_cim_read_la_core(struct adapter * adap,u8 coreid,u32 * la_buf,u32 * wrptr)12183 int t4_cim_read_la_core(struct adapter *adap, u8 coreid, u32 *la_buf,
12184 			u32 *wrptr)
12185 {
12186 	unsigned int cfg, val, idx;
12187 	int i, ret;
12188 
12189 	ret = t4_cim_read_core(adap, 1, coreid, A_UP_UP_DBG_LA_CFG, 1, &cfg);
12190 	if (ret)
12191 		return ret;
12192 
12193 	if (cfg & F_UPDBGLAEN) {	/* LA is running, freeze it */
12194 		val = 0;
12195 		ret = t4_cim_write_core(adap, 1, coreid, A_UP_UP_DBG_LA_CFG, 1,
12196 					&val);
12197 		if (ret)
12198 			return ret;
12199 	}
12200 
12201 	ret = t4_cim_read_core(adap, 1, coreid, A_UP_UP_DBG_LA_CFG, 1, &val);
12202 	if (ret)
12203 		goto restart;
12204 
12205 	idx = G_UPDBGLAWRPTR(val);
12206 	if (wrptr)
12207 		*wrptr = idx;
12208 
12209 	for (i = 0; i < adap->params.cim_la_size; i++) {
12210 		val = V_UPDBGLARDPTR(idx) | F_UPDBGLARDEN;
12211 		ret = t4_cim_write_core(adap, 1, coreid, A_UP_UP_DBG_LA_CFG, 1,
12212 					&val);
12213 		if (ret)
12214 			break;
12215 		ret = t4_cim_read_core(adap, 1, coreid, A_UP_UP_DBG_LA_CFG, 1,
12216 				       &val);
12217 		if (ret)
12218 			break;
12219 		if (val & F_UPDBGLARDEN) {
12220 			ret = -ETIMEDOUT;
12221 			break;
12222 		}
12223 		ret = t4_cim_read_core(adap, 1, coreid, A_UP_UP_DBG_LA_DATA, 1,
12224 				       &la_buf[i]);
12225 		if (ret)
12226 			break;
12227 
12228 		/* Bits 0-3 of UpDbgLaRdPtr can be between 0000 to 1001 to
12229 		 * identify the 32-bit portion of the full 312-bit data
12230 		 */
12231 		if ((chip_id(adap) > CHELSIO_T5) && (idx & 0xf) >= 9)
12232 			idx = (idx & 0xff0) + 0x10;
12233 		else
12234 			idx++;
12235 		/* address can't exceed 0xfff */
12236 		idx &= M_UPDBGLARDPTR;
12237 	}
12238 restart:
12239 	if (cfg & F_UPDBGLAEN) {
12240 		int r;
12241 
12242 		val = cfg & ~F_UPDBGLARDEN;
12243 		r = t4_cim_write_core(adap, 1, coreid, A_UP_UP_DBG_LA_CFG, 1,
12244 				      &val);
12245 		if (!ret)
12246 			ret = r;
12247 	}
12248 
12249 	return ret;
12250 }
12251 
12252 /**
12253  *	t4_tp_read_la - read TP LA capture buffer
12254  *	@adap: the adapter
12255  *	@la_buf: where to store the LA data
12256  *	@wrptr: the HW write pointer within the capture buffer
12257  *
12258  *	Reads the contents of the TP LA buffer with the most recent entry at
12259  *	the end	of the returned data and with the entry at @wrptr first.
12260  *	We leave the LA in the running state we find it in.
12261  */
t4_tp_read_la(struct adapter * adap,u64 * la_buf,unsigned int * wrptr)12262 void t4_tp_read_la(struct adapter *adap, u64 *la_buf, unsigned int *wrptr)
12263 {
12264 	bool last_incomplete;
12265 	unsigned int i, cfg, val, idx;
12266 
12267 	cfg = t4_read_reg(adap, A_TP_DBG_LA_CONFIG) & 0xffff;
12268 	if (cfg & F_DBGLAENABLE)			/* freeze LA */
12269 		t4_write_reg(adap, A_TP_DBG_LA_CONFIG,
12270 			     adap->params.tp.la_mask | (cfg ^ F_DBGLAENABLE));
12271 
12272 	val = t4_read_reg(adap, A_TP_DBG_LA_CONFIG);
12273 	idx = G_DBGLAWPTR(val);
12274 	last_incomplete = G_DBGLAMODE(val) >= 2 && (val & F_DBGLAWHLF) == 0;
12275 	if (last_incomplete)
12276 		idx = (idx + 1) & M_DBGLARPTR;
12277 	if (wrptr)
12278 		*wrptr = idx;
12279 
12280 	val &= 0xffff;
12281 	val &= ~V_DBGLARPTR(M_DBGLARPTR);
12282 	val |= adap->params.tp.la_mask;
12283 
12284 	for (i = 0; i < TPLA_SIZE; i++) {
12285 		t4_write_reg(adap, A_TP_DBG_LA_CONFIG, V_DBGLARPTR(idx) | val);
12286 		la_buf[i] = t4_read_reg64(adap, A_TP_DBG_LA_DATAL);
12287 		idx = (idx + 1) & M_DBGLARPTR;
12288 	}
12289 
12290 	/* Wipe out last entry if it isn't valid */
12291 	if (last_incomplete)
12292 		la_buf[TPLA_SIZE - 1] = ~0ULL;
12293 
12294 	if (cfg & F_DBGLAENABLE)		/* restore running state */
12295 		t4_write_reg(adap, A_TP_DBG_LA_CONFIG,
12296 			     cfg | adap->params.tp.la_mask);
12297 }
12298 
12299 /*
12300  * SGE Hung Ingress DMA Warning Threshold time and Warning Repeat Rate (in
12301  * seconds).  If we find one of the SGE Ingress DMA State Machines in the same
12302  * state for more than the Warning Threshold then we'll issue a warning about
12303  * a potential hang.  We'll repeat the warning as the SGE Ingress DMA Channel
12304  * appears to be hung every Warning Repeat second till the situation clears.
12305  * If the situation clears, we'll note that as well.
12306  */
12307 #define SGE_IDMA_WARN_THRESH 1
12308 #define SGE_IDMA_WARN_REPEAT 300
12309 
12310 /**
12311  *	t4_idma_monitor_init - initialize SGE Ingress DMA Monitor
12312  *	@adapter: the adapter
12313  *	@idma: the adapter IDMA Monitor state
12314  *
12315  *	Initialize the state of an SGE Ingress DMA Monitor.
12316  */
t4_idma_monitor_init(struct adapter * adapter,struct sge_idma_monitor_state * idma)12317 void t4_idma_monitor_init(struct adapter *adapter,
12318 			  struct sge_idma_monitor_state *idma)
12319 {
12320 	/* Initialize the state variables for detecting an SGE Ingress DMA
12321 	 * hang.  The SGE has internal counters which count up on each clock
12322 	 * tick whenever the SGE finds its Ingress DMA State Engines in the
12323 	 * same state they were on the previous clock tick.  The clock used is
12324 	 * the Core Clock so we have a limit on the maximum "time" they can
12325 	 * record; typically a very small number of seconds.  For instance,
12326 	 * with a 600MHz Core Clock, we can only count up to a bit more than
12327 	 * 7s.  So we'll synthesize a larger counter in order to not run the
12328 	 * risk of having the "timers" overflow and give us the flexibility to
12329 	 * maintain a Hung SGE State Machine of our own which operates across
12330 	 * a longer time frame.
12331 	 */
12332 	idma->idma_1s_thresh = core_ticks_per_usec(adapter) * 1000000; /* 1s */
12333 	idma->idma_stalled[0] = idma->idma_stalled[1] = 0;
12334 }
12335 
12336 /**
12337  *	t4_idma_monitor - monitor SGE Ingress DMA state
12338  *	@adapter: the adapter
12339  *	@idma: the adapter IDMA Monitor state
12340  *	@hz: number of ticks/second
12341  *	@ticks: number of ticks since the last IDMA Monitor call
12342  */
t4_idma_monitor(struct adapter * adapter,struct sge_idma_monitor_state * idma,int hz,int ticks)12343 void t4_idma_monitor(struct adapter *adapter,
12344 		     struct sge_idma_monitor_state *idma,
12345 		     int hz, int ticks)
12346 {
12347 	int i, idma_same_state_cnt[2];
12348 
12349 	 /* Read the SGE Debug Ingress DMA Same State Count registers.  These
12350 	  * are counters inside the SGE which count up on each clock when the
12351 	  * SGE finds its Ingress DMA State Engines in the same states they
12352 	  * were in the previous clock.  The counters will peg out at
12353 	  * 0xffffffff without wrapping around so once they pass the 1s
12354 	  * threshold they'll stay above that till the IDMA state changes.
12355 	  */
12356 	t4_write_reg(adapter, A_SGE_DEBUG_INDEX, 13);
12357 	idma_same_state_cnt[0] = t4_read_reg(adapter, A_SGE_DEBUG_DATA_HIGH);
12358 	idma_same_state_cnt[1] = t4_read_reg(adapter, A_SGE_DEBUG_DATA_LOW);
12359 
12360 	for (i = 0; i < 2; i++) {
12361 		u32 debug0, debug11;
12362 
12363 		/* If the Ingress DMA Same State Counter ("timer") is less
12364 		 * than 1s, then we can reset our synthesized Stall Timer and
12365 		 * continue.  If we have previously emitted warnings about a
12366 		 * potential stalled Ingress Queue, issue a note indicating
12367 		 * that the Ingress Queue has resumed forward progress.
12368 		 */
12369 		if (idma_same_state_cnt[i] < idma->idma_1s_thresh) {
12370 			if (idma->idma_stalled[i] >= SGE_IDMA_WARN_THRESH*hz)
12371 				CH_WARN(adapter, "SGE idma%d, queue %u, "
12372 					"resumed after %d seconds\n",
12373 					i, idma->idma_qid[i],
12374 					idma->idma_stalled[i]/hz);
12375 			idma->idma_stalled[i] = 0;
12376 			continue;
12377 		}
12378 
12379 		/* Synthesize an SGE Ingress DMA Same State Timer in the Hz
12380 		 * domain.  The first time we get here it'll be because we
12381 		 * passed the 1s Threshold; each additional time it'll be
12382 		 * because the RX Timer Callback is being fired on its regular
12383 		 * schedule.
12384 		 *
12385 		 * If the stall is below our Potential Hung Ingress Queue
12386 		 * Warning Threshold, continue.
12387 		 */
12388 		if (idma->idma_stalled[i] == 0) {
12389 			idma->idma_stalled[i] = hz;
12390 			idma->idma_warn[i] = 0;
12391 		} else {
12392 			idma->idma_stalled[i] += ticks;
12393 			idma->idma_warn[i] -= ticks;
12394 		}
12395 
12396 		if (idma->idma_stalled[i] < SGE_IDMA_WARN_THRESH*hz)
12397 			continue;
12398 
12399 		/* We'll issue a warning every SGE_IDMA_WARN_REPEAT seconds.
12400 		 */
12401 		if (idma->idma_warn[i] > 0)
12402 			continue;
12403 		idma->idma_warn[i] = SGE_IDMA_WARN_REPEAT*hz;
12404 
12405 		/* Read and save the SGE IDMA State and Queue ID information.
12406 		 * We do this every time in case it changes across time ...
12407 		 * can't be too careful ...
12408 		 */
12409 		t4_write_reg(adapter, A_SGE_DEBUG_INDEX, 0);
12410 		debug0 = t4_read_reg(adapter, A_SGE_DEBUG_DATA_LOW);
12411 		idma->idma_state[i] = (debug0 >> (i * 9)) & 0x3f;
12412 
12413 		t4_write_reg(adapter, A_SGE_DEBUG_INDEX, 11);
12414 		debug11 = t4_read_reg(adapter, A_SGE_DEBUG_DATA_LOW);
12415 		idma->idma_qid[i] = (debug11 >> (i * 16)) & 0xffff;
12416 
12417 		CH_WARN(adapter, "SGE idma%u, queue %u, potentially stuck in "
12418 			" state %u for %d seconds (debug0=%#x, debug11=%#x)\n",
12419 			i, idma->idma_qid[i], idma->idma_state[i],
12420 			idma->idma_stalled[i]/hz,
12421 			debug0, debug11);
12422 		t4_sge_decode_idma_state(adapter, idma->idma_state[i]);
12423 	}
12424 }
12425 
12426 /**
12427  *     t4_set_vf_mac - Set MAC address for the specified VF
12428  *     @adapter: The adapter
12429  *     @pf: the PF used to instantiate the VFs
12430  *     @vf: one of the VFs instantiated by the specified PF
12431  *     @naddr: the number of MAC addresses
12432  *     @addr: the MAC address(es) to be set to the specified VF
12433  */
t4_set_vf_mac(struct adapter * adapter,unsigned int pf,unsigned int vf,unsigned int naddr,u8 * addr)12434 int t4_set_vf_mac(struct adapter *adapter, unsigned int pf, unsigned int vf,
12435 		  unsigned int naddr, u8 *addr)
12436 {
12437 	struct fw_acl_mac_cmd cmd;
12438 
12439 	memset(&cmd, 0, sizeof(cmd));
12440 	cmd.op_to_vfn = cpu_to_be32(V_FW_CMD_OP(FW_ACL_MAC_CMD) |
12441 				    F_FW_CMD_REQUEST |
12442 				    F_FW_CMD_WRITE |
12443 				    V_FW_ACL_MAC_CMD_PFN(pf) |
12444 				    V_FW_ACL_MAC_CMD_VFN(vf));
12445 
12446 	/* Note: Do not enable the ACL */
12447 	cmd.en_to_len16 = cpu_to_be32((unsigned int)FW_LEN16(cmd));
12448 	cmd.nmac = naddr;
12449 
12450 	switch (pf) {
12451 	case 3:
12452 		memcpy(cmd.macaddr3, addr, sizeof(cmd.macaddr3));
12453 		break;
12454 	case 2:
12455 		memcpy(cmd.macaddr2, addr, sizeof(cmd.macaddr2));
12456 		break;
12457 	case 1:
12458 		memcpy(cmd.macaddr1, addr, sizeof(cmd.macaddr1));
12459 		break;
12460 	case 0:
12461 		memcpy(cmd.macaddr0, addr, sizeof(cmd.macaddr0));
12462 		break;
12463 	}
12464 
12465 	return t4_wr_mbox(adapter, adapter->mbox, &cmd, sizeof(cmd), &cmd);
12466 }
12467 
12468 /**
12469  *	t4_read_pace_tbl - read the pace table
12470  *	@adap: the adapter
12471  *	@pace_vals: holds the returned values
12472  *
12473  *	Returns the values of TP's pace table in microseconds.
12474  */
t4_read_pace_tbl(struct adapter * adap,unsigned int pace_vals[NTX_SCHED])12475 void t4_read_pace_tbl(struct adapter *adap, unsigned int pace_vals[NTX_SCHED])
12476 {
12477 	unsigned int i, v;
12478 
12479 	for (i = 0; i < NTX_SCHED; i++) {
12480 		t4_write_reg(adap, A_TP_PACE_TABLE, 0xffff0000 + i);
12481 		v = t4_read_reg(adap, A_TP_PACE_TABLE);
12482 		pace_vals[i] = dack_ticks_to_usec(adap, v);
12483 	}
12484 }
12485 
12486 /**
12487  *	t4_get_tx_sched - get the configuration of a Tx HW traffic scheduler
12488  *	@adap: the adapter
12489  *	@sched: the scheduler index
12490  *	@kbps: the byte rate in Kbps
12491  *	@ipg: the interpacket delay in tenths of nanoseconds
12492  *
12493  *	Return the current configuration of a HW Tx scheduler.
12494  */
t4_get_tx_sched(struct adapter * adap,unsigned int sched,unsigned int * kbps,unsigned int * ipg,bool sleep_ok)12495 void t4_get_tx_sched(struct adapter *adap, unsigned int sched, unsigned int *kbps,
12496 		     unsigned int *ipg, bool sleep_ok)
12497 {
12498 	unsigned int v, addr, bpt, cpt;
12499 
12500 	if (kbps) {
12501 		addr = A_TP_TX_MOD_Q1_Q0_RATE_LIMIT - sched / 2;
12502 		t4_tp_tm_pio_read(adap, &v, 1, addr, sleep_ok);
12503 		if (sched & 1)
12504 			v >>= 16;
12505 		bpt = (v >> 8) & 0xff;
12506 		cpt = v & 0xff;
12507 		if (!cpt)
12508 			*kbps = 0;	/* scheduler disabled */
12509 		else {
12510 			v = (adap->params.vpd.cclk * 1000) / cpt; /* ticks/s */
12511 			*kbps = (v * bpt) / 125;
12512 		}
12513 	}
12514 	if (ipg) {
12515 		addr = A_TP_TX_MOD_Q1_Q0_TIMER_SEPARATOR - sched / 2;
12516 		t4_tp_tm_pio_read(adap, &v, 1, addr, sleep_ok);
12517 		if (sched & 1)
12518 			v >>= 16;
12519 		v &= 0xffff;
12520 		*ipg = (10000 * v) / core_ticks_per_usec(adap);
12521 	}
12522 }
12523 
12524 /**
12525  *	t4_load_cfg - download config file
12526  *	@adap: the adapter
12527  *	@cfg_data: the cfg text file to write
12528  *	@size: text file size
12529  *
12530  *	Write the supplied config text file to the card's serial flash.
12531  */
t4_load_cfg(struct adapter * adap,const u8 * cfg_data,unsigned int size)12532 int t4_load_cfg(struct adapter *adap, const u8 *cfg_data, unsigned int size)
12533 {
12534 	int ret, i, n, cfg_addr;
12535 	unsigned int addr, len;
12536 	unsigned int flash_cfg_start_sec;
12537 
12538 	cfg_addr = t4_flash_cfg_addr(adap, &len);
12539 	if (cfg_addr < 0)
12540 		return cfg_addr;
12541 
12542 	if (size > len) {
12543 		CH_ERR(adap, "cfg file too large, max is %u bytes\n", len);
12544 		return -EFBIG;
12545 	}
12546 
12547 	flash_cfg_start_sec = cfg_addr / SF_SEC_SIZE;
12548 	i = DIV_ROUND_UP(len, SF_SEC_SIZE);
12549 	ret = t4_flash_erase_sectors(adap, flash_cfg_start_sec,
12550 				     flash_cfg_start_sec + i - 1);
12551 	/*
12552 	 * If size == 0 then we're simply erasing the FLASH sectors associated
12553 	 * with the on-adapter Firmware Configuration File.
12554 	 */
12555 	if (ret || size == 0)
12556 		goto out;
12557 
12558 	/* this will write to the flash up to SF_PAGE_SIZE at a time */
12559 	addr = cfg_addr;
12560 	for (i = 0; i < size; i += SF_PAGE_SIZE) {
12561 		n = min(size - i, SF_PAGE_SIZE);
12562 		ret = t4_write_flash(adap, addr, n, cfg_data, 1);
12563 		if (ret)
12564 			goto out;
12565 		addr += SF_PAGE_SIZE;
12566 		cfg_data += SF_PAGE_SIZE;
12567 	}
12568 
12569 out:
12570 	if (ret)
12571 		CH_ERR(adap, "config file %s failed %d\n",
12572 		       (size == 0 ? "clear" : "download"), ret);
12573 	return ret;
12574 }
12575 
12576 /**
12577  *	t5_fw_init_extern_mem - initialize the external memory
12578  *	@adap: the adapter
12579  *
12580  *	Initializes the external memory on T5.
12581  */
t5_fw_init_extern_mem(struct adapter * adap)12582 int t5_fw_init_extern_mem(struct adapter *adap)
12583 {
12584 	u32 params[1], val[1];
12585 	int ret;
12586 
12587 	if (!is_t5(adap))
12588 		return 0;
12589 
12590 	val[0] = 0xff; /* Initialize all MCs */
12591 	params[0] = (V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
12592 			V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_MCINIT));
12593 	ret = t4_set_params_timeout(adap, adap->mbox, adap->pf, 0, 1, params, val,
12594 			FW_CMD_MAX_TIMEOUT);
12595 
12596 	return ret;
12597 }
12598 
12599 /* BIOS boot headers */
12600 typedef struct pci_expansion_rom_header {
12601 	u8	signature[2]; /* ROM Signature. Should be 0xaa55 */
12602 	u8	reserved[22]; /* Reserved per processor Architecture data */
12603 	u8	pcir_offset[2]; /* Offset to PCI Data Structure */
12604 } pci_exp_rom_header_t; /* PCI_EXPANSION_ROM_HEADER */
12605 
12606 /* Legacy PCI Expansion ROM Header */
12607 typedef struct legacy_pci_expansion_rom_header {
12608 	u8	signature[2]; /* ROM Signature. Should be 0xaa55 */
12609 	u8	size512; /* Current Image Size in units of 512 bytes */
12610 	u8	initentry_point[4];
12611 	u8	cksum; /* Checksum computed on the entire Image */
12612 	u8	reserved[16]; /* Reserved */
12613 	u8	pcir_offset[2]; /* Offset to PCI Data Struture */
12614 } legacy_pci_exp_rom_header_t; /* LEGACY_PCI_EXPANSION_ROM_HEADER */
12615 
12616 /* EFI PCI Expansion ROM Header */
12617 typedef struct efi_pci_expansion_rom_header {
12618 	u8	signature[2]; // ROM signature. The value 0xaa55
12619 	u8	initialization_size[2]; /* Units 512. Includes this header */
12620 	u8	efi_signature[4]; /* Signature from EFI image header. 0x0EF1 */
12621 	u8	efi_subsystem[2]; /* Subsystem value for EFI image header */
12622 	u8	efi_machine_type[2]; /* Machine type from EFI image header */
12623 	u8	compression_type[2]; /* Compression type. */
12624 		/*
12625 		 * Compression type definition
12626 		 * 0x0: uncompressed
12627 		 * 0x1: Compressed
12628 		 * 0x2-0xFFFF: Reserved
12629 		 */
12630 	u8	reserved[8]; /* Reserved */
12631 	u8	efi_image_header_offset[2]; /* Offset to EFI Image */
12632 	u8	pcir_offset[2]; /* Offset to PCI Data Structure */
12633 } efi_pci_exp_rom_header_t; /* EFI PCI Expansion ROM Header */
12634 
12635 /* PCI Data Structure Format */
12636 typedef struct pcir_data_structure { /* PCI Data Structure */
12637 	u8	signature[4]; /* Signature. The string "PCIR" */
12638 	u8	vendor_id[2]; /* Vendor Identification */
12639 	u8	device_id[2]; /* Device Identification */
12640 	u8	vital_product[2]; /* Pointer to Vital Product Data */
12641 	u8	length[2]; /* PCIR Data Structure Length */
12642 	u8	revision; /* PCIR Data Structure Revision */
12643 	u8	class_code[3]; /* Class Code */
12644 	u8	image_length[2]; /* Image Length. Multiple of 512B */
12645 	u8	code_revision[2]; /* Revision Level of Code/Data */
12646 	u8	code_type; /* Code Type. */
12647 		/*
12648 		 * PCI Expansion ROM Code Types
12649 		 * 0x00: Intel IA-32, PC-AT compatible. Legacy
12650 		 * 0x01: Open Firmware standard for PCI. FCODE
12651 		 * 0x02: Hewlett-Packard PA RISC. HP reserved
12652 		 * 0x03: EFI Image. EFI
12653 		 * 0x04-0xFF: Reserved.
12654 		 */
12655 	u8	indicator; /* Indicator. Identifies the last image in the ROM */
12656 	u8	reserved[2]; /* Reserved */
12657 } pcir_data_t; /* PCI__DATA_STRUCTURE */
12658 
12659 /* BOOT constants */
12660 enum {
12661 	BOOT_FLASH_BOOT_ADDR = 0x0,/* start address of boot image in flash */
12662 	BOOT_SIGNATURE = 0xaa55,   /* signature of BIOS boot ROM */
12663 	BOOT_SIZE_INC = 512,       /* image size measured in 512B chunks */
12664 	BOOT_MIN_SIZE = sizeof(pci_exp_rom_header_t), /* basic header */
12665 	BOOT_MAX_SIZE = 1024*BOOT_SIZE_INC, /* 1 byte * length increment  */
12666 	VENDOR_ID = 0x1425, /* Vendor ID */
12667 	PCIR_SIGNATURE = 0x52494350 /* PCIR signature */
12668 };
12669 
12670 /*
12671  *	modify_device_id - Modifies the device ID of the Boot BIOS image
12672  *	@adatper: the device ID to write.
12673  *	@boot_data: the boot image to modify.
12674  *
12675  *	Write the supplied device ID to the boot BIOS image.
12676  */
modify_device_id(int device_id,u8 * boot_data)12677 static void modify_device_id(int device_id, u8 *boot_data)
12678 {
12679 	legacy_pci_exp_rom_header_t *header;
12680 	pcir_data_t *pcir_header;
12681 	u32 cur_header = 0;
12682 
12683 	/*
12684 	 * Loop through all chained images and change the device ID's
12685 	 */
12686 	while (1) {
12687 		header = (legacy_pci_exp_rom_header_t *) &boot_data[cur_header];
12688 		pcir_header = (pcir_data_t *) &boot_data[cur_header +
12689 			      le16_to_cpu(*(u16*)header->pcir_offset)];
12690 
12691 		/*
12692 		 * Only modify the Device ID if code type is Legacy or HP.
12693 		 * 0x00: Okay to modify
12694 		 * 0x01: FCODE. Do not be modify
12695 		 * 0x03: Okay to modify
12696 		 * 0x04-0xFF: Do not modify
12697 		 */
12698 		if (pcir_header->code_type == 0x00) {
12699 			u8 csum = 0;
12700 			int i;
12701 
12702 			/*
12703 			 * Modify Device ID to match current adatper
12704 			 */
12705 			*(u16*) pcir_header->device_id = device_id;
12706 
12707 			/*
12708 			 * Set checksum temporarily to 0.
12709 			 * We will recalculate it later.
12710 			 */
12711 			header->cksum = 0x0;
12712 
12713 			/*
12714 			 * Calculate and update checksum
12715 			 */
12716 			for (i = 0; i < (header->size512 * 512); i++)
12717 				csum += (u8)boot_data[cur_header + i];
12718 
12719 			/*
12720 			 * Invert summed value to create the checksum
12721 			 * Writing new checksum value directly to the boot data
12722 			 */
12723 			boot_data[cur_header + 7] = -csum;
12724 
12725 		} else if (pcir_header->code_type == 0x03) {
12726 
12727 			/*
12728 			 * Modify Device ID to match current adatper
12729 			 */
12730 			*(u16*) pcir_header->device_id = device_id;
12731 
12732 		}
12733 
12734 
12735 		/*
12736 		 * Check indicator element to identify if this is the last
12737 		 * image in the ROM.
12738 		 */
12739 		if (pcir_header->indicator & 0x80)
12740 			break;
12741 
12742 		/*
12743 		 * Move header pointer up to the next image in the ROM.
12744 		 */
12745 		cur_header += header->size512 * 512;
12746 	}
12747 }
12748 
12749 /*
12750  *	t4_load_boot - download boot flash
12751  *	@adapter: the adapter
12752  *	@boot_data: the boot image to write
12753  *	@boot_addr: offset in flash to write boot_data
12754  *	@size: image size
12755  *
12756  *	Write the supplied boot image to the card's serial flash.
12757  *	The boot image has the following sections: a 28-byte header and the
12758  *	boot image.
12759  */
t4_load_boot(struct adapter * adap,u8 * boot_data,unsigned int boot_addr,unsigned int size)12760 int t4_load_boot(struct adapter *adap, u8 *boot_data,
12761 		 unsigned int boot_addr, unsigned int size)
12762 {
12763 	pci_exp_rom_header_t *header;
12764 	int pcir_offset ;
12765 	pcir_data_t *pcir_header;
12766 	int ret, addr;
12767 	uint16_t device_id;
12768 	unsigned int i, start, len;
12769 	unsigned int boot_sector = boot_addr * 1024;
12770 
12771 	/*
12772 	 * Make sure the boot image does not exceed its available space.
12773 	 */
12774 	len = 0;
12775 	start = t4_flash_loc_start(adap, FLASH_LOC_BOOT_AREA, &len);
12776 	if (boot_sector + size > start + len) {
12777 		CH_ERR(adap, "boot data is larger than available BOOT area\n");
12778 		return -EFBIG;
12779 	}
12780 
12781 	/*
12782 	 * The boot sector is comprised of the Expansion-ROM boot, iSCSI boot,
12783 	 * and Boot configuration data sections. These 3 boot sections span
12784 	 * the entire FLASH_LOC_BOOT_AREA.
12785 	 */
12786 	i = DIV_ROUND_UP(size ? size : len, SF_SEC_SIZE);
12787 	ret = t4_flash_erase_sectors(adap, boot_sector >> 16,
12788 				     (boot_sector >> 16) + i - 1);
12789 
12790 	/*
12791 	 * If size == 0 then we're simply erasing the FLASH sectors associated
12792 	 * with the on-adapter option ROM file
12793 	 */
12794 	if (ret || (size == 0))
12795 		goto out;
12796 
12797 	/* Get boot header */
12798 	header = (pci_exp_rom_header_t *)boot_data;
12799 	pcir_offset = le16_to_cpu(*(u16 *)header->pcir_offset);
12800 	/* PCIR Data Structure */
12801 	pcir_header = (pcir_data_t *) &boot_data[pcir_offset];
12802 
12803 	/*
12804 	 * Perform some primitive sanity testing to avoid accidentally
12805 	 * writing garbage over the boot sectors.  We ought to check for
12806 	 * more but it's not worth it for now ...
12807 	 */
12808 	if (size < BOOT_MIN_SIZE || size > BOOT_MAX_SIZE) {
12809 		CH_ERR(adap, "boot image too small/large\n");
12810 		return -EFBIG;
12811 	}
12812 
12813 #ifndef CHELSIO_T4_DIAGS
12814 	/*
12815 	 * Check BOOT ROM header signature
12816 	 */
12817 	if (le16_to_cpu(*(u16*)header->signature) != BOOT_SIGNATURE ) {
12818 		CH_ERR(adap, "Boot image missing signature\n");
12819 		return -EINVAL;
12820 	}
12821 
12822 	/*
12823 	 * Check PCI header signature
12824 	 */
12825 	if (le32_to_cpu(*(u32*)pcir_header->signature) != PCIR_SIGNATURE) {
12826 		CH_ERR(adap, "PCI header missing signature\n");
12827 		return -EINVAL;
12828 	}
12829 
12830 	/*
12831 	 * Check Vendor ID matches Chelsio ID
12832 	 */
12833 	if (le16_to_cpu(*(u16*)pcir_header->vendor_id) != VENDOR_ID) {
12834 		CH_ERR(adap, "Vendor ID missing signature\n");
12835 		return -EINVAL;
12836 	}
12837 #endif
12838 
12839 	/*
12840 	 * Retrieve adapter's device ID
12841 	 */
12842 	t4_os_pci_read_cfg2(adap, PCI_DEVICE_ID, &device_id);
12843 	/* Want to deal with PF 0 so I strip off PF 4 indicator */
12844 	device_id = device_id & 0xf0ff;
12845 
12846 	/*
12847 	 * Check PCIE Device ID
12848 	 */
12849 	if (le16_to_cpu(*(u16*)pcir_header->device_id) != device_id) {
12850 		/*
12851 		 * Change the device ID in the Boot BIOS image to match
12852 		 * the Device ID of the current adapter.
12853 		 */
12854 		modify_device_id(device_id, boot_data);
12855 	}
12856 
12857 	/*
12858 	 * Skip over the first SF_PAGE_SIZE worth of data and write it after
12859 	 * we finish copying the rest of the boot image. This will ensure
12860 	 * that the BIOS boot header will only be written if the boot image
12861 	 * was written in full.
12862 	 */
12863 	addr = boot_sector;
12864 	for (size -= SF_PAGE_SIZE; size; size -= SF_PAGE_SIZE) {
12865 		addr += SF_PAGE_SIZE;
12866 		boot_data += SF_PAGE_SIZE;
12867 		ret = t4_write_flash(adap, addr, SF_PAGE_SIZE, boot_data, 0);
12868 		if (ret)
12869 			goto out;
12870 	}
12871 
12872 	ret = t4_write_flash(adap, boot_sector, SF_PAGE_SIZE,
12873 			     (const u8 *)header, 0);
12874 
12875 out:
12876 	if (ret)
12877 		CH_ERR(adap, "boot image download failed, error %d\n", ret);
12878 	return ret;
12879 }
12880 
12881 /*
12882  *	t4_flash_bootcfg_addr - return the address of the flash optionrom configuration
12883  *	@adapter: the adapter
12884  *
12885  *	Return the address within the flash where the OptionROM Configuration
12886  *	is stored, or an error if the device FLASH is too small to contain
12887  *	a OptionROM Configuration.
12888  */
t4_flash_bootcfg_addr(struct adapter * adapter,unsigned int * lenp)12889 static int t4_flash_bootcfg_addr(struct adapter *adapter, unsigned int *lenp)
12890 {
12891 	unsigned int len = 0;
12892 	const int start = t4_flash_loc_start(adapter, FLASH_LOC_BOOTCFG, &len);
12893 
12894 	/*
12895 	 * If the device FLASH isn't large enough to hold a Firmware
12896 	 * Configuration File, return an error.
12897 	 */
12898 	if (adapter->params.sf_size < start + len)
12899 		return -ENOSPC;
12900 	if (lenp != NULL)
12901 		*lenp = len;
12902 	return (start);
12903 }
12904 
t4_load_bootcfg(struct adapter * adap,const u8 * cfg_data,unsigned int size)12905 int t4_load_bootcfg(struct adapter *adap,const u8 *cfg_data, unsigned int size)
12906 {
12907 	int ret, i, n, cfg_addr;
12908 	unsigned int addr, len;
12909 	unsigned int flash_cfg_start_sec;
12910 
12911 	cfg_addr = t4_flash_bootcfg_addr(adap, &len);
12912 	if (cfg_addr < 0)
12913 		return cfg_addr;
12914 
12915 	if (size > len) {
12916 		CH_ERR(adap, "bootcfg file too large, max is %u bytes\n", len);
12917 		return -EFBIG;
12918 	}
12919 
12920 	flash_cfg_start_sec = cfg_addr / SF_SEC_SIZE;
12921 	i = DIV_ROUND_UP(len, SF_SEC_SIZE);
12922 	ret = t4_flash_erase_sectors(adap, flash_cfg_start_sec,
12923 					flash_cfg_start_sec + i - 1);
12924 
12925 	/*
12926 	 * If size == 0 then we're simply erasing the FLASH sectors associated
12927 	 * with the on-adapter OptionROM Configuration File.
12928 	 */
12929 	if (ret || size == 0)
12930 		goto out;
12931 
12932 	/* this will write to the flash up to SF_PAGE_SIZE at a time */
12933 	addr = cfg_addr;
12934 	for (i = 0; i < size; i += SF_PAGE_SIZE) {
12935 		n = min(size - i, SF_PAGE_SIZE);
12936 		ret = t4_write_flash(adap, addr, n, cfg_data, 0);
12937 		if (ret)
12938 			goto out;
12939 		addr += SF_PAGE_SIZE;
12940 		cfg_data += SF_PAGE_SIZE;
12941 	}
12942 
12943 out:
12944 	if (ret)
12945 		CH_ERR(adap, "boot config data %s failed %d\n",
12946 				(size == 0 ? "clear" : "download"), ret);
12947 	return ret;
12948 }
12949 
12950 /**
12951  *	t4_set_filter_cfg - set up filter mode/mask and ingress config.
12952  *	@adap: the adapter
12953  *	@mode: a bitmap selecting which optional filter components to enable
12954  *	@mask: a bitmap selecting which components to enable in filter mask
12955  *	@vnic_mode: the ingress config/vnic mode setting
12956  *
12957  *	Sets the filter mode and mask by selecting the optional components to
12958  *	enable in filter tuples.  Returns 0 on success and a negative error if
12959  *	the requested mode needs more bits than are available for optional
12960  *	components.  The filter mask must be a subset of the filter mode.
12961  */
t4_set_filter_cfg(struct adapter * adap,int mode,int mask,int vnic_mode)12962 int t4_set_filter_cfg(struct adapter *adap, int mode, int mask, int vnic_mode)
12963 {
12964 	int i, nbits, rc;
12965 	uint32_t param, val;
12966 	uint16_t fmode, fmask;
12967 	const int maxbits = adap->chip_params->filter_opt_len;
12968 	const int nopt = adap->chip_params->filter_num_opt;
12969 	int width;
12970 
12971 	if (mode != -1 || mask != -1) {
12972 		if (mode != -1) {
12973 			fmode = mode;
12974 			nbits = 0;
12975 			for (i = 0; i < nopt; i++) {
12976 				if (fmode & (1 << i))
12977 					nbits += t4_filter_field_width(adap, i);
12978 			}
12979 			if (nbits > maxbits) {
12980 				CH_ERR(adap, "optional fields in the filter "
12981 				    "mode (0x%x) add up to %d bits "
12982 				    "(must be <= %db).  Remove some fields and "
12983 				    "try again.\n", fmode, nbits, maxbits);
12984 				return -E2BIG;
12985 			}
12986 
12987 			/*
12988 			 * Hardware < T7 wants the bits to be maxed out.  Keep
12989 			 * setting them until there's no room for more.
12990 			 */
12991 			if (chip_id(adap) < CHELSIO_T7) {
12992 				for (i = 0; i < nopt; i++) {
12993 					if (fmode & (1 << i))
12994 						continue;
12995 					width = t4_filter_field_width(adap, i);
12996 					if (nbits + width <= maxbits) {
12997 						fmode |= 1 << i;
12998 						nbits += width;
12999 						if (nbits == maxbits)
13000 							break;
13001 					}
13002 				}
13003 			}
13004 
13005 			fmask = fmode & adap->params.tp.filter_mask;
13006 			if (fmask != adap->params.tp.filter_mask) {
13007 				CH_WARN(adap,
13008 				    "filter mask will be changed from 0x%x to "
13009 				    "0x%x to comply with the filter mode (0x%x).\n",
13010 				    adap->params.tp.filter_mask, fmask, fmode);
13011 			}
13012 		} else {
13013 			fmode = adap->params.tp.filter_mode;
13014 			fmask = mask;
13015 			if ((fmode | fmask) != fmode) {
13016 				CH_ERR(adap,
13017 				    "filter mask (0x%x) must be a subset of "
13018 				    "the filter mode (0x%x).\n", fmask, fmode);
13019 				return -EINVAL;
13020 			}
13021 		}
13022 
13023 		param = V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
13024 		    V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_FILTER) |
13025 		    V_FW_PARAMS_PARAM_Y(FW_PARAM_DEV_FILTER_MODE_MASK);
13026 		val = V_FW_PARAMS_PARAM_FILTER_MODE(fmode) |
13027 		    V_FW_PARAMS_PARAM_FILTER_MASK(fmask);
13028 		rc = t4_set_params(adap, adap->mbox, adap->pf, 0, 1, &param,
13029 		    &val);
13030 		if (rc < 0)
13031 			return rc;
13032 	}
13033 
13034 	if (vnic_mode != -1) {
13035 		param = V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
13036 		    V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_FILTER) |
13037 		    V_FW_PARAMS_PARAM_Y(FW_PARAM_DEV_FILTER_VNIC_MODE);
13038 		val = vnic_mode;
13039 		rc = t4_set_params(adap, adap->mbox, adap->pf, 0, 1, &param,
13040 		    &val);
13041 		if (rc < 0)
13042 			return rc;
13043 	}
13044 
13045 	/* Refresh. */
13046 	read_filter_mode_and_ingress_config(adap);
13047 
13048 	return 0;
13049 }
13050 
13051 /**
13052  *	t4_clr_port_stats - clear port statistics
13053  *	@adap: the adapter
13054  *	@idx: the port index
13055  *
13056  *	Clear HW statistics for the given port.
13057  */
t4_clr_port_stats(struct adapter * adap,int idx)13058 void t4_clr_port_stats(struct adapter *adap, int idx)
13059 {
13060 	struct port_info *pi;
13061 	int i, port_id, tx_chan;
13062 	u32 bgmap, port_base_addr;
13063 
13064 	port_id  = adap->port_map[idx];
13065 	MPASS(port_id >= 0 && port_id <= adap->params.nports);
13066 	pi = adap->port[port_id];
13067 
13068 	for (tx_chan = pi->tx_chan;
13069 	    tx_chan < pi->tx_chan + adap->params.tp.lb_nchan; tx_chan++) {
13070 		port_base_addr = t4_port_reg(adap, tx_chan, 0);
13071 
13072 		for (i = A_MPS_PORT_STAT_TX_PORT_BYTES_L;
13073 				i <= A_MPS_PORT_STAT_TX_PORT_PPP7_H; i += 8)
13074 			t4_write_reg(adap, port_base_addr + i, 0);
13075 		for (i = A_MPS_PORT_STAT_RX_PORT_BYTES_L;
13076 				i <= A_MPS_PORT_STAT_RX_PORT_LESS_64B_H; i += 8)
13077 			t4_write_reg(adap, port_base_addr + i, 0);
13078 	}
13079 	bgmap = pi->mps_bg_map;
13080 	for (i = 0; i < 4; i++)
13081 		if (bgmap & (1 << i)) {
13082 			t4_write_reg(adap,
13083 			A_MPS_STAT_RX_BG_0_MAC_DROP_FRAME_L + i * 8, 0);
13084 			t4_write_reg(adap,
13085 			A_MPS_STAT_RX_BG_0_MAC_TRUNC_FRAME_L + i * 8, 0);
13086 		}
13087 }
13088 
13089 /**
13090  *	t4_i2c_io - read/write I2C data from adapter
13091  *	@adap: the adapter
13092  *	@port: Port number if per-port device; <0 if not
13093  *	@devid: per-port device ID or absolute device ID
13094  *	@offset: byte offset into device I2C space
13095  *	@len: byte length of I2C space data
13096  *	@buf: buffer in which to return I2C data for read
13097  *	      buffer which holds the I2C data for write
13098  *	@write: if true, do a write; else do a read
13099  *	Reads/Writes the I2C data from/to the indicated device and location.
13100  */
t4_i2c_io(struct adapter * adap,unsigned int mbox,int port,unsigned int devid,unsigned int offset,unsigned int len,u8 * buf,bool write)13101 int t4_i2c_io(struct adapter *adap, unsigned int mbox,
13102 	      int port, unsigned int devid,
13103 	      unsigned int offset, unsigned int len,
13104 	      u8 *buf, bool write)
13105 {
13106 	struct fw_ldst_cmd ldst_cmd, ldst_rpl;
13107 	unsigned int i2c_max = sizeof(ldst_cmd.u.i2c.data);
13108 	int ret = 0;
13109 
13110 	if (len > I2C_PAGE_SIZE)
13111 		return -EINVAL;
13112 
13113 	/* Dont allow reads that spans multiple pages */
13114 	if (offset < I2C_PAGE_SIZE && offset + len > I2C_PAGE_SIZE)
13115 		return -EINVAL;
13116 
13117 	memset(&ldst_cmd, 0, sizeof(ldst_cmd));
13118 	ldst_cmd.op_to_addrspace =
13119 		cpu_to_be32(V_FW_CMD_OP(FW_LDST_CMD) |
13120 			    F_FW_CMD_REQUEST |
13121 			    (write ? F_FW_CMD_WRITE : F_FW_CMD_READ) |
13122 			    V_FW_LDST_CMD_ADDRSPACE(FW_LDST_ADDRSPC_I2C));
13123 	ldst_cmd.cycles_to_len16 = cpu_to_be32(FW_LEN16(ldst_cmd));
13124 	ldst_cmd.u.i2c.pid = (port < 0 ? 0xff : port);
13125 	ldst_cmd.u.i2c.did = devid;
13126 
13127 	while (len > 0) {
13128 		unsigned int i2c_len = (len < i2c_max) ? len : i2c_max;
13129 
13130 		ldst_cmd.u.i2c.boffset = offset;
13131 		ldst_cmd.u.i2c.blen = i2c_len;
13132 
13133 		if (write)
13134 			memcpy(ldst_cmd.u.i2c.data, buf, i2c_len);
13135 
13136 		ret = t4_wr_mbox(adap, mbox, &ldst_cmd, sizeof(ldst_cmd),
13137 				 write ? NULL : &ldst_rpl);
13138 		if (ret)
13139 			break;
13140 
13141 		if (!write)
13142 			memcpy(buf, ldst_rpl.u.i2c.data, i2c_len);
13143 		offset += i2c_len;
13144 		buf += i2c_len;
13145 		len -= i2c_len;
13146 	}
13147 
13148 	return ret;
13149 }
13150 
t4_i2c_rd(struct adapter * adap,unsigned int mbox,int port,unsigned int devid,unsigned int offset,unsigned int len,u8 * buf)13151 int t4_i2c_rd(struct adapter *adap, unsigned int mbox,
13152 	      int port, unsigned int devid,
13153 	      unsigned int offset, unsigned int len,
13154 	      u8 *buf)
13155 {
13156 	return t4_i2c_io(adap, mbox, port, devid, offset, len, buf, false);
13157 }
13158 
t4_i2c_wr(struct adapter * adap,unsigned int mbox,int port,unsigned int devid,unsigned int offset,unsigned int len,u8 * buf)13159 int t4_i2c_wr(struct adapter *adap, unsigned int mbox,
13160 	      int port, unsigned int devid,
13161 	      unsigned int offset, unsigned int len,
13162 	      u8 *buf)
13163 {
13164 	return t4_i2c_io(adap, mbox, port, devid, offset, len, buf, true);
13165 }
13166 
13167 /**
13168  * 	t4_sge_ctxt_rd - read an SGE context through FW
13169  * 	@adap: the adapter
13170  * 	@mbox: mailbox to use for the FW command
13171  * 	@cid: the context id
13172  * 	@ctype: the context type
13173  * 	@data: where to store the context data
13174  *
13175  * 	Issues a FW command through the given mailbox to read an SGE context.
13176  */
t4_sge_ctxt_rd(struct adapter * adap,unsigned int mbox,unsigned int cid,enum ctxt_type ctype,u32 * data)13177 int t4_sge_ctxt_rd(struct adapter *adap, unsigned int mbox, unsigned int cid,
13178 		   enum ctxt_type ctype, u32 *data)
13179 {
13180 	int ret;
13181 	struct fw_ldst_cmd c;
13182 
13183 	if (ctype == CTXT_EGRESS)
13184 		ret = FW_LDST_ADDRSPC_SGE_EGRC;
13185 	else if (ctype == CTXT_INGRESS)
13186 		ret = FW_LDST_ADDRSPC_SGE_INGC;
13187 	else if (ctype == CTXT_FLM)
13188 		ret = FW_LDST_ADDRSPC_SGE_FLMC;
13189 	else
13190 		ret = FW_LDST_ADDRSPC_SGE_CONMC;
13191 
13192 	memset(&c, 0, sizeof(c));
13193 	c.op_to_addrspace = cpu_to_be32(V_FW_CMD_OP(FW_LDST_CMD) |
13194 					F_FW_CMD_REQUEST | F_FW_CMD_READ |
13195 					V_FW_LDST_CMD_ADDRSPACE(ret));
13196 	c.cycles_to_len16 = cpu_to_be32(FW_LEN16(c));
13197 	c.u.idctxt.physid = cpu_to_be32(cid);
13198 
13199 	ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
13200 	if (ret == 0) {
13201 		data[0] = be32_to_cpu(c.u.idctxt.ctxt_data0);
13202 		data[1] = be32_to_cpu(c.u.idctxt.ctxt_data1);
13203 		data[2] = be32_to_cpu(c.u.idctxt.ctxt_data2);
13204 		data[3] = be32_to_cpu(c.u.idctxt.ctxt_data3);
13205 		data[4] = be32_to_cpu(c.u.idctxt.ctxt_data4);
13206 		data[5] = be32_to_cpu(c.u.idctxt.ctxt_data5);
13207 		if (chip_id(adap) > CHELSIO_T6)
13208 			data[6] = be32_to_cpu(c.u.idctxt.ctxt_data6);
13209 	}
13210 	return ret;
13211 }
13212 
13213 /**
13214  * 	t4_sge_ctxt_rd_bd - read an SGE context bypassing FW
13215  * 	@adap: the adapter
13216  * 	@cid: the context id
13217  * 	@ctype: the context type
13218  * 	@data: where to store the context data
13219  *
13220  * 	Reads an SGE context directly, bypassing FW.  This is only for
13221  * 	debugging when FW is unavailable.
13222  */
t4_sge_ctxt_rd_bd(struct adapter * adap,unsigned int cid,enum ctxt_type ctype,u32 * data)13223 int t4_sge_ctxt_rd_bd(struct adapter *adap, unsigned int cid, enum ctxt_type ctype,
13224 		      u32 *data)
13225 {
13226 	int i, ret;
13227 
13228 	t4_write_reg(adap, A_SGE_CTXT_CMD, V_CTXTQID(cid) | V_CTXTTYPE(ctype));
13229 	ret = t4_wait_op_done(adap, A_SGE_CTXT_CMD, F_BUSY, 0, 3, 1);
13230 	if (!ret) {
13231 		for (i = A_SGE_CTXT_DATA0; i <= A_SGE_CTXT_DATA5; i += 4)
13232 			*data++ = t4_read_reg(adap, i);
13233 		if (chip_id(adap) > CHELSIO_T6)
13234 			*data++ = t4_read_reg(adap, i);
13235 	}
13236 	return ret;
13237 }
13238 
t4_sched_config(struct adapter * adapter,int type,int minmaxen,int sleep_ok)13239 int t4_sched_config(struct adapter *adapter, int type, int minmaxen,
13240     int sleep_ok)
13241 {
13242 	struct fw_sched_cmd cmd;
13243 
13244 	memset(&cmd, 0, sizeof(cmd));
13245 	cmd.op_to_write = cpu_to_be32(V_FW_CMD_OP(FW_SCHED_CMD) |
13246 				      F_FW_CMD_REQUEST |
13247 				      F_FW_CMD_WRITE);
13248 	cmd.retval_len16 = cpu_to_be32(FW_LEN16(cmd));
13249 
13250 	cmd.u.config.sc = FW_SCHED_SC_CONFIG;
13251 	cmd.u.config.type = type;
13252 	cmd.u.config.minmaxen = minmaxen;
13253 
13254 	return t4_wr_mbox_meat(adapter,adapter->mbox, &cmd, sizeof(cmd),
13255 			       NULL, sleep_ok);
13256 }
13257 
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)13258 int t4_sched_params(struct adapter *adapter, int type, int level, int mode,
13259 		    int rateunit, int ratemode, int channel, int cl,
13260 		    int minrate, int maxrate, int weight, int pktsize,
13261 		    int burstsize, int sleep_ok)
13262 {
13263 	struct fw_sched_cmd cmd;
13264 
13265 	memset(&cmd, 0, sizeof(cmd));
13266 	cmd.op_to_write = cpu_to_be32(V_FW_CMD_OP(FW_SCHED_CMD) |
13267 				      F_FW_CMD_REQUEST |
13268 				      F_FW_CMD_WRITE);
13269 	cmd.retval_len16 = cpu_to_be32(FW_LEN16(cmd));
13270 
13271 	cmd.u.params.sc = FW_SCHED_SC_PARAMS;
13272 	cmd.u.params.type = type;
13273 	cmd.u.params.level = level;
13274 	cmd.u.params.mode = mode;
13275 	cmd.u.params.ch = channel;
13276 	cmd.u.params.cl = cl;
13277 	cmd.u.params.unit = rateunit;
13278 	cmd.u.params.rate = ratemode;
13279 	cmd.u.params.min = cpu_to_be32(minrate);
13280 	cmd.u.params.max = cpu_to_be32(maxrate);
13281 	cmd.u.params.weight = cpu_to_be16(weight);
13282 	cmd.u.params.pktsize = cpu_to_be16(pktsize);
13283 	cmd.u.params.burstsize = cpu_to_be16(burstsize);
13284 
13285 	return t4_wr_mbox_meat(adapter,adapter->mbox, &cmd, sizeof(cmd),
13286 			       NULL, sleep_ok);
13287 }
13288 
t4_sched_params_ch_rl(struct adapter * adapter,int channel,int ratemode,unsigned int maxrate,int sleep_ok)13289 int t4_sched_params_ch_rl(struct adapter *adapter, int channel, int ratemode,
13290     unsigned int maxrate, int sleep_ok)
13291 {
13292 	struct fw_sched_cmd cmd;
13293 
13294 	memset(&cmd, 0, sizeof(cmd));
13295 	cmd.op_to_write = cpu_to_be32(V_FW_CMD_OP(FW_SCHED_CMD) |
13296 				      F_FW_CMD_REQUEST |
13297 				      F_FW_CMD_WRITE);
13298 	cmd.retval_len16 = cpu_to_be32(FW_LEN16(cmd));
13299 
13300 	cmd.u.params.sc = FW_SCHED_SC_PARAMS;
13301 	cmd.u.params.type = FW_SCHED_TYPE_PKTSCHED;
13302 	cmd.u.params.level = FW_SCHED_PARAMS_LEVEL_CH_RL;
13303 	cmd.u.params.ch = channel;
13304 	cmd.u.params.rate = ratemode;		/* REL or ABS */
13305 	cmd.u.params.max = cpu_to_be32(maxrate);/*  %  or kbps */
13306 
13307 	return t4_wr_mbox_meat(adapter,adapter->mbox, &cmd, sizeof(cmd),
13308 			       NULL, sleep_ok);
13309 }
13310 
t4_sched_params_cl_wrr(struct adapter * adapter,int channel,int cl,int weight,int sleep_ok)13311 int t4_sched_params_cl_wrr(struct adapter *adapter, int channel, int cl,
13312     int weight, int sleep_ok)
13313 {
13314 	struct fw_sched_cmd cmd;
13315 
13316 	if (weight < 0 || weight > 100)
13317 		return -EINVAL;
13318 
13319 	memset(&cmd, 0, sizeof(cmd));
13320 	cmd.op_to_write = cpu_to_be32(V_FW_CMD_OP(FW_SCHED_CMD) |
13321 				      F_FW_CMD_REQUEST |
13322 				      F_FW_CMD_WRITE);
13323 	cmd.retval_len16 = cpu_to_be32(FW_LEN16(cmd));
13324 
13325 	cmd.u.params.sc = FW_SCHED_SC_PARAMS;
13326 	cmd.u.params.type = FW_SCHED_TYPE_PKTSCHED;
13327 	cmd.u.params.level = FW_SCHED_PARAMS_LEVEL_CL_WRR;
13328 	cmd.u.params.ch = channel;
13329 	cmd.u.params.cl = cl;
13330 	cmd.u.params.weight = cpu_to_be16(weight);
13331 
13332 	return t4_wr_mbox_meat(adapter,adapter->mbox, &cmd, sizeof(cmd),
13333 			       NULL, sleep_ok);
13334 }
13335 
t4_sched_params_cl_rl_kbps(struct adapter * adapter,int channel,int cl,int mode,unsigned int maxrate,int pktsize,int sleep_ok)13336 int t4_sched_params_cl_rl_kbps(struct adapter *adapter, int channel, int cl,
13337     int mode, unsigned int maxrate, int pktsize, int sleep_ok)
13338 {
13339 	struct fw_sched_cmd cmd;
13340 
13341 	memset(&cmd, 0, sizeof(cmd));
13342 	cmd.op_to_write = cpu_to_be32(V_FW_CMD_OP(FW_SCHED_CMD) |
13343 				      F_FW_CMD_REQUEST |
13344 				      F_FW_CMD_WRITE);
13345 	cmd.retval_len16 = cpu_to_be32(FW_LEN16(cmd));
13346 
13347 	cmd.u.params.sc = FW_SCHED_SC_PARAMS;
13348 	cmd.u.params.type = FW_SCHED_TYPE_PKTSCHED;
13349 	cmd.u.params.level = FW_SCHED_PARAMS_LEVEL_CL_RL;
13350 	cmd.u.params.mode = mode;
13351 	cmd.u.params.ch = channel;
13352 	cmd.u.params.cl = cl;
13353 	cmd.u.params.unit = FW_SCHED_PARAMS_UNIT_BITRATE;
13354 	cmd.u.params.rate = FW_SCHED_PARAMS_RATE_ABS;
13355 	cmd.u.params.max = cpu_to_be32(maxrate);
13356 	cmd.u.params.pktsize = cpu_to_be16(pktsize);
13357 
13358 	return t4_wr_mbox_meat(adapter,adapter->mbox, &cmd, sizeof(cmd),
13359 			       NULL, sleep_ok);
13360 }
13361 
13362 /*
13363  *	t4_config_watchdog - configure (enable/disable) a watchdog timer
13364  *	@adapter: the adapter
13365  * 	@mbox: mailbox to use for the FW command
13366  * 	@pf: the PF owning the queue
13367  * 	@vf: the VF owning the queue
13368  *	@timeout: watchdog timeout in ms
13369  *	@action: watchdog timer / action
13370  *
13371  *	There are separate watchdog timers for each possible watchdog
13372  *	action.  Configure one of the watchdog timers by setting a non-zero
13373  *	timeout.  Disable a watchdog timer by using a timeout of zero.
13374  */
t4_config_watchdog(struct adapter * adapter,unsigned int mbox,unsigned int pf,unsigned int vf,unsigned int timeout,unsigned int action)13375 int t4_config_watchdog(struct adapter *adapter, unsigned int mbox,
13376 		       unsigned int pf, unsigned int vf,
13377 		       unsigned int timeout, unsigned int action)
13378 {
13379 	struct fw_watchdog_cmd wdog;
13380 	unsigned int ticks;
13381 
13382 	/*
13383 	 * The watchdog command expects a timeout in units of 10ms so we need
13384 	 * to convert it here (via rounding) and force a minimum of one 10ms
13385 	 * "tick" if the timeout is non-zero but the conversion results in 0
13386 	 * ticks.
13387 	 */
13388 	ticks = (timeout + 5)/10;
13389 	if (timeout && !ticks)
13390 		ticks = 1;
13391 
13392 	memset(&wdog, 0, sizeof wdog);
13393 	wdog.op_to_vfn = cpu_to_be32(V_FW_CMD_OP(FW_WATCHDOG_CMD) |
13394 				     F_FW_CMD_REQUEST |
13395 				     F_FW_CMD_WRITE |
13396 				     V_FW_PARAMS_CMD_PFN(pf) |
13397 				     V_FW_PARAMS_CMD_VFN(vf));
13398 	wdog.retval_len16 = cpu_to_be32(FW_LEN16(wdog));
13399 	wdog.timeout = cpu_to_be32(ticks);
13400 	wdog.action = cpu_to_be32(action);
13401 
13402 	return t4_wr_mbox(adapter, mbox, &wdog, sizeof wdog, NULL);
13403 }
13404 
t4_get_devlog_level(struct adapter * adapter,unsigned int * level)13405 int t4_get_devlog_level(struct adapter *adapter, unsigned int *level)
13406 {
13407 	struct fw_devlog_cmd devlog_cmd;
13408 	int ret;
13409 
13410 	memset(&devlog_cmd, 0, sizeof(devlog_cmd));
13411 	devlog_cmd.op_to_write = cpu_to_be32(V_FW_CMD_OP(FW_DEVLOG_CMD) |
13412 					     F_FW_CMD_REQUEST | F_FW_CMD_READ);
13413 	devlog_cmd.retval_len16 = cpu_to_be32(FW_LEN16(devlog_cmd));
13414 	ret = t4_wr_mbox(adapter, adapter->mbox, &devlog_cmd,
13415 			 sizeof(devlog_cmd), &devlog_cmd);
13416 	if (ret)
13417 		return ret;
13418 
13419 	*level = devlog_cmd.level;
13420 	return 0;
13421 }
13422 
t4_set_devlog_level(struct adapter * adapter,unsigned int level)13423 int t4_set_devlog_level(struct adapter *adapter, unsigned int level)
13424 {
13425 	struct fw_devlog_cmd devlog_cmd;
13426 
13427 	memset(&devlog_cmd, 0, sizeof(devlog_cmd));
13428 	devlog_cmd.op_to_write = cpu_to_be32(V_FW_CMD_OP(FW_DEVLOG_CMD) |
13429 					     F_FW_CMD_REQUEST |
13430 					     F_FW_CMD_WRITE);
13431 	devlog_cmd.level = level;
13432 	devlog_cmd.retval_len16 = cpu_to_be32(FW_LEN16(devlog_cmd));
13433 	return t4_wr_mbox(adapter, adapter->mbox, &devlog_cmd,
13434 			  sizeof(devlog_cmd), &devlog_cmd);
13435 }
13436 
t4_configure_add_smac(struct adapter * adap)13437 int t4_configure_add_smac(struct adapter *adap)
13438 {
13439 	unsigned int param, val;
13440 	int ret = 0;
13441 
13442 	adap->params.smac_add_support = 0;
13443 	param = (V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
13444 		  V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_ADD_SMAC));
13445 	/* Query FW to check if FW supports adding source mac address
13446 	 * to TCAM feature or not.
13447 	 * If FW returns 1, driver can use this feature and driver need to send
13448 	 * FW_PARAMS_PARAM_DEV_ADD_SMAC write command with value 1 to
13449 	 * enable adding smac to TCAM.
13450 	 */
13451 	ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1, &param, &val);
13452 	if (ret)
13453 		return ret;
13454 
13455 	if (val == 1) {
13456 		ret = t4_set_params(adap, adap->mbox, adap->pf, 0, 1,
13457 				    &param, &val);
13458 		if (!ret)
13459 			/* Firmware allows adding explicit TCAM entries.
13460 			 * Save this internally.
13461 			 */
13462 			adap->params.smac_add_support = 1;
13463 	}
13464 
13465 	return ret;
13466 }
13467 
t4_configure_ringbb(struct adapter * adap)13468 int t4_configure_ringbb(struct adapter *adap)
13469 {
13470 	unsigned int param, val;
13471 	int ret = 0;
13472 
13473 	param = (V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
13474 		  V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_RING_BACKBONE));
13475 	/* Query FW to check if FW supports ring switch feature or not.
13476 	 * If FW returns 1, driver can use this feature and driver need to send
13477 	 * FW_PARAMS_PARAM_DEV_RING_BACKBONE write command with value 1 to
13478 	 * enable the ring backbone configuration.
13479 	 */
13480 	ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1, &param, &val);
13481 	if (ret < 0) {
13482 		CH_ERR(adap, "Querying FW using Ring backbone params command failed, err=%d\n",
13483 			ret);
13484 		goto out;
13485 	}
13486 
13487 	if (val != 1) {
13488 		CH_ERR(adap, "FW doesnot support ringbackbone features\n");
13489 		goto out;
13490 	}
13491 
13492 	ret = t4_set_params(adap, adap->mbox, adap->pf, 0, 1, &param, &val);
13493 	if (ret < 0) {
13494 		CH_ERR(adap, "Could not set Ringbackbone, err= %d\n",
13495 			ret);
13496 		goto out;
13497 	}
13498 
13499 out:
13500 	return ret;
13501 }
13502 
13503 /*
13504  *	t4_set_vlan_acl - Set a VLAN id for the specified VF
13505  *	@adapter: the adapter
13506  *	@mbox: mailbox to use for the FW command
13507  *	@vf: one of the VFs instantiated by the specified PF
13508  *	@vlan: The vlanid to be set
13509  *
13510  */
t4_set_vlan_acl(struct adapter * adap,unsigned int pf,unsigned int vf,u16 vlan)13511 int t4_set_vlan_acl(struct adapter *adap, unsigned int pf, unsigned int vf,
13512 		    u16 vlan)
13513 {
13514 	struct fw_acl_vlan_cmd vlan_cmd;
13515 	unsigned int enable;
13516 
13517 	enable = (vlan ? F_FW_ACL_VLAN_CMD_EN : 0);
13518 	memset(&vlan_cmd, 0, sizeof(vlan_cmd));
13519 	vlan_cmd.op_to_vfn = cpu_to_be32(V_FW_CMD_OP(FW_ACL_VLAN_CMD) |
13520 					 F_FW_CMD_REQUEST |
13521 					 F_FW_CMD_WRITE |
13522 					 F_FW_CMD_EXEC |
13523 					 V_FW_ACL_VLAN_CMD_PFN(pf) |
13524 					 V_FW_ACL_VLAN_CMD_VFN(vf));
13525 	vlan_cmd.en_to_len16 = cpu_to_be32(enable | FW_LEN16(vlan_cmd) |
13526 					   V_FW_ACL_VLAN_CMD_PMASK(1 << pf));
13527 	/* Drop all packets that donot match vlan id */
13528 	vlan_cmd.dropnovlan_fm = (enable
13529 				  ? (F_FW_ACL_VLAN_CMD_DROPNOVLAN |
13530 				     F_FW_ACL_VLAN_CMD_FM)
13531 				  : 0);
13532 	if (enable != 0) {
13533 		vlan_cmd.nvlan = 1;
13534 		vlan_cmd.vlanid[0] = cpu_to_be16(vlan);
13535 	}
13536 
13537 	return t4_wr_mbox(adap, adap->mbox, &vlan_cmd, sizeof(vlan_cmd), NULL);
13538 }
13539 
13540 /**
13541  *	t4_del_mac - Removes the exact-match filter for a MAC address
13542  *	@adap: the adapter
13543  *	@mbox: mailbox to use for the FW command
13544  *	@viid: the VI id
13545  *	@addr: the MAC address value
13546  *	@smac: if true, delete from only the smac region of MPS
13547  *
13548  *	Modifies an exact-match filter and sets it to the new MAC address if
13549  *	@idx >= 0, or adds the MAC address to a new filter if @idx < 0.  In the
13550  *	latter case the address is added persistently if @persist is %true.
13551  *
13552  *	Returns a negative error number or the index of the filter with the new
13553  *	MAC value.  Note that this index may differ from @idx.
13554  */
t4_del_mac(struct adapter * adap,unsigned int mbox,unsigned int viid,const u8 * addr,bool smac)13555 int t4_del_mac(struct adapter *adap, unsigned int mbox, unsigned int viid,
13556 	       const u8 *addr, bool smac)
13557 {
13558 	int ret;
13559 	struct fw_vi_mac_cmd c;
13560 	struct fw_vi_mac_exact *p = c.u.exact;
13561 	unsigned int max_mac_addr = adap->chip_params->mps_tcam_size;
13562 
13563 	memset(&c, 0, sizeof(c));
13564 	c.op_to_viid = cpu_to_be32(V_FW_CMD_OP(FW_VI_MAC_CMD) |
13565 				   F_FW_CMD_REQUEST | F_FW_CMD_WRITE |
13566 				   V_FW_VI_MAC_CMD_VIID(viid));
13567 	c.freemacs_to_len16 = cpu_to_be32(
13568 					V_FW_CMD_LEN16(1) |
13569 					(smac ? F_FW_VI_MAC_CMD_IS_SMAC : 0));
13570 
13571 	memcpy(p->macaddr, addr, sizeof(p->macaddr));
13572 	p->valid_to_idx = cpu_to_be16(
13573 				F_FW_VI_MAC_CMD_VALID |
13574 				V_FW_VI_MAC_CMD_IDX(FW_VI_MAC_MAC_BASED_FREE));
13575 
13576 	ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
13577 	if (ret == 0) {
13578 		ret = G_FW_VI_MAC_CMD_IDX(be16_to_cpu(p->valid_to_idx));
13579 		if (ret < max_mac_addr)
13580 			return -ENOMEM;
13581 	}
13582 
13583 	return ret;
13584 }
13585 
13586 /**
13587  *	t4_add_mac - Adds an exact-match filter for a MAC address
13588  *	@adap: the adapter
13589  *	@mbox: mailbox to use for the FW command
13590  *	@viid: the VI id
13591  *	@idx: index of existing filter for old value of MAC address, or -1
13592  *	@addr: the new MAC address value
13593  *	@persist: whether a new MAC allocation should be persistent
13594  *	@add_smt: if true also add the address to the HW SMT
13595  *	@smac: if true, update only the smac region of MPS
13596  *
13597  *	Modifies an exact-match filter and sets it to the new MAC address if
13598  *	@idx >= 0, or adds the MAC address to a new filter if @idx < 0.  In the
13599  *	latter case the address is added persistently if @persist is %true.
13600  *
13601  *	Returns a negative error number or the index of the filter with the new
13602  *	MAC value.  Note that this index may differ from @idx.
13603  */
t4_add_mac(struct adapter * adap,unsigned int mbox,unsigned int viid,int idx,const u8 * addr,bool persist,u8 * smt_idx,bool smac)13604 int t4_add_mac(struct adapter *adap, unsigned int mbox, unsigned int viid,
13605 	       int idx, const u8 *addr, bool persist, u8 *smt_idx, bool smac)
13606 {
13607 	int ret, mode;
13608 	struct fw_vi_mac_cmd c;
13609 	struct fw_vi_mac_exact *p = c.u.exact;
13610 	unsigned int max_mac_addr = adap->chip_params->mps_tcam_size;
13611 
13612 	if (idx < 0)		/* new allocation */
13613 		idx = persist ? FW_VI_MAC_ADD_PERSIST_MAC : FW_VI_MAC_ADD_MAC;
13614 	mode = smt_idx ? FW_VI_MAC_SMT_AND_MPSTCAM : FW_VI_MAC_MPS_TCAM_ENTRY;
13615 
13616 	memset(&c, 0, sizeof(c));
13617 	c.op_to_viid = cpu_to_be32(V_FW_CMD_OP(FW_VI_MAC_CMD) |
13618 				   F_FW_CMD_REQUEST | F_FW_CMD_WRITE |
13619 				   V_FW_VI_MAC_CMD_VIID(viid));
13620 	c.freemacs_to_len16 = cpu_to_be32(
13621 				V_FW_CMD_LEN16(1) |
13622 				(smac ? F_FW_VI_MAC_CMD_IS_SMAC : 0));
13623 	p->valid_to_idx = cpu_to_be16(F_FW_VI_MAC_CMD_VALID |
13624 				      V_FW_VI_MAC_CMD_SMAC_RESULT(mode) |
13625 				      V_FW_VI_MAC_CMD_IDX(idx));
13626 	memcpy(p->macaddr, addr, sizeof(p->macaddr));
13627 
13628 	ret = t4_wr_mbox(adap, mbox, &c, sizeof(c), &c);
13629 	if (ret == 0) {
13630 		ret = G_FW_VI_MAC_CMD_IDX(be16_to_cpu(p->valid_to_idx));
13631 		if (ret >= max_mac_addr)
13632 			return -ENOMEM;
13633 		if (smt_idx) {
13634 			/* Does fw supports returning smt_idx? */
13635 			if (adap->params.viid_smt_extn_support)
13636 				*smt_idx = G_FW_VI_MAC_CMD_SMTID(be32_to_cpu(c.op_to_viid));
13637 			else {
13638 				/* In T4/T5, SMT contains 256 SMAC entries
13639 				 * organized in 128 rows of 2 entries each.
13640 				 * In T6, SMT contains 256 SMAC entries in
13641 				 * 256 rows.
13642 				 */
13643 				if (chip_id(adap) <= CHELSIO_T5)
13644 					*smt_idx = ((viid & M_FW_VIID_VIN) << 1);
13645 				else
13646 					*smt_idx = (viid & M_FW_VIID_VIN);
13647 			}
13648 		}
13649 	}
13650 
13651 	return ret;
13652 }
13653