1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
|
/* $OpenBSD: isp_openbsd.c,v 1.11 2000/07/07 19:00:47 mjacob Exp $ */
/*
* Platform (OpenBSD) dependent common attachment code for Qlogic adapters.
*
*---------------------------------------
* Copyright (c) 1999 by Matthew Jacob
* NASA/Ames Research Center
* All rights reserved.
*---------------------------------------
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice immediately at the beginning of the file, without modification,
* this list of conditions, and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The author may be reached via electronic communications at
*
* mjacob@nas.nasa.gov
* mjacob@feral.com
*
* or, via United States Postal Address
*
* Matthew Jacob
* Feral Software
* PMB#825
* 5214-F Diamond Heights Blvd.
* San Francisco, CA, 94131
*/
#include <dev/ic/isp_openbsd.h>
static void ispminphys __P((struct buf *));
static int32_t ispcmd_slow __P((ISP_SCSI_XFER_T *));
static int32_t ispcmd __P((ISP_SCSI_XFER_T *));
static struct scsi_device isp_dev = { NULL, NULL, NULL, NULL };
static int isp_poll __P((struct ispsoftc *, ISP_SCSI_XFER_T *, int));
static void isp_wdog __P((void *));
static void isp_requeue(void *);
static void isp_internal_restart(void *);
/*
* Set a timeout for the watchdogging of a command.
*
* The dimensional analysis is
*
* milliseconds * (seconds/millisecond) * (ticks/second) = ticks
*
* =
*
* (milliseconds / 1000) * hz = ticks
*
*
* For timeouts less than 1 second, we'll get zero. Because of this, and
* because we want to establish *our* timeout to be longer than what the
* firmware might do, we just add 3 seconds at the back end.
*/
#define _XT(xs) ((((xs)->timeout/1000) * hz) + (3 * hz))
struct cfdriver isp_cd = {
NULL, "isp", DV_DULL
};
/*
* Complete attachment of hardware, include subdevices.
*/
void
isp_attach(isp)
struct ispsoftc *isp;
{
struct scsi_link *lptr = &isp->isp_osinfo._link[0];
isp->isp_osinfo._adapter.scsi_minphys = ispminphys;
isp->isp_state = ISP_RUNSTATE;
/*
* We only manage a single wait queues for dual bus controllers.
* This is arguably broken.
*/
isp->isp_osinfo.wqf = isp->isp_osinfo.wqt = NULL;
lptr->adapter_softc = isp;
lptr->device = &isp_dev;
lptr->adapter = &isp->isp_osinfo._adapter;
lptr->openings = isp->isp_maxcmds;
if (IS_FC(isp)) {
isp->isp_osinfo._adapter.scsi_cmd = ispcmd;
lptr->adapter_buswidth = MAX_FC_TARG;
/* We can set max lun width here */
/* loopid set below */
} else {
sdparam *sdp = isp->isp_param;
isp->isp_osinfo._adapter.scsi_cmd = ispcmd_slow;
lptr->adapter_buswidth = MAX_TARGETS;
/* We can set max lun width here */
lptr->adapter_target = sdp->isp_initiator_id;
isp->isp_osinfo.discovered[0] = 1 << sdp->isp_initiator_id;
if (IS_DUALBUS(isp)) {
struct scsi_link *lptrb = &isp->isp_osinfo._link[1];
lptrb->adapter_softc = isp;
lptrb->device = &isp_dev;
lptrb->adapter = &isp->isp_osinfo._adapter;
lptrb->openings = isp->isp_maxcmds;
lptrb->adapter_buswidth = MAX_TARGETS;
lptrb->adapter_target = sdp->isp_initiator_id;
lptrb->flags = SDEV_2NDBUS;
isp->isp_osinfo.discovered[1] =
1 << (sdp+1)->isp_initiator_id;
}
}
/*
* Send a SCSI Bus Reset (used to be done as part of attach,
* but now left to the OS outer layers).
*
* We don't do 'bus resets' for FC because the LIP that occurs
* when we start the firmware does all that for us.
*/
if (IS_SCSI(isp)) {
int bus = 0;
(void) isp_control(isp, ISPCTL_RESET_BUS, &bus);
if (IS_DUALBUS(isp)) {
bus++;
(void) isp_control(isp, ISPCTL_RESET_BUS, &bus);
}
/*
* wait for the bus to settle.
*/
printf("%s: waiting 4 seconds for bus reset settling\n",
isp->isp_name);
delay(4 * 1000000);
} else {
int i, j;
fcparam *fcp = isp->isp_param;
/*
* wait for the loop to settle.
*/
printf("%s: waiting 2 seconds for loop reset settling\n",
isp->isp_name);
delay(2 * 1000000);
for (j = 0; j < 5; j++) {
for (i = 0; i < 5; i++) {
if (isp_control(isp, ISPCTL_FCLINK_TEST, NULL))
continue;
/*
* Wait extra time to see if the f/w
* eventually completed an FLOGI that
* will allow us to know we're on a
* fabric.
*/
if (fcp->isp_onfabric == 0) {
delay(1 * 1000000);
continue;
}
break;
}
if (fcp->isp_fwstate == FW_READY &&
fcp->isp_loopstate >= LOOP_PDB_RCVD) {
break;
}
}
lptr->adapter_target = fcp->isp_loopid;
}
/*
* And attach children (if any).
*/
config_found((void *)isp, lptr, scsiprint);
if (IS_DUALBUS(isp)) {
lptr++;
config_found((void *)isp, lptr, scsiprint);
}
}
/*
* minphys our xfers
*
* Unfortunately, the buffer pointer describes the target device- not the
* adapter device, so we can't use the pointer to find out what kind of
* adapter we are and adjust accordingly.
*/
static void
ispminphys(bp)
struct buf *bp;
{
/*
* XX: Only the 1020 has a 24 bit limit.
*/
if (bp->b_bcount >= (1 << 24)) {
bp->b_bcount = (1 << 24);
}
minphys(bp);
}
static int32_t
ispcmd_slow(xs)
ISP_SCSI_XFER_T *xs;
{
sdparam *sdp;
int tgt, chan;
u_int16_t f;
struct ispsoftc *isp = XS_ISP(xs);
/*
* Have we completed discovery for this target on this adapter?
*/
sdp = isp->isp_param;
tgt = XS_TGT(xs);
chan = XS_CHANNEL(xs);
sdp += chan;
if ((xs->flags & SCSI_POLL) != 0 ||
(isp->isp_osinfo.discovered[chan] & (1 << tgt)) != 0) {
return (ispcmd(xs));
}
f = DPARM_DEFAULT;
if (xs->sc_link->quirks & SDEV_NOSYNC) {
f ^= DPARM_SYNC;
#ifdef DEBUG
} else {
printf("%s: channel %d target %d can do SYNC xfers\n",
isp->isp_name, chan, tgt);
#endif
}
if (xs->sc_link->quirks & SDEV_NOWIDE) {
f ^= DPARM_WIDE;
#ifdef DEBUG
} else {
printf("%s: channel %d target %d can do WIDE xfers\n",
isp->isp_name, chan, tgt);
#endif
}
if (xs->sc_link->quirks & SDEV_NOTAGS) {
f ^= DPARM_TQING;
#ifdef DEBUG
} else {
printf("%s: channel %d target %d can do TAGGED xfers\n",
isp->isp_name, chan, tgt);
#endif
}
/*
* Okay, we know about this device now,
* so mark parameters to be updated for it.
*/
sdp->isp_devparam[tgt].dev_flags = f;
sdp->isp_devparam[tgt].dev_update = 1;
isp->isp_update |= (1 << chan);
/*
* Now check to see whether we can get out of this checking mode now.
* XXX: WE CANNOT AS YET BECAUSE THERE IS NO MECHANISM TO TELL US
* XXX: WHEN WE'RE DONE DISCOVERY BECAUSE WE NEED ONE COMMAND AFTER
* XXX: DISCOVERY IS DONE FOR EACH TARGET TO TELL US THAT WE'RE DONE
* XXX: AND THAT DOESN'T HAPPEN HERE. AT BEST WE CAN MARK OURSELVES
* XXX: DONE WITH DISCOVERY FOR THIS TARGET AND SO SAVE MAYBE 20
* XXX: LINES OF C CODE.
*/
isp->isp_osinfo.discovered[chan] |= (1 << tgt);
/* do not bother with these lines- they'll never execute correctly */
#if 0
sdp = isp->isp_param;
for (chan = 0; chan < (IS_12X0(isp)? 2 : 1); chan++, sdp++) {
f = 0xffff & ~(1 << sdp->isp_initiator_id);
if (isp->isp_osinfo.discovered[chan] != f) {
break;
}
}
if (chan == (IS_12X0(isp)? 2 : 1)) {
CFGPRINTF("%s: allowing sync/wide negotiation and "
"tag usage\n", isp->isp_name);
isp->isp_osinfo._adapter.scsipi_cmd = ispcmd;
if (IS_12X0(isp))
isp->isp_update |= 2;
}
#endif
return (ispcmd(xs));
}
static int32_t
ispcmd(xs)
ISP_SCSI_XFER_T *xs;
{
struct ispsoftc *isp;
int result;
int s;
/*
* Make sure that there's *some* kind of sane setting.
*/
timeout_set(&xs->stimeout, isp_wdog, isp);
timeout_del(&xs->stimeout);
isp = XS_ISP(xs);
s = splbio();
if (isp->isp_state < ISP_RUNSTATE) {
DISABLE_INTS(isp);
isp_init(isp);
if (isp->isp_state != ISP_INITSTATE) {
ENABLE_INTS(isp);
(void) splx(s);
XS_SETERR(xs, HBA_BOTCH);
return (CMD_COMPLETE);
}
isp->isp_state = ISP_RUNSTATE;
ENABLE_INTS(isp);
}
/*
* Check for queue blockage...
*/
if (isp->isp_osinfo.blocked) {
IDPRINTF(2, ("%s: blocked\n", isp->isp_name));
if (xs->flags & SCSI_POLL) {
xs->error = XS_DRIVER_STUFFUP;
splx(s);
return (TRY_AGAIN_LATER);
}
if (isp->isp_osinfo.wqf != NULL) {
isp->isp_osinfo.wqt->free_list.le_next = xs;
} else {
isp->isp_osinfo.wqf = xs;
}
isp->isp_osinfo.wqt = xs;
xs->free_list.le_next = NULL;
splx(s);
return (SUCCESSFULLY_QUEUED);
}
result = ispscsicmd(xs);
if ((xs->flags & SCSI_POLL) == 0) {
switch (result) {
case CMD_QUEUED:
result = SUCCESSFULLY_QUEUED;
if (xs->timeout) {
timeout_add(&xs->stimeout, _XT(xs));
}
break;
case CMD_EAGAIN:
result = TRY_AGAIN_LATER;
break;
case CMD_RQLATER:
result = SUCCESSFULLY_QUEUED;
timeout_set(&xs->stimeout, isp_requeue, xs);
timeout_add(&xs->stimeout, hz);
break;
case CMD_COMPLETE:
result = COMPLETE;
break;
}
(void) splx(s);
return (result);
}
switch (result) {
case CMD_QUEUED:
result = SUCCESSFULLY_QUEUED;
break;
case CMD_RQLATER:
case CMD_EAGAIN:
if (XS_NOERR(xs)) {
xs->error = XS_DRIVER_STUFFUP;
}
result = TRY_AGAIN_LATER;
break;
case CMD_COMPLETE:
result = COMPLETE;
break;
}
/*
* We can't use interrupts so poll on completion.
*/
if (result == SUCCESSFULLY_QUEUED) {
if (isp_poll(isp, xs, xs->timeout)) {
/*
* If no other error occurred but we didn't finish,
* something bad happened.
*/
if (XS_CMD_DONE_P(xs) == 0) {
if (isp_control(isp, ISPCTL_ABORT_CMD, xs)) {
isp_restart(isp);
}
if (XS_NOERR(xs)) {
XS_SETERR(xs, HBA_BOTCH);
}
}
}
result = COMPLETE;
}
(void) splx(s);
return (result);
}
void
isp_done(xs)
ISP_SCSI_XFER_T *xs;
{
XS_CMD_S_DONE(xs);
if (XS_CMD_WDOG_P(xs) == 0) {
if (xs->timeout) {
timeout_del(&xs->stimeout);
}
if (XS_CMD_GRACE_P(xs)) {
struct ispsoftc *isp = XS_ISP(xs);
PRINTF("%s: finished command on borrowed time\n",
isp->isp_name);
}
XS_CMD_S_CLEAR(xs);
scsi_done(xs);
}
}
static int
isp_poll(isp, xs, mswait)
struct ispsoftc *isp;
ISP_SCSI_XFER_T *xs;
int mswait;
{
while (mswait) {
/* Try the interrupt handling routine */
(void)isp_intr((void *)isp);
/* See if the xs is now done */
if (XS_CMD_DONE_P(xs)) {
return (0);
}
delay(1000); /* wait one millisecond */
mswait--;
}
return (1);
}
static void
isp_wdog(arg)
void *arg;
{
ISP_SCSI_XFER_T *xs = arg;
struct ispsoftc *isp = XS_ISP(xs);
u_int32_t handle;
int s = splbio();
/*
* We've decided this command is dead. Make sure we're not trying
* to kill a command that's already dead by getting it's handle and
* and seeing whether it's still alive.
*/
handle = isp_find_handle(isp, xs);
if (handle) {
u_int16_t r, r1, i;
if (XS_CMD_DONE_P(xs)) {
PRINTF("%s: watchdog found done cmd (handle 0x%x)\n",
isp->isp_name, handle);
(void) splx(s);
return;
}
if (XS_CMD_WDOG_P(xs)) {
PRINTF("%s: recursive watchdog (handle 0x%x)\n",
isp->isp_name, handle);
(void) splx(s);
return;
}
XS_CMD_S_WDOG(xs);
i = 0;
do {
r = ISP_READ(isp, BIU_ISR);
SYS_DELAY(1);
r1 = ISP_READ(isp, BIU_ISR);
} while (r != r1 && ++i < 1000);
if (INT_PENDING(isp, r) && isp_intr(isp) && XS_CMD_DONE_P(xs)) {
IDPRINTF(1, ("%s: watchdog cleanup (%x, %x)\n",
isp->isp_name, handle, r));
XS_CMD_C_WDOG(xs);
isp_done(xs);
} else if (XS_CMD_GRACE_P(xs)) {
/*
* Make sure the command is *really* dead before we
* release the handle (and DMA resources) for reuse.
*/
(void) isp_control(isp, ISPCTL_ABORT_CMD, arg);
/*
* After this point, the comamnd is really dead.
*/
if (XS_XFRLEN(xs)) {
ISP_DMAFREE(isp, xs, handle);
}
printf("%s: watchdog timeout (%x, %x)\n",
isp->isp_name, handle, r);
isp_destroy_handle(isp, handle);
XS_SETERR(xs, XS_TIMEOUT);
XS_CMD_S_CLEAR(xs);
isp_done(xs);
} else {
u_int16_t iptr, optr;
ispreq_t *mp;
IDPRINTF(2, ("%s: possible command timeout (%x, %x)\n",
isp->isp_name, handle, r));
XS_CMD_C_WDOG(xs);
timeout_add(&xs->stimeout, _XT(xs));
if (isp_getrqentry(isp, &iptr, &optr, (void **) &mp)) {
(void) splx(s);
return;
}
XS_CMD_S_GRACE(xs);
MEMZERO((void *) mp, sizeof (*mp));
mp->req_header.rqs_entry_count = 1;
mp->req_header.rqs_entry_type = RQSTYPE_MARKER;
mp->req_modifier = SYNC_ALL;
mp->req_target = XS_CHANNEL(xs) << 7;
ISP_SWIZZLE_REQUEST(isp, mp);
MemoryBarrier();
ISP_ADD_REQUEST(isp, iptr);
}
} else if (isp->isp_dblev) {
PRINTF("%s: watchdog with no command\n", isp->isp_name);
}
(void) splx(s);
}
/*
* Free any associated resources prior to decommissioning and
* set the card to a known state (so it doesn't wake up and kick
* us when we aren't expecting it to).
*
* Locks are held before coming here.
*/
void
isp_uninit(isp)
struct ispsoftc *isp;
{
int s = splbio();
/*
* Leave with interrupts disabled.
*/
DISABLE_INTS(isp);
splx(s);
}
/*
* Restart function for a command to be requeued later.
*/
static void
isp_requeue(void *arg)
{
struct scsi_xfer *xs = arg;
struct ispsoftc *isp = XS_ISP(xs);
int s = splbio();
switch (ispcmd_slow(xs)) {
case SUCCESSFULLY_QUEUED:
printf("%s: isp_command_reque: queued %d.%d\n",
isp->isp_name, XS_TGT(xs), XS_LUN(xs));
if (xs->timeout) {
timeout_set(&xs->stimeout, isp_wdog, isp);
timeout_add(&xs->stimeout, _XT(xs));
}
break;
case TRY_AGAIN_LATER:
printf("%s: EAGAIN for %d.%d\n",
isp->isp_name, XS_TGT(xs), XS_LUN(xs));
/* FALLTHROUGH */
case COMPLETE:
/* can only be an error */
if (XS_NOERR(xs))
XS_SETERR(xs, XS_DRIVER_STUFFUP);
XS_CMD_DONE(xs);
break;
}
(void) splx(s);
}
/*
* Restart function after a LOOP UP event (e.g.),
* done as a timeout for some hysteresis.
*/
static void
isp_internal_restart(void *arg)
{
struct ispsoftc *isp = arg;
int result, nrestarted = 0, s;
s = splbio();
if (isp->isp_osinfo.blocked == 0) {
struct scsi_xfer *xs;
while ((xs = isp->isp_osinfo.wqf) != NULL) {
isp->isp_osinfo.wqf = xs->free_list.le_next;
xs->free_list.le_next = NULL;
DISABLE_INTS(isp);
result = ispscsicmd(xs);
ENABLE_INTS(isp);
if (result != CMD_QUEUED) {
printf("%s: botched command restart (0x%x)\n",
isp->isp_name, result);
if (XS_NOERR(xs))
XS_SETERR(xs, XS_DRIVER_STUFFUP);
XS_CMD_DONE(xs);
} else if (xs->timeout) {
timeout_add(&xs->stimeout, _XT(xs));
}
nrestarted++;
}
printf("%s: requeued %d commands\n", isp->isp_name, nrestarted);
}
(void) splx(s);
}
int
isp_async(isp, cmd, arg)
struct ispsoftc *isp;
ispasync_t cmd;
void *arg;
{
int bus, tgt;
int s = splbio();
switch (cmd) {
case ISPASYNC_NEW_TGT_PARAMS:
if (IS_SCSI(isp) && isp->isp_dblev) {
sdparam *sdp = isp->isp_param;
char *wt;
int mhz, flags, period;
tgt = *((int *) arg);
bus = (tgt >> 16) & 0xffff;
tgt &= 0xffff;
sdp += bus;
flags = sdp->isp_devparam[tgt].cur_dflags;
period = sdp->isp_devparam[tgt].cur_period;
if ((flags & DPARM_SYNC) && period &&
(sdp->isp_devparam[tgt].cur_offset) != 0) {
if (sdp->isp_lvdmode || period < 0xc) {
switch (period) {
case 0x9:
mhz = 80;
break;
case 0xa:
mhz = 40;
break;
case 0xb:
mhz = 33;
break;
case 0xc:
mhz = 25;
break;
default:
mhz = 1000 / (period * 4);
break;
}
} else {
mhz = 1000 / (period * 4);
}
} else {
mhz = 0;
}
switch (flags & (DPARM_WIDE|DPARM_TQING)) {
case DPARM_WIDE:
wt = ", 16 bit wide\n";
break;
case DPARM_TQING:
wt = ", Tagged Queueing Enabled\n";
break;
case DPARM_WIDE|DPARM_TQING:
wt = ", 16 bit wide, Tagged Queueing Enabled\n";
break;
default:
wt = "\n";
break;
}
if (mhz) {
CFGPRINTF("%s: Bus %d Target %d at %dMHz Max "
"Offset %d%s", isp->isp_name, bus, tgt, mhz,
sdp->isp_devparam[tgt].cur_offset, wt);
} else {
CFGPRINTF("%s: Bus %d Target %d Async Mode%s",
isp->isp_name, bus, tgt, wt);
}
break;
}
case ISPASYNC_BUS_RESET:
if (arg)
bus = *((int *) arg);
else
bus = 0;
printf("%s: SCSI bus %d reset detected\n", isp->isp_name, bus);
break;
case ISPASYNC_LOOP_DOWN:
/*
* Hopefully we get here in time to minimize the number
* of commands we are firing off that are sure to die.
*/
isp->isp_osinfo.blocked = 1;
printf("%s: Loop DOWN\n", isp->isp_name);
break;
case ISPASYNC_LOOP_UP:
isp->isp_osinfo.blocked = 0;
timeout_set(&isp->isp_osinfo.rqt, isp_internal_restart, isp);
timeout_add(&isp->isp_osinfo.rqt, 1);
printf("%s: Loop UP\n", isp->isp_name);
break;
case ISPASYNC_PDB_CHANGED:
if (IS_FC(isp) && isp->isp_dblev) {
const char *fmt = "%s: Target %d (Loop 0x%x) Port ID 0x%x "
"role %s %s\n Port WWN 0x%08x%08x\n Node WWN 0x%08x%08x\n";
const static char *roles[4] = {
"No", "Target", "Initiator", "Target/Initiator"
};
char *ptr;
fcparam *fcp = isp->isp_param;
int tgt = *((int *) arg);
struct lportdb *lp = &fcp->portdb[tgt];
if (lp->valid) {
ptr = "arrived";
} else {
ptr = "disappeared";
}
printf(fmt, isp->isp_name, tgt, lp->loopid, lp->portid,
roles[lp->roles & 0x3], ptr,
(u_int32_t) (lp->port_wwn >> 32),
(u_int32_t) (lp->port_wwn & 0xffffffffLL),
(u_int32_t) (lp->node_wwn >> 32),
(u_int32_t) (lp->node_wwn & 0xffffffffLL));
break;
}
case ISPASYNC_CHANGE_NOTIFY:
printf("%s: Name Server Database Changed\n", isp->isp_name);
break;
case ISPASYNC_FABRIC_DEV:
{
int target;
struct lportdb *lp;
char *pt;
sns_ganrsp_t *resp = (sns_ganrsp_t *) arg;
u_int32_t portid;
u_int64_t wwpn, wwnn;
fcparam *fcp = isp->isp_param;
portid =
(((u_int32_t) resp->snscb_port_id[0]) << 16) |
(((u_int32_t) resp->snscb_port_id[1]) << 8) |
(((u_int32_t) resp->snscb_port_id[2]));
wwpn =
(((u_int64_t)resp->snscb_portname[0]) << 56) |
(((u_int64_t)resp->snscb_portname[1]) << 48) |
(((u_int64_t)resp->snscb_portname[2]) << 40) |
(((u_int64_t)resp->snscb_portname[3]) << 32) |
(((u_int64_t)resp->snscb_portname[4]) << 24) |
(((u_int64_t)resp->snscb_portname[5]) << 16) |
(((u_int64_t)resp->snscb_portname[6]) << 8) |
(((u_int64_t)resp->snscb_portname[7]));
wwnn =
(((u_int64_t)resp->snscb_nodename[0]) << 56) |
(((u_int64_t)resp->snscb_nodename[1]) << 48) |
(((u_int64_t)resp->snscb_nodename[2]) << 40) |
(((u_int64_t)resp->snscb_nodename[3]) << 32) |
(((u_int64_t)resp->snscb_nodename[4]) << 24) |
(((u_int64_t)resp->snscb_nodename[5]) << 16) |
(((u_int64_t)resp->snscb_nodename[6]) << 8) |
(((u_int64_t)resp->snscb_nodename[7]));
if (portid == 0 || wwpn == 0) {
break;
}
switch (resp->snscb_port_type) {
case 1:
pt = " N_Port";
break;
case 2:
pt = " NL_Port";
break;
case 3:
pt = "F/NL_Port";
break;
case 0x7f:
pt = " Nx_Port";
break;
case 0x81:
pt = " F_port";
break;
case 0x82:
pt = " FL_Port";
break;
case 0x84:
pt = " E_port";
break;
default:
pt = "?";
break;
}
CFGPRINTF("%s: %s @ 0x%x, Node 0x%08x%08x Port %08x%08x\n",
isp->isp_name, pt, portid,
((u_int32_t) (wwnn >> 32)), ((u_int32_t) wwnn),
((u_int32_t) (wwpn >> 32)), ((u_int32_t) wwpn));
#if 0
if ((resp->snscb_fc4_types[1] & 0x1) == 0) {
printf("Types 0..3: 0x%x 0x%x 0x%x 0x%x\n",
resp->snscb_fc4_types[0], resp->snscb_fc4_types[1],
resp->snscb_fc4_types[3], resp->snscb_fc4_types[3]);
break;
}
#endif
for (target = FC_SNS_ID+1; target < MAX_FC_TARG; target++) {
lp = &fcp->portdb[target];
if (lp->port_wwn == wwpn && lp->node_wwn == wwnn)
break;
}
if (target < MAX_FC_TARG) {
break;
}
for (target = FC_SNS_ID+1; target < MAX_FC_TARG; target++) {
lp = &fcp->portdb[target];
if (lp->port_wwn == 0)
break;
}
if (target == MAX_FC_TARG) {
printf("%s: no more space for fabric devices\n",
isp->isp_name);
break;
}
lp->node_wwn = wwnn;
lp->port_wwn = wwpn;
lp->portid = portid;
break;
}
default:
break;
}
(void) splx(s);
return (0);
}
|