1bafec742SSukumar Swaminathan /*
2bafec742SSukumar Swaminathan  * CDDL HEADER START
3bafec742SSukumar Swaminathan  *
4bafec742SSukumar Swaminathan  * The contents of this file are subject to the terms of the
5bafec742SSukumar Swaminathan  * Common Development and Distribution License (the "License").
6bafec742SSukumar Swaminathan  * You may not use this file except in compliance with the License.
7bafec742SSukumar Swaminathan  *
8bafec742SSukumar Swaminathan  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9bafec742SSukumar Swaminathan  * or http://www.opensolaris.org/os/licensing.
10bafec742SSukumar Swaminathan  * See the License for the specific language governing permissions
11bafec742SSukumar Swaminathan  * and limitations under the License.
12bafec742SSukumar Swaminathan  *
13bafec742SSukumar Swaminathan  * When distributing Covered Code, include this CDDL HEADER in each
14bafec742SSukumar Swaminathan  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15bafec742SSukumar Swaminathan  * If applicable, add the following below this CDDL HEADER, with the
16bafec742SSukumar Swaminathan  * fields enclosed by brackets "[]" replaced with your own identifying
17bafec742SSukumar Swaminathan  * information: Portions Copyright [yyyy] [name of copyright owner]
18bafec742SSukumar Swaminathan  *
19bafec742SSukumar Swaminathan  * CDDL HEADER END
20bafec742SSukumar Swaminathan  */
21bafec742SSukumar Swaminathan 
22bafec742SSukumar Swaminathan /*
23accf27a5SSukumar Swaminathan  * Copyright 2010 QLogic Corporation. All rights reserved.
24bafec742SSukumar Swaminathan  */
25bafec742SSukumar Swaminathan 
26bafec742SSukumar Swaminathan #include <qlge.h>
27bafec742SSukumar Swaminathan 
28bafec742SSukumar Swaminathan static uint32_t ql_dump_buf_8(uint8_t *, uint32_t, uint32_t);
29bafec742SSukumar Swaminathan static uint32_t ql_dump_buf_16(uint16_t *, uint32_t, uint32_t);
30bafec742SSukumar Swaminathan static uint32_t ql_dump_buf_32(uint32_t *, uint32_t, uint32_t);
31bafec742SSukumar Swaminathan static uint32_t ql_dump_buf_64(uint64_t *, uint32_t, uint32_t);
32bafec742SSukumar Swaminathan static int ql_binary_core_dump(qlge_t *, uint32_t, uint32_t *);
33bafec742SSukumar Swaminathan 
34bafec742SSukumar Swaminathan static char ISP_8100_REGION[] = {
35bafec742SSukumar Swaminathan 	"nic: nic_boot, nic_param, nic_vpd \n"
36bafec742SSukumar Swaminathan 	"mpi: mpi_fw, mpi_config, edc_fw\n"
37bafec742SSukumar Swaminathan 	"fc: fc_boot, fc_fw, fc_nvram, fc_vpd"};
38bafec742SSukumar Swaminathan static char ISP_8100_AVAILABLE_DUMPS[] = {"core,register,all"};
39bafec742SSukumar Swaminathan 
40bafec742SSukumar Swaminathan /*
41bafec742SSukumar Swaminathan  * Get byte from I/O port
42bafec742SSukumar Swaminathan  */
43bafec742SSukumar Swaminathan uint8_t
ql_get8(qlge_t * qlge,uint32_t index)44bafec742SSukumar Swaminathan ql_get8(qlge_t *qlge, uint32_t index)
45bafec742SSukumar Swaminathan {
46bafec742SSukumar Swaminathan 	uint8_t ret;
47bafec742SSukumar Swaminathan 
48bafec742SSukumar Swaminathan 	ret = (uint8_t)ddi_get8(qlge->dev_handle,
49bafec742SSukumar Swaminathan 	    (uint8_t *)(((caddr_t)qlge->iobase) + index));
50bafec742SSukumar Swaminathan 	return (ret);
51bafec742SSukumar Swaminathan }
52bafec742SSukumar Swaminathan 
53bafec742SSukumar Swaminathan /*
54bafec742SSukumar Swaminathan  * Get word from I/O port
55bafec742SSukumar Swaminathan  */
56bafec742SSukumar Swaminathan uint16_t
ql_get16(qlge_t * qlge,uint32_t index)57bafec742SSukumar Swaminathan ql_get16(qlge_t *qlge, uint32_t index)
58bafec742SSukumar Swaminathan {
59bafec742SSukumar Swaminathan 	uint16_t ret;
60bafec742SSukumar Swaminathan 
61bafec742SSukumar Swaminathan 	ret = (uint16_t)ddi_get16(qlge->dev_handle,
62bafec742SSukumar Swaminathan 	    (uint16_t *)(void *)(((caddr_t)qlge->iobase) + index));
63bafec742SSukumar Swaminathan 	return (ret);
64bafec742SSukumar Swaminathan }
65bafec742SSukumar Swaminathan 
66bafec742SSukumar Swaminathan /*
67bafec742SSukumar Swaminathan  * Get double word from I/O port
68bafec742SSukumar Swaminathan  */
69bafec742SSukumar Swaminathan uint32_t
ql_get32(qlge_t * qlge,uint32_t index)70bafec742SSukumar Swaminathan ql_get32(qlge_t *qlge, uint32_t index)
71bafec742SSukumar Swaminathan {
72bafec742SSukumar Swaminathan 	uint32_t ret;
73bafec742SSukumar Swaminathan 
74bafec742SSukumar Swaminathan 	ret = ddi_get32(qlge->dev_handle,
75bafec742SSukumar Swaminathan 	    (uint32_t *)(void *)(((caddr_t)qlge->iobase) + index));
76bafec742SSukumar Swaminathan 	return (ret);
77bafec742SSukumar Swaminathan }
78bafec742SSukumar Swaminathan 
79bafec742SSukumar Swaminathan /*
80bafec742SSukumar Swaminathan  * Send byte to I/O port
81bafec742SSukumar Swaminathan  */
82bafec742SSukumar Swaminathan void
ql_put8(qlge_t * qlge,uint32_t index,uint8_t data)83bafec742SSukumar Swaminathan ql_put8(qlge_t *qlge, uint32_t index, uint8_t data)
84bafec742SSukumar Swaminathan {
85bafec742SSukumar Swaminathan 	ddi_put8(qlge->dev_handle,
86bafec742SSukumar Swaminathan 	    (uint8_t *)(((caddr_t)qlge->iobase) + index), data);
87bafec742SSukumar Swaminathan }
88bafec742SSukumar Swaminathan 
89bafec742SSukumar Swaminathan /*
90bafec742SSukumar Swaminathan  * Send word to I/O port
91bafec742SSukumar Swaminathan  */
92bafec742SSukumar Swaminathan void
ql_put16(qlge_t * qlge,uint32_t index,uint16_t data)93bafec742SSukumar Swaminathan ql_put16(qlge_t *qlge, uint32_t index, uint16_t data)
94bafec742SSukumar Swaminathan {
95bafec742SSukumar Swaminathan 	ddi_put16(qlge->dev_handle,
96bafec742SSukumar Swaminathan 	    (uint16_t *)(void *)(((caddr_t)qlge->iobase) + index), data);
97bafec742SSukumar Swaminathan }
98bafec742SSukumar Swaminathan 
99bafec742SSukumar Swaminathan /*
100bafec742SSukumar Swaminathan  * Send double word to I/O port
101bafec742SSukumar Swaminathan  */
102bafec742SSukumar Swaminathan void
ql_put32(qlge_t * qlge,uint32_t index,uint32_t data)103bafec742SSukumar Swaminathan ql_put32(qlge_t *qlge, uint32_t index, uint32_t data)
104bafec742SSukumar Swaminathan {
105bafec742SSukumar Swaminathan 	ddi_put32(qlge->dev_handle,
106bafec742SSukumar Swaminathan 	    (uint32_t *)(void *)(((caddr_t)qlge->iobase) + index), data);
107bafec742SSukumar Swaminathan }
108bafec742SSukumar Swaminathan 
109bafec742SSukumar Swaminathan /*
110bafec742SSukumar Swaminathan  * Read from a register
111bafec742SSukumar Swaminathan  */
112bafec742SSukumar Swaminathan uint32_t
ql_read_reg(qlge_t * qlge,uint32_t reg)113bafec742SSukumar Swaminathan ql_read_reg(qlge_t *qlge, uint32_t reg)
114bafec742SSukumar Swaminathan {
115bafec742SSukumar Swaminathan 	uint32_t data = ql_get32(qlge, reg);
116bafec742SSukumar Swaminathan 
117bafec742SSukumar Swaminathan 	return (data);
118bafec742SSukumar Swaminathan }
119bafec742SSukumar Swaminathan 
120bafec742SSukumar Swaminathan /*
121bafec742SSukumar Swaminathan  * Write 32 bit data to a register
122bafec742SSukumar Swaminathan  */
123bafec742SSukumar Swaminathan void
ql_write_reg(qlge_t * qlge,uint32_t reg,uint32_t data)124bafec742SSukumar Swaminathan ql_write_reg(qlge_t *qlge, uint32_t reg, uint32_t data)
125bafec742SSukumar Swaminathan {
126bafec742SSukumar Swaminathan 	ql_put32(qlge, reg, data);
127bafec742SSukumar Swaminathan }
128bafec742SSukumar Swaminathan 
129bafec742SSukumar Swaminathan /*
130bafec742SSukumar Swaminathan  * Set semaphore register bit to lock access to a shared register
131bafec742SSukumar Swaminathan  */
132bafec742SSukumar Swaminathan int
ql_sem_lock(qlge_t * qlge,uint32_t sem_mask,uint32_t sem_bits)133bafec742SSukumar Swaminathan ql_sem_lock(qlge_t *qlge, uint32_t sem_mask, uint32_t sem_bits)
134bafec742SSukumar Swaminathan {
135bafec742SSukumar Swaminathan 	uint32_t value;
136bafec742SSukumar Swaminathan 
137bafec742SSukumar Swaminathan 	ql_put32(qlge, REG_SEMAPHORE, (sem_mask | sem_bits));
138bafec742SSukumar Swaminathan 	value = ql_get32(qlge, REG_SEMAPHORE);
139bafec742SSukumar Swaminathan 	return ((value & (sem_mask >> 16)) == sem_bits);
140bafec742SSukumar Swaminathan }
141bafec742SSukumar Swaminathan /*
142bafec742SSukumar Swaminathan  * Wait up to "delay" seconds until the register "reg"'s
143bafec742SSukumar Swaminathan  * "wait_bit" is set
144bafec742SSukumar Swaminathan  * Default wait time is 5 seconds if "delay" time was not set.
145bafec742SSukumar Swaminathan  */
146bafec742SSukumar Swaminathan int
ql_wait_reg_bit(qlge_t * qlge,uint32_t reg,uint32_t wait_bit,int set,uint32_t delay)147bafec742SSukumar Swaminathan ql_wait_reg_bit(qlge_t *qlge, uint32_t reg, uint32_t wait_bit, int set,
148bafec742SSukumar Swaminathan     uint32_t delay)
149bafec742SSukumar Swaminathan {
150bafec742SSukumar Swaminathan 	uint32_t reg_status;
151bafec742SSukumar Swaminathan 	uint32_t timer = 5; /* 5 second */
152bafec742SSukumar Swaminathan 	int rtn_val = DDI_SUCCESS;
153bafec742SSukumar Swaminathan 	uint32_t delay_ticks;
154bafec742SSukumar Swaminathan 
155bafec742SSukumar Swaminathan 	if (delay != 0)
156bafec742SSukumar Swaminathan 		timer = delay;
157bafec742SSukumar Swaminathan 
158bafec742SSukumar Swaminathan 	delay_ticks = timer * 100;
159bafec742SSukumar Swaminathan 	/*
160bafec742SSukumar Swaminathan 	 * wait for Configuration register test bit to be set,
161bafec742SSukumar Swaminathan 	 * if not, then it is still busy.
162bafec742SSukumar Swaminathan 	 */
163bafec742SSukumar Swaminathan 	do {
164bafec742SSukumar Swaminathan 		reg_status = ql_read_reg(qlge, reg);
165bafec742SSukumar Swaminathan 		/* wait for bit set or reset? */
166bafec742SSukumar Swaminathan 		if (set == BIT_SET) {
167bafec742SSukumar Swaminathan 			if (reg_status & wait_bit)
168bafec742SSukumar Swaminathan 				break;
169bafec742SSukumar Swaminathan 			else
170bafec742SSukumar Swaminathan 				qlge_delay(QL_ONE_SEC_DELAY / 100);
171bafec742SSukumar Swaminathan 		} else {
172bafec742SSukumar Swaminathan 			if (reg_status & wait_bit)
173bafec742SSukumar Swaminathan 				qlge_delay(QL_ONE_SEC_DELAY / 100);
174bafec742SSukumar Swaminathan 			else
175bafec742SSukumar Swaminathan 				break;
176bafec742SSukumar Swaminathan 		}
177bafec742SSukumar Swaminathan 	} while (--delay_ticks);
178bafec742SSukumar Swaminathan 
179bafec742SSukumar Swaminathan 	if (delay_ticks == 0) {
180bafec742SSukumar Swaminathan 		rtn_val = DDI_FAILURE;
181accf27a5SSukumar Swaminathan 		cmn_err(CE_WARN, "qlge(%d)wait reg %x, bit %x time out",
182accf27a5SSukumar Swaminathan 		    qlge->instance, reg, wait_bit);
183accf27a5SSukumar Swaminathan 		if (qlge->fm_enable) {
184accf27a5SSukumar Swaminathan 			ql_fm_ereport(qlge, DDI_FM_DEVICE_NO_RESPONSE);
185accf27a5SSukumar Swaminathan 			atomic_or_32(&qlge->flags, ADAPTER_ERROR);
186accf27a5SSukumar Swaminathan 		}
187bafec742SSukumar Swaminathan 	}
188bafec742SSukumar Swaminathan 	return (rtn_val);
189bafec742SSukumar Swaminathan }
190bafec742SSukumar Swaminathan 
191bafec742SSukumar Swaminathan /*
192bafec742SSukumar Swaminathan  * Dump the value of control registers
193bafec742SSukumar Swaminathan  */
194bafec742SSukumar Swaminathan void
ql_dump_all_contrl_regs(qlge_t * qlge)195bafec742SSukumar Swaminathan ql_dump_all_contrl_regs(qlge_t *qlge)
196bafec742SSukumar Swaminathan {
197bafec742SSukumar Swaminathan 	int i;
198bafec742SSukumar Swaminathan 	uint32_t data;
199bafec742SSukumar Swaminathan 
200bafec742SSukumar Swaminathan 	for (i = 0; i < 0xff; i = i+4) {
201bafec742SSukumar Swaminathan 		data = ql_read_reg(qlge, i);
202bafec742SSukumar Swaminathan 		ql_printf("\tregister# 0x%x value: 0x%x\n", i, data);
203bafec742SSukumar Swaminathan 	}
204bafec742SSukumar Swaminathan }
205bafec742SSukumar Swaminathan 
206bafec742SSukumar Swaminathan /*
207bafec742SSukumar Swaminathan  * Prints string plus buffer.
208bafec742SSukumar Swaminathan  */
209bafec742SSukumar Swaminathan void
ql_dump_buf(char * string,uint8_t * buffer,uint8_t wd_size,uint32_t count)210bafec742SSukumar Swaminathan ql_dump_buf(char *string, uint8_t *buffer, uint8_t wd_size,
211bafec742SSukumar Swaminathan     uint32_t count)
212bafec742SSukumar Swaminathan {
213bafec742SSukumar Swaminathan 	uint32_t offset = 0;
214bafec742SSukumar Swaminathan 
215bafec742SSukumar Swaminathan 	if (strcmp(string, "") != 0)
216bafec742SSukumar Swaminathan 		ql_printf(string);
217bafec742SSukumar Swaminathan 
218bafec742SSukumar Swaminathan 	if ((buffer == NULL) || (count == 0))
219bafec742SSukumar Swaminathan 		return;
220bafec742SSukumar Swaminathan 
221bafec742SSukumar Swaminathan 	switch (wd_size) {
222bafec742SSukumar Swaminathan 	case 8:
223bafec742SSukumar Swaminathan 		while (count) {
224bafec742SSukumar Swaminathan 			count = ql_dump_buf_8(buffer, count, offset);
225bafec742SSukumar Swaminathan 			offset += 8;
226bafec742SSukumar Swaminathan 			buffer += 8;
227bafec742SSukumar Swaminathan 		}
228bafec742SSukumar Swaminathan 		break;
229bafec742SSukumar Swaminathan 
230bafec742SSukumar Swaminathan 	case 16:
231bafec742SSukumar Swaminathan 		while (count) {
232bafec742SSukumar Swaminathan 			count = ql_dump_buf_16((uint16_t *)(void *)buffer,
233bafec742SSukumar Swaminathan 			    count, offset);
234bafec742SSukumar Swaminathan 			offset += 16;
235bafec742SSukumar Swaminathan 			buffer += 16;
236bafec742SSukumar Swaminathan 		}
237bafec742SSukumar Swaminathan 		break;
238bafec742SSukumar Swaminathan 	case 32:
239bafec742SSukumar Swaminathan 		while (count) {
240bafec742SSukumar Swaminathan 			count = ql_dump_buf_32((uint32_t *)(void *)buffer,
241bafec742SSukumar Swaminathan 			    count, offset);
242bafec742SSukumar Swaminathan 			offset += 16;
243bafec742SSukumar Swaminathan 			buffer += 16;
244bafec742SSukumar Swaminathan 		}
245bafec742SSukumar Swaminathan 		break;
246bafec742SSukumar Swaminathan 	case 64:
247bafec742SSukumar Swaminathan 		while (count) {
248bafec742SSukumar Swaminathan 			count = ql_dump_buf_64((uint64_t *)(void *)buffer,
249bafec742SSukumar Swaminathan 			    count, offset);
250bafec742SSukumar Swaminathan 			offset += 16;
251bafec742SSukumar Swaminathan 			buffer += 16;
252bafec742SSukumar Swaminathan 		}
253bafec742SSukumar Swaminathan 		break;
254bafec742SSukumar Swaminathan 	default:
255bafec742SSukumar Swaminathan 		break;
256bafec742SSukumar Swaminathan 	}
257bafec742SSukumar Swaminathan }
258bafec742SSukumar Swaminathan 
259bafec742SSukumar Swaminathan /*
260bafec742SSukumar Swaminathan  * Print as 8bit bytes
261bafec742SSukumar Swaminathan  */
262bafec742SSukumar Swaminathan static uint32_t
ql_dump_buf_8(uint8_t * bp,uint32_t count,uint32_t offset)263bafec742SSukumar Swaminathan ql_dump_buf_8(uint8_t *bp, uint32_t count, uint32_t offset)
264bafec742SSukumar Swaminathan {
265bafec742SSukumar Swaminathan 	switch (count) {
266bafec742SSukumar Swaminathan 	case 1:
267bafec742SSukumar Swaminathan 		ql_printf("0x%016x : %02x\n",
268bafec742SSukumar Swaminathan 		    offset,
269bafec742SSukumar Swaminathan 		    *bp);
270bafec742SSukumar Swaminathan 		break;
271bafec742SSukumar Swaminathan 
272bafec742SSukumar Swaminathan 	case 2:
273bafec742SSukumar Swaminathan 		ql_printf("0x%016x : %02x %02x\n",
274bafec742SSukumar Swaminathan 		    offset,
275bafec742SSukumar Swaminathan 		    *bp, *(bp+1));
276bafec742SSukumar Swaminathan 		break;
277bafec742SSukumar Swaminathan 
278bafec742SSukumar Swaminathan 	case 3:
279bafec742SSukumar Swaminathan 		ql_printf("0x%016x : %02x %02x %02x\n",
280bafec742SSukumar Swaminathan 		    offset,
281bafec742SSukumar Swaminathan 		    *bp, *(bp+1), *(bp+2));
282bafec742SSukumar Swaminathan 		break;
283bafec742SSukumar Swaminathan 
284bafec742SSukumar Swaminathan 	case 4:
285bafec742SSukumar Swaminathan 		ql_printf("0x%016x : %02x %02x %02x %02x\n",
286bafec742SSukumar Swaminathan 		    offset,
287bafec742SSukumar Swaminathan 		    *bp, *(bp+1), *(bp+2), *(bp+3));
288bafec742SSukumar Swaminathan 		break;
289bafec742SSukumar Swaminathan 
290bafec742SSukumar Swaminathan 	case 5:
291bafec742SSukumar Swaminathan 		ql_printf("0x%016x : %02x %02x %02x %02x %02x\n",
292bafec742SSukumar Swaminathan 		    offset,
293bafec742SSukumar Swaminathan 		    *bp, *(bp+1), *(bp+2), *(bp+3), *(bp+4));
294bafec742SSukumar Swaminathan 		break;
295bafec742SSukumar Swaminathan 
296bafec742SSukumar Swaminathan 	case 6:
297bafec742SSukumar Swaminathan 		ql_printf("0x%016x : %02x %02x %02x %02x %02x %02x\n",
298bafec742SSukumar Swaminathan 		    offset,
299bafec742SSukumar Swaminathan 		    *bp, *(bp+1), *(bp+2), *(bp+3), *(bp+4), *(bp+5));
300bafec742SSukumar Swaminathan 		break;
301bafec742SSukumar Swaminathan 
302bafec742SSukumar Swaminathan 	case 7:
303bafec742SSukumar Swaminathan 		ql_printf("0x%016x : %02x %02x %02x %02x %02x %02x %02x\n",
304bafec742SSukumar Swaminathan 		    offset,
305bafec742SSukumar Swaminathan 		    *bp, *(bp+1), *(bp+2), *(bp+3), *(bp+4), *(bp+5), *(bp+6));
306bafec742SSukumar Swaminathan 		break;
307bafec742SSukumar Swaminathan 
308bafec742SSukumar Swaminathan 	default:
309bafec742SSukumar Swaminathan 		ql_printf("0x%016x : %02x %02x %02x %02x %02x %02x %02x %02x\n",
310bafec742SSukumar Swaminathan 		    offset,
311bafec742SSukumar Swaminathan 		    *bp, *(bp+1), *(bp+2), *(bp+3), *(bp+4), *(bp+5), *(bp+6),
312bafec742SSukumar Swaminathan 		    *(bp+7));
313bafec742SSukumar Swaminathan 		break;
314bafec742SSukumar Swaminathan 
315bafec742SSukumar Swaminathan 	}
316bafec742SSukumar Swaminathan 
317bafec742SSukumar Swaminathan 	if (count < 8) {
318bafec742SSukumar Swaminathan 		count = 0;
319bafec742SSukumar Swaminathan 	} else {
320bafec742SSukumar Swaminathan 		count -= 8;
321bafec742SSukumar Swaminathan 	}
322bafec742SSukumar Swaminathan 
323bafec742SSukumar Swaminathan 	return (count);
324bafec742SSukumar Swaminathan }
325bafec742SSukumar Swaminathan 
326bafec742SSukumar Swaminathan /*
327bafec742SSukumar Swaminathan  * Print as 16bit
328bafec742SSukumar Swaminathan  */
329bafec742SSukumar Swaminathan static uint32_t
ql_dump_buf_16(uint16_t * bp,uint32_t count,uint32_t offset)330bafec742SSukumar Swaminathan ql_dump_buf_16(uint16_t *bp, uint32_t count, uint32_t offset)
331bafec742SSukumar Swaminathan {
332bafec742SSukumar Swaminathan 
333bafec742SSukumar Swaminathan 	switch (count) {
334bafec742SSukumar Swaminathan 	case 1:
335bafec742SSukumar Swaminathan 		ql_printf("0x%016x : %04x\n",
336bafec742SSukumar Swaminathan 		    offset,
337bafec742SSukumar Swaminathan 		    *bp);
338bafec742SSukumar Swaminathan 		break;
339bafec742SSukumar Swaminathan 
340bafec742SSukumar Swaminathan 	case 2:
341bafec742SSukumar Swaminathan 		ql_printf("0x%016x : %04x %04x\n",
342bafec742SSukumar Swaminathan 		    offset,
343bafec742SSukumar Swaminathan 		    *bp, *(bp+1));
344bafec742SSukumar Swaminathan 		break;
345bafec742SSukumar Swaminathan 
346bafec742SSukumar Swaminathan 	case 3:
347bafec742SSukumar Swaminathan 		ql_printf("0x%016x : %04x %04x %04x\n",
348bafec742SSukumar Swaminathan 		    offset,
349bafec742SSukumar Swaminathan 		    *bp, *(bp+1), *(bp+2));
350bafec742SSukumar Swaminathan 		break;
351bafec742SSukumar Swaminathan 
352bafec742SSukumar Swaminathan 	case 4:
353bafec742SSukumar Swaminathan 		ql_printf("0x%016x : %04x %04x %04x %04x\n",
354bafec742SSukumar Swaminathan 		    offset,
355bafec742SSukumar Swaminathan 		    *bp, *(bp+1), *(bp+2), *(bp+3));
356bafec742SSukumar Swaminathan 		break;
357bafec742SSukumar Swaminathan 
358bafec742SSukumar Swaminathan 	case 5:
359bafec742SSukumar Swaminathan 		ql_printf("0x%016x : %04x %04x %04x %04x %04x\n",
360bafec742SSukumar Swaminathan 		    offset,
361bafec742SSukumar Swaminathan 		    *bp, *(bp+1), *(bp+2), *(bp+3), *(bp+4));
362bafec742SSukumar Swaminathan 		break;
363bafec742SSukumar Swaminathan 
364bafec742SSukumar Swaminathan 	case 6:
365bafec742SSukumar Swaminathan 		ql_printf("0x%016x : %04x %04x %04x %04x %04x %04x\n",
366bafec742SSukumar Swaminathan 		    offset,
367bafec742SSukumar Swaminathan 		    *bp, *(bp+1), *(bp+2), *(bp+3), *(bp+4), *(bp+5));
368bafec742SSukumar Swaminathan 		break;
369bafec742SSukumar Swaminathan 
370bafec742SSukumar Swaminathan 	case 7:
371bafec742SSukumar Swaminathan 		ql_printf("0x%016x : %04x %04x %04x %04x %04x %04x %04x\n",
372bafec742SSukumar Swaminathan 		    offset,
373bafec742SSukumar Swaminathan 		    *bp, *(bp+1), *(bp+2), *(bp+3), *(bp+4), *(bp+5), *(bp+6));
374bafec742SSukumar Swaminathan 		break;
375bafec742SSukumar Swaminathan 
376bafec742SSukumar Swaminathan 	default:
377bafec742SSukumar Swaminathan 		ql_printf("0x%016x : %04x %04x %04x %04x %04x %04x %04x %04x\n",
378bafec742SSukumar Swaminathan 		    offset,
379bafec742SSukumar Swaminathan 		    *bp, *(bp+1), *(bp+2), *(bp+3), *(bp+4), *(bp+5), *(bp+6),
380bafec742SSukumar Swaminathan 		    *(bp+7));
381bafec742SSukumar Swaminathan 		break;
382bafec742SSukumar Swaminathan 	}
383bafec742SSukumar Swaminathan 
384bafec742SSukumar Swaminathan 	if (count < 8) {
385bafec742SSukumar Swaminathan 		count = 0;
386bafec742SSukumar Swaminathan 	} else {
387bafec742SSukumar Swaminathan 		count -= 8;
388bafec742SSukumar Swaminathan 	}
389bafec742SSukumar Swaminathan 
390bafec742SSukumar Swaminathan 	return (count);
391bafec742SSukumar Swaminathan }
392bafec742SSukumar Swaminathan 
393bafec742SSukumar Swaminathan /*
394bafec742SSukumar Swaminathan  * Print as 32bit
395bafec742SSukumar Swaminathan  */
396bafec742SSukumar Swaminathan static uint32_t
ql_dump_buf_32(uint32_t * bp,uint32_t count,uint32_t offset)397bafec742SSukumar Swaminathan ql_dump_buf_32(uint32_t *bp, uint32_t count, uint32_t offset)
398bafec742SSukumar Swaminathan {
399bafec742SSukumar Swaminathan 
400bafec742SSukumar Swaminathan 	switch (count) {
401bafec742SSukumar Swaminathan 	case 1:
402bafec742SSukumar Swaminathan 		ql_printf("0x%016x : %08x\n",
403bafec742SSukumar Swaminathan 		    offset,
404bafec742SSukumar Swaminathan 		    *bp);
405bafec742SSukumar Swaminathan 		break;
406bafec742SSukumar Swaminathan 
407bafec742SSukumar Swaminathan 	case 2:
408bafec742SSukumar Swaminathan 		ql_printf("0x%016x : %08x %08x\n",
409bafec742SSukumar Swaminathan 		    offset,
410bafec742SSukumar Swaminathan 		    *bp, *(bp+1));
411bafec742SSukumar Swaminathan 		break;
412bafec742SSukumar Swaminathan 
413bafec742SSukumar Swaminathan 	case 3:
414bafec742SSukumar Swaminathan 		ql_printf("0x%016x : %08x %08x %08x\n",
415bafec742SSukumar Swaminathan 		    offset,
416bafec742SSukumar Swaminathan 		    *bp, *(bp+1), *(bp+2));
417bafec742SSukumar Swaminathan 		break;
418bafec742SSukumar Swaminathan 
419bafec742SSukumar Swaminathan 	default:
420bafec742SSukumar Swaminathan 		ql_printf("0x%016x : %08x %08x %08x %08x\n",
421bafec742SSukumar Swaminathan 		    offset,
422bafec742SSukumar Swaminathan 		    *bp, *(bp+1), *(bp+2), *(bp+3));
423bafec742SSukumar Swaminathan 		break;
424bafec742SSukumar Swaminathan 	}
425bafec742SSukumar Swaminathan 
426bafec742SSukumar Swaminathan 	if (count < 4) {
427bafec742SSukumar Swaminathan 		count = 0;
428bafec742SSukumar Swaminathan 	} else {
429bafec742SSukumar Swaminathan 		count -= 4;
430bafec742SSukumar Swaminathan 	}
431bafec742SSukumar Swaminathan 
432bafec742SSukumar Swaminathan 	return (count);
433bafec742SSukumar Swaminathan }
434bafec742SSukumar Swaminathan 
435bafec742SSukumar Swaminathan /*
436bafec742SSukumar Swaminathan  * Print as 64bit
437bafec742SSukumar Swaminathan  */
438bafec742SSukumar Swaminathan static uint32_t
ql_dump_buf_64(uint64_t * bp,uint32_t count,uint32_t offset)439bafec742SSukumar Swaminathan ql_dump_buf_64(uint64_t *bp, uint32_t count, uint32_t offset)
440bafec742SSukumar Swaminathan {
441bafec742SSukumar Swaminathan 
442bafec742SSukumar Swaminathan 	switch (count) {
443bafec742SSukumar Swaminathan 	case 1:
444bafec742SSukumar Swaminathan 		ql_printf("0x%016x : %016x\n",
445bafec742SSukumar Swaminathan 		    offset,
446bafec742SSukumar Swaminathan 		    *bp);
447bafec742SSukumar Swaminathan 		break;
448bafec742SSukumar Swaminathan 
449bafec742SSukumar Swaminathan 	default:
450bafec742SSukumar Swaminathan 		ql_printf("0x%016x : %016x %016x\n",
451bafec742SSukumar Swaminathan 		    offset,
452bafec742SSukumar Swaminathan 		    *bp, *(bp+1));
453bafec742SSukumar Swaminathan 		break;
454bafec742SSukumar Swaminathan 
455bafec742SSukumar Swaminathan 	}
456bafec742SSukumar Swaminathan 
457bafec742SSukumar Swaminathan 	if (count < 2) {
458bafec742SSukumar Swaminathan 		count = 0;
459bafec742SSukumar Swaminathan 	} else {
460bafec742SSukumar Swaminathan 		count -= 2;
461bafec742SSukumar Swaminathan 	}
462bafec742SSukumar Swaminathan 
463bafec742SSukumar Swaminathan 	return (count);
464bafec742SSukumar Swaminathan }
465bafec742SSukumar Swaminathan 
466bafec742SSukumar Swaminathan /*
467bafec742SSukumar Swaminathan  * Print CQICB control block information
468bafec742SSukumar Swaminathan  */
469bafec742SSukumar Swaminathan /* ARGSUSED */
470bafec742SSukumar Swaminathan void
ql_dump_cqicb(qlge_t * qlge,struct cqicb_t * cqicb)471bafec742SSukumar Swaminathan ql_dump_cqicb(qlge_t *qlge, struct cqicb_t *cqicb)
472bafec742SSukumar Swaminathan {
473bafec742SSukumar Swaminathan 	_NOTE(ARGUNUSED(qlge));
474bafec742SSukumar Swaminathan 	ASSERT(qlge != NULL);
475bafec742SSukumar Swaminathan 	ASSERT(cqicb != NULL);
476bafec742SSukumar Swaminathan 	ql_printf("ql_dump_cqicb:entered\n");
477bafec742SSukumar Swaminathan 
478bafec742SSukumar Swaminathan 	ql_printf("\t msix_vect   = 0x%x\n",
479bafec742SSukumar Swaminathan 	    cqicb->msix_vect);
480bafec742SSukumar Swaminathan 	ql_printf("\t reserved1  = 0x%x\n",
481bafec742SSukumar Swaminathan 	    cqicb->reserved1);
482bafec742SSukumar Swaminathan 	ql_printf("\t reserved2  = 0x%x\n",
483bafec742SSukumar Swaminathan 	    cqicb->reserved2);
484bafec742SSukumar Swaminathan 	ql_printf("\t flags  = 0x%x\n",
485bafec742SSukumar Swaminathan 	    cqicb->flags);
486bafec742SSukumar Swaminathan 	ql_printf("\t len  = 0x%x\n",
487bafec742SSukumar Swaminathan 	    le16_to_cpu(cqicb->len));
488bafec742SSukumar Swaminathan 	ql_printf("\t rid = 0x%x\n",
489bafec742SSukumar Swaminathan 	    le16_to_cpu(cqicb->rid));
490bafec742SSukumar Swaminathan 	ql_printf("\t cq_base_addr_lo = 0x%x\n",
491bafec742SSukumar Swaminathan 	    le32_to_cpu(cqicb->cq_base_addr_lo));
492bafec742SSukumar Swaminathan 	ql_printf("\t cq_base_addr_hi = 0x%x\n",
493bafec742SSukumar Swaminathan 	    le32_to_cpu(cqicb->cq_base_addr_hi));
494bafec742SSukumar Swaminathan 	ql_printf("\t prod_idx_addr_lo = %x\n",
495bafec742SSukumar Swaminathan 	    le32_to_cpu(cqicb->prod_idx_addr_lo));
496bafec742SSukumar Swaminathan 	ql_printf("\t prod_idx_addr_hi = %x\n",
497bafec742SSukumar Swaminathan 	    le32_to_cpu(cqicb->prod_idx_addr_hi));
498bafec742SSukumar Swaminathan 	ql_printf("\t pkt_delay = %d\n",
499bafec742SSukumar Swaminathan 	    le16_to_cpu(cqicb->pkt_delay));
500bafec742SSukumar Swaminathan 	ql_printf("\t irq_delay = 0x%x\n",
501bafec742SSukumar Swaminathan 	    le16_to_cpu(cqicb->irq_delay));
502bafec742SSukumar Swaminathan 	ql_printf("\t lbq_addr_lo = 0x%x\n",
503bafec742SSukumar Swaminathan 	    le32_to_cpu(cqicb->lbq_addr_lo));
504bafec742SSukumar Swaminathan 	ql_printf("\t lbq_addr_hi = 0x%x\n",
505bafec742SSukumar Swaminathan 	    le32_to_cpu(cqicb->lbq_addr_hi));
506bafec742SSukumar Swaminathan 	ql_printf("\t lbq_buf_size = 0x%x\n",
507bafec742SSukumar Swaminathan 	    le16_to_cpu(cqicb->lbq_buf_size));
508bafec742SSukumar Swaminathan 	ql_printf("\t lbq_len = 0x%x\n",
509bafec742SSukumar Swaminathan 	    le16_to_cpu(cqicb->lbq_len));
510bafec742SSukumar Swaminathan 	ql_printf("\t sbq_addr_lo = 0x%x\n",
511bafec742SSukumar Swaminathan 	    le32_to_cpu(cqicb->sbq_addr_lo));
512bafec742SSukumar Swaminathan 	ql_printf("\t sbq_addr_hi = 0x%x\n",
513bafec742SSukumar Swaminathan 	    le32_to_cpu(cqicb->sbq_addr_hi));
514bafec742SSukumar Swaminathan 	ql_printf("\t sbq_buf_size = 0x%x\n",
515bafec742SSukumar Swaminathan 	    le16_to_cpu(cqicb->sbq_buf_size));
516bafec742SSukumar Swaminathan 	ql_printf("\t sbq_len = 0x%x\n",
517bafec742SSukumar Swaminathan 	    le16_to_cpu(cqicb->sbq_len));
518bafec742SSukumar Swaminathan 
519bafec742SSukumar Swaminathan 	ql_printf("ql_dump_cqicb:exiting\n");
520bafec742SSukumar Swaminathan }
521bafec742SSukumar Swaminathan 
522bafec742SSukumar Swaminathan /*
523bafec742SSukumar Swaminathan  * Print WQICB control block information
524bafec742SSukumar Swaminathan  */
525bafec742SSukumar Swaminathan /* ARGSUSED */
526bafec742SSukumar Swaminathan void
ql_dump_wqicb(qlge_t * qlge,struct wqicb_t * wqicb)527bafec742SSukumar Swaminathan ql_dump_wqicb(qlge_t *qlge, struct wqicb_t *wqicb)
528bafec742SSukumar Swaminathan {
529bafec742SSukumar Swaminathan 	_NOTE(ARGUNUSED(qlge));
530bafec742SSukumar Swaminathan 	ASSERT(qlge != NULL);
531bafec742SSukumar Swaminathan 	ASSERT(wqicb != NULL);
532bafec742SSukumar Swaminathan 
533bafec742SSukumar Swaminathan 	ql_printf("ql_dump_wqicb:entered\n");
534bafec742SSukumar Swaminathan 
535bafec742SSukumar Swaminathan 	ql_printf("\t len = %x\n",
536bafec742SSukumar Swaminathan 	    le16_to_cpu(wqicb->len));
537bafec742SSukumar Swaminathan 	ql_printf("\t flags = %x\n",
538bafec742SSukumar Swaminathan 	    le16_to_cpu(wqicb->flags));
539bafec742SSukumar Swaminathan 	ql_printf("\t cq_id_rss = %x\n",
540bafec742SSukumar Swaminathan 	    le16_to_cpu(wqicb->cq_id_rss));
541bafec742SSukumar Swaminathan 	ql_printf("\t rid = 0x%x\n",
542bafec742SSukumar Swaminathan 	    le16_to_cpu(wqicb->rid));
543bafec742SSukumar Swaminathan 	ql_printf("\t wq_addr_lo = 0x%x\n",
544bafec742SSukumar Swaminathan 	    le32_to_cpu(wqicb->wq_addr_lo));
545bafec742SSukumar Swaminathan 	ql_printf("\t wq_addr_hi = 0x%x\n",
546bafec742SSukumar Swaminathan 	    le32_to_cpu(wqicb->wq_addr_hi));
547bafec742SSukumar Swaminathan 	ql_printf("\t cnsmr_idx_addr_lo = %x\n",
548bafec742SSukumar Swaminathan 	    le32_to_cpu(wqicb->cnsmr_idx_addr_lo));
549bafec742SSukumar Swaminathan 	ql_printf("\t cnsmr_idx_addr_hi = %x\n",
550bafec742SSukumar Swaminathan 	    le32_to_cpu(wqicb->cnsmr_idx_addr_hi));
551bafec742SSukumar Swaminathan 
552bafec742SSukumar Swaminathan 	ql_printf("ql_dump_wqicb:exit\n");
553bafec742SSukumar Swaminathan }
554bafec742SSukumar Swaminathan 
555bafec742SSukumar Swaminathan /*
556bafec742SSukumar Swaminathan  * Print request descriptor information
557bafec742SSukumar Swaminathan  */
558bafec742SSukumar Swaminathan void
ql_dump_req_pkt(qlge_t * qlge,struct ob_mac_iocb_req * pkt,void * oal,int number)559bafec742SSukumar Swaminathan ql_dump_req_pkt(qlge_t *qlge, struct ob_mac_iocb_req *pkt, void *oal,
560bafec742SSukumar Swaminathan     int number)
561bafec742SSukumar Swaminathan {
562bafec742SSukumar Swaminathan 	int i = 0;
563bafec742SSukumar Swaminathan 	struct oal_entry *oal_entry;
564bafec742SSukumar Swaminathan 
565bafec742SSukumar Swaminathan 	ql_printf("ql_dump_req_pkt(%d):enter\n", qlge->instance);
566bafec742SSukumar Swaminathan 
567bafec742SSukumar Swaminathan 	ql_printf("\t opcode = 0x%x\n",
568bafec742SSukumar Swaminathan 	    pkt->opcode);
569bafec742SSukumar Swaminathan 	ql_printf("\t flag0  = 0x%x\n",
570bafec742SSukumar Swaminathan 	    pkt->flag0);
571bafec742SSukumar Swaminathan 	ql_printf("\t flag1  = 0x%x\n",
572bafec742SSukumar Swaminathan 	    pkt->flag1);
573bafec742SSukumar Swaminathan 	ql_printf("\t flag2  = 0x%x\n",
574bafec742SSukumar Swaminathan 	    pkt->flag2);
575bafec742SSukumar Swaminathan 	ql_printf("\t frame_len  = 0x%x\n",
576bafec742SSukumar Swaminathan 	    le16_to_cpu(pkt->frame_len));
577bafec742SSukumar Swaminathan 	ql_printf("\t transaction_id_low = 0x%x\n",
578bafec742SSukumar Swaminathan 	    le16_to_cpu(pkt->tid));
579bafec742SSukumar Swaminathan 	ql_printf("\t txq_idx = 0x%x\n",
580bafec742SSukumar Swaminathan 	    le16_to_cpu(pkt->txq_idx));
581bafec742SSukumar Swaminathan 	ql_printf("\t protocol_hdr_len = 0x%x\n",
582bafec742SSukumar Swaminathan 	    le16_to_cpu(pkt->protocol_hdr_len));
583bafec742SSukumar Swaminathan 	ql_printf("\t hdr_off = %d\n",
584bafec742SSukumar Swaminathan 	    le16_to_cpu(pkt->hdr_off));
585bafec742SSukumar Swaminathan 	ql_printf("\t vlan_tci = %d\n",
586bafec742SSukumar Swaminathan 	    le16_to_cpu(pkt->vlan_tci));
587bafec742SSukumar Swaminathan 	ql_printf("\t mss = %d\n",
588bafec742SSukumar Swaminathan 	    le16_to_cpu(pkt->mss));
589bafec742SSukumar Swaminathan 
590bafec742SSukumar Swaminathan 	/* if OAL is needed */
591bafec742SSukumar Swaminathan 	if (number > TX_DESC_PER_IOCB) {
592bafec742SSukumar Swaminathan 		for (i = 0; i < TX_DESC_PER_IOCB; i++) {
593bafec742SSukumar Swaminathan 			ql_printf("\t buf_addr%d_low = 0x%x\n",
594bafec742SSukumar Swaminathan 			    i, pkt->oal_entry[i].buf_addr_low);
595bafec742SSukumar Swaminathan 			ql_printf("\t buf_addr%d_high = 0x%x\n",
596bafec742SSukumar Swaminathan 			    i, pkt->oal_entry[i].buf_addr_high);
597bafec742SSukumar Swaminathan 			ql_printf("\t buf%d_len = 0x%x\n",
598bafec742SSukumar Swaminathan 			    i, pkt->oal_entry[i].buf_len);
599bafec742SSukumar Swaminathan 		}
600bafec742SSukumar Swaminathan 		oal_entry = (struct oal_entry *)oal;
601bafec742SSukumar Swaminathan 		ql_printf("\t additional %d tx descriptors in OAL\n",
602bafec742SSukumar Swaminathan 		    (number - TX_DESC_PER_IOCB + 1));
603bafec742SSukumar Swaminathan 		for (i = 0; i < (number-TX_DESC_PER_IOCB + 1); i++) {
604bafec742SSukumar Swaminathan 			ql_printf("\t buf_addr%d_low = 0x%x\n",
605bafec742SSukumar Swaminathan 			    i, oal_entry[i].buf_addr_low);
606bafec742SSukumar Swaminathan 			ql_printf("\t buf_addr%d_high = 0x%x\n",
607bafec742SSukumar Swaminathan 			    i, oal_entry[i].buf_addr_high);
608bafec742SSukumar Swaminathan 			ql_printf("\t buf%d_len = 0x%x\n",
609bafec742SSukumar Swaminathan 			    i, oal_entry[i].buf_len);
610bafec742SSukumar Swaminathan 		}
611bafec742SSukumar Swaminathan 	} else {
612bafec742SSukumar Swaminathan 		for (i = 0; i < number; i++) {
613bafec742SSukumar Swaminathan 			ql_printf("\t buf_addr%d_low = 0x%x\n",
614bafec742SSukumar Swaminathan 			    i, pkt->oal_entry[i].buf_addr_low);
615bafec742SSukumar Swaminathan 			ql_printf("\t buf_addr%d_high = 0x%x\n",
616bafec742SSukumar Swaminathan 			    i, pkt->oal_entry[i].buf_addr_high);
617bafec742SSukumar Swaminathan 			ql_printf("\t buf%d_len = 0x%x\n",
618bafec742SSukumar Swaminathan 			    i, pkt->oal_entry[i].buf_len);
619bafec742SSukumar Swaminathan 		}
620bafec742SSukumar Swaminathan 	}
621bafec742SSukumar Swaminathan 	ql_printf("ql_dump_req_pkt:exiting\n");
622bafec742SSukumar Swaminathan }
623bafec742SSukumar Swaminathan 
624bafec742SSukumar Swaminathan /*
625bafec742SSukumar Swaminathan  * Print PCI configuration
626bafec742SSukumar Swaminathan  */
627bafec742SSukumar Swaminathan void
ql_dump_pci_config(qlge_t * qlge)628bafec742SSukumar Swaminathan ql_dump_pci_config(qlge_t *qlge)
629bafec742SSukumar Swaminathan {
630bafec742SSukumar Swaminathan 	qlge->pci_cfg.vendor_id = (uint16_t)
631bafec742SSukumar Swaminathan 	    pci_config_get16(qlge->pci_handle, PCI_CONF_VENID);
632bafec742SSukumar Swaminathan 
633bafec742SSukumar Swaminathan 	qlge->pci_cfg.device_id = (uint16_t)
634bafec742SSukumar Swaminathan 	    pci_config_get16(qlge->pci_handle, PCI_CONF_DEVID);
635bafec742SSukumar Swaminathan 
636bafec742SSukumar Swaminathan 	qlge->pci_cfg.command = (uint16_t)
637bafec742SSukumar Swaminathan 	    pci_config_get16(qlge->pci_handle, PCI_CONF_COMM);
638bafec742SSukumar Swaminathan 
639bafec742SSukumar Swaminathan 	qlge->pci_cfg.status = (uint16_t)
640bafec742SSukumar Swaminathan 	    pci_config_get16(qlge->pci_handle, PCI_CONF_STAT);
641bafec742SSukumar Swaminathan 
642bafec742SSukumar Swaminathan 	qlge->pci_cfg.revision = (uint8_t)
643bafec742SSukumar Swaminathan 	    pci_config_get8(qlge->pci_handle, PCI_CONF_REVID);
644bafec742SSukumar Swaminathan 
645bafec742SSukumar Swaminathan 	qlge->pci_cfg.prog_class = (uint8_t)
646bafec742SSukumar Swaminathan 	    pci_config_get8(qlge->pci_handle, PCI_CONF_PROGCLASS);
647bafec742SSukumar Swaminathan 
648bafec742SSukumar Swaminathan 	qlge->pci_cfg.sub_class = (uint8_t)
649bafec742SSukumar Swaminathan 	    pci_config_get8(qlge->pci_handle, PCI_CONF_SUBCLASS);
650bafec742SSukumar Swaminathan 
651bafec742SSukumar Swaminathan 	qlge->pci_cfg.base_class = (uint8_t)
652bafec742SSukumar Swaminathan 	    pci_config_get8(qlge->pci_handle, PCI_CONF_BASCLASS);
653bafec742SSukumar Swaminathan 
654bafec742SSukumar Swaminathan 	qlge->pci_cfg.cache_line_size = (uint8_t)
655bafec742SSukumar Swaminathan 	    pci_config_get8(qlge->pci_handle, PCI_CONF_CACHE_LINESZ);
656bafec742SSukumar Swaminathan 
657bafec742SSukumar Swaminathan 	qlge->pci_cfg.latency_timer = (uint8_t)
658bafec742SSukumar Swaminathan 	    pci_config_get8(qlge->pci_handle, PCI_CONF_LATENCY_TIMER);
659bafec742SSukumar Swaminathan 
660bafec742SSukumar Swaminathan 	qlge->pci_cfg.header_type = (uint8_t)
661bafec742SSukumar Swaminathan 	    pci_config_get8(qlge->pci_handle, PCI_CONF_HEADER);
662bafec742SSukumar Swaminathan 
663bafec742SSukumar Swaminathan 	qlge->pci_cfg.io_base_address =
664bafec742SSukumar Swaminathan 	    pci_config_get32(qlge->pci_handle, PCI_CONF_BASE0);
665bafec742SSukumar Swaminathan 
666bafec742SSukumar Swaminathan 	qlge->pci_cfg.pci_cntl_reg_set_mem_base_address_lower =
667bafec742SSukumar Swaminathan 	    pci_config_get32(qlge->pci_handle, PCI_CONF_BASE1);
668bafec742SSukumar Swaminathan 
669bafec742SSukumar Swaminathan 	qlge->pci_cfg.pci_cntl_reg_set_mem_base_address_upper =
670bafec742SSukumar Swaminathan 	    pci_config_get32(qlge->pci_handle, PCI_CONF_BASE2);
671bafec742SSukumar Swaminathan 
672bafec742SSukumar Swaminathan 	qlge->pci_cfg.pci_doorbell_mem_base_address_lower =
673bafec742SSukumar Swaminathan 	    pci_config_get32(qlge->pci_handle, PCI_CONF_BASE3);
674bafec742SSukumar Swaminathan 
675bafec742SSukumar Swaminathan 	qlge->pci_cfg.pci_doorbell_mem_base_address_upper =
676bafec742SSukumar Swaminathan 	    pci_config_get32(qlge->pci_handle, PCI_CONF_BASE4);
677bafec742SSukumar Swaminathan 
678bafec742SSukumar Swaminathan 	qlge->pci_cfg.sub_vendor_id = (uint16_t)
679bafec742SSukumar Swaminathan 	    pci_config_get16(qlge->pci_handle, PCI_CONF_SUBVENID);
680bafec742SSukumar Swaminathan 
681bafec742SSukumar Swaminathan 	qlge->pci_cfg.sub_device_id = (uint16_t)
682bafec742SSukumar Swaminathan 	    pci_config_get16(qlge->pci_handle, PCI_CONF_SUBSYSID);
683bafec742SSukumar Swaminathan 
684bafec742SSukumar Swaminathan 	qlge->pci_cfg.expansion_rom =
685bafec742SSukumar Swaminathan 	    pci_config_get32(qlge->pci_handle, PCI_CONF_ROM);
686bafec742SSukumar Swaminathan 
687bafec742SSukumar Swaminathan 	qlge->pci_cfg.intr_line = (uint8_t)
688bafec742SSukumar Swaminathan 	    pci_config_get8(qlge->pci_handle, PCI_CONF_ILINE);
689bafec742SSukumar Swaminathan 
690bafec742SSukumar Swaminathan 	qlge->pci_cfg.intr_pin = (uint8_t)
691bafec742SSukumar Swaminathan 	    pci_config_get8(qlge->pci_handle, PCI_CONF_IPIN);
692bafec742SSukumar Swaminathan 
693bafec742SSukumar Swaminathan 	qlge->pci_cfg.min_grant = (uint8_t)
694bafec742SSukumar Swaminathan 	    pci_config_get8(qlge->pci_handle, PCI_CONF_MIN_G);
695bafec742SSukumar Swaminathan 
696bafec742SSukumar Swaminathan 	qlge->pci_cfg.max_latency = (uint8_t)
697bafec742SSukumar Swaminathan 	    pci_config_get8(qlge->pci_handle, PCI_CONF_MAX_L);
698bafec742SSukumar Swaminathan 
699bafec742SSukumar Swaminathan 	qlge->pci_cfg.pcie_device_control = (uint16_t)
700bafec742SSukumar Swaminathan 	    pci_config_get16(qlge->pci_handle, 0x54);
701bafec742SSukumar Swaminathan 
702bafec742SSukumar Swaminathan 	qlge->pci_cfg.link_status = (uint16_t)
703bafec742SSukumar Swaminathan 	    pci_config_get16(qlge->pci_handle, 0x5e);
704bafec742SSukumar Swaminathan 
705bafec742SSukumar Swaminathan 	qlge->pci_cfg.msi_msg_control = (uint16_t)
706bafec742SSukumar Swaminathan 	    pci_config_get16(qlge->pci_handle, 0x8a);
707bafec742SSukumar Swaminathan 
708bafec742SSukumar Swaminathan 	qlge->pci_cfg.msi_x_msg_control = (uint16_t)
709bafec742SSukumar Swaminathan 	    pci_config_get16(qlge->pci_handle, 0xa2);
710bafec742SSukumar Swaminathan 
711bafec742SSukumar Swaminathan 	if (qlge->ql_dbgprnt & DBG_GLD) {
712accf27a5SSukumar Swaminathan 		ql_printf("ql_dump_pci_config(%d): enter\n",
713accf27a5SSukumar Swaminathan 		    qlge->instance);
714bafec742SSukumar Swaminathan 		ql_printf("\tvendorid =0x%x.\n",
715bafec742SSukumar Swaminathan 		    qlge->pci_cfg.vendor_id);
716bafec742SSukumar Swaminathan 		ql_printf("\tdeviceid =0x%x.\n",
717bafec742SSukumar Swaminathan 		    qlge->pci_cfg.device_id);
718bafec742SSukumar Swaminathan 		ql_printf("\tcommand =0x%x.\n",
719bafec742SSukumar Swaminathan 		    qlge->pci_cfg.command);
720bafec742SSukumar Swaminathan 		ql_printf("\tstatus =0x%x.\n",
721bafec742SSukumar Swaminathan 		    qlge->pci_cfg.status);
722bafec742SSukumar Swaminathan 		ql_printf("\trevision id =0x%x.\n",
723bafec742SSukumar Swaminathan 		    qlge->pci_cfg.revision);
724bafec742SSukumar Swaminathan 		ql_printf("\tprogram class =0x%x.\n",
725bafec742SSukumar Swaminathan 		    qlge->pci_cfg.prog_class);
726bafec742SSukumar Swaminathan 		ql_printf("\tsubclass code =0x%x.\n",
727bafec742SSukumar Swaminathan 		    qlge->pci_cfg.sub_class);
728bafec742SSukumar Swaminathan 		ql_printf("\tbase class code =0x%x.\n",
729bafec742SSukumar Swaminathan 		    qlge->pci_cfg.base_class);
730bafec742SSukumar Swaminathan 		ql_printf("\tcache line size =0x%x.\n",
731bafec742SSukumar Swaminathan 		    qlge->pci_cfg.cache_line_size);
732bafec742SSukumar Swaminathan 		ql_printf("\tlatency timer =0x%x.\n",
733bafec742SSukumar Swaminathan 		    qlge->pci_cfg.latency_timer);
734bafec742SSukumar Swaminathan 		ql_printf("\theader =0x%x.\n",
735bafec742SSukumar Swaminathan 		    qlge->pci_cfg.header_type);
736bafec742SSukumar Swaminathan 		ql_printf("\tI/O Base Register Address0 =0x%x.\n",
737bafec742SSukumar Swaminathan 		    qlge->pci_cfg.io_base_address);
738bafec742SSukumar Swaminathan 		ql_printf("\tpci_cntl_reg_set_mem_base_address_lower =0x%x.\n",
739bafec742SSukumar Swaminathan 		    qlge->pci_cfg.pci_cntl_reg_set_mem_base_address_lower);
740bafec742SSukumar Swaminathan 		ql_printf("\tpci_cntl_reg_set_mem_base_address_upper =0x%x.\n",
741bafec742SSukumar Swaminathan 		    qlge->pci_cfg.pci_cntl_reg_set_mem_base_address_upper);
742bafec742SSukumar Swaminathan 		ql_printf("\tpci_doorbell_mem_base_address_lower =0x%x.\n",
743bafec742SSukumar Swaminathan 		    qlge->pci_cfg.pci_doorbell_mem_base_address_lower);
744bafec742SSukumar Swaminathan 		ql_printf("\tpci_doorbell_mem_base_address_upper =0x%x.\n",
745bafec742SSukumar Swaminathan 		    qlge->pci_cfg.pci_doorbell_mem_base_address_upper);
746*d0b12b66SToomas Soome 		ql_printf("\tSubsystem Vendor Id =0x%x.\n",
747bafec742SSukumar Swaminathan 		    qlge->pci_cfg.sub_vendor_id);
748*d0b12b66SToomas Soome 		ql_printf("\tSubsystem Id =0x%x.\n",
749bafec742SSukumar Swaminathan 		    qlge->pci_cfg.sub_device_id);
750bafec742SSukumar Swaminathan 		ql_printf("\tExpansion ROM Base Register =0x%x.\n",
751bafec742SSukumar Swaminathan 		    qlge->pci_cfg.expansion_rom);
752bafec742SSukumar Swaminathan 		ql_printf("\tInterrupt Line =0x%x.\n",
753bafec742SSukumar Swaminathan 		    qlge->pci_cfg.intr_line);
754bafec742SSukumar Swaminathan 		ql_printf("\tInterrupt Pin =0x%x.\n",
755bafec742SSukumar Swaminathan 		    qlge->pci_cfg.intr_pin);
756bafec742SSukumar Swaminathan 		ql_printf("\tMin Grant =0x%x.\n",
757bafec742SSukumar Swaminathan 		    qlge->pci_cfg.min_grant);
758bafec742SSukumar Swaminathan 		ql_printf("\tMax Grant =0x%x.\n",
759bafec742SSukumar Swaminathan 		    qlge->pci_cfg.max_latency);
760bafec742SSukumar Swaminathan 		ql_printf("\tdevice_control =0x%x.\n",
761bafec742SSukumar Swaminathan 		    qlge->pci_cfg.pcie_device_control);
762bafec742SSukumar Swaminathan 		ql_printf("\tlink_status =0x%x.\n",
763bafec742SSukumar Swaminathan 		    qlge->pci_cfg.link_status);
764bafec742SSukumar Swaminathan 		ql_printf("\tmsi_msg_control =0x%x.\n",
765bafec742SSukumar Swaminathan 		    qlge->pci_cfg.msi_msg_control);
766bafec742SSukumar Swaminathan 		ql_printf("\tmsi_x_msg_control =0x%x.\n",
767bafec742SSukumar Swaminathan 		    qlge->pci_cfg.msi_x_msg_control);
768bafec742SSukumar Swaminathan 
769accf27a5SSukumar Swaminathan 		ql_printf("ql_dump_pci_config(%d): exit\n", qlge->instance);
770bafec742SSukumar Swaminathan 	}
771bafec742SSukumar Swaminathan }
772bafec742SSukumar Swaminathan 
773bafec742SSukumar Swaminathan /*
774bafec742SSukumar Swaminathan  * Print a formated string
775bafec742SSukumar Swaminathan  */
776bafec742SSukumar Swaminathan void
ql_printf(const char * fmt,...)777bafec742SSukumar Swaminathan ql_printf(const char *fmt, ...)
778bafec742SSukumar Swaminathan {
779bafec742SSukumar Swaminathan 	va_list ap;
780bafec742SSukumar Swaminathan 
781bafec742SSukumar Swaminathan 	va_start(ap, fmt);
782bafec742SSukumar Swaminathan 	vcmn_err(CE_CONT, fmt, ap);
783bafec742SSukumar Swaminathan 	va_end(ap);
784bafec742SSukumar Swaminathan 
785bafec742SSukumar Swaminathan }
786bafec742SSukumar Swaminathan 
787bafec742SSukumar Swaminathan /*
788bafec742SSukumar Swaminathan  * Read all control registers value and save in a string
789bafec742SSukumar Swaminathan  */
790bafec742SSukumar Swaminathan static uint32_t
read_ctrl_reg_set(qlge_t * qlge,caddr_t bufp)791bafec742SSukumar Swaminathan read_ctrl_reg_set(qlge_t *qlge, caddr_t bufp)
792bafec742SSukumar Swaminathan {
793bafec742SSukumar Swaminathan 	int i, j;
794bafec742SSukumar Swaminathan 	uint32_t data;
795bafec742SSukumar Swaminathan 	caddr_t bp = bufp;
796bafec742SSukumar Swaminathan 	uint32_t cnt;
797bafec742SSukumar Swaminathan 
798bafec742SSukumar Swaminathan 	/* read Reg 0 -0xC4 */
799bafec742SSukumar Swaminathan 	for (i = 0, j = 0; i <= 0xfc; i += 4) {
800bafec742SSukumar Swaminathan 		data = ql_read_reg(qlge, i);
801bafec742SSukumar Swaminathan 		(void) sprintf(bp, "Register[%x] = 0x%x\n", i, data);
802bafec742SSukumar Swaminathan 		bp += strlen(bp);
803bafec742SSukumar Swaminathan 		if (i == REG_INTERRUPT_ENABLE) {
804bafec742SSukumar Swaminathan 			/* Read */
805bafec742SSukumar Swaminathan 			data = INTR_EN_TYPE_READ;
806bafec742SSukumar Swaminathan 			ql_write_reg(qlge, i, (data | (data << 16)));
807bafec742SSukumar Swaminathan 			data = ql_read_reg(qlge, i);
808bafec742SSukumar Swaminathan 			if (data & INTR_EN_EN) {
809bafec742SSukumar Swaminathan 				(void) sprintf(bp, "Intr0 enabled: 0x%x\n",
810bafec742SSukumar Swaminathan 				    data);
811bafec742SSukumar Swaminathan 				bp += strlen(bp);
812bafec742SSukumar Swaminathan 			} else {
813bafec742SSukumar Swaminathan 				(void) sprintf(bp, "Intr0 disabled: 0x%x\n",
814bafec742SSukumar Swaminathan 				    data);
815bafec742SSukumar Swaminathan 				bp += strlen(bp);
816bafec742SSukumar Swaminathan 			}
817bafec742SSukumar Swaminathan 		}
818bafec742SSukumar Swaminathan 		j++;
819bafec742SSukumar Swaminathan 	}
820bafec742SSukumar Swaminathan 	*bp = '\0';
821bafec742SSukumar Swaminathan 	bp++;
822bafec742SSukumar Swaminathan 	cnt = (uint32_t)((uintptr_t)bp - (uintptr_t)bufp);
823bafec742SSukumar Swaminathan 	QL_PRINT(DBG_GLD, ("%s(%d) %x bytes to export\n",
824bafec742SSukumar Swaminathan 	    __func__, qlge->instance, cnt));
825bafec742SSukumar Swaminathan 	return (cnt);
826bafec742SSukumar Swaminathan }
827bafec742SSukumar Swaminathan 
828bafec742SSukumar Swaminathan /*
829bafec742SSukumar Swaminathan  * Get address and size of image tables in flash memory
830bafec742SSukumar Swaminathan  */
831bafec742SSukumar Swaminathan static int
ql_get_flash_table_region_info(qlge_t * qlge,uint32_t region,uint32_t * addr,uint32_t * size)832bafec742SSukumar Swaminathan ql_get_flash_table_region_info(qlge_t *qlge, uint32_t region, uint32_t *addr,
833bafec742SSukumar Swaminathan     uint32_t *size)
834bafec742SSukumar Swaminathan {
835bafec742SSukumar Swaminathan 	int rval = DDI_SUCCESS;
836bafec742SSukumar Swaminathan 
837bafec742SSukumar Swaminathan 	switch (region) {
838bafec742SSukumar Swaminathan 	case FLT_REGION_FDT:
839bafec742SSukumar Swaminathan 		*addr = ISP_8100_FDT_ADDR;
840bafec742SSukumar Swaminathan 		*size = ISP_8100_FDT_SIZE;
841bafec742SSukumar Swaminathan 		break;
842bafec742SSukumar Swaminathan 	case FLT_REGION_FLT:
843bafec742SSukumar Swaminathan 		*addr = ISP_8100_FLT_ADDR;
844bafec742SSukumar Swaminathan 		*size = ISP_8100_FLT_SIZE;
845bafec742SSukumar Swaminathan 		break;
846bafec742SSukumar Swaminathan 	case FLT_REGION_NIC_BOOT_CODE:
847bafec742SSukumar Swaminathan 		*addr = ISP_8100_NIC_BOOT_CODE_ADDR;
848bafec742SSukumar Swaminathan 		*size = ISP_8100_NIC_BOOT_CODE_SIZE;
849bafec742SSukumar Swaminathan 		break;
850bafec742SSukumar Swaminathan 	case FLT_REGION_MPI_FW_USE:
851bafec742SSukumar Swaminathan 		*addr = ISP_8100_MPI_FW_USE_ADDR;
852bafec742SSukumar Swaminathan 		*size = ISP_8100_MPI_FW_USE_SIZE;
853bafec742SSukumar Swaminathan 		break;
854bafec742SSukumar Swaminathan 	case FLT_REGION_MPI_RISC_FW:
855bafec742SSukumar Swaminathan 		*addr = ISP_8100_MPI_RISC_FW_ADDR;
856bafec742SSukumar Swaminathan 		*size = ISP_8100_MPI_RISC_FW_SIZE;
857bafec742SSukumar Swaminathan 		break;
858bafec742SSukumar Swaminathan 	case FLT_REGION_VPD0:
859bafec742SSukumar Swaminathan 		*addr = ISP_8100_VPD0_ADDR;
860bafec742SSukumar Swaminathan 		*size = ISP_8100_VPD0_SIZE;
861bafec742SSukumar Swaminathan 		break;
862bafec742SSukumar Swaminathan 	case FLT_REGION_NIC_PARAM0:
863bafec742SSukumar Swaminathan 		*addr = ISP_8100_NIC_PARAM0_ADDR;
864bafec742SSukumar Swaminathan 		*size = ISP_8100_NIC_PARAM0_SIZE;
865bafec742SSukumar Swaminathan 		break;
866bafec742SSukumar Swaminathan 	case FLT_REGION_VPD1:
867bafec742SSukumar Swaminathan 		*addr = ISP_8100_VPD1_ADDR;
868bafec742SSukumar Swaminathan 		*size = ISP_8100_VPD1_SIZE;
869bafec742SSukumar Swaminathan 		break;
870bafec742SSukumar Swaminathan 	case FLT_REGION_NIC_PARAM1:
871bafec742SSukumar Swaminathan 		*addr = ISP_8100_NIC_PARAM1_ADDR;
872bafec742SSukumar Swaminathan 		*size = ISP_8100_NIC_PARAM1_SIZE;
873bafec742SSukumar Swaminathan 		break;
874bafec742SSukumar Swaminathan 	case FLT_REGION_MPI_CFG:
875bafec742SSukumar Swaminathan 		*addr = ISP_8100_MPI_CFG_ADDR;
876bafec742SSukumar Swaminathan 		*size = ISP_8100_MPI_CFG_SIZE;
877bafec742SSukumar Swaminathan 		break;
878bafec742SSukumar Swaminathan 	case FLT_REGION_EDC_PHY_FW:
879bafec742SSukumar Swaminathan 		*addr = ISP_8100_EDC_PHY_FW_ADDR;
880bafec742SSukumar Swaminathan 		*size =