2 * Generic driver for the BusLogic MultiMaster SCSI host adapters
3 * Product specific probe and attach routines can be found in:
4 * sys/dev/buslogic/bt_isa.c BT-54X, BT-445 cards
5 * sys/dev/buslogic/bt_mca.c BT-64X, SDC3211B, SDC3211F
6 * sys/dev/buslogic/bt_eisa.c BT-74X, BT-75x cards, SDC3222F
7 * sys/dev/buslogic/bt_pci.c BT-946, BT-948, BT-956, BT-958 cards
9 * Copyright (c) 1998, 1999 Justin T. Gibbs.
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification, immediately at the beginning of the file.
18 * 2. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
25 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
38 * Special thanks to Leonard N. Zubkoff for writing such a complete and
39 * well documented Mylex/BusLogic MultiMaster driver for Linux. Support
40 * in this driver for the wide range of MultiMaster controllers and
41 * firmware revisions, with their otherwise undocumented quirks, would not
42 * have been possible without his efforts.
45 #include <sys/param.h>
46 #include <sys/systm.h>
47 #include <sys/malloc.h>
48 #include <sys/kernel.h>
50 #include <sys/module.h>
51 #include <sys/mutex.h>
52 #include <sys/sysctl.h>
55 #include <machine/bus.h>
59 #include <cam/cam_ccb.h>
60 #include <cam/cam_sim.h>
61 #include <cam/cam_xpt_sim.h>
62 #include <cam/cam_debug.h>
64 #include <cam/scsi/scsi_message.h>
69 #include <dev/buslogic/btreg.h>
71 /* MailBox Management functions */
72 static __inline void btnextinbox(struct bt_softc *bt);
73 static __inline void btnextoutbox(struct bt_softc *bt);
76 btnextinbox(struct bt_softc *bt)
78 if (bt->cur_inbox == bt->last_inbox)
79 bt->cur_inbox = bt->in_boxes;
85 btnextoutbox(struct bt_softc *bt)
87 if (bt->cur_outbox == bt->last_outbox)
88 bt->cur_outbox = bt->out_boxes;
93 /* CCB Mangement functions */
94 static __inline u_int32_t btccbvtop(struct bt_softc *bt,
96 static __inline struct bt_ccb* btccbptov(struct bt_softc *bt,
98 static __inline u_int32_t btsensepaddr(struct bt_softc *bt,
100 static __inline struct scsi_sense_data* btsensevaddr(struct bt_softc *bt,
101 struct bt_ccb *bccb);
103 static __inline u_int32_t
104 btccbvtop(struct bt_softc *bt, struct bt_ccb *bccb)
106 return (bt->bt_ccb_physbase
107 + (u_int32_t)((caddr_t)bccb - (caddr_t)bt->bt_ccb_array));
110 static __inline struct bt_ccb *
111 btccbptov(struct bt_softc *bt, u_int32_t ccb_addr)
113 return (bt->bt_ccb_array +
114 ((struct bt_ccb*)(uintptr_t)ccb_addr - (struct bt_ccb*)(uintptr_t)bt->bt_ccb_physbase));
117 static __inline u_int32_t
118 btsensepaddr(struct bt_softc *bt, struct bt_ccb *bccb)
122 index = (u_int)(bccb - bt->bt_ccb_array);
123 return (bt->sense_buffers_physbase
124 + (index * sizeof(struct scsi_sense_data)));
127 static __inline struct scsi_sense_data *
128 btsensevaddr(struct bt_softc *bt, struct bt_ccb *bccb)
132 index = (u_int)(bccb - bt->bt_ccb_array);
133 return (bt->sense_buffers + index);
136 static __inline struct bt_ccb* btgetccb(struct bt_softc *bt);
137 static __inline void btfreeccb(struct bt_softc *bt,
138 struct bt_ccb *bccb);
139 static void btallocccbs(struct bt_softc *bt);
140 static bus_dmamap_callback_t btexecuteccb;
141 static void btdone(struct bt_softc *bt, struct bt_ccb *bccb,
142 bt_mbi_comp_code_t comp_code);
144 /* Host adapter command functions */
145 static int btreset(struct bt_softc* bt, int hard_reset);
147 /* Initialization functions */
148 static int btinitmboxes(struct bt_softc *bt);
149 static bus_dmamap_callback_t btmapmboxes;
150 static bus_dmamap_callback_t btmapccbs;
151 static bus_dmamap_callback_t btmapsgs;
153 /* Transfer Negotiation Functions */
154 static void btfetchtransinfo(struct bt_softc *bt,
155 struct ccb_trans_settings *cts);
157 /* CAM SIM entry points */
158 #define ccb_bccb_ptr spriv_ptr0
159 #define ccb_bt_ptr spriv_ptr1
160 static void btaction(struct cam_sim *sim, union ccb *ccb);
161 static void btpoll(struct cam_sim *sim);
163 /* Our timeout handler */
170 * Do our own re-probe protection until a configuration
171 * manager can do it for us. This ensures that we don't
172 * reprobe a card already found by the EISA or PCI probes.
174 struct bt_isa_port bt_isa_ports[] =
185 * I/O ports listed in the order enumerated by the
186 * card for certain op codes.
188 u_int16_t bt_board_ports[] =
198 /* Exported functions */
200 bt_init_softc(device_t dev, struct resource *port,
201 struct resource *irq, struct resource *drq)
203 struct bt_softc *bt = device_get_softc(dev);
205 SLIST_INIT(&bt->free_bt_ccbs);
206 LIST_INIT(&bt->pending_ccbs);
207 SLIST_INIT(&bt->sg_maps);
209 bt->unit = device_get_unit(dev);
213 bt->tag = rman_get_bustag(port);
214 bt->bsh = rman_get_bushandle(port);
218 bt_free_softc(device_t dev)
220 struct bt_softc *bt = device_get_softc(dev);
222 switch (bt->init_level) {
225 bus_dmamap_unload(bt->sense_dmat, bt->sense_dmamap);
227 bus_dmamem_free(bt->sense_dmat, bt->sense_buffers,
230 bus_dma_tag_destroy(bt->sense_dmat);
233 struct sg_map_node *sg_map;
235 while ((sg_map = SLIST_FIRST(&bt->sg_maps))!= NULL) {
236 SLIST_REMOVE_HEAD(&bt->sg_maps, links);
237 bus_dmamap_unload(bt->sg_dmat,
239 bus_dmamem_free(bt->sg_dmat, sg_map->sg_vaddr,
241 free(sg_map, M_DEVBUF);
243 bus_dma_tag_destroy(bt->sg_dmat);
246 bus_dmamap_unload(bt->ccb_dmat, bt->ccb_dmamap);
249 bus_dmamem_free(bt->ccb_dmat, bt->bt_ccb_array,
251 bus_dmamap_destroy(bt->ccb_dmat, bt->ccb_dmamap);
254 bus_dma_tag_destroy(bt->ccb_dmat);
257 bus_dmamap_unload(bt->mailbox_dmat, bt->mailbox_dmamap);
260 bus_dmamem_free(bt->mailbox_dmat, bt->in_boxes,
262 bus_dmamap_destroy(bt->mailbox_dmat, bt->mailbox_dmamap);
265 bus_dma_tag_destroy(bt->buffer_dmat);
268 bus_dma_tag_destroy(bt->mailbox_dmat);
276 bt_port_probe(device_t dev, struct bt_probe_info *info)
278 struct bt_softc *bt = device_get_softc(dev);
279 config_data_t config_data;
282 /* See if there is really a card present */
283 if (bt_probe(dev) || bt_fetch_adapter_info(dev))
287 * Determine our IRQ, and DMA settings and
288 * export them to the configuration system.
290 error = bt_cmd(bt, BOP_INQUIRE_CONFIG, NULL, /*parmlen*/0,
291 (u_int8_t*)&config_data, sizeof(config_data),
292 DEFAULT_CMD_TIMEOUT);
294 printf("bt_port_probe: Could not determine IRQ or DMA "
295 "settings for adapter.\n");
299 if (bt->model[0] == '5') {
300 /* DMA settings only make sense for ISA cards */
301 switch (config_data.dma_chan) {
312 printf("bt_port_probe: Invalid DMA setting "
313 "detected for adapter.\n");
317 /* VL/EISA/PCI DMA */
320 switch (config_data.irq) {
327 info->irq = ffs(config_data.irq) + 8;
330 printf("bt_port_probe: Invalid IRQ setting %x"
331 "detected for adapter.\n", config_data.irq);
338 * Probe the adapter and verify that the card is a BusLogic.
341 bt_probe(device_t dev)
343 struct bt_softc *bt = device_get_softc(dev);
344 esetup_info_data_t esetup_info;
352 * See if the three I/O ports look reasonable.
353 * Touch the minimal number of registers in the
356 status = bt_inb(bt, STATUS_REG);
358 || (status & (DIAG_ACTIVE|CMD_REG_BUSY|
359 STATUS_REG_RSVD|CMD_INVALID)) != 0) {
361 device_printf(dev, "Failed Status Reg Test - %x\n",
366 intstat = bt_inb(bt, INTSTAT_REG);
367 if ((intstat & INTSTAT_REG_RSVD) != 0) {
368 device_printf(dev, "Failed Intstat Reg Test\n");
372 geometry = bt_inb(bt, GEOMETRY_REG);
373 if (geometry == 0xFF) {
375 device_printf(dev, "Failed Geometry Reg Test\n");
380 * Looking good so far. Final test is to reset the
381 * adapter and attempt to fetch the extended setup
382 * information. This should filter out all 1542 cards.
384 if ((error = btreset(bt, /*hard_reset*/TRUE)) != 0) {
386 device_printf(dev, "Failed Reset\n");
390 param = sizeof(esetup_info);
391 error = bt_cmd(bt, BOP_INQUIRE_ESETUP_INFO, ¶m, /*parmlen*/1,
392 (u_int8_t*)&esetup_info, sizeof(esetup_info),
393 DEFAULT_CMD_TIMEOUT);
402 * Pull the boards setup information and record it in our softc.
405 bt_fetch_adapter_info(device_t dev)
407 struct bt_softc *bt = device_get_softc(dev);
408 board_id_data_t board_id;
409 esetup_info_data_t esetup_info;
410 config_data_t config_data;
412 u_int8_t length_param;
414 /* First record the firmware version */
415 error = bt_cmd(bt, BOP_INQUIRE_BOARD_ID, NULL, /*parmlen*/0,
416 (u_int8_t*)&board_id, sizeof(board_id),
417 DEFAULT_CMD_TIMEOUT);
419 device_printf(dev, "bt_fetch_adapter_info - Failed Get Board Info\n");
422 bt->firmware_ver[0] = board_id.firmware_rev_major;
423 bt->firmware_ver[1] = '.';
424 bt->firmware_ver[2] = board_id.firmware_rev_minor;
425 bt->firmware_ver[3] = '\0';
428 * Depending on the firmware major and minor version,
429 * we may be able to fetch additional minor version info.
431 if (bt->firmware_ver[0] > '0') {
433 error = bt_cmd(bt, BOP_INQUIRE_FW_VER_3DIG, NULL, /*parmlen*/0,
434 (u_int8_t*)&bt->firmware_ver[3], 1,
435 DEFAULT_CMD_TIMEOUT);
438 "bt_fetch_adapter_info - Failed Get "
439 "Firmware 3rd Digit\n");
442 if (bt->firmware_ver[3] == ' ')
443 bt->firmware_ver[3] = '\0';
444 bt->firmware_ver[4] = '\0';
447 if (strcmp(bt->firmware_ver, "3.3") >= 0) {
449 error = bt_cmd(bt, BOP_INQUIRE_FW_VER_4DIG, NULL, /*parmlen*/0,
450 (u_int8_t*)&bt->firmware_ver[4], 1,
451 DEFAULT_CMD_TIMEOUT);
454 "bt_fetch_adapter_info - Failed Get "
455 "Firmware 4th Digit\n");
458 if (bt->firmware_ver[4] == ' ')
459 bt->firmware_ver[4] = '\0';
460 bt->firmware_ver[5] = '\0';
464 * Some boards do not handle the "recently documented"
465 * Inquire Board Model Number command correctly or do not give
466 * exact information. Use the Firmware and Extended Setup
467 * information in these cases to come up with the right answer.
468 * The major firmware revision number indicates:
470 * 5.xx BusLogic "W" Series Host Adapters:
472 * 4.xx BusLogic "C" Series Host Adapters:
473 * BT-946C/956C/956CD/747C/757C/757CD/445C/545C/540CF
474 * 3.xx BusLogic "S" Series Host Adapters:
475 * BT-747S/747D/757S/757D/445S/545S/542D
476 * BT-542B/742A (revision H)
477 * 2.xx BusLogic "A" Series Host Adapters:
478 * BT-542B/742A (revision G and below)
479 * 0.xx AMI FastDisk VLB/EISA BusLogic Clone Host Adapter
481 length_param = sizeof(esetup_info);
482 error = bt_cmd(bt, BOP_INQUIRE_ESETUP_INFO, &length_param, /*parmlen*/1,
483 (u_int8_t*)&esetup_info, sizeof(esetup_info),
484 DEFAULT_CMD_TIMEOUT);
489 bt->bios_addr = esetup_info.bios_addr << 12;
491 bt->mailbox_addrlimit = BUS_SPACE_MAXADDR;
492 if (esetup_info.bus_type == 'A'
493 && bt->firmware_ver[0] == '2') {
494 snprintf(bt->model, sizeof(bt->model), "542B");
495 } else if (esetup_info.bus_type == 'E'
496 && bt->firmware_ver[0] == '2') {
499 * The 742A seems to object if its mailboxes are
500 * allocated above the 16MB mark.
502 bt->mailbox_addrlimit = BUS_SPACE_MAXADDR_24BIT;
503 snprintf(bt->model, sizeof(bt->model), "742A");
504 } else if (esetup_info.bus_type == 'E'
505 && bt->firmware_ver[0] == '0') {
506 /* AMI FastDisk EISA Series 441 0.x */
507 snprintf(bt->model, sizeof(bt->model), "747A");
509 ha_model_data_t model_data;
512 length_param = sizeof(model_data);
513 error = bt_cmd(bt, BOP_INQUIRE_MODEL, &length_param, 1,
514 (u_int8_t*)&model_data, sizeof(model_data),
515 DEFAULT_CMD_TIMEOUT);
518 "bt_fetch_adapter_info - Failed Inquire "
522 for (i = 0; i < sizeof(model_data.ascii_model); i++) {
523 bt->model[i] = model_data.ascii_model[i];
524 if (bt->model[i] == ' ')
530 bt->level_trigger_ints = esetup_info.level_trigger_ints ? 1 : 0;
532 /* SG element limits */
533 bt->max_sg = esetup_info.max_sg;
535 /* Set feature flags */
536 bt->wide_bus = esetup_info.wide_bus;
537 bt->diff_bus = esetup_info.diff_bus;
538 bt->ultra_scsi = esetup_info.ultra_scsi;
540 if ((bt->firmware_ver[0] == '5')
541 || (bt->firmware_ver[0] == '4' && bt->wide_bus))
542 bt->extended_lun = TRUE;
544 bt->strict_rr = (strcmp(bt->firmware_ver, "3.31") >= 0);
547 ((bt_inb(bt, GEOMETRY_REG) & EXTENDED_TRANSLATION) != 0);
550 * Determine max CCB count and whether tagged queuing is
551 * available based on controller type. Tagged queuing
552 * only works on 'W' series adapters, 'C' series adapters
553 * with firmware of rev 4.42 and higher, and 'S' series
554 * adapters with firmware of rev 3.35 and higher. The
555 * maximum CCB counts are as follows:
557 * 192 BT-948/958/958D
558 * 100 BT-946C/956C/956CD/747C/757C/757CD/445C
560 * 30 BT-747S/747D/757S/757D/445S/545S/542D/542B/742A
562 if (bt->firmware_ver[0] == '5') {
564 bt->tag_capable = TRUE;
565 } else if (bt->firmware_ver[0] == '4') {
566 if (bt->model[0] == '5')
570 bt->tag_capable = (strcmp(bt->firmware_ver, "4.22") >= 0);
573 if (bt->firmware_ver[0] == '3'
574 && (strcmp(bt->firmware_ver, "3.35") >= 0))
575 bt->tag_capable = TRUE;
577 bt->tag_capable = FALSE;
580 if (bt->tag_capable != FALSE)
581 bt->tags_permitted = ALL_TARGETS;
583 /* Determine Sync/Wide/Disc settings */
584 if (bt->firmware_ver[0] >= '4') {
585 auto_scsi_data_t auto_scsi_data;
586 fetch_lram_params_t fetch_lram_params;
590 * These settings are stored in the
591 * AutoSCSI data in LRAM of 'W' and 'C'
594 fetch_lram_params.offset = AUTO_SCSI_BYTE_OFFSET;
595 fetch_lram_params.response_len = sizeof(auto_scsi_data);
596 error = bt_cmd(bt, BOP_FETCH_LRAM,
597 (u_int8_t*)&fetch_lram_params,
598 sizeof(fetch_lram_params),
599 (u_int8_t*)&auto_scsi_data,
600 sizeof(auto_scsi_data), DEFAULT_CMD_TIMEOUT);
604 "bt_fetch_adapter_info - Failed "
605 "Get Auto SCSI Info\n");
609 bt->disc_permitted = auto_scsi_data.low_disc_permitted
610 | (auto_scsi_data.high_disc_permitted << 8);
611 bt->sync_permitted = auto_scsi_data.low_sync_permitted
612 | (auto_scsi_data.high_sync_permitted << 8);
613 bt->fast_permitted = auto_scsi_data.low_fast_permitted
614 | (auto_scsi_data.high_fast_permitted << 8);
615 bt->ultra_permitted = auto_scsi_data.low_ultra_permitted
616 | (auto_scsi_data.high_ultra_permitted << 8);
617 bt->wide_permitted = auto_scsi_data.low_wide_permitted
618 | (auto_scsi_data.high_wide_permitted << 8);
620 if (bt->ultra_scsi == FALSE)
621 bt->ultra_permitted = 0;
623 if (bt->wide_bus == FALSE)
624 bt->wide_permitted = 0;
627 * 'S' and 'A' series have this information in the setup
628 * information structure.
630 setup_data_t setup_info;
632 length_param = sizeof(setup_info);
633 error = bt_cmd(bt, BOP_INQUIRE_SETUP_INFO, &length_param,
634 /*paramlen*/1, (u_int8_t*)&setup_info,
635 sizeof(setup_info), DEFAULT_CMD_TIMEOUT);
639 "bt_fetch_adapter_info - Failed "
644 if (setup_info.initiate_sync != 0) {
645 bt->sync_permitted = ALL_TARGETS;
647 if (bt->model[0] == '7') {
648 if (esetup_info.sync_neg10MB != 0)
649 bt->fast_permitted = ALL_TARGETS;
650 if (strcmp(bt->model, "757") == 0)
651 bt->wide_permitted = ALL_TARGETS;
654 bt->disc_permitted = ALL_TARGETS;
657 /* We need as many mailboxes as we can have ccbs */
658 bt->num_boxes = bt->max_ccbs;
660 /* Determine our SCSI ID */
662 error = bt_cmd(bt, BOP_INQUIRE_CONFIG, NULL, /*parmlen*/0,
663 (u_int8_t*)&config_data, sizeof(config_data),
664 DEFAULT_CMD_TIMEOUT);
667 "bt_fetch_adapter_info - Failed Get Config\n");
670 bt->scsi_id = config_data.scsi_id;
676 * Start the board, ready for normal operation
679 bt_init(device_t dev)
681 struct bt_softc *bt = device_get_softc(dev);
683 /* Announce the Adapter */
684 device_printf(dev, "BT-%s FW Rev. %s ", bt->model, bt->firmware_ver);
686 if (bt->ultra_scsi != 0)
689 if (bt->wide_bus != 0)
694 if (bt->diff_bus != 0)
697 printf("SCSI Host Adapter, SCSI ID %d, %d CCBs\n", bt->scsi_id,
701 * Create our DMA tags. These tags define the kinds of device
702 * accessible memory allocations and memory mappings we will
703 * need to perform during normal operation.
705 * Unless we need to further restrict the allocation, we rely
706 * on the restrictions of the parent dmat, hence the common
707 * use of MAXADDR and MAXSIZE.
710 /* DMA tag for mapping buffers into device visible space. */
711 if (bus_dma_tag_create( /* parent */ bt->parent_dmat,
714 /* lowaddr */ BUS_SPACE_MAXADDR,
715 /* highaddr */ BUS_SPACE_MAXADDR,
717 /* filterarg */ NULL,
718 /* maxsize */ MAXBSIZE,
719 /* nsegments */ BT_NSEG,
720 /* maxsegsz */ BUS_SPACE_MAXSIZE_32BIT,
721 /* flags */ BUS_DMA_ALLOCNOW,
722 /* lockfunc */ busdma_lock_mutex,
723 /* lockarg */ &Giant,
724 &bt->buffer_dmat) != 0) {
729 /* DMA tag for our mailboxes */
730 if (bus_dma_tag_create( /* parent */ bt->parent_dmat,
733 /* lowaddr */ bt->mailbox_addrlimit,
734 /* highaddr */ BUS_SPACE_MAXADDR,
736 /* filterarg */ NULL,
737 /* maxsize */ bt->num_boxes *
738 (sizeof(bt_mbox_in_t) +
739 sizeof(bt_mbox_out_t)),
741 /* maxsegsz */ BUS_SPACE_MAXSIZE_32BIT,
743 /* lockfunc */ busdma_lock_mutex,
744 /* lockarg */ &Giant,
745 &bt->mailbox_dmat) != 0) {
751 /* Allocation for our mailboxes */
752 if (bus_dmamem_alloc(bt->mailbox_dmat, (void **)&bt->out_boxes,
753 BUS_DMA_NOWAIT, &bt->mailbox_dmamap) != 0) {
759 /* And permanently map them */
760 bus_dmamap_load(bt->mailbox_dmat, bt->mailbox_dmamap,
762 bt->num_boxes * (sizeof(bt_mbox_in_t)
763 + sizeof(bt_mbox_out_t)),
764 btmapmboxes, bt, /*flags*/0);
768 bt->in_boxes = (bt_mbox_in_t *)&bt->out_boxes[bt->num_boxes];
772 /* DMA tag for our ccb structures */
773 if (bus_dma_tag_create( /* parent */ bt->parent_dmat,
776 /* lowaddr */ BUS_SPACE_MAXADDR,
777 /* highaddr */ BUS_SPACE_MAXADDR,
779 /* filterarg */ NULL,
780 /* maxsize */ bt->max_ccbs *
781 sizeof(struct bt_ccb),
783 /* maxsegsz */ BUS_SPACE_MAXSIZE_32BIT,
785 /* lockfunc */ busdma_lock_mutex,
786 /* lockarg */ &Giant,
787 &bt->ccb_dmat) != 0) {
793 /* Allocation for our ccbs */
794 if (bus_dmamem_alloc(bt->ccb_dmat, (void **)&bt->bt_ccb_array,
795 BUS_DMA_NOWAIT, &bt->ccb_dmamap) != 0) {
801 /* And permanently map them */
802 bus_dmamap_load(bt->ccb_dmat, bt->ccb_dmamap,
804 bt->max_ccbs * sizeof(struct bt_ccb),
805 btmapccbs, bt, /*flags*/0);
809 /* DMA tag for our S/G structures. We allocate in page sized chunks */
810 if (bus_dma_tag_create( /* parent */ bt->parent_dmat,
813 /* lowaddr */ BUS_SPACE_MAXADDR,
814 /* highaddr */ BUS_SPACE_MAXADDR,
816 /* filterarg */ NULL,
817 /* maxsize */ PAGE_SIZE,
819 /* maxsegsz */ BUS_SPACE_MAXSIZE_32BIT,
821 /* lockfunc */ busdma_lock_mutex,
822 /* lockarg */ &Giant,
823 &bt->sg_dmat) != 0) {
829 /* Perform initial CCB allocation */
830 bzero(bt->bt_ccb_array, bt->max_ccbs * sizeof(struct bt_ccb));
833 if (bt->num_ccbs == 0) {
835 "bt_init - Unable to allocate initial ccbs\n");
840 * Note that we are going and return (to probe)
850 bt_attach(device_t dev)
852 struct bt_softc *bt = device_get_softc(dev);
853 int tagged_dev_openings;
854 struct cam_devq *devq;
858 * We reserve 1 ccb for error recovery, so don't
859 * tell the XPT about it.
861 if (bt->tag_capable != 0)
862 tagged_dev_openings = bt->max_ccbs - 1;
864 tagged_dev_openings = 0;
867 * Create the device queue for our SIM.
869 devq = cam_simq_alloc(bt->max_ccbs - 1);
874 * Construct our SIM entry
876 bt->sim = cam_sim_alloc(btaction, btpoll, "bt", bt, bt->unit,
877 &Giant, 2, tagged_dev_openings, devq);
878 if (bt->sim == NULL) {
883 if (xpt_bus_register(bt->sim, dev, 0) != CAM_SUCCESS) {
884 cam_sim_free(bt->sim, /*free_devq*/TRUE);
888 if (xpt_create_path(&bt->path, /*periph*/NULL,
889 cam_sim_path(bt->sim), CAM_TARGET_WILDCARD,
890 CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
891 xpt_bus_deregister(cam_sim_path(bt->sim));
892 cam_sim_free(bt->sim, /*free_devq*/TRUE);
899 error = bus_setup_intr(dev, bt->irq, INTR_TYPE_CAM|INTR_ENTROPY, NULL,
900 bt_intr, bt, &bt->ih);
902 device_printf(dev, "bus_setup_intr() failed: %d\n", error);
910 bt_check_probed_iop(u_int ioport)
914 for (i = 0; i < BT_NUM_ISAPORTS; i++) {
915 if (bt_isa_ports[i].addr == ioport) {
916 if (bt_isa_ports[i].probed != 0)
927 bt_mark_probed_bio(isa_compat_io_t port)
929 if (port < BIO_DISABLED)
930 bt_mark_probed_iop(bt_board_ports[port]);
934 bt_mark_probed_iop(u_int ioport)
938 for (i = 0; i < BT_NUM_ISAPORTS; i++) {
939 if (ioport == bt_isa_ports[i].addr) {
940 bt_isa_ports[i].probed = 1;
947 bt_find_probe_range(int ioport, int *port_index, int *max_port_index)
952 for (i = 0;i < BT_NUM_ISAPORTS; i++)
953 if (ioport <= bt_isa_ports[i].addr)
955 if ((i >= BT_NUM_ISAPORTS)
956 || (ioport != bt_isa_ports[i].addr)) {
958 "bt_find_probe_range: Invalid baseport of 0x%x specified.\n"
959 "bt_find_probe_range: Nearest valid baseport is 0x%x.\n"
960 "bt_find_probe_range: Failing probe.\n",
962 (i < BT_NUM_ISAPORTS)
963 ? bt_isa_ports[i].addr
964 : bt_isa_ports[BT_NUM_ISAPORTS - 1].addr);
965 *port_index = *max_port_index = -1;
968 *port_index = *max_port_index = bt_isa_ports[i].bio;
971 *max_port_index = BT_NUM_ISAPORTS - 1;
976 bt_iop_from_bio(isa_compat_io_t bio_index)
978 if (bio_index < BT_NUM_ISAPORTS)
979 return (bt_board_ports[bio_index]);
985 btallocccbs(struct bt_softc *bt)
987 struct bt_ccb *next_ccb;
988 struct sg_map_node *sg_map;
994 if (bt->num_ccbs >= bt->max_ccbs)
995 /* Can't allocate any more */
998 next_ccb = &bt->bt_ccb_array[bt->num_ccbs];
1000 sg_map = malloc(sizeof(*sg_map), M_DEVBUF, M_NOWAIT);
1005 /* Allocate S/G space for the next batch of CCBS */
1006 if (bus_dmamem_alloc(bt->sg_dmat, (void **)&sg_map->sg_vaddr,
1007 BUS_DMA_NOWAIT, &sg_map->sg_dmamap) != 0) {
1008 free(sg_map, M_DEVBUF);
1012 SLIST_INSERT_HEAD(&bt->sg_maps, sg_map, links);
1014 bus_dmamap_load(bt->sg_dmat, sg_map->sg_dmamap, sg_map->sg_vaddr,
1015 PAGE_SIZE, btmapsgs, bt, /*flags*/0);
1017 segs = sg_map->sg_vaddr;
1018 physaddr = sg_map->sg_physaddr;
1020 newcount = (PAGE_SIZE / (BT_NSEG * sizeof(bt_sg_t)));
1021 for (i = 0; bt->num_ccbs < bt->max_ccbs && i < newcount; i++) {
1024 next_ccb->sg_list = segs;
1025 next_ccb->sg_list_phys = physaddr;
1026 next_ccb->flags = BCCB_FREE;
1027 error = bus_dmamap_create(bt->buffer_dmat, /*flags*/0,
1031 SLIST_INSERT_HEAD(&bt->free_bt_ccbs, next_ccb, links);
1033 physaddr += (BT_NSEG * sizeof(bt_sg_t));
1038 /* Reserve a CCB for error recovery */
1039 if (bt->recovery_bccb == NULL) {
1040 bt->recovery_bccb = SLIST_FIRST(&bt->free_bt_ccbs);
1041 SLIST_REMOVE_HEAD(&bt->free_bt_ccbs, links);
1044 if (SLIST_FIRST(&bt->free_bt_ccbs) != NULL)
1048 device_printf(bt->dev, "Can't malloc BCCBs\n");
1051 static __inline void
1052 btfreeccb(struct bt_softc *bt, struct bt_ccb *bccb)
1057 if ((bccb->flags & BCCB_ACTIVE) != 0)
1058 LIST_REMOVE(&bccb->ccb->ccb_h, sim_links.le);
1059 if (bt->resource_shortage != 0
1060 && (bccb->ccb->ccb_h.status & CAM_RELEASE_SIMQ) == 0) {
1061 bccb->ccb->ccb_h.status |= CAM_RELEASE_SIMQ;
1062 bt->resource_shortage = FALSE;
1064 bccb->flags = BCCB_FREE;
1065 SLIST_INSERT_HEAD(&bt->free_bt_ccbs, bccb, links);
1070 static __inline struct bt_ccb*
1071 btgetccb(struct bt_softc *bt)
1073 struct bt_ccb* bccb;
1077 if ((bccb = SLIST_FIRST(&bt->free_bt_ccbs)) != NULL) {
1078 SLIST_REMOVE_HEAD(&bt->free_bt_ccbs, links);
1082 bccb = SLIST_FIRST(&bt->free_bt_ccbs);
1084 SLIST_REMOVE_HEAD(&bt->free_bt_ccbs, links);
1094 btaction(struct cam_sim *sim, union ccb *ccb)
1096 struct bt_softc *bt;
1098 CAM_DEBUG(ccb->ccb_h.path, CAM_DEBUG_TRACE, ("btaction\n"));
1100 bt = (struct bt_softc *)cam_sim_softc(sim);
1102 switch (ccb->ccb_h.func_code) {
1103 /* Common cases first */
1104 case XPT_SCSI_IO: /* Execute the requested I/O operation */
1105 case XPT_RESET_DEV: /* Bus Device Reset the specified SCSI device */
1107 struct bt_ccb *bccb;
1108 struct bt_hccb *hccb;
1111 * get a bccb to use.
1113 if ((bccb = btgetccb(bt)) == NULL) {
1117 bt->resource_shortage = TRUE;
1119 xpt_freeze_simq(bt->sim, /*count*/1);
1120 ccb->ccb_h.status = CAM_REQUEUE_REQ;
1128 * So we can find the BCCB when an abort is requested
1131 ccb->ccb_h.ccb_bccb_ptr = bccb;
1132 ccb->ccb_h.ccb_bt_ptr = bt;
1135 * Put all the arguments for the xfer in the bccb
1137 hccb->target_id = ccb->ccb_h.target_id;
1138 hccb->target_lun = ccb->ccb_h.target_lun;
1142 if (ccb->ccb_h.func_code == XPT_SCSI_IO) {
1143 struct ccb_scsiio *csio;
1144 struct ccb_hdr *ccbh;
1147 ccbh = &csio->ccb_h;
1148 hccb->opcode = INITIATOR_CCB_WRESID;
1149 hccb->datain = (ccb->ccb_h.flags & CAM_DIR_IN) ? 1 : 0;
1150 hccb->dataout =(ccb->ccb_h.flags & CAM_DIR_OUT) ? 1 : 0;
1151 hccb->cmd_len = csio->cdb_len;
1152 if (hccb->cmd_len > sizeof(hccb->scsi_cdb)) {
1153 ccb->ccb_h.status = CAM_REQ_INVALID;
1154 btfreeccb(bt, bccb);
1158 hccb->sense_len = csio->sense_len;
1159 if ((ccbh->flags & CAM_TAG_ACTION_VALID) != 0
1160 && ccb->csio.tag_action != CAM_TAG_ACTION_NONE) {
1161 hccb->tag_enable = TRUE;
1162 hccb->tag_type = (ccb->csio.tag_action & 0x3);
1164 hccb->tag_enable = FALSE;
1167 if ((ccbh->flags & CAM_CDB_POINTER) != 0) {
1168 if ((ccbh->flags & CAM_CDB_PHYS) == 0) {
1169 bcopy(csio->cdb_io.cdb_ptr,
1170 hccb->scsi_cdb, hccb->cmd_len);
1172 /* I guess I could map it in... */
1173 ccbh->status = CAM_REQ_INVALID;
1174 btfreeccb(bt, bccb);
1179 bcopy(csio->cdb_io.cdb_bytes,
1180 hccb->scsi_cdb, hccb->cmd_len);
1182 /* If need be, bounce our sense buffer */
1183 if (bt->sense_buffers != NULL) {
1184 hccb->sense_addr = btsensepaddr(bt, bccb);
1186 hccb->sense_addr = vtophys(&csio->sense_data);
1189 * If we have any data to send with this command,
1190 * map it into bus space.
1192 /* Only use S/G if there is a transfer */
1193 if ((ccbh->flags & CAM_DIR_MASK) != CAM_DIR_NONE) {
1194 if ((ccbh->flags & CAM_SCATTER_VALID) == 0) {
1196 * We've been given a pointer
1197 * to a single buffer.
1199 if ((ccbh->flags & CAM_DATA_PHYS)==0) {
1204 error = bus_dmamap_load(
1212 if (error == EINPROGRESS) {
1215 * ordering, freeze the
1217 * until our mapping is
1220 xpt_freeze_simq(bt->sim,
1222 csio->ccb_h.status |=
1227 struct bus_dma_segment seg;
1229 /* Pointer to physical buffer */
1231 (bus_addr_t)csio->data_ptr;
1232 seg.ds_len = csio->dxfer_len;
1233 btexecuteccb(bccb, &seg, 1, 0);
1236 struct bus_dma_segment *segs;
1238 if ((ccbh->flags & CAM_DATA_PHYS) != 0)
1239 panic("btaction - Physical "
1243 if ((ccbh->flags&CAM_SG_LIST_PHYS)==0)
1244 panic("btaction - Virtual "
1245 "segment addresses "
1248 /* Just use the segments provided */
1249 segs = (struct bus_dma_segment *)
1251 btexecuteccb(bccb, segs,
1252 csio->sglist_cnt, 0);
1255 btexecuteccb(bccb, NULL, 0, 0);
1258 hccb->opcode = INITIATOR_BUS_DEV_RESET;
1259 /* No data transfer */
1260 hccb->datain = TRUE;
1261 hccb->dataout = TRUE;
1263 hccb->sense_len = 0;
1264 hccb->tag_enable = FALSE;
1266 btexecuteccb(bccb, NULL, 0, 0);
1270 case XPT_EN_LUN: /* Enable LUN as a target */
1271 case XPT_TARGET_IO: /* Execute target I/O request */
1272 case XPT_ACCEPT_TARGET_IO: /* Accept Host Target Mode CDB */
1273 case XPT_CONT_TARGET_IO: /* Continue Host Target I/O Connection*/
1274 case XPT_ABORT: /* Abort the specified CCB */
1276 ccb->ccb_h.status = CAM_REQ_INVALID;
1279 case XPT_SET_TRAN_SETTINGS:
1282 ccb->ccb_h.status = CAM_PROVIDE_FAIL;
1286 case XPT_GET_TRAN_SETTINGS:
1287 /* Get default/user set transfer settings for the target */
1289 struct ccb_trans_settings *cts;
1293 target_mask = 0x01 << ccb->ccb_h.target_id;
1294 if (cts->type == CTS_TYPE_CURRENT_SETTINGS) {
1295 struct ccb_trans_settings_scsi *scsi =
1296 &cts->proto_specific.scsi;
1297 struct ccb_trans_settings_spi *spi =
1298 &cts->xport_specific.spi;
1299 cts->protocol = PROTO_SCSI;
1300 cts->protocol_version = SCSI_REV_2;
1301 cts->transport = XPORT_SPI;
1302 cts->transport_version = 2;
1304 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
1305 spi->flags &= ~CTS_SPI_FLAGS_DISC_ENB;
1307 if ((bt->disc_permitted & target_mask) != 0)
1308 spi->flags |= CTS_SPI_FLAGS_DISC_ENB;
1309 if ((bt->tags_permitted & target_mask) != 0)
1310 scsi->flags |= CTS_SCSI_FLAGS_TAG_ENB;
1312 if ((bt->ultra_permitted & target_mask) != 0)
1313 spi->sync_period = 12;
1314 else if ((bt->fast_permitted & target_mask) != 0)
1315 spi->sync_period = 25;
1316 else if ((bt->sync_permitted & target_mask) != 0)
1317 spi->sync_period = 50;
1319 spi->sync_period = 0;
1321 if (spi->sync_period != 0)
1322 spi->sync_offset = 15;
1324 spi->valid |= CTS_SPI_VALID_SYNC_RATE;
1325 spi->valid |= CTS_SPI_VALID_SYNC_OFFSET;
1327 spi->valid |= CTS_SPI_VALID_BUS_WIDTH;
1328 if ((bt->wide_permitted & target_mask) != 0)
1329 spi->bus_width = MSG_EXT_WDTR_BUS_16_BIT;
1331 spi->bus_width = MSG_EXT_WDTR_BUS_8_BIT;
1333 if (cts->ccb_h.target_lun != CAM_LUN_WILDCARD) {
1334 scsi->valid = CTS_SCSI_VALID_TQ;
1335 spi->valid |= CTS_SPI_VALID_DISC;
1339 btfetchtransinfo(bt, cts);
1342 ccb->ccb_h.status = CAM_REQ_CMP;
1346 case XPT_CALC_GEOMETRY:
1348 struct ccb_calc_geometry *ccg;
1350 u_int32_t secs_per_cylinder;
1353 size_mb = ccg->volume_size
1354 / ((1024L * 1024L) / ccg->block_size);
1356 if (size_mb >= 1024 && (bt->extended_trans != 0)) {
1357 if (size_mb >= 2048) {
1359 ccg->secs_per_track = 63;
1362 ccg->secs_per_track = 32;
1366 ccg->secs_per_track = 32;
1368 secs_per_cylinder = ccg->heads * ccg->secs_per_track;
1369 ccg->cylinders = ccg->volume_size / secs_per_cylinder;
1370 ccb->ccb_h.status = CAM_REQ_CMP;
1374 case XPT_RESET_BUS: /* Reset the specified SCSI bus */
1376 btreset(bt, /*hardreset*/TRUE);
1377 ccb->ccb_h.status = CAM_REQ_CMP;
1381 case XPT_TERM_IO: /* Terminate the I/O process */
1383 ccb->ccb_h.status = CAM_REQ_INVALID;
1386 case XPT_PATH_INQ: /* Path routing inquiry */
1388 struct ccb_pathinq *cpi = &ccb->cpi;
1390 cpi->version_num = 1; /* XXX??? */
1391 cpi->hba_inquiry = PI_SDTR_ABLE;
1392 if (bt->tag_capable != 0)
1393 cpi->hba_inquiry |= PI_TAG_ABLE;
1394 if (bt->wide_bus != 0)
1395 cpi->hba_inquiry |= PI_WIDE_16;
1396 cpi->target_sprt = 0;
1398 cpi->hba_eng_cnt = 0;
1399 cpi->max_target = bt->wide_bus ? 15 : 7;
1401 cpi->initiator_id = bt->scsi_id;
1402 cpi->bus_id = cam_sim_bus(sim);
1403 cpi->base_transfer_speed = 3300;
1404 strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
1405 strncpy(cpi->hba_vid, "BusLogic", HBA_IDLEN);
1406 strncpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN);
1407 cpi->unit_number = cam_sim_unit(sim);
1408 cpi->ccb_h.status = CAM_REQ_CMP;
1409 cpi->transport = XPORT_SPI;
1410 cpi->transport_version = 2;
1411 cpi->protocol = PROTO_SCSI;
1412 cpi->protocol_version = SCSI_REV_2;
1417 ccb->ccb_h.status = CAM_REQ_INVALID;
1424 btexecuteccb(void *arg, bus_dma_segment_t *dm_segs, int nseg, int error)
1426 struct bt_ccb *bccb;
1428 struct bt_softc *bt;
1431 bccb = (struct bt_ccb *)arg;
1433 bt = (struct bt_softc *)ccb->ccb_h.ccb_bt_ptr;
1437 device_printf(bt->dev,
1438 "Unexepected error 0x%x returned from "
1439 "bus_dmamap_load\n", error);
1440 if (ccb->ccb_h.status == CAM_REQ_INPROG) {
1441 xpt_freeze_devq(ccb->ccb_h.path, /*count*/1);
1442 ccb->ccb_h.status = CAM_REQ_TOO_BIG|CAM_DEV_QFRZN;
1444 btfreeccb(bt, bccb);
1451 bus_dma_segment_t *end_seg;
1452 bus_dmasync_op_t op;
1454 end_seg = dm_segs + nseg;
1456 /* Copy the segments into our SG list */
1458 while (dm_segs < end_seg) {
1459 sg->len = dm_segs->ds_len;
1460 sg->addr = dm_segs->ds_addr;
1466 bccb->hccb.opcode = INITIATOR_SG_CCB_WRESID;
1467 bccb->hccb.data_len = sizeof(bt_sg_t) * nseg;
1468 bccb->hccb.data_addr = bccb->sg_list_phys;
1470 bccb->hccb.data_len = bccb->sg_list->len;
1471 bccb->hccb.data_addr = bccb->sg_list->addr;
1474 if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN)
1475 op = BUS_DMASYNC_PREREAD;
1477 op = BUS_DMASYNC_PREWRITE;
1479 bus_dmamap_sync(bt->buffer_dmat, bccb->dmamap, op);
1482 bccb->hccb.opcode = INITIATOR_CCB;
1483 bccb->hccb.data_len = 0;
1484 bccb->hccb.data_addr = 0;
1490 * Last time we need to check if this CCB needs to
1493 if (ccb->ccb_h.status != CAM_REQ_INPROG) {
1495 bus_dmamap_unload(bt->buffer_dmat, bccb->dmamap);
1496 btfreeccb(bt, bccb);
1502 bccb->flags = BCCB_ACTIVE;
1503 ccb->ccb_h.status |= CAM_SIM_QUEUED;
1504 LIST_INSERT_HEAD(&bt->pending_ccbs, &ccb->ccb_h, sim_links.le);
1506 ccb->ccb_h.timeout_ch =
1507 timeout(bttimeout, (caddr_t)bccb,
1508 (ccb->ccb_h.timeout * hz) / 1000);
1510 /* Tell the adapter about this command */
1511 bt->cur_outbox->ccb_addr = btccbvtop(bt, bccb);
1512 if (bt->cur_outbox->action_code != BMBO_FREE) {
1514 * We should never encounter a busy mailbox.
1515 * If we do, warn the user, and treat it as
1516 * a resource shortage. If the controller is
1517 * hung, one of the pending transactions will
1518 * timeout causing us to start recovery operations.
1520 device_printf(bt->dev,
1521 "Encountered busy mailbox with %d out of %d "
1522 "commands active!!!\n", bt->active_ccbs,
1524 untimeout(bttimeout, bccb, ccb->ccb_h.timeout_ch);
1526 bus_dmamap_unload(bt->buffer_dmat, bccb->dmamap);
1527 btfreeccb(bt, bccb);
1528 bt->resource_shortage = TRUE;
1529 xpt_freeze_simq(bt->sim, /*count*/1);
1530 ccb->ccb_h.status = CAM_REQUEUE_REQ;
1534 bt->cur_outbox->action_code = BMBO_START;
1535 bt_outb(bt, COMMAND_REG, BOP_START_MBOX);
1543 struct bt_softc *bt;
1546 bt = (struct bt_softc *)arg;
1547 while (((intstat = bt_inb(bt, INTSTAT_REG)) & INTR_PENDING) != 0) {
1549 if ((intstat & CMD_COMPLETE) != 0) {
1550 bt->latched_status = bt_inb(bt, STATUS_REG);
1551 bt->command_cmp = TRUE;
1554 bt_outb(bt, CONTROL_REG, RESET_INTR);
1556 if ((intstat & IMB_LOADED) != 0) {
1557 while (bt->cur_inbox->comp_code != BMBI_FREE) {
1559 btccbptov(bt, bt->cur_inbox->ccb_addr),
1560 bt->cur_inbox->comp_code);
1561 bt->cur_inbox->comp_code = BMBI_FREE;
1566 if ((intstat & SCSI_BUS_RESET) != 0) {
1567 btreset(bt, /*hardreset*/FALSE);
1573 btdone(struct bt_softc *bt, struct bt_ccb *bccb, bt_mbi_comp_code_t comp_code)
1576 struct ccb_scsiio *csio;
1579 csio = &bccb->ccb->csio;
1581 if ((bccb->flags & BCCB_ACTIVE) == 0) {
1582 device_printf(bt->dev,
1583 "btdone - Attempt to free non-active BCCB %p\n",
1588 if ((ccb->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE) {
1589 bus_dmasync_op_t op;
1591 if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN)
1592 op = BUS_DMASYNC_POSTREAD;
1594 op = BUS_DMASYNC_POSTWRITE;
1595 bus_dmamap_sync(bt->buffer_dmat, bccb->dmamap, op);
1596 bus_dmamap_unload(bt->buffer_dmat, bccb->dmamap);
1599 if (bccb == bt->recovery_bccb) {
1601 * The recovery BCCB does not have a CCB associated
1602 * with it, so short circuit the normal error handling.
1603 * We now traverse our list of pending CCBs and process
1604 * any that were terminated by the recovery CCBs action.
1605 * We also reinstate timeouts for all remaining, pending,
1608 struct cam_path *path;
1609 struct ccb_hdr *ccb_h;
1612 /* Notify all clients that a BDR occured */
1613 error = xpt_create_path(&path, /*periph*/NULL,
1614 cam_sim_path(bt->sim),
1615 bccb->hccb.target_id,
1618 if (error == CAM_REQ_CMP)
1619 xpt_async(AC_SENT_BDR, path, NULL);
1621 ccb_h = LIST_FIRST(&bt->pending_ccbs);
1622 while (ccb_h != NULL) {
1623 struct bt_ccb *pending_bccb;
1625 pending_bccb = (struct bt_ccb *)ccb_h->ccb_bccb_ptr;
1626 if (pending_bccb->hccb.target_id
1627 == bccb->hccb.target_id) {
1628 pending_bccb->hccb.btstat = BTSTAT_HA_BDR;
1629 ccb_h = LIST_NEXT(ccb_h, sim_links.le);
1630 btdone(bt, pending_bccb, BMBI_ERROR);
1633 timeout(bttimeout, (caddr_t)pending_bccb,
1634 (ccb_h->timeout * hz) / 1000);
1635 ccb_h = LIST_NEXT(ccb_h, sim_links.le);
1638 device_printf(bt->dev, "No longer in timeout\n");
1642 untimeout(bttimeout, bccb, ccb->ccb_h.timeout_ch);
1644 switch (comp_code) {
1646 device_printf(bt->dev,
1647 "btdone - CCB completed with free status!\n");
1649 case BMBI_NOT_FOUND:
1650 device_printf(bt->dev,
1651 "btdone - CCB Abort failed to find CCB\n");
1656 printf("bt: ccb %p - error %x occured. "
1657 "btstat = %x, sdstat = %x\n",
1658 (void *)bccb, comp_code, bccb->hccb.btstat,
1661 /* An error occured */
1662 switch(bccb->hccb.btstat) {
1663 case BTSTAT_DATARUN_ERROR:
1664 if (bccb->hccb.data_len == 0) {
1666 * At least firmware 4.22, does this
1667 * for a QUEUE FULL condition.
1669 bccb->hccb.sdstat = SCSI_STATUS_QUEUE_FULL;
1670 } else if (bccb->hccb.data_len < 0) {
1671 csio->ccb_h.status = CAM_DATA_RUN_ERR;
1675 case BTSTAT_NOERROR:
1676 case BTSTAT_LINKED_CMD_COMPLETE:
1677 case BTSTAT_LINKED_CMD_FLAG_COMPLETE:
1678 case BTSTAT_DATAUNDERUN_ERROR:
1680 csio->scsi_status = bccb->hccb.sdstat;
1681 csio->ccb_h.status |= CAM_SCSI_STATUS_ERROR;
1682 switch(csio->scsi_status) {
1683 case SCSI_STATUS_CHECK_COND:
1684 case SCSI_STATUS_CMD_TERMINATED:
1685 csio->ccb_h.status |= CAM_AUTOSNS_VALID;
1686 /* Bounce sense back if necessary */
1687 if (bt->sense_buffers != NULL) {
1689 *btsensevaddr(bt, bccb);
1694 case SCSI_STATUS_OK:
1695 csio->ccb_h.status = CAM_REQ_CMP;
1698 csio->resid = bccb->hccb.data_len;
1700 case BTSTAT_SELTIMEOUT:
1701 csio->ccb_h.status = CAM_SEL_TIMEOUT;
1703 case BTSTAT_UNEXPECTED_BUSFREE:
1704 csio->ccb_h.status = CAM_UNEXP_BUSFREE;
1706 case BTSTAT_INVALID_PHASE:
1707 csio->ccb_h.status = CAM_SEQUENCE_FAIL;
1709 case BTSTAT_INVALID_ACTION_CODE:
1710 panic("%s: Inavlid Action code", bt_name(bt));
1712 case BTSTAT_INVALID_OPCODE:
1713 panic("%s: Inavlid CCB Opcode code", bt_name(bt));
1715 case BTSTAT_LINKED_CCB_LUN_MISMATCH:
1716 /* We don't even support linked commands... */
1717 panic("%s: Linked CCB Lun Mismatch", bt_name(bt));
1719 case BTSTAT_INVALID_CCB_OR_SG_PARAM:
1720 panic("%s: Invalid CCB or SG list", bt_name(bt));
1722 case BTSTAT_AUTOSENSE_FAILED:
1723 csio->ccb_h.status = CAM_AUTOSENSE_FAIL;
1725 case BTSTAT_TAGGED_MSG_REJECTED:
1727 struct ccb_trans_settings neg;
1728 struct ccb_trans_settings_scsi *scsi =
1729 &neg.proto_specific.scsi;
1731 neg.protocol = PROTO_SCSI;
1732 neg.protocol_version = SCSI_REV_2;
1733 neg.transport = XPORT_SPI;
1734 neg.transport_version = 2;
1735 scsi->valid = CTS_SCSI_VALID_TQ;
1737 xpt_print_path(csio->ccb_h.path);
1738 printf("refuses tagged commands. Performing "
1739 "non-tagged I/O\n");
1740 xpt_setup_ccb(&neg.ccb_h, csio->ccb_h.path,
1742 xpt_async(AC_TRANSFER_NEG, csio->ccb_h.path, &neg);
1743 bt->tags_permitted &= ~(0x01 << csio->ccb_h.target_id);
1744 csio->ccb_h.status = CAM_MSG_REJECT_REC;
1747 case BTSTAT_UNSUPPORTED_MSG_RECEIVED:
1749 * XXX You would think that this is
1750 * a recoverable error... Hmmm.
1752 csio->ccb_h.status = CAM_REQ_CMP_ERR;
1754 case BTSTAT_HA_SOFTWARE_ERROR:
1755 case BTSTAT_HA_WATCHDOG_ERROR:
1756 case BTSTAT_HARDWARE_FAILURE:
1757 /* Hardware reset ??? Can we recover ??? */
1758 csio->ccb_h.status = CAM_NO_HBA;
1760 case BTSTAT_TARGET_IGNORED_ATN:
1761 case BTSTAT_OTHER_SCSI_BUS_RESET:
1762 case BTSTAT_HA_SCSI_BUS_RESET:
1763 if ((csio->ccb_h.status & CAM_STATUS_MASK)
1765 csio->ccb_h.status = CAM_SCSI_BUS_RESET;
1768 if ((bccb->flags & BCCB_DEVICE_RESET) == 0)
1769 csio->ccb_h.status = CAM_BDR_SENT;
1771 csio->ccb_h.status = CAM_CMD_TIMEOUT;
1773 case BTSTAT_INVALID_RECONNECT:
1774 case BTSTAT_ABORT_QUEUE_GENERATED:
1775 csio->ccb_h.status = CAM_REQ_TERMIO;
1777 case BTSTAT_SCSI_PERROR_DETECTED:
1778 csio->ccb_h.status = CAM_UNCOR_PARITY;
1781 if (csio->ccb_h.status != CAM_REQ_CMP) {
1782 xpt_freeze_devq(csio->ccb_h.path, /*count*/1);
1783 csio->ccb_h.status |= CAM_DEV_QFRZN;
1785 if ((bccb->flags & BCCB_RELEASE_SIMQ) != 0)
1786 ccb->ccb_h.status |= CAM_RELEASE_SIMQ;
1787 btfreeccb(bt, bccb);
1791 /* All completed without incident */
1792 ccb->ccb_h.status |= CAM_REQ_CMP;
1793 if ((bccb->flags & BCCB_RELEASE_SIMQ) != 0)
1794 ccb->ccb_h.status |= CAM_RELEASE_SIMQ;
1795 btfreeccb(bt, bccb);
1802 btreset(struct bt_softc* bt, int hard_reset)
1804 struct ccb_hdr *ccb_h;
1807 u_int8_t reset_type;
1809 if (hard_reset != 0)
1810 reset_type = HARD_RESET;
1812 reset_type = SOFT_RESET;
1813 bt_outb(bt, CONTROL_REG, reset_type);
1815 /* Wait 5sec. for Diagnostic start */
1816 timeout = 5 * 10000;
1818 status = bt_inb(bt, STATUS_REG);
1819 if ((status & DIAG_ACTIVE) != 0)
1825 printf("%s: btreset - Diagnostic Active failed to "
1826 "assert. status = 0x%x\n", bt_name(bt), status);
1830 /* Wait 10sec. for Diagnostic end */
1831 timeout = 10 * 10000;
1833 status = bt_inb(bt, STATUS_REG);
1834 if ((status & DIAG_ACTIVE) == 0)
1839 panic("%s: btreset - Diagnostic Active failed to drop. "
1840 "status = 0x%x\n", bt_name(bt), status);
1844 /* Wait for the host adapter to become ready or report a failure */
1847 status = bt_inb(bt, STATUS_REG);
1848 if ((status & (DIAG_FAIL|HA_READY|DATAIN_REG_READY)) != 0)
1853 printf("%s: btreset - Host adapter failed to come ready. "
1854 "status = 0x%x\n", bt_name(bt), status);
1858 /* If the diagnostics failed, tell the user */
1859 if ((status & DIAG_FAIL) != 0
1860 || (status & HA_READY) == 0) {
1861 printf("%s: btreset - Adapter failed diagnostics\n",
1864 if ((status & DATAIN_REG_READY) != 0)
1865 printf("%s: btreset - Host Adapter Error code = 0x%x\n",
1866 bt_name(bt), bt_inb(bt, DATAIN_REG));
1870 /* If we've allocated mailboxes, initialize them */
1871 if (bt->init_level > 4)
1874 /* If we've attached to the XPT, tell it about the event */
1875 if (bt->path != NULL)
1876 xpt_async(AC_BUS_RESET, bt->path, NULL);
1879 * Perform completion processing for all outstanding CCBs.
1881 while ((ccb_h = LIST_FIRST(&bt->pending_ccbs)) != NULL) {
1882 struct bt_ccb *pending_bccb;
1884 pending_bccb = (struct bt_ccb *)ccb_h->ccb_bccb_ptr;
1885 pending_bccb->hccb.btstat = BTSTAT_HA_SCSI_BUS_RESET;
1886 btdone(bt, pending_bccb, BMBI_ERROR);
1893 * Send a command to the adapter.
1896 bt_cmd(struct bt_softc *bt, bt_op_t opcode, u_int8_t *params, u_int param_len,
1897 u_int8_t *reply_data, u_int reply_len, u_int cmd_timeout)
1903 u_int reply_buf_size;
1908 /* No data returned to start */
1909 reply_buf_size = reply_len;
1916 bt->command_cmp = 0;
1918 * Wait up to 10 sec. for the adapter to become
1919 * ready to accept commands.
1923 status = bt_inb(bt, STATUS_REG);
1924 if ((status & HA_READY) != 0
1925 && (status & CMD_REG_BUSY) == 0)
1928 * Throw away any pending data which may be
1929 * left over from earlier commands that we
1932 if ((status & DATAIN_REG_READY) != 0)
1933 (void)bt_inb(bt, DATAIN_REG);
1937 printf("%s: bt_cmd: Timeout waiting for adapter ready, "
1938 "status = 0x%x\n", bt_name(bt), status);
1943 * Send the opcode followed by any necessary parameter bytes.
1945 bt_outb(bt, COMMAND_REG, opcode);
1948 * Wait for up to 1sec for each byte of the the
1949 * parameter list sent to be sent.
1952 while (param_len && --timeout) {
1955 status = bt_inb(bt, STATUS_REG);
1956 intstat = bt_inb(bt, INTSTAT_REG);
1959 if ((intstat & (INTR_PENDING|CMD_COMPLETE))
1960 == (INTR_PENDING|CMD_COMPLETE)) {
1961 saved_status = status;
1965 if (bt->command_cmp != 0) {
1966 saved_status = bt->latched_status;
1970 if ((status & DATAIN_REG_READY) != 0)
1972 if ((status & CMD_REG_BUSY) == 0) {
1973 bt_outb(bt, COMMAND_REG, *params++);
1979 printf("%s: bt_cmd: Timeout sending parameters, "
1980 "status = 0x%x\n", bt_name(bt), status);
1982 saved_status = status;
1987 * Wait for the command to complete.
1989 while (cmd_complete == 0 && --cmd_timeout) {
1992 status = bt_inb(bt, STATUS_REG);
1993 intstat = bt_inb(bt, INTSTAT_REG);
1995 * It may be that this command was issued with
1996 * controller interrupts disabled. We'll never
1997 * get to our command if an incoming mailbox
1998 * interrupt is pending, so take care of completed
1999 * mailbox commands by calling our interrupt handler.
2001 if ((intstat & (INTR_PENDING|IMB_LOADED))
2002 == (INTR_PENDING|IMB_LOADED))
2006 if (bt->command_cmp != 0) {
2008 * Our interrupt handler saw CMD_COMPLETE
2009 * status before we did.
2012 saved_status = bt->latched_status;
2013 } else if ((intstat & (INTR_PENDING|CMD_COMPLETE))
2014 == (INTR_PENDING|CMD_COMPLETE)) {
2016 * Our poll (in case interrupts are blocked)
2017 * saw the CMD_COMPLETE interrupt.
2020 saved_status = status;
2021 } else if (opcode == BOP_MODIFY_IO_ADDR
2022 && (status & CMD_REG_BUSY) == 0) {
2024 * The BOP_MODIFY_IO_ADDR does not issue a CMD_COMPLETE,
2025 * but it should update the status register. So, we
2026 * consider this command complete when the CMD_REG_BUSY
2029 saved_status = status;
2031 } else if ((status & DATAIN_REG_READY) != 0) {
2034 data = bt_inb(bt, DATAIN_REG);
2035 if (reply_len < reply_buf_size) {
2036 *reply_data++ = data;
2038 printf("%s: bt_cmd - Discarded reply data byte "
2039 "for opcode 0x%x\n", bt_name(bt),
2043 * Reset timeout to ensure at least a second
2044 * between response bytes.
2046 cmd_timeout = MAX(cmd_timeout, 10000);
2049 } else if ((opcode == BOP_FETCH_LRAM)
2050 && (status & HA_READY) != 0) {
2051 saved_status = status;
2056 if (cmd_timeout == 0) {
2057 printf("%s: bt_cmd: Timeout waiting for command (%x) "
2058 "to complete.\n%s: status = 0x%x, intstat = 0x%x, "
2059 "rlen %d\n", bt_name(bt), opcode,
2060 bt_name(bt), status, intstat, reply_len);
2061 error = (ETIMEDOUT);
2065 * Clear any pending interrupts. Block interrupts so our
2066 * interrupt handler is not re-entered.
2076 * If the command was rejected by the controller, tell the caller.
2078 if ((saved_status & CMD_INVALID) != 0) {
2080 * Some early adapters may not recover properly from
2081 * an invalid command. If it appears that the controller
2082 * has wedged (i.e. status was not cleared by our interrupt
2083 * reset above), perform a soft reset.
2086 printf("%s: Invalid Command 0x%x\n", bt_name(bt),
2089 status = bt_inb(bt, STATUS_REG);
2090 if ((status & (CMD_INVALID|STATUS_REG_RSVD|DATAIN_REG_READY|
2091 CMD_REG_BUSY|DIAG_FAIL|DIAG_ACTIVE)) != 0
2092 || (status & (HA_READY|INIT_REQUIRED))
2093 != (HA_READY|INIT_REQUIRED)) {
2094 btreset(bt, /*hard_reset*/FALSE);
2099 if (param_len > 0) {
2100 /* The controller did not accept the full argument list */
2104 if (reply_len != reply_buf_size) {
2105 /* Too much or too little data received */
2109 /* We were successful */
2114 btinitmboxes(struct bt_softc *bt) {
2115 init_32b_mbox_params_t init_mbox;
2118 bzero(bt->in_boxes, sizeof(bt_mbox_in_t) * bt->num_boxes);
2119 bzero(bt->out_boxes, sizeof(bt_mbox_out_t) * bt->num_boxes);
2120 bt->cur_inbox = bt->in_boxes;
2121 bt->last_inbox = bt->in_boxes + bt->num_boxes - 1;
2122 bt->cur_outbox = bt->out_boxes;
2123 bt->last_outbox = bt->out_boxes + bt->num_boxes - 1;
2125 /* Tell the adapter about them */
2126 init_mbox.num_boxes = bt->num_boxes;
2127 init_mbox.base_addr[0] = bt->mailbox_physbase & 0xFF;
2128 init_mbox.base_addr[1] = (bt->mailbox_physbase >> 8) & 0xFF;
2129 init_mbox.base_addr[2] = (bt->mailbox_physbase >> 16) & 0xFF;
2130 init_mbox.base_addr[3] = (bt->mailbox_physbase >> 24) & 0xFF;
2131 error = bt_cmd(bt, BOP_INITIALIZE_32BMBOX, (u_int8_t *)&init_mbox,
2132 /*parmlen*/sizeof(init_mbox), /*reply_buf*/NULL,
2133 /*reply_len*/0, DEFAULT_CMD_TIMEOUT);
2136 printf("btinitmboxes: Initialization command failed\n");
2137 else if (bt->strict_rr != 0) {
2139 * If the controller supports
2140 * strict round robin mode,
2146 error = bt_cmd(bt, BOP_ENABLE_STRICT_RR, ¶m, 1,
2147 /*reply_buf*/NULL, /*reply_len*/0,
2148 DEFAULT_CMD_TIMEOUT);
2151 printf("btinitmboxes: Unable to enable strict RR\n");
2153 } else if (bootverbose) {
2154 printf("%s: Using Strict Round Robin Mailbox Mode\n",
2163 * Update the XPT's idea of the negotiated transfer
2164 * parameters for a particular target.
2167 btfetchtransinfo(struct bt_softc *bt, struct ccb_trans_settings *cts)
2169 setup_data_t setup_info;
2178 targ_syncinfo_t sync_info;
2179 struct ccb_trans_settings_scsi *scsi =
2180 &cts->proto_specific.scsi;
2181 struct ccb_trans_settings_spi *spi =
2182 &cts->xport_specific.spi;
2187 target = cts->ccb_h.target_id;
2188 targ_offset = (target & 0x7);
2189 targ_mask = (0x01 << targ_offset);
2192 * Inquire Setup Information. This command retreives the
2193 * Wide negotiation status for recent adapters as well as
2194 * the sync info for older models.
2196 param = sizeof(setup_info);
2197 error = bt_cmd(bt, BOP_INQUIRE_SETUP_INFO, ¶m, /*paramlen*/1,
2198 (u_int8_t*)&setup_info, sizeof(setup_info),
2199 DEFAULT_CMD_TIMEOUT);
2202 printf("%s: btfetchtransinfo - Inquire Setup Info Failed %x\n",
2203 bt_name(bt), error);
2207 sync_info = (target < 8) ? setup_info.low_syncinfo[targ_offset]
2208 : setup_info.high_syncinfo[targ_offset];
2210 if (sync_info.sync == 0)
2213 sync_offset = sync_info.offset;
2216 bus_width = MSG_EXT_WDTR_BUS_8_BIT;
2217 if (strcmp(bt->firmware_ver, "5.06L") >= 0) {
2221 (target < 8) ? (setup_info.low_wide_active & targ_mask)
2222 : (setup_info.high_wide_active & targ_mask);
2225 bus_width = MSG_EXT_WDTR_BUS_16_BIT;
2226 } else if ((bt->wide_permitted & targ_mask) != 0) {
2227 struct ccb_getdev cgd;
2230 * Prior to rev 5.06L, wide status isn't provided,
2231 * so we "guess" that wide transfers are in effect
2232 * if the user settings allow for wide and the inquiry
2233 * data for the device indicates that it can handle
2236 xpt_setup_ccb(&cgd.ccb_h, cts->ccb_h.path, /*priority*/1);
2237 cgd.ccb_h.func_code = XPT_GDEV_TYPE;
2238 xpt_action((union ccb *)&cgd);
2239 if ((cgd.ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP
2240 && (cgd.inq_data.flags & SID_WBus16) != 0)
2241 bus_width = MSG_EXT_WDTR_BUS_16_BIT;
2244 if (bt->firmware_ver[0] >= '3') {
2246 * For adapters that can do fast or ultra speeds,
2247 * use the more exact Target Sync Information command.
2249 target_sync_info_data_t sync_info;
2251 param = sizeof(sync_info);
2252 error = bt_cmd(bt, BOP_TARG_SYNC_INFO, ¶m, /*paramlen*/1,
2253 (u_int8_t*)&sync_info, sizeof(sync_info),
2254 DEFAULT_CMD_TIMEOUT);
2257 printf("%s: btfetchtransinfo - Inquire Sync "
2258 "Info Failed 0x%x\n", bt_name(bt), error);
2261 sync_period = sync_info.sync_rate[target] * 100;
2263 sync_period = 2000 + (500 * sync_info.period);
2266 cts->protocol = PROTO_SCSI;
2267 cts->protocol_version = SCSI_REV_2;
2268 cts->transport = XPORT_SPI;
2269 cts->transport_version = 2;
2271 spi->sync_period = sync_period;
2272 spi->valid |= CTS_SPI_VALID_SYNC_RATE;
2273 spi->sync_offset = sync_offset;
2274 spi->valid |= CTS_SPI_VALID_SYNC_OFFSET;
2276 spi->valid |= CTS_SPI_VALID_BUS_WIDTH;
2277 spi->bus_width = bus_width;
2279 if (cts->ccb_h.target_lun != CAM_LUN_WILDCARD) {
2280 scsi->valid = CTS_SCSI_VALID_TQ;
2281 spi->valid |= CTS_SPI_VALID_DISC;
2285 xpt_async(AC_TRANSFER_NEG, cts->ccb_h.path, cts);
2289 btmapmboxes(void *arg, bus_dma_segment_t *segs, int nseg, int error)
2291 struct bt_softc* bt;
2293 bt = (struct bt_softc*)arg;
2294 bt->mailbox_physbase = segs->ds_addr;
2298 btmapccbs(void *arg, bus_dma_segment_t *segs, int nseg, int error)
2300 struct bt_softc* bt;
2302 bt = (struct bt_softc*)arg;
2303 bt->bt_ccb_physbase = segs->ds_addr;
2307 btmapsgs(void *arg, bus_dma_segment_t *segs, int nseg, int error)
2310 struct bt_softc* bt;
2312 bt = (struct bt_softc*)arg;
2313 SLIST_FIRST(&bt->sg_maps)->sg_physaddr = segs->ds_addr;
2317 btpoll(struct cam_sim *sim)
2319 bt_intr(cam_sim_softc(sim));
2323 bttimeout(void *arg)
2325 struct bt_ccb *bccb;
2327 struct bt_softc *bt;
2330 bccb = (struct bt_ccb *)arg;
2332 bt = (struct bt_softc *)ccb->ccb_h.ccb_bt_ptr;
2333 xpt_print_path(ccb->ccb_h.path);
2334 printf("CCB %p - timed out\n", (void *)bccb);
2338 if ((bccb->flags & BCCB_ACTIVE) == 0) {
2339 xpt_print_path(ccb->ccb_h.path);
2340 printf("CCB %p - timed out CCB already completed\n",
2347 * In order to simplify the recovery process, we ask the XPT
2348 * layer to halt the queue of new transactions and we traverse
2349 * the list of pending CCBs and remove their timeouts. This
2350 * means that the driver attempts to clear only one error
2351 * condition at a time. In general, timeouts that occur
2352 * close together are related anyway, so there is no benefit
2353 * in attempting to handle errors in parrallel. Timeouts will
2354 * be reinstated when the recovery process ends.
2356 if ((bccb->flags & BCCB_DEVICE_RESET) == 0) {
2357 struct ccb_hdr *ccb_h;
2359 if ((bccb->flags & BCCB_RELEASE_SIMQ) == 0) {
2360 xpt_freeze_simq(bt->sim, /*count*/1);
2361 bccb->flags |= BCCB_RELEASE_SIMQ;
2364 ccb_h = LIST_FIRST(&bt->pending_ccbs);
2365 while (ccb_h != NULL) {
2366 struct bt_ccb *pending_bccb;
2368 pending_bccb = (struct bt_ccb *)ccb_h->ccb_bccb_ptr;
2369 untimeout(bttimeout, pending_bccb, ccb_h->timeout_ch);
2370 ccb_h = LIST_NEXT(ccb_h, sim_links.le);
2374 if ((bccb->flags & BCCB_DEVICE_RESET) != 0
2375 || bt->cur_outbox->action_code != BMBO_FREE
2376 || ((bccb->hccb.tag_enable == TRUE)
2377 && (bt->firmware_ver[0] < '5'))) {
2379 * Try a full host adapter/SCSI bus reset.
2380 * We do this only if we have already attempted
2381 * to clear the condition with a BDR, or we cannot
2382 * attempt a BDR for lack of mailbox resources
2383 * or because of faulty firmware. It turns out
2384 * that firmware versions prior to 5.xx treat BDRs
2385 * as untagged commands that cannot be sent until
2386 * all outstanding tagged commands have been processed.
2387 * This makes it somewhat difficult to use a BDR to
2388 * clear up a problem with an uncompleted tagged command.
2390 ccb->ccb_h.status = CAM_CMD_TIMEOUT;
2391 btreset(bt, /*hardreset*/TRUE);
2392 printf("%s: No longer in timeout\n", bt_name(bt));
2395 * Send a Bus Device Reset message:
2396 * The target that is holding up the bus may not
2397 * be the same as the one that triggered this timeout
2398 * (different commands have different timeout lengths),
2399 * but we have no way of determining this from our
2400 * timeout handler. Our strategy here is to queue a
2401 * BDR message to the target of the timed out command.
2402 * If this fails, we'll get another timeout 2 seconds
2403 * later which will attempt a bus reset.
2405 bccb->flags |= BCCB_DEVICE_RESET;
2406 ccb->ccb_h.timeout_ch =
2407 timeout(bttimeout, (caddr_t)bccb, 2 * hz);
2409 bt->recovery_bccb->hccb.opcode = INITIATOR_BUS_DEV_RESET;
2411 /* No Data Transfer */
2412 bt->recovery_bccb->hccb.datain = TRUE;
2413 bt->recovery_bccb->hccb.dataout = TRUE;
2414 bt->recovery_bccb->hccb.btstat = 0;
2415 bt->recovery_bccb->hccb.sdstat = 0;
2416 bt->recovery_bccb->hccb.target_id = ccb->ccb_h.target_id;
2418 /* Tell the adapter about this command */
2419 bt->cur_outbox->ccb_addr = btccbvtop(bt, bt->recovery_bccb);
2420 bt->cur_outbox->action_code = BMBO_START;
2421 bt_outb(bt, COMMAND_REG, BOP_START_MBOX);
2428 MODULE_VERSION(bt, 1);
2429 MODULE_DEPEND(bt, cam, 1, 1, 1);