Deleted Added
full compact
bt.c (40749) bt.c (41048)
1/*
2 * Generic driver for the BusLogic MultiMaster SCSI host adapters
3 * Product specific probe and attach routines can be found in:
4 * i386/isa/bt_isa.c BT-54X, BT-445 cards
5 * i386/eisa/bt_eisa.c BT-74x, BT-75x cards
6 * pci/bt_pci.c BT-946, BT-948, BT-956, BT-958 cards
7 *
8 * Copyright (c) 1998 Justin T. Gibbs.

--- 15 unchanged lines hidden (view full) ---

24 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
1/*
2 * Generic driver for the BusLogic MultiMaster SCSI host adapters
3 * Product specific probe and attach routines can be found in:
4 * i386/isa/bt_isa.c BT-54X, BT-445 cards
5 * i386/eisa/bt_eisa.c BT-74x, BT-75x cards
6 * pci/bt_pci.c BT-946, BT-948, BT-956, BT-958 cards
7 *
8 * Copyright (c) 1998 Justin T. Gibbs.

--- 15 unchanged lines hidden (view full) ---

24 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
32 * $Id: bt.c,v 1.7 1998/10/15 23:46:28 gibbs Exp $
32 * $Id: bt.c,v 1.8 1998/10/30 02:06:44 gibbs Exp $
33 */
34
35 /*
36 * Special thanks to Leonard N. Zubkoff for writing such a complete and
37 * well documented Mylex/BusLogic MultiMaster driver for Linux. Support
38 * in this driver for the wide range of MultiMaster controllers and
39 * firmware revisions, with their otherwise undocumented quirks, would not
40 * have been possible without his efforts.

--- 135 unchanged lines hidden (view full) ---

176/*
177 * XXX
178 * Do our own re-probe protection until a configuration
179 * manager can do it for us. This ensures that we don't
180 * reprobe a card already found by the EISA or PCI probes.
181 */
182struct bt_isa_port bt_isa_ports[] =
183{
33 */
34
35 /*
36 * Special thanks to Leonard N. Zubkoff for writing such a complete and
37 * well documented Mylex/BusLogic MultiMaster driver for Linux. Support
38 * in this driver for the wide range of MultiMaster controllers and
39 * firmware revisions, with their otherwise undocumented quirks, would not
40 * have been possible without his efforts.

--- 135 unchanged lines hidden (view full) ---

176/*
177 * XXX
178 * Do our own re-probe protection until a configuration
179 * manager can do it for us. This ensures that we don't
180 * reprobe a card already found by the EISA or PCI probes.
181 */
182struct bt_isa_port bt_isa_ports[] =
183{
184 { 0x330, 0 },
185 { 0x334, 0 },
186 { 0x230, 0 },
187 { 0x234, 0 },
188 { 0x130, 0 },
189 { 0x134, 0 }
184 { 0x130, 0, 4 },
185 { 0x134, 0, 5 },
186 { 0x230, 0, 2 },
187 { 0x234, 0, 3 },
188 { 0x330, 0, 0 },
189 { 0x334, 0, 1 }
190};
191
190};
191
192/*
193 * I/O ports listed in the order enumerated by the
194 * card for certain op codes.
195 */
196u_int16_t bt_board_ports[] =
197{
198 0x330,
199 0x334,
200 0x230,
201 0x234,
202 0x130,
203 0x134
204};
205
192/* Exported functions */
193struct bt_softc *
194bt_alloc(int unit, bus_space_tag_t tag, bus_space_handle_t bsh)
195{
196 struct bt_softc *bt;
197
198 if (unit != BT_TEMP_UNIT) {
199 if (unit >= NBT) {

--- 609 unchanged lines hidden (view full) ---

809 return (name);
810}
811
812int
813bt_check_probed_iop(u_int ioport)
814{
815 u_int i;
816
206/* Exported functions */
207struct bt_softc *
208bt_alloc(int unit, bus_space_tag_t tag, bus_space_handle_t bsh)
209{
210 struct bt_softc *bt;
211
212 if (unit != BT_TEMP_UNIT) {
213 if (unit >= NBT) {

--- 609 unchanged lines hidden (view full) ---

823 return (name);
824}
825
826int
827bt_check_probed_iop(u_int ioport)
828{
829 u_int i;
830
817 for (i=0; i < BT_NUM_ISAPORTS; i++) {
831 for (i = 0; i < BT_NUM_ISAPORTS; i++) {
818 if (bt_isa_ports[i].addr == ioport) {
819 if (bt_isa_ports[i].probed != 0)
820 return (1);
821 else {
822 return (0);
823 }
824 }
825 }
826 return (1);
827}
828
832 if (bt_isa_ports[i].addr == ioport) {
833 if (bt_isa_ports[i].probed != 0)
834 return (1);
835 else {
836 return (0);
837 }
838 }
839 }
840 return (1);
841}
842
829u_int
830bt_fetch_isa_iop(isa_compat_io_t port)
831{
832 return (bt_isa_ports[port].addr);
833}
834
835void
836bt_mark_probed_bio(isa_compat_io_t port)
837{
838 if (port < BIO_DISABLED)
843void
844bt_mark_probed_bio(isa_compat_io_t port)
845{
846 if (port < BIO_DISABLED)
839 bt_isa_ports[port].probed = 1;
847 bt_mark_probed_iop(bt_board_ports[port]);
840}
841
842void
843bt_mark_probed_iop(u_int ioport)
844{
845 u_int i;
846
847 for (i = 0; i < BT_NUM_ISAPORTS; i++) {
848 if (ioport == bt_isa_ports[i].addr) {
849 bt_isa_ports[i].probed = 1;
850 break;
851 }
852 }
853}
854
848}
849
850void
851bt_mark_probed_iop(u_int ioport)
852{
853 u_int i;
854
855 for (i = 0; i < BT_NUM_ISAPORTS; i++) {
856 if (ioport == bt_isa_ports[i].addr) {
857 bt_isa_ports[i].probed = 1;
858 break;
859 }
860 }
861}
862
863void
864bt_find_probe_range(int ioport, int *port_index, int *max_port_index)
865{
866 if (ioport > 0) {
867 int i;
868
869 for (i = 0;i < BT_NUM_ISAPORTS; i++)
870 if (ioport <= bt_isa_ports[i].addr)
871 break;
872 if ((i >= BT_NUM_ISAPORTS)
873 || (ioport != bt_isa_ports[i].addr)) {
874 printf("
875bt_isa_probe: Invalid baseport of 0x%x specified.
876bt_isa_probe: Nearest valid baseport is 0x%x.
877bt_isa_probe: Failing probe.\n",
878 ioport,
879 (i < BT_NUM_ISAPORTS)
880 ? bt_isa_ports[i].addr
881 : bt_isa_ports[BT_NUM_ISAPORTS - 1].addr);
882 *port_index = *max_port_index = -1;
883 return;
884 }
885 *port_index = *max_port_index = bt_isa_ports[i].bio;
886 } else {
887 *port_index = 0;
888 *max_port_index = BT_NUM_ISAPORTS - 1;
889 }
890}
891
892int
893bt_iop_from_bio(isa_compat_io_t bio_index)
894{
895 if (bio_index >= 0 && bio_index < BT_NUM_ISAPORTS)
896 return (bt_board_ports[bio_index]);
897 return (-1);
898}
899
900
855static void
856btallocccbs(struct bt_softc *bt)
857{
858 struct bt_ccb *next_ccb;
859 struct sg_map_node *sg_map;
860 bus_addr_t physaddr;
861 bt_sg_t *segs;
862 int newcount;

--- 56 unchanged lines hidden (view full) ---

919 LIST_REMOVE(&bccb->ccb->ccb_h, sim_links.le);
920 if (bt->resource_shortage != 0
921 && (bccb->ccb->ccb_h.status & CAM_RELEASE_SIMQ) == 0) {
922 bccb->ccb->ccb_h.status |= CAM_RELEASE_SIMQ;
923 bt->resource_shortage = FALSE;
924 }
925 bccb->flags = BCCB_FREE;
926 SLIST_INSERT_HEAD(&bt->free_bt_ccbs, bccb, links);
901static void
902btallocccbs(struct bt_softc *bt)
903{
904 struct bt_ccb *next_ccb;
905 struct sg_map_node *sg_map;
906 bus_addr_t physaddr;
907 bt_sg_t *segs;
908 int newcount;

--- 56 unchanged lines hidden (view full) ---

965 LIST_REMOVE(&bccb->ccb->ccb_h, sim_links.le);
966 if (bt->resource_shortage != 0
967 && (bccb->ccb->ccb_h.status & CAM_RELEASE_SIMQ) == 0) {
968 bccb->ccb->ccb_h.status |= CAM_RELEASE_SIMQ;
969 bt->resource_shortage = FALSE;
970 }
971 bccb->flags = BCCB_FREE;
972 SLIST_INSERT_HEAD(&bt->free_bt_ccbs, bccb, links);
973 bt->active_ccbs--;
927 splx(s);
928}
929
930static __inline struct bt_ccb*
931btgetccb(struct bt_softc *bt)
932{
933 struct bt_ccb* bccb;
934 int s;
935
936 s = splcam();
937 if ((bccb = SLIST_FIRST(&bt->free_bt_ccbs)) != NULL) {
938 SLIST_REMOVE_HEAD(&bt->free_bt_ccbs, links);
974 splx(s);
975}
976
977static __inline struct bt_ccb*
978btgetccb(struct bt_softc *bt)
979{
980 struct bt_ccb* bccb;
981 int s;
982
983 s = splcam();
984 if ((bccb = SLIST_FIRST(&bt->free_bt_ccbs)) != NULL) {
985 SLIST_REMOVE_HEAD(&bt->free_bt_ccbs, links);
986 bt->active_ccbs++;
939 } else if (bt->num_ccbs < bt->max_ccbs) {
940 btallocccbs(bt);
941 bccb = SLIST_FIRST(&bt->free_bt_ccbs);
942 if (bccb == NULL)
943 printf("%s: Can't malloc BCCB\n", bt_name(bt));
987 } else if (bt->num_ccbs < bt->max_ccbs) {
988 btallocccbs(bt);
989 bccb = SLIST_FIRST(&bt->free_bt_ccbs);
990 if (bccb == NULL)
991 printf("%s: Can't malloc BCCB\n", bt_name(bt));
944 else
992 else {
945 SLIST_REMOVE_HEAD(&bt->free_bt_ccbs, links);
993 SLIST_REMOVE_HEAD(&bt->free_bt_ccbs, links);
994 bt->active_ccbs++;
995 }
946 }
947 splx(s);
948
949 return (bccb);
950}
951
952static void
953btaction(struct cam_sim *sim, union ccb *ccb)

--- 388 unchanged lines hidden (view full) ---

1342 LIST_INSERT_HEAD(&bt->pending_ccbs, &ccb->ccb_h, sim_links.le);
1343
1344 ccb->ccb_h.timeout_ch =
1345 timeout(bttimeout, (caddr_t)bccb,
1346 (ccb->ccb_h.timeout * hz) / 1000);
1347
1348 /* Tell the adapter about this command */
1349 bt->cur_outbox->ccb_addr = btccbvtop(bt, bccb);
996 }
997 splx(s);
998
999 return (bccb);
1000}
1001
1002static void
1003btaction(struct cam_sim *sim, union ccb *ccb)

--- 388 unchanged lines hidden (view full) ---

1392 LIST_INSERT_HEAD(&bt->pending_ccbs, &ccb->ccb_h, sim_links.le);
1393
1394 ccb->ccb_h.timeout_ch =
1395 timeout(bttimeout, (caddr_t)bccb,
1396 (ccb->ccb_h.timeout * hz) / 1000);
1397
1398 /* Tell the adapter about this command */
1399 bt->cur_outbox->ccb_addr = btccbvtop(bt, bccb);
1350 if (bt->cur_outbox->action_code != BMBO_FREE)
1351 panic("%s: Too few mailboxes or to many ccbs???", bt_name(bt));
1400 if (bt->cur_outbox->action_code != BMBO_FREE) {
1401 /*
1402 * We should never encounter a busy mailbox.
1403 * If we do, warn the user, and treat it as
1404 * a resource shortage. If the controller is
1405 * hung, one of the pending transactions will
1406 * timeout causing us to start recovery operations.
1407 */
1408 printf("%s: Encountered busy mailbox with %d out of %d "
1409 "commands active!!!", bt_name(bt), bt->active_ccbs,
1410 bt->max_ccbs);
1411 untimeout(bttimeout, bccb, ccb->ccb_h.timeout_ch);
1412 if (nseg != 0)
1413 bus_dmamap_unload(bt->buffer_dmat, bccb->dmamap);
1414 btfreeccb(bt, bccb);
1415 bt->resource_shortage = TRUE;
1416 xpt_freeze_simq(bt->sim, /*count*/1);
1417 ccb->ccb_h.status = CAM_REQUEUE_REQ;
1418 xpt_done(ccb);
1419 return;
1420 }
1352 bt->cur_outbox->action_code = BMBO_START;
1353 bt_outb(bt, COMMAND_REG, BOP_START_MBOX);
1354 btnextoutbox(bt);
1355 splx(s);
1356}
1357
1358void
1359bt_intr(void *arg)

--- 104 unchanged lines hidden (view full) ---

1464 bt_name(bt));
1465 break;
1466 case BMBI_NOT_FOUND:
1467 printf("%s: btdone - CCB Abort failed to find CCB\n",
1468 bt_name(bt));
1469 break;
1470 case BMBI_ABORT:
1471 case BMBI_ERROR:
1421 bt->cur_outbox->action_code = BMBO_START;
1422 bt_outb(bt, COMMAND_REG, BOP_START_MBOX);
1423 btnextoutbox(bt);
1424 splx(s);
1425}
1426
1427void
1428bt_intr(void *arg)

--- 104 unchanged lines hidden (view full) ---

1533 bt_name(bt));
1534 break;
1535 case BMBI_NOT_FOUND:
1536 printf("%s: btdone - CCB Abort failed to find CCB\n",
1537 bt_name(bt));
1538 break;
1539 case BMBI_ABORT:
1540 case BMBI_ERROR:
1472#if 0
1473 printf("bt: ccb %x - error %x occured. btstat = %x, sdstat = %x\n",
1474 bccb, comp_code, bccb->hccb.btstat, bccb->hccb.sdstat);
1475#endif
1541 printf("bt: ccb %p - error %x occured. "
1542 "btstat = %x, sdstat = %x\n",
1543 (void *)bccb, comp_code, bccb->hccb.btstat,
1544 bccb->hccb.sdstat);
1476 /* An error occured */
1477 switch(bccb->hccb.btstat) {
1478 case BTSTAT_DATARUN_ERROR:
1545 /* An error occured */
1546 switch(bccb->hccb.btstat) {
1547 case BTSTAT_DATARUN_ERROR:
1479 if (bccb->hccb.data_len <= 0) {
1548 if (bccb->hccb.data_len == 0) {
1549 /*
1550 * At least firmware 4.22, does this
1551 * for a QUEUE FULL condition.
1552 */
1553 bccb->hccb.sdstat = SCSI_STATUS_QUEUE_FULL;
1554 } else if (bccb->hccb.data_len < 0) {
1480 csio->ccb_h.status = CAM_DATA_RUN_ERR;
1481 break;
1482 }
1483 /* FALLTHROUGH */
1484 case BTSTAT_NOERROR:
1485 case BTSTAT_LINKED_CMD_COMPLETE:
1486 case BTSTAT_LINKED_CMD_FLAG_COMPLETE:
1487 case BTSTAT_DATAUNDERUN_ERROR:

--- 691 unchanged lines hidden ---
1555 csio->ccb_h.status = CAM_DATA_RUN_ERR;
1556 break;
1557 }
1558 /* FALLTHROUGH */
1559 case BTSTAT_NOERROR:
1560 case BTSTAT_LINKED_CMD_COMPLETE:
1561 case BTSTAT_LINKED_CMD_FLAG_COMPLETE:
1562 case BTSTAT_DATAUNDERUN_ERROR:

--- 691 unchanged lines hidden ---