Deleted Added
full compact
isp.c (151834) isp.c (154704)
1/* $FreeBSD: head/sys/dev/isp/isp.c 151834 2005-10-29 02:46:59Z mjacob $ */
2/*-
3 * Machine and OS Independent (well, as best as possible)
4 * code for the Qlogic ISP SCSI adapters.
5 *
1/*-
2 * Machine and OS Independent (well, as best as possible)
3 * code for the Qlogic ISP SCSI adapters.
4 *
6 * Copyright (c) 1997, 1998, 1999, 2000, 2001 by Matthew Jacob
7 * Feral Software
5 * Copyright (c) 1997-2006 by Matthew Jacob
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice immediately at the beginning of the file, without modification,
15 * this list of conditions, and the following disclaimer.
16 * 2. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32/*
33 * Inspiration and ideas about this driver are from Erik Moe's Linux driver
34 * (qlogicisp.c) and Dave Miller's SBus version of same (qlogicisp.c). Some
35 * ideas dredged from the Solaris driver.
36 */
37
38/*
39 * Include header file appropriate for platform we're building on.
40 */
41
42#ifdef __NetBSD__
43#include <dev/ic/isp_netbsd.h>
44#endif
45#ifdef __FreeBSD__
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice immediately at the beginning of the file, without modification,
13 * this list of conditions, and the following disclaimer.
14 * 2. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
21 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30/*
31 * Inspiration and ideas about this driver are from Erik Moe's Linux driver
32 * (qlogicisp.c) and Dave Miller's SBus version of same (qlogicisp.c). Some
33 * ideas dredged from the Solaris driver.
34 */
35
36/*
37 * Include header file appropriate for platform we're building on.
38 */
39
40#ifdef __NetBSD__
41#include <dev/ic/isp_netbsd.h>
42#endif
43#ifdef __FreeBSD__
44#include <sys/cdefs.h>
45__FBSDID("$FreeBSD: head/sys/dev/isp/isp.c 154704 2006-01-23 06:23:37Z mjacob $");
46#include <dev/isp/isp_freebsd.h>
47#endif
48#ifdef __OpenBSD__
49#include <dev/ic/isp_openbsd.h>
50#endif
51#ifdef __linux__
52#include "isp_linux.h"
53#endif
54#ifdef __svr4__
55#include "isp_solaris.h"
56#endif
57
58/*
59 * General defines
60 */
61
62#define MBOX_DELAY_COUNT 1000000 / 100
63
64/*
65 * Local static data
66 */
67static const char portshift[] =
68 "Target %d Loop ID 0x%x (Port 0x%x) => Loop 0x%x (Port 0x%x)";
69static const char portdup[] =
70 "Target %d duplicates Target %d- killing off both";
71static const char retained[] =
72 "Retaining Loop ID 0x%x for Target %d (Port 0x%x)";
73static const char lretained[] =
74 "Retained login of Target %d (Loop ID 0x%x) Port 0x%x";
75static const char plogout[] =
76 "Logging out Target %d at Loop ID 0x%x (Port 0x%x)";
77static const char plogierr[] =
78 "Command Error in PLOGI for Port 0x%x (0x%x)";
79static const char nopdb[] =
80 "Could not get PDB for Device @ Port 0x%x";
81static const char pdbmfail1[] =
82 "PDB Loop ID info for Device @ Port 0x%x does not match up (0x%x)";
83static const char pdbmfail2[] =
84 "PDB Port info for Device @ Port 0x%x does not match up (0x%x)";
85static const char ldumped[] =
86 "Target %d (Loop ID 0x%x) Port 0x%x dumped after login info mismatch";
87static const char notresp[] =
88 "Not RESPONSE in RESPONSE Queue (type 0x%x) @ idx %d (next %d) nlooked %d";
89static const char xact1[] =
90 "HBA attempted queued transaction with disconnect not set for %d.%d.%d";
91static const char xact2[] =
92 "HBA attempted queued transaction to target routine %d on target %d bus %d";
93static const char xact3[] =
94 "HBA attempted queued cmd for %d.%d.%d when queueing disabled";
95static const char pskip[] =
96 "SCSI phase skipped for target %d.%d.%d";
97static const char topology[] =
46#include <dev/isp/isp_freebsd.h>
47#endif
48#ifdef __OpenBSD__
49#include <dev/ic/isp_openbsd.h>
50#endif
51#ifdef __linux__
52#include "isp_linux.h"
53#endif
54#ifdef __svr4__
55#include "isp_solaris.h"
56#endif
57
58/*
59 * General defines
60 */
61
62#define MBOX_DELAY_COUNT 1000000 / 100
63
64/*
65 * Local static data
66 */
67static const char portshift[] =
68 "Target %d Loop ID 0x%x (Port 0x%x) => Loop 0x%x (Port 0x%x)";
69static const char portdup[] =
70 "Target %d duplicates Target %d- killing off both";
71static const char retained[] =
72 "Retaining Loop ID 0x%x for Target %d (Port 0x%x)";
73static const char lretained[] =
74 "Retained login of Target %d (Loop ID 0x%x) Port 0x%x";
75static const char plogout[] =
76 "Logging out Target %d at Loop ID 0x%x (Port 0x%x)";
77static const char plogierr[] =
78 "Command Error in PLOGI for Port 0x%x (0x%x)";
79static const char nopdb[] =
80 "Could not get PDB for Device @ Port 0x%x";
81static const char pdbmfail1[] =
82 "PDB Loop ID info for Device @ Port 0x%x does not match up (0x%x)";
83static const char pdbmfail2[] =
84 "PDB Port info for Device @ Port 0x%x does not match up (0x%x)";
85static const char ldumped[] =
86 "Target %d (Loop ID 0x%x) Port 0x%x dumped after login info mismatch";
87static const char notresp[] =
88 "Not RESPONSE in RESPONSE Queue (type 0x%x) @ idx %d (next %d) nlooked %d";
89static const char xact1[] =
90 "HBA attempted queued transaction with disconnect not set for %d.%d.%d";
91static const char xact2[] =
92 "HBA attempted queued transaction to target routine %d on target %d bus %d";
93static const char xact3[] =
94 "HBA attempted queued cmd for %d.%d.%d when queueing disabled";
95static const char pskip[] =
96 "SCSI phase skipped for target %d.%d.%d";
97static const char topology[] =
98 "Loop ID %d, AL_PA 0x%x, Port ID 0x%x, Loop State 0x%x, Topology '%s'";
98 "Loop ID %d, Port ID 0x%x, Loop State 0x%x, Topology '%s'";
99static const char swrej[] =
100 "Fabric Nameserver rejected %s (Reason=0x%x Expl=0x%x) for Port ID 0x%x";
101static const char finmsg[] =
102 "(%d.%d.%d): FIN dl%d resid %d STS 0x%x SKEY %c XS_ERR=0x%x";
103static const char sc0[] =
104 "%s CHAN %d FTHRSH %d IID %d RESETD %d RETRYC %d RETRYD %d ASD 0x%x";
105static const char sc1[] =
106 "%s RAAN 0x%x DLAN 0x%x DDMAB 0x%x CDMAB 0x%x SELTIME %d MQD %d";
107static const char sc2[] = "%s CHAN %d TGT %d FLAGS 0x%x 0x%x/0x%x";
108static const char sc3[] = "Generated";
109static const char sc4[] = "NVRAM";
110static const char bun[] =
111 "bad underrun for %d.%d (count %d, resid %d, status %s)";
112
113/*
114 * Local function prototypes.
115 */
116static int isp_parse_async(struct ispsoftc *, u_int16_t);
117static int isp_handle_other_response(struct ispsoftc *, int, isphdr_t *,
118 u_int16_t *);
119static void
120isp_parse_status(struct ispsoftc *, ispstatusreq_t *, XS_T *);
121static void isp_fastpost_complete(struct ispsoftc *, u_int16_t);
122static int isp_mbox_continue(struct ispsoftc *);
123static void isp_scsi_init(struct ispsoftc *);
124static void isp_scsi_channel_init(struct ispsoftc *, int);
125static void isp_fibre_init(struct ispsoftc *);
126static void isp_mark_getpdb_all(struct ispsoftc *);
127static int isp_getmap(struct ispsoftc *, fcpos_map_t *);
128static int isp_getpdb(struct ispsoftc *, int, isp_pdb_t *);
129static u_int64_t isp_get_portname(struct ispsoftc *, int, int);
130static int isp_fclink_test(struct ispsoftc *, int);
131static char *isp2100_fw_statename(int);
132static int isp_pdb_sync(struct ispsoftc *);
133static int isp_scan_loop(struct ispsoftc *);
134static int isp_fabric_mbox_cmd(struct ispsoftc *, mbreg_t *);
135static int isp_scan_fabric(struct ispsoftc *, int);
136static void isp_register_fc4_type(struct ispsoftc *);
137static void isp_fw_state(struct ispsoftc *);
138static void isp_mboxcmd_qnw(struct ispsoftc *, mbreg_t *, int);
139static void isp_mboxcmd(struct ispsoftc *, mbreg_t *, int);
140
141static void isp_update(struct ispsoftc *);
142static void isp_update_bus(struct ispsoftc *, int);
143static void isp_setdfltparm(struct ispsoftc *, int);
144static int isp_read_nvram(struct ispsoftc *);
145static void isp_rdnvram_word(struct ispsoftc *, int, u_int16_t *);
146static void isp_parse_nvram_1020(struct ispsoftc *, u_int8_t *);
147static void isp_parse_nvram_1080(struct ispsoftc *, int, u_int8_t *);
148static void isp_parse_nvram_12160(struct ispsoftc *, int, u_int8_t *);
149static void isp_parse_nvram_2100(struct ispsoftc *, u_int8_t *);
150
151/*
152 * Reset Hardware.
153 *
154 * Hit the chip over the head, download new f/w if available and set it running.
155 *
156 * Locking done elsewhere.
157 */
158
159void
160isp_reset(struct ispsoftc *isp)
161{
162 mbreg_t mbs;
163 u_int16_t code_org;
164 int loops, i, dodnld = 1;
165 char *btype = "????";
166
167 isp->isp_state = ISP_NILSTATE;
99static const char swrej[] =
100 "Fabric Nameserver rejected %s (Reason=0x%x Expl=0x%x) for Port ID 0x%x";
101static const char finmsg[] =
102 "(%d.%d.%d): FIN dl%d resid %d STS 0x%x SKEY %c XS_ERR=0x%x";
103static const char sc0[] =
104 "%s CHAN %d FTHRSH %d IID %d RESETD %d RETRYC %d RETRYD %d ASD 0x%x";
105static const char sc1[] =
106 "%s RAAN 0x%x DLAN 0x%x DDMAB 0x%x CDMAB 0x%x SELTIME %d MQD %d";
107static const char sc2[] = "%s CHAN %d TGT %d FLAGS 0x%x 0x%x/0x%x";
108static const char sc3[] = "Generated";
109static const char sc4[] = "NVRAM";
110static const char bun[] =
111 "bad underrun for %d.%d (count %d, resid %d, status %s)";
112
113/*
114 * Local function prototypes.
115 */
116static int isp_parse_async(struct ispsoftc *, u_int16_t);
117static int isp_handle_other_response(struct ispsoftc *, int, isphdr_t *,
118 u_int16_t *);
119static void
120isp_parse_status(struct ispsoftc *, ispstatusreq_t *, XS_T *);
121static void isp_fastpost_complete(struct ispsoftc *, u_int16_t);
122static int isp_mbox_continue(struct ispsoftc *);
123static void isp_scsi_init(struct ispsoftc *);
124static void isp_scsi_channel_init(struct ispsoftc *, int);
125static void isp_fibre_init(struct ispsoftc *);
126static void isp_mark_getpdb_all(struct ispsoftc *);
127static int isp_getmap(struct ispsoftc *, fcpos_map_t *);
128static int isp_getpdb(struct ispsoftc *, int, isp_pdb_t *);
129static u_int64_t isp_get_portname(struct ispsoftc *, int, int);
130static int isp_fclink_test(struct ispsoftc *, int);
131static char *isp2100_fw_statename(int);
132static int isp_pdb_sync(struct ispsoftc *);
133static int isp_scan_loop(struct ispsoftc *);
134static int isp_fabric_mbox_cmd(struct ispsoftc *, mbreg_t *);
135static int isp_scan_fabric(struct ispsoftc *, int);
136static void isp_register_fc4_type(struct ispsoftc *);
137static void isp_fw_state(struct ispsoftc *);
138static void isp_mboxcmd_qnw(struct ispsoftc *, mbreg_t *, int);
139static void isp_mboxcmd(struct ispsoftc *, mbreg_t *, int);
140
141static void isp_update(struct ispsoftc *);
142static void isp_update_bus(struct ispsoftc *, int);
143static void isp_setdfltparm(struct ispsoftc *, int);
144static int isp_read_nvram(struct ispsoftc *);
145static void isp_rdnvram_word(struct ispsoftc *, int, u_int16_t *);
146static void isp_parse_nvram_1020(struct ispsoftc *, u_int8_t *);
147static void isp_parse_nvram_1080(struct ispsoftc *, int, u_int8_t *);
148static void isp_parse_nvram_12160(struct ispsoftc *, int, u_int8_t *);
149static void isp_parse_nvram_2100(struct ispsoftc *, u_int8_t *);
150
151/*
152 * Reset Hardware.
153 *
154 * Hit the chip over the head, download new f/w if available and set it running.
155 *
156 * Locking done elsewhere.
157 */
158
159void
160isp_reset(struct ispsoftc *isp)
161{
162 mbreg_t mbs;
163 u_int16_t code_org;
164 int loops, i, dodnld = 1;
165 char *btype = "????";
166
167 isp->isp_state = ISP_NILSTATE;
168 MEMZERO(&mbs, sizeof (mbs));
168
169 /*
170 * Basic types (SCSI, FibreChannel and PCI or SBus)
171 * have been set in the MD code. We figure out more
172 * here. Possibly more refined types based upon PCI
173 * identification. Chip revision has been gathered.
174 *
175 * After we've fired this chip up, zero out the conf1 register
176 * for SCSI adapters and do other settings for the 2100.
177 */
178
179 /*
180 * Get the current running firmware revision out of the
181 * chip before we hit it over the head (if this is our
182 * first time through). Note that we store this as the
183 * 'ROM' firmware revision- which it may not be. In any
184 * case, we don't really use this yet, but we may in
185 * the future.
186 */
187 if (isp->isp_touched == 0) {
188 /*
189 * First see whether or not we're sitting in the ISP PROM.
190 * If we've just been reset, we'll have the string "ISP "
191 * spread through outgoing mailbox registers 1-3. We do
192 * this for PCI cards because otherwise we really don't
193 * know what state the card is in and we could hang if
194 * we try this command otherwise.
195 *
196 * For SBus cards, we just do this because they almost
197 * certainly will be running firmware by now.
198 */
199 if (ISP_READ(isp, OUTMAILBOX1) != 0x4953 ||
200 ISP_READ(isp, OUTMAILBOX2) != 0x5020 ||
201 ISP_READ(isp, OUTMAILBOX3) != 0x2020) {
202 /*
203 * Just in case it was paused...
204 */
205 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE);
206 mbs.param[0] = MBOX_ABOUT_FIRMWARE;
207 isp_mboxcmd(isp, &mbs, MBLOGNONE);
208 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
209 isp->isp_romfw_rev[0] = mbs.param[1];
210 isp->isp_romfw_rev[1] = mbs.param[2];
211 isp->isp_romfw_rev[2] = mbs.param[3];
212 }
213 }
214 isp->isp_touched = 1;
215 }
216
217 DISABLE_INTS(isp);
218
219 /*
220 * Set up default request/response queue in-pointer/out-pointer
221 * register indices.
222 */
223 if (IS_23XX(isp)) {
224 isp->isp_rqstinrp = BIU_REQINP;
225 isp->isp_rqstoutrp = BIU_REQOUTP;
226 isp->isp_respinrp = BIU_RSPINP;
227 isp->isp_respoutrp = BIU_RSPOUTP;
228 } else {
229 isp->isp_rqstinrp = INMAILBOX4;
230 isp->isp_rqstoutrp = OUTMAILBOX4;
231 isp->isp_respinrp = OUTMAILBOX5;
232 isp->isp_respoutrp = INMAILBOX5;
233 }
234
235 /*
236 * Put the board into PAUSE mode (so we can read the SXP registers
237 * or write FPM/FBM registers).
238 */
239 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
240
241 if (IS_FC(isp)) {
242 switch (isp->isp_type) {
243 case ISP_HA_FC_2100:
244 btype = "2100";
245 break;
246 case ISP_HA_FC_2200:
247 btype = "2200";
248 break;
249 case ISP_HA_FC_2300:
250 btype = "2300";
251 break;
252 case ISP_HA_FC_2312:
253 btype = "2312";
254 break;
169
170 /*
171 * Basic types (SCSI, FibreChannel and PCI or SBus)
172 * have been set in the MD code. We figure out more
173 * here. Possibly more refined types based upon PCI
174 * identification. Chip revision has been gathered.
175 *
176 * After we've fired this chip up, zero out the conf1 register
177 * for SCSI adapters and do other settings for the 2100.
178 */
179
180 /*
181 * Get the current running firmware revision out of the
182 * chip before we hit it over the head (if this is our
183 * first time through). Note that we store this as the
184 * 'ROM' firmware revision- which it may not be. In any
185 * case, we don't really use this yet, but we may in
186 * the future.
187 */
188 if (isp->isp_touched == 0) {
189 /*
190 * First see whether or not we're sitting in the ISP PROM.
191 * If we've just been reset, we'll have the string "ISP "
192 * spread through outgoing mailbox registers 1-3. We do
193 * this for PCI cards because otherwise we really don't
194 * know what state the card is in and we could hang if
195 * we try this command otherwise.
196 *
197 * For SBus cards, we just do this because they almost
198 * certainly will be running firmware by now.
199 */
200 if (ISP_READ(isp, OUTMAILBOX1) != 0x4953 ||
201 ISP_READ(isp, OUTMAILBOX2) != 0x5020 ||
202 ISP_READ(isp, OUTMAILBOX3) != 0x2020) {
203 /*
204 * Just in case it was paused...
205 */
206 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE);
207 mbs.param[0] = MBOX_ABOUT_FIRMWARE;
208 isp_mboxcmd(isp, &mbs, MBLOGNONE);
209 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
210 isp->isp_romfw_rev[0] = mbs.param[1];
211 isp->isp_romfw_rev[1] = mbs.param[2];
212 isp->isp_romfw_rev[2] = mbs.param[3];
213 }
214 }
215 isp->isp_touched = 1;
216 }
217
218 DISABLE_INTS(isp);
219
220 /*
221 * Set up default request/response queue in-pointer/out-pointer
222 * register indices.
223 */
224 if (IS_23XX(isp)) {
225 isp->isp_rqstinrp = BIU_REQINP;
226 isp->isp_rqstoutrp = BIU_REQOUTP;
227 isp->isp_respinrp = BIU_RSPINP;
228 isp->isp_respoutrp = BIU_RSPOUTP;
229 } else {
230 isp->isp_rqstinrp = INMAILBOX4;
231 isp->isp_rqstoutrp = OUTMAILBOX4;
232 isp->isp_respinrp = OUTMAILBOX5;
233 isp->isp_respoutrp = INMAILBOX5;
234 }
235
236 /*
237 * Put the board into PAUSE mode (so we can read the SXP registers
238 * or write FPM/FBM registers).
239 */
240 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
241
242 if (IS_FC(isp)) {
243 switch (isp->isp_type) {
244 case ISP_HA_FC_2100:
245 btype = "2100";
246 break;
247 case ISP_HA_FC_2200:
248 btype = "2200";
249 break;
250 case ISP_HA_FC_2300:
251 btype = "2300";
252 break;
253 case ISP_HA_FC_2312:
254 btype = "2312";
255 break;
256 case ISP_HA_FC_2322:
257 btype = "2322";
258 break;
259 case ISP_HA_FC_2422:
260 btype = "2422";
261 break;
255 default:
256 break;
257 }
258 /*
259 * While we're paused, reset the FPM module and FBM fifos.
260 */
261 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FPM0_REGS);
262 ISP_WRITE(isp, FPM_DIAG_CONFIG, FPM_SOFT_RESET);
263 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FB_REGS);
264 ISP_WRITE(isp, FBM_CMD, FBMCMD_FIFO_RESET_ALL);
265 ISP_WRITE(isp, BIU2100_CSR, BIU2100_RISC_REGS);
266 } else if (IS_1240(isp)) {
267 sdparam *sdp = isp->isp_param;
268 btype = "1240";
269 isp->isp_clock = 60;
270 sdp->isp_ultramode = 1;
271 sdp++;
272 sdp->isp_ultramode = 1;
273 /*
274 * XXX: Should probably do some bus sensing.
275 */
276 } else if (IS_ULTRA2(isp)) {
277 static const char m[] = "bus %d is in %s Mode";
278 u_int16_t l;
279 sdparam *sdp = isp->isp_param;
280
281 isp->isp_clock = 100;
282
283 if (IS_1280(isp))
284 btype = "1280";
285 else if (IS_1080(isp))
286 btype = "1080";
287 else if (IS_10160(isp))
288 btype = "10160";
289 else if (IS_12160(isp))
290 btype = "12160";
291 else
292 btype = "<UNKLVD>";
293
294 l = ISP_READ(isp, SXP_PINS_DIFF) & ISP1080_MODE_MASK;
295 switch (l) {
296 case ISP1080_LVD_MODE:
297 sdp->isp_lvdmode = 1;
298 isp_prt(isp, ISP_LOGCONFIG, m, 0, "LVD");
299 break;
300 case ISP1080_HVD_MODE:
301 sdp->isp_diffmode = 1;
302 isp_prt(isp, ISP_LOGCONFIG, m, 0, "Differential");
303 break;
304 case ISP1080_SE_MODE:
305 sdp->isp_ultramode = 1;
306 isp_prt(isp, ISP_LOGCONFIG, m, 0, "Single-Ended");
307 break;
308 default:
309 isp_prt(isp, ISP_LOGERR,
310 "unknown mode on bus %d (0x%x)", 0, l);
311 break;
312 }
313
314 if (IS_DUALBUS(isp)) {
315 sdp++;
316 l = ISP_READ(isp, SXP_PINS_DIFF|SXP_BANK1_SELECT);
317 l &= ISP1080_MODE_MASK;
318 switch(l) {
319 case ISP1080_LVD_MODE:
320 sdp->isp_lvdmode = 1;
321 isp_prt(isp, ISP_LOGCONFIG, m, 1, "LVD");
322 break;
323 case ISP1080_HVD_MODE:
324 sdp->isp_diffmode = 1;
325 isp_prt(isp, ISP_LOGCONFIG,
326 m, 1, "Differential");
327 break;
328 case ISP1080_SE_MODE:
329 sdp->isp_ultramode = 1;
330 isp_prt(isp, ISP_LOGCONFIG,
331 m, 1, "Single-Ended");
332 break;
333 default:
334 isp_prt(isp, ISP_LOGERR,
335 "unknown mode on bus %d (0x%x)", 1, l);
336 break;
337 }
338 }
339 } else {
340 sdparam *sdp = isp->isp_param;
341 i = ISP_READ(isp, BIU_CONF0) & BIU_CONF0_HW_MASK;
342 switch (i) {
343 default:
344 isp_prt(isp, ISP_LOGALL, "Unknown Chip Type 0x%x", i);
345 /* FALLTHROUGH */
346 case 1:
347 btype = "1020";
348 isp->isp_type = ISP_HA_SCSI_1020;
349 isp->isp_clock = 40;
350 break;
351 case 2:
352 /*
353 * Some 1020A chips are Ultra Capable, but don't
354 * run the clock rate up for that unless told to
355 * do so by the Ultra Capable bits being set.
356 */
357 btype = "1020A";
358 isp->isp_type = ISP_HA_SCSI_1020A;
359 isp->isp_clock = 40;
360 break;
361 case 3:
362 btype = "1040";
363 isp->isp_type = ISP_HA_SCSI_1040;
364 isp->isp_clock = 60;
365 break;
366 case 4:
367 btype = "1040A";
368 isp->isp_type = ISP_HA_SCSI_1040A;
369 isp->isp_clock = 60;
370 break;
371 case 5:
372 btype = "1040B";
373 isp->isp_type = ISP_HA_SCSI_1040B;
374 isp->isp_clock = 60;
375 break;
376 case 6:
377 btype = "1040C";
378 isp->isp_type = ISP_HA_SCSI_1040C;
379 isp->isp_clock = 60;
380 break;
381 }
382 /*
383 * Now, while we're at it, gather info about ultra
384 * and/or differential mode.
385 */
386 if (ISP_READ(isp, SXP_PINS_DIFF) & SXP_PINS_DIFF_MODE) {
387 isp_prt(isp, ISP_LOGCONFIG, "Differential Mode");
388 sdp->isp_diffmode = 1;
389 } else {
390 sdp->isp_diffmode = 0;
391 }
392 i = ISP_READ(isp, RISC_PSR);
393 if (isp->isp_bustype == ISP_BT_SBUS) {
394 i &= RISC_PSR_SBUS_ULTRA;
395 } else {
396 i &= RISC_PSR_PCI_ULTRA;
397 }
398 if (i != 0) {
399 isp_prt(isp, ISP_LOGCONFIG, "Ultra Mode Capable");
400 sdp->isp_ultramode = 1;
401 /*
402 * If we're in Ultra Mode, we have to be 60MHz clock-
403 * even for the SBus version.
404 */
405 isp->isp_clock = 60;
406 } else {
407 sdp->isp_ultramode = 0;
408 /*
409 * Clock is known. Gronk.
410 */
411 }
412
413 /*
414 * Machine dependent clock (if set) overrides
415 * our generic determinations.
416 */
417 if (isp->isp_mdvec->dv_clock) {
418 if (isp->isp_mdvec->dv_clock < isp->isp_clock) {
419 isp->isp_clock = isp->isp_mdvec->dv_clock;
420 }
421 }
422
423 }
424
425 /*
426 * Clear instrumentation
427 */
428 isp->isp_intcnt = isp->isp_intbogus = 0;
429
430 /*
431 * Do MD specific pre initialization
432 */
433 ISP_RESET0(isp);
434
435again:
436
437 /*
438 * Hit the chip over the head with hammer,
439 * and give the ISP a chance to recover.
440 */
441
442 if (IS_SCSI(isp)) {
443 ISP_WRITE(isp, BIU_ICR, BIU_ICR_SOFT_RESET);
444 /*
445 * A slight delay...
446 */
447 USEC_DELAY(100);
448
449 /*
450 * Clear data && control DMA engines.
451 */
452 ISP_WRITE(isp, CDMA_CONTROL,
453 DMA_CNTRL_CLEAR_CHAN | DMA_CNTRL_RESET_INT);
454 ISP_WRITE(isp, DDMA_CONTROL,
455 DMA_CNTRL_CLEAR_CHAN | DMA_CNTRL_RESET_INT);
456
457
458 } else {
459 ISP_WRITE(isp, BIU2100_CSR, BIU2100_SOFT_RESET);
460 /*
461 * A slight delay...
462 */
463 USEC_DELAY(100);
464
465 /*
466 * Clear data && control DMA engines.
467 */
468 ISP_WRITE(isp, CDMA2100_CONTROL,
469 DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
470 ISP_WRITE(isp, TDMA2100_CONTROL,
471 DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
472 ISP_WRITE(isp, RDMA2100_CONTROL,
473 DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
474 }
475
476 /*
477 * Wait for ISP to be ready to go...
478 */
479 loops = MBOX_DELAY_COUNT;
480 for (;;) {
481 if (IS_SCSI(isp)) {
482 if (!(ISP_READ(isp, BIU_ICR) & BIU_ICR_SOFT_RESET))
483 break;
484 } else {
485 if (!(ISP_READ(isp, BIU2100_CSR) & BIU2100_SOFT_RESET))
486 break;
487 }
488 USEC_DELAY(100);
489 if (--loops < 0) {
490 ISP_DUMPREGS(isp, "chip reset timed out");
491 return;
492 }
493 }
494
495 /*
496 * After we've fired this chip up, zero out the conf1 register
497 * for SCSI adapters and other settings for the 2100.
498 */
499
500 if (IS_SCSI(isp)) {
501 ISP_WRITE(isp, BIU_CONF1, 0);
502 } else {
503 ISP_WRITE(isp, BIU2100_CSR, 0);
504 }
505
506 /*
507 * Reset RISC Processor
508 */
509 ISP_WRITE(isp, HCCR, HCCR_CMD_RESET);
510 USEC_DELAY(100);
511 /* Clear semaphore register (just to be sure) */
512 ISP_WRITE(isp, BIU_SEMA, 0);
513
514 /*
515 * Establish some initial burst rate stuff.
516 * (only for the 1XX0 boards). This really should
517 * be done later after fetching from NVRAM.
518 */
519 if (IS_SCSI(isp)) {
520 u_int16_t tmp = isp->isp_mdvec->dv_conf1;
521 /*
522 * Busted FIFO. Turn off all but burst enables.
523 */
524 if (isp->isp_type == ISP_HA_SCSI_1040A) {
525 tmp &= BIU_BURST_ENABLE;
526 }
527 ISP_SETBITS(isp, BIU_CONF1, tmp);
528 if (tmp & BIU_BURST_ENABLE) {
529 ISP_SETBITS(isp, CDMA_CONF, DMA_ENABLE_BURST);
530 ISP_SETBITS(isp, DDMA_CONF, DMA_ENABLE_BURST);
531 }
532#ifdef PTI_CARDS
533 if (((sdparam *) isp->isp_param)->isp_ultramode) {
534 while (ISP_READ(isp, RISC_MTR) != 0x1313) {
535 ISP_WRITE(isp, RISC_MTR, 0x1313);
536 ISP_WRITE(isp, HCCR, HCCR_CMD_STEP);
537 }
538 } else {
539 ISP_WRITE(isp, RISC_MTR, 0x1212);
540 }
541 /*
542 * PTI specific register
543 */
544 ISP_WRITE(isp, RISC_EMB, DUAL_BANK)
545#else
546 ISP_WRITE(isp, RISC_MTR, 0x1212);
547#endif
548 } else {
549 ISP_WRITE(isp, RISC_MTR2100, 0x1212);
550 if (IS_2200(isp) || IS_23XX(isp)) {
551 ISP_WRITE(isp, HCCR, HCCR_2X00_DISABLE_PARITY_PAUSE);
552 }
553 }
554
555 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE); /* release paused processor */
556
557 /*
558 * Do MD specific post initialization
559 */
560 ISP_RESET1(isp);
561
562 /*
563 * Wait for everything to finish firing up.
564 *
565 * Avoid doing this on the 2312 because you can generate a PCI
566 * parity error (chip breakage).
567 */
568 if (IS_23XX(isp)) {
569 USEC_DELAY(5);
570 } else {
571 loops = MBOX_DELAY_COUNT;
572 while (ISP_READ(isp, OUTMAILBOX0) == MBOX_BUSY) {
573 USEC_DELAY(100);
574 if (--loops < 0) {
575 isp_prt(isp, ISP_LOGERR,
576 "MBOX_BUSY never cleared on reset");
577 return;
578 }
579 }
580 }
581
582 /*
583 * Up until this point we've done everything by just reading or
584 * setting registers. From this point on we rely on at least *some*
585 * kind of firmware running in the card.
586 */
587
588 /*
589 * Do some sanity checking.
590 */
591 mbs.param[0] = MBOX_NO_OP;
592 isp_mboxcmd(isp, &mbs, MBLOGALL);
593 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
594 return;
595 }
596
597 if (IS_SCSI(isp)) {
598 mbs.param[0] = MBOX_MAILBOX_REG_TEST;
599 mbs.param[1] = 0xdead;
600 mbs.param[2] = 0xbeef;
601 mbs.param[3] = 0xffff;
602 mbs.param[4] = 0x1111;
603 mbs.param[5] = 0xa5a5;
604 isp_mboxcmd(isp, &mbs, MBLOGALL);
605 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
606 return;
607 }
608 if (mbs.param[1] != 0xdead || mbs.param[2] != 0xbeef ||
609 mbs.param[3] != 0xffff || mbs.param[4] != 0x1111 ||
610 mbs.param[5] != 0xa5a5) {
611 isp_prt(isp, ISP_LOGERR,
612 "Register Test Failed (0x%x 0x%x 0x%x 0x%x 0x%x)",
613 mbs.param[1], mbs.param[2], mbs.param[3],
614 mbs.param[4], mbs.param[5]);
615 return;
616 }
617
618 }
619
620 /*
621 * Download new Firmware, unless requested not to do so.
622 * This is made slightly trickier in some cases where the
623 * firmware of the ROM revision is newer than the revision
624 * compiled into the driver. So, where we used to compare
625 * versions of our f/w and the ROM f/w, now we just see
626 * whether we have f/w at all and whether a config flag
627 * has disabled our download.
628 */
629 if ((isp->isp_mdvec->dv_ispfw == NULL) ||
630 (isp->isp_confopts & ISP_CFG_NORELOAD)) {
631 dodnld = 0;
632 }
633
634 if (IS_23XX(isp))
635 code_org = ISP_CODE_ORG_2300;
636 else
637 code_org = ISP_CODE_ORG;
638
639 if (dodnld) {
640 isp->isp_mbxworkp = (void *) &isp->isp_mdvec->dv_ispfw[1];
641 isp->isp_mbxwrk0 = isp->isp_mdvec->dv_ispfw[3] - 1;
642 isp->isp_mbxwrk1 = code_org + 1;
643 mbs.param[0] = MBOX_WRITE_RAM_WORD;
644 mbs.param[1] = code_org;
645 mbs.param[2] = isp->isp_mdvec->dv_ispfw[0];
646 isp_mboxcmd(isp, &mbs, MBLOGNONE);
647 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
648 isp_prt(isp, ISP_LOGERR,
649 "F/W download failed at word %d",
650 isp->isp_mbxwrk1 - code_org);
651 dodnld = 0;
652 goto again;
653 }
654 /*
655 * Verify that it downloaded correctly.
656 */
657 mbs.param[0] = MBOX_VERIFY_CHECKSUM;
658 mbs.param[1] = code_org;
659 isp_mboxcmd(isp, &mbs, MBLOGNONE);
660 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
661 isp_prt(isp, ISP_LOGERR, "Ram Checksum Failure");
662 return;
663 }
664 isp->isp_loaded_fw = 1;
665 } else {
666 isp->isp_loaded_fw = 0;
667 isp_prt(isp, ISP_LOGDEBUG2, "skipping f/w download");
668 }
669
670 /*
671 * Now start it rolling.
672 *
673 * If we didn't actually download f/w,
674 * we still need to (re)start it.
675 */
676
677
678 mbs.param[0] = MBOX_EXEC_FIRMWARE;
679 mbs.param[1] = code_org;
262 default:
263 break;
264 }
265 /*
266 * While we're paused, reset the FPM module and FBM fifos.
267 */
268 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FPM0_REGS);
269 ISP_WRITE(isp, FPM_DIAG_CONFIG, FPM_SOFT_RESET);
270 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FB_REGS);
271 ISP_WRITE(isp, FBM_CMD, FBMCMD_FIFO_RESET_ALL);
272 ISP_WRITE(isp, BIU2100_CSR, BIU2100_RISC_REGS);
273 } else if (IS_1240(isp)) {
274 sdparam *sdp = isp->isp_param;
275 btype = "1240";
276 isp->isp_clock = 60;
277 sdp->isp_ultramode = 1;
278 sdp++;
279 sdp->isp_ultramode = 1;
280 /*
281 * XXX: Should probably do some bus sensing.
282 */
283 } else if (IS_ULTRA2(isp)) {
284 static const char m[] = "bus %d is in %s Mode";
285 u_int16_t l;
286 sdparam *sdp = isp->isp_param;
287
288 isp->isp_clock = 100;
289
290 if (IS_1280(isp))
291 btype = "1280";
292 else if (IS_1080(isp))
293 btype = "1080";
294 else if (IS_10160(isp))
295 btype = "10160";
296 else if (IS_12160(isp))
297 btype = "12160";
298 else
299 btype = "<UNKLVD>";
300
301 l = ISP_READ(isp, SXP_PINS_DIFF) & ISP1080_MODE_MASK;
302 switch (l) {
303 case ISP1080_LVD_MODE:
304 sdp->isp_lvdmode = 1;
305 isp_prt(isp, ISP_LOGCONFIG, m, 0, "LVD");
306 break;
307 case ISP1080_HVD_MODE:
308 sdp->isp_diffmode = 1;
309 isp_prt(isp, ISP_LOGCONFIG, m, 0, "Differential");
310 break;
311 case ISP1080_SE_MODE:
312 sdp->isp_ultramode = 1;
313 isp_prt(isp, ISP_LOGCONFIG, m, 0, "Single-Ended");
314 break;
315 default:
316 isp_prt(isp, ISP_LOGERR,
317 "unknown mode on bus %d (0x%x)", 0, l);
318 break;
319 }
320
321 if (IS_DUALBUS(isp)) {
322 sdp++;
323 l = ISP_READ(isp, SXP_PINS_DIFF|SXP_BANK1_SELECT);
324 l &= ISP1080_MODE_MASK;
325 switch(l) {
326 case ISP1080_LVD_MODE:
327 sdp->isp_lvdmode = 1;
328 isp_prt(isp, ISP_LOGCONFIG, m, 1, "LVD");
329 break;
330 case ISP1080_HVD_MODE:
331 sdp->isp_diffmode = 1;
332 isp_prt(isp, ISP_LOGCONFIG,
333 m, 1, "Differential");
334 break;
335 case ISP1080_SE_MODE:
336 sdp->isp_ultramode = 1;
337 isp_prt(isp, ISP_LOGCONFIG,
338 m, 1, "Single-Ended");
339 break;
340 default:
341 isp_prt(isp, ISP_LOGERR,
342 "unknown mode on bus %d (0x%x)", 1, l);
343 break;
344 }
345 }
346 } else {
347 sdparam *sdp = isp->isp_param;
348 i = ISP_READ(isp, BIU_CONF0) & BIU_CONF0_HW_MASK;
349 switch (i) {
350 default:
351 isp_prt(isp, ISP_LOGALL, "Unknown Chip Type 0x%x", i);
352 /* FALLTHROUGH */
353 case 1:
354 btype = "1020";
355 isp->isp_type = ISP_HA_SCSI_1020;
356 isp->isp_clock = 40;
357 break;
358 case 2:
359 /*
360 * Some 1020A chips are Ultra Capable, but don't
361 * run the clock rate up for that unless told to
362 * do so by the Ultra Capable bits being set.
363 */
364 btype = "1020A";
365 isp->isp_type = ISP_HA_SCSI_1020A;
366 isp->isp_clock = 40;
367 break;
368 case 3:
369 btype = "1040";
370 isp->isp_type = ISP_HA_SCSI_1040;
371 isp->isp_clock = 60;
372 break;
373 case 4:
374 btype = "1040A";
375 isp->isp_type = ISP_HA_SCSI_1040A;
376 isp->isp_clock = 60;
377 break;
378 case 5:
379 btype = "1040B";
380 isp->isp_type = ISP_HA_SCSI_1040B;
381 isp->isp_clock = 60;
382 break;
383 case 6:
384 btype = "1040C";
385 isp->isp_type = ISP_HA_SCSI_1040C;
386 isp->isp_clock = 60;
387 break;
388 }
389 /*
390 * Now, while we're at it, gather info about ultra
391 * and/or differential mode.
392 */
393 if (ISP_READ(isp, SXP_PINS_DIFF) & SXP_PINS_DIFF_MODE) {
394 isp_prt(isp, ISP_LOGCONFIG, "Differential Mode");
395 sdp->isp_diffmode = 1;
396 } else {
397 sdp->isp_diffmode = 0;
398 }
399 i = ISP_READ(isp, RISC_PSR);
400 if (isp->isp_bustype == ISP_BT_SBUS) {
401 i &= RISC_PSR_SBUS_ULTRA;
402 } else {
403 i &= RISC_PSR_PCI_ULTRA;
404 }
405 if (i != 0) {
406 isp_prt(isp, ISP_LOGCONFIG, "Ultra Mode Capable");
407 sdp->isp_ultramode = 1;
408 /*
409 * If we're in Ultra Mode, we have to be 60MHz clock-
410 * even for the SBus version.
411 */
412 isp->isp_clock = 60;
413 } else {
414 sdp->isp_ultramode = 0;
415 /*
416 * Clock is known. Gronk.
417 */
418 }
419
420 /*
421 * Machine dependent clock (if set) overrides
422 * our generic determinations.
423 */
424 if (isp->isp_mdvec->dv_clock) {
425 if (isp->isp_mdvec->dv_clock < isp->isp_clock) {
426 isp->isp_clock = isp->isp_mdvec->dv_clock;
427 }
428 }
429
430 }
431
432 /*
433 * Clear instrumentation
434 */
435 isp->isp_intcnt = isp->isp_intbogus = 0;
436
437 /*
438 * Do MD specific pre initialization
439 */
440 ISP_RESET0(isp);
441
442again:
443
444 /*
445 * Hit the chip over the head with hammer,
446 * and give the ISP a chance to recover.
447 */
448
449 if (IS_SCSI(isp)) {
450 ISP_WRITE(isp, BIU_ICR, BIU_ICR_SOFT_RESET);
451 /*
452 * A slight delay...
453 */
454 USEC_DELAY(100);
455
456 /*
457 * Clear data && control DMA engines.
458 */
459 ISP_WRITE(isp, CDMA_CONTROL,
460 DMA_CNTRL_CLEAR_CHAN | DMA_CNTRL_RESET_INT);
461 ISP_WRITE(isp, DDMA_CONTROL,
462 DMA_CNTRL_CLEAR_CHAN | DMA_CNTRL_RESET_INT);
463
464
465 } else {
466 ISP_WRITE(isp, BIU2100_CSR, BIU2100_SOFT_RESET);
467 /*
468 * A slight delay...
469 */
470 USEC_DELAY(100);
471
472 /*
473 * Clear data && control DMA engines.
474 */
475 ISP_WRITE(isp, CDMA2100_CONTROL,
476 DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
477 ISP_WRITE(isp, TDMA2100_CONTROL,
478 DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
479 ISP_WRITE(isp, RDMA2100_CONTROL,
480 DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
481 }
482
483 /*
484 * Wait for ISP to be ready to go...
485 */
486 loops = MBOX_DELAY_COUNT;
487 for (;;) {
488 if (IS_SCSI(isp)) {
489 if (!(ISP_READ(isp, BIU_ICR) & BIU_ICR_SOFT_RESET))
490 break;
491 } else {
492 if (!(ISP_READ(isp, BIU2100_CSR) & BIU2100_SOFT_RESET))
493 break;
494 }
495 USEC_DELAY(100);
496 if (--loops < 0) {
497 ISP_DUMPREGS(isp, "chip reset timed out");
498 return;
499 }
500 }
501
502 /*
503 * After we've fired this chip up, zero out the conf1 register
504 * for SCSI adapters and other settings for the 2100.
505 */
506
507 if (IS_SCSI(isp)) {
508 ISP_WRITE(isp, BIU_CONF1, 0);
509 } else {
510 ISP_WRITE(isp, BIU2100_CSR, 0);
511 }
512
513 /*
514 * Reset RISC Processor
515 */
516 ISP_WRITE(isp, HCCR, HCCR_CMD_RESET);
517 USEC_DELAY(100);
518 /* Clear semaphore register (just to be sure) */
519 ISP_WRITE(isp, BIU_SEMA, 0);
520
521 /*
522 * Establish some initial burst rate stuff.
523 * (only for the 1XX0 boards). This really should
524 * be done later after fetching from NVRAM.
525 */
526 if (IS_SCSI(isp)) {
527 u_int16_t tmp = isp->isp_mdvec->dv_conf1;
528 /*
529 * Busted FIFO. Turn off all but burst enables.
530 */
531 if (isp->isp_type == ISP_HA_SCSI_1040A) {
532 tmp &= BIU_BURST_ENABLE;
533 }
534 ISP_SETBITS(isp, BIU_CONF1, tmp);
535 if (tmp & BIU_BURST_ENABLE) {
536 ISP_SETBITS(isp, CDMA_CONF, DMA_ENABLE_BURST);
537 ISP_SETBITS(isp, DDMA_CONF, DMA_ENABLE_BURST);
538 }
539#ifdef PTI_CARDS
540 if (((sdparam *) isp->isp_param)->isp_ultramode) {
541 while (ISP_READ(isp, RISC_MTR) != 0x1313) {
542 ISP_WRITE(isp, RISC_MTR, 0x1313);
543 ISP_WRITE(isp, HCCR, HCCR_CMD_STEP);
544 }
545 } else {
546 ISP_WRITE(isp, RISC_MTR, 0x1212);
547 }
548 /*
549 * PTI specific register
550 */
551 ISP_WRITE(isp, RISC_EMB, DUAL_BANK)
552#else
553 ISP_WRITE(isp, RISC_MTR, 0x1212);
554#endif
555 } else {
556 ISP_WRITE(isp, RISC_MTR2100, 0x1212);
557 if (IS_2200(isp) || IS_23XX(isp)) {
558 ISP_WRITE(isp, HCCR, HCCR_2X00_DISABLE_PARITY_PAUSE);
559 }
560 }
561
562 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE); /* release paused processor */
563
564 /*
565 * Do MD specific post initialization
566 */
567 ISP_RESET1(isp);
568
569 /*
570 * Wait for everything to finish firing up.
571 *
572 * Avoid doing this on the 2312 because you can generate a PCI
573 * parity error (chip breakage).
574 */
575 if (IS_23XX(isp)) {
576 USEC_DELAY(5);
577 } else {
578 loops = MBOX_DELAY_COUNT;
579 while (ISP_READ(isp, OUTMAILBOX0) == MBOX_BUSY) {
580 USEC_DELAY(100);
581 if (--loops < 0) {
582 isp_prt(isp, ISP_LOGERR,
583 "MBOX_BUSY never cleared on reset");
584 return;
585 }
586 }
587 }
588
589 /*
590 * Up until this point we've done everything by just reading or
591 * setting registers. From this point on we rely on at least *some*
592 * kind of firmware running in the card.
593 */
594
595 /*
596 * Do some sanity checking.
597 */
598 mbs.param[0] = MBOX_NO_OP;
599 isp_mboxcmd(isp, &mbs, MBLOGALL);
600 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
601 return;
602 }
603
604 if (IS_SCSI(isp)) {
605 mbs.param[0] = MBOX_MAILBOX_REG_TEST;
606 mbs.param[1] = 0xdead;
607 mbs.param[2] = 0xbeef;
608 mbs.param[3] = 0xffff;
609 mbs.param[4] = 0x1111;
610 mbs.param[5] = 0xa5a5;
611 isp_mboxcmd(isp, &mbs, MBLOGALL);
612 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
613 return;
614 }
615 if (mbs.param[1] != 0xdead || mbs.param[2] != 0xbeef ||
616 mbs.param[3] != 0xffff || mbs.param[4] != 0x1111 ||
617 mbs.param[5] != 0xa5a5) {
618 isp_prt(isp, ISP_LOGERR,
619 "Register Test Failed (0x%x 0x%x 0x%x 0x%x 0x%x)",
620 mbs.param[1], mbs.param[2], mbs.param[3],
621 mbs.param[4], mbs.param[5]);
622 return;
623 }
624
625 }
626
627 /*
628 * Download new Firmware, unless requested not to do so.
629 * This is made slightly trickier in some cases where the
630 * firmware of the ROM revision is newer than the revision
631 * compiled into the driver. So, where we used to compare
632 * versions of our f/w and the ROM f/w, now we just see
633 * whether we have f/w at all and whether a config flag
634 * has disabled our download.
635 */
636 if ((isp->isp_mdvec->dv_ispfw == NULL) ||
637 (isp->isp_confopts & ISP_CFG_NORELOAD)) {
638 dodnld = 0;
639 }
640
641 if (IS_23XX(isp))
642 code_org = ISP_CODE_ORG_2300;
643 else
644 code_org = ISP_CODE_ORG;
645
646 if (dodnld) {
647 isp->isp_mbxworkp = (void *) &isp->isp_mdvec->dv_ispfw[1];
648 isp->isp_mbxwrk0 = isp->isp_mdvec->dv_ispfw[3] - 1;
649 isp->isp_mbxwrk1 = code_org + 1;
650 mbs.param[0] = MBOX_WRITE_RAM_WORD;
651 mbs.param[1] = code_org;
652 mbs.param[2] = isp->isp_mdvec->dv_ispfw[0];
653 isp_mboxcmd(isp, &mbs, MBLOGNONE);
654 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
655 isp_prt(isp, ISP_LOGERR,
656 "F/W download failed at word %d",
657 isp->isp_mbxwrk1 - code_org);
658 dodnld = 0;
659 goto again;
660 }
661 /*
662 * Verify that it downloaded correctly.
663 */
664 mbs.param[0] = MBOX_VERIFY_CHECKSUM;
665 mbs.param[1] = code_org;
666 isp_mboxcmd(isp, &mbs, MBLOGNONE);
667 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
668 isp_prt(isp, ISP_LOGERR, "Ram Checksum Failure");
669 return;
670 }
671 isp->isp_loaded_fw = 1;
672 } else {
673 isp->isp_loaded_fw = 0;
674 isp_prt(isp, ISP_LOGDEBUG2, "skipping f/w download");
675 }
676
677 /*
678 * Now start it rolling.
679 *
680 * If we didn't actually download f/w,
681 * we still need to (re)start it.
682 */
683
684
685 mbs.param[0] = MBOX_EXEC_FIRMWARE;
686 mbs.param[1] = code_org;
687 if (IS_2322(isp) || IS_24XX(isp)) {
688 if (isp->isp_loaded_fw) {
689 mbs.param[2] = 1;
690 } else {
691 mbs.param[2] = 0;
692 }
693 mbs.obits |= 2;
694 }
695
680 isp_mboxcmd(isp, &mbs, MBLOGNONE);
681 /*
682 * Give it a chance to start.
683 */
684 USEC_DELAY(500);
685
686 if (IS_SCSI(isp)) {
687 /*
688 * Set CLOCK RATE, but only if asked to.
689 */
690 if (isp->isp_clock) {
691 mbs.param[0] = MBOX_SET_CLOCK_RATE;
692 mbs.param[1] = isp->isp_clock;
693 isp_mboxcmd(isp, &mbs, MBLOGALL);
694 /* we will try not to care if this fails */
695 }
696 }
697
698 mbs.param[0] = MBOX_ABOUT_FIRMWARE;
699 isp_mboxcmd(isp, &mbs, MBLOGALL);
700 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
701 return;
702 }
703
704 /*
705 * The SBus firmware that we are using apparently does not return
706 * major, minor, micro revisions in the mailbox registers, which
707 * is really, really, annoying.
708 */
709 if (ISP_SBUS_SUPPORTED && isp->isp_bustype == ISP_BT_SBUS) {
710 if (dodnld) {
711#ifdef ISP_TARGET_MODE
712 isp->isp_fwrev[0] = 7;
713 isp->isp_fwrev[1] = 55;
714#else
715 isp->isp_fwrev[0] = 1;
716 isp->isp_fwrev[1] = 37;
717#endif
718 isp->isp_fwrev[2] = 0;
719 }
720 } else {
721 isp->isp_fwrev[0] = mbs.param[1];
722 isp->isp_fwrev[1] = mbs.param[2];
723 isp->isp_fwrev[2] = mbs.param[3];
724 }
725 isp_prt(isp, ISP_LOGCONFIG,
726 "Board Type %s, Chip Revision 0x%x, %s F/W Revision %d.%d.%d",
727 btype, isp->isp_revision, dodnld? "loaded" : "resident",
728 isp->isp_fwrev[0], isp->isp_fwrev[1], isp->isp_fwrev[2]);
729
730 if (IS_FC(isp)) {
731 /*
732 * We do not believe firmware attributes for 2100 code less
733 * than 1.17.0, unless it's the firmware we specifically
734 * are loading.
735 *
736 * Note that all 22XX and 23XX f/w is greater than 1.X.0.
737 */
738 if (!(ISP_FW_NEWER_THAN(isp, 1, 17, 0))) {
739#ifdef USE_SMALLER_2100_FIRMWARE
740 FCPARAM(isp)->isp_fwattr = ISP_FW_ATTR_SCCLUN;
741#else
742 FCPARAM(isp)->isp_fwattr = 0;
743#endif
744 } else {
745 FCPARAM(isp)->isp_fwattr = mbs.param[6];
746 isp_prt(isp, ISP_LOGDEBUG0,
747 "Firmware Attributes = 0x%x", mbs.param[6]);
748 }
696 isp_mboxcmd(isp, &mbs, MBLOGNONE);
697 /*
698 * Give it a chance to start.
699 */
700 USEC_DELAY(500);
701
702 if (IS_SCSI(isp)) {
703 /*
704 * Set CLOCK RATE, but only if asked to.
705 */
706 if (isp->isp_clock) {
707 mbs.param[0] = MBOX_SET_CLOCK_RATE;
708 mbs.param[1] = isp->isp_clock;
709 isp_mboxcmd(isp, &mbs, MBLOGALL);
710 /* we will try not to care if this fails */
711 }
712 }
713
714 mbs.param[0] = MBOX_ABOUT_FIRMWARE;
715 isp_mboxcmd(isp, &mbs, MBLOGALL);
716 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
717 return;
718 }
719
720 /*
721 * The SBus firmware that we are using apparently does not return
722 * major, minor, micro revisions in the mailbox registers, which
723 * is really, really, annoying.
724 */
725 if (ISP_SBUS_SUPPORTED && isp->isp_bustype == ISP_BT_SBUS) {
726 if (dodnld) {
727#ifdef ISP_TARGET_MODE
728 isp->isp_fwrev[0] = 7;
729 isp->isp_fwrev[1] = 55;
730#else
731 isp->isp_fwrev[0] = 1;
732 isp->isp_fwrev[1] = 37;
733#endif
734 isp->isp_fwrev[2] = 0;
735 }
736 } else {
737 isp->isp_fwrev[0] = mbs.param[1];
738 isp->isp_fwrev[1] = mbs.param[2];
739 isp->isp_fwrev[2] = mbs.param[3];
740 }
741 isp_prt(isp, ISP_LOGCONFIG,
742 "Board Type %s, Chip Revision 0x%x, %s F/W Revision %d.%d.%d",
743 btype, isp->isp_revision, dodnld? "loaded" : "resident",
744 isp->isp_fwrev[0], isp->isp_fwrev[1], isp->isp_fwrev[2]);
745
746 if (IS_FC(isp)) {
747 /*
748 * We do not believe firmware attributes for 2100 code less
749 * than 1.17.0, unless it's the firmware we specifically
750 * are loading.
751 *
752 * Note that all 22XX and 23XX f/w is greater than 1.X.0.
753 */
754 if (!(ISP_FW_NEWER_THAN(isp, 1, 17, 0))) {
755#ifdef USE_SMALLER_2100_FIRMWARE
756 FCPARAM(isp)->isp_fwattr = ISP_FW_ATTR_SCCLUN;
757#else
758 FCPARAM(isp)->isp_fwattr = 0;
759#endif
760 } else {
761 FCPARAM(isp)->isp_fwattr = mbs.param[6];
762 isp_prt(isp, ISP_LOGDEBUG0,
763 "Firmware Attributes = 0x%x", mbs.param[6]);
764 }
749 if (ISP_READ(isp, BIU2100_CSR) & BIU2100_PCI64) {
750 isp_prt(isp, ISP_LOGCONFIG,
751 "Installed in 64-Bit PCI slot");
765 if (IS_2KLOGIN(isp)) {
766 isp_prt(isp, ISP_LOGCONFIG, "2K Logins Supported");
752 }
753 }
754
755 if (isp->isp_romfw_rev[0] || isp->isp_romfw_rev[1] ||
756 isp->isp_romfw_rev[2]) {
757 isp_prt(isp, ISP_LOGCONFIG, "Last F/W revision was %d.%d.%d",
758 isp->isp_romfw_rev[0], isp->isp_romfw_rev[1],
759 isp->isp_romfw_rev[2]);
760 }
761
762 mbs.param[0] = MBOX_GET_FIRMWARE_STATUS;
763 isp_mboxcmd(isp, &mbs, MBLOGALL);
764 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
765 return;
766 }
767 isp->isp_maxcmds = mbs.param[2];
768 isp_prt(isp, ISP_LOGINFO,
769 "%d max I/O commands supported", mbs.param[2]);
770 isp_fw_state(isp);
771
772 /*
773 * Set up DMA for the request and result mailboxes.
774 */
775 if (ISP_MBOXDMASETUP(isp) != 0) {
776 isp_prt(isp, ISP_LOGERR, "Cannot setup DMA");
777 return;
778 }
779 isp->isp_state = ISP_RESETSTATE;
780
781 /*
782 * Okay- now that we have new firmware running, we now (re)set our
783 * notion of how many luns we support. This is somewhat tricky because
784 * if we haven't loaded firmware, we sometimes do not have an easy way
785 * of knowing how many luns we support.
786 *
787 * Expanded lun firmware gives you 32 luns for SCSI cards and
788 * 16384 luns for Fibre Channel cards.
789 *
790 * It turns out that even for QLogic 2100s with ROM 1.10 and above
791 * we do get a firmware attributes word returned in mailbox register 6.
792 *
793 * Because the lun is in a different position in the Request Queue
794 * Entry structure for Fibre Channel with expanded lun firmware, we
795 * can only support one lun (lun zero) when we don't know what kind
796 * of firmware we're running.
797 */
798 if (IS_SCSI(isp)) {
799 if (dodnld) {
800 if (IS_ULTRA2(isp) || IS_ULTRA3(isp)) {
801 isp->isp_maxluns = 32;
802 } else {
803 isp->isp_maxluns = 8;
804 }
805 } else {
806 isp->isp_maxluns = 8;
807 }
808 } else {
809 if (FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) {
810 isp->isp_maxluns = 16384;
811 } else {
812 isp->isp_maxluns = 16;
813 }
814 }
815}
816
817/*
818 * Initialize Parameters of Hardware to a known state.
819 *
820 * Locks are held before coming here.
821 */
822
823void
824isp_init(struct ispsoftc *isp)
825{
826 /*
827 * Must do this first to get defaults established.
828 */
829 isp_setdfltparm(isp, 0);
830 if (IS_DUALBUS(isp)) {
831 isp_setdfltparm(isp, 1);
832 }
833 if (IS_FC(isp)) {
834 isp_fibre_init(isp);
835 } else {
836 isp_scsi_init(isp);
837 }
838}
839
840static void
841isp_scsi_init(struct ispsoftc *isp)
842{
843 sdparam *sdp_chan0, *sdp_chan1;
844 mbreg_t mbs;
845
846 sdp_chan0 = isp->isp_param;
847 sdp_chan1 = sdp_chan0;
848 if (IS_DUALBUS(isp)) {
849 sdp_chan1++;
850 }
851
852 /*
853 * If we have no role (neither target nor initiator), return.
854 */
855 if (isp->isp_role == ISP_ROLE_NONE) {
856 return;
857 }
858
859 /* First do overall per-card settings. */
860
861 /*
862 * If we have fast memory timing enabled, turn it on.
863 */
864 if (sdp_chan0->isp_fast_mttr) {
865 ISP_WRITE(isp, RISC_MTR, 0x1313);
866 }
867
868 /*
869 * Set Retry Delay and Count.
870 * You set both channels at the same time.
871 */
767 }
768 }
769
770 if (isp->isp_romfw_rev[0] || isp->isp_romfw_rev[1] ||
771 isp->isp_romfw_rev[2]) {
772 isp_prt(isp, ISP_LOGCONFIG, "Last F/W revision was %d.%d.%d",
773 isp->isp_romfw_rev[0], isp->isp_romfw_rev[1],
774 isp->isp_romfw_rev[2]);
775 }
776
777 mbs.param[0] = MBOX_GET_FIRMWARE_STATUS;
778 isp_mboxcmd(isp, &mbs, MBLOGALL);
779 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
780 return;
781 }
782 isp->isp_maxcmds = mbs.param[2];
783 isp_prt(isp, ISP_LOGINFO,
784 "%d max I/O commands supported", mbs.param[2]);
785 isp_fw_state(isp);
786
787 /*
788 * Set up DMA for the request and result mailboxes.
789 */
790 if (ISP_MBOXDMASETUP(isp) != 0) {
791 isp_prt(isp, ISP_LOGERR, "Cannot setup DMA");
792 return;
793 }
794 isp->isp_state = ISP_RESETSTATE;
795
796 /*
797 * Okay- now that we have new firmware running, we now (re)set our
798 * notion of how many luns we support. This is somewhat tricky because
799 * if we haven't loaded firmware, we sometimes do not have an easy way
800 * of knowing how many luns we support.
801 *
802 * Expanded lun firmware gives you 32 luns for SCSI cards and
803 * 16384 luns for Fibre Channel cards.
804 *
805 * It turns out that even for QLogic 2100s with ROM 1.10 and above
806 * we do get a firmware attributes word returned in mailbox register 6.
807 *
808 * Because the lun is in a different position in the Request Queue
809 * Entry structure for Fibre Channel with expanded lun firmware, we
810 * can only support one lun (lun zero) when we don't know what kind
811 * of firmware we're running.
812 */
813 if (IS_SCSI(isp)) {
814 if (dodnld) {
815 if (IS_ULTRA2(isp) || IS_ULTRA3(isp)) {
816 isp->isp_maxluns = 32;
817 } else {
818 isp->isp_maxluns = 8;
819 }
820 } else {
821 isp->isp_maxluns = 8;
822 }
823 } else {
824 if (FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) {
825 isp->isp_maxluns = 16384;
826 } else {
827 isp->isp_maxluns = 16;
828 }
829 }
830}
831
832/*
833 * Initialize Parameters of Hardware to a known state.
834 *
835 * Locks are held before coming here.
836 */
837
838void
839isp_init(struct ispsoftc *isp)
840{
841 /*
842 * Must do this first to get defaults established.
843 */
844 isp_setdfltparm(isp, 0);
845 if (IS_DUALBUS(isp)) {
846 isp_setdfltparm(isp, 1);
847 }
848 if (IS_FC(isp)) {
849 isp_fibre_init(isp);
850 } else {
851 isp_scsi_init(isp);
852 }
853}
854
855static void
856isp_scsi_init(struct ispsoftc *isp)
857{
858 sdparam *sdp_chan0, *sdp_chan1;
859 mbreg_t mbs;
860
861 sdp_chan0 = isp->isp_param;
862 sdp_chan1 = sdp_chan0;
863 if (IS_DUALBUS(isp)) {
864 sdp_chan1++;
865 }
866
867 /*
868 * If we have no role (neither target nor initiator), return.
869 */
870 if (isp->isp_role == ISP_ROLE_NONE) {
871 return;
872 }
873
874 /* First do overall per-card settings. */
875
876 /*
877 * If we have fast memory timing enabled, turn it on.
878 */
879 if (sdp_chan0->isp_fast_mttr) {
880 ISP_WRITE(isp, RISC_MTR, 0x1313);
881 }
882
883 /*
884 * Set Retry Delay and Count.
885 * You set both channels at the same time.
886 */
887 MEMZERO(&mbs, sizeof (mbs));
872 mbs.param[0] = MBOX_SET_RETRY_COUNT;
873 mbs.param[1] = sdp_chan0->isp_retry_count;
874 mbs.param[2] = sdp_chan0->isp_retry_delay;
875 mbs.param[6] = sdp_chan1->isp_retry_count;
876 mbs.param[7] = sdp_chan1->isp_retry_delay;
877
878 isp_mboxcmd(isp, &mbs, MBLOGALL);
879 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
880 return;
881 }
882
883 /*
884 * Set ASYNC DATA SETUP time. This is very important.
885 */
886 mbs.param[0] = MBOX_SET_ASYNC_DATA_SETUP_TIME;
887 mbs.param[1] = sdp_chan0->isp_async_data_setup;
888 mbs.param[2] = sdp_chan1->isp_async_data_setup;
889 isp_mboxcmd(isp, &mbs, MBLOGALL);
890 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
891 return;
892 }
893
894 /*
895 * Set ACTIVE Negation State.
896 */
897 mbs.param[0] = MBOX_SET_ACT_NEG_STATE;
898 mbs.param[1] =
899 (sdp_chan0->isp_req_ack_active_neg << 4) |
900 (sdp_chan0->isp_data_line_active_neg << 5);
901 mbs.param[2] =
902 (sdp_chan1->isp_req_ack_active_neg << 4) |
903 (sdp_chan1->isp_data_line_active_neg << 5);
904
905 isp_mboxcmd(isp, &mbs, MBLOGNONE);
906 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
907 isp_prt(isp, ISP_LOGERR,
908 "failed to set active negation state (%d,%d), (%d,%d)",
909 sdp_chan0->isp_req_ack_active_neg,
910 sdp_chan0->isp_data_line_active_neg,
911 sdp_chan1->isp_req_ack_active_neg,
912 sdp_chan1->isp_data_line_active_neg);
913 /*
914 * But don't return.
915 */
916 }
917
918 /*
919 * Set the Tag Aging limit
920 */
921 mbs.param[0] = MBOX_SET_TAG_AGE_LIMIT;
922 mbs.param[1] = sdp_chan0->isp_tag_aging;
923 mbs.param[2] = sdp_chan1->isp_tag_aging;
924 isp_mboxcmd(isp, &mbs, MBLOGALL);
925 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
926 isp_prt(isp, ISP_LOGERR, "failed to set tag age limit (%d,%d)",
927 sdp_chan0->isp_tag_aging, sdp_chan1->isp_tag_aging);
928 return;
929 }
930
931 /*
932 * Set selection timeout.
933 */
934 mbs.param[0] = MBOX_SET_SELECT_TIMEOUT;
935 mbs.param[1] = sdp_chan0->isp_selection_timeout;
936 mbs.param[2] = sdp_chan1->isp_selection_timeout;
937 isp_mboxcmd(isp, &mbs, MBLOGALL);
938 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
939 return;
940 }
941
942 /* now do per-channel settings */
943 isp_scsi_channel_init(isp, 0);
944 if (IS_DUALBUS(isp))
945 isp_scsi_channel_init(isp, 1);
946
947 /*
948 * Now enable request/response queues
949 */
950
951 if (IS_ULTRA2(isp) || IS_1240(isp)) {
952 mbs.param[0] = MBOX_INIT_RES_QUEUE_A64;
953 mbs.param[1] = RESULT_QUEUE_LEN(isp);
954 mbs.param[2] = DMA_WD1(isp->isp_result_dma);
955 mbs.param[3] = DMA_WD0(isp->isp_result_dma);
956 mbs.param[4] = 0;
957 mbs.param[6] = DMA_WD3(isp->isp_result_dma);
958 mbs.param[7] = DMA_WD2(isp->isp_result_dma);
959 isp_mboxcmd(isp, &mbs, MBLOGALL);
960 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
961 return;
962 }
963 isp->isp_residx = mbs.param[5];
964
965 mbs.param[0] = MBOX_INIT_REQ_QUEUE_A64;
966 mbs.param[1] = RQUEST_QUEUE_LEN(isp);
967 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
968 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
969 mbs.param[5] = 0;
970 mbs.param[6] = DMA_WD3(isp->isp_result_dma);
971 mbs.param[7] = DMA_WD2(isp->isp_result_dma);
972 isp_mboxcmd(isp, &mbs, MBLOGALL);
973 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
974 return;
975 }
976 isp->isp_reqidx = isp->isp_reqodx = mbs.param[4];
977 } else {
978 mbs.param[0] = MBOX_INIT_RES_QUEUE;
979 mbs.param[1] = RESULT_QUEUE_LEN(isp);
980 mbs.param[2] = DMA_WD1(isp->isp_result_dma);
981 mbs.param[3] = DMA_WD0(isp->isp_result_dma);
982 mbs.param[4] = 0;
983 isp_mboxcmd(isp, &mbs, MBLOGALL);
984 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
985 return;
986 }
987 isp->isp_residx = mbs.param[5];
988
989 mbs.param[0] = MBOX_INIT_REQ_QUEUE;
990 mbs.param[1] = RQUEST_QUEUE_LEN(isp);
991 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
992 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
993 mbs.param[5] = 0;
994 isp_mboxcmd(isp, &mbs, MBLOGALL);
995 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
996 return;
997 }
998 isp->isp_reqidx = isp->isp_reqodx = mbs.param[4];
999 }
1000
1001 /*
1002 * Turn on Fast Posting, LVD transitions
1003 *
1004 * Ultra2 F/W always has had fast posting (and LVD transitions)
1005 *
1006 * Ultra and older (i.e., SBus) cards may not. It's just safer
1007 * to assume not for them.
1008 */
1009
1010 mbs.param[0] = MBOX_SET_FW_FEATURES;
1011 mbs.param[1] = 0;
1012 if (IS_ULTRA2(isp))
1013 mbs.param[1] |= FW_FEATURE_LVD_NOTIFY;
1014#ifndef ISP_NO_RIO
1015 if (IS_ULTRA2(isp) || IS_1240(isp))
1016 mbs.param[1] |= FW_FEATURE_RIO_16BIT;
1017#else
1018#ifndef ISP_NO_FASTPOST
1019 if (IS_ULTRA2(isp) || IS_1240(isp))
1020 mbs.param[1] |= FW_FEATURE_FAST_POST;
1021#endif
1022#endif
1023 if (mbs.param[1] != 0) {
1024 u_int16_t sfeat = mbs.param[1];
1025 isp_mboxcmd(isp, &mbs, MBLOGALL);
1026 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1027 isp_prt(isp, ISP_LOGINFO,
1028 "Enabled FW features (0x%x)", sfeat);
1029 }
1030 }
1031
1032 /*
1033 * Let the outer layers decide whether to issue a SCSI bus reset.
1034 */
1035 isp->isp_state = ISP_INITSTATE;
1036}
1037
1038static void
1039isp_scsi_channel_init(struct ispsoftc *isp, int channel)
1040{
1041 sdparam *sdp;
1042 mbreg_t mbs;
1043 int tgt;
1044
1045 sdp = isp->isp_param;
1046 sdp += channel;
1047
1048 /*
1049 * Set (possibly new) Initiator ID.
1050 */
888 mbs.param[0] = MBOX_SET_RETRY_COUNT;
889 mbs.param[1] = sdp_chan0->isp_retry_count;
890 mbs.param[2] = sdp_chan0->isp_retry_delay;
891 mbs.param[6] = sdp_chan1->isp_retry_count;
892 mbs.param[7] = sdp_chan1->isp_retry_delay;
893
894 isp_mboxcmd(isp, &mbs, MBLOGALL);
895 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
896 return;
897 }
898
899 /*
900 * Set ASYNC DATA SETUP time. This is very important.
901 */
902 mbs.param[0] = MBOX_SET_ASYNC_DATA_SETUP_TIME;
903 mbs.param[1] = sdp_chan0->isp_async_data_setup;
904 mbs.param[2] = sdp_chan1->isp_async_data_setup;
905 isp_mboxcmd(isp, &mbs, MBLOGALL);
906 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
907 return;
908 }
909
910 /*
911 * Set ACTIVE Negation State.
912 */
913 mbs.param[0] = MBOX_SET_ACT_NEG_STATE;
914 mbs.param[1] =
915 (sdp_chan0->isp_req_ack_active_neg << 4) |
916 (sdp_chan0->isp_data_line_active_neg << 5);
917 mbs.param[2] =
918 (sdp_chan1->isp_req_ack_active_neg << 4) |
919 (sdp_chan1->isp_data_line_active_neg << 5);
920
921 isp_mboxcmd(isp, &mbs, MBLOGNONE);
922 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
923 isp_prt(isp, ISP_LOGERR,
924 "failed to set active negation state (%d,%d), (%d,%d)",
925 sdp_chan0->isp_req_ack_active_neg,
926 sdp_chan0->isp_data_line_active_neg,
927 sdp_chan1->isp_req_ack_active_neg,
928 sdp_chan1->isp_data_line_active_neg);
929 /*
930 * But don't return.
931 */
932 }
933
934 /*
935 * Set the Tag Aging limit
936 */
937 mbs.param[0] = MBOX_SET_TAG_AGE_LIMIT;
938 mbs.param[1] = sdp_chan0->isp_tag_aging;
939 mbs.param[2] = sdp_chan1->isp_tag_aging;
940 isp_mboxcmd(isp, &mbs, MBLOGALL);
941 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
942 isp_prt(isp, ISP_LOGERR, "failed to set tag age limit (%d,%d)",
943 sdp_chan0->isp_tag_aging, sdp_chan1->isp_tag_aging);
944 return;
945 }
946
947 /*
948 * Set selection timeout.
949 */
950 mbs.param[0] = MBOX_SET_SELECT_TIMEOUT;
951 mbs.param[1] = sdp_chan0->isp_selection_timeout;
952 mbs.param[2] = sdp_chan1->isp_selection_timeout;
953 isp_mboxcmd(isp, &mbs, MBLOGALL);
954 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
955 return;
956 }
957
958 /* now do per-channel settings */
959 isp_scsi_channel_init(isp, 0);
960 if (IS_DUALBUS(isp))
961 isp_scsi_channel_init(isp, 1);
962
963 /*
964 * Now enable request/response queues
965 */
966
967 if (IS_ULTRA2(isp) || IS_1240(isp)) {
968 mbs.param[0] = MBOX_INIT_RES_QUEUE_A64;
969 mbs.param[1] = RESULT_QUEUE_LEN(isp);
970 mbs.param[2] = DMA_WD1(isp->isp_result_dma);
971 mbs.param[3] = DMA_WD0(isp->isp_result_dma);
972 mbs.param[4] = 0;
973 mbs.param[6] = DMA_WD3(isp->isp_result_dma);
974 mbs.param[7] = DMA_WD2(isp->isp_result_dma);
975 isp_mboxcmd(isp, &mbs, MBLOGALL);
976 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
977 return;
978 }
979 isp->isp_residx = mbs.param[5];
980
981 mbs.param[0] = MBOX_INIT_REQ_QUEUE_A64;
982 mbs.param[1] = RQUEST_QUEUE_LEN(isp);
983 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
984 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
985 mbs.param[5] = 0;
986 mbs.param[6] = DMA_WD3(isp->isp_result_dma);
987 mbs.param[7] = DMA_WD2(isp->isp_result_dma);
988 isp_mboxcmd(isp, &mbs, MBLOGALL);
989 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
990 return;
991 }
992 isp->isp_reqidx = isp->isp_reqodx = mbs.param[4];
993 } else {
994 mbs.param[0] = MBOX_INIT_RES_QUEUE;
995 mbs.param[1] = RESULT_QUEUE_LEN(isp);
996 mbs.param[2] = DMA_WD1(isp->isp_result_dma);
997 mbs.param[3] = DMA_WD0(isp->isp_result_dma);
998 mbs.param[4] = 0;
999 isp_mboxcmd(isp, &mbs, MBLOGALL);
1000 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1001 return;
1002 }
1003 isp->isp_residx = mbs.param[5];
1004
1005 mbs.param[0] = MBOX_INIT_REQ_QUEUE;
1006 mbs.param[1] = RQUEST_QUEUE_LEN(isp);
1007 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
1008 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
1009 mbs.param[5] = 0;
1010 isp_mboxcmd(isp, &mbs, MBLOGALL);
1011 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1012 return;
1013 }
1014 isp->isp_reqidx = isp->isp_reqodx = mbs.param[4];
1015 }
1016
1017 /*
1018 * Turn on Fast Posting, LVD transitions
1019 *
1020 * Ultra2 F/W always has had fast posting (and LVD transitions)
1021 *
1022 * Ultra and older (i.e., SBus) cards may not. It's just safer
1023 * to assume not for them.
1024 */
1025
1026 mbs.param[0] = MBOX_SET_FW_FEATURES;
1027 mbs.param[1] = 0;
1028 if (IS_ULTRA2(isp))
1029 mbs.param[1] |= FW_FEATURE_LVD_NOTIFY;
1030#ifndef ISP_NO_RIO
1031 if (IS_ULTRA2(isp) || IS_1240(isp))
1032 mbs.param[1] |= FW_FEATURE_RIO_16BIT;
1033#else
1034#ifndef ISP_NO_FASTPOST
1035 if (IS_ULTRA2(isp) || IS_1240(isp))
1036 mbs.param[1] |= FW_FEATURE_FAST_POST;
1037#endif
1038#endif
1039 if (mbs.param[1] != 0) {
1040 u_int16_t sfeat = mbs.param[1];
1041 isp_mboxcmd(isp, &mbs, MBLOGALL);
1042 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1043 isp_prt(isp, ISP_LOGINFO,
1044 "Enabled FW features (0x%x)", sfeat);
1045 }
1046 }
1047
1048 /*
1049 * Let the outer layers decide whether to issue a SCSI bus reset.
1050 */
1051 isp->isp_state = ISP_INITSTATE;
1052}
1053
1054static void
1055isp_scsi_channel_init(struct ispsoftc *isp, int channel)
1056{
1057 sdparam *sdp;
1058 mbreg_t mbs;
1059 int tgt;
1060
1061 sdp = isp->isp_param;
1062 sdp += channel;
1063
1064 /*
1065 * Set (possibly new) Initiator ID.
1066 */
1067 MEMZERO(&mbs, sizeof (mbs));
1051 mbs.param[0] = MBOX_SET_INIT_SCSI_ID;
1052 mbs.param[1] = (channel << 7) | sdp->isp_initiator_id;
1053 isp_mboxcmd(isp, &mbs, MBLOGALL);
1054 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1055 return;
1056 }
1057 isp_prt(isp, ISP_LOGINFO, "Initiator ID is %d on Channel %d",
1058 sdp->isp_initiator_id, channel);
1059
1060
1061 /*
1062 * Set current per-target parameters to an initial safe minimum.
1063 */
1064 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
1065 int lun;
1066 u_int16_t sdf;
1067
1068 if (sdp->isp_devparam[tgt].dev_enable == 0) {
1069 continue;
1070 }
1071#ifndef ISP_TARGET_MODE
1072 sdf = sdp->isp_devparam[tgt].goal_flags;
1073 sdf &= DPARM_SAFE_DFLT;
1074 /*
1075 * It is not quite clear when this changed over so that
1076 * we could force narrow and async for 1000/1020 cards,
1077 * but assume that this is only the case for loaded
1078 * firmware.
1079 */
1080 if (isp->isp_loaded_fw) {
1081 sdf |= DPARM_NARROW | DPARM_ASYNC;
1082 }
1083#else
1084 /*
1085 * The !$*!)$!$)* f/w uses the same index into some
1086 * internal table to decide how to respond to negotiations,
1087 * so if we've said "let's be safe" for ID X, and ID X
1088 * selects *us*, the negotiations will back to 'safe'
1089 * (as in narrow/async). What the f/w *should* do is
1090 * use the initiator id settings to decide how to respond.
1091 */
1092 sdp->isp_devparam[tgt].goal_flags = sdf = DPARM_DEFAULT;
1093#endif
1094 mbs.param[0] = MBOX_SET_TARGET_PARAMS;
1095 mbs.param[1] = (channel << 15) | (tgt << 8);
1096 mbs.param[2] = sdf;
1097 if ((sdf & DPARM_SYNC) == 0) {
1098 mbs.param[3] = 0;
1099 } else {
1100 mbs.param[3] =
1101 (sdp->isp_devparam[tgt].goal_offset << 8) |
1102 (sdp->isp_devparam[tgt].goal_period);
1103 }
1104 isp_prt(isp, ISP_LOGDEBUG0,
1105 "Initial Settings bus%d tgt%d flags 0x%x off 0x%x per 0x%x",
1106 channel, tgt, mbs.param[2], mbs.param[3] >> 8,
1107 mbs.param[3] & 0xff);
1108 isp_mboxcmd(isp, &mbs, MBLOGNONE);
1109 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1110 sdf = DPARM_SAFE_DFLT;
1111 mbs.param[0] = MBOX_SET_TARGET_PARAMS;
1112 mbs.param[1] = (tgt << 8) | (channel << 15);
1113 mbs.param[2] = sdf;
1114 mbs.param[3] = 0;
1115 isp_mboxcmd(isp, &mbs, MBLOGALL);
1116 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1117 continue;
1118 }
1119 }
1120
1121 /*
1122 * We don't update any information directly from the f/w
1123 * because we need to run at least one command to cause a
1124 * new state to be latched up. So, we just assume that we
1125 * converge to the values we just had set.
1126 *
1127 * Ensure that we don't believe tagged queuing is enabled yet.
1128 * It turns out that sometimes the ISP just ignores our
1129 * attempts to set parameters for devices that it hasn't
1130 * seen yet.
1131 */
1132 sdp->isp_devparam[tgt].actv_flags = sdf & ~DPARM_TQING;
1133 for (lun = 0; lun < (int) isp->isp_maxluns; lun++) {
1134 mbs.param[0] = MBOX_SET_DEV_QUEUE_PARAMS;
1135 mbs.param[1] = (channel << 15) | (tgt << 8) | lun;
1136 mbs.param[2] = sdp->isp_max_queue_depth;
1137 mbs.param[3] = sdp->isp_devparam[tgt].exc_throttle;
1138 isp_mboxcmd(isp, &mbs, MBLOGALL);
1139 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1140 break;
1141 }
1142 }
1143 }
1144 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
1145 if (sdp->isp_devparam[tgt].dev_refresh) {
1146 isp->isp_sendmarker |= (1 << channel);
1147 isp->isp_update |= (1 << channel);
1148 break;
1149 }
1150 }
1151}
1152
1153/*
1154 * Fibre Channel specific initialization.
1155 *
1156 * Locks are held before coming here.
1157 */
1158static void
1159isp_fibre_init(struct ispsoftc *isp)
1160{
1161 fcparam *fcp;
1162 isp_icb_t local, *icbp = &local;
1163 mbreg_t mbs;
1164 int loopid;
1165 u_int64_t nwwn, pwwn;
1166
1167 fcp = isp->isp_param;
1168
1169 /*
1170 * Do this *before* initializing the firmware.
1171 */
1172 isp_mark_getpdb_all(isp);
1173 fcp->isp_fwstate = FW_CONFIG_WAIT;
1174 fcp->isp_loopstate = LOOP_NIL;
1175
1176 /*
1177 * If we have no role (neither target nor initiator), return.
1178 */
1179 if (isp->isp_role == ISP_ROLE_NONE) {
1180 return;
1181 }
1182
1183 loopid = fcp->isp_loopid;
1184 MEMZERO(icbp, sizeof (*icbp));
1185 icbp->icb_version = ICB_VERSION1;
1186
1187 /*
1188 * Firmware Options are either retrieved from NVRAM or
1189 * are patched elsewhere. We check them for sanity here
1190 * and make changes based on board revision, but otherwise
1191 * let others decide policy.
1192 */
1193
1194 /*
1195 * If this is a 2100 < revision 5, we have to turn off FAIRNESS.
1196 */
1197 if ((isp->isp_type == ISP_HA_FC_2100) && isp->isp_revision < 5) {
1198 fcp->isp_fwoptions &= ~ICBOPT_FAIRNESS;
1199 }
1200
1201 /*
1202 * We have to use FULL LOGIN even though it resets the loop too much
1203 * because otherwise port database entries don't get updated after
1204 * a LIP- this is a known f/w bug for 2100 f/w less than 1.17.0.
1205 */
1206 if (!ISP_FW_NEWER_THAN(isp, 1, 17, 0)) {
1207 fcp->isp_fwoptions |= ICBOPT_FULL_LOGIN;
1208 }
1209
1210 /*
1211 * Insist on Port Database Update Async notifications
1212 */
1213 fcp->isp_fwoptions |= ICBOPT_PDBCHANGE_AE;
1214
1215 /*
1216 * Make sure that target role reflects into fwoptions.
1217 */
1218 if (isp->isp_role & ISP_ROLE_TARGET) {
1219 fcp->isp_fwoptions |= ICBOPT_TGT_ENABLE;
1220 } else {
1221 fcp->isp_fwoptions &= ~ICBOPT_TGT_ENABLE;
1222 }
1223
1224 if (isp->isp_role & ISP_ROLE_INITIATOR) {
1225 fcp->isp_fwoptions &= ~ICBOPT_INI_DISABLE;
1226 } else {
1227 fcp->isp_fwoptions |= ICBOPT_INI_DISABLE;
1228 }
1229
1230 /*
1231 * Propagate all of this into the ICB structure.
1232 */
1233 icbp->icb_fwoptions = fcp->isp_fwoptions;
1234 icbp->icb_maxfrmlen = fcp->isp_maxfrmlen;
1235 if (icbp->icb_maxfrmlen < ICB_MIN_FRMLEN ||
1236 icbp->icb_maxfrmlen > ICB_MAX_FRMLEN) {
1237 isp_prt(isp, ISP_LOGERR,
1238 "bad frame length (%d) from NVRAM- using %d",
1239 fcp->isp_maxfrmlen, ICB_DFLT_FRMLEN);
1240 icbp->icb_maxfrmlen = ICB_DFLT_FRMLEN;
1241 }
1242 icbp->icb_maxalloc = fcp->isp_maxalloc;
1243 if (icbp->icb_maxalloc < 1) {
1244 isp_prt(isp, ISP_LOGERR,
1245 "bad maximum allocation (%d)- using 16", fcp->isp_maxalloc);
1246 icbp->icb_maxalloc = 16;
1247 }
1248 icbp->icb_execthrottle = fcp->isp_execthrottle;
1249 if (icbp->icb_execthrottle < 1) {
1250 isp_prt(isp, ISP_LOGERR,
1251 "bad execution throttle of %d- using 16",
1252 fcp->isp_execthrottle);
1253 icbp->icb_execthrottle = ICB_DFLT_THROTTLE;
1254 }
1255 icbp->icb_retry_delay = fcp->isp_retry_delay;
1256 icbp->icb_retry_count = fcp->isp_retry_count;
1257 icbp->icb_hardaddr = loopid;
1258 if (icbp->icb_hardaddr >= 125) {
1259 /*
1068 mbs.param[0] = MBOX_SET_INIT_SCSI_ID;
1069 mbs.param[1] = (channel << 7) | sdp->isp_initiator_id;
1070 isp_mboxcmd(isp, &mbs, MBLOGALL);
1071 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1072 return;
1073 }
1074 isp_prt(isp, ISP_LOGINFO, "Initiator ID is %d on Channel %d",
1075 sdp->isp_initiator_id, channel);
1076
1077
1078 /*
1079 * Set current per-target parameters to an initial safe minimum.
1080 */
1081 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
1082 int lun;
1083 u_int16_t sdf;
1084
1085 if (sdp->isp_devparam[tgt].dev_enable == 0) {
1086 continue;
1087 }
1088#ifndef ISP_TARGET_MODE
1089 sdf = sdp->isp_devparam[tgt].goal_flags;
1090 sdf &= DPARM_SAFE_DFLT;
1091 /*
1092 * It is not quite clear when this changed over so that
1093 * we could force narrow and async for 1000/1020 cards,
1094 * but assume that this is only the case for loaded
1095 * firmware.
1096 */
1097 if (isp->isp_loaded_fw) {
1098 sdf |= DPARM_NARROW | DPARM_ASYNC;
1099 }
1100#else
1101 /*
1102 * The !$*!)$!$)* f/w uses the same index into some
1103 * internal table to decide how to respond to negotiations,
1104 * so if we've said "let's be safe" for ID X, and ID X
1105 * selects *us*, the negotiations will back to 'safe'
1106 * (as in narrow/async). What the f/w *should* do is
1107 * use the initiator id settings to decide how to respond.
1108 */
1109 sdp->isp_devparam[tgt].goal_flags = sdf = DPARM_DEFAULT;
1110#endif
1111 mbs.param[0] = MBOX_SET_TARGET_PARAMS;
1112 mbs.param[1] = (channel << 15) | (tgt << 8);
1113 mbs.param[2] = sdf;
1114 if ((sdf & DPARM_SYNC) == 0) {
1115 mbs.param[3] = 0;
1116 } else {
1117 mbs.param[3] =
1118 (sdp->isp_devparam[tgt].goal_offset << 8) |
1119 (sdp->isp_devparam[tgt].goal_period);
1120 }
1121 isp_prt(isp, ISP_LOGDEBUG0,
1122 "Initial Settings bus%d tgt%d flags 0x%x off 0x%x per 0x%x",
1123 channel, tgt, mbs.param[2], mbs.param[3] >> 8,
1124 mbs.param[3] & 0xff);
1125 isp_mboxcmd(isp, &mbs, MBLOGNONE);
1126 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1127 sdf = DPARM_SAFE_DFLT;
1128 mbs.param[0] = MBOX_SET_TARGET_PARAMS;
1129 mbs.param[1] = (tgt << 8) | (channel << 15);
1130 mbs.param[2] = sdf;
1131 mbs.param[3] = 0;
1132 isp_mboxcmd(isp, &mbs, MBLOGALL);
1133 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1134 continue;
1135 }
1136 }
1137
1138 /*
1139 * We don't update any information directly from the f/w
1140 * because we need to run at least one command to cause a
1141 * new state to be latched up. So, we just assume that we
1142 * converge to the values we just had set.
1143 *
1144 * Ensure that we don't believe tagged queuing is enabled yet.
1145 * It turns out that sometimes the ISP just ignores our
1146 * attempts to set parameters for devices that it hasn't
1147 * seen yet.
1148 */
1149 sdp->isp_devparam[tgt].actv_flags = sdf & ~DPARM_TQING;
1150 for (lun = 0; lun < (int) isp->isp_maxluns; lun++) {
1151 mbs.param[0] = MBOX_SET_DEV_QUEUE_PARAMS;
1152 mbs.param[1] = (channel << 15) | (tgt << 8) | lun;
1153 mbs.param[2] = sdp->isp_max_queue_depth;
1154 mbs.param[3] = sdp->isp_devparam[tgt].exc_throttle;
1155 isp_mboxcmd(isp, &mbs, MBLOGALL);
1156 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1157 break;
1158 }
1159 }
1160 }
1161 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
1162 if (sdp->isp_devparam[tgt].dev_refresh) {
1163 isp->isp_sendmarker |= (1 << channel);
1164 isp->isp_update |= (1 << channel);
1165 break;
1166 }
1167 }
1168}
1169
1170/*
1171 * Fibre Channel specific initialization.
1172 *
1173 * Locks are held before coming here.
1174 */
1175static void
1176isp_fibre_init(struct ispsoftc *isp)
1177{
1178 fcparam *fcp;
1179 isp_icb_t local, *icbp = &local;
1180 mbreg_t mbs;
1181 int loopid;
1182 u_int64_t nwwn, pwwn;
1183
1184 fcp = isp->isp_param;
1185
1186 /*
1187 * Do this *before* initializing the firmware.
1188 */
1189 isp_mark_getpdb_all(isp);
1190 fcp->isp_fwstate = FW_CONFIG_WAIT;
1191 fcp->isp_loopstate = LOOP_NIL;
1192
1193 /*
1194 * If we have no role (neither target nor initiator), return.
1195 */
1196 if (isp->isp_role == ISP_ROLE_NONE) {
1197 return;
1198 }
1199
1200 loopid = fcp->isp_loopid;
1201 MEMZERO(icbp, sizeof (*icbp));
1202 icbp->icb_version = ICB_VERSION1;
1203
1204 /*
1205 * Firmware Options are either retrieved from NVRAM or
1206 * are patched elsewhere. We check them for sanity here
1207 * and make changes based on board revision, but otherwise
1208 * let others decide policy.
1209 */
1210
1211 /*
1212 * If this is a 2100 < revision 5, we have to turn off FAIRNESS.
1213 */
1214 if ((isp->isp_type == ISP_HA_FC_2100) && isp->isp_revision < 5) {
1215 fcp->isp_fwoptions &= ~ICBOPT_FAIRNESS;
1216 }
1217
1218 /*
1219 * We have to use FULL LOGIN even though it resets the loop too much
1220 * because otherwise port database entries don't get updated after
1221 * a LIP- this is a known f/w bug for 2100 f/w less than 1.17.0.
1222 */
1223 if (!ISP_FW_NEWER_THAN(isp, 1, 17, 0)) {
1224 fcp->isp_fwoptions |= ICBOPT_FULL_LOGIN;
1225 }
1226
1227 /*
1228 * Insist on Port Database Update Async notifications
1229 */
1230 fcp->isp_fwoptions |= ICBOPT_PDBCHANGE_AE;
1231
1232 /*
1233 * Make sure that target role reflects into fwoptions.
1234 */
1235 if (isp->isp_role & ISP_ROLE_TARGET) {
1236 fcp->isp_fwoptions |= ICBOPT_TGT_ENABLE;
1237 } else {
1238 fcp->isp_fwoptions &= ~ICBOPT_TGT_ENABLE;
1239 }
1240
1241 if (isp->isp_role & ISP_ROLE_INITIATOR) {
1242 fcp->isp_fwoptions &= ~ICBOPT_INI_DISABLE;
1243 } else {
1244 fcp->isp_fwoptions |= ICBOPT_INI_DISABLE;
1245 }
1246
1247 /*
1248 * Propagate all of this into the ICB structure.
1249 */
1250 icbp->icb_fwoptions = fcp->isp_fwoptions;
1251 icbp->icb_maxfrmlen = fcp->isp_maxfrmlen;
1252 if (icbp->icb_maxfrmlen < ICB_MIN_FRMLEN ||
1253 icbp->icb_maxfrmlen > ICB_MAX_FRMLEN) {
1254 isp_prt(isp, ISP_LOGERR,
1255 "bad frame length (%d) from NVRAM- using %d",
1256 fcp->isp_maxfrmlen, ICB_DFLT_FRMLEN);
1257 icbp->icb_maxfrmlen = ICB_DFLT_FRMLEN;
1258 }
1259 icbp->icb_maxalloc = fcp->isp_maxalloc;
1260 if (icbp->icb_maxalloc < 1) {
1261 isp_prt(isp, ISP_LOGERR,
1262 "bad maximum allocation (%d)- using 16", fcp->isp_maxalloc);
1263 icbp->icb_maxalloc = 16;
1264 }
1265 icbp->icb_execthrottle = fcp->isp_execthrottle;
1266 if (icbp->icb_execthrottle < 1) {
1267 isp_prt(isp, ISP_LOGERR,
1268 "bad execution throttle of %d- using 16",
1269 fcp->isp_execthrottle);
1270 icbp->icb_execthrottle = ICB_DFLT_THROTTLE;
1271 }
1272 icbp->icb_retry_delay = fcp->isp_retry_delay;
1273 icbp->icb_retry_count = fcp->isp_retry_count;
1274 icbp->icb_hardaddr = loopid;
1275 if (icbp->icb_hardaddr >= 125) {
1276 /*
1260 * We end up with a Loop ID of 255 for F-Port topologies
1277 * We end up with these Loop IDs for F-Port topologies
1261 */
1278 */
1262 if (icbp->icb_hardaddr != 255) {
1279 if (icbp->icb_hardaddr != 0xff || icbp->icb_hardaddr != 0x800) {
1263 isp_prt(isp, ISP_LOGERR,
1264 "bad hard address %u- resetting to zero",
1265 icbp->icb_hardaddr);
1266 }
1267 icbp->icb_hardaddr = 0;
1268 }
1269 /*
1270 * Right now we just set extended options to prefer point-to-point
1271 * over loop based upon some soft config options.
1272 *
1273 * NB: for the 2300, ICBOPT_EXTENDED is required.
1274 */
1275 if (IS_2200(isp) || IS_23XX(isp)) {
1276 icbp->icb_fwoptions |= ICBOPT_EXTENDED;
1277 /*
1278 * Prefer or force Point-To-Point instead Loop?
1279 */
1280 switch(isp->isp_confopts & ISP_CFG_PORT_PREF) {
1281 case ISP_CFG_NPORT:
1282 icbp->icb_xfwoptions |= ICBXOPT_PTP_2_LOOP;
1283 break;
1284 case ISP_CFG_NPORT_ONLY:
1285 icbp->icb_xfwoptions |= ICBXOPT_PTP_ONLY;
1286 break;
1287 case ISP_CFG_LPORT_ONLY:
1288 icbp->icb_xfwoptions |= ICBXOPT_LOOP_ONLY;
1289 break;
1290 default:
1291 icbp->icb_xfwoptions |= ICBXOPT_LOOP_2_PTP;
1292 break;
1293 }
1294 if (IS_23XX(isp)) {
1295 /*
1296 * QLogic recommends that FAST Posting be turned
1297 * off for 23XX cards and instead allow the HBA
1298 * to write response queue entries and interrupt
1299 * after a delay (ZIO).
1300 *
1301 * If we set ZIO, it will disable fast posting,
1302 * so we don't need to clear it in fwoptions.
1303 *
1304 * Depending on the role we're selecting, we
1305 * chose fast posting or not as it still is
1306 * a win for target mode.
1307 */
1308#ifndef ISP_NO_ZIO
1309 if (isp->isp_role == ISP_ROLE_TARGET) {
1310 icbp->icb_fwoptions |= ICBOPT_FAST_POST;
1311 } else {
1312 icbp->icb_xfwoptions |= ICBXOPT_ZIO;
1313 }
1314#else
1315 icbp->icb_fwoptions |= ICBOPT_FAST_POST;
1316#endif
1317#if 0
1318 /*
1319 * Values, in 100us increments. The default
1320 * is 2 (200us) if a value 0 (default) is
1321 * selected.
1322 */
1323 icbp->icb_idelaytimer = 2;
1324#endif
1325
1326 if (isp->isp_confopts & ISP_CFG_ONEGB) {
1327 icbp->icb_zfwoptions |= ICBZOPT_RATE_ONEGB;
1328 } else if (isp->isp_confopts & ISP_CFG_TWOGB) {
1329 icbp->icb_zfwoptions |= ICBZOPT_RATE_TWOGB;
1330 } else {
1331 icbp->icb_zfwoptions |= ICBZOPT_RATE_AUTO;
1332 }
1333 }
1334 }
1335
1336#ifndef ISP_NO_RIO_FC
1337 /*
1338 * RIO seems to be enabled in 2100s for fw >= 1.17.0.
1339 *
1340 * I've had some questionable problems with RIO on 2200.
1341 * More specifically, on a 2204 I had problems with RIO
1342 * on a Linux system where I was dropping commands right
1343 * and left. It's not clear to me what the actual problem
1344 * was.
1345 *
1346 * 23XX Cards do not support RIO. Instead they support ZIO.
1347 */
1348#if 0
1349 if (!IS_23XX(isp) && ISP_FW_NEWER_THAN(isp, 1, 17, 0)) {
1350 icbp->icb_xfwoptions |= ICBXOPT_RIO_16BIT;
1351 icbp->icb_racctimer = 4;
1352 icbp->icb_idelaytimer = 8;
1353 }
1354#endif
1355#endif
1356
1280 isp_prt(isp, ISP_LOGERR,
1281 "bad hard address %u- resetting to zero",
1282 icbp->icb_hardaddr);
1283 }
1284 icbp->icb_hardaddr = 0;
1285 }
1286 /*
1287 * Right now we just set extended options to prefer point-to-point
1288 * over loop based upon some soft config options.
1289 *
1290 * NB: for the 2300, ICBOPT_EXTENDED is required.
1291 */
1292 if (IS_2200(isp) || IS_23XX(isp)) {
1293 icbp->icb_fwoptions |= ICBOPT_EXTENDED;
1294 /*
1295 * Prefer or force Point-To-Point instead Loop?
1296 */
1297 switch(isp->isp_confopts & ISP_CFG_PORT_PREF) {
1298 case ISP_CFG_NPORT:
1299 icbp->icb_xfwoptions |= ICBXOPT_PTP_2_LOOP;
1300 break;
1301 case ISP_CFG_NPORT_ONLY:
1302 icbp->icb_xfwoptions |= ICBXOPT_PTP_ONLY;
1303 break;
1304 case ISP_CFG_LPORT_ONLY:
1305 icbp->icb_xfwoptions |= ICBXOPT_LOOP_ONLY;
1306 break;
1307 default:
1308 icbp->icb_xfwoptions |= ICBXOPT_LOOP_2_PTP;
1309 break;
1310 }
1311 if (IS_23XX(isp)) {
1312 /*
1313 * QLogic recommends that FAST Posting be turned
1314 * off for 23XX cards and instead allow the HBA
1315 * to write response queue entries and interrupt
1316 * after a delay (ZIO).
1317 *
1318 * If we set ZIO, it will disable fast posting,
1319 * so we don't need to clear it in fwoptions.
1320 *
1321 * Depending on the role we're selecting, we
1322 * chose fast posting or not as it still is
1323 * a win for target mode.
1324 */
1325#ifndef ISP_NO_ZIO
1326 if (isp->isp_role == ISP_ROLE_TARGET) {
1327 icbp->icb_fwoptions |= ICBOPT_FAST_POST;
1328 } else {
1329 icbp->icb_xfwoptions |= ICBXOPT_ZIO;
1330 }
1331#else
1332 icbp->icb_fwoptions |= ICBOPT_FAST_POST;
1333#endif
1334#if 0
1335 /*
1336 * Values, in 100us increments. The default
1337 * is 2 (200us) if a value 0 (default) is
1338 * selected.
1339 */
1340 icbp->icb_idelaytimer = 2;
1341#endif
1342
1343 if (isp->isp_confopts & ISP_CFG_ONEGB) {
1344 icbp->icb_zfwoptions |= ICBZOPT_RATE_ONEGB;
1345 } else if (isp->isp_confopts & ISP_CFG_TWOGB) {
1346 icbp->icb_zfwoptions |= ICBZOPT_RATE_TWOGB;
1347 } else {
1348 icbp->icb_zfwoptions |= ICBZOPT_RATE_AUTO;
1349 }
1350 }
1351 }
1352
1353#ifndef ISP_NO_RIO_FC
1354 /*
1355 * RIO seems to be enabled in 2100s for fw >= 1.17.0.
1356 *
1357 * I've had some questionable problems with RIO on 2200.
1358 * More specifically, on a 2204 I had problems with RIO
1359 * on a Linux system where I was dropping commands right
1360 * and left. It's not clear to me what the actual problem
1361 * was.
1362 *
1363 * 23XX Cards do not support RIO. Instead they support ZIO.
1364 */
1365#if 0
1366 if (!IS_23XX(isp) && ISP_FW_NEWER_THAN(isp, 1, 17, 0)) {
1367 icbp->icb_xfwoptions |= ICBXOPT_RIO_16BIT;
1368 icbp->icb_racctimer = 4;
1369 icbp->icb_idelaytimer = 8;
1370 }
1371#endif
1372#endif
1373
1374 MEMZERO(&mbs, sizeof (mbs));
1375
1357 /*
1376 /*
1358 * For 22XX > 2.1.26 && 23XX, set someoptions.
1377 * For 22XX > 2.1.26 && 23XX, set some options.
1359 * XXX: Probably okay for newer 2100 f/w too.
1360 */
1361 if (ISP_FW_NEWER_THAN(isp, 2, 26, 0)) {
1362 /*
1363 * Turn on LIP F8 async event (1)
1364 * Turn on generate AE 8013 on all LIP Resets (2)
1365 * Disable LIP F7 switching (8)
1366 */
1367 mbs.param[0] = MBOX_SET_FIRMWARE_OPTIONS;
1368 mbs.param[1] = 0xb;
1369 mbs.param[2] = 0;
1370 mbs.param[3] = 0;
1371 isp_mboxcmd(isp, &mbs, MBLOGALL);
1372 }
1373 icbp->icb_logintime = 30; /* 30 second login timeout */
1374
1375 if (IS_23XX(isp)) {
1376 ISP_WRITE(isp, isp->isp_rqstinrp, 0);
1377 ISP_WRITE(isp, isp->isp_rqstoutrp, 0);
1378 ISP_WRITE(isp, isp->isp_respinrp, 0);
1379 ISP_WRITE(isp, isp->isp_respoutrp, 0);
1380 }
1381
1382 nwwn = ISP_NODEWWN(isp);
1383 pwwn = ISP_PORTWWN(isp);
1384 if (nwwn && pwwn) {
1385 icbp->icb_fwoptions |= ICBOPT_BOTH_WWNS;
1386 MAKE_NODE_NAME_FROM_WWN(icbp->icb_nodename, nwwn);
1387 MAKE_NODE_NAME_FROM_WWN(icbp->icb_portname, pwwn);
1388 isp_prt(isp, ISP_LOGDEBUG1,
1389 "Setting ICB Node 0x%08x%08x Port 0x%08x%08x",
1390 ((u_int32_t) (nwwn >> 32)),
1391 ((u_int32_t) (nwwn & 0xffffffff)),
1392 ((u_int32_t) (pwwn >> 32)),
1393 ((u_int32_t) (pwwn & 0xffffffff)));
1394 } else {
1395 isp_prt(isp, ISP_LOGDEBUG1, "Not using any WWNs");
1396 icbp->icb_fwoptions &= ~(ICBOPT_BOTH_WWNS|ICBOPT_FULL_LOGIN);
1397 }
1398 icbp->icb_rqstqlen = RQUEST_QUEUE_LEN(isp);
1399 if (icbp->icb_rqstqlen < 1) {
1400 isp_prt(isp, ISP_LOGERR, "bad request queue length");
1401 }
1402 icbp->icb_rsltqlen = RESULT_QUEUE_LEN(isp);
1403 if (icbp->icb_rsltqlen < 1) {
1404 isp_prt(isp, ISP_LOGERR, "bad result queue length");
1405 }
1406 icbp->icb_rqstaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_rquest_dma);
1407 icbp->icb_rqstaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_rquest_dma);
1408 icbp->icb_rqstaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_rquest_dma);
1409 icbp->icb_rqstaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_rquest_dma);
1410 icbp->icb_respaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_result_dma);
1411 icbp->icb_respaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_result_dma);
1412 icbp->icb_respaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_result_dma);
1413 icbp->icb_respaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_result_dma);
1414 isp_prt(isp, ISP_LOGDEBUG0,
1415 "isp_fibre_init: fwopt 0x%x xfwopt 0x%x zfwopt 0x%x",
1416 icbp->icb_fwoptions, icbp->icb_xfwoptions, icbp->icb_zfwoptions);
1417
1418 FC_SCRATCH_ACQUIRE(isp);
1419 isp_put_icb(isp, icbp, (isp_icb_t *)fcp->isp_scratch);
1420
1421 /*
1422 * Init the firmware
1423 */
1424 mbs.param[0] = MBOX_INIT_FIRMWARE;
1425 mbs.param[1] = 0;
1426 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
1427 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
1428 mbs.param[4] = 0;
1429 mbs.param[5] = 0;
1430 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
1431 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
1432 isp_mboxcmd(isp, &mbs, MBLOGALL);
1433 FC_SCRATCH_RELEASE(isp);
1434 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1435 return;
1436 }
1437 isp->isp_reqidx = isp->isp_reqodx = 0;
1438 isp->isp_residx = 0;
1439 isp->isp_sendmarker = 1;
1440
1441 /*
1442 * Whatever happens, we're now committed to being here.
1443 */
1444 isp->isp_state = ISP_INITSTATE;
1445}
1446
1447/*
1448 * Fibre Channel Support- get the port database for the id.
1449 *
1450 * Locks are held before coming here. Return 0 if success,
1451 * else failure.
1452 */
1453
1454static int
1455isp_getmap(struct ispsoftc *isp, fcpos_map_t *map)
1456{
1457 fcparam *fcp = (fcparam *) isp->isp_param;
1458 mbreg_t mbs;
1459
1378 * XXX: Probably okay for newer 2100 f/w too.
1379 */
1380 if (ISP_FW_NEWER_THAN(isp, 2, 26, 0)) {
1381 /*
1382 * Turn on LIP F8 async event (1)
1383 * Turn on generate AE 8013 on all LIP Resets (2)
1384 * Disable LIP F7 switching (8)
1385 */
1386 mbs.param[0] = MBOX_SET_FIRMWARE_OPTIONS;
1387 mbs.param[1] = 0xb;
1388 mbs.param[2] = 0;
1389 mbs.param[3] = 0;
1390 isp_mboxcmd(isp, &mbs, MBLOGALL);
1391 }
1392 icbp->icb_logintime = 30; /* 30 second login timeout */
1393
1394 if (IS_23XX(isp)) {
1395 ISP_WRITE(isp, isp->isp_rqstinrp, 0);
1396 ISP_WRITE(isp, isp->isp_rqstoutrp, 0);
1397 ISP_WRITE(isp, isp->isp_respinrp, 0);
1398 ISP_WRITE(isp, isp->isp_respoutrp, 0);
1399 }
1400
1401 nwwn = ISP_NODEWWN(isp);
1402 pwwn = ISP_PORTWWN(isp);
1403 if (nwwn && pwwn) {
1404 icbp->icb_fwoptions |= ICBOPT_BOTH_WWNS;
1405 MAKE_NODE_NAME_FROM_WWN(icbp->icb_nodename, nwwn);
1406 MAKE_NODE_NAME_FROM_WWN(icbp->icb_portname, pwwn);
1407 isp_prt(isp, ISP_LOGDEBUG1,
1408 "Setting ICB Node 0x%08x%08x Port 0x%08x%08x",
1409 ((u_int32_t) (nwwn >> 32)),
1410 ((u_int32_t) (nwwn & 0xffffffff)),
1411 ((u_int32_t) (pwwn >> 32)),
1412 ((u_int32_t) (pwwn & 0xffffffff)));
1413 } else {
1414 isp_prt(isp, ISP_LOGDEBUG1, "Not using any WWNs");
1415 icbp->icb_fwoptions &= ~(ICBOPT_BOTH_WWNS|ICBOPT_FULL_LOGIN);
1416 }
1417 icbp->icb_rqstqlen = RQUEST_QUEUE_LEN(isp);
1418 if (icbp->icb_rqstqlen < 1) {
1419 isp_prt(isp, ISP_LOGERR, "bad request queue length");
1420 }
1421 icbp->icb_rsltqlen = RESULT_QUEUE_LEN(isp);
1422 if (icbp->icb_rsltqlen < 1) {
1423 isp_prt(isp, ISP_LOGERR, "bad result queue length");
1424 }
1425 icbp->icb_rqstaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_rquest_dma);
1426 icbp->icb_rqstaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_rquest_dma);
1427 icbp->icb_rqstaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_rquest_dma);
1428 icbp->icb_rqstaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_rquest_dma);
1429 icbp->icb_respaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_result_dma);
1430 icbp->icb_respaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_result_dma);
1431 icbp->icb_respaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_result_dma);
1432 icbp->icb_respaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_result_dma);
1433 isp_prt(isp, ISP_LOGDEBUG0,
1434 "isp_fibre_init: fwopt 0x%x xfwopt 0x%x zfwopt 0x%x",
1435 icbp->icb_fwoptions, icbp->icb_xfwoptions, icbp->icb_zfwoptions);
1436
1437 FC_SCRATCH_ACQUIRE(isp);
1438 isp_put_icb(isp, icbp, (isp_icb_t *)fcp->isp_scratch);
1439
1440 /*
1441 * Init the firmware
1442 */
1443 mbs.param[0] = MBOX_INIT_FIRMWARE;
1444 mbs.param[1] = 0;
1445 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
1446 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
1447 mbs.param[4] = 0;
1448 mbs.param[5] = 0;
1449 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
1450 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
1451 isp_mboxcmd(isp, &mbs, MBLOGALL);
1452 FC_SCRATCH_RELEASE(isp);
1453 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1454 return;
1455 }
1456 isp->isp_reqidx = isp->isp_reqodx = 0;
1457 isp->isp_residx = 0;
1458 isp->isp_sendmarker = 1;
1459
1460 /*
1461 * Whatever happens, we're now committed to being here.
1462 */
1463 isp->isp_state = ISP_INITSTATE;
1464}
1465
1466/*
1467 * Fibre Channel Support- get the port database for the id.
1468 *
1469 * Locks are held before coming here. Return 0 if success,
1470 * else failure.
1471 */
1472
1473static int
1474isp_getmap(struct ispsoftc *isp, fcpos_map_t *map)
1475{
1476 fcparam *fcp = (fcparam *) isp->isp_param;
1477 mbreg_t mbs;
1478
1479 MEMZERO(&mbs, sizeof (mbs));
1460 mbs.param[0] = MBOX_GET_FC_AL_POSITION_MAP;
1461 mbs.param[1] = 0;
1462 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
1463 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
1464 /*
1465 * Unneeded. For the 2100, except for initializing f/w, registers
1466 * 4/5 have to not be written to.
1467 * mbs.param[4] = 0;
1468 * mbs.param[5] = 0;
1469 *
1470 */
1471 mbs.param[6] = 0;
1472 mbs.param[7] = 0;
1473 FC_SCRATCH_ACQUIRE(isp);
1474 isp_mboxcmd(isp, &mbs, MBLOGALL & ~MBOX_COMMAND_PARAM_ERROR);
1475 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1476 MEMCPY(map, fcp->isp_scratch, sizeof (fcpos_map_t));
1477 map->fwmap = mbs.param[1] != 0;
1478 FC_SCRATCH_RELEASE(isp);
1479 return (0);
1480 }
1481 FC_SCRATCH_RELEASE(isp);
1482 return (-1);
1483}
1484
1485static void
1486isp_mark_getpdb_all(struct ispsoftc *isp)
1487{
1488 fcparam *fcp = (fcparam *) isp->isp_param;
1489 int i;
1490 for (i = 0; i < MAX_FC_TARG; i++) {
1491 fcp->portdb[i].valid = fcp->portdb[i].fabric_dev = 0;
1492 }
1493}
1494
1495static int
1496isp_getpdb(struct ispsoftc *isp, int id, isp_pdb_t *pdbp)
1497{
1498 fcparam *fcp = (fcparam *) isp->isp_param;
1499 mbreg_t mbs;
1500
1480 mbs.param[0] = MBOX_GET_FC_AL_POSITION_MAP;
1481 mbs.param[1] = 0;
1482 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
1483 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
1484 /*
1485 * Unneeded. For the 2100, except for initializing f/w, registers
1486 * 4/5 have to not be written to.
1487 * mbs.param[4] = 0;
1488 * mbs.param[5] = 0;
1489 *
1490 */
1491 mbs.param[6] = 0;
1492 mbs.param[7] = 0;
1493 FC_SCRATCH_ACQUIRE(isp);
1494 isp_mboxcmd(isp, &mbs, MBLOGALL & ~MBOX_COMMAND_PARAM_ERROR);
1495 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1496 MEMCPY(map, fcp->isp_scratch, sizeof (fcpos_map_t));
1497 map->fwmap = mbs.param[1] != 0;
1498 FC_SCRATCH_RELEASE(isp);
1499 return (0);
1500 }
1501 FC_SCRATCH_RELEASE(isp);
1502 return (-1);
1503}
1504
1505static void
1506isp_mark_getpdb_all(struct ispsoftc *isp)
1507{
1508 fcparam *fcp = (fcparam *) isp->isp_param;
1509 int i;
1510 for (i = 0; i < MAX_FC_TARG; i++) {
1511 fcp->portdb[i].valid = fcp->portdb[i].fabric_dev = 0;
1512 }
1513}
1514
1515static int
1516isp_getpdb(struct ispsoftc *isp, int id, isp_pdb_t *pdbp)
1517{
1518 fcparam *fcp = (fcparam *) isp->isp_param;
1519 mbreg_t mbs;
1520
1521 MEMZERO(&mbs, sizeof (mbs));
1501 mbs.param[0] = MBOX_GET_PORT_DB;
1522 mbs.param[0] = MBOX_GET_PORT_DB;
1502 mbs.param[1] = id << 8;
1523 if (IS_2KLOGIN(isp)) {
1524 mbs.param[1] = id;
1525 mbs.obits |= (1 << 10);
1526 } else {
1527 mbs.param[1] = id << 8;
1528 }
1503 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
1504 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
1505 /*
1506 * Unneeded. For the 2100, except for initializing f/w, registers
1507 * 4/5 have to not be written to.
1508 * mbs.param[4] = 0;
1509 * mbs.param[5] = 0;
1510 *
1511 */
1512 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
1513 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
1514 FC_SCRATCH_ACQUIRE(isp);
1515 isp_mboxcmd(isp, &mbs, MBLOGALL & ~MBOX_COMMAND_PARAM_ERROR);
1516 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1517 isp_get_pdb(isp, (isp_pdb_t *)fcp->isp_scratch, pdbp);
1518 FC_SCRATCH_RELEASE(isp);
1519 return (0);
1520 }
1521 FC_SCRATCH_RELEASE(isp);
1522 return (-1);
1523}
1524
1525static u_int64_t
1526isp_get_portname(struct ispsoftc *isp, int loopid, int nodename)
1527{
1528 u_int64_t wwn = 0;
1529 mbreg_t mbs;
1530
1529 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
1530 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
1531 /*
1532 * Unneeded. For the 2100, except for initializing f/w, registers
1533 * 4/5 have to not be written to.
1534 * mbs.param[4] = 0;
1535 * mbs.param[5] = 0;
1536 *
1537 */
1538 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
1539 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
1540 FC_SCRATCH_ACQUIRE(isp);
1541 isp_mboxcmd(isp, &mbs, MBLOGALL & ~MBOX_COMMAND_PARAM_ERROR);
1542 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1543 isp_get_pdb(isp, (isp_pdb_t *)fcp->isp_scratch, pdbp);
1544 FC_SCRATCH_RELEASE(isp);
1545 return (0);
1546 }
1547 FC_SCRATCH_RELEASE(isp);
1548 return (-1);
1549}
1550
1551static u_int64_t
1552isp_get_portname(struct ispsoftc *isp, int loopid, int nodename)
1553{
1554 u_int64_t wwn = 0;
1555 mbreg_t mbs;
1556
1557 MEMZERO(&mbs, sizeof (mbs));
1531 mbs.param[0] = MBOX_GET_PORT_NAME;
1558 mbs.param[0] = MBOX_GET_PORT_NAME;
1532 mbs.param[1] = loopid << 8;
1533 if (nodename)
1534 mbs.param[1] |= 1;
1559 if (IS_2KLOGIN(isp)) {
1560 mbs.param[1] = loopid;
1561 if (nodename)
1562 mbs.param[10] = 1;
1563 mbs.obits |= (1 << 10);
1564 } else {
1565 mbs.param[1] = loopid << 8;
1566 if (nodename)
1567 mbs.param[1] |= 1;
1568 }
1535 isp_mboxcmd(isp, &mbs, MBLOGALL & ~MBOX_COMMAND_PARAM_ERROR);
1536 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1537 wwn =
1538 (((u_int64_t)(mbs.param[2] & 0xff)) << 56) |
1539 (((u_int64_t)(mbs.param[2] >> 8)) << 48) |
1540 (((u_int64_t)(mbs.param[3] & 0xff)) << 40) |
1541 (((u_int64_t)(mbs.param[3] >> 8)) << 32) |
1542 (((u_int64_t)(mbs.param[6] & 0xff)) << 24) |
1543 (((u_int64_t)(mbs.param[6] >> 8)) << 16) |
1544 (((u_int64_t)(mbs.param[7] & 0xff)) << 8) |
1545 (((u_int64_t)(mbs.param[7] >> 8)));
1546 }
1547 return (wwn);
1548}
1549
1550/*
1551 * Make sure we have good FC link and know our Loop ID.
1552 */
1553
1554static int
1555isp_fclink_test(struct ispsoftc *isp, int usdelay)
1556{
1557 static char *toponames[] = {
1558 "Private Loop",
1559 "FL Port",
1560 "N-Port to N-Port",
1561 "F Port",
1562 "F Port (no FLOGI_ACC response)"
1563 };
1564 mbreg_t mbs;
1565 int count, check_for_fabric;
1566 u_int8_t lwfs;
1567 fcparam *fcp;
1568 struct lportdb *lp;
1569 isp_pdb_t pdb;
1570
1571 fcp = isp->isp_param;
1572
1573 /*
1574 * XXX: Here is where we would start a 'loop dead' timeout
1575 */
1576
1577 /*
1578 * Wait up to N microseconds for F/W to go to a ready state.
1579 */
1580 lwfs = FW_CONFIG_WAIT;
1581 count = 0;
1582 while (count < usdelay) {
1583 u_int64_t enano;
1584 u_int32_t wrk;
1585 NANOTIME_T hra, hrb;
1586
1587 GET_NANOTIME(&hra);
1588 isp_fw_state(isp);
1589 if (lwfs != fcp->isp_fwstate) {
1590 isp_prt(isp, ISP_LOGINFO, "Firmware State <%s->%s>",
1591 isp2100_fw_statename((int)lwfs),
1592 isp2100_fw_statename((int)fcp->isp_fwstate));
1593 lwfs = fcp->isp_fwstate;
1594 }
1595 if (fcp->isp_fwstate == FW_READY) {
1596 break;
1597 }
1598 GET_NANOTIME(&hrb);
1599
1600 /*
1601 * Get the elapsed time in nanoseconds.
1602 * Always guaranteed to be non-zero.
1603 */
1604 enano = NANOTIME_SUB(&hrb, &hra);
1605
1606 isp_prt(isp, ISP_LOGDEBUG1,
1607 "usec%d: 0x%lx->0x%lx enano 0x%x%08x",
1608 count, (long) GET_NANOSEC(&hra), (long) GET_NANOSEC(&hrb),
1609 (u_int32_t)(enano >> 32), (u_int32_t)(enano & 0xffffffff));
1610
1611 /*
1612 * If the elapsed time is less than 1 millisecond,
1613 * delay a period of time up to that millisecond of
1614 * waiting.
1615 *
1616 * This peculiar code is an attempt to try and avoid
1617 * invoking u_int64_t math support functions for some
1618 * platforms where linkage is a problem.
1619 */
1620 if (enano < (1000 * 1000)) {
1621 count += 1000;
1622 enano = (1000 * 1000) - enano;
1623 while (enano > (u_int64_t) 4000000000U) {
1624 USEC_SLEEP(isp, 4000000);
1625 enano -= (u_int64_t) 4000000000U;
1626 }
1627 wrk = enano;
1628 wrk /= 1000;
1629 USEC_SLEEP(isp, wrk);
1630 } else {
1631 while (enano > (u_int64_t) 4000000000U) {
1632 count += 4000000;
1633 enano -= (u_int64_t) 4000000000U;
1634 }
1635 wrk = enano;
1636 count += (wrk / 1000);
1637 }
1638 }
1639
1640 /*
1641 * If we haven't gone to 'ready' state, return.
1642 */
1643 if (fcp->isp_fwstate != FW_READY) {
1644 return (-1);
1645 }
1646
1647 /*
1648 * Get our Loop ID (if possible). We really need to have it.
1649 */
1569 isp_mboxcmd(isp, &mbs, MBLOGALL & ~MBOX_COMMAND_PARAM_ERROR);
1570 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1571 wwn =
1572 (((u_int64_t)(mbs.param[2] & 0xff)) << 56) |
1573 (((u_int64_t)(mbs.param[2] >> 8)) << 48) |
1574 (((u_int64_t)(mbs.param[3] & 0xff)) << 40) |
1575 (((u_int64_t)(mbs.param[3] >> 8)) << 32) |
1576 (((u_int64_t)(mbs.param[6] & 0xff)) << 24) |
1577 (((u_int64_t)(mbs.param[6] >> 8)) << 16) |
1578 (((u_int64_t)(mbs.param[7] & 0xff)) << 8) |
1579 (((u_int64_t)(mbs.param[7] >> 8)));
1580 }
1581 return (wwn);
1582}
1583
1584/*
1585 * Make sure we have good FC link and know our Loop ID.
1586 */
1587
1588static int
1589isp_fclink_test(struct ispsoftc *isp, int usdelay)
1590{
1591 static char *toponames[] = {
1592 "Private Loop",
1593 "FL Port",
1594 "N-Port to N-Port",
1595 "F Port",
1596 "F Port (no FLOGI_ACC response)"
1597 };
1598 mbreg_t mbs;
1599 int count, check_for_fabric;
1600 u_int8_t lwfs;
1601 fcparam *fcp;
1602 struct lportdb *lp;
1603 isp_pdb_t pdb;
1604
1605 fcp = isp->isp_param;
1606
1607 /*
1608 * XXX: Here is where we would start a 'loop dead' timeout
1609 */
1610
1611 /*
1612 * Wait up to N microseconds for F/W to go to a ready state.
1613 */
1614 lwfs = FW_CONFIG_WAIT;
1615 count = 0;
1616 while (count < usdelay) {
1617 u_int64_t enano;
1618 u_int32_t wrk;
1619 NANOTIME_T hra, hrb;
1620
1621 GET_NANOTIME(&hra);
1622 isp_fw_state(isp);
1623 if (lwfs != fcp->isp_fwstate) {
1624 isp_prt(isp, ISP_LOGINFO, "Firmware State <%s->%s>",
1625 isp2100_fw_statename((int)lwfs),
1626 isp2100_fw_statename((int)fcp->isp_fwstate));
1627 lwfs = fcp->isp_fwstate;
1628 }
1629 if (fcp->isp_fwstate == FW_READY) {
1630 break;
1631 }
1632 GET_NANOTIME(&hrb);
1633
1634 /*
1635 * Get the elapsed time in nanoseconds.
1636 * Always guaranteed to be non-zero.
1637 */
1638 enano = NANOTIME_SUB(&hrb, &hra);
1639
1640 isp_prt(isp, ISP_LOGDEBUG1,
1641 "usec%d: 0x%lx->0x%lx enano 0x%x%08x",
1642 count, (long) GET_NANOSEC(&hra), (long) GET_NANOSEC(&hrb),
1643 (u_int32_t)(enano >> 32), (u_int32_t)(enano & 0xffffffff));
1644
1645 /*
1646 * If the elapsed time is less than 1 millisecond,
1647 * delay a period of time up to that millisecond of
1648 * waiting.
1649 *
1650 * This peculiar code is an attempt to try and avoid
1651 * invoking u_int64_t math support functions for some
1652 * platforms where linkage is a problem.
1653 */
1654 if (enano < (1000 * 1000)) {
1655 count += 1000;
1656 enano = (1000 * 1000) - enano;
1657 while (enano > (u_int64_t) 4000000000U) {
1658 USEC_SLEEP(isp, 4000000);
1659 enano -= (u_int64_t) 4000000000U;
1660 }
1661 wrk = enano;
1662 wrk /= 1000;
1663 USEC_SLEEP(isp, wrk);
1664 } else {
1665 while (enano > (u_int64_t) 4000000000U) {
1666 count += 4000000;
1667 enano -= (u_int64_t) 4000000000U;
1668 }
1669 wrk = enano;
1670 count += (wrk / 1000);
1671 }
1672 }
1673
1674 /*
1675 * If we haven't gone to 'ready' state, return.
1676 */
1677 if (fcp->isp_fwstate != FW_READY) {
1678 return (-1);
1679 }
1680
1681 /*
1682 * Get our Loop ID (if possible). We really need to have it.
1683 */
1684 MEMZERO(&mbs, sizeof (mbs));
1650 mbs.param[0] = MBOX_GET_LOOP_ID;
1651 isp_mboxcmd(isp, &mbs, MBLOGALL);
1652 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1653 return (-1);
1654 }
1655 fcp->isp_loopid = mbs.param[1];
1656 if (IS_2200(isp) || IS_23XX(isp)) {
1657 int topo = (int) mbs.param[6];
1658 if (topo < TOPO_NL_PORT || topo > TOPO_PTP_STUB)
1659 topo = TOPO_PTP_STUB;
1660 fcp->isp_topo = topo;
1661 } else {
1662 fcp->isp_topo = TOPO_NL_PORT;
1663 }
1685 mbs.param[0] = MBOX_GET_LOOP_ID;
1686 isp_mboxcmd(isp, &mbs, MBLOGALL);
1687 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1688 return (-1);
1689 }
1690 fcp->isp_loopid = mbs.param[1];
1691 if (IS_2200(isp) || IS_23XX(isp)) {
1692 int topo = (int) mbs.param[6];
1693 if (topo < TOPO_NL_PORT || topo > TOPO_PTP_STUB)
1694 topo = TOPO_PTP_STUB;
1695 fcp->isp_topo = topo;
1696 } else {
1697 fcp->isp_topo = TOPO_NL_PORT;
1698 }
1664 fcp->isp_portid = fcp->isp_alpa = mbs.param[2] & 0xff;
1699 /*
1700 * XXX: We can get the AL_PA (low 8 bits) from here.
1701 * XXX: Where do we get the upper 16 bits?
1702 */
1703 fcp->isp_portid = mbs.param[2] & 0xff;
1665
1666 /*
1667 * Check to see if we're on a fabric by trying to see if we
1668 * can talk to the fabric name server. This can be a bit
1669 * tricky because if we're a 2100, we should check always
1670 * (in case we're connected to a server doing aliasing).
1671 */
1672 fcp->isp_onfabric = 0;
1673
1674 if (IS_2100(isp)) {
1675 /*
1676 * Don't bother with fabric if we are using really old
1677 * 2100 firmware. It's just not worth it.
1678 */
1679 if (ISP_FW_NEWER_THAN(isp, 1, 15, 37)) {
1680 check_for_fabric = 1;
1681 } else {
1682 check_for_fabric = 0;
1683 }
1684 } else if (fcp->isp_topo == TOPO_FL_PORT ||
1685 fcp->isp_topo == TOPO_F_PORT) {
1686 check_for_fabric = 1;
1687 } else
1688 check_for_fabric = 0;
1689
1690 if (check_for_fabric && isp_getpdb(isp, FL_PORT_ID, &pdb) == 0) {
1691 int loopid = FL_PORT_ID;
1692 if (IS_2100(isp)) {
1693 fcp->isp_topo = TOPO_FL_PORT;
1694 }
1695
1696 if (BITS2WORD(pdb.pdb_portid_bits) == 0) {
1697 /*
1698 * Crock.
1699 */
1700 fcp->isp_topo = TOPO_NL_PORT;
1701 goto not_on_fabric;
1702 }
1703 fcp->isp_portid = mbs.param[2] | ((int) mbs.param[3] << 16);
1704
1705 /*
1706 * Save the Fabric controller's port database entry.
1707 */
1708 lp = &fcp->portdb[loopid];
1709 lp->node_wwn =
1710 (((u_int64_t)pdb.pdb_nodename[0]) << 56) |
1711 (((u_int64_t)pdb.pdb_nodename[1]) << 48) |
1712 (((u_int64_t)pdb.pdb_nodename[2]) << 40) |
1713 (((u_int64_t)pdb.pdb_nodename[3]) << 32) |
1714 (((u_int64_t)pdb.pdb_nodename[4]) << 24) |
1715 (((u_int64_t)pdb.pdb_nodename[5]) << 16) |
1716 (((u_int64_t)pdb.pdb_nodename[6]) << 8) |
1717 (((u_int64_t)pdb.pdb_nodename[7]));
1718 lp->port_wwn =
1719 (((u_int64_t)pdb.pdb_portname[0]) << 56) |
1720 (((u_int64_t)pdb.pdb_portname[1]) << 48) |
1721 (((u_int64_t)pdb.pdb_portname[2]) << 40) |
1722 (((u_int64_t)pdb.pdb_portname[3]) << 32) |
1723 (((u_int64_t)pdb.pdb_portname[4]) << 24) |
1724 (((u_int64_t)pdb.pdb_portname[5]) << 16) |
1725 (((u_int64_t)pdb.pdb_portname[6]) << 8) |
1726 (((u_int64_t)pdb.pdb_portname[7]));
1727 lp->roles =
1728 (pdb.pdb_prli_svc3 & SVC3_ROLE_MASK) >> SVC3_ROLE_SHIFT;
1729 lp->portid = BITS2WORD(pdb.pdb_portid_bits);
1730 lp->loopid = pdb.pdb_loopid;
1731 lp->loggedin = lp->valid = 1;
1732 fcp->isp_onfabric = 1;
1733 (void) isp_async(isp, ISPASYNC_PROMENADE, &loopid);
1734 isp_register_fc4_type(isp);
1735 } else {
1736not_on_fabric:
1737 fcp->isp_onfabric = 0;
1738 fcp->portdb[FL_PORT_ID].valid = 0;
1739 }
1740
1741 fcp->isp_gbspeed = 1;
1742 if (IS_23XX(isp)) {
1743 mbs.param[0] = MBOX_GET_SET_DATA_RATE;
1744 mbs.param[1] = MBGSD_GET_RATE;
1745 /* mbs.param[2] undefined if we're just getting rate */
1746 isp_mboxcmd(isp, &mbs, MBLOGALL);
1747 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1748 if (mbs.param[1] == MBGSD_TWOGB) {
1749 isp_prt(isp, ISP_LOGINFO, "2Gb link speed/s");
1750 fcp->isp_gbspeed = 2;
1751 }
1752 }
1753 }
1754
1704
1705 /*
1706 * Check to see if we're on a fabric by trying to see if we
1707 * can talk to the fabric name server. This can be a bit
1708 * tricky because if we're a 2100, we should check always
1709 * (in case we're connected to a server doing aliasing).
1710 */
1711 fcp->isp_onfabric = 0;
1712
1713 if (IS_2100(isp)) {
1714 /*
1715 * Don't bother with fabric if we are using really old
1716 * 2100 firmware. It's just not worth it.
1717 */
1718 if (ISP_FW_NEWER_THAN(isp, 1, 15, 37)) {
1719 check_for_fabric = 1;
1720 } else {
1721 check_for_fabric = 0;
1722 }
1723 } else if (fcp->isp_topo == TOPO_FL_PORT ||
1724 fcp->isp_topo == TOPO_F_PORT) {
1725 check_for_fabric = 1;
1726 } else
1727 check_for_fabric = 0;
1728
1729 if (check_for_fabric && isp_getpdb(isp, FL_PORT_ID, &pdb) == 0) {
1730 int loopid = FL_PORT_ID;
1731 if (IS_2100(isp)) {
1732 fcp->isp_topo = TOPO_FL_PORT;
1733 }
1734
1735 if (BITS2WORD(pdb.pdb_portid_bits) == 0) {
1736 /*
1737 * Crock.
1738 */
1739 fcp->isp_topo = TOPO_NL_PORT;
1740 goto not_on_fabric;
1741 }
1742 fcp->isp_portid = mbs.param[2] | ((int) mbs.param[3] << 16);
1743
1744 /*
1745 * Save the Fabric controller's port database entry.
1746 */
1747 lp = &fcp->portdb[loopid];
1748 lp->node_wwn =
1749 (((u_int64_t)pdb.pdb_nodename[0]) << 56) |
1750 (((u_int64_t)pdb.pdb_nodename[1]) << 48) |
1751 (((u_int64_t)pdb.pdb_nodename[2]) << 40) |
1752 (((u_int64_t)pdb.pdb_nodename[3]) << 32) |
1753 (((u_int64_t)pdb.pdb_nodename[4]) << 24) |
1754 (((u_int64_t)pdb.pdb_nodename[5]) << 16) |
1755 (((u_int64_t)pdb.pdb_nodename[6]) << 8) |
1756 (((u_int64_t)pdb.pdb_nodename[7]));
1757 lp->port_wwn =
1758 (((u_int64_t)pdb.pdb_portname[0]) << 56) |
1759 (((u_int64_t)pdb.pdb_portname[1]) << 48) |
1760 (((u_int64_t)pdb.pdb_portname[2]) << 40) |
1761 (((u_int64_t)pdb.pdb_portname[3]) << 32) |
1762 (((u_int64_t)pdb.pdb_portname[4]) << 24) |
1763 (((u_int64_t)pdb.pdb_portname[5]) << 16) |
1764 (((u_int64_t)pdb.pdb_portname[6]) << 8) |
1765 (((u_int64_t)pdb.pdb_portname[7]));
1766 lp->roles =
1767 (pdb.pdb_prli_svc3 & SVC3_ROLE_MASK) >> SVC3_ROLE_SHIFT;
1768 lp->portid = BITS2WORD(pdb.pdb_portid_bits);
1769 lp->loopid = pdb.pdb_loopid;
1770 lp->loggedin = lp->valid = 1;
1771 fcp->isp_onfabric = 1;
1772 (void) isp_async(isp, ISPASYNC_PROMENADE, &loopid);
1773 isp_register_fc4_type(isp);
1774 } else {
1775not_on_fabric:
1776 fcp->isp_onfabric = 0;
1777 fcp->portdb[FL_PORT_ID].valid = 0;
1778 }
1779
1780 fcp->isp_gbspeed = 1;
1781 if (IS_23XX(isp)) {
1782 mbs.param[0] = MBOX_GET_SET_DATA_RATE;
1783 mbs.param[1] = MBGSD_GET_RATE;
1784 /* mbs.param[2] undefined if we're just getting rate */
1785 isp_mboxcmd(isp, &mbs, MBLOGALL);
1786 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1787 if (mbs.param[1] == MBGSD_TWOGB) {
1788 isp_prt(isp, ISP_LOGINFO, "2Gb link speed/s");
1789 fcp->isp_gbspeed = 2;
1790 }
1791 }
1792 }
1793
1755 isp_prt(isp, ISP_LOGCONFIG, topology, fcp->isp_loopid, fcp->isp_alpa,
1794 isp_prt(isp, ISP_LOGCONFIG, topology, fcp->isp_loopid,
1756 fcp->isp_portid, fcp->isp_loopstate, toponames[fcp->isp_topo]);
1757
1758 /*
1759 * Announce ourselves, too. This involves synthesizing an entry.
1760 */
1761 if (fcp->isp_iid_set == 0) {
1762 fcp->isp_iid_set = 1;
1763 fcp->isp_iid = fcp->isp_loopid;
1764 lp = &fcp->portdb[fcp->isp_iid];
1765 } else {
1766 lp = &fcp->portdb[fcp->isp_iid];
1767 if (fcp->isp_portid != lp->portid ||
1768 fcp->isp_loopid != lp->loopid ||
1769 fcp->isp_nodewwn != ISP_NODEWWN(isp) ||
1770 fcp->isp_portwwn != ISP_PORTWWN(isp)) {
1771 lp->valid = 0;
1772 count = fcp->isp_iid;
1773 (void) isp_async(isp, ISPASYNC_PROMENADE, &count);
1774 }
1775 }
1776 lp->loopid = fcp->isp_loopid;
1777 lp->portid = fcp->isp_portid;
1778 lp->node_wwn = ISP_NODEWWN(isp);
1779 lp->port_wwn = ISP_PORTWWN(isp);
1780 switch (isp->isp_role) {
1781 case ISP_ROLE_NONE:
1782 lp->roles = 0;
1783 break;
1784 case ISP_ROLE_TARGET:
1785 lp->roles = SVC3_TGT_ROLE >> SVC3_ROLE_SHIFT;
1786 break;
1787 case ISP_ROLE_INITIATOR:
1788 lp->roles = SVC3_INI_ROLE >> SVC3_ROLE_SHIFT;
1789 break;
1790 case ISP_ROLE_BOTH:
1791 lp->roles = (SVC3_INI_ROLE|SVC3_TGT_ROLE) >> SVC3_ROLE_SHIFT;
1792 break;
1793 }
1794 lp->loggedin = lp->valid = 1;
1795 count = fcp->isp_iid;
1796 (void) isp_async(isp, ISPASYNC_PROMENADE, &count);
1797 return (0);
1798}
1799
1800static char *
1801isp2100_fw_statename(int state)
1802{
1803 switch(state) {
1804 case FW_CONFIG_WAIT: return "Config Wait";
1805 case FW_WAIT_AL_PA: return "Waiting for AL_PA";
1806 case FW_WAIT_LOGIN: return "Wait Login";
1807 case FW_READY: return "Ready";
1808 case FW_LOSS_OF_SYNC: return "Loss Of Sync";
1809 case FW_ERROR: return "Error";
1810 case FW_REINIT: return "Re-Init";
1811 case FW_NON_PART: return "Nonparticipating";
1812 default: return "?????";
1813 }
1814}
1815
1816/*
1817 * Synchronize our soft copy of the port database with what the f/w thinks
1818 * (with a view toward possibly for a specific target....)
1819 */
1820
1821static int
1822isp_pdb_sync(struct ispsoftc *isp)
1823{
1824 struct lportdb *lp;
1825 fcparam *fcp = isp->isp_param;
1826 isp_pdb_t pdb;
1827 int loopid, base, lim;
1828
1829 /*
1830 * Make sure we're okay for doing this right now.
1831 */
1832 if (fcp->isp_loopstate != LOOP_PDB_RCVD &&
1833 fcp->isp_loopstate != LOOP_FSCAN_DONE &&
1834 fcp->isp_loopstate != LOOP_LSCAN_DONE) {
1835 return (-1);
1836 }
1837
1838 if (fcp->isp_topo == TOPO_FL_PORT || fcp->isp_topo == TOPO_NL_PORT ||
1839 fcp->isp_topo == TOPO_N_PORT) {
1840 if (fcp->isp_loopstate < LOOP_LSCAN_DONE) {
1841 if (isp_scan_loop(isp) != 0) {
1842 return (-1);
1843 }
1844 }
1845 }
1846 fcp->isp_loopstate = LOOP_SYNCING_PDB;
1847
1848 /*
1849 * If we get this far, we've settled our differences with the f/w
1850 * (for local loop device) and we can say that the loop state is ready.
1851 */
1852
1853 if (fcp->isp_topo == TOPO_NL_PORT) {
1854 fcp->loop_seen_once = 1;
1855 fcp->isp_loopstate = LOOP_READY;
1856 return (0);
1857 }
1858
1859 /*
1860 * Find all Fabric Entities that didn't make it from one scan to the
1861 * next and let the world know they went away. Scan the whole database.
1862 */
1863 for (lp = &fcp->portdb[0]; lp < &fcp->portdb[MAX_FC_TARG]; lp++) {
1864 if (lp->was_fabric_dev && lp->fabric_dev == 0) {
1865 loopid = lp - fcp->portdb;
1866 lp->valid = 0; /* should already be set */
1867 (void) isp_async(isp, ISPASYNC_PROMENADE, &loopid);
1868 MEMZERO((void *) lp, sizeof (*lp));
1869 continue;
1870 }
1871 lp->was_fabric_dev = lp->fabric_dev;
1872 }
1873
1874 if (fcp->isp_topo == TOPO_FL_PORT)
1875 base = FC_SNS_ID+1;
1876 else
1877 base = 0;
1878
1879 if (fcp->isp_topo == TOPO_N_PORT)
1880 lim = 1;
1881 else
1882 lim = MAX_FC_TARG;
1883
1884 /*
1885 * Now log in any fabric devices that the outer layer has
1886 * left for us to see. This seems the most sane policy
1887 * for the moment.
1888 */
1889 for (lp = &fcp->portdb[base]; lp < &fcp->portdb[lim]; lp++) {
1890 u_int32_t portid;
1891 mbreg_t mbs;
1892
1893 loopid = lp - fcp->portdb;
1894 if (loopid >= FL_PORT_ID && loopid <= FC_SNS_ID) {
1895 continue;
1896 }
1897
1898 /*
1899 * Anything here?
1900 */
1901 if (lp->port_wwn == 0) {
1902 continue;
1903 }
1904
1905 /*
1906 * Don't try to log into yourself.
1907 */
1908 if ((portid = lp->portid) == fcp->isp_portid) {
1909 continue;
1910 }
1911
1912
1913 /*
1914 * If we'd been logged in- see if we still are and we haven't
1915 * changed. If so, no need to log ourselves out, etc..
1916 *
1917 * Unfortunately, our charming Qlogic f/w has decided to
1918 * return a valid port database entry for a fabric device
1919 * that has, in fact, gone away. And it hangs trying to
1920 * log it out.
1921 */
1922 if (lp->loggedin && lp->force_logout == 0 &&
1923 isp_getpdb(isp, lp->loopid, &pdb) == 0) {
1924 int nrole;
1925 u_int64_t nwwnn, nwwpn;
1926 nwwnn =
1927 (((u_int64_t)pdb.pdb_nodename[0]) << 56) |
1928 (((u_int64_t)pdb.pdb_nodename[1]) << 48) |
1929 (((u_int64_t)pdb.pdb_nodename[2]) << 40) |
1930 (((u_int64_t)pdb.pdb_nodename[3]) << 32) |
1931 (((u_int64_t)pdb.pdb_nodename[4]) << 24) |
1932 (((u_int64_t)pdb.pdb_nodename[5]) << 16) |
1933 (((u_int64_t)pdb.pdb_nodename[6]) << 8) |
1934 (((u_int64_t)pdb.pdb_nodename[7]));
1935 nwwpn =
1936 (((u_int64_t)pdb.pdb_portname[0]) << 56) |
1937 (((u_int64_t)pdb.pdb_portname[1]) << 48) |
1938 (((u_int64_t)pdb.pdb_portname[2]) << 40) |
1939 (((u_int64_t)pdb.pdb_portname[3]) << 32) |
1940 (((u_int64_t)pdb.pdb_portname[4]) << 24) |
1941 (((u_int64_t)pdb.pdb_portname[5]) << 16) |
1942 (((u_int64_t)pdb.pdb_portname[6]) << 8) |
1943 (((u_int64_t)pdb.pdb_portname[7]));
1944 nrole = (pdb.pdb_prli_svc3 & SVC3_ROLE_MASK) >>
1945 SVC3_ROLE_SHIFT;
1946 if (pdb.pdb_loopid == lp->loopid && lp->portid ==
1947 (u_int32_t) BITS2WORD(pdb.pdb_portid_bits) &&
1948 nwwnn == lp->node_wwn && nwwpn == lp->port_wwn &&
1949 lp->roles == nrole && lp->force_logout == 0) {
1950 lp->loggedin = lp->valid = 1;
1951 isp_prt(isp, ISP_LOGCONFIG, lretained,
1952 (int) (lp - fcp->portdb),
1953 (int) lp->loopid, lp->portid);
1954 continue;
1955 }
1956 }
1957
1958 if (fcp->isp_fwstate != FW_READY ||
1959 fcp->isp_loopstate != LOOP_SYNCING_PDB) {
1960 return (-1);
1961 }
1962
1963 /*
1964 * Force a logout if we were logged in.
1965 */
1966 if (lp->loggedin) {
1967 if (lp->force_logout ||
1968 isp_getpdb(isp, lp->loopid, &pdb) == 0) {
1795 fcp->isp_portid, fcp->isp_loopstate, toponames[fcp->isp_topo]);
1796
1797 /*
1798 * Announce ourselves, too. This involves synthesizing an entry.
1799 */
1800 if (fcp->isp_iid_set == 0) {
1801 fcp->isp_iid_set = 1;
1802 fcp->isp_iid = fcp->isp_loopid;
1803 lp = &fcp->portdb[fcp->isp_iid];
1804 } else {
1805 lp = &fcp->portdb[fcp->isp_iid];
1806 if (fcp->isp_portid != lp->portid ||
1807 fcp->isp_loopid != lp->loopid ||
1808 fcp->isp_nodewwn != ISP_NODEWWN(isp) ||
1809 fcp->isp_portwwn != ISP_PORTWWN(isp)) {
1810 lp->valid = 0;
1811 count = fcp->isp_iid;
1812 (void) isp_async(isp, ISPASYNC_PROMENADE, &count);
1813 }
1814 }
1815 lp->loopid = fcp->isp_loopid;
1816 lp->portid = fcp->isp_portid;
1817 lp->node_wwn = ISP_NODEWWN(isp);
1818 lp->port_wwn = ISP_PORTWWN(isp);
1819 switch (isp->isp_role) {
1820 case ISP_ROLE_NONE:
1821 lp->roles = 0;
1822 break;
1823 case ISP_ROLE_TARGET:
1824 lp->roles = SVC3_TGT_ROLE >> SVC3_ROLE_SHIFT;
1825 break;
1826 case ISP_ROLE_INITIATOR:
1827 lp->roles = SVC3_INI_ROLE >> SVC3_ROLE_SHIFT;
1828 break;
1829 case ISP_ROLE_BOTH:
1830 lp->roles = (SVC3_INI_ROLE|SVC3_TGT_ROLE) >> SVC3_ROLE_SHIFT;
1831 break;
1832 }
1833 lp->loggedin = lp->valid = 1;
1834 count = fcp->isp_iid;
1835 (void) isp_async(isp, ISPASYNC_PROMENADE, &count);
1836 return (0);
1837}
1838
1839static char *
1840isp2100_fw_statename(int state)
1841{
1842 switch(state) {
1843 case FW_CONFIG_WAIT: return "Config Wait";
1844 case FW_WAIT_AL_PA: return "Waiting for AL_PA";
1845 case FW_WAIT_LOGIN: return "Wait Login";
1846 case FW_READY: return "Ready";
1847 case FW_LOSS_OF_SYNC: return "Loss Of Sync";
1848 case FW_ERROR: return "Error";
1849 case FW_REINIT: return "Re-Init";
1850 case FW_NON_PART: return "Nonparticipating";
1851 default: return "?????";
1852 }
1853}
1854
1855/*
1856 * Synchronize our soft copy of the port database with what the f/w thinks
1857 * (with a view toward possibly for a specific target....)
1858 */
1859
1860static int
1861isp_pdb_sync(struct ispsoftc *isp)
1862{
1863 struct lportdb *lp;
1864 fcparam *fcp = isp->isp_param;
1865 isp_pdb_t pdb;
1866 int loopid, base, lim;
1867
1868 /*
1869 * Make sure we're okay for doing this right now.
1870 */
1871 if (fcp->isp_loopstate != LOOP_PDB_RCVD &&
1872 fcp->isp_loopstate != LOOP_FSCAN_DONE &&
1873 fcp->isp_loopstate != LOOP_LSCAN_DONE) {
1874 return (-1);
1875 }
1876
1877 if (fcp->isp_topo == TOPO_FL_PORT || fcp->isp_topo == TOPO_NL_PORT ||
1878 fcp->isp_topo == TOPO_N_PORT) {
1879 if (fcp->isp_loopstate < LOOP_LSCAN_DONE) {
1880 if (isp_scan_loop(isp) != 0) {
1881 return (-1);
1882 }
1883 }
1884 }
1885 fcp->isp_loopstate = LOOP_SYNCING_PDB;
1886
1887 /*
1888 * If we get this far, we've settled our differences with the f/w
1889 * (for local loop device) and we can say that the loop state is ready.
1890 */
1891
1892 if (fcp->isp_topo == TOPO_NL_PORT) {
1893 fcp->loop_seen_once = 1;
1894 fcp->isp_loopstate = LOOP_READY;
1895 return (0);
1896 }
1897
1898 /*
1899 * Find all Fabric Entities that didn't make it from one scan to the
1900 * next and let the world know they went away. Scan the whole database.
1901 */
1902 for (lp = &fcp->portdb[0]; lp < &fcp->portdb[MAX_FC_TARG]; lp++) {
1903 if (lp->was_fabric_dev && lp->fabric_dev == 0) {
1904 loopid = lp - fcp->portdb;
1905 lp->valid = 0; /* should already be set */
1906 (void) isp_async(isp, ISPASYNC_PROMENADE, &loopid);
1907 MEMZERO((void *) lp, sizeof (*lp));
1908 continue;
1909 }
1910 lp->was_fabric_dev = lp->fabric_dev;
1911 }
1912
1913 if (fcp->isp_topo == TOPO_FL_PORT)
1914 base = FC_SNS_ID+1;
1915 else
1916 base = 0;
1917
1918 if (fcp->isp_topo == TOPO_N_PORT)
1919 lim = 1;
1920 else
1921 lim = MAX_FC_TARG;
1922
1923 /*
1924 * Now log in any fabric devices that the outer layer has
1925 * left for us to see. This seems the most sane policy
1926 * for the moment.
1927 */
1928 for (lp = &fcp->portdb[base]; lp < &fcp->portdb[lim]; lp++) {
1929 u_int32_t portid;
1930 mbreg_t mbs;
1931
1932 loopid = lp - fcp->portdb;
1933 if (loopid >= FL_PORT_ID && loopid <= FC_SNS_ID) {
1934 continue;
1935 }
1936
1937 /*
1938 * Anything here?
1939 */
1940 if (lp->port_wwn == 0) {
1941 continue;
1942 }
1943
1944 /*
1945 * Don't try to log into yourself.
1946 */
1947 if ((portid = lp->portid) == fcp->isp_portid) {
1948 continue;
1949 }
1950
1951
1952 /*
1953 * If we'd been logged in- see if we still are and we haven't
1954 * changed. If so, no need to log ourselves out, etc..
1955 *
1956 * Unfortunately, our charming Qlogic f/w has decided to
1957 * return a valid port database entry for a fabric device
1958 * that has, in fact, gone away. And it hangs trying to
1959 * log it out.
1960 */
1961 if (lp->loggedin && lp->force_logout == 0 &&
1962 isp_getpdb(isp, lp->loopid, &pdb) == 0) {
1963 int nrole;
1964 u_int64_t nwwnn, nwwpn;
1965 nwwnn =
1966 (((u_int64_t)pdb.pdb_nodename[0]) << 56) |
1967 (((u_int64_t)pdb.pdb_nodename[1]) << 48) |
1968 (((u_int64_t)pdb.pdb_nodename[2]) << 40) |
1969 (((u_int64_t)pdb.pdb_nodename[3]) << 32) |
1970 (((u_int64_t)pdb.pdb_nodename[4]) << 24) |
1971 (((u_int64_t)pdb.pdb_nodename[5]) << 16) |
1972 (((u_int64_t)pdb.pdb_nodename[6]) << 8) |
1973 (((u_int64_t)pdb.pdb_nodename[7]));
1974 nwwpn =
1975 (((u_int64_t)pdb.pdb_portname[0]) << 56) |
1976 (((u_int64_t)pdb.pdb_portname[1]) << 48) |
1977 (((u_int64_t)pdb.pdb_portname[2]) << 40) |
1978 (((u_int64_t)pdb.pdb_portname[3]) << 32) |
1979 (((u_int64_t)pdb.pdb_portname[4]) << 24) |
1980 (((u_int64_t)pdb.pdb_portname[5]) << 16) |
1981 (((u_int64_t)pdb.pdb_portname[6]) << 8) |
1982 (((u_int64_t)pdb.pdb_portname[7]));
1983 nrole = (pdb.pdb_prli_svc3 & SVC3_ROLE_MASK) >>
1984 SVC3_ROLE_SHIFT;
1985 if (pdb.pdb_loopid == lp->loopid && lp->portid ==
1986 (u_int32_t) BITS2WORD(pdb.pdb_portid_bits) &&
1987 nwwnn == lp->node_wwn && nwwpn == lp->port_wwn &&
1988 lp->roles == nrole && lp->force_logout == 0) {
1989 lp->loggedin = lp->valid = 1;
1990 isp_prt(isp, ISP_LOGCONFIG, lretained,
1991 (int) (lp - fcp->portdb),
1992 (int) lp->loopid, lp->portid);
1993 continue;
1994 }
1995 }
1996
1997 if (fcp->isp_fwstate != FW_READY ||
1998 fcp->isp_loopstate != LOOP_SYNCING_PDB) {
1999 return (-1);
2000 }
2001
2002 /*
2003 * Force a logout if we were logged in.
2004 */
2005 if (lp->loggedin) {
2006 if (lp->force_logout ||
2007 isp_getpdb(isp, lp->loopid, &pdb) == 0) {
2008 MEMZERO(&mbs, sizeof (mbs));
1969 mbs.param[0] = MBOX_FABRIC_LOGOUT;
2009 mbs.param[0] = MBOX_FABRIC_LOGOUT;
1970 mbs.param[1] = lp->loopid << 8;
2010 if (IS_2KLOGIN(isp)) {
2011 mbs.param[1] = lp->loopid;
2012 mbs.obits |= (1 << 10);
2013 } else {
2014 mbs.param[1] = lp->loopid << 8;
2015 }
1971 mbs.param[2] = 0;
1972 mbs.param[3] = 0;
1973 isp_mboxcmd(isp, &mbs, MBLOGNONE);
1974 isp_prt(isp, ISP_LOGINFO, plogout,
1975 (int) (lp - fcp->portdb), lp->loopid,
1976 lp->portid);
1977 }
1978 lp->force_logout = lp->loggedin = 0;
1979 if (fcp->isp_fwstate != FW_READY ||
1980 fcp->isp_loopstate != LOOP_SYNCING_PDB) {
1981 return (-1);
1982 }
1983 }
1984
1985 /*
1986 * And log in....
1987 */
1988 loopid = lp - fcp->portdb;
1989 lp->loopid = FL_PORT_ID;
1990 do {
2016 mbs.param[2] = 0;
2017 mbs.param[3] = 0;
2018 isp_mboxcmd(isp, &mbs, MBLOGNONE);
2019 isp_prt(isp, ISP_LOGINFO, plogout,
2020 (int) (lp - fcp->portdb), lp->loopid,
2021 lp->portid);
2022 }
2023 lp->force_logout = lp->loggedin = 0;
2024 if (fcp->isp_fwstate != FW_READY ||
2025 fcp->isp_loopstate != LOOP_SYNCING_PDB) {
2026 return (-1);
2027 }
2028 }
2029
2030 /*
2031 * And log in....
2032 */
2033 loopid = lp - fcp->portdb;
2034 lp->loopid = FL_PORT_ID;
2035 do {
2036 MEMZERO(&mbs, sizeof (mbs));
1991 mbs.param[0] = MBOX_FABRIC_LOGIN;
2037 mbs.param[0] = MBOX_FABRIC_LOGIN;
1992 mbs.param[1] = loopid << 8;
2038 if (IS_2KLOGIN(isp)) {
2039 mbs.param[1] = loopid;
2040 mbs.obits |= (1 << 10);
2041 } else {
2042 mbs.param[1] = loopid << 8;
2043 }
1993 mbs.param[2] = portid >> 16;
1994 mbs.param[3] = portid & 0xffff;
1995 isp_mboxcmd(isp, &mbs, MBLOGALL & ~(MBOX_LOOP_ID_USED |
1996 MBOX_PORT_ID_USED | MBOX_COMMAND_ERROR));
1997 if (fcp->isp_fwstate != FW_READY ||
1998 fcp->isp_loopstate != LOOP_SYNCING_PDB) {
1999 return (-1);
2000 }
2001 switch (mbs.param[0]) {
2002 case MBOX_LOOP_ID_USED:
2003 /*
2004 * Try the next available loop id.
2005 */
2006 loopid++;
2007 break;
2008 case MBOX_PORT_ID_USED:
2009 /*
2010 * This port is already logged in.
2011 * Snaffle the loop id it's using if it's
2012 * nonzero, otherwise we're hosed.
2013 */
2014 if (mbs.param[1] != 0) {
2015 loopid = mbs.param[1];
2016 isp_prt(isp, ISP_LOGINFO, retained,
2017 loopid, (int) (lp - fcp->portdb),
2018 lp->portid);
2019 } else {
2020 loopid = MAX_FC_TARG;
2021 break;
2022 }
2023 /* FALLTHROUGH */
2024 case MBOX_COMMAND_COMPLETE:
2025 lp->loggedin = 1;
2026 lp->loopid = loopid;
2027 break;
2028 case MBOX_COMMAND_ERROR:
2029 isp_prt(isp, ISP_LOGINFO, plogierr,
2030 portid, mbs.param[1]);
2031 /* FALLTHROUGH */
2032 case MBOX_ALL_IDS_USED: /* We're outta IDs */
2033 default:
2034 loopid = MAX_FC_TARG;
2035 break;
2036 }
2037 } while (lp->loopid == FL_PORT_ID && loopid < MAX_FC_TARG);
2038
2039 /*
2040 * If we get here and we haven't set a Loop ID,
2041 * we failed to log into this device.
2042 */
2043
2044 if (lp->loopid == FL_PORT_ID) {
2045 lp->loopid = 0;
2046 continue;
2047 }
2048
2049 /*
2050 * Make sure we can get the approriate port information.
2051 */
2052 if (isp_getpdb(isp, lp->loopid, &pdb) != 0) {
2053 isp_prt(isp, ISP_LOGWARN, nopdb, lp->portid);
2054 goto dump_em;
2055 }
2056
2057 if (fcp->isp_fwstate != FW_READY ||
2058 fcp->isp_loopstate != LOOP_SYNCING_PDB) {
2059 return (-1);
2060 }
2061
2062 if (pdb.pdb_loopid != lp->loopid) {
2063 isp_prt(isp, ISP_LOGWARN, pdbmfail1,
2064 lp->portid, pdb.pdb_loopid);
2065 goto dump_em;
2066 }
2067
2068 if (lp->portid != (u_int32_t) BITS2WORD(pdb.pdb_portid_bits)) {
2069 isp_prt(isp, ISP_LOGWARN, pdbmfail2,
2070 lp->portid, BITS2WORD(pdb.pdb_portid_bits));
2071 goto dump_em;
2072 }
2073
2074 lp->roles =
2075 (pdb.pdb_prli_svc3 & SVC3_ROLE_MASK) >> SVC3_ROLE_SHIFT;
2076 lp->node_wwn =
2077 (((u_int64_t)pdb.pdb_nodename[0]) << 56) |
2078 (((u_int64_t)pdb.pdb_nodename[1]) << 48) |
2079 (((u_int64_t)pdb.pdb_nodename[2]) << 40) |
2080 (((u_int64_t)pdb.pdb_nodename[3]) << 32) |
2081 (((u_int64_t)pdb.pdb_nodename[4]) << 24) |
2082 (((u_int64_t)pdb.pdb_nodename[5]) << 16) |
2083 (((u_int64_t)pdb.pdb_nodename[6]) << 8) |
2084 (((u_int64_t)pdb.pdb_nodename[7]));
2085 lp->port_wwn =
2086 (((u_int64_t)pdb.pdb_portname[0]) << 56) |
2087 (((u_int64_t)pdb.pdb_portname[1]) << 48) |
2088 (((u_int64_t)pdb.pdb_portname[2]) << 40) |
2089 (((u_int64_t)pdb.pdb_portname[3]) << 32) |
2090 (((u_int64_t)pdb.pdb_portname[4]) << 24) |
2091 (((u_int64_t)pdb.pdb_portname[5]) << 16) |
2092 (((u_int64_t)pdb.pdb_portname[6]) << 8) |
2093 (((u_int64_t)pdb.pdb_portname[7]));
2094 /*
2095 * Check to make sure this all makes sense.
2096 */
2097 if (lp->node_wwn && lp->port_wwn) {
2098 lp->valid = 1;
2099 loopid = lp - fcp->portdb;
2100 (void) isp_async(isp, ISPASYNC_PROMENADE, &loopid);
2101 continue;
2102 }
2103dump_em:
2104 lp->valid = 0;
2105 isp_prt(isp, ISP_LOGINFO,
2106 ldumped, loopid, lp->loopid, lp->portid);
2044 mbs.param[2] = portid >> 16;
2045 mbs.param[3] = portid & 0xffff;
2046 isp_mboxcmd(isp, &mbs, MBLOGALL & ~(MBOX_LOOP_ID_USED |
2047 MBOX_PORT_ID_USED | MBOX_COMMAND_ERROR));
2048 if (fcp->isp_fwstate != FW_READY ||
2049 fcp->isp_loopstate != LOOP_SYNCING_PDB) {
2050 return (-1);
2051 }
2052 switch (mbs.param[0]) {
2053 case MBOX_LOOP_ID_USED:
2054 /*
2055 * Try the next available loop id.
2056 */
2057 loopid++;
2058 break;
2059 case MBOX_PORT_ID_USED:
2060 /*
2061 * This port is already logged in.
2062 * Snaffle the loop id it's using if it's
2063 * nonzero, otherwise we're hosed.
2064 */
2065 if (mbs.param[1] != 0) {
2066 loopid = mbs.param[1];
2067 isp_prt(isp, ISP_LOGINFO, retained,
2068 loopid, (int) (lp - fcp->portdb),
2069 lp->portid);
2070 } else {
2071 loopid = MAX_FC_TARG;
2072 break;
2073 }
2074 /* FALLTHROUGH */
2075 case MBOX_COMMAND_COMPLETE:
2076 lp->loggedin = 1;
2077 lp->loopid = loopid;
2078 break;
2079 case MBOX_COMMAND_ERROR:
2080 isp_prt(isp, ISP_LOGINFO, plogierr,
2081 portid, mbs.param[1]);
2082 /* FALLTHROUGH */
2083 case MBOX_ALL_IDS_USED: /* We're outta IDs */
2084 default:
2085 loopid = MAX_FC_TARG;
2086 break;
2087 }
2088 } while (lp->loopid == FL_PORT_ID && loopid < MAX_FC_TARG);
2089
2090 /*
2091 * If we get here and we haven't set a Loop ID,
2092 * we failed to log into this device.
2093 */
2094
2095 if (lp->loopid == FL_PORT_ID) {
2096 lp->loopid = 0;
2097 continue;
2098 }
2099
2100 /*
2101 * Make sure we can get the approriate port information.
2102 */
2103 if (isp_getpdb(isp, lp->loopid, &pdb) != 0) {
2104 isp_prt(isp, ISP_LOGWARN, nopdb, lp->portid);
2105 goto dump_em;
2106 }
2107
2108 if (fcp->isp_fwstate != FW_READY ||
2109 fcp->isp_loopstate != LOOP_SYNCING_PDB) {
2110 return (-1);
2111 }
2112
2113 if (pdb.pdb_loopid != lp->loopid) {
2114 isp_prt(isp, ISP_LOGWARN, pdbmfail1,
2115 lp->portid, pdb.pdb_loopid);
2116 goto dump_em;
2117 }
2118
2119 if (lp->portid != (u_int32_t) BITS2WORD(pdb.pdb_portid_bits)) {
2120 isp_prt(isp, ISP_LOGWARN, pdbmfail2,
2121 lp->portid, BITS2WORD(pdb.pdb_portid_bits));
2122 goto dump_em;
2123 }
2124
2125 lp->roles =
2126 (pdb.pdb_prli_svc3 & SVC3_ROLE_MASK) >> SVC3_ROLE_SHIFT;
2127 lp->node_wwn =
2128 (((u_int64_t)pdb.pdb_nodename[0]) << 56) |
2129 (((u_int64_t)pdb.pdb_nodename[1]) << 48) |
2130 (((u_int64_t)pdb.pdb_nodename[2]) << 40) |
2131 (((u_int64_t)pdb.pdb_nodename[3]) << 32) |
2132 (((u_int64_t)pdb.pdb_nodename[4]) << 24) |
2133 (((u_int64_t)pdb.pdb_nodename[5]) << 16) |
2134 (((u_int64_t)pdb.pdb_nodename[6]) << 8) |
2135 (((u_int64_t)pdb.pdb_nodename[7]));
2136 lp->port_wwn =
2137 (((u_int64_t)pdb.pdb_portname[0]) << 56) |
2138 (((u_int64_t)pdb.pdb_portname[1]) << 48) |
2139 (((u_int64_t)pdb.pdb_portname[2]) << 40) |
2140 (((u_int64_t)pdb.pdb_portname[3]) << 32) |
2141 (((u_int64_t)pdb.pdb_portname[4]) << 24) |
2142 (((u_int64_t)pdb.pdb_portname[5]) << 16) |
2143 (((u_int64_t)pdb.pdb_portname[6]) << 8) |
2144 (((u_int64_t)pdb.pdb_portname[7]));
2145 /*
2146 * Check to make sure this all makes sense.
2147 */
2148 if (lp->node_wwn && lp->port_wwn) {
2149 lp->valid = 1;
2150 loopid = lp - fcp->portdb;
2151 (void) isp_async(isp, ISPASYNC_PROMENADE, &loopid);
2152 continue;
2153 }
2154dump_em:
2155 lp->valid = 0;
2156 isp_prt(isp, ISP_LOGINFO,
2157 ldumped, loopid, lp->loopid, lp->portid);
2158 MEMZERO(&mbs, sizeof (mbs));
2107 mbs.param[0] = MBOX_FABRIC_LOGOUT;
2159 mbs.param[0] = MBOX_FABRIC_LOGOUT;
2108 mbs.param[1] = lp->loopid << 8;
2109 mbs.param[2] = 0;
2110 mbs.param[3] = 0;
2160 if (IS_2KLOGIN(isp)) {
2161 mbs.param[1] = lp->loopid;
2162 mbs.obits |= (1 << 10);
2163 } else {
2164 mbs.param[1] = lp->loopid << 8;
2165 }
2111 isp_mboxcmd(isp, &mbs, MBLOGNONE);
2112 if (fcp->isp_fwstate != FW_READY ||
2113 fcp->isp_loopstate != LOOP_SYNCING_PDB) {
2114 return (-1);
2115 }
2116 }
2117 /*
2118 * If we get here, we've for sure seen not only a valid loop
2119 * but know what is or isn't on it, so mark this for usage
2120 * in isp_start.
2121 */
2122 fcp->loop_seen_once = 1;
2123 fcp->isp_loopstate = LOOP_READY;
2124 return (0);
2125}
2126
2127static int
2128isp_scan_loop(struct ispsoftc *isp)
2129{
2130 struct lportdb *lp;
2131 fcparam *fcp = isp->isp_param;
2132 isp_pdb_t pdb;
2133 int loopid, lim, hival;
2134
2135 switch (fcp->isp_topo) {
2136 case TOPO_NL_PORT:
2137 hival = FL_PORT_ID;
2138 break;
2139 case TOPO_N_PORT:
2140 hival = 2;
2141 break;
2142 case TOPO_FL_PORT:
2143 hival = FC_PORT_ID;
2144 break;
2145 default:
2146 fcp->isp_loopstate = LOOP_LSCAN_DONE;
2147 return (0);
2148 }
2149 fcp->isp_loopstate = LOOP_SCANNING_LOOP;
2150
2151 /*
2152 * make sure the temp port database is clean...
2153 */
2154 MEMZERO((void *)fcp->tport, sizeof (fcp->tport));
2155
2156 /*
2157 * Run through the local loop ports and get port database info
2158 * for each loop ID.
2159 *
2160 * There's a somewhat unexplained situation where the f/w passes back
2161 * the wrong database entity- if that happens, just restart (up to
2162 * FL_PORT_ID times).
2163 */
2164 for (lim = loopid = 0; loopid < hival; loopid++) {
2165 lp = &fcp->tport[loopid];
2166
2167 /*
2168 * Don't even try for ourselves...
2169 */
2170 if (loopid == fcp->isp_loopid)
2171 continue;
2172
2173 lp->node_wwn = isp_get_portname(isp, loopid, 1);
2174 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
2175 return (-1);
2176 if (lp->node_wwn == 0)
2177 continue;
2178 lp->port_wwn = isp_get_portname(isp, loopid, 0);
2179 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
2180 return (-1);
2181 if (lp->port_wwn == 0) {
2182 lp->node_wwn = 0;
2183 continue;
2184 }
2185
2186 /*
2187 * Get an entry....
2188 */
2189 if (isp_getpdb(isp, loopid, &pdb) != 0) {
2190 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
2191 return (-1);
2192 continue;
2193 }
2194 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP) {
2195 return (-1);
2196 }
2197
2198 /*
2199 * If the returned database element doesn't match what we
2200 * asked for, restart the process entirely (up to a point...).
2201 */
2202 if (pdb.pdb_loopid != loopid) {
2203 loopid = 0;
2204 if (lim++ < hival) {
2205 continue;
2206 }
2207 isp_prt(isp, ISP_LOGWARN,
2208 "giving up on synchronizing the port database");
2209 return (-1);
2210 }
2211
2212 /*
2213 * Save the pertinent info locally.
2214 */
2215 lp->node_wwn =
2216 (((u_int64_t)pdb.pdb_nodename[0]) << 56) |
2217 (((u_int64_t)pdb.pdb_nodename[1]) << 48) |
2218 (((u_int64_t)pdb.pdb_nodename[2]) << 40) |
2219 (((u_int64_t)pdb.pdb_nodename[3]) << 32) |
2220 (((u_int64_t)pdb.pdb_nodename[4]) << 24) |
2221 (((u_int64_t)pdb.pdb_nodename[5]) << 16) |
2222 (((u_int64_t)pdb.pdb_nodename[6]) << 8) |
2223 (((u_int64_t)pdb.pdb_nodename[7]));
2224 lp->port_wwn =
2225 (((u_int64_t)pdb.pdb_portname[0]) << 56) |
2226 (((u_int64_t)pdb.pdb_portname[1]) << 48) |
2227 (((u_int64_t)pdb.pdb_portname[2]) << 40) |
2228 (((u_int64_t)pdb.pdb_portname[3]) << 32) |
2229 (((u_int64_t)pdb.pdb_portname[4]) << 24) |
2230 (((u_int64_t)pdb.pdb_portname[5]) << 16) |
2231 (((u_int64_t)pdb.pdb_portname[6]) << 8) |
2232 (((u_int64_t)pdb.pdb_portname[7]));
2233 lp->roles =
2234 (pdb.pdb_prli_svc3 & SVC3_ROLE_MASK) >> SVC3_ROLE_SHIFT;
2235 lp->portid = BITS2WORD(pdb.pdb_portid_bits);
2236 lp->loopid = pdb.pdb_loopid;
2237 }
2238
2239 /*
2240 * Mark all of the permanent local loop database entries as invalid
2241 * (except our own entry).
2242 */
2243 for (loopid = 0; loopid < hival; loopid++) {
2244 if (loopid == fcp->isp_iid) {
2245 fcp->portdb[loopid].valid = 1;
2246 fcp->portdb[loopid].loopid = fcp->isp_loopid;
2247 continue;
2248 }
2249 fcp->portdb[loopid].valid = 0;
2250 }
2251
2252 /*
2253 * Now merge our local copy of the port database into our saved copy.
2254 * Notify the outer layers of new devices arriving.
2255 */
2256 for (loopid = 0; loopid < hival; loopid++) {
2257 int i;
2258
2259 /*
2260 * If we don't have a non-zero Port WWN, we're not here.
2261 */
2262 if (fcp->tport[loopid].port_wwn == 0) {
2263 continue;
2264 }
2265
2266 /*
2267 * Skip ourselves.
2268 */
2269 if (loopid == fcp->isp_iid) {
2270 continue;
2271 }
2272
2273 /*
2274 * For the purposes of deciding whether this is the
2275 * 'same' device or not, we only search for an identical
2276 * Port WWN. Node WWNs may or may not be the same as
2277 * the Port WWN, and there may be multiple different
2278 * Port WWNs with the same Node WWN. It would be chaos
2279 * to have multiple identical Port WWNs, so we don't
2280 * allow that.
2281 */
2282
2283 for (i = 0; i < hival; i++) {
2284 int j;
2285 if (fcp->portdb[i].port_wwn == 0)
2286 continue;
2287 if (fcp->portdb[i].port_wwn !=
2288 fcp->tport[loopid].port_wwn)
2289 continue;
2290 /*
2291 * We found this WWN elsewhere- it's changed
2292 * loopids then. We don't change it's actual
2293 * position in our cached port database- we
2294 * just change the actual loop ID we'd use.
2295 */
2296 if (fcp->portdb[i].loopid != loopid) {
2297 isp_prt(isp, ISP_LOGINFO, portshift, i,
2298 fcp->portdb[i].loopid,
2299 fcp->portdb[i].portid, loopid,
2300 fcp->tport[loopid].portid);
2301 }
2302 fcp->portdb[i].portid = fcp->tport[loopid].portid;
2303 fcp->portdb[i].loopid = loopid;
2304 fcp->portdb[i].valid = 1;
2305 fcp->portdb[i].roles = fcp->tport[loopid].roles;
2306
2307 /*
2308 * Now make sure this Port WWN doesn't exist elsewhere
2309 * in the port database.
2310 */
2311 for (j = i+1; j < hival; j++) {
2312 if (fcp->portdb[i].port_wwn !=
2313 fcp->portdb[j].port_wwn) {
2314 continue;
2315 }
2316 isp_prt(isp, ISP_LOGWARN, portdup, j, i);
2317 /*
2318 * Invalidate the 'old' *and* 'new' ones.
2319 * This is really harsh and not quite right,
2320 * but if this happens, we really don't know
2321 * who is what at this point.
2322 */
2323 fcp->portdb[i].valid = 0;
2324 fcp->portdb[j].valid = 0;
2325 }
2326 break;
2327 }
2328
2329 /*
2330 * If we didn't traverse the entire port database,
2331 * then we found (and remapped) an existing entry.
2332 * No need to notify anyone- go for the next one.
2333 */
2334 if (i < hival) {
2335 isp_prt(isp, ISP_LOGINFO, retained,
2336 fcp->portdb[i].loopid, i, fcp->portdb[i].portid);
2337 continue;
2338 }
2339
2340 /*
2341 * We've not found this Port WWN anywhere. It's a new entry.
2342 * See if we can leave it where it is (with target == loopid).
2343 */
2344 if (fcp->portdb[loopid].port_wwn != 0) {
2345 for (lim = 0; lim < hival; lim++) {
2346 if (fcp->portdb[lim].port_wwn == 0)
2347 break;
2348 }
2349 /* "Cannot Happen" */
2350 if (lim == hival) {
2351 isp_prt(isp, ISP_LOGWARN, "Remap Overflow");
2352 continue;
2353 }
2354 i = lim;
2355 } else {
2356 i = loopid;
2357 }
2358
2359 /*
2360 * NB: The actual loopid we use here is loopid- we may
2361 * in fact be at a completely different index (target).
2362 */
2363 fcp->portdb[i].loopid = loopid;
2364 fcp->portdb[i].port_wwn = fcp->tport[loopid].port_wwn;
2365 fcp->portdb[i].node_wwn = fcp->tport[loopid].node_wwn;
2366 fcp->portdb[i].roles = fcp->tport[loopid].roles;
2367 fcp->portdb[i].portid = fcp->tport[loopid].portid;
2368 fcp->portdb[i].valid = 1;
2369
2370 /*
2371 * Tell the outside world we've arrived.
2372 */
2373 (void) isp_async(isp, ISPASYNC_PROMENADE, &i);
2374 }
2375
2376 /*
2377 * Now find all previously used targets that are now invalid and
2378 * notify the outer layers that they're gone.
2379 */
2380 for (lp = &fcp->portdb[0]; lp < &fcp->portdb[hival]; lp++) {
2381 if (lp->valid || lp->port_wwn == 0) {
2382 continue;
2383 }
2384
2385 /*
2386 * Tell the outside world we've gone
2387 * away and erase our pdb entry.
2388 *
2389 */
2390 loopid = lp - fcp->portdb;
2391 (void) isp_async(isp, ISPASYNC_PROMENADE, &loopid);
2392 MEMZERO((void *) lp, sizeof (*lp));
2393 }
2394 fcp->isp_loopstate = LOOP_LSCAN_DONE;
2395 return (0);
2396}
2397
2398
2399static int
2400isp_fabric_mbox_cmd(struct ispsoftc *isp, mbreg_t *mbp)
2401{
2402 isp_mboxcmd(isp, mbp, MBLOGNONE);
2403 if (mbp->param[0] != MBOX_COMMAND_COMPLETE) {
2404 if (FCPARAM(isp)->isp_loopstate == LOOP_SCANNING_FABRIC) {
2405 FCPARAM(isp)->isp_loopstate = LOOP_PDB_RCVD;
2406 }
2407 if (mbp->param[0] == MBOX_COMMAND_ERROR) {
2408 char tbuf[16];
2409 char *m;
2410 switch (mbp->param[1]) {
2411 case 1:
2412 m = "No Loop";
2413 break;
2414 case 2:
2415 m = "Failed to allocate IOCB buffer";
2416 break;
2417 case 3:
2418 m = "Failed to allocate XCB buffer";
2419 break;
2420 case 4:
2421 m = "timeout or transmit failed";
2422 break;
2423 case 5:
2424 m = "no fabric loop";
2425 break;
2426 case 6:
2427 m = "remote device not a target";
2428 break;
2429 default:
2430 SNPRINTF(tbuf, sizeof tbuf, "%x",
2431 mbp->param[1]);
2432 m = tbuf;
2433 break;
2434 }
2435 isp_prt(isp, ISP_LOGERR, "SNS Failed- %s", m);
2436 }
2437 return (-1);
2438 }
2439
2440 if (FCPARAM(isp)->isp_fwstate != FW_READY ||
2441 FCPARAM(isp)->isp_loopstate < LOOP_SCANNING_FABRIC) {
2442 return (-1);
2443 }
2444 return(0);
2445}
2446
2447#ifdef ISP_USE_GA_NXT
2448static int
2449isp_scan_fabric(struct ispsoftc *isp, int ftype)
2450{
2451 fcparam *fcp = isp->isp_param;
2452 u_int32_t portid, first_portid, last_portid;
2453 int hicap, last_port_same;
2454
2455 if (fcp->isp_onfabric == 0) {
2456 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2457 return (0);
2458 }
2459
2460 FC_SCRATCH_ACQUIRE(isp);
2461
2462 /*
2463 * Since Port IDs are 24 bits, we can check against having seen
2464 * anything yet with this value.
2465 */
2466 last_port_same = 0;
2467 last_portid = 0xffffffff; /* not a port */
2468 first_portid = portid = fcp->isp_portid;
2469 fcp->isp_loopstate = LOOP_SCANNING_FABRIC;
2470
2471 for (hicap = 0; hicap < GA_NXT_MAX; hicap++) {
2472 mbreg_t mbs;
2473 sns_screq_t *rq;
2474 sns_ga_nxt_rsp_t *rs0, *rs1;
2475 struct lportdb lcl;
2476 u_int8_t sc[SNS_GA_NXT_RESP_SIZE];
2477
2478 rq = (sns_screq_t *)sc;
2479 MEMZERO((void *) rq, SNS_GA_NXT_REQ_SIZE);
2480 rq->snscb_rblen = SNS_GA_NXT_RESP_SIZE >> 1;
2481 rq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma+0x100);
2482 rq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma+0x100);
2483 rq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma+0x100);
2484 rq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma+0x100);
2485 rq->snscb_sblen = 6;
2486 rq->snscb_data[0] = SNS_GA_NXT;
2487 rq->snscb_data[4] = portid & 0xffff;
2488 rq->snscb_data[5] = (portid >> 16) & 0xff;
2489 isp_put_sns_request(isp, rq, (sns_screq_t *) fcp->isp_scratch);
2490 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GA_NXT_REQ_SIZE);
2166 isp_mboxcmd(isp, &mbs, MBLOGNONE);
2167 if (fcp->isp_fwstate != FW_READY ||
2168 fcp->isp_loopstate != LOOP_SYNCING_PDB) {
2169 return (-1);
2170 }
2171 }
2172 /*
2173 * If we get here, we've for sure seen not only a valid loop
2174 * but know what is or isn't on it, so mark this for usage
2175 * in isp_start.
2176 */
2177 fcp->loop_seen_once = 1;
2178 fcp->isp_loopstate = LOOP_READY;
2179 return (0);
2180}
2181
2182static int
2183isp_scan_loop(struct ispsoftc *isp)
2184{
2185 struct lportdb *lp;
2186 fcparam *fcp = isp->isp_param;
2187 isp_pdb_t pdb;
2188 int loopid, lim, hival;
2189
2190 switch (fcp->isp_topo) {
2191 case TOPO_NL_PORT:
2192 hival = FL_PORT_ID;
2193 break;
2194 case TOPO_N_PORT:
2195 hival = 2;
2196 break;
2197 case TOPO_FL_PORT:
2198 hival = FC_PORT_ID;
2199 break;
2200 default:
2201 fcp->isp_loopstate = LOOP_LSCAN_DONE;
2202 return (0);
2203 }
2204 fcp->isp_loopstate = LOOP_SCANNING_LOOP;
2205
2206 /*
2207 * make sure the temp port database is clean...
2208 */
2209 MEMZERO((void *)fcp->tport, sizeof (fcp->tport));
2210
2211 /*
2212 * Run through the local loop ports and get port database info
2213 * for each loop ID.
2214 *
2215 * There's a somewhat unexplained situation where the f/w passes back
2216 * the wrong database entity- if that happens, just restart (up to
2217 * FL_PORT_ID times).
2218 */
2219 for (lim = loopid = 0; loopid < hival; loopid++) {
2220 lp = &fcp->tport[loopid];
2221
2222 /*
2223 * Don't even try for ourselves...
2224 */
2225 if (loopid == fcp->isp_loopid)
2226 continue;
2227
2228 lp->node_wwn = isp_get_portname(isp, loopid, 1);
2229 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
2230 return (-1);
2231 if (lp->node_wwn == 0)
2232 continue;
2233 lp->port_wwn = isp_get_portname(isp, loopid, 0);
2234 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
2235 return (-1);
2236 if (lp->port_wwn == 0) {
2237 lp->node_wwn = 0;
2238 continue;
2239 }
2240
2241 /*
2242 * Get an entry....
2243 */
2244 if (isp_getpdb(isp, loopid, &pdb) != 0) {
2245 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
2246 return (-1);
2247 continue;
2248 }
2249 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP) {
2250 return (-1);
2251 }
2252
2253 /*
2254 * If the returned database element doesn't match what we
2255 * asked for, restart the process entirely (up to a point...).
2256 */
2257 if (pdb.pdb_loopid != loopid) {
2258 loopid = 0;
2259 if (lim++ < hival) {
2260 continue;
2261 }
2262 isp_prt(isp, ISP_LOGWARN,
2263 "giving up on synchronizing the port database");
2264 return (-1);
2265 }
2266
2267 /*
2268 * Save the pertinent info locally.
2269 */
2270 lp->node_wwn =
2271 (((u_int64_t)pdb.pdb_nodename[0]) << 56) |
2272 (((u_int64_t)pdb.pdb_nodename[1]) << 48) |
2273 (((u_int64_t)pdb.pdb_nodename[2]) << 40) |
2274 (((u_int64_t)pdb.pdb_nodename[3]) << 32) |
2275 (((u_int64_t)pdb.pdb_nodename[4]) << 24) |
2276 (((u_int64_t)pdb.pdb_nodename[5]) << 16) |
2277 (((u_int64_t)pdb.pdb_nodename[6]) << 8) |
2278 (((u_int64_t)pdb.pdb_nodename[7]));
2279 lp->port_wwn =
2280 (((u_int64_t)pdb.pdb_portname[0]) << 56) |
2281 (((u_int64_t)pdb.pdb_portname[1]) << 48) |
2282 (((u_int64_t)pdb.pdb_portname[2]) << 40) |
2283 (((u_int64_t)pdb.pdb_portname[3]) << 32) |
2284 (((u_int64_t)pdb.pdb_portname[4]) << 24) |
2285 (((u_int64_t)pdb.pdb_portname[5]) << 16) |
2286 (((u_int64_t)pdb.pdb_portname[6]) << 8) |
2287 (((u_int64_t)pdb.pdb_portname[7]));
2288 lp->roles =
2289 (pdb.pdb_prli_svc3 & SVC3_ROLE_MASK) >> SVC3_ROLE_SHIFT;
2290 lp->portid = BITS2WORD(pdb.pdb_portid_bits);
2291 lp->loopid = pdb.pdb_loopid;
2292 }
2293
2294 /*
2295 * Mark all of the permanent local loop database entries as invalid
2296 * (except our own entry).
2297 */
2298 for (loopid = 0; loopid < hival; loopid++) {
2299 if (loopid == fcp->isp_iid) {
2300 fcp->portdb[loopid].valid = 1;
2301 fcp->portdb[loopid].loopid = fcp->isp_loopid;
2302 continue;
2303 }
2304 fcp->portdb[loopid].valid = 0;
2305 }
2306
2307 /*
2308 * Now merge our local copy of the port database into our saved copy.
2309 * Notify the outer layers of new devices arriving.
2310 */
2311 for (loopid = 0; loopid < hival; loopid++) {
2312 int i;
2313
2314 /*
2315 * If we don't have a non-zero Port WWN, we're not here.
2316 */
2317 if (fcp->tport[loopid].port_wwn == 0) {
2318 continue;
2319 }
2320
2321 /*
2322 * Skip ourselves.
2323 */
2324 if (loopid == fcp->isp_iid) {
2325 continue;
2326 }
2327
2328 /*
2329 * For the purposes of deciding whether this is the
2330 * 'same' device or not, we only search for an identical
2331 * Port WWN. Node WWNs may or may not be the same as
2332 * the Port WWN, and there may be multiple different
2333 * Port WWNs with the same Node WWN. It would be chaos
2334 * to have multiple identical Port WWNs, so we don't
2335 * allow that.
2336 */
2337
2338 for (i = 0; i < hival; i++) {
2339 int j;
2340 if (fcp->portdb[i].port_wwn == 0)
2341 continue;
2342 if (fcp->portdb[i].port_wwn !=
2343 fcp->tport[loopid].port_wwn)
2344 continue;
2345 /*
2346 * We found this WWN elsewhere- it's changed
2347 * loopids then. We don't change it's actual
2348 * position in our cached port database- we
2349 * just change the actual loop ID we'd use.
2350 */
2351 if (fcp->portdb[i].loopid != loopid) {
2352 isp_prt(isp, ISP_LOGINFO, portshift, i,
2353 fcp->portdb[i].loopid,
2354 fcp->portdb[i].portid, loopid,
2355 fcp->tport[loopid].portid);
2356 }
2357 fcp->portdb[i].portid = fcp->tport[loopid].portid;
2358 fcp->portdb[i].loopid = loopid;
2359 fcp->portdb[i].valid = 1;
2360 fcp->portdb[i].roles = fcp->tport[loopid].roles;
2361
2362 /*
2363 * Now make sure this Port WWN doesn't exist elsewhere
2364 * in the port database.
2365 */
2366 for (j = i+1; j < hival; j++) {
2367 if (fcp->portdb[i].port_wwn !=
2368 fcp->portdb[j].port_wwn) {
2369 continue;
2370 }
2371 isp_prt(isp, ISP_LOGWARN, portdup, j, i);
2372 /*
2373 * Invalidate the 'old' *and* 'new' ones.
2374 * This is really harsh and not quite right,
2375 * but if this happens, we really don't know
2376 * who is what at this point.
2377 */
2378 fcp->portdb[i].valid = 0;
2379 fcp->portdb[j].valid = 0;
2380 }
2381 break;
2382 }
2383
2384 /*
2385 * If we didn't traverse the entire port database,
2386 * then we found (and remapped) an existing entry.
2387 * No need to notify anyone- go for the next one.
2388 */
2389 if (i < hival) {
2390 isp_prt(isp, ISP_LOGINFO, retained,
2391 fcp->portdb[i].loopid, i, fcp->portdb[i].portid);
2392 continue;
2393 }
2394
2395 /*
2396 * We've not found this Port WWN anywhere. It's a new entry.
2397 * See if we can leave it where it is (with target == loopid).
2398 */
2399 if (fcp->portdb[loopid].port_wwn != 0) {
2400 for (lim = 0; lim < hival; lim++) {
2401 if (fcp->portdb[lim].port_wwn == 0)
2402 break;
2403 }
2404 /* "Cannot Happen" */
2405 if (lim == hival) {
2406 isp_prt(isp, ISP_LOGWARN, "Remap Overflow");
2407 continue;
2408 }
2409 i = lim;
2410 } else {
2411 i = loopid;
2412 }
2413
2414 /*
2415 * NB: The actual loopid we use here is loopid- we may
2416 * in fact be at a completely different index (target).
2417 */
2418 fcp->portdb[i].loopid = loopid;
2419 fcp->portdb[i].port_wwn = fcp->tport[loopid].port_wwn;
2420 fcp->portdb[i].node_wwn = fcp->tport[loopid].node_wwn;
2421 fcp->portdb[i].roles = fcp->tport[loopid].roles;
2422 fcp->portdb[i].portid = fcp->tport[loopid].portid;
2423 fcp->portdb[i].valid = 1;
2424
2425 /*
2426 * Tell the outside world we've arrived.
2427 */
2428 (void) isp_async(isp, ISPASYNC_PROMENADE, &i);
2429 }
2430
2431 /*
2432 * Now find all previously used targets that are now invalid and
2433 * notify the outer layers that they're gone.
2434 */
2435 for (lp = &fcp->portdb[0]; lp < &fcp->portdb[hival]; lp++) {
2436 if (lp->valid || lp->port_wwn == 0) {
2437 continue;
2438 }
2439
2440 /*
2441 * Tell the outside world we've gone
2442 * away and erase our pdb entry.
2443 *
2444 */
2445 loopid = lp - fcp->portdb;
2446 (void) isp_async(isp, ISPASYNC_PROMENADE, &loopid);
2447 MEMZERO((void *) lp, sizeof (*lp));
2448 }
2449 fcp->isp_loopstate = LOOP_LSCAN_DONE;
2450 return (0);
2451}
2452
2453
2454static int
2455isp_fabric_mbox_cmd(struct ispsoftc *isp, mbreg_t *mbp)
2456{
2457 isp_mboxcmd(isp, mbp, MBLOGNONE);
2458 if (mbp->param[0] != MBOX_COMMAND_COMPLETE) {
2459 if (FCPARAM(isp)->isp_loopstate == LOOP_SCANNING_FABRIC) {
2460 FCPARAM(isp)->isp_loopstate = LOOP_PDB_RCVD;
2461 }
2462 if (mbp->param[0] == MBOX_COMMAND_ERROR) {
2463 char tbuf[16];
2464 char *m;
2465 switch (mbp->param[1]) {
2466 case 1:
2467 m = "No Loop";
2468 break;
2469 case 2:
2470 m = "Failed to allocate IOCB buffer";
2471 break;
2472 case 3:
2473 m = "Failed to allocate XCB buffer";
2474 break;
2475 case 4:
2476 m = "timeout or transmit failed";
2477 break;
2478 case 5:
2479 m = "no fabric loop";
2480 break;
2481 case 6:
2482 m = "remote device not a target";
2483 break;
2484 default:
2485 SNPRINTF(tbuf, sizeof tbuf, "%x",
2486 mbp->param[1]);
2487 m = tbuf;
2488 break;
2489 }
2490 isp_prt(isp, ISP_LOGERR, "SNS Failed- %s", m);
2491 }
2492 return (-1);
2493 }
2494
2495 if (FCPARAM(isp)->isp_fwstate != FW_READY ||
2496 FCPARAM(isp)->isp_loopstate < LOOP_SCANNING_FABRIC) {
2497 return (-1);
2498 }
2499 return(0);
2500}
2501
2502#ifdef ISP_USE_GA_NXT
2503static int
2504isp_scan_fabric(struct ispsoftc *isp, int ftype)
2505{
2506 fcparam *fcp = isp->isp_param;
2507 u_int32_t portid, first_portid, last_portid;
2508 int hicap, last_port_same;
2509
2510 if (fcp->isp_onfabric == 0) {
2511 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2512 return (0);
2513 }
2514
2515 FC_SCRATCH_ACQUIRE(isp);
2516
2517 /*
2518 * Since Port IDs are 24 bits, we can check against having seen
2519 * anything yet with this value.
2520 */
2521 last_port_same = 0;
2522 last_portid = 0xffffffff; /* not a port */
2523 first_portid = portid = fcp->isp_portid;
2524 fcp->isp_loopstate = LOOP_SCANNING_FABRIC;
2525
2526 for (hicap = 0; hicap < GA_NXT_MAX; hicap++) {
2527 mbreg_t mbs;
2528 sns_screq_t *rq;
2529 sns_ga_nxt_rsp_t *rs0, *rs1;
2530 struct lportdb lcl;
2531 u_int8_t sc[SNS_GA_NXT_RESP_SIZE];
2532
2533 rq = (sns_screq_t *)sc;
2534 MEMZERO((void *) rq, SNS_GA_NXT_REQ_SIZE);
2535 rq->snscb_rblen = SNS_GA_NXT_RESP_SIZE >> 1;
2536 rq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma+0x100);
2537 rq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma+0x100);
2538 rq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma+0x100);
2539 rq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma+0x100);
2540 rq->snscb_sblen = 6;
2541 rq->snscb_data[0] = SNS_GA_NXT;
2542 rq->snscb_data[4] = portid & 0xffff;
2543 rq->snscb_data[5] = (portid >> 16) & 0xff;
2544 isp_put_sns_request(isp, rq, (sns_screq_t *) fcp->isp_scratch);
2545 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GA_NXT_REQ_SIZE);
2546 MEMZERO(&mbs, sizeof (mbs));
2491 mbs.param[0] = MBOX_SEND_SNS;
2492 mbs.param[1] = SNS_GA_NXT_REQ_SIZE >> 1;
2493 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2494 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2495 /*
2496 * Leave 4 and 5 alone
2497 */
2498 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2499 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2500 if (isp_fabric_mbox_cmd(isp, &mbs)) {
2501 if (fcp->isp_loopstate >= LOOP_SCANNING_FABRIC) {
2502 fcp->isp_loopstate = LOOP_PDB_RCVD;
2503 }
2504 FC_SCRATCH_RELEASE(isp);
2505 return (-1);
2506 }
2507 MEMORYBARRIER(isp, SYNC_SFORCPU, 0x100, SNS_GA_NXT_RESP_SIZE);
2508 rs1 = (sns_ga_nxt_rsp_t *) sc;
2509 rs0 = (sns_ga_nxt_rsp_t *) ((u_int8_t *)fcp->isp_scratch+0x100);
2510 isp_get_ga_nxt_response(isp, rs0, rs1);
2511 if (rs1->snscb_cthdr.ct_response != FS_ACC) {
2512 int level;
2513 if (rs1->snscb_cthdr.ct_reason == 9 &&
2514 rs1->snscb_cthdr.ct_explanation == 7)
2515 level = ISP_LOGDEBUG0;
2516 else
2517 level = ISP_LOGWARN;
2518 isp_prt(isp, level, swrej, "GA_NXT",
2519 rs1->snscb_cthdr.ct_reason,
2520 rs1->snscb_cthdr.ct_explanation, portid);
2521 FC_SCRATCH_RELEASE(isp);
2522 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2523 return (0);
2524 }
2525 portid =
2526 (((u_int32_t) rs1->snscb_port_id[0]) << 16) |
2527 (((u_int32_t) rs1->snscb_port_id[1]) << 8) |
2528 (((u_int32_t) rs1->snscb_port_id[2]));
2529
2530 /*
2531 * XXX: We should check to make sure that this entry
2532 * XXX: supports the type(s) we are interested in.
2533 */
2534 /*
2535 * Okay, we now have information about a fabric object.
2536 * If it is the type we're interested in, tell the outer layers
2537 * about it. The outer layer needs to know: Port ID, WWNN,
2538 * WWPN, FC4 type, and port type.
2539 *
2540 * The lportdb structure is adequate for this.
2541 */
2542 MEMZERO(&lcl, sizeof (lcl));
2543 lcl.port_type = rs1->snscb_port_type;
2544 lcl.fc4_type = ftype;
2545 lcl.portid = portid;
2546 lcl.node_wwn =
2547 (((u_int64_t)rs1->snscb_nodename[0]) << 56) |
2548 (((u_int64_t)rs1->snscb_nodename[1]) << 48) |
2549 (((u_int64_t)rs1->snscb_nodename[2]) << 40) |
2550 (((u_int64_t)rs1->snscb_nodename[3]) << 32) |
2551 (((u_int64_t)rs1->snscb_nodename[4]) << 24) |
2552 (((u_int64_t)rs1->snscb_nodename[5]) << 16) |
2553 (((u_int64_t)rs1->snscb_nodename[6]) << 8) |
2554 (((u_int64_t)rs1->snscb_nodename[7]));
2555 lcl.port_wwn =
2556 (((u_int64_t)rs1->snscb_portname[0]) << 56) |
2557 (((u_int64_t)rs1->snscb_portname[1]) << 48) |
2558 (((u_int64_t)rs1->snscb_portname[2]) << 40) |
2559 (((u_int64_t)rs1->snscb_portname[3]) << 32) |
2560 (((u_int64_t)rs1->snscb_portname[4]) << 24) |
2561 (((u_int64_t)rs1->snscb_portname[5]) << 16) |
2562 (((u_int64_t)rs1->snscb_portname[6]) << 8) |
2563 (((u_int64_t)rs1->snscb_portname[7]));
2564
2565 /*
2566 * Does this fabric object support the type we want?
2567 * If not, skip it.
2568 */
2569 if (rs1->snscb_fc4_types[ftype >> 5] & (1 << (ftype & 0x1f))) {
2570 if (first_portid == portid) {
2571 lcl.last_fabric_dev = 1;
2572 } else {
2573 lcl.last_fabric_dev = 0;
2574 }
2575 (void) isp_async(isp, ISPASYNC_FABRIC_DEV, &lcl);
2576 } else {
2577 isp_prt(isp, ISP_LOGDEBUG0,
2578 "PortID 0x%x doesn't support FC4 type 0x%x",
2579 portid, ftype);
2580 }
2581 if (first_portid == portid) {
2582 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2583 FC_SCRATCH_RELEASE(isp);
2584 return (0);
2585 }
2586 if (portid == last_portid) {
2587 if (last_port_same++ > 20) {
2588 isp_prt(isp, ISP_LOGWARN,
2589 "tangled fabric database detected");
2590 break;
2591 }
2592 } else {
2593 last_port_same = 0 ;
2594 last_portid = portid;
2595 }
2596 }
2597 FC_SCRATCH_RELEASE(isp);
2598 if (hicap >= GA_NXT_MAX) {
2599 isp_prt(isp, ISP_LOGWARN, "fabric too big (> %d)", GA_NXT_MAX);
2600 }
2601 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2602 return (0);
2603}
2604#else
2605#define GIDLEN ((ISP2100_SCRLEN >> 1) + 16)
2606#define NGENT ((GIDLEN - 16) >> 2)
2607
2608#define IGPOFF (ISP2100_SCRLEN - GIDLEN)
2609#define GXOFF (256)
2610
2611static int
2612isp_scan_fabric(struct ispsoftc *isp, int ftype)
2613{
2614 fcparam *fcp = FCPARAM(isp);
2615 mbreg_t mbs;
2616 int i;
2617 sns_gid_ft_req_t *rq;
2618 sns_gid_ft_rsp_t *rs0, *rs1;
2619
2620 if (fcp->isp_onfabric == 0) {
2621 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2622 return (0);
2623 }
2624
2625 FC_SCRATCH_ACQUIRE(isp);
2626 fcp->isp_loopstate = LOOP_SCANNING_FABRIC;
2627
2628 rq = (sns_gid_ft_req_t *)fcp->tport;
2629 MEMZERO((void *) rq, SNS_GID_FT_REQ_SIZE);
2630 rq->snscb_rblen = GIDLEN >> 1;
2631 rq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma+IGPOFF);
2632 rq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma+IGPOFF);
2633 rq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma+IGPOFF);
2634 rq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma+IGPOFF);
2635 rq->snscb_sblen = 6;
2636 rq->snscb_cmd = SNS_GID_FT;
2637 rq->snscb_mword_div_2 = NGENT;
2638 rq->snscb_fc4_type = ftype;
2639 isp_put_gid_ft_request(isp, rq, (sns_gid_ft_req_t *) fcp->isp_scratch);
2640 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GID_FT_REQ_SIZE);
2547 mbs.param[0] = MBOX_SEND_SNS;
2548 mbs.param[1] = SNS_GA_NXT_REQ_SIZE >> 1;
2549 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2550 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2551 /*
2552 * Leave 4 and 5 alone
2553 */
2554 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2555 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2556 if (isp_fabric_mbox_cmd(isp, &mbs)) {
2557 if (fcp->isp_loopstate >= LOOP_SCANNING_FABRIC) {
2558 fcp->isp_loopstate = LOOP_PDB_RCVD;
2559 }
2560 FC_SCRATCH_RELEASE(isp);
2561 return (-1);
2562 }
2563 MEMORYBARRIER(isp, SYNC_SFORCPU, 0x100, SNS_GA_NXT_RESP_SIZE);
2564 rs1 = (sns_ga_nxt_rsp_t *) sc;
2565 rs0 = (sns_ga_nxt_rsp_t *) ((u_int8_t *)fcp->isp_scratch+0x100);
2566 isp_get_ga_nxt_response(isp, rs0, rs1);
2567 if (rs1->snscb_cthdr.ct_response != FS_ACC) {
2568 int level;
2569 if (rs1->snscb_cthdr.ct_reason == 9 &&
2570 rs1->snscb_cthdr.ct_explanation == 7)
2571 level = ISP_LOGDEBUG0;
2572 else
2573 level = ISP_LOGWARN;
2574 isp_prt(isp, level, swrej, "GA_NXT",
2575 rs1->snscb_cthdr.ct_reason,
2576 rs1->snscb_cthdr.ct_explanation, portid);
2577 FC_SCRATCH_RELEASE(isp);
2578 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2579 return (0);
2580 }
2581 portid =
2582 (((u_int32_t) rs1->snscb_port_id[0]) << 16) |
2583 (((u_int32_t) rs1->snscb_port_id[1]) << 8) |
2584 (((u_int32_t) rs1->snscb_port_id[2]));
2585
2586 /*
2587 * XXX: We should check to make sure that this entry
2588 * XXX: supports the type(s) we are interested in.
2589 */
2590 /*
2591 * Okay, we now have information about a fabric object.
2592 * If it is the type we're interested in, tell the outer layers
2593 * about it. The outer layer needs to know: Port ID, WWNN,
2594 * WWPN, FC4 type, and port type.
2595 *
2596 * The lportdb structure is adequate for this.
2597 */
2598 MEMZERO(&lcl, sizeof (lcl));
2599 lcl.port_type = rs1->snscb_port_type;
2600 lcl.fc4_type = ftype;
2601 lcl.portid = portid;
2602 lcl.node_wwn =
2603 (((u_int64_t)rs1->snscb_nodename[0]) << 56) |
2604 (((u_int64_t)rs1->snscb_nodename[1]) << 48) |
2605 (((u_int64_t)rs1->snscb_nodename[2]) << 40) |
2606 (((u_int64_t)rs1->snscb_nodename[3]) << 32) |
2607 (((u_int64_t)rs1->snscb_nodename[4]) << 24) |
2608 (((u_int64_t)rs1->snscb_nodename[5]) << 16) |
2609 (((u_int64_t)rs1->snscb_nodename[6]) << 8) |
2610 (((u_int64_t)rs1->snscb_nodename[7]));
2611 lcl.port_wwn =
2612 (((u_int64_t)rs1->snscb_portname[0]) << 56) |
2613 (((u_int64_t)rs1->snscb_portname[1]) << 48) |
2614 (((u_int64_t)rs1->snscb_portname[2]) << 40) |
2615 (((u_int64_t)rs1->snscb_portname[3]) << 32) |
2616 (((u_int64_t)rs1->snscb_portname[4]) << 24) |
2617 (((u_int64_t)rs1->snscb_portname[5]) << 16) |
2618 (((u_int64_t)rs1->snscb_portname[6]) << 8) |
2619 (((u_int64_t)rs1->snscb_portname[7]));
2620
2621 /*
2622 * Does this fabric object support the type we want?
2623 * If not, skip it.
2624 */
2625 if (rs1->snscb_fc4_types[ftype >> 5] & (1 << (ftype & 0x1f))) {
2626 if (first_portid == portid) {
2627 lcl.last_fabric_dev = 1;
2628 } else {
2629 lcl.last_fabric_dev = 0;
2630 }
2631 (void) isp_async(isp, ISPASYNC_FABRIC_DEV, &lcl);
2632 } else {
2633 isp_prt(isp, ISP_LOGDEBUG0,
2634 "PortID 0x%x doesn't support FC4 type 0x%x",
2635 portid, ftype);
2636 }
2637 if (first_portid == portid) {
2638 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2639 FC_SCRATCH_RELEASE(isp);
2640 return (0);
2641 }
2642 if (portid == last_portid) {
2643 if (last_port_same++ > 20) {
2644 isp_prt(isp, ISP_LOGWARN,
2645 "tangled fabric database detected");
2646 break;
2647 }
2648 } else {
2649 last_port_same = 0 ;
2650 last_portid = portid;
2651 }
2652 }
2653 FC_SCRATCH_RELEASE(isp);
2654 if (hicap >= GA_NXT_MAX) {
2655 isp_prt(isp, ISP_LOGWARN, "fabric too big (> %d)", GA_NXT_MAX);
2656 }
2657 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2658 return (0);
2659}
2660#else
2661#define GIDLEN ((ISP2100_SCRLEN >> 1) + 16)
2662#define NGENT ((GIDLEN - 16) >> 2)
2663
2664#define IGPOFF (ISP2100_SCRLEN - GIDLEN)
2665#define GXOFF (256)
2666
2667static int
2668isp_scan_fabric(struct ispsoftc *isp, int ftype)
2669{
2670 fcparam *fcp = FCPARAM(isp);
2671 mbreg_t mbs;
2672 int i;
2673 sns_gid_ft_req_t *rq;
2674 sns_gid_ft_rsp_t *rs0, *rs1;
2675
2676 if (fcp->isp_onfabric == 0) {
2677 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2678 return (0);
2679 }
2680
2681 FC_SCRATCH_ACQUIRE(isp);
2682 fcp->isp_loopstate = LOOP_SCANNING_FABRIC;
2683
2684 rq = (sns_gid_ft_req_t *)fcp->tport;
2685 MEMZERO((void *) rq, SNS_GID_FT_REQ_SIZE);
2686 rq->snscb_rblen = GIDLEN >> 1;
2687 rq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma+IGPOFF);
2688 rq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma+IGPOFF);
2689 rq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma+IGPOFF);
2690 rq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma+IGPOFF);
2691 rq->snscb_sblen = 6;
2692 rq->snscb_cmd = SNS_GID_FT;
2693 rq->snscb_mword_div_2 = NGENT;
2694 rq->snscb_fc4_type = ftype;
2695 isp_put_gid_ft_request(isp, rq, (sns_gid_ft_req_t *) fcp->isp_scratch);
2696 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GID_FT_REQ_SIZE);
2697 MEMZERO(&mbs, sizeof (mbs));
2641 mbs.param[0] = MBOX_SEND_SNS;
2642 mbs.param[1] = SNS_GID_FT_REQ_SIZE >> 1;
2643 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2644 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2645
2646 /*
2647 * Leave 4 and 5 alone
2648 */
2649 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2650 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2651 if (isp_fabric_mbox_cmd(isp, &mbs)) {
2652 if (fcp->isp_loopstate >= LOOP_SCANNING_FABRIC) {
2653 fcp->isp_loopstate = LOOP_PDB_RCVD;
2654 }
2655 FC_SCRATCH_RELEASE(isp);
2656 return (-1);
2657 }
2658 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2659 FC_SCRATCH_RELEASE(isp);
2660 return (-1);
2661 }
2662 MEMORYBARRIER(isp, SYNC_SFORCPU, IGPOFF, GIDLEN);
2663 rs1 = (sns_gid_ft_rsp_t *) fcp->tport;
2664 rs0 = (sns_gid_ft_rsp_t *) ((u_int8_t *)fcp->isp_scratch+IGPOFF);
2665 isp_get_gid_ft_response(isp, rs0, rs1, NGENT);
2666 if (rs1->snscb_cthdr.ct_response != FS_ACC) {
2667 int level;
2668 if (rs1->snscb_cthdr.ct_reason == 9 &&
2669 rs1->snscb_cthdr.ct_explanation == 7)
2670 level = ISP_LOGDEBUG0;
2671 else
2672 level = ISP_LOGWARN;
2673 isp_prt(isp, level, swrej, "GID_FT",
2674 rs1->snscb_cthdr.ct_reason,
2675 rs1->snscb_cthdr.ct_explanation, 0);
2676 FC_SCRATCH_RELEASE(isp);
2677 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2678 return (0);
2679 }
2680
2681 /*
2682 * Okay, we now have a list of Port IDs for this class of device.
2683 * Go through the list and for each one get the WWPN/WWNN for it
2684 * and tell the outer layers about it. The outer layer needs to
2685 * know: Port ID, WWNN, WWPN, FC4 type, and (possibly) port type.
2686 *
2687 * The lportdb structure is adequate for this.
2688 */
2689 i = -1;
2690 do {
2691 sns_gxn_id_req_t grqbuf, *gq = &grqbuf;
2692 sns_gxn_id_rsp_t *gs0, grsbuf, *gs1 = &grsbuf;
2693 struct lportdb lcl;
2694#if 0
2695 sns_gff_id_rsp_t *fs0, ffsbuf, *fs1 = &ffsbuf;
2696#endif
2697
2698 i++;
2699 MEMZERO(&lcl, sizeof (lcl));
2700 lcl.fc4_type = ftype;
2701 lcl.portid =
2702 (((u_int32_t) rs1->snscb_ports[i].portid[0]) << 16) |
2703 (((u_int32_t) rs1->snscb_ports[i].portid[1]) << 8) |
2704 (((u_int32_t) rs1->snscb_ports[i].portid[2]));
2705
2706 MEMZERO((void *) gq, sizeof (sns_gxn_id_req_t));
2707 gq->snscb_rblen = SNS_GXN_ID_RESP_SIZE >> 1;
2708 gq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma+GXOFF);
2709 gq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma+GXOFF);
2710 gq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma+GXOFF);
2711 gq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma+GXOFF);
2712 gq->snscb_sblen = 6;
2713 gq->snscb_cmd = SNS_GPN_ID;
2714 gq->snscb_portid = lcl.portid;
2715 isp_put_gxn_id_request(isp, gq,
2716 (sns_gxn_id_req_t *) fcp->isp_scratch);
2717 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GXN_ID_REQ_SIZE);
2698 mbs.param[0] = MBOX_SEND_SNS;
2699 mbs.param[1] = SNS_GID_FT_REQ_SIZE >> 1;
2700 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2701 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2702
2703 /*
2704 * Leave 4 and 5 alone
2705 */
2706 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2707 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2708 if (isp_fabric_mbox_cmd(isp, &mbs)) {
2709 if (fcp->isp_loopstate >= LOOP_SCANNING_FABRIC) {
2710 fcp->isp_loopstate = LOOP_PDB_RCVD;
2711 }
2712 FC_SCRATCH_RELEASE(isp);
2713 return (-1);
2714 }
2715 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2716 FC_SCRATCH_RELEASE(isp);
2717 return (-1);
2718 }
2719 MEMORYBARRIER(isp, SYNC_SFORCPU, IGPOFF, GIDLEN);
2720 rs1 = (sns_gid_ft_rsp_t *) fcp->tport;
2721 rs0 = (sns_gid_ft_rsp_t *) ((u_int8_t *)fcp->isp_scratch+IGPOFF);
2722 isp_get_gid_ft_response(isp, rs0, rs1, NGENT);
2723 if (rs1->snscb_cthdr.ct_response != FS_ACC) {
2724 int level;
2725 if (rs1->snscb_cthdr.ct_reason == 9 &&
2726 rs1->snscb_cthdr.ct_explanation == 7)
2727 level = ISP_LOGDEBUG0;
2728 else
2729 level = ISP_LOGWARN;
2730 isp_prt(isp, level, swrej, "GID_FT",
2731 rs1->snscb_cthdr.ct_reason,
2732 rs1->snscb_cthdr.ct_explanation, 0);
2733 FC_SCRATCH_RELEASE(isp);
2734 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2735 return (0);
2736 }
2737
2738 /*
2739 * Okay, we now have a list of Port IDs for this class of device.
2740 * Go through the list and for each one get the WWPN/WWNN for it
2741 * and tell the outer layers about it. The outer layer needs to
2742 * know: Port ID, WWNN, WWPN, FC4 type, and (possibly) port type.
2743 *
2744 * The lportdb structure is adequate for this.
2745 */
2746 i = -1;
2747 do {
2748 sns_gxn_id_req_t grqbuf, *gq = &grqbuf;
2749 sns_gxn_id_rsp_t *gs0, grsbuf, *gs1 = &grsbuf;
2750 struct lportdb lcl;
2751#if 0
2752 sns_gff_id_rsp_t *fs0, ffsbuf, *fs1 = &ffsbuf;
2753#endif
2754
2755 i++;
2756 MEMZERO(&lcl, sizeof (lcl));
2757 lcl.fc4_type = ftype;
2758 lcl.portid =
2759 (((u_int32_t) rs1->snscb_ports[i].portid[0]) << 16) |
2760 (((u_int32_t) rs1->snscb_ports[i].portid[1]) << 8) |
2761 (((u_int32_t) rs1->snscb_ports[i].portid[2]));
2762
2763 MEMZERO((void *) gq, sizeof (sns_gxn_id_req_t));
2764 gq->snscb_rblen = SNS_GXN_ID_RESP_SIZE >> 1;
2765 gq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma+GXOFF);
2766 gq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma+GXOFF);
2767 gq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma+GXOFF);
2768 gq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma+GXOFF);
2769 gq->snscb_sblen = 6;
2770 gq->snscb_cmd = SNS_GPN_ID;
2771 gq->snscb_portid = lcl.portid;
2772 isp_put_gxn_id_request(isp, gq,
2773 (sns_gxn_id_req_t *) fcp->isp_scratch);
2774 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GXN_ID_REQ_SIZE);
2775 MEMZERO(&mbs, sizeof (mbs));
2718 mbs.param[0] = MBOX_SEND_SNS;
2719 mbs.param[1] = SNS_GXN_ID_REQ_SIZE >> 1;
2720 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2721 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2722 /*
2723 * Leave 4 and 5 alone
2724 */
2725 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2726 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2727 if (isp_fabric_mbox_cmd(isp, &mbs)) {
2728 if (fcp->isp_loopstate >= LOOP_SCANNING_FABRIC) {
2729 fcp->isp_loopstate = LOOP_PDB_RCVD;
2730 }
2731 FC_SCRATCH_RELEASE(isp);
2732 return (-1);
2733 }
2734 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2735 FC_SCRATCH_RELEASE(isp);
2736 return (-1);
2737 }
2738 MEMORYBARRIER(isp, SYNC_SFORCPU, GXOFF, SNS_GXN_ID_RESP_SIZE);
2739 gs0 = (sns_gxn_id_rsp_t *) ((u_int8_t *)fcp->isp_scratch+GXOFF);
2740 isp_get_gxn_id_response(isp, gs0, gs1);
2741 if (gs1->snscb_cthdr.ct_response != FS_ACC) {
2742 isp_prt(isp, ISP_LOGWARN, swrej, "GPN_ID",
2743 gs1->snscb_cthdr.ct_reason,
2744 gs1->snscb_cthdr.ct_explanation, lcl.portid);
2745 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2746 FC_SCRATCH_RELEASE(isp);
2747 return (-1);
2748 }
2749 continue;
2750 }
2751 lcl.port_wwn =
2752 (((u_int64_t)gs1->snscb_wwn[0]) << 56) |
2753 (((u_int64_t)gs1->snscb_wwn[1]) << 48) |
2754 (((u_int64_t)gs1->snscb_wwn[2]) << 40) |
2755 (((u_int64_t)gs1->snscb_wwn[3]) << 32) |
2756 (((u_int64_t)gs1->snscb_wwn[4]) << 24) |
2757 (((u_int64_t)gs1->snscb_wwn[5]) << 16) |
2758 (((u_int64_t)gs1->snscb_wwn[6]) << 8) |
2759 (((u_int64_t)gs1->snscb_wwn[7]));
2760
2761 MEMZERO((void *) gq, sizeof (sns_gxn_id_req_t));
2762 gq->snscb_rblen = SNS_GXN_ID_RESP_SIZE >> 1;
2763 gq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma+GXOFF);
2764 gq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma+GXOFF);
2765 gq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma+GXOFF);
2766 gq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma+GXOFF);
2767 gq->snscb_sblen = 6;
2768 gq->snscb_cmd = SNS_GNN_ID;
2769 gq->snscb_portid = lcl.portid;
2770 isp_put_gxn_id_request(isp, gq,
2771 (sns_gxn_id_req_t *) fcp->isp_scratch);
2772 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GXN_ID_REQ_SIZE);
2776 mbs.param[0] = MBOX_SEND_SNS;
2777 mbs.param[1] = SNS_GXN_ID_REQ_SIZE >> 1;
2778 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2779 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2780 /*
2781 * Leave 4 and 5 alone
2782 */
2783 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2784 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2785 if (isp_fabric_mbox_cmd(isp, &mbs)) {
2786 if (fcp->isp_loopstate >= LOOP_SCANNING_FABRIC) {
2787 fcp->isp_loopstate = LOOP_PDB_RCVD;
2788 }
2789 FC_SCRATCH_RELEASE(isp);
2790 return (-1);
2791 }
2792 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2793 FC_SCRATCH_RELEASE(isp);
2794 return (-1);
2795 }
2796 MEMORYBARRIER(isp, SYNC_SFORCPU, GXOFF, SNS_GXN_ID_RESP_SIZE);
2797 gs0 = (sns_gxn_id_rsp_t *) ((u_int8_t *)fcp->isp_scratch+GXOFF);
2798 isp_get_gxn_id_response(isp, gs0, gs1);
2799 if (gs1->snscb_cthdr.ct_response != FS_ACC) {
2800 isp_prt(isp, ISP_LOGWARN, swrej, "GPN_ID",
2801 gs1->snscb_cthdr.ct_reason,
2802 gs1->snscb_cthdr.ct_explanation, lcl.portid);
2803 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2804 FC_SCRATCH_RELEASE(isp);
2805 return (-1);
2806 }
2807 continue;
2808 }
2809 lcl.port_wwn =
2810 (((u_int64_t)gs1->snscb_wwn[0]) << 56) |
2811 (((u_int64_t)gs1->snscb_wwn[1]) << 48) |
2812 (((u_int64_t)gs1->snscb_wwn[2]) << 40) |
2813 (((u_int64_t)gs1->snscb_wwn[3]) << 32) |
2814 (((u_int64_t)gs1->snscb_wwn[4]) << 24) |
2815 (((u_int64_t)gs1->snscb_wwn[5]) << 16) |
2816 (((u_int64_t)gs1->snscb_wwn[6]) << 8) |
2817 (((u_int64_t)gs1->snscb_wwn[7]));
2818
2819 MEMZERO((void *) gq, sizeof (sns_gxn_id_req_t));
2820 gq->snscb_rblen = SNS_GXN_ID_RESP_SIZE >> 1;
2821 gq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma+GXOFF);
2822 gq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma+GXOFF);
2823 gq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma+GXOFF);
2824 gq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma+GXOFF);
2825 gq->snscb_sblen = 6;
2826 gq->snscb_cmd = SNS_GNN_ID;
2827 gq->snscb_portid = lcl.portid;
2828 isp_put_gxn_id_request(isp, gq,
2829 (sns_gxn_id_req_t *) fcp->isp_scratch);
2830 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GXN_ID_REQ_SIZE);
2831 MEMZERO(&mbs, sizeof (mbs));
2773 mbs.param[0] = MBOX_SEND_SNS;
2774 mbs.param[1] = SNS_GXN_ID_REQ_SIZE >> 1;
2775 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2776 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2777 /*
2778 * Leave 4 and 5 alone
2779 */
2780 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2781 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2782 if (isp_fabric_mbox_cmd(isp, &mbs)) {
2783 if (fcp->isp_loopstate >= LOOP_SCANNING_FABRIC) {
2784 fcp->isp_loopstate = LOOP_PDB_RCVD;
2785 }
2786 FC_SCRATCH_RELEASE(isp);
2787 return (-1);
2788 }
2789 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2790 FC_SCRATCH_RELEASE(isp);
2791 return (-1);
2792 }
2793 MEMORYBARRIER(isp, SYNC_SFORCPU, GXOFF, SNS_GXN_ID_RESP_SIZE);
2794 gs0 = (sns_gxn_id_rsp_t *) ((u_int8_t *)fcp->isp_scratch+GXOFF);
2795 isp_get_gxn_id_response(isp, gs0, gs1);
2796 if (gs1->snscb_cthdr.ct_response != FS_ACC) {
2797 isp_prt(isp, ISP_LOGWARN, swrej, "GNN_ID",
2798 gs1->snscb_cthdr.ct_reason,
2799 gs1->snscb_cthdr.ct_explanation, lcl.portid);
2800 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2801 FC_SCRATCH_RELEASE(isp);
2802 return (-1);
2803 }
2804 continue;
2805 }
2806 lcl.node_wwn =
2807 (((u_int64_t)gs1->snscb_wwn[0]) << 56) |
2808 (((u_int64_t)gs1->snscb_wwn[1]) << 48) |
2809 (((u_int64_t)gs1->snscb_wwn[2]) << 40) |
2810 (((u_int64_t)gs1->snscb_wwn[3]) << 32) |
2811 (((u_int64_t)gs1->snscb_wwn[4]) << 24) |
2812 (((u_int64_t)gs1->snscb_wwn[5]) << 16) |
2813 (((u_int64_t)gs1->snscb_wwn[6]) << 8) |
2814 (((u_int64_t)gs1->snscb_wwn[7]));
2815
2816 /*
2817 * The QLogic f/w is bouncing this with a parameter error.
2818 */
2819#if 0
2820 /*
2821 * Try and get FC4 Features (FC-GS-3 only).
2822 * We can use the sns_gxn_id_req_t for this request.
2823 */
2824 MEMZERO((void *) gq, sizeof (sns_gxn_id_req_t));
2825 gq->snscb_rblen = SNS_GFF_ID_RESP_SIZE >> 1;
2826 gq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma+GXOFF);
2827 gq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma+GXOFF);
2828 gq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma+GXOFF);
2829 gq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma+GXOFF);
2830 gq->snscb_sblen = 6;
2831 gq->snscb_cmd = SNS_GFF_ID;
2832 gq->snscb_portid = lcl.portid;
2833 isp_put_gxn_id_request(isp, gq,
2834 (sns_gxn_id_req_t *) fcp->isp_scratch);
2835 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GXN_ID_REQ_SIZE);
2832 mbs.param[0] = MBOX_SEND_SNS;
2833 mbs.param[1] = SNS_GXN_ID_REQ_SIZE >> 1;
2834 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2835 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2836 /*
2837 * Leave 4 and 5 alone
2838 */
2839 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2840 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2841 if (isp_fabric_mbox_cmd(isp, &mbs)) {
2842 if (fcp->isp_loopstate >= LOOP_SCANNING_FABRIC) {
2843 fcp->isp_loopstate = LOOP_PDB_RCVD;
2844 }
2845 FC_SCRATCH_RELEASE(isp);
2846 return (-1);
2847 }
2848 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2849 FC_SCRATCH_RELEASE(isp);
2850 return (-1);
2851 }
2852 MEMORYBARRIER(isp, SYNC_SFORCPU, GXOFF, SNS_GXN_ID_RESP_SIZE);
2853 gs0 = (sns_gxn_id_rsp_t *) ((u_int8_t *)fcp->isp_scratch+GXOFF);
2854 isp_get_gxn_id_response(isp, gs0, gs1);
2855 if (gs1->snscb_cthdr.ct_response != FS_ACC) {
2856 isp_prt(isp, ISP_LOGWARN, swrej, "GNN_ID",
2857 gs1->snscb_cthdr.ct_reason,
2858 gs1->snscb_cthdr.ct_explanation, lcl.portid);
2859 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2860 FC_SCRATCH_RELEASE(isp);
2861 return (-1);
2862 }
2863 continue;
2864 }
2865 lcl.node_wwn =
2866 (((u_int64_t)gs1->snscb_wwn[0]) << 56) |
2867 (((u_int64_t)gs1->snscb_wwn[1]) << 48) |
2868 (((u_int64_t)gs1->snscb_wwn[2]) << 40) |
2869 (((u_int64_t)gs1->snscb_wwn[3]) << 32) |
2870 (((u_int64_t)gs1->snscb_wwn[4]) << 24) |
2871 (((u_int64_t)gs1->snscb_wwn[5]) << 16) |
2872 (((u_int64_t)gs1->snscb_wwn[6]) << 8) |
2873 (((u_int64_t)gs1->snscb_wwn[7]));
2874
2875 /*
2876 * The QLogic f/w is bouncing this with a parameter error.
2877 */
2878#if 0
2879 /*
2880 * Try and get FC4 Features (FC-GS-3 only).
2881 * We can use the sns_gxn_id_req_t for this request.
2882 */
2883 MEMZERO((void *) gq, sizeof (sns_gxn_id_req_t));
2884 gq->snscb_rblen = SNS_GFF_ID_RESP_SIZE >> 1;
2885 gq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma+GXOFF);
2886 gq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma+GXOFF);
2887 gq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma+GXOFF);
2888 gq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma+GXOFF);
2889 gq->snscb_sblen = 6;
2890 gq->snscb_cmd = SNS_GFF_ID;
2891 gq->snscb_portid = lcl.portid;
2892 isp_put_gxn_id_request(isp, gq,
2893 (sns_gxn_id_req_t *) fcp->isp_scratch);
2894 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GXN_ID_REQ_SIZE);
2895 MEMZERO(&mbs, sizeof (mbs));
2836 mbs.param[0] = MBOX_SEND_SNS;
2837 mbs.param[1] = SNS_GXN_ID_REQ_SIZE >> 1;
2838 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2839 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2840 /*
2841 * Leave 4 and 5 alone
2842 */
2843 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2844 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2845 if (isp_fabric_mbox_cmd(isp, &mbs)) {
2846 if (fcp->isp_loopstate >= LOOP_SCANNING_FABRIC) {
2847 fcp->isp_loopstate = LOOP_PDB_RCVD;
2848 }
2849 FC_SCRATCH_RELEASE(isp);
2850 return (-1);
2851 }
2852 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2853 FC_SCRATCH_RELEASE(isp);
2854 return (-1);
2855 }
2856 MEMORYBARRIER(isp, SYNC_SFORCPU, GXOFF, SNS_GFF_ID_RESP_SIZE);
2857 fs0 = (sns_gff_id_rsp_t *) ((u_int8_t *)fcp->isp_scratch+GXOFF);
2858 isp_get_gff_id_response(isp, fs0, fs1);
2859 if (fs1->snscb_cthdr.ct_response != FS_ACC) {
2860 isp_prt(isp, /* ISP_LOGDEBUG0 */ ISP_LOGWARN,
2861 swrej, "GFF_ID",
2862 fs1->snscb_cthdr.ct_reason,
2863 fs1->snscb_cthdr.ct_explanation, lcl.portid);
2864 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2865 FC_SCRATCH_RELEASE(isp);
2866 return (-1);
2867 }
2868 } else {
2869 int index = (ftype >> 3);
2870 int bshft = (ftype & 0x7) * 4;
2871 int fc4_fval =
2872 (fs1->snscb_fc4_features[index] >> bshft) & 0xf;
2873 if (fc4_fval & 0x1) {
2874 lcl.roles |=
2875 (SVC3_INI_ROLE >> SVC3_ROLE_SHIFT);
2876 }
2877 if (fc4_fval & 0x2) {
2878 lcl.roles |=
2879 (SVC3_TGT_ROLE >> SVC3_ROLE_SHIFT);
2880 }
2881 }
2882#endif
2883
2884 /*
2885 * If we really want to know what kind of port type this is,
2886 * we have to run another CT command. Otherwise, we'll leave
2887 * it as undefined.
2888 *
2889 lcl.port_type = 0;
2890 */
2891 if (rs1->snscb_ports[i].control & 0x80) {
2892 lcl.last_fabric_dev = 1;
2893 } else {
2894 lcl.last_fabric_dev = 0;
2895 }
2896 (void) isp_async(isp, ISPASYNC_FABRIC_DEV, &lcl);
2897
2898 } while ((rs1->snscb_ports[i].control & 0x80) == 0 && i < NGENT-1);
2899
2900 /*
2901 * If we're not at the last entry, our list isn't big enough.
2902 */
2903 if ((rs1->snscb_ports[i].control & 0x80) == 0) {
2904 isp_prt(isp, ISP_LOGWARN, "fabric too big for scratch area");
2905 }
2906
2907 FC_SCRATCH_RELEASE(isp);
2908 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2909 return (0);
2910}
2911#endif
2912
2913static void
2914isp_register_fc4_type(struct ispsoftc *isp)
2915{
2916 fcparam *fcp = isp->isp_param;
2917 u_int8_t local[SNS_RFT_ID_REQ_SIZE];
2918 sns_screq_t *reqp = (sns_screq_t *) local;
2919 mbreg_t mbs;
2920
2921 MEMZERO((void *) reqp, SNS_RFT_ID_REQ_SIZE);
2922 reqp->snscb_rblen = SNS_RFT_ID_RESP_SIZE >> 1;
2923 reqp->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma + 0x100);
2924 reqp->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma + 0x100);
2925 reqp->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma + 0x100);
2926 reqp->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma + 0x100);
2927 reqp->snscb_sblen = 22;
2928 reqp->snscb_data[0] = SNS_RFT_ID;
2929 reqp->snscb_data[4] = fcp->isp_portid & 0xffff;
2930 reqp->snscb_data[5] = (fcp->isp_portid >> 16) & 0xff;
2931 reqp->snscb_data[6] = (1 << FC4_SCSI);
2932#if 0
2933 reqp->snscb_data[6] |= (1 << FC4_IP); /* ISO/IEC 8802-2 LLC/SNAP */
2934#endif
2935 FC_SCRATCH_ACQUIRE(isp);
2936 isp_put_sns_request(isp, reqp, (sns_screq_t *) fcp->isp_scratch);
2896 mbs.param[0] = MBOX_SEND_SNS;
2897 mbs.param[1] = SNS_GXN_ID_REQ_SIZE >> 1;
2898 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2899 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2900 /*
2901 * Leave 4 and 5 alone
2902 */
2903 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2904 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2905 if (isp_fabric_mbox_cmd(isp, &mbs)) {
2906 if (fcp->isp_loopstate >= LOOP_SCANNING_FABRIC) {
2907 fcp->isp_loopstate = LOOP_PDB_RCVD;
2908 }
2909 FC_SCRATCH_RELEASE(isp);
2910 return (-1);
2911 }
2912 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2913 FC_SCRATCH_RELEASE(isp);
2914 return (-1);
2915 }
2916 MEMORYBARRIER(isp, SYNC_SFORCPU, GXOFF, SNS_GFF_ID_RESP_SIZE);
2917 fs0 = (sns_gff_id_rsp_t *) ((u_int8_t *)fcp->isp_scratch+GXOFF);
2918 isp_get_gff_id_response(isp, fs0, fs1);
2919 if (fs1->snscb_cthdr.ct_response != FS_ACC) {
2920 isp_prt(isp, /* ISP_LOGDEBUG0 */ ISP_LOGWARN,
2921 swrej, "GFF_ID",
2922 fs1->snscb_cthdr.ct_reason,
2923 fs1->snscb_cthdr.ct_explanation, lcl.portid);
2924 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2925 FC_SCRATCH_RELEASE(isp);
2926 return (-1);
2927 }
2928 } else {
2929 int index = (ftype >> 3);
2930 int bshft = (ftype & 0x7) * 4;
2931 int fc4_fval =
2932 (fs1->snscb_fc4_features[index] >> bshft) & 0xf;
2933 if (fc4_fval & 0x1) {
2934 lcl.roles |=
2935 (SVC3_INI_ROLE >> SVC3_ROLE_SHIFT);
2936 }
2937 if (fc4_fval & 0x2) {
2938 lcl.roles |=
2939 (SVC3_TGT_ROLE >> SVC3_ROLE_SHIFT);
2940 }
2941 }
2942#endif
2943
2944 /*
2945 * If we really want to know what kind of port type this is,
2946 * we have to run another CT command. Otherwise, we'll leave
2947 * it as undefined.
2948 *
2949 lcl.port_type = 0;
2950 */
2951 if (rs1->snscb_ports[i].control & 0x80) {
2952 lcl.last_fabric_dev = 1;
2953 } else {
2954 lcl.last_fabric_dev = 0;
2955 }
2956 (void) isp_async(isp, ISPASYNC_FABRIC_DEV, &lcl);
2957
2958 } while ((rs1->snscb_ports[i].control & 0x80) == 0 && i < NGENT-1);
2959
2960 /*
2961 * If we're not at the last entry, our list isn't big enough.
2962 */
2963 if ((rs1->snscb_ports[i].control & 0x80) == 0) {
2964 isp_prt(isp, ISP_LOGWARN, "fabric too big for scratch area");
2965 }
2966
2967 FC_SCRATCH_RELEASE(isp);
2968 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2969 return (0);
2970}
2971#endif
2972
2973static void
2974isp_register_fc4_type(struct ispsoftc *isp)
2975{
2976 fcparam *fcp = isp->isp_param;
2977 u_int8_t local[SNS_RFT_ID_REQ_SIZE];
2978 sns_screq_t *reqp = (sns_screq_t *) local;
2979 mbreg_t mbs;
2980
2981 MEMZERO((void *) reqp, SNS_RFT_ID_REQ_SIZE);
2982 reqp->snscb_rblen = SNS_RFT_ID_RESP_SIZE >> 1;
2983 reqp->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma + 0x100);
2984 reqp->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma + 0x100);
2985 reqp->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma + 0x100);
2986 reqp->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma + 0x100);
2987 reqp->snscb_sblen = 22;
2988 reqp->snscb_data[0] = SNS_RFT_ID;
2989 reqp->snscb_data[4] = fcp->isp_portid & 0xffff;
2990 reqp->snscb_data[5] = (fcp->isp_portid >> 16) & 0xff;
2991 reqp->snscb_data[6] = (1 << FC4_SCSI);
2992#if 0
2993 reqp->snscb_data[6] |= (1 << FC4_IP); /* ISO/IEC 8802-2 LLC/SNAP */
2994#endif
2995 FC_SCRATCH_ACQUIRE(isp);
2996 isp_put_sns_request(isp, reqp, (sns_screq_t *) fcp->isp_scratch);
2997 MEMZERO(&mbs, sizeof (mbs));
2937 mbs.param[0] = MBOX_SEND_SNS;
2938 mbs.param[1] = SNS_RFT_ID_REQ_SIZE >> 1;
2939 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2940 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2941 /*
2942 * Leave 4 and 5 alone
2943 */
2944 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2945 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2946 isp_mboxcmd(isp, &mbs, MBLOGALL);
2947 FC_SCRATCH_RELEASE(isp);
2948 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
2949 isp_prt(isp, ISP_LOGDEBUG0, "Register FC4 types succeeded");
2950 }
2951}
2952
2953/*
2954 * Start a command. Locking is assumed done in the caller.
2955 */
2956
2957int
2958isp_start(XS_T *xs)
2959{
2960 struct ispsoftc *isp;
2961 u_int16_t nxti, optr, handle;
2962 u_int8_t local[QENTRY_LEN];
2963 ispreq_t *reqp, *qep;
2964 int target, i;
2965
2966 XS_INITERR(xs);
2967 isp = XS_ISP(xs);
2968
2969 /*
2970 * Check to make sure we're supporting initiator role.
2971 */
2972 if ((isp->isp_role & ISP_ROLE_INITIATOR) == 0) {
2973 XS_SETERR(xs, HBA_SELTIMEOUT);
2974 return (CMD_COMPLETE);
2975 }
2976
2977 /*
2978 * Now make sure we're running.
2979 */
2980
2981 if (isp->isp_state != ISP_RUNSTATE) {
2982 isp_prt(isp, ISP_LOGERR, "Adapter not at RUNSTATE");
2983 XS_SETERR(xs, HBA_BOTCH);
2984 return (CMD_COMPLETE);
2985 }
2986
2987 /*
2988 * Check command CDB length, etc.. We really are limited to 16 bytes
2989 * for Fibre Channel, but can do up to 44 bytes in parallel SCSI,
2990 * but probably only if we're running fairly new firmware (we'll
2991 * let the old f/w choke on an extended command queue entry).
2992 */
2993
2994 if (XS_CDBLEN(xs) > (IS_FC(isp)? 16 : 44) || XS_CDBLEN(xs) == 0) {
2995 isp_prt(isp, ISP_LOGERR,
2996 "unsupported cdb length (%d, CDB[0]=0x%x)",
2997 XS_CDBLEN(xs), XS_CDBP(xs)[0] & 0xff);
2998 XS_SETERR(xs, HBA_BOTCH);
2999 return (CMD_COMPLETE);
3000 }
3001
3002 /*
3003 * Check to see whether we have good firmware state still or
3004 * need to refresh our port database for this target.
3005 */
3006 target = XS_TGT(xs);
3007 if (IS_FC(isp)) {
3008 fcparam *fcp = isp->isp_param;
3009 struct lportdb *lp;
3010#ifdef HANDLE_LOOPSTATE_IN_OUTER_LAYERS
3011 if (fcp->isp_fwstate != FW_READY ||
3012 fcp->isp_loopstate != LOOP_READY) {
3013 return (CMD_RQLATER);
3014 }
3015
3016 /*
3017 * If we're not on a Fabric, we can't have a target
3018 * above FL_PORT_ID-1.
3019 *
3020 * If we're on a fabric and *not* connected as an F-port,
3021 * we can't have a target less than FC_SNS_ID+1. This
3022 * keeps us from having to sort out the difference between
3023 * local public loop devices and those which we might get
3024 * from a switch's database.
3025 */
3026 if (fcp->isp_onfabric == 0) {
3027 if (target >= FL_PORT_ID) {
3028 XS_SETERR(xs, HBA_SELTIMEOUT);
3029 return (CMD_COMPLETE);
3030 }
3031 } else {
3032 if (target >= FL_PORT_ID && target <= FC_SNS_ID) {
3033 XS_SETERR(xs, HBA_SELTIMEOUT);
3034 return (CMD_COMPLETE);
3035 }
3036 /*
3037 * We used to exclude having local loop ports
3038 * at the same time that we have fabric ports.
3039 * That is, we used to exclude having ports
3040 * at < FL_PORT_ID if we're FL-port.
3041 *
3042 * That's wrong. The only thing that could be
3043 * dicey is if the switch you're connected to
3044 * has these local loop ports appear on the
3045 * fabric and we somehow attach them twice.
3046 */
3047 }
3048#else
3049 /*
3050 * Check for f/w being in ready state. If the f/w
3051 * isn't in ready state, then we don't know our
3052 * loop ID and the f/w hasn't completed logging
3053 * into all targets on the loop. If this is the
3054 * case, then bounce the command. We pretend this is
3055 * a SELECTION TIMEOUT error if we've never gone to
3056 * FW_READY state at all- in this case we may not
3057 * be hooked to a loop at all and we shouldn't hang
3058 * the machine for this. Otherwise, defer this command
3059 * until later.
3060 */
3061 if (fcp->isp_fwstate != FW_READY) {
3062 /*
3063 * Give ourselves at most a 250ms delay.
3064 */
3065 if (isp_fclink_test(isp, 250000)) {
3066 XS_SETERR(xs, HBA_SELTIMEOUT);
3067 if (fcp->loop_seen_once) {
3068 return (CMD_RQLATER);
3069 } else {
3070 return (CMD_COMPLETE);
3071 }
3072 }
3073 }
3074
3075 /*
3076 * If we're not on a Fabric, we can't have a target
3077 * above FL_PORT_ID-1.
3078 *
3079 * If we're on a fabric and *not* connected as an F-port,
3080 * we can't have a target less than FC_SNS_ID+1. This
3081 * keeps us from having to sort out the difference between
3082 * local public loop devices and those which we might get
3083 * from a switch's database.
3084 */
3085 if (fcp->isp_onfabric == 0) {
3086 if (target >= FL_PORT_ID) {
3087 XS_SETERR(xs, HBA_SELTIMEOUT);
3088 return (CMD_COMPLETE);
3089 }
3090 } else {
3091 if (target >= FL_PORT_ID && target <= FC_SNS_ID) {
3092 XS_SETERR(xs, HBA_SELTIMEOUT);
3093 return (CMD_COMPLETE);
3094 }
3095 if (fcp->isp_topo != TOPO_F_PORT &&
3096 target < FL_PORT_ID) {
3097 XS_SETERR(xs, HBA_SELTIMEOUT);
3098 return (CMD_COMPLETE);
3099 }
3100 }
3101
3102 /*
3103 * If our loop state is such that we haven't yet received
3104 * a "Port Database Changed" notification (after a LIP or
3105 * a Loop Reset or firmware initialization), then defer
3106 * sending commands for a little while, but only if we've
3107 * seen a valid loop at one point (otherwise we can get
3108 * stuck at initialization time).
3109 */
3110 if (fcp->isp_loopstate < LOOP_PDB_RCVD) {
3111 XS_SETERR(xs, HBA_SELTIMEOUT);
3112 if (fcp->loop_seen_once) {
3113 return (CMD_RQLATER);
3114 } else {
3115 return (CMD_COMPLETE);
3116 }
3117 }
3118
3119 /*
3120 * If we're in the middle of loop or fabric scanning
3121 * or merging the port databases, retry this command later.
3122 */
3123 if (fcp->isp_loopstate == LOOP_SCANNING_FABRIC ||
3124 fcp->isp_loopstate == LOOP_SCANNING_LOOP ||
3125 fcp->isp_loopstate == LOOP_SYNCING_PDB) {
3126 return (CMD_RQLATER);
3127 }
3128
3129 /*
3130 * If our loop state is now such that we've just now
3131 * received a Port Database Change notification, then
3132 * we have to go off and (re)scan the fabric. We back
3133 * out and try again later if this doesn't work.
3134 */
3135 if (fcp->isp_loopstate == LOOP_PDB_RCVD && fcp->isp_onfabric) {
3136 if (isp_scan_fabric(isp, FC4_SCSI)) {
3137 return (CMD_RQLATER);
3138 }
3139 if (fcp->isp_fwstate != FW_READY ||
3140 fcp->isp_loopstate < LOOP_FSCAN_DONE) {
3141 return (CMD_RQLATER);
3142 }
3143 }
3144
3145 /*
3146 * If our loop state is now such that we've just now
3147 * received a Port Database Change notification, then
3148 * we have to go off and (re)synchronize our port
3149 * database.
3150 */
3151 if (fcp->isp_loopstate < LOOP_READY) {
3152 if (isp_pdb_sync(isp)) {
3153 return (CMD_RQLATER);
3154 }
3155 if (fcp->isp_fwstate != FW_READY ||
3156 fcp->isp_loopstate != LOOP_READY) {
3157 return (CMD_RQLATER);
3158 }
3159 }
3160
3161 /*
3162 * XXX: Here's were we would cancel any loop_dead flag
3163 * XXX: also cancel in dead_loop timeout that's running
3164 */
3165#endif
3166
3167 /*
3168 * Now check whether we should even think about pursuing this.
3169 */
3170 lp = &fcp->portdb[target];
3171 if (lp->valid == 0) {
3172 XS_SETERR(xs, HBA_SELTIMEOUT);
3173 return (CMD_COMPLETE);
3174 }
3175 if ((lp->roles & (SVC3_TGT_ROLE >> SVC3_ROLE_SHIFT)) == 0) {
3176 isp_prt(isp, ISP_LOGDEBUG2,
3177 "Target %d does not have target service", target);
3178 XS_SETERR(xs, HBA_SELTIMEOUT);
3179 return (CMD_COMPLETE);
3180 }
3181 /*
3182 * Now turn target into what the actual Loop ID is.
3183 */
3184 target = lp->loopid;
3185 }
3186
3187 /*
3188 * Next check to see if any HBA or Device
3189 * parameters need to be updated.
3190 */
3191 if (isp->isp_update != 0) {
3192 isp_update(isp);
3193 }
3194
3195 if (isp_getrqentry(isp, &nxti, &optr, (void *)&qep)) {
3196 isp_prt(isp, ISP_LOGDEBUG0, "Request Queue Overflow");
3197 XS_SETERR(xs, HBA_BOTCH);
3198 return (CMD_EAGAIN);
3199 }
3200
3201 /*
3202 * Now see if we need to synchronize the ISP with respect to anything.
3203 * We do dual duty here (cough) for synchronizing for busses other
3204 * than which we got here to send a command to.
3205 */
3206 reqp = (ispreq_t *) local;
3207 if (isp->isp_sendmarker) {
3208 u_int8_t n = (IS_DUALBUS(isp)? 2: 1);
3209 /*
3210 * Check ports to send markers for...
3211 */
3212 for (i = 0; i < n; i++) {
3213 if ((isp->isp_sendmarker & (1 << i)) == 0) {
3214 continue;
3215 }
3216 MEMZERO((void *) reqp, QENTRY_LEN);
3217 reqp->req_header.rqs_entry_count = 1;
3218 reqp->req_header.rqs_entry_type = RQSTYPE_MARKER;
3219 reqp->req_modifier = SYNC_ALL;
3220 reqp->req_target = i << 7; /* insert bus number */
3221 isp_put_request(isp, reqp, qep);
3222 ISP_ADD_REQUEST(isp, nxti);
3223 isp->isp_sendmarker &= ~(1 << i);
3224 if (isp_getrqentry(isp, &nxti, &optr, (void *) &qep)) {
3225 isp_prt(isp, ISP_LOGDEBUG0,
3226 "Request Queue Overflow+");
3227 XS_SETERR(xs, HBA_BOTCH);
3228 return (CMD_EAGAIN);
3229 }
3230 }
3231 }
3232
3233 MEMZERO((void *)reqp, QENTRY_LEN);
3234 reqp->req_header.rqs_entry_count = 1;
3235 if (IS_FC(isp)) {
3236 reqp->req_header.rqs_entry_type = RQSTYPE_T2RQS;
3237 } else {
3238 if (XS_CDBLEN(xs) > 12)
3239 reqp->req_header.rqs_entry_type = RQSTYPE_CMDONLY;
3240 else
3241 reqp->req_header.rqs_entry_type = RQSTYPE_REQUEST;
3242 }
3243 /* reqp->req_header.rqs_flags = 0; */
3244 /* reqp->req_header.rqs_seqno = 0; */
3245 if (IS_FC(isp)) {
3246 /*
3247 * See comment in isp_intr
3248 */
3249 /* XS_RESID(xs) = 0; */
3250
3251 /*
3252 * Fibre Channel always requires some kind of tag.
3253 * The Qlogic drivers seem be happy not to use a tag,
3254 * but this breaks for some devices (IBM drives).
3255 */
3256 if (XS_TAG_P(xs)) {
3257 ((ispreqt2_t *)reqp)->req_flags = XS_TAG_TYPE(xs);
3258 } else {
3259 /*
3260 * If we don't know what tag to use, use HEAD OF QUEUE
3261 * for Request Sense or Simple.
3262 */
3263 if (XS_CDBP(xs)[0] == 0x3) /* REQUEST SENSE */
3264 ((ispreqt2_t *)reqp)->req_flags = REQFLAG_HTAG;
3265 else
3266 ((ispreqt2_t *)reqp)->req_flags = REQFLAG_STAG;
3267 }
3268 } else {
3269 sdparam *sdp = (sdparam *)isp->isp_param;
3270 sdp += XS_CHANNEL(xs);
3271 if ((sdp->isp_devparam[target].actv_flags & DPARM_TQING) &&
3272 XS_TAG_P(xs)) {
3273 reqp->req_flags = XS_TAG_TYPE(xs);
3274 }
3275 }
2998 mbs.param[0] = MBOX_SEND_SNS;
2999 mbs.param[1] = SNS_RFT_ID_REQ_SIZE >> 1;
3000 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
3001 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
3002 /*
3003 * Leave 4 and 5 alone
3004 */
3005 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
3006 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
3007 isp_mboxcmd(isp, &mbs, MBLOGALL);
3008 FC_SCRATCH_RELEASE(isp);
3009 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
3010 isp_prt(isp, ISP_LOGDEBUG0, "Register FC4 types succeeded");
3011 }
3012}
3013
3014/*
3015 * Start a command. Locking is assumed done in the caller.
3016 */
3017
3018int
3019isp_start(XS_T *xs)
3020{
3021 struct ispsoftc *isp;
3022 u_int16_t nxti, optr, handle;
3023 u_int8_t local[QENTRY_LEN];
3024 ispreq_t *reqp, *qep;
3025 int target, i;
3026
3027 XS_INITERR(xs);
3028 isp = XS_ISP(xs);
3029
3030 /*
3031 * Check to make sure we're supporting initiator role.
3032 */
3033 if ((isp->isp_role & ISP_ROLE_INITIATOR) == 0) {
3034 XS_SETERR(xs, HBA_SELTIMEOUT);
3035 return (CMD_COMPLETE);
3036 }
3037
3038 /*
3039 * Now make sure we're running.
3040 */
3041
3042 if (isp->isp_state != ISP_RUNSTATE) {
3043 isp_prt(isp, ISP_LOGERR, "Adapter not at RUNSTATE");
3044 XS_SETERR(xs, HBA_BOTCH);
3045 return (CMD_COMPLETE);
3046 }
3047
3048 /*
3049 * Check command CDB length, etc.. We really are limited to 16 bytes
3050 * for Fibre Channel, but can do up to 44 bytes in parallel SCSI,
3051 * but probably only if we're running fairly new firmware (we'll
3052 * let the old f/w choke on an extended command queue entry).
3053 */
3054
3055 if (XS_CDBLEN(xs) > (IS_FC(isp)? 16 : 44) || XS_CDBLEN(xs) == 0) {
3056 isp_prt(isp, ISP_LOGERR,
3057 "unsupported cdb length (%d, CDB[0]=0x%x)",
3058 XS_CDBLEN(xs), XS_CDBP(xs)[0] & 0xff);
3059 XS_SETERR(xs, HBA_BOTCH);
3060 return (CMD_COMPLETE);
3061 }
3062
3063 /*
3064 * Check to see whether we have good firmware state still or
3065 * need to refresh our port database for this target.
3066 */
3067 target = XS_TGT(xs);
3068 if (IS_FC(isp)) {
3069 fcparam *fcp = isp->isp_param;
3070 struct lportdb *lp;
3071#ifdef HANDLE_LOOPSTATE_IN_OUTER_LAYERS
3072 if (fcp->isp_fwstate != FW_READY ||
3073 fcp->isp_loopstate != LOOP_READY) {
3074 return (CMD_RQLATER);
3075 }
3076
3077 /*
3078 * If we're not on a Fabric, we can't have a target
3079 * above FL_PORT_ID-1.
3080 *
3081 * If we're on a fabric and *not* connected as an F-port,
3082 * we can't have a target less than FC_SNS_ID+1. This
3083 * keeps us from having to sort out the difference between
3084 * local public loop devices and those which we might get
3085 * from a switch's database.
3086 */
3087 if (fcp->isp_onfabric == 0) {
3088 if (target >= FL_PORT_ID) {
3089 XS_SETERR(xs, HBA_SELTIMEOUT);
3090 return (CMD_COMPLETE);
3091 }
3092 } else {
3093 if (target >= FL_PORT_ID && target <= FC_SNS_ID) {
3094 XS_SETERR(xs, HBA_SELTIMEOUT);
3095 return (CMD_COMPLETE);
3096 }
3097 /*
3098 * We used to exclude having local loop ports
3099 * at the same time that we have fabric ports.
3100 * That is, we used to exclude having ports
3101 * at < FL_PORT_ID if we're FL-port.
3102 *
3103 * That's wrong. The only thing that could be
3104 * dicey is if the switch you're connected to
3105 * has these local loop ports appear on the
3106 * fabric and we somehow attach them twice.
3107 */
3108 }
3109#else
3110 /*
3111 * Check for f/w being in ready state. If the f/w
3112 * isn't in ready state, then we don't know our
3113 * loop ID and the f/w hasn't completed logging
3114 * into all targets on the loop. If this is the
3115 * case, then bounce the command. We pretend this is
3116 * a SELECTION TIMEOUT error if we've never gone to
3117 * FW_READY state at all- in this case we may not
3118 * be hooked to a loop at all and we shouldn't hang
3119 * the machine for this. Otherwise, defer this command
3120 * until later.
3121 */
3122 if (fcp->isp_fwstate != FW_READY) {
3123 /*
3124 * Give ourselves at most a 250ms delay.
3125 */
3126 if (isp_fclink_test(isp, 250000)) {
3127 XS_SETERR(xs, HBA_SELTIMEOUT);
3128 if (fcp->loop_seen_once) {
3129 return (CMD_RQLATER);
3130 } else {
3131 return (CMD_COMPLETE);
3132 }
3133 }
3134 }
3135
3136 /*
3137 * If we're not on a Fabric, we can't have a target
3138 * above FL_PORT_ID-1.
3139 *
3140 * If we're on a fabric and *not* connected as an F-port,
3141 * we can't have a target less than FC_SNS_ID+1. This
3142 * keeps us from having to sort out the difference between
3143 * local public loop devices and those which we might get
3144 * from a switch's database.
3145 */
3146 if (fcp->isp_onfabric == 0) {
3147 if (target >= FL_PORT_ID) {
3148 XS_SETERR(xs, HBA_SELTIMEOUT);
3149 return (CMD_COMPLETE);
3150 }
3151 } else {
3152 if (target >= FL_PORT_ID && target <= FC_SNS_ID) {
3153 XS_SETERR(xs, HBA_SELTIMEOUT);
3154 return (CMD_COMPLETE);
3155 }
3156 if (fcp->isp_topo != TOPO_F_PORT &&
3157 target < FL_PORT_ID) {
3158 XS_SETERR(xs, HBA_SELTIMEOUT);
3159 return (CMD_COMPLETE);
3160 }
3161 }
3162
3163 /*
3164 * If our loop state is such that we haven't yet received
3165 * a "Port Database Changed" notification (after a LIP or
3166 * a Loop Reset or firmware initialization), then defer
3167 * sending commands for a little while, but only if we've
3168 * seen a valid loop at one point (otherwise we can get
3169 * stuck at initialization time).
3170 */
3171 if (fcp->isp_loopstate < LOOP_PDB_RCVD) {
3172 XS_SETERR(xs, HBA_SELTIMEOUT);
3173 if (fcp->loop_seen_once) {
3174 return (CMD_RQLATER);
3175 } else {
3176 return (CMD_COMPLETE);
3177 }
3178 }
3179
3180 /*
3181 * If we're in the middle of loop or fabric scanning
3182 * or merging the port databases, retry this command later.
3183 */
3184 if (fcp->isp_loopstate == LOOP_SCANNING_FABRIC ||
3185 fcp->isp_loopstate == LOOP_SCANNING_LOOP ||
3186 fcp->isp_loopstate == LOOP_SYNCING_PDB) {
3187 return (CMD_RQLATER);
3188 }
3189
3190 /*
3191 * If our loop state is now such that we've just now
3192 * received a Port Database Change notification, then
3193 * we have to go off and (re)scan the fabric. We back
3194 * out and try again later if this doesn't work.
3195 */
3196 if (fcp->isp_loopstate == LOOP_PDB_RCVD && fcp->isp_onfabric) {
3197 if (isp_scan_fabric(isp, FC4_SCSI)) {
3198 return (CMD_RQLATER);
3199 }
3200 if (fcp->isp_fwstate != FW_READY ||
3201 fcp->isp_loopstate < LOOP_FSCAN_DONE) {
3202 return (CMD_RQLATER);
3203 }
3204 }
3205
3206 /*
3207 * If our loop state is now such that we've just now
3208 * received a Port Database Change notification, then
3209 * we have to go off and (re)synchronize our port
3210 * database.
3211 */
3212 if (fcp->isp_loopstate < LOOP_READY) {
3213 if (isp_pdb_sync(isp)) {
3214 return (CMD_RQLATER);
3215 }
3216 if (fcp->isp_fwstate != FW_READY ||
3217 fcp->isp_loopstate != LOOP_READY) {
3218 return (CMD_RQLATER);
3219 }
3220 }
3221
3222 /*
3223 * XXX: Here's were we would cancel any loop_dead flag
3224 * XXX: also cancel in dead_loop timeout that's running
3225 */
3226#endif
3227
3228 /*
3229 * Now check whether we should even think about pursuing this.
3230 */
3231 lp = &fcp->portdb[target];
3232 if (lp->valid == 0) {
3233 XS_SETERR(xs, HBA_SELTIMEOUT);
3234 return (CMD_COMPLETE);
3235 }
3236 if ((lp->roles & (SVC3_TGT_ROLE >> SVC3_ROLE_SHIFT)) == 0) {
3237 isp_prt(isp, ISP_LOGDEBUG2,
3238 "Target %d does not have target service", target);
3239 XS_SETERR(xs, HBA_SELTIMEOUT);
3240 return (CMD_COMPLETE);
3241 }
3242 /*
3243 * Now turn target into what the actual Loop ID is.
3244 */
3245 target = lp->loopid;
3246 }
3247
3248 /*
3249 * Next check to see if any HBA or Device
3250 * parameters need to be updated.
3251 */
3252 if (isp->isp_update != 0) {
3253 isp_update(isp);
3254 }
3255
3256 if (isp_getrqentry(isp, &nxti, &optr, (void *)&qep)) {
3257 isp_prt(isp, ISP_LOGDEBUG0, "Request Queue Overflow");
3258 XS_SETERR(xs, HBA_BOTCH);
3259 return (CMD_EAGAIN);
3260 }
3261
3262 /*
3263 * Now see if we need to synchronize the ISP with respect to anything.
3264 * We do dual duty here (cough) for synchronizing for busses other
3265 * than which we got here to send a command to.
3266 */
3267 reqp = (ispreq_t *) local;
3268 if (isp->isp_sendmarker) {
3269 u_int8_t n = (IS_DUALBUS(isp)? 2: 1);
3270 /*
3271 * Check ports to send markers for...
3272 */
3273 for (i = 0; i < n; i++) {
3274 if ((isp->isp_sendmarker & (1 << i)) == 0) {
3275 continue;
3276 }
3277 MEMZERO((void *) reqp, QENTRY_LEN);
3278 reqp->req_header.rqs_entry_count = 1;
3279 reqp->req_header.rqs_entry_type = RQSTYPE_MARKER;
3280 reqp->req_modifier = SYNC_ALL;
3281 reqp->req_target = i << 7; /* insert bus number */
3282 isp_put_request(isp, reqp, qep);
3283 ISP_ADD_REQUEST(isp, nxti);
3284 isp->isp_sendmarker &= ~(1 << i);
3285 if (isp_getrqentry(isp, &nxti, &optr, (void *) &qep)) {
3286 isp_prt(isp, ISP_LOGDEBUG0,
3287 "Request Queue Overflow+");
3288 XS_SETERR(xs, HBA_BOTCH);
3289 return (CMD_EAGAIN);
3290 }
3291 }
3292 }
3293
3294 MEMZERO((void *)reqp, QENTRY_LEN);
3295 reqp->req_header.rqs_entry_count = 1;
3296 if (IS_FC(isp)) {
3297 reqp->req_header.rqs_entry_type = RQSTYPE_T2RQS;
3298 } else {
3299 if (XS_CDBLEN(xs) > 12)
3300 reqp->req_header.rqs_entry_type = RQSTYPE_CMDONLY;
3301 else
3302 reqp->req_header.rqs_entry_type = RQSTYPE_REQUEST;
3303 }
3304 /* reqp->req_header.rqs_flags = 0; */
3305 /* reqp->req_header.rqs_seqno = 0; */
3306 if (IS_FC(isp)) {
3307 /*
3308 * See comment in isp_intr
3309 */
3310 /* XS_RESID(xs) = 0; */
3311
3312 /*
3313 * Fibre Channel always requires some kind of tag.
3314 * The Qlogic drivers seem be happy not to use a tag,
3315 * but this breaks for some devices (IBM drives).
3316 */
3317 if (XS_TAG_P(xs)) {
3318 ((ispreqt2_t *)reqp)->req_flags = XS_TAG_TYPE(xs);
3319 } else {
3320 /*
3321 * If we don't know what tag to use, use HEAD OF QUEUE
3322 * for Request Sense or Simple.
3323 */
3324 if (XS_CDBP(xs)[0] == 0x3) /* REQUEST SENSE */
3325 ((ispreqt2_t *)reqp)->req_flags = REQFLAG_HTAG;
3326 else
3327 ((ispreqt2_t *)reqp)->req_flags = REQFLAG_STAG;
3328 }
3329 } else {
3330 sdparam *sdp = (sdparam *)isp->isp_param;
3331 sdp += XS_CHANNEL(xs);
3332 if ((sdp->isp_devparam[target].actv_flags & DPARM_TQING) &&
3333 XS_TAG_P(xs)) {
3334 reqp->req_flags = XS_TAG_TYPE(xs);
3335 }
3336 }
3276 reqp->req_target = target | (XS_CHANNEL(xs) << 7);
3277 if (IS_SCSI(isp)) {
3337 if (IS_SCSI(isp)) {
3338 reqp->req_target = target | (XS_CHANNEL(xs) << 7);
3278 reqp->req_lun_trn = XS_LUN(xs);
3279 reqp->req_cdblen = XS_CDBLEN(xs);
3339 reqp->req_lun_trn = XS_LUN(xs);
3340 reqp->req_cdblen = XS_CDBLEN(xs);
3341 } else if (IS_2KLOGIN(isp)) {
3342 ((ispreqt2e_t *)reqp)->req_target = target;
3343 ((ispreqt2e_t *)reqp)->req_scclun = XS_LUN(xs);
3344 } else if (FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) {
3345 ((ispreqt2_t *)reqp)->req_target = target;
3346 ((ispreqt2_t *)reqp)->req_scclun = XS_LUN(xs);
3280 } else {
3347 } else {
3281 if (FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN)
3282 ((ispreqt2_t *)reqp)->req_scclun = XS_LUN(xs);
3283 else
3284 ((ispreqt2_t *)reqp)->req_lun_trn = XS_LUN(xs);
3348 ((ispreqt2_t *)reqp)->req_target = target;
3349 ((ispreqt2_t *)reqp)->req_lun_trn = XS_LUN(xs);
3285 }
3286 MEMCPY(reqp->req_cdb, XS_CDBP(xs), XS_CDBLEN(xs));
3287
3288 reqp->req_time = XS_TIME(xs) / 1000;
3289 if (reqp->req_time == 0 && XS_TIME(xs)) {
3290 reqp->req_time = 1;
3291 }
3292
3293 if (isp_save_xs(isp, xs, &handle)) {
3294 isp_prt(isp, ISP_LOGDEBUG0, "out of xflist pointers");
3295 XS_SETERR(xs, HBA_BOTCH);
3296 return (CMD_EAGAIN);
3297 }
3298 reqp->req_handle = handle;
3299
3300 /*
3301 * Set up DMA and/or do any bus swizzling of the request entry
3302 * so that the Qlogic F/W understands what is being asked of it.
3303 */
3304 i = ISP_DMASETUP(isp, xs, reqp, &nxti, optr);
3305 if (i != CMD_QUEUED) {
3306 isp_destroy_handle(isp, handle);
3307 /*
3308 * dmasetup sets actual error in packet, and
3309 * return what we were given to return.
3310 */
3311 return (i);
3312 }
3313 XS_SETERR(xs, HBA_NOERROR);
3314 isp_prt(isp, ISP_LOGDEBUG2,
3315 "START cmd for %d.%d.%d cmd 0x%x datalen %ld",
3316 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs), XS_CDBP(xs)[0],
3317 (long) XS_XFRLEN(xs));
3318 ISP_ADD_REQUEST(isp, nxti);
3319 isp->isp_nactive++;
3320 return (CMD_QUEUED);
3321}
3322
3323/*
3324 * isp control
3325 * Locks (ints blocked) assumed held.
3326 */
3327
3328int
3329isp_control(struct ispsoftc *isp, ispctl_t ctl, void *arg)
3330{
3331 XS_T *xs;
3332 mbreg_t mbs;
3333 int bus, tgt;
3334 u_int16_t handle;
3335
3350 }
3351 MEMCPY(reqp->req_cdb, XS_CDBP(xs), XS_CDBLEN(xs));
3352
3353 reqp->req_time = XS_TIME(xs) / 1000;
3354 if (reqp->req_time == 0 && XS_TIME(xs)) {
3355 reqp->req_time = 1;
3356 }
3357
3358 if (isp_save_xs(isp, xs, &handle)) {
3359 isp_prt(isp, ISP_LOGDEBUG0, "out of xflist pointers");
3360 XS_SETERR(xs, HBA_BOTCH);
3361 return (CMD_EAGAIN);
3362 }
3363 reqp->req_handle = handle;
3364
3365 /*
3366 * Set up DMA and/or do any bus swizzling of the request entry
3367 * so that the Qlogic F/W understands what is being asked of it.
3368 */
3369 i = ISP_DMASETUP(isp, xs, reqp, &nxti, optr);
3370 if (i != CMD_QUEUED) {
3371 isp_destroy_handle(isp, handle);
3372 /*
3373 * dmasetup sets actual error in packet, and
3374 * return what we were given to return.
3375 */
3376 return (i);
3377 }
3378 XS_SETERR(xs, HBA_NOERROR);
3379 isp_prt(isp, ISP_LOGDEBUG2,
3380 "START cmd for %d.%d.%d cmd 0x%x datalen %ld",
3381 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs), XS_CDBP(xs)[0],
3382 (long) XS_XFRLEN(xs));
3383 ISP_ADD_REQUEST(isp, nxti);
3384 isp->isp_nactive++;
3385 return (CMD_QUEUED);
3386}
3387
3388/*
3389 * isp control
3390 * Locks (ints blocked) assumed held.
3391 */
3392
3393int
3394isp_control(struct ispsoftc *isp, ispctl_t ctl, void *arg)
3395{
3396 XS_T *xs;
3397 mbreg_t mbs;
3398 int bus, tgt;
3399 u_int16_t handle;
3400
3401 MEMZERO(&mbs, sizeof (mbs));
3402
3336 switch (ctl) {
3337 default:
3338 isp_prt(isp, ISP_LOGERR, "Unknown Control Opcode 0x%x", ctl);
3339 break;
3340
3341 case ISPCTL_RESET_BUS:
3342 /*
3343 * Issue a bus reset.
3344 */
3345 mbs.param[0] = MBOX_BUS_RESET;
3346 mbs.param[2] = 0;
3347 if (IS_SCSI(isp)) {
3348 mbs.param[1] =
3349 ((sdparam *) isp->isp_param)->isp_bus_reset_delay;
3350 if (mbs.param[1] < 2)
3351 mbs.param[1] = 2;
3352 bus = *((int *) arg);
3353 if (IS_DUALBUS(isp))
3354 mbs.param[2] = bus;
3355 } else {
3356 mbs.param[1] = 10;
3357 bus = 0;
3358 }
3359 isp->isp_sendmarker |= (1 << bus);
3360 isp_mboxcmd(isp, &mbs, MBLOGALL);
3361 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3362 break;
3363 }
3364 isp_prt(isp, ISP_LOGINFO,
3365 "driver initiated bus reset of bus %d", bus);
3366 return (0);
3367
3368 case ISPCTL_RESET_DEV:
3369 tgt = (*((int *) arg)) & 0xffff;
3370 bus = (*((int *) arg)) >> 16;
3371 mbs.param[0] = MBOX_ABORT_TARGET;
3403 switch (ctl) {
3404 default:
3405 isp_prt(isp, ISP_LOGERR, "Unknown Control Opcode 0x%x", ctl);
3406 break;
3407
3408 case ISPCTL_RESET_BUS:
3409 /*
3410 * Issue a bus reset.
3411 */
3412 mbs.param[0] = MBOX_BUS_RESET;
3413 mbs.param[2] = 0;
3414 if (IS_SCSI(isp)) {
3415 mbs.param[1] =
3416 ((sdparam *) isp->isp_param)->isp_bus_reset_delay;
3417 if (mbs.param[1] < 2)
3418 mbs.param[1] = 2;
3419 bus = *((int *) arg);
3420 if (IS_DUALBUS(isp))
3421 mbs.param[2] = bus;
3422 } else {
3423 mbs.param[1] = 10;
3424 bus = 0;
3425 }
3426 isp->isp_sendmarker |= (1 << bus);
3427 isp_mboxcmd(isp, &mbs, MBLOGALL);
3428 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3429 break;
3430 }
3431 isp_prt(isp, ISP_LOGINFO,
3432 "driver initiated bus reset of bus %d", bus);
3433 return (0);
3434
3435 case ISPCTL_RESET_DEV:
3436 tgt = (*((int *) arg)) & 0xffff;
3437 bus = (*((int *) arg)) >> 16;
3438 mbs.param[0] = MBOX_ABORT_TARGET;
3372 mbs.param[1] = (tgt << 8) | (bus << 15);
3439 if (IS_SCSI(isp)) {
3440 mbs.param[1] = (tgt << 8) | (bus << 15);
3441 } else {
3442 if (IS_2KLOGIN(isp)) {
3443 mbs.param[1] = tgt;
3444 mbs.obits |= (1 << 10);
3445 } else {
3446 mbs.param[1] = (tgt << 8);
3447 }
3448 }
3373 mbs.param[2] = 3; /* 'delay', in seconds */
3374 isp_mboxcmd(isp, &mbs, MBLOGALL);
3375 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3376 break;
3377 }
3378 isp_prt(isp, ISP_LOGINFO,
3379 "Target %d on Bus %d Reset Succeeded", tgt, bus);
3380 isp->isp_sendmarker |= (1 << bus);
3381 return (0);
3382
3383 case ISPCTL_ABORT_CMD:
3384 xs = (XS_T *) arg;
3385 tgt = XS_TGT(xs);
3386 handle = isp_find_handle(isp, xs);
3387 if (handle == 0) {
3388 isp_prt(isp, ISP_LOGWARN,
3389 "cannot find handle for command to abort");
3390 break;
3391 }
3392 bus = XS_CHANNEL(xs);
3393 mbs.param[0] = MBOX_ABORT;
3394 if (IS_FC(isp)) {
3395 if (FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) {
3449 mbs.param[2] = 3; /* 'delay', in seconds */
3450 isp_mboxcmd(isp, &mbs, MBLOGALL);
3451 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3452 break;
3453 }
3454 isp_prt(isp, ISP_LOGINFO,
3455 "Target %d on Bus %d Reset Succeeded", tgt, bus);
3456 isp->isp_sendmarker |= (1 << bus);
3457 return (0);
3458
3459 case ISPCTL_ABORT_CMD:
3460 xs = (XS_T *) arg;
3461 tgt = XS_TGT(xs);
3462 handle = isp_find_handle(isp, xs);
3463 if (handle == 0) {
3464 isp_prt(isp, ISP_LOGWARN,
3465 "cannot find handle for command to abort");
3466 break;
3467 }
3468 bus = XS_CHANNEL(xs);
3469 mbs.param[0] = MBOX_ABORT;
3470 if (IS_FC(isp)) {
3471 if (FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) {
3396 mbs.param[1] = tgt << 8;
3472 if (IS_2KLOGIN(isp)) {
3473 mbs.param[1] = tgt;
3474 } else {
3475 mbs.param[1] = tgt << 8;
3476 }
3397 mbs.param[4] = 0;
3398 mbs.param[5] = 0;
3399 mbs.param[6] = XS_LUN(xs);
3400 } else {
3401 mbs.param[1] = tgt << 8 | XS_LUN(xs);
3402 }
3403 } else {
3404 mbs.param[1] =
3405 (bus << 15) | (XS_TGT(xs) << 8) | XS_LUN(xs);
3406 }
3407 mbs.param[3] = 0;
3408 mbs.param[2] = handle;
3409 isp_mboxcmd(isp, &mbs, MBLOGALL & ~MBOX_COMMAND_ERROR);
3410 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
3411 return (0);
3412 }
3413 /*
3414 * XXX: Look for command in the REQUEST QUEUE. That is,
3415 * XXX: It hasen't been picked up by firmware yet.
3416 */
3417 break;
3418
3419 case ISPCTL_UPDATE_PARAMS:
3420
3421 isp_update(isp);
3422 return (0);
3423
3424 case ISPCTL_FCLINK_TEST:
3425
3426 if (IS_FC(isp)) {
3427 int usdelay = (arg)? *((int *) arg) : 250000;
3428 return (isp_fclink_test(isp, usdelay));
3429 }
3430 break;
3431
3432 case ISPCTL_SCAN_FABRIC:
3433
3434 if (IS_FC(isp)) {
3435 int ftype = (arg)? *((int *) arg) : FC4_SCSI;
3436 return (isp_scan_fabric(isp, ftype));
3437 }
3438 break;
3439
3440 case ISPCTL_SCAN_LOOP:
3441
3442 if (IS_FC(isp)) {
3443 return (isp_scan_loop(isp));
3444 }
3445 break;
3446
3447 case ISPCTL_PDB_SYNC:
3448
3449 if (IS_FC(isp)) {
3450 return (isp_pdb_sync(isp));
3451 }
3452 break;
3453
3454 case ISPCTL_SEND_LIP:
3455
3456 if (IS_FC(isp)) {
3457 mbs.param[0] = MBOX_INIT_LIP;
3458 isp_mboxcmd(isp, &mbs, MBLOGALL);
3459 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
3460 return (0);
3461 }
3462 }
3463 break;
3464
3465 case ISPCTL_GET_POSMAP:
3466
3467 if (IS_FC(isp) && arg) {
3468 return (isp_getmap(isp, arg));
3469 }
3470 break;
3471
3472
3473 case ISPCTL_GET_PDB:
3474 if (IS_FC(isp) && arg) {
3475 int id = *((int *)arg);
3476 isp_pdb_t *pdb = arg;
3477 return (isp_getpdb(isp, id, pdb));
3478 }
3479 break;
3480
3481 case ISPCTL_RUN_MBOXCMD:
3482
3483 isp_mboxcmd(isp, arg, MBLOGALL);
3484 return(0);
3485
3486#ifdef ISP_TARGET_MODE
3487 case ISPCTL_TOGGLE_TMODE:
3488 {
3489
3490 /*
3491 * We don't check/set against role here- that's the
3492 * responsibility for the outer layer to coordinate.
3493 */
3494 if (IS_SCSI(isp)) {
3495 int param = *(int *)arg;
3496 mbs.param[0] = MBOX_ENABLE_TARGET_MODE;
3497 mbs.param[1] = param & 0xffff;
3498 mbs.param[2] = param >> 16;
3499 isp_mboxcmd(isp, &mbs, MBLOGALL);
3500 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3501 break;
3502 }
3503 }
3504 return (0);
3505 }
3506#endif
3507 }
3508 return (-1);
3509}
3510
3511/*
3512 * Interrupt Service Routine(s).
3513 *
3514 * External (OS) framework has done the appropriate locking,
3515 * and the locking will be held throughout this function.
3516 */
3517
3518/*
3519 * Limit our stack depth by sticking with the max likely number
3520 * of completions on a request queue at any one time.
3521 */
3522#ifndef MAX_REQUESTQ_COMPLETIONS
3523#define MAX_REQUESTQ_COMPLETIONS 64
3524#endif
3525
3526void
3527isp_intr(struct ispsoftc *isp, u_int16_t isr, u_int16_t sema, u_int16_t mbox)
3528{
3529 XS_T *complist[MAX_REQUESTQ_COMPLETIONS], *xs;
3530 u_int16_t iptr, optr, junk;
3531 int i, nlooked = 0, ndone = 0;
3532
3533again:
3534 /*
3535 * Is this a mailbox related interrupt?
3536 * The mailbox semaphore will be nonzero if so.
3537 */
3538 if (sema) {
3539 if (mbox & 0x4000) {
3540 isp->isp_intmboxc++;
3541 if (isp->isp_mboxbsy) {
3542 int i = 0, obits = isp->isp_obits;
3543 isp->isp_mboxtmp[i++] = mbox;
3477 mbs.param[4] = 0;
3478 mbs.param[5] = 0;
3479 mbs.param[6] = XS_LUN(xs);
3480 } else {
3481 mbs.param[1] = tgt << 8 | XS_LUN(xs);
3482 }
3483 } else {
3484 mbs.param[1] =
3485 (bus << 15) | (XS_TGT(xs) << 8) | XS_LUN(xs);
3486 }
3487 mbs.param[3] = 0;
3488 mbs.param[2] = handle;
3489 isp_mboxcmd(isp, &mbs, MBLOGALL & ~MBOX_COMMAND_ERROR);
3490 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
3491 return (0);
3492 }
3493 /*
3494 * XXX: Look for command in the REQUEST QUEUE. That is,
3495 * XXX: It hasen't been picked up by firmware yet.
3496 */
3497 break;
3498
3499 case ISPCTL_UPDATE_PARAMS:
3500
3501 isp_update(isp);
3502 return (0);
3503
3504 case ISPCTL_FCLINK_TEST:
3505
3506 if (IS_FC(isp)) {
3507 int usdelay = (arg)? *((int *) arg) : 250000;
3508 return (isp_fclink_test(isp, usdelay));
3509 }
3510 break;
3511
3512 case ISPCTL_SCAN_FABRIC:
3513
3514 if (IS_FC(isp)) {
3515 int ftype = (arg)? *((int *) arg) : FC4_SCSI;
3516 return (isp_scan_fabric(isp, ftype));
3517 }
3518 break;
3519
3520 case ISPCTL_SCAN_LOOP:
3521
3522 if (IS_FC(isp)) {
3523 return (isp_scan_loop(isp));
3524 }
3525 break;
3526
3527 case ISPCTL_PDB_SYNC:
3528
3529 if (IS_FC(isp)) {
3530 return (isp_pdb_sync(isp));
3531 }
3532 break;
3533
3534 case ISPCTL_SEND_LIP:
3535
3536 if (IS_FC(isp)) {
3537 mbs.param[0] = MBOX_INIT_LIP;
3538 isp_mboxcmd(isp, &mbs, MBLOGALL);
3539 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
3540 return (0);
3541 }
3542 }
3543 break;
3544
3545 case ISPCTL_GET_POSMAP:
3546
3547 if (IS_FC(isp) && arg) {
3548 return (isp_getmap(isp, arg));
3549 }
3550 break;
3551
3552
3553 case ISPCTL_GET_PDB:
3554 if (IS_FC(isp) && arg) {
3555 int id = *((int *)arg);
3556 isp_pdb_t *pdb = arg;
3557 return (isp_getpdb(isp, id, pdb));
3558 }
3559 break;
3560
3561 case ISPCTL_RUN_MBOXCMD:
3562
3563 isp_mboxcmd(isp, arg, MBLOGALL);
3564 return(0);
3565
3566#ifdef ISP_TARGET_MODE
3567 case ISPCTL_TOGGLE_TMODE:
3568 {
3569
3570 /*
3571 * We don't check/set against role here- that's the
3572 * responsibility for the outer layer to coordinate.
3573 */
3574 if (IS_SCSI(isp)) {
3575 int param = *(int *)arg;
3576 mbs.param[0] = MBOX_ENABLE_TARGET_MODE;
3577 mbs.param[1] = param & 0xffff;
3578 mbs.param[2] = param >> 16;
3579 isp_mboxcmd(isp, &mbs, MBLOGALL);
3580 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3581 break;
3582 }
3583 }
3584 return (0);
3585 }
3586#endif
3587 }
3588 return (-1);
3589}
3590
3591/*
3592 * Interrupt Service Routine(s).
3593 *
3594 * External (OS) framework has done the appropriate locking,
3595 * and the locking will be held throughout this function.
3596 */
3597
3598/*
3599 * Limit our stack depth by sticking with the max likely number
3600 * of completions on a request queue at any one time.
3601 */
3602#ifndef MAX_REQUESTQ_COMPLETIONS
3603#define MAX_REQUESTQ_COMPLETIONS 64
3604#endif
3605
3606void
3607isp_intr(struct ispsoftc *isp, u_int16_t isr, u_int16_t sema, u_int16_t mbox)
3608{
3609 XS_T *complist[MAX_REQUESTQ_COMPLETIONS], *xs;
3610 u_int16_t iptr, optr, junk;
3611 int i, nlooked = 0, ndone = 0;
3612
3613again:
3614 /*
3615 * Is this a mailbox related interrupt?
3616 * The mailbox semaphore will be nonzero if so.
3617 */
3618 if (sema) {
3619 if (mbox & 0x4000) {
3620 isp->isp_intmboxc++;
3621 if (isp->isp_mboxbsy) {
3622 int i = 0, obits = isp->isp_obits;
3623 isp->isp_mboxtmp[i++] = mbox;
3544 for (i = 1; i < MAX_MAILBOX; i++) {
3624 for (i = 1; i < MAX_MAILBOX(isp); i++) {
3545 if ((obits & (1 << i)) == 0) {
3546 continue;
3547 }
3548 isp->isp_mboxtmp[i] =
3549 ISP_READ(isp, MBOX_OFF(i));
3550 }
3551 if (isp->isp_mbxwrk0) {
3552 if (isp_mbox_continue(isp) == 0) {
3553 return;
3554 }
3555 }
3556 MBOX_NOTIFY_COMPLETE(isp);
3557 } else {
3558 isp_prt(isp, ISP_LOGWARN,
3559 "Mbox Command Async (0x%x) with no waiters",
3560 mbox);
3561 }
3562 } else if (isp_parse_async(isp, mbox) < 0) {
3563 return;
3564 }
3565 if ((IS_FC(isp) && mbox != ASYNC_RIO_RESP) ||
3566 isp->isp_state != ISP_RUNSTATE) {
3567 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
3568 ISP_WRITE(isp, BIU_SEMA, 0);
3569 return;
3570 }
3571 }
3572
3573 /*
3574 * We can't be getting this now.
3575 */
3576 if (isp->isp_state != ISP_RUNSTATE) {
3577 isp_prt(isp, ISP_LOGWARN,
3578 "interrupt (ISR=%x SEMA=%x) when not ready", isr, sema);
3579 /*
3580 * Thank you very much! *Burrrp*!
3581 */
3582 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp,
3583 READ_RESPONSE_QUEUE_IN_POINTER(isp));
3584
3585 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
3586 ISP_WRITE(isp, BIU_SEMA, 0);
3587 return;
3588 }
3589
3590 /*
3591 * Get the current Response Queue Out Pointer.
3592 *
3593 * If we're a 2300, we can ask what hardware what it thinks.
3594 */
3595 if (IS_23XX(isp)) {
3596 optr = ISP_READ(isp, isp->isp_respoutrp);
3597 /*
3598 * Debug: to be taken out eventually
3599 */
3600 if (isp->isp_residx != optr) {
3601 isp_prt(isp, ISP_LOGWARN, "optr %x soft optr %x",
3602 optr, isp->isp_residx);
3603 }
3604 } else {
3605 optr = isp->isp_residx;
3606 }
3607
3608 /*
3609 * You *must* read the Response Queue In Pointer
3610 * prior to clearing the RISC interrupt.
3611 *
3612 * Debounce the 2300 if revision less than 2.
3613 */
3614 if (IS_2100(isp) || (IS_2300(isp) && isp->isp_revision < 2)) {
3615 i = 0;
3616 do {
3617 iptr = READ_RESPONSE_QUEUE_IN_POINTER(isp);
3618 junk = READ_RESPONSE_QUEUE_IN_POINTER(isp);
3619 } while (junk != iptr && ++i < 1000);
3620
3621 if (iptr != junk) {
3622 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
3623 isp_prt(isp, ISP_LOGWARN,
3624 "Response Queue Out Pointer Unstable (%x, %x)",
3625 iptr, junk);
3626 return;
3627 }
3628 } else {
3629 iptr = READ_RESPONSE_QUEUE_IN_POINTER(isp);
3630 }
3631 isp->isp_resodx = iptr;
3632
3633
3634 if (optr == iptr && sema == 0) {
3635 /*
3636 * There are a lot of these- reasons unknown- mostly on
3637 * faster Alpha machines.
3638 *
3639 * I tried delaying after writing HCCR_CMD_CLEAR_RISC_INT to
3640 * make sure the old interrupt went away (to avoid 'ringing'
3641 * effects), but that didn't stop this from occurring.
3642 */
3643 if (IS_23XX(isp)) {
3644 USEC_DELAY(100);
3645 iptr = READ_RESPONSE_QUEUE_IN_POINTER(isp);
3646 junk = ISP_READ(isp, BIU_R2HSTSLO);
3647 } else {
3648 junk = ISP_READ(isp, BIU_ISR);
3649 }
3650 if (optr == iptr) {
3651 if (IS_23XX(isp)) {
3652 ;
3653 } else {
3654 sema = ISP_READ(isp, BIU_SEMA);
3655 mbox = ISP_READ(isp, OUTMAILBOX0);
3656 if ((sema & 0x3) && (mbox & 0x8000)) {
3657 goto again;
3658 }
3659 }
3660 isp->isp_intbogus++;
3661 isp_prt(isp, ISP_LOGDEBUG1,
3662 "bogus intr- isr %x (%x) iptr %x optr %x",
3663 isr, junk, iptr, optr);
3664 }
3665 }
3666 isp->isp_resodx = iptr;
3667 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
3668 ISP_WRITE(isp, BIU_SEMA, 0);
3669
3670 if (isp->isp_rspbsy) {
3671 return;
3672 }
3673 isp->isp_rspbsy = 1;
3674
3675 while (optr != iptr) {
3676 ispstatusreq_t local, *sp = &local;
3677 isphdr_t *hp;
3678 int type;
3679 u_int16_t oop;
3680 int buddaboom = 0;
3681
3682 hp = (isphdr_t *) ISP_QUEUE_ENTRY(isp->isp_result, optr);
3683 oop = optr;
3684 optr = ISP_NXT_QENTRY(optr, RESULT_QUEUE_LEN(isp));
3685 nlooked++;
3686 read_again:
3687 /*
3688 * Synchronize our view of this response queue entry.
3689 */
3690 MEMORYBARRIER(isp, SYNC_RESULT, oop, QENTRY_LEN);
3691
3692 type = isp_get_response_type(isp, hp);
3693
3694 if (type == RQSTYPE_RESPONSE) {
3695 isp_get_response(isp, (ispstatusreq_t *) hp, sp);
3696 } else if (type == RQSTYPE_RIO2) {
3697 isp_rio2_t rio;
3698 isp_get_rio2(isp, (isp_rio2_t *) hp, &rio);
3699 for (i = 0; i < rio.req_header.rqs_seqno; i++) {
3700 isp_fastpost_complete(isp, rio.req_handles[i]);
3701 }
3702 if (isp->isp_fpcchiwater < rio.req_header.rqs_seqno)
3703 isp->isp_fpcchiwater = rio.req_header.rqs_seqno;
3704 MEMZERO(hp, QENTRY_LEN); /* PERF */
3705 continue;
3706 } else {
3707 /*
3708 * Somebody reachable via isp_handle_other_response
3709 * may have updated the response queue pointers for
3710 * us, so we reload our goal index.
3711 */
3712 int i = isp_handle_other_response(isp, type, hp, &optr);
3713 if (i < 0) {
3714 goto read_again;
3715 } else if (i > 0) {
3716 iptr = isp->isp_resodx;
3717 MEMZERO(hp, QENTRY_LEN); /* PERF */
3718 continue;
3719 }
3720
3721 /*
3722 * After this point, we'll just look at the header as
3723 * we don't know how to deal with the rest of the
3724 * response.
3725 */
3726 isp_get_response(isp, (ispstatusreq_t *) hp, sp);
3727
3728 /*
3729 * It really has to be a bounced request just copied
3730 * from the request queue to the response queue. If
3731 * not, something bad has happened.
3732 */
3733 if (sp->req_header.rqs_entry_type != RQSTYPE_REQUEST) {
3734 isp_prt(isp, ISP_LOGERR, notresp,
3735 sp->req_header.rqs_entry_type, oop, optr,
3736 nlooked);
3737 if (isp->isp_dblev & ISP_LOGDEBUG0) {
3738 isp_print_bytes(isp, "Queue Entry",
3739 QENTRY_LEN, sp);
3740 }
3741 MEMZERO(hp, QENTRY_LEN); /* PERF */
3742 continue;
3743 }
3744 buddaboom = 1;
3745 }
3746
3747 if (sp->req_header.rqs_flags & 0xf) {
3748#define _RQS_OFLAGS \
3749 ~(RQSFLAG_CONTINUATION|RQSFLAG_FULL|RQSFLAG_BADHEADER|RQSFLAG_BADPACKET)
3750 if (sp->req_header.rqs_flags & RQSFLAG_CONTINUATION) {
3751 isp_prt(isp, ISP_LOGWARN,
3752 "continuation segment");
3753 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp, optr);
3754 continue;
3755 }
3756 if (sp->req_header.rqs_flags & RQSFLAG_FULL) {
3757 isp_prt(isp, ISP_LOGDEBUG1,
3758 "internal queues full");
3759 /*
3760 * We'll synthesize a QUEUE FULL message below.
3761 */
3762 }
3763 if (sp->req_header.rqs_flags & RQSFLAG_BADHEADER) {
3764 isp_prt(isp, ISP_LOGERR, "bad header flag");
3765 buddaboom++;
3766 }
3767 if (sp->req_header.rqs_flags & RQSFLAG_BADPACKET) {
3768 isp_prt(isp, ISP_LOGERR, "bad request packet");
3769 buddaboom++;
3770 }
3771 if (sp->req_header.rqs_flags & _RQS_OFLAGS) {
3772 isp_prt(isp, ISP_LOGERR,
3773 "unknown flags (0x%x) in response",
3774 sp->req_header.rqs_flags);
3775 buddaboom++;
3776 }
3777#undef _RQS_OFLAGS
3778 }
3779 if (sp->req_handle > isp->isp_maxcmds || sp->req_handle < 1) {
3780 MEMZERO(hp, QENTRY_LEN); /* PERF */
3781 isp_prt(isp, ISP_LOGERR,
3782 "bad request handle %d (type 0x%x, flags 0x%x)",
3783 sp->req_handle, sp->req_header.rqs_entry_type,
3784 sp->req_header.rqs_flags);
3785 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp, optr);
3786 continue;
3787 }
3788 xs = isp_find_xs(isp, sp->req_handle);
3789 if (xs == NULL) {
3790 u_int8_t ts = sp->req_completion_status & 0xff;
3791 MEMZERO(hp, QENTRY_LEN); /* PERF */
3792 /*
3793 * Only whine if this isn't the expected fallout of
3794 * aborting the command.
3795 */
3796 if (sp->req_header.rqs_entry_type != RQSTYPE_RESPONSE) {
3797 isp_prt(isp, ISP_LOGERR,
3798 "cannot find handle 0x%x (type 0x%x)",
3799 sp->req_handle,
3800 sp->req_header.rqs_entry_type);
3801 } else if (ts != RQCS_ABORTED) {
3802 isp_prt(isp, ISP_LOGERR,
3803 "cannot find handle 0x%x (status 0x%x)",
3804 sp->req_handle, ts);
3805 }
3806 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp, optr);
3807 continue;
3808 }
3809 isp_destroy_handle(isp, sp->req_handle);
3810 if (sp->req_status_flags & RQSTF_BUS_RESET) {
3811 XS_SETERR(xs, HBA_BUSRESET);
3812 isp->isp_sendmarker |= (1 << XS_CHANNEL(xs));
3813 }
3814 if (buddaboom) {
3815 XS_SETERR(xs, HBA_BOTCH);
3816 }
3817
3818 if (IS_FC(isp) && (sp->req_scsi_status & RQCS_SV)) {
3819 /*
3820 * Fibre Channel F/W doesn't say we got status
3821 * if there's Sense Data instead. I guess they
3822 * think it goes w/o saying.
3823 */
3824 sp->req_state_flags |= RQSF_GOT_STATUS;
3825 }
3826 if (sp->req_state_flags & RQSF_GOT_STATUS) {
3827 *XS_STSP(xs) = sp->req_scsi_status & 0xff;
3828 }
3829
3830 switch (sp->req_header.rqs_entry_type) {
3831 case RQSTYPE_RESPONSE:
3832 XS_SET_STATE_STAT(isp, xs, sp);
3833 isp_parse_status(isp, sp, xs);
3834 if ((XS_NOERR(xs) || XS_ERR(xs) == HBA_NOERROR) &&
3835 (*XS_STSP(xs) == SCSI_BUSY)) {
3836 XS_SETERR(xs, HBA_TGTBSY);
3837 }
3838 if (IS_SCSI(isp)) {
3839 XS_RESID(xs) = sp->req_resid;
3840 if ((sp->req_state_flags & RQSF_GOT_STATUS) &&
3841 (*XS_STSP(xs) == SCSI_CHECK) &&
3842 (sp->req_state_flags & RQSF_GOT_SENSE)) {
3843 XS_SAVE_SENSE(xs, sp);
3844 }
3845 /*
3846 * A new synchronous rate was negotiated for
3847 * this target. Mark state such that we'll go
3848 * look up that which has changed later.
3849 */
3850 if (sp->req_status_flags & RQSTF_NEGOTIATION) {
3851 int t = XS_TGT(xs);
3852 sdparam *sdp = isp->isp_param;
3853 sdp += XS_CHANNEL(xs);
3854 sdp->isp_devparam[t].dev_refresh = 1;
3855 isp->isp_update |=
3856 (1 << XS_CHANNEL(xs));
3857 }
3858 } else {
3859 if (sp->req_status_flags & RQSF_XFER_COMPLETE) {
3860 XS_RESID(xs) = 0;
3861 } else if (sp->req_scsi_status & RQCS_RESID) {
3862 XS_RESID(xs) = sp->req_resid;
3863 } else {
3864 XS_RESID(xs) = 0;
3865 }
3866 if ((sp->req_state_flags & RQSF_GOT_STATUS) &&
3867 (*XS_STSP(xs) == SCSI_CHECK) &&
3868 (sp->req_scsi_status & RQCS_SV)) {
3869 XS_SAVE_SENSE(xs, sp);
3870 /* solely for the benefit of debug */
3871 sp->req_state_flags |= RQSF_GOT_SENSE;
3872 }
3873 }
3874 isp_prt(isp, ISP_LOGDEBUG2,
3875 "asked for %ld got resid %ld", (long) XS_XFRLEN(xs),
3876 (long) sp->req_resid);
3877 break;
3878 case RQSTYPE_REQUEST:
3879 if (sp->req_header.rqs_flags & RQSFLAG_FULL) {
3880 /*
3881 * Force Queue Full status.
3882 */
3883 *XS_STSP(xs) = SCSI_QFULL;
3884 XS_SETERR(xs, HBA_NOERROR);
3885 } else if (XS_NOERR(xs)) {
3886 /*
3887 * ????
3888 */
3889 isp_prt(isp, ISP_LOGDEBUG0,
3890 "Request Queue Entry bounced back");
3891 XS_SETERR(xs, HBA_BOTCH);
3892 }
3893 XS_RESID(xs) = XS_XFRLEN(xs);
3894 break;
3895 default:
3896 isp_prt(isp, ISP_LOGWARN,
3897 "unhandled response queue type 0x%x",
3898 sp->req_header.rqs_entry_type);
3899 if (XS_NOERR(xs)) {
3900 XS_SETERR(xs, HBA_BOTCH);
3901 }
3902 break;
3903 }
3904
3905 /*
3906 * Free any DMA resources. As a side effect, this may
3907 * also do any cache flushing necessary for data coherence. */
3908 if (XS_XFRLEN(xs)) {
3909 ISP_DMAFREE(isp, xs, sp->req_handle);
3910 }
3911
3912 if (((isp->isp_dblev & (ISP_LOGDEBUG2|ISP_LOGDEBUG3))) ||
3913 ((isp->isp_dblev & ISP_LOGDEBUG1) && ((!XS_NOERR(xs)) ||
3914 (*XS_STSP(xs) != SCSI_GOOD)))) {
3915 char skey;
3916 if (sp->req_state_flags & RQSF_GOT_SENSE) {
3917 skey = XS_SNSKEY(xs) & 0xf;
3918 if (skey < 10)
3919 skey += '0';
3920 else
3921 skey += 'a' - 10;
3922 } else if (*XS_STSP(xs) == SCSI_CHECK) {
3923 skey = '?';
3924 } else {
3925 skey = '.';
3926 }
3927 isp_prt(isp, ISP_LOGALL, finmsg, XS_CHANNEL(xs),
3928 XS_TGT(xs), XS_LUN(xs), XS_XFRLEN(xs), XS_RESID(xs),
3929 *XS_STSP(xs), skey, XS_ERR(xs));
3930 }
3931
3932 if (isp->isp_nactive > 0)
3933 isp->isp_nactive--;
3934 complist[ndone++] = xs; /* defer completion call until later */
3935 MEMZERO(hp, QENTRY_LEN); /* PERF */
3936 if (ndone == MAX_REQUESTQ_COMPLETIONS) {
3937 break;
3938 }
3939 }
3940
3941 /*
3942 * If we looked at any commands, then it's valid to find out
3943 * what the outpointer is. It also is a trigger to update the
3944 * ISP's notion of what we've seen so far.
3945 */
3946 if (nlooked) {
3947 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp, optr);
3948 /*
3949 * While we're at it, read the requst queue out pointer.
3950 */
3951 isp->isp_reqodx = READ_REQUEST_QUEUE_OUT_POINTER(isp);
3952 if (isp->isp_rscchiwater < ndone)
3953 isp->isp_rscchiwater = ndone;
3954 }
3955
3956 isp->isp_residx = optr;
3957 isp->isp_rspbsy = 0;
3958 for (i = 0; i < ndone; i++) {
3959 xs = complist[i];
3960 if (xs) {
3961 isp->isp_rsltccmplt++;
3962 isp_done(xs);
3963 }
3964 }
3965}
3966
3967/*
3968 * Support routines.
3969 */
3970
3971static int
3972isp_parse_async(struct ispsoftc *isp, u_int16_t mbox)
3973{
3974 int rval = 0;
3975 int bus;
3976
3977 if (IS_DUALBUS(isp)) {
3978 bus = ISP_READ(isp, OUTMAILBOX6);
3979 } else {
3980 bus = 0;
3981 }
3982 isp_prt(isp, ISP_LOGDEBUG2, "Async Mbox 0x%x", mbox);
3983
3984 switch (mbox) {
3985 case ASYNC_BUS_RESET:
3986 isp->isp_sendmarker |= (1 << bus);
3987#ifdef ISP_TARGET_MODE
3988 if (isp_target_async(isp, bus, mbox))
3989 rval = -1;
3990#endif
3991 isp_async(isp, ISPASYNC_BUS_RESET, &bus);
3992 break;
3993 case ASYNC_SYSTEM_ERROR:
3994#ifdef ISP_FW_CRASH_DUMP
3995 /*
3996 * If we have crash dumps enabled, it's up to the handler
3997 * for isp_async to reinit stuff and restart the firmware
3998 * after performing the crash dump. The reason we do things
3999 * this way is that we may need to activate a kernel thread
4000 * to do all the crash dump goop.
4001 */
4002 isp_async(isp, ISPASYNC_FW_CRASH, NULL);
4003#else
4004 isp_async(isp, ISPASYNC_FW_CRASH, NULL);
4005 isp_reinit(isp);
4006 isp_async(isp, ISPASYNC_FW_RESTARTED, NULL);
4007#endif
4008 rval = -1;
4009 break;
4010
4011 case ASYNC_RQS_XFER_ERR:
4012 isp_prt(isp, ISP_LOGERR, "Request Queue Transfer Error");
4013 break;
4014
4015 case ASYNC_RSP_XFER_ERR:
4016 isp_prt(isp, ISP_LOGERR, "Response Queue Transfer Error");
4017 break;
4018
4019 case ASYNC_QWAKEUP:
4020 /*
4021 * We've just been notified that the Queue has woken up.
4022 * We don't need to be chatty about this- just unlatch things
4023 * and move on.
4024 */
4025 mbox = READ_REQUEST_QUEUE_OUT_POINTER(isp);
4026 break;
4027
4028 case ASYNC_TIMEOUT_RESET:
4029 isp_prt(isp, ISP_LOGWARN,
4030 "timeout initiated SCSI bus reset of bus %d", bus);
4031 isp->isp_sendmarker |= (1 << bus);
4032#ifdef ISP_TARGET_MODE
4033 if (isp_target_async(isp, bus, mbox))
4034 rval = -1;
4035#endif
4036 break;
4037
4038 case ASYNC_DEVICE_RESET:
4039 isp_prt(isp, ISP_LOGINFO, "device reset on bus %d", bus);
4040 isp->isp_sendmarker |= (1 << bus);
4041#ifdef ISP_TARGET_MODE
4042 if (isp_target_async(isp, bus, mbox))
4043 rval = -1;
4044#endif
4045 break;
4046
4047 case ASYNC_EXTMSG_UNDERRUN:
4048 isp_prt(isp, ISP_LOGWARN, "extended message underrun");
4049 break;
4050
4051 case ASYNC_SCAM_INT:
4052 isp_prt(isp, ISP_LOGINFO, "SCAM interrupt");
4053 break;
4054
4055 case ASYNC_HUNG_SCSI:
4056 isp_prt(isp, ISP_LOGERR,
4057 "stalled SCSI Bus after DATA Overrun");
4058 /* XXX: Need to issue SCSI reset at this point */
4059 break;
4060
4061 case ASYNC_KILLED_BUS:
4062 isp_prt(isp, ISP_LOGERR, "SCSI Bus reset after DATA Overrun");
4063 break;
4064
4065 case ASYNC_BUS_TRANSIT:
4066 mbox = ISP_READ(isp, OUTMAILBOX2);
4067 switch (mbox & 0x1c00) {
4068 case SXP_PINS_LVD_MODE:
4069 isp_prt(isp, ISP_LOGINFO, "Transition to LVD mode");
4070 SDPARAM(isp)->isp_diffmode = 0;
4071 SDPARAM(isp)->isp_ultramode = 0;
4072 SDPARAM(isp)->isp_lvdmode = 1;
4073 break;
4074 case SXP_PINS_HVD_MODE:
4075 isp_prt(isp, ISP_LOGINFO,
4076 "Transition to Differential mode");
4077 SDPARAM(isp)->isp_diffmode = 1;
4078 SDPARAM(isp)->isp_ultramode = 0;
4079 SDPARAM(isp)->isp_lvdmode = 0;
4080 break;
4081 case SXP_PINS_SE_MODE:
4082 isp_prt(isp, ISP_LOGINFO,
4083 "Transition to Single Ended mode");
4084 SDPARAM(isp)->isp_diffmode = 0;
4085 SDPARAM(isp)->isp_ultramode = 1;
4086 SDPARAM(isp)->isp_lvdmode = 0;
4087 break;
4088 default:
4089 isp_prt(isp, ISP_LOGWARN,
4090 "Transition to Unknown Mode 0x%x", mbox);
4091 break;
4092 }
4093 /*
4094 * XXX: Set up to renegotiate again!
4095 */
4096 /* Can only be for a 1080... */
4097 isp->isp_sendmarker |= (1 << bus);
4098 break;
4099
4100 /*
4101 * We can use bus, which will always be zero for FC cards,
4102 * as a mailbox pattern accumulator to be checked below.
4103 */
4104 case ASYNC_RIO5:
4105 bus = 0x1ce; /* outgoing mailbox regs 1-3, 6-7 */
4106 break;
4107
4108 case ASYNC_RIO4:
4109 bus = 0x14e; /* outgoing mailbox regs 1-3, 6 */
4110 break;
4111
4112 case ASYNC_RIO3:
4113 bus = 0x10e; /* outgoing mailbox regs 1-3 */
4114 break;
4115
4116 case ASYNC_RIO2:
4117 bus = 0x106; /* outgoing mailbox regs 1-2 */
4118 break;
4119
4120 case ASYNC_RIO1:
4121 case ASYNC_CMD_CMPLT:
4122 bus = 0x102; /* outgoing mailbox regs 1 */
4123 break;
4124
4125 case ASYNC_RIO_RESP:
4126 return (rval);
4127
4128 case ASYNC_CTIO_DONE:
4129 {
4130#ifdef ISP_TARGET_MODE
4131 int handle =
4132 (ISP_READ(isp, OUTMAILBOX2) << 16) |
4133 (ISP_READ(isp, OUTMAILBOX1));
4134 if (isp_target_async(isp, handle, mbox)) {
4135 rval = -1;
4136 } else {
4137 /* count it as a fast posting intr */
4138 isp->isp_fphccmplt++;
4139 }
4140#else
4141 isp_prt(isp, ISP_LOGINFO, "Fast Posting CTIO done");
4142 isp->isp_fphccmplt++; /* count it as a fast posting intr */
4143#endif
4144 break;
4145 }
4146 case ASYNC_LIP_F8:
4147 case ASYNC_LIP_OCCURRED:
3625 if ((obits & (1 << i)) == 0) {
3626 continue;
3627 }
3628 isp->isp_mboxtmp[i] =
3629 ISP_READ(isp, MBOX_OFF(i));
3630 }
3631 if (isp->isp_mbxwrk0) {
3632 if (isp_mbox_continue(isp) == 0) {
3633 return;
3634 }
3635 }
3636 MBOX_NOTIFY_COMPLETE(isp);
3637 } else {
3638 isp_prt(isp, ISP_LOGWARN,
3639 "Mbox Command Async (0x%x) with no waiters",
3640 mbox);
3641 }
3642 } else if (isp_parse_async(isp, mbox) < 0) {
3643 return;
3644 }
3645 if ((IS_FC(isp) && mbox != ASYNC_RIO_RESP) ||
3646 isp->isp_state != ISP_RUNSTATE) {
3647 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
3648 ISP_WRITE(isp, BIU_SEMA, 0);
3649 return;
3650 }
3651 }
3652
3653 /*
3654 * We can't be getting this now.
3655 */
3656 if (isp->isp_state != ISP_RUNSTATE) {
3657 isp_prt(isp, ISP_LOGWARN,
3658 "interrupt (ISR=%x SEMA=%x) when not ready", isr, sema);
3659 /*
3660 * Thank you very much! *Burrrp*!
3661 */
3662 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp,
3663 READ_RESPONSE_QUEUE_IN_POINTER(isp));
3664
3665 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
3666 ISP_WRITE(isp, BIU_SEMA, 0);
3667 return;
3668 }
3669
3670 /*
3671 * Get the current Response Queue Out Pointer.
3672 *
3673 * If we're a 2300, we can ask what hardware what it thinks.
3674 */
3675 if (IS_23XX(isp)) {
3676 optr = ISP_READ(isp, isp->isp_respoutrp);
3677 /*
3678 * Debug: to be taken out eventually
3679 */
3680 if (isp->isp_residx != optr) {
3681 isp_prt(isp, ISP_LOGWARN, "optr %x soft optr %x",
3682 optr, isp->isp_residx);
3683 }
3684 } else {
3685 optr = isp->isp_residx;
3686 }
3687
3688 /*
3689 * You *must* read the Response Queue In Pointer
3690 * prior to clearing the RISC interrupt.
3691 *
3692 * Debounce the 2300 if revision less than 2.
3693 */
3694 if (IS_2100(isp) || (IS_2300(isp) && isp->isp_revision < 2)) {
3695 i = 0;
3696 do {
3697 iptr = READ_RESPONSE_QUEUE_IN_POINTER(isp);
3698 junk = READ_RESPONSE_QUEUE_IN_POINTER(isp);
3699 } while (junk != iptr && ++i < 1000);
3700
3701 if (iptr != junk) {
3702 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
3703 isp_prt(isp, ISP_LOGWARN,
3704 "Response Queue Out Pointer Unstable (%x, %x)",
3705 iptr, junk);
3706 return;
3707 }
3708 } else {
3709 iptr = READ_RESPONSE_QUEUE_IN_POINTER(isp);
3710 }
3711 isp->isp_resodx = iptr;
3712
3713
3714 if (optr == iptr && sema == 0) {
3715 /*
3716 * There are a lot of these- reasons unknown- mostly on
3717 * faster Alpha machines.
3718 *
3719 * I tried delaying after writing HCCR_CMD_CLEAR_RISC_INT to
3720 * make sure the old interrupt went away (to avoid 'ringing'
3721 * effects), but that didn't stop this from occurring.
3722 */
3723 if (IS_23XX(isp)) {
3724 USEC_DELAY(100);
3725 iptr = READ_RESPONSE_QUEUE_IN_POINTER(isp);
3726 junk = ISP_READ(isp, BIU_R2HSTSLO);
3727 } else {
3728 junk = ISP_READ(isp, BIU_ISR);
3729 }
3730 if (optr == iptr) {
3731 if (IS_23XX(isp)) {
3732 ;
3733 } else {
3734 sema = ISP_READ(isp, BIU_SEMA);
3735 mbox = ISP_READ(isp, OUTMAILBOX0);
3736 if ((sema & 0x3) && (mbox & 0x8000)) {
3737 goto again;
3738 }
3739 }
3740 isp->isp_intbogus++;
3741 isp_prt(isp, ISP_LOGDEBUG1,
3742 "bogus intr- isr %x (%x) iptr %x optr %x",
3743 isr, junk, iptr, optr);
3744 }
3745 }
3746 isp->isp_resodx = iptr;
3747 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
3748 ISP_WRITE(isp, BIU_SEMA, 0);
3749
3750 if (isp->isp_rspbsy) {
3751 return;
3752 }
3753 isp->isp_rspbsy = 1;
3754
3755 while (optr != iptr) {
3756 ispstatusreq_t local, *sp = &local;
3757 isphdr_t *hp;
3758 int type;
3759 u_int16_t oop;
3760 int buddaboom = 0;
3761
3762 hp = (isphdr_t *) ISP_QUEUE_ENTRY(isp->isp_result, optr);
3763 oop = optr;
3764 optr = ISP_NXT_QENTRY(optr, RESULT_QUEUE_LEN(isp));
3765 nlooked++;
3766 read_again:
3767 /*
3768 * Synchronize our view of this response queue entry.
3769 */
3770 MEMORYBARRIER(isp, SYNC_RESULT, oop, QENTRY_LEN);
3771
3772 type = isp_get_response_type(isp, hp);
3773
3774 if (type == RQSTYPE_RESPONSE) {
3775 isp_get_response(isp, (ispstatusreq_t *) hp, sp);
3776 } else if (type == RQSTYPE_RIO2) {
3777 isp_rio2_t rio;
3778 isp_get_rio2(isp, (isp_rio2_t *) hp, &rio);
3779 for (i = 0; i < rio.req_header.rqs_seqno; i++) {
3780 isp_fastpost_complete(isp, rio.req_handles[i]);
3781 }
3782 if (isp->isp_fpcchiwater < rio.req_header.rqs_seqno)
3783 isp->isp_fpcchiwater = rio.req_header.rqs_seqno;
3784 MEMZERO(hp, QENTRY_LEN); /* PERF */
3785 continue;
3786 } else {
3787 /*
3788 * Somebody reachable via isp_handle_other_response
3789 * may have updated the response queue pointers for
3790 * us, so we reload our goal index.
3791 */
3792 int i = isp_handle_other_response(isp, type, hp, &optr);
3793 if (i < 0) {
3794 goto read_again;
3795 } else if (i > 0) {
3796 iptr = isp->isp_resodx;
3797 MEMZERO(hp, QENTRY_LEN); /* PERF */
3798 continue;
3799 }
3800
3801 /*
3802 * After this point, we'll just look at the header as
3803 * we don't know how to deal with the rest of the
3804 * response.
3805 */
3806 isp_get_response(isp, (ispstatusreq_t *) hp, sp);
3807
3808 /*
3809 * It really has to be a bounced request just copied
3810 * from the request queue to the response queue. If
3811 * not, something bad has happened.
3812 */
3813 if (sp->req_header.rqs_entry_type != RQSTYPE_REQUEST) {
3814 isp_prt(isp, ISP_LOGERR, notresp,
3815 sp->req_header.rqs_entry_type, oop, optr,
3816 nlooked);
3817 if (isp->isp_dblev & ISP_LOGDEBUG0) {
3818 isp_print_bytes(isp, "Queue Entry",
3819 QENTRY_LEN, sp);
3820 }
3821 MEMZERO(hp, QENTRY_LEN); /* PERF */
3822 continue;
3823 }
3824 buddaboom = 1;
3825 }
3826
3827 if (sp->req_header.rqs_flags & 0xf) {
3828#define _RQS_OFLAGS \
3829 ~(RQSFLAG_CONTINUATION|RQSFLAG_FULL|RQSFLAG_BADHEADER|RQSFLAG_BADPACKET)
3830 if (sp->req_header.rqs_flags & RQSFLAG_CONTINUATION) {
3831 isp_prt(isp, ISP_LOGWARN,
3832 "continuation segment");
3833 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp, optr);
3834 continue;
3835 }
3836 if (sp->req_header.rqs_flags & RQSFLAG_FULL) {
3837 isp_prt(isp, ISP_LOGDEBUG1,
3838 "internal queues full");
3839 /*
3840 * We'll synthesize a QUEUE FULL message below.
3841 */
3842 }
3843 if (sp->req_header.rqs_flags & RQSFLAG_BADHEADER) {
3844 isp_prt(isp, ISP_LOGERR, "bad header flag");
3845 buddaboom++;
3846 }
3847 if (sp->req_header.rqs_flags & RQSFLAG_BADPACKET) {
3848 isp_prt(isp, ISP_LOGERR, "bad request packet");
3849 buddaboom++;
3850 }
3851 if (sp->req_header.rqs_flags & _RQS_OFLAGS) {
3852 isp_prt(isp, ISP_LOGERR,
3853 "unknown flags (0x%x) in response",
3854 sp->req_header.rqs_flags);
3855 buddaboom++;
3856 }
3857#undef _RQS_OFLAGS
3858 }
3859 if (sp->req_handle > isp->isp_maxcmds || sp->req_handle < 1) {
3860 MEMZERO(hp, QENTRY_LEN); /* PERF */
3861 isp_prt(isp, ISP_LOGERR,
3862 "bad request handle %d (type 0x%x, flags 0x%x)",
3863 sp->req_handle, sp->req_header.rqs_entry_type,
3864 sp->req_header.rqs_flags);
3865 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp, optr);
3866 continue;
3867 }
3868 xs = isp_find_xs(isp, sp->req_handle);
3869 if (xs == NULL) {
3870 u_int8_t ts = sp->req_completion_status & 0xff;
3871 MEMZERO(hp, QENTRY_LEN); /* PERF */
3872 /*
3873 * Only whine if this isn't the expected fallout of
3874 * aborting the command.
3875 */
3876 if (sp->req_header.rqs_entry_type != RQSTYPE_RESPONSE) {
3877 isp_prt(isp, ISP_LOGERR,
3878 "cannot find handle 0x%x (type 0x%x)",
3879 sp->req_handle,
3880 sp->req_header.rqs_entry_type);
3881 } else if (ts != RQCS_ABORTED) {
3882 isp_prt(isp, ISP_LOGERR,
3883 "cannot find handle 0x%x (status 0x%x)",
3884 sp->req_handle, ts);
3885 }
3886 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp, optr);
3887 continue;
3888 }
3889 isp_destroy_handle(isp, sp->req_handle);
3890 if (sp->req_status_flags & RQSTF_BUS_RESET) {
3891 XS_SETERR(xs, HBA_BUSRESET);
3892 isp->isp_sendmarker |= (1 << XS_CHANNEL(xs));
3893 }
3894 if (buddaboom) {
3895 XS_SETERR(xs, HBA_BOTCH);
3896 }
3897
3898 if (IS_FC(isp) && (sp->req_scsi_status & RQCS_SV)) {
3899 /*
3900 * Fibre Channel F/W doesn't say we got status
3901 * if there's Sense Data instead. I guess they
3902 * think it goes w/o saying.
3903 */
3904 sp->req_state_flags |= RQSF_GOT_STATUS;
3905 }
3906 if (sp->req_state_flags & RQSF_GOT_STATUS) {
3907 *XS_STSP(xs) = sp->req_scsi_status & 0xff;
3908 }
3909
3910 switch (sp->req_header.rqs_entry_type) {
3911 case RQSTYPE_RESPONSE:
3912 XS_SET_STATE_STAT(isp, xs, sp);
3913 isp_parse_status(isp, sp, xs);
3914 if ((XS_NOERR(xs) || XS_ERR(xs) == HBA_NOERROR) &&
3915 (*XS_STSP(xs) == SCSI_BUSY)) {
3916 XS_SETERR(xs, HBA_TGTBSY);
3917 }
3918 if (IS_SCSI(isp)) {
3919 XS_RESID(xs) = sp->req_resid;
3920 if ((sp->req_state_flags & RQSF_GOT_STATUS) &&
3921 (*XS_STSP(xs) == SCSI_CHECK) &&
3922 (sp->req_state_flags & RQSF_GOT_SENSE)) {
3923 XS_SAVE_SENSE(xs, sp);
3924 }
3925 /*
3926 * A new synchronous rate was negotiated for
3927 * this target. Mark state such that we'll go
3928 * look up that which has changed later.
3929 */
3930 if (sp->req_status_flags & RQSTF_NEGOTIATION) {
3931 int t = XS_TGT(xs);
3932 sdparam *sdp = isp->isp_param;
3933 sdp += XS_CHANNEL(xs);
3934 sdp->isp_devparam[t].dev_refresh = 1;
3935 isp->isp_update |=
3936 (1 << XS_CHANNEL(xs));
3937 }
3938 } else {
3939 if (sp->req_status_flags & RQSF_XFER_COMPLETE) {
3940 XS_RESID(xs) = 0;
3941 } else if (sp->req_scsi_status & RQCS_RESID) {
3942 XS_RESID(xs) = sp->req_resid;
3943 } else {
3944 XS_RESID(xs) = 0;
3945 }
3946 if ((sp->req_state_flags & RQSF_GOT_STATUS) &&
3947 (*XS_STSP(xs) == SCSI_CHECK) &&
3948 (sp->req_scsi_status & RQCS_SV)) {
3949 XS_SAVE_SENSE(xs, sp);
3950 /* solely for the benefit of debug */
3951 sp->req_state_flags |= RQSF_GOT_SENSE;
3952 }
3953 }
3954 isp_prt(isp, ISP_LOGDEBUG2,
3955 "asked for %ld got resid %ld", (long) XS_XFRLEN(xs),
3956 (long) sp->req_resid);
3957 break;
3958 case RQSTYPE_REQUEST:
3959 if (sp->req_header.rqs_flags & RQSFLAG_FULL) {
3960 /*
3961 * Force Queue Full status.
3962 */
3963 *XS_STSP(xs) = SCSI_QFULL;
3964 XS_SETERR(xs, HBA_NOERROR);
3965 } else if (XS_NOERR(xs)) {
3966 /*
3967 * ????
3968 */
3969 isp_prt(isp, ISP_LOGDEBUG0,
3970 "Request Queue Entry bounced back");
3971 XS_SETERR(xs, HBA_BOTCH);
3972 }
3973 XS_RESID(xs) = XS_XFRLEN(xs);
3974 break;
3975 default:
3976 isp_prt(isp, ISP_LOGWARN,
3977 "unhandled response queue type 0x%x",
3978 sp->req_header.rqs_entry_type);
3979 if (XS_NOERR(xs)) {
3980 XS_SETERR(xs, HBA_BOTCH);
3981 }
3982 break;
3983 }
3984
3985 /*
3986 * Free any DMA resources. As a side effect, this may
3987 * also do any cache flushing necessary for data coherence. */
3988 if (XS_XFRLEN(xs)) {
3989 ISP_DMAFREE(isp, xs, sp->req_handle);
3990 }
3991
3992 if (((isp->isp_dblev & (ISP_LOGDEBUG2|ISP_LOGDEBUG3))) ||
3993 ((isp->isp_dblev & ISP_LOGDEBUG1) && ((!XS_NOERR(xs)) ||
3994 (*XS_STSP(xs) != SCSI_GOOD)))) {
3995 char skey;
3996 if (sp->req_state_flags & RQSF_GOT_SENSE) {
3997 skey = XS_SNSKEY(xs) & 0xf;
3998 if (skey < 10)
3999 skey += '0';
4000 else
4001 skey += 'a' - 10;
4002 } else if (*XS_STSP(xs) == SCSI_CHECK) {
4003 skey = '?';
4004 } else {
4005 skey = '.';
4006 }
4007 isp_prt(isp, ISP_LOGALL, finmsg, XS_CHANNEL(xs),
4008 XS_TGT(xs), XS_LUN(xs), XS_XFRLEN(xs), XS_RESID(xs),
4009 *XS_STSP(xs), skey, XS_ERR(xs));
4010 }
4011
4012 if (isp->isp_nactive > 0)
4013 isp->isp_nactive--;
4014 complist[ndone++] = xs; /* defer completion call until later */
4015 MEMZERO(hp, QENTRY_LEN); /* PERF */
4016 if (ndone == MAX_REQUESTQ_COMPLETIONS) {
4017 break;
4018 }
4019 }
4020
4021 /*
4022 * If we looked at any commands, then it's valid to find out
4023 * what the outpointer is. It also is a trigger to update the
4024 * ISP's notion of what we've seen so far.
4025 */
4026 if (nlooked) {
4027 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp, optr);
4028 /*
4029 * While we're at it, read the requst queue out pointer.
4030 */
4031 isp->isp_reqodx = READ_REQUEST_QUEUE_OUT_POINTER(isp);
4032 if (isp->isp_rscchiwater < ndone)
4033 isp->isp_rscchiwater = ndone;
4034 }
4035
4036 isp->isp_residx = optr;
4037 isp->isp_rspbsy = 0;
4038 for (i = 0; i < ndone; i++) {
4039 xs = complist[i];
4040 if (xs) {
4041 isp->isp_rsltccmplt++;
4042 isp_done(xs);
4043 }
4044 }
4045}
4046
4047/*
4048 * Support routines.
4049 */
4050
4051static int
4052isp_parse_async(struct ispsoftc *isp, u_int16_t mbox)
4053{
4054 int rval = 0;
4055 int bus;
4056
4057 if (IS_DUALBUS(isp)) {
4058 bus = ISP_READ(isp, OUTMAILBOX6);
4059 } else {
4060 bus = 0;
4061 }
4062 isp_prt(isp, ISP_LOGDEBUG2, "Async Mbox 0x%x", mbox);
4063
4064 switch (mbox) {
4065 case ASYNC_BUS_RESET:
4066 isp->isp_sendmarker |= (1 << bus);
4067#ifdef ISP_TARGET_MODE
4068 if (isp_target_async(isp, bus, mbox))
4069 rval = -1;
4070#endif
4071 isp_async(isp, ISPASYNC_BUS_RESET, &bus);
4072 break;
4073 case ASYNC_SYSTEM_ERROR:
4074#ifdef ISP_FW_CRASH_DUMP
4075 /*
4076 * If we have crash dumps enabled, it's up to the handler
4077 * for isp_async to reinit stuff and restart the firmware
4078 * after performing the crash dump. The reason we do things
4079 * this way is that we may need to activate a kernel thread
4080 * to do all the crash dump goop.
4081 */
4082 isp_async(isp, ISPASYNC_FW_CRASH, NULL);
4083#else
4084 isp_async(isp, ISPASYNC_FW_CRASH, NULL);
4085 isp_reinit(isp);
4086 isp_async(isp, ISPASYNC_FW_RESTARTED, NULL);
4087#endif
4088 rval = -1;
4089 break;
4090
4091 case ASYNC_RQS_XFER_ERR:
4092 isp_prt(isp, ISP_LOGERR, "Request Queue Transfer Error");
4093 break;
4094
4095 case ASYNC_RSP_XFER_ERR:
4096 isp_prt(isp, ISP_LOGERR, "Response Queue Transfer Error");
4097 break;
4098
4099 case ASYNC_QWAKEUP:
4100 /*
4101 * We've just been notified that the Queue has woken up.
4102 * We don't need to be chatty about this- just unlatch things
4103 * and move on.
4104 */
4105 mbox = READ_REQUEST_QUEUE_OUT_POINTER(isp);
4106 break;
4107
4108 case ASYNC_TIMEOUT_RESET:
4109 isp_prt(isp, ISP_LOGWARN,
4110 "timeout initiated SCSI bus reset of bus %d", bus);
4111 isp->isp_sendmarker |= (1 << bus);
4112#ifdef ISP_TARGET_MODE
4113 if (isp_target_async(isp, bus, mbox))
4114 rval = -1;
4115#endif
4116 break;
4117
4118 case ASYNC_DEVICE_RESET:
4119 isp_prt(isp, ISP_LOGINFO, "device reset on bus %d", bus);
4120 isp->isp_sendmarker |= (1 << bus);
4121#ifdef ISP_TARGET_MODE
4122 if (isp_target_async(isp, bus, mbox))
4123 rval = -1;
4124#endif
4125 break;
4126
4127 case ASYNC_EXTMSG_UNDERRUN:
4128 isp_prt(isp, ISP_LOGWARN, "extended message underrun");
4129 break;
4130
4131 case ASYNC_SCAM_INT:
4132 isp_prt(isp, ISP_LOGINFO, "SCAM interrupt");
4133 break;
4134
4135 case ASYNC_HUNG_SCSI:
4136 isp_prt(isp, ISP_LOGERR,
4137 "stalled SCSI Bus after DATA Overrun");
4138 /* XXX: Need to issue SCSI reset at this point */
4139 break;
4140
4141 case ASYNC_KILLED_BUS:
4142 isp_prt(isp, ISP_LOGERR, "SCSI Bus reset after DATA Overrun");
4143 break;
4144
4145 case ASYNC_BUS_TRANSIT:
4146 mbox = ISP_READ(isp, OUTMAILBOX2);
4147 switch (mbox & 0x1c00) {
4148 case SXP_PINS_LVD_MODE:
4149 isp_prt(isp, ISP_LOGINFO, "Transition to LVD mode");
4150 SDPARAM(isp)->isp_diffmode = 0;
4151 SDPARAM(isp)->isp_ultramode = 0;
4152 SDPARAM(isp)->isp_lvdmode = 1;
4153 break;
4154 case SXP_PINS_HVD_MODE:
4155 isp_prt(isp, ISP_LOGINFO,
4156 "Transition to Differential mode");
4157 SDPARAM(isp)->isp_diffmode = 1;
4158 SDPARAM(isp)->isp_ultramode = 0;
4159 SDPARAM(isp)->isp_lvdmode = 0;
4160 break;
4161 case SXP_PINS_SE_MODE:
4162 isp_prt(isp, ISP_LOGINFO,
4163 "Transition to Single Ended mode");
4164 SDPARAM(isp)->isp_diffmode = 0;
4165 SDPARAM(isp)->isp_ultramode = 1;
4166 SDPARAM(isp)->isp_lvdmode = 0;
4167 break;
4168 default:
4169 isp_prt(isp, ISP_LOGWARN,
4170 "Transition to Unknown Mode 0x%x", mbox);
4171 break;
4172 }
4173 /*
4174 * XXX: Set up to renegotiate again!
4175 */
4176 /* Can only be for a 1080... */
4177 isp->isp_sendmarker |= (1 << bus);
4178 break;
4179
4180 /*
4181 * We can use bus, which will always be zero for FC cards,
4182 * as a mailbox pattern accumulator to be checked below.
4183 */
4184 case ASYNC_RIO5:
4185 bus = 0x1ce; /* outgoing mailbox regs 1-3, 6-7 */
4186 break;
4187
4188 case ASYNC_RIO4:
4189 bus = 0x14e; /* outgoing mailbox regs 1-3, 6 */
4190 break;
4191
4192 case ASYNC_RIO3:
4193 bus = 0x10e; /* outgoing mailbox regs 1-3 */
4194 break;
4195
4196 case ASYNC_RIO2:
4197 bus = 0x106; /* outgoing mailbox regs 1-2 */
4198 break;
4199
4200 case ASYNC_RIO1:
4201 case ASYNC_CMD_CMPLT:
4202 bus = 0x102; /* outgoing mailbox regs 1 */
4203 break;
4204
4205 case ASYNC_RIO_RESP:
4206 return (rval);
4207
4208 case ASYNC_CTIO_DONE:
4209 {
4210#ifdef ISP_TARGET_MODE
4211 int handle =
4212 (ISP_READ(isp, OUTMAILBOX2) << 16) |
4213 (ISP_READ(isp, OUTMAILBOX1));
4214 if (isp_target_async(isp, handle, mbox)) {
4215 rval = -1;
4216 } else {
4217 /* count it as a fast posting intr */
4218 isp->isp_fphccmplt++;
4219 }
4220#else
4221 isp_prt(isp, ISP_LOGINFO, "Fast Posting CTIO done");
4222 isp->isp_fphccmplt++; /* count it as a fast posting intr */
4223#endif
4224 break;
4225 }
4226 case ASYNC_LIP_F8:
4227 case ASYNC_LIP_OCCURRED:
4148 FCPARAM(isp)->isp_lipseq =
4149 ISP_READ(isp, OUTMAILBOX1);
4150 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4151 FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
4152 isp->isp_sendmarker = 1;
4153 isp_mark_getpdb_all(isp);
4154 isp_async(isp, ISPASYNC_LIP, NULL);
4155#ifdef ISP_TARGET_MODE
4156 if (isp_target_async(isp, bus, mbox))
4157 rval = -1;
4158#endif
4159 /*
4160 * We've had problems with data corruption occuring on
4161 * commands that complete (with no apparent error) after
4162 * we receive a LIP. This has been observed mostly on
4163 * Local Loop topologies. To be safe, let's just mark
4164 * all active commands as dead.
4165 */
4166 if (FCPARAM(isp)->isp_topo == TOPO_NL_PORT ||
4167 FCPARAM(isp)->isp_topo == TOPO_FL_PORT) {
4168 int i, j;
4169 for (i = j = 0; i < isp->isp_maxcmds; i++) {
4170 XS_T *xs;
4171 xs = isp->isp_xflist[i];
4172 if (xs != NULL) {
4173 j++;
4174 XS_SETERR(xs, HBA_BUSRESET);
4175 }
4176 }
4177 if (j) {
4178 isp_prt(isp, ISP_LOGERR,
4179 "LIP destroyed %d active commands", j);
4180 }
4181 }
4182 break;
4183
4184 case ASYNC_LOOP_UP:
4185 isp->isp_sendmarker = 1;
4186 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4187 FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
4188 isp_mark_getpdb_all(isp);
4189 isp_async(isp, ISPASYNC_LOOP_UP, NULL);
4190#ifdef ISP_TARGET_MODE
4191 if (isp_target_async(isp, bus, mbox))
4192 rval = -1;
4193#endif
4194 break;
4195
4196 case ASYNC_LOOP_DOWN:
4197 isp->isp_sendmarker = 1;
4198 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4199 FCPARAM(isp)->isp_loopstate = LOOP_NIL;
4200 isp_mark_getpdb_all(isp);
4201 isp_async(isp, ISPASYNC_LOOP_DOWN, NULL);
4202#ifdef ISP_TARGET_MODE
4203 if (isp_target_async(isp, bus, mbox))
4204 rval = -1;
4205#endif
4206 break;
4207
4208 case ASYNC_LOOP_RESET:
4209 isp->isp_sendmarker = 1;
4210 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4211 FCPARAM(isp)->isp_loopstate = LOOP_NIL;
4212 isp_mark_getpdb_all(isp);
4213 isp_async(isp, ISPASYNC_LOOP_RESET, NULL);
4214#ifdef ISP_TARGET_MODE
4215 if (isp_target_async(isp, bus, mbox))
4216 rval = -1;
4217#endif
4218 break;
4219
4220 case ASYNC_PDB_CHANGED:
4221 isp->isp_sendmarker = 1;
4222 FCPARAM(isp)->isp_loopstate = LOOP_PDB_RCVD;
4223 isp_mark_getpdb_all(isp);
4224 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_PDB);
4225 break;
4226
4227 case ASYNC_CHANGE_NOTIFY:
4228 /*
4229 * Not correct, but it will force us to rescan the loop.
4230 */
4231 FCPARAM(isp)->isp_loopstate = LOOP_PDB_RCVD;
4232 isp_mark_getpdb_all(isp);
4233 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_SNS);
4234 break;
4235
4236 case ASYNC_PTPMODE:
4237 if (FCPARAM(isp)->isp_onfabric)
4238 FCPARAM(isp)->isp_topo = TOPO_F_PORT;
4239 else
4240 FCPARAM(isp)->isp_topo = TOPO_N_PORT;
4241 isp_mark_getpdb_all(isp);
4242 isp->isp_sendmarker = 1;
4243 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4244 FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
4245 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_OTHER);
4246#ifdef ISP_TARGET_MODE
4247 if (isp_target_async(isp, bus, mbox))
4248 rval = -1;
4249#endif
4250 isp_prt(isp, ISP_LOGINFO, "Point-to-Point mode");
4251 break;
4252
4253 case ASYNC_CONNMODE:
4254 mbox = ISP_READ(isp, OUTMAILBOX1);
4255 isp_mark_getpdb_all(isp);
4256 switch (mbox) {
4257 case ISP_CONN_LOOP:
4258 isp_prt(isp, ISP_LOGINFO,
4259 "Point-to-Point -> Loop mode");
4260 break;
4261 case ISP_CONN_PTP:
4262 isp_prt(isp, ISP_LOGINFO,
4263 "Loop -> Point-to-Point mode");
4264 break;
4265 case ISP_CONN_BADLIP:
4266 isp_prt(isp, ISP_LOGWARN,
4267 "Point-to-Point -> Loop mode (BAD LIP)");
4268 break;
4269 case ISP_CONN_FATAL:
4270 isp_prt(isp, ISP_LOGERR, "FATAL CONNECTION ERROR");
4271#ifdef ISP_FW_CRASH_DUMP
4272 isp_async(isp, ISPASYNC_FW_CRASH, NULL);
4273#else
4274 isp_async(isp, ISPASYNC_FW_CRASH, NULL);
4275 isp_reinit(isp);
4276 isp_async(isp, ISPASYNC_FW_RESTARTED, NULL);
4277#endif
4278 return (-1);
4279 case ISP_CONN_LOOPBACK:
4280 isp_prt(isp, ISP_LOGWARN,
4281 "Looped Back in Point-to-Point mode");
4282 break;
4283 default:
4284 isp_prt(isp, ISP_LOGWARN,
4285 "Unknown connection mode (0x%x)", mbox);
4286 break;
4287 }
4288 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_OTHER);
4289 isp->isp_sendmarker = 1;
4290 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4291 FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
4292 break;
4293
4294 default:
4295 isp_prt(isp, ISP_LOGWARN, "Unknown Async Code 0x%x", mbox);
4296 break;
4297 }
4298
4299 if (bus & 0x100) {
4300 int i, nh;
4301 u_int16_t handles[16];
4302
4228 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4229 FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
4230 isp->isp_sendmarker = 1;
4231 isp_mark_getpdb_all(isp);
4232 isp_async(isp, ISPASYNC_LIP, NULL);
4233#ifdef ISP_TARGET_MODE
4234 if (isp_target_async(isp, bus, mbox))
4235 rval = -1;
4236#endif
4237 /*
4238 * We've had problems with data corruption occuring on
4239 * commands that complete (with no apparent error) after
4240 * we receive a LIP. This has been observed mostly on
4241 * Local Loop topologies. To be safe, let's just mark
4242 * all active commands as dead.
4243 */
4244 if (FCPARAM(isp)->isp_topo == TOPO_NL_PORT ||
4245 FCPARAM(isp)->isp_topo == TOPO_FL_PORT) {
4246 int i, j;
4247 for (i = j = 0; i < isp->isp_maxcmds; i++) {
4248 XS_T *xs;
4249 xs = isp->isp_xflist[i];
4250 if (xs != NULL) {
4251 j++;
4252 XS_SETERR(xs, HBA_BUSRESET);
4253 }
4254 }
4255 if (j) {
4256 isp_prt(isp, ISP_LOGERR,
4257 "LIP destroyed %d active commands", j);
4258 }
4259 }
4260 break;
4261
4262 case ASYNC_LOOP_UP:
4263 isp->isp_sendmarker = 1;
4264 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4265 FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
4266 isp_mark_getpdb_all(isp);
4267 isp_async(isp, ISPASYNC_LOOP_UP, NULL);
4268#ifdef ISP_TARGET_MODE
4269 if (isp_target_async(isp, bus, mbox))
4270 rval = -1;
4271#endif
4272 break;
4273
4274 case ASYNC_LOOP_DOWN:
4275 isp->isp_sendmarker = 1;
4276 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4277 FCPARAM(isp)->isp_loopstate = LOOP_NIL;
4278 isp_mark_getpdb_all(isp);
4279 isp_async(isp, ISPASYNC_LOOP_DOWN, NULL);
4280#ifdef ISP_TARGET_MODE
4281 if (isp_target_async(isp, bus, mbox))
4282 rval = -1;
4283#endif
4284 break;
4285
4286 case ASYNC_LOOP_RESET:
4287 isp->isp_sendmarker = 1;
4288 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4289 FCPARAM(isp)->isp_loopstate = LOOP_NIL;
4290 isp_mark_getpdb_all(isp);
4291 isp_async(isp, ISPASYNC_LOOP_RESET, NULL);
4292#ifdef ISP_TARGET_MODE
4293 if (isp_target_async(isp, bus, mbox))
4294 rval = -1;
4295#endif
4296 break;
4297
4298 case ASYNC_PDB_CHANGED:
4299 isp->isp_sendmarker = 1;
4300 FCPARAM(isp)->isp_loopstate = LOOP_PDB_RCVD;
4301 isp_mark_getpdb_all(isp);
4302 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_PDB);
4303 break;
4304
4305 case ASYNC_CHANGE_NOTIFY:
4306 /*
4307 * Not correct, but it will force us to rescan the loop.
4308 */
4309 FCPARAM(isp)->isp_loopstate = LOOP_PDB_RCVD;
4310 isp_mark_getpdb_all(isp);
4311 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_SNS);
4312 break;
4313
4314 case ASYNC_PTPMODE:
4315 if (FCPARAM(isp)->isp_onfabric)
4316 FCPARAM(isp)->isp_topo = TOPO_F_PORT;
4317 else
4318 FCPARAM(isp)->isp_topo = TOPO_N_PORT;
4319 isp_mark_getpdb_all(isp);
4320 isp->isp_sendmarker = 1;
4321 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4322 FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
4323 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_OTHER);
4324#ifdef ISP_TARGET_MODE
4325 if (isp_target_async(isp, bus, mbox))
4326 rval = -1;
4327#endif
4328 isp_prt(isp, ISP_LOGINFO, "Point-to-Point mode");
4329 break;
4330
4331 case ASYNC_CONNMODE:
4332 mbox = ISP_READ(isp, OUTMAILBOX1);
4333 isp_mark_getpdb_all(isp);
4334 switch (mbox) {
4335 case ISP_CONN_LOOP:
4336 isp_prt(isp, ISP_LOGINFO,
4337 "Point-to-Point -> Loop mode");
4338 break;
4339 case ISP_CONN_PTP:
4340 isp_prt(isp, ISP_LOGINFO,
4341 "Loop -> Point-to-Point mode");
4342 break;
4343 case ISP_CONN_BADLIP:
4344 isp_prt(isp, ISP_LOGWARN,
4345 "Point-to-Point -> Loop mode (BAD LIP)");
4346 break;
4347 case ISP_CONN_FATAL:
4348 isp_prt(isp, ISP_LOGERR, "FATAL CONNECTION ERROR");
4349#ifdef ISP_FW_CRASH_DUMP
4350 isp_async(isp, ISPASYNC_FW_CRASH, NULL);
4351#else
4352 isp_async(isp, ISPASYNC_FW_CRASH, NULL);
4353 isp_reinit(isp);
4354 isp_async(isp, ISPASYNC_FW_RESTARTED, NULL);
4355#endif
4356 return (-1);
4357 case ISP_CONN_LOOPBACK:
4358 isp_prt(isp, ISP_LOGWARN,
4359 "Looped Back in Point-to-Point mode");
4360 break;
4361 default:
4362 isp_prt(isp, ISP_LOGWARN,
4363 "Unknown connection mode (0x%x)", mbox);
4364 break;
4365 }
4366 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_OTHER);
4367 isp->isp_sendmarker = 1;
4368 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4369 FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
4370 break;
4371
4372 default:
4373 isp_prt(isp, ISP_LOGWARN, "Unknown Async Code 0x%x", mbox);
4374 break;
4375 }
4376
4377 if (bus & 0x100) {
4378 int i, nh;
4379 u_int16_t handles[16];
4380
4303 for (nh = 0, i = 1; i < MAX_MAILBOX; i++) {
4381 for (nh = 0, i = 1; i < MAX_MAILBOX(isp); i++) {
4304 if ((bus & (1 << i)) == 0) {
4305 continue;
4306 }
4307 handles[nh++] = ISP_READ(isp, MBOX_OFF(i));
4308 }
4309 for (i = 0; i < nh; i++) {
4310 isp_fastpost_complete(isp, handles[i]);
4311 isp_prt(isp, ISP_LOGDEBUG3,
4312 "fast post completion of %u", handles[i]);
4313 }
4314 if (isp->isp_fpcchiwater < nh)
4315 isp->isp_fpcchiwater = nh;
4316 } else {
4317 isp->isp_intoasync++;
4318 }
4319 return (rval);
4320}
4321
4322/*
4323 * Handle other response entries. A pointer to the request queue output
4324 * index is here in case we want to eat several entries at once, although
4325 * this is not used currently.
4326 */
4327
4328static int
4329isp_handle_other_response(struct ispsoftc *isp, int type,
4330 isphdr_t *hp, u_int16_t *optrp)
4331{
4332 switch (type) {
4333 case RQSTYPE_STATUS_CONT:
4334 isp_prt(isp, ISP_LOGINFO, "Ignored Continuation Response");
4335 return (1);
4336 case RQSTYPE_ATIO:
4337 case RQSTYPE_CTIO:
4338 case RQSTYPE_ENABLE_LUN:
4339 case RQSTYPE_MODIFY_LUN:
4340 case RQSTYPE_NOTIFY:
4341 case RQSTYPE_NOTIFY_ACK:
4342 case RQSTYPE_CTIO1:
4343 case RQSTYPE_ATIO2:
4344 case RQSTYPE_CTIO2:
4345 case RQSTYPE_CTIO3:
4346 isp->isp_rsltccmplt++; /* count as a response completion */
4347#ifdef ISP_TARGET_MODE
4348 if (isp_target_notify(isp, (ispstatusreq_t *) hp, optrp)) {
4349 return (1);
4350 }
4351#endif
4352 /* FALLTHROUGH */
4353 case RQSTYPE_REQUEST:
4354 default:
4355 USEC_DELAY(100);
4356 if (type != isp_get_response_type(isp, hp)) {
4357 /*
4358 * This is questionable- we're just papering over
4359 * something we've seen on SMP linux in target
4360 * mode- we don't really know what's happening
4361 * here that causes us to think we've gotten
4362 * an entry, but that either the entry isn't
4363 * filled out yet or our CPU read data is stale.
4364 */
4365 isp_prt(isp, ISP_LOGINFO,
4366 "unstable type in response queue");
4367 return (-1);
4368 }
4369 isp_prt(isp, ISP_LOGWARN, "Unhandled Response Type 0x%x",
4370 isp_get_response_type(isp, hp));
4371 if (isp_async(isp, ISPASYNC_UNHANDLED_RESPONSE, hp)) {
4372 return (1);
4373 }
4374 return (0);
4375 }
4376}
4377
4378static void
4379isp_parse_status(struct ispsoftc *isp, ispstatusreq_t *sp, XS_T *xs)
4380{
4381 switch (sp->req_completion_status & 0xff) {
4382 case RQCS_COMPLETE:
4383 if (XS_NOERR(xs)) {
4384 XS_SETERR(xs, HBA_NOERROR);
4385 }
4386 return;
4387
4388 case RQCS_INCOMPLETE:
4389 if ((sp->req_state_flags & RQSF_GOT_TARGET) == 0) {
4390 isp_prt(isp, ISP_LOGDEBUG1,
4391 "Selection Timeout for %d.%d.%d",
4392 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4393 if (XS_NOERR(xs)) {
4394 XS_SETERR(xs, HBA_SELTIMEOUT);
4395 }
4396 return;
4397 }
4398 isp_prt(isp, ISP_LOGERR,
4399 "command incomplete for %d.%d.%d, state 0x%x",
4400 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs),
4401 sp->req_state_flags);
4402 break;
4403
4404 case RQCS_DMA_ERROR:
4405 isp_prt(isp, ISP_LOGERR, "DMA error for command on %d.%d.%d",
4406 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4407 break;
4408
4409 case RQCS_TRANSPORT_ERROR:
4410 {
4411 char buf[172];
4412 SNPRINTF(buf, sizeof (buf), "states=>");
4413 if (sp->req_state_flags & RQSF_GOT_BUS) {
4414 SNPRINTF(buf, sizeof (buf), "%s GOT_BUS", buf);
4415 }
4416 if (sp->req_state_flags & RQSF_GOT_TARGET) {
4417 SNPRINTF(buf, sizeof (buf), "%s GOT_TGT", buf);
4418 }
4419 if (sp->req_state_flags & RQSF_SENT_CDB) {
4420 SNPRINTF(buf, sizeof (buf), "%s SENT_CDB", buf);
4421 }
4422 if (sp->req_state_flags & RQSF_XFRD_DATA) {
4423 SNPRINTF(buf, sizeof (buf), "%s XFRD_DATA", buf);
4424 }
4425 if (sp->req_state_flags & RQSF_GOT_STATUS) {
4426 SNPRINTF(buf, sizeof (buf), "%s GOT_STS", buf);
4427 }
4428 if (sp->req_state_flags & RQSF_GOT_SENSE) {
4429 SNPRINTF(buf, sizeof (buf), "%s GOT_SNS", buf);
4430 }
4431 if (sp->req_state_flags & RQSF_XFER_COMPLETE) {
4432 SNPRINTF(buf, sizeof (buf), "%s XFR_CMPLT", buf);
4433 }
4434 SNPRINTF(buf, sizeof (buf), "%s\nstatus=>", buf);
4435 if (sp->req_status_flags & RQSTF_DISCONNECT) {
4436 SNPRINTF(buf, sizeof (buf), "%s Disconnect", buf);
4437 }
4438 if (sp->req_status_flags & RQSTF_SYNCHRONOUS) {
4439 SNPRINTF(buf, sizeof (buf), "%s Sync_xfr", buf);
4440 }
4441 if (sp->req_status_flags & RQSTF_PARITY_ERROR) {
4442 SNPRINTF(buf, sizeof (buf), "%s Parity", buf);
4443 }
4444 if (sp->req_status_flags & RQSTF_BUS_RESET) {
4445 SNPRINTF(buf, sizeof (buf), "%s Bus_Reset", buf);
4446 }
4447 if (sp->req_status_flags & RQSTF_DEVICE_RESET) {
4448 SNPRINTF(buf, sizeof (buf), "%s Device_Reset", buf);
4449 }
4450 if (sp->req_status_flags & RQSTF_ABORTED) {
4451 SNPRINTF(buf, sizeof (buf), "%s Aborted", buf);
4452 }
4453 if (sp->req_status_flags & RQSTF_TIMEOUT) {
4454 SNPRINTF(buf, sizeof (buf), "%s Timeout", buf);
4455 }
4456 if (sp->req_status_flags & RQSTF_NEGOTIATION) {
4457 SNPRINTF(buf, sizeof (buf), "%s Negotiation", buf);
4458 }
4459 isp_prt(isp, ISP_LOGERR, "%s", buf);
4460 isp_prt(isp, ISP_LOGERR, "transport error for %d.%d.%d:\n%s",
4461 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs), buf);
4462 break;
4463 }
4464 case RQCS_RESET_OCCURRED:
4465 isp_prt(isp, ISP_LOGWARN,
4466 "bus reset destroyed command for %d.%d.%d",
4467 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4468 isp->isp_sendmarker |= (1 << XS_CHANNEL(xs));
4469 if (XS_NOERR(xs)) {
4470 XS_SETERR(xs, HBA_BUSRESET);
4471 }
4472 return;
4473
4474 case RQCS_ABORTED:
4475 isp_prt(isp, ISP_LOGERR, "command aborted for %d.%d.%d",
4476 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4477 isp->isp_sendmarker |= (1 << XS_CHANNEL(xs));
4478 if (XS_NOERR(xs)) {
4479 XS_SETERR(xs, HBA_ABORTED);
4480 }
4481 return;
4482
4483 case RQCS_TIMEOUT:
4484 isp_prt(isp, ISP_LOGWARN, "command timed out for %d.%d.%d",
4485 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4486 /*
4487 * Check to see if we logged out the device.
4488 */
4489 if (IS_FC(isp)) {
4490 if ((sp->req_completion_status & RQSTF_LOGOUT) &&
4491 FCPARAM(isp)->portdb[XS_TGT(xs)].valid &&
4492 FCPARAM(isp)->portdb[XS_TGT(xs)].fabric_dev) {
4493 FCPARAM(isp)->portdb[XS_TGT(xs)].relogin = 1;
4494 }
4495 }
4496 if (XS_NOERR(xs)) {
4497 XS_SETERR(xs, HBA_CMDTIMEOUT);
4498 }
4499 return;
4500
4501 case RQCS_DATA_OVERRUN:
4502 XS_RESID(xs) = sp->req_resid;
4503 isp_prt(isp, ISP_LOGERR, "data overrun for command on %d.%d.%d",
4504 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4505 if (XS_NOERR(xs)) {
4506 XS_SETERR(xs, HBA_DATAOVR);
4507 }
4508 return;
4509
4510 case RQCS_COMMAND_OVERRUN:
4511 isp_prt(isp, ISP_LOGERR,
4512 "command overrun for command on %d.%d.%d",
4513 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4514 break;
4515
4516 case RQCS_STATUS_OVERRUN:
4517 isp_prt(isp, ISP_LOGERR,
4518 "status overrun for command on %d.%d.%d",
4519 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4520 break;
4521
4522 case RQCS_BAD_MESSAGE:
4523 isp_prt(isp, ISP_LOGERR,
4524 "msg not COMMAND COMPLETE after status %d.%d.%d",
4525 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4526 break;
4527
4528 case RQCS_NO_MESSAGE_OUT:
4529 isp_prt(isp, ISP_LOGERR,
4530 "No MESSAGE OUT phase after selection on %d.%d.%d",
4531 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4532 break;
4533
4534 case RQCS_EXT_ID_FAILED:
4535 isp_prt(isp, ISP_LOGERR, "EXTENDED IDENTIFY failed %d.%d.%d",
4536 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4537 break;
4538
4539 case RQCS_IDE_MSG_FAILED:
4540 isp_prt(isp, ISP_LOGERR,
4541 "INITIATOR DETECTED ERROR rejected by %d.%d.%d",
4542 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4543 break;
4544
4545 case RQCS_ABORT_MSG_FAILED:
4546 isp_prt(isp, ISP_LOGERR, "ABORT OPERATION rejected by %d.%d.%d",
4547 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4548 break;
4549
4550 case RQCS_REJECT_MSG_FAILED:
4551 isp_prt(isp, ISP_LOGERR, "MESSAGE REJECT rejected by %d.%d.%d",
4552 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4553 break;
4554
4555 case RQCS_NOP_MSG_FAILED:
4556 isp_prt(isp, ISP_LOGERR, "NOP rejected by %d.%d.%d",
4557 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4558 break;
4559
4560 case RQCS_PARITY_ERROR_MSG_FAILED:
4561 isp_prt(isp, ISP_LOGERR,
4562 "MESSAGE PARITY ERROR rejected by %d.%d.%d",
4563 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4564 break;
4565
4566 case RQCS_DEVICE_RESET_MSG_FAILED:
4567 isp_prt(isp, ISP_LOGWARN,
4568 "BUS DEVICE RESET rejected by %d.%d.%d",
4569 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4570 break;
4571
4572 case RQCS_ID_MSG_FAILED:
4573 isp_prt(isp, ISP_LOGERR, "IDENTIFY rejected by %d.%d.%d",
4574 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4575 break;
4576
4577 case RQCS_UNEXP_BUS_FREE:
4578 isp_prt(isp, ISP_LOGERR, "%d.%d.%d had an unexpected bus free",
4579 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4580 break;
4581
4582 case RQCS_DATA_UNDERRUN:
4583 {
4584 if (IS_FC(isp)) {
4585 int ru_marked = (sp->req_scsi_status & RQCS_RU) != 0;
4586 if (!ru_marked || sp->req_resid > XS_XFRLEN(xs)) {
4587 isp_prt(isp, ISP_LOGWARN, bun, XS_TGT(xs),
4588 XS_LUN(xs), XS_XFRLEN(xs), sp->req_resid,
4589 (ru_marked)? "marked" : "not marked");
4590 if (XS_NOERR(xs)) {
4591 XS_SETERR(xs, HBA_BOTCH);
4592 }
4593 return;
4594 }
4595 }
4596 XS_RESID(xs) = sp->req_resid;
4597 if (XS_NOERR(xs)) {
4598 XS_SETERR(xs, HBA_NOERROR);
4599 }
4600 return;
4601 }
4602
4603 case RQCS_XACT_ERR1:
4604 isp_prt(isp, ISP_LOGERR, xact1, XS_CHANNEL(xs),
4605 XS_TGT(xs), XS_LUN(xs));
4606 break;
4607
4608 case RQCS_XACT_ERR2:
4609 isp_prt(isp, ISP_LOGERR, xact2,
4610 XS_LUN(xs), XS_TGT(xs), XS_CHANNEL(xs));
4611 break;
4612
4613 case RQCS_XACT_ERR3:
4614 isp_prt(isp, ISP_LOGERR, xact3,
4615 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4616 break;
4617
4618 case RQCS_BAD_ENTRY:
4619 isp_prt(isp, ISP_LOGERR, "Invalid IOCB entry type detected");
4620 break;
4621
4622 case RQCS_QUEUE_FULL:
4623 isp_prt(isp, ISP_LOGDEBUG0,
4624 "internal queues full for %d.%d.%d status 0x%x",
4625 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs), *XS_STSP(xs));
4626
4627 /*
4628 * If QFULL or some other status byte is set, then this
4629 * isn't an error, per se.
4630 *
4631 * Unfortunately, some QLogic f/w writers have, in
4632 * some cases, ommitted to *set* status to QFULL.
4633 *
4634
4635 if (*XS_STSP(xs) != SCSI_GOOD && XS_NOERR(xs)) {
4636 XS_SETERR(xs, HBA_NOERROR);
4637 return;
4638 }
4639
4640 *
4641 *
4642 */
4643
4644 *XS_STSP(xs) = SCSI_QFULL;
4645 XS_SETERR(xs, HBA_NOERROR);
4646 return;
4647
4648 case RQCS_PHASE_SKIPPED:
4649 isp_prt(isp, ISP_LOGERR, pskip, XS_CHANNEL(xs),
4650 XS_TGT(xs), XS_LUN(xs));
4651 break;
4652
4653 case RQCS_ARQS_FAILED:
4654 isp_prt(isp, ISP_LOGERR,
4655 "Auto Request Sense failed for %d.%d.%d",
4656 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4657 if (XS_NOERR(xs)) {
4658 XS_SETERR(xs, HBA_ARQFAIL);
4659 }
4660 return;
4661
4662 case RQCS_WIDE_FAILED:
4663 isp_prt(isp, ISP_LOGERR,
4664 "Wide Negotiation failed for %d.%d.%d",
4665 XS_TGT(xs), XS_LUN(xs), XS_CHANNEL(xs));
4666 if (IS_SCSI(isp)) {
4667 sdparam *sdp = isp->isp_param;
4668 sdp += XS_CHANNEL(xs);
4669 sdp->isp_devparam[XS_TGT(xs)].goal_flags &= ~DPARM_WIDE;
4670 sdp->isp_devparam[XS_TGT(xs)].dev_update = 1;
4671 isp->isp_update |= (1 << XS_CHANNEL(xs));
4672 }
4673 if (XS_NOERR(xs)) {
4674 XS_SETERR(xs, HBA_NOERROR);
4675 }
4676 return;
4677
4678 case RQCS_SYNCXFER_FAILED:
4679 isp_prt(isp, ISP_LOGERR,
4680 "SDTR Message failed for target %d.%d.%d",
4681 XS_TGT(xs), XS_LUN(xs), XS_CHANNEL(xs));
4682 if (IS_SCSI(isp)) {
4683 sdparam *sdp = isp->isp_param;
4684 sdp += XS_CHANNEL(xs);
4685 sdp->isp_devparam[XS_TGT(xs)].goal_flags &= ~DPARM_SYNC;
4686 sdp->isp_devparam[XS_TGT(xs)].dev_update = 1;
4687 isp->isp_update |= (1 << XS_CHANNEL(xs));
4688 }
4689 break;
4690
4691 case RQCS_LVD_BUSERR:
4692 isp_prt(isp, ISP_LOGERR,
4693 "Bad LVD condition while talking to %d.%d.%d",
4694 XS_TGT(xs), XS_LUN(xs), XS_CHANNEL(xs));
4695 break;
4696
4697 case RQCS_PORT_UNAVAILABLE:
4698 /*
4699 * No such port on the loop. Moral equivalent of SELTIMEO
4700 */
4701 case RQCS_PORT_LOGGED_OUT:
4702 /*
4703 * It was there (maybe)- treat as a selection timeout.
4704 */
4705 if ((sp->req_completion_status & 0xff) == RQCS_PORT_UNAVAILABLE)
4706 isp_prt(isp, ISP_LOGINFO,
4707 "port unavailable for target %d", XS_TGT(xs));
4708 else
4709 isp_prt(isp, ISP_LOGINFO,
4710 "port logout for target %d", XS_TGT(xs));
4711 /*
4712 * If we're on a local loop, force a LIP (which is overkill)
4713 * to force a re-login of this unit. If we're on fabric,
4714 * then we'll have to relogin as a matter of course.
4715 */
4716 if (FCPARAM(isp)->isp_topo == TOPO_NL_PORT ||
4717 FCPARAM(isp)->isp_topo == TOPO_FL_PORT) {
4718 mbreg_t mbs;
4382 if ((bus & (1 << i)) == 0) {
4383 continue;
4384 }
4385 handles[nh++] = ISP_READ(isp, MBOX_OFF(i));
4386 }
4387 for (i = 0; i < nh; i++) {
4388 isp_fastpost_complete(isp, handles[i]);
4389 isp_prt(isp, ISP_LOGDEBUG3,
4390 "fast post completion of %u", handles[i]);
4391 }
4392 if (isp->isp_fpcchiwater < nh)
4393 isp->isp_fpcchiwater = nh;
4394 } else {
4395 isp->isp_intoasync++;
4396 }
4397 return (rval);
4398}
4399
4400/*
4401 * Handle other response entries. A pointer to the request queue output
4402 * index is here in case we want to eat several entries at once, although
4403 * this is not used currently.
4404 */
4405
4406static int
4407isp_handle_other_response(struct ispsoftc *isp, int type,
4408 isphdr_t *hp, u_int16_t *optrp)
4409{
4410 switch (type) {
4411 case RQSTYPE_STATUS_CONT:
4412 isp_prt(isp, ISP_LOGINFO, "Ignored Continuation Response");
4413 return (1);
4414 case RQSTYPE_ATIO:
4415 case RQSTYPE_CTIO:
4416 case RQSTYPE_ENABLE_LUN:
4417 case RQSTYPE_MODIFY_LUN:
4418 case RQSTYPE_NOTIFY:
4419 case RQSTYPE_NOTIFY_ACK:
4420 case RQSTYPE_CTIO1:
4421 case RQSTYPE_ATIO2:
4422 case RQSTYPE_CTIO2:
4423 case RQSTYPE_CTIO3:
4424 isp->isp_rsltccmplt++; /* count as a response completion */
4425#ifdef ISP_TARGET_MODE
4426 if (isp_target_notify(isp, (ispstatusreq_t *) hp, optrp)) {
4427 return (1);
4428 }
4429#endif
4430 /* FALLTHROUGH */
4431 case RQSTYPE_REQUEST:
4432 default:
4433 USEC_DELAY(100);
4434 if (type != isp_get_response_type(isp, hp)) {
4435 /*
4436 * This is questionable- we're just papering over
4437 * something we've seen on SMP linux in target
4438 * mode- we don't really know what's happening
4439 * here that causes us to think we've gotten
4440 * an entry, but that either the entry isn't
4441 * filled out yet or our CPU read data is stale.
4442 */
4443 isp_prt(isp, ISP_LOGINFO,
4444 "unstable type in response queue");
4445 return (-1);
4446 }
4447 isp_prt(isp, ISP_LOGWARN, "Unhandled Response Type 0x%x",
4448 isp_get_response_type(isp, hp));
4449 if (isp_async(isp, ISPASYNC_UNHANDLED_RESPONSE, hp)) {
4450 return (1);
4451 }
4452 return (0);
4453 }
4454}
4455
4456static void
4457isp_parse_status(struct ispsoftc *isp, ispstatusreq_t *sp, XS_T *xs)
4458{
4459 switch (sp->req_completion_status & 0xff) {
4460 case RQCS_COMPLETE:
4461 if (XS_NOERR(xs)) {
4462 XS_SETERR(xs, HBA_NOERROR);
4463 }
4464 return;
4465
4466 case RQCS_INCOMPLETE:
4467 if ((sp->req_state_flags & RQSF_GOT_TARGET) == 0) {
4468 isp_prt(isp, ISP_LOGDEBUG1,
4469 "Selection Timeout for %d.%d.%d",
4470 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4471 if (XS_NOERR(xs)) {
4472 XS_SETERR(xs, HBA_SELTIMEOUT);
4473 }
4474 return;
4475 }
4476 isp_prt(isp, ISP_LOGERR,
4477 "command incomplete for %d.%d.%d, state 0x%x",
4478 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs),
4479 sp->req_state_flags);
4480 break;
4481
4482 case RQCS_DMA_ERROR:
4483 isp_prt(isp, ISP_LOGERR, "DMA error for command on %d.%d.%d",
4484 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4485 break;
4486
4487 case RQCS_TRANSPORT_ERROR:
4488 {
4489 char buf[172];
4490 SNPRINTF(buf, sizeof (buf), "states=>");
4491 if (sp->req_state_flags & RQSF_GOT_BUS) {
4492 SNPRINTF(buf, sizeof (buf), "%s GOT_BUS", buf);
4493 }
4494 if (sp->req_state_flags & RQSF_GOT_TARGET) {
4495 SNPRINTF(buf, sizeof (buf), "%s GOT_TGT", buf);
4496 }
4497 if (sp->req_state_flags & RQSF_SENT_CDB) {
4498 SNPRINTF(buf, sizeof (buf), "%s SENT_CDB", buf);
4499 }
4500 if (sp->req_state_flags & RQSF_XFRD_DATA) {
4501 SNPRINTF(buf, sizeof (buf), "%s XFRD_DATA", buf);
4502 }
4503 if (sp->req_state_flags & RQSF_GOT_STATUS) {
4504 SNPRINTF(buf, sizeof (buf), "%s GOT_STS", buf);
4505 }
4506 if (sp->req_state_flags & RQSF_GOT_SENSE) {
4507 SNPRINTF(buf, sizeof (buf), "%s GOT_SNS", buf);
4508 }
4509 if (sp->req_state_flags & RQSF_XFER_COMPLETE) {
4510 SNPRINTF(buf, sizeof (buf), "%s XFR_CMPLT", buf);
4511 }
4512 SNPRINTF(buf, sizeof (buf), "%s\nstatus=>", buf);
4513 if (sp->req_status_flags & RQSTF_DISCONNECT) {
4514 SNPRINTF(buf, sizeof (buf), "%s Disconnect", buf);
4515 }
4516 if (sp->req_status_flags & RQSTF_SYNCHRONOUS) {
4517 SNPRINTF(buf, sizeof (buf), "%s Sync_xfr", buf);
4518 }
4519 if (sp->req_status_flags & RQSTF_PARITY_ERROR) {
4520 SNPRINTF(buf, sizeof (buf), "%s Parity", buf);
4521 }
4522 if (sp->req_status_flags & RQSTF_BUS_RESET) {
4523 SNPRINTF(buf, sizeof (buf), "%s Bus_Reset", buf);
4524 }
4525 if (sp->req_status_flags & RQSTF_DEVICE_RESET) {
4526 SNPRINTF(buf, sizeof (buf), "%s Device_Reset", buf);
4527 }
4528 if (sp->req_status_flags & RQSTF_ABORTED) {
4529 SNPRINTF(buf, sizeof (buf), "%s Aborted", buf);
4530 }
4531 if (sp->req_status_flags & RQSTF_TIMEOUT) {
4532 SNPRINTF(buf, sizeof (buf), "%s Timeout", buf);
4533 }
4534 if (sp->req_status_flags & RQSTF_NEGOTIATION) {
4535 SNPRINTF(buf, sizeof (buf), "%s Negotiation", buf);
4536 }
4537 isp_prt(isp, ISP_LOGERR, "%s", buf);
4538 isp_prt(isp, ISP_LOGERR, "transport error for %d.%d.%d:\n%s",
4539 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs), buf);
4540 break;
4541 }
4542 case RQCS_RESET_OCCURRED:
4543 isp_prt(isp, ISP_LOGWARN,
4544 "bus reset destroyed command for %d.%d.%d",
4545 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4546 isp->isp_sendmarker |= (1 << XS_CHANNEL(xs));
4547 if (XS_NOERR(xs)) {
4548 XS_SETERR(xs, HBA_BUSRESET);
4549 }
4550 return;
4551
4552 case RQCS_ABORTED:
4553 isp_prt(isp, ISP_LOGERR, "command aborted for %d.%d.%d",
4554 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4555 isp->isp_sendmarker |= (1 << XS_CHANNEL(xs));
4556 if (XS_NOERR(xs)) {
4557 XS_SETERR(xs, HBA_ABORTED);
4558 }
4559 return;
4560
4561 case RQCS_TIMEOUT:
4562 isp_prt(isp, ISP_LOGWARN, "command timed out for %d.%d.%d",
4563 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4564 /*
4565 * Check to see if we logged out the device.
4566 */
4567 if (IS_FC(isp)) {
4568 if ((sp->req_completion_status & RQSTF_LOGOUT) &&
4569 FCPARAM(isp)->portdb[XS_TGT(xs)].valid &&
4570 FCPARAM(isp)->portdb[XS_TGT(xs)].fabric_dev) {
4571 FCPARAM(isp)->portdb[XS_TGT(xs)].relogin = 1;
4572 }
4573 }
4574 if (XS_NOERR(xs)) {
4575 XS_SETERR(xs, HBA_CMDTIMEOUT);
4576 }
4577 return;
4578
4579 case RQCS_DATA_OVERRUN:
4580 XS_RESID(xs) = sp->req_resid;
4581 isp_prt(isp, ISP_LOGERR, "data overrun for command on %d.%d.%d",
4582 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4583 if (XS_NOERR(xs)) {
4584 XS_SETERR(xs, HBA_DATAOVR);
4585 }
4586 return;
4587
4588 case RQCS_COMMAND_OVERRUN:
4589 isp_prt(isp, ISP_LOGERR,
4590 "command overrun for command on %d.%d.%d",
4591 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4592 break;
4593
4594 case RQCS_STATUS_OVERRUN:
4595 isp_prt(isp, ISP_LOGERR,
4596 "status overrun for command on %d.%d.%d",
4597 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4598 break;
4599
4600 case RQCS_BAD_MESSAGE:
4601 isp_prt(isp, ISP_LOGERR,
4602 "msg not COMMAND COMPLETE after status %d.%d.%d",
4603 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4604 break;
4605
4606 case RQCS_NO_MESSAGE_OUT:
4607 isp_prt(isp, ISP_LOGERR,
4608 "No MESSAGE OUT phase after selection on %d.%d.%d",
4609 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4610 break;
4611
4612 case RQCS_EXT_ID_FAILED:
4613 isp_prt(isp, ISP_LOGERR, "EXTENDED IDENTIFY failed %d.%d.%d",
4614 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4615 break;
4616
4617 case RQCS_IDE_MSG_FAILED:
4618 isp_prt(isp, ISP_LOGERR,
4619 "INITIATOR DETECTED ERROR rejected by %d.%d.%d",
4620 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4621 break;
4622
4623 case RQCS_ABORT_MSG_FAILED:
4624 isp_prt(isp, ISP_LOGERR, "ABORT OPERATION rejected by %d.%d.%d",
4625 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4626 break;
4627
4628 case RQCS_REJECT_MSG_FAILED:
4629 isp_prt(isp, ISP_LOGERR, "MESSAGE REJECT rejected by %d.%d.%d",
4630 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4631 break;
4632
4633 case RQCS_NOP_MSG_FAILED:
4634 isp_prt(isp, ISP_LOGERR, "NOP rejected by %d.%d.%d",
4635 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4636 break;
4637
4638 case RQCS_PARITY_ERROR_MSG_FAILED:
4639 isp_prt(isp, ISP_LOGERR,
4640 "MESSAGE PARITY ERROR rejected by %d.%d.%d",
4641 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4642 break;
4643
4644 case RQCS_DEVICE_RESET_MSG_FAILED:
4645 isp_prt(isp, ISP_LOGWARN,
4646 "BUS DEVICE RESET rejected by %d.%d.%d",
4647 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4648 break;
4649
4650 case RQCS_ID_MSG_FAILED:
4651 isp_prt(isp, ISP_LOGERR, "IDENTIFY rejected by %d.%d.%d",
4652 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4653 break;
4654
4655 case RQCS_UNEXP_BUS_FREE:
4656 isp_prt(isp, ISP_LOGERR, "%d.%d.%d had an unexpected bus free",
4657 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4658 break;
4659
4660 case RQCS_DATA_UNDERRUN:
4661 {
4662 if (IS_FC(isp)) {
4663 int ru_marked = (sp->req_scsi_status & RQCS_RU) != 0;
4664 if (!ru_marked || sp->req_resid > XS_XFRLEN(xs)) {
4665 isp_prt(isp, ISP_LOGWARN, bun, XS_TGT(xs),
4666 XS_LUN(xs), XS_XFRLEN(xs), sp->req_resid,
4667 (ru_marked)? "marked" : "not marked");
4668 if (XS_NOERR(xs)) {
4669 XS_SETERR(xs, HBA_BOTCH);
4670 }
4671 return;
4672 }
4673 }
4674 XS_RESID(xs) = sp->req_resid;
4675 if (XS_NOERR(xs)) {
4676 XS_SETERR(xs, HBA_NOERROR);
4677 }
4678 return;
4679 }
4680
4681 case RQCS_XACT_ERR1:
4682 isp_prt(isp, ISP_LOGERR, xact1, XS_CHANNEL(xs),
4683 XS_TGT(xs), XS_LUN(xs));
4684 break;
4685
4686 case RQCS_XACT_ERR2:
4687 isp_prt(isp, ISP_LOGERR, xact2,
4688 XS_LUN(xs), XS_TGT(xs), XS_CHANNEL(xs));
4689 break;
4690
4691 case RQCS_XACT_ERR3:
4692 isp_prt(isp, ISP_LOGERR, xact3,
4693 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4694 break;
4695
4696 case RQCS_BAD_ENTRY:
4697 isp_prt(isp, ISP_LOGERR, "Invalid IOCB entry type detected");
4698 break;
4699
4700 case RQCS_QUEUE_FULL:
4701 isp_prt(isp, ISP_LOGDEBUG0,
4702 "internal queues full for %d.%d.%d status 0x%x",
4703 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs), *XS_STSP(xs));
4704
4705 /*
4706 * If QFULL or some other status byte is set, then this
4707 * isn't an error, per se.
4708 *
4709 * Unfortunately, some QLogic f/w writers have, in
4710 * some cases, ommitted to *set* status to QFULL.
4711 *
4712
4713 if (*XS_STSP(xs) != SCSI_GOOD && XS_NOERR(xs)) {
4714 XS_SETERR(xs, HBA_NOERROR);
4715 return;
4716 }
4717
4718 *
4719 *
4720 */
4721
4722 *XS_STSP(xs) = SCSI_QFULL;
4723 XS_SETERR(xs, HBA_NOERROR);
4724 return;
4725
4726 case RQCS_PHASE_SKIPPED:
4727 isp_prt(isp, ISP_LOGERR, pskip, XS_CHANNEL(xs),
4728 XS_TGT(xs), XS_LUN(xs));
4729 break;
4730
4731 case RQCS_ARQS_FAILED:
4732 isp_prt(isp, ISP_LOGERR,
4733 "Auto Request Sense failed for %d.%d.%d",
4734 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4735 if (XS_NOERR(xs)) {
4736 XS_SETERR(xs, HBA_ARQFAIL);
4737 }
4738 return;
4739
4740 case RQCS_WIDE_FAILED:
4741 isp_prt(isp, ISP_LOGERR,
4742 "Wide Negotiation failed for %d.%d.%d",
4743 XS_TGT(xs), XS_LUN(xs), XS_CHANNEL(xs));
4744 if (IS_SCSI(isp)) {
4745 sdparam *sdp = isp->isp_param;
4746 sdp += XS_CHANNEL(xs);
4747 sdp->isp_devparam[XS_TGT(xs)].goal_flags &= ~DPARM_WIDE;
4748 sdp->isp_devparam[XS_TGT(xs)].dev_update = 1;
4749 isp->isp_update |= (1 << XS_CHANNEL(xs));
4750 }
4751 if (XS_NOERR(xs)) {
4752 XS_SETERR(xs, HBA_NOERROR);
4753 }
4754 return;
4755
4756 case RQCS_SYNCXFER_FAILED:
4757 isp_prt(isp, ISP_LOGERR,
4758 "SDTR Message failed for target %d.%d.%d",
4759 XS_TGT(xs), XS_LUN(xs), XS_CHANNEL(xs));
4760 if (IS_SCSI(isp)) {
4761 sdparam *sdp = isp->isp_param;
4762 sdp += XS_CHANNEL(xs);
4763 sdp->isp_devparam[XS_TGT(xs)].goal_flags &= ~DPARM_SYNC;
4764 sdp->isp_devparam[XS_TGT(xs)].dev_update = 1;
4765 isp->isp_update |= (1 << XS_CHANNEL(xs));
4766 }
4767 break;
4768
4769 case RQCS_LVD_BUSERR:
4770 isp_prt(isp, ISP_LOGERR,
4771 "Bad LVD condition while talking to %d.%d.%d",
4772 XS_TGT(xs), XS_LUN(xs), XS_CHANNEL(xs));
4773 break;
4774
4775 case RQCS_PORT_UNAVAILABLE:
4776 /*
4777 * No such port on the loop. Moral equivalent of SELTIMEO
4778 */
4779 case RQCS_PORT_LOGGED_OUT:
4780 /*
4781 * It was there (maybe)- treat as a selection timeout.
4782 */
4783 if ((sp->req_completion_status & 0xff) == RQCS_PORT_UNAVAILABLE)
4784 isp_prt(isp, ISP_LOGINFO,
4785 "port unavailable for target %d", XS_TGT(xs));
4786 else
4787 isp_prt(isp, ISP_LOGINFO,
4788 "port logout for target %d", XS_TGT(xs));
4789 /*
4790 * If we're on a local loop, force a LIP (which is overkill)
4791 * to force a re-login of this unit. If we're on fabric,
4792 * then we'll have to relogin as a matter of course.
4793 */
4794 if (FCPARAM(isp)->isp_topo == TOPO_NL_PORT ||
4795 FCPARAM(isp)->isp_topo == TOPO_FL_PORT) {
4796 mbreg_t mbs;
4797 MEMZERO(&mbs, sizeof (mbs));
4719 mbs.param[0] = MBOX_INIT_LIP;
4720 isp_mboxcmd_qnw(isp, &mbs, 1);
4721 }
4722
4723 /*
4724 * Probably overkill.
4725 */
4726 isp->isp_sendmarker = 1;
4727 FCPARAM(isp)->isp_loopstate = LOOP_PDB_RCVD;
4728 isp_mark_getpdb_all(isp);
4729 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_OTHER);
4730 if (XS_NOERR(xs)) {
4731 XS_SETERR(xs, HBA_SELTIMEOUT);
4732 }
4733 return;
4734
4735 case RQCS_PORT_CHANGED:
4736 isp_prt(isp, ISP_LOGWARN,
4737 "port changed for target %d", XS_TGT(xs));
4738 if (XS_NOERR(xs)) {
4739 XS_SETERR(xs, HBA_SELTIMEOUT);
4740 }
4741 return;
4742
4743 case RQCS_PORT_BUSY:
4744 isp_prt(isp, ISP_LOGWARN,
4745 "port busy for target %d", XS_TGT(xs));
4746 if (XS_NOERR(xs)) {
4747 XS_SETERR(xs, HBA_TGTBSY);
4748 }
4749 return;
4750
4751 default:
4752 isp_prt(isp, ISP_LOGERR, "Unknown Completion Status 0x%x",
4753 sp->req_completion_status);
4754 break;
4755 }
4756 if (XS_NOERR(xs)) {
4757 XS_SETERR(xs, HBA_BOTCH);
4758 }
4759}
4760
4761static void
4762isp_fastpost_complete(struct ispsoftc *isp, u_int16_t fph)
4763{
4764 XS_T *xs;
4765
4766 if (fph == 0) {
4767 return;
4768 }
4769 xs = isp_find_xs(isp, fph);
4770 if (xs == NULL) {
4771 isp_prt(isp, ISP_LOGWARN,
4772 "Command for fast post handle 0x%x not found", fph);
4773 return;
4774 }
4775 isp_destroy_handle(isp, fph);
4776
4777 /*
4778 * Since we don't have a result queue entry item,
4779 * we must believe that SCSI status is zero and
4780 * that all data transferred.
4781 */
4782 XS_SET_STATE_STAT(isp, xs, NULL);
4783 XS_RESID(xs) = 0;
4784 *XS_STSP(xs) = SCSI_GOOD;
4785 if (XS_XFRLEN(xs)) {
4786 ISP_DMAFREE(isp, xs, fph);
4787 }
4788 if (isp->isp_nactive)
4789 isp->isp_nactive--;
4790 isp->isp_fphccmplt++;
4791 isp_done(xs);
4792}
4793
4794static int
4795isp_mbox_continue(struct ispsoftc *isp)
4796{
4797 mbreg_t mbs;
4798 u_int16_t *ptr;
4799
4800 switch (isp->isp_lastmbxcmd) {
4801 case MBOX_WRITE_RAM_WORD:
4802 case MBOX_READ_RAM_WORD:
4803 case MBOX_READ_RAM_WORD_EXTENDED:
4804 break;
4805 default:
4806 return (1);
4807 }
4808 if (isp->isp_mboxtmp[0] != MBOX_COMMAND_COMPLETE) {
4809 isp->isp_mbxwrk0 = 0;
4810 return (-1);
4811 }
4812
4798 mbs.param[0] = MBOX_INIT_LIP;
4799 isp_mboxcmd_qnw(isp, &mbs, 1);
4800 }
4801
4802 /*
4803 * Probably overkill.
4804 */
4805 isp->isp_sendmarker = 1;
4806 FCPARAM(isp)->isp_loopstate = LOOP_PDB_RCVD;
4807 isp_mark_getpdb_all(isp);
4808 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_OTHER);
4809 if (XS_NOERR(xs)) {
4810 XS_SETERR(xs, HBA_SELTIMEOUT);
4811 }
4812 return;
4813
4814 case RQCS_PORT_CHANGED:
4815 isp_prt(isp, ISP_LOGWARN,
4816 "port changed for target %d", XS_TGT(xs));
4817 if (XS_NOERR(xs)) {
4818 XS_SETERR(xs, HBA_SELTIMEOUT);
4819 }
4820 return;
4821
4822 case RQCS_PORT_BUSY:
4823 isp_prt(isp, ISP_LOGWARN,
4824 "port busy for target %d", XS_TGT(xs));
4825 if (XS_NOERR(xs)) {
4826 XS_SETERR(xs, HBA_TGTBSY);
4827 }
4828 return;
4829
4830 default:
4831 isp_prt(isp, ISP_LOGERR, "Unknown Completion Status 0x%x",
4832 sp->req_completion_status);
4833 break;
4834 }
4835 if (XS_NOERR(xs)) {
4836 XS_SETERR(xs, HBA_BOTCH);
4837 }
4838}
4839
4840static void
4841isp_fastpost_complete(struct ispsoftc *isp, u_int16_t fph)
4842{
4843 XS_T *xs;
4844
4845 if (fph == 0) {
4846 return;
4847 }
4848 xs = isp_find_xs(isp, fph);
4849 if (xs == NULL) {
4850 isp_prt(isp, ISP_LOGWARN,
4851 "Command for fast post handle 0x%x not found", fph);
4852 return;
4853 }
4854 isp_destroy_handle(isp, fph);
4855
4856 /*
4857 * Since we don't have a result queue entry item,
4858 * we must believe that SCSI status is zero and
4859 * that all data transferred.
4860 */
4861 XS_SET_STATE_STAT(isp, xs, NULL);
4862 XS_RESID(xs) = 0;
4863 *XS_STSP(xs) = SCSI_GOOD;
4864 if (XS_XFRLEN(xs)) {
4865 ISP_DMAFREE(isp, xs, fph);
4866 }
4867 if (isp->isp_nactive)
4868 isp->isp_nactive--;
4869 isp->isp_fphccmplt++;
4870 isp_done(xs);
4871}
4872
4873static int
4874isp_mbox_continue(struct ispsoftc *isp)
4875{
4876 mbreg_t mbs;
4877 u_int16_t *ptr;
4878
4879 switch (isp->isp_lastmbxcmd) {
4880 case MBOX_WRITE_RAM_WORD:
4881 case MBOX_READ_RAM_WORD:
4882 case MBOX_READ_RAM_WORD_EXTENDED:
4883 break;
4884 default:
4885 return (1);
4886 }
4887 if (isp->isp_mboxtmp[0] != MBOX_COMMAND_COMPLETE) {
4888 isp->isp_mbxwrk0 = 0;
4889 return (-1);
4890 }
4891
4813
4814 /*
4815 * Clear the previous interrupt.
4816 */
4817 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
4818 ISP_WRITE(isp, BIU_SEMA, 0);
4819
4820 /*
4821 * Continue with next word.
4822 */
4892 /*
4893 * Clear the previous interrupt.
4894 */
4895 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
4896 ISP_WRITE(isp, BIU_SEMA, 0);
4897
4898 /*
4899 * Continue with next word.
4900 */
4901 MEMZERO(&mbs, sizeof (mbs));
4823 ptr = isp->isp_mbxworkp;
4824 switch (isp->isp_lastmbxcmd) {
4825 case MBOX_WRITE_RAM_WORD:
4826 mbs.param[2] = *ptr++;
4827 mbs.param[1] = isp->isp_mbxwrk1++;
4828 break;
4829 case MBOX_READ_RAM_WORD:
4830 case MBOX_READ_RAM_WORD_EXTENDED:
4831 *ptr++ = isp->isp_mboxtmp[2];
4832 mbs.param[1] = isp->isp_mbxwrk1++;
4833 break;
4834 }
4835 isp->isp_mbxworkp = ptr;
4836 mbs.param[0] = isp->isp_lastmbxcmd;
4837 isp->isp_mbxwrk0 -= 1;
4838 isp_mboxcmd_qnw(isp, &mbs, 0);
4839 return (0);
4840}
4841
4842
4902 ptr = isp->isp_mbxworkp;
4903 switch (isp->isp_lastmbxcmd) {
4904 case MBOX_WRITE_RAM_WORD:
4905 mbs.param[2] = *ptr++;
4906 mbs.param[1] = isp->isp_mbxwrk1++;
4907 break;
4908 case MBOX_READ_RAM_WORD:
4909 case MBOX_READ_RAM_WORD_EXTENDED:
4910 *ptr++ = isp->isp_mboxtmp[2];
4911 mbs.param[1] = isp->isp_mbxwrk1++;
4912 break;
4913 }
4914 isp->isp_mbxworkp = ptr;
4915 mbs.param[0] = isp->isp_lastmbxcmd;
4916 isp->isp_mbxwrk0 -= 1;
4917 isp_mboxcmd_qnw(isp, &mbs, 0);
4918 return (0);
4919}
4920
4921
4843#define HIBYT(x) ((x) >> 0x8)
4844#define LOBYT(x) ((x) & 0xff)
4845#define ISPOPMAP(a, b) (((a) << 8) | (b))
4846static const u_int16_t mbpscsi[] = {
4922#define HIWRD(x) ((x) >> 16)
4923#define LOWRD(x) ((x) & 0xffff)
4924#define ISPOPMAP(a, b) (((a) << 16) | (b))
4925static const u_int32_t mbpscsi[] = {
4847 ISPOPMAP(0x01, 0x01), /* 0x00: MBOX_NO_OP */
4848 ISPOPMAP(0x1f, 0x01), /* 0x01: MBOX_LOAD_RAM */
4849 ISPOPMAP(0x03, 0x01), /* 0x02: MBOX_EXEC_FIRMWARE */
4850 ISPOPMAP(0x1f, 0x01), /* 0x03: MBOX_DUMP_RAM */
4851 ISPOPMAP(0x07, 0x07), /* 0x04: MBOX_WRITE_RAM_WORD */
4852 ISPOPMAP(0x03, 0x07), /* 0x05: MBOX_READ_RAM_WORD */
4853 ISPOPMAP(0x3f, 0x3f), /* 0x06: MBOX_MAILBOX_REG_TEST */
4854 ISPOPMAP(0x03, 0x07), /* 0x07: MBOX_VERIFY_CHECKSUM */
4855 ISPOPMAP(0x01, 0x0f), /* 0x08: MBOX_ABOUT_FIRMWARE */
4856 ISPOPMAP(0x00, 0x00), /* 0x09: */
4857 ISPOPMAP(0x00, 0x00), /* 0x0a: */
4858 ISPOPMAP(0x00, 0x00), /* 0x0b: */
4859 ISPOPMAP(0x00, 0x00), /* 0x0c: */
4860 ISPOPMAP(0x00, 0x00), /* 0x0d: */
4861 ISPOPMAP(0x01, 0x05), /* 0x0e: MBOX_CHECK_FIRMWARE */
4862 ISPOPMAP(0x00, 0x00), /* 0x0f: */
4863 ISPOPMAP(0x1f, 0x1f), /* 0x10: MBOX_INIT_REQ_QUEUE */
4864 ISPOPMAP(0x3f, 0x3f), /* 0x11: MBOX_INIT_RES_QUEUE */
4865 ISPOPMAP(0x0f, 0x0f), /* 0x12: MBOX_EXECUTE_IOCB */
4866 ISPOPMAP(0x03, 0x03), /* 0x13: MBOX_WAKE_UP */
4867 ISPOPMAP(0x01, 0x3f), /* 0x14: MBOX_STOP_FIRMWARE */
4868 ISPOPMAP(0x0f, 0x0f), /* 0x15: MBOX_ABORT */
4869 ISPOPMAP(0x03, 0x03), /* 0x16: MBOX_ABORT_DEVICE */
4870 ISPOPMAP(0x07, 0x07), /* 0x17: MBOX_ABORT_TARGET */
4871 ISPOPMAP(0x07, 0x07), /* 0x18: MBOX_BUS_RESET */
4872 ISPOPMAP(0x03, 0x07), /* 0x19: MBOX_STOP_QUEUE */
4873 ISPOPMAP(0x03, 0x07), /* 0x1a: MBOX_START_QUEUE */
4874 ISPOPMAP(0x03, 0x07), /* 0x1b: MBOX_SINGLE_STEP_QUEUE */
4875 ISPOPMAP(0x03, 0x07), /* 0x1c: MBOX_ABORT_QUEUE */
4876 ISPOPMAP(0x03, 0x4f), /* 0x1d: MBOX_GET_DEV_QUEUE_STATUS */
4877 ISPOPMAP(0x00, 0x00), /* 0x1e: */
4878 ISPOPMAP(0x01, 0x07), /* 0x1f: MBOX_GET_FIRMWARE_STATUS */
4879 ISPOPMAP(0x01, 0x07), /* 0x20: MBOX_GET_INIT_SCSI_ID */
4880 ISPOPMAP(0x01, 0x07), /* 0x21: MBOX_GET_SELECT_TIMEOUT */
4881 ISPOPMAP(0x01, 0xc7), /* 0x22: MBOX_GET_RETRY_COUNT */
4882 ISPOPMAP(0x01, 0x07), /* 0x23: MBOX_GET_TAG_AGE_LIMIT */
4883 ISPOPMAP(0x01, 0x03), /* 0x24: MBOX_GET_CLOCK_RATE */
4884 ISPOPMAP(0x01, 0x07), /* 0x25: MBOX_GET_ACT_NEG_STATE */
4885 ISPOPMAP(0x01, 0x07), /* 0x26: MBOX_GET_ASYNC_DATA_SETUP_TIME */
4886 ISPOPMAP(0x01, 0x07), /* 0x27: MBOX_GET_PCI_PARAMS */
4887 ISPOPMAP(0x03, 0x4f), /* 0x28: MBOX_GET_TARGET_PARAMS */
4888 ISPOPMAP(0x03, 0x0f), /* 0x29: MBOX_GET_DEV_QUEUE_PARAMS */
4889 ISPOPMAP(0x01, 0x07), /* 0x2a: MBOX_GET_RESET_DELAY_PARAMS */
4890 ISPOPMAP(0x00, 0x00), /* 0x2b: */
4891 ISPOPMAP(0x00, 0x00), /* 0x2c: */
4892 ISPOPMAP(0x00, 0x00), /* 0x2d: */
4893 ISPOPMAP(0x00, 0x00), /* 0x2e: */
4894 ISPOPMAP(0x00, 0x00), /* 0x2f: */
4895 ISPOPMAP(0x03, 0x03), /* 0x30: MBOX_SET_INIT_SCSI_ID */
4896 ISPOPMAP(0x07, 0x07), /* 0x31: MBOX_SET_SELECT_TIMEOUT */
4897 ISPOPMAP(0xc7, 0xc7), /* 0x32: MBOX_SET_RETRY_COUNT */
4898 ISPOPMAP(0x07, 0x07), /* 0x33: MBOX_SET_TAG_AGE_LIMIT */
4899 ISPOPMAP(0x03, 0x03), /* 0x34: MBOX_SET_CLOCK_RATE */
4900 ISPOPMAP(0x07, 0x07), /* 0x35: MBOX_SET_ACT_NEG_STATE */
4901 ISPOPMAP(0x07, 0x07), /* 0x36: MBOX_SET_ASYNC_DATA_SETUP_TIME */
4902 ISPOPMAP(0x07, 0x07), /* 0x37: MBOX_SET_PCI_CONTROL_PARAMS */
4903 ISPOPMAP(0x4f, 0x4f), /* 0x38: MBOX_SET_TARGET_PARAMS */
4904 ISPOPMAP(0x0f, 0x0f), /* 0x39: MBOX_SET_DEV_QUEUE_PARAMS */
4905 ISPOPMAP(0x07, 0x07), /* 0x3a: MBOX_SET_RESET_DELAY_PARAMS */
4906 ISPOPMAP(0x00, 0x00), /* 0x3b: */
4907 ISPOPMAP(0x00, 0x00), /* 0x3c: */
4908 ISPOPMAP(0x00, 0x00), /* 0x3d: */
4909 ISPOPMAP(0x00, 0x00), /* 0x3e: */
4910 ISPOPMAP(0x00, 0x00), /* 0x3f: */
4911 ISPOPMAP(0x01, 0x03), /* 0x40: MBOX_RETURN_BIOS_BLOCK_ADDR */
4912 ISPOPMAP(0x3f, 0x01), /* 0x41: MBOX_WRITE_FOUR_RAM_WORDS */
4913 ISPOPMAP(0x03, 0x07), /* 0x42: MBOX_EXEC_BIOS_IOCB */
4914 ISPOPMAP(0x00, 0x00), /* 0x43: */
4915 ISPOPMAP(0x00, 0x00), /* 0x44: */
4916 ISPOPMAP(0x03, 0x03), /* 0x45: SET SYSTEM PARAMETER */
4917 ISPOPMAP(0x01, 0x03), /* 0x46: GET SYSTEM PARAMETER */
4918 ISPOPMAP(0x00, 0x00), /* 0x47: */
4919 ISPOPMAP(0x01, 0xcf), /* 0x48: GET SCAM CONFIGURATION */
4920 ISPOPMAP(0xcf, 0xcf), /* 0x49: SET SCAM CONFIGURATION */
4921 ISPOPMAP(0x03, 0x03), /* 0x4a: MBOX_SET_FIRMWARE_FEATURES */
4922 ISPOPMAP(0x01, 0x03), /* 0x4b: MBOX_GET_FIRMWARE_FEATURES */
4923 ISPOPMAP(0x00, 0x00), /* 0x4c: */
4924 ISPOPMAP(0x00, 0x00), /* 0x4d: */
4925 ISPOPMAP(0x00, 0x00), /* 0x4e: */
4926 ISPOPMAP(0x00, 0x00), /* 0x4f: */
4927 ISPOPMAP(0xdf, 0xdf), /* 0x50: LOAD RAM A64 */
4928 ISPOPMAP(0xdf, 0xdf), /* 0x51: DUMP RAM A64 */
4929 ISPOPMAP(0xdf, 0xff), /* 0x52: INITIALIZE REQUEST QUEUE A64 */
4930 ISPOPMAP(0xef, 0xff), /* 0x53: INITIALIZE RESPONSE QUEUE A64 */
4931 ISPOPMAP(0xcf, 0x01), /* 0x54: EXECUTE IOCB A64 */
4932 ISPOPMAP(0x07, 0x01), /* 0x55: ENABLE TARGET MODE */
4933 ISPOPMAP(0x03, 0x0f), /* 0x56: GET TARGET STATUS */
4934 ISPOPMAP(0x00, 0x00), /* 0x57: */
4935 ISPOPMAP(0x00, 0x00), /* 0x58: */
4936 ISPOPMAP(0x00, 0x00), /* 0x59: */
4937 ISPOPMAP(0x03, 0x03), /* 0x5a: SET DATA OVERRUN RECOVERY MODE */
4938 ISPOPMAP(0x01, 0x03), /* 0x5b: GET DATA OVERRUN RECOVERY MODE */
4939 ISPOPMAP(0x0f, 0x0f), /* 0x5c: SET HOST DATA */
4940 ISPOPMAP(0x01, 0x01) /* 0x5d: GET NOST DATA */
4941};
4942
4943#ifndef ISP_STRIPPED
4944static char *scsi_mbcmd_names[] = {
4945 "NO-OP",
4946 "LOAD RAM",
4947 "EXEC FIRMWARE",
4948 "DUMP RAM",
4949 "WRITE RAM WORD",
4950 "READ RAM WORD",
4951 "MAILBOX REG TEST",
4952 "VERIFY CHECKSUM",
4953 "ABOUT FIRMWARE",
4954 NULL,
4955 NULL,
4956 NULL,
4957 NULL,
4958 NULL,
4959 "CHECK FIRMWARE",
4960 NULL,
4961 "INIT REQUEST QUEUE",
4962 "INIT RESULT QUEUE",
4963 "EXECUTE IOCB",
4964 "WAKE UP",
4965 "STOP FIRMWARE",
4966 "ABORT",
4967 "ABORT DEVICE",
4968 "ABORT TARGET",
4969 "BUS RESET",
4970 "STOP QUEUE",
4971 "START QUEUE",
4972 "SINGLE STEP QUEUE",
4973 "ABORT QUEUE",
4974 "GET DEV QUEUE STATUS",
4975 NULL,
4976 "GET FIRMWARE STATUS",
4977 "GET INIT SCSI ID",
4978 "GET SELECT TIMEOUT",
4979 "GET RETRY COUNT",
4980 "GET TAG AGE LIMIT",
4981 "GET CLOCK RATE",
4982 "GET ACT NEG STATE",
4983 "GET ASYNC DATA SETUP TIME",
4984 "GET PCI PARAMS",
4985 "GET TARGET PARAMS",
4986 "GET DEV QUEUE PARAMS",
4987 "GET RESET DELAY PARAMS",
4988 NULL,
4989 NULL,
4990 NULL,
4991 NULL,
4992 NULL,
4993 "SET INIT SCSI ID",
4994 "SET SELECT TIMEOUT",
4995 "SET RETRY COUNT",
4996 "SET TAG AGE LIMIT",
4997 "SET CLOCK RATE",
4998 "SET ACT NEG STATE",
4999 "SET ASYNC DATA SETUP TIME",
5000 "SET PCI CONTROL PARAMS",
5001 "SET TARGET PARAMS",
5002 "SET DEV QUEUE PARAMS",
5003 "SET RESET DELAY PARAMS",
5004 NULL,
5005 NULL,
5006 NULL,
5007 NULL,
5008 NULL,
5009 "RETURN BIOS BLOCK ADDR",
5010 "WRITE FOUR RAM WORDS",
5011 "EXEC BIOS IOCB",
5012 NULL,
5013 NULL,
5014 "SET SYSTEM PARAMETER",
5015 "GET SYSTEM PARAMETER",
5016 NULL,
5017 "GET SCAM CONFIGURATION",
5018 "SET SCAM CONFIGURATION",
5019 "SET FIRMWARE FEATURES",
5020 "GET FIRMWARE FEATURES",
5021 NULL,
5022 NULL,
5023 NULL,
5024 NULL,
5025 "LOAD RAM A64",
5026 "DUMP RAM A64",
5027 "INITIALIZE REQUEST QUEUE A64",
5028 "INITIALIZE RESPONSE QUEUE A64",
5029 "EXECUTE IOCB A64",
5030 "ENABLE TARGET MODE",
5031 "GET TARGET MODE STATE",
5032 NULL,
5033 NULL,
5034 NULL,
5035 "SET DATA OVERRUN RECOVERY MODE",
5036 "GET DATA OVERRUN RECOVERY MODE",
5037 "SET HOST DATA",
5038 "GET NOST DATA",
5039};
5040#endif
5041
4926 ISPOPMAP(0x01, 0x01), /* 0x00: MBOX_NO_OP */
4927 ISPOPMAP(0x1f, 0x01), /* 0x01: MBOX_LOAD_RAM */
4928 ISPOPMAP(0x03, 0x01), /* 0x02: MBOX_EXEC_FIRMWARE */
4929 ISPOPMAP(0x1f, 0x01), /* 0x03: MBOX_DUMP_RAM */
4930 ISPOPMAP(0x07, 0x07), /* 0x04: MBOX_WRITE_RAM_WORD */
4931 ISPOPMAP(0x03, 0x07), /* 0x05: MBOX_READ_RAM_WORD */
4932 ISPOPMAP(0x3f, 0x3f), /* 0x06: MBOX_MAILBOX_REG_TEST */
4933 ISPOPMAP(0x03, 0x07), /* 0x07: MBOX_VERIFY_CHECKSUM */
4934 ISPOPMAP(0x01, 0x0f), /* 0x08: MBOX_ABOUT_FIRMWARE */
4935 ISPOPMAP(0x00, 0x00), /* 0x09: */
4936 ISPOPMAP(0x00, 0x00), /* 0x0a: */
4937 ISPOPMAP(0x00, 0x00), /* 0x0b: */
4938 ISPOPMAP(0x00, 0x00), /* 0x0c: */
4939 ISPOPMAP(0x00, 0x00), /* 0x0d: */
4940 ISPOPMAP(0x01, 0x05), /* 0x0e: MBOX_CHECK_FIRMWARE */
4941 ISPOPMAP(0x00, 0x00), /* 0x0f: */
4942 ISPOPMAP(0x1f, 0x1f), /* 0x10: MBOX_INIT_REQ_QUEUE */
4943 ISPOPMAP(0x3f, 0x3f), /* 0x11: MBOX_INIT_RES_QUEUE */
4944 ISPOPMAP(0x0f, 0x0f), /* 0x12: MBOX_EXECUTE_IOCB */
4945 ISPOPMAP(0x03, 0x03), /* 0x13: MBOX_WAKE_UP */
4946 ISPOPMAP(0x01, 0x3f), /* 0x14: MBOX_STOP_FIRMWARE */
4947 ISPOPMAP(0x0f, 0x0f), /* 0x15: MBOX_ABORT */
4948 ISPOPMAP(0x03, 0x03), /* 0x16: MBOX_ABORT_DEVICE */
4949 ISPOPMAP(0x07, 0x07), /* 0x17: MBOX_ABORT_TARGET */
4950 ISPOPMAP(0x07, 0x07), /* 0x18: MBOX_BUS_RESET */
4951 ISPOPMAP(0x03, 0x07), /* 0x19: MBOX_STOP_QUEUE */
4952 ISPOPMAP(0x03, 0x07), /* 0x1a: MBOX_START_QUEUE */
4953 ISPOPMAP(0x03, 0x07), /* 0x1b: MBOX_SINGLE_STEP_QUEUE */
4954 ISPOPMAP(0x03, 0x07), /* 0x1c: MBOX_ABORT_QUEUE */
4955 ISPOPMAP(0x03, 0x4f), /* 0x1d: MBOX_GET_DEV_QUEUE_STATUS */
4956 ISPOPMAP(0x00, 0x00), /* 0x1e: */
4957 ISPOPMAP(0x01, 0x07), /* 0x1f: MBOX_GET_FIRMWARE_STATUS */
4958 ISPOPMAP(0x01, 0x07), /* 0x20: MBOX_GET_INIT_SCSI_ID */
4959 ISPOPMAP(0x01, 0x07), /* 0x21: MBOX_GET_SELECT_TIMEOUT */
4960 ISPOPMAP(0x01, 0xc7), /* 0x22: MBOX_GET_RETRY_COUNT */
4961 ISPOPMAP(0x01, 0x07), /* 0x23: MBOX_GET_TAG_AGE_LIMIT */
4962 ISPOPMAP(0x01, 0x03), /* 0x24: MBOX_GET_CLOCK_RATE */
4963 ISPOPMAP(0x01, 0x07), /* 0x25: MBOX_GET_ACT_NEG_STATE */
4964 ISPOPMAP(0x01, 0x07), /* 0x26: MBOX_GET_ASYNC_DATA_SETUP_TIME */
4965 ISPOPMAP(0x01, 0x07), /* 0x27: MBOX_GET_PCI_PARAMS */
4966 ISPOPMAP(0x03, 0x4f), /* 0x28: MBOX_GET_TARGET_PARAMS */
4967 ISPOPMAP(0x03, 0x0f), /* 0x29: MBOX_GET_DEV_QUEUE_PARAMS */
4968 ISPOPMAP(0x01, 0x07), /* 0x2a: MBOX_GET_RESET_DELAY_PARAMS */
4969 ISPOPMAP(0x00, 0x00), /* 0x2b: */
4970 ISPOPMAP(0x00, 0x00), /* 0x2c: */
4971 ISPOPMAP(0x00, 0x00), /* 0x2d: */
4972 ISPOPMAP(0x00, 0x00), /* 0x2e: */
4973 ISPOPMAP(0x00, 0x00), /* 0x2f: */
4974 ISPOPMAP(0x03, 0x03), /* 0x30: MBOX_SET_INIT_SCSI_ID */
4975 ISPOPMAP(0x07, 0x07), /* 0x31: MBOX_SET_SELECT_TIMEOUT */
4976 ISPOPMAP(0xc7, 0xc7), /* 0x32: MBOX_SET_RETRY_COUNT */
4977 ISPOPMAP(0x07, 0x07), /* 0x33: MBOX_SET_TAG_AGE_LIMIT */
4978 ISPOPMAP(0x03, 0x03), /* 0x34: MBOX_SET_CLOCK_RATE */
4979 ISPOPMAP(0x07, 0x07), /* 0x35: MBOX_SET_ACT_NEG_STATE */
4980 ISPOPMAP(0x07, 0x07), /* 0x36: MBOX_SET_ASYNC_DATA_SETUP_TIME */
4981 ISPOPMAP(0x07, 0x07), /* 0x37: MBOX_SET_PCI_CONTROL_PARAMS */
4982 ISPOPMAP(0x4f, 0x4f), /* 0x38: MBOX_SET_TARGET_PARAMS */
4983 ISPOPMAP(0x0f, 0x0f), /* 0x39: MBOX_SET_DEV_QUEUE_PARAMS */
4984 ISPOPMAP(0x07, 0x07), /* 0x3a: MBOX_SET_RESET_DELAY_PARAMS */
4985 ISPOPMAP(0x00, 0x00), /* 0x3b: */
4986 ISPOPMAP(0x00, 0x00), /* 0x3c: */
4987 ISPOPMAP(0x00, 0x00), /* 0x3d: */
4988 ISPOPMAP(0x00, 0x00), /* 0x3e: */
4989 ISPOPMAP(0x00, 0x00), /* 0x3f: */
4990 ISPOPMAP(0x01, 0x03), /* 0x40: MBOX_RETURN_BIOS_BLOCK_ADDR */
4991 ISPOPMAP(0x3f, 0x01), /* 0x41: MBOX_WRITE_FOUR_RAM_WORDS */
4992 ISPOPMAP(0x03, 0x07), /* 0x42: MBOX_EXEC_BIOS_IOCB */
4993 ISPOPMAP(0x00, 0x00), /* 0x43: */
4994 ISPOPMAP(0x00, 0x00), /* 0x44: */
4995 ISPOPMAP(0x03, 0x03), /* 0x45: SET SYSTEM PARAMETER */
4996 ISPOPMAP(0x01, 0x03), /* 0x46: GET SYSTEM PARAMETER */
4997 ISPOPMAP(0x00, 0x00), /* 0x47: */
4998 ISPOPMAP(0x01, 0xcf), /* 0x48: GET SCAM CONFIGURATION */
4999 ISPOPMAP(0xcf, 0xcf), /* 0x49: SET SCAM CONFIGURATION */
5000 ISPOPMAP(0x03, 0x03), /* 0x4a: MBOX_SET_FIRMWARE_FEATURES */
5001 ISPOPMAP(0x01, 0x03), /* 0x4b: MBOX_GET_FIRMWARE_FEATURES */
5002 ISPOPMAP(0x00, 0x00), /* 0x4c: */
5003 ISPOPMAP(0x00, 0x00), /* 0x4d: */
5004 ISPOPMAP(0x00, 0x00), /* 0x4e: */
5005 ISPOPMAP(0x00, 0x00), /* 0x4f: */
5006 ISPOPMAP(0xdf, 0xdf), /* 0x50: LOAD RAM A64 */
5007 ISPOPMAP(0xdf, 0xdf), /* 0x51: DUMP RAM A64 */
5008 ISPOPMAP(0xdf, 0xff), /* 0x52: INITIALIZE REQUEST QUEUE A64 */
5009 ISPOPMAP(0xef, 0xff), /* 0x53: INITIALIZE RESPONSE QUEUE A64 */
5010 ISPOPMAP(0xcf, 0x01), /* 0x54: EXECUTE IOCB A64 */
5011 ISPOPMAP(0x07, 0x01), /* 0x55: ENABLE TARGET MODE */
5012 ISPOPMAP(0x03, 0x0f), /* 0x56: GET TARGET STATUS */
5013 ISPOPMAP(0x00, 0x00), /* 0x57: */
5014 ISPOPMAP(0x00, 0x00), /* 0x58: */
5015 ISPOPMAP(0x00, 0x00), /* 0x59: */
5016 ISPOPMAP(0x03, 0x03), /* 0x5a: SET DATA OVERRUN RECOVERY MODE */
5017 ISPOPMAP(0x01, 0x03), /* 0x5b: GET DATA OVERRUN RECOVERY MODE */
5018 ISPOPMAP(0x0f, 0x0f), /* 0x5c: SET HOST DATA */
5019 ISPOPMAP(0x01, 0x01) /* 0x5d: GET NOST DATA */
5020};
5021
5022#ifndef ISP_STRIPPED
5023static char *scsi_mbcmd_names[] = {
5024 "NO-OP",
5025 "LOAD RAM",
5026 "EXEC FIRMWARE",
5027 "DUMP RAM",
5028 "WRITE RAM WORD",
5029 "READ RAM WORD",
5030 "MAILBOX REG TEST",
5031 "VERIFY CHECKSUM",
5032 "ABOUT FIRMWARE",
5033 NULL,
5034 NULL,
5035 NULL,
5036 NULL,
5037 NULL,
5038 "CHECK FIRMWARE",
5039 NULL,
5040 "INIT REQUEST QUEUE",
5041 "INIT RESULT QUEUE",
5042 "EXECUTE IOCB",
5043 "WAKE UP",
5044 "STOP FIRMWARE",
5045 "ABORT",
5046 "ABORT DEVICE",
5047 "ABORT TARGET",
5048 "BUS RESET",
5049 "STOP QUEUE",
5050 "START QUEUE",
5051 "SINGLE STEP QUEUE",
5052 "ABORT QUEUE",
5053 "GET DEV QUEUE STATUS",
5054 NULL,
5055 "GET FIRMWARE STATUS",
5056 "GET INIT SCSI ID",
5057 "GET SELECT TIMEOUT",
5058 "GET RETRY COUNT",
5059 "GET TAG AGE LIMIT",
5060 "GET CLOCK RATE",
5061 "GET ACT NEG STATE",
5062 "GET ASYNC DATA SETUP TIME",
5063 "GET PCI PARAMS",
5064 "GET TARGET PARAMS",
5065 "GET DEV QUEUE PARAMS",
5066 "GET RESET DELAY PARAMS",
5067 NULL,
5068 NULL,
5069 NULL,
5070 NULL,
5071 NULL,
5072 "SET INIT SCSI ID",
5073 "SET SELECT TIMEOUT",
5074 "SET RETRY COUNT",
5075 "SET TAG AGE LIMIT",
5076 "SET CLOCK RATE",
5077 "SET ACT NEG STATE",
5078 "SET ASYNC DATA SETUP TIME",
5079 "SET PCI CONTROL PARAMS",
5080 "SET TARGET PARAMS",
5081 "SET DEV QUEUE PARAMS",
5082 "SET RESET DELAY PARAMS",
5083 NULL,
5084 NULL,
5085 NULL,
5086 NULL,
5087 NULL,
5088 "RETURN BIOS BLOCK ADDR",
5089 "WRITE FOUR RAM WORDS",
5090 "EXEC BIOS IOCB",
5091 NULL,
5092 NULL,
5093 "SET SYSTEM PARAMETER",
5094 "GET SYSTEM PARAMETER",
5095 NULL,
5096 "GET SCAM CONFIGURATION",
5097 "SET SCAM CONFIGURATION",
5098 "SET FIRMWARE FEATURES",
5099 "GET FIRMWARE FEATURES",
5100 NULL,
5101 NULL,
5102 NULL,
5103 NULL,
5104 "LOAD RAM A64",
5105 "DUMP RAM A64",
5106 "INITIALIZE REQUEST QUEUE A64",
5107 "INITIALIZE RESPONSE QUEUE A64",
5108 "EXECUTE IOCB A64",
5109 "ENABLE TARGET MODE",
5110 "GET TARGET MODE STATE",
5111 NULL,
5112 NULL,
5113 NULL,
5114 "SET DATA OVERRUN RECOVERY MODE",
5115 "GET DATA OVERRUN RECOVERY MODE",
5116 "SET HOST DATA",
5117 "GET NOST DATA",
5118};
5119#endif
5120
5042static const u_int16_t mbpfc[] = {
5121static const u_int32_t mbpfc[] = {
5043 ISPOPMAP(0x01, 0x01), /* 0x00: MBOX_NO_OP */
5044 ISPOPMAP(0x1f, 0x01), /* 0x01: MBOX_LOAD_RAM */
5045 ISPOPMAP(0x03, 0x01), /* 0x02: MBOX_EXEC_FIRMWARE */
5046 ISPOPMAP(0xdf, 0x01), /* 0x03: MBOX_DUMP_RAM */
5047 ISPOPMAP(0x07, 0x07), /* 0x04: MBOX_WRITE_RAM_WORD */
5048 ISPOPMAP(0x03, 0x07), /* 0x05: MBOX_READ_RAM_WORD */
5049 ISPOPMAP(0xff, 0xff), /* 0x06: MBOX_MAILBOX_REG_TEST */
5050 ISPOPMAP(0x03, 0x05), /* 0x07: MBOX_VERIFY_CHECKSUM */
5051 ISPOPMAP(0x01, 0x4f), /* 0x08: MBOX_ABOUT_FIRMWARE */
5052 ISPOPMAP(0xdf, 0x01), /* 0x09: LOAD RAM */
5053 ISPOPMAP(0xdf, 0x01), /* 0x0a: DUMP RAM */
5054 ISPOPMAP(0x00, 0x00), /* 0x0b: */
5055 ISPOPMAP(0x00, 0x00), /* 0x0c: */
5056 ISPOPMAP(0x00, 0x00), /* 0x0d: */
5057 ISPOPMAP(0x01, 0x05), /* 0x0e: MBOX_CHECK_FIRMWARE */
5058 ISPOPMAP(0x03, 0x07), /* 0x0f: MBOX_READ_RAM_WORD_EXTENDED(1) */
5059 ISPOPMAP(0x1f, 0x11), /* 0x10: MBOX_INIT_REQ_QUEUE */
5060 ISPOPMAP(0x2f, 0x21), /* 0x11: MBOX_INIT_RES_QUEUE */
5061 ISPOPMAP(0x0f, 0x01), /* 0x12: MBOX_EXECUTE_IOCB */
5062 ISPOPMAP(0x03, 0x03), /* 0x13: MBOX_WAKE_UP */
5063 ISPOPMAP(0x01, 0xff), /* 0x14: MBOX_STOP_FIRMWARE */
5064 ISPOPMAP(0x4f, 0x01), /* 0x15: MBOX_ABORT */
5065 ISPOPMAP(0x07, 0x01), /* 0x16: MBOX_ABORT_DEVICE */
5066 ISPOPMAP(0x07, 0x01), /* 0x17: MBOX_ABORT_TARGET */
5067 ISPOPMAP(0x03, 0x03), /* 0x18: MBOX_BUS_RESET */
5068 ISPOPMAP(0x07, 0x05), /* 0x19: MBOX_STOP_QUEUE */
5069 ISPOPMAP(0x07, 0x05), /* 0x1a: MBOX_START_QUEUE */
5070 ISPOPMAP(0x07, 0x05), /* 0x1b: MBOX_SINGLE_STEP_QUEUE */
5071 ISPOPMAP(0x07, 0x05), /* 0x1c: MBOX_ABORT_QUEUE */
5072 ISPOPMAP(0x07, 0x03), /* 0x1d: MBOX_GET_DEV_QUEUE_STATUS */
5073 ISPOPMAP(0x00, 0x00), /* 0x1e: */
5074 ISPOPMAP(0x01, 0x07), /* 0x1f: MBOX_GET_FIRMWARE_STATUS */
5075 ISPOPMAP(0x01, 0x4f), /* 0x20: MBOX_GET_LOOP_ID */
5076 ISPOPMAP(0x00, 0x00), /* 0x21: */
5077 ISPOPMAP(0x01, 0x07), /* 0x22: MBOX_GET_RETRY_COUNT */
5078 ISPOPMAP(0x00, 0x00), /* 0x23: */
5079 ISPOPMAP(0x00, 0x00), /* 0x24: */
5080 ISPOPMAP(0x00, 0x00), /* 0x25: */
5081 ISPOPMAP(0x00, 0x00), /* 0x26: */
5082 ISPOPMAP(0x00, 0x00), /* 0x27: */
5083 ISPOPMAP(0x01, 0x03), /* 0x28: MBOX_GET_FIRMWARE_OPTIONS */
5084 ISPOPMAP(0x03, 0x07), /* 0x29: MBOX_GET_PORT_QUEUE_PARAMS */
5085 ISPOPMAP(0x00, 0x00), /* 0x2a: */
5086 ISPOPMAP(0x00, 0x00), /* 0x2b: */
5087 ISPOPMAP(0x00, 0x00), /* 0x2c: */
5088 ISPOPMAP(0x00, 0x00), /* 0x2d: */
5089 ISPOPMAP(0x00, 0x00), /* 0x2e: */
5090 ISPOPMAP(0x00, 0x00), /* 0x2f: */
5091 ISPOPMAP(0x00, 0x00), /* 0x30: */
5092 ISPOPMAP(0x00, 0x00), /* 0x31: */
5093 ISPOPMAP(0x07, 0x07), /* 0x32: MBOX_SET_RETRY_COUNT */
5094 ISPOPMAP(0x00, 0x00), /* 0x33: */
5095 ISPOPMAP(0x00, 0x00), /* 0x34: */
5096 ISPOPMAP(0x00, 0x00), /* 0x35: */
5097 ISPOPMAP(0x00, 0x00), /* 0x36: */
5098 ISPOPMAP(0x00, 0x00), /* 0x37: */
5099 ISPOPMAP(0x0f, 0x01), /* 0x38: MBOX_SET_FIRMWARE_OPTIONS */
5100 ISPOPMAP(0x0f, 0x07), /* 0x39: MBOX_SET_PORT_QUEUE_PARAMS */
5101 ISPOPMAP(0x00, 0x00), /* 0x3a: */
5102 ISPOPMAP(0x00, 0x00), /* 0x3b: */
5103 ISPOPMAP(0x00, 0x00), /* 0x3c: */
5104 ISPOPMAP(0x00, 0x00), /* 0x3d: */
5105 ISPOPMAP(0x00, 0x00), /* 0x3e: */
5106 ISPOPMAP(0x00, 0x00), /* 0x3f: */
5107 ISPOPMAP(0x03, 0x01), /* 0x40: MBOX_LOOP_PORT_BYPASS */
5108 ISPOPMAP(0x03, 0x01), /* 0x41: MBOX_LOOP_PORT_ENABLE */
5109 ISPOPMAP(0x03, 0x07), /* 0x42: MBOX_GET_RESOURCE_COUNTS */
5110 ISPOPMAP(0x01, 0x01), /* 0x43: MBOX_REQUEST_NON_PARTICIPATING_MODE */
5111 ISPOPMAP(0x00, 0x00), /* 0x44: */
5112 ISPOPMAP(0x00, 0x00), /* 0x45: */
5113 ISPOPMAP(0x00, 0x00), /* 0x46: */
5114 ISPOPMAP(0xcf, 0x03), /* 0x47: GET PORT_DATABASE ENHANCED */
5115 ISPOPMAP(0x00, 0x00), /* 0x48: */
5116 ISPOPMAP(0x00, 0x00), /* 0x49: */
5117 ISPOPMAP(0x00, 0x00), /* 0x4a: */
5118 ISPOPMAP(0x00, 0x00), /* 0x4b: */
5119 ISPOPMAP(0x00, 0x00), /* 0x4c: */
5120 ISPOPMAP(0x00, 0x00), /* 0x4d: */
5121 ISPOPMAP(0x00, 0x00), /* 0x4e: */
5122 ISPOPMAP(0x00, 0x00), /* 0x4f: */
5123 ISPOPMAP(0x00, 0x00), /* 0x50: */
5124 ISPOPMAP(0x00, 0x00), /* 0x51: */
5125 ISPOPMAP(0x00, 0x00), /* 0x52: */
5126 ISPOPMAP(0x00, 0x00), /* 0x53: */
5127 ISPOPMAP(0xcf, 0x01), /* 0x54: EXECUTE IOCB A64 */
5128 ISPOPMAP(0x00, 0x00), /* 0x55: */
5129 ISPOPMAP(0x00, 0x00), /* 0x56: */
5130 ISPOPMAP(0x00, 0x00), /* 0x57: */
5131 ISPOPMAP(0x00, 0x00), /* 0x58: */
5132 ISPOPMAP(0x00, 0x00), /* 0x59: */
5133 ISPOPMAP(0x00, 0x00), /* 0x5a: */
5134 ISPOPMAP(0x03, 0x01), /* 0x5b: MBOX_DRIVER_HEARTBEAT */
5135 ISPOPMAP(0xcf, 0x01), /* 0x5c: MBOX_FW_HEARTBEAT */
5136 ISPOPMAP(0x07, 0x03), /* 0x5d: MBOX_GET_SET_DATA_RATE */
5137 ISPOPMAP(0x00, 0x00), /* 0x5e: */
5138 ISPOPMAP(0x00, 0x00), /* 0x5f: */
5139 ISPOPMAP(0xfd, 0x31), /* 0x60: MBOX_INIT_FIRMWARE */
5140 ISPOPMAP(0x00, 0x00), /* 0x61: */
5141 ISPOPMAP(0x01, 0x01), /* 0x62: MBOX_INIT_LIP */
5142 ISPOPMAP(0xcd, 0x03), /* 0x63: MBOX_GET_FC_AL_POSITION_MAP */
5143 ISPOPMAP(0xcf, 0x01), /* 0x64: MBOX_GET_PORT_DB */
5144 ISPOPMAP(0x07, 0x01), /* 0x65: MBOX_CLEAR_ACA */
5145 ISPOPMAP(0x07, 0x01), /* 0x66: MBOX_TARGET_RESET */
5146 ISPOPMAP(0x07, 0x01), /* 0x67: MBOX_CLEAR_TASK_SET */
5147 ISPOPMAP(0x07, 0x01), /* 0x68: MBOX_ABORT_TASK_SET */
5148 ISPOPMAP(0x01, 0x07), /* 0x69: MBOX_GET_FW_STATE */
5149 ISPOPMAP(0x03, 0xcf), /* 0x6a: MBOX_GET_PORT_NAME */
5150 ISPOPMAP(0xcf, 0x01), /* 0x6b: MBOX_GET_LINK_STATUS */
5151 ISPOPMAP(0x0f, 0x01), /* 0x6c: MBOX_INIT_LIP_RESET */
5152 ISPOPMAP(0x00, 0x00), /* 0x6d: */
5153 ISPOPMAP(0xcf, 0x03), /* 0x6e: MBOX_SEND_SNS */
5154 ISPOPMAP(0x0f, 0x07), /* 0x6f: MBOX_FABRIC_LOGIN */
5155 ISPOPMAP(0x03, 0x01), /* 0x70: MBOX_SEND_CHANGE_REQUEST */
5156 ISPOPMAP(0x03, 0x03), /* 0x71: MBOX_FABRIC_LOGOUT */
5157 ISPOPMAP(0x0f, 0x0f), /* 0x72: MBOX_INIT_LIP_LOGIN */
5158 ISPOPMAP(0x00, 0x00), /* 0x73: */
5159 ISPOPMAP(0x07, 0x01), /* 0x74: LOGIN LOOP PORT */
5160 ISPOPMAP(0xcf, 0x03), /* 0x75: GET PORT/NODE NAME LIST */
5161 ISPOPMAP(0x4f, 0x01), /* 0x76: SET VENDOR ID */
5162 ISPOPMAP(0xcd, 0x01), /* 0x77: INITIALIZE IP MAILBOX */
5163 ISPOPMAP(0x00, 0x00), /* 0x78: */
5164 ISPOPMAP(0x00, 0x00), /* 0x79: */
5165 ISPOPMAP(0x00, 0x00), /* 0x7a: */
5166 ISPOPMAP(0x00, 0x00), /* 0x7b: */
5167 ISPOPMAP(0x4f, 0x03), /* 0x7c: Get ID List */
5168 ISPOPMAP(0xcf, 0x01), /* 0x7d: SEND LFA */
5169 ISPOPMAP(0x0f, 0x01) /* 0x7e: LUN RESET */
5170};
5171/*
5172 * Footnotes
5173 *
5174 * (1): this sets bits 21..16 in mailbox register #8, which we nominally
5175 * do not access at this time in the core driver. The caller is
5176 * responsible for setting this register first (Gross!).
5177 */
5178
5179#ifndef ISP_STRIPPED
5180static char *fc_mbcmd_names[] = {
5181 "NO-OP",
5182 "LOAD RAM",
5183 "EXEC FIRMWARE",
5184 "DUMP RAM",
5185 "WRITE RAM WORD",
5186 "READ RAM WORD",
5187 "MAILBOX REG TEST",
5188 "VERIFY CHECKSUM",
5189 "ABOUT FIRMWARE",
5190 "LOAD RAM",
5191 "DUMP RAM",
5192 NULL,
5193 NULL,
5194 "READ RAM WORD EXTENDED",
5195 "CHECK FIRMWARE",
5196 NULL,
5197 "INIT REQUEST QUEUE",
5198 "INIT RESULT QUEUE",
5199 "EXECUTE IOCB",
5200 "WAKE UP",
5201 "STOP FIRMWARE",
5202 "ABORT",
5203 "ABORT DEVICE",
5204 "ABORT TARGET",
5205 "BUS RESET",
5206 "STOP QUEUE",
5207 "START QUEUE",
5208 "SINGLE STEP QUEUE",
5209 "ABORT QUEUE",
5210 "GET DEV QUEUE STATUS",
5211 NULL,
5212 "GET FIRMWARE STATUS",
5213 "GET LOOP ID",
5214 NULL,
5215 "GET RETRY COUNT",
5216 NULL,
5217 NULL,
5218 NULL,
5219 NULL,
5220 NULL,
5221 "GET FIRMWARE OPTIONS",
5222 "GET PORT QUEUE PARAMS",
5223 NULL,
5224 NULL,
5225 NULL,
5226 NULL,
5227 NULL,
5228 NULL,
5229 NULL,
5230 NULL,
5231 "SET RETRY COUNT",
5232 NULL,
5233 NULL,
5234 NULL,
5235 NULL,
5236 NULL,
5237 "SET FIRMWARE OPTIONS",
5238 "SET PORT QUEUE PARAMS",
5239 NULL,
5240 NULL,
5241 NULL,
5242 NULL,
5243 NULL,
5244 NULL,
5245 "LOOP PORT BYPASS",
5246 "LOOP PORT ENABLE",
5247 "GET RESOURCE COUNTS",
5248 "REQUEST NON PARTICIPATING MODE",
5249 NULL,
5250 NULL,
5251 NULL,
5252 "GET PORT DATABASE,, ENHANCED",
5253 NULL,
5254 NULL,
5255 NULL,
5256 NULL,
5257 NULL,
5258 NULL,
5259 NULL,
5260 NULL,
5261 NULL,
5262 NULL,
5263 NULL,
5264 NULL,
5265 "EXECUTE IOCB A64",
5266 NULL,
5267 NULL,
5268 NULL,
5269 NULL,
5270 NULL,
5271 NULL,
5272 "DRIVER HEARTBEAT",
5273 NULL,
5274 "GET/SET DATA RATE",
5275 NULL,
5276 NULL,
5277 "INIT FIRMWARE",
5278 NULL,
5279 "INIT LIP",
5280 "GET FC-AL POSITION MAP",
5281 "GET PORT DATABASE",
5282 "CLEAR ACA",
5283 "TARGET RESET",
5284 "CLEAR TASK SET",
5285 "ABORT TASK SET",
5286 "GET FW STATE",
5287 "GET PORT NAME",
5288 "GET LINK STATUS",
5289 "INIT LIP RESET",
5290 NULL,
5291 "SEND SNS",
5292 "FABRIC LOGIN",
5293 "SEND CHANGE REQUEST",
5294 "FABRIC LOGOUT",
5295 "INIT LIP LOGIN",
5296 NULL,
5297 "LOGIN LOOP PORT",
5298 "GET PORT/NODE NAME LIST",
5299 "SET VENDOR ID",
5300 "INITIALIZE IP MAILBOX",
5301 NULL,
5302 NULL,
5303 NULL,
5304 NULL,
5305 "Get ID List",
5306 "SEND LFA",
5307 "Lun RESET"
5308};
5309#endif
5310
5311static void
5312isp_mboxcmd_qnw(struct ispsoftc *isp, mbreg_t *mbp, int nodelay)
5313{
5314 unsigned int ibits, obits, box, opcode;
5122 ISPOPMAP(0x01, 0x01), /* 0x00: MBOX_NO_OP */
5123 ISPOPMAP(0x1f, 0x01), /* 0x01: MBOX_LOAD_RAM */
5124 ISPOPMAP(0x03, 0x01), /* 0x02: MBOX_EXEC_FIRMWARE */
5125 ISPOPMAP(0xdf, 0x01), /* 0x03: MBOX_DUMP_RAM */
5126 ISPOPMAP(0x07, 0x07), /* 0x04: MBOX_WRITE_RAM_WORD */
5127 ISPOPMAP(0x03, 0x07), /* 0x05: MBOX_READ_RAM_WORD */
5128 ISPOPMAP(0xff, 0xff), /* 0x06: MBOX_MAILBOX_REG_TEST */
5129 ISPOPMAP(0x03, 0x05), /* 0x07: MBOX_VERIFY_CHECKSUM */
5130 ISPOPMAP(0x01, 0x4f), /* 0x08: MBOX_ABOUT_FIRMWARE */
5131 ISPOPMAP(0xdf, 0x01), /* 0x09: LOAD RAM */
5132 ISPOPMAP(0xdf, 0x01), /* 0x0a: DUMP RAM */
5133 ISPOPMAP(0x00, 0x00), /* 0x0b: */
5134 ISPOPMAP(0x00, 0x00), /* 0x0c: */
5135 ISPOPMAP(0x00, 0x00), /* 0x0d: */
5136 ISPOPMAP(0x01, 0x05), /* 0x0e: MBOX_CHECK_FIRMWARE */
5137 ISPOPMAP(0x03, 0x07), /* 0x0f: MBOX_READ_RAM_WORD_EXTENDED(1) */
5138 ISPOPMAP(0x1f, 0x11), /* 0x10: MBOX_INIT_REQ_QUEUE */
5139 ISPOPMAP(0x2f, 0x21), /* 0x11: MBOX_INIT_RES_QUEUE */
5140 ISPOPMAP(0x0f, 0x01), /* 0x12: MBOX_EXECUTE_IOCB */
5141 ISPOPMAP(0x03, 0x03), /* 0x13: MBOX_WAKE_UP */
5142 ISPOPMAP(0x01, 0xff), /* 0x14: MBOX_STOP_FIRMWARE */
5143 ISPOPMAP(0x4f, 0x01), /* 0x15: MBOX_ABORT */
5144 ISPOPMAP(0x07, 0x01), /* 0x16: MBOX_ABORT_DEVICE */
5145 ISPOPMAP(0x07, 0x01), /* 0x17: MBOX_ABORT_TARGET */
5146 ISPOPMAP(0x03, 0x03), /* 0x18: MBOX_BUS_RESET */
5147 ISPOPMAP(0x07, 0x05), /* 0x19: MBOX_STOP_QUEUE */
5148 ISPOPMAP(0x07, 0x05), /* 0x1a: MBOX_START_QUEUE */
5149 ISPOPMAP(0x07, 0x05), /* 0x1b: MBOX_SINGLE_STEP_QUEUE */
5150 ISPOPMAP(0x07, 0x05), /* 0x1c: MBOX_ABORT_QUEUE */
5151 ISPOPMAP(0x07, 0x03), /* 0x1d: MBOX_GET_DEV_QUEUE_STATUS */
5152 ISPOPMAP(0x00, 0x00), /* 0x1e: */
5153 ISPOPMAP(0x01, 0x07), /* 0x1f: MBOX_GET_FIRMWARE_STATUS */
5154 ISPOPMAP(0x01, 0x4f), /* 0x20: MBOX_GET_LOOP_ID */
5155 ISPOPMAP(0x00, 0x00), /* 0x21: */
5156 ISPOPMAP(0x01, 0x07), /* 0x22: MBOX_GET_RETRY_COUNT */
5157 ISPOPMAP(0x00, 0x00), /* 0x23: */
5158 ISPOPMAP(0x00, 0x00), /* 0x24: */
5159 ISPOPMAP(0x00, 0x00), /* 0x25: */
5160 ISPOPMAP(0x00, 0x00), /* 0x26: */
5161 ISPOPMAP(0x00, 0x00), /* 0x27: */
5162 ISPOPMAP(0x01, 0x03), /* 0x28: MBOX_GET_FIRMWARE_OPTIONS */
5163 ISPOPMAP(0x03, 0x07), /* 0x29: MBOX_GET_PORT_QUEUE_PARAMS */
5164 ISPOPMAP(0x00, 0x00), /* 0x2a: */
5165 ISPOPMAP(0x00, 0x00), /* 0x2b: */
5166 ISPOPMAP(0x00, 0x00), /* 0x2c: */
5167 ISPOPMAP(0x00, 0x00), /* 0x2d: */
5168 ISPOPMAP(0x00, 0x00), /* 0x2e: */
5169 ISPOPMAP(0x00, 0x00), /* 0x2f: */
5170 ISPOPMAP(0x00, 0x00), /* 0x30: */
5171 ISPOPMAP(0x00, 0x00), /* 0x31: */
5172 ISPOPMAP(0x07, 0x07), /* 0x32: MBOX_SET_RETRY_COUNT */
5173 ISPOPMAP(0x00, 0x00), /* 0x33: */
5174 ISPOPMAP(0x00, 0x00), /* 0x34: */
5175 ISPOPMAP(0x00, 0x00), /* 0x35: */
5176 ISPOPMAP(0x00, 0x00), /* 0x36: */
5177 ISPOPMAP(0x00, 0x00), /* 0x37: */
5178 ISPOPMAP(0x0f, 0x01), /* 0x38: MBOX_SET_FIRMWARE_OPTIONS */
5179 ISPOPMAP(0x0f, 0x07), /* 0x39: MBOX_SET_PORT_QUEUE_PARAMS */
5180 ISPOPMAP(0x00, 0x00), /* 0x3a: */
5181 ISPOPMAP(0x00, 0x00), /* 0x3b: */
5182 ISPOPMAP(0x00, 0x00), /* 0x3c: */
5183 ISPOPMAP(0x00, 0x00), /* 0x3d: */
5184 ISPOPMAP(0x00, 0x00), /* 0x3e: */
5185 ISPOPMAP(0x00, 0x00), /* 0x3f: */
5186 ISPOPMAP(0x03, 0x01), /* 0x40: MBOX_LOOP_PORT_BYPASS */
5187 ISPOPMAP(0x03, 0x01), /* 0x41: MBOX_LOOP_PORT_ENABLE */
5188 ISPOPMAP(0x03, 0x07), /* 0x42: MBOX_GET_RESOURCE_COUNTS */
5189 ISPOPMAP(0x01, 0x01), /* 0x43: MBOX_REQUEST_NON_PARTICIPATING_MODE */
5190 ISPOPMAP(0x00, 0x00), /* 0x44: */
5191 ISPOPMAP(0x00, 0x00), /* 0x45: */
5192 ISPOPMAP(0x00, 0x00), /* 0x46: */
5193 ISPOPMAP(0xcf, 0x03), /* 0x47: GET PORT_DATABASE ENHANCED */
5194 ISPOPMAP(0x00, 0x00), /* 0x48: */
5195 ISPOPMAP(0x00, 0x00), /* 0x49: */
5196 ISPOPMAP(0x00, 0x00), /* 0x4a: */
5197 ISPOPMAP(0x00, 0x00), /* 0x4b: */
5198 ISPOPMAP(0x00, 0x00), /* 0x4c: */
5199 ISPOPMAP(0x00, 0x00), /* 0x4d: */
5200 ISPOPMAP(0x00, 0x00), /* 0x4e: */
5201 ISPOPMAP(0x00, 0x00), /* 0x4f: */
5202 ISPOPMAP(0x00, 0x00), /* 0x50: */
5203 ISPOPMAP(0x00, 0x00), /* 0x51: */
5204 ISPOPMAP(0x00, 0x00), /* 0x52: */
5205 ISPOPMAP(0x00, 0x00), /* 0x53: */
5206 ISPOPMAP(0xcf, 0x01), /* 0x54: EXECUTE IOCB A64 */
5207 ISPOPMAP(0x00, 0x00), /* 0x55: */
5208 ISPOPMAP(0x00, 0x00), /* 0x56: */
5209 ISPOPMAP(0x00, 0x00), /* 0x57: */
5210 ISPOPMAP(0x00, 0x00), /* 0x58: */
5211 ISPOPMAP(0x00, 0x00), /* 0x59: */
5212 ISPOPMAP(0x00, 0x00), /* 0x5a: */
5213 ISPOPMAP(0x03, 0x01), /* 0x5b: MBOX_DRIVER_HEARTBEAT */
5214 ISPOPMAP(0xcf, 0x01), /* 0x5c: MBOX_FW_HEARTBEAT */
5215 ISPOPMAP(0x07, 0x03), /* 0x5d: MBOX_GET_SET_DATA_RATE */
5216 ISPOPMAP(0x00, 0x00), /* 0x5e: */
5217 ISPOPMAP(0x00, 0x00), /* 0x5f: */
5218 ISPOPMAP(0xfd, 0x31), /* 0x60: MBOX_INIT_FIRMWARE */
5219 ISPOPMAP(0x00, 0x00), /* 0x61: */
5220 ISPOPMAP(0x01, 0x01), /* 0x62: MBOX_INIT_LIP */
5221 ISPOPMAP(0xcd, 0x03), /* 0x63: MBOX_GET_FC_AL_POSITION_MAP */
5222 ISPOPMAP(0xcf, 0x01), /* 0x64: MBOX_GET_PORT_DB */
5223 ISPOPMAP(0x07, 0x01), /* 0x65: MBOX_CLEAR_ACA */
5224 ISPOPMAP(0x07, 0x01), /* 0x66: MBOX_TARGET_RESET */
5225 ISPOPMAP(0x07, 0x01), /* 0x67: MBOX_CLEAR_TASK_SET */
5226 ISPOPMAP(0x07, 0x01), /* 0x68: MBOX_ABORT_TASK_SET */
5227 ISPOPMAP(0x01, 0x07), /* 0x69: MBOX_GET_FW_STATE */
5228 ISPOPMAP(0x03, 0xcf), /* 0x6a: MBOX_GET_PORT_NAME */
5229 ISPOPMAP(0xcf, 0x01), /* 0x6b: MBOX_GET_LINK_STATUS */
5230 ISPOPMAP(0x0f, 0x01), /* 0x6c: MBOX_INIT_LIP_RESET */
5231 ISPOPMAP(0x00, 0x00), /* 0x6d: */
5232 ISPOPMAP(0xcf, 0x03), /* 0x6e: MBOX_SEND_SNS */
5233 ISPOPMAP(0x0f, 0x07), /* 0x6f: MBOX_FABRIC_LOGIN */
5234 ISPOPMAP(0x03, 0x01), /* 0x70: MBOX_SEND_CHANGE_REQUEST */
5235 ISPOPMAP(0x03, 0x03), /* 0x71: MBOX_FABRIC_LOGOUT */
5236 ISPOPMAP(0x0f, 0x0f), /* 0x72: MBOX_INIT_LIP_LOGIN */
5237 ISPOPMAP(0x00, 0x00), /* 0x73: */
5238 ISPOPMAP(0x07, 0x01), /* 0x74: LOGIN LOOP PORT */
5239 ISPOPMAP(0xcf, 0x03), /* 0x75: GET PORT/NODE NAME LIST */
5240 ISPOPMAP(0x4f, 0x01), /* 0x76: SET VENDOR ID */
5241 ISPOPMAP(0xcd, 0x01), /* 0x77: INITIALIZE IP MAILBOX */
5242 ISPOPMAP(0x00, 0x00), /* 0x78: */
5243 ISPOPMAP(0x00, 0x00), /* 0x79: */
5244 ISPOPMAP(0x00, 0x00), /* 0x7a: */
5245 ISPOPMAP(0x00, 0x00), /* 0x7b: */
5246 ISPOPMAP(0x4f, 0x03), /* 0x7c: Get ID List */
5247 ISPOPMAP(0xcf, 0x01), /* 0x7d: SEND LFA */
5248 ISPOPMAP(0x0f, 0x01) /* 0x7e: LUN RESET */
5249};
5250/*
5251 * Footnotes
5252 *
5253 * (1): this sets bits 21..16 in mailbox register #8, which we nominally
5254 * do not access at this time in the core driver. The caller is
5255 * responsible for setting this register first (Gross!).
5256 */
5257
5258#ifndef ISP_STRIPPED
5259static char *fc_mbcmd_names[] = {
5260 "NO-OP",
5261 "LOAD RAM",
5262 "EXEC FIRMWARE",
5263 "DUMP RAM",
5264 "WRITE RAM WORD",
5265 "READ RAM WORD",
5266 "MAILBOX REG TEST",
5267 "VERIFY CHECKSUM",
5268 "ABOUT FIRMWARE",
5269 "LOAD RAM",
5270 "DUMP RAM",
5271 NULL,
5272 NULL,
5273 "READ RAM WORD EXTENDED",
5274 "CHECK FIRMWARE",
5275 NULL,
5276 "INIT REQUEST QUEUE",
5277 "INIT RESULT QUEUE",
5278 "EXECUTE IOCB",
5279 "WAKE UP",
5280 "STOP FIRMWARE",
5281 "ABORT",
5282 "ABORT DEVICE",
5283 "ABORT TARGET",
5284 "BUS RESET",
5285 "STOP QUEUE",
5286 "START QUEUE",
5287 "SINGLE STEP QUEUE",
5288 "ABORT QUEUE",
5289 "GET DEV QUEUE STATUS",
5290 NULL,
5291 "GET FIRMWARE STATUS",
5292 "GET LOOP ID",
5293 NULL,
5294 "GET RETRY COUNT",
5295 NULL,
5296 NULL,
5297 NULL,
5298 NULL,
5299 NULL,
5300 "GET FIRMWARE OPTIONS",
5301 "GET PORT QUEUE PARAMS",
5302 NULL,
5303 NULL,
5304 NULL,
5305 NULL,
5306 NULL,
5307 NULL,
5308 NULL,
5309 NULL,
5310 "SET RETRY COUNT",
5311 NULL,
5312 NULL,
5313 NULL,
5314 NULL,
5315 NULL,
5316 "SET FIRMWARE OPTIONS",
5317 "SET PORT QUEUE PARAMS",
5318 NULL,
5319 NULL,
5320 NULL,
5321 NULL,
5322 NULL,
5323 NULL,
5324 "LOOP PORT BYPASS",
5325 "LOOP PORT ENABLE",
5326 "GET RESOURCE COUNTS",
5327 "REQUEST NON PARTICIPATING MODE",
5328 NULL,
5329 NULL,
5330 NULL,
5331 "GET PORT DATABASE,, ENHANCED",
5332 NULL,
5333 NULL,
5334 NULL,
5335 NULL,
5336 NULL,
5337 NULL,
5338 NULL,
5339 NULL,
5340 NULL,
5341 NULL,
5342 NULL,
5343 NULL,
5344 "EXECUTE IOCB A64",
5345 NULL,
5346 NULL,
5347 NULL,
5348 NULL,
5349 NULL,
5350 NULL,
5351 "DRIVER HEARTBEAT",
5352 NULL,
5353 "GET/SET DATA RATE",
5354 NULL,
5355 NULL,
5356 "INIT FIRMWARE",
5357 NULL,
5358 "INIT LIP",
5359 "GET FC-AL POSITION MAP",
5360 "GET PORT DATABASE",
5361 "CLEAR ACA",
5362 "TARGET RESET",
5363 "CLEAR TASK SET",
5364 "ABORT TASK SET",
5365 "GET FW STATE",
5366 "GET PORT NAME",
5367 "GET LINK STATUS",
5368 "INIT LIP RESET",
5369 NULL,
5370 "SEND SNS",
5371 "FABRIC LOGIN",
5372 "SEND CHANGE REQUEST",
5373 "FABRIC LOGOUT",
5374 "INIT LIP LOGIN",
5375 NULL,
5376 "LOGIN LOOP PORT",
5377 "GET PORT/NODE NAME LIST",
5378 "SET VENDOR ID",
5379 "INITIALIZE IP MAILBOX",
5380 NULL,
5381 NULL,
5382 NULL,
5383 NULL,
5384 "Get ID List",
5385 "SEND LFA",
5386 "Lun RESET"
5387};
5388#endif
5389
5390static void
5391isp_mboxcmd_qnw(struct ispsoftc *isp, mbreg_t *mbp, int nodelay)
5392{
5393 unsigned int ibits, obits, box, opcode;
5315 const u_int16_t *mcp;
5394 const u_int32_t *mcp;
5316
5317 if (IS_FC(isp)) {
5318 mcp = mbpfc;
5319 } else {
5320 mcp = mbpscsi;
5321 }
5322 opcode = mbp->param[0];
5395
5396 if (IS_FC(isp)) {
5397 mcp = mbpfc;
5398 } else {
5399 mcp = mbpscsi;
5400 }
5401 opcode = mbp->param[0];
5323 ibits = HIBYT(mcp[opcode]) & NMBOX_BMASK(isp);
5324 obits = LOBYT(mcp[opcode]) & NMBOX_BMASK(isp);
5325 for (box = 0; box < MAX_MAILBOX; box++) {
5402 ibits = HIWRD(mcp[opcode]) & NMBOX_BMASK(isp);
5403 obits = LOWRD(mcp[opcode]) & NMBOX_BMASK(isp);
5404 ibits |= mbp->ibits;
5405 obits |= mbp->obits;
5406 for (box = 0; box < MAX_MAILBOX(isp); box++) {
5326 if (ibits & (1 << box)) {
5327 ISP_WRITE(isp, MBOX_OFF(box), mbp->param[box]);
5328 }
5329 if (nodelay == 0) {
5330 isp->isp_mboxtmp[box] = mbp->param[box] = 0;
5331 }
5332 }
5333 if (nodelay == 0) {
5334 isp->isp_lastmbxcmd = opcode;
5335 isp->isp_obits = obits;
5336 isp->isp_mboxbsy = 1;
5337 }
5338 ISP_WRITE(isp, HCCR, HCCR_CMD_SET_HOST_INT);
5339 /*
5340 * Oddly enough, if we're not delaying for an answer,
5341 * delay a bit to give the f/w a chance to pick up the
5342 * command.
5343 */
5344 if (nodelay) {
5345 USEC_DELAY(1000);
5346 }
5347}
5348
5349static void
5350isp_mboxcmd(struct ispsoftc *isp, mbreg_t *mbp, int logmask)
5351{
5352 char *cname, *xname, tname[16], mname[16];
5353 unsigned int lim, ibits, obits, box, opcode;
5407 if (ibits & (1 << box)) {
5408 ISP_WRITE(isp, MBOX_OFF(box), mbp->param[box]);
5409 }
5410 if (nodelay == 0) {
5411 isp->isp_mboxtmp[box] = mbp->param[box] = 0;
5412 }
5413 }
5414 if (nodelay == 0) {
5415 isp->isp_lastmbxcmd = opcode;
5416 isp->isp_obits = obits;
5417 isp->isp_mboxbsy = 1;
5418 }
5419 ISP_WRITE(isp, HCCR, HCCR_CMD_SET_HOST_INT);
5420 /*
5421 * Oddly enough, if we're not delaying for an answer,
5422 * delay a bit to give the f/w a chance to pick up the
5423 * command.
5424 */
5425 if (nodelay) {
5426 USEC_DELAY(1000);
5427 }
5428}
5429
5430static void
5431isp_mboxcmd(struct ispsoftc *isp, mbreg_t *mbp, int logmask)
5432{
5433 char *cname, *xname, tname[16], mname[16];
5434 unsigned int lim, ibits, obits, box, opcode;
5354 const u_int16_t *mcp;
5435 const u_int32_t *mcp;
5355
5356 if (IS_FC(isp)) {
5357 mcp = mbpfc;
5358 lim = (sizeof (mbpfc) / sizeof (mbpfc[0]));
5359 } else {
5360 mcp = mbpscsi;
5361 lim = (sizeof (mbpscsi) / sizeof (mbpscsi[0]));
5362 }
5363
5364 if ((opcode = mbp->param[0]) >= lim) {
5365 mbp->param[0] = MBOX_INVALID_COMMAND;
5366 isp_prt(isp, ISP_LOGERR, "Unknown Command 0x%x", opcode);
5367 return;
5368 }
5369
5436
5437 if (IS_FC(isp)) {
5438 mcp = mbpfc;
5439 lim = (sizeof (mbpfc) / sizeof (mbpfc[0]));
5440 } else {
5441 mcp = mbpscsi;
5442 lim = (sizeof (mbpscsi) / sizeof (mbpscsi[0]));
5443 }
5444
5445 if ((opcode = mbp->param[0]) >= lim) {
5446 mbp->param[0] = MBOX_INVALID_COMMAND;
5447 isp_prt(isp, ISP_LOGERR, "Unknown Command 0x%x", opcode);
5448 return;
5449 }
5450
5370 ibits = HIBYT(mcp[opcode]) & NMBOX_BMASK(isp);
5371 obits = LOBYT(mcp[opcode]) & NMBOX_BMASK(isp);
5451 ibits = HIWRD(mcp[opcode]) & NMBOX_BMASK(isp);
5452 obits = LOWRD(mcp[opcode]) & NMBOX_BMASK(isp);
5372
5453
5454 ibits |= mbp->ibits;
5455 obits |= mbp->obits;
5456
5373 if (ibits == 0 && obits == 0) {
5374 mbp->param[0] = MBOX_COMMAND_PARAM_ERROR;
5375 isp_prt(isp, ISP_LOGERR, "no parameters for 0x%x", opcode);
5376 return;
5377 }
5378
5379 /*
5380 * Get exclusive usage of mailbox registers.
5381 */
5382 MBOX_ACQUIRE(isp);
5383
5457 if (ibits == 0 && obits == 0) {
5458 mbp->param[0] = MBOX_COMMAND_PARAM_ERROR;
5459 isp_prt(isp, ISP_LOGERR, "no parameters for 0x%x", opcode);
5460 return;
5461 }
5462
5463 /*
5464 * Get exclusive usage of mailbox registers.
5465 */
5466 MBOX_ACQUIRE(isp);
5467
5384 for (box = 0; box < MAX_MAILBOX; box++) {
5468 for (box = 0; box < MAX_MAILBOX(isp); box++) {
5385 if (ibits & (1 << box)) {
5386 ISP_WRITE(isp, MBOX_OFF(box), mbp->param[box]);
5387 }
5388 isp->isp_mboxtmp[box] = mbp->param[box] = 0;
5389 }
5390
5391 isp->isp_lastmbxcmd = opcode;
5392
5393 /*
5394 * We assume that we can't overwrite a previous command.
5395 */
5396 isp->isp_obits = obits;
5397 isp->isp_mboxbsy = 1;
5398
5399 /*
5400 * Set Host Interrupt condition so that RISC will pick up mailbox regs.
5401 */
5402 ISP_WRITE(isp, HCCR, HCCR_CMD_SET_HOST_INT);
5403
5404 /*
5405 * While we haven't finished the command, spin our wheels here.
5406 */
5407 MBOX_WAIT_COMPLETE(isp);
5408
5409 if (isp->isp_mboxbsy) {
5410 /*
5411 * Command timed out.
5412 */
5413 isp->isp_mboxbsy = 0;
5414 MBOX_RELEASE(isp);
5415 return;
5416 }
5417
5418 /*
5419 * Copy back output registers.
5420 */
5469 if (ibits & (1 << box)) {
5470 ISP_WRITE(isp, MBOX_OFF(box), mbp->param[box]);
5471 }
5472 isp->isp_mboxtmp[box] = mbp->param[box] = 0;
5473 }
5474
5475 isp->isp_lastmbxcmd = opcode;
5476
5477 /*
5478 * We assume that we can't overwrite a previous command.
5479 */
5480 isp->isp_obits = obits;
5481 isp->isp_mboxbsy = 1;
5482
5483 /*
5484 * Set Host Interrupt condition so that RISC will pick up mailbox regs.
5485 */
5486 ISP_WRITE(isp, HCCR, HCCR_CMD_SET_HOST_INT);
5487
5488 /*
5489 * While we haven't finished the command, spin our wheels here.
5490 */
5491 MBOX_WAIT_COMPLETE(isp);
5492
5493 if (isp->isp_mboxbsy) {
5494 /*
5495 * Command timed out.
5496 */
5497 isp->isp_mboxbsy = 0;
5498 MBOX_RELEASE(isp);
5499 return;
5500 }
5501
5502 /*
5503 * Copy back output registers.
5504 */
5421 for (box = 0; box < MAX_MAILBOX; box++) {
5505 for (box = 0; box < MAX_MAILBOX(isp); box++) {
5422 if (obits & (1 << box)) {
5423 mbp->param[box] = isp->isp_mboxtmp[box];
5424 }
5425 }
5426
5427 MBOX_RELEASE(isp);
5428
5429 if (logmask == 0 || opcode == MBOX_EXEC_FIRMWARE) {
5430 return;
5431 }
5432#ifdef ISP_STRIPPED
5433 cname = NULL;
5434#else
5435 cname = (IS_FC(isp))? fc_mbcmd_names[opcode] : scsi_mbcmd_names[opcode];
5436#endif
5437 if (cname == NULL) {
5438 cname = tname;
5439 SNPRINTF(tname, sizeof tname, "opcode %x", opcode);
5440 }
5441
5442 /*
5443 * Just to be chatty here...
5444 */
5445 xname = NULL;
5446 switch (mbp->param[0]) {
5447 case MBOX_COMMAND_COMPLETE:
5448 break;
5449 case MBOX_INVALID_COMMAND:
5450 if (logmask & MBLOGMASK(MBOX_COMMAND_COMPLETE))
5451 xname = "INVALID COMMAND";
5452 break;
5453 case MBOX_HOST_INTERFACE_ERROR:
5454 if (logmask & MBLOGMASK(MBOX_HOST_INTERFACE_ERROR))
5455 xname = "HOST INTERFACE ERROR";
5456 break;
5457 case MBOX_TEST_FAILED:
5458 if (logmask & MBLOGMASK(MBOX_TEST_FAILED))
5459 xname = "TEST FAILED";
5460 break;
5461 case MBOX_COMMAND_ERROR:
5462 if (logmask & MBLOGMASK(MBOX_COMMAND_ERROR))
5463 xname = "COMMAND ERROR";
5464 break;
5465 case MBOX_COMMAND_PARAM_ERROR:
5466 if (logmask & MBLOGMASK(MBOX_COMMAND_PARAM_ERROR))
5467 xname = "COMMAND PARAMETER ERROR";
5468 break;
5469 case MBOX_LOOP_ID_USED:
5470 if (logmask & MBLOGMASK(MBOX_LOOP_ID_USED))
5471 xname = "LOOP ID ALREADY IN USE";
5472 break;
5473 case MBOX_PORT_ID_USED:
5474 if (logmask & MBLOGMASK(MBOX_PORT_ID_USED))
5475 xname = "PORT ID ALREADY IN USE";
5476 break;
5477 case MBOX_ALL_IDS_USED:
5478 if (logmask & MBLOGMASK(MBOX_ALL_IDS_USED))
5479 xname = "ALL LOOP IDS IN USE";
5480 break;
5481 case 0: /* special case */
5482 xname = "TIMEOUT";
5483 break;
5484 default:
5485 SNPRINTF(mname, sizeof mname, "error 0x%x", mbp->param[0]);
5486 xname = mname;
5487 break;
5488 }
5489 if (xname)
5490 isp_prt(isp, ISP_LOGALL, "Mailbox Command '%s' failed (%s)",
5491 cname, xname);
5492}
5493
5494static void
5495isp_fw_state(struct ispsoftc *isp)
5496{
5497 if (IS_FC(isp)) {
5498 mbreg_t mbs;
5499 fcparam *fcp = isp->isp_param;
5500
5506 if (obits & (1 << box)) {
5507 mbp->param[box] = isp->isp_mboxtmp[box];
5508 }
5509 }
5510
5511 MBOX_RELEASE(isp);
5512
5513 if (logmask == 0 || opcode == MBOX_EXEC_FIRMWARE) {
5514 return;
5515 }
5516#ifdef ISP_STRIPPED
5517 cname = NULL;
5518#else
5519 cname = (IS_FC(isp))? fc_mbcmd_names[opcode] : scsi_mbcmd_names[opcode];
5520#endif
5521 if (cname == NULL) {
5522 cname = tname;
5523 SNPRINTF(tname, sizeof tname, "opcode %x", opcode);
5524 }
5525
5526 /*
5527 * Just to be chatty here...
5528 */
5529 xname = NULL;
5530 switch (mbp->param[0]) {
5531 case MBOX_COMMAND_COMPLETE:
5532 break;
5533 case MBOX_INVALID_COMMAND:
5534 if (logmask & MBLOGMASK(MBOX_COMMAND_COMPLETE))
5535 xname = "INVALID COMMAND";
5536 break;
5537 case MBOX_HOST_INTERFACE_ERROR:
5538 if (logmask & MBLOGMASK(MBOX_HOST_INTERFACE_ERROR))
5539 xname = "HOST INTERFACE ERROR";
5540 break;
5541 case MBOX_TEST_FAILED:
5542 if (logmask & MBLOGMASK(MBOX_TEST_FAILED))
5543 xname = "TEST FAILED";
5544 break;
5545 case MBOX_COMMAND_ERROR:
5546 if (logmask & MBLOGMASK(MBOX_COMMAND_ERROR))
5547 xname = "COMMAND ERROR";
5548 break;
5549 case MBOX_COMMAND_PARAM_ERROR:
5550 if (logmask & MBLOGMASK(MBOX_COMMAND_PARAM_ERROR))
5551 xname = "COMMAND PARAMETER ERROR";
5552 break;
5553 case MBOX_LOOP_ID_USED:
5554 if (logmask & MBLOGMASK(MBOX_LOOP_ID_USED))
5555 xname = "LOOP ID ALREADY IN USE";
5556 break;
5557 case MBOX_PORT_ID_USED:
5558 if (logmask & MBLOGMASK(MBOX_PORT_ID_USED))
5559 xname = "PORT ID ALREADY IN USE";
5560 break;
5561 case MBOX_ALL_IDS_USED:
5562 if (logmask & MBLOGMASK(MBOX_ALL_IDS_USED))
5563 xname = "ALL LOOP IDS IN USE";
5564 break;
5565 case 0: /* special case */
5566 xname = "TIMEOUT";
5567 break;
5568 default:
5569 SNPRINTF(mname, sizeof mname, "error 0x%x", mbp->param[0]);
5570 xname = mname;
5571 break;
5572 }
5573 if (xname)
5574 isp_prt(isp, ISP_LOGALL, "Mailbox Command '%s' failed (%s)",
5575 cname, xname);
5576}
5577
5578static void
5579isp_fw_state(struct ispsoftc *isp)
5580{
5581 if (IS_FC(isp)) {
5582 mbreg_t mbs;
5583 fcparam *fcp = isp->isp_param;
5584
5585 MEMZERO(&mbs, sizeof (mbs));
5501 mbs.param[0] = MBOX_GET_FW_STATE;
5502 isp_mboxcmd(isp, &mbs, MBLOGALL);
5503 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
5504 fcp->isp_fwstate = mbs.param[1];
5505 }
5506 }
5507}
5508
5509static void
5510isp_update(struct ispsoftc *isp)
5511{
5512 int bus, upmask;
5513
5514 for (bus = 0, upmask = isp->isp_update; upmask != 0; bus++) {
5515 if (upmask & (1 << bus)) {
5516 isp_update_bus(isp, bus);
5517 }
5518 upmask &= ~(1 << bus);
5519 }
5520}
5521
5522static void
5523isp_update_bus(struct ispsoftc *isp, int bus)
5524{
5525 int tgt;
5526 mbreg_t mbs;
5527 sdparam *sdp;
5528
5529 isp->isp_update &= ~(1 << bus);
5530 if (IS_FC(isp)) {
5531 /*
5532 * There are no 'per-bus' settings for Fibre Channel.
5533 */
5534 return;
5535 }
5536 sdp = isp->isp_param;
5537 sdp += bus;
5586 mbs.param[0] = MBOX_GET_FW_STATE;
5587 isp_mboxcmd(isp, &mbs, MBLOGALL);
5588 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
5589 fcp->isp_fwstate = mbs.param[1];
5590 }
5591 }
5592}
5593
5594static void
5595isp_update(struct ispsoftc *isp)
5596{
5597 int bus, upmask;
5598
5599 for (bus = 0, upmask = isp->isp_update; upmask != 0; bus++) {
5600 if (upmask & (1 << bus)) {
5601 isp_update_bus(isp, bus);
5602 }
5603 upmask &= ~(1 << bus);
5604 }
5605}
5606
5607static void
5608isp_update_bus(struct ispsoftc *isp, int bus)
5609{
5610 int tgt;
5611 mbreg_t mbs;
5612 sdparam *sdp;
5613
5614 isp->isp_update &= ~(1 << bus);
5615 if (IS_FC(isp)) {
5616 /*
5617 * There are no 'per-bus' settings for Fibre Channel.
5618 */
5619 return;
5620 }
5621 sdp = isp->isp_param;
5622 sdp += bus;
5623 MEMZERO(&mbs, sizeof (mbs));
5538
5539 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
5540 u_int16_t flags, period, offset;
5541 int get;
5542
5543 if (sdp->isp_devparam[tgt].dev_enable == 0) {
5544 sdp->isp_devparam[tgt].dev_update = 0;
5545 sdp->isp_devparam[tgt].dev_refresh = 0;
5546 isp_prt(isp, ISP_LOGDEBUG0,
5547 "skipping target %d bus %d update", tgt, bus);
5548 continue;
5549 }
5550 /*
5551 * If the goal is to update the status of the device,
5552 * take what's in goal_flags and try and set the device
5553 * toward that. Otherwise, if we're just refreshing the
5554 * current device state, get the current parameters.
5555 */
5556
5557 /*
5558 * Refresh overrides set
5559 */
5560 if (sdp->isp_devparam[tgt].dev_refresh) {
5561 mbs.param[0] = MBOX_GET_TARGET_PARAMS;
5562 sdp->isp_devparam[tgt].dev_refresh = 0;
5563 get = 1;
5564 } else if (sdp->isp_devparam[tgt].dev_update) {
5565 mbs.param[0] = MBOX_SET_TARGET_PARAMS;
5566 /*
5567 * Make sure goal_flags has "Renegotiate on Error"
5568 * on and "Freeze Queue on Error" off.
5569 */
5570 sdp->isp_devparam[tgt].goal_flags |= DPARM_RENEG;
5571 sdp->isp_devparam[tgt].goal_flags &= ~DPARM_QFRZ;
5572
5573 mbs.param[2] = sdp->isp_devparam[tgt].goal_flags;
5574
5575 /*
5576 * Insist that PARITY must be enabled
5577 * if SYNC or WIDE is enabled.
5578 */
5579 if ((mbs.param[2] & (DPARM_SYNC|DPARM_WIDE)) != 0) {
5580 mbs.param[2] |= DPARM_PARITY;
5581 }
5582
5583 if ((mbs.param[2] & DPARM_SYNC) == 0) {
5584 mbs.param[3] = 0;
5585 } else {
5586 mbs.param[3] =
5587 (sdp->isp_devparam[tgt].goal_offset << 8) |
5588 (sdp->isp_devparam[tgt].goal_period);
5589 }
5590 /*
5591 * A command completion later that has
5592 * RQSTF_NEGOTIATION set can cause
5593 * the dev_refresh/announce cycle also.
5594 *
5595 * Note: It is really important to update our current
5596 * flags with at least the state of TAG capabilities-
5597 * otherwise we might try and send a tagged command
5598 * when we have it all turned off. So change it here
5599 * to say that current already matches goal.
5600 */
5601 sdp->isp_devparam[tgt].actv_flags &= ~DPARM_TQING;
5602 sdp->isp_devparam[tgt].actv_flags |=
5603 (sdp->isp_devparam[tgt].goal_flags & DPARM_TQING);
5604 isp_prt(isp, ISP_LOGDEBUG0,
5605 "bus %d set tgt %d flags 0x%x off 0x%x period 0x%x",
5606 bus, tgt, mbs.param[2], mbs.param[3] >> 8,
5607 mbs.param[3] & 0xff);
5608 sdp->isp_devparam[tgt].dev_update = 0;
5609 sdp->isp_devparam[tgt].dev_refresh = 1;
5610 get = 0;
5611 } else {
5612 continue;
5613 }
5614 mbs.param[1] = (bus << 15) | (tgt << 8);
5615 isp_mboxcmd(isp, &mbs, MBLOGALL);
5616 if (get == 0) {
5617 isp->isp_sendmarker |= (1 << bus);
5618 continue;
5619 }
5620 flags = mbs.param[2];
5621 period = mbs.param[3] & 0xff;
5622 offset = mbs.param[3] >> 8;
5623 sdp->isp_devparam[tgt].actv_flags = flags;
5624 sdp->isp_devparam[tgt].actv_period = period;
5625 sdp->isp_devparam[tgt].actv_offset = offset;
5626 get = (bus << 16) | tgt;
5627 (void) isp_async(isp, ISPASYNC_NEW_TGT_PARAMS, &get);
5628 }
5629
5630 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
5631 if (sdp->isp_devparam[tgt].dev_update ||
5632 sdp->isp_devparam[tgt].dev_refresh) {
5633 isp->isp_update |= (1 << bus);
5634 break;
5635 }
5636 }
5637}
5638
5639#ifndef DEFAULT_FRAMESIZE
5640#define DEFAULT_FRAMESIZE(isp) ICB_DFLT_FRMLEN
5641#endif
5642#ifndef DEFAULT_EXEC_THROTTLE
5643#define DEFAULT_EXEC_THROTTLE(isp) ISP_EXEC_THROTTLE
5644#endif
5645
5646static void
5647isp_setdfltparm(struct ispsoftc *isp, int channel)
5648{
5649 int tgt;
5650 mbreg_t mbs;
5651 sdparam *sdp;
5652
5624
5625 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
5626 u_int16_t flags, period, offset;
5627 int get;
5628
5629 if (sdp->isp_devparam[tgt].dev_enable == 0) {
5630 sdp->isp_devparam[tgt].dev_update = 0;
5631 sdp->isp_devparam[tgt].dev_refresh = 0;
5632 isp_prt(isp, ISP_LOGDEBUG0,
5633 "skipping target %d bus %d update", tgt, bus);
5634 continue;
5635 }
5636 /*
5637 * If the goal is to update the status of the device,
5638 * take what's in goal_flags and try and set the device
5639 * toward that. Otherwise, if we're just refreshing the
5640 * current device state, get the current parameters.
5641 */
5642
5643 /*
5644 * Refresh overrides set
5645 */
5646 if (sdp->isp_devparam[tgt].dev_refresh) {
5647 mbs.param[0] = MBOX_GET_TARGET_PARAMS;
5648 sdp->isp_devparam[tgt].dev_refresh = 0;
5649 get = 1;
5650 } else if (sdp->isp_devparam[tgt].dev_update) {
5651 mbs.param[0] = MBOX_SET_TARGET_PARAMS;
5652 /*
5653 * Make sure goal_flags has "Renegotiate on Error"
5654 * on and "Freeze Queue on Error" off.
5655 */
5656 sdp->isp_devparam[tgt].goal_flags |= DPARM_RENEG;
5657 sdp->isp_devparam[tgt].goal_flags &= ~DPARM_QFRZ;
5658
5659 mbs.param[2] = sdp->isp_devparam[tgt].goal_flags;
5660
5661 /*
5662 * Insist that PARITY must be enabled
5663 * if SYNC or WIDE is enabled.
5664 */
5665 if ((mbs.param[2] & (DPARM_SYNC|DPARM_WIDE)) != 0) {
5666 mbs.param[2] |= DPARM_PARITY;
5667 }
5668
5669 if ((mbs.param[2] & DPARM_SYNC) == 0) {
5670 mbs.param[3] = 0;
5671 } else {
5672 mbs.param[3] =
5673 (sdp->isp_devparam[tgt].goal_offset << 8) |
5674 (sdp->isp_devparam[tgt].goal_period);
5675 }
5676 /*
5677 * A command completion later that has
5678 * RQSTF_NEGOTIATION set can cause
5679 * the dev_refresh/announce cycle also.
5680 *
5681 * Note: It is really important to update our current
5682 * flags with at least the state of TAG capabilities-
5683 * otherwise we might try and send a tagged command
5684 * when we have it all turned off. So change it here
5685 * to say that current already matches goal.
5686 */
5687 sdp->isp_devparam[tgt].actv_flags &= ~DPARM_TQING;
5688 sdp->isp_devparam[tgt].actv_flags |=
5689 (sdp->isp_devparam[tgt].goal_flags & DPARM_TQING);
5690 isp_prt(isp, ISP_LOGDEBUG0,
5691 "bus %d set tgt %d flags 0x%x off 0x%x period 0x%x",
5692 bus, tgt, mbs.param[2], mbs.param[3] >> 8,
5693 mbs.param[3] & 0xff);
5694 sdp->isp_devparam[tgt].dev_update = 0;
5695 sdp->isp_devparam[tgt].dev_refresh = 1;
5696 get = 0;
5697 } else {
5698 continue;
5699 }
5700 mbs.param[1] = (bus << 15) | (tgt << 8);
5701 isp_mboxcmd(isp, &mbs, MBLOGALL);
5702 if (get == 0) {
5703 isp->isp_sendmarker |= (1 << bus);
5704 continue;
5705 }
5706 flags = mbs.param[2];
5707 period = mbs.param[3] & 0xff;
5708 offset = mbs.param[3] >> 8;
5709 sdp->isp_devparam[tgt].actv_flags = flags;
5710 sdp->isp_devparam[tgt].actv_period = period;
5711 sdp->isp_devparam[tgt].actv_offset = offset;
5712 get = (bus << 16) | tgt;
5713 (void) isp_async(isp, ISPASYNC_NEW_TGT_PARAMS, &get);
5714 }
5715
5716 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
5717 if (sdp->isp_devparam[tgt].dev_update ||
5718 sdp->isp_devparam[tgt].dev_refresh) {
5719 isp->isp_update |= (1 << bus);
5720 break;
5721 }
5722 }
5723}
5724
5725#ifndef DEFAULT_FRAMESIZE
5726#define DEFAULT_FRAMESIZE(isp) ICB_DFLT_FRMLEN
5727#endif
5728#ifndef DEFAULT_EXEC_THROTTLE
5729#define DEFAULT_EXEC_THROTTLE(isp) ISP_EXEC_THROTTLE
5730#endif
5731
5732static void
5733isp_setdfltparm(struct ispsoftc *isp, int channel)
5734{
5735 int tgt;
5736 mbreg_t mbs;
5737 sdparam *sdp;
5738
5739 MEMZERO(&mbs, sizeof (mbs));
5653 if (IS_FC(isp)) {
5654 fcparam *fcp = (fcparam *) isp->isp_param;
5655 int nvfail;
5656
5657 fcp += channel;
5658 if (fcp->isp_gotdparms) {
5659 return;
5660 }
5661 fcp->isp_gotdparms = 1;
5662 fcp->isp_maxfrmlen = DEFAULT_FRAMESIZE(isp);
5663 fcp->isp_maxalloc = ICB_DFLT_ALLOC;
5664 fcp->isp_execthrottle = DEFAULT_EXEC_THROTTLE(isp);
5665 fcp->isp_retry_delay = ICB_DFLT_RDELAY;
5666 fcp->isp_retry_count = ICB_DFLT_RCOUNT;
5667 /* Platform specific.... */
5668 fcp->isp_loopid = DEFAULT_LOOPID(isp);
5669 fcp->isp_nodewwn = DEFAULT_NODEWWN(isp);
5670 fcp->isp_portwwn = DEFAULT_PORTWWN(isp);
5671 fcp->isp_fwoptions = 0;
5672 fcp->isp_fwoptions |= ICBOPT_FAIRNESS;
5673 fcp->isp_fwoptions |= ICBOPT_PDBCHANGE_AE;
5674 fcp->isp_fwoptions |= ICBOPT_HARD_ADDRESS;
5675#ifndef ISP_NO_FASTPOST_FC
5676 fcp->isp_fwoptions |= ICBOPT_FAST_POST;
5677#endif
5678 if (isp->isp_confopts & ISP_CFG_FULL_DUPLEX)
5679 fcp->isp_fwoptions |= ICBOPT_FULL_DUPLEX;
5680
5681 /*
5682 * Make sure this is turned off now until we get
5683 * extended options from NVRAM
5684 */
5685 fcp->isp_fwoptions &= ~ICBOPT_EXTENDED;
5686
5687 /*
5688 * Now try and read NVRAM unless told to not do so.
5689 * This will set fcparam's isp_nodewwn && isp_portwwn.
5690 */
5691 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
5692 nvfail = isp_read_nvram(isp);
5693 if (nvfail)
5694 isp->isp_confopts |= ISP_CFG_NONVRAM;
5695 } else {
5696 nvfail = 1;
5697 }
5698 /*
5699 * Set node && port to override platform set defaults
5700 * unless the nvram read failed (or none was done),
5701 * or the platform code wants to use what had been
5702 * set in the defaults.
5703 */
5704 if (nvfail) {
5705 isp->isp_confopts |= ISP_CFG_OWNWWPN|ISP_CFG_OWNWWNN;
5706 }
5707 if (isp->isp_confopts & ISP_CFG_OWNWWNN) {
5708 isp_prt(isp, ISP_LOGCONFIG, "Using Node WWN 0x%08x%08x",
5709 (u_int32_t) (DEFAULT_NODEWWN(isp) >> 32),
5710 (u_int32_t) (DEFAULT_NODEWWN(isp) & 0xffffffff));
5711 ISP_NODEWWN(isp) = DEFAULT_NODEWWN(isp);
5712 } else {
5713 /*
5714 * We always start out with values derived
5715 * from NVRAM or our platform default.
5716 */
5717 ISP_NODEWWN(isp) = fcp->isp_nodewwn;
5718 }
5719 if (isp->isp_confopts & ISP_CFG_OWNWWPN) {
5720 isp_prt(isp, ISP_LOGCONFIG, "Using Port WWN 0x%08x%08x",
5721 (u_int32_t) (DEFAULT_PORTWWN(isp) >> 32),
5722 (u_int32_t) (DEFAULT_PORTWWN(isp) & 0xffffffff));
5723 ISP_PORTWWN(isp) = DEFAULT_PORTWWN(isp);
5724 } else {
5725 /*
5726 * We always start out with values derived
5727 * from NVRAM or our platform default.
5728 */
5729 ISP_PORTWWN(isp) = fcp->isp_portwwn;
5730 }
5731 return;
5732 }
5733
5734 sdp = (sdparam *) isp->isp_param;
5735 sdp += channel;
5736
5737 /*
5738 * Been there, done that, got the T-shirt...
5739 */
5740 if (sdp->isp_gotdparms) {
5741 return;
5742 }
5743 sdp->isp_gotdparms = 1;
5744
5745 /*
5746 * Establish some default parameters.
5747 */
5748 sdp->isp_cmd_dma_burst_enable = 0;
5749 sdp->isp_data_dma_burst_enabl = 1;
5750 sdp->isp_fifo_threshold = 0;
5751 sdp->isp_initiator_id = DEFAULT_IID(isp);
5752 if (isp->isp_type >= ISP_HA_SCSI_1040) {
5753 sdp->isp_async_data_setup = 9;
5754 } else {
5755 sdp->isp_async_data_setup = 6;
5756 }
5757 sdp->isp_selection_timeout = 250;
5758 sdp->isp_max_queue_depth = MAXISPREQUEST(isp);
5759 sdp->isp_tag_aging = 8;
5760 sdp->isp_bus_reset_delay = 5;
5761 /*
5762 * Don't retry selection, busy or queue full automatically- reflect
5763 * these back to us.
5764 */
5765 sdp->isp_retry_count = 0;
5766 sdp->isp_retry_delay = 0;
5767
5768 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
5769 sdp->isp_devparam[tgt].exc_throttle = ISP_EXEC_THROTTLE;
5770 sdp->isp_devparam[tgt].dev_enable = 1;
5771 }
5772
5773 /*
5774 * If we've not been told to avoid reading NVRAM, try and read it.
5775 * If we're successful reading it, we can then return because NVRAM
5776 * will tell us what the desired settings are. Otherwise, we establish
5777 * some reasonable 'fake' nvram and goal defaults.
5778 */
5779
5780 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
5781 if (isp_read_nvram(isp) == 0) {
5782 return;
5783 }
5784 }
5785
5786 /*
5787 * Now try and see whether we have specific values for them.
5788 */
5789 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
5790 mbs.param[0] = MBOX_GET_ACT_NEG_STATE;
5791 isp_mboxcmd(isp, &mbs, MBLOGNONE);
5792 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
5793 sdp->isp_req_ack_active_neg = 1;
5794 sdp->isp_data_line_active_neg = 1;
5795 } else {
5796 sdp->isp_req_ack_active_neg =
5797 (mbs.param[1+channel] >> 4) & 0x1;
5798 sdp->isp_data_line_active_neg =
5799 (mbs.param[1+channel] >> 5) & 0x1;
5800 }
5801 }
5802
5803 isp_prt(isp, ISP_LOGDEBUG0, sc0, sc3,
5804 0, sdp->isp_fifo_threshold, sdp->isp_initiator_id,
5805 sdp->isp_bus_reset_delay, sdp->isp_retry_count,
5806 sdp->isp_retry_delay, sdp->isp_async_data_setup);
5807 isp_prt(isp, ISP_LOGDEBUG0, sc1, sc3,
5808 sdp->isp_req_ack_active_neg, sdp->isp_data_line_active_neg,
5809 sdp->isp_data_dma_burst_enabl, sdp->isp_cmd_dma_burst_enable,
5810 sdp->isp_selection_timeout, sdp->isp_max_queue_depth);
5811
5812 /*
5813 * The trick here is to establish a default for the default (honk!)
5814 * state (goal_flags). Then try and get the current status from
5815 * the card to fill in the current state. We don't, in fact, set
5816 * the default to the SAFE default state- that's not the goal state.
5817 */
5818 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
5819 u_int8_t off, per;
5820 sdp->isp_devparam[tgt].actv_offset = 0;
5821 sdp->isp_devparam[tgt].actv_period = 0;
5822 sdp->isp_devparam[tgt].actv_flags = 0;
5823
5824 sdp->isp_devparam[tgt].goal_flags =
5825 sdp->isp_devparam[tgt].nvrm_flags = DPARM_DEFAULT;
5826
5827 /*
5828 * We default to Wide/Fast for versions less than a 1040
5829 * (unless it's SBus).
5830 */
5831 if (IS_ULTRA3(isp)) {
5832 off = ISP_80M_SYNCPARMS >> 8;
5833 per = ISP_80M_SYNCPARMS & 0xff;
5834 } else if (IS_ULTRA2(isp)) {
5835 off = ISP_40M_SYNCPARMS >> 8;
5836 per = ISP_40M_SYNCPARMS & 0xff;
5837 } else if (IS_1240(isp)) {
5838 off = ISP_20M_SYNCPARMS >> 8;
5839 per = ISP_20M_SYNCPARMS & 0xff;
5840 } else if ((isp->isp_bustype == ISP_BT_SBUS &&
5841 isp->isp_type < ISP_HA_SCSI_1020A) ||
5842 (isp->isp_bustype == ISP_BT_PCI &&
5843 isp->isp_type < ISP_HA_SCSI_1040) ||
5844 (isp->isp_clock && isp->isp_clock < 60) ||
5845 (sdp->isp_ultramode == 0)) {
5846 off = ISP_10M_SYNCPARMS >> 8;
5847 per = ISP_10M_SYNCPARMS & 0xff;
5848 } else {
5849 off = ISP_20M_SYNCPARMS_1040 >> 8;
5850 per = ISP_20M_SYNCPARMS_1040 & 0xff;
5851 }
5852 sdp->isp_devparam[tgt].goal_offset =
5853 sdp->isp_devparam[tgt].nvrm_offset = off;
5854 sdp->isp_devparam[tgt].goal_period =
5855 sdp->isp_devparam[tgt].nvrm_period = per;
5856
5857 isp_prt(isp, ISP_LOGDEBUG0, sc2, sc3,
5858 channel, tgt, sdp->isp_devparam[tgt].nvrm_flags,
5859 sdp->isp_devparam[tgt].nvrm_offset,
5860 sdp->isp_devparam[tgt].nvrm_period);
5861 }
5862}
5863
5864/*
5865 * Re-initialize the ISP and complete all orphaned commands
5866 * with a 'botched' notice. The reset/init routines should
5867 * not disturb an already active list of commands.
5868 *
5869 * Locks held prior to coming here.
5870 */
5871
5872void
5873isp_reinit(struct ispsoftc *isp)
5874{
5875 XS_T *xs;
5876 int i;
5877
5878 if (IS_FC(isp)) {
5879 isp_mark_getpdb_all(isp);
5880 }
5881 isp_reset(isp);
5882 if (isp->isp_state != ISP_RESETSTATE) {
5883 isp_prt(isp, ISP_LOGERR, "isp_reinit cannot reset card");
5884 } else if (isp->isp_role != ISP_ROLE_NONE) {
5885 isp_init(isp);
5886 if (isp->isp_state == ISP_INITSTATE) {
5887 isp->isp_state = ISP_RUNSTATE;
5888 }
5889 if (isp->isp_state != ISP_RUNSTATE) {
5890 isp_prt(isp, ISP_LOGERR,
5891 "isp_reinit cannot restart card");
5892 }
5893 }
5894 isp->isp_nactive = 0;
5895
5896 for (i = 0; i < isp->isp_maxcmds; i++) {
5897 u_int16_t handle;
5898 xs = isp->isp_xflist[i];
5899 if (xs == NULL) {
5900 continue;
5901 }
5902 handle = isp_index_handle(i);
5903 isp_destroy_handle(isp, handle);
5904 if (XS_XFRLEN(xs)) {
5905 ISP_DMAFREE(isp, xs, handle);
5906 XS_RESID(xs) = XS_XFRLEN(xs);
5907 } else {
5908 XS_RESID(xs) = 0;
5909 }
5910 XS_SETERR(xs, HBA_BUSRESET);
5911 isp_done(xs);
5912 }
5913}
5914
5915/*
5916 * NVRAM Routines
5917 */
5918static int
5919isp_read_nvram(struct ispsoftc *isp)
5920{
5921 int i, amt;
5922 u_int8_t csum, minversion;
5923 union {
5924 u_int8_t _x[ISP2100_NVRAM_SIZE];
5925 u_int16_t _s[ISP2100_NVRAM_SIZE>>1];
5926 } _n;
5927#define nvram_data _n._x
5928#define nvram_words _n._s
5929
5930 if (IS_FC(isp)) {
5931 amt = ISP2100_NVRAM_SIZE;
5932 minversion = 1;
5933 } else if (IS_ULTRA2(isp)) {
5934 amt = ISP1080_NVRAM_SIZE;
5935 minversion = 0;
5936 } else {
5937 amt = ISP_NVRAM_SIZE;
5938 minversion = 2;
5939 }
5940
5941 /*
5942 * Just read the first two words first to see if we have a valid
5943 * NVRAM to continue reading the rest with.
5944 */
5945 for (i = 0; i < 2; i++) {
5946 isp_rdnvram_word(isp, i, &nvram_words[i]);
5947 }
5948 if (nvram_data[0] != 'I' || nvram_data[1] != 'S' ||
5949 nvram_data[2] != 'P') {
5950 if (isp->isp_bustype != ISP_BT_SBUS) {
5951 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM header");
5952 isp_prt(isp, ISP_LOGDEBUG0, "%x %x %x",
5953 nvram_data[0], nvram_data[1], nvram_data[2]);
5954 }
5955 return (-1);
5956 }
5957 for (i = 2; i < amt>>1; i++) {
5958 isp_rdnvram_word(isp, i, &nvram_words[i]);
5959 }
5960 for (csum = 0, i = 0; i < amt; i++) {
5961 csum += nvram_data[i];
5962 }
5963 if (csum != 0) {
5964 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM checksum");
5965 return (-1);
5966 }
5967 if (ISP_NVRAM_VERSION(nvram_data) < minversion) {
5968 isp_prt(isp, ISP_LOGWARN, "version %d NVRAM not understood",
5969 ISP_NVRAM_VERSION(nvram_data));
5970 return (-1);
5971 }
5972
5973 if (IS_ULTRA3(isp)) {
5974 isp_parse_nvram_12160(isp, 0, nvram_data);
5975 if (IS_12160(isp))
5976 isp_parse_nvram_12160(isp, 1, nvram_data);
5977 } else if (IS_1080(isp)) {
5978 isp_parse_nvram_1080(isp, 0, nvram_data);
5979 } else if (IS_1280(isp) || IS_1240(isp)) {
5980 isp_parse_nvram_1080(isp, 0, nvram_data);
5981 isp_parse_nvram_1080(isp, 1, nvram_data);
5982 } else if (IS_SCSI(isp)) {
5983 isp_parse_nvram_1020(isp, nvram_data);
5984 } else {
5985 isp_parse_nvram_2100(isp, nvram_data);
5986 }
5987 return (0);
5988#undef nvram_data
5989#undef nvram_words
5990}
5991
5992static void
5993isp_rdnvram_word(struct ispsoftc *isp, int wo, u_int16_t *rp)
5994{
5995 int i, cbits;
5996 u_int16_t bit, rqst;
5997
5998 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT);
5999 USEC_DELAY(2);
6000 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT|BIU_NVRAM_CLOCK);
6001 USEC_DELAY(2);
6002
6003 if (IS_FC(isp)) {
6004 wo &= ((ISP2100_NVRAM_SIZE >> 1) - 1);
6005 if (IS_2312(isp) && isp->isp_port) {
6006 wo += 128;
6007 }
6008 rqst = (ISP_NVRAM_READ << 8) | wo;
6009 cbits = 10;
6010 } else if (IS_ULTRA2(isp)) {
6011 wo &= ((ISP1080_NVRAM_SIZE >> 1) - 1);
6012 rqst = (ISP_NVRAM_READ << 8) | wo;
6013 cbits = 10;
6014 } else {
6015 wo &= ((ISP_NVRAM_SIZE >> 1) - 1);
6016 rqst = (ISP_NVRAM_READ << 6) | wo;
6017 cbits = 8;
6018 }
6019
6020 /*
6021 * Clock the word select request out...
6022 */
6023 for (i = cbits; i >= 0; i--) {
6024 if ((rqst >> i) & 1) {
6025 bit = BIU_NVRAM_SELECT | BIU_NVRAM_DATAOUT;
6026 } else {
6027 bit = BIU_NVRAM_SELECT;
6028 }
6029 ISP_WRITE(isp, BIU_NVRAM, bit);
6030 USEC_DELAY(2);
6031 ISP_WRITE(isp, BIU_NVRAM, bit | BIU_NVRAM_CLOCK);
6032 USEC_DELAY(2);
6033 ISP_WRITE(isp, BIU_NVRAM, bit);
6034 USEC_DELAY(2);
6035 }
6036 /*
6037 * Now read the result back in (bits come back in MSB format).
6038 */
6039 *rp = 0;
6040 for (i = 0; i < 16; i++) {
6041 u_int16_t rv;
6042 *rp <<= 1;
6043 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT|BIU_NVRAM_CLOCK);
6044 USEC_DELAY(2);
6045 rv = ISP_READ(isp, BIU_NVRAM);
6046 if (rv & BIU_NVRAM_DATAIN) {
6047 *rp |= 1;
6048 }
6049 USEC_DELAY(2);
6050 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT);
6051 USEC_DELAY(2);
6052 }
6053 ISP_WRITE(isp, BIU_NVRAM, 0);
6054 USEC_DELAY(2);
6055 ISP_SWIZZLE_NVRAM_WORD(isp, rp);
6056}
6057
6058static void
6059isp_parse_nvram_1020(struct ispsoftc *isp, u_int8_t *nvram_data)
6060{
6061 sdparam *sdp = (sdparam *) isp->isp_param;
6062 int tgt;
6063
6064 sdp->isp_fifo_threshold =
6065 ISP_NVRAM_FIFO_THRESHOLD(nvram_data) |
6066 (ISP_NVRAM_FIFO_THRESHOLD_128(nvram_data) << 2);
6067
6068 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
6069 sdp->isp_initiator_id =
6070 ISP_NVRAM_INITIATOR_ID(nvram_data);
6071
6072 sdp->isp_bus_reset_delay =
6073 ISP_NVRAM_BUS_RESET_DELAY(nvram_data);
6074
6075 sdp->isp_retry_count =
6076 ISP_NVRAM_BUS_RETRY_COUNT(nvram_data);
6077
6078 sdp->isp_retry_delay =
6079 ISP_NVRAM_BUS_RETRY_DELAY(nvram_data);
6080
6081 sdp->isp_async_data_setup =
6082 ISP_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data);
6083
6084 if (isp->isp_type >= ISP_HA_SCSI_1040) {
6085 if (sdp->isp_async_data_setup < 9) {
6086 sdp->isp_async_data_setup = 9;
6087 }
6088 } else {
6089 if (sdp->isp_async_data_setup != 6) {
6090 sdp->isp_async_data_setup = 6;
6091 }
6092 }
6093
6094 sdp->isp_req_ack_active_neg =
6095 ISP_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data);
6096
6097 sdp->isp_data_line_active_neg =
6098 ISP_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data);
6099
6100 sdp->isp_data_dma_burst_enabl =
6101 ISP_NVRAM_DATA_DMA_BURST_ENABLE(nvram_data);
6102
6103 sdp->isp_cmd_dma_burst_enable =
6104 ISP_NVRAM_CMD_DMA_BURST_ENABLE(nvram_data);
6105
6106 sdp->isp_tag_aging =
6107 ISP_NVRAM_TAG_AGE_LIMIT(nvram_data);
6108
6109 sdp->isp_selection_timeout =
6110 ISP_NVRAM_SELECTION_TIMEOUT(nvram_data);
6111
6112 sdp->isp_max_queue_depth =
6113 ISP_NVRAM_MAX_QUEUE_DEPTH(nvram_data);
6114
6115 sdp->isp_fast_mttr = ISP_NVRAM_FAST_MTTR_ENABLE(nvram_data);
6116
6117 isp_prt(isp, ISP_LOGDEBUG0, sc0, sc4,
6118 0, sdp->isp_fifo_threshold, sdp->isp_initiator_id,
6119 sdp->isp_bus_reset_delay, sdp->isp_retry_count,
6120 sdp->isp_retry_delay, sdp->isp_async_data_setup);
6121 isp_prt(isp, ISP_LOGDEBUG0, sc1, sc4,
6122 sdp->isp_req_ack_active_neg, sdp->isp_data_line_active_neg,
6123 sdp->isp_data_dma_burst_enabl, sdp->isp_cmd_dma_burst_enable,
6124 sdp->isp_selection_timeout, sdp->isp_max_queue_depth);
6125
6126 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
6127 sdp->isp_devparam[tgt].dev_enable =
6128 ISP_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt);
6129 sdp->isp_devparam[tgt].exc_throttle =
6130 ISP_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt);
6131 sdp->isp_devparam[tgt].nvrm_offset =
6132 ISP_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt);
6133 sdp->isp_devparam[tgt].nvrm_period =
6134 ISP_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt);
6135 /*
6136 * We probably shouldn't lie about this, but it
6137 * it makes it much safer if we limit NVRAM values
6138 * to sanity.
6139 */
6140 if (isp->isp_type < ISP_HA_SCSI_1040) {
6141 /*
6142 * If we're not ultra, we can't possibly
6143 * be a shorter period than this.
6144 */
6145 if (sdp->isp_devparam[tgt].nvrm_period < 0x19) {
6146 sdp->isp_devparam[tgt].nvrm_period = 0x19;
6147 }
6148 if (sdp->isp_devparam[tgt].nvrm_offset > 0xc) {
6149 sdp->isp_devparam[tgt].nvrm_offset = 0x0c;
6150 }
6151 } else {
6152 if (sdp->isp_devparam[tgt].nvrm_offset > 0x8) {
6153 sdp->isp_devparam[tgt].nvrm_offset = 0x8;
6154 }
6155 }
6156 sdp->isp_devparam[tgt].nvrm_flags = 0;
6157 if (ISP_NVRAM_TGT_RENEG(nvram_data, tgt))
6158 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
6159 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
6160 if (ISP_NVRAM_TGT_TQING(nvram_data, tgt))
6161 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
6162 if (ISP_NVRAM_TGT_SYNC(nvram_data, tgt))
6163 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
6164 if (ISP_NVRAM_TGT_WIDE(nvram_data, tgt))
6165 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
6166 if (ISP_NVRAM_TGT_PARITY(nvram_data, tgt))
6167 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
6168 if (ISP_NVRAM_TGT_DISC(nvram_data, tgt))
6169 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
6170 sdp->isp_devparam[tgt].actv_flags = 0; /* we don't know */
6171 isp_prt(isp, ISP_LOGDEBUG0, sc2, sc4,
6172 0, tgt, sdp->isp_devparam[tgt].nvrm_flags,
6173 sdp->isp_devparam[tgt].nvrm_offset,
6174 sdp->isp_devparam[tgt].nvrm_period);
6175 sdp->isp_devparam[tgt].goal_offset =
6176 sdp->isp_devparam[tgt].nvrm_offset;
6177 sdp->isp_devparam[tgt].goal_period =
6178 sdp->isp_devparam[tgt].nvrm_period;
6179 sdp->isp_devparam[tgt].goal_flags =
6180 sdp->isp_devparam[tgt].nvrm_flags;
6181 }
6182}
6183
6184static void
6185isp_parse_nvram_1080(struct ispsoftc *isp, int bus, u_int8_t *nvram_data)
6186{
6187 sdparam *sdp = (sdparam *) isp->isp_param;
6188 int tgt;
6189
6190 sdp += bus;
6191
6192 sdp->isp_fifo_threshold =
6193 ISP1080_NVRAM_FIFO_THRESHOLD(nvram_data);
6194
6195 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
6196 sdp->isp_initiator_id =
6197 ISP1080_NVRAM_INITIATOR_ID(nvram_data, bus);
6198
6199 sdp->isp_bus_reset_delay =
6200 ISP1080_NVRAM_BUS_RESET_DELAY(nvram_data, bus);
6201
6202 sdp->isp_retry_count =
6203 ISP1080_NVRAM_BUS_RETRY_COUNT(nvram_data, bus);
6204
6205 sdp->isp_retry_delay =
6206 ISP1080_NVRAM_BUS_RETRY_DELAY(nvram_data, bus);
6207
6208 sdp->isp_async_data_setup =
6209 ISP1080_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data, bus);
6210
6211 sdp->isp_req_ack_active_neg =
6212 ISP1080_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data, bus);
6213
6214 sdp->isp_data_line_active_neg =
6215 ISP1080_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data, bus);
6216
6217 sdp->isp_data_dma_burst_enabl =
6218 ISP1080_NVRAM_BURST_ENABLE(nvram_data);
6219
6220 sdp->isp_cmd_dma_burst_enable =
6221 ISP1080_NVRAM_BURST_ENABLE(nvram_data);
6222
6223 sdp->isp_selection_timeout =
6224 ISP1080_NVRAM_SELECTION_TIMEOUT(nvram_data, bus);
6225
6226 sdp->isp_max_queue_depth =
6227 ISP1080_NVRAM_MAX_QUEUE_DEPTH(nvram_data, bus);
6228
6229 isp_prt(isp, ISP_LOGDEBUG0, sc0, sc4,
6230 bus, sdp->isp_fifo_threshold, sdp->isp_initiator_id,
6231 sdp->isp_bus_reset_delay, sdp->isp_retry_count,
6232 sdp->isp_retry_delay, sdp->isp_async_data_setup);
6233 isp_prt(isp, ISP_LOGDEBUG0, sc1, sc4,
6234 sdp->isp_req_ack_active_neg, sdp->isp_data_line_active_neg,
6235 sdp->isp_data_dma_burst_enabl, sdp->isp_cmd_dma_burst_enable,
6236 sdp->isp_selection_timeout, sdp->isp_max_queue_depth);
6237
6238
6239 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
6240 sdp->isp_devparam[tgt].dev_enable =
6241 ISP1080_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt, bus);
6242 sdp->isp_devparam[tgt].exc_throttle =
6243 ISP1080_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt, bus);
6244 sdp->isp_devparam[tgt].nvrm_offset =
6245 ISP1080_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt, bus);
6246 sdp->isp_devparam[tgt].nvrm_period =
6247 ISP1080_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt, bus);
6248 sdp->isp_devparam[tgt].nvrm_flags = 0;
6249 if (ISP1080_NVRAM_TGT_RENEG(nvram_data, tgt, bus))
6250 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
6251 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
6252 if (ISP1080_NVRAM_TGT_TQING(nvram_data, tgt, bus))
6253 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
6254 if (ISP1080_NVRAM_TGT_SYNC(nvram_data, tgt, bus))
6255 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
6256 if (ISP1080_NVRAM_TGT_WIDE(nvram_data, tgt, bus))
6257 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
6258 if (ISP1080_NVRAM_TGT_PARITY(nvram_data, tgt, bus))
6259 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
6260 if (ISP1080_NVRAM_TGT_DISC(nvram_data, tgt, bus))
6261 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
6262 sdp->isp_devparam[tgt].actv_flags = 0;
6263 isp_prt(isp, ISP_LOGDEBUG0, sc2, sc4,
6264 bus, tgt, sdp->isp_devparam[tgt].nvrm_flags,
6265 sdp->isp_devparam[tgt].nvrm_offset,
6266 sdp->isp_devparam[tgt].nvrm_period);
6267 sdp->isp_devparam[tgt].goal_offset =
6268 sdp->isp_devparam[tgt].nvrm_offset;
6269 sdp->isp_devparam[tgt].goal_period =
6270 sdp->isp_devparam[tgt].nvrm_period;
6271 sdp->isp_devparam[tgt].goal_flags =
6272 sdp->isp_devparam[tgt].nvrm_flags;
6273 }
6274}
6275
6276static void
6277isp_parse_nvram_12160(struct ispsoftc *isp, int bus, u_int8_t *nvram_data)
6278{
6279 sdparam *sdp = (sdparam *) isp->isp_param;
6280 int tgt;
6281
6282 sdp += bus;
6283
6284 sdp->isp_fifo_threshold =
6285 ISP12160_NVRAM_FIFO_THRESHOLD(nvram_data);
6286
6287 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
6288 sdp->isp_initiator_id =
6289 ISP12160_NVRAM_INITIATOR_ID(nvram_data, bus);
6290
6291 sdp->isp_bus_reset_delay =
6292 ISP12160_NVRAM_BUS_RESET_DELAY(nvram_data, bus);
6293
6294 sdp->isp_retry_count =
6295 ISP12160_NVRAM_BUS_RETRY_COUNT(nvram_data, bus);
6296
6297 sdp->isp_retry_delay =
6298 ISP12160_NVRAM_BUS_RETRY_DELAY(nvram_data, bus);
6299
6300 sdp->isp_async_data_setup =
6301 ISP12160_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data, bus);
6302
6303 sdp->isp_req_ack_active_neg =
6304 ISP12160_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data, bus);
6305
6306 sdp->isp_data_line_active_neg =
6307 ISP12160_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data, bus);
6308
6309 sdp->isp_data_dma_burst_enabl =
6310 ISP12160_NVRAM_BURST_ENABLE(nvram_data);
6311
6312 sdp->isp_cmd_dma_burst_enable =
6313 ISP12160_NVRAM_BURST_ENABLE(nvram_data);
6314
6315 sdp->isp_selection_timeout =
6316 ISP12160_NVRAM_SELECTION_TIMEOUT(nvram_data, bus);
6317
6318 sdp->isp_max_queue_depth =
6319 ISP12160_NVRAM_MAX_QUEUE_DEPTH(nvram_data, bus);
6320
6321 isp_prt(isp, ISP_LOGDEBUG0, sc0, sc4,
6322 bus, sdp->isp_fifo_threshold, sdp->isp_initiator_id,
6323 sdp->isp_bus_reset_delay, sdp->isp_retry_count,
6324 sdp->isp_retry_delay, sdp->isp_async_data_setup);
6325 isp_prt(isp, ISP_LOGDEBUG0, sc1, sc4,
6326 sdp->isp_req_ack_active_neg, sdp->isp_data_line_active_neg,
6327 sdp->isp_data_dma_burst_enabl, sdp->isp_cmd_dma_burst_enable,
6328 sdp->isp_selection_timeout, sdp->isp_max_queue_depth);
6329
6330 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
6331 sdp->isp_devparam[tgt].dev_enable =
6332 ISP12160_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt, bus);
6333 sdp->isp_devparam[tgt].exc_throttle =
6334 ISP12160_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt, bus);
6335 sdp->isp_devparam[tgt].nvrm_offset =
6336 ISP12160_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt, bus);
6337 sdp->isp_devparam[tgt].nvrm_period =
6338 ISP12160_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt, bus);
6339 sdp->isp_devparam[tgt].nvrm_flags = 0;
6340 if (ISP12160_NVRAM_TGT_RENEG(nvram_data, tgt, bus))
6341 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
6342 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
6343 if (ISP12160_NVRAM_TGT_TQING(nvram_data, tgt, bus))
6344 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
6345 if (ISP12160_NVRAM_TGT_SYNC(nvram_data, tgt, bus))
6346 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
6347 if (ISP12160_NVRAM_TGT_WIDE(nvram_data, tgt, bus))
6348 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
6349 if (ISP12160_NVRAM_TGT_PARITY(nvram_data, tgt, bus))
6350 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
6351 if (ISP12160_NVRAM_TGT_DISC(nvram_data, tgt, bus))
6352 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
6353 sdp->isp_devparam[tgt].actv_flags = 0;
6354 isp_prt(isp, ISP_LOGDEBUG0, sc2, sc4,
6355 bus, tgt, sdp->isp_devparam[tgt].nvrm_flags,
6356 sdp->isp_devparam[tgt].nvrm_offset,
6357 sdp->isp_devparam[tgt].nvrm_period);
6358 sdp->isp_devparam[tgt].goal_offset =
6359 sdp->isp_devparam[tgt].nvrm_offset;
6360 sdp->isp_devparam[tgt].goal_period =
6361 sdp->isp_devparam[tgt].nvrm_period;
6362 sdp->isp_devparam[tgt].goal_flags =
6363 sdp->isp_devparam[tgt].nvrm_flags;
6364 }
6365}
6366
6367static void
6368isp_parse_nvram_2100(struct ispsoftc *isp, u_int8_t *nvram_data)
6369{
6370 fcparam *fcp = (fcparam *) isp->isp_param;
6371 u_int64_t wwn;
6372
6373 /*
6374 * There is NVRAM storage for both Port and Node entities-
6375 * but the Node entity appears to be unused on all the cards
6376 * I can find. However, we should account for this being set
6377 * at some point in the future.
6378 *
6379 * Qlogic WWNs have an NAA of 2, but usually nothing shows up in
6380 * bits 48..60. In the case of the 2202, it appears that they do
6381 * use bit 48 to distinguish between the two instances on the card.
6382 * The 2204, which I've never seen, *probably* extends this method.
6383 */
6384 wwn = ISP2100_NVRAM_PORT_NAME(nvram_data);
6385 if (wwn) {
6386 isp_prt(isp, ISP_LOGCONFIG, "NVRAM Port WWN 0x%08x%08x",
6387 (u_int32_t) (wwn >> 32), (u_int32_t) (wwn & 0xffffffff));
6388 if ((wwn >> 60) == 0) {
6389 wwn |= (((u_int64_t) 2)<< 60);
6390 }
6391 }
6392 fcp->isp_portwwn = wwn;
6393 if (IS_2200(isp) || IS_23XX(isp)) {
6394 wwn = ISP2200_NVRAM_NODE_NAME(nvram_data);
6395 if (wwn) {
6396 isp_prt(isp, ISP_LOGCONFIG, "NVRAM Node WWN 0x%08x%08x",
6397 (u_int32_t) (wwn >> 32),
6398 (u_int32_t) (wwn & 0xffffffff));
6399 if ((wwn >> 60) == 0) {
6400 wwn |= (((u_int64_t) 2)<< 60);
6401 }
6402 }
6403 } else {
6404 wwn &= ~((u_int64_t) 0xfff << 48);
6405 }
6406 fcp->isp_nodewwn = wwn;
6407
6408 /*
6409 * Make sure we have both Node and Port as non-zero values.
6410 */
6411 if (fcp->isp_nodewwn != 0 && fcp->isp_portwwn == 0) {
6412 fcp->isp_portwwn = fcp->isp_nodewwn;
6413 } else if (fcp->isp_nodewwn == 0 && fcp->isp_portwwn != 0) {
6414 fcp->isp_nodewwn = fcp->isp_portwwn;
6415 }
6416
6417 /*
6418 * Make the Node and Port values sane if they're NAA == 2.
6419 * This means to clear bits 48..56 for the Node WWN and
6420 * make sure that there's some non-zero value in 48..56
6421 * for the Port WWN.
6422 */
6423 if (fcp->isp_nodewwn && fcp->isp_portwwn) {
6424 if ((fcp->isp_nodewwn & (((u_int64_t) 0xfff) << 48)) != 0 &&
6425 (fcp->isp_nodewwn >> 60) == 2) {
6426 fcp->isp_nodewwn &= ~((u_int64_t) 0xfff << 48);
6427 }
6428 if ((fcp->isp_portwwn & (((u_int64_t) 0xfff) << 48)) == 0 &&
6429 (fcp->isp_portwwn >> 60) == 2) {
6430 fcp->isp_portwwn |= ((u_int64_t) 1 << 56);
6431 }
6432 }
6433
6434 isp_prt(isp, ISP_LOGDEBUG0,
6435 "NVRAM: maxfrmlen %d execthrottle %d fwoptions 0x%x loopid %x",
6436 ISP2100_NVRAM_MAXFRAMELENGTH(nvram_data),
6437 ISP2100_NVRAM_EXECUTION_THROTTLE(nvram_data),
6438 ISP2100_NVRAM_OPTIONS(nvram_data),
6439 ISP2100_NVRAM_HARDLOOPID(nvram_data));
6440
6441 fcp->isp_maxalloc =
6442 ISP2100_NVRAM_MAXIOCBALLOCATION(nvram_data);
6443 if ((isp->isp_confopts & ISP_CFG_OWNFSZ) == 0)
6444 fcp->isp_maxfrmlen =
6445 ISP2100_NVRAM_MAXFRAMELENGTH(nvram_data);
6446 fcp->isp_retry_delay =
6447 ISP2100_NVRAM_RETRY_DELAY(nvram_data);
6448 fcp->isp_retry_count =
6449 ISP2100_NVRAM_RETRY_COUNT(nvram_data);
6450 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
6451 fcp->isp_loopid =
6452 ISP2100_NVRAM_HARDLOOPID(nvram_data);
6453 if ((isp->isp_confopts & ISP_CFG_OWNEXCTHROTTLE) == 0)
6454 fcp->isp_execthrottle =
6455 ISP2100_NVRAM_EXECUTION_THROTTLE(nvram_data);
6456 fcp->isp_fwoptions = ISP2100_NVRAM_OPTIONS(nvram_data);
6457}
6458
6459#ifdef ISP_FW_CRASH_DUMP
6460static void isp2200_fw_dump(struct ispsoftc *);
6461static void isp2300_fw_dump(struct ispsoftc *);
6462
6463static void
6464isp2200_fw_dump(struct ispsoftc *isp)
6465{
6466 int i, j;
6467 mbreg_t mbs;
6468 u_int16_t *ptr;
6469
5740 if (IS_FC(isp)) {
5741 fcparam *fcp = (fcparam *) isp->isp_param;
5742 int nvfail;
5743
5744 fcp += channel;
5745 if (fcp->isp_gotdparms) {
5746 return;
5747 }
5748 fcp->isp_gotdparms = 1;
5749 fcp->isp_maxfrmlen = DEFAULT_FRAMESIZE(isp);
5750 fcp->isp_maxalloc = ICB_DFLT_ALLOC;
5751 fcp->isp_execthrottle = DEFAULT_EXEC_THROTTLE(isp);
5752 fcp->isp_retry_delay = ICB_DFLT_RDELAY;
5753 fcp->isp_retry_count = ICB_DFLT_RCOUNT;
5754 /* Platform specific.... */
5755 fcp->isp_loopid = DEFAULT_LOOPID(isp);
5756 fcp->isp_nodewwn = DEFAULT_NODEWWN(isp);
5757 fcp->isp_portwwn = DEFAULT_PORTWWN(isp);
5758 fcp->isp_fwoptions = 0;
5759 fcp->isp_fwoptions |= ICBOPT_FAIRNESS;
5760 fcp->isp_fwoptions |= ICBOPT_PDBCHANGE_AE;
5761 fcp->isp_fwoptions |= ICBOPT_HARD_ADDRESS;
5762#ifndef ISP_NO_FASTPOST_FC
5763 fcp->isp_fwoptions |= ICBOPT_FAST_POST;
5764#endif
5765 if (isp->isp_confopts & ISP_CFG_FULL_DUPLEX)
5766 fcp->isp_fwoptions |= ICBOPT_FULL_DUPLEX;
5767
5768 /*
5769 * Make sure this is turned off now until we get
5770 * extended options from NVRAM
5771 */
5772 fcp->isp_fwoptions &= ~ICBOPT_EXTENDED;
5773
5774 /*
5775 * Now try and read NVRAM unless told to not do so.
5776 * This will set fcparam's isp_nodewwn && isp_portwwn.
5777 */
5778 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
5779 nvfail = isp_read_nvram(isp);
5780 if (nvfail)
5781 isp->isp_confopts |= ISP_CFG_NONVRAM;
5782 } else {
5783 nvfail = 1;
5784 }
5785 /*
5786 * Set node && port to override platform set defaults
5787 * unless the nvram read failed (or none was done),
5788 * or the platform code wants to use what had been
5789 * set in the defaults.
5790 */
5791 if (nvfail) {
5792 isp->isp_confopts |= ISP_CFG_OWNWWPN|ISP_CFG_OWNWWNN;
5793 }
5794 if (isp->isp_confopts & ISP_CFG_OWNWWNN) {
5795 isp_prt(isp, ISP_LOGCONFIG, "Using Node WWN 0x%08x%08x",
5796 (u_int32_t) (DEFAULT_NODEWWN(isp) >> 32),
5797 (u_int32_t) (DEFAULT_NODEWWN(isp) & 0xffffffff));
5798 ISP_NODEWWN(isp) = DEFAULT_NODEWWN(isp);
5799 } else {
5800 /*
5801 * We always start out with values derived
5802 * from NVRAM or our platform default.
5803 */
5804 ISP_NODEWWN(isp) = fcp->isp_nodewwn;
5805 }
5806 if (isp->isp_confopts & ISP_CFG_OWNWWPN) {
5807 isp_prt(isp, ISP_LOGCONFIG, "Using Port WWN 0x%08x%08x",
5808 (u_int32_t) (DEFAULT_PORTWWN(isp) >> 32),
5809 (u_int32_t) (DEFAULT_PORTWWN(isp) & 0xffffffff));
5810 ISP_PORTWWN(isp) = DEFAULT_PORTWWN(isp);
5811 } else {
5812 /*
5813 * We always start out with values derived
5814 * from NVRAM or our platform default.
5815 */
5816 ISP_PORTWWN(isp) = fcp->isp_portwwn;
5817 }
5818 return;
5819 }
5820
5821 sdp = (sdparam *) isp->isp_param;
5822 sdp += channel;
5823
5824 /*
5825 * Been there, done that, got the T-shirt...
5826 */
5827 if (sdp->isp_gotdparms) {
5828 return;
5829 }
5830 sdp->isp_gotdparms = 1;
5831
5832 /*
5833 * Establish some default parameters.
5834 */
5835 sdp->isp_cmd_dma_burst_enable = 0;
5836 sdp->isp_data_dma_burst_enabl = 1;
5837 sdp->isp_fifo_threshold = 0;
5838 sdp->isp_initiator_id = DEFAULT_IID(isp);
5839 if (isp->isp_type >= ISP_HA_SCSI_1040) {
5840 sdp->isp_async_data_setup = 9;
5841 } else {
5842 sdp->isp_async_data_setup = 6;
5843 }
5844 sdp->isp_selection_timeout = 250;
5845 sdp->isp_max_queue_depth = MAXISPREQUEST(isp);
5846 sdp->isp_tag_aging = 8;
5847 sdp->isp_bus_reset_delay = 5;
5848 /*
5849 * Don't retry selection, busy or queue full automatically- reflect
5850 * these back to us.
5851 */
5852 sdp->isp_retry_count = 0;
5853 sdp->isp_retry_delay = 0;
5854
5855 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
5856 sdp->isp_devparam[tgt].exc_throttle = ISP_EXEC_THROTTLE;
5857 sdp->isp_devparam[tgt].dev_enable = 1;
5858 }
5859
5860 /*
5861 * If we've not been told to avoid reading NVRAM, try and read it.
5862 * If we're successful reading it, we can then return because NVRAM
5863 * will tell us what the desired settings are. Otherwise, we establish
5864 * some reasonable 'fake' nvram and goal defaults.
5865 */
5866
5867 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
5868 if (isp_read_nvram(isp) == 0) {
5869 return;
5870 }
5871 }
5872
5873 /*
5874 * Now try and see whether we have specific values for them.
5875 */
5876 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
5877 mbs.param[0] = MBOX_GET_ACT_NEG_STATE;
5878 isp_mboxcmd(isp, &mbs, MBLOGNONE);
5879 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
5880 sdp->isp_req_ack_active_neg = 1;
5881 sdp->isp_data_line_active_neg = 1;
5882 } else {
5883 sdp->isp_req_ack_active_neg =
5884 (mbs.param[1+channel] >> 4) & 0x1;
5885 sdp->isp_data_line_active_neg =
5886 (mbs.param[1+channel] >> 5) & 0x1;
5887 }
5888 }
5889
5890 isp_prt(isp, ISP_LOGDEBUG0, sc0, sc3,
5891 0, sdp->isp_fifo_threshold, sdp->isp_initiator_id,
5892 sdp->isp_bus_reset_delay, sdp->isp_retry_count,
5893 sdp->isp_retry_delay, sdp->isp_async_data_setup);
5894 isp_prt(isp, ISP_LOGDEBUG0, sc1, sc3,
5895 sdp->isp_req_ack_active_neg, sdp->isp_data_line_active_neg,
5896 sdp->isp_data_dma_burst_enabl, sdp->isp_cmd_dma_burst_enable,
5897 sdp->isp_selection_timeout, sdp->isp_max_queue_depth);
5898
5899 /*
5900 * The trick here is to establish a default for the default (honk!)
5901 * state (goal_flags). Then try and get the current status from
5902 * the card to fill in the current state. We don't, in fact, set
5903 * the default to the SAFE default state- that's not the goal state.
5904 */
5905 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
5906 u_int8_t off, per;
5907 sdp->isp_devparam[tgt].actv_offset = 0;
5908 sdp->isp_devparam[tgt].actv_period = 0;
5909 sdp->isp_devparam[tgt].actv_flags = 0;
5910
5911 sdp->isp_devparam[tgt].goal_flags =
5912 sdp->isp_devparam[tgt].nvrm_flags = DPARM_DEFAULT;
5913
5914 /*
5915 * We default to Wide/Fast for versions less than a 1040
5916 * (unless it's SBus).
5917 */
5918 if (IS_ULTRA3(isp)) {
5919 off = ISP_80M_SYNCPARMS >> 8;
5920 per = ISP_80M_SYNCPARMS & 0xff;
5921 } else if (IS_ULTRA2(isp)) {
5922 off = ISP_40M_SYNCPARMS >> 8;
5923 per = ISP_40M_SYNCPARMS & 0xff;
5924 } else if (IS_1240(isp)) {
5925 off = ISP_20M_SYNCPARMS >> 8;
5926 per = ISP_20M_SYNCPARMS & 0xff;
5927 } else if ((isp->isp_bustype == ISP_BT_SBUS &&
5928 isp->isp_type < ISP_HA_SCSI_1020A) ||
5929 (isp->isp_bustype == ISP_BT_PCI &&
5930 isp->isp_type < ISP_HA_SCSI_1040) ||
5931 (isp->isp_clock && isp->isp_clock < 60) ||
5932 (sdp->isp_ultramode == 0)) {
5933 off = ISP_10M_SYNCPARMS >> 8;
5934 per = ISP_10M_SYNCPARMS & 0xff;
5935 } else {
5936 off = ISP_20M_SYNCPARMS_1040 >> 8;
5937 per = ISP_20M_SYNCPARMS_1040 & 0xff;
5938 }
5939 sdp->isp_devparam[tgt].goal_offset =
5940 sdp->isp_devparam[tgt].nvrm_offset = off;
5941 sdp->isp_devparam[tgt].goal_period =
5942 sdp->isp_devparam[tgt].nvrm_period = per;
5943
5944 isp_prt(isp, ISP_LOGDEBUG0, sc2, sc3,
5945 channel, tgt, sdp->isp_devparam[tgt].nvrm_flags,
5946 sdp->isp_devparam[tgt].nvrm_offset,
5947 sdp->isp_devparam[tgt].nvrm_period);
5948 }
5949}
5950
5951/*
5952 * Re-initialize the ISP and complete all orphaned commands
5953 * with a 'botched' notice. The reset/init routines should
5954 * not disturb an already active list of commands.
5955 *
5956 * Locks held prior to coming here.
5957 */
5958
5959void
5960isp_reinit(struct ispsoftc *isp)
5961{
5962 XS_T *xs;
5963 int i;
5964
5965 if (IS_FC(isp)) {
5966 isp_mark_getpdb_all(isp);
5967 }
5968 isp_reset(isp);
5969 if (isp->isp_state != ISP_RESETSTATE) {
5970 isp_prt(isp, ISP_LOGERR, "isp_reinit cannot reset card");
5971 } else if (isp->isp_role != ISP_ROLE_NONE) {
5972 isp_init(isp);
5973 if (isp->isp_state == ISP_INITSTATE) {
5974 isp->isp_state = ISP_RUNSTATE;
5975 }
5976 if (isp->isp_state != ISP_RUNSTATE) {
5977 isp_prt(isp, ISP_LOGERR,
5978 "isp_reinit cannot restart card");
5979 }
5980 }
5981 isp->isp_nactive = 0;
5982
5983 for (i = 0; i < isp->isp_maxcmds; i++) {
5984 u_int16_t handle;
5985 xs = isp->isp_xflist[i];
5986 if (xs == NULL) {
5987 continue;
5988 }
5989 handle = isp_index_handle(i);
5990 isp_destroy_handle(isp, handle);
5991 if (XS_XFRLEN(xs)) {
5992 ISP_DMAFREE(isp, xs, handle);
5993 XS_RESID(xs) = XS_XFRLEN(xs);
5994 } else {
5995 XS_RESID(xs) = 0;
5996 }
5997 XS_SETERR(xs, HBA_BUSRESET);
5998 isp_done(xs);
5999 }
6000}
6001
6002/*
6003 * NVRAM Routines
6004 */
6005static int
6006isp_read_nvram(struct ispsoftc *isp)
6007{
6008 int i, amt;
6009 u_int8_t csum, minversion;
6010 union {
6011 u_int8_t _x[ISP2100_NVRAM_SIZE];
6012 u_int16_t _s[ISP2100_NVRAM_SIZE>>1];
6013 } _n;
6014#define nvram_data _n._x
6015#define nvram_words _n._s
6016
6017 if (IS_FC(isp)) {
6018 amt = ISP2100_NVRAM_SIZE;
6019 minversion = 1;
6020 } else if (IS_ULTRA2(isp)) {
6021 amt = ISP1080_NVRAM_SIZE;
6022 minversion = 0;
6023 } else {
6024 amt = ISP_NVRAM_SIZE;
6025 minversion = 2;
6026 }
6027
6028 /*
6029 * Just read the first two words first to see if we have a valid
6030 * NVRAM to continue reading the rest with.
6031 */
6032 for (i = 0; i < 2; i++) {
6033 isp_rdnvram_word(isp, i, &nvram_words[i]);
6034 }
6035 if (nvram_data[0] != 'I' || nvram_data[1] != 'S' ||
6036 nvram_data[2] != 'P') {
6037 if (isp->isp_bustype != ISP_BT_SBUS) {
6038 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM header");
6039 isp_prt(isp, ISP_LOGDEBUG0, "%x %x %x",
6040 nvram_data[0], nvram_data[1], nvram_data[2]);
6041 }
6042 return (-1);
6043 }
6044 for (i = 2; i < amt>>1; i++) {
6045 isp_rdnvram_word(isp, i, &nvram_words[i]);
6046 }
6047 for (csum = 0, i = 0; i < amt; i++) {
6048 csum += nvram_data[i];
6049 }
6050 if (csum != 0) {
6051 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM checksum");
6052 return (-1);
6053 }
6054 if (ISP_NVRAM_VERSION(nvram_data) < minversion) {
6055 isp_prt(isp, ISP_LOGWARN, "version %d NVRAM not understood",
6056 ISP_NVRAM_VERSION(nvram_data));
6057 return (-1);
6058 }
6059
6060 if (IS_ULTRA3(isp)) {
6061 isp_parse_nvram_12160(isp, 0, nvram_data);
6062 if (IS_12160(isp))
6063 isp_parse_nvram_12160(isp, 1, nvram_data);
6064 } else if (IS_1080(isp)) {
6065 isp_parse_nvram_1080(isp, 0, nvram_data);
6066 } else if (IS_1280(isp) || IS_1240(isp)) {
6067 isp_parse_nvram_1080(isp, 0, nvram_data);
6068 isp_parse_nvram_1080(isp, 1, nvram_data);
6069 } else if (IS_SCSI(isp)) {
6070 isp_parse_nvram_1020(isp, nvram_data);
6071 } else {
6072 isp_parse_nvram_2100(isp, nvram_data);
6073 }
6074 return (0);
6075#undef nvram_data
6076#undef nvram_words
6077}
6078
6079static void
6080isp_rdnvram_word(struct ispsoftc *isp, int wo, u_int16_t *rp)
6081{
6082 int i, cbits;
6083 u_int16_t bit, rqst;
6084
6085 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT);
6086 USEC_DELAY(2);
6087 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT|BIU_NVRAM_CLOCK);
6088 USEC_DELAY(2);
6089
6090 if (IS_FC(isp)) {
6091 wo &= ((ISP2100_NVRAM_SIZE >> 1) - 1);
6092 if (IS_2312(isp) && isp->isp_port) {
6093 wo += 128;
6094 }
6095 rqst = (ISP_NVRAM_READ << 8) | wo;
6096 cbits = 10;
6097 } else if (IS_ULTRA2(isp)) {
6098 wo &= ((ISP1080_NVRAM_SIZE >> 1) - 1);
6099 rqst = (ISP_NVRAM_READ << 8) | wo;
6100 cbits = 10;
6101 } else {
6102 wo &= ((ISP_NVRAM_SIZE >> 1) - 1);
6103 rqst = (ISP_NVRAM_READ << 6) | wo;
6104 cbits = 8;
6105 }
6106
6107 /*
6108 * Clock the word select request out...
6109 */
6110 for (i = cbits; i >= 0; i--) {
6111 if ((rqst >> i) & 1) {
6112 bit = BIU_NVRAM_SELECT | BIU_NVRAM_DATAOUT;
6113 } else {
6114 bit = BIU_NVRAM_SELECT;
6115 }
6116 ISP_WRITE(isp, BIU_NVRAM, bit);
6117 USEC_DELAY(2);
6118 ISP_WRITE(isp, BIU_NVRAM, bit | BIU_NVRAM_CLOCK);
6119 USEC_DELAY(2);
6120 ISP_WRITE(isp, BIU_NVRAM, bit);
6121 USEC_DELAY(2);
6122 }
6123 /*
6124 * Now read the result back in (bits come back in MSB format).
6125 */
6126 *rp = 0;
6127 for (i = 0; i < 16; i++) {
6128 u_int16_t rv;
6129 *rp <<= 1;
6130 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT|BIU_NVRAM_CLOCK);
6131 USEC_DELAY(2);
6132 rv = ISP_READ(isp, BIU_NVRAM);
6133 if (rv & BIU_NVRAM_DATAIN) {
6134 *rp |= 1;
6135 }
6136 USEC_DELAY(2);
6137 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT);
6138 USEC_DELAY(2);
6139 }
6140 ISP_WRITE(isp, BIU_NVRAM, 0);
6141 USEC_DELAY(2);
6142 ISP_SWIZZLE_NVRAM_WORD(isp, rp);
6143}
6144
6145static void
6146isp_parse_nvram_1020(struct ispsoftc *isp, u_int8_t *nvram_data)
6147{
6148 sdparam *sdp = (sdparam *) isp->isp_param;
6149 int tgt;
6150
6151 sdp->isp_fifo_threshold =
6152 ISP_NVRAM_FIFO_THRESHOLD(nvram_data) |
6153 (ISP_NVRAM_FIFO_THRESHOLD_128(nvram_data) << 2);
6154
6155 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
6156 sdp->isp_initiator_id =
6157 ISP_NVRAM_INITIATOR_ID(nvram_data);
6158
6159 sdp->isp_bus_reset_delay =
6160 ISP_NVRAM_BUS_RESET_DELAY(nvram_data);
6161
6162 sdp->isp_retry_count =
6163 ISP_NVRAM_BUS_RETRY_COUNT(nvram_data);
6164
6165 sdp->isp_retry_delay =
6166 ISP_NVRAM_BUS_RETRY_DELAY(nvram_data);
6167
6168 sdp->isp_async_data_setup =
6169 ISP_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data);
6170
6171 if (isp->isp_type >= ISP_HA_SCSI_1040) {
6172 if (sdp->isp_async_data_setup < 9) {
6173 sdp->isp_async_data_setup = 9;
6174 }
6175 } else {
6176 if (sdp->isp_async_data_setup != 6) {
6177 sdp->isp_async_data_setup = 6;
6178 }
6179 }
6180
6181 sdp->isp_req_ack_active_neg =
6182 ISP_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data);
6183
6184 sdp->isp_data_line_active_neg =
6185 ISP_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data);
6186
6187 sdp->isp_data_dma_burst_enabl =
6188 ISP_NVRAM_DATA_DMA_BURST_ENABLE(nvram_data);
6189
6190 sdp->isp_cmd_dma_burst_enable =
6191 ISP_NVRAM_CMD_DMA_BURST_ENABLE(nvram_data);
6192
6193 sdp->isp_tag_aging =
6194 ISP_NVRAM_TAG_AGE_LIMIT(nvram_data);
6195
6196 sdp->isp_selection_timeout =
6197 ISP_NVRAM_SELECTION_TIMEOUT(nvram_data);
6198
6199 sdp->isp_max_queue_depth =
6200 ISP_NVRAM_MAX_QUEUE_DEPTH(nvram_data);
6201
6202 sdp->isp_fast_mttr = ISP_NVRAM_FAST_MTTR_ENABLE(nvram_data);
6203
6204 isp_prt(isp, ISP_LOGDEBUG0, sc0, sc4,
6205 0, sdp->isp_fifo_threshold, sdp->isp_initiator_id,
6206 sdp->isp_bus_reset_delay, sdp->isp_retry_count,
6207 sdp->isp_retry_delay, sdp->isp_async_data_setup);
6208 isp_prt(isp, ISP_LOGDEBUG0, sc1, sc4,
6209 sdp->isp_req_ack_active_neg, sdp->isp_data_line_active_neg,
6210 sdp->isp_data_dma_burst_enabl, sdp->isp_cmd_dma_burst_enable,
6211 sdp->isp_selection_timeout, sdp->isp_max_queue_depth);
6212
6213 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
6214 sdp->isp_devparam[tgt].dev_enable =
6215 ISP_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt);
6216 sdp->isp_devparam[tgt].exc_throttle =
6217 ISP_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt);
6218 sdp->isp_devparam[tgt].nvrm_offset =
6219 ISP_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt);
6220 sdp->isp_devparam[tgt].nvrm_period =
6221 ISP_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt);
6222 /*
6223 * We probably shouldn't lie about this, but it
6224 * it makes it much safer if we limit NVRAM values
6225 * to sanity.
6226 */
6227 if (isp->isp_type < ISP_HA_SCSI_1040) {
6228 /*
6229 * If we're not ultra, we can't possibly
6230 * be a shorter period than this.
6231 */
6232 if (sdp->isp_devparam[tgt].nvrm_period < 0x19) {
6233 sdp->isp_devparam[tgt].nvrm_period = 0x19;
6234 }
6235 if (sdp->isp_devparam[tgt].nvrm_offset > 0xc) {
6236 sdp->isp_devparam[tgt].nvrm_offset = 0x0c;
6237 }
6238 } else {
6239 if (sdp->isp_devparam[tgt].nvrm_offset > 0x8) {
6240 sdp->isp_devparam[tgt].nvrm_offset = 0x8;
6241 }
6242 }
6243 sdp->isp_devparam[tgt].nvrm_flags = 0;
6244 if (ISP_NVRAM_TGT_RENEG(nvram_data, tgt))
6245 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
6246 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
6247 if (ISP_NVRAM_TGT_TQING(nvram_data, tgt))
6248 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
6249 if (ISP_NVRAM_TGT_SYNC(nvram_data, tgt))
6250 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
6251 if (ISP_NVRAM_TGT_WIDE(nvram_data, tgt))
6252 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
6253 if (ISP_NVRAM_TGT_PARITY(nvram_data, tgt))
6254 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
6255 if (ISP_NVRAM_TGT_DISC(nvram_data, tgt))
6256 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
6257 sdp->isp_devparam[tgt].actv_flags = 0; /* we don't know */
6258 isp_prt(isp, ISP_LOGDEBUG0, sc2, sc4,
6259 0, tgt, sdp->isp_devparam[tgt].nvrm_flags,
6260 sdp->isp_devparam[tgt].nvrm_offset,
6261 sdp->isp_devparam[tgt].nvrm_period);
6262 sdp->isp_devparam[tgt].goal_offset =
6263 sdp->isp_devparam[tgt].nvrm_offset;
6264 sdp->isp_devparam[tgt].goal_period =
6265 sdp->isp_devparam[tgt].nvrm_period;
6266 sdp->isp_devparam[tgt].goal_flags =
6267 sdp->isp_devparam[tgt].nvrm_flags;
6268 }
6269}
6270
6271static void
6272isp_parse_nvram_1080(struct ispsoftc *isp, int bus, u_int8_t *nvram_data)
6273{
6274 sdparam *sdp = (sdparam *) isp->isp_param;
6275 int tgt;
6276
6277 sdp += bus;
6278
6279 sdp->isp_fifo_threshold =
6280 ISP1080_NVRAM_FIFO_THRESHOLD(nvram_data);
6281
6282 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
6283 sdp->isp_initiator_id =
6284 ISP1080_NVRAM_INITIATOR_ID(nvram_data, bus);
6285
6286 sdp->isp_bus_reset_delay =
6287 ISP1080_NVRAM_BUS_RESET_DELAY(nvram_data, bus);
6288
6289 sdp->isp_retry_count =
6290 ISP1080_NVRAM_BUS_RETRY_COUNT(nvram_data, bus);
6291
6292 sdp->isp_retry_delay =
6293 ISP1080_NVRAM_BUS_RETRY_DELAY(nvram_data, bus);
6294
6295 sdp->isp_async_data_setup =
6296 ISP1080_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data, bus);
6297
6298 sdp->isp_req_ack_active_neg =
6299 ISP1080_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data, bus);
6300
6301 sdp->isp_data_line_active_neg =
6302 ISP1080_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data, bus);
6303
6304 sdp->isp_data_dma_burst_enabl =
6305 ISP1080_NVRAM_BURST_ENABLE(nvram_data);
6306
6307 sdp->isp_cmd_dma_burst_enable =
6308 ISP1080_NVRAM_BURST_ENABLE(nvram_data);
6309
6310 sdp->isp_selection_timeout =
6311 ISP1080_NVRAM_SELECTION_TIMEOUT(nvram_data, bus);
6312
6313 sdp->isp_max_queue_depth =
6314 ISP1080_NVRAM_MAX_QUEUE_DEPTH(nvram_data, bus);
6315
6316 isp_prt(isp, ISP_LOGDEBUG0, sc0, sc4,
6317 bus, sdp->isp_fifo_threshold, sdp->isp_initiator_id,
6318 sdp->isp_bus_reset_delay, sdp->isp_retry_count,
6319 sdp->isp_retry_delay, sdp->isp_async_data_setup);
6320 isp_prt(isp, ISP_LOGDEBUG0, sc1, sc4,
6321 sdp->isp_req_ack_active_neg, sdp->isp_data_line_active_neg,
6322 sdp->isp_data_dma_burst_enabl, sdp->isp_cmd_dma_burst_enable,
6323 sdp->isp_selection_timeout, sdp->isp_max_queue_depth);
6324
6325
6326 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
6327 sdp->isp_devparam[tgt].dev_enable =
6328 ISP1080_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt, bus);
6329 sdp->isp_devparam[tgt].exc_throttle =
6330 ISP1080_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt, bus);
6331 sdp->isp_devparam[tgt].nvrm_offset =
6332 ISP1080_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt, bus);
6333 sdp->isp_devparam[tgt].nvrm_period =
6334 ISP1080_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt, bus);
6335 sdp->isp_devparam[tgt].nvrm_flags = 0;
6336 if (ISP1080_NVRAM_TGT_RENEG(nvram_data, tgt, bus))
6337 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
6338 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
6339 if (ISP1080_NVRAM_TGT_TQING(nvram_data, tgt, bus))
6340 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
6341 if (ISP1080_NVRAM_TGT_SYNC(nvram_data, tgt, bus))
6342 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
6343 if (ISP1080_NVRAM_TGT_WIDE(nvram_data, tgt, bus))
6344 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
6345 if (ISP1080_NVRAM_TGT_PARITY(nvram_data, tgt, bus))
6346 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
6347 if (ISP1080_NVRAM_TGT_DISC(nvram_data, tgt, bus))
6348 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
6349 sdp->isp_devparam[tgt].actv_flags = 0;
6350 isp_prt(isp, ISP_LOGDEBUG0, sc2, sc4,
6351 bus, tgt, sdp->isp_devparam[tgt].nvrm_flags,
6352 sdp->isp_devparam[tgt].nvrm_offset,
6353 sdp->isp_devparam[tgt].nvrm_period);
6354 sdp->isp_devparam[tgt].goal_offset =
6355 sdp->isp_devparam[tgt].nvrm_offset;
6356 sdp->isp_devparam[tgt].goal_period =
6357 sdp->isp_devparam[tgt].nvrm_period;
6358 sdp->isp_devparam[tgt].goal_flags =
6359 sdp->isp_devparam[tgt].nvrm_flags;
6360 }
6361}
6362
6363static void
6364isp_parse_nvram_12160(struct ispsoftc *isp, int bus, u_int8_t *nvram_data)
6365{
6366 sdparam *sdp = (sdparam *) isp->isp_param;
6367 int tgt;
6368
6369 sdp += bus;
6370
6371 sdp->isp_fifo_threshold =
6372 ISP12160_NVRAM_FIFO_THRESHOLD(nvram_data);
6373
6374 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
6375 sdp->isp_initiator_id =
6376 ISP12160_NVRAM_INITIATOR_ID(nvram_data, bus);
6377
6378 sdp->isp_bus_reset_delay =
6379 ISP12160_NVRAM_BUS_RESET_DELAY(nvram_data, bus);
6380
6381 sdp->isp_retry_count =
6382 ISP12160_NVRAM_BUS_RETRY_COUNT(nvram_data, bus);
6383
6384 sdp->isp_retry_delay =
6385 ISP12160_NVRAM_BUS_RETRY_DELAY(nvram_data, bus);
6386
6387 sdp->isp_async_data_setup =
6388 ISP12160_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data, bus);
6389
6390 sdp->isp_req_ack_active_neg =
6391 ISP12160_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data, bus);
6392
6393 sdp->isp_data_line_active_neg =
6394 ISP12160_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data, bus);
6395
6396 sdp->isp_data_dma_burst_enabl =
6397 ISP12160_NVRAM_BURST_ENABLE(nvram_data);
6398
6399 sdp->isp_cmd_dma_burst_enable =
6400 ISP12160_NVRAM_BURST_ENABLE(nvram_data);
6401
6402 sdp->isp_selection_timeout =
6403 ISP12160_NVRAM_SELECTION_TIMEOUT(nvram_data, bus);
6404
6405 sdp->isp_max_queue_depth =
6406 ISP12160_NVRAM_MAX_QUEUE_DEPTH(nvram_data, bus);
6407
6408 isp_prt(isp, ISP_LOGDEBUG0, sc0, sc4,
6409 bus, sdp->isp_fifo_threshold, sdp->isp_initiator_id,
6410 sdp->isp_bus_reset_delay, sdp->isp_retry_count,
6411 sdp->isp_retry_delay, sdp->isp_async_data_setup);
6412 isp_prt(isp, ISP_LOGDEBUG0, sc1, sc4,
6413 sdp->isp_req_ack_active_neg, sdp->isp_data_line_active_neg,
6414 sdp->isp_data_dma_burst_enabl, sdp->isp_cmd_dma_burst_enable,
6415 sdp->isp_selection_timeout, sdp->isp_max_queue_depth);
6416
6417 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
6418 sdp->isp_devparam[tgt].dev_enable =
6419 ISP12160_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt, bus);
6420 sdp->isp_devparam[tgt].exc_throttle =
6421 ISP12160_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt, bus);
6422 sdp->isp_devparam[tgt].nvrm_offset =
6423 ISP12160_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt, bus);
6424 sdp->isp_devparam[tgt].nvrm_period =
6425 ISP12160_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt, bus);
6426 sdp->isp_devparam[tgt].nvrm_flags = 0;
6427 if (ISP12160_NVRAM_TGT_RENEG(nvram_data, tgt, bus))
6428 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
6429 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
6430 if (ISP12160_NVRAM_TGT_TQING(nvram_data, tgt, bus))
6431 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
6432 if (ISP12160_NVRAM_TGT_SYNC(nvram_data, tgt, bus))
6433 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
6434 if (ISP12160_NVRAM_TGT_WIDE(nvram_data, tgt, bus))
6435 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
6436 if (ISP12160_NVRAM_TGT_PARITY(nvram_data, tgt, bus))
6437 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
6438 if (ISP12160_NVRAM_TGT_DISC(nvram_data, tgt, bus))
6439 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
6440 sdp->isp_devparam[tgt].actv_flags = 0;
6441 isp_prt(isp, ISP_LOGDEBUG0, sc2, sc4,
6442 bus, tgt, sdp->isp_devparam[tgt].nvrm_flags,
6443 sdp->isp_devparam[tgt].nvrm_offset,
6444 sdp->isp_devparam[tgt].nvrm_period);
6445 sdp->isp_devparam[tgt].goal_offset =
6446 sdp->isp_devparam[tgt].nvrm_offset;
6447 sdp->isp_devparam[tgt].goal_period =
6448 sdp->isp_devparam[tgt].nvrm_period;
6449 sdp->isp_devparam[tgt].goal_flags =
6450 sdp->isp_devparam[tgt].nvrm_flags;
6451 }
6452}
6453
6454static void
6455isp_parse_nvram_2100(struct ispsoftc *isp, u_int8_t *nvram_data)
6456{
6457 fcparam *fcp = (fcparam *) isp->isp_param;
6458 u_int64_t wwn;
6459
6460 /*
6461 * There is NVRAM storage for both Port and Node entities-
6462 * but the Node entity appears to be unused on all the cards
6463 * I can find. However, we should account for this being set
6464 * at some point in the future.
6465 *
6466 * Qlogic WWNs have an NAA of 2, but usually nothing shows up in
6467 * bits 48..60. In the case of the 2202, it appears that they do
6468 * use bit 48 to distinguish between the two instances on the card.
6469 * The 2204, which I've never seen, *probably* extends this method.
6470 */
6471 wwn = ISP2100_NVRAM_PORT_NAME(nvram_data);
6472 if (wwn) {
6473 isp_prt(isp, ISP_LOGCONFIG, "NVRAM Port WWN 0x%08x%08x",
6474 (u_int32_t) (wwn >> 32), (u_int32_t) (wwn & 0xffffffff));
6475 if ((wwn >> 60) == 0) {
6476 wwn |= (((u_int64_t) 2)<< 60);
6477 }
6478 }
6479 fcp->isp_portwwn = wwn;
6480 if (IS_2200(isp) || IS_23XX(isp)) {
6481 wwn = ISP2200_NVRAM_NODE_NAME(nvram_data);
6482 if (wwn) {
6483 isp_prt(isp, ISP_LOGCONFIG, "NVRAM Node WWN 0x%08x%08x",
6484 (u_int32_t) (wwn >> 32),
6485 (u_int32_t) (wwn & 0xffffffff));
6486 if ((wwn >> 60) == 0) {
6487 wwn |= (((u_int64_t) 2)<< 60);
6488 }
6489 }
6490 } else {
6491 wwn &= ~((u_int64_t) 0xfff << 48);
6492 }
6493 fcp->isp_nodewwn = wwn;
6494
6495 /*
6496 * Make sure we have both Node and Port as non-zero values.
6497 */
6498 if (fcp->isp_nodewwn != 0 && fcp->isp_portwwn == 0) {
6499 fcp->isp_portwwn = fcp->isp_nodewwn;
6500 } else if (fcp->isp_nodewwn == 0 && fcp->isp_portwwn != 0) {
6501 fcp->isp_nodewwn = fcp->isp_portwwn;
6502 }
6503
6504 /*
6505 * Make the Node and Port values sane if they're NAA == 2.
6506 * This means to clear bits 48..56 for the Node WWN and
6507 * make sure that there's some non-zero value in 48..56
6508 * for the Port WWN.
6509 */
6510 if (fcp->isp_nodewwn && fcp->isp_portwwn) {
6511 if ((fcp->isp_nodewwn & (((u_int64_t) 0xfff) << 48)) != 0 &&
6512 (fcp->isp_nodewwn >> 60) == 2) {
6513 fcp->isp_nodewwn &= ~((u_int64_t) 0xfff << 48);
6514 }
6515 if ((fcp->isp_portwwn & (((u_int64_t) 0xfff) << 48)) == 0 &&
6516 (fcp->isp_portwwn >> 60) == 2) {
6517 fcp->isp_portwwn |= ((u_int64_t) 1 << 56);
6518 }
6519 }
6520
6521 isp_prt(isp, ISP_LOGDEBUG0,
6522 "NVRAM: maxfrmlen %d execthrottle %d fwoptions 0x%x loopid %x",
6523 ISP2100_NVRAM_MAXFRAMELENGTH(nvram_data),
6524 ISP2100_NVRAM_EXECUTION_THROTTLE(nvram_data),
6525 ISP2100_NVRAM_OPTIONS(nvram_data),
6526 ISP2100_NVRAM_HARDLOOPID(nvram_data));
6527
6528 fcp->isp_maxalloc =
6529 ISP2100_NVRAM_MAXIOCBALLOCATION(nvram_data);
6530 if ((isp->isp_confopts & ISP_CFG_OWNFSZ) == 0)
6531 fcp->isp_maxfrmlen =
6532 ISP2100_NVRAM_MAXFRAMELENGTH(nvram_data);
6533 fcp->isp_retry_delay =
6534 ISP2100_NVRAM_RETRY_DELAY(nvram_data);
6535 fcp->isp_retry_count =
6536 ISP2100_NVRAM_RETRY_COUNT(nvram_data);
6537 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
6538 fcp->isp_loopid =
6539 ISP2100_NVRAM_HARDLOOPID(nvram_data);
6540 if ((isp->isp_confopts & ISP_CFG_OWNEXCTHROTTLE) == 0)
6541 fcp->isp_execthrottle =
6542 ISP2100_NVRAM_EXECUTION_THROTTLE(nvram_data);
6543 fcp->isp_fwoptions = ISP2100_NVRAM_OPTIONS(nvram_data);
6544}
6545
6546#ifdef ISP_FW_CRASH_DUMP
6547static void isp2200_fw_dump(struct ispsoftc *);
6548static void isp2300_fw_dump(struct ispsoftc *);
6549
6550static void
6551isp2200_fw_dump(struct ispsoftc *isp)
6552{
6553 int i, j;
6554 mbreg_t mbs;
6555 u_int16_t *ptr;
6556
6557 MEMZERO(&mbs, sizeof (mbs));
6470 ptr = FCPARAM(isp)->isp_dump_data;
6471 if (ptr == NULL) {
6472 isp_prt(isp, ISP_LOGERR,
6473 "No place to dump RISC registers and SRAM");
6474 return;
6475 }
6476 if (*ptr++) {
6477 isp_prt(isp, ISP_LOGERR,
6478 "dump area for RISC registers and SRAM already used");
6479 return;
6480 }
6481 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
6482 for (i = 0; i < 100; i++) {
6483 USEC_DELAY(100);
6484 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6485 break;
6486 }
6487 }
6488 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6489 /*
6490 * PBIU Registers
6491 */
6492 for (i = 0; i < 8; i++) {
6493 *ptr++ = ISP_READ(isp, BIU_BLOCK + (i << 1));
6494 }
6495
6496 /*
6497 * Mailbox Registers
6498 */
6499 for (i = 0; i < 8; i++) {
6500 *ptr++ = ISP_READ(isp, MBOX_BLOCK + (i << 1));
6501 }
6502
6503 /*
6504 * DMA Registers
6505 */
6506 for (i = 0; i < 48; i++) {
6507 *ptr++ = ISP_READ(isp, DMA_BLOCK + 0x20 + (i << 1));
6508 }
6509
6510 /*
6511 * RISC H/W Registers
6512 */
6513 ISP_WRITE(isp, BIU2100_CSR, 0);
6514 for (i = 0; i < 16; i++) {
6515 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0xA0 + (i << 1));
6516 }
6517
6518 /*
6519 * RISC GP Registers
6520 */
6521 for (j = 0; j < 8; j++) {
6522 ISP_WRITE(isp, BIU_BLOCK + 0xA4, 0x2000 + (j << 8));
6523 for (i = 0; i < 16; i++) {
6524 *ptr++ =
6525 ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6526 }
6527 }
6528
6529 /*
6530 * Frame Buffer Hardware Registers
6531 */
6532 ISP_WRITE(isp, BIU2100_CSR, 0x10);
6533 for (i = 0; i < 16; i++) {
6534 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6535 }
6536
6537 /*
6538 * Fibre Protocol Module 0 Hardware Registers
6539 */
6540 ISP_WRITE(isp, BIU2100_CSR, 0x20);
6541 for (i = 0; i < 64; i++) {
6542 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6543 }
6544
6545 /*
6546 * Fibre Protocol Module 1 Hardware Registers
6547 */
6548 ISP_WRITE(isp, BIU2100_CSR, 0x30);
6549 for (i = 0; i < 64; i++) {
6550 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6551 }
6552 } else {
6553 isp_prt(isp, ISP_LOGERR, "RISC Would Not Pause");
6554 return;
6555 }
6556 isp_prt(isp, ISP_LOGALL,
6557 "isp_fw_dump: RISC registers dumped successfully");
6558 ISP_WRITE(isp, BIU2100_CSR, BIU2100_SOFT_RESET);
6559 for (i = 0; i < 100; i++) {
6560 USEC_DELAY(100);
6561 if (ISP_READ(isp, OUTMAILBOX0) == 0) {
6562 break;
6563 }
6564 }
6565 if (ISP_READ(isp, OUTMAILBOX0) != 0) {
6566 isp_prt(isp, ISP_LOGERR, "Board Would Not Reset");
6567 return;
6568 }
6569 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
6570 for (i = 0; i < 100; i++) {
6571 USEC_DELAY(100);
6572 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6573 break;
6574 }
6575 }
6576 if ((ISP_READ(isp, HCCR) & HCCR_PAUSE) == 0) {
6577 isp_prt(isp, ISP_LOGERR, "RISC Would Not Pause After Reset");
6578 return;
6579 }
6580 ISP_WRITE(isp, RISC_EMB, 0xf2);
6581 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE);
6582 for (i = 0; i < 100; i++) {
6583 USEC_DELAY(100);
6584 if ((ISP_READ(isp, HCCR) & HCCR_PAUSE) == 0) {
6585 break;
6586 }
6587 }
6588 ENABLE_INTS(isp);
6589 mbs.param[0] = MBOX_READ_RAM_WORD;
6590 mbs.param[1] = 0x1000;
6591 isp->isp_mbxworkp = (void *) ptr;
6592 isp->isp_mbxwrk0 = 0xefff; /* continuation count */
6593 isp->isp_mbxwrk1 = 0x1001; /* next SRAM address */
6594 isp_control(isp, ISPCTL_RUN_MBOXCMD, &mbs);
6595 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
6596 isp_prt(isp, ISP_LOGWARN,
6597 "RAM DUMP FAILED @ WORD %x", isp->isp_mbxwrk1);
6598 return;
6599 }
6600 ptr = isp->isp_mbxworkp; /* finish fetch of final word */
6601 *ptr++ = isp->isp_mboxtmp[2];
6602 isp_prt(isp, ISP_LOGALL, "isp_fw_dump: SRAM dumped successfully");
6603 FCPARAM(isp)->isp_dump_data[0] = isp->isp_type; /* now used */
6604 (void) isp_async(isp, ISPASYNC_FW_DUMPED, 0);
6605}
6606
6607static void
6608isp2300_fw_dump(struct ispsoftc *isp)
6609{
6610 int i, j;
6611 mbreg_t mbs;
6612 u_int16_t *ptr;
6613
6558 ptr = FCPARAM(isp)->isp_dump_data;
6559 if (ptr == NULL) {
6560 isp_prt(isp, ISP_LOGERR,
6561 "No place to dump RISC registers and SRAM");
6562 return;
6563 }
6564 if (*ptr++) {
6565 isp_prt(isp, ISP_LOGERR,
6566 "dump area for RISC registers and SRAM already used");
6567 return;
6568 }
6569 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
6570 for (i = 0; i < 100; i++) {
6571 USEC_DELAY(100);
6572 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6573 break;
6574 }
6575 }
6576 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6577 /*
6578 * PBIU Registers
6579 */
6580 for (i = 0; i < 8; i++) {
6581 *ptr++ = ISP_READ(isp, BIU_BLOCK + (i << 1));
6582 }
6583
6584 /*
6585 * Mailbox Registers
6586 */
6587 for (i = 0; i < 8; i++) {
6588 *ptr++ = ISP_READ(isp, MBOX_BLOCK + (i << 1));
6589 }
6590
6591 /*
6592 * DMA Registers
6593 */
6594 for (i = 0; i < 48; i++) {
6595 *ptr++ = ISP_READ(isp, DMA_BLOCK + 0x20 + (i << 1));
6596 }
6597
6598 /*
6599 * RISC H/W Registers
6600 */
6601 ISP_WRITE(isp, BIU2100_CSR, 0);
6602 for (i = 0; i < 16; i++) {
6603 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0xA0 + (i << 1));
6604 }
6605
6606 /*
6607 * RISC GP Registers
6608 */
6609 for (j = 0; j < 8; j++) {
6610 ISP_WRITE(isp, BIU_BLOCK + 0xA4, 0x2000 + (j << 8));
6611 for (i = 0; i < 16; i++) {
6612 *ptr++ =
6613 ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6614 }
6615 }
6616
6617 /*
6618 * Frame Buffer Hardware Registers
6619 */
6620 ISP_WRITE(isp, BIU2100_CSR, 0x10);
6621 for (i = 0; i < 16; i++) {
6622 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6623 }
6624
6625 /*
6626 * Fibre Protocol Module 0 Hardware Registers
6627 */
6628 ISP_WRITE(isp, BIU2100_CSR, 0x20);
6629 for (i = 0; i < 64; i++) {
6630 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6631 }
6632
6633 /*
6634 * Fibre Protocol Module 1 Hardware Registers
6635 */
6636 ISP_WRITE(isp, BIU2100_CSR, 0x30);
6637 for (i = 0; i < 64; i++) {
6638 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6639 }
6640 } else {
6641 isp_prt(isp, ISP_LOGERR, "RISC Would Not Pause");
6642 return;
6643 }
6644 isp_prt(isp, ISP_LOGALL,
6645 "isp_fw_dump: RISC registers dumped successfully");
6646 ISP_WRITE(isp, BIU2100_CSR, BIU2100_SOFT_RESET);
6647 for (i = 0; i < 100; i++) {
6648 USEC_DELAY(100);
6649 if (ISP_READ(isp, OUTMAILBOX0) == 0) {
6650 break;
6651 }
6652 }
6653 if (ISP_READ(isp, OUTMAILBOX0) != 0) {
6654 isp_prt(isp, ISP_LOGERR, "Board Would Not Reset");
6655 return;
6656 }
6657 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
6658 for (i = 0; i < 100; i++) {
6659 USEC_DELAY(100);
6660 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6661 break;
6662 }
6663 }
6664 if ((ISP_READ(isp, HCCR) & HCCR_PAUSE) == 0) {
6665 isp_prt(isp, ISP_LOGERR, "RISC Would Not Pause After Reset");
6666 return;
6667 }
6668 ISP_WRITE(isp, RISC_EMB, 0xf2);
6669 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE);
6670 for (i = 0; i < 100; i++) {
6671 USEC_DELAY(100);
6672 if ((ISP_READ(isp, HCCR) & HCCR_PAUSE) == 0) {
6673 break;
6674 }
6675 }
6676 ENABLE_INTS(isp);
6677 mbs.param[0] = MBOX_READ_RAM_WORD;
6678 mbs.param[1] = 0x1000;
6679 isp->isp_mbxworkp = (void *) ptr;
6680 isp->isp_mbxwrk0 = 0xefff; /* continuation count */
6681 isp->isp_mbxwrk1 = 0x1001; /* next SRAM address */
6682 isp_control(isp, ISPCTL_RUN_MBOXCMD, &mbs);
6683 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
6684 isp_prt(isp, ISP_LOGWARN,
6685 "RAM DUMP FAILED @ WORD %x", isp->isp_mbxwrk1);
6686 return;
6687 }
6688 ptr = isp->isp_mbxworkp; /* finish fetch of final word */
6689 *ptr++ = isp->isp_mboxtmp[2];
6690 isp_prt(isp, ISP_LOGALL, "isp_fw_dump: SRAM dumped successfully");
6691 FCPARAM(isp)->isp_dump_data[0] = isp->isp_type; /* now used */
6692 (void) isp_async(isp, ISPASYNC_FW_DUMPED, 0);
6693}
6694
6695static void
6696isp2300_fw_dump(struct ispsoftc *isp)
6697{
6698 int i, j;
6699 mbreg_t mbs;
6700 u_int16_t *ptr;
6701
6702 MEMZERO(&mbs, sizeof (mbs));
6614 ptr = FCPARAM(isp)->isp_dump_data;
6615 if (ptr == NULL) {
6616 isp_prt(isp, ISP_LOGERR,
6617 "No place to dump RISC registers and SRAM");
6618 return;
6619 }
6620 if (*ptr++) {
6621 isp_prt(isp, ISP_LOGERR,
6622 "dump area for RISC registers and SRAM already used");
6623 return;
6624 }
6625 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
6626 for (i = 0; i < 100; i++) {
6627 USEC_DELAY(100);
6628 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6629 break;
6630 }
6631 }
6632 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6633 /*
6634 * PBIU registers
6635 */
6636 for (i = 0; i < 8; i++) {
6637 *ptr++ = ISP_READ(isp, BIU_BLOCK + (i << 1));
6638 }
6639
6640 /*
6641 * ReqQ-RspQ-Risc2Host Status registers
6642 */
6643 for (i = 0; i < 8; i++) {
6644 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x10 + (i << 1));
6645 }
6646
6647 /*
6648 * Mailbox Registers
6649 */
6650 for (i = 0; i < 32; i++) {
6651 *ptr++ =
6652 ISP_READ(isp, PCI_MBOX_REGS2300_OFF + (i << 1));
6653 }
6654
6655 /*
6656 * Auto Request Response DMA registers
6657 */
6658 ISP_WRITE(isp, BIU2100_CSR, 0x40);
6659 for (i = 0; i < 32; i++) {
6660 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6661 }
6662
6663 /*
6664 * DMA registers
6665 */
6666 ISP_WRITE(isp, BIU2100_CSR, 0x50);
6667 for (i = 0; i < 48; i++) {
6668 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6669 }
6670
6671 /*
6672 * RISC hardware registers
6673 */
6674 ISP_WRITE(isp, BIU2100_CSR, 0);
6675 for (i = 0; i < 16; i++) {
6676 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0xA0 + (i << 1));
6677 }
6678
6679 /*
6680 * RISC GP? registers
6681 */
6682 for (j = 0; j < 8; j++) {
6683 ISP_WRITE(isp, BIU_BLOCK + 0xA4, 0x2000 + (j << 9));
6684 for (i = 0; i < 16; i++) {
6685 *ptr++ =
6686 ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6687 }
6688 }
6689
6690 /*
6691 * frame buffer hardware registers
6692 */
6693 ISP_WRITE(isp, BIU2100_CSR, 0x10);
6694 for (i = 0; i < 64; i++) {
6695 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6696 }
6697
6698 /*
6699 * FPM B0 hardware registers
6700 */
6701 ISP_WRITE(isp, BIU2100_CSR, 0x20);
6702 for (i = 0; i < 64; i++) {
6703 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6704 }
6705
6706 /*
6707 * FPM B1 hardware registers
6708 */
6709 ISP_WRITE(isp, BIU2100_CSR, 0x30);
6710 for (i = 0; i < 64; i++) {
6711 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6712 }
6713 } else {
6714 isp_prt(isp, ISP_LOGERR, "RISC Would Not Pause");
6715 return;
6716 }
6717 isp_prt(isp, ISP_LOGALL,
6718 "isp_fw_dump: RISC registers dumped successfully");
6719 ISP_WRITE(isp, BIU2100_CSR, BIU2100_SOFT_RESET);
6720 for (i = 0; i < 100; i++) {
6721 USEC_DELAY(100);
6722 if (ISP_READ(isp, OUTMAILBOX0) == 0) {
6723 break;
6724 }
6725 }
6726 if (ISP_READ(isp, OUTMAILBOX0) != 0) {
6727 isp_prt(isp, ISP_LOGERR, "Board Would Not Reset");
6728 return;
6729 }
6730 ENABLE_INTS(isp);
6731 mbs.param[0] = MBOX_READ_RAM_WORD;
6732 mbs.param[1] = 0x800;
6733 isp->isp_mbxworkp = (void *) ptr;
6734 isp->isp_mbxwrk0 = 0xf7ff; /* continuation count */
6735 isp->isp_mbxwrk1 = 0x801; /* next SRAM address */
6736 isp_control(isp, ISPCTL_RUN_MBOXCMD, &mbs);
6737 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
6738 isp_prt(isp, ISP_LOGWARN,
6739 "RAM DUMP FAILED @ WORD %x", isp->isp_mbxwrk1);
6740 return;
6741 }
6742 ptr = isp->isp_mbxworkp; /* finish fetch of final word */
6743 *ptr++ = isp->isp_mboxtmp[2];
6744
6745 /*
6746 * We don't have access to mailbox registers 8.. onward
6747 * in our 'common' device model- so we have to set it
6748 * here and hope it stays the same!
6749 */
6750 ISP_WRITE(isp, PCI_MBOX_REGS2300_OFF + (8 << 1), 0x1);
6751
6752 mbs.param[0] = MBOX_READ_RAM_WORD_EXTENDED;
6753 mbs.param[1] = 0;
6754 isp->isp_mbxworkp = (void *) ptr;
6755 isp->isp_mbxwrk0 = 0xffff; /* continuation count */
6756 isp->isp_mbxwrk1 = 0x1; /* next SRAM address */
6757 isp_control(isp, ISPCTL_RUN_MBOXCMD, &mbs);
6758 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
6759 isp_prt(isp, ISP_LOGWARN,
6760 "RAM DUMP FAILED @ WORD %x", 0x10000 + isp->isp_mbxwrk1);
6761 return;
6762 }
6763 ptr = isp->isp_mbxworkp; /* finish final word */
6764 *ptr++ = mbs.param[2];
6765 isp_prt(isp, ISP_LOGALL, "isp_fw_dump: SRAM dumped successfully");
6766 FCPARAM(isp)->isp_dump_data[0] = isp->isp_type; /* now used */
6767 (void) isp_async(isp, ISPASYNC_FW_DUMPED, 0);
6768}
6769
6770void
6771isp_fw_dump(struct ispsoftc *isp)
6772{
6773 if (IS_2200(isp))
6774 isp2200_fw_dump(isp);
6775 else if (IS_23XX(isp))
6776 isp2300_fw_dump(isp);
6777}
6778#endif
6703 ptr = FCPARAM(isp)->isp_dump_data;
6704 if (ptr == NULL) {
6705 isp_prt(isp, ISP_LOGERR,
6706 "No place to dump RISC registers and SRAM");
6707 return;
6708 }
6709 if (*ptr++) {
6710 isp_prt(isp, ISP_LOGERR,
6711 "dump area for RISC registers and SRAM already used");
6712 return;
6713 }
6714 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
6715 for (i = 0; i < 100; i++) {
6716 USEC_DELAY(100);
6717 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6718 break;
6719 }
6720 }
6721 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6722 /*
6723 * PBIU registers
6724 */
6725 for (i = 0; i < 8; i++) {
6726 *ptr++ = ISP_READ(isp, BIU_BLOCK + (i << 1));
6727 }
6728
6729 /*
6730 * ReqQ-RspQ-Risc2Host Status registers
6731 */
6732 for (i = 0; i < 8; i++) {
6733 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x10 + (i << 1));
6734 }
6735
6736 /*
6737 * Mailbox Registers
6738 */
6739 for (i = 0; i < 32; i++) {
6740 *ptr++ =
6741 ISP_READ(isp, PCI_MBOX_REGS2300_OFF + (i << 1));
6742 }
6743
6744 /*
6745 * Auto Request Response DMA registers
6746 */
6747 ISP_WRITE(isp, BIU2100_CSR, 0x40);
6748 for (i = 0; i < 32; i++) {
6749 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6750 }
6751
6752 /*
6753 * DMA registers
6754 */
6755 ISP_WRITE(isp, BIU2100_CSR, 0x50);
6756 for (i = 0; i < 48; i++) {
6757 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6758 }
6759
6760 /*
6761 * RISC hardware registers
6762 */
6763 ISP_WRITE(isp, BIU2100_CSR, 0);
6764 for (i = 0; i < 16; i++) {
6765 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0xA0 + (i << 1));
6766 }
6767
6768 /*
6769 * RISC GP? registers
6770 */
6771 for (j = 0; j < 8; j++) {
6772 ISP_WRITE(isp, BIU_BLOCK + 0xA4, 0x2000 + (j << 9));
6773 for (i = 0; i < 16; i++) {
6774 *ptr++ =
6775 ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6776 }
6777 }
6778
6779 /*
6780 * frame buffer hardware registers
6781 */
6782 ISP_WRITE(isp, BIU2100_CSR, 0x10);
6783 for (i = 0; i < 64; i++) {
6784 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6785 }
6786
6787 /*
6788 * FPM B0 hardware registers
6789 */
6790 ISP_WRITE(isp, BIU2100_CSR, 0x20);
6791 for (i = 0; i < 64; i++) {
6792 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6793 }
6794
6795 /*
6796 * FPM B1 hardware registers
6797 */
6798 ISP_WRITE(isp, BIU2100_CSR, 0x30);
6799 for (i = 0; i < 64; i++) {
6800 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6801 }
6802 } else {
6803 isp_prt(isp, ISP_LOGERR, "RISC Would Not Pause");
6804 return;
6805 }
6806 isp_prt(isp, ISP_LOGALL,
6807 "isp_fw_dump: RISC registers dumped successfully");
6808 ISP_WRITE(isp, BIU2100_CSR, BIU2100_SOFT_RESET);
6809 for (i = 0; i < 100; i++) {
6810 USEC_DELAY(100);
6811 if (ISP_READ(isp, OUTMAILBOX0) == 0) {
6812 break;
6813 }
6814 }
6815 if (ISP_READ(isp, OUTMAILBOX0) != 0) {
6816 isp_prt(isp, ISP_LOGERR, "Board Would Not Reset");
6817 return;
6818 }
6819 ENABLE_INTS(isp);
6820 mbs.param[0] = MBOX_READ_RAM_WORD;
6821 mbs.param[1] = 0x800;
6822 isp->isp_mbxworkp = (void *) ptr;
6823 isp->isp_mbxwrk0 = 0xf7ff; /* continuation count */
6824 isp->isp_mbxwrk1 = 0x801; /* next SRAM address */
6825 isp_control(isp, ISPCTL_RUN_MBOXCMD, &mbs);
6826 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
6827 isp_prt(isp, ISP_LOGWARN,
6828 "RAM DUMP FAILED @ WORD %x", isp->isp_mbxwrk1);
6829 return;
6830 }
6831 ptr = isp->isp_mbxworkp; /* finish fetch of final word */
6832 *ptr++ = isp->isp_mboxtmp[2];
6833
6834 /*
6835 * We don't have access to mailbox registers 8.. onward
6836 * in our 'common' device model- so we have to set it
6837 * here and hope it stays the same!
6838 */
6839 ISP_WRITE(isp, PCI_MBOX_REGS2300_OFF + (8 << 1), 0x1);
6840
6841 mbs.param[0] = MBOX_READ_RAM_WORD_EXTENDED;
6842 mbs.param[1] = 0;
6843 isp->isp_mbxworkp = (void *) ptr;
6844 isp->isp_mbxwrk0 = 0xffff; /* continuation count */
6845 isp->isp_mbxwrk1 = 0x1; /* next SRAM address */
6846 isp_control(isp, ISPCTL_RUN_MBOXCMD, &mbs);
6847 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
6848 isp_prt(isp, ISP_LOGWARN,
6849 "RAM DUMP FAILED @ WORD %x", 0x10000 + isp->isp_mbxwrk1);
6850 return;
6851 }
6852 ptr = isp->isp_mbxworkp; /* finish final word */
6853 *ptr++ = mbs.param[2];
6854 isp_prt(isp, ISP_LOGALL, "isp_fw_dump: SRAM dumped successfully");
6855 FCPARAM(isp)->isp_dump_data[0] = isp->isp_type; /* now used */
6856 (void) isp_async(isp, ISPASYNC_FW_DUMPED, 0);
6857}
6858
6859void
6860isp_fw_dump(struct ispsoftc *isp)
6861{
6862 if (IS_2200(isp))
6863 isp2200_fw_dump(isp);
6864 else if (IS_23XX(isp))
6865 isp2300_fw_dump(isp);
6866}
6867#endif