xref: /freebsd/sys/dev/isp/isp_library.c (revision 895f86f15fbf6540071feb9328c3c50ed1f027b8)
1 /*-
2  *  Copyright (c) 1997-2009 by Matthew Jacob
3  *  All rights reserved.
4  *
5  *  Redistribution and use in source and binary forms, with or without
6  *  modification, are permitted provided that the following conditions
7  *  are met:
8  *
9  *  1. Redistributions of source code must retain the above copyright
10  *     notice, this list of conditions and the following disclaimer.
11  *  2. Redistributions in binary form must reproduce the above copyright
12  *     notice, this list of conditions and the following disclaimer in the
13  *     documentation and/or other materials provided with the distribution.
14  *
15  *  THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  *  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  *  ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
19  *  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  *  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  *  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  *  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  *  SUCH DAMAGE.
26  *
27  */
28 /*
29  * Qlogic Host Adapter Internal Library Functions
30  */
31 #ifdef	__NetBSD__
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD$");
34 #include <dev/ic/isp_netbsd.h>
35 #endif
36 #ifdef	__FreeBSD__
37 #include <sys/cdefs.h>
38 __FBSDID("$FreeBSD$");
39 #include <dev/isp/isp_freebsd.h>
40 #endif
41 #ifdef	__OpenBSD__
42 #include <dev/ic/isp_openbsd.h>
43 #endif
44 #ifdef	__linux__
45 #include "isp_linux.h"
46 #endif
47 #ifdef	__svr4__
48 #include "isp_solaris.h"
49 #endif
50 
51 const char *isp_class3_roles[4] = {
52     "None", "Target", "Initiator", "Target/Initiator"
53 };
54 
55 /*
56  * Command shipping- finish off first queue entry and do dma mapping and additional segments as needed.
57  *
58  * Called with the first queue entry at least partially filled out.
59  */
60 int
61 isp_send_cmd(ispsoftc_t *isp, void *fqe, void *segp, uint32_t nsegs, uint32_t totalcnt, isp_ddir_t ddir, ispds64_t *ecmd)
62 {
63 	uint8_t storage[QENTRY_LEN];
64 	uint8_t type, nqe;
65 	uint32_t seg, curseg, seglim, nxt, nxtnxt, ddf;
66 	ispds_t *dsp = NULL;
67 	ispds64_t *dsp64 = NULL;
68 	void *qe0, *qe1;
69 
70 	qe0 = isp_getrqentry(isp);
71 	if (qe0 == NULL) {
72 		return (CMD_EAGAIN);
73 	}
74 	nxt = ISP_NXT_QENTRY(isp->isp_reqidx, RQUEST_QUEUE_LEN(isp));
75 
76 	type = ((isphdr_t *)fqe)->rqs_entry_type;
77 	nqe = 1;
78 
79 	/*
80 	 * If we have no data to transmit, just copy the first IOCB and start it up.
81 	 */
82 	if (ddir == ISP_NOXFR) {
83 		if (type == RQSTYPE_T2RQS || type == RQSTYPE_T3RQS) {
84 			ddf = CT2_NO_DATA;
85 		} else {
86 			ddf = 0;
87 		}
88 		goto copy_and_sync;
89 	}
90 
91 	/*
92 	 * First figure out how many pieces of data to transfer and what kind and how many we can put into the first queue entry.
93 	 */
94 	switch (type) {
95 	case RQSTYPE_REQUEST:
96 		ddf = (ddir == ISP_TO_DEVICE)? REQFLAG_DATA_OUT : REQFLAG_DATA_IN;
97 		dsp = ((ispreq_t *)fqe)->req_dataseg;
98 		seglim = ISP_RQDSEG;
99 		break;
100 	case RQSTYPE_CMDONLY:
101 		ddf = (ddir == ISP_TO_DEVICE)? REQFLAG_DATA_OUT : REQFLAG_DATA_IN;
102 		seglim = 0;
103 		break;
104 	case RQSTYPE_T2RQS:
105 		ddf = (ddir == ISP_TO_DEVICE)? REQFLAG_DATA_OUT : REQFLAG_DATA_IN;
106 		dsp = ((ispreqt2_t *)fqe)->req_dataseg;
107 		seglim = ISP_RQDSEG_T2;
108 		break;
109 	case RQSTYPE_A64:
110 		ddf = (ddir == ISP_TO_DEVICE)? REQFLAG_DATA_OUT : REQFLAG_DATA_IN;
111 		dsp64 = ((ispreqt3_t *)fqe)->req_dataseg;
112 		seglim = ISP_RQDSEG_T3;
113 		break;
114 	case RQSTYPE_T3RQS:
115 		ddf = (ddir == ISP_TO_DEVICE)? REQFLAG_DATA_OUT : REQFLAG_DATA_IN;
116 		dsp64 = ((ispreqt3_t *)fqe)->req_dataseg;
117 		seglim = ISP_RQDSEG_T3;
118 		break;
119 	case RQSTYPE_T7RQS:
120 		ddf = (ddir == ISP_TO_DEVICE)? FCP_CMND_DATA_WRITE : FCP_CMND_DATA_READ;
121 		dsp64 = &((ispreqt7_t *)fqe)->req_dataseg;
122 		seglim = 1;
123 		break;
124 	default:
125 		return (CMD_COMPLETE);
126 	}
127 
128 	if (seglim > nsegs) {
129 		seglim = nsegs;
130 	}
131 
132 	for (seg = curseg = 0; curseg < seglim; curseg++) {
133 		if (dsp64) {
134 			XS_GET_DMA64_SEG(dsp64++, segp, seg++);
135 		} else {
136 			XS_GET_DMA_SEG(dsp++, segp, seg++);
137 		}
138 	}
139 
140 
141 	/*
142 	 * Second, start building additional continuation segments as needed.
143 	 */
144 	while (seg < nsegs) {
145 		nxtnxt = ISP_NXT_QENTRY(nxt, RQUEST_QUEUE_LEN(isp));
146 		if (nxtnxt == isp->isp_reqodx) {
147 			isp->isp_reqodx = ISP_READ(isp, isp->isp_rqstoutrp);
148 			if (nxtnxt == isp->isp_reqodx)
149 				return (CMD_EAGAIN);
150 		}
151 		ISP_MEMZERO(storage, QENTRY_LEN);
152 		qe1 = ISP_QUEUE_ENTRY(isp->isp_rquest, nxt);
153 		nxt = nxtnxt;
154 		if (dsp64) {
155 			ispcontreq64_t *crq = (ispcontreq64_t *) storage;
156 			seglim = ISP_CDSEG64;
157 			crq->req_header.rqs_entry_type = RQSTYPE_A64_CONT;
158 			crq->req_header.rqs_entry_count = 1;
159 			dsp64 = crq->req_dataseg;
160 		} else {
161 			ispcontreq_t *crq = (ispcontreq_t *) storage;
162 			seglim = ISP_CDSEG;
163 			crq->req_header.rqs_entry_type = RQSTYPE_DATASEG;
164 			crq->req_header.rqs_entry_count = 1;
165 			dsp = crq->req_dataseg;
166 		}
167 		if (seg + seglim > nsegs) {
168 			seglim = nsegs - seg;
169 		}
170 		for (curseg = 0; curseg < seglim; curseg++) {
171 			if (dsp64) {
172 				XS_GET_DMA64_SEG(dsp64++, segp, seg++);
173 			} else {
174 				XS_GET_DMA_SEG(dsp++, segp, seg++);
175 			}
176 		}
177 		if (dsp64) {
178 			isp_put_cont64_req(isp, (ispcontreq64_t *)storage, qe1);
179 		} else {
180 			isp_put_cont_req(isp, (ispcontreq_t *)storage, qe1);
181 		}
182 		if (isp->isp_dblev & ISP_LOGDEBUG1) {
183 			isp_print_bytes(isp, "additional queue entry", QENTRY_LEN, storage);
184 		}
185 		nqe++;
186         }
187 
188 copy_and_sync:
189 	((isphdr_t *)fqe)->rqs_entry_count = nqe;
190 	switch (type) {
191 	case RQSTYPE_REQUEST:
192 		((ispreq_t *)fqe)->req_flags |= ddf;
193 		/*
194 		 * This is historical and not clear whether really needed.
195 		 */
196 		if (nsegs == 0) {
197 			nsegs = 1;
198 		}
199 		((ispreq_t *)fqe)->req_seg_count = nsegs;
200 		isp_put_request(isp, fqe, qe0);
201 		break;
202 	case RQSTYPE_CMDONLY:
203 		((ispreq_t *)fqe)->req_flags |= ddf;
204 		/*
205 		 * This is historical and not clear whether really needed.
206 		 */
207 		if (nsegs == 0) {
208 			nsegs = 1;
209 		}
210 		((ispextreq_t *)fqe)->req_seg_count = nsegs;
211 		isp_put_extended_request(isp, fqe, qe0);
212 		break;
213 	case RQSTYPE_T2RQS:
214 		((ispreqt2_t *)fqe)->req_flags |= ddf;
215 		((ispreqt2_t *)fqe)->req_seg_count = nsegs;
216 		((ispreqt2_t *)fqe)->req_totalcnt = totalcnt;
217 		if (ISP_CAP_2KLOGIN(isp)) {
218 			isp_put_request_t2e(isp, fqe, qe0);
219 		} else {
220 			isp_put_request_t2(isp, fqe, qe0);
221 		}
222 		break;
223 	case RQSTYPE_A64:
224 	case RQSTYPE_T3RQS:
225 		((ispreqt3_t *)fqe)->req_flags |= ddf;
226 		((ispreqt3_t *)fqe)->req_seg_count = nsegs;
227 		((ispreqt3_t *)fqe)->req_totalcnt = totalcnt;
228 		if (ISP_CAP_2KLOGIN(isp)) {
229 			isp_put_request_t3e(isp, fqe, qe0);
230 		} else {
231 			isp_put_request_t3(isp, fqe, qe0);
232 		}
233 		break;
234 	case RQSTYPE_T7RQS:
235         	((ispreqt7_t *)fqe)->req_alen_datadir = ddf;
236 		((ispreqt7_t *)fqe)->req_seg_count = nsegs;
237 		((ispreqt7_t *)fqe)->req_dl = totalcnt;
238 		isp_put_request_t7(isp, fqe, qe0);
239 		break;
240 	default:
241 		return (CMD_COMPLETE);
242 	}
243 	if (isp->isp_dblev & ISP_LOGDEBUG1) {
244 		isp_print_bytes(isp, "first queue entry", QENTRY_LEN, fqe);
245 	}
246 	ISP_ADD_REQUEST(isp, nxt);
247 	return (CMD_QUEUED);
248 }
249 
250 int
251 isp_allocate_xs(ispsoftc_t *isp, XS_T *xs, uint32_t *handlep)
252 {
253 	isp_hdl_t *hdp;
254 
255 	hdp = isp->isp_xffree;
256 	if (hdp == NULL) {
257 		return (-1);
258 	}
259 	isp->isp_xffree = hdp->cmd;
260 	hdp->cmd = xs;
261 	hdp->handle = (hdp - isp->isp_xflist);
262 	hdp->handle |= (ISP_HANDLE_INITIATOR << ISP_HANDLE_USAGE_SHIFT);
263 	hdp->handle |= (isp->isp_seqno++ << ISP_HANDLE_SEQ_SHIFT);
264 	*handlep = hdp->handle;
265 	return (0);
266 }
267 
268 XS_T *
269 isp_find_xs(ispsoftc_t *isp, uint32_t handle)
270 {
271 	if (!ISP_VALID_INI_HANDLE(isp, handle)) {
272 		isp_prt(isp, ISP_LOGERR, "%s: bad handle 0x%x", __func__, handle);
273 		return (NULL);
274 	}
275 	return (isp->isp_xflist[(handle & ISP_HANDLE_CMD_MASK)].cmd);
276 }
277 
278 uint32_t
279 isp_find_handle(ispsoftc_t *isp, XS_T *xs)
280 {
281 	uint32_t i, foundhdl = ISP_HANDLE_FREE;
282 
283 	if (xs != NULL) {
284 		for (i = 0; i < isp->isp_maxcmds; i++) {
285 			if (isp->isp_xflist[i].cmd != xs) {
286 				continue;
287 			}
288 			foundhdl = isp->isp_xflist[i].handle;
289 			break;
290 		}
291 	}
292 	return (foundhdl);
293 }
294 
295 uint32_t
296 isp_handle_index(ispsoftc_t *isp, uint32_t handle)
297 {
298 	if (!ISP_VALID_HANDLE(isp, handle)) {
299 		isp_prt(isp, ISP_LOGERR, "%s: bad handle 0x%x", __func__, handle);
300 		return (ISP_BAD_HANDLE_INDEX);
301 	} else {
302 		return (handle & ISP_HANDLE_CMD_MASK);
303 	}
304 }
305 
306 void
307 isp_destroy_handle(ispsoftc_t *isp, uint32_t handle)
308 {
309 	if (!ISP_VALID_INI_HANDLE(isp, handle)) {
310 		isp_prt(isp, ISP_LOGERR, "%s: bad handle 0x%x", __func__, handle);
311 	} else {
312 		isp->isp_xflist[(handle & ISP_HANDLE_CMD_MASK)].handle = ISP_HANDLE_FREE;
313 		isp->isp_xflist[(handle & ISP_HANDLE_CMD_MASK)].cmd = isp->isp_xffree;
314 		isp->isp_xffree = &isp->isp_xflist[(handle & ISP_HANDLE_CMD_MASK)];
315 	}
316 }
317 
318 /*
319  * Make sure we have space to put something on the request queue.
320  * Return a pointer to that entry if we do. A side effect of this
321  * function is to update the output index. The input index
322  * stays the same.
323  */
324 void *
325 isp_getrqentry(ispsoftc_t *isp)
326 {
327 	uint32_t next;
328 
329 	next = ISP_NXT_QENTRY(isp->isp_reqidx, RQUEST_QUEUE_LEN(isp));
330 	if (next == isp->isp_reqodx) {
331 		isp->isp_reqodx = ISP_READ(isp, isp->isp_rqstoutrp);
332 		if (next == isp->isp_reqodx)
333 			return (NULL);
334 	}
335 	return (ISP_QUEUE_ENTRY(isp->isp_rquest, isp->isp_reqidx));
336 }
337 
338 #define	TBA	(4 * (((QENTRY_LEN >> 2) * 3) + 1) + 1)
339 void
340 isp_print_qentry(ispsoftc_t *isp, const char *msg, int idx, void *arg)
341 {
342 	char buf[TBA];
343 	int amt, i, j;
344 	uint8_t *ptr = arg;
345 
346 	isp_prt(isp, ISP_LOGALL, "%s index %d=>", msg, idx);
347 	for (buf[0] = 0, amt = i = 0; i < 4; i++) {
348 		buf[0] = 0;
349 		ISP_SNPRINTF(buf, TBA, "  ");
350 		for (j = 0; j < (QENTRY_LEN >> 2); j++) {
351 			ISP_SNPRINTF(buf, TBA, "%s %02x", buf, ptr[amt++] & 0xff);
352 		}
353 		isp_prt(isp, ISP_LOGALL, "%s", buf);
354 	}
355 }
356 
357 void
358 isp_print_bytes(ispsoftc_t *isp, const char *msg, int amt, void *arg)
359 {
360 	char buf[128];
361 	uint8_t *ptr = arg;
362 	int off;
363 
364 	if (msg)
365 		isp_prt(isp, ISP_LOGALL, "%s:", msg);
366 	off = 0;
367 	buf[0] = 0;
368 	while (off < amt) {
369 		int j, to;
370 		to = off;
371 		for (j = 0; j < 16; j++) {
372 			ISP_SNPRINTF(buf, 128, "%s %02x", buf, ptr[off++] & 0xff);
373 			if (off == amt) {
374 				break;
375 			}
376 		}
377 		isp_prt(isp, ISP_LOGALL, "0x%08x:%s", to, buf);
378 		buf[0] = 0;
379 	}
380 }
381 
382 /*
383  * Do the common path to try and ensure that link is up, we've scanned
384  * the fabric (if we're on a fabric), and that we've synchronized this
385  * all with our own database and done the appropriate logins.
386  *
387  * We repeatedly check for firmware state and loop state after each
388  * action because things may have changed while we were doing this.
389  * Any failure or change of state causes us to return a nonzero value.
390  *
391  * We assume we enter here with any locks held.
392  */
393 
394 int
395 isp_fc_runstate(ispsoftc_t *isp, int chan, int tval)
396 {
397 	fcparam *fcp = FCPARAM(isp, chan);
398 	int res;
399 
400 again:
401 	if (fcp->role == ISP_ROLE_NONE)
402 		return (-1);
403 	res = isp_control(isp, ISPCTL_FCLINK_TEST, chan, tval);
404 	if (res > 0)
405 		goto again;
406 	if (res < 0)
407 		return (fcp->isp_loopstate);
408 	res = isp_control(isp, ISPCTL_SCAN_LOOP, chan);
409 	if (res > 0)
410 		goto again;
411 	if (res < 0)
412 		return (fcp->isp_loopstate);
413 	res = isp_control(isp, ISPCTL_SCAN_FABRIC, chan);
414 	if (res > 0)
415 		goto again;
416 	if (res < 0)
417 		return (fcp->isp_loopstate);
418 	res = isp_control(isp, ISPCTL_PDB_SYNC, chan);
419 	if (res > 0)
420 		goto again;
421 	return (fcp->isp_loopstate);
422 }
423 
424 /*
425  * Fibre Channel Support routines
426  */
427 void
428 isp_dump_portdb(ispsoftc_t *isp, int chan)
429 {
430 	fcparam *fcp = FCPARAM(isp, chan);
431 	int i;
432 
433 	for (i = 0; i < MAX_FC_TARG; i++) {
434 		char buf1[64], buf2[64];
435 		const char *dbs[8] = {
436 			"NIL ",
437 			"PROB",
438 			"DEAD",
439 			"CHGD",
440 			"NEW ",
441 			"PVLD",
442 			"ZOMB",
443 			"VLD "
444 		};
445 		fcportdb_t *lp = &fcp->portdb[i];
446 
447 		if (lp->state == FC_PORTDB_STATE_NIL) {
448 			continue;
449 		}
450 		isp_gen_role_str(buf1, sizeof (buf1), lp->prli_word3);
451 		isp_gen_role_str(buf2, sizeof (buf2), lp->new_prli_word3);
452 		isp_prt(isp, ISP_LOGALL, "Chan %d [%d]: hdl 0x%x %s al%d %s 0x%06x =>%s 0x%06x; WWNN 0x%08x%08x WWPN 0x%08x%08x",
453 		    chan, i, lp->handle, dbs[lp->state], lp->autologin, buf1, lp->portid, buf2, lp->new_portid,
454 		    (uint32_t) (lp->node_wwn >> 32), (uint32_t) (lp->node_wwn), (uint32_t) (lp->port_wwn >> 32), (uint32_t) (lp->port_wwn));
455 	}
456 }
457 
458 void
459 isp_gen_role_str(char *buf, size_t len, uint16_t p3)
460 {
461 	int nd = 0;
462 	buf[0] = '(';
463 	buf[1] = 0;
464 	if (p3 & PRLI_WD3_ENHANCED_DISCOVERY) {
465 		nd++;
466 		strlcat(buf, "EDisc", len);
467 	}
468 	if (p3 & PRLI_WD3_REC_SUPPORT) {
469 		if (nd++) {
470 			strlcat(buf, ",", len);
471 		}
472 		strlcat(buf, "REC", len);
473 	}
474 	if (p3 & PRLI_WD3_TASK_RETRY_IDENTIFICATION_REQUESTED) {
475 		if (nd++) {
476 			strlcat(buf, ",", len);
477 		}
478 		strlcat(buf, "RetryID", len);
479 	}
480 	if (p3 & PRLI_WD3_RETRY) {
481 		if (nd++) {
482 			strlcat(buf, ",", len);
483 		}
484 		strlcat(buf, "Retry", len);
485 	}
486 	if (p3 & PRLI_WD3_CONFIRMED_COMPLETION_ALLOWED) {
487 		if (nd++) {
488 			strlcat(buf, ",", len);
489 		}
490 		strlcat(buf, "CNFRM", len);
491 	}
492 	if (p3 & PRLI_WD3_DATA_OVERLAY_ALLOWED) {
493 		if (nd++) {
494 			strlcat(buf, ",", len);
495 		}
496 		strlcat(buf, "DOver", len);
497 	}
498 	if (p3 & PRLI_WD3_INITIATOR_FUNCTION) {
499 		if (nd++) {
500 			strlcat(buf, ",", len);
501 		}
502 		strlcat(buf, "INI", len);
503 	}
504 	if (p3 & PRLI_WD3_TARGET_FUNCTION) {
505 		if (nd++) {
506 			strlcat(buf, ",", len);
507 		}
508 		strlcat(buf, "TGT", len);
509 	}
510 	if (p3 & PRLI_WD3_READ_FCP_XFER_RDY_DISABLED) {
511 		if (nd++) {
512 			strlcat(buf, ",", len);
513 		}
514 		strlcat(buf, "RdXfrDis", len);
515 	}
516 	if (p3 & PRLI_WD3_WRITE_FCP_XFER_RDY_DISABLED) {
517 		if (nd++) {
518 			strlcat(buf, ",", len);
519 		}
520 		strlcat(buf, "XfrDis", len);
521 	}
522 	strlcat(buf, ")", len);
523 }
524 
525 const char *
526 isp_fc_fw_statename(int state)
527 {
528 	switch (state) {
529 	case FW_CONFIG_WAIT:	return "Config Wait";
530 	case FW_WAIT_LINK:	return "Wait Link";
531 	case FW_WAIT_LOGIN:	return "Wait Login";
532 	case FW_READY:		return "Ready";
533 	case FW_LOSS_OF_SYNC:	return "Loss Of Sync";
534 	case FW_ERROR:		return "Error";
535 	case FW_REINIT:		return "Re-Init";
536 	case FW_NON_PART:	return "Nonparticipating";
537 	default:		return "?????";
538 	}
539 }
540 
541 const char *
542 isp_fc_loop_statename(int state)
543 {
544 	switch (state) {
545 	case LOOP_NIL:                  return "NIL";
546 	case LOOP_HAVE_LINK:            return "Have Link";
547 	case LOOP_TESTING_LINK:         return "Testing Link";
548 	case LOOP_LTEST_DONE:           return "Link Test Done";
549 	case LOOP_SCANNING_LOOP:        return "Scanning Loop";
550 	case LOOP_LSCAN_DONE:           return "Loop Scan Done";
551 	case LOOP_SCANNING_FABRIC:      return "Scanning Fabric";
552 	case LOOP_FSCAN_DONE:           return "Fabric Scan Done";
553 	case LOOP_SYNCING_PDB:          return "Syncing PDB";
554 	case LOOP_READY:                return "Ready";
555 	default:                        return "?????";
556 	}
557 }
558 
559 const char *
560 isp_fc_toponame(fcparam *fcp)
561 {
562 
563 	if (fcp->isp_loopstate < LOOP_LTEST_DONE) {
564 		return "Unavailable";
565 	}
566 	switch (fcp->isp_topo) {
567 	case TOPO_NL_PORT:      return "Private Loop (NL_Port)";
568 	case TOPO_FL_PORT:      return "Public Loop (FL_Port)";
569 	case TOPO_N_PORT:       return "Point-to-Point (N_Port)";
570 	case TOPO_F_PORT:       return "Fabric (F_Port)";
571 	case TOPO_PTP_STUB:     return "Point-to-Point (no response)";
572 	default:                return "?????";
573 	}
574 }
575 
576 static int
577 isp_fc_enable_vp(ispsoftc_t *isp, int chan)
578 {
579 	fcparam *fcp = FCPARAM(isp, chan);
580 	mbreg_t mbs;
581 	vp_modify_t *vp;
582 	uint8_t qe[QENTRY_LEN], *scp;
583 
584 	ISP_MEMZERO(qe, QENTRY_LEN);
585 	if (FC_SCRATCH_ACQUIRE(isp, chan)) {
586 		return (EBUSY);
587 	}
588 	scp = fcp->isp_scratch;
589 
590 	/*
591 	 * Build a VP MODIFY command in memory
592 	 */
593 	vp = (vp_modify_t *) qe;
594 	vp->vp_mod_hdr.rqs_entry_type = RQSTYPE_VP_MODIFY;
595 	vp->vp_mod_hdr.rqs_entry_count = 1;
596 	vp->vp_mod_cnt = 1;
597 	vp->vp_mod_idx0 = chan;
598 	vp->vp_mod_cmd = VP_MODIFY_ENA;
599 	vp->vp_mod_ports[0].options = ICB2400_VPOPT_ENABLED |
600 	    ICB2400_VPOPT_ENA_SNSLOGIN;
601 	if (fcp->role & ISP_ROLE_INITIATOR) {
602 		vp->vp_mod_ports[0].options |= ICB2400_VPOPT_INI_ENABLE;
603 	}
604 	if ((fcp->role & ISP_ROLE_TARGET) == 0) {
605 		vp->vp_mod_ports[0].options |= ICB2400_VPOPT_TGT_DISABLE;
606 	}
607 	if (fcp->isp_loopid < LOCAL_LOOP_LIM) {
608 		vp->vp_mod_ports[0].loopid = fcp->isp_loopid;
609 		if (isp->isp_confopts & ISP_CFG_OWNLOOPID)
610 			vp->vp_mod_ports[0].options |=
611 			    ICB2400_VPOPT_HARD_ADDRESS;
612 		else
613 			vp->vp_mod_ports[0].options |=
614 			    ICB2400_VPOPT_PREV_ADDRESS;
615 	}
616 	MAKE_NODE_NAME_FROM_WWN(vp->vp_mod_ports[0].wwpn, fcp->isp_wwpn);
617 	MAKE_NODE_NAME_FROM_WWN(vp->vp_mod_ports[0].wwnn, fcp->isp_wwnn);
618 	isp_put_vp_modify(isp, vp, (vp_modify_t *) scp);
619 
620 	/*
621 	 * Build a EXEC IOCB A64 command that points to the VP MODIFY command
622 	 */
623 	MBSINIT(&mbs, MBOX_EXEC_COMMAND_IOCB_A64, MBLOGALL, 0);
624 	mbs.param[1] = QENTRY_LEN;
625 	mbs.param[2] = DMA_WD1(fcp->isp_scdma);
626 	mbs.param[3] = DMA_WD0(fcp->isp_scdma);
627 	mbs.param[6] = DMA_WD3(fcp->isp_scdma);
628 	mbs.param[7] = DMA_WD2(fcp->isp_scdma);
629 	MEMORYBARRIER(isp, SYNC_SFORDEV, 0, 2 * QENTRY_LEN, chan);
630 	isp_control(isp, ISPCTL_RUN_MBOXCMD, &mbs);
631 	if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
632 		FC_SCRATCH_RELEASE(isp, chan);
633 		return (EIO);
634 	}
635 	MEMORYBARRIER(isp, SYNC_SFORCPU, QENTRY_LEN, QENTRY_LEN, chan);
636 	isp_get_vp_modify(isp, (vp_modify_t *)&scp[QENTRY_LEN], vp);
637 
638 	FC_SCRATCH_RELEASE(isp, chan);
639 
640 	if (vp->vp_mod_status != VP_STS_OK) {
641 		isp_prt(isp, ISP_LOGERR, "%s: VP_MODIFY of Chan %d failed with status %d", __func__, chan, vp->vp_mod_status);
642 		return (EIO);
643 	}
644 	return (0);
645 }
646 
647 static int
648 isp_fc_disable_vp(ispsoftc_t *isp, int chan)
649 {
650 	fcparam *fcp = FCPARAM(isp, chan);
651 	mbreg_t mbs;
652 	vp_ctrl_info_t *vp;
653 	uint8_t qe[QENTRY_LEN], *scp;
654 
655 	ISP_MEMZERO(qe, QENTRY_LEN);
656 	if (FC_SCRATCH_ACQUIRE(isp, chan)) {
657 		return (EBUSY);
658 	}
659 	scp = fcp->isp_scratch;
660 
661 	/*
662 	 * Build a VP CTRL command in memory
663 	 */
664 	vp = (vp_ctrl_info_t *) qe;
665 	vp->vp_ctrl_hdr.rqs_entry_type = RQSTYPE_VP_CTRL;
666 	vp->vp_ctrl_hdr.rqs_entry_count = 1;
667 	if (ISP_CAP_VP0(isp)) {
668 		vp->vp_ctrl_status = 1;
669 	} else {
670 		vp->vp_ctrl_status = 0;
671 		chan--;	/* VP0 can not be controlled in this case. */
672 	}
673 	vp->vp_ctrl_command = VP_CTRL_CMD_DISABLE_VP_LOGO_ALL;
674 	vp->vp_ctrl_vp_count = 1;
675 	vp->vp_ctrl_idmap[chan / 16] |= (1 << chan % 16);
676 	isp_put_vp_ctrl_info(isp, vp, (vp_ctrl_info_t *) scp);
677 
678 	/*
679 	 * Build a EXEC IOCB A64 command that points to the VP CTRL command
680 	 */
681 	MBSINIT(&mbs, MBOX_EXEC_COMMAND_IOCB_A64, MBLOGALL, 0);
682 	mbs.param[1] = QENTRY_LEN;
683 	mbs.param[2] = DMA_WD1(fcp->isp_scdma);
684 	mbs.param[3] = DMA_WD0(fcp->isp_scdma);
685 	mbs.param[6] = DMA_WD3(fcp->isp_scdma);
686 	mbs.param[7] = DMA_WD2(fcp->isp_scdma);
687 	MEMORYBARRIER(isp, SYNC_SFORDEV, 0, 2 * QENTRY_LEN, chan);
688 	isp_control(isp, ISPCTL_RUN_MBOXCMD, &mbs);
689 	if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
690 		FC_SCRATCH_RELEASE(isp, chan);
691 		return (EIO);
692 	}
693 	MEMORYBARRIER(isp, SYNC_SFORCPU, QENTRY_LEN, QENTRY_LEN, chan);
694 	isp_get_vp_ctrl_info(isp, (vp_ctrl_info_t *)&scp[QENTRY_LEN], vp);
695 
696 	FC_SCRATCH_RELEASE(isp, chan);
697 
698 	if (vp->vp_ctrl_status != 0) {
699 		isp_prt(isp, ISP_LOGERR,
700 		    "%s: VP_CTRL of Chan %d failed with status %d %d",
701 		    __func__, chan, vp->vp_ctrl_status, vp->vp_ctrl_index_fail);
702 		return (EIO);
703 	}
704 	return (0);
705 }
706 
707 /*
708  * Change Roles
709  */
710 int
711 isp_fc_change_role(ispsoftc_t *isp, int chan, int new_role)
712 {
713 	fcparam *fcp = FCPARAM(isp, chan);
714 	int i, was, res = 0;
715 
716 	if (chan >= isp->isp_nchan) {
717 		isp_prt(isp, ISP_LOGWARN, "%s: bad channel %d", __func__, chan);
718 		return (ENXIO);
719 	}
720 	if (fcp->role == new_role)
721 		return (0);
722 	for (was = 0, i = 0; i < isp->isp_nchan; i++) {
723 		if (FCPARAM(isp, i)->role != ISP_ROLE_NONE)
724 			was++;
725 	}
726 	if (was == 0 || (was == 1 && fcp->role != ISP_ROLE_NONE)) {
727 		fcp->role = new_role;
728 		return (isp_reinit(isp, 0));
729 	}
730 	if (fcp->role != ISP_ROLE_NONE)
731 		res = isp_fc_disable_vp(isp, chan);
732 	fcp->role = new_role;
733 	if (fcp->role != ISP_ROLE_NONE)
734 		res = isp_fc_enable_vp(isp, chan);
735 	return (res);
736 }
737 
738 void
739 isp_clear_commands(ispsoftc_t *isp)
740 {
741 	uint32_t tmp;
742 	isp_hdl_t *hdp;
743 #ifdef	ISP_TARGET_MODE
744 	isp_notify_t notify;
745 #endif
746 
747 	for (tmp = 0; isp->isp_xflist && tmp < isp->isp_maxcmds; tmp++) {
748 		XS_T *xs;
749 
750 		hdp = &isp->isp_xflist[tmp];
751 		if (hdp->handle == ISP_HANDLE_FREE) {
752 			continue;
753 		}
754 		xs = hdp->cmd;
755 		if (XS_XFRLEN(xs)) {
756 			ISP_DMAFREE(isp, xs, hdp->handle);
757 			XS_SET_RESID(xs, XS_XFRLEN(xs));
758 		} else {
759 			XS_SET_RESID(xs, 0);
760 		}
761 		hdp->handle = 0;
762 		hdp->cmd = NULL;
763 		XS_SETERR(xs, HBA_BUSRESET);
764 		isp_done(xs);
765 	}
766 #ifdef	ISP_TARGET_MODE
767 	for (tmp = 0; isp->isp_tgtlist && tmp < isp->isp_maxcmds; tmp++) {
768 		uint8_t local[QENTRY_LEN];
769 		hdp = &isp->isp_tgtlist[tmp];
770 		if (hdp->handle == ISP_HANDLE_FREE) {
771 			continue;
772 		}
773 		ISP_DMAFREE(isp, hdp->cmd, hdp->handle);
774 		ISP_MEMZERO(local, QENTRY_LEN);
775 		if (IS_24XX(isp)) {
776 			ct7_entry_t *ctio = (ct7_entry_t *) local;
777 			ctio->ct_syshandle = hdp->handle;
778 			ctio->ct_nphdl = CT_HBA_RESET;
779 			ctio->ct_header.rqs_entry_type = RQSTYPE_CTIO7;
780 		} else {
781 			ct2_entry_t *ctio = (ct2_entry_t *) local;
782 			ctio->ct_syshandle = hdp->handle;
783 			ctio->ct_status = CT_HBA_RESET;
784 			ctio->ct_header.rqs_entry_type = RQSTYPE_CTIO2;
785 		}
786 		isp_async(isp, ISPASYNC_TARGET_ACTION, local);
787 	}
788 	for (tmp = 0; tmp < isp->isp_nchan; tmp++) {
789 		ISP_MEMZERO(&notify, sizeof (isp_notify_t));
790 		notify.nt_ncode = NT_HBA_RESET;
791 		notify.nt_hba = isp;
792 		notify.nt_wwn = INI_ANY;
793 		notify.nt_nphdl = NIL_HANDLE;
794 		notify.nt_sid = PORT_ANY;
795 		notify.nt_did = PORT_ANY;
796 		notify.nt_tgt = TGT_ANY;
797 		notify.nt_channel = tmp;
798 		notify.nt_lun = LUN_ANY;
799 		notify.nt_tagval = TAG_ANY;
800 		isp_async(isp, ISPASYNC_TARGET_NOTIFY, &notify);
801 	}
802 #endif
803 }
804 
805 void
806 isp_shutdown(ispsoftc_t *isp)
807 {
808 	if (IS_FC(isp)) {
809 		if (IS_24XX(isp)) {
810 			ISP_WRITE(isp, BIU2400_ICR, 0);
811 			ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_PAUSE);
812 		} else {
813 			ISP_WRITE(isp, BIU_ICR, 0);
814 			ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
815 			ISP_WRITE(isp, BIU2100_CSR, BIU2100_FPM0_REGS);
816 			ISP_WRITE(isp, FPM_DIAG_CONFIG, FPM_SOFT_RESET);
817 			ISP_WRITE(isp, BIU2100_CSR, BIU2100_FB_REGS);
818 			ISP_WRITE(isp, FBM_CMD, FBMCMD_FIFO_RESET_ALL);
819 			ISP_WRITE(isp, BIU2100_CSR, BIU2100_RISC_REGS);
820 		}
821 	} else {
822 		ISP_WRITE(isp, BIU_ICR, 0);
823 		ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
824 	}
825 }
826 
827 /*
828  * Functions to move stuff to a form that the QLogic RISC engine understands
829  * and functions to move stuff back to a form the processor understands.
830  *
831  * Each platform is required to provide the 8, 16 and 32 bit
832  * swizzle and unswizzle macros (ISP_IOX{PUT|GET}_{8,16,32})
833  *
834  * The assumption is that swizzling and unswizzling is mostly done 'in place'
835  * (with a few exceptions for efficiency).
836  */
837 
838 #define	ISP_IS_SBUS(isp)	(ISP_SBUS_SUPPORTED && (isp)->isp_bustype == ISP_BT_SBUS)
839 
840 #define	ASIZE(x)	(sizeof (x) / sizeof (x[0]))
841 /*
842  * Swizzle/Copy Functions
843  */
844 void
845 isp_put_hdr(ispsoftc_t *isp, isphdr_t *hpsrc, isphdr_t *hpdst)
846 {
847 	if (ISP_IS_SBUS(isp)) {
848 		ISP_IOXPUT_8(isp, hpsrc->rqs_entry_type, &hpdst->rqs_entry_count);
849 		ISP_IOXPUT_8(isp, hpsrc->rqs_entry_count, &hpdst->rqs_entry_type);
850 		ISP_IOXPUT_8(isp, hpsrc->rqs_seqno, &hpdst->rqs_flags);
851 		ISP_IOXPUT_8(isp, hpsrc->rqs_flags, &hpdst->rqs_seqno);
852 	} else {
853 		ISP_IOXPUT_8(isp, hpsrc->rqs_entry_type, &hpdst->rqs_entry_type);
854 		ISP_IOXPUT_8(isp, hpsrc->rqs_entry_count, &hpdst->rqs_entry_count);
855 		ISP_IOXPUT_8(isp, hpsrc->rqs_seqno, &hpdst->rqs_seqno);
856 		ISP_IOXPUT_8(isp, hpsrc->rqs_flags, &hpdst->rqs_flags);
857 	}
858 }
859 
860 void
861 isp_get_hdr(ispsoftc_t *isp, isphdr_t *hpsrc, isphdr_t *hpdst)
862 {
863 	if (ISP_IS_SBUS(isp)) {
864 		ISP_IOXGET_8(isp, &hpsrc->rqs_entry_type, hpdst->rqs_entry_count);
865 		ISP_IOXGET_8(isp, &hpsrc->rqs_entry_count, hpdst->rqs_entry_type);
866 		ISP_IOXGET_8(isp, &hpsrc->rqs_seqno, hpdst->rqs_flags);
867 		ISP_IOXGET_8(isp, &hpsrc->rqs_flags, hpdst->rqs_seqno);
868 	} else {
869 		ISP_IOXGET_8(isp, &hpsrc->rqs_entry_type, hpdst->rqs_entry_type);
870 		ISP_IOXGET_8(isp, &hpsrc->rqs_entry_count, hpdst->rqs_entry_count);
871 		ISP_IOXGET_8(isp, &hpsrc->rqs_seqno, hpdst->rqs_seqno);
872 		ISP_IOXGET_8(isp, &hpsrc->rqs_flags, hpdst->rqs_flags);
873 	}
874 }
875 
876 int
877 isp_get_response_type(ispsoftc_t *isp, isphdr_t *hp)
878 {
879 	uint8_t type;
880 	if (ISP_IS_SBUS(isp)) {
881 		ISP_IOXGET_8(isp, &hp->rqs_entry_count, type);
882 	} else {
883 		ISP_IOXGET_8(isp, &hp->rqs_entry_type, type);
884 	}
885 	return ((int)type);
886 }
887 
888 void
889 isp_put_request(ispsoftc_t *isp, ispreq_t *rqsrc, ispreq_t *rqdst)
890 {
891 	int i;
892 	isp_put_hdr(isp, &rqsrc->req_header, &rqdst->req_header);
893 	ISP_IOXPUT_32(isp, rqsrc->req_handle, &rqdst->req_handle);
894 	if (ISP_IS_SBUS(isp)) {
895 		ISP_IOXPUT_8(isp, rqsrc->req_lun_trn, &rqdst->req_target);
896 		ISP_IOXPUT_8(isp, rqsrc->req_target, &rqdst->req_lun_trn);
897 	} else {
898 		ISP_IOXPUT_8(isp, rqsrc->req_lun_trn, &rqdst->req_lun_trn);
899 		ISP_IOXPUT_8(isp, rqsrc->req_target, &rqdst->req_target);
900 	}
901 	ISP_IOXPUT_16(isp, rqsrc->req_cdblen, &rqdst->req_cdblen);
902 	ISP_IOXPUT_16(isp, rqsrc->req_flags, &rqdst->req_flags);
903 	ISP_IOXPUT_16(isp, rqsrc->req_time, &rqdst->req_time);
904 	ISP_IOXPUT_16(isp, rqsrc->req_seg_count, &rqdst->req_seg_count);
905 	for (i = 0; i < ASIZE(rqsrc->req_cdb); i++) {
906 		ISP_IOXPUT_8(isp, rqsrc->req_cdb[i], &rqdst->req_cdb[i]);
907 	}
908 	for (i = 0; i < ISP_RQDSEG; i++) {
909 		ISP_IOXPUT_32(isp, rqsrc->req_dataseg[i].ds_base, &rqdst->req_dataseg[i].ds_base);
910 		ISP_IOXPUT_32(isp, rqsrc->req_dataseg[i].ds_count, &rqdst->req_dataseg[i].ds_count);
911 	}
912 }
913 
914 void
915 isp_put_marker(ispsoftc_t *isp, isp_marker_t *src, isp_marker_t *dst)
916 {
917 	int i;
918 	isp_put_hdr(isp, &src->mrk_header, &dst->mrk_header);
919 	ISP_IOXPUT_32(isp, src->mrk_handle, &dst->mrk_handle);
920 	if (ISP_IS_SBUS(isp)) {
921 		ISP_IOXPUT_8(isp, src->mrk_reserved0, &dst->mrk_target);
922 		ISP_IOXPUT_8(isp, src->mrk_target, &dst->mrk_reserved0);
923 	} else {
924 		ISP_IOXPUT_8(isp, src->mrk_reserved0, &dst->mrk_reserved0);
925 		ISP_IOXPUT_8(isp, src->mrk_target, &dst->mrk_target);
926 	}
927 	ISP_IOXPUT_16(isp, src->mrk_modifier, &dst->mrk_modifier);
928 	ISP_IOXPUT_16(isp, src->mrk_flags, &dst->mrk_flags);
929 	ISP_IOXPUT_16(isp, src->mrk_lun, &dst->mrk_lun);
930 	for (i = 0; i < ASIZE(src->mrk_reserved1); i++) {
931 		ISP_IOXPUT_8(isp, src->mrk_reserved1[i], &dst->mrk_reserved1[i]);
932 	}
933 }
934 
935 void
936 isp_put_marker_24xx(ispsoftc_t *isp, isp_marker_24xx_t *src, isp_marker_24xx_t *dst)
937 {
938 	int i;
939 	isp_put_hdr(isp, &src->mrk_header, &dst->mrk_header);
940 	ISP_IOXPUT_32(isp, src->mrk_handle, &dst->mrk_handle);
941 	ISP_IOXPUT_16(isp, src->mrk_nphdl, &dst->mrk_nphdl);
942 	ISP_IOXPUT_8(isp, src->mrk_modifier, &dst->mrk_modifier);
943 	ISP_IOXPUT_8(isp, src->mrk_reserved0, &dst->mrk_reserved0);
944 	ISP_IOXPUT_8(isp, src->mrk_reserved1, &dst->mrk_reserved1);
945 	ISP_IOXPUT_8(isp, src->mrk_vphdl, &dst->mrk_vphdl);
946 	ISP_IOXPUT_8(isp, src->mrk_reserved2, &dst->mrk_reserved2);
947 	for (i = 0; i < ASIZE(src->mrk_lun); i++) {
948 		ISP_IOXPUT_8(isp, src->mrk_lun[i], &dst->mrk_lun[i]);
949 	}
950 	for (i = 0; i < ASIZE(src->mrk_reserved3); i++) {
951 		ISP_IOXPUT_8(isp, src->mrk_reserved3[i], &dst->mrk_reserved3[i]);
952 	}
953 }
954 
955 void
956 isp_put_request_t2(ispsoftc_t *isp, ispreqt2_t *src, ispreqt2_t *dst)
957 {
958 	int i;
959 	isp_put_hdr(isp, &src->req_header, &dst->req_header);
960 	ISP_IOXPUT_32(isp, src->req_handle, &dst->req_handle);
961 	ISP_IOXPUT_8(isp, src->req_lun_trn, &dst->req_lun_trn);
962 	ISP_IOXPUT_8(isp, src->req_target, &dst->req_target);
963 	ISP_IOXPUT_16(isp, src->req_scclun, &dst->req_scclun);
964 	ISP_IOXPUT_16(isp, src->req_flags,  &dst->req_flags);
965 	ISP_IOXPUT_8(isp, src->req_crn, &dst->req_crn);
966 	ISP_IOXPUT_8(isp, src->req_reserved, &dst->req_reserved);
967 	ISP_IOXPUT_16(isp, src->req_time, &dst->req_time);
968 	ISP_IOXPUT_16(isp, src->req_seg_count, &dst->req_seg_count);
969 	for (i = 0; i < ASIZE(src->req_cdb); i++) {
970 		ISP_IOXPUT_8(isp, src->req_cdb[i], &dst->req_cdb[i]);
971 	}
972 	ISP_IOXPUT_32(isp, src->req_totalcnt, &dst->req_totalcnt);
973 	for (i = 0; i < ISP_RQDSEG_T2; i++) {
974 		ISP_IOXPUT_32(isp, src->req_dataseg[i].ds_base, &dst->req_dataseg[i].ds_base);
975 		ISP_IOXPUT_32(isp, src->req_dataseg[i].ds_count, &dst->req_dataseg[i].ds_count);
976 	}
977 }
978 
979 void
980 isp_put_request_t2e(ispsoftc_t *isp, ispreqt2e_t *src, ispreqt2e_t *dst)
981 {
982 	int i;
983 	isp_put_hdr(isp, &src->req_header, &dst->req_header);
984 	ISP_IOXPUT_32(isp, src->req_handle, &dst->req_handle);
985 	ISP_IOXPUT_16(isp, src->req_target, &dst->req_target);
986 	ISP_IOXPUT_16(isp, src->req_scclun, &dst->req_scclun);
987 	ISP_IOXPUT_16(isp, src->req_flags,  &dst->req_flags);
988 	ISP_IOXPUT_8(isp, src->req_crn, &dst->req_crn);
989 	ISP_IOXPUT_8(isp, src->req_reserved, &dst->req_reserved);
990 	ISP_IOXPUT_16(isp, src->req_time, &dst->req_time);
991 	ISP_IOXPUT_16(isp, src->req_seg_count, &dst->req_seg_count);
992 	for (i = 0; i < ASIZE(src->req_cdb); i++) {
993 		ISP_IOXPUT_8(isp, src->req_cdb[i], &dst->req_cdb[i]);
994 	}
995 	ISP_IOXPUT_32(isp, src->req_totalcnt, &dst->req_totalcnt);
996 	for (i = 0; i < ISP_RQDSEG_T2; i++) {
997 		ISP_IOXPUT_32(isp, src->req_dataseg[i].ds_base, &dst->req_dataseg[i].ds_base);
998 		ISP_IOXPUT_32(isp, src->req_dataseg[i].ds_count, &dst->req_dataseg[i].ds_count);
999 	}
1000 }
1001 
1002 void
1003 isp_put_request_t3(ispsoftc_t *isp, ispreqt3_t *src, ispreqt3_t *dst)
1004 {
1005 	int i;
1006 	isp_put_hdr(isp, &src->req_header, &dst->req_header);
1007 	ISP_IOXPUT_32(isp, src->req_handle, &dst->req_handle);
1008 	ISP_IOXPUT_8(isp, src->req_lun_trn, &dst->req_lun_trn);
1009 	ISP_IOXPUT_8(isp, src->req_target, &dst->req_target);
1010 	ISP_IOXPUT_16(isp, src->req_scclun, &dst->req_scclun);
1011 	ISP_IOXPUT_16(isp, src->req_flags,  &dst->req_flags);
1012 	ISP_IOXPUT_8(isp, src->req_crn, &dst->req_crn);
1013 	ISP_IOXPUT_8(isp, src->req_reserved, &dst->req_reserved);
1014 	ISP_IOXPUT_16(isp, src->req_time, &dst->req_time);
1015 	ISP_IOXPUT_16(isp, src->req_seg_count, &dst->req_seg_count);
1016 	for (i = 0; i < ASIZE(src->req_cdb); i++) {
1017 		ISP_IOXPUT_8(isp, src->req_cdb[i], &dst->req_cdb[i]);
1018 	}
1019 	ISP_IOXPUT_32(isp, src->req_totalcnt, &dst->req_totalcnt);
1020 	for (i = 0; i < ISP_RQDSEG_T3; i++) {
1021 		ISP_IOXPUT_32(isp, src->req_dataseg[i].ds_base, &dst->req_dataseg[i].ds_base);
1022 		ISP_IOXPUT_32(isp, src->req_dataseg[i].ds_basehi, &dst->req_dataseg[i].ds_basehi);
1023 		ISP_IOXPUT_32(isp, src->req_dataseg[i].ds_count, &dst->req_dataseg[i].ds_count);
1024 	}
1025 }
1026 
1027 void
1028 isp_put_request_t3e(ispsoftc_t *isp, ispreqt3e_t *src, ispreqt3e_t *dst)
1029 {
1030 	int i;
1031 	isp_put_hdr(isp, &src->req_header, &dst->req_header);
1032 	ISP_IOXPUT_32(isp, src->req_handle, &dst->req_handle);
1033 	ISP_IOXPUT_16(isp, src->req_target, &dst->req_target);
1034 	ISP_IOXPUT_16(isp, src->req_scclun, &dst->req_scclun);
1035 	ISP_IOXPUT_16(isp, src->req_flags,  &dst->req_flags);
1036 	ISP_IOXPUT_8(isp, src->req_crn, &dst->req_crn);
1037 	ISP_IOXPUT_8(isp, src->req_reserved, &dst->req_reserved);
1038 	ISP_IOXPUT_16(isp, src->req_time, &dst->req_time);
1039 	ISP_IOXPUT_16(isp, src->req_seg_count, &dst->req_seg_count);
1040 	for (i = 0; i < ASIZE(src->req_cdb); i++) {
1041 		ISP_IOXPUT_8(isp, src->req_cdb[i], &dst->req_cdb[i]);
1042 	}
1043 	ISP_IOXPUT_32(isp, src->req_totalcnt, &dst->req_totalcnt);
1044 	for (i = 0; i < ISP_RQDSEG_T3; i++) {
1045 		ISP_IOXPUT_32(isp, src->req_dataseg[i].ds_base, &dst->req_dataseg[i].ds_base);
1046 		ISP_IOXPUT_32(isp, src->req_dataseg[i].ds_basehi, &dst->req_dataseg[i].ds_basehi);
1047 		ISP_IOXPUT_32(isp, src->req_dataseg[i].ds_count, &dst->req_dataseg[i].ds_count);
1048 	}
1049 }
1050 
1051 void
1052 isp_put_extended_request(ispsoftc_t *isp, ispextreq_t *src, ispextreq_t *dst)
1053 {
1054 	int i;
1055 	isp_put_hdr(isp, &src->req_header, &dst->req_header);
1056 	ISP_IOXPUT_32(isp, src->req_handle, &dst->req_handle);
1057 	if (ISP_IS_SBUS(isp)) {
1058 		ISP_IOXPUT_8(isp, src->req_lun_trn, &dst->req_target);
1059 		ISP_IOXPUT_8(isp, src->req_target, &dst->req_lun_trn);
1060 	} else {
1061 		ISP_IOXPUT_8(isp, src->req_lun_trn, &dst->req_lun_trn);
1062 		ISP_IOXPUT_8(isp, src->req_target, &dst->req_target);
1063 	}
1064 	ISP_IOXPUT_16(isp, src->req_cdblen, &dst->req_cdblen);
1065 	ISP_IOXPUT_16(isp, src->req_flags, &dst->req_flags);
1066 	ISP_IOXPUT_16(isp, src->req_time, &dst->req_time);
1067 	ISP_IOXPUT_16(isp, src->req_seg_count, &dst->req_seg_count);
1068 	for (i = 0; i < ASIZE(src->req_cdb); i++) {
1069 		ISP_IOXPUT_8(isp, src->req_cdb[i], &dst->req_cdb[i]);
1070 	}
1071 }
1072 
1073 void
1074 isp_put_request_t7(ispsoftc_t *isp, ispreqt7_t *src, ispreqt7_t *dst)
1075 {
1076 	int i;
1077 	uint32_t *a, *b;
1078 
1079 	isp_put_hdr(isp, &src->req_header, &dst->req_header);
1080 	ISP_IOXPUT_32(isp, src->req_handle, &dst->req_handle);
1081 	ISP_IOXPUT_16(isp, src->req_nphdl, &dst->req_nphdl);
1082 	ISP_IOXPUT_16(isp, src->req_time, &dst->req_time);
1083 	ISP_IOXPUT_16(isp, src->req_seg_count, &dst->req_seg_count);
1084 	ISP_IOXPUT_16(isp, src->req_reserved, &dst->req_reserved);
1085 	a = (uint32_t *) src->req_lun;
1086 	b = (uint32_t *) dst->req_lun;
1087 	for (i = 0; i < (ASIZE(src->req_lun) >> 2); i++ ) {
1088 		*b++ = ISP_SWAP32(isp, *a++);
1089 	}
1090 	ISP_IOXPUT_8(isp, src->req_alen_datadir, &dst->req_alen_datadir);
1091 	ISP_IOXPUT_8(isp, src->req_task_management, &dst->req_task_management);
1092 	ISP_IOXPUT_8(isp, src->req_task_attribute, &dst->req_task_attribute);
1093 	ISP_IOXPUT_8(isp, src->req_crn, &dst->req_crn);
1094 	a = (uint32_t *) src->req_cdb;
1095 	b = (uint32_t *) dst->req_cdb;
1096 	for (i = 0; i < (ASIZE(src->req_cdb) >> 2); i++) {
1097 		*b++ = ISP_SWAP32(isp, *a++);
1098 	}
1099 	ISP_IOXPUT_32(isp, src->req_dl, &dst->req_dl);
1100 	ISP_IOXPUT_16(isp, src->req_tidlo, &dst->req_tidlo);
1101 	ISP_IOXPUT_8(isp, src->req_tidhi, &dst->req_tidhi);
1102 	ISP_IOXPUT_8(isp, src->req_vpidx, &dst->req_vpidx);
1103 	ISP_IOXPUT_32(isp, src->req_dataseg.ds_base, &dst->req_dataseg.ds_base);
1104 	ISP_IOXPUT_32(isp, src->req_dataseg.ds_basehi, &dst->req_dataseg.ds_basehi);
1105 	ISP_IOXPUT_32(isp, src->req_dataseg.ds_count, &dst->req_dataseg.ds_count);
1106 }
1107 
1108 void
1109 isp_put_24xx_tmf(ispsoftc_t *isp, isp24xx_tmf_t *src, isp24xx_tmf_t *dst)
1110 {
1111 	int i;
1112 	uint32_t *a, *b;
1113 
1114 	isp_put_hdr(isp, &src->tmf_header, &dst->tmf_header);
1115 	ISP_IOXPUT_32(isp, src->tmf_handle, &dst->tmf_handle);
1116 	ISP_IOXPUT_16(isp, src->tmf_nphdl, &dst->tmf_nphdl);
1117 	ISP_IOXPUT_16(isp, src->tmf_delay, &dst->tmf_delay);
1118 	ISP_IOXPUT_16(isp, src->tmf_timeout, &dst->tmf_timeout);
1119 	for (i = 0; i < ASIZE(src->tmf_reserved0); i++) {
1120 		ISP_IOXPUT_8(isp, src->tmf_reserved0[i], &dst->tmf_reserved0[i]);
1121 	}
1122 	a = (uint32_t *) src->tmf_lun;
1123 	b = (uint32_t *) dst->tmf_lun;
1124 	for (i = 0; i < (ASIZE(src->tmf_lun) >> 2); i++ ) {
1125 		*b++ = ISP_SWAP32(isp, *a++);
1126 	}
1127 	ISP_IOXPUT_32(isp, src->tmf_flags, &dst->tmf_flags);
1128 	for (i = 0; i < ASIZE(src->tmf_reserved1); i++) {
1129 		ISP_IOXPUT_8(isp, src->tmf_reserved1[i], &dst->tmf_reserved1[i]);
1130 	}
1131 	ISP_IOXPUT_16(isp, src->tmf_tidlo, &dst->tmf_tidlo);
1132 	ISP_IOXPUT_8(isp, src->tmf_tidhi, &dst->tmf_tidhi);
1133 	ISP_IOXPUT_8(isp, src->tmf_vpidx, &dst->tmf_vpidx);
1134 	for (i = 0; i < ASIZE(src->tmf_reserved2); i++) {
1135 		ISP_IOXPUT_8(isp, src->tmf_reserved2[i], &dst->tmf_reserved2[i]);
1136 	}
1137 }
1138 
1139 void
1140 isp_put_24xx_abrt(ispsoftc_t *isp, isp24xx_abrt_t *src, isp24xx_abrt_t *dst)
1141 {
1142 	int i;
1143 	isp_put_hdr(isp, &src->abrt_header, &dst->abrt_header);
1144 	ISP_IOXPUT_32(isp, src->abrt_handle, &dst->abrt_handle);
1145 	ISP_IOXPUT_16(isp, src->abrt_nphdl, &dst->abrt_nphdl);
1146 	ISP_IOXPUT_16(isp, src->abrt_options, &dst->abrt_options);
1147 	ISP_IOXPUT_32(isp, src->abrt_cmd_handle, &dst->abrt_cmd_handle);
1148 	ISP_IOXPUT_16(isp, src->abrt_queue_number, &dst->abrt_queue_number);
1149 	for (i = 0; i < ASIZE(src->abrt_reserved); i++) {
1150 		ISP_IOXPUT_8(isp, src->abrt_reserved[i], &dst->abrt_reserved[i]);
1151 	}
1152 	ISP_IOXPUT_16(isp, src->abrt_tidlo, &dst->abrt_tidlo);
1153 	ISP_IOXPUT_8(isp, src->abrt_tidhi, &dst->abrt_tidhi);
1154 	ISP_IOXPUT_8(isp, src->abrt_vpidx, &dst->abrt_vpidx);
1155 	for (i = 0; i < ASIZE(src->abrt_reserved1); i++) {
1156 		ISP_IOXPUT_8(isp, src->abrt_reserved1[i], &dst->abrt_reserved1[i]);
1157 	}
1158 }
1159 
1160 void
1161 isp_put_cont_req(ispsoftc_t *isp, ispcontreq_t *src, ispcontreq_t *dst)
1162 {
1163 	int i;
1164 	isp_put_hdr(isp, &src->req_header, &dst->req_header);
1165 	for (i = 0; i < ISP_CDSEG; i++) {
1166 		ISP_IOXPUT_32(isp, src->req_dataseg[i].ds_base, &dst->req_dataseg[i].ds_base);
1167 		ISP_IOXPUT_32(isp, src->req_dataseg[i].ds_count, &dst->req_dataseg[i].ds_count);
1168 	}
1169 }
1170 
1171 void
1172 isp_put_cont64_req(ispsoftc_t *isp, ispcontreq64_t *src, ispcontreq64_t *dst)
1173 {
1174 	int i;
1175 	isp_put_hdr(isp, &src->req_header, &dst->req_header);
1176 	for (i = 0; i < ISP_CDSEG64; i++) {
1177 		ISP_IOXPUT_32(isp, src->req_dataseg[i].ds_base, &dst->req_dataseg[i].ds_base);
1178 		ISP_IOXPUT_32(isp, src->req_dataseg[i].ds_basehi, &dst->req_dataseg[i].ds_basehi);
1179 		ISP_IOXPUT_32(isp, src->req_dataseg[i].ds_count, &dst->req_dataseg[i].ds_count);
1180 	}
1181 }
1182 
1183 void
1184 isp_get_response(ispsoftc_t *isp, ispstatusreq_t *src, ispstatusreq_t *dst)
1185 {
1186 	int i;
1187 	isp_get_hdr(isp, &src->req_header, &dst->req_header);
1188 	ISP_IOXGET_32(isp, &src->req_handle, dst->req_handle);
1189 	ISP_IOXGET_16(isp, &src->req_scsi_status, dst->req_scsi_status);
1190 	ISP_IOXGET_16(isp, &src->req_completion_status, dst->req_completion_status);
1191 	ISP_IOXGET_16(isp, &src->req_state_flags, dst->req_state_flags);
1192 	ISP_IOXGET_16(isp, &src->req_status_flags, dst->req_status_flags);
1193 	ISP_IOXGET_16(isp, &src->req_time, dst->req_time);
1194 	ISP_IOXGET_16(isp, &src->req_sense_len, dst->req_sense_len);
1195 	ISP_IOXGET_32(isp, &src->req_resid, dst->req_resid);
1196 	for (i = 0; i < sizeof (src->req_response); i++) {
1197 		ISP_IOXGET_8(isp, &src->req_response[i], dst->req_response[i]);
1198 	}
1199 	for (i = 0; i < sizeof (src->req_sense_data); i++) {
1200 		ISP_IOXGET_8(isp, &src->req_sense_data[i], dst->req_sense_data[i]);
1201 	}
1202 }
1203 
1204 void
1205 isp_get_cont_response(ispsoftc_t *isp, ispstatus_cont_t *src, ispstatus_cont_t *dst)
1206 {
1207 	int i;
1208 	isp_get_hdr(isp, &src->req_header, &dst->req_header);
1209 	if (IS_24XX(isp)) {
1210 		uint32_t *a, *b;
1211 		a = (uint32_t *) src->req_sense_data;
1212 		b = (uint32_t *) dst->req_sense_data;
1213 		for (i = 0; i < (sizeof (src->req_sense_data) / sizeof (uint32_t)); i++) {
1214 			ISP_IOZGET_32(isp, a++, *b++);
1215 		}
1216 	} else {
1217 		for (i = 0; i < sizeof (src->req_sense_data); i++) {
1218 			ISP_IOXGET_8(isp, &src->req_sense_data[i], dst->req_sense_data[i]);
1219 		}
1220 	}
1221 }
1222 
1223 void
1224 isp_get_24xx_response(ispsoftc_t *isp, isp24xx_statusreq_t *src, isp24xx_statusreq_t *dst)
1225 {
1226 	int i;
1227 	uint32_t *s, *d;
1228 
1229 	isp_get_hdr(isp, &src->req_header, &dst->req_header);
1230 	ISP_IOXGET_32(isp, &src->req_handle, dst->req_handle);
1231 	ISP_IOXGET_16(isp, &src->req_completion_status, dst->req_completion_status);
1232 	ISP_IOXGET_16(isp, &src->req_oxid, dst->req_oxid);
1233 	ISP_IOXGET_32(isp, &src->req_resid, dst->req_resid);
1234 	ISP_IOXGET_16(isp, &src->req_reserved0, dst->req_reserved0);
1235 	ISP_IOXGET_16(isp, &src->req_state_flags, dst->req_state_flags);
1236 	ISP_IOXGET_16(isp, &src->req_retry_delay, dst->req_retry_delay);
1237 	ISP_IOXGET_16(isp, &src->req_scsi_status, dst->req_scsi_status);
1238 	ISP_IOXGET_32(isp, &src->req_fcp_residual, dst->req_fcp_residual);
1239 	ISP_IOXGET_32(isp, &src->req_sense_len, dst->req_sense_len);
1240 	ISP_IOXGET_32(isp, &src->req_response_len, dst->req_response_len);
1241 	s = (uint32_t *)src->req_rsp_sense;
1242 	d = (uint32_t *)dst->req_rsp_sense;
1243 	for (i = 0; i < (ASIZE(src->req_rsp_sense) >> 2); i++) {
1244 		d[i] = ISP_SWAP32(isp, s[i]);
1245 	}
1246 }
1247 
1248 void
1249 isp_get_24xx_abrt(ispsoftc_t *isp, isp24xx_abrt_t *src, isp24xx_abrt_t *dst)
1250 {
1251 	int i;
1252 	isp_get_hdr(isp, &src->abrt_header, &dst->abrt_header);
1253 	ISP_IOXGET_32(isp, &src->abrt_handle, dst->abrt_handle);
1254 	ISP_IOXGET_16(isp, &src->abrt_nphdl, dst->abrt_nphdl);
1255 	ISP_IOXGET_16(isp, &src->abrt_options, dst->abrt_options);
1256 	ISP_IOXGET_32(isp, &src->abrt_cmd_handle, dst->abrt_cmd_handle);
1257 	ISP_IOXGET_16(isp, &src->abrt_queue_number, dst->abrt_queue_number);
1258 	for (i = 0; i < ASIZE(src->abrt_reserved); i++) {
1259 		ISP_IOXGET_8(isp, &src->abrt_reserved[i], dst->abrt_reserved[i]);
1260 	}
1261 	ISP_IOXGET_16(isp, &src->abrt_tidlo, dst->abrt_tidlo);
1262 	ISP_IOXGET_8(isp, &src->abrt_tidhi, dst->abrt_tidhi);
1263 	ISP_IOXGET_8(isp, &src->abrt_vpidx, dst->abrt_vpidx);
1264 	for (i = 0; i < ASIZE(src->abrt_reserved1); i++) {
1265 		ISP_IOXGET_8(isp, &src->abrt_reserved1[i], dst->abrt_reserved1[i]);
1266 	}
1267 }
1268 
1269 
1270 void
1271 isp_get_rio1(ispsoftc_t *isp, isp_rio1_t *r1src, isp_rio1_t *r1dst)
1272 {
1273 	const int lim = sizeof (r1dst->req_handles) / sizeof (r1dst->req_handles[0]);
1274 	int i;
1275 	isp_get_hdr(isp, &r1src->req_header, &r1dst->req_header);
1276 	if (r1dst->req_header.rqs_seqno > lim) {
1277 		r1dst->req_header.rqs_seqno = lim;
1278 	}
1279 	for (i = 0; i < r1dst->req_header.rqs_seqno; i++) {
1280 		ISP_IOXGET_32(isp, &r1src->req_handles[i], r1dst->req_handles[i]);
1281 	}
1282 	while (i < lim) {
1283 		r1dst->req_handles[i++] = 0;
1284 	}
1285 }
1286 
1287 void
1288 isp_get_rio2(ispsoftc_t *isp, isp_rio2_t *r2src, isp_rio2_t *r2dst)
1289 {
1290 	const int lim = sizeof (r2dst->req_handles) / sizeof (r2dst->req_handles[0]);
1291 	int i;
1292 
1293 	isp_get_hdr(isp, &r2src->req_header, &r2dst->req_header);
1294 	if (r2dst->req_header.rqs_seqno > lim) {
1295 		r2dst->req_header.rqs_seqno = lim;
1296 	}
1297 	for (i = 0; i < r2dst->req_header.rqs_seqno; i++) {
1298 		ISP_IOXGET_16(isp, &r2src->req_handles[i], r2dst->req_handles[i]);
1299 	}
1300 	while (i < lim) {
1301 		r2dst->req_handles[i++] = 0;
1302 	}
1303 }
1304 
1305 void
1306 isp_put_icb(ispsoftc_t *isp, isp_icb_t *src, isp_icb_t *dst)
1307 {
1308 	int i;
1309 	if (ISP_IS_SBUS(isp)) {
1310 		ISP_IOXPUT_8(isp, src->icb_version, &dst->icb_reserved0);
1311 		ISP_IOXPUT_8(isp, src->icb_reserved0, &dst->icb_version);
1312 	} else {
1313 		ISP_IOXPUT_8(isp, src->icb_version, &dst->icb_version);
1314 		ISP_IOXPUT_8(isp, src->icb_reserved0, &dst->icb_reserved0);
1315 	}
1316 	ISP_IOXPUT_16(isp, src->icb_fwoptions, &dst->icb_fwoptions);
1317 	ISP_IOXPUT_16(isp, src->icb_maxfrmlen, &dst->icb_maxfrmlen);
1318 	ISP_IOXPUT_16(isp, src->icb_maxalloc, &dst->icb_maxalloc);
1319 	ISP_IOXPUT_16(isp, src->icb_execthrottle, &dst->icb_execthrottle);
1320 	if (ISP_IS_SBUS(isp)) {
1321 		ISP_IOXPUT_8(isp, src->icb_retry_count, &dst->icb_retry_delay);
1322 		ISP_IOXPUT_8(isp, src->icb_retry_delay, &dst->icb_retry_count);
1323 	} else {
1324 		ISP_IOXPUT_8(isp, src->icb_retry_count, &dst->icb_retry_count);
1325 		ISP_IOXPUT_8(isp, src->icb_retry_delay, &dst->icb_retry_delay);
1326 	}
1327 	for (i = 0; i < 8; i++) {
1328 		ISP_IOXPUT_8(isp, src->icb_portname[i], &dst->icb_portname[i]);
1329 	}
1330 	ISP_IOXPUT_16(isp, src->icb_hardaddr, &dst->icb_hardaddr);
1331 	if (ISP_IS_SBUS(isp)) {
1332 		ISP_IOXPUT_8(isp, src->icb_iqdevtype, &dst->icb_logintime);
1333 		ISP_IOXPUT_8(isp, src->icb_logintime, &dst->icb_iqdevtype);
1334 	} else {
1335 		ISP_IOXPUT_8(isp, src->icb_iqdevtype, &dst->icb_iqdevtype);
1336 		ISP_IOXPUT_8(isp, src->icb_logintime, &dst->icb_logintime);
1337 	}
1338 	for (i = 0; i < 8; i++) {
1339 		ISP_IOXPUT_8(isp, src->icb_nodename[i], &dst->icb_nodename[i]);
1340 	}
1341 	ISP_IOXPUT_16(isp, src->icb_rqstout, &dst->icb_rqstout);
1342 	ISP_IOXPUT_16(isp, src->icb_rspnsin, &dst->icb_rspnsin);
1343 	ISP_IOXPUT_16(isp, src->icb_rqstqlen, &dst->icb_rqstqlen);
1344 	ISP_IOXPUT_16(isp, src->icb_rsltqlen, &dst->icb_rsltqlen);
1345 	for (i = 0; i < 4; i++) {
1346 		ISP_IOXPUT_16(isp, src->icb_rqstaddr[i], &dst->icb_rqstaddr[i]);
1347 	}
1348 	for (i = 0; i < 4; i++) {
1349 		ISP_IOXPUT_16(isp, src->icb_respaddr[i], &dst->icb_respaddr[i]);
1350 	}
1351 	ISP_IOXPUT_16(isp, src->icb_lunenables, &dst->icb_lunenables);
1352 	if (ISP_IS_SBUS(isp)) {
1353 		ISP_IOXPUT_8(isp, src->icb_ccnt, &dst->icb_icnt);
1354 		ISP_IOXPUT_8(isp, src->icb_icnt, &dst->icb_ccnt);
1355 	} else {
1356 		ISP_IOXPUT_8(isp, src->icb_ccnt, &dst->icb_ccnt);
1357 		ISP_IOXPUT_8(isp, src->icb_icnt, &dst->icb_icnt);
1358 	}
1359 	ISP_IOXPUT_16(isp, src->icb_lunetimeout, &dst->icb_lunetimeout);
1360 	ISP_IOXPUT_16(isp, src->icb_reserved1, &dst->icb_reserved1);
1361 	ISP_IOXPUT_16(isp, src->icb_xfwoptions, &dst->icb_xfwoptions);
1362 	if (ISP_IS_SBUS(isp)) {
1363 		ISP_IOXPUT_8(isp, src->icb_racctimer, &dst->icb_idelaytimer);
1364 		ISP_IOXPUT_8(isp, src->icb_idelaytimer, &dst->icb_racctimer);
1365 	} else {
1366 		ISP_IOXPUT_8(isp, src->icb_racctimer, &dst->icb_racctimer);
1367 		ISP_IOXPUT_8(isp, src->icb_idelaytimer, &dst->icb_idelaytimer);
1368 	}
1369 	ISP_IOXPUT_16(isp, src->icb_zfwoptions, &dst->icb_zfwoptions);
1370 }
1371 
1372 void
1373 isp_put_icb_2400(ispsoftc_t *isp, isp_icb_2400_t *src, isp_icb_2400_t *dst)
1374 {
1375 	int i;
1376 	ISP_IOXPUT_16(isp, src->icb_version, &dst->icb_version);
1377 	ISP_IOXPUT_16(isp, src->icb_reserved0, &dst->icb_reserved0);
1378 	ISP_IOXPUT_16(isp, src->icb_maxfrmlen, &dst->icb_maxfrmlen);
1379 	ISP_IOXPUT_16(isp, src->icb_execthrottle, &dst->icb_execthrottle);
1380 	ISP_IOXPUT_16(isp, src->icb_xchgcnt, &dst->icb_xchgcnt);
1381 	ISP_IOXPUT_16(isp, src->icb_hardaddr, &dst->icb_hardaddr);
1382 	for (i = 0; i < 8; i++) {
1383 		ISP_IOXPUT_8(isp, src->icb_portname[i], &dst->icb_portname[i]);
1384 	}
1385 	for (i = 0; i < 8; i++) {
1386 		ISP_IOXPUT_8(isp, src->icb_nodename[i], &dst->icb_nodename[i]);
1387 	}
1388 	ISP_IOXPUT_16(isp, src->icb_rspnsin, &dst->icb_rspnsin);
1389 	ISP_IOXPUT_16(isp, src->icb_rqstout, &dst->icb_rqstout);
1390 	ISP_IOXPUT_16(isp, src->icb_retry_count, &dst->icb_retry_count);
1391 	ISP_IOXPUT_16(isp, src->icb_priout, &dst->icb_priout);
1392 	ISP_IOXPUT_16(isp, src->icb_rsltqlen, &dst->icb_rsltqlen);
1393 	ISP_IOXPUT_16(isp, src->icb_rqstqlen, &dst->icb_rqstqlen);
1394 	ISP_IOXPUT_16(isp, src->icb_ldn_nols, &dst->icb_ldn_nols);
1395 	ISP_IOXPUT_16(isp, src->icb_prqstqlen, &dst->icb_prqstqlen);
1396 	for (i = 0; i < 4; i++) {
1397 		ISP_IOXPUT_16(isp, src->icb_rqstaddr[i], &dst->icb_rqstaddr[i]);
1398 	}
1399 	for (i = 0; i < 4; i++) {
1400 		ISP_IOXPUT_16(isp, src->icb_respaddr[i], &dst->icb_respaddr[i]);
1401 	}
1402 	for (i = 0; i < 4; i++) {
1403 		ISP_IOXPUT_16(isp, src->icb_priaddr[i], &dst->icb_priaddr[i]);
1404 	}
1405 	for (i = 0; i < 4; i++) {
1406 		ISP_IOXPUT_16(isp, src->icb_reserved1[i], &dst->icb_reserved1[i]);
1407 	}
1408 	ISP_IOXPUT_16(isp, src->icb_atio_in, &dst->icb_atio_in);
1409 	ISP_IOXPUT_16(isp, src->icb_atioqlen, &dst->icb_atioqlen);
1410 	for (i = 0; i < 4; i++) {
1411 		ISP_IOXPUT_16(isp, src->icb_atioqaddr[i], &dst->icb_atioqaddr[i]);
1412 	}
1413 	ISP_IOXPUT_16(isp, src->icb_idelaytimer, &dst->icb_idelaytimer);
1414 	ISP_IOXPUT_16(isp, src->icb_logintime, &dst->icb_logintime);
1415 	ISP_IOXPUT_32(isp, src->icb_fwoptions1, &dst->icb_fwoptions1);
1416 	ISP_IOXPUT_32(isp, src->icb_fwoptions2, &dst->icb_fwoptions2);
1417 	ISP_IOXPUT_32(isp, src->icb_fwoptions3, &dst->icb_fwoptions3);
1418 	for (i = 0; i < 12; i++) {
1419 		ISP_IOXPUT_16(isp, src->icb_reserved2[i], &dst->icb_reserved2[i]);
1420 	}
1421 }
1422 
1423 void
1424 isp_put_icb_2400_vpinfo(ispsoftc_t *isp, isp_icb_2400_vpinfo_t *src, isp_icb_2400_vpinfo_t *dst)
1425 {
1426 	ISP_IOXPUT_16(isp, src->vp_count, &dst->vp_count);
1427 	ISP_IOXPUT_16(isp, src->vp_global_options, &dst->vp_global_options);
1428 }
1429 
1430 void
1431 isp_put_vp_port_info(ispsoftc_t *isp, vp_port_info_t *src, vp_port_info_t *dst)
1432 {
1433 	int i;
1434 	ISP_IOXPUT_16(isp, src->vp_port_status, &dst->vp_port_status);
1435 	ISP_IOXPUT_8(isp, src->vp_port_options, &dst->vp_port_options);
1436 	ISP_IOXPUT_8(isp, src->vp_port_loopid, &dst->vp_port_loopid);
1437 	for (i = 0; i < 8; i++) {
1438 		ISP_IOXPUT_8(isp, src->vp_port_portname[i], &dst->vp_port_portname[i]);
1439 	}
1440 	for (i = 0; i < 8; i++) {
1441 		ISP_IOXPUT_8(isp, src->vp_port_nodename[i], &dst->vp_port_nodename[i]);
1442 	}
1443 	/* we never *put* portid_lo/portid_hi */
1444 }
1445 
1446 void
1447 isp_get_vp_port_info(ispsoftc_t *isp, vp_port_info_t *src, vp_port_info_t *dst)
1448 {
1449 	int i;
1450 	ISP_IOXGET_16(isp, &src->vp_port_status, dst->vp_port_status);
1451 	ISP_IOXGET_8(isp, &src->vp_port_options, dst->vp_port_options);
1452 	ISP_IOXGET_8(isp, &src->vp_port_loopid, dst->vp_port_loopid);
1453 	for (i = 0; i < ASIZE(src->vp_port_portname); i++) {
1454 		ISP_IOXGET_8(isp, &src->vp_port_portname[i], dst->vp_port_portname[i]);
1455 	}
1456 	for (i = 0; i < ASIZE(src->vp_port_nodename); i++) {
1457 		ISP_IOXGET_8(isp, &src->vp_port_nodename[i], dst->vp_port_nodename[i]);
1458 	}
1459 	ISP_IOXGET_16(isp, &src->vp_port_portid_lo, dst->vp_port_portid_lo);
1460 	ISP_IOXGET_16(isp, &src->vp_port_portid_hi, dst->vp_port_portid_hi);
1461 }
1462 
1463 void
1464 isp_put_vp_ctrl_info(ispsoftc_t *isp, vp_ctrl_info_t *src, vp_ctrl_info_t *dst)
1465 {
1466 	int i;
1467 	isp_put_hdr(isp, &src->vp_ctrl_hdr, &dst->vp_ctrl_hdr);
1468 	ISP_IOXPUT_32(isp, src->vp_ctrl_handle, &dst->vp_ctrl_handle);
1469 	ISP_IOXPUT_16(isp, src->vp_ctrl_index_fail, &dst->vp_ctrl_index_fail);
1470 	ISP_IOXPUT_16(isp, src->vp_ctrl_status, &dst->vp_ctrl_status);
1471 	ISP_IOXPUT_16(isp, src->vp_ctrl_command, &dst->vp_ctrl_command);
1472 	ISP_IOXPUT_16(isp, src->vp_ctrl_vp_count, &dst->vp_ctrl_vp_count);
1473 	for (i = 0; i < ASIZE(src->vp_ctrl_idmap); i++) {
1474 		ISP_IOXPUT_16(isp, src->vp_ctrl_idmap[i], &dst->vp_ctrl_idmap[i]);
1475 	}
1476 	for (i = 0; i < ASIZE(src->vp_ctrl_reserved); i++) {
1477 		ISP_IOXPUT_16(isp, src->vp_ctrl_reserved[i], &dst->vp_ctrl_reserved[i]);
1478 	}
1479 	ISP_IOXPUT_16(isp, src->vp_ctrl_fcf_index, &dst->vp_ctrl_fcf_index);
1480 }
1481 
1482 void
1483 isp_get_vp_ctrl_info(ispsoftc_t *isp, vp_ctrl_info_t *src, vp_ctrl_info_t *dst)
1484 {
1485 	int i;
1486 	isp_get_hdr(isp, &src->vp_ctrl_hdr, &dst->vp_ctrl_hdr);
1487 	ISP_IOXGET_32(isp, &src->vp_ctrl_handle, dst->vp_ctrl_handle);
1488 	ISP_IOXGET_16(isp, &src->vp_ctrl_index_fail, dst->vp_ctrl_index_fail);
1489 	ISP_IOXGET_16(isp, &src->vp_ctrl_status, dst->vp_ctrl_status);
1490 	ISP_IOXGET_16(isp, &src->vp_ctrl_command, dst->vp_ctrl_command);
1491 	ISP_IOXGET_16(isp, &src->vp_ctrl_vp_count, dst->vp_ctrl_vp_count);
1492 	for (i = 0; i < ASIZE(src->vp_ctrl_idmap); i++) {
1493 		ISP_IOXGET_16(isp, &src->vp_ctrl_idmap[i], dst->vp_ctrl_idmap[i]);
1494 	}
1495 	for (i = 0; i < ASIZE(src->vp_ctrl_reserved); i++) {
1496 		ISP_IOXGET_16(isp, &src->vp_ctrl_reserved[i], dst->vp_ctrl_reserved[i]);
1497 	}
1498 	ISP_IOXGET_16(isp, &src->vp_ctrl_fcf_index, dst->vp_ctrl_fcf_index);
1499 }
1500 
1501 void
1502 isp_put_vp_modify(ispsoftc_t *isp, vp_modify_t *src, vp_modify_t *dst)
1503 {
1504 	int i, j;
1505 	isp_put_hdr(isp, &src->vp_mod_hdr, &dst->vp_mod_hdr);
1506 	ISP_IOXPUT_32(isp, src->vp_mod_hdl, &dst->vp_mod_hdl);
1507 	ISP_IOXPUT_16(isp, src->vp_mod_reserved0, &dst->vp_mod_reserved0);
1508 	ISP_IOXPUT_16(isp, src->vp_mod_status, &dst->vp_mod_status);
1509 	ISP_IOXPUT_8(isp, src->vp_mod_cmd, &dst->vp_mod_cmd);
1510 	ISP_IOXPUT_8(isp, src->vp_mod_cnt, &dst->vp_mod_cnt);
1511 	ISP_IOXPUT_8(isp, src->vp_mod_idx0, &dst->vp_mod_idx0);
1512 	ISP_IOXPUT_8(isp, src->vp_mod_idx1, &dst->vp_mod_idx1);
1513 	for (i = 0; i < ASIZE(src->vp_mod_ports); i++) {
1514 		ISP_IOXPUT_8(isp, src->vp_mod_ports[i].options, &dst->vp_mod_ports[i].options);
1515 		ISP_IOXPUT_8(isp, src->vp_mod_ports[i].loopid, &dst->vp_mod_ports[i].loopid);
1516 		ISP_IOXPUT_16(isp, src->vp_mod_ports[i].reserved1, &dst->vp_mod_ports[i].reserved1);
1517 		for (j = 0; j < ASIZE(src->vp_mod_ports[i].wwpn); j++) {
1518 			ISP_IOXPUT_8(isp, src->vp_mod_ports[i].wwpn[j], &dst->vp_mod_ports[i].wwpn[j]);
1519 		}
1520 		for (j = 0; j < ASIZE(src->vp_mod_ports[i].wwnn); j++) {
1521 			ISP_IOXPUT_8(isp, src->vp_mod_ports[i].wwnn[j], &dst->vp_mod_ports[i].wwnn[j]);
1522 		}
1523 	}
1524 	for (i = 0; i < ASIZE(src->vp_mod_reserved2); i++) {
1525 		ISP_IOXPUT_8(isp, src->vp_mod_reserved2[i], &dst->vp_mod_reserved2[i]);
1526 	}
1527 }
1528 
1529 void
1530 isp_get_vp_modify(ispsoftc_t *isp, vp_modify_t *src, vp_modify_t *dst)
1531 {
1532 	int i, j;
1533 	isp_get_hdr(isp, &src->vp_mod_hdr, &dst->vp_mod_hdr);
1534 	ISP_IOXGET_32(isp, &src->vp_mod_hdl, dst->vp_mod_hdl);
1535 	ISP_IOXGET_16(isp, &src->vp_mod_reserved0, dst->vp_mod_reserved0);
1536 	ISP_IOXGET_16(isp, &src->vp_mod_status, dst->vp_mod_status);
1537 	ISP_IOXGET_8(isp, &src->vp_mod_cmd, dst->vp_mod_cmd);
1538 	ISP_IOXGET_8(isp, &src->vp_mod_cnt, dst->vp_mod_cnt);
1539 	ISP_IOXGET_8(isp, &src->vp_mod_idx0, dst->vp_mod_idx0);
1540 	ISP_IOXGET_8(isp, &src->vp_mod_idx1, dst->vp_mod_idx1);
1541 	for (i = 0; i < ASIZE(src->vp_mod_ports); i++) {
1542 		ISP_IOXGET_8(isp, &src->vp_mod_ports[i].options, dst->vp_mod_ports[i].options);
1543 		ISP_IOXGET_8(isp, &src->vp_mod_ports[i].loopid, dst->vp_mod_ports[i].loopid);
1544 		ISP_IOXGET_16(isp, &src->vp_mod_ports[i].reserved1, dst->vp_mod_ports[i].reserved1);
1545 		for (j = 0; j < ASIZE(src->vp_mod_ports[i].wwpn); j++) {
1546 			ISP_IOXGET_8(isp, &src->vp_mod_ports[i].wwpn[j], dst->vp_mod_ports[i].wwpn[j]);
1547 		}
1548 		for (j = 0; j < ASIZE(src->vp_mod_ports[i].wwnn); j++) {
1549 			ISP_IOXGET_8(isp, &src->vp_mod_ports[i].wwnn[j], dst->vp_mod_ports[i].wwnn[j]);
1550 		}
1551 	}
1552 	for (i = 0; i < ASIZE(src->vp_mod_reserved2); i++) {
1553 		ISP_IOXGET_8(isp, &src->vp_mod_reserved2[i], dst->vp_mod_reserved2[i]);
1554 	}
1555 }
1556 
1557 void
1558 isp_get_pdb_21xx(ispsoftc_t *isp, isp_pdb_21xx_t *src, isp_pdb_21xx_t *dst)
1559 {
1560 	int i;
1561 	ISP_IOXGET_16(isp, &src->pdb_options, dst->pdb_options);
1562         ISP_IOXGET_8(isp, &src->pdb_mstate, dst->pdb_mstate);
1563         ISP_IOXGET_8(isp, &src->pdb_sstate, dst->pdb_sstate);
1564 	for (i = 0; i < 4; i++) {
1565 		ISP_IOXGET_8(isp, &src->pdb_hardaddr_bits[i], dst->pdb_hardaddr_bits[i]);
1566 	}
1567 	for (i = 0; i < 4; i++) {
1568 		ISP_IOXGET_8(isp, &src->pdb_portid_bits[i], dst->pdb_portid_bits[i]);
1569 	}
1570 	for (i = 0; i < 8; i++) {
1571 		ISP_IOXGET_8(isp, &src->pdb_nodename[i], dst->pdb_nodename[i]);
1572 	}
1573 	for (i = 0; i < 8; i++) {
1574 		ISP_IOXGET_8(isp, &src->pdb_portname[i], dst->pdb_portname[i]);
1575 	}
1576 	ISP_IOXGET_16(isp, &src->pdb_execthrottle, dst->pdb_execthrottle);
1577 	ISP_IOXGET_16(isp, &src->pdb_exec_count, dst->pdb_exec_count);
1578 	ISP_IOXGET_8(isp, &src->pdb_retry_count, dst->pdb_retry_count);
1579 	ISP_IOXGET_8(isp, &src->pdb_retry_delay, dst->pdb_retry_delay);
1580 	ISP_IOXGET_16(isp, &src->pdb_resalloc, dst->pdb_resalloc);
1581 	ISP_IOXGET_16(isp, &src->pdb_curalloc, dst->pdb_curalloc);
1582 	ISP_IOXGET_16(isp, &src->pdb_qhead, dst->pdb_qhead);
1583 	ISP_IOXGET_16(isp, &src->pdb_qtail, dst->pdb_qtail);
1584 	ISP_IOXGET_16(isp, &src->pdb_tl_next, dst->pdb_tl_next);
1585 	ISP_IOXGET_16(isp, &src->pdb_tl_last, dst->pdb_tl_last);
1586 	ISP_IOXGET_16(isp, &src->pdb_features, dst->pdb_features);
1587 	ISP_IOXGET_16(isp, &src->pdb_pconcurrnt, dst->pdb_pconcurrnt);
1588 	ISP_IOXGET_16(isp, &src->pdb_roi, dst->pdb_roi);
1589 	ISP_IOXGET_8(isp, &src->pdb_target, dst->pdb_target);
1590 	ISP_IOXGET_8(isp, &src->pdb_initiator, dst->pdb_initiator);
1591 	ISP_IOXGET_16(isp, &src->pdb_rdsiz, dst->pdb_rdsiz);
1592 	ISP_IOXGET_16(isp, &src->pdb_ncseq, dst->pdb_ncseq);
1593 	ISP_IOXGET_16(isp, &src->pdb_noseq, dst->pdb_noseq);
1594 	ISP_IOXGET_16(isp, &src->pdb_labrtflg, dst->pdb_labrtflg);
1595 	ISP_IOXGET_16(isp, &src->pdb_lstopflg, dst->pdb_lstopflg);
1596 	ISP_IOXGET_16(isp, &src->pdb_sqhead, dst->pdb_sqhead);
1597 	ISP_IOXGET_16(isp, &src->pdb_sqtail, dst->pdb_sqtail);
1598 	ISP_IOXGET_16(isp, &src->pdb_ptimer, dst->pdb_ptimer);
1599 	ISP_IOXGET_16(isp, &src->pdb_nxt_seqid, dst->pdb_nxt_seqid);
1600 	ISP_IOXGET_16(isp, &src->pdb_fcount, dst->pdb_fcount);
1601 	ISP_IOXGET_16(isp, &src->pdb_prli_len, dst->pdb_prli_len);
1602 	ISP_IOXGET_16(isp, &src->pdb_prli_svc0, dst->pdb_prli_svc0);
1603 	ISP_IOXGET_16(isp, &src->pdb_prli_svc3, dst->pdb_prli_svc3);
1604 	ISP_IOXGET_16(isp, &src->pdb_loopid, dst->pdb_loopid);
1605 	ISP_IOXGET_16(isp, &src->pdb_il_ptr, dst->pdb_il_ptr);
1606 	ISP_IOXGET_16(isp, &src->pdb_sl_ptr, dst->pdb_sl_ptr);
1607 }
1608 
1609 void
1610 isp_get_pdb_24xx(ispsoftc_t *isp, isp_pdb_24xx_t *src, isp_pdb_24xx_t *dst)
1611 {
1612 	int i;
1613 	ISP_IOXGET_16(isp, &src->pdb_flags, dst->pdb_flags);
1614         ISP_IOXGET_8(isp, &src->pdb_curstate, dst->pdb_curstate);
1615         ISP_IOXGET_8(isp, &src->pdb_laststate, dst->pdb_laststate);
1616 	for (i = 0; i < 4; i++) {
1617 		ISP_IOXGET_8(isp, &src->pdb_hardaddr_bits[i], dst->pdb_hardaddr_bits[i]);
1618 	}
1619 	for (i = 0; i < 4; i++) {
1620 		ISP_IOXGET_8(isp, &src->pdb_portid_bits[i], dst->pdb_portid_bits[i]);
1621 	}
1622 	ISP_IOXGET_16(isp, &src->pdb_retry_timer, dst->pdb_retry_timer);
1623 	ISP_IOXGET_16(isp, &src->pdb_handle, dst->pdb_handle);
1624 	ISP_IOXGET_16(isp, &src->pdb_rcv_dsize, dst->pdb_rcv_dsize);
1625 	ISP_IOXGET_16(isp, &src->pdb_reserved0, dst->pdb_reserved0);
1626 	ISP_IOXGET_16(isp, &src->pdb_prli_svc0, dst->pdb_prli_svc0);
1627 	ISP_IOXGET_16(isp, &src->pdb_prli_svc3, dst->pdb_prli_svc3);
1628 	for (i = 0; i < 8; i++) {
1629 		ISP_IOXGET_8(isp, &src->pdb_nodename[i], dst->pdb_nodename[i]);
1630 	}
1631 	for (i = 0; i < 8; i++) {
1632 		ISP_IOXGET_8(isp, &src->pdb_portname[i], dst->pdb_portname[i]);
1633 	}
1634 	for (i = 0; i < 24; i++) {
1635 		ISP_IOXGET_8(isp, &src->pdb_reserved1[i], dst->pdb_reserved1[i]);
1636 	}
1637 }
1638 
1639 void
1640 isp_get_pnhle_21xx(ispsoftc_t *isp, isp_pnhle_21xx_t *src, isp_pnhle_21xx_t *dst)
1641 {
1642 
1643 	ISP_IOXGET_16(isp, &src->pnhle_port_id_lo, dst->pnhle_port_id_lo);
1644 	ISP_IOXGET_16(isp, &src->pnhle_port_id_hi_handle, dst->pnhle_port_id_hi_handle);
1645 }
1646 
1647 void
1648 isp_get_pnhle_23xx(ispsoftc_t *isp, isp_pnhle_23xx_t *src, isp_pnhle_23xx_t *dst)
1649 {
1650 
1651 	ISP_IOXGET_16(isp, &src->pnhle_port_id_lo, dst->pnhle_port_id_lo);
1652 	ISP_IOXGET_16(isp, &src->pnhle_port_id_hi, dst->pnhle_port_id_hi);
1653 	ISP_IOXGET_16(isp, &src->pnhle_handle, dst->pnhle_handle);
1654 }
1655 
1656 void
1657 isp_get_pnhle_24xx(ispsoftc_t *isp, isp_pnhle_24xx_t *src, isp_pnhle_24xx_t *dst)
1658 {
1659 
1660 	ISP_IOXGET_16(isp, &src->pnhle_port_id_lo, dst->pnhle_port_id_lo);
1661 	ISP_IOXGET_16(isp, &src->pnhle_port_id_hi, dst->pnhle_port_id_hi);
1662 	ISP_IOXGET_16(isp, &src->pnhle_handle, dst->pnhle_handle);
1663 	ISP_IOXGET_16(isp, &src->pnhle_reserved, dst->pnhle_reserved);
1664 }
1665 
1666 void
1667 isp_get_pnnle(ispsoftc_t *isp, isp_pnnle_t *src, isp_pnnle_t *dst)
1668 {
1669 	int i;
1670 
1671 	for (i = 0; i < 8; i++)
1672 		ISP_IOXGET_8(isp, &src->pnnle_name[i], dst->pnnle_name[i]);
1673 	ISP_IOXGET_16(isp, &src->pnnle_handle, dst->pnnle_handle);
1674 	ISP_IOXGET_16(isp, &src->pnnle_reserved, dst->pnnle_reserved);
1675 }
1676 
1677 /*
1678  * PLOGI/LOGO IOCB canonicalization
1679  */
1680 
1681 void
1682 isp_get_plogx(ispsoftc_t *isp, isp_plogx_t *src, isp_plogx_t *dst)
1683 {
1684 	int i;
1685 	isp_get_hdr(isp, &src->plogx_header, &dst->plogx_header);
1686 	ISP_IOXGET_32(isp, &src->plogx_handle, dst->plogx_handle);
1687 	ISP_IOXGET_16(isp, &src->plogx_status, dst->plogx_status);
1688 	ISP_IOXGET_16(isp, &src->plogx_nphdl, dst->plogx_nphdl);
1689 	ISP_IOXGET_16(isp, &src->plogx_flags, dst->plogx_flags);
1690 	ISP_IOXGET_16(isp, &src->plogx_vphdl, dst->plogx_vphdl);
1691 	ISP_IOXGET_16(isp, &src->plogx_portlo, dst->plogx_portlo);
1692 	ISP_IOXGET_16(isp, &src->plogx_rspsz_porthi, dst->plogx_rspsz_porthi);
1693 	for (i = 0; i < 11; i++) {
1694 		ISP_IOXGET_16(isp, &src->plogx_ioparm[i].lo16, dst->plogx_ioparm[i].lo16);
1695 		ISP_IOXGET_16(isp, &src->plogx_ioparm[i].hi16, dst->plogx_ioparm[i].hi16);
1696 	}
1697 }
1698 
1699 void
1700 isp_put_plogx(ispsoftc_t *isp, isp_plogx_t *src, isp_plogx_t *dst)
1701 {
1702 	int i;
1703 	isp_put_hdr(isp, &src->plogx_header, &dst->plogx_header);
1704 	ISP_IOXPUT_32(isp, src->plogx_handle, &dst->plogx_handle);
1705 	ISP_IOXPUT_16(isp, src->plogx_status, &dst->plogx_status);
1706 	ISP_IOXPUT_16(isp, src->plogx_nphdl, &dst->plogx_nphdl);
1707 	ISP_IOXPUT_16(isp, src->plogx_flags, &dst->plogx_flags);
1708 	ISP_IOXPUT_16(isp, src->plogx_vphdl, &dst->plogx_vphdl);
1709 	ISP_IOXPUT_16(isp, src->plogx_portlo, &dst->plogx_portlo);
1710 	ISP_IOXPUT_16(isp, src->plogx_rspsz_porthi, &dst->plogx_rspsz_porthi);
1711 	for (i = 0; i < 11; i++) {
1712 		ISP_IOXPUT_16(isp, src->plogx_ioparm[i].lo16, &dst->plogx_ioparm[i].lo16);
1713 		ISP_IOXPUT_16(isp, src->plogx_ioparm[i].hi16, &dst->plogx_ioparm[i].hi16);
1714 	}
1715 }
1716 
1717 /*
1718  * Report ID canonicalization
1719  */
1720 void
1721 isp_get_ridacq(ispsoftc_t *isp, isp_ridacq_t *src, isp_ridacq_t *dst)
1722 {
1723 	int i;
1724 	isp_get_hdr(isp, &src->ridacq_hdr, &dst->ridacq_hdr);
1725 	ISP_IOXGET_32(isp, &src->ridacq_handle, dst->ridacq_handle);
1726 	ISP_IOXGET_8(isp, &src->ridacq_vp_acquired, dst->ridacq_vp_acquired);
1727 	ISP_IOXGET_8(isp, &src->ridacq_vp_setup, dst->ridacq_vp_setup);
1728 	ISP_IOXGET_8(isp, &src->ridacq_vp_index, dst->ridacq_vp_index);
1729 	ISP_IOXGET_8(isp, &src->ridacq_vp_status, dst->ridacq_vp_status);
1730 	ISP_IOXGET_16(isp, &src->ridacq_vp_port_lo, dst->ridacq_vp_port_lo);
1731 	ISP_IOXGET_8(isp, &src->ridacq_vp_port_hi, dst->ridacq_vp_port_hi);
1732 	ISP_IOXGET_8(isp, &src->ridacq_format, dst->ridacq_format);
1733 	for (i = 0; i < sizeof (src->ridacq_map) / sizeof (src->ridacq_map[0]); i++) {
1734 		ISP_IOXGET_16(isp, &src->ridacq_map[i], dst->ridacq_map[i]);
1735 	}
1736 	for (i = 0; i < sizeof (src->ridacq_reserved1) / sizeof (src->ridacq_reserved1[0]); i++) {
1737 		ISP_IOXGET_16(isp, &src->ridacq_reserved1[i], dst->ridacq_reserved1[i]);
1738 	}
1739 }
1740 
1741 
1742 /*
1743  * CT Passthru canonicalization
1744  */
1745 void
1746 isp_get_ct_pt(ispsoftc_t *isp, isp_ct_pt_t *src, isp_ct_pt_t *dst)
1747 {
1748 	int i;
1749 
1750 	isp_get_hdr(isp, &src->ctp_header, &dst->ctp_header);
1751 	ISP_IOXGET_32(isp, &src->ctp_handle, dst->ctp_handle);
1752 	ISP_IOXGET_16(isp, &src->ctp_status, dst->ctp_status);
1753 	ISP_IOXGET_16(isp, &src->ctp_nphdl, dst->ctp_nphdl);
1754 	ISP_IOXGET_16(isp, &src->ctp_cmd_cnt, dst->ctp_cmd_cnt);
1755 	ISP_IOXGET_8(isp, &src->ctp_vpidx, dst->ctp_vpidx);
1756 	ISP_IOXGET_8(isp, &src->ctp_reserved0, dst->ctp_reserved0);
1757 	ISP_IOXGET_16(isp, &src->ctp_time, dst->ctp_time);
1758 	ISP_IOXGET_16(isp, &src->ctp_reserved1, dst->ctp_reserved1);
1759 	ISP_IOXGET_16(isp, &src->ctp_rsp_cnt, dst->ctp_rsp_cnt);
1760 	for (i = 0; i < 5; i++) {
1761 		ISP_IOXGET_16(isp, &src->ctp_reserved2[i], dst->ctp_reserved2[i]);
1762 	}
1763 	ISP_IOXGET_32(isp, &src->ctp_rsp_bcnt, dst->ctp_rsp_bcnt);
1764 	ISP_IOXGET_32(isp, &src->ctp_cmd_bcnt, dst->ctp_cmd_bcnt);
1765 	for (i = 0; i < 2; i++) {
1766 		ISP_IOXGET_32(isp, &src->ctp_dataseg[i].ds_base, dst->ctp_dataseg[i].ds_base);
1767 		ISP_IOXGET_32(isp, &src->ctp_dataseg[i].ds_basehi, dst->ctp_dataseg[i].ds_basehi);
1768 		ISP_IOXGET_32(isp, &src->ctp_dataseg[i].ds_count, dst->ctp_dataseg[i].ds_count);
1769 	}
1770 }
1771 
1772 void
1773 isp_get_ms(ispsoftc_t *isp, isp_ms_t *src, isp_ms_t *dst)
1774 {
1775 	int i;
1776 
1777 	isp_get_hdr(isp, &src->ms_header, &dst->ms_header);
1778 	ISP_IOXGET_32(isp, &src->ms_handle, dst->ms_handle);
1779 	ISP_IOXGET_16(isp, &src->ms_nphdl, dst->ms_nphdl);
1780 	ISP_IOXGET_16(isp, &src->ms_status, dst->ms_status);
1781 	ISP_IOXGET_16(isp, &src->ms_flags, dst->ms_flags);
1782 	ISP_IOXGET_16(isp, &src->ms_reserved1, dst->ms_reserved1);
1783 	ISP_IOXGET_16(isp, &src->ms_time, dst->ms_time);
1784 	ISP_IOXGET_16(isp, &src->ms_cmd_cnt, dst->ms_cmd_cnt);
1785 	ISP_IOXGET_16(isp, &src->ms_tot_cnt, dst->ms_tot_cnt);
1786 	ISP_IOXGET_8(isp, &src->ms_type, dst->ms_type);
1787 	ISP_IOXGET_8(isp, &src->ms_r_ctl, dst->ms_r_ctl);
1788 	ISP_IOXGET_16(isp, &src->ms_rxid, dst->ms_rxid);
1789 	ISP_IOXGET_16(isp, &src->ms_reserved2, dst->ms_reserved2);
1790 	ISP_IOXGET_32(isp, &src->ms_rsp_bcnt, dst->ms_rsp_bcnt);
1791 	ISP_IOXGET_32(isp, &src->ms_cmd_bcnt, dst->ms_cmd_bcnt);
1792 	for (i = 0; i < 2; i++) {
1793 		ISP_IOXGET_32(isp, &src->ms_dataseg[i].ds_base, dst->ms_dataseg[i].ds_base);
1794 		ISP_IOXGET_32(isp, &src->ms_dataseg[i].ds_basehi, dst->ms_dataseg[i].ds_basehi);
1795 		ISP_IOXGET_32(isp, &src->ms_dataseg[i].ds_count, dst->ms_dataseg[i].ds_count);
1796 	}
1797 }
1798 
1799 void
1800 isp_put_ct_pt(ispsoftc_t *isp, isp_ct_pt_t *src, isp_ct_pt_t *dst)
1801 {
1802 	int i;
1803 
1804 	isp_put_hdr(isp, &src->ctp_header, &dst->ctp_header);
1805 	ISP_IOXPUT_32(isp, src->ctp_handle, &dst->ctp_handle);
1806 	ISP_IOXPUT_16(isp, src->ctp_status, &dst->ctp_status);
1807 	ISP_IOXPUT_16(isp, src->ctp_nphdl, &dst->ctp_nphdl);
1808 	ISP_IOXPUT_16(isp, src->ctp_cmd_cnt, &dst->ctp_cmd_cnt);
1809 	ISP_IOXPUT_8(isp, src->ctp_vpidx, &dst->ctp_vpidx);
1810 	ISP_IOXPUT_8(isp, src->ctp_reserved0, &dst->ctp_reserved0);
1811 	ISP_IOXPUT_16(isp, src->ctp_time, &dst->ctp_time);
1812 	ISP_IOXPUT_16(isp, src->ctp_reserved1, &dst->ctp_reserved1);
1813 	ISP_IOXPUT_16(isp, src->ctp_rsp_cnt, &dst->ctp_rsp_cnt);
1814 	for (i = 0; i < 5; i++) {
1815 		ISP_IOXPUT_16(isp, src->ctp_reserved2[i], &dst->ctp_reserved2[i]);
1816 	}
1817 	ISP_IOXPUT_32(isp, src->ctp_rsp_bcnt, &dst->ctp_rsp_bcnt);
1818 	ISP_IOXPUT_32(isp, src->ctp_cmd_bcnt, &dst->ctp_cmd_bcnt);
1819 	for (i = 0; i < 2; i++) {
1820 		ISP_IOXPUT_32(isp, src->ctp_dataseg[i].ds_base, &dst->ctp_dataseg[i].ds_base);
1821 		ISP_IOXPUT_32(isp, src->ctp_dataseg[i].ds_basehi, &dst->ctp_dataseg[i].ds_basehi);
1822 		ISP_IOXPUT_32(isp, src->ctp_dataseg[i].ds_count, &dst->ctp_dataseg[i].ds_count);
1823 	}
1824 }
1825 
1826 void
1827 isp_put_ms(ispsoftc_t *isp, isp_ms_t *src, isp_ms_t *dst)
1828 {
1829 	int i;
1830 
1831 	isp_put_hdr(isp, &src->ms_header, &dst->ms_header);
1832 	ISP_IOXPUT_32(isp, src->ms_handle, &dst->ms_handle);
1833 	ISP_IOXPUT_16(isp, src->ms_nphdl, &dst->ms_nphdl);
1834 	ISP_IOXPUT_16(isp, src->ms_status, &dst->ms_status);
1835 	ISP_IOXPUT_16(isp, src->ms_flags, &dst->ms_flags);
1836 	ISP_IOXPUT_16(isp, src->ms_reserved1, &dst->ms_reserved1);
1837 	ISP_IOXPUT_16(isp, src->ms_time, &dst->ms_time);
1838 	ISP_IOXPUT_16(isp, src->ms_cmd_cnt, &dst->ms_cmd_cnt);
1839 	ISP_IOXPUT_16(isp, src->ms_tot_cnt, &dst->ms_tot_cnt);
1840 	ISP_IOXPUT_8(isp, src->ms_type, &dst->ms_type);
1841 	ISP_IOXPUT_8(isp, src->ms_r_ctl, &dst->ms_r_ctl);
1842 	ISP_IOXPUT_16(isp, src->ms_rxid, &dst->ms_rxid);
1843 	ISP_IOXPUT_16(isp, src->ms_reserved2, &dst->ms_reserved2);
1844 	ISP_IOXPUT_32(isp, src->ms_rsp_bcnt, &dst->ms_rsp_bcnt);
1845 	ISP_IOXPUT_32(isp, src->ms_cmd_bcnt, &dst->ms_cmd_bcnt);
1846 	for (i = 0; i < 2; i++) {
1847 		ISP_IOXPUT_32(isp, src->ms_dataseg[i].ds_base, &dst->ms_dataseg[i].ds_base);
1848 		ISP_IOXPUT_32(isp, src->ms_dataseg[i].ds_basehi, &dst->ms_dataseg[i].ds_basehi);
1849 		ISP_IOXPUT_32(isp, src->ms_dataseg[i].ds_count, &dst->ms_dataseg[i].ds_count);
1850 	}
1851 }
1852 
1853 /*
1854  * Generic SNS request - not particularly useful since the per-command data
1855  * isn't always 16 bit words.
1856  */
1857 void
1858 isp_put_sns_request(ispsoftc_t *isp, sns_screq_t *src, sns_screq_t *dst)
1859 {
1860 	int i, nw = (int) src->snscb_sblen;
1861 	ISP_IOXPUT_16(isp, src->snscb_rblen, &dst->snscb_rblen);
1862 	for (i = 0; i < 4; i++) {
1863 		ISP_IOXPUT_16(isp, src->snscb_addr[i], &dst->snscb_addr[i]);
1864 	}
1865 	ISP_IOXPUT_16(isp, src->snscb_sblen, &dst->snscb_sblen);
1866 	for (i = 0; i < nw; i++) {
1867 		ISP_IOXPUT_16(isp, src->snscb_data[i], &dst->snscb_data[i]);
1868 	}
1869 }
1870 
1871 void
1872 isp_put_gid_ft_request(ispsoftc_t *isp, sns_gid_ft_req_t *src, sns_gid_ft_req_t *dst)
1873 {
1874 	ISP_IOXPUT_16(isp, src->snscb_rblen, &dst->snscb_rblen);
1875 	ISP_IOXPUT_16(isp, src->snscb_reserved0, &dst->snscb_reserved0);
1876 	ISP_IOXPUT_16(isp, src->snscb_addr[0], &dst->snscb_addr[0]);
1877 	ISP_IOXPUT_16(isp, src->snscb_addr[1], &dst->snscb_addr[1]);
1878 	ISP_IOXPUT_16(isp, src->snscb_addr[2], &dst->snscb_addr[2]);
1879 	ISP_IOXPUT_16(isp, src->snscb_addr[3], &dst->snscb_addr[3]);
1880 	ISP_IOXPUT_16(isp, src->snscb_sblen, &dst->snscb_sblen);
1881 	ISP_IOXPUT_16(isp, src->snscb_reserved1, &dst->snscb_reserved1);
1882 	ISP_IOXPUT_16(isp, src->snscb_cmd, &dst->snscb_cmd);
1883 	ISP_IOXPUT_16(isp, src->snscb_mword_div_2, &dst->snscb_mword_div_2);
1884 	ISP_IOXPUT_32(isp, src->snscb_reserved3, &dst->snscb_reserved3);
1885 	ISP_IOXPUT_32(isp, src->snscb_fc4_type, &dst->snscb_fc4_type);
1886 }
1887 
1888 void
1889 isp_put_gxn_id_request(ispsoftc_t *isp, sns_gxn_id_req_t *src, sns_gxn_id_req_t *dst)
1890 {
1891 	ISP_IOXPUT_16(isp, src->snscb_rblen, &dst->snscb_rblen);
1892 	ISP_IOXPUT_16(isp, src->snscb_reserved0, &dst->snscb_reserved0);
1893 	ISP_IOXPUT_16(isp, src->snscb_addr[0], &dst->snscb_addr[0]);
1894 	ISP_IOXPUT_16(isp, src->snscb_addr[1], &dst->snscb_addr[1]);
1895 	ISP_IOXPUT_16(isp, src->snscb_addr[2], &dst->snscb_addr[2]);
1896 	ISP_IOXPUT_16(isp, src->snscb_addr[3], &dst->snscb_addr[3]);
1897 	ISP_IOXPUT_16(isp, src->snscb_sblen, &dst->snscb_sblen);
1898 	ISP_IOXPUT_16(isp, src->snscb_reserved1, &dst->snscb_reserved1);
1899 	ISP_IOXPUT_16(isp, src->snscb_cmd, &dst->snscb_cmd);
1900 	ISP_IOXPUT_16(isp, src->snscb_reserved2, &dst->snscb_reserved2);
1901 	ISP_IOXPUT_32(isp, src->snscb_reserved3, &dst->snscb_reserved3);
1902 	ISP_IOXPUT_32(isp, src->snscb_portid, &dst->snscb_portid);
1903 }
1904 
1905 /*
1906  * Generic SNS response - not particularly useful since the per-command data
1907  * isn't always 16 bit words.
1908  */
1909 void
1910 isp_get_sns_response(ispsoftc_t *isp, sns_scrsp_t *src, sns_scrsp_t *dst, int nwords)
1911 {
1912 	int i;
1913 	isp_get_ct_hdr(isp, &src->snscb_cthdr, &dst->snscb_cthdr);
1914 	ISP_IOXGET_8(isp, &src->snscb_port_type, dst->snscb_port_type);
1915 	for (i = 0; i < 3; i++) {
1916 		ISP_IOXGET_8(isp, &src->snscb_port_id[i],
1917 		    dst->snscb_port_id[i]);
1918 	}
1919 	for (i = 0; i < 8; i++) {
1920 		ISP_IOXGET_8(isp, &src->snscb_portname[i],
1921 		    dst->snscb_portname[i]);
1922 	}
1923 	for (i = 0; i < nwords; i++) {
1924 		ISP_IOXGET_16(isp, &src->snscb_data[i], dst->snscb_data[i]);
1925 	}
1926 }
1927 
1928 void
1929 isp_get_gid_ft_response(ispsoftc_t *isp, sns_gid_ft_rsp_t *src, sns_gid_ft_rsp_t *dst, int nwords)
1930 {
1931 	int i;
1932 	isp_get_ct_hdr(isp, &src->snscb_cthdr, &dst->snscb_cthdr);
1933 	for (i = 0; i < nwords; i++) {
1934 		int j;
1935 		ISP_IOXGET_8(isp, &src->snscb_ports[i].control, dst->snscb_ports[i].control);
1936 		for (j = 0; j < 3; j++) {
1937 			ISP_IOXGET_8(isp, &src->snscb_ports[i].portid[j], dst->snscb_ports[i].portid[j]);
1938 		}
1939 		if (dst->snscb_ports[i].control & 0x80) {
1940 			break;
1941 		}
1942 	}
1943 }
1944 
1945 void
1946 isp_get_gxn_id_response(ispsoftc_t *isp, sns_gxn_id_rsp_t *src, sns_gxn_id_rsp_t *dst)
1947 {
1948 	int i;
1949 	isp_get_ct_hdr(isp, &src->snscb_cthdr, &dst->snscb_cthdr);
1950 	for (i = 0; i < 8; i++) {
1951 		ISP_IOXGET_8(isp, &src->snscb_wwn[i], dst->snscb_wwn[i]);
1952 	}
1953 }
1954 
1955 void
1956 isp_get_gff_id_response(ispsoftc_t *isp, sns_gff_id_rsp_t *src, sns_gff_id_rsp_t *dst)
1957 {
1958 	int i;
1959 	isp_get_ct_hdr(isp, &src->snscb_cthdr, &dst->snscb_cthdr);
1960 	for (i = 0; i < 32; i++) {
1961 		ISP_IOXGET_32(isp, &src->snscb_fc4_features[i], dst->snscb_fc4_features[i]);
1962 	}
1963 }
1964 
1965 void
1966 isp_get_ga_nxt_response(ispsoftc_t *isp, sns_ga_nxt_rsp_t *src, sns_ga_nxt_rsp_t *dst)
1967 {
1968 	int i;
1969 	isp_get_ct_hdr(isp, &src->snscb_cthdr, &dst->snscb_cthdr);
1970 	ISP_IOXGET_8(isp, &src->snscb_port_type, dst->snscb_port_type);
1971 	for (i = 0; i < 3; i++) {
1972 		ISP_IOXGET_8(isp, &src->snscb_port_id[i], dst->snscb_port_id[i]);
1973 	}
1974 	for (i = 0; i < 8; i++) {
1975 		ISP_IOXGET_8(isp, &src->snscb_portname[i], dst->snscb_portname[i]);
1976 	}
1977 	ISP_IOXGET_8(isp, &src->snscb_pnlen, dst->snscb_pnlen);
1978 	for (i = 0; i < 255; i++) {
1979 		ISP_IOXGET_8(isp, &src->snscb_pname[i], dst->snscb_pname[i]);
1980 	}
1981 	for (i = 0; i < 8; i++) {
1982 		ISP_IOXGET_8(isp, &src->snscb_nodename[i], dst->snscb_nodename[i]);
1983 	}
1984 	ISP_IOXGET_8(isp, &src->snscb_nnlen, dst->snscb_nnlen);
1985 	for (i = 0; i < 255; i++) {
1986 		ISP_IOXGET_8(isp, &src->snscb_nname[i], dst->snscb_nname[i]);
1987 	}
1988 	for (i = 0; i < 8; i++) {
1989 		ISP_IOXGET_8(isp, &src->snscb_ipassoc[i], dst->snscb_ipassoc[i]);
1990 	}
1991 	for (i = 0; i < 16; i++) {
1992 		ISP_IOXGET_8(isp, &src->snscb_ipaddr[i], dst->snscb_ipaddr[i]);
1993 	}
1994 	for (i = 0; i < 4; i++) {
1995 		ISP_IOXGET_8(isp, &src->snscb_svc_class[i], dst->snscb_svc_class[i]);
1996 	}
1997 	for (i = 0; i < 32; i++) {
1998 		ISP_IOXGET_8(isp, &src->snscb_fc4_types[i], dst->snscb_fc4_types[i]);
1999 	}
2000 	for (i = 0; i < 8; i++) {
2001 		ISP_IOXGET_8(isp, &src->snscb_fpname[i], dst->snscb_fpname[i]);
2002 	}
2003 	ISP_IOXGET_8(isp, &src->snscb_reserved, dst->snscb_reserved);
2004 	for (i = 0; i < 3; i++) {
2005 		ISP_IOXGET_8(isp, &src->snscb_hardaddr[i], dst->snscb_hardaddr[i]);
2006 	}
2007 }
2008 
2009 void
2010 isp_get_els(ispsoftc_t *isp, els_t *src, els_t *dst)
2011 {
2012 	int i;
2013 
2014 	isp_get_hdr(isp, &src->els_hdr, &dst->els_hdr);
2015 	ISP_IOXGET_32(isp, &src->els_handle, dst->els_handle);
2016 	ISP_IOXGET_16(isp, &src->els_status, dst->els_status);
2017 	ISP_IOXGET_16(isp, &src->els_nphdl, dst->els_nphdl);
2018 	ISP_IOXGET_16(isp, &src->els_xmit_dsd_count, dst->els_xmit_dsd_count);
2019 	ISP_IOXGET_8(isp, &src->els_vphdl, dst->els_vphdl);
2020 	ISP_IOXGET_8(isp, &src->els_sof, dst->els_sof);
2021 	ISP_IOXGET_32(isp, &src->els_rxid, dst->els_rxid);
2022 	ISP_IOXGET_16(isp, &src->els_recv_dsd_count, dst->els_recv_dsd_count);
2023 	ISP_IOXGET_8(isp, &src->els_opcode, dst->els_opcode);
2024 	ISP_IOXGET_8(isp, &src->els_reserved2, dst->els_reserved1);
2025 	ISP_IOXGET_8(isp, &src->els_did_lo, dst->els_did_lo);
2026 	ISP_IOXGET_8(isp, &src->els_did_mid, dst->els_did_mid);
2027 	ISP_IOXGET_8(isp, &src->els_did_hi, dst->els_did_hi);
2028 	ISP_IOXGET_8(isp, &src->els_reserved2, dst->els_reserved2);
2029 	ISP_IOXGET_16(isp, &src->els_reserved3, dst->els_reserved3);
2030 	ISP_IOXGET_16(isp, &src->els_ctl_flags, dst->els_ctl_flags);
2031 	ISP_IOXGET_32(isp, &src->els_bytecnt, dst->els_bytecnt);
2032 	ISP_IOXGET_32(isp, &src->els_subcode1, dst->els_subcode1);
2033 	ISP_IOXGET_32(isp, &src->els_subcode2, dst->els_subcode2);
2034 	for (i = 0; i < 20; i++) {
2035 		ISP_IOXGET_8(isp, &src->els_reserved4[i], dst->els_reserved4[i]);
2036 	}
2037 }
2038 
2039 void
2040 isp_put_els(ispsoftc_t *isp, els_t *src, els_t *dst)
2041 {
2042 	isp_put_hdr(isp, &src->els_hdr, &dst->els_hdr);
2043 	ISP_IOXPUT_32(isp, src->els_handle, &dst->els_handle);
2044 	ISP_IOXPUT_16(isp, src->els_status, &dst->els_status);
2045 	ISP_IOXPUT_16(isp, src->els_nphdl, &dst->els_nphdl);
2046 	ISP_IOXPUT_16(isp, src->els_xmit_dsd_count, &dst->els_xmit_dsd_count);
2047 	ISP_IOXPUT_8(isp, src->els_vphdl, &dst->els_vphdl);
2048 	ISP_IOXPUT_8(isp, src->els_sof, &dst->els_sof);
2049 	ISP_IOXPUT_32(isp, src->els_rxid, &dst->els_rxid);
2050 	ISP_IOXPUT_16(isp, src->els_recv_dsd_count, &dst->els_recv_dsd_count);
2051 	ISP_IOXPUT_8(isp, src->els_opcode, &dst->els_opcode);
2052 	ISP_IOXPUT_8(isp, src->els_reserved2, &dst->els_reserved1);
2053 	ISP_IOXPUT_8(isp, src->els_did_lo, &dst->els_did_lo);
2054 	ISP_IOXPUT_8(isp, src->els_did_mid, &dst->els_did_mid);
2055 	ISP_IOXPUT_8(isp, src->els_did_hi, &dst->els_did_hi);
2056 	ISP_IOXPUT_8(isp, src->els_reserved2, &dst->els_reserved2);
2057 	ISP_IOXPUT_16(isp, src->els_reserved3, &dst->els_reserved3);
2058 	ISP_IOXPUT_16(isp, src->els_ctl_flags, &dst->els_ctl_flags);
2059 	ISP_IOXPUT_32(isp, src->els_recv_bytecnt, &dst->els_recv_bytecnt);
2060 	ISP_IOXPUT_32(isp, src->els_xmit_bytecnt, &dst->els_xmit_bytecnt);
2061 	ISP_IOXPUT_32(isp, src->els_xmit_dsd_length, &dst->els_xmit_dsd_length);
2062 	ISP_IOXPUT_16(isp, src->els_xmit_dsd_a1500, &dst->els_xmit_dsd_a1500);
2063 	ISP_IOXPUT_16(isp, src->els_xmit_dsd_a3116, &dst->els_xmit_dsd_a3116);
2064 	ISP_IOXPUT_16(isp, src->els_xmit_dsd_a4732, &dst->els_xmit_dsd_a4732);
2065 	ISP_IOXPUT_16(isp, src->els_xmit_dsd_a6348, &dst->els_xmit_dsd_a6348);
2066 	ISP_IOXPUT_32(isp, src->els_recv_dsd_length, &dst->els_recv_dsd_length);
2067 	ISP_IOXPUT_16(isp, src->els_recv_dsd_a1500, &dst->els_recv_dsd_a1500);
2068 	ISP_IOXPUT_16(isp, src->els_recv_dsd_a3116, &dst->els_recv_dsd_a3116);
2069 	ISP_IOXPUT_16(isp, src->els_recv_dsd_a4732, &dst->els_recv_dsd_a4732);
2070 	ISP_IOXPUT_16(isp, src->els_recv_dsd_a6348, &dst->els_recv_dsd_a6348);
2071 }
2072 
2073 /*
2074  * FC Structure Canonicalization
2075  */
2076 
2077 void
2078 isp_get_fc_hdr(ispsoftc_t *isp, fc_hdr_t *src, fc_hdr_t *dst)
2079 {
2080         ISP_IOZGET_8(isp, &src->r_ctl, dst->r_ctl);
2081         ISP_IOZGET_8(isp, &src->d_id[0], dst->d_id[0]);
2082         ISP_IOZGET_8(isp, &src->d_id[1], dst->d_id[1]);
2083         ISP_IOZGET_8(isp, &src->d_id[2], dst->d_id[2]);
2084         ISP_IOZGET_8(isp, &src->cs_ctl, dst->cs_ctl);
2085         ISP_IOZGET_8(isp, &src->s_id[0], dst->s_id[0]);
2086         ISP_IOZGET_8(isp, &src->s_id[1], dst->s_id[1]);
2087         ISP_IOZGET_8(isp, &src->s_id[2], dst->s_id[2]);
2088         ISP_IOZGET_8(isp, &src->type, dst->type);
2089         ISP_IOZGET_8(isp, &src->f_ctl[0], dst->f_ctl[0]);
2090         ISP_IOZGET_8(isp, &src->f_ctl[1], dst->f_ctl[1]);
2091         ISP_IOZGET_8(isp, &src->f_ctl[2], dst->f_ctl[2]);
2092         ISP_IOZGET_8(isp, &src->seq_id, dst->seq_id);
2093         ISP_IOZGET_8(isp, &src->df_ctl, dst->df_ctl);
2094         ISP_IOZGET_16(isp, &src->seq_cnt, dst->seq_cnt);
2095         ISP_IOZGET_16(isp, &src->ox_id, dst->ox_id);
2096         ISP_IOZGET_16(isp, &src->rx_id, dst->rx_id);
2097         ISP_IOZGET_32(isp, &src->parameter, dst->parameter);
2098 }
2099 
2100 void
2101 isp_put_fc_hdr(ispsoftc_t *isp, fc_hdr_t *src, fc_hdr_t *dst)
2102 {
2103         ISP_IOZPUT_8(isp, src->r_ctl, &dst->r_ctl);
2104         ISP_IOZPUT_8(isp, src->d_id[0], &dst->d_id[0]);
2105         ISP_IOZPUT_8(isp, src->d_id[1], &dst->d_id[1]);
2106         ISP_IOZPUT_8(isp, src->d_id[2], &dst->d_id[2]);
2107         ISP_IOZPUT_8(isp, src->cs_ctl, &dst->cs_ctl);
2108         ISP_IOZPUT_8(isp, src->s_id[0], &dst->s_id[0]);
2109         ISP_IOZPUT_8(isp, src->s_id[1], &dst->s_id[1]);
2110         ISP_IOZPUT_8(isp, src->s_id[2], &dst->s_id[2]);
2111         ISP_IOZPUT_8(isp, src->type, &dst->type);
2112         ISP_IOZPUT_8(isp, src->f_ctl[0], &dst->f_ctl[0]);
2113         ISP_IOZPUT_8(isp, src->f_ctl[1], &dst->f_ctl[1]);
2114         ISP_IOZPUT_8(isp, src->f_ctl[2], &dst->f_ctl[2]);
2115         ISP_IOZPUT_8(isp, src->seq_id, &dst->seq_id);
2116         ISP_IOZPUT_8(isp, src->df_ctl, &dst->df_ctl);
2117         ISP_IOZPUT_16(isp, src->seq_cnt, &dst->seq_cnt);
2118         ISP_IOZPUT_16(isp, src->ox_id, &dst->ox_id);
2119         ISP_IOZPUT_16(isp, src->rx_id, &dst->rx_id);
2120         ISP_IOZPUT_32(isp, src->parameter, &dst->parameter);
2121 }
2122 
2123 void
2124 isp_get_fcp_cmnd_iu(ispsoftc_t *isp, fcp_cmnd_iu_t *src, fcp_cmnd_iu_t *dst)
2125 {
2126 	int i;
2127 
2128 	for (i = 0; i < 8; i++) {
2129 		ISP_IOZGET_8(isp, &src->fcp_cmnd_lun[i], dst->fcp_cmnd_lun[i]);
2130 	}
2131         ISP_IOZGET_8(isp, &src->fcp_cmnd_crn, dst->fcp_cmnd_crn);
2132         ISP_IOZGET_8(isp, &src->fcp_cmnd_task_attribute, dst->fcp_cmnd_task_attribute);
2133         ISP_IOZGET_8(isp, &src->fcp_cmnd_task_management, dst->fcp_cmnd_task_management);
2134         ISP_IOZGET_8(isp, &src->fcp_cmnd_alen_datadir, dst->fcp_cmnd_alen_datadir);
2135 	for (i = 0; i < 16; i++) {
2136 		ISP_IOZGET_8(isp, &src->cdb_dl.sf.fcp_cmnd_cdb[i], dst->cdb_dl.sf.fcp_cmnd_cdb[i]);
2137 	}
2138 	ISP_IOZGET_32(isp, &src->cdb_dl.sf.fcp_cmnd_dl, dst->cdb_dl.sf.fcp_cmnd_dl);
2139 }
2140 
2141 void
2142 isp_put_rft_id(ispsoftc_t *isp, rft_id_t *src, rft_id_t *dst)
2143 {
2144 	int i;
2145 	isp_put_ct_hdr(isp, &src->rftid_hdr, &dst->rftid_hdr);
2146 	ISP_IOZPUT_8(isp, src->rftid_reserved, &dst->rftid_reserved);
2147 	for (i = 0; i < 3; i++) {
2148 		ISP_IOZPUT_8(isp, src->rftid_portid[i], &dst->rftid_portid[i]);
2149 	}
2150 	for (i = 0; i < 8; i++) {
2151 		ISP_IOZPUT_32(isp, src->rftid_fc4types[i], &dst->rftid_fc4types[i]);
2152 	}
2153 }
2154 
2155 void
2156 isp_put_rff_id(ispsoftc_t *isp, rff_id_t *src, rff_id_t *dst)
2157 {
2158 	int i;
2159 
2160 	isp_put_ct_hdr(isp, &src->rffid_hdr, &dst->rffid_hdr);
2161 	ISP_IOZPUT_8(isp, src->rffid_reserved, &dst->rffid_reserved);
2162 	for (i = 0; i < 3; i++)
2163 		ISP_IOZPUT_8(isp, src->rffid_portid[i], &dst->rffid_portid[i]);
2164 	ISP_IOZPUT_16(isp, src->rffid_reserved2, &dst->rffid_reserved2);
2165 	ISP_IOZPUT_8(isp, src->rffid_fc4features, &dst->rffid_fc4features);
2166 	ISP_IOZPUT_8(isp, src->rffid_fc4type, &dst->rffid_fc4type);
2167 }
2168 
2169 void
2170 isp_get_ct_hdr(ispsoftc_t *isp, ct_hdr_t *src, ct_hdr_t *dst)
2171 {
2172 	ISP_IOZGET_8(isp, &src->ct_revision, dst->ct_revision);
2173 	ISP_IOZGET_8(isp, &src->ct_in_id[0], dst->ct_in_id[0]);
2174 	ISP_IOZGET_8(isp, &src->ct_in_id[1], dst->ct_in_id[1]);
2175 	ISP_IOZGET_8(isp, &src->ct_in_id[2], dst->ct_in_id[2]);
2176 	ISP_IOZGET_8(isp, &src->ct_fcs_type, dst->ct_fcs_type);
2177 	ISP_IOZGET_8(isp, &src->ct_fcs_subtype, dst->ct_fcs_subtype);
2178 	ISP_IOZGET_8(isp, &src->ct_options, dst->ct_options);
2179 	ISP_IOZGET_8(isp, &src->ct_reserved0, dst->ct_reserved0);
2180 	ISP_IOZGET_16(isp, &src->ct_cmd_resp, dst->ct_cmd_resp);
2181 	ISP_IOZGET_16(isp, &src->ct_bcnt_resid, dst->ct_bcnt_resid);
2182 	ISP_IOZGET_8(isp, &src->ct_reserved1, dst->ct_reserved1);
2183 	ISP_IOZGET_8(isp, &src->ct_reason, dst->ct_reason);
2184 	ISP_IOZGET_8(isp, &src->ct_explanation, dst->ct_explanation);
2185 	ISP_IOZGET_8(isp, &src->ct_vunique, dst->ct_vunique);
2186 }
2187 
2188 void
2189 isp_put_ct_hdr(ispsoftc_t *isp, ct_hdr_t *src, ct_hdr_t *dst)
2190 {
2191 	ISP_IOZPUT_8(isp, src->ct_revision, &dst->ct_revision);
2192 	ISP_IOZPUT_8(isp, src->ct_in_id[0], &dst->ct_in_id[0]);
2193 	ISP_IOZPUT_8(isp, src->ct_in_id[1], &dst->ct_in_id[1]);
2194 	ISP_IOZPUT_8(isp, src->ct_in_id[2], &dst->ct_in_id[2]);
2195 	ISP_IOZPUT_8(isp, src->ct_fcs_type, &dst->ct_fcs_type);
2196 	ISP_IOZPUT_8(isp, src->ct_fcs_subtype, &dst->ct_fcs_subtype);
2197 	ISP_IOZPUT_8(isp, src->ct_options, &dst->ct_options);
2198 	ISP_IOZPUT_8(isp, src->ct_reserved0, &dst->ct_reserved0);
2199 	ISP_IOZPUT_16(isp, src->ct_cmd_resp, &dst->ct_cmd_resp);
2200 	ISP_IOZPUT_16(isp, src->ct_bcnt_resid, &dst->ct_bcnt_resid);
2201 	ISP_IOZPUT_8(isp, src->ct_reserved1, &dst->ct_reserved1);
2202 	ISP_IOZPUT_8(isp, src->ct_reason, &dst->ct_reason);
2203 	ISP_IOZPUT_8(isp, src->ct_explanation, &dst->ct_explanation);
2204 	ISP_IOZPUT_8(isp, src->ct_vunique, &dst->ct_vunique);
2205 }
2206 
2207 void
2208 isp_put_fcp_rsp_iu(ispsoftc_t *isp, fcp_rsp_iu_t *src, fcp_rsp_iu_t *dst)
2209 {
2210 	int i;
2211 	for (i = 0; i < ((sizeof (src->fcp_rsp_reserved))/(sizeof (src->fcp_rsp_reserved[0]))); i++) {
2212 		ISP_IOZPUT_8(isp, src->fcp_rsp_reserved[i], &dst->fcp_rsp_reserved[i]);
2213 	}
2214 	ISP_IOZPUT_16(isp, src->fcp_rsp_status_qualifier, &dst->fcp_rsp_status_qualifier);
2215 	ISP_IOZPUT_8(isp, src->fcp_rsp_bits, &dst->fcp_rsp_bits);
2216 	ISP_IOZPUT_8(isp, src->fcp_rsp_scsi_status, &dst->fcp_rsp_scsi_status);
2217 	ISP_IOZPUT_32(isp, src->fcp_rsp_resid, &dst->fcp_rsp_resid);
2218 	ISP_IOZPUT_32(isp, src->fcp_rsp_snslen, &dst->fcp_rsp_snslen);
2219 	ISP_IOZPUT_32(isp, src->fcp_rsp_rsplen, &dst->fcp_rsp_rsplen);
2220 }
2221 
2222 #ifdef	ISP_TARGET_MODE
2223 
2224 /*
2225  * Command shipping- finish off first queue entry and do dma mapping and
2226  * additional segments as needed.
2227  *
2228  * Called with the first queue entry mostly filled out.
2229  * Our job here is to finish that and add additional data
2230  * segments if needed.
2231  *
2232  * We used to do synthetic entries to split data and status
2233  * at this level, but that started getting too tricky.
2234  */
2235 int
2236 isp_send_tgt_cmd(ispsoftc_t *isp, void *fqe, void *segp, uint32_t nsegs, uint32_t totalcnt, isp_ddir_t ddir, void *snsptr, uint32_t snslen)
2237 {
2238 	uint8_t storage[QENTRY_LEN];
2239 	uint8_t type, nqe;
2240 	uint32_t seg, curseg, seglim, nxt, nxtnxt;
2241 	ispds_t *dsp = NULL;
2242 	ispds64_t *dsp64 = NULL;
2243 	void *qe0, *qe1;
2244 
2245 	qe0 = isp_getrqentry(isp);
2246 	if (qe0 == NULL) {
2247 		return (CMD_EAGAIN);
2248 	}
2249 	nxt = ISP_NXT_QENTRY(isp->isp_reqidx, RQUEST_QUEUE_LEN(isp));
2250 
2251 	type = ((isphdr_t *)fqe)->rqs_entry_type;
2252 	nqe = 1;
2253 	seglim = 0;
2254 
2255 	/*
2256 	 * If we have data to transmit, figure out how many segments can fit into the first entry.
2257 	 */
2258 	if (ddir != ISP_NOXFR) {
2259 		/*
2260 		 * First, figure out how many pieces of data to transfer and what kind and how many we can put into the first queue entry.
2261 		 */
2262 		switch (type) {
2263 		case RQSTYPE_CTIO2:
2264 			dsp = ((ct2_entry_t *)fqe)->rsp.m0.u.ct_dataseg;
2265 			seglim = ISP_RQDSEG_T2;
2266 			break;
2267 		case RQSTYPE_CTIO3:
2268 			dsp64 = ((ct2_entry_t *)fqe)->rsp.m0.u.ct_dataseg64;
2269 			seglim = ISP_RQDSEG_T3;
2270 			break;
2271 		case RQSTYPE_CTIO7:
2272 			dsp64 = &((ct7_entry_t *)fqe)->rsp.m0.ds;
2273 			seglim = 1;
2274 			break;
2275 		default:
2276 			return (CMD_COMPLETE);
2277 		}
2278 	}
2279 
2280 	/*
2281 	 * First, fill out any of the data transfer stuff that fits
2282 	 * in the first queue entry.
2283 	 */
2284 	if (seglim > nsegs) {
2285 		seglim = nsegs;
2286 	}
2287 
2288 	for (seg = curseg = 0; curseg < seglim; curseg++) {
2289 		if (dsp64) {
2290 			XS_GET_DMA64_SEG(dsp64++, segp, seg++);
2291 		} else {
2292 			XS_GET_DMA_SEG(dsp++, segp, seg++);
2293 		}
2294 	}
2295 
2296 	/*
2297 	 * Second, start building additional continuation segments as needed.
2298 	 */
2299 	while (seg < nsegs) {
2300 		nxtnxt = ISP_NXT_QENTRY(nxt, RQUEST_QUEUE_LEN(isp));
2301 		if (nxtnxt == isp->isp_reqodx) {
2302 			isp->isp_reqodx = ISP_READ(isp, isp->isp_rqstoutrp);
2303 			if (nxtnxt == isp->isp_reqodx)
2304 				return (CMD_EAGAIN);
2305 		}
2306 		ISP_MEMZERO(storage, QENTRY_LEN);
2307 		qe1 = ISP_QUEUE_ENTRY(isp->isp_rquest, nxt);
2308 		nxt = nxtnxt;
2309 		if (dsp64) {
2310 			ispcontreq64_t *crq = (ispcontreq64_t *) storage;
2311 			seglim = ISP_CDSEG64;
2312 			crq->req_header.rqs_entry_type = RQSTYPE_A64_CONT;
2313 			crq->req_header.rqs_entry_count = 1;
2314 			dsp64 = crq->req_dataseg;
2315 		} else {
2316 			ispcontreq_t *crq = (ispcontreq_t *) storage;
2317 			seglim = ISP_CDSEG;
2318 			crq->req_header.rqs_entry_type = RQSTYPE_DATASEG;
2319 			crq->req_header.rqs_entry_count = 1;
2320 			dsp = crq->req_dataseg;
2321 		}
2322 		if (seg + seglim > nsegs) {
2323 			seglim = nsegs - seg;
2324 		}
2325 		for (curseg = 0; curseg < seglim; curseg++) {
2326 			if (dsp64) {
2327 				XS_GET_DMA64_SEG(dsp64++, segp, seg++);
2328 			} else {
2329 				XS_GET_DMA_SEG(dsp++, segp, seg++);
2330 			}
2331 		}
2332 		if (dsp64) {
2333 			isp_put_cont64_req(isp, (ispcontreq64_t *)storage, qe1);
2334 		} else {
2335 			isp_put_cont_req(isp, (ispcontreq_t *)storage, qe1);
2336 		}
2337 		if (isp->isp_dblev & ISP_LOGTDEBUG1) {
2338 			isp_print_bytes(isp, "additional queue entry", QENTRY_LEN, storage);
2339 		}
2340 		nqe++;
2341         }
2342 
2343 	/*
2344 	 * Third, not patch up the first queue entry with the number of segments
2345 	 * we actually are going to be transmitting. At the same time, handle
2346 	 * any mode 2 requests.
2347 	 */
2348 	((isphdr_t *)fqe)->rqs_entry_count = nqe;
2349 	switch (type) {
2350 	case RQSTYPE_CTIO2:
2351 	case RQSTYPE_CTIO3:
2352 		if (((ct2_entry_t *)fqe)->ct_flags & CT2_FLAG_MODE2) {
2353 			((ct2_entry_t *)fqe)->ct_seg_count = 1;
2354 		} else {
2355 			((ct2_entry_t *)fqe)->ct_seg_count = nsegs;
2356 		}
2357 		if (ISP_CAP_2KLOGIN(isp)) {
2358 			isp_put_ctio2e(isp, fqe, qe0);
2359 		} else {
2360 			isp_put_ctio2(isp, fqe, qe0);
2361 		}
2362 		break;
2363 	case RQSTYPE_CTIO7:
2364 		if (((ct7_entry_t *)fqe)->ct_flags & CT7_FLAG_MODE2) {
2365 			((ct7_entry_t *)fqe)->ct_seg_count = 1;
2366 		} else {
2367 			((ct7_entry_t *)fqe)->ct_seg_count = nsegs;
2368 		}
2369 		isp_put_ctio7(isp, fqe, qe0);
2370 		break;
2371 	default:
2372 		return (CMD_COMPLETE);
2373 	}
2374 	if (isp->isp_dblev & ISP_LOGTDEBUG1) {
2375 		isp_print_bytes(isp, "first queue entry", QENTRY_LEN, fqe);
2376 	}
2377 	ISP_ADD_REQUEST(isp, nxt);
2378 	return (CMD_QUEUED);
2379 }
2380 
2381 int
2382 isp_allocate_xs_tgt(ispsoftc_t *isp, void *xs, uint32_t *handlep)
2383 {
2384 	isp_hdl_t *hdp;
2385 
2386 	hdp = isp->isp_tgtfree;
2387 	if (hdp == NULL) {
2388 		return (-1);
2389 	}
2390 	isp->isp_tgtfree = hdp->cmd;
2391 	hdp->cmd = xs;
2392 	hdp->handle = (hdp - isp->isp_tgtlist);
2393 	hdp->handle |= (ISP_HANDLE_TARGET << ISP_HANDLE_USAGE_SHIFT);
2394 	/*
2395 	 * Target handles for SCSI cards are only 16 bits, so
2396 	 * sequence number protection will be ommitted.
2397 	 */
2398 	if (IS_FC(isp)) {
2399 		hdp->handle |= (isp->isp_seqno++ << ISP_HANDLE_SEQ_SHIFT);
2400 	}
2401 	*handlep = hdp->handle;
2402 	return (0);
2403 }
2404 
2405 void *
2406 isp_find_xs_tgt(ispsoftc_t *isp, uint32_t handle)
2407 {
2408 	if (!ISP_VALID_TGT_HANDLE(isp, handle)) {
2409 		isp_prt(isp, ISP_LOGERR, "%s: bad handle 0x%x", __func__, handle);
2410 		return (NULL);
2411 	}
2412 	return (isp->isp_tgtlist[(handle & ISP_HANDLE_CMD_MASK)].cmd);
2413 }
2414 
2415 uint32_t
2416 isp_find_tgt_handle(ispsoftc_t *isp, void *xs)
2417 {
2418 	uint32_t i, foundhdl = ISP_HANDLE_FREE;
2419 
2420 	if (xs != NULL) {
2421 		for (i = 0; i < isp->isp_maxcmds; i++) {
2422 			if (isp->isp_tgtlist[i].cmd != xs) {
2423 				continue;
2424 			}
2425 			foundhdl = isp->isp_tgtlist[i].handle;
2426 			break;
2427 		}
2428 	}
2429 	return (foundhdl);
2430 }
2431 
2432 void
2433 isp_destroy_tgt_handle(ispsoftc_t *isp, uint32_t handle)
2434 {
2435 	if (!ISP_VALID_TGT_HANDLE(isp, handle)) {
2436 		isp_prt(isp, ISP_LOGERR, "%s: bad handle 0x%x", __func__, handle);
2437 	} else {
2438 		isp->isp_tgtlist[(handle & ISP_HANDLE_CMD_MASK)].handle = ISP_HANDLE_FREE;
2439 		isp->isp_tgtlist[(handle & ISP_HANDLE_CMD_MASK)].cmd = isp->isp_tgtfree;
2440 		isp->isp_tgtfree = &isp->isp_tgtlist[(handle & ISP_HANDLE_CMD_MASK)];
2441 	}
2442 }
2443 
2444 #endif
2445 
2446 /*
2447  * Find port database entries
2448  */
2449 int
2450 isp_find_pdb_empty(ispsoftc_t *isp, int chan, fcportdb_t **lptr)
2451 {
2452 	fcparam *fcp = FCPARAM(isp, chan);
2453 	int i;
2454 
2455 	for (i = 0; i < MAX_FC_TARG; i++) {
2456 		fcportdb_t *lp = &fcp->portdb[i];
2457 
2458 		if (lp->state == FC_PORTDB_STATE_NIL) {
2459 			*lptr = lp;
2460 			return (1);
2461 		}
2462 	}
2463 	return (0);
2464 }
2465 
2466 int
2467 isp_find_pdb_by_wwpn(ispsoftc_t *isp, int chan, uint64_t wwpn, fcportdb_t **lptr)
2468 {
2469 	fcparam *fcp = FCPARAM(isp, chan);
2470 	int i;
2471 
2472 	for (i = 0; i < MAX_FC_TARG; i++) {
2473 		fcportdb_t *lp = &fcp->portdb[i];
2474 
2475 		if (lp->state == FC_PORTDB_STATE_NIL)
2476 			continue;
2477 		if (lp->port_wwn == wwpn) {
2478 			*lptr = lp;
2479 			return (1);
2480 		}
2481 	}
2482 	return (0);
2483 }
2484 
2485 int
2486 isp_find_pdb_by_handle(ispsoftc_t *isp, int chan, uint16_t handle,
2487     fcportdb_t **lptr)
2488 {
2489 	fcparam *fcp = FCPARAM(isp, chan);
2490 	int i;
2491 
2492 	for (i = 0; i < MAX_FC_TARG; i++) {
2493 		fcportdb_t *lp = &fcp->portdb[i];
2494 
2495 		if (lp->state == FC_PORTDB_STATE_NIL)
2496 			continue;
2497 		if (lp->handle == handle) {
2498 			*lptr = lp;
2499 			return (1);
2500 		}
2501 	}
2502 	return (0);
2503 }
2504 
2505 int
2506 isp_find_pdb_by_portid(ispsoftc_t *isp, int chan, uint32_t portid,
2507     fcportdb_t **lptr)
2508 {
2509 	fcparam *fcp = FCPARAM(isp, chan);
2510 	int i;
2511 
2512 	for (i = 0; i < MAX_FC_TARG; i++) {
2513 		fcportdb_t *lp = &fcp->portdb[i];
2514 
2515 		if (lp->state == FC_PORTDB_STATE_NIL)
2516 			continue;
2517 		if (lp->portid == portid) {
2518 			*lptr = lp;
2519 			return (1);
2520 		}
2521 	}
2522 	return (0);
2523 }
2524 
2525 #ifdef	ISP_TARGET_MODE
2526 void
2527 isp_find_chan_by_did(ispsoftc_t *isp, uint32_t did, uint16_t *cp)
2528 {
2529 	uint16_t chan;
2530 
2531 	*cp = ISP_NOCHAN;
2532 	for (chan = 0; chan < isp->isp_nchan; chan++) {
2533 		fcparam *fcp = FCPARAM(isp, chan);
2534 		if ((fcp->role & ISP_ROLE_TARGET) == 0 ||
2535 		    fcp->isp_loopstate < LOOP_LTEST_DONE) {
2536 			continue;
2537 		}
2538 		if (fcp->isp_portid == did) {
2539 			*cp = chan;
2540 			break;
2541 		}
2542 	}
2543 }
2544 
2545 /*
2546  * Add an initiator device to the port database
2547  */
2548 void
2549 isp_add_wwn_entry(ispsoftc_t *isp, int chan, uint64_t wwpn, uint64_t wwnn,
2550     uint16_t nphdl, uint32_t s_id, uint16_t prli_params)
2551 {
2552 	char buf[64];
2553 	fcparam *fcp;
2554 	fcportdb_t *lp;
2555 	int i, change;
2556 
2557 	fcp = FCPARAM(isp, chan);
2558 	if (nphdl >= MAX_NPORT_HANDLE) {
2559 		isp_prt(isp, ISP_LOGTINFO|ISP_LOGWARN, "Chan %d WWPN 0x%016llx "
2560 		    "PortID 0x%06x handle 0x%x -- bad handle",
2561 		    chan, (unsigned long long) wwpn, s_id, nphdl);
2562 		return;
2563 	}
2564 
2565 	/*
2566 	 * If valid record for requested handle already exists, update it
2567 	 * with new parameters.  Some cases of update can be suspicious,
2568 	 * so log them verbosely and dump the whole port database.
2569 	 */
2570 	if ((VALID_INI(wwpn) && isp_find_pdb_by_wwpn(isp, chan, wwpn, &lp)) ||
2571 	    (VALID_PORT(s_id) && isp_find_pdb_by_portid(isp, chan, s_id, &lp))) {
2572 		change = 0;
2573 		lp->new_portid = lp->portid;
2574 		lp->new_prli_word3 = lp->prli_word3;
2575 		if (VALID_PORT(s_id) && lp->portid != s_id) {
2576 			if (!VALID_PORT(lp->portid)) {
2577 				isp_prt(isp, ISP_LOGTINFO,
2578 				    "Chan %d WWPN 0x%016llx handle 0x%x "
2579 				    "gets PortID 0x%06x",
2580 				    chan, (unsigned long long) lp->port_wwn,
2581 				    nphdl, s_id);
2582 			} else {
2583 				isp_prt(isp, ISP_LOGTINFO|ISP_LOGWARN,
2584 				    "Chan %d WWPN 0x%016llx handle 0x%x "
2585 				    "changes PortID 0x%06x to 0x%06x",
2586 				    chan, (unsigned long long) lp->port_wwn,
2587 				    nphdl, lp->portid, s_id);
2588 				if (isp->isp_dblev & (ISP_LOGTINFO|ISP_LOGWARN))
2589 					isp_dump_portdb(isp, chan);
2590 			}
2591 			lp->new_portid = s_id;
2592 			change++;
2593 		}
2594 		if (VALID_INI(wwpn) && lp->port_wwn != wwpn) {
2595 			if (!VALID_INI(lp->port_wwn)) {
2596 				isp_prt(isp, ISP_LOGTINFO,
2597 				    "Chan %d PortID 0x%06x handle 0x%x "
2598 				    "gets WWPN 0x%016llxx",
2599 				    chan, lp->portid, nphdl,
2600 				    (unsigned long long) wwpn);
2601 			} else if (lp->port_wwn != wwpn) {
2602 				isp_prt(isp, ISP_LOGTINFO|ISP_LOGWARN,
2603 				    "Chan %d PortID 0x%06x handle 0x%x "
2604 				    "changes WWPN 0x%016llx to 0x%016llx",
2605 				    chan, lp->portid, nphdl,
2606 				    (unsigned long long) lp->port_wwn,
2607 				    (unsigned long long) wwpn);
2608 				if (isp->isp_dblev & (ISP_LOGTINFO|ISP_LOGWARN))
2609 					isp_dump_portdb(isp, chan);
2610 			}
2611 			lp->port_wwn = wwpn;
2612 			change++;
2613 		}
2614 		if (VALID_INI(wwnn) && lp->node_wwn != wwnn) {
2615 			if (!VALID_INI(lp->node_wwn)) {
2616 				isp_prt(isp, ISP_LOGTINFO,
2617 				    "Chan %d PortID 0x%06x handle 0x%x "
2618 				    "gets WWNN 0x%016llxx",
2619 				    chan, lp->portid, nphdl,
2620 				    (unsigned long long) wwnn);
2621 			} else if (lp->port_wwn != wwnn) {
2622 				isp_prt(isp, ISP_LOGTINFO,
2623 				    "Chan %d PortID 0x%06x handle 0x%x "
2624 				    "changes WWNN 0x%016llx to 0x%016llx",
2625 				    chan, lp->portid, nphdl,
2626 				    (unsigned long long) lp->node_wwn,
2627 				    (unsigned long long) wwnn);
2628 			}
2629 			lp->node_wwn = wwnn;
2630 			change++;
2631 		}
2632 		if (prli_params != 0 && lp->prli_word3 != prli_params) {
2633 			isp_gen_role_str(buf, sizeof (buf), prli_params);
2634 			isp_prt(isp, ISP_LOGTINFO|ISP_LOGCONFIG,
2635 			    "Chan %d WWPN 0x%016llx PortID 0x%06x "
2636 			    "handle 0x%x changes PRLI Word 3 %s",
2637 			    chan, (unsigned long long) lp->port_wwn,
2638 			    lp->portid, lp->handle, buf);
2639 			lp->new_prli_word3 = prli_params;
2640 			change++;
2641 		}
2642 		if (lp->handle != nphdl) {
2643 			isp_prt(isp, ISP_LOGTINFO|ISP_LOGCONFIG,
2644 			    "Chan %d WWPN 0x%016llx PortID 0x%06x "
2645 			    "changes handle 0x%x to 0x%x",
2646 			    chan, (unsigned long long) lp->port_wwn,
2647 			    lp->portid, lp->handle, nphdl);
2648 			lp->handle = nphdl;
2649 			change++;
2650 		}
2651 		lp->state = FC_PORTDB_STATE_VALID;
2652 		if (change) {
2653 			isp_async(isp, ISPASYNC_DEV_CHANGED, chan, lp);
2654 			lp->portid = lp->new_portid;
2655 			lp->prli_word3 = lp->new_prli_word3;
2656 		} else {
2657 			isp_prt(isp, ISP_LOGTINFO,
2658 			    "Chan %d WWPN 0x%016llx PortID 0x%06x "
2659 			    "handle 0x%x reentered",
2660 			    chan, (unsigned long long) lp->port_wwn,
2661 			    lp->portid, lp->handle);
2662 			isp_async(isp, ISPASYNC_DEV_STAYED, chan, lp);
2663 		}
2664 		return;
2665 	}
2666 
2667 	/* Search for room to insert new record. */
2668 	for (i = 0; i < MAX_FC_TARG; i++) {
2669 		if (fcp->portdb[i].state == FC_PORTDB_STATE_NIL)
2670 			break;
2671 	}
2672 	if (i >= MAX_FC_TARG) {
2673 		isp_prt(isp, ISP_LOGTINFO|ISP_LOGWARN,
2674 		    "Chan %d WWPN 0x%016llx PortID 0x%06x handle 0x%x "
2675 		    "-- no room in port database",
2676 		    chan, (unsigned long long) wwpn, s_id, nphdl);
2677 		if (isp->isp_dblev & (ISP_LOGTINFO|ISP_LOGWARN))
2678 			isp_dump_portdb(isp, chan);
2679 		return;
2680 	}
2681 
2682 	/* Insert new record and mark it valid. */
2683 	lp = &fcp->portdb[i];
2684 	ISP_MEMZERO(lp, sizeof (fcportdb_t));
2685 	lp->handle = nphdl;
2686 	lp->portid = s_id;
2687 	lp->port_wwn = wwpn;
2688 	lp->node_wwn = wwnn;
2689 	lp->prli_word3 = (prli_params != 0) ? prli_params : PRLI_WD3_INITIATOR_FUNCTION;
2690 	lp->state = FC_PORTDB_STATE_VALID;
2691 
2692 	isp_gen_role_str(buf, sizeof (buf), lp->prli_word3);
2693 	isp_prt(isp, ISP_LOGTINFO, "Chan %d WWPN 0x%016llx "
2694 	    "PortID 0x%06x handle 0x%x vtgt %d %s added", chan,
2695 	    (unsigned long long) wwpn, s_id, nphdl, i, buf);
2696 
2697 	/* Notify above levels about new port arrival. */
2698 	isp_async(isp, ISPASYNC_DEV_ARRIVED, chan, lp);
2699 }
2700 
2701 /*
2702  * Remove a target device to the port database
2703  */
2704 void
2705 isp_del_wwn_entry(ispsoftc_t *isp, int chan, uint64_t wwpn, uint16_t nphdl, uint32_t s_id)
2706 {
2707 	fcparam *fcp;
2708 	fcportdb_t *lp;
2709 
2710 	if (nphdl >= MAX_NPORT_HANDLE) {
2711 		isp_prt(isp, ISP_LOGWARN, "Chan %d WWPN 0x%016llx PortID 0x%06x bad handle 0x%x",
2712 		    chan, (unsigned long long) wwpn, s_id, nphdl);
2713 		return;
2714 	}
2715 
2716 	fcp = FCPARAM(isp, chan);
2717 	if (isp_find_pdb_by_handle(isp, chan, nphdl, &lp) == 0) {
2718 		isp_prt(isp, ISP_LOGWARN, "Chan %d WWPN 0x%016llx PortID 0x%06x handle 0x%x cannot be found to be deleted",
2719 		    chan, (unsigned long long) wwpn, s_id, nphdl);
2720 		isp_dump_portdb(isp, chan);
2721 		return;
2722 	}
2723 	isp_prt(isp, ISP_LOGTINFO, "Chan %d WWPN 0x%016llx PortID 0x%06x handle 0x%x vtgt %d deleted",
2724 	    chan, (unsigned long long) lp->port_wwn, lp->portid, nphdl, FC_PORTDB_TGT(isp, chan, lp));
2725 	lp->state = FC_PORTDB_STATE_NIL;
2726 
2727 	/* Notify above levels about gone port. */
2728 	isp_async(isp, ISPASYNC_DEV_GONE, chan, lp);
2729 }
2730 
2731 void
2732 isp_del_all_wwn_entries(ispsoftc_t *isp, int chan)
2733 {
2734 	fcparam *fcp;
2735 	int i;
2736 
2737 	if (!IS_FC(isp)) {
2738 		return;
2739 	}
2740 
2741 	/*
2742 	 * Handle iterations over all channels via recursion
2743 	 */
2744 	if (chan == ISP_NOCHAN) {
2745 		for (chan = 0; chan < isp->isp_nchan; chan++) {
2746 			isp_del_all_wwn_entries(isp, chan);
2747 		}
2748 		return;
2749 	}
2750 
2751 	if (chan > isp->isp_nchan) {
2752 		return;
2753 	}
2754 
2755 	fcp = FCPARAM(isp, chan);
2756 	if (fcp == NULL) {
2757 		return;
2758 	}
2759 	for (i = 0; i < MAX_FC_TARG; i++) {
2760 		fcportdb_t *lp = &fcp->portdb[i];
2761 
2762 		if (lp->state != FC_PORTDB_STATE_NIL)
2763 			isp_del_wwn_entry(isp, chan, lp->port_wwn, lp->handle, lp->portid);
2764 	}
2765 }
2766 
2767 void
2768 isp_del_wwn_entries(ispsoftc_t *isp, isp_notify_t *mp)
2769 {
2770 	fcportdb_t *lp;
2771 
2772 	/*
2773 	 * Handle iterations over all channels via recursion
2774 	 */
2775 	if (mp->nt_channel == ISP_NOCHAN) {
2776 		for (mp->nt_channel = 0; mp->nt_channel < isp->isp_nchan; mp->nt_channel++) {
2777 			isp_del_wwn_entries(isp, mp);
2778 		}
2779 		mp->nt_channel = ISP_NOCHAN;
2780 		return;
2781 	}
2782 
2783 	/*
2784 	 * We have an entry which is only partially identified.
2785 	 *
2786 	 * It's only known by WWN, N-Port handle, or Port ID.
2787 	 * We need to find the actual entry so we can delete it.
2788 	 */
2789 	if (mp->nt_nphdl != NIL_HANDLE) {
2790 		if (isp_find_pdb_by_handle(isp, mp->nt_channel, mp->nt_nphdl, &lp)) {
2791 			isp_del_wwn_entry(isp, mp->nt_channel, lp->port_wwn, lp->handle, lp->portid);
2792 			return;
2793 		}
2794 	}
2795 	if (VALID_INI(mp->nt_wwn)) {
2796 		if (isp_find_pdb_by_wwpn(isp, mp->nt_channel, mp->nt_wwn, &lp)) {
2797 			isp_del_wwn_entry(isp, mp->nt_channel, lp->port_wwn, lp->handle, lp->portid);
2798 			return;
2799 		}
2800 	}
2801 	if (VALID_PORT(mp->nt_sid)) {
2802 		if (isp_find_pdb_by_portid(isp, mp->nt_channel, mp->nt_sid, &lp)) {
2803 			isp_del_wwn_entry(isp, mp->nt_channel, lp->port_wwn, lp->handle, lp->portid);
2804 			return;
2805 		}
2806 	}
2807 	isp_prt(isp, ISP_LOGWARN, "Chan %d unable to find entry to delete WWPN 0x%016jx PortID 0x%06x handle 0x%x",
2808 	    mp->nt_channel, mp->nt_wwn, mp->nt_sid, mp->nt_nphdl);
2809 }
2810 
2811 void
2812 isp_put_atio2(ispsoftc_t *isp, at2_entry_t *src, at2_entry_t *dst)
2813 {
2814 	int i;
2815 	isp_put_hdr(isp, &src->at_header, &dst->at_header);
2816 	ISP_IOXPUT_32(isp, src->at_reserved, &dst->at_reserved);
2817 	ISP_IOXPUT_8(isp, src->at_lun, &dst->at_lun);
2818 	ISP_IOXPUT_8(isp, src->at_iid, &dst->at_iid);
2819 	ISP_IOXPUT_16(isp, src->at_rxid, &dst->at_rxid);
2820 	ISP_IOXPUT_16(isp, src->at_flags, &dst->at_flags);
2821 	ISP_IOXPUT_16(isp, src->at_status, &dst->at_status);
2822 	ISP_IOXPUT_8(isp, src->at_crn, &dst->at_crn);
2823 	ISP_IOXPUT_8(isp, src->at_taskcodes, &dst->at_taskcodes);
2824 	ISP_IOXPUT_8(isp, src->at_taskflags, &dst->at_taskflags);
2825 	ISP_IOXPUT_8(isp, src->at_execodes, &dst->at_execodes);
2826 	for (i = 0; i < ATIO2_CDBLEN; i++) {
2827 		ISP_IOXPUT_8(isp, src->at_cdb[i], &dst->at_cdb[i]);
2828 	}
2829 	ISP_IOXPUT_32(isp, src->at_datalen, &dst->at_datalen);
2830 	ISP_IOXPUT_16(isp, src->at_scclun, &dst->at_scclun);
2831 	for (i = 0; i < 4; i++) {
2832 		ISP_IOXPUT_16(isp, src->at_wwpn[i], &dst->at_wwpn[i]);
2833 	}
2834 	for (i = 0; i < 6; i++) {
2835 		ISP_IOXPUT_16(isp, src->at_reserved2[i], &dst->at_reserved2[i]);
2836 	}
2837 	ISP_IOXPUT_16(isp, src->at_oxid, &dst->at_oxid);
2838 }
2839 
2840 void
2841 isp_put_atio2e(ispsoftc_t *isp, at2e_entry_t *src, at2e_entry_t *dst)
2842 {
2843 	int i;
2844 	isp_put_hdr(isp, &src->at_header, &dst->at_header);
2845 	ISP_IOXPUT_32(isp, src->at_reserved, &dst->at_reserved);
2846 	ISP_IOXPUT_16(isp, src->at_iid, &dst->at_iid);
2847 	ISP_IOXPUT_16(isp, src->at_rxid, &dst->at_rxid);
2848 	ISP_IOXPUT_16(isp, src->at_flags, &dst->at_flags);
2849 	ISP_IOXPUT_16(isp, src->at_status, &dst->at_status);
2850 	ISP_IOXPUT_8(isp, src->at_crn, &dst->at_crn);
2851 	ISP_IOXPUT_8(isp, src->at_taskcodes, &dst->at_taskcodes);
2852 	ISP_IOXPUT_8(isp, src->at_taskflags, &dst->at_taskflags);
2853 	ISP_IOXPUT_8(isp, src->at_execodes, &dst->at_execodes);
2854 	for (i = 0; i < ATIO2_CDBLEN; i++) {
2855 		ISP_IOXPUT_8(isp, src->at_cdb[i], &dst->at_cdb[i]);
2856 	}
2857 	ISP_IOXPUT_32(isp, src->at_datalen, &dst->at_datalen);
2858 	ISP_IOXPUT_16(isp, src->at_scclun, &dst->at_scclun);
2859 	for (i = 0; i < 4; i++) {
2860 		ISP_IOXPUT_16(isp, src->at_wwpn[i], &dst->at_wwpn[i]);
2861 	}
2862 	for (i = 0; i < 6; i++) {
2863 		ISP_IOXPUT_16(isp, src->at_reserved2[i], &dst->at_reserved2[i]);
2864 	}
2865 	ISP_IOXPUT_16(isp, src->at_oxid, &dst->at_oxid);
2866 }
2867 
2868 void
2869 isp_get_atio2(ispsoftc_t *isp, at2_entry_t *src, at2_entry_t *dst)
2870 {
2871 	int i;
2872 	isp_get_hdr(isp, &src->at_header, &dst->at_header);
2873 	ISP_IOXGET_32(isp, &src->at_reserved, dst->at_reserved);
2874 	ISP_IOXGET_8(isp, &src->at_lun, dst->at_lun);
2875 	ISP_IOXGET_8(isp, &src->at_iid, dst->at_iid);
2876 	ISP_IOXGET_16(isp, &src->at_rxid, dst->at_rxid);
2877 	ISP_IOXGET_16(isp, &src->at_flags, dst->at_flags);
2878 	ISP_IOXGET_16(isp, &src->at_status, dst->at_status);
2879 	ISP_IOXGET_8(isp, &src->at_crn, dst->at_crn);
2880 	ISP_IOXGET_8(isp, &src->at_taskcodes, dst->at_taskcodes);
2881 	ISP_IOXGET_8(isp, &src->at_taskflags, dst->at_taskflags);
2882 	ISP_IOXGET_8(isp, &src->at_execodes, dst->at_execodes);
2883 	for (i = 0; i < ATIO2_CDBLEN; i++) {
2884 		ISP_IOXGET_8(isp, &src->at_cdb[i], dst->at_cdb[i]);
2885 	}
2886 	ISP_IOXGET_32(isp, &src->at_datalen, dst->at_datalen);
2887 	ISP_IOXGET_16(isp, &src->at_scclun, dst->at_scclun);
2888 	for (i = 0; i < 4; i++) {
2889 		ISP_IOXGET_16(isp, &src->at_wwpn[i], dst->at_wwpn[i]);
2890 	}
2891 	for (i = 0; i < 6; i++) {
2892 		ISP_IOXGET_16(isp, &src->at_reserved2[i], dst->at_reserved2[i]);
2893 	}
2894 	ISP_IOXGET_16(isp, &src->at_oxid, dst->at_oxid);
2895 }
2896 
2897 void
2898 isp_get_atio2e(ispsoftc_t *isp, at2e_entry_t *src, at2e_entry_t *dst)
2899 {
2900 	int i;
2901 	isp_get_hdr(isp, &src->at_header, &dst->at_header);
2902 	ISP_IOXGET_32(isp, &src->at_reserved, dst->at_reserved);
2903 	ISP_IOXGET_16(isp, &src->at_iid, dst->at_iid);
2904 	ISP_IOXGET_16(isp, &src->at_rxid, dst->at_rxid);
2905 	ISP_IOXGET_16(isp, &src->at_flags, dst->at_flags);
2906 	ISP_IOXGET_16(isp, &src->at_status, dst->at_status);
2907 	ISP_IOXGET_8(isp, &src->at_crn, dst->at_crn);
2908 	ISP_IOXGET_8(isp, &src->at_taskcodes, dst->at_taskcodes);
2909 	ISP_IOXGET_8(isp, &src->at_taskflags, dst->at_taskflags);
2910 	ISP_IOXGET_8(isp, &src->at_execodes, dst->at_execodes);
2911 	for (i = 0; i < ATIO2_CDBLEN; i++) {
2912 		ISP_IOXGET_8(isp, &src->at_cdb[i], dst->at_cdb[i]);
2913 	}
2914 	ISP_IOXGET_32(isp, &src->at_datalen, dst->at_datalen);
2915 	ISP_IOXGET_16(isp, &src->at_scclun, dst->at_scclun);
2916 	for (i = 0; i < 4; i++) {
2917 		ISP_IOXGET_16(isp, &src->at_wwpn[i], dst->at_wwpn[i]);
2918 	}
2919 	for (i = 0; i < 6; i++) {
2920 		ISP_IOXGET_16(isp, &src->at_reserved2[i], dst->at_reserved2[i]);
2921 	}
2922 	ISP_IOXGET_16(isp, &src->at_oxid, dst->at_oxid);
2923 }
2924 
2925 void
2926 isp_get_atio7(ispsoftc_t *isp, at7_entry_t *src, at7_entry_t *dst)
2927 {
2928 	ISP_IOXGET_8(isp, &src->at_type, dst->at_type);
2929 	ISP_IOXGET_8(isp, &src->at_count, dst->at_count);
2930 	ISP_IOXGET_16(isp, &src->at_ta_len, dst->at_ta_len);
2931 	ISP_IOXGET_32(isp, &src->at_rxid, dst->at_rxid);
2932 	isp_get_fc_hdr(isp, &src->at_hdr, &dst->at_hdr);
2933 	isp_get_fcp_cmnd_iu(isp, &src->at_cmnd, &dst->at_cmnd);
2934 }
2935 
2936 void
2937 isp_put_ctio2(ispsoftc_t *isp, ct2_entry_t *src, ct2_entry_t *dst)
2938 {
2939 	int i;
2940 	isp_put_hdr(isp, &src->ct_header, &dst->ct_header);
2941 	ISP_IOXPUT_32(isp, src->ct_syshandle, &dst->ct_syshandle);
2942 	ISP_IOXPUT_8(isp, src->ct_lun, &dst->ct_lun);
2943 	ISP_IOXPUT_8(isp, src->ct_iid, &dst->ct_iid);
2944 	ISP_IOXPUT_16(isp, src->ct_rxid, &dst->ct_rxid);
2945 	ISP_IOXPUT_16(isp, src->ct_flags, &dst->ct_flags);
2946 	ISP_IOXPUT_16(isp, src->ct_timeout, &dst->ct_timeout);
2947 	ISP_IOXPUT_16(isp, src->ct_seg_count, &dst->ct_seg_count);
2948 	ISP_IOXPUT_32(isp, src->ct_resid, &dst->ct_resid);
2949 	ISP_IOXPUT_32(isp, src->ct_reloff, &dst->ct_reloff);
2950 	if ((src->ct_flags & CT2_FLAG_MMASK) == CT2_FLAG_MODE0) {
2951 		ISP_IOXPUT_32(isp, src->rsp.m0._reserved, &dst->rsp.m0._reserved);
2952 		ISP_IOXPUT_16(isp, src->rsp.m0._reserved2, &dst->rsp.m0._reserved2);
2953 		ISP_IOXPUT_16(isp, src->rsp.m0.ct_scsi_status, &dst->rsp.m0.ct_scsi_status);
2954 		ISP_IOXPUT_32(isp, src->rsp.m0.ct_xfrlen, &dst->rsp.m0.ct_xfrlen);
2955 		if (src->ct_header.rqs_entry_type == RQSTYPE_CTIO2) {
2956 			for (i = 0; i < ISP_RQDSEG_T2; i++) {
2957 				ISP_IOXPUT_32(isp, src->rsp.m0.u.ct_dataseg[i].ds_base, &dst->rsp.m0.u.ct_dataseg[i].ds_base);
2958 				ISP_IOXPUT_32(isp, src->rsp.m0.u.ct_dataseg[i].ds_count, &dst->rsp.m0.u.ct_dataseg[i].ds_count);
2959 			}
2960 		} else if (src->ct_header.rqs_entry_type == RQSTYPE_CTIO3) {
2961 			for (i = 0; i < ISP_RQDSEG_T3; i++) {
2962 				ISP_IOXPUT_32(isp, src->rsp.m0.u.ct_dataseg64[i].ds_base, &dst->rsp.m0.u.ct_dataseg64[i].ds_base);
2963 				ISP_IOXPUT_32(isp, src->rsp.m0.u.ct_dataseg64[i].ds_basehi, &dst->rsp.m0.u.ct_dataseg64[i].ds_basehi);
2964 				ISP_IOXPUT_32(isp, src->rsp.m0.u.ct_dataseg64[i].ds_count, &dst->rsp.m0.u.ct_dataseg64[i].ds_count);
2965 			}
2966 		} else if (src->ct_header.rqs_entry_type == RQSTYPE_CTIO4) {
2967 			ISP_IOXPUT_16(isp, src->rsp.m0.u.ct_dslist.ds_type, &dst->rsp.m0.u.ct_dslist.ds_type); ISP_IOXPUT_32(isp, src->rsp.m0.u.ct_dslist.ds_segment,
2968 			    &dst->rsp.m0.u.ct_dslist.ds_segment);
2969 			ISP_IOXPUT_32(isp, src->rsp.m0.u.ct_dslist.ds_base, &dst->rsp.m0.u.ct_dslist.ds_base);
2970 		}
2971 	} else if ((src->ct_flags & CT2_FLAG_MMASK) == CT2_FLAG_MODE1) {
2972 		ISP_IOXPUT_16(isp, src->rsp.m1._reserved, &dst->rsp.m1._reserved);
2973 		ISP_IOXPUT_16(isp, src->rsp.m1._reserved2, &dst->rsp.m1._reserved2);
2974 		ISP_IOXPUT_16(isp, src->rsp.m1.ct_senselen, &dst->rsp.m1.ct_senselen);
2975 		ISP_IOXPUT_16(isp, src->rsp.m1.ct_scsi_status, &dst->rsp.m1.ct_scsi_status);
2976 		ISP_IOXPUT_16(isp, src->rsp.m1.ct_resplen, &dst->rsp.m1.ct_resplen);
2977 		for (i = 0; i < MAXRESPLEN; i++) {
2978 			ISP_IOXPUT_8(isp, src->rsp.m1.ct_resp[i], &dst->rsp.m1.ct_resp[i]);
2979 		}
2980 	} else {
2981 		ISP_IOXPUT_32(isp, src->rsp.m2._reserved, &dst->rsp.m2._reserved);
2982 		ISP_IOXPUT_16(isp, src->rsp.m2._reserved2, &dst->rsp.m2._reserved2);
2983 		ISP_IOXPUT_16(isp, src->rsp.m2._reserved3, &dst->rsp.m2._reserved3);
2984 		ISP_IOXPUT_32(isp, src->rsp.m2.ct_datalen, &dst->rsp.m2.ct_datalen);
2985 		if (src->ct_header.rqs_entry_type == RQSTYPE_CTIO2) {
2986 			ISP_IOXPUT_32(isp, src->rsp.m2.u.ct_fcp_rsp_iudata_32.ds_base, &dst->rsp.m2.u.ct_fcp_rsp_iudata_32.ds_base);
2987 			ISP_IOXPUT_32(isp, src->rsp.m2.u.ct_fcp_rsp_iudata_32.ds_count, &dst->rsp.m2.u.ct_fcp_rsp_iudata_32.ds_count);
2988 		} else {
2989 			ISP_IOXPUT_32(isp, src->rsp.m2.u.ct_fcp_rsp_iudata_64.ds_base, &dst->rsp.m2.u.ct_fcp_rsp_iudata_64.ds_base);
2990 			ISP_IOXPUT_32(isp, src->rsp.m2.u.ct_fcp_rsp_iudata_64.ds_basehi, &dst->rsp.m2.u.ct_fcp_rsp_iudata_64.ds_basehi);
2991 			ISP_IOXPUT_32(isp, src->rsp.m2.u.ct_fcp_rsp_iudata_64.ds_count, &dst->rsp.m2.u.ct_fcp_rsp_iudata_64.ds_count);
2992 		}
2993 	}
2994 }
2995 
2996 void
2997 isp_put_ctio2e(ispsoftc_t *isp, ct2e_entry_t *src, ct2e_entry_t *dst)
2998 {
2999 	int i;
3000 	isp_put_hdr(isp, &src->ct_header, &dst->ct_header);
3001 	ISP_IOXPUT_32(isp, src->ct_syshandle, &dst->ct_syshandle);
3002 	ISP_IOXPUT_16(isp, src->ct_iid, &dst->ct_iid);
3003 	ISP_IOXPUT_16(isp, src->ct_rxid, &dst->ct_rxid);
3004 	ISP_IOXPUT_16(isp, src->ct_flags, &dst->ct_flags);
3005 	ISP_IOXPUT_16(isp, src->ct_timeout, &dst->ct_timeout);
3006 	ISP_IOXPUT_16(isp, src->ct_seg_count, &dst->ct_seg_count);
3007 	ISP_IOXPUT_32(isp, src->ct_resid, &dst->ct_resid);
3008 	ISP_IOXPUT_32(isp, src->ct_reloff, &dst->ct_reloff);
3009 	if ((src->ct_flags & CT2_FLAG_MMASK) == CT2_FLAG_MODE0) {
3010 		ISP_IOXPUT_32(isp, src->rsp.m0._reserved, &dst->rsp.m0._reserved);
3011 		ISP_IOXPUT_16(isp, src->rsp.m0._reserved2, &dst->rsp.m0._reserved2);
3012 		ISP_IOXPUT_16(isp, src->rsp.m0.ct_scsi_status, &dst->rsp.m0.ct_scsi_status);
3013 		ISP_IOXPUT_32(isp, src->rsp.m0.ct_xfrlen, &dst->rsp.m0.ct_xfrlen);
3014 		if (src->ct_header.rqs_entry_type == RQSTYPE_CTIO2) {
3015 			for (i = 0; i < ISP_RQDSEG_T2; i++) {
3016 				ISP_IOXPUT_32(isp, src->rsp.m0.u.ct_dataseg[i].ds_base, &dst->rsp.m0.u.ct_dataseg[i].ds_base);
3017 				ISP_IOXPUT_32(isp, src->rsp.m0.u.ct_dataseg[i].ds_count, &dst->rsp.m0.u.ct_dataseg[i].ds_count);
3018 			}
3019 		} else if (src->ct_header.rqs_entry_type == RQSTYPE_CTIO3) {
3020 			for (i = 0; i < ISP_RQDSEG_T3; i++) {
3021 				ISP_IOXPUT_32(isp, src->rsp.m0.u.ct_dataseg64[i].ds_base, &dst->rsp.m0.u.ct_dataseg64[i].ds_base);
3022 				ISP_IOXPUT_32(isp, src->rsp.m0.u.ct_dataseg64[i].ds_basehi, &dst->rsp.m0.u.ct_dataseg64[i].ds_basehi);
3023 				ISP_IOXPUT_32(isp, src->rsp.m0.u.ct_dataseg64[i].ds_count, &dst->rsp.m0.u.ct_dataseg64[i].ds_count);
3024 			}
3025 		} else if (src->ct_header.rqs_entry_type == RQSTYPE_CTIO4) {
3026 			ISP_IOXPUT_16(isp, src->rsp.m0.u.ct_dslist.ds_type, &dst->rsp.m0.u.ct_dslist.ds_type);
3027 			ISP_IOXPUT_32(isp, src->rsp.m0.u.ct_dslist.ds_segment, &dst->rsp.m0.u.ct_dslist.ds_segment);
3028 			ISP_IOXPUT_32(isp, src->rsp.m0.u.ct_dslist.ds_base, &dst->rsp.m0.u.ct_dslist.ds_base);
3029 		}
3030 	} else if ((src->ct_flags & CT2_FLAG_MMASK) == CT2_FLAG_MODE1) {
3031 		ISP_IOXPUT_16(isp, src->rsp.m1._reserved, &dst->rsp.m1._reserved);
3032 		ISP_IOXPUT_16(isp, src->rsp.m1._reserved2, &dst->rsp.m1._reserved2);
3033 		ISP_IOXPUT_16(isp, src->rsp.m1.ct_senselen, &dst->rsp.m1.ct_senselen);
3034 		ISP_IOXPUT_16(isp, src->rsp.m1.ct_scsi_status, &dst->rsp.m1.ct_scsi_status);
3035 		ISP_IOXPUT_16(isp, src->rsp.m1.ct_resplen, &dst->rsp.m1.ct_resplen);
3036 		for (i = 0; i < MAXRESPLEN; i++) {
3037 			ISP_IOXPUT_8(isp, src->rsp.m1.ct_resp[i], &dst->rsp.m1.ct_resp[i]);
3038 		}
3039 	} else {
3040 		ISP_IOXPUT_32(isp, src->rsp.m2._reserved, &dst->rsp.m2._reserved);
3041 		ISP_IOXPUT_16(isp, src->rsp.m2._reserved2, &dst->rsp.m2._reserved2);
3042 		ISP_IOXPUT_16(isp, src->rsp.m2._reserved3, &dst->rsp.m2._reserved3);
3043 		ISP_IOXPUT_32(isp, src->rsp.m2.ct_datalen, &dst->rsp.m2.ct_datalen);
3044 		if (src->ct_header.rqs_entry_type == RQSTYPE_CTIO2) {
3045 			ISP_IOXPUT_32(isp, src->rsp.m2.u.ct_fcp_rsp_iudata_32.ds_base, &dst->rsp.m2.u.ct_fcp_rsp_iudata_32.ds_base);
3046 			ISP_IOXPUT_32(isp, src->rsp.m2.u.ct_fcp_rsp_iudata_32.ds_count, &dst->rsp.m2.u.ct_fcp_rsp_iudata_32.ds_count);
3047 		} else {
3048 			ISP_IOXPUT_32(isp, src->rsp.m2.u.ct_fcp_rsp_iudata_64.ds_base, &dst->rsp.m2.u.ct_fcp_rsp_iudata_64.ds_base);
3049 			ISP_IOXPUT_32(isp, src->rsp.m2.u.ct_fcp_rsp_iudata_64.ds_basehi, &dst->rsp.m2.u.ct_fcp_rsp_iudata_64.ds_basehi);
3050 			ISP_IOXPUT_32(isp, src->rsp.m2.u.ct_fcp_rsp_iudata_64.ds_count, &dst->rsp.m2.u.ct_fcp_rsp_iudata_64.ds_count);
3051 		}
3052 	}
3053 }
3054 
3055 void
3056 isp_put_ctio7(ispsoftc_t *isp, ct7_entry_t *src, ct7_entry_t *dst)
3057 {
3058 	int i;
3059 
3060 	isp_put_hdr(isp, &src->ct_header, &dst->ct_header);
3061 	ISP_IOXPUT_32(isp, src->ct_syshandle, &dst->ct_syshandle);
3062 	ISP_IOXPUT_16(isp, src->ct_nphdl, &dst->ct_nphdl);
3063 	ISP_IOXPUT_16(isp, src->ct_timeout, &dst->ct_timeout);
3064 	ISP_IOXPUT_16(isp, src->ct_seg_count, &dst->ct_seg_count);
3065 	ISP_IOXPUT_8(isp, src->ct_vpidx, &dst->ct_vpidx);
3066 	ISP_IOXPUT_8(isp, src->ct_xflags, &dst->ct_xflags);
3067 	ISP_IOXPUT_16(isp, src->ct_iid_lo, &dst->ct_iid_lo);
3068 	ISP_IOXPUT_8(isp, src->ct_iid_hi, &dst->ct_iid_hi);
3069 	ISP_IOXPUT_8(isp, src->ct_reserved, &dst->ct_reserved);
3070 	ISP_IOXPUT_32(isp, src->ct_rxid, &dst->ct_rxid);
3071 	ISP_IOXPUT_16(isp, src->ct_senselen, &dst->ct_senselen);
3072 	ISP_IOXPUT_16(isp, src->ct_flags, &dst->ct_flags);
3073 	ISP_IOXPUT_32(isp, src->ct_resid, &dst->ct_resid);
3074 	ISP_IOXPUT_16(isp, src->ct_oxid, &dst->ct_oxid);
3075 	ISP_IOXPUT_16(isp, src->ct_scsi_status, &dst->ct_scsi_status);
3076 	if ((dst->ct_flags & CT7_FLAG_MMASK) == CT7_FLAG_MODE0) {
3077 		ISP_IOXPUT_32(isp, src->rsp.m0.reloff, &dst->rsp.m0.reloff);
3078 		ISP_IOXPUT_32(isp, src->rsp.m0.reserved0, &dst->rsp.m0.reserved0);
3079 		ISP_IOXPUT_32(isp, src->rsp.m0.ct_xfrlen, &dst->rsp.m0.ct_xfrlen);
3080 		ISP_IOXPUT_32(isp, src->rsp.m0.reserved1, &dst->rsp.m0.reserved1);
3081 		ISP_IOXPUT_32(isp, src->rsp.m0.ds.ds_base, &dst->rsp.m0.ds.ds_base);
3082 		ISP_IOXPUT_32(isp, src->rsp.m0.ds.ds_basehi, &dst->rsp.m0.ds.ds_basehi);
3083 		ISP_IOXPUT_32(isp, src->rsp.m0.ds.ds_count, &dst->rsp.m0.ds.ds_count);
3084 	} else if ((dst->ct_flags & CT7_FLAG_MMASK) == CT7_FLAG_MODE1) {
3085 		uint32_t *a, *b;
3086 
3087 		ISP_IOXPUT_16(isp, src->rsp.m1.ct_resplen, &dst->rsp.m1.ct_resplen);
3088 		ISP_IOXPUT_16(isp, src->rsp.m1.reserved, &dst->rsp.m1.reserved);
3089 		a = (uint32_t *) src->rsp.m1.ct_resp;
3090 		b = (uint32_t *) dst->rsp.m1.ct_resp;
3091 		for (i = 0; i < (ASIZE(src->rsp.m1.ct_resp) >> 2); i++) {
3092 			*b++ = ISP_SWAP32(isp, *a++);
3093 		}
3094 	} else {
3095 		ISP_IOXPUT_32(isp, src->rsp.m2.reserved0, &dst->rsp.m2.reserved0);
3096 		ISP_IOXPUT_32(isp, src->rsp.m2.reserved1, &dst->rsp.m2.reserved1);
3097 		ISP_IOXPUT_32(isp, src->rsp.m2.ct_datalen, &dst->rsp.m2.ct_datalen);
3098 		ISP_IOXPUT_32(isp, src->rsp.m2.reserved2, &dst->rsp.m2.reserved2);
3099 		ISP_IOXPUT_32(isp, src->rsp.m2.ct_fcp_rsp_iudata.ds_base, &dst->rsp.m2.ct_fcp_rsp_iudata.ds_base);
3100 		ISP_IOXPUT_32(isp, src->rsp.m2.ct_fcp_rsp_iudata.ds_basehi, &dst->rsp.m2.ct_fcp_rsp_iudata.ds_basehi);
3101 		ISP_IOXPUT_32(isp, src->rsp.m2.ct_fcp_rsp_iudata.ds_count, &dst->rsp.m2.ct_fcp_rsp_iudata.ds_count);
3102 	}
3103 }
3104 
3105 
3106 void
3107 isp_get_ctio2(ispsoftc_t *isp, ct2_entry_t *src, ct2_entry_t *dst)
3108 {
3109 	int i;
3110 
3111 	isp_get_hdr(isp, &src->ct_header, &dst->ct_header);
3112 	ISP_IOXGET_32(isp, &src->ct_syshandle, dst->ct_syshandle);
3113 	ISP_IOXGET_8(isp, &src->ct_lun, dst->ct_lun);
3114 	ISP_IOXGET_8(isp, &src->ct_iid, dst->ct_iid);
3115 	ISP_IOXGET_16(isp, &src->ct_rxid, dst->ct_rxid);
3116 	ISP_IOXGET_16(isp, &src->ct_flags, dst->ct_flags);
3117 	ISP_IOXGET_16(isp, &src->ct_status, dst->ct_status);
3118 	ISP_IOXGET_16(isp, &src->ct_timeout, dst->ct_timeout);
3119 	ISP_IOXGET_16(isp, &src->ct_seg_count, dst->ct_seg_count);
3120 	ISP_IOXGET_32(isp, &src->ct_reloff, dst->ct_reloff);
3121 	ISP_IOXGET_32(isp, &src->ct_resid, dst->ct_resid);
3122 	if ((dst->ct_flags & CT2_FLAG_MMASK) == CT2_FLAG_MODE0) {
3123 		ISP_IOXGET_32(isp, &src->rsp.m0._reserved, dst->rsp.m0._reserved);
3124 		ISP_IOXGET_16(isp, &src->rsp.m0._reserved2, dst->rsp.m0._reserved2);
3125 		ISP_IOXGET_16(isp, &src->rsp.m0.ct_scsi_status, dst->rsp.m0.ct_scsi_status);
3126 		ISP_IOXGET_32(isp, &src->rsp.m0.ct_xfrlen, dst->rsp.m0.ct_xfrlen);
3127 		if (dst->ct_header.rqs_entry_type == RQSTYPE_CTIO2) {
3128 			for (i = 0; i < ISP_RQDSEG_T2; i++) {
3129 				ISP_IOXGET_32(isp, &src->rsp.m0.u.ct_dataseg[i].ds_base, dst->rsp.m0.u.ct_dataseg[i].ds_base);
3130 				ISP_IOXGET_32(isp, &src->rsp.m0.u.ct_dataseg[i].ds_count, dst->rsp.m0.u.ct_dataseg[i].ds_count);
3131 			}
3132 		} else if (dst->ct_header.rqs_entry_type == RQSTYPE_CTIO3) {
3133 			for (i = 0; i < ISP_RQDSEG_T3; i++) {
3134 				ISP_IOXGET_32(isp, &src->rsp.m0.u.ct_dataseg64[i].ds_base, dst->rsp.m0.u.ct_dataseg64[i].ds_base);
3135 				ISP_IOXGET_32(isp, &src->rsp.m0.u.ct_dataseg64[i].ds_basehi, dst->rsp.m0.u.ct_dataseg64[i].ds_basehi);
3136 				ISP_IOXGET_32(isp, &src->rsp.m0.u.ct_dataseg64[i].ds_count, dst->rsp.m0.u.ct_dataseg64[i].ds_count);
3137 			}
3138 		} else if (dst->ct_header.rqs_entry_type == RQSTYPE_CTIO4) {
3139 			ISP_IOXGET_16(isp, &src->rsp.m0.u.ct_dslist.ds_type, dst->rsp.m0.u.ct_dslist.ds_type);
3140 			ISP_IOXGET_32(isp, &src->rsp.m0.u.ct_dslist.ds_segment, dst->rsp.m0.u.ct_dslist.ds_segment);
3141 			ISP_IOXGET_32(isp, &src->rsp.m0.u.ct_dslist.ds_base, dst->rsp.m0.u.ct_dslist.ds_base);
3142 		}
3143 	} else if ((dst->ct_flags & CT2_FLAG_MMASK) == CT2_FLAG_MODE1) {
3144 		ISP_IOXGET_16(isp, &src->rsp.m1._reserved, dst->rsp.m1._reserved);
3145 		ISP_IOXGET_16(isp, &src->rsp.m1._reserved2, dst->rsp.m1._reserved2);
3146 		ISP_IOXGET_16(isp, &src->rsp.m1.ct_senselen, dst->rsp.m1.ct_senselen);
3147 		ISP_IOXGET_16(isp, &src->rsp.m1.ct_scsi_status, dst->rsp.m1.ct_scsi_status);
3148 		ISP_IOXGET_16(isp, &src->rsp.m1.ct_resplen, dst->rsp.m1.ct_resplen);
3149 		for (i = 0; i < MAXRESPLEN; i++) {
3150 			ISP_IOXGET_8(isp, &src->rsp.m1.ct_resp[i], dst->rsp.m1.ct_resp[i]);
3151 		}
3152 	} else {
3153 		ISP_IOXGET_32(isp, &src->rsp.m2._reserved, dst->rsp.m2._reserved);
3154 		ISP_IOXGET_16(isp, &src->rsp.m2._reserved2, dst->rsp.m2._reserved2);
3155 		ISP_IOXGET_16(isp, &src->rsp.m2._reserved3, dst->rsp.m2._reserved3);
3156 		ISP_IOXGET_32(isp, &src->rsp.m2.ct_datalen, dst->rsp.m2.ct_datalen);
3157 		if (src->ct_header.rqs_entry_type == RQSTYPE_CTIO2) {
3158 			ISP_IOXGET_32(isp, &src->rsp.m2.u.ct_fcp_rsp_iudata_32.ds_base, dst->rsp.m2.u.ct_fcp_rsp_iudata_32.ds_base);
3159 			ISP_IOXGET_32(isp, &src->rsp.m2.u.ct_fcp_rsp_iudata_32.ds_count, dst->rsp.m2.u.ct_fcp_rsp_iudata_32.ds_count);
3160 		} else {
3161 			ISP_IOXGET_32(isp, &src->rsp.m2.u.ct_fcp_rsp_iudata_64.ds_base, dst->rsp.m2.u.ct_fcp_rsp_iudata_64.ds_base);
3162 			ISP_IOXGET_32(isp, &src->rsp.m2.u.ct_fcp_rsp_iudata_64.ds_basehi, dst->rsp.m2.u.ct_fcp_rsp_iudata_64.ds_basehi);
3163 			ISP_IOXGET_32(isp, &src->rsp.m2.u.ct_fcp_rsp_iudata_64.ds_count, dst->rsp.m2.u.ct_fcp_rsp_iudata_64.ds_count);
3164 		}
3165 	}
3166 }
3167 
3168 void
3169 isp_get_ctio2e(ispsoftc_t *isp, ct2e_entry_t *src, ct2e_entry_t *dst)
3170 {
3171 	int i;
3172 
3173 	isp_get_hdr(isp, &src->ct_header, &dst->ct_header);
3174 	ISP_IOXGET_32(isp, &src->ct_syshandle, dst->ct_syshandle);
3175 	ISP_IOXGET_16(isp, &src->ct_iid, dst->ct_iid);
3176 	ISP_IOXGET_16(isp, &src->ct_rxid, dst->ct_rxid);
3177 	ISP_IOXGET_16(isp, &src->ct_flags, dst->ct_flags);
3178 	ISP_IOXGET_16(isp, &src->ct_status, dst->ct_status);
3179 	ISP_IOXGET_16(isp, &src->ct_timeout, dst->ct_timeout);
3180 	ISP_IOXGET_16(isp, &src->ct_seg_count, dst->ct_seg_count);
3181 	ISP_IOXGET_32(isp, &src->ct_reloff, dst->ct_reloff);
3182 	ISP_IOXGET_32(isp, &src->ct_resid, dst->ct_resid);
3183 	if ((dst->ct_flags & CT2_FLAG_MMASK) == CT2_FLAG_MODE0) {
3184 		ISP_IOXGET_32(isp, &src->rsp.m0._reserved, dst->rsp.m0._reserved);
3185 		ISP_IOXGET_16(isp, &src->rsp.m0._reserved2, dst->rsp.m0._reserved2);
3186 		ISP_IOXGET_16(isp, &src->rsp.m0.ct_scsi_status, dst->rsp.m0.ct_scsi_status);
3187 		ISP_IOXGET_32(isp, &src->rsp.m0.ct_xfrlen, dst->rsp.m0.ct_xfrlen);
3188 		if (src->ct_header.rqs_entry_type == RQSTYPE_CTIO2) {
3189 			for (i = 0; i < ISP_RQDSEG_T2; i++) {
3190 				ISP_IOXGET_32(isp, &src->rsp.m0.u.ct_dataseg[i].ds_base, dst->rsp.m0.u.ct_dataseg[i].ds_base);
3191 				ISP_IOXGET_32(isp, &src->rsp.m0.u.ct_dataseg[i].ds_count, dst->rsp.m0.u.ct_dataseg[i].ds_count);
3192 			}
3193 		} else if (dst->ct_header.rqs_entry_type == RQSTYPE_CTIO3) {
3194 			for (i = 0; i < ISP_RQDSEG_T3; i++) {
3195 				ISP_IOXGET_32(isp, &src->rsp.m0.u.ct_dataseg64[i].ds_base, dst->rsp.m0.u.ct_dataseg64[i].ds_base);
3196 				ISP_IOXGET_32(isp, &src->rsp.m0.u.ct_dataseg64[i].ds_basehi, dst->rsp.m0.u.ct_dataseg64[i].ds_basehi);
3197 				ISP_IOXGET_32(isp, &src->rsp.m0.u.ct_dataseg64[i].ds_count, dst->rsp.m0.u.ct_dataseg64[i].ds_count);
3198 			}
3199 		} else if (dst->ct_header.rqs_entry_type == RQSTYPE_CTIO4) {
3200 			ISP_IOXGET_16(isp, &src->rsp.m0.u.ct_dslist.ds_type, dst->rsp.m0.u.ct_dslist.ds_type);
3201 			ISP_IOXGET_32(isp, &src->rsp.m0.u.ct_dslist.ds_segment, dst->rsp.m0.u.ct_dslist.ds_segment);
3202 			ISP_IOXGET_32(isp, &src->rsp.m0.u.ct_dslist.ds_base, dst->rsp.m0.u.ct_dslist.ds_base);
3203 		}
3204 	} else if ((dst->ct_flags & CT2_FLAG_MMASK) == CT2_FLAG_MODE1) {
3205 		ISP_IOXGET_16(isp, &src->rsp.m1._reserved, dst->rsp.m1._reserved);
3206 		ISP_IOXGET_16(isp, &src->rsp.m1._reserved2, dst->rsp.m1._reserved2);
3207 		ISP_IOXGET_16(isp, &src->rsp.m1.ct_senselen, dst->rsp.m1.ct_senselen);
3208 		ISP_IOXGET_16(isp, &src->rsp.m1.ct_scsi_status, dst->rsp.m1.ct_scsi_status);
3209 		ISP_IOXGET_16(isp, &src->rsp.m1.ct_resplen, dst->rsp.m1.ct_resplen);
3210 		for (i = 0; i < MAXRESPLEN; i++) {
3211 			ISP_IOXGET_8(isp, &src->rsp.m1.ct_resp[i], dst->rsp.m1.ct_resp[i]);
3212 		}
3213 	} else {
3214 		ISP_IOXGET_32(isp, &src->rsp.m2._reserved, dst->rsp.m2._reserved);
3215 		ISP_IOXGET_16(isp, &src->rsp.m2._reserved2, dst->rsp.m2._reserved2);
3216 		ISP_IOXGET_16(isp, &src->rsp.m2._reserved3, dst->rsp.m2._reserved3);
3217 		ISP_IOXGET_32(isp, &src->rsp.m2.ct_datalen, dst->rsp.m2.ct_datalen);
3218 		if (src->ct_header.rqs_entry_type == RQSTYPE_CTIO2) {
3219 			ISP_IOXGET_32(isp, &src->rsp.m2.u.ct_fcp_rsp_iudata_32.ds_base, dst->rsp.m2.u.ct_fcp_rsp_iudata_32.ds_base);
3220 			ISP_IOXGET_32(isp, &src->rsp.m2.u.ct_fcp_rsp_iudata_32.ds_count, dst->rsp.m2.u.ct_fcp_rsp_iudata_32.ds_count);
3221 		} else {
3222 			ISP_IOXGET_32(isp, &src->rsp.m2.u.ct_fcp_rsp_iudata_64.ds_base, dst->rsp.m2.u.ct_fcp_rsp_iudata_64.ds_base);
3223 			ISP_IOXGET_32(isp, &src->rsp.m2.u.ct_fcp_rsp_iudata_64.ds_basehi, dst->rsp.m2.u.ct_fcp_rsp_iudata_64.ds_basehi);
3224 			ISP_IOXGET_32(isp, &src->rsp.m2.u.ct_fcp_rsp_iudata_64.ds_count, dst->rsp.m2.u.ct_fcp_rsp_iudata_64.ds_count);
3225 		}
3226 	}
3227 }
3228 
3229 void
3230 isp_get_ctio7(ispsoftc_t *isp, ct7_entry_t *src, ct7_entry_t *dst)
3231 {
3232 	int i;
3233 
3234 	isp_get_hdr(isp, &src->ct_header, &dst->ct_header);
3235 	ISP_IOXGET_32(isp, &src->ct_syshandle, dst->ct_syshandle);
3236 	ISP_IOXGET_16(isp, &src->ct_nphdl, dst->ct_nphdl);
3237 	ISP_IOXGET_16(isp, &src->ct_timeout, dst->ct_timeout);
3238 	ISP_IOXGET_16(isp, &src->ct_seg_count, dst->ct_seg_count);
3239 	ISP_IOXGET_8(isp, &src->ct_vpidx, dst->ct_vpidx);
3240 	ISP_IOXGET_8(isp, &src->ct_xflags, dst->ct_xflags);
3241 	ISP_IOXGET_16(isp, &src->ct_iid_lo, dst->ct_iid_lo);
3242 	ISP_IOXGET_8(isp, &src->ct_iid_hi, dst->ct_iid_hi);
3243 	ISP_IOXGET_8(isp, &src->ct_reserved, dst->ct_reserved);
3244 	ISP_IOXGET_32(isp, &src->ct_rxid, dst->ct_rxid);
3245 	ISP_IOXGET_16(isp, &src->ct_senselen, dst->ct_senselen);
3246 	ISP_IOXGET_16(isp, &src->ct_flags, dst->ct_flags);
3247 	ISP_IOXGET_32(isp, &src->ct_resid, dst->ct_resid);
3248 	ISP_IOXGET_16(isp, &src->ct_oxid, dst->ct_oxid);
3249 	ISP_IOXGET_16(isp, &src->ct_scsi_status, dst->ct_scsi_status);
3250 	if ((dst->ct_flags & CT7_FLAG_MMASK) == CT7_FLAG_MODE0) {
3251 		ISP_IOXGET_32(isp, &src->rsp.m0.reloff, dst->rsp.m0.reloff);
3252 		ISP_IOXGET_32(isp, &src->rsp.m0.reserved0, dst->rsp.m0.reserved0);
3253 		ISP_IOXGET_32(isp, &src->rsp.m0.ct_xfrlen, dst->rsp.m0.ct_xfrlen);
3254 		ISP_IOXGET_32(isp, &src->rsp.m0.reserved1, dst->rsp.m0.reserved1);
3255 		ISP_IOXGET_32(isp, &src->rsp.m0.ds.ds_base, dst->rsp.m0.ds.ds_base);
3256 		ISP_IOXGET_32(isp, &src->rsp.m0.ds.ds_basehi, dst->rsp.m0.ds.ds_basehi);
3257 		ISP_IOXGET_32(isp, &src->rsp.m0.ds.ds_count, dst->rsp.m0.ds.ds_count);
3258 	} else if ((dst->ct_flags & CT7_FLAG_MMASK) == CT7_FLAG_MODE1) {
3259 		uint32_t *a, *b;
3260 
3261 		ISP_IOXGET_16(isp, &src->rsp.m1.ct_resplen, dst->rsp.m1.ct_resplen);
3262 		ISP_IOXGET_16(isp, &src->rsp.m1.reserved, dst->rsp.m1.reserved);
3263 		a = (uint32_t *) src->rsp.m1.ct_resp;
3264 		b = (uint32_t *) dst->rsp.m1.ct_resp;
3265 		for (i = 0; i < MAXRESPLEN_24XX; i++) {
3266 			ISP_IOXGET_8(isp, &src->rsp.m1.ct_resp[i], dst->rsp.m1.ct_resp[i]);
3267 		}
3268 		for (i = 0; i < (ASIZE(src->rsp.m1.ct_resp) >> 2); i++) {
3269 			*b++ = ISP_SWAP32(isp, *a++);
3270 		}
3271 	} else {
3272 		ISP_IOXGET_32(isp, &src->rsp.m2.reserved0, dst->rsp.m2.reserved0);
3273 		ISP_IOXGET_32(isp, &src->rsp.m2.ct_datalen, dst->rsp.m2.ct_datalen);
3274 		ISP_IOXGET_32(isp, &src->rsp.m2.reserved1, dst->rsp.m2.reserved1);
3275 		ISP_IOXGET_32(isp, &src->rsp.m2.ct_fcp_rsp_iudata.ds_base, dst->rsp.m2.ct_fcp_rsp_iudata.ds_base);
3276 		ISP_IOXGET_32(isp, &src->rsp.m2.ct_fcp_rsp_iudata.ds_basehi, dst->rsp.m2.ct_fcp_rsp_iudata.ds_basehi);
3277 		ISP_IOXGET_32(isp, &src->rsp.m2.ct_fcp_rsp_iudata.ds_count, dst->rsp.m2.ct_fcp_rsp_iudata.ds_count);
3278 	}
3279 }
3280 
3281 void
3282 isp_put_enable_lun(ispsoftc_t *isp, lun_entry_t *lesrc, lun_entry_t *ledst)
3283 {
3284 	int i;
3285 	isp_put_hdr(isp, &lesrc->le_header, &ledst->le_header);
3286 	ISP_IOXPUT_32(isp, lesrc->le_reserved, &ledst->le_reserved);
3287 	if (ISP_IS_SBUS(isp)) {
3288 		ISP_IOXPUT_8(isp, lesrc->le_lun, &ledst->le_rsvd);
3289 		ISP_IOXPUT_8(isp, lesrc->le_rsvd, &ledst->le_lun);
3290 		ISP_IOXPUT_8(isp, lesrc->le_ops, &ledst->le_tgt);
3291 		ISP_IOXPUT_8(isp, lesrc->le_tgt, &ledst->le_ops);
3292 		ISP_IOXPUT_8(isp, lesrc->le_status, &ledst->le_reserved2);
3293 		ISP_IOXPUT_8(isp, lesrc->le_reserved2, &ledst->le_status);
3294 		ISP_IOXPUT_8(isp, lesrc->le_cmd_count, &ledst->le_in_count);
3295 		ISP_IOXPUT_8(isp, lesrc->le_in_count, &ledst->le_cmd_count);
3296 		ISP_IOXPUT_8(isp, lesrc->le_cdb6len, &ledst->le_cdb7len);
3297 		ISP_IOXPUT_8(isp, lesrc->le_cdb7len, &ledst->le_cdb6len);
3298 	} else {
3299 		ISP_IOXPUT_8(isp, lesrc->le_lun, &ledst->le_lun);
3300 		ISP_IOXPUT_8(isp, lesrc->le_rsvd, &ledst->le_rsvd);
3301 		ISP_IOXPUT_8(isp, lesrc->le_ops, &ledst->le_ops);
3302 		ISP_IOXPUT_8(isp, lesrc->le_tgt, &ledst->le_tgt);
3303 		ISP_IOXPUT_8(isp, lesrc->le_status, &ledst->le_status);
3304 		ISP_IOXPUT_8(isp, lesrc->le_reserved2, &ledst->le_reserved2);
3305 		ISP_IOXPUT_8(isp, lesrc->le_cmd_count, &ledst->le_cmd_count);
3306 		ISP_IOXPUT_8(isp, lesrc->le_in_count, &ledst->le_in_count);
3307 		ISP_IOXPUT_8(isp, lesrc->le_cdb6len, &ledst->le_cdb6len);
3308 		ISP_IOXPUT_8(isp, lesrc->le_cdb7len, &ledst->le_cdb7len);
3309 	}
3310 	ISP_IOXPUT_32(isp, lesrc->le_flags, &ledst->le_flags);
3311 	ISP_IOXPUT_16(isp, lesrc->le_timeout, &ledst->le_timeout);
3312 	for (i = 0; i < 20; i++) {
3313 		ISP_IOXPUT_8(isp, lesrc->le_reserved3[i], &ledst->le_reserved3[i]);
3314 	}
3315 }
3316 
3317 void
3318 isp_get_enable_lun(ispsoftc_t *isp, lun_entry_t *lesrc, lun_entry_t *ledst)
3319 {
3320 	int i;
3321 	isp_get_hdr(isp, &lesrc->le_header, &ledst->le_header);
3322 	ISP_IOXGET_32(isp, &lesrc->le_reserved, ledst->le_reserved);
3323 	if (ISP_IS_SBUS(isp)) {
3324 		ISP_IOXGET_8(isp, &lesrc->le_lun, ledst->le_rsvd);
3325 		ISP_IOXGET_8(isp, &lesrc->le_rsvd, ledst->le_lun);
3326 		ISP_IOXGET_8(isp, &lesrc->le_ops, ledst->le_tgt);
3327 		ISP_IOXGET_8(isp, &lesrc->le_tgt, ledst->le_ops);
3328 		ISP_IOXGET_8(isp, &lesrc->le_status, ledst->le_reserved2);
3329 		ISP_IOXGET_8(isp, &lesrc->le_reserved2, ledst->le_status);
3330 		ISP_IOXGET_8(isp, &lesrc->le_cmd_count, ledst->le_in_count);
3331 		ISP_IOXGET_8(isp, &lesrc->le_in_count, ledst->le_cmd_count);
3332 		ISP_IOXGET_8(isp, &lesrc->le_cdb6len, ledst->le_cdb7len);
3333 		ISP_IOXGET_8(isp, &lesrc->le_cdb7len, ledst->le_cdb6len);
3334 	} else {
3335 		ISP_IOXGET_8(isp, &lesrc->le_lun, ledst->le_lun);
3336 		ISP_IOXGET_8(isp, &lesrc->le_rsvd, ledst->le_rsvd);
3337 		ISP_IOXGET_8(isp, &lesrc->le_ops, ledst->le_ops);
3338 		ISP_IOXGET_8(isp, &lesrc->le_tgt, ledst->le_tgt);
3339 		ISP_IOXGET_8(isp, &lesrc->le_status, ledst->le_status);
3340 		ISP_IOXGET_8(isp, &lesrc->le_reserved2, ledst->le_reserved2);
3341 		ISP_IOXGET_8(isp, &lesrc->le_cmd_count, ledst->le_cmd_count);
3342 		ISP_IOXGET_8(isp, &lesrc->le_in_count, ledst->le_in_count);
3343 		ISP_IOXGET_8(isp, &lesrc->le_cdb6len, ledst->le_cdb6len);
3344 		ISP_IOXGET_8(isp, &lesrc->le_cdb7len, ledst->le_cdb7len);
3345 	}
3346 	ISP_IOXGET_32(isp, &lesrc->le_flags, ledst->le_flags);
3347 	ISP_IOXGET_16(isp, &lesrc->le_timeout, ledst->le_timeout);
3348 	for (i = 0; i < 20; i++) {
3349 		ISP_IOXGET_8(isp, &lesrc->le_reserved3[i], ledst->le_reserved3[i]);
3350 	}
3351 }
3352 
3353 void
3354 isp_put_notify_fc(ispsoftc_t *isp, in_fcentry_t *src, in_fcentry_t *dst)
3355 {
3356 	isp_put_hdr(isp, &src->in_header, &dst->in_header);
3357 	ISP_IOXPUT_32(isp, src->in_reserved, &dst->in_reserved);
3358 	ISP_IOXPUT_8(isp, src->in_lun, &dst->in_lun);
3359 	ISP_IOXPUT_8(isp, src->in_iid, &dst->in_iid);
3360 	ISP_IOXPUT_16(isp, src->in_scclun, &dst->in_scclun);
3361 	ISP_IOXPUT_32(isp, src->in_reserved2, &dst->in_reserved2);
3362 	ISP_IOXPUT_16(isp, src->in_status, &dst->in_status);
3363 	ISP_IOXPUT_16(isp, src->in_task_flags, &dst->in_task_flags);
3364 	ISP_IOXPUT_16(isp, src->in_seqid, &dst->in_seqid);
3365 }
3366 
3367 void
3368 isp_put_notify_fc_e(ispsoftc_t *isp, in_fcentry_e_t *src, in_fcentry_e_t *dst)
3369 {
3370 	isp_put_hdr(isp, &src->in_header, &dst->in_header);
3371 	ISP_IOXPUT_32(isp, src->in_reserved, &dst->in_reserved);
3372 	ISP_IOXPUT_16(isp, src->in_iid, &dst->in_iid);
3373 	ISP_IOXPUT_16(isp, src->in_scclun, &dst->in_scclun);
3374 	ISP_IOXPUT_32(isp, src->in_reserved2, &dst->in_reserved2);
3375 	ISP_IOXPUT_16(isp, src->in_status, &dst->in_status);
3376 	ISP_IOXPUT_16(isp, src->in_task_flags, &dst->in_task_flags);
3377 	ISP_IOXPUT_16(isp, src->in_seqid, &dst->in_seqid);
3378 }
3379 
3380 void
3381 isp_put_notify_24xx(ispsoftc_t *isp, in_fcentry_24xx_t *src, in_fcentry_24xx_t *dst)
3382 {
3383 	int i;
3384 
3385 	isp_put_hdr(isp, &src->in_header, &dst->in_header);
3386 	ISP_IOXPUT_32(isp, src->in_reserved, &dst->in_reserved);
3387 	ISP_IOXPUT_16(isp, src->in_nphdl, &dst->in_nphdl);
3388 	ISP_IOXPUT_16(isp, src->in_reserved1, &dst->in_reserved1);
3389 	ISP_IOXPUT_16(isp, src->in_flags, &dst->in_flags);
3390 	ISP_IOXPUT_16(isp, src->in_srr_rxid, &dst->in_srr_rxid);
3391 	ISP_IOXPUT_16(isp, src->in_status, &dst->in_status);
3392 	ISP_IOXPUT_8(isp, src->in_status_subcode, &dst->in_status_subcode);
3393 	ISP_IOXPUT_8(isp, src->in_fwhandle, &dst->in_fwhandle);
3394 	ISP_IOXPUT_32(isp, src->in_rxid, &dst->in_rxid);
3395 	ISP_IOXPUT_16(isp, src->in_srr_reloff_hi, &dst->in_srr_reloff_hi);
3396 	ISP_IOXPUT_16(isp, src->in_srr_reloff_lo, &dst->in_srr_reloff_lo);
3397 	ISP_IOXPUT_16(isp, src->in_srr_iu, &dst->in_srr_iu);
3398 	ISP_IOXPUT_16(isp, src->in_srr_oxid, &dst->in_srr_oxid);
3399 	ISP_IOXPUT_16(isp, src->in_nport_id_hi, &dst->in_nport_id_hi);
3400 	ISP_IOXPUT_8(isp, src->in_nport_id_lo, &dst->in_nport_id_lo);
3401 	ISP_IOXPUT_8(isp, src->in_reserved3, &dst->in_reserved3);
3402 	ISP_IOXPUT_16(isp, src->in_np_handle, &dst->in_np_handle);
3403 	for (i = 0; i < ASIZE(src->in_reserved4); i++) {
3404 		ISP_IOXPUT_8(isp, src->in_reserved4[i], &dst->in_reserved4[i]);
3405 	}
3406 	ISP_IOXPUT_8(isp, src->in_reserved5, &dst->in_reserved5);
3407 	ISP_IOXPUT_8(isp, src->in_vpidx, &dst->in_vpidx);
3408 	ISP_IOXPUT_32(isp, src->in_reserved6, &dst->in_reserved6);
3409 	ISP_IOXPUT_16(isp, src->in_portid_lo, &dst->in_portid_lo);
3410 	ISP_IOXPUT_8(isp, src->in_portid_hi, &dst->in_portid_hi);
3411 	ISP_IOXPUT_8(isp, src->in_reserved7, &dst->in_reserved7);
3412 	ISP_IOXPUT_16(isp, src->in_reserved8, &dst->in_reserved8);
3413 	ISP_IOXPUT_16(isp, src->in_oxid, &dst->in_oxid);
3414 }
3415 
3416 void
3417 isp_get_notify_fc(ispsoftc_t *isp, in_fcentry_t *src, in_fcentry_t *dst)
3418 {
3419 	isp_get_hdr(isp, &src->in_header, &dst->in_header);
3420 	ISP_IOXGET_32(isp, &src->in_reserved, dst->in_reserved);
3421 	ISP_IOXGET_8(isp, &src->in_lun, dst->in_lun);
3422 	ISP_IOXGET_8(isp, &src->in_iid, dst->in_iid);
3423 	ISP_IOXGET_16(isp, &src->in_scclun, dst->in_scclun);
3424 	ISP_IOXGET_32(isp, &src->in_reserved2, dst->in_reserved2);
3425 	ISP_IOXGET_16(isp, &src->in_status, dst->in_status);
3426 	ISP_IOXGET_16(isp, &src->in_task_flags, dst->in_task_flags);
3427 	ISP_IOXGET_16(isp, &src->in_seqid, dst->in_seqid);
3428 }
3429 
3430 void
3431 isp_get_notify_fc_e(ispsoftc_t *isp, in_fcentry_e_t *src, in_fcentry_e_t *dst)
3432 {
3433 	isp_get_hdr(isp, &src->in_header, &dst->in_header);
3434 	ISP_IOXGET_32(isp, &src->in_reserved, dst->in_reserved);
3435 	ISP_IOXGET_16(isp, &src->in_iid, dst->in_iid);
3436 	ISP_IOXGET_16(isp, &src->in_scclun, dst->in_scclun);
3437 	ISP_IOXGET_32(isp, &src->in_reserved2, dst->in_reserved2);
3438 	ISP_IOXGET_16(isp, &src->in_status, dst->in_status);
3439 	ISP_IOXGET_16(isp, &src->in_task_flags, dst->in_task_flags);
3440 	ISP_IOXGET_16(isp, &src->in_seqid, dst->in_seqid);
3441 }
3442 
3443 void
3444 isp_get_notify_24xx(ispsoftc_t *isp, in_fcentry_24xx_t *src, in_fcentry_24xx_t *dst)
3445 {
3446 	int i;
3447 
3448 	isp_get_hdr(isp, &src->in_header, &dst->in_header);
3449 	ISP_IOXGET_32(isp, &src->in_reserved, dst->in_reserved);
3450 	ISP_IOXGET_16(isp, &src->in_nphdl, dst->in_nphdl);
3451 	ISP_IOXGET_16(isp, &src->in_reserved1, dst->in_reserved1);
3452 	ISP_IOXGET_16(isp, &src->in_flags, dst->in_flags);
3453 	ISP_IOXGET_16(isp, &src->in_srr_rxid, dst->in_srr_rxid);
3454 	ISP_IOXGET_16(isp, &src->in_status, dst->in_status);
3455 	ISP_IOXGET_8(isp, &src->in_status_subcode, dst->in_status_subcode);
3456 	ISP_IOXGET_8(isp, &src->in_fwhandle, dst->in_fwhandle);
3457 	ISP_IOXGET_32(isp, &src->in_rxid, dst->in_rxid);
3458 	ISP_IOXGET_16(isp, &src->in_srr_reloff_hi, dst->in_srr_reloff_hi);
3459 	ISP_IOXGET_16(isp, &src->in_srr_reloff_lo, dst->in_srr_reloff_lo);
3460 	ISP_IOXGET_16(isp, &src->in_srr_iu, dst->in_srr_iu);
3461 	ISP_IOXGET_16(isp, &src->in_srr_oxid, dst->in_srr_oxid);
3462 	ISP_IOXGET_16(isp, &src->in_nport_id_hi, dst->in_nport_id_hi);
3463 	ISP_IOXGET_8(isp, &src->in_nport_id_lo, dst->in_nport_id_lo);
3464 	ISP_IOXGET_8(isp, &src->in_reserved3, dst->in_reserved3);
3465 	ISP_IOXGET_16(isp, &src->in_np_handle, dst->in_np_handle);
3466 	for (i = 0; i < ASIZE(src->in_reserved4); i++) {
3467 		ISP_IOXGET_8(isp, &src->in_reserved4[i], dst->in_reserved4[i]);
3468 	}
3469 	ISP_IOXGET_8(isp, &src->in_reserved5, dst->in_reserved5);
3470 	ISP_IOXGET_8(isp, &src->in_vpidx, dst->in_vpidx);
3471 	ISP_IOXGET_32(isp, &src->in_reserved6, dst->in_reserved6);
3472 	ISP_IOXGET_16(isp, &src->in_portid_lo, dst->in_portid_lo);
3473 	ISP_IOXGET_8(isp, &src->in_portid_hi, dst->in_portid_hi);
3474 	ISP_IOXGET_8(isp, &src->in_reserved7, dst->in_reserved7);
3475 	ISP_IOXGET_16(isp, &src->in_reserved8, dst->in_reserved8);
3476 	ISP_IOXGET_16(isp, &src->in_oxid, dst->in_oxid);
3477 }
3478 
3479 void
3480 isp_put_notify_ack_fc(ispsoftc_t *isp, na_fcentry_t *src, na_fcentry_t *dst)
3481 {
3482 	int i;
3483 	isp_put_hdr(isp, &src->na_header, &dst->na_header);
3484 	ISP_IOXPUT_32(isp, src->na_reserved, &dst->na_reserved);
3485 	ISP_IOXPUT_8(isp, src->na_reserved1, &dst->na_reserved1);
3486 	ISP_IOXPUT_8(isp, src->na_iid, &dst->na_iid);
3487 	ISP_IOXPUT_16(isp, src->na_response, &dst->na_response);
3488 	ISP_IOXPUT_16(isp, src->na_flags, &dst->na_flags);
3489 	ISP_IOXPUT_16(isp, src->na_reserved2, &dst->na_reserved2);
3490 	ISP_IOXPUT_16(isp, src->na_status, &dst->na_status);
3491 	ISP_IOXPUT_16(isp, src->na_task_flags, &dst->na_task_flags);
3492 	ISP_IOXPUT_16(isp, src->na_seqid, &dst->na_seqid);
3493 	for (i = 0; i < NA2_RSVDLEN; i++) {
3494 		ISP_IOXPUT_16(isp, src->na_reserved3[i], &dst->na_reserved3[i]);
3495 	}
3496 }
3497 
3498 void
3499 isp_put_notify_ack_fc_e(ispsoftc_t *isp, na_fcentry_e_t *src, na_fcentry_e_t *dst)
3500 {
3501 	int i;
3502 	isp_put_hdr(isp, &src->na_header, &dst->na_header);
3503 	ISP_IOXPUT_32(isp, src->na_reserved, &dst->na_reserved);
3504 	ISP_IOXPUT_16(isp, src->na_iid, &dst->na_iid);
3505 	ISP_IOXPUT_16(isp, src->na_response, &dst->na_response);
3506 	ISP_IOXPUT_16(isp, src->na_flags, &dst->na_flags);
3507 	ISP_IOXPUT_16(isp, src->na_reserved2, &dst->na_reserved2);
3508 	ISP_IOXPUT_16(isp, src->na_status, &dst->na_status);
3509 	ISP_IOXPUT_16(isp, src->na_task_flags, &dst->na_task_flags);
3510 	ISP_IOXPUT_16(isp, src->na_seqid, &dst->na_seqid);
3511 	for (i = 0; i < NA2_RSVDLEN; i++) {
3512 		ISP_IOXPUT_16(isp, src->na_reserved3[i], &dst->na_reserved3[i]);
3513 	}
3514 }
3515 
3516 void
3517 isp_put_notify_24xx_ack(ispsoftc_t *isp, na_fcentry_24xx_t *src, na_fcentry_24xx_t *dst)
3518 {
3519 	int i;
3520 
3521 	isp_put_hdr(isp, &src->na_header, &dst->na_header);
3522 	ISP_IOXPUT_32(isp, src->na_handle, &dst->na_handle);
3523 	ISP_IOXPUT_16(isp, src->na_nphdl, &dst->na_nphdl);
3524 	ISP_IOXPUT_16(isp, src->na_reserved1, &dst->na_reserved1);
3525 	ISP_IOXPUT_16(isp, src->na_flags, &dst->na_flags);
3526 	ISP_IOXPUT_16(isp, src->na_srr_rxid, &dst->na_srr_rxid);
3527 	ISP_IOXPUT_16(isp, src->na_status, &dst->na_status);
3528 	ISP_IOXPUT_8(isp, src->na_status_subcode, &dst->na_status_subcode);
3529 	ISP_IOXPUT_8(isp, src->na_fwhandle, &dst->na_fwhandle);
3530 	ISP_IOXPUT_32(isp, src->na_rxid, &dst->na_rxid);
3531 	ISP_IOXPUT_16(isp, src->na_srr_reloff_hi, &dst->na_srr_reloff_hi);
3532 	ISP_IOXPUT_16(isp, src->na_srr_reloff_lo, &dst->na_srr_reloff_lo);
3533 	ISP_IOXPUT_16(isp, src->na_srr_iu, &dst->na_srr_iu);
3534 	ISP_IOXPUT_16(isp, src->na_srr_flags, &dst->na_srr_flags);
3535 	for (i = 0; i < 18; i++) {
3536 		ISP_IOXPUT_8(isp, src->na_reserved3[i], &dst->na_reserved3[i]);
3537 	}
3538 	ISP_IOXPUT_8(isp, src->na_reserved4, &dst->na_reserved4);
3539 	ISP_IOXPUT_8(isp, src->na_vpidx, &dst->na_vpidx);
3540 	ISP_IOXPUT_8(isp, src->na_srr_reject_vunique, &dst->na_srr_reject_vunique);
3541 	ISP_IOXPUT_8(isp, src->na_srr_reject_explanation, &dst->na_srr_reject_explanation);
3542 	ISP_IOXPUT_8(isp, src->na_srr_reject_code, &dst->na_srr_reject_code);
3543 	ISP_IOXPUT_8(isp, src->na_reserved5, &dst->na_reserved5);
3544 	for (i = 0; i < 6; i++) {
3545 		ISP_IOXPUT_8(isp, src->na_reserved6[i], &dst->na_reserved6[i]);
3546 	}
3547 	ISP_IOXPUT_16(isp, src->na_oxid, &dst->na_oxid);
3548 }
3549 
3550 void
3551 isp_get_notify_ack_fc(ispsoftc_t *isp, na_fcentry_t *src, na_fcentry_t *dst)
3552 {
3553 	int i;
3554 	isp_get_hdr(isp, &src->na_header, &dst->na_header);
3555 	ISP_IOXGET_32(isp, &src->na_reserved, dst->na_reserved);
3556 	ISP_IOXGET_8(isp, &src->na_reserved1, dst->na_reserved1);
3557 	ISP_IOXGET_8(isp, &src->na_iid, dst->na_iid);
3558 	ISP_IOXGET_16(isp, &src->na_response, dst->na_response);
3559 	ISP_IOXGET_16(isp, &src->na_flags, dst->na_flags);
3560 	ISP_IOXGET_16(isp, &src->na_reserved2, dst->na_reserved2);
3561 	ISP_IOXGET_16(isp, &src->na_status, dst->na_status);
3562 	ISP_IOXGET_16(isp, &src->na_task_flags, dst->na_task_flags);
3563 	ISP_IOXGET_16(isp, &src->na_seqid, dst->na_seqid);
3564 	for (i = 0; i < NA2_RSVDLEN; i++) {
3565 		ISP_IOXGET_16(isp, &src->na_reserved3[i], dst->na_reserved3[i]);
3566 	}
3567 }
3568 
3569 void
3570 isp_get_notify_ack_fc_e(ispsoftc_t *isp, na_fcentry_e_t *src, na_fcentry_e_t *dst)
3571 {
3572 	int i;
3573 	isp_get_hdr(isp, &src->na_header, &dst->na_header);
3574 	ISP_IOXGET_32(isp, &src->na_reserved, dst->na_reserved);
3575 	ISP_IOXGET_16(isp, &src->na_iid, dst->na_iid);
3576 	ISP_IOXGET_16(isp, &src->na_response, dst->na_response);
3577 	ISP_IOXGET_16(isp, &src->na_flags, dst->na_flags);
3578 	ISP_IOXGET_16(isp, &src->na_reserved2, dst->na_reserved2);
3579 	ISP_IOXGET_16(isp, &src->na_status, dst->na_status);
3580 	ISP_IOXGET_16(isp, &src->na_task_flags, dst->na_task_flags);
3581 	ISP_IOXGET_16(isp, &src->na_seqid, dst->na_seqid);
3582 	for (i = 0; i < NA2_RSVDLEN; i++) {
3583 		ISP_IOXGET_16(isp, &src->na_reserved3[i], dst->na_reserved3[i]);
3584 	}
3585 }
3586 
3587 void
3588 isp_get_notify_ack_24xx(ispsoftc_t *isp, na_fcentry_24xx_t *src, na_fcentry_24xx_t *dst)
3589 {
3590 	int i;
3591 
3592 	isp_get_hdr(isp, &src->na_header, &dst->na_header);
3593 	ISP_IOXGET_32(isp, &src->na_handle, dst->na_handle);
3594 	ISP_IOXGET_16(isp, &src->na_nphdl, dst->na_nphdl);
3595 	ISP_IOXGET_16(isp, &src->na_reserved1, dst->na_reserved1);
3596 	ISP_IOXGET_16(isp, &src->na_flags, dst->na_flags);
3597 	ISP_IOXGET_16(isp, &src->na_srr_rxid, dst->na_srr_rxid);
3598 	ISP_IOXGET_16(isp, &src->na_status, dst->na_status);
3599 	ISP_IOXGET_8(isp, &src->na_status_subcode, dst->na_status_subcode);
3600 	ISP_IOXGET_8(isp, &src->na_fwhandle, dst->na_fwhandle);
3601 	ISP_IOXGET_32(isp, &src->na_rxid, dst->na_rxid);
3602 	ISP_IOXGET_16(isp, &src->na_srr_reloff_hi, dst->na_srr_reloff_hi);
3603 	ISP_IOXGET_16(isp, &src->na_srr_reloff_lo, dst->na_srr_reloff_lo);
3604 	ISP_IOXGET_16(isp, &src->na_srr_iu, dst->na_srr_iu);
3605 	ISP_IOXGET_16(isp, &src->na_srr_flags, dst->na_srr_flags);
3606 	for (i = 0; i < 18; i++) {
3607 		ISP_IOXGET_8(isp, &src->na_reserved3[i], dst->na_reserved3[i]);
3608 	}
3609 	ISP_IOXGET_8(isp, &src->na_reserved4, dst->na_reserved4);
3610 	ISP_IOXGET_8(isp, &src->na_vpidx, dst->na_vpidx);
3611 	ISP_IOXGET_8(isp, &src->na_srr_reject_vunique, dst->na_srr_reject_vunique);
3612 	ISP_IOXGET_8(isp, &src->na_srr_reject_explanation, dst->na_srr_reject_explanation);
3613 	ISP_IOXGET_8(isp, &src->na_srr_reject_code, dst->na_srr_reject_code);
3614 	ISP_IOXGET_8(isp, &src->na_reserved5, dst->na_reserved5);
3615 	for (i = 0; i < 6; i++) {
3616 		ISP_IOXGET_8(isp, &src->na_reserved6[i], dst->na_reserved6[i]);
3617 	}
3618 	ISP_IOXGET_16(isp, &src->na_oxid, dst->na_oxid);
3619 }
3620 
3621 void
3622 isp_get_abts(ispsoftc_t *isp, abts_t *src, abts_t *dst)
3623 {
3624 	int i;
3625 
3626 	isp_get_hdr(isp, &src->abts_header, &dst->abts_header);
3627 	for (i = 0; i < 6; i++) {
3628 		ISP_IOXGET_8(isp, &src->abts_reserved0[i], dst->abts_reserved0[i]);
3629 	}
3630 	ISP_IOXGET_16(isp, &src->abts_nphdl, dst->abts_nphdl);
3631 	ISP_IOXGET_16(isp, &src->abts_reserved1, dst->abts_reserved1);
3632 	ISP_IOXGET_16(isp, &src->abts_sof, dst->abts_sof);
3633 	ISP_IOXGET_32(isp, &src->abts_rxid_abts, dst->abts_rxid_abts);
3634 	ISP_IOXGET_16(isp, &src->abts_did_lo, dst->abts_did_lo);
3635 	ISP_IOXGET_8(isp, &src->abts_did_hi, dst->abts_did_hi);
3636 	ISP_IOXGET_8(isp, &src->abts_r_ctl, dst->abts_r_ctl);
3637 	ISP_IOXGET_16(isp, &src->abts_sid_lo, dst->abts_sid_lo);
3638 	ISP_IOXGET_8(isp, &src->abts_sid_hi, dst->abts_sid_hi);
3639 	ISP_IOXGET_8(isp, &src->abts_cs_ctl, dst->abts_cs_ctl);
3640 	ISP_IOXGET_16(isp, &src->abts_fs_ctl, dst->abts_fs_ctl);
3641 	ISP_IOXGET_8(isp, &src->abts_f_ctl, dst->abts_f_ctl);
3642 	ISP_IOXGET_8(isp, &src->abts_type, dst->abts_type);
3643 	ISP_IOXGET_16(isp, &src->abts_seq_cnt, dst->abts_seq_cnt);
3644 	ISP_IOXGET_8(isp, &src->abts_df_ctl, dst->abts_df_ctl);
3645 	ISP_IOXGET_8(isp, &src->abts_seq_id, dst->abts_seq_id);
3646 	ISP_IOXGET_16(isp, &src->abts_rx_id, dst->abts_rx_id);
3647 	ISP_IOXGET_16(isp, &src->abts_ox_id, dst->abts_ox_id);
3648 	ISP_IOXGET_32(isp, &src->abts_param, dst->abts_param);
3649 	for (i = 0; i < 16; i++) {
3650 		ISP_IOXGET_8(isp, &src->abts_reserved2[i], dst->abts_reserved2[i]);
3651 	}
3652 	ISP_IOXGET_32(isp, &src->abts_rxid_task, dst->abts_rxid_task);
3653 }
3654 
3655 void
3656 isp_put_abts_rsp(ispsoftc_t *isp, abts_rsp_t *src, abts_rsp_t *dst)
3657 {
3658 	int i;
3659 
3660 	isp_put_hdr(isp, &src->abts_rsp_header, &dst->abts_rsp_header);
3661 	ISP_IOXPUT_32(isp, src->abts_rsp_handle, &dst->abts_rsp_handle);
3662 	ISP_IOXPUT_16(isp, src->abts_rsp_status, &dst->abts_rsp_status);
3663 	ISP_IOXPUT_16(isp, src->abts_rsp_nphdl, &dst->abts_rsp_nphdl);
3664 	ISP_IOXPUT_16(isp, src->abts_rsp_ctl_flags, &dst->abts_rsp_ctl_flags);
3665 	ISP_IOXPUT_16(isp, src->abts_rsp_sof, &dst->abts_rsp_sof);
3666 	ISP_IOXPUT_32(isp, src->abts_rsp_rxid_abts, &dst->abts_rsp_rxid_abts);
3667 	ISP_IOXPUT_16(isp, src->abts_rsp_did_lo, &dst->abts_rsp_did_lo);
3668 	ISP_IOXPUT_8(isp, src->abts_rsp_did_hi, &dst->abts_rsp_did_hi);
3669 	ISP_IOXPUT_8(isp, src->abts_rsp_r_ctl, &dst->abts_rsp_r_ctl);
3670 	ISP_IOXPUT_16(isp, src->abts_rsp_sid_lo, &dst->abts_rsp_sid_lo);
3671 	ISP_IOXPUT_8(isp, src->abts_rsp_sid_hi, &dst->abts_rsp_sid_hi);
3672 	ISP_IOXPUT_8(isp, src->abts_rsp_cs_ctl, &dst->abts_rsp_cs_ctl);
3673 	ISP_IOXPUT_16(isp, src->abts_rsp_f_ctl_lo, &dst->abts_rsp_f_ctl_lo);
3674 	ISP_IOXPUT_8(isp, src->abts_rsp_f_ctl_hi, &dst->abts_rsp_f_ctl_hi);
3675 	ISP_IOXPUT_8(isp, src->abts_rsp_type, &dst->abts_rsp_type);
3676 	ISP_IOXPUT_16(isp, src->abts_rsp_seq_cnt, &dst->abts_rsp_seq_cnt);
3677 	ISP_IOXPUT_8(isp, src->abts_rsp_df_ctl, &dst->abts_rsp_df_ctl);
3678 	ISP_IOXPUT_8(isp, src->abts_rsp_seq_id, &dst->abts_rsp_seq_id);
3679 	ISP_IOXPUT_16(isp, src->abts_rsp_rx_id, &dst->abts_rsp_rx_id);
3680 	ISP_IOXPUT_16(isp, src->abts_rsp_ox_id, &dst->abts_rsp_ox_id);
3681 	ISP_IOXPUT_32(isp, src->abts_rsp_param, &dst->abts_rsp_param);
3682 	if (src->abts_rsp_r_ctl == BA_ACC) {
3683 		ISP_IOXPUT_16(isp, src->abts_rsp_payload.ba_acc.reserved, &dst->abts_rsp_payload.ba_acc.reserved);
3684 		ISP_IOXPUT_8(isp, src->abts_rsp_payload.ba_acc.last_seq_id, &dst->abts_rsp_payload.ba_acc.last_seq_id);
3685 		ISP_IOXPUT_8(isp, src->abts_rsp_payload.ba_acc.seq_id_valid, &dst->abts_rsp_payload.ba_acc.seq_id_valid);
3686 		ISP_IOXPUT_16(isp, src->abts_rsp_payload.ba_acc.aborted_rx_id, &dst->abts_rsp_payload.ba_acc.aborted_rx_id);
3687 		ISP_IOXPUT_16(isp, src->abts_rsp_payload.ba_acc.aborted_ox_id, &dst->abts_rsp_payload.ba_acc.aborted_ox_id);
3688 		ISP_IOXPUT_16(isp, src->abts_rsp_payload.ba_acc.high_seq_cnt, &dst->abts_rsp_payload.ba_acc.high_seq_cnt);
3689 		ISP_IOXPUT_16(isp, src->abts_rsp_payload.ba_acc.low_seq_cnt, &dst->abts_rsp_payload.ba_acc.low_seq_cnt);
3690 		for (i = 0; i < 4; i++) {
3691 			ISP_IOXPUT_16(isp, src->abts_rsp_payload.ba_acc.reserved2[i], &dst->abts_rsp_payload.ba_acc.reserved2[i]);
3692 		}
3693 	} else if (src->abts_rsp_r_ctl == BA_RJT) {
3694 		ISP_IOXPUT_8(isp, src->abts_rsp_payload.ba_rjt.vendor_unique, &dst->abts_rsp_payload.ba_rjt.vendor_unique);
3695 		ISP_IOXPUT_8(isp, src->abts_rsp_payload.ba_rjt.explanation, &dst->abts_rsp_payload.ba_rjt.explanation);
3696 		ISP_IOXPUT_8(isp, src->abts_rsp_payload.ba_rjt.reason, &dst->abts_rsp_payload.ba_rjt.reason);
3697 		ISP_IOXPUT_8(isp, src->abts_rsp_payload.ba_rjt.reserved, &dst->abts_rsp_payload.ba_rjt.reserved);
3698 		for (i = 0; i < 12; i++) {
3699 			ISP_IOXPUT_16(isp, src->abts_rsp_payload.ba_rjt.reserved2[i], &dst->abts_rsp_payload.ba_rjt.reserved2[i]);
3700 		}
3701 	} else {
3702 		for (i = 0; i < 16; i++) {
3703 			ISP_IOXPUT_8(isp, src->abts_rsp_payload.reserved[i], &dst->abts_rsp_payload.reserved[i]);
3704 		}
3705 	}
3706 	ISP_IOXPUT_32(isp, src->abts_rsp_rxid_task, &dst->abts_rsp_rxid_task);
3707 }
3708 
3709 void
3710 isp_get_abts_rsp(ispsoftc_t *isp, abts_rsp_t *src, abts_rsp_t *dst)
3711 {
3712 	int i;
3713 
3714 	isp_get_hdr(isp, &src->abts_rsp_header, &dst->abts_rsp_header);
3715 	ISP_IOXGET_32(isp, &src->abts_rsp_handle, dst->abts_rsp_handle);
3716 	ISP_IOXGET_16(isp, &src->abts_rsp_status, dst->abts_rsp_status);
3717 	ISP_IOXGET_16(isp, &src->abts_rsp_nphdl, dst->abts_rsp_nphdl);
3718 	ISP_IOXGET_16(isp, &src->abts_rsp_ctl_flags, dst->abts_rsp_ctl_flags);
3719 	ISP_IOXGET_16(isp, &src->abts_rsp_sof, dst->abts_rsp_sof);
3720 	ISP_IOXGET_32(isp, &src->abts_rsp_rxid_abts, dst->abts_rsp_rxid_abts);
3721 	ISP_IOXGET_16(isp, &src->abts_rsp_did_lo, dst->abts_rsp_did_lo);
3722 	ISP_IOXGET_8(isp, &src->abts_rsp_did_hi, dst->abts_rsp_did_hi);
3723 	ISP_IOXGET_8(isp, &src->abts_rsp_r_ctl, dst->abts_rsp_r_ctl);
3724 	ISP_IOXGET_16(isp, &src->abts_rsp_sid_lo, dst->abts_rsp_sid_lo);
3725 	ISP_IOXGET_8(isp, &src->abts_rsp_sid_hi, dst->abts_rsp_sid_hi);
3726 	ISP_IOXGET_8(isp, &src->abts_rsp_cs_ctl, dst->abts_rsp_cs_ctl);
3727 	ISP_IOXGET_16(isp, &src->abts_rsp_f_ctl_lo, dst->abts_rsp_f_ctl_lo);
3728 	ISP_IOXGET_8(isp, &src->abts_rsp_f_ctl_hi, dst->abts_rsp_f_ctl_hi);
3729 	ISP_IOXGET_8(isp, &src->abts_rsp_type, dst->abts_rsp_type);
3730 	ISP_IOXGET_16(isp, &src->abts_rsp_seq_cnt, dst->abts_rsp_seq_cnt);
3731 	ISP_IOXGET_8(isp, &src->abts_rsp_df_ctl, dst->abts_rsp_df_ctl);
3732 	ISP_IOXGET_8(isp, &src->abts_rsp_seq_id, dst->abts_rsp_seq_id);
3733 	ISP_IOXGET_16(isp, &src->abts_rsp_rx_id, dst->abts_rsp_rx_id);
3734 	ISP_IOXGET_16(isp, &src->abts_rsp_ox_id, dst->abts_rsp_ox_id);
3735 	ISP_IOXGET_32(isp, &src->abts_rsp_param, dst->abts_rsp_param);
3736 	for (i = 0; i < 8; i++) {
3737 		ISP_IOXGET_8(isp, &src->abts_rsp_payload.rsp.reserved[i], dst->abts_rsp_payload.rsp.reserved[i]);
3738 	}
3739 	ISP_IOXGET_32(isp, &src->abts_rsp_payload.rsp.subcode1, dst->abts_rsp_payload.rsp.subcode1);
3740 	ISP_IOXGET_32(isp, &src->abts_rsp_payload.rsp.subcode2, dst->abts_rsp_payload.rsp.subcode2);
3741 	ISP_IOXGET_32(isp, &src->abts_rsp_rxid_task, dst->abts_rsp_rxid_task);
3742 }
3743 #endif	/* ISP_TARGET_MODE */
3744 /*
3745  * vim:ts=8:sw=8
3746  */
3747