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