isp_netbsd.c revision 1.16 1 1.16 thorpej /* $NetBSD: isp_netbsd.c,v 1.16 1999/09/30 23:06:18 thorpej Exp $ */
2 1.15 mjacob /* release_6_5_99 */
3 1.1 mjacob /*
4 1.1 mjacob * Platform (NetBSD) dependent common attachment code for Qlogic adapters.
5 1.15 mjacob * Matthew Jacob <mjacob (at) nas.nasa.gov>
6 1.15 mjacob */
7 1.15 mjacob /*
8 1.15 mjacob * Copyright (C) 1997, 1998, 1999 National Aeronautics & Space Administration
9 1.1 mjacob * All rights reserved.
10 1.1 mjacob *
11 1.1 mjacob * Redistribution and use in source and binary forms, with or without
12 1.1 mjacob * modification, are permitted provided that the following conditions
13 1.1 mjacob * are met:
14 1.1 mjacob * 1. Redistributions of source code must retain the above copyright
15 1.15 mjacob * notice, this list of conditions and the following disclaimer.
16 1.1 mjacob * 2. Redistributions in binary form must reproduce the above copyright
17 1.1 mjacob * notice, this list of conditions and the following disclaimer in the
18 1.1 mjacob * documentation and/or other materials provided with the distribution.
19 1.1 mjacob * 3. The name of the author may not be used to endorse or promote products
20 1.15 mjacob * derived from this software without specific prior written permission
21 1.1 mjacob *
22 1.15 mjacob * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 1.15 mjacob * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 1.15 mjacob * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 1.15 mjacob * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 1.15 mjacob * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 1.15 mjacob * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 1.15 mjacob * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 1.15 mjacob * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 1.15 mjacob * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 1.15 mjacob * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 1.1 mjacob */
33 1.1 mjacob
34 1.1 mjacob #include <dev/ic/isp_netbsd.h>
35 1.1 mjacob
36 1.1 mjacob static void ispminphys __P((struct buf *));
37 1.1 mjacob static int32_t ispcmd __P((ISP_SCSI_XFER_T *));
38 1.1 mjacob
39 1.1 mjacob static struct scsipi_device isp_dev = { NULL, NULL, NULL, NULL };
40 1.1 mjacob static int isp_poll __P((struct ispsoftc *, ISP_SCSI_XFER_T *, int));
41 1.10 mjacob static void isp_watch __P((void *));
42 1.10 mjacob static void isp_internal_restart __P((void *));
43 1.10 mjacob
44 1.10 mjacob #define FC_OPENINGS RQUEST_QUEUE_LEN / (MAX_FC_TARG-1)
45 1.10 mjacob #define PI_OPENINGS RQUEST_QUEUE_LEN / (MAX_TARGETS-1)
46 1.1 mjacob
47 1.1 mjacob /*
48 1.1 mjacob * Complete attachment of hardware, include subdevices.
49 1.1 mjacob */
50 1.1 mjacob void
51 1.1 mjacob isp_attach(isp)
52 1.1 mjacob struct ispsoftc *isp;
53 1.1 mjacob {
54 1.6 thorpej
55 1.6 thorpej isp->isp_osinfo._adapter.scsipi_cmd = ispcmd;
56 1.6 thorpej isp->isp_osinfo._adapter.scsipi_minphys = ispminphys;
57 1.6 thorpej
58 1.1 mjacob isp->isp_state = ISP_RUNSTATE;
59 1.1 mjacob isp->isp_osinfo._link.scsipi_scsi.channel = SCSI_CHANNEL_ONLY_ONE;
60 1.1 mjacob isp->isp_osinfo._link.adapter_softc = isp;
61 1.1 mjacob isp->isp_osinfo._link.device = &isp_dev;
62 1.6 thorpej isp->isp_osinfo._link.adapter = &isp->isp_osinfo._adapter;
63 1.10 mjacob TAILQ_INIT(&isp->isp_osinfo.waitq);
64 1.1 mjacob
65 1.15 mjacob if (IS_FC(isp)) {
66 1.11 mjacob /*
67 1.11 mjacob * Give it another chance here to come alive...
68 1.11 mjacob */
69 1.11 mjacob fcparam *fcp = isp->isp_param;
70 1.11 mjacob if (fcp->isp_fwstate != FW_READY) {
71 1.11 mjacob (void) isp_control(isp, ISPCTL_FCLINK_TEST, NULL);
72 1.11 mjacob }
73 1.1 mjacob isp->isp_osinfo._link.scsipi_scsi.max_target = MAX_FC_TARG-1;
74 1.11 mjacob #ifdef ISP2100_SCCLUN
75 1.7 mjacob /*
76 1.7 mjacob * 16 bits worth, but let's be reasonable..
77 1.7 mjacob */
78 1.7 mjacob isp->isp_osinfo._link.scsipi_scsi.max_lun = 255;
79 1.7 mjacob #else
80 1.7 mjacob isp->isp_osinfo._link.scsipi_scsi.max_lun = 15;
81 1.7 mjacob #endif
82 1.10 mjacob isp->isp_osinfo._link.openings = FC_OPENINGS;
83 1.7 mjacob isp->isp_osinfo._link.scsipi_scsi.adapter_target =
84 1.7 mjacob ((fcparam *)isp->isp_param)->isp_loopid;
85 1.1 mjacob } else {
86 1.14 mjacob sdparam *sdp = isp->isp_param;
87 1.10 mjacob isp->isp_osinfo._link.openings = PI_OPENINGS;
88 1.1 mjacob isp->isp_osinfo._link.scsipi_scsi.max_target = MAX_TARGETS-1;
89 1.7 mjacob if (isp->isp_bustype == ISP_BT_SBUS) {
90 1.7 mjacob isp->isp_osinfo._link.scsipi_scsi.max_lun = 7;
91 1.7 mjacob } else {
92 1.7 mjacob /*
93 1.7 mjacob * Too much target breakage at present.
94 1.7 mjacob */
95 1.7 mjacob #if 0
96 1.13 mjacob if (isp->isp_fwrev >= ISP_FW_REV(7,55,0))
97 1.7 mjacob isp->isp_osinfo._link.scsipi_scsi.max_lun = 31;
98 1.7 mjacob else
99 1.7 mjacob #endif
100 1.7 mjacob isp->isp_osinfo._link.scsipi_scsi.max_lun = 7;
101 1.7 mjacob }
102 1.1 mjacob isp->isp_osinfo._link.scsipi_scsi.adapter_target =
103 1.14 mjacob sdp->isp_initiator_id;
104 1.14 mjacob if (IS_12X0(isp)) {
105 1.14 mjacob isp->isp_osinfo._link_b = isp->isp_osinfo._link;
106 1.14 mjacob sdp++;
107 1.14 mjacob isp->isp_osinfo._link_b.scsipi_scsi.adapter_target =
108 1.14 mjacob sdp->isp_initiator_id;
109 1.14 mjacob isp->isp_osinfo._link_b.scsipi_scsi.channel = 1;
110 1.14 mjacob }
111 1.1 mjacob }
112 1.1 mjacob if (isp->isp_osinfo._link.openings < 2)
113 1.1 mjacob isp->isp_osinfo._link.openings = 2;
114 1.1 mjacob isp->isp_osinfo._link.type = BUS_SCSI;
115 1.8 mjacob
116 1.8 mjacob /*
117 1.10 mjacob * Send a SCSI Bus Reset (used to be done as part of attach,
118 1.10 mjacob * but now left to the OS outer layers).
119 1.10 mjacob */
120 1.10 mjacob
121 1.14 mjacob if (IS_SCSI(isp)) {
122 1.14 mjacob int bus = 0;
123 1.14 mjacob (void) isp_control(isp, ISPCTL_RESET_BUS, &bus);
124 1.14 mjacob if (IS_12X0(isp)) {
125 1.14 mjacob bus++;
126 1.14 mjacob (void) isp_control(isp, ISPCTL_RESET_BUS, &bus);
127 1.14 mjacob }
128 1.11 mjacob SYS_DELAY(2*1000000);
129 1.11 mjacob }
130 1.10 mjacob
131 1.10 mjacob /*
132 1.8 mjacob * Start the watchdog.
133 1.8 mjacob */
134 1.8 mjacob isp->isp_dogactive = 1;
135 1.8 mjacob timeout(isp_watch, isp, 30 * hz);
136 1.8 mjacob
137 1.8 mjacob /*
138 1.8 mjacob * And attach children (if any).
139 1.8 mjacob */
140 1.1 mjacob config_found((void *)isp, &isp->isp_osinfo._link, scsiprint);
141 1.14 mjacob if (IS_12X0(isp)) {
142 1.14 mjacob config_found((void *)isp, &isp->isp_osinfo._link_b, scsiprint);
143 1.14 mjacob }
144 1.1 mjacob }
145 1.1 mjacob
146 1.1 mjacob /*
147 1.1 mjacob * minphys our xfers
148 1.1 mjacob *
149 1.1 mjacob * Unfortunately, the buffer pointer describes the target device- not the
150 1.1 mjacob * adapter device, so we can't use the pointer to find out what kind of
151 1.1 mjacob * adapter we are and adjust accordingly.
152 1.1 mjacob */
153 1.1 mjacob
154 1.1 mjacob static void
155 1.1 mjacob ispminphys(bp)
156 1.1 mjacob struct buf *bp;
157 1.1 mjacob {
158 1.1 mjacob /*
159 1.1 mjacob * XX: Only the 1020 has a 24 bit limit.
160 1.1 mjacob */
161 1.1 mjacob if (bp->b_bcount >= (1 << 24)) {
162 1.1 mjacob bp->b_bcount = (1 << 24);
163 1.1 mjacob }
164 1.1 mjacob minphys(bp);
165 1.1 mjacob }
166 1.1 mjacob
167 1.1 mjacob static int
168 1.1 mjacob ispcmd(xs)
169 1.1 mjacob ISP_SCSI_XFER_T *xs;
170 1.1 mjacob {
171 1.1 mjacob struct ispsoftc *isp;
172 1.3 mjacob int result;
173 1.10 mjacob int s;
174 1.1 mjacob
175 1.1 mjacob isp = XS_ISP(xs);
176 1.10 mjacob s = splbio();
177 1.3 mjacob /*
178 1.3 mjacob * This is less efficient than I would like in that the
179 1.3 mjacob * majority of cases will have to do some pointer deferences
180 1.3 mjacob * to find out that things don't need to be updated.
181 1.3 mjacob */
182 1.16 thorpej #if 0 /* XXX THORPEJ */
183 1.16 thorpej if ((xs->xs_control & XS_CTL_DISCOVERY) == 0 &&
184 1.16 thorpej (isp->isp_type & ISP_HA_SCSI)) {
185 1.3 mjacob sdparam *sdp = isp->isp_param;
186 1.14 mjacob sdp += XS_CHANNEL(xs);
187 1.3 mjacob if (sdp->isp_devparam[XS_TGT(xs)].dev_flags !=
188 1.3 mjacob sdp->isp_devparam[XS_TGT(xs)].cur_dflags) {
189 1.3 mjacob u_int16_t f = DPARM_WIDE|DPARM_SYNC|DPARM_TQING;
190 1.3 mjacob if (xs->sc_link->quirks & SDEV_NOSYNC)
191 1.3 mjacob f &= ~DPARM_SYNC;
192 1.3 mjacob if (xs->sc_link->quirks & SDEV_NOWIDE)
193 1.3 mjacob f &= ~DPARM_WIDE;
194 1.3 mjacob if (xs->sc_link->quirks & SDEV_NOTAG)
195 1.3 mjacob f &= ~DPARM_TQING;
196 1.3 mjacob sdp->isp_devparam[XS_TGT(xs)].dev_flags &=
197 1.3 mjacob ~(DPARM_WIDE|DPARM_SYNC|DPARM_TQING);
198 1.3 mjacob sdp->isp_devparam[XS_TGT(xs)].dev_flags |= f;
199 1.3 mjacob sdp->isp_devparam[XS_TGT(xs)].dev_update = 1;
200 1.14 mjacob isp->isp_update |= (1 << XS_CHANNEL(xs));
201 1.3 mjacob }
202 1.3 mjacob }
203 1.16 thorpej #endif /* XXX THORPEJ */
204 1.11 mjacob
205 1.11 mjacob if (isp->isp_state < ISP_RUNSTATE) {
206 1.11 mjacob DISABLE_INTS(isp);
207 1.11 mjacob isp_init(isp);
208 1.11 mjacob if (isp->isp_state != ISP_INITSTATE) {
209 1.11 mjacob ENABLE_INTS(isp);
210 1.11 mjacob (void) splx(s);
211 1.11 mjacob XS_SETERR(xs, HBA_BOTCH);
212 1.11 mjacob return (CMD_COMPLETE);
213 1.11 mjacob }
214 1.11 mjacob isp->isp_state = ISP_RUNSTATE;
215 1.11 mjacob ENABLE_INTS(isp);
216 1.11 mjacob }
217 1.11 mjacob
218 1.10 mjacob /*
219 1.10 mjacob * Check for queue blockage...
220 1.10 mjacob */
221 1.10 mjacob
222 1.10 mjacob if (isp->isp_osinfo.blocked) {
223 1.16 thorpej if (xs->xs_control & XS_CTL_POLL) {
224 1.10 mjacob xs->error = XS_DRIVER_STUFFUP;
225 1.10 mjacob splx(s);
226 1.10 mjacob return (TRY_AGAIN_LATER);
227 1.10 mjacob }
228 1.10 mjacob TAILQ_INSERT_TAIL(&isp->isp_osinfo.waitq, xs, adapter_q);
229 1.10 mjacob splx(s);
230 1.10 mjacob return (CMD_QUEUED);
231 1.10 mjacob }
232 1.10 mjacob
233 1.11 mjacob DISABLE_INTS(isp);
234 1.3 mjacob result = ispscsicmd(xs);
235 1.11 mjacob ENABLE_INTS(isp);
236 1.16 thorpej if (result != CMD_QUEUED || (xs->xs_control & XS_CTL_POLL) == 0) {
237 1.10 mjacob (void) splx(s);
238 1.3 mjacob return (result);
239 1.1 mjacob }
240 1.1 mjacob
241 1.1 mjacob /*
242 1.1 mjacob * If we can't use interrupts, poll on completion.
243 1.1 mjacob */
244 1.1 mjacob if (isp_poll(isp, xs, XS_TIME(xs))) {
245 1.1 mjacob /*
246 1.1 mjacob * If no other error occurred but we didn't finish,
247 1.1 mjacob * something bad happened.
248 1.1 mjacob */
249 1.1 mjacob if (XS_IS_CMD_DONE(xs) == 0) {
250 1.1 mjacob isp->isp_nactive--;
251 1.1 mjacob if (isp->isp_nactive < 0)
252 1.1 mjacob isp->isp_nactive = 0;
253 1.1 mjacob if (XS_NOERR(xs)) {
254 1.1 mjacob isp_lostcmd(isp, xs);
255 1.1 mjacob XS_SETERR(xs, HBA_BOTCH);
256 1.1 mjacob }
257 1.1 mjacob }
258 1.1 mjacob }
259 1.10 mjacob (void) splx(s);
260 1.1 mjacob return (CMD_COMPLETE);
261 1.1 mjacob }
262 1.1 mjacob
263 1.1 mjacob static int
264 1.1 mjacob isp_poll(isp, xs, mswait)
265 1.1 mjacob struct ispsoftc *isp;
266 1.1 mjacob ISP_SCSI_XFER_T *xs;
267 1.1 mjacob int mswait;
268 1.1 mjacob {
269 1.1 mjacob
270 1.1 mjacob while (mswait) {
271 1.1 mjacob /* Try the interrupt handling routine */
272 1.1 mjacob (void)isp_intr((void *)isp);
273 1.1 mjacob
274 1.1 mjacob /* See if the xs is now done */
275 1.1 mjacob if (XS_IS_CMD_DONE(xs)) {
276 1.1 mjacob return (0);
277 1.1 mjacob }
278 1.1 mjacob SYS_DELAY(1000); /* wait one millisecond */
279 1.1 mjacob mswait--;
280 1.1 mjacob }
281 1.1 mjacob return (1);
282 1.8 mjacob }
283 1.8 mjacob
284 1.8 mjacob static void
285 1.8 mjacob isp_watch(arg)
286 1.8 mjacob void *arg;
287 1.8 mjacob {
288 1.8 mjacob int i;
289 1.8 mjacob struct ispsoftc *isp = arg;
290 1.8 mjacob ISP_SCSI_XFER_T *xs;
291 1.8 mjacob ISP_ILOCKVAL_DECL;
292 1.8 mjacob
293 1.8 mjacob /*
294 1.8 mjacob * Look for completely dead commands (but not polled ones).
295 1.8 mjacob */
296 1.8 mjacob ISP_ILOCK(isp);
297 1.8 mjacob for (i = 0; i < RQUEST_QUEUE_LEN; i++) {
298 1.8 mjacob if ((xs = (ISP_SCSI_XFER_T *) isp->isp_xflist[i]) == NULL) {
299 1.8 mjacob continue;
300 1.8 mjacob }
301 1.8 mjacob if (XS_TIME(xs) == 0) {
302 1.8 mjacob continue;
303 1.8 mjacob }
304 1.8 mjacob XS_TIME(xs) -= (WATCH_INTERVAL * 1000);
305 1.8 mjacob /*
306 1.8 mjacob * Avoid later thinking that this
307 1.8 mjacob * transaction is not being timed.
308 1.8 mjacob * Then give ourselves to watchdog
309 1.8 mjacob * periods of grace.
310 1.8 mjacob */
311 1.8 mjacob if (XS_TIME(xs) == 0) {
312 1.8 mjacob XS_TIME(xs) = 1;
313 1.8 mjacob } else if (XS_TIME(xs) > -(2 * WATCH_INTERVAL * 1000)) {
314 1.8 mjacob continue;
315 1.8 mjacob }
316 1.8 mjacob if (isp_control(isp, ISPCTL_ABORT_CMD, xs)) {
317 1.8 mjacob printf("%s: isp_watch failed to abort command\n",
318 1.8 mjacob isp->isp_name);
319 1.8 mjacob isp_restart(isp);
320 1.8 mjacob break;
321 1.8 mjacob }
322 1.8 mjacob }
323 1.8 mjacob timeout(isp_watch, isp, WATCH_INTERVAL * hz);
324 1.8 mjacob isp->isp_dogactive = 1;
325 1.8 mjacob ISP_IUNLOCK(isp);
326 1.8 mjacob }
327 1.8 mjacob
328 1.8 mjacob /*
329 1.8 mjacob * Free any associated resources prior to decommissioning and
330 1.8 mjacob * set the card to a known state (so it doesn't wake up and kick
331 1.8 mjacob * us when we aren't expecting it to).
332 1.8 mjacob *
333 1.8 mjacob * Locks are held before coming here.
334 1.8 mjacob */
335 1.8 mjacob void
336 1.8 mjacob isp_uninit(isp)
337 1.8 mjacob struct ispsoftc *isp;
338 1.8 mjacob {
339 1.8 mjacob ISP_ILOCKVAL_DECL;
340 1.8 mjacob ISP_ILOCK(isp);
341 1.8 mjacob /*
342 1.8 mjacob * Leave with interrupts disabled.
343 1.8 mjacob */
344 1.8 mjacob DISABLE_INTS(isp);
345 1.8 mjacob
346 1.8 mjacob /*
347 1.8 mjacob * Turn off the watchdog (if active).
348 1.8 mjacob */
349 1.8 mjacob if (isp->isp_dogactive) {
350 1.8 mjacob untimeout(isp_watch, isp);
351 1.8 mjacob isp->isp_dogactive = 0;
352 1.8 mjacob }
353 1.8 mjacob
354 1.8 mjacob ISP_IUNLOCK(isp);
355 1.9 mjacob }
356 1.9 mjacob
357 1.10 mjacob /*
358 1.10 mjacob * Restart function after a LOOP UP event (e.g.),
359 1.10 mjacob * done as a timeout for some hysteresis.
360 1.10 mjacob */
361 1.10 mjacob static void
362 1.10 mjacob isp_internal_restart(arg)
363 1.10 mjacob void *arg;
364 1.10 mjacob {
365 1.10 mjacob struct ispsoftc *isp = arg;
366 1.11 mjacob int result, nrestarted = 0, s;
367 1.10 mjacob
368 1.11 mjacob s = splbio();
369 1.10 mjacob if (isp->isp_osinfo.blocked == 0) {
370 1.10 mjacob struct scsipi_xfer *xs;
371 1.10 mjacob while ((xs = TAILQ_FIRST(&isp->isp_osinfo.waitq)) != NULL) {
372 1.10 mjacob TAILQ_REMOVE(&isp->isp_osinfo.waitq, xs, adapter_q);
373 1.11 mjacob DISABLE_INTS(isp);
374 1.11 mjacob result = ispscsicmd(xs);
375 1.11 mjacob ENABLE_INTS(isp);
376 1.11 mjacob if (result != CMD_QUEUED) {
377 1.10 mjacob printf("%s: botched command restart (0x%x)\n",
378 1.10 mjacob isp->isp_name, result);
379 1.16 thorpej xs->xs_status |= XS_STS_DONE;
380 1.10 mjacob if (xs->error == XS_NOERROR)
381 1.10 mjacob xs->error = XS_DRIVER_STUFFUP;
382 1.10 mjacob scsipi_done(xs);
383 1.10 mjacob }
384 1.10 mjacob nrestarted++;
385 1.10 mjacob }
386 1.10 mjacob printf("%s: requeued %d commands\n", isp->isp_name, nrestarted);
387 1.10 mjacob }
388 1.10 mjacob (void) splx(s);
389 1.10 mjacob }
390 1.10 mjacob
391 1.9 mjacob int
392 1.9 mjacob isp_async(isp, cmd, arg)
393 1.9 mjacob struct ispsoftc *isp;
394 1.9 mjacob ispasync_t cmd;
395 1.9 mjacob void *arg;
396 1.9 mjacob {
397 1.14 mjacob int bus, tgt;
398 1.10 mjacob int s = splbio();
399 1.9 mjacob switch (cmd) {
400 1.9 mjacob case ISPASYNC_NEW_TGT_PARAMS:
401 1.9 mjacob if (isp->isp_type & ISP_HA_SCSI) {
402 1.9 mjacob sdparam *sdp = isp->isp_param;
403 1.9 mjacob char *wt;
404 1.14 mjacob int mhz, flags, period;
405 1.9 mjacob
406 1.9 mjacob tgt = *((int *) arg);
407 1.14 mjacob bus = (tgt >> 16) & 0xffff;
408 1.14 mjacob tgt &= 0xffff;
409 1.12 mjacob
410 1.12 mjacob flags = sdp->isp_devparam[tgt].cur_dflags;
411 1.12 mjacob period = sdp->isp_devparam[tgt].cur_period;
412 1.12 mjacob if ((flags & DPARM_SYNC) && period &&
413 1.12 mjacob (sdp->isp_devparam[tgt].cur_offset) != 0) {
414 1.12 mjacob if (sdp->isp_lvdmode) {
415 1.12 mjacob switch (period) {
416 1.12 mjacob case 0xa:
417 1.12 mjacob mhz = 40;
418 1.12 mjacob break;
419 1.12 mjacob case 0xb:
420 1.12 mjacob mhz = 33;
421 1.12 mjacob break;
422 1.12 mjacob case 0xc:
423 1.12 mjacob mhz = 25;
424 1.12 mjacob break;
425 1.12 mjacob default:
426 1.12 mjacob mhz = 1000 / (period * 4);
427 1.12 mjacob break;
428 1.12 mjacob }
429 1.12 mjacob } else {
430 1.12 mjacob mhz = 1000 / (period * 4);
431 1.12 mjacob }
432 1.9 mjacob } else {
433 1.12 mjacob mhz = 0;
434 1.9 mjacob }
435 1.9 mjacob switch (flags & (DPARM_WIDE|DPARM_TQING)) {
436 1.9 mjacob case DPARM_WIDE:
437 1.9 mjacob wt = ", 16 bit wide\n";
438 1.9 mjacob break;
439 1.9 mjacob case DPARM_TQING:
440 1.9 mjacob wt = ", Tagged Queueing Enabled\n";
441 1.9 mjacob break;
442 1.9 mjacob case DPARM_WIDE|DPARM_TQING:
443 1.9 mjacob wt = ", 16 bit wide, Tagged Queueing Enabled\n";
444 1.9 mjacob break;
445 1.9 mjacob default:
446 1.9 mjacob wt = "\n";
447 1.9 mjacob break;
448 1.9 mjacob }
449 1.12 mjacob if (mhz) {
450 1.14 mjacob printf("%s: Bus %d Target %d at %dMHz Max "
451 1.14 mjacob "Offset %d%s", isp->isp_name, bus, tgt, mhz,
452 1.12 mjacob sdp->isp_devparam[tgt].cur_offset, wt);
453 1.9 mjacob } else {
454 1.14 mjacob printf("%s: Bus %d Target %d Async Mode%s",
455 1.14 mjacob isp->isp_name, bus, tgt, wt);
456 1.9 mjacob }
457 1.9 mjacob }
458 1.11 mjacob break;
459 1.11 mjacob case ISPASYNC_BUS_RESET:
460 1.14 mjacob if (arg)
461 1.14 mjacob bus = *((int *) arg);
462 1.14 mjacob else
463 1.14 mjacob bus = 0;
464 1.14 mjacob printf("%s: SCSI bus %d reset detected\n", isp->isp_name, bus);
465 1.11 mjacob break;
466 1.11 mjacob case ISPASYNC_LOOP_DOWN:
467 1.11 mjacob /*
468 1.11 mjacob * Hopefully we get here in time to minimize the number
469 1.11 mjacob * of commands we are firing off that are sure to die.
470 1.11 mjacob */
471 1.11 mjacob isp->isp_osinfo.blocked = 1;
472 1.11 mjacob printf("%s: Loop DOWN\n", isp->isp_name);
473 1.11 mjacob break;
474 1.11 mjacob case ISPASYNC_LOOP_UP:
475 1.11 mjacob isp->isp_osinfo.blocked = 0;
476 1.11 mjacob timeout(isp_internal_restart, isp, 1);
477 1.11 mjacob printf("%s: Loop UP\n", isp->isp_name);
478 1.11 mjacob break;
479 1.15 mjacob case ISPASYNC_PDB_CHANGED:
480 1.15 mjacob if (IS_FC(isp)) {
481 1.15 mjacob const char *fmt = "%s: Target %d (Loop 0x%x) Port ID 0x%x "
482 1.15 mjacob "role %s %s\n Port WWN 0x%08x%08x\n Node WWN 0x%08x%08x\n";
483 1.15 mjacob const static char *roles[4] = {
484 1.11 mjacob "No", "Target", "Initiator", "Target/Initiator"
485 1.11 mjacob };
486 1.15 mjacob char *ptr;
487 1.15 mjacob fcparam *fcp = isp->isp_param;
488 1.15 mjacob int tgt = *((int *) arg);
489 1.15 mjacob struct lportdb *lp = &fcp->portdb[tgt];
490 1.15 mjacob
491 1.15 mjacob if (lp->valid) {
492 1.15 mjacob ptr = "arrived";
493 1.15 mjacob } else {
494 1.15 mjacob ptr = "disappeared";
495 1.11 mjacob }
496 1.15 mjacob printf(fmt, isp->isp_name, tgt, lp->loopid, lp->portid,
497 1.15 mjacob roles[lp->roles & 0x3], ptr,
498 1.15 mjacob (u_int32_t) (lp->port_wwn >> 32),
499 1.15 mjacob (u_int32_t) (lp->port_wwn & 0xffffffffLL),
500 1.15 mjacob (u_int32_t) (lp->node_wwn >> 32),
501 1.15 mjacob (u_int32_t) (lp->node_wwn & 0xffffffffLL));
502 1.11 mjacob break;
503 1.11 mjacob }
504 1.15 mjacob #ifdef ISP2100_FABRIC
505 1.11 mjacob case ISPASYNC_CHANGE_NOTIFY:
506 1.11 mjacob printf("%s: Name Server Database Changed\n", isp->isp_name);
507 1.9 mjacob break;
508 1.15 mjacob case ISPASYNC_FABRIC_DEV:
509 1.15 mjacob {
510 1.15 mjacob int target;
511 1.15 mjacob struct lportdb *lp;
512 1.15 mjacob sns_scrsp_t *resp = (sns_scrsp_t *) arg;
513 1.15 mjacob u_int32_t portid;
514 1.15 mjacob u_int64_t wwn;
515 1.15 mjacob fcparam *fcp = isp->isp_param;
516 1.15 mjacob
517 1.15 mjacob portid =
518 1.15 mjacob (((u_int32_t) resp->snscb_port_id[0]) << 16) |
519 1.15 mjacob (((u_int32_t) resp->snscb_port_id[1]) << 8) |
520 1.15 mjacob (((u_int32_t) resp->snscb_port_id[2]));
521 1.15 mjacob wwn =
522 1.15 mjacob (((u_int64_t)resp->snscb_portname[0]) << 56) |
523 1.15 mjacob (((u_int64_t)resp->snscb_portname[1]) << 48) |
524 1.15 mjacob (((u_int64_t)resp->snscb_portname[2]) << 40) |
525 1.15 mjacob (((u_int64_t)resp->snscb_portname[3]) << 32) |
526 1.15 mjacob (((u_int64_t)resp->snscb_portname[4]) << 24) |
527 1.15 mjacob (((u_int64_t)resp->snscb_portname[5]) << 16) |
528 1.15 mjacob (((u_int64_t)resp->snscb_portname[6]) << 8) |
529 1.15 mjacob (((u_int64_t)resp->snscb_portname[7]));
530 1.15 mjacob printf("%s: Fabric Device (Type 0x%x)@PortID 0x%x WWN "
531 1.15 mjacob "0x%08x%08x\n", isp->isp_name, resp->snscb_port_type,
532 1.15 mjacob portid, ((u_int32_t)(wwn >> 32)),
533 1.15 mjacob ((u_int32_t)(wwn & 0xffffffff)));
534 1.15 mjacob if (resp->snscb_port_type != 2)
535 1.15 mjacob break;
536 1.15 mjacob for (target = FC_SNS_ID+1; target < MAX_FC_TARG; target++) {
537 1.15 mjacob lp = &fcp->portdb[target];
538 1.15 mjacob if (lp->port_wwn == wwn)
539 1.15 mjacob break;
540 1.15 mjacob }
541 1.15 mjacob if (target < MAX_FC_TARG) {
542 1.15 mjacob break;
543 1.15 mjacob }
544 1.15 mjacob for (target = FC_SNS_ID+1; target < MAX_FC_TARG; target++) {
545 1.15 mjacob lp = &fcp->portdb[target];
546 1.15 mjacob if (lp->port_wwn == 0)
547 1.15 mjacob break;
548 1.15 mjacob }
549 1.15 mjacob if (target == MAX_FC_TARG) {
550 1.15 mjacob printf("%s: no more space for fabric devices\n",
551 1.15 mjacob isp->isp_name);
552 1.15 mjacob return (-1);
553 1.15 mjacob }
554 1.15 mjacob lp->port_wwn = lp->node_wwn = wwn;
555 1.15 mjacob lp->portid = portid;
556 1.15 mjacob break;
557 1.15 mjacob }
558 1.15 mjacob #endif
559 1.9 mjacob default:
560 1.9 mjacob break;
561 1.9 mjacob }
562 1.10 mjacob (void) splx(s);
563 1.9 mjacob return (0);
564 1.1 mjacob }
565