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>
47 #include <sys/systm.h>
48 #include <sys/malloc.h>
49 #include <sys/kernel.h>
51 #include <sys/module.h>
52 #include <sys/mutex.h>
53 #include <sys/sysctl.h>
56 #include <machine/bus.h>
60 #include <cam/cam_ccb.h>
61 #include <cam/cam_sim.h>
62 #include <cam/cam_xpt_sim.h>
63 #include <cam/cam_debug.h>
65 #include <cam/scsi/scsi_message.h>
70 #include <dev/buslogic/btreg.h>
72 /* MailBox Management functions */
73 static __inline void btnextinbox(struct bt_softc *bt);
74 static __inline void btnextoutbox(struct bt_softc *bt);
77 btnextinbox(struct bt_softc *bt)
79 if (bt->cur_inbox == bt->last_inbox)
80 bt->cur_inbox = bt->in_boxes;
86 btnextoutbox(struct bt_softc *bt)
88 if (bt->cur_outbox == bt->last_outbox)
89 bt->cur_outbox = bt->out_boxes;
94 /* CCB Mangement functions */
95 static __inline u_int32_t btccbvtop(struct bt_softc *bt,
97 static __inline struct bt_ccb* btccbptov(struct bt_softc *bt,
99 static __inline u_int32_t btsensepaddr(struct bt_softc *bt,
100 struct bt_ccb *bccb);
101 static __inline struct scsi_sense_data* btsensevaddr(struct bt_softc *bt,
102 struct bt_ccb *bccb);
104 static __inline u_int32_t
105 btccbvtop(struct bt_softc *bt, struct bt_ccb *bccb)
107 return (bt->bt_ccb_physbase
108 + (u_int32_t)((caddr_t)bccb - (caddr_t)bt->bt_ccb_array));
111 static __inline struct bt_ccb *
112 btccbptov(struct bt_softc *bt, u_int32_t ccb_addr)
114 return (bt->bt_ccb_array +
115 ((struct bt_ccb*)(uintptr_t)ccb_addr - (struct bt_ccb*)(uintptr_t)bt->bt_ccb_physbase));
118 static __inline u_int32_t
119 btsensepaddr(struct bt_softc *bt, struct bt_ccb *bccb)
123 index = (u_int)(bccb - bt->bt_ccb_array);
124 return (bt->sense_buffers_physbase
125 + (index * sizeof(struct scsi_sense_data)));
128 static __inline struct scsi_sense_data *
129 btsensevaddr(struct bt_softc *bt, struct bt_ccb *bccb)
133 index = (u_int)(bccb - bt->bt_ccb_array);
134 return (bt->sense_buffers + index);
137 static __inline struct bt_ccb* btgetccb(struct bt_softc *bt);
138 static __inline void btfreeccb(struct bt_softc *bt,
139 struct bt_ccb *bccb);
140 static void btallocccbs(struct bt_softc *bt);
141 static bus_dmamap_callback_t btexecuteccb;
142 static void btdone(struct bt_softc *bt, struct bt_ccb *bccb,
143 bt_mbi_comp_code_t comp_code);
144 static void bt_intr_locked(struct bt_softc *bt);
146 /* Host adapter command functions */
147 static int btreset(struct bt_softc* bt, int hard_reset);
149 /* Initialization functions */
150 static int btinitmboxes(struct bt_softc *bt);
151 static bus_dmamap_callback_t btmapmboxes;
152 static bus_dmamap_callback_t btmapccbs;
153 static bus_dmamap_callback_t btmapsgs;
155 /* Transfer Negotiation Functions */
156 static void btfetchtransinfo(struct bt_softc *bt,
157 struct ccb_trans_settings *cts);
159 /* CAM SIM entry points */
160 #define ccb_bccb_ptr spriv_ptr0
161 #define ccb_bt_ptr spriv_ptr1
162 static void btaction(struct cam_sim *sim, union ccb *ccb);
163 static void btpoll(struct cam_sim *sim);
165 /* Our timeout handler */
166 static void bttimeout(void *arg);
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);
212 mtx_init(&bt->lock, "bt", NULL, MTX_DEF);
216 bt_free_softc(device_t dev)
218 struct bt_softc *bt = device_get_softc(dev);
220 switch (bt->init_level) {
223 bus_dmamap_unload(bt->sense_dmat, bt->sense_dmamap);
225 bus_dmamem_free(bt->sense_dmat, bt->sense_buffers,
228 bus_dma_tag_destroy(bt->sense_dmat);
231 struct sg_map_node *sg_map;
233 while ((sg_map = SLIST_FIRST(&bt->sg_maps))!= NULL) {
234 SLIST_REMOVE_HEAD(&bt->sg_maps, links);
235 bus_dmamap_unload(bt->sg_dmat,
237 bus_dmamem_free(bt->sg_dmat, sg_map->sg_vaddr,
239 free(sg_map, M_DEVBUF);
241 bus_dma_tag_destroy(bt->sg_dmat);
244 bus_dmamap_unload(bt->ccb_dmat, bt->ccb_dmamap);
247 bus_dmamem_free(bt->ccb_dmat, bt->bt_ccb_array,
249 bus_dmamap_destroy(bt->ccb_dmat, bt->ccb_dmamap);
252 bus_dma_tag_destroy(bt->ccb_dmat);
255 bus_dmamap_unload(bt->mailbox_dmat, bt->mailbox_dmamap);
258 bus_dmamem_free(bt->mailbox_dmat, bt->in_boxes,
260 bus_dmamap_destroy(bt->mailbox_dmat, bt->mailbox_dmamap);
263 bus_dma_tag_destroy(bt->buffer_dmat);
266 bus_dma_tag_destroy(bt->mailbox_dmat);
271 mtx_destroy(&bt->lock);
275 bt_port_probe(device_t dev, struct bt_probe_info *info)
277 struct bt_softc *bt = device_get_softc(dev);
278 config_data_t config_data;
281 /* See if there is really a card present */
282 if (bt_probe(dev) || bt_fetch_adapter_info(dev))
286 * Determine our IRQ, and DMA settings and
287 * 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);
293 mtx_unlock(&bt->lock);
295 printf("bt_port_probe: Could not determine IRQ or DMA "
296 "settings for adapter.\n");
300 if (bt->model[0] == '5') {
301 /* DMA settings only make sense for ISA cards */
302 switch (config_data.dma_chan) {
313 printf("bt_port_probe: Invalid DMA setting "
314 "detected for adapter.\n");
318 /* VL/EISA/PCI DMA */
321 switch (config_data.irq) {
328 info->irq = ffs(config_data.irq) + 8;
331 printf("bt_port_probe: Invalid IRQ setting %x"
332 "detected for adapter.\n", config_data.irq);
339 * Probe the adapter and verify that the card is a BusLogic.
342 bt_probe(device_t dev)
344 struct bt_softc *bt = device_get_softc(dev);
345 esetup_info_data_t esetup_info;
353 * See if the three I/O ports look reasonable.
354 * Touch the minimal number of registers in the
357 status = bt_inb(bt, STATUS_REG);
359 || (status & (DIAG_ACTIVE|CMD_REG_BUSY|
360 STATUS_REG_RSVD|CMD_INVALID)) != 0) {
362 device_printf(dev, "Failed Status Reg Test - %x\n",
367 intstat = bt_inb(bt, INTSTAT_REG);
368 if ((intstat & INTSTAT_REG_RSVD) != 0) {
369 device_printf(dev, "Failed Intstat Reg Test\n");
373 geometry = bt_inb(bt, GEOMETRY_REG);
374 if (geometry == 0xFF) {
376 device_printf(dev, "Failed Geometry Reg Test\n");
381 * Looking good so far. Final test is to reset the
382 * adapter and attempt to fetch the extended setup
383 * information. This should filter out all 1542 cards.
386 if ((error = btreset(bt, /*hard_reset*/TRUE)) != 0) {
387 mtx_unlock(&bt->lock);
389 device_printf(dev, "Failed Reset\n");
393 param = sizeof(esetup_info);
394 error = bt_cmd(bt, BOP_INQUIRE_ESETUP_INFO, ¶m, /*parmlen*/1,
395 (u_int8_t*)&esetup_info, sizeof(esetup_info),
396 DEFAULT_CMD_TIMEOUT);
397 mtx_unlock(&bt->lock);
406 * Pull the boards setup information and record it in our softc.
409 bt_fetch_adapter_info(device_t dev)
411 struct bt_softc *bt = device_get_softc(dev);
412 board_id_data_t board_id;
413 esetup_info_data_t esetup_info;
414 config_data_t config_data;
416 u_int8_t length_param;
418 /* First record the firmware version */
420 error = bt_cmd(bt, BOP_INQUIRE_BOARD_ID, NULL, /*parmlen*/0,
421 (u_int8_t*)&board_id, sizeof(board_id),
422 DEFAULT_CMD_TIMEOUT);
424 mtx_unlock(&bt->lock);
425 device_printf(dev, "bt_fetch_adapter_info - Failed Get Board Info\n");
428 bt->firmware_ver[0] = board_id.firmware_rev_major;
429 bt->firmware_ver[1] = '.';
430 bt->firmware_ver[2] = board_id.firmware_rev_minor;
431 bt->firmware_ver[3] = '\0';
434 * Depending on the firmware major and minor version,
435 * we may be able to fetch additional minor version info.
437 if (bt->firmware_ver[0] > '0') {
439 error = bt_cmd(bt, BOP_INQUIRE_FW_VER_3DIG, NULL, /*parmlen*/0,
440 (u_int8_t*)&bt->firmware_ver[3], 1,
441 DEFAULT_CMD_TIMEOUT);
443 mtx_unlock(&bt->lock);
445 "bt_fetch_adapter_info - Failed Get "
446 "Firmware 3rd Digit\n");
449 if (bt->firmware_ver[3] == ' ')
450 bt->firmware_ver[3] = '\0';
451 bt->firmware_ver[4] = '\0';
454 if (strcmp(bt->firmware_ver, "3.3") >= 0) {
456 error = bt_cmd(bt, BOP_INQUIRE_FW_VER_4DIG, NULL, /*parmlen*/0,
457 (u_int8_t*)&bt->firmware_ver[4], 1,
458 DEFAULT_CMD_TIMEOUT);
460 mtx_unlock(&bt->lock);
462 "bt_fetch_adapter_info - Failed Get "
463 "Firmware 4th Digit\n");
466 if (bt->firmware_ver[4] == ' ')
467 bt->firmware_ver[4] = '\0';
468 bt->firmware_ver[5] = '\0';
472 * Some boards do not handle the "recently documented"
473 * Inquire Board Model Number command correctly or do not give
474 * exact information. Use the Firmware and Extended Setup
475 * information in these cases to come up with the right answer.
476 * The major firmware revision number indicates:
478 * 5.xx BusLogic "W" Series Host Adapters:
480 * 4.xx BusLogic "C" Series Host Adapters:
481 * BT-946C/956C/956CD/747C/757C/757CD/445C/545C/540CF
482 * 3.xx BusLogic "S" Series Host Adapters:
483 * BT-747S/747D/757S/757D/445S/545S/542D
484 * BT-542B/742A (revision H)
485 * 2.xx BusLogic "A" Series Host Adapters:
486 * BT-542B/742A (revision G and below)
487 * 0.xx AMI FastDisk VLB/EISA BusLogic Clone Host Adapter
489 length_param = sizeof(esetup_info);
490 error = bt_cmd(bt, BOP_INQUIRE_ESETUP_INFO, &length_param, /*parmlen*/1,
491 (u_int8_t*)&esetup_info, sizeof(esetup_info),
492 DEFAULT_CMD_TIMEOUT);
494 mtx_unlock(&bt->lock);
498 bt->bios_addr = esetup_info.bios_addr << 12;
500 bt->mailbox_addrlimit = BUS_SPACE_MAXADDR;
501 if (esetup_info.bus_type == 'A'
502 && bt->firmware_ver[0] == '2') {
503 snprintf(bt->model, sizeof(bt->model), "542B");
504 } else if (esetup_info.bus_type == 'E'
505 && bt->firmware_ver[0] == '2') {
508 * The 742A seems to object if its mailboxes are
509 * allocated above the 16MB mark.
511 bt->mailbox_addrlimit = BUS_SPACE_MAXADDR_24BIT;
512 snprintf(bt->model, sizeof(bt->model), "742A");
513 } else if (esetup_info.bus_type == 'E'
514 && bt->firmware_ver[0] == '0') {
515 /* AMI FastDisk EISA Series 441 0.x */
516 snprintf(bt->model, sizeof(bt->model), "747A");
518 ha_model_data_t model_data;
521 length_param = sizeof(model_data);
522 error = bt_cmd(bt, BOP_INQUIRE_MODEL, &length_param, 1,
523 (u_int8_t*)&model_data, sizeof(model_data),
524 DEFAULT_CMD_TIMEOUT);
526 mtx_unlock(&bt->lock);
528 "bt_fetch_adapter_info - Failed Inquire "
532 for (i = 0; i < sizeof(model_data.ascii_model); i++) {
533 bt->model[i] = model_data.ascii_model[i];
534 if (bt->model[i] == ' ')
540 bt->level_trigger_ints = esetup_info.level_trigger_ints ? 1 : 0;
542 /* SG element limits */
543 bt->max_sg = esetup_info.max_sg;
545 /* Set feature flags */
546 bt->wide_bus = esetup_info.wide_bus;
547 bt->diff_bus = esetup_info.diff_bus;
548 bt->ultra_scsi = esetup_info.ultra_scsi;
550 if ((bt->firmware_ver[0] == '5')
551 || (bt->firmware_ver[0] == '4' && bt->wide_bus))
552 bt->extended_lun = TRUE;
554 bt->strict_rr = (strcmp(bt->firmware_ver, "3.31") >= 0);
557 ((bt_inb(bt, GEOMETRY_REG) & EXTENDED_TRANSLATION) != 0);
560 * Determine max CCB count and whether tagged queuing is
561 * available based on controller type. Tagged queuing
562 * only works on 'W' series adapters, 'C' series adapters
563 * with firmware of rev 4.42 and higher, and 'S' series
564 * adapters with firmware of rev 3.35 and higher. The
565 * maximum CCB counts are as follows:
567 * 192 BT-948/958/958D
568 * 100 BT-946C/956C/956CD/747C/757C/757CD/445C
570 * 30 BT-747S/747D/757S/757D/445S/545S/542D/542B/742A
572 if (bt->firmware_ver[0] == '5') {
574 bt->tag_capable = TRUE;
575 } else if (bt->firmware_ver[0] == '4') {
576 if (bt->model[0] == '5')
580 bt->tag_capable = (strcmp(bt->firmware_ver, "4.22") >= 0);
583 if (bt->firmware_ver[0] == '3'
584 && (strcmp(bt->firmware_ver, "3.35") >= 0))
585 bt->tag_capable = TRUE;
587 bt->tag_capable = FALSE;
590 if (bt->tag_capable != FALSE)
591 bt->tags_permitted = ALL_TARGETS;
593 /* Determine Sync/Wide/Disc settings */
594 if (bt->firmware_ver[0] >= '4') {
595 auto_scsi_data_t auto_scsi_data;
596 fetch_lram_params_t fetch_lram_params;
600 * These settings are stored in the
601 * AutoSCSI data in LRAM of 'W' and 'C'
604 fetch_lram_params.offset = AUTO_SCSI_BYTE_OFFSET;
605 fetch_lram_params.response_len = sizeof(auto_scsi_data);
606 error = bt_cmd(bt, BOP_FETCH_LRAM,
607 (u_int8_t*)&fetch_lram_params,
608 sizeof(fetch_lram_params),
609 (u_int8_t*)&auto_scsi_data,
610 sizeof(auto_scsi_data), DEFAULT_CMD_TIMEOUT);
613 mtx_unlock(&bt->lock);
615 "bt_fetch_adapter_info - Failed "
616 "Get Auto SCSI Info\n");
620 bt->disc_permitted = auto_scsi_data.low_disc_permitted
621 | (auto_scsi_data.high_disc_permitted << 8);
622 bt->sync_permitted = auto_scsi_data.low_sync_permitted
623 | (auto_scsi_data.high_sync_permitted << 8);
624 bt->fast_permitted = auto_scsi_data.low_fast_permitted
625 | (auto_scsi_data.high_fast_permitted << 8);
626 bt->ultra_permitted = auto_scsi_data.low_ultra_permitted
627 | (auto_scsi_data.high_ultra_permitted << 8);
628 bt->wide_permitted = auto_scsi_data.low_wide_permitted
629 | (auto_scsi_data.high_wide_permitted << 8);
631 if (bt->ultra_scsi == FALSE)
632 bt->ultra_permitted = 0;
634 if (bt->wide_bus == FALSE)
635 bt->wide_permitted = 0;
638 * 'S' and 'A' series have this information in the setup
639 * information structure.
641 setup_data_t setup_info;
643 length_param = sizeof(setup_info);
644 error = bt_cmd(bt, BOP_INQUIRE_SETUP_INFO, &length_param,
645 /*paramlen*/1, (u_int8_t*)&setup_info,
646 sizeof(setup_info), DEFAULT_CMD_TIMEOUT);
649 mtx_unlock(&bt->lock);
651 "bt_fetch_adapter_info - Failed "
656 if (setup_info.initiate_sync != 0) {
657 bt->sync_permitted = ALL_TARGETS;
659 if (bt->model[0] == '7') {
660 if (esetup_info.sync_neg10MB != 0)
661 bt->fast_permitted = ALL_TARGETS;
662 if (strcmp(bt->model, "757") == 0)
663 bt->wide_permitted = ALL_TARGETS;
666 bt->disc_permitted = ALL_TARGETS;
669 /* We need as many mailboxes as we can have ccbs */
670 bt->num_boxes = bt->max_ccbs;
672 /* Determine our SCSI ID */
674 error = bt_cmd(bt, BOP_INQUIRE_CONFIG, NULL, /*parmlen*/0,
675 (u_int8_t*)&config_data, sizeof(config_data),
676 DEFAULT_CMD_TIMEOUT);
677 mtx_unlock(&bt->lock);
680 "bt_fetch_adapter_info - Failed Get Config\n");
683 bt->scsi_id = config_data.scsi_id;
689 * Start the board, ready for normal operation
692 bt_init(device_t dev)
694 struct bt_softc *bt = device_get_softc(dev);
696 /* Announce the Adapter */
697 device_printf(dev, "BT-%s FW Rev. %s ", bt->model, bt->firmware_ver);
699 if (bt->ultra_scsi != 0)
702 if (bt->wide_bus != 0)
707 if (bt->diff_bus != 0)
710 printf("SCSI Host Adapter, SCSI ID %d, %d CCBs\n", bt->scsi_id,
714 * Create our DMA tags. These tags define the kinds of device
715 * accessible memory allocations and memory mappings we will
716 * need to perform during normal operation.
718 * Unless we need to further restrict the allocation, we rely
719 * on the restrictions of the parent dmat, hence the common
720 * use of MAXADDR and MAXSIZE.
723 /* DMA tag for mapping buffers into device visible space. */
724 if (bus_dma_tag_create( /* parent */ bt->parent_dmat,
727 /* lowaddr */ BUS_SPACE_MAXADDR,
728 /* highaddr */ BUS_SPACE_MAXADDR,
730 /* filterarg */ NULL,
731 /* maxsize */ DFLTPHYS,
732 /* nsegments */ BT_NSEG,
733 /* maxsegsz */ BUS_SPACE_MAXSIZE_32BIT,
734 /* flags */ BUS_DMA_ALLOCNOW,
735 /* lockfunc */ busdma_lock_mutex,
736 /* lockarg */ &bt->lock,
737 &bt->buffer_dmat) != 0) {
742 /* DMA tag for our mailboxes */
743 if (bus_dma_tag_create( /* parent */ bt->parent_dmat,
746 /* lowaddr */ bt->mailbox_addrlimit,
747 /* highaddr */ BUS_SPACE_MAXADDR,
749 /* filterarg */ NULL,
750 /* maxsize */ bt->num_boxes *
751 (sizeof(bt_mbox_in_t) +
752 sizeof(bt_mbox_out_t)),
754 /* maxsegsz */ BUS_SPACE_MAXSIZE_32BIT,
758 &bt->mailbox_dmat) != 0) {
764 /* Allocation for our mailboxes */
765 if (bus_dmamem_alloc(bt->mailbox_dmat, (void **)&bt->out_boxes,
766 BUS_DMA_NOWAIT, &bt->mailbox_dmamap) != 0) {
772 /* And permanently map them */
773 bus_dmamap_load(bt->mailbox_dmat, bt->mailbox_dmamap,
775 bt->num_boxes * (sizeof(bt_mbox_in_t)
776 + sizeof(bt_mbox_out_t)),
777 btmapmboxes, bt, /*flags*/0);
781 bt->in_boxes = (bt_mbox_in_t *)&bt->out_boxes[bt->num_boxes];
785 mtx_unlock(&bt->lock);
787 /* DMA tag for our ccb structures */
788 if (bus_dma_tag_create( /* parent */ bt->parent_dmat,
791 /* lowaddr */ BUS_SPACE_MAXADDR,
792 /* highaddr */ BUS_SPACE_MAXADDR,
794 /* filterarg */ NULL,
795 /* maxsize */ bt->max_ccbs *
796 sizeof(struct bt_ccb),
798 /* maxsegsz */ BUS_SPACE_MAXSIZE_32BIT,
802 &bt->ccb_dmat) != 0) {
808 /* Allocation for our ccbs */
809 if (bus_dmamem_alloc(bt->ccb_dmat, (void **)&bt->bt_ccb_array,
810 BUS_DMA_NOWAIT, &bt->ccb_dmamap) != 0) {
816 /* And permanently map them */
817 bus_dmamap_load(bt->ccb_dmat, bt->ccb_dmamap,
819 bt->max_ccbs * sizeof(struct bt_ccb),
820 btmapccbs, bt, /*flags*/0);
824 /* DMA tag for our S/G structures. We allocate in page sized chunks */
825 if (bus_dma_tag_create( /* parent */ bt->parent_dmat,
828 /* lowaddr */ BUS_SPACE_MAXADDR,
829 /* highaddr */ BUS_SPACE_MAXADDR,
831 /* filterarg */ NULL,
832 /* maxsize */ PAGE_SIZE,
834 /* maxsegsz */ BUS_SPACE_MAXSIZE_32BIT,
838 &bt->sg_dmat) != 0) {
844 /* Perform initial CCB allocation */
845 bzero(bt->bt_ccb_array, bt->max_ccbs * sizeof(struct bt_ccb));
848 if (bt->num_ccbs == 0) {
850 "bt_init - Unable to allocate initial ccbs\n");
855 * Note that we are going and return (to attach)
865 bt_attach(device_t dev)
867 struct bt_softc *bt = device_get_softc(dev);
868 int tagged_dev_openings;
869 struct cam_devq *devq;
873 * We reserve 1 ccb for error recovery, so don't
874 * tell the XPT about it.
876 if (bt->tag_capable != 0)
877 tagged_dev_openings = bt->max_ccbs - 1;
879 tagged_dev_openings = 0;
882 * Create the device queue for our SIM.
884 devq = cam_simq_alloc(bt->max_ccbs - 1);
889 * Construct our SIM entry
891 bt->sim = cam_sim_alloc(btaction, btpoll, "bt", bt,
892 device_get_unit(bt->dev), &bt->lock, 2, tagged_dev_openings, devq);
893 if (bt->sim == NULL) {
899 if (xpt_bus_register(bt->sim, dev, 0) != CAM_SUCCESS) {
900 cam_sim_free(bt->sim, /*free_devq*/TRUE);
901 mtx_unlock(&bt->lock);
905 if (xpt_create_path(&bt->path, /*periph*/NULL,
906 cam_sim_path(bt->sim), CAM_TARGET_WILDCARD,
907 CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
908 xpt_bus_deregister(cam_sim_path(bt->sim));
909 cam_sim_free(bt->sim, /*free_devq*/TRUE);
910 mtx_unlock(&bt->lock);
913 mtx_unlock(&bt->lock);
918 error = bus_setup_intr(dev, bt->irq, INTR_TYPE_CAM | INTR_ENTROPY |
919 INTR_MPSAFE, NULL, bt_intr, bt, &bt->ih);
921 device_printf(dev, "bus_setup_intr() failed: %d\n", error);
929 bt_check_probed_iop(u_int ioport)
933 for (i = 0; i < BT_NUM_ISAPORTS; i++) {
934 if (bt_isa_ports[i].addr == ioport) {
935 if (bt_isa_ports[i].probed != 0)
946 bt_mark_probed_bio(isa_compat_io_t port)
948 if (port < BIO_DISABLED)
949 bt_mark_probed_iop(bt_board_ports[port]);
953 bt_mark_probed_iop(u_int ioport)
957 for (i = 0; i < BT_NUM_ISAPORTS; i++) {
958 if (ioport == bt_isa_ports[i].addr) {
959 bt_isa_ports[i].probed = 1;
966 bt_find_probe_range(int ioport, int *port_index, int *max_port_index)
971 for (i = 0;i < BT_NUM_ISAPORTS; i++)
972 if (ioport <= bt_isa_ports[i].addr)
974 if ((i >= BT_NUM_ISAPORTS)
975 || (ioport != bt_isa_ports[i].addr)) {
977 "bt_find_probe_range: Invalid baseport of 0x%x specified.\n"
978 "bt_find_probe_range: Nearest valid baseport is 0x%x.\n"
979 "bt_find_probe_range: Failing probe.\n",
981 (i < BT_NUM_ISAPORTS)
982 ? bt_isa_ports[i].addr
983 : bt_isa_ports[BT_NUM_ISAPORTS - 1].addr);
984 *port_index = *max_port_index = -1;
987 *port_index = *max_port_index = bt_isa_ports[i].bio;
990 *max_port_index = BT_NUM_ISAPORTS - 1;
995 bt_iop_from_bio(isa_compat_io_t bio_index)
997 if (bio_index < BT_NUM_ISAPORTS)
998 return (bt_board_ports[bio_index]);
1004 btallocccbs(struct bt_softc *bt)
1006 struct bt_ccb *next_ccb;
1007 struct sg_map_node *sg_map;
1008 bus_addr_t physaddr;
1013 if (bt->num_ccbs >= bt->max_ccbs)
1014 /* Can't allocate any more */
1017 next_ccb = &bt->bt_ccb_array[bt->num_ccbs];
1019 sg_map = malloc(sizeof(*sg_map), M_DEVBUF, M_NOWAIT);
1024 /* Allocate S/G space for the next batch of CCBS */
1025 if (bus_dmamem_alloc(bt->sg_dmat, (void **)&sg_map->sg_vaddr,
1026 BUS_DMA_NOWAIT, &sg_map->sg_dmamap) != 0) {
1027 free(sg_map, M_DEVBUF);
1031 SLIST_INSERT_HEAD(&bt->sg_maps, sg_map, links);
1033 bus_dmamap_load(bt->sg_dmat, sg_map->sg_dmamap, sg_map->sg_vaddr,
1034 PAGE_SIZE, btmapsgs, bt, /*flags*/0);
1036 segs = sg_map->sg_vaddr;
1037 physaddr = sg_map->sg_physaddr;
1039 newcount = (PAGE_SIZE / (BT_NSEG * sizeof(bt_sg_t)));
1040 for (i = 0; bt->num_ccbs < bt->max_ccbs && i < newcount; i++) {
1043 next_ccb->sg_list = segs;
1044 next_ccb->sg_list_phys = physaddr;
1045 next_ccb->flags = BCCB_FREE;
1046 callout_init_mtx(&next_ccb->timer, &bt->lock, 0);
1047 error = bus_dmamap_create(bt->buffer_dmat, /*flags*/0,
1051 SLIST_INSERT_HEAD(&bt->free_bt_ccbs, next_ccb, links);
1053 physaddr += (BT_NSEG * sizeof(bt_sg_t));
1058 /* Reserve a CCB for error recovery */
1059 if (bt->recovery_bccb == NULL) {
1060 bt->recovery_bccb = SLIST_FIRST(&bt->free_bt_ccbs);
1061 SLIST_REMOVE_HEAD(&bt->free_bt_ccbs, links);
1064 if (SLIST_FIRST(&bt->free_bt_ccbs) != NULL)
1068 device_printf(bt->dev, "Can't malloc BCCBs\n");
1071 static __inline void
1072 btfreeccb(struct bt_softc *bt, struct bt_ccb *bccb)
1076 mtx_assert(&bt->lock, MA_OWNED);
1077 if ((bccb->flags & BCCB_ACTIVE) != 0)
1078 LIST_REMOVE(&bccb->ccb->ccb_h, sim_links.le);
1079 if (bt->resource_shortage != 0
1080 && (bccb->ccb->ccb_h.status & CAM_RELEASE_SIMQ) == 0) {
1081 bccb->ccb->ccb_h.status |= CAM_RELEASE_SIMQ;
1082 bt->resource_shortage = FALSE;
1084 bccb->flags = BCCB_FREE;
1085 SLIST_INSERT_HEAD(&bt->free_bt_ccbs, bccb, links);
1089 static __inline struct bt_ccb*
1090 btgetccb(struct bt_softc *bt)
1092 struct bt_ccb* bccb;
1095 mtx_assert(&bt->lock, MA_OWNED);
1096 if ((bccb = SLIST_FIRST(&bt->free_bt_ccbs)) != NULL) {
1097 SLIST_REMOVE_HEAD(&bt->free_bt_ccbs, links);
1101 bccb = SLIST_FIRST(&bt->free_bt_ccbs);
1103 SLIST_REMOVE_HEAD(&bt->free_bt_ccbs, links);
1112 btaction(struct cam_sim *sim, union ccb *ccb)
1114 struct bt_softc *bt;
1116 CAM_DEBUG(ccb->ccb_h.path, CAM_DEBUG_TRACE, ("btaction\n"));
1118 bt = (struct bt_softc *)cam_sim_softc(sim);
1119 mtx_assert(&bt->lock, MA_OWNED);
1121 switch (ccb->ccb_h.func_code) {
1122 /* Common cases first */
1123 case XPT_SCSI_IO: /* Execute the requested I/O operation */
1124 case XPT_RESET_DEV: /* Bus Device Reset the specified SCSI device */
1126 struct bt_ccb *bccb;
1127 struct bt_hccb *hccb;
1130 * get a bccb to use.
1132 if ((bccb = btgetccb(bt)) == NULL) {
1134 bt->resource_shortage = TRUE;
1135 xpt_freeze_simq(bt->sim, /*count*/1);
1136 ccb->ccb_h.status = CAM_REQUEUE_REQ;
1144 * So we can find the BCCB when an abort is requested
1147 ccb->ccb_h.ccb_bccb_ptr = bccb;
1148 ccb->ccb_h.ccb_bt_ptr = bt;
1151 * Put all the arguments for the xfer in the bccb
1153 hccb->target_id = ccb->ccb_h.target_id;
1154 hccb->target_lun = ccb->ccb_h.target_lun;
1158 if (ccb->ccb_h.func_code == XPT_SCSI_IO) {
1159 struct ccb_scsiio *csio;
1160 struct ccb_hdr *ccbh;
1164 ccbh = &csio->ccb_h;
1165 hccb->opcode = INITIATOR_CCB_WRESID;
1166 hccb->datain = (ccb->ccb_h.flags & CAM_DIR_IN) ? 1 : 0;
1167 hccb->dataout =(ccb->ccb_h.flags & CAM_DIR_OUT) ? 1 : 0;
1168 hccb->cmd_len = csio->cdb_len;
1169 if (hccb->cmd_len > sizeof(hccb->scsi_cdb)) {
1170 ccb->ccb_h.status = CAM_REQ_INVALID;
1171 btfreeccb(bt, bccb);
1175 hccb->sense_len = csio->sense_len;
1176 if ((ccbh->flags & CAM_TAG_ACTION_VALID) != 0
1177 && ccb->csio.tag_action != CAM_TAG_ACTION_NONE) {
1178 hccb->tag_enable = TRUE;
1179 hccb->tag_type = (ccb->csio.tag_action & 0x3);
1181 hccb->tag_enable = FALSE;
1184 if ((ccbh->flags & CAM_CDB_POINTER) != 0) {
1185 if ((ccbh->flags & CAM_CDB_PHYS) == 0) {
1186 bcopy(csio->cdb_io.cdb_ptr,
1187 hccb->scsi_cdb, hccb->cmd_len);
1189 /* I guess I could map it in... */
1190 ccbh->status = CAM_REQ_INVALID;
1191 btfreeccb(bt, bccb);
1196 bcopy(csio->cdb_io.cdb_bytes,
1197 hccb->scsi_cdb, hccb->cmd_len);
1199 /* If need be, bounce our sense buffer */
1200 if (bt->sense_buffers != NULL) {
1201 hccb->sense_addr = btsensepaddr(bt, bccb);
1203 hccb->sense_addr = vtophys(&csio->sense_data);
1206 * If we have any data to send with this command,
1207 * map it into bus space.
1209 error = bus_dmamap_load_ccb(
1216 if (error == EINPROGRESS) {
1218 * So as to maintain ordering, freeze the
1219 * controller queue until our mapping is
1222 xpt_freeze_simq(bt->sim, 1);
1223 csio->ccb_h.status |= CAM_RELEASE_SIMQ;
1226 hccb->opcode = INITIATOR_BUS_DEV_RESET;
1227 /* No data transfer */
1228 hccb->datain = TRUE;
1229 hccb->dataout = TRUE;
1231 hccb->sense_len = 0;
1232 hccb->tag_enable = FALSE;
1234 btexecuteccb(bccb, NULL, 0, 0);
1238 case XPT_EN_LUN: /* Enable LUN as a target */
1239 case XPT_TARGET_IO: /* Execute target I/O request */
1240 case XPT_ACCEPT_TARGET_IO: /* Accept Host Target Mode CDB */
1241 case XPT_CONT_TARGET_IO: /* Continue Host Target I/O Connection*/
1242 case XPT_ABORT: /* Abort the specified CCB */
1244 ccb->ccb_h.status = CAM_REQ_INVALID;
1247 case XPT_SET_TRAN_SETTINGS:
1250 ccb->ccb_h.status = CAM_PROVIDE_FAIL;
1254 case XPT_GET_TRAN_SETTINGS:
1255 /* Get default/user set transfer settings for the target */
1257 struct ccb_trans_settings *cts;
1261 target_mask = 0x01 << ccb->ccb_h.target_id;
1262 if (cts->type == CTS_TYPE_CURRENT_SETTINGS) {
1263 struct ccb_trans_settings_scsi *scsi =
1264 &cts->proto_specific.scsi;
1265 struct ccb_trans_settings_spi *spi =
1266 &cts->xport_specific.spi;
1267 cts->protocol = PROTO_SCSI;
1268 cts->protocol_version = SCSI_REV_2;
1269 cts->transport = XPORT_SPI;
1270 cts->transport_version = 2;
1272 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
1273 spi->flags &= ~CTS_SPI_FLAGS_DISC_ENB;
1275 if ((bt->disc_permitted & target_mask) != 0)
1276 spi->flags |= CTS_SPI_FLAGS_DISC_ENB;
1277 if ((bt->tags_permitted & target_mask) != 0)
1278 scsi->flags |= CTS_SCSI_FLAGS_TAG_ENB;
1280 if ((bt->ultra_permitted & target_mask) != 0)
1281 spi->sync_period = 12;
1282 else if ((bt->fast_permitted & target_mask) != 0)
1283 spi->sync_period = 25;
1284 else if ((bt->sync_permitted & target_mask) != 0)
1285 spi->sync_period = 50;
1287 spi->sync_period = 0;
1289 if (spi->sync_period != 0)
1290 spi->sync_offset = 15;
1292 spi->valid |= CTS_SPI_VALID_SYNC_RATE;
1293 spi->valid |= CTS_SPI_VALID_SYNC_OFFSET;
1295 spi->valid |= CTS_SPI_VALID_BUS_WIDTH;
1296 if ((bt->wide_permitted & target_mask) != 0)
1297 spi->bus_width = MSG_EXT_WDTR_BUS_16_BIT;
1299 spi->bus_width = MSG_EXT_WDTR_BUS_8_BIT;
1301 if (cts->ccb_h.target_lun != CAM_LUN_WILDCARD) {
1302 scsi->valid = CTS_SCSI_VALID_TQ;
1303 spi->valid |= CTS_SPI_VALID_DISC;
1307 btfetchtransinfo(bt, cts);
1310 ccb->ccb_h.status = CAM_REQ_CMP;
1314 case XPT_CALC_GEOMETRY:
1316 struct ccb_calc_geometry *ccg;
1318 u_int32_t secs_per_cylinder;
1321 size_mb = ccg->volume_size
1322 / ((1024L * 1024L) / ccg->block_size);
1324 if (size_mb >= 1024 && (bt->extended_trans != 0)) {
1325 if (size_mb >= 2048) {
1327 ccg->secs_per_track = 63;
1330 ccg->secs_per_track = 32;
1334 ccg->secs_per_track = 32;
1336 secs_per_cylinder = ccg->heads * ccg->secs_per_track;
1337 ccg->cylinders = ccg->volume_size / secs_per_cylinder;
1338 ccb->ccb_h.status = CAM_REQ_CMP;
1342 case XPT_RESET_BUS: /* Reset the specified SCSI bus */
1344 btreset(bt, /*hardreset*/TRUE);
1345 ccb->ccb_h.status = CAM_REQ_CMP;
1349 case XPT_TERM_IO: /* Terminate the I/O process */
1351 ccb->ccb_h.status = CAM_REQ_INVALID;
1354 case XPT_PATH_INQ: /* Path routing inquiry */
1356 struct ccb_pathinq *cpi = &ccb->cpi;
1358 cpi->version_num = 1; /* XXX??? */
1359 cpi->hba_inquiry = PI_SDTR_ABLE;
1360 if (bt->tag_capable != 0)
1361 cpi->hba_inquiry |= PI_TAG_ABLE;
1362 if (bt->wide_bus != 0)
1363 cpi->hba_inquiry |= PI_WIDE_16;
1364 cpi->target_sprt = 0;
1366 cpi->hba_eng_cnt = 0;
1367 cpi->max_target = bt->wide_bus ? 15 : 7;
1369 cpi->initiator_id = bt->scsi_id;
1370 cpi->bus_id = cam_sim_bus(sim);
1371 cpi->base_transfer_speed = 3300;
1372 strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
1373 strncpy(cpi->hba_vid, "BusLogic", HBA_IDLEN);
1374 strncpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN);
1375 cpi->unit_number = cam_sim_unit(sim);
1376 cpi->ccb_h.status = CAM_REQ_CMP;
1377 cpi->transport = XPORT_SPI;
1378 cpi->transport_version = 2;
1379 cpi->protocol = PROTO_SCSI;
1380 cpi->protocol_version = SCSI_REV_2;
1385 ccb->ccb_h.status = CAM_REQ_INVALID;
1392 btexecuteccb(void *arg, bus_dma_segment_t *dm_segs, int nseg, int error)
1394 struct bt_ccb *bccb;
1396 struct bt_softc *bt;
1398 bccb = (struct bt_ccb *)arg;
1400 bt = (struct bt_softc *)ccb->ccb_h.ccb_bt_ptr;
1404 device_printf(bt->dev,
1405 "Unexepected error 0x%x returned from "
1406 "bus_dmamap_load\n", error);
1407 if (ccb->ccb_h.status == CAM_REQ_INPROG) {
1408 xpt_freeze_devq(ccb->ccb_h.path, /*count*/1);
1409 ccb->ccb_h.status = CAM_REQ_TOO_BIG|CAM_DEV_QFRZN;
1411 btfreeccb(bt, bccb);
1418 bus_dma_segment_t *end_seg;
1419 bus_dmasync_op_t op;
1421 end_seg = dm_segs + nseg;
1423 /* Copy the segments into our SG list */
1425 while (dm_segs < end_seg) {
1426 sg->len = dm_segs->ds_len;
1427 sg->addr = dm_segs->ds_addr;
1433 bccb->hccb.opcode = INITIATOR_SG_CCB_WRESID;
1434 bccb->hccb.data_len = sizeof(bt_sg_t) * nseg;
1435 bccb->hccb.data_addr = bccb->sg_list_phys;
1437 bccb->hccb.data_len = bccb->sg_list->len;
1438 bccb->hccb.data_addr = bccb->sg_list->addr;
1441 if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN)
1442 op = BUS_DMASYNC_PREREAD;
1444 op = BUS_DMASYNC_PREWRITE;
1446 bus_dmamap_sync(bt->buffer_dmat, bccb->dmamap, op);
1449 bccb->hccb.opcode = INITIATOR_CCB;
1450 bccb->hccb.data_len = 0;
1451 bccb->hccb.data_addr = 0;
1455 * Last time we need to check if this CCB needs to
1458 if (ccb->ccb_h.status != CAM_REQ_INPROG) {
1460 bus_dmamap_unload(bt->buffer_dmat, bccb->dmamap);
1461 btfreeccb(bt, bccb);
1466 bccb->flags = BCCB_ACTIVE;
1467 ccb->ccb_h.status |= CAM_SIM_QUEUED;
1468 LIST_INSERT_HEAD(&bt->pending_ccbs, &ccb->ccb_h, sim_links.le);
1470 callout_reset_sbt(&bccb->timer, SBT_1MS * ccb->ccb_h.timeout, 0,
1471 bttimeout, bccb, 0);
1473 /* Tell the adapter about this command */
1474 bt->cur_outbox->ccb_addr = btccbvtop(bt, bccb);
1475 if (bt->cur_outbox->action_code != BMBO_FREE) {
1477 * We should never encounter a busy mailbox.
1478 * If we do, warn the user, and treat it as
1479 * a resource shortage. If the controller is
1480 * hung, one of the pending transactions will
1481 * timeout causing us to start recovery operations.
1483 device_printf(bt->dev,
1484 "Encountered busy mailbox with %d out of %d "
1485 "commands active!!!\n", bt->active_ccbs,
1487 callout_stop(&bccb->timer);
1489 bus_dmamap_unload(bt->buffer_dmat, bccb->dmamap);
1490 btfreeccb(bt, bccb);
1491 bt->resource_shortage = TRUE;
1492 xpt_freeze_simq(bt->sim, /*count*/1);
1493 ccb->ccb_h.status = CAM_REQUEUE_REQ;
1497 bt->cur_outbox->action_code = BMBO_START;
1498 bt_outb(bt, COMMAND_REG, BOP_START_MBOX);
1505 struct bt_softc *bt;
1508 mtx_lock(&bt->lock);
1510 mtx_unlock(&bt->lock);
1514 bt_intr_locked(struct bt_softc *bt)
1518 while (((intstat = bt_inb(bt, INTSTAT_REG)) & INTR_PENDING) != 0) {
1520 if ((intstat & CMD_COMPLETE) != 0) {
1521 bt->latched_status = bt_inb(bt, STATUS_REG);
1522 bt->command_cmp = TRUE;
1525 bt_outb(bt, CONTROL_REG, RESET_INTR);
1527 if ((intstat & IMB_LOADED) != 0) {
1528 while (bt->cur_inbox->comp_code != BMBI_FREE) {
1530 btccbptov(bt, bt->cur_inbox->ccb_addr),
1531 bt->cur_inbox->comp_code);
1532 bt->cur_inbox->comp_code = BMBI_FREE;
1537 if ((intstat & SCSI_BUS_RESET) != 0) {
1538 btreset(bt, /*hardreset*/FALSE);
1544 btdone(struct bt_softc *bt, struct bt_ccb *bccb, bt_mbi_comp_code_t comp_code)
1547 struct ccb_scsiio *csio;
1550 csio = &bccb->ccb->csio;
1552 if ((bccb->flags & BCCB_ACTIVE) == 0) {
1553 device_printf(bt->dev,
1554 "btdone - Attempt to free non-active BCCB %p\n",
1559 if ((ccb->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE) {
1560 bus_dmasync_op_t op;
1562 if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN)
1563 op = BUS_DMASYNC_POSTREAD;
1565 op = BUS_DMASYNC_POSTWRITE;
1566 bus_dmamap_sync(bt->buffer_dmat, bccb->dmamap, op);
1567 bus_dmamap_unload(bt->buffer_dmat, bccb->dmamap);
1570 if (bccb == bt->recovery_bccb) {
1572 * The recovery BCCB does not have a CCB associated
1573 * with it, so short circuit the normal error handling.
1574 * We now traverse our list of pending CCBs and process
1575 * any that were terminated by the recovery CCBs action.
1576 * We also reinstate timeouts for all remaining, pending,
1579 struct cam_path *path;
1580 struct ccb_hdr *ccb_h;
1583 /* Notify all clients that a BDR occured */
1584 error = xpt_create_path(&path, /*periph*/NULL,
1585 cam_sim_path(bt->sim),
1586 bccb->hccb.target_id,
1589 if (error == CAM_REQ_CMP) {
1590 xpt_async(AC_SENT_BDR, path, NULL);
1591 xpt_free_path(path);
1594 ccb_h = LIST_FIRST(&bt->pending_ccbs);
1595 while (ccb_h != NULL) {
1596 struct bt_ccb *pending_bccb;
1598 pending_bccb = (struct bt_ccb *)ccb_h->ccb_bccb_ptr;
1599 if (pending_bccb->hccb.target_id
1600 == bccb->hccb.target_id) {
1601 pending_bccb->hccb.btstat = BTSTAT_HA_BDR;
1602 ccb_h = LIST_NEXT(ccb_h, sim_links.le);
1603 btdone(bt, pending_bccb, BMBI_ERROR);
1605 callout_reset_sbt(&pending_bccb->timer,
1606 SBT_1MS * ccb_h->timeout, 0, bttimeout,
1608 ccb_h = LIST_NEXT(ccb_h, sim_links.le);
1611 device_printf(bt->dev, "No longer in timeout\n");
1615 callout_stop(&bccb->timer);
1617 switch (comp_code) {
1619 device_printf(bt->dev,
1620 "btdone - CCB completed with free status!\n");
1622 case BMBI_NOT_FOUND:
1623 device_printf(bt->dev,
1624 "btdone - CCB Abort failed to find CCB\n");
1629 printf("bt: ccb %p - error %x occured. "
1630 "btstat = %x, sdstat = %x\n",
1631 (void *)bccb, comp_code, bccb->hccb.btstat,
1634 /* An error occured */
1635 switch(bccb->hccb.btstat) {
1636 case BTSTAT_DATARUN_ERROR:
1637 if (bccb->hccb.data_len == 0) {
1639 * At least firmware 4.22, does this
1640 * for a QUEUE FULL condition.
1642 bccb->hccb.sdstat = SCSI_STATUS_QUEUE_FULL;
1643 } else if (bccb->hccb.data_len < 0) {
1644 csio->ccb_h.status = CAM_DATA_RUN_ERR;
1648 case BTSTAT_NOERROR:
1649 case BTSTAT_LINKED_CMD_COMPLETE:
1650 case BTSTAT_LINKED_CMD_FLAG_COMPLETE:
1651 case BTSTAT_DATAUNDERUN_ERROR:
1653 csio->scsi_status = bccb->hccb.sdstat;
1654 csio->ccb_h.status |= CAM_SCSI_STATUS_ERROR;
1655 switch(csio->scsi_status) {
1656 case SCSI_STATUS_CHECK_COND:
1657 case SCSI_STATUS_CMD_TERMINATED:
1658 csio->ccb_h.status |= CAM_AUTOSNS_VALID;
1659 /* Bounce sense back if necessary */
1660 if (bt->sense_buffers != NULL) {
1662 *btsensevaddr(bt, bccb);
1667 case SCSI_STATUS_OK:
1668 csio->ccb_h.status = CAM_REQ_CMP;
1671 csio->resid = bccb->hccb.data_len;
1673 case BTSTAT_SELTIMEOUT:
1674 csio->ccb_h.status = CAM_SEL_TIMEOUT;
1676 case BTSTAT_UNEXPECTED_BUSFREE:
1677 csio->ccb_h.status = CAM_UNEXP_BUSFREE;
1679 case BTSTAT_INVALID_PHASE:
1680 csio->ccb_h.status = CAM_SEQUENCE_FAIL;
1682 case BTSTAT_INVALID_ACTION_CODE:
1683 panic("%s: Inavlid Action code", bt_name(bt));
1685 case BTSTAT_INVALID_OPCODE:
1686 panic("%s: Inavlid CCB Opcode code", bt_name(bt));
1688 case BTSTAT_LINKED_CCB_LUN_MISMATCH:
1689 /* We don't even support linked commands... */
1690 panic("%s: Linked CCB Lun Mismatch", bt_name(bt));
1692 case BTSTAT_INVALID_CCB_OR_SG_PARAM:
1693 panic("%s: Invalid CCB or SG list", bt_name(bt));
1695 case BTSTAT_AUTOSENSE_FAILED:
1696 csio->ccb_h.status = CAM_AUTOSENSE_FAIL;
1698 case BTSTAT_TAGGED_MSG_REJECTED:
1700 struct ccb_trans_settings neg;
1701 struct ccb_trans_settings_scsi *scsi =
1702 &neg.proto_specific.scsi;
1704 neg.protocol = PROTO_SCSI;
1705 neg.protocol_version = SCSI_REV_2;
1706 neg.transport = XPORT_SPI;
1707 neg.transport_version = 2;
1708 scsi->valid = CTS_SCSI_VALID_TQ;
1710 xpt_print_path(csio->ccb_h.path);
1711 printf("refuses tagged commands. Performing "
1712 "non-tagged I/O\n");
1713 xpt_setup_ccb(&neg.ccb_h, csio->ccb_h.path,
1715 xpt_async(AC_TRANSFER_NEG, csio->ccb_h.path, &neg);
1716 bt->tags_permitted &= ~(0x01 << csio->ccb_h.target_id);
1717 csio->ccb_h.status = CAM_MSG_REJECT_REC;
1720 case BTSTAT_UNSUPPORTED_MSG_RECEIVED:
1722 * XXX You would think that this is
1723 * a recoverable error... Hmmm.
1725 csio->ccb_h.status = CAM_REQ_CMP_ERR;
1727 case BTSTAT_HA_SOFTWARE_ERROR:
1728 case BTSTAT_HA_WATCHDOG_ERROR:
1729 case BTSTAT_HARDWARE_FAILURE:
1730 /* Hardware reset ??? Can we recover ??? */
1731 csio->ccb_h.status = CAM_NO_HBA;
1733 case BTSTAT_TARGET_IGNORED_ATN:
1734 case BTSTAT_OTHER_SCSI_BUS_RESET:
1735 case BTSTAT_HA_SCSI_BUS_RESET:
1736 if ((csio->ccb_h.status & CAM_STATUS_MASK)
1738 csio->ccb_h.status = CAM_SCSI_BUS_RESET;
1741 if ((bccb->flags & BCCB_DEVICE_RESET) == 0)
1742 csio->ccb_h.status = CAM_BDR_SENT;
1744 csio->ccb_h.status = CAM_CMD_TIMEOUT;
1746 case BTSTAT_INVALID_RECONNECT:
1747 case BTSTAT_ABORT_QUEUE_GENERATED:
1748 csio->ccb_h.status = CAM_REQ_TERMIO;
1750 case BTSTAT_SCSI_PERROR_DETECTED:
1751 csio->ccb_h.status = CAM_UNCOR_PARITY;
1754 if (csio->ccb_h.status != CAM_REQ_CMP) {
1755 xpt_freeze_devq(csio->ccb_h.path, /*count*/1);
1756 csio->ccb_h.status |= CAM_DEV_QFRZN;
1758 if ((bccb->flags & BCCB_RELEASE_SIMQ) != 0)
1759 ccb->ccb_h.status |= CAM_RELEASE_SIMQ;
1760 btfreeccb(bt, bccb);
1764 /* All completed without incident */
1765 ccb->ccb_h.status |= CAM_REQ_CMP;
1766 if ((bccb->flags & BCCB_RELEASE_SIMQ) != 0)
1767 ccb->ccb_h.status |= CAM_RELEASE_SIMQ;
1768 btfreeccb(bt, bccb);
1775 btreset(struct bt_softc* bt, int hard_reset)
1777 struct ccb_hdr *ccb_h;
1780 u_int8_t reset_type;
1782 if (hard_reset != 0)
1783 reset_type = HARD_RESET;
1785 reset_type = SOFT_RESET;
1786 bt_outb(bt, CONTROL_REG, reset_type);
1788 /* Wait 5sec. for Diagnostic start */
1789 timeout = 5 * 10000;
1791 status = bt_inb(bt, STATUS_REG);
1792 if ((status & DIAG_ACTIVE) != 0)
1798 device_printf(bt->dev,
1799 "btreset - Diagnostic Active failed to "
1800 "assert. status = 0x%x\n", status);
1804 /* Wait 10sec. for Diagnostic end */
1805 timeout = 10 * 10000;
1807 status = bt_inb(bt, STATUS_REG);
1808 if ((status & DIAG_ACTIVE) == 0)
1813 panic("%s: btreset - Diagnostic Active failed to drop. "
1814 "status = 0x%x\n", bt_name(bt), status);
1818 /* Wait for the host adapter to become ready or report a failure */
1821 status = bt_inb(bt, STATUS_REG);
1822 if ((status & (DIAG_FAIL|HA_READY|DATAIN_REG_READY)) != 0)
1827 device_printf(bt->dev,
1828 "btreset - Host adapter failed to come ready. "
1829 "status = 0x%x\n", status);
1833 /* If the diagnostics failed, tell the user */
1834 if ((status & DIAG_FAIL) != 0
1835 || (status & HA_READY) == 0) {
1836 device_printf(bt->dev,
1837 "btreset - Adapter failed diagnostics\n");
1839 if ((status & DATAIN_REG_READY) != 0)
1840 device_printf(bt->dev,
1841 "btreset - Host Adapter Error code = 0x%x\n",
1842 bt_inb(bt, DATAIN_REG));
1846 /* If we've allocated mailboxes, initialize them */
1847 if (bt->init_level > 4)
1850 /* If we've attached to the XPT, tell it about the event */
1851 if (bt->path != NULL)
1852 xpt_async(AC_BUS_RESET, bt->path, NULL);
1855 * Perform completion processing for all outstanding CCBs.
1857 while ((ccb_h = LIST_FIRST(&bt->pending_ccbs)) != NULL) {
1858 struct bt_ccb *pending_bccb;
1860 pending_bccb = (struct bt_ccb *)ccb_h->ccb_bccb_ptr;
1861 pending_bccb->hccb.btstat = BTSTAT_HA_SCSI_BUS_RESET;
1862 btdone(bt, pending_bccb, BMBI_ERROR);
1869 * Send a command to the adapter.
1872 bt_cmd(struct bt_softc *bt, bt_op_t opcode, u_int8_t *params, u_int param_len,
1873 u_int8_t *reply_data, u_int reply_len, u_int cmd_timeout)
1879 u_int reply_buf_size;
1883 /* No data returned to start */
1884 reply_buf_size = reply_len;
1891 bt->command_cmp = 0;
1893 * Wait up to 10 sec. for the adapter to become
1894 * ready to accept commands.
1898 status = bt_inb(bt, STATUS_REG);
1899 if ((status & HA_READY) != 0
1900 && (status & CMD_REG_BUSY) == 0)
1903 * Throw away any pending data which may be
1904 * left over from earlier commands that we
1907 if ((status & DATAIN_REG_READY) != 0)
1908 (void)bt_inb(bt, DATAIN_REG);
1912 device_printf(bt->dev,
1913 "bt_cmd: Timeout waiting for adapter ready, "
1914 "status = 0x%x\n", status);
1919 * Send the opcode followed by any necessary parameter bytes.
1921 bt_outb(bt, COMMAND_REG, opcode);
1924 * Wait for up to 1sec for each byte of the
1925 * parameter list sent to be sent.
1928 while (param_len && --timeout) {
1930 status = bt_inb(bt, STATUS_REG);
1931 intstat = bt_inb(bt, INTSTAT_REG);
1933 if ((intstat & (INTR_PENDING|CMD_COMPLETE))
1934 == (INTR_PENDING|CMD_COMPLETE)) {
1935 saved_status = status;
1939 if (bt->command_cmp != 0) {
1940 saved_status = bt->latched_status;
1944 if ((status & DATAIN_REG_READY) != 0)
1946 if ((status & CMD_REG_BUSY) == 0) {
1947 bt_outb(bt, COMMAND_REG, *params++);
1953 device_printf(bt->dev, "bt_cmd: Timeout sending parameters, "
1954 "status = 0x%x\n", status);
1956 saved_status = status;
1961 * Wait for the command to complete.
1963 while (cmd_complete == 0 && --cmd_timeout) {
1965 status = bt_inb(bt, STATUS_REG);
1966 intstat = bt_inb(bt, INTSTAT_REG);
1968 * It may be that this command was issued with
1969 * controller interrupts disabled. We'll never
1970 * get to our command if an incoming mailbox
1971 * interrupt is pending, so take care of completed
1972 * mailbox commands by calling our interrupt handler.
1974 if ((intstat & (INTR_PENDING|IMB_LOADED))
1975 == (INTR_PENDING|IMB_LOADED))
1978 if (bt->command_cmp != 0) {
1980 * Our interrupt handler saw CMD_COMPLETE
1981 * status before we did.
1984 saved_status = bt->latched_status;
1985 } else if ((intstat & (INTR_PENDING|CMD_COMPLETE))
1986 == (INTR_PENDING|CMD_COMPLETE)) {
1988 * Our poll (in case interrupts are blocked)
1989 * saw the CMD_COMPLETE interrupt.
1992 saved_status = status;
1993 } else if (opcode == BOP_MODIFY_IO_ADDR
1994 && (status & CMD_REG_BUSY) == 0) {
1996 * The BOP_MODIFY_IO_ADDR does not issue a CMD_COMPLETE,
1997 * but it should update the status register. So, we
1998 * consider this command complete when the CMD_REG_BUSY
2001 saved_status = status;
2003 } else if ((status & DATAIN_REG_READY) != 0) {
2006 data = bt_inb(bt, DATAIN_REG);
2007 if (reply_len < reply_buf_size) {
2008 *reply_data++ = data;
2010 device_printf(bt->dev,
2011 "bt_cmd - Discarded reply data byte "
2012 "for opcode 0x%x\n", opcode);
2015 * Reset timeout to ensure at least a second
2016 * between response bytes.
2018 cmd_timeout = MAX(cmd_timeout, 10000);
2021 } else if ((opcode == BOP_FETCH_LRAM)
2022 && (status & HA_READY) != 0) {
2023 saved_status = status;
2028 if (cmd_timeout == 0) {
2029 device_printf(bt->dev,
2030 "bt_cmd: Timeout waiting for command (%x) "
2031 "to complete.\n", opcode);
2032 device_printf(bt->dev, "status = 0x%x, intstat = 0x%x, "
2033 "rlen %d\n", status, intstat, reply_len);
2034 error = (ETIMEDOUT);
2038 * Clear any pending interrupts.
2046 * If the command was rejected by the controller, tell the caller.
2048 if ((saved_status & CMD_INVALID) != 0) {
2050 * Some early adapters may not recover properly from
2051 * an invalid command. If it appears that the controller
2052 * has wedged (i.e. status was not cleared by our interrupt
2053 * reset above), perform a soft reset.
2056 device_printf(bt->dev, "Invalid Command 0x%x\n",
2059 status = bt_inb(bt, STATUS_REG);
2060 if ((status & (CMD_INVALID|STATUS_REG_RSVD|DATAIN_REG_READY|
2061 CMD_REG_BUSY|DIAG_FAIL|DIAG_ACTIVE)) != 0
2062 || (status & (HA_READY|INIT_REQUIRED))
2063 != (HA_READY|INIT_REQUIRED)) {
2064 btreset(bt, /*hard_reset*/FALSE);
2069 if (param_len > 0) {
2070 /* The controller did not accept the full argument list */
2074 if (reply_len != reply_buf_size) {
2075 /* Too much or too little data received */
2079 /* We were successful */
2084 btinitmboxes(struct bt_softc *bt) {
2085 init_32b_mbox_params_t init_mbox;
2088 bzero(bt->in_boxes, sizeof(bt_mbox_in_t) * bt->num_boxes);
2089 bzero(bt->out_boxes, sizeof(bt_mbox_out_t) * bt->num_boxes);
2090 bt->cur_inbox = bt->in_boxes;
2091 bt->last_inbox = bt->in_boxes + bt->num_boxes - 1;
2092 bt->cur_outbox = bt->out_boxes;
2093 bt->last_outbox = bt->out_boxes + bt->num_boxes - 1;
2095 /* Tell the adapter about them */
2096 init_mbox.num_boxes = bt->num_boxes;
2097 init_mbox.base_addr[0] = bt->mailbox_physbase & 0xFF;
2098 init_mbox.base_addr[1] = (bt->mailbox_physbase >> 8) & 0xFF;
2099 init_mbox.base_addr[2] = (bt->mailbox_physbase >> 16) & 0xFF;
2100 init_mbox.base_addr[3] = (bt->mailbox_physbase >> 24) & 0xFF;
2101 error = bt_cmd(bt, BOP_INITIALIZE_32BMBOX, (u_int8_t *)&init_mbox,
2102 /*parmlen*/sizeof(init_mbox), /*reply_buf*/NULL,
2103 /*reply_len*/0, DEFAULT_CMD_TIMEOUT);
2106 printf("btinitmboxes: Initialization command failed\n");
2107 else if (bt->strict_rr != 0) {
2109 * If the controller supports
2110 * strict round robin mode,
2116 error = bt_cmd(bt, BOP_ENABLE_STRICT_RR, ¶m, 1,
2117 /*reply_buf*/NULL, /*reply_len*/0,
2118 DEFAULT_CMD_TIMEOUT);
2121 printf("btinitmboxes: Unable to enable strict RR\n");
2123 } else if (bootverbose) {
2124 device_printf(bt->dev,
2125 "Using Strict Round Robin Mailbox Mode\n");
2133 * Update the XPT's idea of the negotiated transfer
2134 * parameters for a particular target.
2137 btfetchtransinfo(struct bt_softc *bt, struct ccb_trans_settings *cts)
2139 setup_data_t setup_info;
2148 targ_syncinfo_t sync_info;
2149 struct ccb_trans_settings_scsi *scsi =
2150 &cts->proto_specific.scsi;
2151 struct ccb_trans_settings_spi *spi =
2152 &cts->xport_specific.spi;
2157 target = cts->ccb_h.target_id;
2158 targ_offset = (target & 0x7);
2159 targ_mask = (0x01 << targ_offset);
2162 * Inquire Setup Information. This command retreives the
2163 * Wide negotiation status for recent adapters as well as
2164 * the sync info for older models.
2166 param = sizeof(setup_info);
2167 error = bt_cmd(bt, BOP_INQUIRE_SETUP_INFO, ¶m, /*paramlen*/1,
2168 (u_int8_t*)&setup_info, sizeof(setup_info),
2169 DEFAULT_CMD_TIMEOUT);
2172 device_printf(bt->dev,
2173 "btfetchtransinfo - Inquire Setup Info Failed %x\n",
2178 sync_info = (target < 8) ? setup_info.low_syncinfo[targ_offset]
2179 : setup_info.high_syncinfo[targ_offset];
2181 if (sync_info.sync == 0)
2184 sync_offset = sync_info.offset;
2187 bus_width = MSG_EXT_WDTR_BUS_8_BIT;
2188 if (strcmp(bt->firmware_ver, "5.06L") >= 0) {
2192 (target < 8) ? (setup_info.low_wide_active & targ_mask)
2193 : (setup_info.high_wide_active & targ_mask);
2196 bus_width = MSG_EXT_WDTR_BUS_16_BIT;
2197 } else if ((bt->wide_permitted & targ_mask) != 0) {
2198 struct ccb_getdev cgd;
2201 * Prior to rev 5.06L, wide status isn't provided,
2202 * so we "guess" that wide transfers are in effect
2203 * if the user settings allow for wide and the inquiry
2204 * data for the device indicates that it can handle
2207 xpt_setup_ccb(&cgd.ccb_h, cts->ccb_h.path, /*priority*/1);
2208 cgd.ccb_h.func_code = XPT_GDEV_TYPE;
2209 xpt_action((union ccb *)&cgd);
2210 if ((cgd.ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP
2211 && (cgd.inq_data.flags & SID_WBus16) != 0)
2212 bus_width = MSG_EXT_WDTR_BUS_16_BIT;
2215 if (bt->firmware_ver[0] >= '3') {
2217 * For adapters that can do fast or ultra speeds,
2218 * use the more exact Target Sync Information command.
2220 target_sync_info_data_t sync_info;
2222 param = sizeof(sync_info);
2223 error = bt_cmd(bt, BOP_TARG_SYNC_INFO, ¶m, /*paramlen*/1,
2224 (u_int8_t*)&sync_info, sizeof(sync_info),
2225 DEFAULT_CMD_TIMEOUT);
2228 device_printf(bt->dev,
2229 "btfetchtransinfo - Inquire Sync "
2230 "Info Failed 0x%x\n", error);
2233 sync_period = sync_info.sync_rate[target] * 100;
2235 sync_period = 2000 + (500 * sync_info.period);
2238 cts->protocol = PROTO_SCSI;
2239 cts->protocol_version = SCSI_REV_2;
2240 cts->transport = XPORT_SPI;
2241 cts->transport_version = 2;
2243 spi->sync_period = sync_period;
2244 spi->valid |= CTS_SPI_VALID_SYNC_RATE;
2245 spi->sync_offset = sync_offset;
2246 spi->valid |= CTS_SPI_VALID_SYNC_OFFSET;
2248 spi->valid |= CTS_SPI_VALID_BUS_WIDTH;
2249 spi->bus_width = bus_width;
2251 if (cts->ccb_h.target_lun != CAM_LUN_WILDCARD) {
2252 scsi->valid = CTS_SCSI_VALID_TQ;
2253 spi->valid |= CTS_SPI_VALID_DISC;
2257 xpt_async(AC_TRANSFER_NEG, cts->ccb_h.path, cts);
2261 btmapmboxes(void *arg, bus_dma_segment_t *segs, int nseg, int error)
2263 struct bt_softc* bt;
2265 bt = (struct bt_softc*)arg;
2266 bt->mailbox_physbase = segs->ds_addr;
2270 btmapccbs(void *arg, bus_dma_segment_t *segs, int nseg, int error)
2272 struct bt_softc* bt;
2274 bt = (struct bt_softc*)arg;
2275 bt->bt_ccb_physbase = segs->ds_addr;
2279 btmapsgs(void *arg, bus_dma_segment_t *segs, int nseg, int error)
2282 struct bt_softc* bt;
2284 bt = (struct bt_softc*)arg;
2285 SLIST_FIRST(&bt->sg_maps)->sg_physaddr = segs->ds_addr;
2289 btpoll(struct cam_sim *sim)
2291 bt_intr_locked(cam_sim_softc(sim));
2295 bttimeout(void *arg)
2297 struct bt_ccb *bccb;
2299 struct bt_softc *bt;
2301 bccb = (struct bt_ccb *)arg;
2303 bt = (struct bt_softc *)ccb->ccb_h.ccb_bt_ptr;
2304 mtx_assert(&bt->lock, MA_OWNED);
2305 xpt_print_path(ccb->ccb_h.path);
2306 printf("CCB %p - timed out\n", (void *)bccb);
2308 if ((bccb->flags & BCCB_ACTIVE) == 0) {
2309 xpt_print_path(ccb->ccb_h.path);
2310 printf("CCB %p - timed out CCB already completed\n",
2316 * In order to simplify the recovery process, we ask the XPT
2317 * layer to halt the queue of new transactions and we traverse
2318 * the list of pending CCBs and remove their timeouts. This
2319 * means that the driver attempts to clear only one error
2320 * condition at a time. In general, timeouts that occur
2321 * close together are related anyway, so there is no benefit
2322 * in attempting to handle errors in parrallel. Timeouts will
2323 * be reinstated when the recovery process ends.
2325 if ((bccb->flags & BCCB_DEVICE_RESET) == 0) {
2326 struct ccb_hdr *ccb_h;
2328 if ((bccb->flags & BCCB_RELEASE_SIMQ) == 0) {
2329 xpt_freeze_simq(bt->sim, /*count*/1);
2330 bccb->flags |= BCCB_RELEASE_SIMQ;
2333 ccb_h = LIST_FIRST(&bt->pending_ccbs);
2334 while (ccb_h != NULL) {
2335 struct bt_ccb *pending_bccb;
2337 pending_bccb = (struct bt_ccb *)ccb_h->ccb_bccb_ptr;
2338 callout_stop(&pending_bccb->timer);
2339 ccb_h = LIST_NEXT(ccb_h, sim_links.le);
2343 if ((bccb->flags & BCCB_DEVICE_RESET) != 0
2344 || bt->cur_outbox->action_code != BMBO_FREE
2345 || ((bccb->hccb.tag_enable == TRUE)
2346 && (bt->firmware_ver[0] < '5'))) {
2348 * Try a full host adapter/SCSI bus reset.
2349 * We do this only if we have already attempted
2350 * to clear the condition with a BDR, or we cannot
2351 * attempt a BDR for lack of mailbox resources
2352 * or because of faulty firmware. It turns out
2353 * that firmware versions prior to 5.xx treat BDRs
2354 * as untagged commands that cannot be sent until
2355 * all outstanding tagged commands have been processed.
2356 * This makes it somewhat difficult to use a BDR to
2357 * clear up a problem with an uncompleted tagged command.
2359 ccb->ccb_h.status = CAM_CMD_TIMEOUT;
2360 btreset(bt, /*hardreset*/TRUE);
2361 device_printf(bt->dev, "No longer in timeout\n");
2364 * Send a Bus Device Reset message:
2365 * The target that is holding up the bus may not
2366 * be the same as the one that triggered this timeout
2367 * (different commands have different timeout lengths),
2368 * but we have no way of determining this from our
2369 * timeout handler. Our strategy here is to queue a
2370 * BDR message to the target of the timed out command.
2371 * If this fails, we'll get another timeout 2 seconds
2372 * later which will attempt a bus reset.
2374 bccb->flags |= BCCB_DEVICE_RESET;
2375 callout_reset(&bccb->timer, 2 * hz, bttimeout, bccb);
2377 bt->recovery_bccb->hccb.opcode = INITIATOR_BUS_DEV_RESET;
2379 /* No Data Transfer */
2380 bt->recovery_bccb->hccb.datain = TRUE;
2381 bt->recovery_bccb->hccb.dataout = TRUE;
2382 bt->recovery_bccb->hccb.btstat = 0;
2383 bt->recovery_bccb->hccb.sdstat = 0;
2384 bt->recovery_bccb->hccb.target_id = ccb->ccb_h.target_id;
2386 /* Tell the adapter about this command */
2387 bt->cur_outbox->ccb_addr = btccbvtop(bt, bt->recovery_bccb);
2388 bt->cur_outbox->action_code = BMBO_START;
2389 bt_outb(bt, COMMAND_REG, BOP_START_MBOX);
2394 MODULE_VERSION(bt, 1);
2395 MODULE_DEPEND(bt, cam, 1, 1, 1);