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