1*d6c07702Smartin /* $NetBSD: ahareg.h,v 1.15 2008/05/10 11:52:20 martin Exp $ */ 2fbc0df0aSthorpej 3fbc0df0aSthorpej /*- 4*d6c07702Smartin * Copyright (c) 1997-1999 The NetBSD Foundation, Inc. 5fbc0df0aSthorpej * All rights reserved. 6fbc0df0aSthorpej * 7fbc0df0aSthorpej * This code is derived from software contributed to The NetBSD Foundation 8a1ac6881Smycroft * by Charles M. Hannum and by Jason R. Thorpe of the Numerical Aerospace 9a1ac6881Smycroft * Simulation Facility, NASA Ames Research Center. 10fbc0df0aSthorpej * 11fbc0df0aSthorpej * Redistribution and use in source and binary forms, with or without 12fbc0df0aSthorpej * modification, are permitted provided that the following conditions 13fbc0df0aSthorpej * are met: 14fbc0df0aSthorpej * 1. Redistributions of source code must retain the above copyright 15fbc0df0aSthorpej * notice, this list of conditions and the following disclaimer. 16fbc0df0aSthorpej * 2. Redistributions in binary form must reproduce the above copyright 17fbc0df0aSthorpej * notice, this list of conditions and the following disclaimer in the 18fbc0df0aSthorpej * documentation and/or other materials provided with the distribution. 19fbc0df0aSthorpej * 20fbc0df0aSthorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21fbc0df0aSthorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22fbc0df0aSthorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23fbc0df0aSthorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24fbc0df0aSthorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25fbc0df0aSthorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26fbc0df0aSthorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27fbc0df0aSthorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28fbc0df0aSthorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29fbc0df0aSthorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30fbc0df0aSthorpej * POSSIBILITY OF SUCH DAMAGE. 31fbc0df0aSthorpej */ 321dd15049Smycroft 331dd15049Smycroft /* 341dd15049Smycroft * Originally written by Julian Elischer (julian@tfs.com) 351dd15049Smycroft * for TRW Financial Systems for use under the MACH(2.5) operating system. 361dd15049Smycroft * 371dd15049Smycroft * TRW Financial Systems, in accordance with their agreement with Carnegie 381dd15049Smycroft * Mellon University, makes this software available to CMU to distribute 391dd15049Smycroft * or use in any manner that they see fit as long as this message is kept with 401dd15049Smycroft * the software. For this reason TFS also grants any other persons or 411dd15049Smycroft * organisations permission to use or modify this software. 421dd15049Smycroft * 431dd15049Smycroft * TFS supplies this software to be publicly redistributed 441dd15049Smycroft * on the understanding that TFS is not responsible for the correct 451dd15049Smycroft * functioning of this software in any circumstances. 461dd15049Smycroft */ 471dd15049Smycroft 481dd15049Smycroft typedef u_int8_t physaddr[3]; 491dd15049Smycroft typedef u_int8_t physlen[3]; 501dd15049Smycroft #define ltophys _lto3b 511dd15049Smycroft #define phystol _3btol 521dd15049Smycroft 531dd15049Smycroft /* 541dd15049Smycroft * I/O port offsets 551dd15049Smycroft */ 561dd15049Smycroft #define AHA_CTRL_PORT 0 /* control (wo) */ 571dd15049Smycroft #define AHA_STAT_PORT 0 /* status (ro) */ 581dd15049Smycroft #define AHA_CMD_PORT 1 /* command (wo) */ 591dd15049Smycroft #define AHA_DATA_PORT 1 /* data (ro) */ 601dd15049Smycroft #define AHA_INTR_PORT 2 /* interrupt status (ro) */ 611dd15049Smycroft 621dd15049Smycroft /* 631dd15049Smycroft * AHA_CTRL bits 641dd15049Smycroft */ 651dd15049Smycroft #define AHA_CTRL_HRST 0x80 /* Hardware reset */ 661dd15049Smycroft #define AHA_CTRL_SRST 0x40 /* Software reset */ 671dd15049Smycroft #define AHA_CTRL_IRST 0x20 /* Interrupt reset */ 681dd15049Smycroft #define AHA_CTRL_SCRST 0x10 /* SCSI bus reset */ 691dd15049Smycroft 701dd15049Smycroft /* 711dd15049Smycroft * AHA_STAT bits 721dd15049Smycroft */ 731dd15049Smycroft #define AHA_STAT_STST 0x80 /* Self test in Progress */ 741dd15049Smycroft #define AHA_STAT_DIAGF 0x40 /* Diagnostic Failure */ 751dd15049Smycroft #define AHA_STAT_INIT 0x20 /* Mbx Init required */ 761dd15049Smycroft #define AHA_STAT_IDLE 0x10 /* Host Adapter Idle */ 771dd15049Smycroft #define AHA_STAT_CDF 0x08 /* cmd/data out port full */ 781dd15049Smycroft #define AHA_STAT_DF 0x04 /* Data in port full */ 7972afc67cSad #define AHA_STAT_RSVD 0x02 /* Unused */ 801dd15049Smycroft #define AHA_STAT_INVDCMD 0x01 /* Invalid command */ 811dd15049Smycroft 821dd15049Smycroft /* 831dd15049Smycroft * AHA_CMD opcodes 841dd15049Smycroft */ 851dd15049Smycroft #define AHA_NOP 0x00 /* No operation */ 861dd15049Smycroft #define AHA_MBX_INIT 0x01 /* Mbx initialization */ 871dd15049Smycroft #define AHA_START_SCSI 0x02 /* start scsi command */ 881dd15049Smycroft #define AHA_INQUIRE_REVISION 0x04 /* Adapter Inquiry */ 891dd15049Smycroft #define AHA_MBO_INTR_EN 0x05 /* Enable MBO available interrupt */ 901dd15049Smycroft #if 0 911dd15049Smycroft #define AHA_SEL_TIMEOUT_SET 0x06 /* set selection time-out */ 921dd15049Smycroft #define AHA_BUS_ON_TIME_SET 0x07 /* set bus-on time */ 931dd15049Smycroft #define AHA_BUS_OFF_TIME_SET 0x08 /* set bus-off time */ 941dd15049Smycroft #define AHA_SPEED_SET 0x09 /* set transfer speed */ 951dd15049Smycroft #endif 961dd15049Smycroft #define AHA_INQUIRE_DEVICES 0x0a /* return installed devices 0-7 */ 971dd15049Smycroft #define AHA_INQUIRE_CONFIG 0x0b /* return configuration data */ 981dd15049Smycroft #define AHA_TARGET_EN 0x0c /* enable target mode */ 991dd15049Smycroft #define AHA_INQUIRE_SETUP 0x0d /* return setup data */ 1001dd15049Smycroft #define AHA_ECHO 0x1e /* Echo command data */ 1011dd15049Smycroft #define AHA_INQUIRE_DEVICES_2 0x23 /* return installed devices 8-15 */ 1021dd15049Smycroft #define AHA_EXT_BIOS 0x28 /* return extended bios info */ 1031dd15049Smycroft #define AHA_MBX_ENABLE 0x29 /* enable mail box interface */ 1041dd15049Smycroft 1051dd15049Smycroft /* 1061dd15049Smycroft * AHA_INTR bits 1071dd15049Smycroft */ 1081dd15049Smycroft #define AHA_INTR_ANYINTR 0x80 /* Any interrupt */ 10972afc67cSad #define AHA_INTR_RSVD 0x70 /* unused bits */ 1101dd15049Smycroft #define AHA_INTR_SCRD 0x08 /* SCSI reset detected */ 1111dd15049Smycroft #define AHA_INTR_HACC 0x04 /* Command complete */ 1121dd15049Smycroft #define AHA_INTR_MBOA 0x02 /* MBX out empty */ 1131dd15049Smycroft #define AHA_INTR_MBIF 0x01 /* MBX in full */ 1141dd15049Smycroft 1156224c1beSmjl /* 1166224c1beSmjl * AHA Board IDs 1176224c1beSmjl */ 1186224c1beSmjl #define BOARD_1540_16HEAD_BIOS 0x00 1196224c1beSmjl #define BOARD_1540_64HEAD_BIOS 0x30 1206224c1beSmjl #define BOARD_1540 0x31 1216224c1beSmjl #define BOARD_1542 0x41 /* aha-1540/1542 w/64-h bios */ 1226224c1beSmjl #define BOARD_1640 0x42 /* aha-1640 */ 1236224c1beSmjl #define BOARD_1740 0x43 /* aha-1740A/1742A/1744 */ 1246224c1beSmjl #define BOARD_1542C 0x44 /* aha-1542C */ 1256224c1beSmjl #define BOARD_1542CF 0x45 /* aha-1542CF */ 1266224c1beSmjl #define BOARD_1542CP 0x46 /* aha-1542CP, plug and play */ 1276224c1beSmjl 1281dd15049Smycroft struct aha_mbx_out { 1291dd15049Smycroft u_char cmd; 1301dd15049Smycroft physaddr ccb_addr; 1311dd15049Smycroft }; 1321dd15049Smycroft 1331dd15049Smycroft struct aha_mbx_in { 1341dd15049Smycroft u_char stat; 1351dd15049Smycroft physaddr ccb_addr; 1361dd15049Smycroft }; 1371dd15049Smycroft 1381dd15049Smycroft /* 1391dd15049Smycroft * mbo.cmd values 1401dd15049Smycroft */ 1411dd15049Smycroft #define AHA_MBO_FREE 0x0 /* MBO entry is free */ 1421dd15049Smycroft #define AHA_MBO_START 0x1 /* MBO activate entry */ 1431dd15049Smycroft #define AHA_MBO_ABORT 0x2 /* MBO abort entry */ 1441dd15049Smycroft 1451dd15049Smycroft /* 1461dd15049Smycroft * mbi.stat values 1471dd15049Smycroft */ 1481dd15049Smycroft #define AHA_MBI_FREE 0x0 /* MBI entry is free */ 1491dd15049Smycroft #define AHA_MBI_OK 0x1 /* completed without error */ 1501dd15049Smycroft #define AHA_MBI_ABORT 0x2 /* aborted ccb */ 1511dd15049Smycroft #define AHA_MBI_UNKNOWN 0x3 /* Tried to abort invalid CCB */ 1521dd15049Smycroft #define AHA_MBI_ERROR 0x4 /* Completed with error */ 1531dd15049Smycroft 1541dd15049Smycroft /* FOR OLD VERSIONS OF THE !%$@ this may have to be 16 (yuk) */ 1551dd15049Smycroft #define AHA_NSEG 17 /* Number of scatter gather segments <= 16 */ 1561dd15049Smycroft /* allow 64 K i/o (min) */ 1571dd15049Smycroft 1581dd15049Smycroft struct aha_scat_gath { 1591dd15049Smycroft physlen seg_len; 1601dd15049Smycroft physaddr seg_addr; 1611dd15049Smycroft }; 1621dd15049Smycroft 1631dd15049Smycroft struct aha_ccb { 1641dd15049Smycroft u_char opcode; 1651dd15049Smycroft u_char lun:3; 1661dd15049Smycroft u_char data_in:1; /* must be 0 */ 1671dd15049Smycroft u_char data_out:1; /* must be 0 */ 1681dd15049Smycroft u_char target:3; 1691dd15049Smycroft u_char scsi_cmd_length; 1701dd15049Smycroft u_char req_sense_length; 1711dd15049Smycroft physlen data_length; 1721dd15049Smycroft physaddr data_addr; 1731dd15049Smycroft physaddr link_addr; 1741dd15049Smycroft u_char link_id; 1751dd15049Smycroft u_char host_stat; 1761dd15049Smycroft u_char target_stat; 1771dd15049Smycroft u_char reserved[2]; 178d41e8f00Sthorpej u_char scsi_cmd[12]; 179df9803ceSthorpej struct scsi_sense_data scsi_sense; 1801dd15049Smycroft struct aha_scat_gath scat_gath[AHA_NSEG]; 1811dd15049Smycroft /*----------------------------------------------------------------*/ 1821dd15049Smycroft TAILQ_ENTRY(aha_ccb) chain; 1831dd15049Smycroft struct aha_ccb *nexthash; 184fa0b1878Smycroft u_long hashkey; 1856f3bab1fSbouyer struct scsipi_xfer *xs; /* the scsipi_xfer for this cmd */ 1861dd15049Smycroft int flags; 1871dd15049Smycroft #define CCB_ALLOC 0x01 1881dd15049Smycroft #define CCB_ABORT 0x02 1891dd15049Smycroft #ifdef AHADIAG 1901dd15049Smycroft #define CCB_SENDING 0x04 1911dd15049Smycroft #endif 1921dd15049Smycroft int timeout; 193fbc0df0aSthorpej 194fbc0df0aSthorpej /* 195fbc0df0aSthorpej * This DMA map maps the buffer involved in the transfer. 196fbc0df0aSthorpej * Its contents are loaded into "scat_gath" above. 197fbc0df0aSthorpej */ 198fbc0df0aSthorpej bus_dmamap_t dmamap_xfer; 1991dd15049Smycroft }; 2001dd15049Smycroft 2011dd15049Smycroft /* 2021dd15049Smycroft * opcode fields 2031dd15049Smycroft */ 2041dd15049Smycroft #define AHA_INITIATOR_CCB 0x00 /* SCSI Initiator CCB */ 2051dd15049Smycroft #define AHA_TARGET_CCB 0x01 /* SCSI Target CCB */ 2061dd15049Smycroft #define AHA_INIT_SCAT_GATH_CCB 0x02 /* SCSI Initiator with scatter gather */ 2071dd15049Smycroft #define AHA_RESET_CCB 0x81 /* SCSI Bus reset */ 2081dd15049Smycroft 2091dd15049Smycroft /* 2101dd15049Smycroft * aha_ccb.host_stat values 2111dd15049Smycroft */ 2121dd15049Smycroft #define AHA_OK 0x00 /* cmd ok */ 2131dd15049Smycroft #define AHA_LINK_OK 0x0a /* Link cmd ok */ 2141dd15049Smycroft #define AHA_LINK_IT 0x0b /* Link cmd ok + int */ 2151dd15049Smycroft #define AHA_SEL_TIMEOUT 0x11 /* Selection time out */ 2161dd15049Smycroft #define AHA_OVER_UNDER 0x12 /* Data over/under run */ 2171dd15049Smycroft #define AHA_BUS_FREE 0x13 /* Bus dropped at unexpected time */ 2181dd15049Smycroft #define AHA_INV_BUS 0x14 /* Invalid bus phase/sequence */ 2191dd15049Smycroft #define AHA_BAD_MBO 0x15 /* Incorrect MBO cmd */ 2201dd15049Smycroft #define AHA_BAD_CCB 0x16 /* Incorrect ccb opcode */ 2211dd15049Smycroft #define AHA_BAD_LINK 0x17 /* Not same values of LUN for links */ 2221dd15049Smycroft #define AHA_INV_TARGET 0x18 /* Invalid target direction */ 2231dd15049Smycroft #define AHA_CCB_DUP 0x19 /* Duplicate CCB received */ 2241dd15049Smycroft #define AHA_INV_CCB 0x1a /* Invalid CCB or segment list */ 2251dd15049Smycroft 2261dd15049Smycroft struct aha_revision { 2271dd15049Smycroft struct { 2281dd15049Smycroft u_char opcode; 2291dd15049Smycroft } cmd; 2301dd15049Smycroft struct { 2311dd15049Smycroft u_char boardid; /* type of board */ 2321dd15049Smycroft /* 0x31 = AHA-1540 */ 2331dd15049Smycroft /* 0x41 = AHA-1540A/1542A/1542B */ 2341dd15049Smycroft /* 0x42 = AHA-1640 */ 2351dd15049Smycroft /* 0x43 = AHA-1542C */ 2361dd15049Smycroft /* 0x44 = AHA-1542CF */ 2371dd15049Smycroft /* 0x45 = AHA-1542CF, BIOS v2.01 */ 2381dd15049Smycroft /* 0x46 = AHA-1542CP */ 2391dd15049Smycroft u_char spec_opts; /* special options ID */ 2401dd15049Smycroft /* 0x41 = Board is standard model */ 2411dd15049Smycroft u_char revision_1; /* firmware revision [0-9A-Z] */ 2421dd15049Smycroft u_char revision_2; /* firmware revision [0-9A-Z] */ 2431dd15049Smycroft } reply; 2441dd15049Smycroft }; 2451dd15049Smycroft 2461dd15049Smycroft struct aha_extbios { 2471dd15049Smycroft struct { 2481dd15049Smycroft u_char opcode; 2491dd15049Smycroft } cmd; 2501dd15049Smycroft struct { 2511dd15049Smycroft u_char flags; /* Bit 3 == 1 extended bios enabled */ 2521dd15049Smycroft u_char mailboxlock; /* mail box lock code to unlock it */ 2531dd15049Smycroft } reply; 2541dd15049Smycroft }; 2551dd15049Smycroft 2561dd15049Smycroft struct aha_toggle { 2571dd15049Smycroft struct { 2581dd15049Smycroft u_char opcode; 2591dd15049Smycroft u_char enable; 2601dd15049Smycroft } cmd; 2611dd15049Smycroft }; 2621dd15049Smycroft 2631dd15049Smycroft struct aha_config { 2641dd15049Smycroft struct { 2651dd15049Smycroft u_char opcode; 2661dd15049Smycroft } cmd; 2671dd15049Smycroft struct { 2681dd15049Smycroft u_char chan; 2691dd15049Smycroft u_char intr; 2701dd15049Smycroft u_char scsi_dev:3; 2711dd15049Smycroft u_char :5; 2721dd15049Smycroft } reply; 2731dd15049Smycroft }; 2741dd15049Smycroft 2751dd15049Smycroft struct aha_mailbox { 2761dd15049Smycroft struct { 2771dd15049Smycroft u_char opcode; 2781dd15049Smycroft u_char nmbx; 2791dd15049Smycroft physaddr addr; 2801dd15049Smycroft } cmd; 2811dd15049Smycroft }; 2821dd15049Smycroft 2831dd15049Smycroft struct aha_unlock { 2841dd15049Smycroft struct { 2851dd15049Smycroft u_char opcode; 2861dd15049Smycroft u_char junk; 2871dd15049Smycroft u_char magic; 2881dd15049Smycroft } cmd; 2891dd15049Smycroft }; 2901dd15049Smycroft 2911dd15049Smycroft struct aha_devices { 2921dd15049Smycroft struct { 2931dd15049Smycroft u_char opcode; 2941dd15049Smycroft } cmd; 2951dd15049Smycroft struct { 2965d4f9889Shannken u_char lun_map[8]; 2971dd15049Smycroft } reply; 2981dd15049Smycroft }; 2991dd15049Smycroft 3001dd15049Smycroft struct aha_setup { 3011dd15049Smycroft struct { 3021dd15049Smycroft u_char opcode; 3031dd15049Smycroft u_char len; 3041dd15049Smycroft } cmd; 3051dd15049Smycroft struct { 3061dd15049Smycroft u_char sync_neg:1; 3071dd15049Smycroft u_char parity:1; 3081dd15049Smycroft u_char :6; 3091dd15049Smycroft u_char speed; 3101dd15049Smycroft u_char bus_on; 3111dd15049Smycroft u_char bus_off; 3121dd15049Smycroft u_char num_mbx; 3131dd15049Smycroft u_char mbx[3]; 3141dd15049Smycroft struct { 3151dd15049Smycroft u_char offset:4; 3161dd15049Smycroft u_char period:3; 3171dd15049Smycroft u_char valid:1; 3181dd15049Smycroft } sync[8]; 3191dd15049Smycroft u_char disc_sts; 3201dd15049Smycroft } reply; 3211dd15049Smycroft }; 3221dd15049Smycroft 3231dd15049Smycroft #define INT9 0x01 3241dd15049Smycroft #define INT10 0x02 3251dd15049Smycroft #define INT11 0x04 3261dd15049Smycroft #define INT12 0x08 3271dd15049Smycroft #define INT14 0x20 3281dd15049Smycroft #define INT15 0x40 3291dd15049Smycroft 3301dd15049Smycroft #define EISADMA 0x00 3311dd15049Smycroft #define CHAN0 0x01 3321dd15049Smycroft #define CHAN5 0x20 3331dd15049Smycroft #define CHAN6 0x40 3341dd15049Smycroft #define CHAN7 0x80 335