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