xref: /illumos-gate/usr/src/uts/common/io/cxgbe/t4nex/t4_ioctl.c (revision 5f82aa32fbc5dc2c59bca6ff315f44a4c4c9ea86)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source. A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * This file is part of the Chelsio T4 support code.
14  *
15  * Copyright (C) 2011-2013 Chelsio Communications.  All rights reserved.
16  *
17  * This program is distributed in the hope that it will be useful, but WITHOUT
18  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19  * FITNESS FOR A PARTICULAR PURPOSE.  See the LICENSE file included in this
20  * release for licensing terms and conditions.
21  */
22 
23 #include <sys/ddi.h>
24 #include <sys/sunddi.h>
25 #include <sys/queue.h>
26 
27 #include "t4nex.h"
28 #include "common/common.h"
29 #include "common/t4_regs.h"
30 
31 /* helpers */
32 static int pci_rw(struct adapter *sc, void *data, int flags, int write);
33 static int reg_rw(struct adapter *sc, void *data, int flags, int write);
34 static void reg_block_dump(struct adapter *sc, uint8_t *buf, unsigned int start,
35     unsigned int end);
36 static int regdump(struct adapter *sc, void *data, int flags);
37 static int get_sge_context(struct adapter *sc, void *data, int flags);
38 static int get_devlog(struct adapter *sc, void *data, int flags);
39 static int validate_mem_range(struct adapter *, uint32_t, int);
40 static int read_card_mem(struct adapter *sc, void *data, int flags);
41 static int read_tid_tab(struct adapter *sc, void *data, int flags);
42 static int read_mbox(struct adapter *sc, void *data, int flags);
43 static int read_cim_la(struct adapter *sc, void *data, int flags);
44 static int read_cim_qcfg(struct adapter *sc, void *data, int flags);
45 static int read_cim_ibq(struct adapter *sc, void *data, int flags);
46 static int read_edc(struct adapter *sc, void *data, int flags);
47 
48 int
49 t4_ioctl(struct adapter *sc, int cmd, void *data, int mode)
50 {
51 	int rc = ENOTSUP;
52 
53 	switch (cmd) {
54 	case T4_IOCTL_PCIGET32:
55 	case T4_IOCTL_PCIPUT32:
56 		rc = pci_rw(sc, data, mode, cmd == T4_IOCTL_PCIPUT32);
57 		break;
58 	case T4_IOCTL_GET32:
59 	case T4_IOCTL_PUT32:
60 		rc = reg_rw(sc, data, mode, cmd == T4_IOCTL_PUT32);
61 		break;
62 	case T4_IOCTL_REGDUMP:
63 		rc = regdump(sc, data, mode);
64 		break;
65 	case T4_IOCTL_SGE_CONTEXT:
66 		rc = get_sge_context(sc, data, mode);
67 		break;
68 	case T4_IOCTL_DEVLOG:
69 		rc = get_devlog(sc, data, mode);
70 		break;
71 	case T4_IOCTL_GET_MEM:
72 		rc = read_card_mem(sc, data, mode);
73 		break;
74 	case T4_IOCTL_GET_TID_TAB:
75 		rc = read_tid_tab(sc, data, mode);
76 		break;
77 	case T4_IOCTL_GET_MBOX:
78 		rc = read_mbox(sc, data, mode);
79 		break;
80 	case T4_IOCTL_GET_CIM_LA:
81 		rc = read_cim_la(sc, data, mode);
82 		break;
83 	case T4_IOCTL_GET_CIM_QCFG:
84 		rc = read_cim_qcfg(sc, data, mode);
85 		break;
86 	case T4_IOCTL_GET_CIM_IBQ:
87 		rc = read_cim_ibq(sc, data, mode);
88 		break;
89 	case T4_IOCTL_GET_EDC:
90 		rc = read_edc(sc, data, mode);
91 		break;
92 	default:
93 		return (EINVAL);
94 	}
95 
96 	return (rc);
97 }
98 
99 static int
100 pci_rw(struct adapter *sc, void *data, int flags, int write)
101 {
102 	struct t4_reg32_cmd r;
103 
104 	if (ddi_copyin(data, &r, sizeof (r), flags) < 0)
105 		return (EFAULT);
106 
107 	/* address must be 32 bit aligned */
108 	r.reg &= ~0x3;
109 
110 	if (write != 0)
111 		t4_os_pci_write_cfg4(sc, r.reg, r.value);
112 	else {
113 		t4_os_pci_read_cfg4(sc, r.reg, &r.value);
114 		if (ddi_copyout(&r, data, sizeof (r), flags) < 0)
115 			return (EFAULT);
116 	}
117 
118 	return (0);
119 }
120 
121 static int
122 reg_rw(struct adapter *sc, void *data, int flags, int write)
123 {
124 	struct t4_reg32_cmd r;
125 
126 	if (ddi_copyin(data, &r, sizeof (r), flags) < 0)
127 		return (EFAULT);
128 
129 	/* Register address must be 32 bit aligned */
130 	r.reg &= ~0x3;
131 
132 	if (write != 0)
133 		t4_write_reg(sc, r.reg, r.value);
134 	else {
135 		r.value = t4_read_reg(sc, r.reg);
136 		if (ddi_copyout(&r, data, sizeof (r), flags) < 0)
137 			return (EFAULT);
138 	}
139 
140 	return (0);
141 }
142 
143 static void
144 reg_block_dump(struct adapter *sc, uint8_t *buf, unsigned int start,
145     unsigned int end)
146 {
147 	/* LINTED: E_BAD_PTR_CAST_ALIGN */
148 	uint32_t *p = (uint32_t *)(buf + start);
149 
150 	for (/* */; start <= end; start += sizeof (uint32_t))
151 		*p++ = t4_read_reg(sc, start);
152 }
153 
154 /*
155  * Return a version number to identify the type of adapter.  The scheme is:
156  * - bits 0..9: chip version
157  * - bits 10..15: chip revision
158  * - bits 16..23: register dump version
159  */
160 static inline
161 unsigned int mk_adap_vers(const struct adapter *sc)
162 {
163 	return CHELSIO_CHIP_VERSION(sc->params.chip) |
164 		(CHELSIO_CHIP_RELEASE(sc->params.chip) << 10) | (1 << 16);
165 }
166 
167 static int
168 regdump(struct adapter *sc, void *data, int flags)
169 {
170 	struct t4_regdump r;
171 	uint8_t *buf;
172 	static const unsigned int *reg_ranges;
173 	int rc = 0, arr_size = 0, buf_size = 0, i;
174 	static const unsigned int t4_reg_ranges[] = {
175 		0x1008, 0x1108,
176 		0x1180, 0x11b4,
177 		0x11fc, 0x123c,
178 		0x1300, 0x173c,
179 		0x1800, 0x18fc,
180 		0x3000, 0x30d8,
181 		0x30e0, 0x5924,
182 		0x5960, 0x59d4,
183 		0x5a00, 0x5af8,
184 		0x6000, 0x6098,
185 		0x6100, 0x6150,
186 		0x6200, 0x6208,
187 		0x6240, 0x6248,
188 		0x6280, 0x6338,
189 		0x6370, 0x638c,
190 		0x6400, 0x643c,
191 		0x6500, 0x6524,
192 		0x6a00, 0x6a38,
193 		0x6a60, 0x6a78,
194 		0x6b00, 0x6b84,
195 		0x6bf0, 0x6c84,
196 		0x6cf0, 0x6d84,
197 		0x6df0, 0x6e84,
198 		0x6ef0, 0x6f84,
199 		0x6ff0, 0x7084,
200 		0x70f0, 0x7184,
201 		0x71f0, 0x7284,
202 		0x72f0, 0x7384,
203 		0x73f0, 0x7450,
204 		0x7500, 0x7530,
205 		0x7600, 0x761c,
206 		0x7680, 0x76cc,
207 		0x7700, 0x7798,
208 		0x77c0, 0x77fc,
209 		0x7900, 0x79fc,
210 		0x7b00, 0x7c38,
211 		0x7d00, 0x7efc,
212 		0x8dc0, 0x8e1c,
213 		0x8e30, 0x8e78,
214 		0x8ea0, 0x8f6c,
215 		0x8fc0, 0x9074,
216 		0x90fc, 0x90fc,
217 		0x9400, 0x9458,
218 		0x9600, 0x96bc,
219 		0x9800, 0x9808,
220 		0x9820, 0x983c,
221 		0x9850, 0x9864,
222 		0x9c00, 0x9c6c,
223 		0x9c80, 0x9cec,
224 		0x9d00, 0x9d6c,
225 		0x9d80, 0x9dec,
226 		0x9e00, 0x9e6c,
227 		0x9e80, 0x9eec,
228 		0x9f00, 0x9f6c,
229 		0x9f80, 0x9fec,
230 		0xd004, 0xd03c,
231 		0xdfc0, 0xdfe0,
232 		0xe000, 0xea7c,
233 		0xf000, 0x11190,
234 		0x19040, 0x19124,
235 		0x19150, 0x191b0,
236 		0x191d0, 0x191e8,
237 		0x19238, 0x1924c,
238 		0x193f8, 0x19474,
239 		0x19490, 0x194f8,
240 		0x19800, 0x19f30,
241 		0x1a000, 0x1a06c,
242 		0x1a0b0, 0x1a120,
243 		0x1a128, 0x1a138,
244 		0x1a190, 0x1a1c4,
245 		0x1a1fc, 0x1a1fc,
246 		0x1e040, 0x1e04c,
247 		0x1e240, 0x1e28c,
248 		0x1e2c0, 0x1e2c0,
249 		0x1e2e0, 0x1e2e0,
250 		0x1e300, 0x1e384,
251 		0x1e3c0, 0x1e3c8,
252 		0x1e440, 0x1e44c,
253 		0x1e640, 0x1e68c,
254 		0x1e6c0, 0x1e6c0,
255 		0x1e6e0, 0x1e6e0,
256 		0x1e700, 0x1e784,
257 		0x1e7c0, 0x1e7c8,
258 		0x1e840, 0x1e84c,
259 		0x1ea40, 0x1ea8c,
260 		0x1eac0, 0x1eac0,
261 		0x1eae0, 0x1eae0,
262 		0x1eb00, 0x1eb84,
263 		0x1ebc0, 0x1ebc8,
264 		0x1ec40, 0x1ec4c,
265 		0x1ee40, 0x1ee8c,
266 		0x1eec0, 0x1eec0,
267 		0x1eee0, 0x1eee0,
268 		0x1ef00, 0x1ef84,
269 		0x1efc0, 0x1efc8,
270 		0x1f040, 0x1f04c,
271 		0x1f240, 0x1f28c,
272 		0x1f2c0, 0x1f2c0,
273 		0x1f2e0, 0x1f2e0,
274 		0x1f300, 0x1f384,
275 		0x1f3c0, 0x1f3c8,
276 		0x1f440, 0x1f44c,
277 		0x1f640, 0x1f68c,
278 		0x1f6c0, 0x1f6c0,
279 		0x1f6e0, 0x1f6e0,
280 		0x1f700, 0x1f784,
281 		0x1f7c0, 0x1f7c8,
282 		0x1f840, 0x1f84c,
283 		0x1fa40, 0x1fa8c,
284 		0x1fac0, 0x1fac0,
285 		0x1fae0, 0x1fae0,
286 		0x1fb00, 0x1fb84,
287 		0x1fbc0, 0x1fbc8,
288 		0x1fc40, 0x1fc4c,
289 		0x1fe40, 0x1fe8c,
290 		0x1fec0, 0x1fec0,
291 		0x1fee0, 0x1fee0,
292 		0x1ff00, 0x1ff84,
293 		0x1ffc0, 0x1ffc8,
294 		0x20000, 0x2002c,
295 		0x20100, 0x2013c,
296 		0x20190, 0x201c8,
297 		0x20200, 0x20318,
298 		0x20400, 0x20528,
299 		0x20540, 0x20614,
300 		0x21000, 0x21040,
301 		0x2104c, 0x21060,
302 		0x210c0, 0x210ec,
303 		0x21200, 0x21268,
304 		0x21270, 0x21284,
305 		0x212fc, 0x21388,
306 		0x21400, 0x21404,
307 		0x21500, 0x21518,
308 		0x2152c, 0x2153c,
309 		0x21550, 0x21554,
310 		0x21600, 0x21600,
311 		0x21608, 0x21628,
312 		0x21630, 0x2163c,
313 		0x21700, 0x2171c,
314 		0x21780, 0x2178c,
315 		0x21800, 0x21c38,
316 		0x21c80, 0x21d7c,
317 		0x21e00, 0x21e04,
318 		0x22000, 0x2202c,
319 		0x22100, 0x2213c,
320 		0x22190, 0x221c8,
321 		0x22200, 0x22318,
322 		0x22400, 0x22528,
323 		0x22540, 0x22614,
324 		0x23000, 0x23040,
325 		0x2304c, 0x23060,
326 		0x230c0, 0x230ec,
327 		0x23200, 0x23268,
328 		0x23270, 0x23284,
329 		0x232fc, 0x23388,
330 		0x23400, 0x23404,
331 		0x23500, 0x23518,
332 		0x2352c, 0x2353c,
333 		0x23550, 0x23554,
334 		0x23600, 0x23600,
335 		0x23608, 0x23628,
336 		0x23630, 0x2363c,
337 		0x23700, 0x2371c,
338 		0x23780, 0x2378c,
339 		0x23800, 0x23c38,
340 		0x23c80, 0x23d7c,
341 		0x23e00, 0x23e04,
342 		0x24000, 0x2402c,
343 		0x24100, 0x2413c,
344 		0x24190, 0x241c8,
345 		0x24200, 0x24318,
346 		0x24400, 0x24528,
347 		0x24540, 0x24614,
348 		0x25000, 0x25040,
349 		0x2504c, 0x25060,
350 		0x250c0, 0x250ec,
351 		0x25200, 0x25268,
352 		0x25270, 0x25284,
353 		0x252fc, 0x25388,
354 		0x25400, 0x25404,
355 		0x25500, 0x25518,
356 		0x2552c, 0x2553c,
357 		0x25550, 0x25554,
358 		0x25600, 0x25600,
359 		0x25608, 0x25628,
360 		0x25630, 0x2563c,
361 		0x25700, 0x2571c,
362 		0x25780, 0x2578c,
363 		0x25800, 0x25c38,
364 		0x25c80, 0x25d7c,
365 		0x25e00, 0x25e04,
366 		0x26000, 0x2602c,
367 		0x26100, 0x2613c,
368 		0x26190, 0x261c8,
369 		0x26200, 0x26318,
370 		0x26400, 0x26528,
371 		0x26540, 0x26614,
372 		0x27000, 0x27040,
373 		0x2704c, 0x27060,
374 		0x270c0, 0x270ec,
375 		0x27200, 0x27268,
376 		0x27270, 0x27284,
377 		0x272fc, 0x27388,
378 		0x27400, 0x27404,
379 		0x27500, 0x27518,
380 		0x2752c, 0x2753c,
381 		0x27550, 0x27554,
382 		0x27600, 0x27600,
383 		0x27608, 0x27628,
384 		0x27630, 0x2763c,
385 		0x27700, 0x2771c,
386 		0x27780, 0x2778c,
387 		0x27800, 0x27c38,
388 		0x27c80, 0x27d7c,
389 		0x27e00, 0x27e04
390 	};
391 
392 	static const unsigned int t5_reg_ranges[] = {
393 		0x1008, 0x10c0,
394 		0x10cc, 0x10f8,
395 		0x1100, 0x1100,
396 		0x110c, 0x1148,
397 		0x1180, 0x1184,
398 		0x1190, 0x1194,
399 		0x11a0, 0x11a4,
400 		0x11b0, 0x11b4,
401 		0x11fc, 0x123c,
402 		0x1280, 0x173c,
403 		0x1800, 0x18fc,
404 		0x3000, 0x3028,
405 		0x3060, 0x30b0,
406 		0x30b8, 0x30d8,
407 		0x30e0, 0x30fc,
408 		0x3140, 0x357c,
409 		0x35a8, 0x35cc,
410 		0x35ec, 0x35ec,
411 		0x3600, 0x5624,
412 		0x56cc, 0x56ec,
413 		0x56f4, 0x5720,
414 		0x5728, 0x575c,
415 		0x580c, 0x5814,
416 		0x5890, 0x589c,
417 		0x58a4, 0x58ac,
418 		0x58b8, 0x58bc,
419 		0x5940, 0x59c8,
420 		0x59d0, 0x59dc,
421 		0x59fc, 0x5a18,
422 		0x5a60, 0x5a70,
423 		0x5a80, 0x5a9c,
424 		0x5b94, 0x5bfc,
425 		0x6000, 0x6020,
426 		0x6028, 0x6040,
427 		0x6058, 0x609c,
428 		0x60a8, 0x614c,
429 		0x7700, 0x7798,
430 		0x77c0, 0x78fc,
431 		0x7b00, 0x7b58,
432 		0x7b60, 0x7b84,
433 		0x7b8c, 0x7c54,
434 		0x7d00, 0x7d38,
435 		0x7d40, 0x7d80,
436 		0x7d8c, 0x7ddc,
437 		0x7de4, 0x7e04,
438 		0x7e10, 0x7e1c,
439 		0x7e24, 0x7e38,
440 		0x7e40, 0x7e44,
441 		0x7e4c, 0x7e78,
442 		0x7e80, 0x7edc,
443 		0x7ee8, 0x7efc,
444 		0x8dc0, 0x8de0,
445 		0x8df8, 0x8e04,
446 		0x8e10, 0x8e84,
447 		0x8ea0, 0x8f84,
448 		0x8fc0, 0x9058,
449 		0x9060, 0x9060,
450 		0x9068, 0x90f8,
451 		0x9400, 0x9408,
452 		0x9410, 0x9470,
453 		0x9600, 0x9600,
454 		0x9608, 0x9638,
455 		0x9640, 0x96f4,
456 		0x9800, 0x9808,
457 		0x9820, 0x983c,
458 		0x9850, 0x9864,
459 		0x9c00, 0x9c6c,
460 		0x9c80, 0x9cec,
461 		0x9d00, 0x9d6c,
462 		0x9d80, 0x9dec,
463 		0x9e00, 0x9e6c,
464 		0x9e80, 0x9eec,
465 		0x9f00, 0x9f6c,
466 		0x9f80, 0xa020,
467 		0xd004, 0xd004,
468 		0xd010, 0xd03c,
469 		0xdfc0, 0xdfe0,
470 		0xe000, 0x1106c,
471 		0x11074, 0x11088,
472 		0x1109c, 0x1117c,
473 		0x11190, 0x11204,
474 		0x19040, 0x1906c,
475 		0x19078, 0x19080,
476 		0x1908c, 0x190e8,
477 		0x190f0, 0x190f8,
478 		0x19100, 0x19110,
479 		0x19120, 0x19124,
480 		0x19150, 0x19194,
481 		0x1919c, 0x191b0,
482 		0x191d0, 0x191e8,
483 		0x19238, 0x19290,
484 		0x193f8, 0x19428,
485 		0x19430, 0x19444,
486 		0x1944c, 0x1946c,
487 		0x19474, 0x19474,
488 		0x19490, 0x194cc,
489 		0x194f0, 0x194f8,
490 		0x19c00, 0x19c08,
491 		0x19c10, 0x19c60,
492 		0x19c94, 0x19ce4,
493 		0x19cf0, 0x19d40,
494 		0x19d50, 0x19d94,
495 		0x19da0, 0x19de8,
496 		0x19df0, 0x19e10,
497 		0x19e50, 0x19e90,
498 		0x19ea0, 0x19f24,
499 		0x19f34, 0x19f34,
500 		0x19f40, 0x19f50,
501 		0x19f90, 0x19fb4,
502 		0x19fc4, 0x19fe4,
503 		0x1a000, 0x1a004,
504 		0x1a010, 0x1a06c,
505 		0x1a0b0, 0x1a0e4,
506 		0x1a0ec, 0x1a0f8,
507 		0x1a100, 0x1a108,
508 		0x1a114, 0x1a120,
509 		0x1a128, 0x1a130,
510 		0x1a138, 0x1a138,
511 		0x1a190, 0x1a1c4,
512 		0x1a1fc, 0x1a1fc,
513 		0x1e008, 0x1e00c,
514 		0x1e040, 0x1e044,
515 		0x1e04c, 0x1e04c,
516 		0x1e284, 0x1e290,
517 		0x1e2c0, 0x1e2c0,
518 		0x1e2e0, 0x1e2e0,
519 		0x1e300, 0x1e384,
520 		0x1e3c0, 0x1e3c8,
521 		0x1e408, 0x1e40c,
522 		0x1e440, 0x1e444,
523 		0x1e44c, 0x1e44c,
524 		0x1e684, 0x1e690,
525 		0x1e6c0, 0x1e6c0,
526 		0x1e6e0, 0x1e6e0,
527 		0x1e700, 0x1e784,
528 		0x1e7c0, 0x1e7c8,
529 		0x1e808, 0x1e80c,
530 		0x1e840, 0x1e844,
531 		0x1e84c, 0x1e84c,
532 		0x1ea84, 0x1ea90,
533 		0x1eac0, 0x1eac0,
534 		0x1eae0, 0x1eae0,
535 		0x1eb00, 0x1eb84,
536 		0x1ebc0, 0x1ebc8,
537 		0x1ec08, 0x1ec0c,
538 		0x1ec40, 0x1ec44,
539 		0x1ec4c, 0x1ec4c,
540 		0x1ee84, 0x1ee90,
541 		0x1eec0, 0x1eec0,
542 		0x1eee0, 0x1eee0,
543 		0x1ef00, 0x1ef84,
544 		0x1efc0, 0x1efc8,
545 		0x1f008, 0x1f00c,
546 		0x1f040, 0x1f044,
547 		0x1f04c, 0x1f04c,
548 		0x1f284, 0x1f290,
549 		0x1f2c0, 0x1f2c0,
550 		0x1f2e0, 0x1f2e0,
551 		0x1f300, 0x1f384,
552 		0x1f3c0, 0x1f3c8,
553 		0x1f408, 0x1f40c,
554 		0x1f440, 0x1f444,
555 		0x1f44c, 0x1f44c,
556 		0x1f684, 0x1f690,
557 		0x1f6c0, 0x1f6c0,
558 		0x1f6e0, 0x1f6e0,
559 		0x1f700, 0x1f784,
560 		0x1f7c0, 0x1f7c8,
561 		0x1f808, 0x1f80c,
562 		0x1f840, 0x1f844,
563 		0x1f84c, 0x1f84c,
564 		0x1fa84, 0x1fa90,
565 		0x1fac0, 0x1fac0,
566 		0x1fae0, 0x1fae0,
567 		0x1fb00, 0x1fb84,
568 		0x1fbc0, 0x1fbc8,
569 		0x1fc08, 0x1fc0c,
570 		0x1fc40, 0x1fc44,
571 		0x1fc4c, 0x1fc4c,
572 		0x1fe84, 0x1fe90,
573 		0x1fec0, 0x1fec0,
574 		0x1fee0, 0x1fee0,
575 		0x1ff00, 0x1ff84,
576 		0x1ffc0, 0x1ffc8,
577 		0x30000, 0x30030,
578 		0x30038, 0x30038,
579 		0x30040, 0x30040,
580 		0x30100, 0x30144,
581 		0x30190, 0x301a0,
582 		0x301a8, 0x301b8,
583 		0x301c4, 0x301c8,
584 		0x301d0, 0x301d0,
585 		0x30200, 0x30318,
586 		0x30400, 0x304b4,
587 		0x304c0, 0x3052c,
588 		0x30540, 0x3061c,
589 		0x30800, 0x30828,
590 		0x30834, 0x30834,
591 		0x308c0, 0x30908,
592 		0x30910, 0x309ac,
593 		0x30a00, 0x30a14,
594 		0x30a1c, 0x30a2c,
595 		0x30a44, 0x30a50,
596 		0x30a74, 0x30a74,
597 		0x30a7c, 0x30afc,
598 		0x30b08, 0x30c24,
599 		0x30d00, 0x30d00,
600 		0x30d08, 0x30d14,
601 		0x30d1c, 0x30d20,
602 		0x30d3c, 0x30d3c,
603 		0x30d48, 0x30d50,
604 		0x31200, 0x3120c,
605 		0x31220, 0x31220,
606 		0x31240, 0x31240,
607 		0x31600, 0x3160c,
608 		0x31a00, 0x31a1c,
609 		0x31e00, 0x31e20,
610 		0x31e38, 0x31e3c,
611 		0x31e80, 0x31e80,
612 		0x31e88, 0x31ea8,
613 		0x31eb0, 0x31eb4,
614 		0x31ec8, 0x31ed4,
615 		0x31fb8, 0x32004,
616 		0x32200, 0x32200,
617 		0x32208, 0x32240,
618 		0x32248, 0x32280,
619 		0x32288, 0x322c0,
620 		0x322c8, 0x322fc,
621 		0x32600, 0x32630,
622 		0x32a00, 0x32abc,
623 		0x32b00, 0x32b10,
624 		0x32b20, 0x32b30,
625 		0x32b40, 0x32b50,
626 		0x32b60, 0x32b70,
627 		0x33000, 0x33028,
628 		0x33030, 0x33048,
629 		0x33060, 0x33068,
630 		0x33070, 0x3309c,
631 		0x330f0, 0x33128,
632 		0x33130, 0x33148,
633 		0x33160, 0x33168,
634 		0x33170, 0x3319c,
635 		0x331f0, 0x33238,
636 		0x33240, 0x33240,
637 		0x33248, 0x33250,
638 		0x3325c, 0x33264,
639 		0x33270, 0x332b8,
640 		0x332c0, 0x332e4,
641 		0x332f8, 0x33338,
642 		0x33340, 0x33340,
643 		0x33348, 0x33350,
644 		0x3335c, 0x33364,
645 		0x33370, 0x333b8,
646 		0x333c0, 0x333e4,
647 		0x333f8, 0x33428,
648 		0x33430, 0x33448,
649 		0x33460, 0x33468,
650 		0x33470, 0x3349c,
651 		0x334f0, 0x33528,
652 		0x33530, 0x33548,
653 		0x33560, 0x33568,
654 		0x33570, 0x3359c,
655 		0x335f0, 0x33638,
656 		0x33640, 0x33640,
657 		0x33648, 0x33650,
658 		0x3365c, 0x33664,
659 		0x33670, 0x336b8,
660 		0x336c0, 0x336e4,
661 		0x336f8, 0x33738,
662 		0x33740, 0x33740,
663 		0x33748, 0x33750,
664 		0x3375c, 0x33764,
665 		0x33770, 0x337b8,
666 		0x337c0, 0x337e4,
667 		0x337f8, 0x337fc,
668 		0x33814, 0x33814,
669 		0x3382c, 0x3382c,
670 		0x33880, 0x3388c,
671 		0x338e8, 0x338ec,
672 		0x33900, 0x33928,
673 		0x33930, 0x33948,
674 		0x33960, 0x33968,
675 		0x33970, 0x3399c,
676 		0x339f0, 0x33a38,
677 		0x33a40, 0x33a40,
678 		0x33a48, 0x33a50,
679 		0x33a5c, 0x33a64,
680 		0x33a70, 0x33ab8,
681 		0x33ac0, 0x33ae4,
682 		0x33af8, 0x33b10,
683 		0x33b28, 0x33b28,
684 		0x33b3c, 0x33b50,
685 		0x33bf0, 0x33c10,
686 		0x33c28, 0x33c28,
687 		0x33c3c, 0x33c50,
688 		0x33cf0, 0x33cfc,
689 		0x34000, 0x34030,
690 		0x34038, 0x34038,
691 		0x34040, 0x34040,
692 		0x34100, 0x34144,
693 		0x34190, 0x341a0,
694 		0x341a8, 0x341b8,
695 		0x341c4, 0x341c8,
696 		0x341d0, 0x341d0,
697 		0x34200, 0x34318,
698 		0x34400, 0x344b4,
699 		0x344c0, 0x3452c,
700 		0x34540, 0x3461c,
701 		0x34800, 0x34828,
702 		0x34834, 0x34834,
703 		0x348c0, 0x34908,
704 		0x34910, 0x349ac,
705 		0x34a00, 0x34a14,
706 		0x34a1c, 0x34a2c,
707 		0x34a44, 0x34a50,
708 		0x34a74, 0x34a74,
709 		0x34a7c, 0x34afc,
710 		0x34b08, 0x34c24,
711 		0x34d00, 0x34d00,
712 		0x34d08, 0x34d14,
713 		0x34d1c, 0x34d20,
714 		0x34d3c, 0x34d3c,
715 		0x34d48, 0x34d50,
716 		0x35200, 0x3520c,
717 		0x35220, 0x35220,
718 		0x35240, 0x35240,
719 		0x35600, 0x3560c,
720 		0x35a00, 0x35a1c,
721 		0x35e00, 0x35e20,
722 		0x35e38, 0x35e3c,
723 		0x35e80, 0x35e80,
724 		0x35e88, 0x35ea8,
725 		0x35eb0, 0x35eb4,
726 		0x35ec8, 0x35ed4,
727 		0x35fb8, 0x36004,
728 		0x36200, 0x36200,
729 		0x36208, 0x36240,
730 		0x36248, 0x36280,
731 		0x36288, 0x362c0,
732 		0x362c8, 0x362fc,
733 		0x36600, 0x36630,
734 		0x36a00, 0x36abc,
735 		0x36b00, 0x36b10,
736 		0x36b20, 0x36b30,
737 		0x36b40, 0x36b50,
738 		0x36b60, 0x36b70,
739 		0x37000, 0x37028,
740 		0x37030, 0x37048,
741 		0x37060, 0x37068,
742 		0x37070, 0x3709c,
743 		0x370f0, 0x37128,
744 		0x37130, 0x37148,
745 		0x37160, 0x37168,
746 		0x37170, 0x3719c,
747 		0x371f0, 0x37238,
748 		0x37240, 0x37240,
749 		0x37248, 0x37250,
750 		0x3725c, 0x37264,
751 		0x37270, 0x372b8,
752 		0x372c0, 0x372e4,
753 		0x372f8, 0x37338,
754 		0x37340, 0x37340,
755 		0x37348, 0x37350,
756 		0x3735c, 0x37364,
757 		0x37370, 0x373b8,
758 		0x373c0, 0x373e4,
759 		0x373f8, 0x37428,
760 		0x37430, 0x37448,
761 		0x37460, 0x37468,
762 		0x37470, 0x3749c,
763 		0x374f0, 0x37528,
764 		0x37530, 0x37548,
765 		0x37560, 0x37568,
766 		0x37570, 0x3759c,
767 		0x375f0, 0x37638,
768 		0x37640, 0x37640,
769 		0x37648, 0x37650,
770 		0x3765c, 0x37664,
771 		0x37670, 0x376b8,
772 		0x376c0, 0x376e4,
773 		0x376f8, 0x37738,
774 		0x37740, 0x37740,
775 		0x37748, 0x37750,
776 		0x3775c, 0x37764,
777 		0x37770, 0x377b8,
778 		0x377c0, 0x377e4,
779 		0x377f8, 0x377fc,
780 		0x37814, 0x37814,
781 		0x3782c, 0x3782c,
782 		0x37880, 0x3788c,
783 		0x378e8, 0x378ec,
784 		0x37900, 0x37928,
785 		0x37930, 0x37948,
786 		0x37960, 0x37968,
787 		0x37970, 0x3799c,
788 		0x379f0, 0x37a38,
789 		0x37a40, 0x37a40,
790 		0x37a48, 0x37a50,
791 		0x37a5c, 0x37a64,
792 		0x37a70, 0x37ab8,
793 		0x37ac0, 0x37ae4,
794 		0x37af8, 0x37b10,
795 		0x37b28, 0x37b28,
796 		0x37b3c, 0x37b50,
797 		0x37bf0, 0x37c10,
798 		0x37c28, 0x37c28,
799 		0x37c3c, 0x37c50,
800 		0x37cf0, 0x37cfc,
801 		0x38000, 0x38030,
802 		0x38038, 0x38038,
803 		0x38040, 0x38040,
804 		0x38100, 0x38144,
805 		0x38190, 0x381a0,
806 		0x381a8, 0x381b8,
807 		0x381c4, 0x381c8,
808 		0x381d0, 0x381d0,
809 		0x38200, 0x38318,
810 		0x38400, 0x384b4,
811 		0x384c0, 0x3852c,
812 		0x38540, 0x3861c,
813 		0x38800, 0x38828,
814 		0x38834, 0x38834,
815 		0x388c0, 0x38908,
816 		0x38910, 0x389ac,
817 		0x38a00, 0x38a14,
818 		0x38a1c, 0x38a2c,
819 		0x38a44, 0x38a50,
820 		0x38a74, 0x38a74,
821 		0x38a7c, 0x38afc,
822 		0x38b08, 0x38c24,
823 		0x38d00, 0x38d00,
824 		0x38d08, 0x38d14,
825 		0x38d1c, 0x38d20,
826 		0x38d3c, 0x38d3c,
827 		0x38d48, 0x38d50,
828 		0x39200, 0x3920c,
829 		0x39220, 0x39220,
830 		0x39240, 0x39240,
831 		0x39600, 0x3960c,
832 		0x39a00, 0x39a1c,
833 		0x39e00, 0x39e20,
834 		0x39e38, 0x39e3c,
835 		0x39e80, 0x39e80,
836 		0x39e88, 0x39ea8,
837 		0x39eb0, 0x39eb4,
838 		0x39ec8, 0x39ed4,
839 		0x39fb8, 0x3a004,
840 		0x3a200, 0x3a200,
841 		0x3a208, 0x3a240,
842 		0x3a248, 0x3a280,
843 		0x3a288, 0x3a2c0,
844 		0x3a2c8, 0x3a2fc,
845 		0x3a600, 0x3a630,
846 		0x3aa00, 0x3aabc,
847 		0x3ab00, 0x3ab10,
848 		0x3ab20, 0x3ab30,
849 		0x3ab40, 0x3ab50,
850 		0x3ab60, 0x3ab70,
851 		0x3b000, 0x3b028,
852 		0x3b030, 0x3b048,
853 		0x3b060, 0x3b068,
854 		0x3b070, 0x3b09c,
855 		0x3b0f0, 0x3b128,
856 		0x3b130, 0x3b148,
857 		0x3b160, 0x3b168,
858 		0x3b170, 0x3b19c,
859 		0x3b1f0, 0x3b238,
860 		0x3b240, 0x3b240,
861 		0x3b248, 0x3b250,
862 		0x3b25c, 0x3b264,
863 		0x3b270, 0x3b2b8,
864 		0x3b2c0, 0x3b2e4,
865 		0x3b2f8, 0x3b338,
866 		0x3b340, 0x3b340,
867 		0x3b348, 0x3b350,
868 		0x3b35c, 0x3b364,
869 		0x3b370, 0x3b3b8,
870 		0x3b3c0, 0x3b3e4,
871 		0x3b3f8, 0x3b428,
872 		0x3b430, 0x3b448,
873 		0x3b460, 0x3b468,
874 		0x3b470, 0x3b49c,
875 		0x3b4f0, 0x3b528,
876 		0x3b530, 0x3b548,
877 		0x3b560, 0x3b568,
878 		0x3b570, 0x3b59c,
879 		0x3b5f0, 0x3b638,
880 		0x3b640, 0x3b640,
881 		0x3b648, 0x3b650,
882 		0x3b65c, 0x3b664,
883 		0x3b670, 0x3b6b8,
884 		0x3b6c0, 0x3b6e4,
885 		0x3b6f8, 0x3b738,
886 		0x3b740, 0x3b740,
887 		0x3b748, 0x3b750,
888 		0x3b75c, 0x3b764,
889 		0x3b770, 0x3b7b8,
890 		0x3b7c0, 0x3b7e4,
891 		0x3b7f8, 0x3b7fc,
892 		0x3b814, 0x3b814,
893 		0x3b82c, 0x3b82c,
894 		0x3b880, 0x3b88c,
895 		0x3b8e8, 0x3b8ec,
896 		0x3b900, 0x3b928,
897 		0x3b930, 0x3b948,
898 		0x3b960, 0x3b968,
899 		0x3b970, 0x3b99c,
900 		0x3b9f0, 0x3ba38,
901 		0x3ba40, 0x3ba40,
902 		0x3ba48, 0x3ba50,
903 		0x3ba5c, 0x3ba64,
904 		0x3ba70, 0x3bab8,
905 		0x3bac0, 0x3bae4,
906 		0x3baf8, 0x3bb10,
907 		0x3bb28, 0x3bb28,
908 		0x3bb3c, 0x3bb50,
909 		0x3bbf0, 0x3bc10,
910 		0x3bc28, 0x3bc28,
911 		0x3bc3c, 0x3bc50,
912 		0x3bcf0, 0x3bcfc,
913 		0x3c000, 0x3c030,
914 		0x3c038, 0x3c038,
915 		0x3c040, 0x3c040,
916 		0x3c100, 0x3c144,
917 		0x3c190, 0x3c1a0,
918 		0x3c1a8, 0x3c1b8,
919 		0x3c1c4, 0x3c1c8,
920 		0x3c1d0, 0x3c1d0,
921 		0x3c200, 0x3c318,
922 		0x3c400, 0x3c4b4,
923 		0x3c4c0, 0x3c52c,
924 		0x3c540, 0x3c61c,
925 		0x3c800, 0x3c828,
926 		0x3c834, 0x3c834,
927 		0x3c8c0, 0x3c908,
928 		0x3c910, 0x3c9ac,
929 		0x3ca00, 0x3ca14,
930 		0x3ca1c, 0x3ca2c,
931 		0x3ca44, 0x3ca50,
932 		0x3ca74, 0x3ca74,
933 		0x3ca7c, 0x3cafc,
934 		0x3cb08, 0x3cc24,
935 		0x3cd00, 0x3cd00,
936 		0x3cd08, 0x3cd14,
937 		0x3cd1c, 0x3cd20,
938 		0x3cd3c, 0x3cd3c,
939 		0x3cd48, 0x3cd50,
940 		0x3d200, 0x3d20c,
941 		0x3d220, 0x3d220,
942 		0x3d240, 0x3d240,
943 		0x3d600, 0x3d60c,
944 		0x3da00, 0x3da1c,
945 		0x3de00, 0x3de20,
946 		0x3de38, 0x3de3c,
947 		0x3de80, 0x3de80,
948 		0x3de88, 0x3dea8,
949 		0x3deb0, 0x3deb4,
950 		0x3dec8, 0x3ded4,
951 		0x3dfb8, 0x3e004,
952 		0x3e200, 0x3e200,
953 		0x3e208, 0x3e240,
954 		0x3e248, 0x3e280,
955 		0x3e288, 0x3e2c0,
956 		0x3e2c8, 0x3e2fc,
957 		0x3e600, 0x3e630,
958 		0x3ea00, 0x3eabc,
959 		0x3eb00, 0x3eb10,
960 		0x3eb20, 0x3eb30,
961 		0x3eb40, 0x3eb50,
962 		0x3eb60, 0x3eb70,
963 		0x3f000, 0x3f028,
964 		0x3f030, 0x3f048,
965 		0x3f060, 0x3f068,
966 		0x3f070, 0x3f09c,
967 		0x3f0f0, 0x3f128,
968 		0x3f130, 0x3f148,
969 		0x3f160, 0x3f168,
970 		0x3f170, 0x3f19c,
971 		0x3f1f0, 0x3f238,
972 		0x3f240, 0x3f240,
973 		0x3f248, 0x3f250,
974 		0x3f25c, 0x3f264,
975 		0x3f270, 0x3f2b8,
976 		0x3f2c0, 0x3f2e4,
977 		0x3f2f8, 0x3f338,
978 		0x3f340, 0x3f340,
979 		0x3f348, 0x3f350,
980 		0x3f35c, 0x3f364,
981 		0x3f370, 0x3f3b8,
982 		0x3f3c0, 0x3f3e4,
983 		0x3f3f8, 0x3f428,
984 		0x3f430, 0x3f448,
985 		0x3f460, 0x3f468,
986 		0x3f470, 0x3f49c,
987 		0x3f4f0, 0x3f528,
988 		0x3f530, 0x3f548,
989 		0x3f560, 0x3f568,
990 		0x3f570, 0x3f59c,
991 		0x3f5f0, 0x3f638,
992 		0x3f640, 0x3f640,
993 		0x3f648, 0x3f650,
994 		0x3f65c, 0x3f664,
995 		0x3f670, 0x3f6b8,
996 		0x3f6c0, 0x3f6e4,
997 		0x3f6f8, 0x3f738,
998 		0x3f740, 0x3f740,
999 		0x3f748, 0x3f750,
1000 		0x3f75c, 0x3f764,
1001 		0x3f770, 0x3f7b8,
1002 		0x3f7c0, 0x3f7e4,
1003 		0x3f7f8, 0x3f7fc,
1004 		0x3f814, 0x3f814,
1005 		0x3f82c, 0x3f82c,
1006 		0x3f880, 0x3f88c,
1007 		0x3f8e8, 0x3f8ec,
1008 		0x3f900, 0x3f928,
1009 		0x3f930, 0x3f948,
1010 		0x3f960, 0x3f968,
1011 		0x3f970, 0x3f99c,
1012 		0x3f9f0, 0x3fa38,
1013 		0x3fa40, 0x3fa40,
1014 		0x3fa48, 0x3fa50,
1015 		0x3fa5c, 0x3fa64,
1016 		0x3fa70, 0x3fab8,
1017 		0x3fac0, 0x3fae4,
1018 		0x3faf8, 0x3fb10,
1019 		0x3fb28, 0x3fb28,
1020 		0x3fb3c, 0x3fb50,
1021 		0x3fbf0, 0x3fc10,
1022 		0x3fc28, 0x3fc28,
1023 		0x3fc3c, 0x3fc50,
1024 		0x3fcf0, 0x3fcfc,
1025 		0x40000, 0x4000c,
1026 		0x40040, 0x40050,
1027 		0x40060, 0x40068,
1028 		0x4007c, 0x4008c,
1029 		0x40094, 0x400b0,
1030 		0x400c0, 0x40144,
1031 		0x40180, 0x4018c,
1032 		0x40200, 0x40254,
1033 		0x40260, 0x40264,
1034 		0x40270, 0x40288,
1035 		0x40290, 0x40298,
1036 		0x402ac, 0x402c8,
1037 		0x402d0, 0x402e0,
1038 		0x402f0, 0x402f0,
1039 		0x40300, 0x4033c,
1040 		0x403f8, 0x403fc,
1041 		0x41304, 0x413c4,
1042 		0x41400, 0x4140c,
1043 		0x41414, 0x4141c,
1044 		0x41480, 0x414d0,
1045 		0x44000, 0x44054,
1046 		0x4405c, 0x44078,
1047 		0x440c0, 0x44174,
1048 		0x44180, 0x441ac,
1049 		0x441b4, 0x441b8,
1050 		0x441c0, 0x44254,
1051 		0x4425c, 0x44278,
1052 		0x442c0, 0x44374,
1053 		0x44380, 0x443ac,
1054 		0x443b4, 0x443b8,
1055 		0x443c0, 0x44454,
1056 		0x4445c, 0x44478,
1057 		0x444c0, 0x44574,
1058 		0x44580, 0x445ac,
1059 		0x445b4, 0x445b8,
1060 		0x445c0, 0x44654,
1061 		0x4465c, 0x44678,
1062 		0x446c0, 0x44774,
1063 		0x44780, 0x447ac,
1064 		0x447b4, 0x447b8,
1065 		0x447c0, 0x44854,
1066 		0x4485c, 0x44878,
1067 		0x448c0, 0x44974,
1068 		0x44980, 0x449ac,
1069 		0x449b4, 0x449b8,
1070 		0x449c0, 0x449fc,
1071 		0x45000, 0x45004,
1072 		0x45010, 0x45030,
1073 		0x45040, 0x45060,
1074 		0x45068, 0x45068,
1075 		0x45080, 0x45084,
1076 		0x450a0, 0x450b0,
1077 		0x45200, 0x45204,
1078 		0x45210, 0x45230,
1079 		0x45240, 0x45260,
1080 		0x45268, 0x45268,
1081 		0x45280, 0x45284,
1082 		0x452a0, 0x452b0,
1083 		0x460c0, 0x460e4,
1084 		0x47000, 0x4703c,
1085 		0x47044, 0x4708c,
1086 		0x47200, 0x47250,
1087 		0x47400, 0x47408,
1088 		0x47414, 0x47420,
1089 		0x47600, 0x47618,
1090 		0x47800, 0x47814,
1091 		0x48000, 0x4800c,
1092 		0x48040, 0x48050,
1093 		0x48060, 0x48068,
1094 		0x4807c, 0x4808c,
1095 		0x48094, 0x480b0,
1096 		0x480c0, 0x48144,
1097 		0x48180, 0x4818c,
1098 		0x48200, 0x48254,
1099 		0x48260, 0x48264,
1100 		0x48270, 0x48288,
1101 		0x48290, 0x48298,
1102 		0x482ac, 0x482c8,
1103 		0x482d0, 0x482e0,
1104 		0x482f0, 0x482f0,
1105 		0x48300, 0x4833c,
1106 		0x483f8, 0x483fc,
1107 		0x49304, 0x493c4,
1108 		0x49400, 0x4940c,
1109 		0x49414, 0x4941c,
1110 		0x49480, 0x494d0,
1111 		0x4c000, 0x4c054,
1112 		0x4c05c, 0x4c078,
1113 		0x4c0c0, 0x4c174,
1114 		0x4c180, 0x4c1ac,
1115 		0x4c1b4, 0x4c1b8,
1116 		0x4c1c0, 0x4c254,
1117 		0x4c25c, 0x4c278,
1118 		0x4c2c0, 0x4c374,
1119 		0x4c380, 0x4c3ac,
1120 		0x4c3b4, 0x4c3b8,
1121 		0x4c3c0, 0x4c454,
1122 		0x4c45c, 0x4c478,
1123 		0x4c4c0, 0x4c574,
1124 		0x4c580, 0x4c5ac,
1125 		0x4c5b4, 0x4c5b8,
1126 		0x4c5c0, 0x4c654,
1127 		0x4c65c, 0x4c678,
1128 		0x4c6c0, 0x4c774,
1129 		0x4c780, 0x4c7ac,
1130 		0x4c7b4, 0x4c7b8,
1131 		0x4c7c0, 0x4c854,
1132 		0x4c85c, 0x4c878,
1133 		0x4c8c0, 0x4c974,
1134 		0x4c980, 0x4c9ac,
1135 		0x4c9b4, 0x4c9b8,
1136 		0x4c9c0, 0x4c9fc,
1137 		0x4d000, 0x4d004,
1138 		0x4d010, 0x4d030,
1139 		0x4d040, 0x4d060,
1140 		0x4d068, 0x4d068,
1141 		0x4d080, 0x4d084,
1142 		0x4d0a0, 0x4d0b0,
1143 		0x4d200, 0x4d204,
1144 		0x4d210, 0x4d230,
1145 		0x4d240, 0x4d260,
1146 		0x4d268, 0x4d268,
1147 		0x4d280, 0x4d284,
1148 		0x4d2a0, 0x4d2b0,
1149 		0x4e0c0, 0x4e0e4,
1150 		0x4f000, 0x4f03c,
1151 		0x4f044, 0x4f08c,
1152 		0x4f200, 0x4f250,
1153 		0x4f400, 0x4f408,
1154 		0x4f414, 0x4f420,
1155 		0x4f600, 0x4f618,
1156 		0x4f800, 0x4f814,
1157 		0x50000, 0x50084,
1158 		0x50090, 0x500cc,
1159 		0x50400, 0x50400,
1160 		0x50800, 0x50884,
1161 		0x50890, 0x508cc,
1162 		0x50c00, 0x50c00,
1163 		0x51000, 0x5101c,
1164 		0x51300, 0x51308,
1165 	};
1166 
1167 	if (ddi_copyin(data, &r, sizeof (r), flags) < 0)
1168 		return (EFAULT);
1169 
1170 	if (r.len > T4_REGDUMP_SIZE)
1171 		r.len = T4_REGDUMP_SIZE;
1172 	else if (r.len < T4_REGDUMP_SIZE)
1173 		return (E2BIG);
1174 
1175 	r.version = mk_adap_vers(sc);
1176 
1177 	if (is_t4(sc->params.chip)) {
1178 		reg_ranges = &t4_reg_ranges[0];
1179 		arr_size = ARRAY_SIZE(t4_reg_ranges);
1180 		buf_size = T4_REGDUMP_SIZE;
1181 	} else {
1182 		reg_ranges = &t5_reg_ranges[0];
1183 		arr_size = ARRAY_SIZE(t5_reg_ranges);
1184 		buf_size = T5_REGDUMP_SIZE;
1185 	}
1186 
1187 	buf = kmem_zalloc(buf_size, KM_SLEEP);
1188 	if (buf == NULL)
1189 		return (ENOMEM);
1190 
1191 	for (i = 0; i < arr_size; i += 2)
1192 		reg_block_dump(sc, buf, reg_ranges[i], reg_ranges[i + 1]);
1193 
1194 	if (ddi_copyout(buf, r.data, r.len, flags) < 0)
1195 		rc = EFAULT;
1196 
1197 	if (rc == 0 && ddi_copyout(&r, data, sizeof (r), flags) < 0)
1198 		rc = EFAULT;
1199 
1200 	kmem_free(buf, buf_size);
1201 	return (rc);
1202 }
1203 
1204 static int
1205 get_sge_context(struct adapter *sc, void *data, int flags)
1206 {
1207 	struct t4_sge_context sgec;
1208 	uint32_t buff[SGE_CTXT_SIZE / 4];
1209 	int rc = 0;
1210 
1211 	if (ddi_copyin(data, &sgec, sizeof (sgec), flags) < 0) {
1212 		rc = EFAULT;
1213 		goto _exit;
1214 	}
1215 
1216 	if (sgec.len < SGE_CTXT_SIZE || sgec.addr > M_CTXTQID) {
1217 		rc = EINVAL;
1218 		goto _exit;
1219 	}
1220 
1221 	if ((sgec.mem_id != T4_CTXT_EGRESS) && (sgec.mem_id != T4_CTXT_FLM) &&
1222 	    (sgec.mem_id != T4_CTXT_INGRESS)) {
1223 		rc = EINVAL;
1224 		goto _exit;
1225 	}
1226 
1227 	rc = (sc->flags & FW_OK) ?
1228 	    -t4_sge_ctxt_rd(sc, sc->mbox, sgec.addr, sgec.mem_id, buff) :
1229 	    -t4_sge_ctxt_rd_bd(sc, sgec.addr, sgec.mem_id, buff);
1230 	if (rc != 0)
1231 		goto _exit;
1232 
1233 	sgec.version = 4 | (sc->params.chip << 10);
1234 
1235 	/* copyout data and then t4_sge_context */
1236 	rc = ddi_copyout(buff, sgec.data, sgec.len, flags);
1237 	if (rc == 0)
1238 		rc = ddi_copyout(&sgec, data, sizeof (sgec), flags);
1239 	/* if ddi_copyout fails, return EFAULT - for either of the two */
1240 	if (rc != 0)
1241 		rc = EFAULT;
1242 
1243 _exit:
1244 	return (rc);
1245 }
1246 
1247 static int
1248 read_tid_tab(struct adapter *sc, void *data, int flags)
1249 {
1250 	struct t4_tid_info t4tid;
1251 	uint32_t *buf, *b;
1252 	struct tid_info *t = &sc->tids;
1253 	int rc = 0;
1254 
1255 	if (ddi_copyin(data, &t4tid, sizeof (t4tid), flags) < 0) {
1256 		rc = EFAULT;
1257 		goto _exit;
1258 	}
1259 
1260 	buf = b = kmem_zalloc(t4tid.len, KM_NOSLEEP);
1261 	if (buf == NULL) {
1262 		rc = ENOMEM;
1263 		goto _exit;
1264 	}
1265 
1266 	*b++ = t->tids_in_use;
1267 	*b++ = t->atids_in_use;
1268 	*b = t->stids_in_use;
1269 
1270 	if (ddi_copyout(buf, t4tid.data, t4tid.len, flags) < 0)
1271 		rc = EFAULT;
1272 
1273 	kmem_free(buf, t4tid.len);
1274 
1275 _exit:
1276 	return (rc);
1277 }
1278 
1279 /*
1280  * Verify that the memory range specified by the addr/len pair is valid and lies
1281  * entirely within a single region (EDCx or MCx).
1282  */
1283 static int
1284 validate_mem_range(struct adapter *sc, uint32_t addr, int len)
1285 {
1286 	uint32_t em, addr_len, maddr, mlen;
1287 
1288 	/* Memory can only be accessed in naturally aligned 4 byte units */
1289 	if (addr & 3 || len & 3 || len == 0)
1290 		return (EINVAL);
1291 
1292 	/* Enabled memories */
1293 	em = t4_read_reg(sc, A_MA_TARGET_MEM_ENABLE);
1294 	if (em & F_EDRAM0_ENABLE) {
1295 		addr_len = t4_read_reg(sc, A_MA_EDRAM0_BAR);
1296 		maddr = G_EDRAM0_BASE(addr_len) << 20;
1297 		mlen = G_EDRAM0_SIZE(addr_len) << 20;
1298 		if (mlen > 0 && addr >= maddr && addr < maddr + mlen &&
1299 				addr + len <= maddr + mlen)
1300 			return (0);
1301 	}
1302 	if (em & F_EDRAM1_ENABLE) {
1303 		addr_len = t4_read_reg(sc, A_MA_EDRAM1_BAR);
1304 		maddr = G_EDRAM1_BASE(addr_len) << 20;
1305 		mlen = G_EDRAM1_SIZE(addr_len) << 20;
1306 		if (mlen > 0 && addr >= maddr && addr < maddr + mlen &&
1307 				addr + len <= maddr + mlen)
1308 			return (0);
1309 	}
1310 	if (em & F_EXT_MEM_ENABLE) {
1311 		addr_len = t4_read_reg(sc, A_MA_EXT_MEMORY_BAR);
1312 		maddr = G_EXT_MEM_BASE(addr_len) << 20;
1313 		mlen = G_EXT_MEM_SIZE(addr_len) << 20;
1314 		if (mlen > 0 && addr >= maddr && addr < maddr + mlen &&
1315 				addr + len <= maddr + mlen)
1316 			return (0);
1317 	}
1318 	if (!is_t4(sc->params.chip) && em & F_EXT_MEM1_ENABLE) {
1319 		addr_len = t4_read_reg(sc, A_MA_EXT_MEMORY1_BAR);
1320 		maddr = G_EXT_MEM1_BASE(addr_len) << 20;
1321 		mlen = G_EXT_MEM1_SIZE(addr_len) << 20;
1322 		if (mlen > 0 && addr >= maddr && addr < maddr + mlen &&
1323 				addr + len <= maddr + mlen)
1324 			return (0);
1325 	}
1326 
1327 	return (EFAULT);
1328 }
1329 
1330 static int
1331 read_card_mem(struct adapter *sc, void *data, int flags)
1332 {
1333 	struct t4_mem_range mr;
1334 	uint32_t addr, off, remaining, i, n;
1335 	uint32_t *buf, *b;
1336 	int rc = 0;
1337 	uint32_t mw_base, mw_aperture;
1338 	uint8_t *dst;
1339 
1340 	if (ddi_copyin(data, &mr, sizeof (mr), flags) < 0) {
1341 		rc = EFAULT;
1342 		goto _exit;
1343 	}
1344 
1345 	rc = validate_mem_range(sc, mr.addr, mr.len);
1346 	if (rc != 0)
1347 		return (rc);
1348 
1349 	memwin_info(sc, 2, &mw_base, &mw_aperture);
1350 	buf = b = kmem_zalloc(min(mr.len, mw_aperture), KM_NOSLEEP);
1351 	if (buf == NULL) {
1352 		rc = ENOMEM;
1353 		goto _exit;
1354 	}
1355 
1356 	addr = mr.addr;
1357 	remaining = mr.len;
1358 	dst = (void *)mr.data;
1359 
1360 	while (remaining) {
1361 		off = position_memwin(sc, 2, addr);
1362 
1363 		/* number of bytes that we'll copy in the inner loop */
1364 		n = min(remaining, mw_aperture - off);
1365 
1366 		for (i = 0; i < n; i += 4)
1367 			*b++ = t4_read_reg(sc, mw_base + off + i);
1368 		rc = ddi_copyout(buf, dst, n, flags);
1369 		if (rc != 0) {
1370 			rc = EFAULT;
1371 			break;
1372 		}
1373 
1374 		b = buf;
1375 		dst += n;
1376 		remaining -= n;
1377 		addr += n;
1378 	}
1379 
1380 	kmem_free(buf, min(mr.len, mw_aperture));
1381 _exit:
1382 	return (rc);
1383 }
1384 
1385 static int
1386 get_devlog(struct adapter *sc, void *data, int flags)
1387 {
1388 	struct devlog_params *dparams = &sc->params.devlog;
1389 	struct fw_devlog_e *buf;
1390 	struct t4_devlog dl;
1391 	int rc = 0;
1392 
1393 	if (ddi_copyin(data, &dl, sizeof (dl), flags) < 0) {
1394 		rc = EFAULT;
1395 		goto done;
1396 	}
1397 
1398 	if (dparams->start == 0) {
1399 		dparams->memtype = 0;
1400 		dparams->start = 0x84000;
1401 		dparams->size = 32768;
1402 	}
1403 
1404 	if (dl.len < dparams->size) {
1405 		dl.len = dparams->size;
1406 		rc = ddi_copyout(&dl, data, sizeof (dl), flags);
1407 		/*
1408 		 * rc = 0 indicates copyout was successful, then return ENOBUFS
1409 		 * to indicate that the buffer size was not enough. Return of
1410 		 * EFAULT indicates that the copyout was not successful.
1411 		 */
1412 		rc = (rc == 0) ? ENOBUFS : EFAULT;
1413 		goto done;
1414 	}
1415 
1416 	buf = kmem_zalloc(dparams->size, KM_NOSLEEP);
1417 	if (buf == NULL) {
1418 		rc = ENOMEM;
1419 		goto done;
1420 	}
1421 
1422 	rc = -t4_memory_rw(sc, sc->params.drv_memwin, dparams->memtype,
1423 			   dparams->start, dparams->size, (void *)buf,
1424 			   T4_MEMORY_READ);
1425 	if (rc != 0)
1426 		goto done1;
1427 
1428 	/* Copyout device log buffer and then carrier buffer */
1429 	if (ddi_copyout(buf, dl.data, dl.len, flags) < 0)
1430 		rc = EFAULT;
1431 	else if (ddi_copyout(&dl, data, sizeof (dl), flags) < 0)
1432 		rc = EFAULT;
1433 
1434 done1:
1435 	kmem_free(buf, dparams->size);
1436 
1437 done:
1438 	return (rc);
1439 }
1440 
1441 static int
1442 read_cim_qcfg(struct adapter *sc, void *data, int flags)
1443 {
1444 	struct t4_cim_qcfg t4cimqcfg;
1445 	int rc = 0;
1446 	unsigned int ibq_rdaddr, obq_rdaddr, nq;
1447 
1448 	if (ddi_copyin(data, &t4cimqcfg, sizeof (t4cimqcfg), flags) < 0) {
1449 		rc = EFAULT;
1450 		goto _exit;
1451 	}
1452 
1453         if (is_t4(sc->params.chip)) {
1454 		t4cimqcfg.num_obq = CIM_NUM_OBQ;
1455                 ibq_rdaddr = A_UP_IBQ_0_RDADDR;
1456                 obq_rdaddr = A_UP_OBQ_0_REALADDR;
1457         } else {
1458                 t4cimqcfg.num_obq = CIM_NUM_OBQ_T5;
1459                 ibq_rdaddr = A_UP_IBQ_0_SHADOW_RDADDR;
1460                 obq_rdaddr = A_UP_OBQ_0_SHADOW_REALADDR;
1461         }
1462 	nq = CIM_NUM_IBQ + t4cimqcfg.num_obq;
1463 
1464 	rc = -t4_cim_read(sc, ibq_rdaddr, 4 * nq, t4cimqcfg.stat);
1465 	if (rc == 0)
1466 		rc = -t4_cim_read(sc, obq_rdaddr, 2 * t4cimqcfg.num_obq,
1467 		    t4cimqcfg.obq_wr);
1468 	if (rc != 0)
1469 		return (rc);
1470 
1471 	t4_read_cimq_cfg(sc, t4cimqcfg.base, t4cimqcfg.size, t4cimqcfg.thres);
1472 
1473 	if (ddi_copyout(&t4cimqcfg, data, sizeof (t4cimqcfg), flags) < 0)
1474 		rc = EFAULT;
1475 
1476 _exit:
1477 	return (rc);
1478 }
1479 
1480 static int
1481 read_edc(struct adapter *sc, void *data, int flags)
1482 {
1483 	struct t4_edc t4edc;
1484 	int rc = 0;
1485 	u32 count, pos = 0;
1486 	u32 memoffset;
1487 	__be32 *edc = NULL;
1488 
1489 	if (ddi_copyin(data, &t4edc, sizeof (t4edc), flags) < 0) {
1490 		rc = EFAULT;
1491 		goto _exit;
1492 	}
1493 
1494 	if (t4edc.mem > 2)
1495 		goto _exit;
1496 
1497 	edc = kmem_zalloc(t4edc.len, KM_NOSLEEP);
1498 	if (edc == NULL) {
1499 		rc = ENOMEM;
1500 		goto _exit;
1501 	}
1502 	/*
1503 	 * Offset into the region of memory which is being accessed
1504 	 * MEM_EDC0 = 0
1505 	 * MEM_EDC1 = 1
1506 	 * MEM_MC   = 2
1507 	 */
1508 	memoffset = (t4edc.mem * (5 * 1024 * 1024));
1509 	count = t4edc.len;
1510 	pos = t4edc.pos;
1511 
1512 	while (count) {
1513 		u32 len;
1514 
1515 		rc = t4_memory_rw(sc, sc->params.drv_memwin, memoffset, pos,
1516 				  count, edc, T4_MEMORY_READ);
1517 		if (rc != 0) {
1518 			kmem_free(edc, t4edc.len);
1519 			goto _exit;
1520 		}
1521 
1522 		len = MEMWIN0_APERTURE;
1523 		pos += len;
1524 		count -= len;
1525 	}
1526 
1527 	if (ddi_copyout(edc, t4edc.data, t4edc.len, flags) < 0)
1528 		rc = EFAULT;
1529 
1530 	kmem_free(edc, t4edc.len);
1531 _exit:
1532 	return (rc);
1533 }
1534 
1535 static int
1536 read_cim_ibq(struct adapter *sc, void *data, int flags)
1537 {
1538 	struct t4_ibq t4ibq;
1539 	int rc = 0;
1540 	__be64 *buf;
1541 
1542 	if (ddi_copyin(data, &t4ibq, sizeof (t4ibq), flags) < 0) {
1543 		rc = EFAULT;
1544 		goto _exit;
1545 	}
1546 
1547 	buf = kmem_zalloc(t4ibq.len, KM_NOSLEEP);
1548 	if (buf == NULL) {
1549 		rc = ENOMEM;
1550 		goto _exit;
1551 	}
1552 
1553 	rc = t4_read_cim_ibq(sc, 3, (u32 *)buf, CIM_IBQ_SIZE * 4);
1554 	if (rc < 0) {
1555 		kmem_free(buf, t4ibq.len);
1556 		return (rc);
1557 	} else
1558 		rc = 0;
1559 
1560 	if (ddi_copyout(buf, t4ibq.data, t4ibq.len, flags) < 0)
1561 		rc = EFAULT;
1562 
1563 	kmem_free(buf, t4ibq.len);
1564 
1565 _exit:
1566 	return (rc);
1567 }
1568 
1569 static int
1570 read_cim_la(struct adapter *sc, void *data, int flags)
1571 {
1572 	struct t4_cim_la t4cimla;
1573 	int rc = 0;
1574 	unsigned int cfg;
1575 	__be64 *buf;
1576 
1577 	rc = t4_cim_read(sc, A_UP_UP_DBG_LA_CFG, 1, &cfg);
1578 	if (rc != 0)
1579 		return (rc);
1580 
1581 	if (ddi_copyin(data, &t4cimla, sizeof (t4cimla), flags) < 0) {
1582 		rc = EFAULT;
1583 		goto _exit;
1584 	}
1585 
1586 	buf = kmem_zalloc(t4cimla.len, KM_NOSLEEP);
1587 	if (buf == NULL) {
1588 		rc = ENOMEM;
1589 		goto _exit;
1590 	}
1591 
1592 	rc = t4_cim_read_la(sc, (u32 *)buf, NULL);
1593 	if (rc != 0) {
1594 		kmem_free(buf, t4cimla.len);
1595 		return (rc);
1596 	}
1597 
1598 	if (ddi_copyout(buf, t4cimla.data, t4cimla.len, flags) < 0)
1599 		rc = EFAULT;
1600 
1601 	kmem_free(buf, t4cimla.len);
1602 
1603 _exit:
1604 	return (rc);
1605 }
1606 
1607 static int
1608 read_mbox(struct adapter *sc, void *data, int flags)
1609 {
1610 	struct t4_mbox t4mbox;
1611 	int rc = 0, i;
1612 	__be64 *p, *buf;
1613 
1614 	u32 data_reg = PF_REG(4, A_CIM_PF_MAILBOX_DATA);
1615 
1616 	if (ddi_copyin(data, &t4mbox, sizeof (t4mbox), flags) < 0) {
1617 		rc = EFAULT;
1618 		goto _exit;
1619 	}
1620 
1621 	buf = p = kmem_zalloc(t4mbox.len, KM_NOSLEEP);
1622 	if (buf == NULL) {
1623 		rc = ENOMEM;
1624 		goto _exit;
1625 	}
1626 
1627 	for (i = 0; i < t4mbox.len; i += 8, p++)
1628 		*p =  t4_read_reg64(sc, data_reg + i);
1629 
1630 	if (ddi_copyout(buf, t4mbox.data, t4mbox.len, flags) < 0)
1631 		rc = EFAULT;
1632 
1633 	kmem_free(buf, t4mbox.len);
1634 
1635 _exit:
1636 	return (rc);
1637 }
1638