Index: head/sys/dev/ic/i82586.h =================================================================== --- head/sys/dev/ic/i82586.h (revision 38231) +++ head/sys/dev/ic/i82586.h (revision 38232) @@ -1,325 +1,325 @@ /*- * Copyright (c) 1992, University of Vermont and State Agricultural College. * Copyright (c) 1992, Garrett A. Wollman. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * Vermont and State Agricultural College and Garrett A. Wollman. * 4. Neither the name of the University nor the name of the author * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR AUTHOR BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: i82586.h,v 1.5 1997/02/22 09:38:02 peter Exp $ + * $Id: i82586.h,v 1.6 1998/04/15 17:45:58 bde Exp $ */ /* * Intel 82586 Ethernet chip * Register, bit, and structure definitions. * * Written by GAW with reference to the Clarkson Packet Driver code for this * chip written by Russ Nelson and others. */ struct ie_en_addr { u_char data[6]; }; /* * This is the master configuration block. It tells the hardware where all * the rest of the stuff is. */ struct ie_sys_conf_ptr { u_short mbz; /* must be zero */ u_char ie_bus_use; /* true if 8-bit only */ u_char mbz2[5]; /* must be zero */ caddr_t ie_iscp_ptr; /* 24-bit physaddr of ISCP */ }; /* * Note that this is wired in hardware; the SCP is always located here, no * matter what. */ #define IE_SCP_ADDR 0xfffff4 /* * The tells the hardware where all the rest of the stuff is, too. * FIXME: some of these should be re-commented after we figure out their * REAL function. */ struct ie_int_sys_conf_ptr { u_char ie_busy; /* zeroed after init */ u_char mbz; u_short ie_scb_offset; /* 16-bit physaddr of next struct */ caddr_t ie_base; /* 24-bit physaddr for all 16-bit vars */ }; /* * This FINALLY tells the hardware what to do and where to put it. */ struct ie_sys_ctl_block { u_short ie_status; /* status word */ u_short ie_command; /* command word */ u_short ie_command_list; /* 16-pointer to command block list */ u_short ie_recv_list; /* 16-pointer to receive frame list */ u_short ie_err_crc; /* CRC errors */ u_short ie_err_align; /* Alignment errors */ u_short ie_err_resource; /* Resource errors */ u_short ie_err_overrun; /* Overrun errors */ }; /* Command values */ #define IE_RU_COMMAND 0x0070 /* mask for RU command */ #define IE_RU_NOP 0 /* for completeness */ #define IE_RU_START 0x0010 /* start receive unit command */ #define IE_RU_ENABLE 0x0020 /* enable receiver command */ #define IE_RU_DISABLE 0x0030 /* disable receiver command */ #define IE_RU_ABORT 0x0040 /* abort current receive operation */ #define IE_CU_COMMAND 0x0700 /* mask for CU command */ #define IE_CU_NOP 0 /* included for completeness */ #define IE_CU_START 0x0100 /* do-command command */ #define IE_CU_RESUME 0x0200 /* resume a suspended cmd list */ #define IE_CU_STOP 0x0300 /* SUSPEND was already taken */ #define IE_CU_ABORT 0x0400 /* abort current command */ #define IE_ACK_COMMAND 0xf000 /* mask for ACK command */ #define IE_ACK_CX 0x8000 /* ack IE_ST_DONE */ #define IE_ACK_FR 0x4000 /* ack IE_ST_RECV */ #define IE_ACK_CNA 0x2000 /* ack IE_ST_ALLDONE */ #define IE_ACK_RNR 0x1000 /* ack IE_ST_RNR */ #define IE_ACTION_COMMAND(x) (((x) & IE_CU_COMMAND) == IE_CU_START) /* is this command an action command? */ /* Status values */ #define IE_ST_WHENCE 0xf000 /* mask for cause of interrupt */ #define IE_ST_DONE 0x8000 /* command with I bit completed */ #define IE_ST_RECV 0x4000 /* frame received */ #define IE_ST_ALLDONE 0x2000 /* all commands completed */ #define IE_ST_RNR 0x1000 /* receive not ready */ #define IE_CU_STATUS 0x700 /* mask for command unit status */ #define IE_CU_ACTIVE 0x200 /* command unit is active */ #define IE_CU_SUSPEND 0x100 /* command unit is suspended */ #define IE_RU_STATUS 0x70 /* mask for receiver unit status */ #define IE_RU_SUSPEND 0x10 /* receiver is suspended */ #define IE_RU_NOSPACE 0x20 /* receiver has no resources */ #define IE_RU_READY 0x40 /* reveiver is ready */ /* * This is filled in partially by the chip, partially by us. */ struct ie_recv_frame_desc { u_short ie_fd_status; /* status for this frame */ u_short ie_fd_last; /* end of frame list flag */ u_short ie_fd_next; /* 16-pointer to next RFD */ u_short ie_fd_buf_desc; /* 16-pointer to list of buffer desc's */ struct ie_en_addr dest; /* destination ether */ struct ie_en_addr src; /* source ether */ u_short ie_length; /* 802 length/Ether type */ u_short mbz; /* must be zero */ }; #define IE_FD_LAST 0x8000 /* last rfd in list */ #define IE_FD_SUSP 0x4000 /* suspend RU after receipt */ #define IE_FD_COMPLETE 0x8000 /* frame is complete */ #define IE_FD_BUSY 0x4000 /* frame is busy */ #define IE_FD_OK 0x2000 /* frame is bad */ #define IE_FD_RNR 0x0200 /* receiver out of resources here */ /* * linked list of buffers... */ struct ie_recv_buf_desc { u_short ie_rbd_actual; /* status for this buffer */ u_short ie_rbd_next; /* 16-pointer to next RBD */ caddr_t ie_rbd_buffer; /* 24-pointer to buffer for this RBD */ u_short ie_rbd_length; /* length of the buffer */ u_short mbz; /* must be zero */ }; #define IE_RBD_LAST 0x8000 /* last buffer */ #define IE_RBD_USED 0x4000 /* this buffer has data */ /* * All commands share this in common. */ struct ie_cmd_common { u_short ie_cmd_status; /* status of this command */ u_short ie_cmd_cmd; /* command word */ u_short ie_cmd_link; /* link to next command */ }; #define IE_STAT_COMPL 0x8000 /* command is completed */ #define IE_STAT_BUSY 0x4000 /* command is running now */ #define IE_STAT_OK 0x2000 /* command completed successfully */ #define IE_CMD_NOP 0x0000 /* NOP */ #define IE_CMD_IASETUP 0x0001 /* initial address setup */ #define IE_CMD_CONFIG 0x0002 /* configure command */ #define IE_CMD_MCAST 0x0003 /* multicast setup command */ #define IE_CMD_XMIT 0x0004 /* transmit command */ #define IE_CMD_TDR 0x0005 /* time-domain reflectometer command */ #define IE_CMD_DUMP 0x0006 /* dump command */ #define IE_CMD_DIAGNOSE 0x0007 /* diagnostics command */ #define IE_CMD_LAST 0x8000 /* this is the last command in the list */ #define IE_CMD_SUSPEND 0x4000 /* suspend CU after this command */ #define IE_CMD_INTR 0x2000 /* post an interrupt after completion */ /* * This is the command to transmit a frame. */ struct ie_xmit_cmd { struct ie_cmd_common com; /* common part */ #define ie_xmit_status com.ie_cmd_status u_short ie_xmit_desc; /* 16-pointer to buffer descriptor */ struct ie_en_addr ie_xmit_addr; /* destination address */ u_short ie_xmit_length; /* 802.3 length/Ether type field */ }; #define IE_XS_MAXCOLL 0x000f /* number of collisions during transmit */ #define IE_XS_EXCMAX 0x0020 /* exceeded maximum number of collisions */ #define IE_XS_SQE 0x0040 /* SQE positive */ #define IE_XS_DEFERRED 0x0080 /* transmission deferred */ #define IE_XS_UNDERRUN 0x0100 /* DMA underrun */ #define IE_XS_LOSTCTS 0x0200 /* Lost CTS */ #define IE_XS_NOCARRIER 0x0400 /* No Carrier */ #define IE_XS_LATECOLL 0x0800 /* Late collision */ /* * This is a buffer descriptor for a frame to be transmitted. */ struct ie_xmit_buf { u_short ie_xmit_flags; /* see below */ u_short ie_xmit_next; /* 16-pointer to next desc. */ caddr_t ie_xmit_buf; /* 24-pointer to the actual buffer */ }; #define IE_XMIT_LAST 0x8000 /* this TBD is the last one */ /* The rest of the `flags' word is actually the length. */ /* * Multicast setup command. */ #define MAXMCAST 50 /* must fit in transmit buffer */ struct ie_mcast_cmd { struct ie_cmd_common com; /* common part */ #define ie_mcast_status com.ie_cmd_status u_short ie_mcast_bytes; /* size (in bytes) of multicast addresses */ struct ie_en_addr ie_mcast_addrs[MAXMCAST + 1]; /* space for them */ }; /* * Time Domain Reflectometer command. */ struct ie_tdr_cmd { struct ie_cmd_common com; /* common part */ #define ie_tdr_status com.ie_cmd_status u_short ie_tdr_time; /* error bits and time */ }; #define IE_TDR_SUCCESS 0x8000 /* TDR succeeded without error */ #define IE_TDR_XCVR 0x4000 /* detected a transceiver problem */ #define IE_TDR_OPEN 0x2000 /* detected an open */ #define IE_TDR_SHORT 0x1000 /* TDR detected a short */ #define IE_TDR_TIME 0x07ff /* mask for reflection time */ /* * Initial Address Setup command */ struct ie_iasetup_cmd { struct ie_cmd_common com; #define ie_iasetup_status com.ie_cmd_status struct ie_en_addr ie_address; }; /* * Configuration command */ struct ie_config_cmd { struct ie_cmd_common com; /* common part */ #define ie_config_status com.ie_cmd_status u_char ie_config_count; /* byte count (0x0c) */ u_char ie_fifo; /* fifo (8) */ u_char ie_save_bad; /* save bad frames (0x40) */ u_char ie_addr_len; /* address length (0x2e) (AL-LOC == 1) */ u_char ie_priority; /* priority and backoff (0x0) */ u_char ie_ifs; /* inter-frame spacing (0x60) */ u_char ie_slot_low; /* slot time, LSB (0x0) */ u_char ie_slot_high; /* slot time, MSN, and retries (0xf2) */ u_char ie_promisc; /* 1 if promiscuous, else 0 */ u_char ie_crs_cdt; /* CSMA/CD parameters (0x0) */ u_char ie_min_len; /* min frame length (0x40) */ u_char ie_junk; /* stuff for 82596 (0xff) */ }; /* * Here are a few useful functions. We could have done these as macros, * but since we have the inline facility, it makes sense to use that * instead. */ static __inline void ie_setup_config(volatile struct ie_config_cmd *cmd, int promiscuous, int manchester) { cmd->ie_config_count = 0x0c; cmd->ie_fifo = 8; cmd->ie_save_bad = 0x40; cmd->ie_addr_len = 0x2e; cmd->ie_priority = 0; cmd->ie_ifs = 0x60; cmd->ie_slot_low = 0; cmd->ie_slot_high = 0xf2; cmd->ie_promisc = !!promiscuous | manchester << 2; cmd->ie_crs_cdt = 0; cmd->ie_min_len = 64; cmd->ie_junk = 0xff; } static __inline caddr_t Align(caddr_t ptr) { - unsigned long l = (unsigned long)ptr; + uintptr_t l = (uintptr_t)ptr; l = (l + 3) & ~3L; return (caddr_t)l; } static __inline void ie_ack(volatile struct ie_sys_ctl_block *scb, u_int mask, int unit, void (*ca)(int)) { scb->ie_command = scb->ie_status & mask; (*ca)(unit); } Index: head/sys/dev/ie/if_ie.c =================================================================== --- head/sys/dev/ie/if_ie.c (revision 38231) +++ head/sys/dev/ie/if_ie.c (revision 38232) @@ -1,2427 +1,2431 @@ /*- * Copyright (c) 1992, 1993, University of Vermont and State * Agricultural College. * Copyright (c) 1992, 1993, Garrett A. Wollman. * * Portions: * Copyright (c) 1990, 1991, William F. Jolitz * Copyright (c) 1990, The Regents of the University of California * * 3Com 3C507 support: * Copyright (c) 1993, 1994, Charles M. Hannum * * EtherExpress 16 support: * Copyright (c) 1993, 1994, 1995, Rodney W. Grimes * Copyright (c) 1997, Aaron C. Smith * * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * Vermont and State Agricultural College and Garrett A. Wollman, by * William F. Jolitz, by the University of California, Berkeley, * Lawrence Berkeley Laboratory, and their contributors, by * Charles M. Hannum, by Rodney W. Grimes, and by Aaron C. Smith. * 4. Neither the names of the Universities nor the names of the authors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR AUTHORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: if_ie.c,v 1.54 1998/07/13 09:52:59 bde Exp $ + * $Id: if_ie.c,v 1.55 1998/08/10 14:27:32 bde Exp $ */ /* * Intel 82586 Ethernet chip * Register, bit, and structure definitions. * * Written by GAW with reference to the Clarkson Packet Driver code for this * chip written by Russ Nelson and others. * * Intel EtherExpress 16 support from if_ix.c, written by Rodney W. Grimes. */ /* * The i82586 is a very versatile chip, found in many implementations. * Programming this chip is mostly the same, but certain details differ * from card to card. This driver is written so that different cards * can be automatically detected at run-time. */ /* Mode of operation: We run the 82586 in a standard Ethernet mode. We keep NFRAMES received frame descriptors around for the receiver to use, and NRXBUFS associated receive buffer descriptors, both in a circular list. Whenever a frame is received, we rotate both lists as necessary. (The 586 treats both lists as a simple queue.) We also keep a transmit command around so that packets can be sent off quickly. We configure the adapter in AL-LOC = 1 mode, which means that the Ethernet/802.3 MAC header is placed at the beginning of the receive buffer rather than being split off into various fields in the RFD. This also means that we must include this header in the transmit buffer as well. By convention, all transmit commands, and only transmit commands, shall have the I (IE_CMD_INTR) bit set in the command. This way, when an interrupt arrives at ieintr(), it is immediately possible to tell what precisely caused it. ANY OTHER command-sending routines should run at splimp(), and should post an acknowledgement to every interrupt they generate. The 82586 has a 24-bit address space internally, and the adaptor's memory is located at the top of this region. However, the value we are given in configuration is normally the *bottom* of the adaptor RAM. So, we must go through a few gyrations to come up with a kernel virtual address which represents the actual beginning of the 586 address space. First, we autosize the RAM by running through several possible sizes and trying to initialize the adapter under the assumption that the selected size is correct. Then, knowing the correct RAM size, we set up our pointers in ie_softc[unit]. `iomem' represents the computed base of the 586 address space. `iomembot' represents the actual configured base of adapter RAM. Finally, `iosize' represents the calculated size of 586 RAM. Then, when laying out commands, we use the interval [iomembot, iomembot + iosize); to make 24-pointers, we subtract iomem, and to make 16-pointers, we subtract iomem and and with 0xffff. */ #include "ie.h" #if NIE > 0 #include "opt_inet.h" #include "opt_ipx.h" #include #include #include #include #include #include #include #include #include #include #include #include #include "bpfilter.h" #ifdef INET #include #include #endif #ifdef IPX #include #include #endif #ifdef NS #include #include #endif #include #include #include #include #include #include #include #include #include #if NBPFILTER > 0 #include #endif #ifdef DEBUG #define IED_RINT 0x01 #define IED_TINT 0x02 #define IED_RNR 0x04 #define IED_CNA 0x08 #define IED_READFRAME 0x10 static int ie_debug = IED_RNR; #endif #define IE_BUF_LEN ETHER_MAX_LEN /* length of transmit buffer */ /* Forward declaration */ struct ie_softc; static struct mbuf *last_not_for_us; static int ieprobe(struct isa_device * dvp); static int ieattach(struct isa_device * dvp); static int sl_probe(struct isa_device * dvp); static int el_probe(struct isa_device * dvp); static int ni_probe(struct isa_device * dvp); static int ee16_probe(struct isa_device * dvp); static int check_ie_present(int unit, caddr_t where, unsigned size); static void ieinit(int unit); static void ie_stop(int unit); static int ieioctl(struct ifnet * ifp, u_long command, caddr_t data); static void iestart(struct ifnet * ifp); static void el_reset_586(int unit); static void el_chan_attn(int unit); static void sl_reset_586(int unit); static void sl_chan_attn(int unit); static void ee16_reset_586(int unit); static void ee16_chan_attn(int unit); static __inline void ee16_interrupt_enable(struct ie_softc * ie); static void ee16_eeprom_outbits(struct ie_softc * ie, int edata, int cnt); static void ee16_eeprom_clock(struct ie_softc * ie, int state); static u_short ee16_read_eeprom(struct ie_softc * ie, int location); static int ee16_eeprom_inbits(struct ie_softc * ie); static void ee16_shutdown(int howto, void *sc); static void iereset(int unit); static void ie_readframe(int unit, struct ie_softc * ie, int bufno); static void ie_drop_packet_buffer(int unit, struct ie_softc * ie); static void sl_read_ether(int unit, unsigned char addr[6]); static void find_ie_mem_size(int unit); static void chan_attn_timeout(void *rock); static int command_and_wait(int unit, int command, void volatile * pcmd, int); static void run_tdr(int unit, struct ie_tdr_cmd * cmd); static int ierint(int unit, struct ie_softc * ie); static int ietint(int unit, struct ie_softc * ie); static int iernr(int unit, struct ie_softc * ie); static void start_receiver(int unit); static __inline int ieget(int, struct ie_softc *, struct mbuf **, struct ether_header *, int *); static caddr_t setup_rfa(caddr_t ptr, struct ie_softc * ie); static int mc_setup(int, caddr_t, volatile struct ie_sys_ctl_block *); static void ie_mc_reset(int unit); #ifdef DEBUG static void print_rbd(volatile struct ie_recv_buf_desc * rbd); static int in_ierint = 0; static int in_ietint = 0; #endif /* * This tells the autoconf code how to set us up. */ struct isa_driver iedriver = { ieprobe, ieattach, "ie", }; enum ie_hardware { IE_STARLAN10, IE_EN100, IE_SLFIBER, IE_3C507, IE_NI5210, IE_EE16, IE_UNKNOWN }; static const char *ie_hardware_names[] = { "StarLAN 10", "EN100", "StarLAN Fiber", "3C507", "NI5210", "EtherExpress 16", "Unknown" }; /* sizeof(iscp) == 1+1+2+4 == 8 sizeof(scb) == 2+2+2+2+2+2+2+2 == 16 NFRAMES * sizeof(rfd) == NFRAMES*(2+2+2+2+6+6+2+2) == NFRAMES*24 == 384 sizeof(xmit_cmd) == 2+2+2+2+6+2 == 18 sizeof(transmit buffer) == 1512 sizeof(transmit buffer desc) == 8 ----- 1946 NRXBUFS * sizeof(rbd) == NRXBUFS*(2+2+4+2+2) == NRXBUFS*12 NRXBUFS * IE_RBUF_SIZE == NRXBUFS*256 NRXBUFS should be (16384 - 1946) / (256 + 12) == 14438 / 268 == 53 With NRXBUFS == 48, this leaves us 1574 bytes for another command or more buffers. Another transmit command would be 18+8+1512 == 1538 ---just barely fits! Obviously all these would have to be reduced for smaller memory sizes. With a larger memory, it would be possible to roughly double the number of both transmit and receive buffers. */ #define NFRAMES 8 /* number of receive frames */ #define NRXBUFS 48 /* number of buffers to allocate */ #define IE_RBUF_SIZE 256 /* size of each buffer, MUST BE POWER OF TWO */ #define NTXBUFS 2 /* number of transmit commands */ #define IE_TBUF_SIZE ETHER_MAX_LEN /* size of transmit buffer */ /* * Ethernet status, per interface. */ static struct ie_softc { struct arpcom arpcom; void (*ie_reset_586) (int); void (*ie_chan_attn) (int); enum ie_hardware hard_type; int hard_vers; u_short port; /* i/o base address for this interface */ caddr_t iomem; /* memory size */ caddr_t iomembot; /* memory base address */ unsigned iosize; int bus_use; /* 0 means 16bit, 1 means 8 bit adapter */ int want_mcsetup; int promisc; int nframes; int nrxbufs; int ntxbufs; volatile struct ie_int_sys_conf_ptr *iscp; volatile struct ie_sys_ctl_block *scb; volatile struct ie_recv_frame_desc **rframes; /* nframes worth */ volatile struct ie_recv_buf_desc **rbuffs; /* nrxbufs worth */ volatile u_char **cbuffs; /* nrxbufs worth */ int rfhead, rftail, rbhead, rbtail; volatile struct ie_xmit_cmd **xmit_cmds; /* ntxbufs worth */ volatile struct ie_xmit_buf **xmit_buffs; /* ntxbufs worth */ u_char **xmit_cbuffs; /* ntxbufs worth */ int xmit_count; struct ie_en_addr mcast_addrs[MAXMCAST + 1]; int mcast_count; u_short irq_encoded; /* encoded interrupt on IEE16 */ } ie_softc[NIE]; -#define MK_24(base, ptr) ((caddr_t)((u_long)ptr - (u_long)base)) -#define MK_16(base, ptr) ((u_short)(u_long)MK_24(base, ptr)) +#define MK_24(base, ptr) ((caddr_t)((uintptr_t)ptr - (uintptr_t)base)) +#define MK_16(base, ptr) ((u_short)(uintptr_t)MK_24(base, ptr)) #define PORT ie_softc[unit].port #define MEM ie_softc[unit].iomem int ieprobe(struct isa_device *dvp) { int ret; ret = sl_probe(dvp); if (!ret) ret = el_probe(dvp); if (!ret) ret = ni_probe(dvp); if (!ret) ret = ee16_probe(dvp); return (ret); } static int sl_probe(struct isa_device *dvp) { int unit = dvp->id_unit; u_char c; ie_softc[unit].port = dvp->id_iobase; ie_softc[unit].iomembot = dvp->id_maddr; ie_softc[unit].iomem = 0; ie_softc[unit].bus_use = 0; c = inb(PORT + IEATT_REVISION); switch (SL_BOARD(c)) { case SL10_BOARD: ie_softc[unit].hard_type = IE_STARLAN10; ie_softc[unit].ie_reset_586 = sl_reset_586; ie_softc[unit].ie_chan_attn = sl_chan_attn; break; case EN100_BOARD: ie_softc[unit].hard_type = IE_EN100; ie_softc[unit].ie_reset_586 = sl_reset_586; ie_softc[unit].ie_chan_attn = sl_chan_attn; break; case SLFIBER_BOARD: ie_softc[unit].hard_type = IE_SLFIBER; ie_softc[unit].ie_reset_586 = sl_reset_586; ie_softc[unit].ie_chan_attn = sl_chan_attn; break; /* * Anything else is not recognized or cannot be used. */ default: return (0); } ie_softc[unit].hard_vers = SL_REV(c); /* * Divine memory size on-board the card. Ususally 16k. */ find_ie_mem_size(unit); if (!ie_softc[unit].iosize) { return (0); } dvp->id_msize = ie_softc[unit].iosize; switch (ie_softc[unit].hard_type) { case IE_EN100: case IE_STARLAN10: case IE_SLFIBER: sl_read_ether(unit, ie_softc[unit].arpcom.ac_enaddr); break; default: if (bootverbose) printf("ie%d: unknown AT&T board type code %d\n", unit, ie_softc[unit].hard_type); return (0); } return (1); } static int el_probe(struct isa_device *dvp) { struct ie_softc *sc = &ie_softc[dvp->id_unit]; u_char c; int i; u_char signature[] = "*3COM*"; int unit = dvp->id_unit; sc->port = dvp->id_iobase; sc->iomembot = dvp->id_maddr; sc->bus_use = 0; /* Need this for part of the probe. */ sc->ie_reset_586 = el_reset_586; sc->ie_chan_attn = el_chan_attn; /* Reset and put card in CONFIG state without changing address. */ elink_reset(); outb(ELINK_ID_PORT, 0x00); elink_idseq(ELINK_507_POLY); elink_idseq(ELINK_507_POLY); outb(ELINK_ID_PORT, 0xff); c = inb(PORT + IE507_MADDR); if (c & 0x20) { #ifdef DEBUG printf("ie%d: can't map 3C507 RAM in high memory\n", unit); #endif return (0); } /* go to RUN state */ outb(ELINK_ID_PORT, 0x00); elink_idseq(ELINK_507_POLY); outb(ELINK_ID_PORT, 0x00); outb(PORT + IE507_CTRL, EL_CTRL_NRST); for (i = 0; i < 6; i++) if (inb(PORT + i) != signature[i]) return (0); c = inb(PORT + IE507_IRQ) & 0x0f; if (dvp->id_irq != (1 << c)) { printf("ie%d: kernel configured irq %d " "doesn't match board configured irq %d\n", unit, ffs(dvp->id_irq) - 1, c); return (0); } c = (inb(PORT + IE507_MADDR) & 0x1c) + 0xc0; if (kvtop(dvp->id_maddr) != ((int) c << 12)) { printf("ie%d: kernel configured maddr %lx " "doesn't match board configured maddr %x\n", unit, kvtop(dvp->id_maddr), (int) c << 12); return (0); } outb(PORT + IE507_CTRL, EL_CTRL_NORMAL); sc->hard_type = IE_3C507; sc->hard_vers = 0; /* 3C507 has no version number. */ /* * Divine memory size on-board the card. */ find_ie_mem_size(unit); if (!sc->iosize) { printf("ie%d: can't find shared memory\n", unit); outb(PORT + IE507_CTRL, EL_CTRL_NRST); return (0); } if (!dvp->id_msize) dvp->id_msize = sc->iosize; else if (dvp->id_msize != sc->iosize) { printf("ie%d: kernel configured msize %d " "doesn't match board configured msize %d\n", unit, dvp->id_msize, sc->iosize); outb(PORT + IE507_CTRL, EL_CTRL_NRST); return (0); } sl_read_ether(unit, ie_softc[unit].arpcom.ac_enaddr); /* Clear the interrupt latch just in case. */ outb(PORT + IE507_ICTRL, 1); return (16); } static int ni_probe(struct isa_device *dvp) { int unit = dvp->id_unit; int boardtype, c; ie_softc[unit].port = dvp->id_iobase; ie_softc[unit].iomembot = dvp->id_maddr; ie_softc[unit].iomem = 0; ie_softc[unit].bus_use = 1; boardtype = inb(PORT + IEATT_REVISION); c = inb(PORT + IEATT_REVISION + 1); boardtype = boardtype + (c << 8); switch (boardtype) { case 0x5500: /* This is the magic cookie for the NI5210 */ ie_softc[unit].hard_type = IE_NI5210; ie_softc[unit].ie_reset_586 = sl_reset_586; ie_softc[unit].ie_chan_attn = sl_chan_attn; break; /* * Anything else is not recognized or cannot be used. */ default: return (0); } ie_softc[unit].hard_vers = 0; /* * Divine memory size on-board the card. Either 8 or 16k. */ find_ie_mem_size(unit); if (!ie_softc[unit].iosize) { return (0); } if (!dvp->id_msize) dvp->id_msize = ie_softc[unit].iosize; else if (dvp->id_msize != ie_softc[unit].iosize) { printf("ie%d: kernel configured msize %d " "doesn't match board configured msize %d\n", unit, dvp->id_msize, ie_softc[unit].iosize); return (0); } sl_read_ether(unit, ie_softc[unit].arpcom.ac_enaddr); return (8); } static void ee16_shutdown(int howto, void *sc) { struct ie_softc *ie = (struct ie_softc *)sc; int unit = ie - &ie_softc[0]; ee16_reset_586(unit); outb(PORT + IEE16_ECTRL, IEE16_RESET_ASIC); outb(PORT + IEE16_ECTRL, 0); } /* Taken almost exactly from Rod's if_ix.c. */ int ee16_probe(struct isa_device *dvp) { struct ie_softc *sc = &ie_softc[dvp->id_unit]; int i; int unit = dvp->id_unit; u_short board_id, id_var1, id_var2, checksum = 0; u_short eaddrtemp, irq; u_short pg, adjust, decode, edecode; u_char bart_config; u_long bd_maddr; short irq_translate[] = {0, IRQ9, IRQ3, IRQ4, IRQ5, IRQ10, IRQ11, 0}; char irq_encode[] = {0, 0, 0, 2, 3, 4, 0, 0, 0, 1, 5, 6, 0, 0, 0, 0}; /* Need this for part of the probe. */ sc->ie_reset_586 = ee16_reset_586; sc->ie_chan_attn = ee16_chan_attn; /* unsure if this is necessary */ sc->bus_use = 0; /* reset any ee16 at the current iobase */ outb(dvp->id_iobase + IEE16_ECTRL, IEE16_RESET_ASIC); outb(dvp->id_iobase + IEE16_ECTRL, 0); DELAY(240); /* now look for ee16. */ board_id = id_var1 = id_var2 = 0; for (i = 0; i < 4; i++) { id_var1 = inb(dvp->id_iobase + IEE16_ID_PORT); id_var2 = ((id_var1 & 0x03) << 2); board_id |= ((id_var1 >> 4) << id_var2); } if (board_id != IEE16_ID) { printf("ie%d: unknown board_id: %x\n", unit, board_id); return (0); } /* need sc->port for ee16_read_eeprom */ sc->port = dvp->id_iobase; sc->hard_type = IE_EE16; /* * The shared RAM location on the EE16 is encoded into bits 3-7 of * EEPROM location 6. We zero the upper byte, and shift the 5 bits * right 3. The resulting number tells us the RAM location. * Because the EE16 supports either 16k or 32k of shared RAM, we * only worry about the 32k locations. * * NOTE: if a 64k EE16 exists, it should be added to this switch. then * the ia->ia_msize would need to be set per case statement. * * value msize location ===== ===== ======== 0x03 0x8000 * 0xCC000 0x06 0x8000 0xD0000 0x0C 0x8000 0xD4000 0x18 * 0x8000 0xD8000 * */ bd_maddr = 0; i = (ee16_read_eeprom(sc, 6) & 0x00ff) >> 3; switch (i) { case 0x03: bd_maddr = 0xCC000; break; case 0x06: bd_maddr = 0xD0000; break; case 0x0c: bd_maddr = 0xD4000; break; case 0x18: bd_maddr = 0xD8000; break; default: bd_maddr = 0; break; } dvp->id_msize = 0x8000; if (kvtop(dvp->id_maddr) != bd_maddr) { printf("ie%d: kernel configured maddr %lx " "doesn't match board configured maddr %lx\n", unit, kvtop(dvp->id_maddr), bd_maddr); } sc->iomembot = dvp->id_maddr; sc->iomem = 0; /* XXX some probes set this and some don't */ sc->iosize = dvp->id_msize; /* need to put the 586 in RESET while we access the eeprom. */ outb(PORT + IEE16_ECTRL, IEE16_RESET_586); /* read the eeprom and checksum it, should == IEE16_ID */ for (i = 0; i < 0x40; i++) checksum += ee16_read_eeprom(sc, i); if (checksum != IEE16_ID) { printf("ie%d: invalid eeprom checksum: %x\n", unit, checksum); return (0); } /* * Size and test the memory on the board. The size of the memory * can be one of 16k, 32k, 48k or 64k. It can be located in the * address range 0xC0000 to 0xEFFFF on 16k boundaries. * * If the size does not match the passed in memory allocation size * issue a warning, but continue with the minimum of the two sizes. */ switch (dvp->id_msize) { case 65536: case 32768: /* XXX Only support 32k and 64k right now */ break; case 16384: case 49512: default: printf("ie%d: mapped memory size %d not supported\n", unit, dvp->id_msize); return (0); break; /* NOTREACHED */ } if ((kvtop(dvp->id_maddr) < 0xC0000) || (kvtop(dvp->id_maddr) + sc->iosize > 0xF0000)) { printf("ie%d: mapped memory location %p out of range\n", unit, (void *)dvp->id_maddr); return (0); } pg = (kvtop(dvp->id_maddr) & 0x3C000) >> 14; adjust = IEE16_MCTRL_FMCS16 | (pg & 0x3) << 2; decode = ((1 << (sc->iosize / 16384)) - 1) << pg; edecode = ((~decode >> 4) & 0xF0) | (decode >> 8); /* ZZZ This should be checked against eeprom location 6, low byte */ outb(PORT + IEE16_MEMDEC, decode & 0xFF); /* ZZZ This should be checked against eeprom location 1, low byte */ outb(PORT + IEE16_MCTRL, adjust); /* ZZZ Now if I could find this one I would have it made */ outb(PORT + IEE16_MPCTRL, (~decode & 0xFF)); /* ZZZ I think this is location 6, high byte */ outb(PORT + IEE16_MECTRL, edecode); /* XXX disable Exxx */ (void) kvtop(dvp->id_maddr); /* * first prime the stupid bart DRAM controller so that it works, * then zero out all of memory. */ bzero(sc->iomembot, 32); bzero(sc->iomembot, sc->iosize); /* * Get the encoded interrupt number from the EEPROM, check it * against the passed in IRQ. Issue a warning if they do not match. * Always use the passed in IRQ, not the one in the EEPROM. */ irq = ee16_read_eeprom(sc, IEE16_EEPROM_CONFIG1); irq = (irq & IEE16_EEPROM_IRQ) >> IEE16_EEPROM_IRQ_SHIFT; irq = irq_translate[irq]; if (dvp->id_irq > 0) { if (irq != dvp->id_irq) { printf("ie%d: WARNING: board configured " "at irq %u, using %u\n", dvp->id_unit, dvp->id_irq, irq); irq = dvp->id_unit; } } else { dvp->id_irq = irq; } sc->irq_encoded = irq_encode[ffs(irq) - 1]; /* * Get the hardware ethernet address from the EEPROM and save it in * the softc for use by the 586 setup code. */ eaddrtemp = ee16_read_eeprom(sc, IEE16_EEPROM_ENET_HIGH); sc->arpcom.ac_enaddr[1] = eaddrtemp & 0xFF; sc->arpcom.ac_enaddr[0] = eaddrtemp >> 8; eaddrtemp = ee16_read_eeprom(sc, IEE16_EEPROM_ENET_MID); sc->arpcom.ac_enaddr[3] = eaddrtemp & 0xFF; sc->arpcom.ac_enaddr[2] = eaddrtemp >> 8; eaddrtemp = ee16_read_eeprom(sc, IEE16_EEPROM_ENET_LOW); sc->arpcom.ac_enaddr[5] = eaddrtemp & 0xFF; sc->arpcom.ac_enaddr[4] = eaddrtemp >> 8; /* disable the board interrupts */ outb(PORT + IEE16_IRQ, sc->irq_encoded); /* enable loopback to keep bad packets off the wire */ if (sc->hard_type == IE_EE16) { bart_config = inb(PORT + IEE16_CONFIG); bart_config |= IEE16_BART_LOOPBACK; bart_config |= IEE16_BART_MCS16_TEST;/* inb doesn't get bit! */ outb(PORT + IEE16_CONFIG, bart_config); bart_config = inb(PORT + IEE16_CONFIG); } /* take the board out of reset state */ outb(PORT + IEE16_ECTRL, 0); DELAY(100); if (!check_ie_present(unit, dvp->id_maddr, sc->iosize)) return (0); return (16); /* return the number of I/O ports */ } /* * Taken almost exactly from Bill's if_is.c, then modified beyond recognition. */ int ieattach(struct isa_device *dvp) { int factor; int unit = dvp->id_unit; struct ie_softc *ie = &ie_softc[unit]; struct ifnet *ifp = &ie->arpcom.ac_if; size_t allocsize; /* * based on the amount of memory we have, allocate our tx and rx * resources. */ factor = dvp->id_msize / 16384; ie->nframes = factor * NFRAMES; ie->nrxbufs = factor * NRXBUFS; ie->ntxbufs = factor * NTXBUFS; /* * Since all of these guys are arrays of pointers, allocate as one * big chunk and dole out accordingly. */ allocsize = sizeof(void *) * (ie->nframes + (ie->nrxbufs * 2) + (ie->ntxbufs * 3)); ie->rframes = (volatile struct ie_recv_frame_desc **) malloc(allocsize, M_DEVBUF, M_NOWAIT); if (ie->rframes == NULL) return (0); ie->rbuffs = (volatile struct ie_recv_buf_desc **)&ie->rframes[ie->nframes]; ie->cbuffs = (volatile u_char **)&ie->rbuffs[ie->nrxbufs]; ie->xmit_cmds = (volatile struct ie_xmit_cmd **)&ie->cbuffs[ie->nrxbufs]; ie->xmit_buffs = (volatile struct ie_xmit_buf **)&ie->xmit_cmds[ie->ntxbufs]; ie->xmit_cbuffs = (u_char **)&ie->xmit_buffs[ie->ntxbufs]; ifp->if_softc = ie; ifp->if_unit = unit; ifp->if_name = iedriver.name; ifp->if_mtu = ETHERMTU; printf("ie%d: <%s R%d> address %6D\n", unit, ie_hardware_names[ie->hard_type], ie->hard_vers + 1, ie->arpcom.ac_enaddr, ":"); ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; ifp->if_output = ether_output; ifp->if_start = iestart; ifp->if_ioctl = ieioctl; ifp->if_type = IFT_ETHER; ifp->if_addrlen = 6; ifp->if_hdrlen = 14; if (ie->hard_type == IE_EE16) at_shutdown(ee16_shutdown, ie, SHUTDOWN_POST_SYNC); #if NBPFILTER > 0 bpfattach(ifp, DLT_EN10MB, sizeof(struct ether_header)); #endif if_attach(ifp); ether_ifattach(ifp); return (1); } /* * What to do upon receipt of an interrupt. */ void ieintr(int unit) { register struct ie_softc *ie = &ie_softc[unit]; register u_short status; /* Clear the interrupt latch on the 3C507. */ if (ie->hard_type == IE_3C507 && (inb(PORT + IE507_CTRL) & EL_CTRL_INTL)) outb(PORT + IE507_ICTRL, 1); /* disable interrupts on the EE16. */ if (ie->hard_type == IE_EE16) outb(PORT + IEE16_IRQ, ie->irq_encoded); status = ie->scb->ie_status; loop: /* Don't ack interrupts which we didn't receive */ ie_ack(ie->scb, IE_ST_WHENCE & status, unit, ie->ie_chan_attn); if (status & (IE_ST_RECV | IE_ST_RNR)) { #ifdef DEBUG in_ierint++; if (ie_debug & IED_RINT) printf("ie%d: rint\n", unit); #endif ierint(unit, ie); #ifdef DEBUG in_ierint--; #endif } if (status & IE_ST_DONE) { #ifdef DEBUG in_ietint++; if (ie_debug & IED_TINT) printf("ie%d: tint\n", unit); #endif ietint(unit, ie); #ifdef DEBUG in_ietint--; #endif } if (status & IE_ST_RNR) { #ifdef DEBUG if (ie_debug & IED_RNR) printf("ie%d: rnr\n", unit); #endif iernr(unit, ie); } #ifdef DEBUG if ((status & IE_ST_ALLDONE) && (ie_debug & IED_CNA)) printf("ie%d: cna\n", unit); #endif if ((status = ie->scb->ie_status) & IE_ST_WHENCE) goto loop; /* Clear the interrupt latch on the 3C507. */ if (ie->hard_type == IE_3C507) outb(PORT + IE507_ICTRL, 1); /* enable interrupts on the EE16. */ if (ie->hard_type == IE_EE16) outb(PORT + IEE16_IRQ, ie->irq_encoded | IEE16_IRQ_ENABLE); } /* * Process a received-frame interrupt. */ static int ierint(int unit, struct ie_softc *ie) { int i, status; static int timesthru = 1024; i = ie->rfhead; while (1) { status = ie->rframes[i]->ie_fd_status; if ((status & IE_FD_COMPLETE) && (status & IE_FD_OK)) { ie->arpcom.ac_if.if_ipackets++; if (!--timesthru) { ie->arpcom.ac_if.if_ierrors += ie->scb->ie_err_crc + ie->scb->ie_err_align + ie->scb->ie_err_resource + ie->scb->ie_err_overrun; ie->scb->ie_err_crc = 0; ie->scb->ie_err_align = 0; ie->scb->ie_err_resource = 0; ie->scb->ie_err_overrun = 0; timesthru = 1024; } ie_readframe(unit, ie, i); } else { if (status & IE_FD_RNR) { if (!(ie->scb->ie_status & IE_RU_READY)) { ie->rframes[0]->ie_fd_next = MK_16(MEM, ie->rbuffs[0]); ie->scb->ie_recv_list = MK_16(MEM, ie->rframes[0]); command_and_wait(unit, IE_RU_START, 0, 0); } } break; } i = (i + 1) % ie->nframes; } return (0); } /* * Process a command-complete interrupt. These are only generated by * the transmission of frames. This routine is deceptively simple, since * most of the real work is done by iestart(). */ static int ietint(int unit, struct ie_softc *ie) { int status; int i; ie->arpcom.ac_if.if_timer = 0; ie->arpcom.ac_if.if_flags &= ~IFF_OACTIVE; for (i = 0; i < ie->xmit_count; i++) { status = ie->xmit_cmds[i]->ie_xmit_status; if (status & IE_XS_LATECOLL) { printf("ie%d: late collision\n", unit); ie->arpcom.ac_if.if_collisions++; ie->arpcom.ac_if.if_oerrors++; } else if (status & IE_XS_NOCARRIER) { printf("ie%d: no carrier\n", unit); ie->arpcom.ac_if.if_oerrors++; } else if (status & IE_XS_LOSTCTS) { printf("ie%d: lost CTS\n", unit); ie->arpcom.ac_if.if_oerrors++; } else if (status & IE_XS_UNDERRUN) { printf("ie%d: DMA underrun\n", unit); ie->arpcom.ac_if.if_oerrors++; } else if (status & IE_XS_EXCMAX) { printf("ie%d: too many collisions\n", unit); ie->arpcom.ac_if.if_collisions += 16; ie->arpcom.ac_if.if_oerrors++; } else { ie->arpcom.ac_if.if_opackets++; ie->arpcom.ac_if.if_collisions += status & IE_XS_MAXCOLL; } } ie->xmit_count = 0; /* * If multicast addresses were added or deleted while we were * transmitting, ie_mc_reset() set the want_mcsetup flag indicating * that we should do it. */ if (ie->want_mcsetup) { mc_setup(unit, (caddr_t) ie->xmit_cbuffs[0], ie->scb); ie->want_mcsetup = 0; } /* Wish I knew why this seems to be necessary... */ ie->xmit_cmds[0]->ie_xmit_status |= IE_STAT_COMPL; iestart(&ie->arpcom.ac_if); return (0); /* shouldn't be necessary */ } /* * Process a receiver-not-ready interrupt. I believe that we get these * when there aren't enough buffers to go around. For now (FIXME), we * just restart the receiver, and hope everything's ok. */ static int iernr(int unit, struct ie_softc *ie) { #ifdef doesnt_work setup_rfa((caddr_t) ie->rframes[0], ie); ie->scb->ie_recv_list = MK_16(MEM, ie_softc[unit].rframes[0]); command_and_wait(unit, IE_RU_START, 0, 0); #else /* This doesn't work either, but it doesn't hang either. */ command_and_wait(unit, IE_RU_DISABLE, 0, 0); /* just in case */ setup_rfa((caddr_t) ie->rframes[0], ie); /* ignore cast-qual */ ie->scb->ie_recv_list = MK_16(MEM, ie_softc[unit].rframes[0]); command_and_wait(unit, IE_RU_START, 0, 0); /* was ENABLE */ #endif ie_ack(ie->scb, IE_ST_WHENCE, unit, ie->ie_chan_attn); ie->arpcom.ac_if.if_ierrors++; return (0); } /* * Compare two Ether/802 addresses for equality, inlined and * unrolled for speed. I'd love to have an inline assembler * version of this... */ static __inline int ether_equal(u_char * one, u_char * two) { if (one[0] != two[0]) return (0); if (one[1] != two[1]) return (0); if (one[2] != two[2]) return (0); if (one[3] != two[3]) return (0); if (one[4] != two[4]) return (0); if (one[5] != two[5]) return (0); return 1; } /* * Check for a valid address. to_bpf is filled in with one of the following: * 0 -> BPF doesn't get this packet * 1 -> BPF does get this packet * 2 -> BPF does get this packet, but we don't * Return value is true if the packet is for us, and false otherwise. * * This routine is a mess, but it's also critical that it be as fast * as possible. It could be made cleaner if we can assume that the * only client which will fiddle with IFF_PROMISC is BPF. This is * probably a good assumption, but we do not make it here. (Yet.) */ static __inline int check_eh(struct ie_softc * ie, struct ether_header * eh, int *to_bpf) { int i; switch (ie->promisc) { case IFF_ALLMULTI: /* * Receiving all multicasts, but no unicasts except those * destined for us. */ #if NBPFILTER > 0 /* BPF gets this packet if anybody cares */ *to_bpf = (ie->arpcom.ac_if.if_bpf != 0); #endif if (eh->ether_dhost[0] & 1) { return (1); } if (ether_equal(eh->ether_dhost, ie->arpcom.ac_enaddr)) return (1); return (0); case IFF_PROMISC: /* * Receiving all packets. These need to be passed on to * BPF. */ #if NBPFILTER > 0 *to_bpf = (ie->arpcom.ac_if.if_bpf != 0); #endif /* If for us, accept and hand up to BPF */ if (ether_equal(eh->ether_dhost, ie->arpcom.ac_enaddr)) return (1); #if NBPFILTER > 0 if (*to_bpf) *to_bpf = 2; /* we don't need to see it */ #endif /* * Not a multicast, so BPF wants to see it but we don't. */ if (!(eh->ether_dhost[0] & 1)) return (1); /* * If it's one of our multicast groups, accept it and pass * it up. */ for (i = 0; i < ie->mcast_count; i++) { if (ether_equal(eh->ether_dhost, (u_char *)&ie->mcast_addrs[i])) { #if NBPFILTER > 0 if (*to_bpf) *to_bpf = 1; #endif return (1); } } return (1); case IFF_ALLMULTI | IFF_PROMISC: /* * Acting as a multicast router, and BPF running at the same * time. Whew! (Hope this is a fast machine...) */ #if NBPFILTER > 0 *to_bpf = (ie->arpcom.ac_if.if_bpf != 0); #endif /* We want to see multicasts. */ if (eh->ether_dhost[0] & 1) return (1); /* We want to see our own packets */ if (ether_equal(eh->ether_dhost, ie->arpcom.ac_enaddr)) return (1); /* Anything else goes to BPF but nothing else. */ #if NBPFILTER > 0 if (*to_bpf) *to_bpf = 2; #endif return (1); default: /* * Only accept unicast packets destined for us, or * multicasts for groups that we belong to. For now, we * assume that the '586 will only return packets that we * asked it for. This isn't strictly true (it uses hashing * for the multicast filter), but it will do in this case, * and we want to get out of here as quickly as possible. */ #if NBPFILTER > 0 *to_bpf = (ie->arpcom.ac_if.if_bpf != 0); #endif return (1); } return (0); } /* * We want to isolate the bits that have meaning... This assumes that * IE_RBUF_SIZE is an even power of two. If somehow the act_len exceeds * the size of the buffer, then we are screwed anyway. */ static __inline int ie_buflen(struct ie_softc * ie, int head) { return (ie->rbuffs[head]->ie_rbd_actual & (IE_RBUF_SIZE | (IE_RBUF_SIZE - 1))); } static __inline int ie_packet_len(int unit, struct ie_softc * ie) { int i; int head = ie->rbhead; int acc = 0; do { if (!(ie->rbuffs[ie->rbhead]->ie_rbd_actual & IE_RBD_USED)) { #ifdef DEBUG print_rbd(ie->rbuffs[ie->rbhead]); #endif log(LOG_ERR, "ie%d: receive descriptors out of sync at %d\n", unit, ie->rbhead); iereset(unit); return (-1); } i = ie->rbuffs[head]->ie_rbd_actual & IE_RBD_LAST; acc += ie_buflen(ie, head); head = (head + 1) % ie->nrxbufs; } while (!i); return (acc); } /* * Read data off the interface, and turn it into an mbuf chain. * * This code is DRAMATICALLY different from the previous version; this * version tries to allocate the entire mbuf chain up front, given the * length of the data available. This enables us to allocate mbuf * clusters in many situations where before we would have had a long * chain of partially-full mbufs. This should help to speed up the * operation considerably. (Provided that it works, of course.) */ static __inline int ieget(int unit, struct ie_softc *ie, struct mbuf **mp, struct ether_header *ehp, int *to_bpf) { struct mbuf *m, *top, **mymp; int i; int offset; int totlen, resid; int thismboff; int head; totlen = ie_packet_len(unit, ie); if (totlen <= 0) return (-1); i = ie->rbhead; /* * Snarf the Ethernet header. */ bcopy((caddr_t) ie->cbuffs[i], (caddr_t) ehp, sizeof *ehp); /* ignore cast-qual warning here */ /* * As quickly as possible, check if this packet is for us. If not, * don't waste a single cycle copying the rest of the packet in. * This is only a consideration when FILTER is defined; i.e., when * we are either running BPF or doing multicasting. */ if (!check_eh(ie, ehp, to_bpf)) { ie_drop_packet_buffer(unit, ie); ie->arpcom.ac_if.if_ierrors--; /* just this case, it's not an * error */ return (-1); } totlen -= (offset = sizeof *ehp); MGETHDR(*mp, M_DONTWAIT, MT_DATA); if (!*mp) { ie_drop_packet_buffer(unit, ie); return (-1); } m = *mp; m->m_pkthdr.rcvif = &ie->arpcom.ac_if; m->m_len = MHLEN; resid = m->m_pkthdr.len = totlen; top = 0; mymp = ⊤ /* * This loop goes through and allocates mbufs for all the data we * will be copying in. It does not actually do the copying yet. */ do { /* while(resid > 0) */ /* * Try to allocate an mbuf to hold the data that we have. * If we already allocated one, just get another one and * stick it on the end (eventually). If we don't already * have one, try to allocate an mbuf cluster big enough to * hold the whole packet, if we think it's reasonable, or a * single mbuf which may or may not be big enough. Got that? */ if (top) { MGET(m, M_DONTWAIT, MT_DATA); if (!m) { m_freem(top); ie_drop_packet_buffer(unit, ie); return (-1); } m->m_len = MLEN; } if (resid >= MINCLSIZE) { MCLGET(m, M_DONTWAIT); if (m->m_flags & M_EXT) m->m_len = min(resid, MCLBYTES); } else { if (resid < m->m_len) { if (!top && resid + max_linkhdr <= m->m_len) m->m_data += max_linkhdr; m->m_len = resid; } } resid -= m->m_len; *mymp = m; mymp = &m->m_next; } while (resid > 0); resid = totlen; m = top; thismboff = 0; head = ie->rbhead; /* * Now we take the mbuf chain (hopefully only one mbuf most of the * time) and stuff the data into it. There are no possible failures * at or after this point. */ while (resid > 0) { /* while there's stuff left */ int thislen = ie_buflen(ie, head) - offset; /* * If too much data for the current mbuf, then fill the * current one up, go to the next one, and try again. */ if (thislen > m->m_len - thismboff) { int newlen = m->m_len - thismboff; bcopy((caddr_t) (ie->cbuffs[head] + offset), mtod(m, caddr_t) +thismboff, (unsigned) newlen); /* ignore cast-qual warning */ m = m->m_next; thismboff = 0; /* new mbuf, so no offset */ offset += newlen; /* we are now this far into * the packet */ resid -= newlen; /* so there is this much left * to get */ continue; } /* * If there is more than enough space in the mbuf to hold * the contents of this buffer, copy everything in, advance * pointers, and so on. */ if (thislen < m->m_len - thismboff) { bcopy((caddr_t) (ie->cbuffs[head] + offset), mtod(m, caddr_t) +thismboff, (unsigned) thislen); thismboff += thislen; /* we are this far into the * mbuf */ resid -= thislen; /* and this much is left */ goto nextbuf; } /* * Otherwise, there is exactly enough space to put this * buffer's contents into the current mbuf. Do the * combination of the above actions. */ bcopy((caddr_t) (ie->cbuffs[head] + offset), mtod(m, caddr_t) + thismboff, (unsigned) thislen); m = m->m_next; thismboff = 0; /* new mbuf, start at the beginning */ resid -= thislen; /* and we are this far through */ /* * Advance all the pointers. We can get here from either of * the last two cases, but never the first. */ nextbuf: offset = 0; ie->rbuffs[head]->ie_rbd_actual = 0; ie->rbuffs[head]->ie_rbd_length |= IE_RBD_LAST; ie->rbhead = head = (head + 1) % ie->nrxbufs; ie->rbuffs[ie->rbtail]->ie_rbd_length &= ~IE_RBD_LAST; ie->rbtail = (ie->rbtail + 1) % ie->nrxbufs; } /* * Unless something changed strangely while we were doing the copy, * we have now copied everything in from the shared memory. This * means that we are done. */ return (0); } /* * Read frame NUM from unit UNIT (pre-cached as IE). * * This routine reads the RFD at NUM, and copies in the buffers from * the list of RBD, then rotates the RBD and RFD lists so that the receiver * doesn't start complaining. Trailers are DROPPED---there's no point * in wasting time on confusing code to deal with them. Hopefully, * this machine will never ARP for trailers anyway. */ static void ie_readframe(int unit, struct ie_softc *ie, int num/* frame number to read */) { struct ie_recv_frame_desc rfd; struct mbuf *m = 0; struct ether_header eh; #if NBPFILTER > 0 int bpf_gets_it = 0; #endif bcopy((caddr_t) (ie->rframes[num]), &rfd, sizeof(struct ie_recv_frame_desc)); /* * Immediately advance the RFD list, since we we have copied ours * now. */ ie->rframes[num]->ie_fd_status = 0; ie->rframes[num]->ie_fd_last |= IE_FD_LAST; ie->rframes[ie->rftail]->ie_fd_last &= ~IE_FD_LAST; ie->rftail = (ie->rftail + 1) % ie->nframes; ie->rfhead = (ie->rfhead + 1) % ie->nframes; if (rfd.ie_fd_status & IE_FD_OK) { #if NBPFILTER > 0 if (ieget(unit, ie, &m, &eh, &bpf_gets_it)) { #else if (ieget(unit, ie, &m, &eh, (int *)0)) { #endif ie->arpcom.ac_if.if_ierrors++; /* this counts as an * error */ return; } } #ifdef DEBUG if (ie_debug & IED_READFRAME) { printf("ie%d: frame from ether %6D type %x\n", unit, eh.ether_shost, ":", (unsigned) eh.ether_type); } if (ntohs(eh.ether_type) > ETHERTYPE_TRAIL && ntohs(eh.ether_type) < (ETHERTYPE_TRAIL + ETHERTYPE_NTRAILER)) printf("received trailer!\n"); #endif if (!m) return; if (last_not_for_us) { m_freem(last_not_for_us); last_not_for_us = 0; } #if NBPFILTER > 0 /* * Check for a BPF filter; if so, hand it up. Note that we have to * stick an extra mbuf up front, because bpf_mtap expects to have * the ether header at the front. It doesn't matter that this * results in an ill-formatted mbuf chain, since BPF just looks at * the data. (It doesn't try to free the mbuf, tho' it will make a * copy for tcpdump.) */ if (bpf_gets_it) { struct mbuf m0; m0.m_len = sizeof eh; m0.m_data = (caddr_t)&eh; m0.m_next = m; /* Pass it up */ bpf_mtap(&ie->arpcom.ac_if, &m0); } /* * A signal passed up from the filtering code indicating that the * packet is intended for BPF but not for the protocol machinery. We * can save a few cycles by not handing it off to them. */ if (bpf_gets_it == 2) { last_not_for_us = m; return; } #endif /* NBPFILTER > 0 */ /* * In here there used to be code to check destination addresses upon * receipt of a packet. We have deleted that code, and replaced it * with code to check the address much earlier in the cycle, before * copying the data in; this saves us valuable cycles when operating * as a multicast router or when using BPF. */ /* * Finally pass this packet up to higher layers. */ ether_input(&ie->arpcom.ac_if, &eh, m); } static void ie_drop_packet_buffer(int unit, struct ie_softc * ie) { int i; do { /* * This means we are somehow out of sync. So, we reset the * adapter. */ if (!(ie->rbuffs[ie->rbhead]->ie_rbd_actual & IE_RBD_USED)) { #ifdef DEBUG print_rbd(ie->rbuffs[ie->rbhead]); #endif log(LOG_ERR, "ie%d: receive descriptors out of sync at %d\n", unit, ie->rbhead); iereset(unit); return; } i = ie->rbuffs[ie->rbhead]->ie_rbd_actual & IE_RBD_LAST; ie->rbuffs[ie->rbhead]->ie_rbd_length |= IE_RBD_LAST; ie->rbuffs[ie->rbhead]->ie_rbd_actual = 0; ie->rbhead = (ie->rbhead + 1) % ie->nrxbufs; ie->rbuffs[ie->rbtail]->ie_rbd_length &= ~IE_RBD_LAST; ie->rbtail = (ie->rbtail + 1) % ie->nrxbufs; } while (!i); } /* * Start transmission on an interface. */ static void iestart(struct ifnet *ifp) { struct ie_softc *ie = ifp->if_softc; struct mbuf *m0, *m; unsigned char *buffer; u_short len; /* * This is not really volatile, in this routine, but it makes gcc * happy. */ volatile u_short *bptr = &ie->scb->ie_command_list; if (!(ifp->if_flags & IFF_RUNNING)) return; if (ifp->if_flags & IFF_OACTIVE) return; do { IF_DEQUEUE(&ie->arpcom.ac_if.if_snd, m); if (!m) break; buffer = ie->xmit_cbuffs[ie->xmit_count]; len = 0; for (m0 = m; m && len < IE_BUF_LEN; m = m->m_next) { bcopy(mtod(m, caddr_t), buffer, m->m_len); buffer += m->m_len; len += m->m_len; } m_freem(m0); len = max(len, ETHER_MIN_LEN); #if NBPFILTER > 0 /* * See if bpf is listening on this interface, let it see the * packet before we commit it to the wire. */ if (ie->arpcom.ac_if.if_bpf) bpf_tap(&ie->arpcom.ac_if, ie->xmit_cbuffs[ie->xmit_count], len); #endif ie->xmit_buffs[ie->xmit_count]->ie_xmit_flags = IE_XMIT_LAST|len; ie->xmit_buffs[ie->xmit_count]->ie_xmit_next = 0xffff; ie->xmit_buffs[ie->xmit_count]->ie_xmit_buf = MK_24(ie->iomem, ie->xmit_cbuffs[ie->xmit_count]); ie->xmit_cmds[ie->xmit_count]->com.ie_cmd_cmd = IE_CMD_XMIT; ie->xmit_cmds[ie->xmit_count]->ie_xmit_status = 0; ie->xmit_cmds[ie->xmit_count]->ie_xmit_desc = MK_16(ie->iomem, ie->xmit_buffs[ie->xmit_count]); *bptr = MK_16(ie->iomem, ie->xmit_cmds[ie->xmit_count]); bptr = &ie->xmit_cmds[ie->xmit_count]->com.ie_cmd_link; ie->xmit_count++; } while (ie->xmit_count < ie->ntxbufs); /* * If we queued up anything for transmission, send it. */ if (ie->xmit_count) { ie->xmit_cmds[ie->xmit_count - 1]->com.ie_cmd_cmd |= IE_CMD_LAST | IE_CMD_INTR; /* * By passing the command pointer as a null, we tell * command_and_wait() to pretend that this isn't an action * command. I wish I understood what was happening here. */ command_and_wait(ifp->if_unit, IE_CU_START, 0, 0); ifp->if_flags |= IFF_OACTIVE; } return; } /* * Check to see if there's an 82586 out there. */ static int check_ie_present(int unit, caddr_t where, unsigned size) { volatile struct ie_sys_conf_ptr *scp; volatile struct ie_int_sys_conf_ptr *iscp; volatile struct ie_sys_ctl_block *scb; u_long realbase; int s; s = splimp(); - realbase = (u_long) where + size - (1 << 24); + realbase = (uintptr_t) where + size - (1 << 24); - scp = (volatile struct ie_sys_conf_ptr *) (realbase + IE_SCP_ADDR); + scp = (volatile struct ie_sys_conf_ptr *) (uintptr_t) + (realbase + IE_SCP_ADDR); bzero((char *) scp, sizeof *scp); /* * First we put the ISCP at the bottom of memory; this tests to make * sure that our idea of the size of memory is the same as the * controller's. This is NOT where the ISCP will be in normal * operation. */ iscp = (volatile struct ie_int_sys_conf_ptr *) where; bzero((char *)iscp, sizeof *iscp); scb = (volatile struct ie_sys_ctl_block *) where; bzero((char *)scb, sizeof *scb); scp->ie_bus_use = ie_softc[unit].bus_use; /* 8-bit or 16-bit */ scp->ie_iscp_ptr = (caddr_t) ((volatile caddr_t) iscp - - (volatile caddr_t) realbase); + (volatile caddr_t) (volatile uintptr_t) + realbase); iscp->ie_busy = 1; iscp->ie_scb_offset = MK_16(realbase, scb) + 256; (*ie_softc[unit].ie_reset_586) (unit); (*ie_softc[unit].ie_chan_attn) (unit); DELAY(100); /* wait a while... */ if (iscp->ie_busy) { splx(s); return (0); } /* * Now relocate the ISCP to its real home, and reset the controller * again. */ - iscp = (void *) Align((caddr_t) (realbase + IE_SCP_ADDR - - sizeof(struct ie_int_sys_conf_ptr))); + iscp = (void *) Align((caddr_t) (uintptr_t) + (realbase + IE_SCP_ADDR - + sizeof(struct ie_int_sys_conf_ptr))); bzero((char *) iscp, sizeof *iscp); /* ignore cast-qual */ - scp->ie_iscp_ptr = (caddr_t) ((caddr_t) iscp - (caddr_t) realbase); + scp->ie_iscp_ptr = (caddr_t) ((caddr_t) iscp - + (caddr_t) (uintptr_t) realbase); /* ignore cast-qual */ iscp->ie_busy = 1; iscp->ie_scb_offset = MK_16(realbase, scb); (*ie_softc[unit].ie_reset_586) (unit); (*ie_softc[unit].ie_chan_attn) (unit); DELAY(100); if (iscp->ie_busy) { splx(s); return (0); } ie_softc[unit].iosize = size; - ie_softc[unit].iomem = (caddr_t) realbase; + ie_softc[unit].iomem = (caddr_t) (uintptr_t) realbase; ie_softc[unit].iscp = iscp; ie_softc[unit].scb = scb; /* * Acknowledge any interrupts we may have caused... */ ie_ack(scb, IE_ST_WHENCE, unit, ie_softc[unit].ie_chan_attn); splx(s); return (1); } /* * Divine the memory size of ie board UNIT. * Better hope there's nothing important hiding just below the ie card... */ static void find_ie_mem_size(int unit) { unsigned size; ie_softc[unit].iosize = 0; for (size = 65536; size >= 8192; size -= 8192) { if (check_ie_present(unit, ie_softc[unit].iomembot, size)) { return; } } return; } void el_reset_586(int unit) { outb(PORT + IE507_CTRL, EL_CTRL_RESET); DELAY(100); outb(PORT + IE507_CTRL, EL_CTRL_NORMAL); DELAY(100); } void sl_reset_586(int unit) { outb(PORT + IEATT_RESET, 0); } void ee16_reset_586(int unit) { outb(PORT + IEE16_ECTRL, IEE16_RESET_586); DELAY(100); outb(PORT + IEE16_ECTRL, 0); DELAY(100); } void el_chan_attn(int unit) { outb(PORT + IE507_ATTN, 1); } void sl_chan_attn(int unit) { outb(PORT + IEATT_ATTN, 0); } void ee16_chan_attn(int unit) { outb(PORT + IEE16_ATTN, 0); } u_short ee16_read_eeprom(struct ie_softc *sc, int location) { int ectrl, edata; ectrl = inb(sc->port + IEE16_ECTRL); ectrl &= IEE16_ECTRL_MASK; ectrl |= IEE16_ECTRL_EECS; outb(sc->port + IEE16_ECTRL, ectrl); ee16_eeprom_outbits(sc, IEE16_EEPROM_READ, IEE16_EEPROM_OPSIZE1); ee16_eeprom_outbits(sc, location, IEE16_EEPROM_ADDR_SIZE); edata = ee16_eeprom_inbits(sc); ectrl = inb(sc->port + IEE16_ECTRL); ectrl &= ~(IEE16_RESET_ASIC | IEE16_ECTRL_EEDI | IEE16_ECTRL_EECS); outb(sc->port + IEE16_ECTRL, ectrl); ee16_eeprom_clock(sc, 1); ee16_eeprom_clock(sc, 0); return edata; } void ee16_eeprom_outbits(struct ie_softc *sc, int edata, int count) { int ectrl, i; ectrl = inb(sc->port + IEE16_ECTRL); ectrl &= ~IEE16_RESET_ASIC; for (i = count - 1; i >= 0; i--) { ectrl &= ~IEE16_ECTRL_EEDI; if (edata & (1 << i)) { ectrl |= IEE16_ECTRL_EEDI; } outb(sc->port + IEE16_ECTRL, ectrl); DELAY(1); /* eeprom data must be setup for 0.4 uSec */ ee16_eeprom_clock(sc, 1); ee16_eeprom_clock(sc, 0); } ectrl &= ~IEE16_ECTRL_EEDI; outb(sc->port + IEE16_ECTRL, ectrl); DELAY(1); /* eeprom data must be held for 0.4 uSec */ } int ee16_eeprom_inbits(struct ie_softc *sc) { int ectrl, edata, i; ectrl = inb(sc->port + IEE16_ECTRL); ectrl &= ~IEE16_RESET_ASIC; for (edata = 0, i = 0; i < 16; i++) { edata = edata << 1; ee16_eeprom_clock(sc, 1); ectrl = inb(sc->port + IEE16_ECTRL); if (ectrl & IEE16_ECTRL_EEDO) { edata |= 1; } ee16_eeprom_clock(sc, 0); } return (edata); } void ee16_eeprom_clock(struct ie_softc *sc, int state) { int ectrl; ectrl = inb(sc->port + IEE16_ECTRL); ectrl &= ~(IEE16_RESET_ASIC | IEE16_ECTRL_EESK); if (state) { ectrl |= IEE16_ECTRL_EESK; } outb(sc->port + IEE16_ECTRL, ectrl); DELAY(9); /* EESK must be stable for 8.38 uSec */ } static __inline void ee16_interrupt_enable(struct ie_softc *sc) { DELAY(100); outb(sc->port + IEE16_IRQ, sc->irq_encoded | IEE16_IRQ_ENABLE); DELAY(100); } void sl_read_ether(int unit, unsigned char addr[6]) { int i; for (i = 0; i < 6; i++) addr[i] = inb(PORT + i); } static void iereset(int unit) { int s = splimp(); if (unit >= NIE) { splx(s); return; } printf("ie%d: reset\n", unit); ie_softc[unit].arpcom.ac_if.if_flags &= ~IFF_UP; ieioctl(&ie_softc[unit].arpcom.ac_if, SIOCSIFFLAGS, 0); /* * Stop i82586 dead in its tracks. */ if (command_and_wait(unit, IE_RU_ABORT | IE_CU_ABORT, 0, 0)) printf("ie%d: abort commands timed out\n", unit); if (command_and_wait(unit, IE_RU_DISABLE | IE_CU_STOP, 0, 0)) printf("ie%d: disable commands timed out\n", unit); #ifdef notdef if (!check_ie_present(unit, ie_softc[unit].iomembot, e_softc[unit].iosize)) panic("ie disappeared!"); #endif ie_softc[unit].arpcom.ac_if.if_flags |= IFF_UP; ieioctl(&ie_softc[unit].arpcom.ac_if, SIOCSIFFLAGS, 0); splx(s); return; } /* * This is called if we time out. */ static void chan_attn_timeout(void *rock) { *(int *) rock = 1; } /* * Send a command to the controller and wait for it to either * complete or be accepted, depending on the command. If the * command pointer is null, then pretend that the command is * not an action command. If the command pointer is not null, * and the command is an action command, wait for * ((volatile struct ie_cmd_common *)pcmd)->ie_cmd_status & MASK * to become true. */ static int command_and_wait(int unit, int cmd, volatile void *pcmd, int mask) { volatile struct ie_cmd_common *cc = pcmd; volatile int timedout = 0; struct callout_handle ch; ie_softc[unit].scb->ie_command = (u_short) cmd; if (IE_ACTION_COMMAND(cmd) && pcmd) { (*ie_softc[unit].ie_chan_attn) (unit); /* * According to the packet driver, the minimum timeout * should be .369 seconds, which we round up to .37. */ ch = timeout(chan_attn_timeout, (caddr_t)&timedout, 37 * hz / 100); /* ignore cast-qual */ /* * Now spin-lock waiting for status. This is not a very * nice thing to do, but I haven't figured out how, or * indeed if, we can put the process waiting for action to * sleep. (We may be getting called through some other * timeout running in the kernel.) */ while (1) { if ((cc->ie_cmd_status & mask) || timedout) break; } untimeout(chan_attn_timeout, (caddr_t)&timedout, ch); /* ignore cast-qual */ return (timedout); } else { /* * Otherwise, just wait for the command to be accepted. */ (*ie_softc[unit].ie_chan_attn) (unit); while (ie_softc[unit].scb->ie_command); /* spin lock */ return (0); } } /* * Run the time-domain reflectometer... */ static void run_tdr(int unit, struct ie_tdr_cmd *cmd) { int result; cmd->com.ie_cmd_status = 0; cmd->com.ie_cmd_cmd = IE_CMD_TDR | IE_CMD_LAST; cmd->com.ie_cmd_link = 0xffff; cmd->ie_tdr_time = 0; ie_softc[unit].scb->ie_command_list = MK_16(MEM, cmd); cmd->ie_tdr_time = 0; if (command_and_wait(unit, IE_CU_START, cmd, IE_STAT_COMPL)) result = 0x2000; else result = cmd->ie_tdr_time; ie_ack(ie_softc[unit].scb, IE_ST_WHENCE, unit, ie_softc[unit].ie_chan_attn); if (result & IE_TDR_SUCCESS) return; if (result & IE_TDR_XCVR) { printf("ie%d: transceiver problem\n", unit); } else if (result & IE_TDR_OPEN) { printf("ie%d: TDR detected an open %d clocks away\n", unit, result & IE_TDR_TIME); } else if (result & IE_TDR_SHORT) { printf("ie%d: TDR detected a short %d clocks away\n", unit, result & IE_TDR_TIME); } else { printf("ie%d: TDR returned unknown status %x\n", unit, result); } } static void start_receiver(int unit) { int s = splimp(); ie_softc[unit].scb->ie_recv_list = MK_16(MEM, ie_softc[unit].rframes[0]); command_and_wait(unit, IE_RU_START, 0, 0); ie_ack(ie_softc[unit].scb, IE_ST_WHENCE, unit, ie_softc[unit].ie_chan_attn); splx(s); } /* * Here is a helper routine for iernr() and ieinit(). This sets up * the RFA. */ static caddr_t setup_rfa(caddr_t ptr, struct ie_softc * ie) { volatile struct ie_recv_frame_desc *rfd = (void *) ptr; volatile struct ie_recv_buf_desc *rbd; int i; int unit = ie - &ie_softc[0]; /* First lay them out */ for (i = 0; i < ie->nframes; i++) { ie->rframes[i] = rfd; bzero((char *) rfd, sizeof *rfd); /* ignore cast-qual */ rfd++; } ptr = (caddr_t) Align((caddr_t) rfd); /* ignore cast-qual */ /* Now link them together */ for (i = 0; i < ie->nframes; i++) { ie->rframes[i]->ie_fd_next = MK_16(MEM, ie->rframes[(i + 1) % ie->nframes]); } /* Finally, set the EOL bit on the last one. */ ie->rframes[ie->nframes - 1]->ie_fd_last |= IE_FD_LAST; /* * Now lay out some buffers for the incoming frames. Note that we * set aside a bit of slop in each buffer, to make sure that we have * enough space to hold a single frame in every buffer. */ rbd = (void *) ptr; for (i = 0; i < ie->nrxbufs; i++) { ie->rbuffs[i] = rbd; bzero((char *)rbd, sizeof *rbd); ptr = (caddr_t) Align(ptr + sizeof *rbd); rbd->ie_rbd_length = IE_RBUF_SIZE; rbd->ie_rbd_buffer = MK_24(MEM, ptr); ie->cbuffs[i] = (void *) ptr; ptr += IE_RBUF_SIZE; rbd = (void *) ptr; } /* Now link them together */ for (i = 0; i < ie->nrxbufs; i++) { ie->rbuffs[i]->ie_rbd_next = MK_16(MEM, ie->rbuffs[(i + 1) % ie->nrxbufs]); } /* Tag EOF on the last one */ ie->rbuffs[ie->nrxbufs - 1]->ie_rbd_length |= IE_RBD_LAST; /* * We use the head and tail pointers on receive to keep track of the * order in which RFDs and RBDs are used. */ ie->rfhead = 0; ie->rftail = ie->nframes - 1; ie->rbhead = 0; ie->rbtail = ie->nrxbufs - 1; ie->scb->ie_recv_list = MK_16(MEM, ie->rframes[0]); ie->rframes[0]->ie_fd_buf_desc = MK_16(MEM, ie->rbuffs[0]); ptr = Align(ptr); return (ptr); } /* * Run the multicast setup command. * Call at splimp(). */ static int mc_setup(int unit, caddr_t ptr, volatile struct ie_sys_ctl_block * scb) { struct ie_softc *ie = &ie_softc[unit]; volatile struct ie_mcast_cmd *cmd = (void *) ptr; cmd->com.ie_cmd_status = 0; cmd->com.ie_cmd_cmd = IE_CMD_MCAST | IE_CMD_LAST; cmd->com.ie_cmd_link = 0xffff; /* ignore cast-qual */ bcopy((caddr_t) ie->mcast_addrs, (caddr_t) cmd->ie_mcast_addrs, ie->mcast_count * sizeof *ie->mcast_addrs); cmd->ie_mcast_bytes = ie->mcast_count * 6; /* grrr... */ scb->ie_command_list = MK_16(MEM, cmd); if (command_and_wait(unit, IE_CU_START, cmd, IE_STAT_COMPL) || !(cmd->com.ie_cmd_status & IE_STAT_OK)) { printf("ie%d: multicast address setup command failed\n", unit); return (0); } return (1); } /* * This routine takes the environment generated by check_ie_present() * and adds to it all the other structures we need to operate the adapter. * This includes executing the CONFIGURE, IA-SETUP, and MC-SETUP commands, * starting the receiver unit, and clearing interrupts. * * THIS ROUTINE MUST BE CALLED AT splimp() OR HIGHER. */ static void ieinit(int unit) { struct ie_softc *ie = &ie_softc[unit]; volatile struct ie_sys_ctl_block *scb = ie->scb; caddr_t ptr; int i; ptr = (caddr_t) Align((caddr_t) scb + sizeof *scb); /* * Send the configure command first. */ { volatile struct ie_config_cmd *cmd = (void *) ptr; ie_setup_config(cmd, ie->promisc, ie->hard_type == IE_STARLAN10); cmd->com.ie_cmd_status = 0; cmd->com.ie_cmd_cmd = IE_CMD_CONFIG | IE_CMD_LAST; cmd->com.ie_cmd_link = 0xffff; scb->ie_command_list = MK_16(MEM, cmd); if (command_and_wait(unit, IE_CU_START, cmd, IE_STAT_COMPL) || !(cmd->com.ie_cmd_status & IE_STAT_OK)) { printf("ie%d: configure command failed\n", unit); return; } } /* * Now send the Individual Address Setup command. */ { volatile struct ie_iasetup_cmd *cmd = (void *) ptr; cmd->com.ie_cmd_status = 0; cmd->com.ie_cmd_cmd = IE_CMD_IASETUP | IE_CMD_LAST; cmd->com.ie_cmd_link = 0xffff; bcopy((char *)ie_softc[unit].arpcom.ac_enaddr, (char *)&cmd->ie_address, sizeof cmd->ie_address); scb->ie_command_list = MK_16(MEM, cmd); if (command_and_wait(unit, IE_CU_START, cmd, IE_STAT_COMPL) || !(cmd->com.ie_cmd_status & IE_STAT_OK)) { printf("ie%d: individual address " "setup command failed\n", unit); return; } } /* * Now run the time-domain reflectometer. */ run_tdr(unit, (void *) ptr); /* * Acknowledge any interrupts we have generated thus far. */ ie_ack(ie->scb, IE_ST_WHENCE, unit, ie->ie_chan_attn); /* * Set up the RFA. */ ptr = setup_rfa(ptr, ie); /* * Finally, the transmit command and buffer are the last little bit * of work. */ /* transmit command buffers */ for (i = 0; i < ie->ntxbufs; i++) { ie->xmit_cmds[i] = (void *) ptr; ptr += sizeof *ie->xmit_cmds[i]; ptr = Align(ptr); ie->xmit_buffs[i] = (void *)ptr; ptr += sizeof *ie->xmit_buffs[i]; ptr = Align(ptr); } /* transmit buffers */ for (i = 0; i < ie->ntxbufs - 1; i++) { ie->xmit_cbuffs[i] = (void *)ptr; ptr += IE_BUF_LEN; ptr = Align(ptr); } ie->xmit_cbuffs[ie->ntxbufs - 1] = (void *) ptr; for (i = 1; i < ie->ntxbufs; i++) { bzero((caddr_t) ie->xmit_cmds[i], sizeof *ie->xmit_cmds[i]); bzero((caddr_t) ie->xmit_buffs[i], sizeof *ie->xmit_buffs[i]); } /* * This must be coordinated with iestart() and ietint(). */ ie->xmit_cmds[0]->ie_xmit_status = IE_STAT_COMPL; /* take the ee16 out of loopback */ if (ie->hard_type == IE_EE16) { u_int8_t bart_config; bart_config = inb(PORT + IEE16_CONFIG); bart_config &= ~IEE16_BART_LOOPBACK; /* inb doesn't get bit! */ bart_config |= IEE16_BART_MCS16_TEST; outb(PORT + IEE16_CONFIG, bart_config); ee16_interrupt_enable(ie); ee16_chan_attn(unit); } ie->arpcom.ac_if.if_flags |= IFF_RUNNING; /* tell higher levels * we're here */ start_receiver(unit); return; } static void ie_stop(int unit) { command_and_wait(unit, IE_RU_DISABLE, 0, 0); } static int ieioctl(struct ifnet *ifp, u_long command, caddr_t data) { struct ifaddr *ifa = (struct ifaddr *) data; struct ie_softc *ie = ifp->if_softc; struct ifreq *ifr = (struct ifreq *) data; int s, error = 0; s = splimp(); switch (command) { case SIOCSIFADDR: ifp->if_flags |= IFF_UP; switch (ifa->ifa_addr->sa_family) { #ifdef INET case AF_INET: ieinit(ifp->if_unit); arp_ifinit((struct arpcom *) ifp, ifa); break; #endif /* INET */ #ifdef IPX /* * This magic copied from if_is.c; I don't use XNS, * so I have no way of telling if this actually * works or not. */ case AF_IPX: { struct ipx_addr *ina = &(IA_SIPX(ifa)->sipx_addr); if (ipx_nullhost(*ina)) { ina->x_host = *(union ipx_host *) (ie->arpcom.ac_enaddr); } else { ifp->if_flags &= ~IFF_RUNNING; bcopy((caddr_t) ina->x_host.c_host, (caddr_t) ie->arpcom.ac_enaddr, sizeof ie->arpcom.ac_enaddr); } ieinit(ifp->if_unit); } break; #endif /* IPX */ #ifdef NS /* * This magic copied from if_is.c; I don't use XNS, * so I have no way of telling if this actually * works or not. */ case AF_NS: { struct ns_addr *ina = &(IA_SNS(ifa)->sns_addr); if (ns_nullhost(*ina)) { ina->x_host = *(union ns_host *)(ie->arpcom.ac_enaddr); } else { ifp->if_flags &= ~IFF_RUNNING; bcopy((caddr_t) ina->x_host.c_host, (caddr_t) ie->arpcom.ac_enaddr, sizeof ie->arpcom.ac_enaddr); } ieinit(ifp->if_unit); } break; #endif /* NS */ default: ieinit(ifp->if_unit); break; } break; case SIOCSIFFLAGS: /* * Note that this device doesn't have an "all multicast" * mode, so we must turn on promiscuous mode and do the * filtering manually. */ if ((ifp->if_flags & IFF_UP) == 0 && (ifp->if_flags & IFF_RUNNING)) { ifp->if_flags &= ~IFF_RUNNING; ie_stop(ifp->if_unit); } else if ((ifp->if_flags & IFF_UP) && (ifp->if_flags & IFF_RUNNING) == 0) { ie_softc[ifp->if_unit].promisc = ifp->if_flags & (IFF_PROMISC | IFF_ALLMULTI); ieinit(ifp->if_unit); } else if (ie_softc[ifp->if_unit].promisc ^ (ifp->if_flags & (IFF_PROMISC | IFF_ALLMULTI))) { ie_softc[ifp->if_unit].promisc = ifp->if_flags & (IFF_PROMISC | IFF_ALLMULTI); ieinit(ifp->if_unit); } break; case SIOCADDMULTI: case SIOCDELMULTI: /* * Update multicast listeners */ /* reset multicast filtering */ ie_mc_reset(ifp->if_unit); error = 0; break; case SIOCSIFMTU: /* * Set the interface MTU. */ if (ifr->ifr_mtu > ETHERMTU) { error = EINVAL; } else { ifp->if_mtu = ifr->ifr_mtu; } break; default: error = EINVAL; } splx(s); return (error); } static void ie_mc_reset(int unit) { struct ie_softc *ie = &ie_softc[unit]; struct ifmultiaddr *ifma; /* * Step through the list of addresses. */ ie->mcast_count = 0; for (ifma = ie->arpcom.ac_if.if_multiaddrs.lh_first; ifma; ifma = ifma->ifma_link.le_next) { if (ifma->ifma_addr->sa_family != AF_LINK) continue; /* XXX - this is broken... */ if (ie->mcast_count >= MAXMCAST) { ie->arpcom.ac_if.if_flags |= IFF_ALLMULTI; ieioctl(&ie->arpcom.ac_if, SIOCSIFFLAGS, (void *) 0); goto setflag; } bcopy(LLADDR((struct sockaddr_dl *) ifma->ifma_addr), &(ie->mcast_addrs[ie->mcast_count]), 6); ie->mcast_count++; } setflag: ie->want_mcsetup = 1; } #ifdef DEBUG static void print_rbd(volatile struct ie_recv_buf_desc * rbd) { printf("RBD at %p:\n" "actual %04x, next %04x, buffer %p\n" "length %04x, mbz %04x\n", (void *) rbd, rbd->ie_rbd_actual, rbd->ie_rbd_next, (void *) rbd->ie_rbd_buffer, rbd->ie_rbd_length, rbd->mbz); } #endif /* DEBUG */ #endif /* NIE > 0 */ Index: head/sys/dev/isp/isp_pci.c =================================================================== --- head/sys/dev/isp/isp_pci.c (revision 38231) +++ head/sys/dev/isp/isp_pci.c (revision 38232) @@ -1,559 +1,559 @@ /* $FreeBSD$ */ -/* $Id: isp_pci.c,v 1.1 1998/04/22 18:10:34 mjacob Exp $ */ +/* $Id: isp_pci.c,v 1.2 1998/07/13 09:53:09 bde Exp $ */ /* * PCI specific probe and attach routines for Qlogic ISP SCSI adapters. * FreeBSD Version. * *--------------------------------------- * Copyright (c) 1997, 1998 by Matthew Jacob * NASA/Ames Research Center * All rights reserved. *--------------------------------------- * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice immediately at the beginning of the file, without modification, * this list of conditions, and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include #if NPCI > 0 #include #include #include #include static u_int16_t isp_pci_rd_reg __P((struct ispsoftc *, int)); static void isp_pci_wr_reg __P((struct ispsoftc *, int, u_int16_t)); static int isp_pci_mbxdma __P((struct ispsoftc *)); static int isp_pci_dmasetup __P((struct ispsoftc *, ISP_SCSI_XFER_T *, ispreq_t *, u_int8_t *, u_int8_t)); static void isp_pci_reset1 __P((struct ispsoftc *)); static void isp_pci_dumpregs __P((struct ispsoftc *)); static struct ispmdvec mdvec = { isp_pci_rd_reg, isp_pci_wr_reg, isp_pci_mbxdma, isp_pci_dmasetup, NULL, NULL, isp_pci_reset1, isp_pci_dumpregs, ISP_RISC_CODE, ISP_CODE_LENGTH, ISP_CODE_ORG, ISP_CODE_VERSION, BIU_PCI_CONF1_FIFO_64 | BIU_BURST_ENABLE, 60 /* MAGIC- all known PCI card implementations are 60MHz */ }; static struct ispmdvec mdvec_2100 = { isp_pci_rd_reg, isp_pci_wr_reg, isp_pci_mbxdma, isp_pci_dmasetup, NULL, NULL, isp_pci_reset1, isp_pci_dumpregs, ISP2100_RISC_CODE, ISP2100_CODE_LENGTH, ISP2100_CODE_ORG, ISP2100_CODE_VERSION, BIU_PCI_CONF1_FIFO_64 | BIU_BURST_ENABLE, 60 /* MAGIC- all known PCI card implementations are 60MHz */ }; #ifndef PCIM_CMD_INVEN #define PCIM_CMD_INVEN 0x10 #endif #ifndef PCIM_CMD_BUSMASTEREN #define PCIM_CMD_BUSMASTEREN 0x0004 #endif #ifndef PCI_VENDOR_QLOGIC #define PCI_VENDOR_QLOGIC 0x1077 #endif #ifndef PCI_PRODUCT_QLOGIC_ISP1020 #define PCI_PRODUCT_QLOGIC_ISP1020 0x1020 #endif #define PCI_QLOGIC_ISP \ ((PCI_PRODUCT_QLOGIC_ISP1020 << 16) | PCI_VENDOR_QLOGIC) #ifndef PCI_PRODUCT_QLOGIC_ISP2100 #define PCI_PRODUCT_QLOGIC_ISP2100 0x2100 #endif #define PCI_QLOGIC_ISP2100 \ ((PCI_PRODUCT_QLOGIC_ISP2100 << 16) | PCI_VENDOR_QLOGIC) #define IO_MAP_REG 0x10 #define MEM_MAP_REG 0x14 static char *isp_pci_probe __P((pcici_t tag, pcidi_t type)); static void isp_pci_attach __P((pcici_t config_d, int unit)); #define I386_BUS_SPACE_IO 0 #define I386_BUS_SPACE_MEM 1 typedef int bus_space_tag_t; typedef u_long bus_space_handle_t; #define bus_space_read_2(st, sh, offset) \ (st == I386_BUS_SPACE_IO)? \ - inw((u_int16_t)sh + offset) : *((u_int16_t *) sh) + inw((u_int16_t)sh + offset) : *((u_int16_t *)(uintptr_t)sh) #define bus_space_write_2(st, sh, offset, val) \ if (st == I386_BUS_SPACE_IO) outw((u_int16_t)sh + offset, val); else \ - *((u_int16_t *) sh) = val + *((u_int16_t *)(uintptr_t)sh) = val struct isp_pcisoftc { struct ispsoftc pci_isp; pcici_t pci_id; bus_space_tag_t pci_st; bus_space_handle_t pci_sh; union { sdparam _x; struct { fcparam _a; char _b[ISP2100_SCRLEN]; } _y; } _z; }; static u_long isp_unit; struct pci_device isp_pci_driver = { "isp", isp_pci_probe, isp_pci_attach, &isp_unit, NULL }; DATA_SET (pcidevice_set, isp_pci_driver); static char * isp_pci_probe(tag, type) pcici_t tag; pcidi_t type; { static int oneshot = 1; char *x; switch (type) { case PCI_QLOGIC_ISP: x = "Qlogic ISP 10X0 PCI SCSI Adapter"; break; case PCI_QLOGIC_ISP2100: x = "Qlogic ISP 2100 PCI FC-AL Adapter"; break; default: return (NULL); } if (oneshot) { oneshot = 0; printf("***Qlogic ISP Driver, FreeBSD NonCam Version\n***%s\n", ISP_VERSION_STRING); } return (x); } static void isp_pci_attach(config_id, unit) pcici_t config_id; int unit; { int mapped; u_int16_t io_port; u_int32_t data; struct isp_pcisoftc *pcs; struct ispsoftc *isp; vm_offset_t vaddr, paddr; ISP_LOCKVAL_DECL; pcs = malloc(sizeof (struct isp_pcisoftc), M_DEVBUF, M_NOWAIT); if (pcs == NULL) { printf("isp%d: cannot allocate softc\n", unit); return; } bzero(pcs, sizeof (struct isp_pcisoftc)); vaddr = paddr = NULL; mapped = 0; data = pci_conf_read(config_id, PCI_COMMAND_STATUS_REG); if (mapped == 0 && (data & PCI_COMMAND_IO_ENABLE)) { if (pci_map_port(config_id, PCI_MAP_REG_START, &io_port)) { pcs->pci_st = I386_BUS_SPACE_IO; pcs->pci_sh = io_port; mapped++; } } if (mapped == 0 && (data & PCI_COMMAND_MEM_ENABLE)) { if (pci_map_mem(config_id, PCI_MAP_REG_START, &vaddr, &paddr)) { pcs->pci_st = I386_BUS_SPACE_MEM; pcs->pci_sh = vaddr; mapped++; } } if (mapped == 0) { printf("isp%d: unable to map any ports!\n", unit); free(pcs, M_DEVBUF); return; } printf("isp%d: using %s space register mapping\n", unit, pcs->pci_st == I386_BUS_SPACE_IO? "I/O" : "Memory"); isp = &pcs->pci_isp; (void) sprintf(isp->isp_name, "isp%d", unit); isp->isp_osinfo.unit = unit; data = pci_conf_read(config_id, PCI_ID_REG); if (data == PCI_QLOGIC_ISP) { isp->isp_mdvec = &mdvec; isp->isp_type = ISP_HA_SCSI_UNKNOWN; isp->isp_param = &pcs->_z._x; } else if (data == PCI_QLOGIC_ISP2100) { isp->isp_mdvec = &mdvec_2100; isp->isp_type = ISP_HA_FC_2100; isp->isp_param = &pcs->_z._y._a; ISP_LOCK; data = pci_conf_read(config_id, PCI_COMMAND_STATUS_REG); data |= PCIM_CMD_BUSMASTEREN | PCIM_CMD_INVEN; pci_conf_write(config_id, PCI_COMMAND_STATUS_REG, data); /* * Wierd- we need to clear the lsb in offset 0x30 to take the * chip out of reset state. */ data = pci_conf_read(config_id, 0x30); data &= ~1; pci_conf_write(config_id, 0x30, data); ISP_UNLOCK; } else { free(pcs, M_DEVBUF); return; } if (pci_map_int(config_id, (void (*)(void *))isp_intr, (void *)isp, &IMASK) == 0) { printf("%s: could not map interrupt\n", isp->isp_name); free(pcs, M_DEVBUF); return; } pcs->pci_id = config_id; ISP_LOCK; isp_reset(isp); if (isp->isp_state != ISP_RESETSTATE) { ISP_UNLOCK; free(pcs, M_DEVBUF); return; } isp_init(isp); if (isp->isp_state != ISP_INITSTATE) { isp_uninit(isp); ISP_UNLOCK; free(pcs, M_DEVBUF); return; } isp_attach(isp); if (isp->isp_state != ISP_RUNSTATE) { isp_uninit(isp); ISP_UNLOCK; free(pcs, M_DEVBUF); return; } ISP_UNLOCK; } #define PCI_BIU_REGS_OFF BIU_REGS_OFF static u_int16_t isp_pci_rd_reg(isp, regoff) struct ispsoftc *isp; int regoff; { u_int16_t rv; struct isp_pcisoftc *pcs = (struct isp_pcisoftc *) isp; int offset, oldsxp = 0; if ((regoff & BIU_BLOCK) != 0) { offset = PCI_BIU_REGS_OFF; } else if ((regoff & MBOX_BLOCK) != 0) { if (isp->isp_type & ISP_HA_SCSI) offset = PCI_MBOX_REGS_OFF; else offset = PCI_MBOX_REGS2100_OFF; } else if ((regoff & SXP_BLOCK) != 0) { offset = PCI_SXP_REGS_OFF; /* * We will assume that someone has paused the RISC processor. */ oldsxp = isp_pci_rd_reg(isp, BIU_CONF1); isp_pci_wr_reg(isp, BIU_CONF1, oldsxp & ~BIU_PCI_CONF1_SXP); } else { offset = PCI_RISC_REGS_OFF; } regoff &= 0xff; offset += regoff; rv = bus_space_read_2(pcs->pci_st, pcs->pci_sh, offset); if ((regoff & SXP_BLOCK) != 0) { isp_pci_wr_reg(isp, BIU_CONF1, oldsxp); } return (rv); } static void isp_pci_wr_reg(isp, regoff, val) struct ispsoftc *isp; int regoff; u_int16_t val; { struct isp_pcisoftc *pcs = (struct isp_pcisoftc *) isp; int offset, oldsxp = 0; if ((regoff & BIU_BLOCK) != 0) { offset = PCI_BIU_REGS_OFF; } else if ((regoff & MBOX_BLOCK) != 0) { if (isp->isp_type & ISP_HA_SCSI) offset = PCI_MBOX_REGS_OFF; else offset = PCI_MBOX_REGS2100_OFF; } else if ((regoff & SXP_BLOCK) != 0) { offset = PCI_SXP_REGS_OFF; /* * We will assume that someone has paused the RISC processor. */ oldsxp = isp_pci_rd_reg(isp, BIU_CONF1); isp_pci_wr_reg(isp, BIU_CONF1, oldsxp & ~BIU_PCI_CONF1_SXP); } else { offset = PCI_RISC_REGS_OFF; } regoff &= 0xff; offset += regoff; bus_space_write_2(pcs->pci_st, pcs->pci_sh, offset, val); if ((regoff & SXP_BLOCK) != 0) { isp_pci_wr_reg(isp, BIU_CONF1, oldsxp); } } static int isp_pci_mbxdma(isp) struct ispsoftc *isp; { struct isp_pcisoftc *pci = (struct isp_pcisoftc *)isp; u_int32_t len; int rseg; /* XXXX CHECK FOR ALIGNMENT */ /* * Allocate and map the request queue. */ len = ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp)); isp->isp_rquest = malloc(len, M_DEVBUF, M_NOWAIT); if (isp->isp_rquest == NULL) { printf("%s: cannot malloc request queue\n", isp->isp_name); return (1); } isp->isp_rquest_dma = vtophys(isp->isp_rquest); #if 0 printf("RQUEST=0x%x (0x%x)...", isp->isp_rquest, isp->isp_rquest_dma); #endif /* * Allocate and map the result queue. */ len = ISP_QUEUE_SIZE(RESULT_QUEUE_LEN(isp)); isp->isp_result = malloc(len, M_DEVBUF, M_NOWAIT); if (isp->isp_result == NULL) { free(isp->isp_rquest, M_DEVBUF); printf("%s: cannot malloc result queue\n", isp->isp_name); return (1); } isp->isp_result_dma = vtophys(isp->isp_result); #if 0 printf("RESULT=0x%x (0x%x)\n", isp->isp_result, isp->isp_result_dma); #endif if (isp->isp_type & ISP_HA_FC) { fcparam *fcp = isp->isp_param; len = ISP2100_SCRLEN; fcp->isp_scratch = (volatile caddr_t) &pci->_z._y._b; fcp->isp_scdma = vtophys(fcp->isp_scratch); } return (0); } static int isp_pci_dmasetup(isp, xs, rq, iptrp, optr) struct ispsoftc *isp; ISP_SCSI_XFER_T *xs; ispreq_t *rq; u_int8_t *iptrp; u_int8_t optr; { struct isp_pcisoftc *pci = (struct isp_pcisoftc *)isp; ispcontreq_t *crq; vm_offset_t vaddr; int drq, seglim; u_int32_t paddr, nextpaddr, datalen, size, *ctrp; if (xs->datalen == 0) { rq->req_seg_count = 1; return (0); } if (xs->flags & SCSI_DATA_IN) { drq = REQFLAG_DATA_IN; } else { drq = REQFLAG_DATA_OUT; } if (isp->isp_type & ISP_HA_FC) { seglim = ISP_RQDSEG_T2; ((ispreqt2_t *)rq)->req_totalcnt = xs->datalen; ((ispreqt2_t *)rq)->req_flags |= drq; } else { seglim = ISP_RQDSEG; rq->req_flags |= drq; } datalen = xs->datalen;; vaddr = (vm_offset_t) xs->data; paddr = vtophys(vaddr); while (datalen != 0 && rq->req_seg_count < seglim) { if (isp->isp_type & ISP_HA_FC) { ispreqt2_t *rq2 = (ispreqt2_t *)rq; rq2->req_dataseg[rq2->req_seg_count].ds_base = paddr; ctrp = &rq2->req_dataseg[rq2->req_seg_count].ds_count; } else { rq->req_dataseg[rq->req_seg_count].ds_base = paddr; ctrp = &rq->req_dataseg[rq->req_seg_count].ds_count; } nextpaddr = paddr; *(ctrp) = 0; while (datalen != 0 && paddr == nextpaddr) { nextpaddr = (paddr & (~PAGE_MASK)) + PAGE_SIZE; size = nextpaddr - paddr; if (size > datalen) size = datalen; *(ctrp) += size; vaddr += size; datalen -= size; if (datalen != 0) paddr = vtophys(vaddr); } #if 0 if (isp->isp_type & ISP_HA_FC) { ispreqt2_t *rq2 = (ispreqt2_t *)rq; printf("%s: seg0[%d] cnt 0x%x paddr 0x%08x\n", isp->isp_name, rq->req_seg_count, rq2->req_dataseg[rq2->req_seg_count].ds_count, rq2->req_dataseg[rq2->req_seg_count].ds_base); } else { printf("%s: seg0[%d] cnt 0x%x paddr 0x%08x\n", isp->isp_name, rq->req_seg_count, rq->req_dataseg[rq->req_seg_count].ds_count, rq->req_dataseg[rq->req_seg_count].ds_base); } #endif rq->req_seg_count++; } if (datalen == 0) return (0); paddr = vtophys(vaddr); while (datalen > 0) { crq = (ispcontreq_t *) ISP_QUEUE_ENTRY(isp->isp_rquest, *iptrp); *iptrp = (*iptrp + 1) & (RQUEST_QUEUE_LEN(isp) - 1); if (*iptrp == optr) { printf("%s: Request Queue Overflow\n", isp->isp_name); return (EFBIG); } rq->req_header.rqs_entry_count++; bzero((void *)crq, sizeof (*crq)); crq->req_header.rqs_entry_count = 1; crq->req_header.rqs_entry_type = RQSTYPE_DATASEG; for (seglim = 0; datalen != 0 && seglim < ISP_CDSEG; seglim++) { crq->req_dataseg[seglim].ds_base = paddr; ctrp = &crq->req_dataseg[seglim].ds_count; *(ctrp) = 0; nextpaddr = paddr; while (datalen != 0 && paddr == nextpaddr) { nextpaddr = (paddr & (~PAGE_MASK)) + PAGE_SIZE; size = nextpaddr - paddr; if (size > datalen) size = datalen; *(ctrp) += size; vaddr += size; datalen -= size; if (datalen != 0) paddr = vtophys(vaddr); } #if 0 printf("%s: seg%d[%d] cnt 0x%x paddr 0x%08x\n", isp->isp_name, rq->req_header.rqs_entry_count-1, seglim, crq->req_dataseg[seglim].ds_count, crq->req_dataseg[seglim].ds_base); #endif rq->req_seg_count++; } } return (0); } static void isp_pci_reset1(isp) struct ispsoftc *isp; { /* Make sure the BIOS is disabled */ isp_pci_wr_reg(isp, HCCR, PCI_HCCR_CMD_BIOS); } static void isp_pci_dumpregs(isp) struct ispsoftc *isp; { struct isp_pcisoftc *pci = (struct isp_pcisoftc *)isp; printf("%s: PCI Status Command/Status=%lx\n", pci->pci_isp.isp_name, pci_conf_read(pci->pci_id, PCI_COMMAND_STATUS_REG)); } #endif Index: head/sys/i386/isa/aha1542.c =================================================================== --- head/sys/i386/isa/aha1542.c (revision 38231) +++ head/sys/i386/isa/aha1542.c (revision 38232) @@ -1,1851 +1,1851 @@ /* * (Mostly) Written by Julian Elischer (julian@tfs.com) * for TRW Financial Systems for use under the MACH(2.5) operating system. * * TRW Financial Systems, in accordance with their agreement with Carnegie * Mellon University, makes this software available to CMU to distribute * or use in any manner that they see fit as long as this message is kept with * the software. For this reason TFS also grants any other persons or * organisations permission to use or modify this software. * * TFS supplies this software to be publicly redistributed * on the understanding that TFS is not responsible for the correct * functioning of this software in any circumstances. * - * $Id: aha1542.c,v 1.77 1998/05/01 18:30:00 bde Exp $ + * $Id: aha1542.c,v 1.78 1998/06/21 14:53:07 bde Exp $ */ /* * Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992 */ #include "aha.h" #include "opt_tune_1542.h" #include #include #include #include #include #include #include #include #include #include #include #include /************************** board definitions *******************************/ /* * I/O Port Interface */ #define AHA_BASE aha->aha_base #define AHA_CTRL_STAT_PORT (AHA_BASE + 0x0) /* control & status */ #define AHA_CMD_DATA_PORT (AHA_BASE + 0x1) /* cmds and datas */ #define AHA_INTR_PORT (AHA_BASE + 0x2) /* Intr. stat */ /* * AHA_CTRL_STAT bits (write) */ #define AHA_HRST 0x80 /* Hardware reset */ #define AHA_SRST 0x40 /* Software reset */ #define AHA_IRST 0x20 /* Interrupt reset */ #define AHA_SCRST 0x10 /* SCSI bus reset */ /* * AHA_CTRL_STAT bits (read) */ #define AHA_STST 0x80 /* Self test in Progress */ #define AHA_DIAGF 0x40 /* Diagnostic Failure */ #define AHA_INIT 0x20 /* Mbx Init required */ #define AHA_IDLE 0x10 /* Host Adapter Idle */ #define AHA_CDF 0x08 /* cmd/data out port full */ #define AHA_DF 0x04 /* Data in port full */ #define AHA_INVDCMD 0x01 /* Invalid command */ /* * AHA_CMD_DATA bits (write) */ #define AHA_NOP 0x00 /* No operation */ #define AHA_MBX_INIT 0x01 /* Mbx initialization */ #define AHA_START_SCSI 0x02 /* start scsi command */ #define AHA_START_BIOS 0x03 /* start bios command */ #define AHA_INQUIRE 0x04 /* Adapter Inquiry */ #define AHA_MBO_INTR_EN 0x05 /* Enable MBO available interrupt */ #define AHA_SEL_TIMEOUT_SET 0x06 /* set selection time-out */ #define AHA_BUS_ON_TIME_SET 0x07 /* set bus-on time */ #define AHA_BUS_OFF_TIME_SET 0x08 /* set bus-off time */ #define AHA_SPEED_SET 0x09 /* set transfer speed */ #define AHA_DEV_GET 0x0a /* return installed devices */ #define AHA_CONF_GET 0x0b /* return configuration data */ #define AHA_TARGET_EN 0x0c /* enable target mode */ #define AHA_SETUP_GET 0x0d /* return setup data */ #define AHA_WRITE_CH2 0x1a /* write channel 2 buffer */ #define AHA_READ_CH2 0x1b /* read channel 2 buffer */ #define AHA_WRITE_FIFO 0x1c /* write fifo buffer */ #define AHA_READ_FIFO 0x1d /* read fifo buffer */ #define AHA_ECHO 0x1e /* Echo command data */ #define AHA_EXT_BIOS 0x28 /* return extended bios info */ #define AHA_MBX_ENABLE 0x29 /* enable mail box interface */ struct aha_cmd_buf { u_char byte[16]; }; /* * AHA_INTR_PORT bits (read) */ #define AHA_ANY_INTR 0x80 /* Any interrupt */ #define AHA_SCRD 0x08 /* SCSI reset detected */ #define AHA_HACC 0x04 /* Command complete */ #define AHA_MBOA 0x02 /* MBX out empty */ #define AHA_MBIF 0x01 /* MBX in full */ /* * Mail box defs */ #define AHA_MBX_SIZE 16 /* mail box size */ struct aha_mbx { struct aha_mbx_out { unsigned char cmd; unsigned char ccb_addr[3]; } mbo[AHA_MBX_SIZE]; struct aha_mbx_in { unsigned char stat; unsigned char ccb_addr[3]; } mbi[AHA_MBX_SIZE]; }; /* * mbo.cmd values */ #define AHA_MBO_FREE 0x0 /* MBO entry is free */ #define AHA_MBO_START 0x1 /* MBO activate entry */ #define AHA_MBO_ABORT 0x2 /* MBO abort entry */ /* * mbi.stat values */ #define AHA_MBI_FREE 0x0 /* MBI entry is free */ #define AHA_MBI_OK 0x1 /* completed without error */ #define AHA_MBI_ABORT 0x2 /* aborted ccb */ #define AHA_MBI_UNKNOWN 0x3 /* Tried to abort invalid CCB */ #define AHA_MBI_ERROR 0x4 /* Completed with error */ #define AHA_MBI_TGT_NO_CCB 0x10 /* Target received, no CCB ready */ /* FOR OLD VERSIONS OF THE !%$@ this may have to be 16 (yuk) */ #define AHA_NSEG 17 /* Number of scatter gather segments <= 16 */ /* allow 64 K i/o (min) */ struct aha_ccb { unsigned char opcode; unsigned char lun:3; unsigned char data_in:1; /* must be 0 */ unsigned char data_out:1; /* must be 0 */ unsigned char target:3; unsigned char scsi_cmd_length; unsigned char req_sense_length; unsigned char data_length[3]; unsigned char data_addr[3]; unsigned char link_addr[3]; unsigned char link_id; unsigned char host_stat; unsigned char target_stat; unsigned char reserved[2]; struct scsi_generic scsi_cmd; struct scsi_sense_data scsi_sense; struct aha_scat_gath { unsigned char seg_len[3]; unsigned char seg_addr[3]; } scat_gath[AHA_NSEG]; struct aha_ccb *next; struct scsi_xfer *xfer; /* the scsi_xfer for this cmd */ struct aha_mbx_out *mbx; /* pointer to mail box */ int flags; #define CCB_FREE 0 #define CCB_ACTIVE 1 #define CCB_ABORTED 2 }; /* * opcode fields */ #define AHA_INITIATOR_CCB 0x00 /* SCSI Initiator CCB */ #define AHA_TARGET_CCB 0x01 /* SCSI Target CCB */ #define AHA_INIT_SCAT_GATH_CCB 0x02 /* SCSI Initiator with scatter gather */ #define AHA_RESET_CCB 0x81 /* SCSI Bus reset */ #define AHA_INIT_RESID_CCB 0x03 /* SCSI Initiator CCB */ #define AHA_INIT_SG_RESID_CCB 0x04 /* SCSI initiator with scatter gather */ /* * aha_ccb.host_stat values */ #define AHA_OK 0x00 /* cmd ok */ #define AHA_LINK_OK 0x0a /* Link cmd ok */ #define AHA_LINK_IT 0x0b /* Link cmd ok + int */ #define AHA_SEL_TIMEOUT 0x11 /* Selection time out */ #define AHA_OVER_UNDER 0x12 /* Data over/under run */ #define AHA_BUS_FREE 0x13 /* Bus dropped at unexpected time */ #define AHA_INV_BUS 0x14 /* Invalid bus phase/sequence */ #define AHA_BAD_MBO 0x15 /* Incorrect MBO cmd */ #define AHA_BAD_CCB 0x16 /* Incorrect ccb opcode */ #define AHA_BAD_LINK 0x17 /* Not same values of LUN for links */ #define AHA_INV_TARGET 0x18 /* Invalid target direction */ #define AHA_CCB_DUP 0x19 /* Duplicate CCB received */ #define AHA_INV_CCB 0x1a /* Invalid CCB or segment list */ #define AHA_ABORTED 42 struct aha_setup { u_char sync_neg:1; u_char parity:1; u_char:6; u_char speed; u_char bus_on; u_char bus_off; u_char num_mbx; u_char mbx[3]; struct { u_char offset:4; u_char period:3; u_char valid:1; } sync[8]; u_char disc_sts; }; struct aha_config { u_char chan; u_char intr; u_char scsi_dev:3; u_char:5; }; struct aha_inquire { u_char boardid; /* type of board */ /* 0x20 (' ') = BusLogic 545, but it gets the command wrong, only returns one byte */ /* 0x31 ('1') = AHA-1540 */ /* 0x41 ('A') = AHA-1540A/1542A/1542B */ /* 0x42 ('B') = AHA-1640 */ /* 0x43 ('C') = AHA-1542C */ /* 0x44 ('D') = AHA-1542CF */ /* 0x45 ('E') = AHA-1542CF, BIOS v2.01 */ /* 0x46 ('F') = AHA-1542CP, "Plug'nPlay" */ u_char spec_opts; /* special options ID */ /* 0x41 = Board is standard model */ u_char revision_1; /* firmware revision [0-9A-Z] */ u_char revision_2; /* firmware revision [0-9A-Z] */ }; struct aha_extbios { u_char flags; /* Bit 3 == 1 extended bios enabled */ u_char mailboxlock; /* mail box lock code to unlock it */ }; #define INT9 0x01 #define INT10 0x02 #define INT11 0x04 #define INT12 0x08 #define INT14 0x20 #define INT15 0x40 #define CHAN0 0x01 #define CHAN5 0x20 #define CHAN6 0x40 #define CHAN7 0x80 /*********************************** end of board definitions***************/ -#define PHYSTOKV(x) (((long int)(x)) ^ aha->kv_phys_xor) +#define PHYSTOKV(x) ((intptr_t)(((long int)(x)) ^ aha->kv_phys_xor)) #define KVTOPHYS(x) vtophys(x) #define AHA_DMA_PAGES AHA_NSEG #define PAGESIZ 4096 #ifdef AHADEBUG int aha_debug = 1; #endif /*AHADEBUG */ static struct aha_data { int aha_base; /* base port for each board */ /* * xor this with a physaddr to get a kv addr and visa versa * for items in THIS STRUCT only. * Used to get the CCD's physical and kv addresses from each * other. */ long int kv_phys_xor; struct aha_mbx aha_mbx; /* all the mailboxes */ struct aha_ccb *aha_ccb_free; /* the next free ccb */ struct aha_ccb aha_ccb[AHA_MBX_SIZE]; /* all the CCBs */ int unit; /* unit number */ int aha_int; /* irq level */ int aha_dma; /* DMA req channel */ int aha_scsi_dev; /* scsi bus address */ int flags; /* We use different op codes for different revs of the board * if we think residual codes will work. */ short init_opcode; /* Command to use for initiator */ short sg_opcode; /* Command to use for scatter/gather */ struct scsi_link sc_link; /* prototype for subdevs */ } *ahadata[NAHA]; static u_int32_t aha_adapter_info __P((int unit)); static int ahaattach __P((struct isa_device *dev)); #ifdef TUNE_1542 static int aha_bus_speed_check __P((struct aha_data *aha, int speed)); static int aha_set_bus_speed __P((struct aha_data *aha)); #endif static int aha_cmd __P((struct aha_data *aha, int icnt, int ocnt, int wait, u_char *retval, u_char opcode, ...)); static void aha_done __P((struct aha_data *aha, struct aha_ccb *ccb)); static int aha_escape __P((struct scsi_xfer *xs, struct aha_ccb *ccb)); static void aha_free_ccb __P((struct aha_data *aha, struct aha_ccb *ccb, int flags)); static struct aha_ccb * aha_get_ccb __P((struct aha_data *aha, int flags)); static int aha_init __P((struct aha_data *aha)); static void ahaminphys __P((struct buf *bp)); static int aha_poll __P((struct aha_data *aha, struct scsi_xfer *xs, struct aha_ccb *ccb)); static int ahaprobe __P((struct isa_device *dev)); static int32_t aha_scsi_cmd __P((struct scsi_xfer *xs)); static timeout_t aha_timeout; static char *board_rev __P((struct aha_data *aha, int type)); static int physcontig __P((int kv, int len)); static void put_host_stat __P((int host_stat)); static struct scsi_adapter aha_switch = { aha_scsi_cmd, ahaminphys, 0, 0, aha_adapter_info, "aha", { 0, 0 } }; /* the below structure is so we have a default dev struct for out link struct */ static struct scsi_device aha_dev = { NULL, /* Use default error handler */ NULL, /* have a queue, served by this */ NULL, /* have no async handler */ NULL, /* Use default 'done' routine */ "aha", 0, { 0, 0 } }; struct isa_driver ahadriver = { ahaprobe, ahaattach, "aha" }; static int ahaunit = 0; #define aha_abortmbx(mbx) \ (mbx)->cmd = AHA_MBO_ABORT; \ outb(AHA_CMD_DATA_PORT, AHA_START_SCSI); #define aha_startmbx(mbx) \ (mbx)->cmd = AHA_MBO_START; \ outb(AHA_CMD_DATA_PORT, AHA_START_SCSI); #define AHA_RESET_TIMEOUT 2000 /* time to wait for reset (mSec) */ /* * aha_cmd(struct aha_data *aha,icnt, ocnt,wait, retval, opcode, ...) * Activate Adapter command * icnt: number of args (outbound bytes written after opcode) * ocnt: number of expected returned bytes * wait: number of seconds to wait for response * retval: buffer where to place returned bytes * opcode: opcode AHA_NOP, AHA_MBX_INIT, AHA_START_SCSI, etc * ... : parameters to the command specified by opcode * * Performs an adapter command through the ports. Not to be confused * with a scsi command, which is read in via the dma. One of the adapter * commands tells it to read in a scsi command but that one is done * separately. This is only called during set-up. * */ static int #ifdef __STDC__ aha_cmd(struct aha_data *aha, int icnt, int ocnt, int wait, u_char *retval, u_char opcode, ... ) #else aha_cmd(aha, icnt, ocnt, wait, retval, opcode, va_alist) struct aha_data *aha, int icnt, int ocnt, int wait, u_char *retval, u_char opcode, va_dcl #endif { va_list ap; u_char oc; u_char data; register int i; int sts; /* * multiply the wait argument by a big constant * zero defaults to 1 sec.. * all wait loops are in 50uSec cycles */ if (wait) wait *= 20000; else wait = 20000; /* * Wait for the adapter to go idle, unless it's one of * the commands which don't need this */ if (opcode != AHA_MBX_INIT && opcode != AHA_START_SCSI) { i = 20000; /*do this for upto about a second */ while (--i) { sts = inb(AHA_CTRL_STAT_PORT); if (sts & AHA_IDLE) { break; } DELAY(50); } if (!i) { printf("aha%d: aha_cmd, host not idle(0x%x)\n", aha->unit, sts); return (ENXIO); } } /* * Now that it is idle, if we expect output, preflush the * queue feeding to us. */ if (ocnt) { while ((inb(AHA_CTRL_STAT_PORT)) & AHA_DF) inb(AHA_CMD_DATA_PORT); } /* * Output the command and the number of arguments given * for each byte, first check the port is empty. */ va_start(ap, opcode); for(data = opcode; icnt >=0; icnt--, data = (u_char)va_arg(ap, int)) { sts = inb(AHA_CTRL_STAT_PORT); for (i = wait; i; i--) { sts = inb(AHA_CTRL_STAT_PORT); if (!(sts & AHA_CDF)) break; DELAY(50); } if (i == 0) { printf("aha%d: aha_cmd, cmd/data port full\n", aha->unit); outb(AHA_CTRL_STAT_PORT, AHA_SRST); return (ENXIO); } outb(AHA_CMD_DATA_PORT, data); } /* * If we expect input, loop that many times, each time, * looking for the data register to have valid data */ while (ocnt--) { sts = inb(AHA_CTRL_STAT_PORT); for (i = wait; i; i--) { sts = inb(AHA_CTRL_STAT_PORT); if (sts & AHA_DF) break; DELAY(50); } if (i == 0) { printf("aha%d: aha_cmd, cmd/data port empty %d\n", aha->unit, ocnt); return (ENXIO); } oc = inb(AHA_CMD_DATA_PORT); if (retval) *retval++ = oc; } /* * Wait for the board to report a finised instruction */ i = 20000; while (--i) { sts = inb(AHA_INTR_PORT); if (sts & AHA_HACC) { break; } DELAY(50); } if (i == 0) { printf("aha%d: aha_cmd, host not finished(0x%x)\n", aha->unit, sts); return (ENXIO); } outb(AHA_CTRL_STAT_PORT, AHA_IRST); return 0; } /* * Check if the device can be found at the port given * and if so, set it up ready for further work * as an argument, takes the isa_device structure from * autoconf.c */ static int ahaprobe(dev) struct isa_device *dev; { int unit = ahaunit; struct aha_data *aha; /* * find unit and check we have that many defined */ if (unit >= NAHA) { printf("aha%d: unit number too high\n", unit); return 0; } dev->id_unit = unit; /* * a quick safety check so we can be sleazy later */ if (sizeof(struct aha_data) > PAGESIZ) { printf("aha struct > pagesize\n"); return 0; } /* * Allocate a storage area for us */ if (ahadata[unit]) { printf("aha%d: memory already allocated\n", unit); return 0; } aha = malloc(sizeof(struct aha_data), M_TEMP, M_NOWAIT); if (!aha) { printf("aha%d: cannot malloc!\n", unit); return 0; } bzero(aha, sizeof(struct aha_data)); ahadata[unit] = aha; aha->unit = unit; aha->aha_base = dev->id_iobase; /* * Try initialise a unit at this location * sets up dma and bus speed, loads aha->aha_int */ if (aha_init(aha) != 0) { ahadata[unit] = NULL; free(aha, M_TEMP); return 0; } /* * Calculate the xor product of the aha struct's * physical and virtual address. This allows us * to change addresses within the structure * from physical to virtual easily, as long as * the structure is less than 1 page in size. * This is used to recognise CCBs which are in * this struct and which are refered to by the * hardware using physical addresses. * (assumes malloc returns a chunk that doesn't * span pages) * eventually use the hash table in aha1742.c */ - aha->kv_phys_xor = (long int) aha ^ (KVTOPHYS(aha)); + aha->kv_phys_xor = (intptr_t) aha ^ (KVTOPHYS(aha)); /* * If it's there, put in it's interrupt vectors */ dev->id_irq = (1 << aha->aha_int); dev->id_drq = aha->aha_dma; ahaunit++; return 0x4; } /* * Attach all the sub-devices we can find */ static int ahaattach(dev) struct isa_device *dev; { int unit = dev->id_unit; struct aha_data *aha = ahadata[unit]; struct scsibus_data *scbus; /* * fill in the prototype scsi_link. */ aha->sc_link.adapter_unit = unit; aha->sc_link.adapter_targ = aha->aha_scsi_dev; aha->sc_link.adapter_softc = aha; aha->sc_link.adapter = &aha_switch; aha->sc_link.device = &aha_dev; aha->sc_link.flags = aha->flags;; /* * Prepare the scsibus_data area for the upperlevel * scsi code. */ scbus = scsi_alloc_bus(); if(!scbus) return 0; scbus->adapter_link = &aha->sc_link; /* * ask the adapter what subunits are present */ scsi_attachdevs(scbus); return 1; } /* * Return some information to the caller about the adapter and its * capabilities. */ static u_int32_t aha_adapter_info(unit) int unit; { return (2); /* 2 outstanding requests at a time per device */ } /* * Catch an interrupt from the adaptor */ void ahaintr(unit) int unit; { unsigned char stat; register int i; struct aha_data *aha = ahadata[unit]; #ifdef AHADEBUG printf("ahaintr "); #endif /*AHADEBUG */ /* * First acknowledge the interrupt, Then if it's not telling about * a completed operation just return. */ stat = inb(AHA_INTR_PORT); outb(AHA_CTRL_STAT_PORT, AHA_IRST); if (!(stat & AHA_MBIF)) return; #ifdef AHADEBUG printf("mbxin "); #endif /*AHADEBUG */ /* * If it IS then process the completed operation */ for (i = 0; i < AHA_MBX_SIZE; i++) { struct aha_mbx_in *mbi = aha->aha_mbx.mbi + i; if (mbi->stat != AHA_MBI_FREE) { struct aha_ccb *ccb = (struct aha_ccb *)PHYSTOKV(scsi_3btou(mbi->ccb_addr)); stat = mbi->stat; switch (stat) { case AHA_MBI_OK: break; case AHA_MBI_ABORT: #ifdef AHADEBUG if (aha_debug) printf("abort"); #endif /*AHADEBUG */ ccb->host_stat = AHA_ABORTED; break; case AHA_MBI_TGT_NO_CCB: /* We enabled target mode and received a SEND * or RECEIVE command from the initiator, but * we don't have any CCB registered to handle the command. * At this point it would be nice to wakeup a * process sleeping on this event via an ioctl, * returning whether it is a SEND or RECEIVE and the * required length. * However, I want to look at the CAM documentation before * I start extending the API at all. */ #ifdef NOISE_WHEN_TGT_NO_CDB printf("Target received, but no CCB ready.\n"); printf("Initiator & lun: %02x\n", mbi->ccb_addr[0]); printf("Max data length: %06x\n", (mbi->ccb_addr[1] << 16) | (mbi->ccb_addr[2] << 8) + 255); #endif #ifdef AHADEBUG if (aha_debug) printf("target-no-ccb"); #endif /*AHADEBUG */ ccb = 0; break; case AHA_MBI_UNKNOWN: ccb = 0; #ifdef AHADEBUG if (aha_debug) printf("unknown ccb for abort "); #endif /*AHADEBUG */ /* may have missed it */ /* no such ccb known for abort */ case AHA_MBI_ERROR: /* XXX ccb is still set up? Driver fails without it? */ break; default: panic("Impossible mbxi status"); } #ifdef AHADEBUG if (aha_debug && ccb && stat != AHA_MBI_OK) { u_char *cp; cp = (u_char *) (&(ccb->scsi_cmd)); printf("op=%x %x %x %x %x %x\n", cp[0], cp[1], cp[2], cp[3], cp[4], cp[5]); printf("stat %x for mbi[%d]\n" ,mbi->stat, i); printf("addr = 0x%x\n", ccb); } #endif /*AHADEBUG */ if (ccb) { untimeout(aha_timeout, (caddr_t)ccb, ccb->xfer->timeout_ch); aha_done(aha, ccb); } mbi->stat = AHA_MBI_FREE; } } } /* * A ccb (and hence a mbx-out) is put onto the * free list. */ static void aha_free_ccb(aha, ccb, flags) struct aha_data *aha; struct aha_ccb *ccb; int flags; { unsigned int opri = 0; if (!(flags & SCSI_NOMASK)) opri = splbio(); ccb->next = aha->aha_ccb_free; aha->aha_ccb_free = ccb; ccb->flags = CCB_FREE; /* * If there were none, wake anybody waiting for * one to come free, starting with queued entries */ if (!ccb->next) { wakeup((caddr_t)&aha->aha_ccb_free); } if (!(flags & SCSI_NOMASK)) splx(opri); } /* * Get a free ccb (and hence mbox-out entry) */ static struct aha_ccb * aha_get_ccb(aha, flags) struct aha_data *aha; int flags; { unsigned opri = 0; struct aha_ccb *rc; if (!(flags & SCSI_NOMASK)) opri = splbio(); /* * If we can and have to, sleep waiting for one * to come free */ while ((!(rc = aha->aha_ccb_free)) && (!(flags & SCSI_NOSLEEP))) { tsleep((caddr_t)&aha->aha_ccb_free, PRIBIO, "ahaccb", 0); } if (rc) { aha->aha_ccb_free = aha->aha_ccb_free->next; rc->flags = CCB_ACTIVE; } if (!(flags & SCSI_NOMASK)) splx(opri); return (rc); } static void put_host_stat(int host_stat) { int i; struct { int host_stat; char *text; } tab[] = { { AHA_OK, "Cmd ok" }, { AHA_LINK_OK, "Link cmd ok" }, { AHA_LINK_IT, "Link cmd ok + int" }, { AHA_SEL_TIMEOUT, "Selection time out" }, { AHA_OVER_UNDER, "Data over/under run" }, { AHA_BUS_FREE, "Bus dropped at unexpected time" }, { AHA_INV_BUS, "Invalid bus phase/sequence" }, { AHA_BAD_MBO, "Incorrect MBO cmd" }, { AHA_BAD_CCB, "Incorrect ccb opcode" }, { AHA_BAD_LINK, "Not same values of LUN for links" }, { AHA_INV_TARGET, "Invalid target direction" }, { AHA_CCB_DUP, "Duplicate CCB received" }, { AHA_INV_CCB, "Invalid CCB or segment list" }, { AHA_ABORTED, "Software abort" }, }; for (i = 0; i < (int)(sizeof(tab) / sizeof(tab[0])); i++) { if (tab[i].host_stat == host_stat) { printf("%s\n", tab[i].text); return; } } printf("Unknown host_stat %02x\n", host_stat); } /* * We have a ccb which has been processed by the * adaptor, now we look to see how the operation * went. Wake up the owner if waiting */ static void aha_done(aha, ccb) struct aha_data *aha; struct aha_ccb *ccb; { struct scsi_sense_data *s1, *s2; struct scsi_xfer *xs = ccb->xfer; SC_DEBUG(xs->sc_link, SDEV_DB2, ("aha_done\n")); /* * Otherwise, put the results of the operation * into the xfer and call whoever started it */ if (!(xs->flags & INUSE)) { printf("aha%d: exiting but not in use!\n", aha->unit); #ifdef DIAGNOSTIC panic("aha1542 exiting but not in use"); #endif } xs->status = ccb->target_stat; xs->resid = 0; if (((ccb->host_stat != AHA_OK) || (ccb->target_stat != SCSI_OK)) && ((xs->flags & SCSI_ERR_OK) == 0)) { /* * We have an error, that we cannot ignore. */ s1 = (struct scsi_sense_data *) (((char *) (&ccb->scsi_cmd)) + ccb->scsi_cmd_length); s2 = &(xs->sense); if (ccb->host_stat) { SC_DEBUG(xs->sc_link, SDEV_DB3, ("host err 0x%x\n", ccb->host_stat)); switch (ccb->host_stat) { case AHA_ABORTED: xs->error = XS_TIMEOUT; break; case AHA_SEL_TIMEOUT: xs->error = XS_SELTIMEOUT; break; case AHA_OVER_UNDER: /* Over run / under run */ switch(ccb->opcode) { case AHA_TARGET_CCB: xs->resid = xs->datalen - scsi_3btoi(ccb->data_length); xs->flags |= SCSI_RESID_VALID; if (xs->resid <= 0) xs->error = XS_LENGTH; break; case AHA_INIT_RESID_CCB: case AHA_INIT_SG_RESID_CCB: xs->resid = scsi_3btoi(ccb->data_length); xs->flags |= SCSI_RESID_VALID; if (xs->resid <= 0) xs->error = XS_LENGTH; break; default: xs->error = XS_LENGTH; } break; default: /* Other scsi protocol messes */ xs->error = XS_DRIVER_STUFFUP; printf("aha%d: ", aha->unit); put_host_stat(ccb->host_stat); } } else { SC_DEBUG(xs->sc_link, SDEV_DB3, ("target err 0x%x\n", ccb->target_stat)); switch (ccb->target_stat) { case 0x02: /* structure copy!!!!! */ *s2 = *s1; xs->error = XS_SENSE; break; case 0x08: xs->error = XS_BUSY; break; default: printf("aha%d:target_stat%x\n", aha->unit, ccb->target_stat); xs->error = XS_DRIVER_STUFFUP; } } } xs->flags |= ITSDONE; aha_free_ccb(aha, ccb, xs->flags); scsi_done(xs); } /* Macro to determine that a rev is potentially a new valid one * so that the driver doesn't keep breaking on new revs as it * did for the CF and CP. */ #define PROBABLY_NEW_BOARD(REV) (REV > 0x43 && REV < 0x56) static char *board_rev(struct aha_data *aha, int type) { switch(type) { case 0x20: return "Buslogic 545?"; case 0x31: return "AHA-1540"; case 0x41: return "AHA-154x[AB]"; case 0x42: return "AHA-1640"; case 0x43: return "AHA-1542C"; case 0x44: return "AHA-1542CF"; case 0x45: return "AHA-1542CF BIOS v2.01"; case 0x46: return "AHA-1542CP"; default: if (PROBABLY_NEW_BOARD(type)) { printf("aha%d: Assuming type %02x is a new board.\n", aha->unit, type); return "New Adaptec rev?"; } printf("aha%d: type %02x is an unknown board.\n", aha->unit, type); return "Unknown board"; } } /* * Start the board, ready for normal operation */ static int aha_init(aha) struct aha_data *aha; { char *desc; unsigned char ad[3]; volatile int i, sts; struct aha_config conf; struct aha_inquire inquire; struct aha_extbios extbios; /* Assume that residual codes don't work. If they * do we enable that after we figure out what kind of * board it is. */ aha->init_opcode = AHA_INITIATOR_CCB; aha->sg_opcode = AHA_INIT_SCAT_GATH_CCB; /* * reset board, If it doesn't respond, assume * that it's not there.. good for the probe */ outb(AHA_CTRL_STAT_PORT, AHA_HRST | AHA_SRST); for (i = AHA_RESET_TIMEOUT; i; i--) { sts = inb(AHA_CTRL_STAT_PORT); if (sts == (AHA_IDLE | AHA_INIT)) { break; } DELAY(1000); /* calibrated in msec */ } #ifdef AHADEBUG printf("aha_init: AHA_RESET_TIMEOUT went to %d\n", i); #endif /* AHADEBUG */ if (i == 0) { #ifdef AHADEBUG if (aha_debug) printf("aha_init: No answer from board\n"); #endif /*AHADEBUG */ return (ENXIO); } /* * Assume we have a board at this stage, do an adapter inquire * to find out what type of controller it is. If the AHA_INQUIRE * command fails, blatter about it, nuke the boardid so the 1542C * stuff gets skipped over, and reset the board again. */ if(aha_cmd(aha, 0, sizeof(inquire), 1, (u_char *)&inquire, AHA_INQUIRE)) { /* * Blah.. not a real adaptec board!!! * Seems that the Buslogic 545S and the DTC3290 both get * this wrong. */ printf ("aha%d: not a REAL adaptec board, may cause warnings\n", aha->unit); inquire.boardid = 0; outb(AHA_CTRL_STAT_PORT, AHA_HRST | AHA_SRST); for (i = AHA_RESET_TIMEOUT; i; i--) { sts = inb(AHA_CTRL_STAT_PORT); if (sts == (AHA_IDLE | AHA_INIT)) { break; } DELAY(1000); /* calibrated in msec */ } #ifdef AHADEBUG printf("aha_init2: AHA_RESET_TIMEOUT went to %d\n", i); #endif /* AHADEBUG */ if (i == 0) { #ifdef AHADEBUG if (aha_debug) printf("aha_init2: No answer from board\n"); #endif /*AHADEBUG */ return (ENXIO); } } #ifdef AHADEBUG printf("aha%d: inquire %x, %x, %x, %x\n", aha->unit, inquire.boardid, inquire.spec_opts, inquire.revision_1, inquire.revision_2); #endif /* AHADEBUG */ aha->flags = SDEV_BOUNCE; #define PRVERBOSE(x) if (bootverbose) printf x /* * If we are a new type of 1542 board (anything newer than a 1542C) * then disable the extended bios so that the * mailbox interface is unlocked. * This is also true for the 1542B Version 3.20. First Adaptec * board that supports >1Gb drives. * No need to check the extended bios flags as some of the * extensions that cause us problems are not flagged in that byte. */ desc = board_rev(aha, inquire.boardid); PRVERBOSE( ("aha%d: Rev %02x (%s) V%c.%c", aha->unit, inquire.boardid, desc, inquire.revision_1, inquire.revision_2) ); if (PROBABLY_NEW_BOARD(inquire.boardid) || (inquire.boardid == 0x41 && inquire.revision_1 == 0x31 && inquire.revision_2 == 0x34)) { aha_cmd(aha, 0, sizeof(extbios), 0, (u_char *)&extbios, AHA_EXT_BIOS); #ifdef AHADEBUG printf("aha%d: extended bios flags %x\n", aha->unit, extbios.flags); #endif /* AHADEBUG */ PRVERBOSE( (", enabling mailbox") ); aha_cmd(aha, 2, 0, 0, 0, AHA_MBX_ENABLE, 0, extbios.mailboxlock); } /* Which boards support residuals? Some early 1542A's apparently * don't. The 1542B with V0.5 of the software does, so I've * arbitrarily set that as the earliest rev. */ if (PROBABLY_NEW_BOARD(inquire.boardid) || (inquire.boardid == 0x41 && (inquire.revision_1 > '0' || inquire.revision_2 >= '5'))) { PRVERBOSE( (", enabling residuals") ); aha->init_opcode = AHA_INIT_RESID_CCB; aha->sg_opcode = AHA_INIT_SG_RESID_CCB; } /* Which boards support target operations? The 1542C completely * locks up the SCSI bus if you enable them. I'm only sure * about the B, which was sold in the OEM market as a target * board. */ if (inquire.boardid == 0x41) { PRVERBOSE( (", target ops") ); aha->flags |= SDEV_TARGET_OPS; } PRVERBOSE( ("\n") ); /* * setup dma channel from jumpers and save int * level */ PRVERBOSE(("aha%d: reading board settings, ", aha->unit)); if (inquire.boardid == 0x20) { DELAY(1000); /* for Bustek 545 */ } aha_cmd(aha, 0, sizeof(conf), 0, (u_char *)&conf, AHA_CONF_GET); switch (conf.chan) { case CHAN0: outb(0x0b, 0x0c); outb(0x0a, 0x00); aha->aha_dma = 0; break; case CHAN5: outb(0xd6, 0xc1); outb(0xd4, 0x01); aha->aha_dma = 5; break; case CHAN6: outb(0xd6, 0xc2); outb(0xd4, 0x02); aha->aha_dma = 6; break; case CHAN7: outb(0xd6, 0xc3); outb(0xd4, 0x03); aha->aha_dma = 7; break; default: printf("aha%d: illegal dma jumper setting\n", aha->unit); return (EIO); } PRVERBOSE( ("dma=%d ", aha->aha_dma) ); switch (conf.intr) { case INT9: aha->aha_int = 9; break; case INT10: aha->aha_int = 10; break; case INT11: aha->aha_int = 11; break; case INT12: aha->aha_int = 12; break; case INT14: aha->aha_int = 14; break; case INT15: aha->aha_int = 15; break; default: printf("aha%d: illegal int jumper setting\n", aha->unit); return (EIO); } PRVERBOSE( ("int=%d ", aha->aha_int) ); /* who are we on the scsi bus? */ aha->aha_scsi_dev = conf.scsi_dev; PRVERBOSE( ("id=%d ", aha->aha_scsi_dev) ); /* * Change the bus on/off times to not clash with other dma users. */ aha_cmd(aha, 1, 0, 0, 0, AHA_BUS_ON_TIME_SET, 7); aha_cmd(aha, 1, 0, 0, 0, AHA_BUS_OFF_TIME_SET, 4); #ifdef TUNE_1542 /* * Initialize memory transfer speed * Not compiled in by default because it breaks some machines */ if (!(aha_set_bus_speed(aha))) { return (EIO); } #else PRVERBOSE( (" (bus speed defaulted)\n") ); #endif /*TUNE_1542*/ /* * Initialize mail box */ scsi_uto3b(KVTOPHYS(&aha->aha_mbx), ad); aha_cmd(aha, 4, 0, 0, 0, AHA_MBX_INIT, AHA_MBX_SIZE, ad[0], ad[1], ad[2]); /* * link the ccb's with the mbox-out entries and * into a free-list * this is a kludge but it works */ for (i = 0; i < AHA_MBX_SIZE; i++) { aha->aha_ccb[i].next = aha->aha_ccb_free; aha->aha_ccb_free = &aha->aha_ccb[i]; aha->aha_ccb_free->flags = CCB_FREE; aha->aha_ccb_free->mbx = &aha->aha_mbx.mbo[i]; scsi_uto3b(KVTOPHYS(aha->aha_ccb_free), aha->aha_mbx.mbo[i].ccb_addr); } /* * Note that we are going and return (to probe) */ return 0; } static void ahaminphys(bp) struct buf *bp; { /* aha seems to explode with 17 segs (64k may require 17 segs) */ /* on old boards so use a max of 16 segs if you have problems here */ if (bp->b_bcount > ((AHA_NSEG - 1) * PAGESIZ)) { bp->b_bcount = ((AHA_NSEG - 1) * PAGESIZ); } } static int aha_escape(xs, ccb) struct scsi_xfer *xs; struct aha_ccb *ccb; { int ret = 0; int s; if (xs->cmd) { switch(xs->cmd->opcode) { case SCSI_OP_RESET: ccb->opcode = AHA_RESET_CCB; ret = 0; break; case SCSI_OP_TARGET: s= splbio(); aha_cmd((struct aha_data *)xs->sc_link->adapter_softc, 2, 0, 0, 0, AHA_TARGET_EN, (int)xs->cmd->bytes[0], (int)1); splx(s); ret = COMPLETE; break; default: ret = ESCAPE_NOT_SUPPORTED; break; } } else { ccb->opcode = AHA_RESET_CCB; ret = 0; } return ret; } #define physdb(ARG) (void)(ARG) /* physcontig: Scan forward from a KV and return length to the * end of physically contiguous addresses. This belongs in * i386/.../something_or_other.c * XXX: Find the right thing in the kernel. */ static int physcontig(int kv, int len) { int len_was = len; u_long kvl = (u_long)kv; int phys_len; u_long phys, prev_phys; prev_phys = KVTOPHYS(kvl); /* We go at least to the end of this page: */ phys_len = PAGESIZ - (prev_phys & (PAGESIZ - 1)); len -= phys_len; kvl += phys_len; prev_phys &= ~(PAGESIZ - 1); while (len > 0) { phys = KVTOPHYS(kvl); if (phys != prev_phys + PAGESIZ) { physdb(("phys %08x != prev_phys %08x + PAGESIZ\n", phys, prev_phys)); break; } prev_phys = phys; kvl += PAGESIZ; len -= PAGESIZ; } phys_len = (len < 0) ? len_was : (len_was - len); physdb(("physcontig(%08x, %d) = %d\n", kv, len_was, phys_len)); return phys_len; } /* * start a scsi operation given the command and * the data address. Also needs the unit, target * and lu */ static int32_t aha_scsi_cmd(xs) struct scsi_xfer *xs; { struct scsi_link *sc_link = xs->sc_link; struct aha_data *aha; struct aha_ccb *ccb; struct aha_scat_gath *sg; int seg; /* scatter gather seg being worked on */ int thiskv; int thisphys, nextphys; int bytes_this_seg, bytes_this_page, datalen, flags; int s; aha = (struct aha_data *)sc_link->adapter_softc; SC_DEBUG(xs->sc_link, SDEV_DB2, ("aha_scsi_cmd\n")); /* * get a ccb (mbox-out) to use. If the transfer * is from a buf (possibly from interrupt time) * then we can't allow it to sleep */ flags = xs->flags; if (!(ccb = aha_get_ccb(aha, flags))) { xs->error = XS_DRIVER_STUFFUP; return (TRY_AGAIN_LATER); } if (ccb->mbx->cmd != AHA_MBO_FREE) printf("aha%d: MBO %02x and not %02x (free)\n", aha->unit, ccb->mbx->cmd, AHA_MBO_FREE); /* * Put all the arguments for the xfer in the ccb */ ccb->xfer = xs; if (flags & SCSI_RESET) { ccb->opcode = AHA_RESET_CCB; } else { /* can't use S/G if zero length */ ccb->opcode = (xs->datalen ? aha->sg_opcode : aha->init_opcode); } ccb->target = sc_link->target; ccb->data_out = 0; ccb->data_in = 0; ccb->lun = sc_link->lun; ccb->scsi_cmd_length = xs->cmdlen; /* Some devices (e.g, Microtek ScanMaker II) * fall on the ground if you ask for anything but * an exact number of sense bytes (wiping out the * sense data) * XXX: This was lost at some point in scsi_ioctl.c. */ ccb->req_sense_length = (xs->req_sense_length) ? xs->req_sense_length : sizeof(ccb->scsi_sense); /* XXX: I propose we move the reset handling into the escape * handling. */ if (flags & SCSI_RESET) { flags |= SCSI_ESCAPE; xs->cmd->opcode = SCSI_OP_RESET; } /* Set up the CCB. For an escape function, the escape hook may * set it up for us. */ if (flags & SCSI_ESCAPE) { int ret; ret = aha_escape(xs, ccb); if (ret) return ret; } else if (flags & SCSI_TARGET) { ccb->opcode = AHA_TARGET_CCB; /* These must be set up for target mode: */ if (flags & SCSI_DATA_IN) ccb->data_in = 1; if (flags & SCSI_DATA_OUT) ccb->data_out = 1; } else { ccb->opcode = (xs->datalen? /* can't use S/G if zero length */ AHA_INIT_SCAT_GATH_CCB :AHA_INITIATOR_CCB); } switch(ccb->opcode) { case AHA_TARGET_CCB: if (xs->data) scsi_uto3b(KVTOPHYS((int)xs->data), ccb->data_addr); else scsi_uto3b(0, ccb->data_addr); /* For non scatter-gather I/O (and Target mode doesn't do * scatter-gather) we need to truncate the transfer * at the first non consecutive physical address. */ scsi_uto3b(physcontig((int)xs->data, xs->datalen), ccb->data_length); break; /* This should be folded in with TARGET_CCB once * physcontig is debugged. */ case AHA_INITIATOR_CCB: case AHA_INIT_RESID_CCB: if (xs->data) scsi_uto3b(KVTOPHYS((int)xs->data), ccb->data_addr); else scsi_uto3b(0, ccb->data_addr); scsi_uto3b(xs->datalen, ccb->data_length); break; case AHA_RESET_CCB: scsi_uto3b(0, ccb->data_addr); scsi_uto3b(0, ccb->data_length); break; case AHA_INIT_SCAT_GATH_CCB: case AHA_INIT_SG_RESID_CCB: scsi_uto3b(KVTOPHYS(ccb->scat_gath), ccb->data_addr ); sg = ccb->scat_gath ; seg = 0; #ifdef TFS_ONLY if (flags & SCSI_DATA_UIO) { iovp = ((struct uio *) xs->data)->uio_iov; datalen = ((struct uio *) xs->data)->uio_iovcnt; while ((datalen) && (seg < AHA_NSEG)) { scsi_uto3b(iovp->iov_base, sg->seg_addr); scsi_uto3b(iovp->iov_len, sg->seg_len); SC_DEBUGN(xs->sc_link, SDEV_DB4, ("UIO(0x%x@0x%x)" ,iovp->iov_len ,iovp->iov_base)); sg++; iovp++; seg++; datalen--; } } else #endif /*TFS_ONLY */ { /* * Set up the scatter gather block */ SC_DEBUG(xs->sc_link, SDEV_DB4, ("%ld @%p:- ", xs->datalen, xs->data)); datalen = xs->datalen; thiskv = (int) xs->data; thisphys = KVTOPHYS(thiskv); while ((datalen) && (seg < AHA_NSEG)) { bytes_this_seg = 0; /* put in the base address */ scsi_uto3b(thisphys, sg->seg_addr); SC_DEBUGN(xs->sc_link, SDEV_DB4, ("0x%x", thisphys)); /* do it at least once */ nextphys = thisphys; while ((datalen) && (thisphys == nextphys)) { /* * This page is contiguous (physically) * with the the last, just extend the * length */ /* check it fits on the ISA bus */ if (thisphys > 0xFFFFFF) { printf("aha%d: DMA beyond" " end Of ISA: 0x%x\n", aha->unit, thisphys); xs->error = XS_DRIVER_STUFFUP; aha_free_ccb(aha, ccb, flags); return (HAD_ERROR); } /** how far to the end of the page ***/ nextphys = (thisphys & (~(PAGESIZ - 1))) + PAGESIZ; bytes_this_page = nextphys - thisphys; /**** or the data ****/ bytes_this_page = min(bytes_this_page ,datalen); bytes_this_seg += bytes_this_page; datalen -= bytes_this_page; /**** get more ready for the next page ****/ thiskv = (thiskv & (~(PAGESIZ - 1))) + PAGESIZ; if (datalen) thisphys = KVTOPHYS(thiskv); } /* * next page isn't contiguous, finish the seg */ SC_DEBUGN(xs->sc_link, SDEV_DB4, ("(0x%x)", bytes_this_seg)); scsi_uto3b(bytes_this_seg, sg->seg_len); sg++; seg++; } } scsi_uto3b(seg * sizeof(struct aha_scat_gath), ccb->data_length); SC_DEBUGN(xs->sc_link, SDEV_DB4, ("\n")); if (datalen) { /* there's still data, must have run out of segs! */ printf("aha%d: aha_scsi_cmd, more than %d DMA segs\n", aha->unit, AHA_NSEG); xs->error = XS_DRIVER_STUFFUP; aha_free_ccb(aha, ccb, flags); return (HAD_ERROR); } break; default: printf("aha_scsi_cmd%d: Illegal CCB opcode.\n", aha->unit); xs->error = XS_DRIVER_STUFFUP; aha_free_ccb(aha,ccb,flags); return HAD_ERROR; } scsi_uto3b(0, ccb->link_addr); /* * Put the scsi command in the ccb and start it */ if (!(flags & SCSI_ESCAPE)) bcopy(xs->cmd, &ccb->scsi_cmd, ccb->scsi_cmd_length); if (!(flags & SCSI_NOMASK)) { s = splbio(); /* stop instant timeouts */ xs->timeout_ch = timeout(aha_timeout, (caddr_t)ccb, (xs->timeout * hz) / 1000); aha_startmbx(ccb->mbx); /* * Usually return SUCCESSFULLY QUEUED */ splx(s); SC_DEBUG(xs->sc_link, SDEV_DB3, ("sent\n")); return (SUCCESSFULLY_QUEUED); } aha_startmbx(ccb->mbx); SC_DEBUG(xs->sc_link, SDEV_DB3, ("cmd sent, waiting\n")); /* * If we can't use interrupts, poll on completion */ return (aha_poll(aha, xs, ccb)); /* only during boot */ } /* * Poll a particular unit, looking for a particular xs */ static int aha_poll(aha, xs, ccb) struct aha_data *aha; struct scsi_xfer *xs; struct aha_ccb *ccb; { int count = xs->timeout; u_char stat; /*timeouts are in msec, so we loop in 1000uSec cycles */ while (count) { /* * If we had interrupts enabled, would we * have got an interrupt? */ stat = inb(AHA_INTR_PORT); if (stat & AHA_ANY_INTR) { ahaintr(aha->unit); } if (xs->flags & ITSDONE) { break; } DELAY(1000); /* only happens in boot so ok */ count--; } if (count == 0) { /* * We timed out, so call the timeout handler * manually, accout for the fact that the * clock is not running yet by taking out the * clock queue entry it makes */ aha_timeout((caddr_t)ccb); /* * because we are polling, * take out the timeout entry aha_timeout made */ untimeout(aha_timeout, (caddr_t)ccb, ccb->xfer->timeout_ch); count = 2000; while (count) { /* * Once again, wait for the int bit */ stat = inb(AHA_INTR_PORT); if (stat & AHA_ANY_INTR) { ahaintr(aha->unit); } if (xs->flags & ITSDONE) { break; } DELAY(1000); /* only happens in boot so ok */ count--; } if (count == 0) { /* * We timed out again.. this is bad * Notice that this time there is no * clock queue entry to remove */ aha_timeout((caddr_t)ccb); } } if (xs->error) return (HAD_ERROR); return (COMPLETE); } #ifdef TUNE_1542 /* * Try all the speeds from slowest to fastest.. if it finds a * speed that fails, back off one notch from the last working * speed (unless there is no other notch). * Returns the nSEC value of the time used * or 0 if it could get a working speed (or the NEXT speed * failed) */ static struct bus_speed { char arg; int nsecs; }aha_bus_speeds[] = { {0x88,100}, {0x99,150}, {0xaa,200}, {0xbb,250}, {0xcc,300}, {0xdd,350}, {0xee,400}, {0xff,450} }; static int aha_set_bus_speed(aha) struct aha_data *aha; { int speed; int lastworking; int retval,retval2; lastworking = -1; speed = 7; while (1) { retval = aha_bus_speed_check(aha,speed); if(retval != 0) { lastworking = speed; } if((retval == 0) || (speed == 0)) { if(lastworking == -1) { printf("No working bus speed for aha154X\n"); return 0; } printf("%d nSEC ok, using " ,aha_bus_speeds[lastworking].nsecs); if(lastworking == 7) { /* is slowest already */ printf("marginal "); } else { lastworking++; } retval2 = aha_bus_speed_check(aha,lastworking); if(retval2 == 0) { printf("test retry failed.. aborting.\n"); return 0; } printf("%d nSEC\n",retval2); return retval2 ; } speed--; } } /* * Set the DMA speed to the Nth speed and try an xfer. If it * fails return 0, if it succeeds return the nSec value selected * If there is no such speed return HAD_ERROR. */ static char aha_test_string[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz!@"; u_char aha_scratch_buf[256]; static int aha_bus_speed_check(aha, speed) struct aha_data *aha; int speed; { int numspeeds = sizeof(aha_bus_speeds) / sizeof(struct bus_speed); int loopcount; u_char ad[3]; /* * Check we have such an entry */ if (speed >= numspeeds) return (HAD_ERROR); /* illegal speed */ /* * Set the dma-speed */ aha_cmd(aha, 1, 0, 0, 0, AHA_SPEED_SET, aha_bus_speeds[speed].arg); /* * put the test data into the buffer and calculate * its address. Read it onto the board */ scsi_uto3b(KVTOPHYS(aha_scratch_buf), ad); for(loopcount = 2000;loopcount;loopcount--) { strcpy(aha_scratch_buf, aha_test_string); aha_cmd(aha, 3, 0, 0, 0, AHA_WRITE_FIFO, ad[0], ad[1], ad[2]); /* * clear the buffer then copy the contents back from the * board. */ bzero(aha_scratch_buf, 54); /* 54 bytes transfered by test */ aha_cmd(aha, 3, 0, 0, 0, AHA_READ_FIFO, ad[0], ad[1], ad[2]); /* * Compare the original data and the final data and * return the correct value depending upon the result */ if (strcmp(aha_test_string, aha_scratch_buf)) return 0; /* failed test */ } /* copy succeded assume speed ok */ return (aha_bus_speeds[speed].nsecs); } #endif /*TUNE_1542*/ static void aha_timeout(void *arg1) { struct aha_ccb * ccb = (struct aha_ccb *)arg1; int s = splbio(); struct aha_data *aha; aha = (struct aha_data *)ccb->xfer->sc_link->adapter_softc; sc_print_addr(ccb->xfer->sc_link); printf("timed out "); /* * If The ccb's mbx is not free, then * the board has gone south */ if (ccb->mbx->cmd != AHA_MBO_FREE) { printf("\nadapter not taking commands.. frozen?!\n"); #ifdef DIAGNOSTIC panic("aha1542 frozen"); #endif } /* * If it has been through before, then * a previous abort has failed, don't * try abort again */ if (ccb->flags == CCB_ABORTED) { /* abort timed out */ printf(" AGAIN\n"); ccb->xfer->retries = 0; /* I MEAN IT ! */ ccb->host_stat = AHA_ABORTED; aha_done(aha, ccb); } else { /* abort the operation that has timed out */ printf("\n"); aha_abortmbx(ccb->mbx); /* 4 secs for the abort */ ccb->xfer->timeout_ch = timeout(aha_timeout, (caddr_t)ccb, 4 * hz); ccb->flags = CCB_ABORTED; } splx(s); } Index: head/sys/i386/isa/ic/i82586.h =================================================================== --- head/sys/i386/isa/ic/i82586.h (revision 38231) +++ head/sys/i386/isa/ic/i82586.h (revision 38232) @@ -1,325 +1,325 @@ /*- * Copyright (c) 1992, University of Vermont and State Agricultural College. * Copyright (c) 1992, Garrett A. Wollman. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * Vermont and State Agricultural College and Garrett A. Wollman. * 4. Neither the name of the University nor the name of the author * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR AUTHOR BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: i82586.h,v 1.5 1997/02/22 09:38:02 peter Exp $ + * $Id: i82586.h,v 1.6 1998/04/15 17:45:58 bde Exp $ */ /* * Intel 82586 Ethernet chip * Register, bit, and structure definitions. * * Written by GAW with reference to the Clarkson Packet Driver code for this * chip written by Russ Nelson and others. */ struct ie_en_addr { u_char data[6]; }; /* * This is the master configuration block. It tells the hardware where all * the rest of the stuff is. */ struct ie_sys_conf_ptr { u_short mbz; /* must be zero */ u_char ie_bus_use; /* true if 8-bit only */ u_char mbz2[5]; /* must be zero */ caddr_t ie_iscp_ptr; /* 24-bit physaddr of ISCP */ }; /* * Note that this is wired in hardware; the SCP is always located here, no * matter what. */ #define IE_SCP_ADDR 0xfffff4 /* * The tells the hardware where all the rest of the stuff is, too. * FIXME: some of these should be re-commented after we figure out their * REAL function. */ struct ie_int_sys_conf_ptr { u_char ie_busy; /* zeroed after init */ u_char mbz; u_short ie_scb_offset; /* 16-bit physaddr of next struct */ caddr_t ie_base; /* 24-bit physaddr for all 16-bit vars */ }; /* * This FINALLY tells the hardware what to do and where to put it. */ struct ie_sys_ctl_block { u_short ie_status; /* status word */ u_short ie_command; /* command word */ u_short ie_command_list; /* 16-pointer to command block list */ u_short ie_recv_list; /* 16-pointer to receive frame list */ u_short ie_err_crc; /* CRC errors */ u_short ie_err_align; /* Alignment errors */ u_short ie_err_resource; /* Resource errors */ u_short ie_err_overrun; /* Overrun errors */ }; /* Command values */ #define IE_RU_COMMAND 0x0070 /* mask for RU command */ #define IE_RU_NOP 0 /* for completeness */ #define IE_RU_START 0x0010 /* start receive unit command */ #define IE_RU_ENABLE 0x0020 /* enable receiver command */ #define IE_RU_DISABLE 0x0030 /* disable receiver command */ #define IE_RU_ABORT 0x0040 /* abort current receive operation */ #define IE_CU_COMMAND 0x0700 /* mask for CU command */ #define IE_CU_NOP 0 /* included for completeness */ #define IE_CU_START 0x0100 /* do-command command */ #define IE_CU_RESUME 0x0200 /* resume a suspended cmd list */ #define IE_CU_STOP 0x0300 /* SUSPEND was already taken */ #define IE_CU_ABORT 0x0400 /* abort current command */ #define IE_ACK_COMMAND 0xf000 /* mask for ACK command */ #define IE_ACK_CX 0x8000 /* ack IE_ST_DONE */ #define IE_ACK_FR 0x4000 /* ack IE_ST_RECV */ #define IE_ACK_CNA 0x2000 /* ack IE_ST_ALLDONE */ #define IE_ACK_RNR 0x1000 /* ack IE_ST_RNR */ #define IE_ACTION_COMMAND(x) (((x) & IE_CU_COMMAND) == IE_CU_START) /* is this command an action command? */ /* Status values */ #define IE_ST_WHENCE 0xf000 /* mask for cause of interrupt */ #define IE_ST_DONE 0x8000 /* command with I bit completed */ #define IE_ST_RECV 0x4000 /* frame received */ #define IE_ST_ALLDONE 0x2000 /* all commands completed */ #define IE_ST_RNR 0x1000 /* receive not ready */ #define IE_CU_STATUS 0x700 /* mask for command unit status */ #define IE_CU_ACTIVE 0x200 /* command unit is active */ #define IE_CU_SUSPEND 0x100 /* command unit is suspended */ #define IE_RU_STATUS 0x70 /* mask for receiver unit status */ #define IE_RU_SUSPEND 0x10 /* receiver is suspended */ #define IE_RU_NOSPACE 0x20 /* receiver has no resources */ #define IE_RU_READY 0x40 /* reveiver is ready */ /* * This is filled in partially by the chip, partially by us. */ struct ie_recv_frame_desc { u_short ie_fd_status; /* status for this frame */ u_short ie_fd_last; /* end of frame list flag */ u_short ie_fd_next; /* 16-pointer to next RFD */ u_short ie_fd_buf_desc; /* 16-pointer to list of buffer desc's */ struct ie_en_addr dest; /* destination ether */ struct ie_en_addr src; /* source ether */ u_short ie_length; /* 802 length/Ether type */ u_short mbz; /* must be zero */ }; #define IE_FD_LAST 0x8000 /* last rfd in list */ #define IE_FD_SUSP 0x4000 /* suspend RU after receipt */ #define IE_FD_COMPLETE 0x8000 /* frame is complete */ #define IE_FD_BUSY 0x4000 /* frame is busy */ #define IE_FD_OK 0x2000 /* frame is bad */ #define IE_FD_RNR 0x0200 /* receiver out of resources here */ /* * linked list of buffers... */ struct ie_recv_buf_desc { u_short ie_rbd_actual; /* status for this buffer */ u_short ie_rbd_next; /* 16-pointer to next RBD */ caddr_t ie_rbd_buffer; /* 24-pointer to buffer for this RBD */ u_short ie_rbd_length; /* length of the buffer */ u_short mbz; /* must be zero */ }; #define IE_RBD_LAST 0x8000 /* last buffer */ #define IE_RBD_USED 0x4000 /* this buffer has data */ /* * All commands share this in common. */ struct ie_cmd_common { u_short ie_cmd_status; /* status of this command */ u_short ie_cmd_cmd; /* command word */ u_short ie_cmd_link; /* link to next command */ }; #define IE_STAT_COMPL 0x8000 /* command is completed */ #define IE_STAT_BUSY 0x4000 /* command is running now */ #define IE_STAT_OK 0x2000 /* command completed successfully */ #define IE_CMD_NOP 0x0000 /* NOP */ #define IE_CMD_IASETUP 0x0001 /* initial address setup */ #define IE_CMD_CONFIG 0x0002 /* configure command */ #define IE_CMD_MCAST 0x0003 /* multicast setup command */ #define IE_CMD_XMIT 0x0004 /* transmit command */ #define IE_CMD_TDR 0x0005 /* time-domain reflectometer command */ #define IE_CMD_DUMP 0x0006 /* dump command */ #define IE_CMD_DIAGNOSE 0x0007 /* diagnostics command */ #define IE_CMD_LAST 0x8000 /* this is the last command in the list */ #define IE_CMD_SUSPEND 0x4000 /* suspend CU after this command */ #define IE_CMD_INTR 0x2000 /* post an interrupt after completion */ /* * This is the command to transmit a frame. */ struct ie_xmit_cmd { struct ie_cmd_common com; /* common part */ #define ie_xmit_status com.ie_cmd_status u_short ie_xmit_desc; /* 16-pointer to buffer descriptor */ struct ie_en_addr ie_xmit_addr; /* destination address */ u_short ie_xmit_length; /* 802.3 length/Ether type field */ }; #define IE_XS_MAXCOLL 0x000f /* number of collisions during transmit */ #define IE_XS_EXCMAX 0x0020 /* exceeded maximum number of collisions */ #define IE_XS_SQE 0x0040 /* SQE positive */ #define IE_XS_DEFERRED 0x0080 /* transmission deferred */ #define IE_XS_UNDERRUN 0x0100 /* DMA underrun */ #define IE_XS_LOSTCTS 0x0200 /* Lost CTS */ #define IE_XS_NOCARRIER 0x0400 /* No Carrier */ #define IE_XS_LATECOLL 0x0800 /* Late collision */ /* * This is a buffer descriptor for a frame to be transmitted. */ struct ie_xmit_buf { u_short ie_xmit_flags; /* see below */ u_short ie_xmit_next; /* 16-pointer to next desc. */ caddr_t ie_xmit_buf; /* 24-pointer to the actual buffer */ }; #define IE_XMIT_LAST 0x8000 /* this TBD is the last one */ /* The rest of the `flags' word is actually the length. */ /* * Multicast setup command. */ #define MAXMCAST 50 /* must fit in transmit buffer */ struct ie_mcast_cmd { struct ie_cmd_common com; /* common part */ #define ie_mcast_status com.ie_cmd_status u_short ie_mcast_bytes; /* size (in bytes) of multicast addresses */ struct ie_en_addr ie_mcast_addrs[MAXMCAST + 1]; /* space for them */ }; /* * Time Domain Reflectometer command. */ struct ie_tdr_cmd { struct ie_cmd_common com; /* common part */ #define ie_tdr_status com.ie_cmd_status u_short ie_tdr_time; /* error bits and time */ }; #define IE_TDR_SUCCESS 0x8000 /* TDR succeeded without error */ #define IE_TDR_XCVR 0x4000 /* detected a transceiver problem */ #define IE_TDR_OPEN 0x2000 /* detected an open */ #define IE_TDR_SHORT 0x1000 /* TDR detected a short */ #define IE_TDR_TIME 0x07ff /* mask for reflection time */ /* * Initial Address Setup command */ struct ie_iasetup_cmd { struct ie_cmd_common com; #define ie_iasetup_status com.ie_cmd_status struct ie_en_addr ie_address; }; /* * Configuration command */ struct ie_config_cmd { struct ie_cmd_common com; /* common part */ #define ie_config_status com.ie_cmd_status u_char ie_config_count; /* byte count (0x0c) */ u_char ie_fifo; /* fifo (8) */ u_char ie_save_bad; /* save bad frames (0x40) */ u_char ie_addr_len; /* address length (0x2e) (AL-LOC == 1) */ u_char ie_priority; /* priority and backoff (0x0) */ u_char ie_ifs; /* inter-frame spacing (0x60) */ u_char ie_slot_low; /* slot time, LSB (0x0) */ u_char ie_slot_high; /* slot time, MSN, and retries (0xf2) */ u_char ie_promisc; /* 1 if promiscuous, else 0 */ u_char ie_crs_cdt; /* CSMA/CD parameters (0x0) */ u_char ie_min_len; /* min frame length (0x40) */ u_char ie_junk; /* stuff for 82596 (0xff) */ }; /* * Here are a few useful functions. We could have done these as macros, * but since we have the inline facility, it makes sense to use that * instead. */ static __inline void ie_setup_config(volatile struct ie_config_cmd *cmd, int promiscuous, int manchester) { cmd->ie_config_count = 0x0c; cmd->ie_fifo = 8; cmd->ie_save_bad = 0x40; cmd->ie_addr_len = 0x2e; cmd->ie_priority = 0; cmd->ie_ifs = 0x60; cmd->ie_slot_low = 0; cmd->ie_slot_high = 0xf2; cmd->ie_promisc = !!promiscuous | manchester << 2; cmd->ie_crs_cdt = 0; cmd->ie_min_len = 64; cmd->ie_junk = 0xff; } static __inline caddr_t Align(caddr_t ptr) { - unsigned long l = (unsigned long)ptr; + uintptr_t l = (uintptr_t)ptr; l = (l + 3) & ~3L; return (caddr_t)l; } static __inline void ie_ack(volatile struct ie_sys_ctl_block *scb, u_int mask, int unit, void (*ca)(int)) { scb->ie_command = scb->ie_status & mask; (*ca)(unit); } Index: head/sys/i386/isa/if_ie.c =================================================================== --- head/sys/i386/isa/if_ie.c (revision 38231) +++ head/sys/i386/isa/if_ie.c (revision 38232) @@ -1,2427 +1,2431 @@ /*- * Copyright (c) 1992, 1993, University of Vermont and State * Agricultural College. * Copyright (c) 1992, 1993, Garrett A. Wollman. * * Portions: * Copyright (c) 1990, 1991, William F. Jolitz * Copyright (c) 1990, The Regents of the University of California * * 3Com 3C507 support: * Copyright (c) 1993, 1994, Charles M. Hannum * * EtherExpress 16 support: * Copyright (c) 1993, 1994, 1995, Rodney W. Grimes * Copyright (c) 1997, Aaron C. Smith * * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * Vermont and State Agricultural College and Garrett A. Wollman, by * William F. Jolitz, by the University of California, Berkeley, * Lawrence Berkeley Laboratory, and their contributors, by * Charles M. Hannum, by Rodney W. Grimes, and by Aaron C. Smith. * 4. Neither the names of the Universities nor the names of the authors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR AUTHORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: if_ie.c,v 1.54 1998/07/13 09:52:59 bde Exp $ + * $Id: if_ie.c,v 1.55 1998/08/10 14:27:32 bde Exp $ */ /* * Intel 82586 Ethernet chip * Register, bit, and structure definitions. * * Written by GAW with reference to the Clarkson Packet Driver code for this * chip written by Russ Nelson and others. * * Intel EtherExpress 16 support from if_ix.c, written by Rodney W. Grimes. */ /* * The i82586 is a very versatile chip, found in many implementations. * Programming this chip is mostly the same, but certain details differ * from card to card. This driver is written so that different cards * can be automatically detected at run-time. */ /* Mode of operation: We run the 82586 in a standard Ethernet mode. We keep NFRAMES received frame descriptors around for the receiver to use, and NRXBUFS associated receive buffer descriptors, both in a circular list. Whenever a frame is received, we rotate both lists as necessary. (The 586 treats both lists as a simple queue.) We also keep a transmit command around so that packets can be sent off quickly. We configure the adapter in AL-LOC = 1 mode, which means that the Ethernet/802.3 MAC header is placed at the beginning of the receive buffer rather than being split off into various fields in the RFD. This also means that we must include this header in the transmit buffer as well. By convention, all transmit commands, and only transmit commands, shall have the I (IE_CMD_INTR) bit set in the command. This way, when an interrupt arrives at ieintr(), it is immediately possible to tell what precisely caused it. ANY OTHER command-sending routines should run at splimp(), and should post an acknowledgement to every interrupt they generate. The 82586 has a 24-bit address space internally, and the adaptor's memory is located at the top of this region. However, the value we are given in configuration is normally the *bottom* of the adaptor RAM. So, we must go through a few gyrations to come up with a kernel virtual address which represents the actual beginning of the 586 address space. First, we autosize the RAM by running through several possible sizes and trying to initialize the adapter under the assumption that the selected size is correct. Then, knowing the correct RAM size, we set up our pointers in ie_softc[unit]. `iomem' represents the computed base of the 586 address space. `iomembot' represents the actual configured base of adapter RAM. Finally, `iosize' represents the calculated size of 586 RAM. Then, when laying out commands, we use the interval [iomembot, iomembot + iosize); to make 24-pointers, we subtract iomem, and to make 16-pointers, we subtract iomem and and with 0xffff. */ #include "ie.h" #if NIE > 0 #include "opt_inet.h" #include "opt_ipx.h" #include #include #include #include #include #include #include #include #include #include #include #include #include "bpfilter.h" #ifdef INET #include #include #endif #ifdef IPX #include #include #endif #ifdef NS #include #include #endif #include #include #include #include #include #include #include #include #include #if NBPFILTER > 0 #include #endif #ifdef DEBUG #define IED_RINT 0x01 #define IED_TINT 0x02 #define IED_RNR 0x04 #define IED_CNA 0x08 #define IED_READFRAME 0x10 static int ie_debug = IED_RNR; #endif #define IE_BUF_LEN ETHER_MAX_LEN /* length of transmit buffer */ /* Forward declaration */ struct ie_softc; static struct mbuf *last_not_for_us; static int ieprobe(struct isa_device * dvp); static int ieattach(struct isa_device * dvp); static int sl_probe(struct isa_device * dvp); static int el_probe(struct isa_device * dvp); static int ni_probe(struct isa_device * dvp); static int ee16_probe(struct isa_device * dvp); static int check_ie_present(int unit, caddr_t where, unsigned size); static void ieinit(int unit); static void ie_stop(int unit); static int ieioctl(struct ifnet * ifp, u_long command, caddr_t data); static void iestart(struct ifnet * ifp); static void el_reset_586(int unit); static void el_chan_attn(int unit); static void sl_reset_586(int unit); static void sl_chan_attn(int unit); static void ee16_reset_586(int unit); static void ee16_chan_attn(int unit); static __inline void ee16_interrupt_enable(struct ie_softc * ie); static void ee16_eeprom_outbits(struct ie_softc * ie, int edata, int cnt); static void ee16_eeprom_clock(struct ie_softc * ie, int state); static u_short ee16_read_eeprom(struct ie_softc * ie, int location); static int ee16_eeprom_inbits(struct ie_softc * ie); static void ee16_shutdown(int howto, void *sc); static void iereset(int unit); static void ie_readframe(int unit, struct ie_softc * ie, int bufno); static void ie_drop_packet_buffer(int unit, struct ie_softc * ie); static void sl_read_ether(int unit, unsigned char addr[6]); static void find_ie_mem_size(int unit); static void chan_attn_timeout(void *rock); static int command_and_wait(int unit, int command, void volatile * pcmd, int); static void run_tdr(int unit, struct ie_tdr_cmd * cmd); static int ierint(int unit, struct ie_softc * ie); static int ietint(int unit, struct ie_softc * ie); static int iernr(int unit, struct ie_softc * ie); static void start_receiver(int unit); static __inline int ieget(int, struct ie_softc *, struct mbuf **, struct ether_header *, int *); static caddr_t setup_rfa(caddr_t ptr, struct ie_softc * ie); static int mc_setup(int, caddr_t, volatile struct ie_sys_ctl_block *); static void ie_mc_reset(int unit); #ifdef DEBUG static void print_rbd(volatile struct ie_recv_buf_desc * rbd); static int in_ierint = 0; static int in_ietint = 0; #endif /* * This tells the autoconf code how to set us up. */ struct isa_driver iedriver = { ieprobe, ieattach, "ie", }; enum ie_hardware { IE_STARLAN10, IE_EN100, IE_SLFIBER, IE_3C507, IE_NI5210, IE_EE16, IE_UNKNOWN }; static const char *ie_hardware_names[] = { "StarLAN 10", "EN100", "StarLAN Fiber", "3C507", "NI5210", "EtherExpress 16", "Unknown" }; /* sizeof(iscp) == 1+1+2+4 == 8 sizeof(scb) == 2+2+2+2+2+2+2+2 == 16 NFRAMES * sizeof(rfd) == NFRAMES*(2+2+2+2+6+6+2+2) == NFRAMES*24 == 384 sizeof(xmit_cmd) == 2+2+2+2+6+2 == 18 sizeof(transmit buffer) == 1512 sizeof(transmit buffer desc) == 8 ----- 1946 NRXBUFS * sizeof(rbd) == NRXBUFS*(2+2+4+2+2) == NRXBUFS*12 NRXBUFS * IE_RBUF_SIZE == NRXBUFS*256 NRXBUFS should be (16384 - 1946) / (256 + 12) == 14438 / 268 == 53 With NRXBUFS == 48, this leaves us 1574 bytes for another command or more buffers. Another transmit command would be 18+8+1512 == 1538 ---just barely fits! Obviously all these would have to be reduced for smaller memory sizes. With a larger memory, it would be possible to roughly double the number of both transmit and receive buffers. */ #define NFRAMES 8 /* number of receive frames */ #define NRXBUFS 48 /* number of buffers to allocate */ #define IE_RBUF_SIZE 256 /* size of each buffer, MUST BE POWER OF TWO */ #define NTXBUFS 2 /* number of transmit commands */ #define IE_TBUF_SIZE ETHER_MAX_LEN /* size of transmit buffer */ /* * Ethernet status, per interface. */ static struct ie_softc { struct arpcom arpcom; void (*ie_reset_586) (int); void (*ie_chan_attn) (int); enum ie_hardware hard_type; int hard_vers; u_short port; /* i/o base address for this interface */ caddr_t iomem; /* memory size */ caddr_t iomembot; /* memory base address */ unsigned iosize; int bus_use; /* 0 means 16bit, 1 means 8 bit adapter */ int want_mcsetup; int promisc; int nframes; int nrxbufs; int ntxbufs; volatile struct ie_int_sys_conf_ptr *iscp; volatile struct ie_sys_ctl_block *scb; volatile struct ie_recv_frame_desc **rframes; /* nframes worth */ volatile struct ie_recv_buf_desc **rbuffs; /* nrxbufs worth */ volatile u_char **cbuffs; /* nrxbufs worth */ int rfhead, rftail, rbhead, rbtail; volatile struct ie_xmit_cmd **xmit_cmds; /* ntxbufs worth */ volatile struct ie_xmit_buf **xmit_buffs; /* ntxbufs worth */ u_char **xmit_cbuffs; /* ntxbufs worth */ int xmit_count; struct ie_en_addr mcast_addrs[MAXMCAST + 1]; int mcast_count; u_short irq_encoded; /* encoded interrupt on IEE16 */ } ie_softc[NIE]; -#define MK_24(base, ptr) ((caddr_t)((u_long)ptr - (u_long)base)) -#define MK_16(base, ptr) ((u_short)(u_long)MK_24(base, ptr)) +#define MK_24(base, ptr) ((caddr_t)((uintptr_t)ptr - (uintptr_t)base)) +#define MK_16(base, ptr) ((u_short)(uintptr_t)MK_24(base, ptr)) #define PORT ie_softc[unit].port #define MEM ie_softc[unit].iomem int ieprobe(struct isa_device *dvp) { int ret; ret = sl_probe(dvp); if (!ret) ret = el_probe(dvp); if (!ret) ret = ni_probe(dvp); if (!ret) ret = ee16_probe(dvp); return (ret); } static int sl_probe(struct isa_device *dvp) { int unit = dvp->id_unit; u_char c; ie_softc[unit].port = dvp->id_iobase; ie_softc[unit].iomembot = dvp->id_maddr; ie_softc[unit].iomem = 0; ie_softc[unit].bus_use = 0; c = inb(PORT + IEATT_REVISION); switch (SL_BOARD(c)) { case SL10_BOARD: ie_softc[unit].hard_type = IE_STARLAN10; ie_softc[unit].ie_reset_586 = sl_reset_586; ie_softc[unit].ie_chan_attn = sl_chan_attn; break; case EN100_BOARD: ie_softc[unit].hard_type = IE_EN100; ie_softc[unit].ie_reset_586 = sl_reset_586; ie_softc[unit].ie_chan_attn = sl_chan_attn; break; case SLFIBER_BOARD: ie_softc[unit].hard_type = IE_SLFIBER; ie_softc[unit].ie_reset_586 = sl_reset_586; ie_softc[unit].ie_chan_attn = sl_chan_attn; break; /* * Anything else is not recognized or cannot be used. */ default: return (0); } ie_softc[unit].hard_vers = SL_REV(c); /* * Divine memory size on-board the card. Ususally 16k. */ find_ie_mem_size(unit); if (!ie_softc[unit].iosize) { return (0); } dvp->id_msize = ie_softc[unit].iosize; switch (ie_softc[unit].hard_type) { case IE_EN100: case IE_STARLAN10: case IE_SLFIBER: sl_read_ether(unit, ie_softc[unit].arpcom.ac_enaddr); break; default: if (bootverbose) printf("ie%d: unknown AT&T board type code %d\n", unit, ie_softc[unit].hard_type); return (0); } return (1); } static int el_probe(struct isa_device *dvp) { struct ie_softc *sc = &ie_softc[dvp->id_unit]; u_char c; int i; u_char signature[] = "*3COM*"; int unit = dvp->id_unit; sc->port = dvp->id_iobase; sc->iomembot = dvp->id_maddr; sc->bus_use = 0; /* Need this for part of the probe. */ sc->ie_reset_586 = el_reset_586; sc->ie_chan_attn = el_chan_attn; /* Reset and put card in CONFIG state without changing address. */ elink_reset(); outb(ELINK_ID_PORT, 0x00); elink_idseq(ELINK_507_POLY); elink_idseq(ELINK_507_POLY); outb(ELINK_ID_PORT, 0xff); c = inb(PORT + IE507_MADDR); if (c & 0x20) { #ifdef DEBUG printf("ie%d: can't map 3C507 RAM in high memory\n", unit); #endif return (0); } /* go to RUN state */ outb(ELINK_ID_PORT, 0x00); elink_idseq(ELINK_507_POLY); outb(ELINK_ID_PORT, 0x00); outb(PORT + IE507_CTRL, EL_CTRL_NRST); for (i = 0; i < 6; i++) if (inb(PORT + i) != signature[i]) return (0); c = inb(PORT + IE507_IRQ) & 0x0f; if (dvp->id_irq != (1 << c)) { printf("ie%d: kernel configured irq %d " "doesn't match board configured irq %d\n", unit, ffs(dvp->id_irq) - 1, c); return (0); } c = (inb(PORT + IE507_MADDR) & 0x1c) + 0xc0; if (kvtop(dvp->id_maddr) != ((int) c << 12)) { printf("ie%d: kernel configured maddr %lx " "doesn't match board configured maddr %x\n", unit, kvtop(dvp->id_maddr), (int) c << 12); return (0); } outb(PORT + IE507_CTRL, EL_CTRL_NORMAL); sc->hard_type = IE_3C507; sc->hard_vers = 0; /* 3C507 has no version number. */ /* * Divine memory size on-board the card. */ find_ie_mem_size(unit); if (!sc->iosize) { printf("ie%d: can't find shared memory\n", unit); outb(PORT + IE507_CTRL, EL_CTRL_NRST); return (0); } if (!dvp->id_msize) dvp->id_msize = sc->iosize; else if (dvp->id_msize != sc->iosize) { printf("ie%d: kernel configured msize %d " "doesn't match board configured msize %d\n", unit, dvp->id_msize, sc->iosize); outb(PORT + IE507_CTRL, EL_CTRL_NRST); return (0); } sl_read_ether(unit, ie_softc[unit].arpcom.ac_enaddr); /* Clear the interrupt latch just in case. */ outb(PORT + IE507_ICTRL, 1); return (16); } static int ni_probe(struct isa_device *dvp) { int unit = dvp->id_unit; int boardtype, c; ie_softc[unit].port = dvp->id_iobase; ie_softc[unit].iomembot = dvp->id_maddr; ie_softc[unit].iomem = 0; ie_softc[unit].bus_use = 1; boardtype = inb(PORT + IEATT_REVISION); c = inb(PORT + IEATT_REVISION + 1); boardtype = boardtype + (c << 8); switch (boardtype) { case 0x5500: /* This is the magic cookie for the NI5210 */ ie_softc[unit].hard_type = IE_NI5210; ie_softc[unit].ie_reset_586 = sl_reset_586; ie_softc[unit].ie_chan_attn = sl_chan_attn; break; /* * Anything else is not recognized or cannot be used. */ default: return (0); } ie_softc[unit].hard_vers = 0; /* * Divine memory size on-board the card. Either 8 or 16k. */ find_ie_mem_size(unit); if (!ie_softc[unit].iosize) { return (0); } if (!dvp->id_msize) dvp->id_msize = ie_softc[unit].iosize; else if (dvp->id_msize != ie_softc[unit].iosize) { printf("ie%d: kernel configured msize %d " "doesn't match board configured msize %d\n", unit, dvp->id_msize, ie_softc[unit].iosize); return (0); } sl_read_ether(unit, ie_softc[unit].arpcom.ac_enaddr); return (8); } static void ee16_shutdown(int howto, void *sc) { struct ie_softc *ie = (struct ie_softc *)sc; int unit = ie - &ie_softc[0]; ee16_reset_586(unit); outb(PORT + IEE16_ECTRL, IEE16_RESET_ASIC); outb(PORT + IEE16_ECTRL, 0); } /* Taken almost exactly from Rod's if_ix.c. */ int ee16_probe(struct isa_device *dvp) { struct ie_softc *sc = &ie_softc[dvp->id_unit]; int i; int unit = dvp->id_unit; u_short board_id, id_var1, id_var2, checksum = 0; u_short eaddrtemp, irq; u_short pg, adjust, decode, edecode; u_char bart_config; u_long bd_maddr; short irq_translate[] = {0, IRQ9, IRQ3, IRQ4, IRQ5, IRQ10, IRQ11, 0}; char irq_encode[] = {0, 0, 0, 2, 3, 4, 0, 0, 0, 1, 5, 6, 0, 0, 0, 0}; /* Need this for part of the probe. */ sc->ie_reset_586 = ee16_reset_586; sc->ie_chan_attn = ee16_chan_attn; /* unsure if this is necessary */ sc->bus_use = 0; /* reset any ee16 at the current iobase */ outb(dvp->id_iobase + IEE16_ECTRL, IEE16_RESET_ASIC); outb(dvp->id_iobase + IEE16_ECTRL, 0); DELAY(240); /* now look for ee16. */ board_id = id_var1 = id_var2 = 0; for (i = 0; i < 4; i++) { id_var1 = inb(dvp->id_iobase + IEE16_ID_PORT); id_var2 = ((id_var1 & 0x03) << 2); board_id |= ((id_var1 >> 4) << id_var2); } if (board_id != IEE16_ID) { printf("ie%d: unknown board_id: %x\n", unit, board_id); return (0); } /* need sc->port for ee16_read_eeprom */ sc->port = dvp->id_iobase; sc->hard_type = IE_EE16; /* * The shared RAM location on the EE16 is encoded into bits 3-7 of * EEPROM location 6. We zero the upper byte, and shift the 5 bits * right 3. The resulting number tells us the RAM location. * Because the EE16 supports either 16k or 32k of shared RAM, we * only worry about the 32k locations. * * NOTE: if a 64k EE16 exists, it should be added to this switch. then * the ia->ia_msize would need to be set per case statement. * * value msize location ===== ===== ======== 0x03 0x8000 * 0xCC000 0x06 0x8000 0xD0000 0x0C 0x8000 0xD4000 0x18 * 0x8000 0xD8000 * */ bd_maddr = 0; i = (ee16_read_eeprom(sc, 6) & 0x00ff) >> 3; switch (i) { case 0x03: bd_maddr = 0xCC000; break; case 0x06: bd_maddr = 0xD0000; break; case 0x0c: bd_maddr = 0xD4000; break; case 0x18: bd_maddr = 0xD8000; break; default: bd_maddr = 0; break; } dvp->id_msize = 0x8000; if (kvtop(dvp->id_maddr) != bd_maddr) { printf("ie%d: kernel configured maddr %lx " "doesn't match board configured maddr %lx\n", unit, kvtop(dvp->id_maddr), bd_maddr); } sc->iomembot = dvp->id_maddr; sc->iomem = 0; /* XXX some probes set this and some don't */ sc->iosize = dvp->id_msize; /* need to put the 586 in RESET while we access the eeprom. */ outb(PORT + IEE16_ECTRL, IEE16_RESET_586); /* read the eeprom and checksum it, should == IEE16_ID */ for (i = 0; i < 0x40; i++) checksum += ee16_read_eeprom(sc, i); if (checksum != IEE16_ID) { printf("ie%d: invalid eeprom checksum: %x\n", unit, checksum); return (0); } /* * Size and test the memory on the board. The size of the memory * can be one of 16k, 32k, 48k or 64k. It can be located in the * address range 0xC0000 to 0xEFFFF on 16k boundaries. * * If the size does not match the passed in memory allocation size * issue a warning, but continue with the minimum of the two sizes. */ switch (dvp->id_msize) { case 65536: case 32768: /* XXX Only support 32k and 64k right now */ break; case 16384: case 49512: default: printf("ie%d: mapped memory size %d not supported\n", unit, dvp->id_msize); return (0); break; /* NOTREACHED */ } if ((kvtop(dvp->id_maddr) < 0xC0000) || (kvtop(dvp->id_maddr) + sc->iosize > 0xF0000)) { printf("ie%d: mapped memory location %p out of range\n", unit, (void *)dvp->id_maddr); return (0); } pg = (kvtop(dvp->id_maddr) & 0x3C000) >> 14; adjust = IEE16_MCTRL_FMCS16 | (pg & 0x3) << 2; decode = ((1 << (sc->iosize / 16384)) - 1) << pg; edecode = ((~decode >> 4) & 0xF0) | (decode >> 8); /* ZZZ This should be checked against eeprom location 6, low byte */ outb(PORT + IEE16_MEMDEC, decode & 0xFF); /* ZZZ This should be checked against eeprom location 1, low byte */ outb(PORT + IEE16_MCTRL, adjust); /* ZZZ Now if I could find this one I would have it made */ outb(PORT + IEE16_MPCTRL, (~decode & 0xFF)); /* ZZZ I think this is location 6, high byte */ outb(PORT + IEE16_MECTRL, edecode); /* XXX disable Exxx */ (void) kvtop(dvp->id_maddr); /* * first prime the stupid bart DRAM controller so that it works, * then zero out all of memory. */ bzero(sc->iomembot, 32); bzero(sc->iomembot, sc->iosize); /* * Get the encoded interrupt number from the EEPROM, check it * against the passed in IRQ. Issue a warning if they do not match. * Always use the passed in IRQ, not the one in the EEPROM. */ irq = ee16_read_eeprom(sc, IEE16_EEPROM_CONFIG1); irq = (irq & IEE16_EEPROM_IRQ) >> IEE16_EEPROM_IRQ_SHIFT; irq = irq_translate[irq]; if (dvp->id_irq > 0) { if (irq != dvp->id_irq) { printf("ie%d: WARNING: board configured " "at irq %u, using %u\n", dvp->id_unit, dvp->id_irq, irq); irq = dvp->id_unit; } } else { dvp->id_irq = irq; } sc->irq_encoded = irq_encode[ffs(irq) - 1]; /* * Get the hardware ethernet address from the EEPROM and save it in * the softc for use by the 586 setup code. */ eaddrtemp = ee16_read_eeprom(sc, IEE16_EEPROM_ENET_HIGH); sc->arpcom.ac_enaddr[1] = eaddrtemp & 0xFF; sc->arpcom.ac_enaddr[0] = eaddrtemp >> 8; eaddrtemp = ee16_read_eeprom(sc, IEE16_EEPROM_ENET_MID); sc->arpcom.ac_enaddr[3] = eaddrtemp & 0xFF; sc->arpcom.ac_enaddr[2] = eaddrtemp >> 8; eaddrtemp = ee16_read_eeprom(sc, IEE16_EEPROM_ENET_LOW); sc->arpcom.ac_enaddr[5] = eaddrtemp & 0xFF; sc->arpcom.ac_enaddr[4] = eaddrtemp >> 8; /* disable the board interrupts */ outb(PORT + IEE16_IRQ, sc->irq_encoded); /* enable loopback to keep bad packets off the wire */ if (sc->hard_type == IE_EE16) { bart_config = inb(PORT + IEE16_CONFIG); bart_config |= IEE16_BART_LOOPBACK; bart_config |= IEE16_BART_MCS16_TEST;/* inb doesn't get bit! */ outb(PORT + IEE16_CONFIG, bart_config); bart_config = inb(PORT + IEE16_CONFIG); } /* take the board out of reset state */ outb(PORT + IEE16_ECTRL, 0); DELAY(100); if (!check_ie_present(unit, dvp->id_maddr, sc->iosize)) return (0); return (16); /* return the number of I/O ports */ } /* * Taken almost exactly from Bill's if_is.c, then modified beyond recognition. */ int ieattach(struct isa_device *dvp) { int factor; int unit = dvp->id_unit; struct ie_softc *ie = &ie_softc[unit]; struct ifnet *ifp = &ie->arpcom.ac_if; size_t allocsize; /* * based on the amount of memory we have, allocate our tx and rx * resources. */ factor = dvp->id_msize / 16384; ie->nframes = factor * NFRAMES; ie->nrxbufs = factor * NRXBUFS; ie->ntxbufs = factor * NTXBUFS; /* * Since all of these guys are arrays of pointers, allocate as one * big chunk and dole out accordingly. */ allocsize = sizeof(void *) * (ie->nframes + (ie->nrxbufs * 2) + (ie->ntxbufs * 3)); ie->rframes = (volatile struct ie_recv_frame_desc **) malloc(allocsize, M_DEVBUF, M_NOWAIT); if (ie->rframes == NULL) return (0); ie->rbuffs = (volatile struct ie_recv_buf_desc **)&ie->rframes[ie->nframes]; ie->cbuffs = (volatile u_char **)&ie->rbuffs[ie->nrxbufs]; ie->xmit_cmds = (volatile struct ie_xmit_cmd **)&ie->cbuffs[ie->nrxbufs]; ie->xmit_buffs = (volatile struct ie_xmit_buf **)&ie->xmit_cmds[ie->ntxbufs]; ie->xmit_cbuffs = (u_char **)&ie->xmit_buffs[ie->ntxbufs]; ifp->if_softc = ie; ifp->if_unit = unit; ifp->if_name = iedriver.name; ifp->if_mtu = ETHERMTU; printf("ie%d: <%s R%d> address %6D\n", unit, ie_hardware_names[ie->hard_type], ie->hard_vers + 1, ie->arpcom.ac_enaddr, ":"); ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; ifp->if_output = ether_output; ifp->if_start = iestart; ifp->if_ioctl = ieioctl; ifp->if_type = IFT_ETHER; ifp->if_addrlen = 6; ifp->if_hdrlen = 14; if (ie->hard_type == IE_EE16) at_shutdown(ee16_shutdown, ie, SHUTDOWN_POST_SYNC); #if NBPFILTER > 0 bpfattach(ifp, DLT_EN10MB, sizeof(struct ether_header)); #endif if_attach(ifp); ether_ifattach(ifp); return (1); } /* * What to do upon receipt of an interrupt. */ void ieintr(int unit) { register struct ie_softc *ie = &ie_softc[unit]; register u_short status; /* Clear the interrupt latch on the 3C507. */ if (ie->hard_type == IE_3C507 && (inb(PORT + IE507_CTRL) & EL_CTRL_INTL)) outb(PORT + IE507_ICTRL, 1); /* disable interrupts on the EE16. */ if (ie->hard_type == IE_EE16) outb(PORT + IEE16_IRQ, ie->irq_encoded); status = ie->scb->ie_status; loop: /* Don't ack interrupts which we didn't receive */ ie_ack(ie->scb, IE_ST_WHENCE & status, unit, ie->ie_chan_attn); if (status & (IE_ST_RECV | IE_ST_RNR)) { #ifdef DEBUG in_ierint++; if (ie_debug & IED_RINT) printf("ie%d: rint\n", unit); #endif ierint(unit, ie); #ifdef DEBUG in_ierint--; #endif } if (status & IE_ST_DONE) { #ifdef DEBUG in_ietint++; if (ie_debug & IED_TINT) printf("ie%d: tint\n", unit); #endif ietint(unit, ie); #ifdef DEBUG in_ietint--; #endif } if (status & IE_ST_RNR) { #ifdef DEBUG if (ie_debug & IED_RNR) printf("ie%d: rnr\n", unit); #endif iernr(unit, ie); } #ifdef DEBUG if ((status & IE_ST_ALLDONE) && (ie_debug & IED_CNA)) printf("ie%d: cna\n", unit); #endif if ((status = ie->scb->ie_status) & IE_ST_WHENCE) goto loop; /* Clear the interrupt latch on the 3C507. */ if (ie->hard_type == IE_3C507) outb(PORT + IE507_ICTRL, 1); /* enable interrupts on the EE16. */ if (ie->hard_type == IE_EE16) outb(PORT + IEE16_IRQ, ie->irq_encoded | IEE16_IRQ_ENABLE); } /* * Process a received-frame interrupt. */ static int ierint(int unit, struct ie_softc *ie) { int i, status; static int timesthru = 1024; i = ie->rfhead; while (1) { status = ie->rframes[i]->ie_fd_status; if ((status & IE_FD_COMPLETE) && (status & IE_FD_OK)) { ie->arpcom.ac_if.if_ipackets++; if (!--timesthru) { ie->arpcom.ac_if.if_ierrors += ie->scb->ie_err_crc + ie->scb->ie_err_align + ie->scb->ie_err_resource + ie->scb->ie_err_overrun; ie->scb->ie_err_crc = 0; ie->scb->ie_err_align = 0; ie->scb->ie_err_resource = 0; ie->scb->ie_err_overrun = 0; timesthru = 1024; } ie_readframe(unit, ie, i); } else { if (status & IE_FD_RNR) { if (!(ie->scb->ie_status & IE_RU_READY)) { ie->rframes[0]->ie_fd_next = MK_16(MEM, ie->rbuffs[0]); ie->scb->ie_recv_list = MK_16(MEM, ie->rframes[0]); command_and_wait(unit, IE_RU_START, 0, 0); } } break; } i = (i + 1) % ie->nframes; } return (0); } /* * Process a command-complete interrupt. These are only generated by * the transmission of frames. This routine is deceptively simple, since * most of the real work is done by iestart(). */ static int ietint(int unit, struct ie_softc *ie) { int status; int i; ie->arpcom.ac_if.if_timer = 0; ie->arpcom.ac_if.if_flags &= ~IFF_OACTIVE; for (i = 0; i < ie->xmit_count; i++) { status = ie->xmit_cmds[i]->ie_xmit_status; if (status & IE_XS_LATECOLL) { printf("ie%d: late collision\n", unit); ie->arpcom.ac_if.if_collisions++; ie->arpcom.ac_if.if_oerrors++; } else if (status & IE_XS_NOCARRIER) { printf("ie%d: no carrier\n", unit); ie->arpcom.ac_if.if_oerrors++; } else if (status & IE_XS_LOSTCTS) { printf("ie%d: lost CTS\n", unit); ie->arpcom.ac_if.if_oerrors++; } else if (status & IE_XS_UNDERRUN) { printf("ie%d: DMA underrun\n", unit); ie->arpcom.ac_if.if_oerrors++; } else if (status & IE_XS_EXCMAX) { printf("ie%d: too many collisions\n", unit); ie->arpcom.ac_if.if_collisions += 16; ie->arpcom.ac_if.if_oerrors++; } else { ie->arpcom.ac_if.if_opackets++; ie->arpcom.ac_if.if_collisions += status & IE_XS_MAXCOLL; } } ie->xmit_count = 0; /* * If multicast addresses were added or deleted while we were * transmitting, ie_mc_reset() set the want_mcsetup flag indicating * that we should do it. */ if (ie->want_mcsetup) { mc_setup(unit, (caddr_t) ie->xmit_cbuffs[0], ie->scb); ie->want_mcsetup = 0; } /* Wish I knew why this seems to be necessary... */ ie->xmit_cmds[0]->ie_xmit_status |= IE_STAT_COMPL; iestart(&ie->arpcom.ac_if); return (0); /* shouldn't be necessary */ } /* * Process a receiver-not-ready interrupt. I believe that we get these * when there aren't enough buffers to go around. For now (FIXME), we * just restart the receiver, and hope everything's ok. */ static int iernr(int unit, struct ie_softc *ie) { #ifdef doesnt_work setup_rfa((caddr_t) ie->rframes[0], ie); ie->scb->ie_recv_list = MK_16(MEM, ie_softc[unit].rframes[0]); command_and_wait(unit, IE_RU_START, 0, 0); #else /* This doesn't work either, but it doesn't hang either. */ command_and_wait(unit, IE_RU_DISABLE, 0, 0); /* just in case */ setup_rfa((caddr_t) ie->rframes[0], ie); /* ignore cast-qual */ ie->scb->ie_recv_list = MK_16(MEM, ie_softc[unit].rframes[0]); command_and_wait(unit, IE_RU_START, 0, 0); /* was ENABLE */ #endif ie_ack(ie->scb, IE_ST_WHENCE, unit, ie->ie_chan_attn); ie->arpcom.ac_if.if_ierrors++; return (0); } /* * Compare two Ether/802 addresses for equality, inlined and * unrolled for speed. I'd love to have an inline assembler * version of this... */ static __inline int ether_equal(u_char * one, u_char * two) { if (one[0] != two[0]) return (0); if (one[1] != two[1]) return (0); if (one[2] != two[2]) return (0); if (one[3] != two[3]) return (0); if (one[4] != two[4]) return (0); if (one[5] != two[5]) return (0); return 1; } /* * Check for a valid address. to_bpf is filled in with one of the following: * 0 -> BPF doesn't get this packet * 1 -> BPF does get this packet * 2 -> BPF does get this packet, but we don't * Return value is true if the packet is for us, and false otherwise. * * This routine is a mess, but it's also critical that it be as fast * as possible. It could be made cleaner if we can assume that the * only client which will fiddle with IFF_PROMISC is BPF. This is * probably a good assumption, but we do not make it here. (Yet.) */ static __inline int check_eh(struct ie_softc * ie, struct ether_header * eh, int *to_bpf) { int i; switch (ie->promisc) { case IFF_ALLMULTI: /* * Receiving all multicasts, but no unicasts except those * destined for us. */ #if NBPFILTER > 0 /* BPF gets this packet if anybody cares */ *to_bpf = (ie->arpcom.ac_if.if_bpf != 0); #endif if (eh->ether_dhost[0] & 1) { return (1); } if (ether_equal(eh->ether_dhost, ie->arpcom.ac_enaddr)) return (1); return (0); case IFF_PROMISC: /* * Receiving all packets. These need to be passed on to * BPF. */ #if NBPFILTER > 0 *to_bpf = (ie->arpcom.ac_if.if_bpf != 0); #endif /* If for us, accept and hand up to BPF */ if (ether_equal(eh->ether_dhost, ie->arpcom.ac_enaddr)) return (1); #if NBPFILTER > 0 if (*to_bpf) *to_bpf = 2; /* we don't need to see it */ #endif /* * Not a multicast, so BPF wants to see it but we don't. */ if (!(eh->ether_dhost[0] & 1)) return (1); /* * If it's one of our multicast groups, accept it and pass * it up. */ for (i = 0; i < ie->mcast_count; i++) { if (ether_equal(eh->ether_dhost, (u_char *)&ie->mcast_addrs[i])) { #if NBPFILTER > 0 if (*to_bpf) *to_bpf = 1; #endif return (1); } } return (1); case IFF_ALLMULTI | IFF_PROMISC: /* * Acting as a multicast router, and BPF running at the same * time. Whew! (Hope this is a fast machine...) */ #if NBPFILTER > 0 *to_bpf = (ie->arpcom.ac_if.if_bpf != 0); #endif /* We want to see multicasts. */ if (eh->ether_dhost[0] & 1) return (1); /* We want to see our own packets */ if (ether_equal(eh->ether_dhost, ie->arpcom.ac_enaddr)) return (1); /* Anything else goes to BPF but nothing else. */ #if NBPFILTER > 0 if (*to_bpf) *to_bpf = 2; #endif return (1); default: /* * Only accept unicast packets destined for us, or * multicasts for groups that we belong to. For now, we * assume that the '586 will only return packets that we * asked it for. This isn't strictly true (it uses hashing * for the multicast filter), but it will do in this case, * and we want to get out of here as quickly as possible. */ #if NBPFILTER > 0 *to_bpf = (ie->arpcom.ac_if.if_bpf != 0); #endif return (1); } return (0); } /* * We want to isolate the bits that have meaning... This assumes that * IE_RBUF_SIZE is an even power of two. If somehow the act_len exceeds * the size of the buffer, then we are screwed anyway. */ static __inline int ie_buflen(struct ie_softc * ie, int head) { return (ie->rbuffs[head]->ie_rbd_actual & (IE_RBUF_SIZE | (IE_RBUF_SIZE - 1))); } static __inline int ie_packet_len(int unit, struct ie_softc * ie) { int i; int head = ie->rbhead; int acc = 0; do { if (!(ie->rbuffs[ie->rbhead]->ie_rbd_actual & IE_RBD_USED)) { #ifdef DEBUG print_rbd(ie->rbuffs[ie->rbhead]); #endif log(LOG_ERR, "ie%d: receive descriptors out of sync at %d\n", unit, ie->rbhead); iereset(unit); return (-1); } i = ie->rbuffs[head]->ie_rbd_actual & IE_RBD_LAST; acc += ie_buflen(ie, head); head = (head + 1) % ie->nrxbufs; } while (!i); return (acc); } /* * Read data off the interface, and turn it into an mbuf chain. * * This code is DRAMATICALLY different from the previous version; this * version tries to allocate the entire mbuf chain up front, given the * length of the data available. This enables us to allocate mbuf * clusters in many situations where before we would have had a long * chain of partially-full mbufs. This should help to speed up the * operation considerably. (Provided that it works, of course.) */ static __inline int ieget(int unit, struct ie_softc *ie, struct mbuf **mp, struct ether_header *ehp, int *to_bpf) { struct mbuf *m, *top, **mymp; int i; int offset; int totlen, resid; int thismboff; int head; totlen = ie_packet_len(unit, ie); if (totlen <= 0) return (-1); i = ie->rbhead; /* * Snarf the Ethernet header. */ bcopy((caddr_t) ie->cbuffs[i], (caddr_t) ehp, sizeof *ehp); /* ignore cast-qual warning here */ /* * As quickly as possible, check if this packet is for us. If not, * don't waste a single cycle copying the rest of the packet in. * This is only a consideration when FILTER is defined; i.e., when * we are either running BPF or doing multicasting. */ if (!check_eh(ie, ehp, to_bpf)) { ie_drop_packet_buffer(unit, ie); ie->arpcom.ac_if.if_ierrors--; /* just this case, it's not an * error */ return (-1); } totlen -= (offset = sizeof *ehp); MGETHDR(*mp, M_DONTWAIT, MT_DATA); if (!*mp) { ie_drop_packet_buffer(unit, ie); return (-1); } m = *mp; m->m_pkthdr.rcvif = &ie->arpcom.ac_if; m->m_len = MHLEN; resid = m->m_pkthdr.len = totlen; top = 0; mymp = ⊤ /* * This loop goes through and allocates mbufs for all the data we * will be copying in. It does not actually do the copying yet. */ do { /* while(resid > 0) */ /* * Try to allocate an mbuf to hold the data that we have. * If we already allocated one, just get another one and * stick it on the end (eventually). If we don't already * have one, try to allocate an mbuf cluster big enough to * hold the whole packet, if we think it's reasonable, or a * single mbuf which may or may not be big enough. Got that? */ if (top) { MGET(m, M_DONTWAIT, MT_DATA); if (!m) { m_freem(top); ie_drop_packet_buffer(unit, ie); return (-1); } m->m_len = MLEN; } if (resid >= MINCLSIZE) { MCLGET(m, M_DONTWAIT); if (m->m_flags & M_EXT) m->m_len = min(resid, MCLBYTES); } else { if (resid < m->m_len) { if (!top && resid + max_linkhdr <= m->m_len) m->m_data += max_linkhdr; m->m_len = resid; } } resid -= m->m_len; *mymp = m; mymp = &m->m_next; } while (resid > 0); resid = totlen; m = top; thismboff = 0; head = ie->rbhead; /* * Now we take the mbuf chain (hopefully only one mbuf most of the * time) and stuff the data into it. There are no possible failures * at or after this point. */ while (resid > 0) { /* while there's stuff left */ int thislen = ie_buflen(ie, head) - offset; /* * If too much data for the current mbuf, then fill the * current one up, go to the next one, and try again. */ if (thislen > m->m_len - thismboff) { int newlen = m->m_len - thismboff; bcopy((caddr_t) (ie->cbuffs[head] + offset), mtod(m, caddr_t) +thismboff, (unsigned) newlen); /* ignore cast-qual warning */ m = m->m_next; thismboff = 0; /* new mbuf, so no offset */ offset += newlen; /* we are now this far into * the packet */ resid -= newlen; /* so there is this much left * to get */ continue; } /* * If there is more than enough space in the mbuf to hold * the contents of this buffer, copy everything in, advance * pointers, and so on. */ if (thislen < m->m_len - thismboff) { bcopy((caddr_t) (ie->cbuffs[head] + offset), mtod(m, caddr_t) +thismboff, (unsigned) thislen); thismboff += thislen; /* we are this far into the * mbuf */ resid -= thislen; /* and this much is left */ goto nextbuf; } /* * Otherwise, there is exactly enough space to put this * buffer's contents into the current mbuf. Do the * combination of the above actions. */ bcopy((caddr_t) (ie->cbuffs[head] + offset), mtod(m, caddr_t) + thismboff, (unsigned) thislen); m = m->m_next; thismboff = 0; /* new mbuf, start at the beginning */ resid -= thislen; /* and we are this far through */ /* * Advance all the pointers. We can get here from either of * the last two cases, but never the first. */ nextbuf: offset = 0; ie->rbuffs[head]->ie_rbd_actual = 0; ie->rbuffs[head]->ie_rbd_length |= IE_RBD_LAST; ie->rbhead = head = (head + 1) % ie->nrxbufs; ie->rbuffs[ie->rbtail]->ie_rbd_length &= ~IE_RBD_LAST; ie->rbtail = (ie->rbtail + 1) % ie->nrxbufs; } /* * Unless something changed strangely while we were doing the copy, * we have now copied everything in from the shared memory. This * means that we are done. */ return (0); } /* * Read frame NUM from unit UNIT (pre-cached as IE). * * This routine reads the RFD at NUM, and copies in the buffers from * the list of RBD, then rotates the RBD and RFD lists so that the receiver * doesn't start complaining. Trailers are DROPPED---there's no point * in wasting time on confusing code to deal with them. Hopefully, * this machine will never ARP for trailers anyway. */ static void ie_readframe(int unit, struct ie_softc *ie, int num/* frame number to read */) { struct ie_recv_frame_desc rfd; struct mbuf *m = 0; struct ether_header eh; #if NBPFILTER > 0 int bpf_gets_it = 0; #endif bcopy((caddr_t) (ie->rframes[num]), &rfd, sizeof(struct ie_recv_frame_desc)); /* * Immediately advance the RFD list, since we we have copied ours * now. */ ie->rframes[num]->ie_fd_status = 0; ie->rframes[num]->ie_fd_last |= IE_FD_LAST; ie->rframes[ie->rftail]->ie_fd_last &= ~IE_FD_LAST; ie->rftail = (ie->rftail + 1) % ie->nframes; ie->rfhead = (ie->rfhead + 1) % ie->nframes; if (rfd.ie_fd_status & IE_FD_OK) { #if NBPFILTER > 0 if (ieget(unit, ie, &m, &eh, &bpf_gets_it)) { #else if (ieget(unit, ie, &m, &eh, (int *)0)) { #endif ie->arpcom.ac_if.if_ierrors++; /* this counts as an * error */ return; } } #ifdef DEBUG if (ie_debug & IED_READFRAME) { printf("ie%d: frame from ether %6D type %x\n", unit, eh.ether_shost, ":", (unsigned) eh.ether_type); } if (ntohs(eh.ether_type) > ETHERTYPE_TRAIL && ntohs(eh.ether_type) < (ETHERTYPE_TRAIL + ETHERTYPE_NTRAILER)) printf("received trailer!\n"); #endif if (!m) return; if (last_not_for_us) { m_freem(last_not_for_us); last_not_for_us = 0; } #if NBPFILTER > 0 /* * Check for a BPF filter; if so, hand it up. Note that we have to * stick an extra mbuf up front, because bpf_mtap expects to have * the ether header at the front. It doesn't matter that this * results in an ill-formatted mbuf chain, since BPF just looks at * the data. (It doesn't try to free the mbuf, tho' it will make a * copy for tcpdump.) */ if (bpf_gets_it) { struct mbuf m0; m0.m_len = sizeof eh; m0.m_data = (caddr_t)&eh; m0.m_next = m; /* Pass it up */ bpf_mtap(&ie->arpcom.ac_if, &m0); } /* * A signal passed up from the filtering code indicating that the * packet is intended for BPF but not for the protocol machinery. We * can save a few cycles by not handing it off to them. */ if (bpf_gets_it == 2) { last_not_for_us = m; return; } #endif /* NBPFILTER > 0 */ /* * In here there used to be code to check destination addresses upon * receipt of a packet. We have deleted that code, and replaced it * with code to check the address much earlier in the cycle, before * copying the data in; this saves us valuable cycles when operating * as a multicast router or when using BPF. */ /* * Finally pass this packet up to higher layers. */ ether_input(&ie->arpcom.ac_if, &eh, m); } static void ie_drop_packet_buffer(int unit, struct ie_softc * ie) { int i; do { /* * This means we are somehow out of sync. So, we reset the * adapter. */ if (!(ie->rbuffs[ie->rbhead]->ie_rbd_actual & IE_RBD_USED)) { #ifdef DEBUG print_rbd(ie->rbuffs[ie->rbhead]); #endif log(LOG_ERR, "ie%d: receive descriptors out of sync at %d\n", unit, ie->rbhead); iereset(unit); return; } i = ie->rbuffs[ie->rbhead]->ie_rbd_actual & IE_RBD_LAST; ie->rbuffs[ie->rbhead]->ie_rbd_length |= IE_RBD_LAST; ie->rbuffs[ie->rbhead]->ie_rbd_actual = 0; ie->rbhead = (ie->rbhead + 1) % ie->nrxbufs; ie->rbuffs[ie->rbtail]->ie_rbd_length &= ~IE_RBD_LAST; ie->rbtail = (ie->rbtail + 1) % ie->nrxbufs; } while (!i); } /* * Start transmission on an interface. */ static void iestart(struct ifnet *ifp) { struct ie_softc *ie = ifp->if_softc; struct mbuf *m0, *m; unsigned char *buffer; u_short len; /* * This is not really volatile, in this routine, but it makes gcc * happy. */ volatile u_short *bptr = &ie->scb->ie_command_list; if (!(ifp->if_flags & IFF_RUNNING)) return; if (ifp->if_flags & IFF_OACTIVE) return; do { IF_DEQUEUE(&ie->arpcom.ac_if.if_snd, m); if (!m) break; buffer = ie->xmit_cbuffs[ie->xmit_count]; len = 0; for (m0 = m; m && len < IE_BUF_LEN; m = m->m_next) { bcopy(mtod(m, caddr_t), buffer, m->m_len); buffer += m->m_len; len += m->m_len; } m_freem(m0); len = max(len, ETHER_MIN_LEN); #if NBPFILTER > 0 /* * See if bpf is listening on this interface, let it see the * packet before we commit it to the wire. */ if (ie->arpcom.ac_if.if_bpf) bpf_tap(&ie->arpcom.ac_if, ie->xmit_cbuffs[ie->xmit_count], len); #endif ie->xmit_buffs[ie->xmit_count]->ie_xmit_flags = IE_XMIT_LAST|len; ie->xmit_buffs[ie->xmit_count]->ie_xmit_next = 0xffff; ie->xmit_buffs[ie->xmit_count]->ie_xmit_buf = MK_24(ie->iomem, ie->xmit_cbuffs[ie->xmit_count]); ie->xmit_cmds[ie->xmit_count]->com.ie_cmd_cmd = IE_CMD_XMIT; ie->xmit_cmds[ie->xmit_count]->ie_xmit_status = 0; ie->xmit_cmds[ie->xmit_count]->ie_xmit_desc = MK_16(ie->iomem, ie->xmit_buffs[ie->xmit_count]); *bptr = MK_16(ie->iomem, ie->xmit_cmds[ie->xmit_count]); bptr = &ie->xmit_cmds[ie->xmit_count]->com.ie_cmd_link; ie->xmit_count++; } while (ie->xmit_count < ie->ntxbufs); /* * If we queued up anything for transmission, send it. */ if (ie->xmit_count) { ie->xmit_cmds[ie->xmit_count - 1]->com.ie_cmd_cmd |= IE_CMD_LAST | IE_CMD_INTR; /* * By passing the command pointer as a null, we tell * command_and_wait() to pretend that this isn't an action * command. I wish I understood what was happening here. */ command_and_wait(ifp->if_unit, IE_CU_START, 0, 0); ifp->if_flags |= IFF_OACTIVE; } return; } /* * Check to see if there's an 82586 out there. */ static int check_ie_present(int unit, caddr_t where, unsigned size) { volatile struct ie_sys_conf_ptr *scp; volatile struct ie_int_sys_conf_ptr *iscp; volatile struct ie_sys_ctl_block *scb; u_long realbase; int s; s = splimp(); - realbase = (u_long) where + size - (1 << 24); + realbase = (uintptr_t) where + size - (1 << 24); - scp = (volatile struct ie_sys_conf_ptr *) (realbase + IE_SCP_ADDR); + scp = (volatile struct ie_sys_conf_ptr *) (uintptr_t) + (realbase + IE_SCP_ADDR); bzero((char *) scp, sizeof *scp); /* * First we put the ISCP at the bottom of memory; this tests to make * sure that our idea of the size of memory is the same as the * controller's. This is NOT where the ISCP will be in normal * operation. */ iscp = (volatile struct ie_int_sys_conf_ptr *) where; bzero((char *)iscp, sizeof *iscp); scb = (volatile struct ie_sys_ctl_block *) where; bzero((char *)scb, sizeof *scb); scp->ie_bus_use = ie_softc[unit].bus_use; /* 8-bit or 16-bit */ scp->ie_iscp_ptr = (caddr_t) ((volatile caddr_t) iscp - - (volatile caddr_t) realbase); + (volatile caddr_t) (volatile uintptr_t) + realbase); iscp->ie_busy = 1; iscp->ie_scb_offset = MK_16(realbase, scb) + 256; (*ie_softc[unit].ie_reset_586) (unit); (*ie_softc[unit].ie_chan_attn) (unit); DELAY(100); /* wait a while... */ if (iscp->ie_busy) { splx(s); return (0); } /* * Now relocate the ISCP to its real home, and reset the controller * again. */ - iscp = (void *) Align((caddr_t) (realbase + IE_SCP_ADDR - - sizeof(struct ie_int_sys_conf_ptr))); + iscp = (void *) Align((caddr_t) (uintptr_t) + (realbase + IE_SCP_ADDR - + sizeof(struct ie_int_sys_conf_ptr))); bzero((char *) iscp, sizeof *iscp); /* ignore cast-qual */ - scp->ie_iscp_ptr = (caddr_t) ((caddr_t) iscp - (caddr_t) realbase); + scp->ie_iscp_ptr = (caddr_t) ((caddr_t) iscp - + (caddr_t) (uintptr_t) realbase); /* ignore cast-qual */ iscp->ie_busy = 1; iscp->ie_scb_offset = MK_16(realbase, scb); (*ie_softc[unit].ie_reset_586) (unit); (*ie_softc[unit].ie_chan_attn) (unit); DELAY(100); if (iscp->ie_busy) { splx(s); return (0); } ie_softc[unit].iosize = size; - ie_softc[unit].iomem = (caddr_t) realbase; + ie_softc[unit].iomem = (caddr_t) (uintptr_t) realbase; ie_softc[unit].iscp = iscp; ie_softc[unit].scb = scb; /* * Acknowledge any interrupts we may have caused... */ ie_ack(scb, IE_ST_WHENCE, unit, ie_softc[unit].ie_chan_attn); splx(s); return (1); } /* * Divine the memory size of ie board UNIT. * Better hope there's nothing important hiding just below the ie card... */ static void find_ie_mem_size(int unit) { unsigned size; ie_softc[unit].iosize = 0; for (size = 65536; size >= 8192; size -= 8192) { if (check_ie_present(unit, ie_softc[unit].iomembot, size)) { return; } } return; } void el_reset_586(int unit) { outb(PORT + IE507_CTRL, EL_CTRL_RESET); DELAY(100); outb(PORT + IE507_CTRL, EL_CTRL_NORMAL); DELAY(100); } void sl_reset_586(int unit) { outb(PORT + IEATT_RESET, 0); } void ee16_reset_586(int unit) { outb(PORT + IEE16_ECTRL, IEE16_RESET_586); DELAY(100); outb(PORT + IEE16_ECTRL, 0); DELAY(100); } void el_chan_attn(int unit) { outb(PORT + IE507_ATTN, 1); } void sl_chan_attn(int unit) { outb(PORT + IEATT_ATTN, 0); } void ee16_chan_attn(int unit) { outb(PORT + IEE16_ATTN, 0); } u_short ee16_read_eeprom(struct ie_softc *sc, int location) { int ectrl, edata; ectrl = inb(sc->port + IEE16_ECTRL); ectrl &= IEE16_ECTRL_MASK; ectrl |= IEE16_ECTRL_EECS; outb(sc->port + IEE16_ECTRL, ectrl); ee16_eeprom_outbits(sc, IEE16_EEPROM_READ, IEE16_EEPROM_OPSIZE1); ee16_eeprom_outbits(sc, location, IEE16_EEPROM_ADDR_SIZE); edata = ee16_eeprom_inbits(sc); ectrl = inb(sc->port + IEE16_ECTRL); ectrl &= ~(IEE16_RESET_ASIC | IEE16_ECTRL_EEDI | IEE16_ECTRL_EECS); outb(sc->port + IEE16_ECTRL, ectrl); ee16_eeprom_clock(sc, 1); ee16_eeprom_clock(sc, 0); return edata; } void ee16_eeprom_outbits(struct ie_softc *sc, int edata, int count) { int ectrl, i; ectrl = inb(sc->port + IEE16_ECTRL); ectrl &= ~IEE16_RESET_ASIC; for (i = count - 1; i >= 0; i--) { ectrl &= ~IEE16_ECTRL_EEDI; if (edata & (1 << i)) { ectrl |= IEE16_ECTRL_EEDI; } outb(sc->port + IEE16_ECTRL, ectrl); DELAY(1); /* eeprom data must be setup for 0.4 uSec */ ee16_eeprom_clock(sc, 1); ee16_eeprom_clock(sc, 0); } ectrl &= ~IEE16_ECTRL_EEDI; outb(sc->port + IEE16_ECTRL, ectrl); DELAY(1); /* eeprom data must be held for 0.4 uSec */ } int ee16_eeprom_inbits(struct ie_softc *sc) { int ectrl, edata, i; ectrl = inb(sc->port + IEE16_ECTRL); ectrl &= ~IEE16_RESET_ASIC; for (edata = 0, i = 0; i < 16; i++) { edata = edata << 1; ee16_eeprom_clock(sc, 1); ectrl = inb(sc->port + IEE16_ECTRL); if (ectrl & IEE16_ECTRL_EEDO) { edata |= 1; } ee16_eeprom_clock(sc, 0); } return (edata); } void ee16_eeprom_clock(struct ie_softc *sc, int state) { int ectrl; ectrl = inb(sc->port + IEE16_ECTRL); ectrl &= ~(IEE16_RESET_ASIC | IEE16_ECTRL_EESK); if (state) { ectrl |= IEE16_ECTRL_EESK; } outb(sc->port + IEE16_ECTRL, ectrl); DELAY(9); /* EESK must be stable for 8.38 uSec */ } static __inline void ee16_interrupt_enable(struct ie_softc *sc) { DELAY(100); outb(sc->port + IEE16_IRQ, sc->irq_encoded | IEE16_IRQ_ENABLE); DELAY(100); } void sl_read_ether(int unit, unsigned char addr[6]) { int i; for (i = 0; i < 6; i++) addr[i] = inb(PORT + i); } static void iereset(int unit) { int s = splimp(); if (unit >= NIE) { splx(s); return; } printf("ie%d: reset\n", unit); ie_softc[unit].arpcom.ac_if.if_flags &= ~IFF_UP; ieioctl(&ie_softc[unit].arpcom.ac_if, SIOCSIFFLAGS, 0); /* * Stop i82586 dead in its tracks. */ if (command_and_wait(unit, IE_RU_ABORT | IE_CU_ABORT, 0, 0)) printf("ie%d: abort commands timed out\n", unit); if (command_and_wait(unit, IE_RU_DISABLE | IE_CU_STOP, 0, 0)) printf("ie%d: disable commands timed out\n", unit); #ifdef notdef if (!check_ie_present(unit, ie_softc[unit].iomembot, e_softc[unit].iosize)) panic("ie disappeared!"); #endif ie_softc[unit].arpcom.ac_if.if_flags |= IFF_UP; ieioctl(&ie_softc[unit].arpcom.ac_if, SIOCSIFFLAGS, 0); splx(s); return; } /* * This is called if we time out. */ static void chan_attn_timeout(void *rock) { *(int *) rock = 1; } /* * Send a command to the controller and wait for it to either * complete or be accepted, depending on the command. If the * command pointer is null, then pretend that the command is * not an action command. If the command pointer is not null, * and the command is an action command, wait for * ((volatile struct ie_cmd_common *)pcmd)->ie_cmd_status & MASK * to become true. */ static int command_and_wait(int unit, int cmd, volatile void *pcmd, int mask) { volatile struct ie_cmd_common *cc = pcmd; volatile int timedout = 0; struct callout_handle ch; ie_softc[unit].scb->ie_command = (u_short) cmd; if (IE_ACTION_COMMAND(cmd) && pcmd) { (*ie_softc[unit].ie_chan_attn) (unit); /* * According to the packet driver, the minimum timeout * should be .369 seconds, which we round up to .37. */ ch = timeout(chan_attn_timeout, (caddr_t)&timedout, 37 * hz / 100); /* ignore cast-qual */ /* * Now spin-lock waiting for status. This is not a very * nice thing to do, but I haven't figured out how, or * indeed if, we can put the process waiting for action to * sleep. (We may be getting called through some other * timeout running in the kernel.) */ while (1) { if ((cc->ie_cmd_status & mask) || timedout) break; } untimeout(chan_attn_timeout, (caddr_t)&timedout, ch); /* ignore cast-qual */ return (timedout); } else { /* * Otherwise, just wait for the command to be accepted. */ (*ie_softc[unit].ie_chan_attn) (unit); while (ie_softc[unit].scb->ie_command); /* spin lock */ return (0); } } /* * Run the time-domain reflectometer... */ static void run_tdr(int unit, struct ie_tdr_cmd *cmd) { int result; cmd->com.ie_cmd_status = 0; cmd->com.ie_cmd_cmd = IE_CMD_TDR | IE_CMD_LAST; cmd->com.ie_cmd_link = 0xffff; cmd->ie_tdr_time = 0; ie_softc[unit].scb->ie_command_list = MK_16(MEM, cmd); cmd->ie_tdr_time = 0; if (command_and_wait(unit, IE_CU_START, cmd, IE_STAT_COMPL)) result = 0x2000; else result = cmd->ie_tdr_time; ie_ack(ie_softc[unit].scb, IE_ST_WHENCE, unit, ie_softc[unit].ie_chan_attn); if (result & IE_TDR_SUCCESS) return; if (result & IE_TDR_XCVR) { printf("ie%d: transceiver problem\n", unit); } else if (result & IE_TDR_OPEN) { printf("ie%d: TDR detected an open %d clocks away\n", unit, result & IE_TDR_TIME); } else if (result & IE_TDR_SHORT) { printf("ie%d: TDR detected a short %d clocks away\n", unit, result & IE_TDR_TIME); } else { printf("ie%d: TDR returned unknown status %x\n", unit, result); } } static void start_receiver(int unit) { int s = splimp(); ie_softc[unit].scb->ie_recv_list = MK_16(MEM, ie_softc[unit].rframes[0]); command_and_wait(unit, IE_RU_START, 0, 0); ie_ack(ie_softc[unit].scb, IE_ST_WHENCE, unit, ie_softc[unit].ie_chan_attn); splx(s); } /* * Here is a helper routine for iernr() and ieinit(). This sets up * the RFA. */ static caddr_t setup_rfa(caddr_t ptr, struct ie_softc * ie) { volatile struct ie_recv_frame_desc *rfd = (void *) ptr; volatile struct ie_recv_buf_desc *rbd; int i; int unit = ie - &ie_softc[0]; /* First lay them out */ for (i = 0; i < ie->nframes; i++) { ie->rframes[i] = rfd; bzero((char *) rfd, sizeof *rfd); /* ignore cast-qual */ rfd++; } ptr = (caddr_t) Align((caddr_t) rfd); /* ignore cast-qual */ /* Now link them together */ for (i = 0; i < ie->nframes; i++) { ie->rframes[i]->ie_fd_next = MK_16(MEM, ie->rframes[(i + 1) % ie->nframes]); } /* Finally, set the EOL bit on the last one. */ ie->rframes[ie->nframes - 1]->ie_fd_last |= IE_FD_LAST; /* * Now lay out some buffers for the incoming frames. Note that we * set aside a bit of slop in each buffer, to make sure that we have * enough space to hold a single frame in every buffer. */ rbd = (void *) ptr; for (i = 0; i < ie->nrxbufs; i++) { ie->rbuffs[i] = rbd; bzero((char *)rbd, sizeof *rbd); ptr = (caddr_t) Align(ptr + sizeof *rbd); rbd->ie_rbd_length = IE_RBUF_SIZE; rbd->ie_rbd_buffer = MK_24(MEM, ptr); ie->cbuffs[i] = (void *) ptr; ptr += IE_RBUF_SIZE; rbd = (void *) ptr; } /* Now link them together */ for (i = 0; i < ie->nrxbufs; i++) { ie->rbuffs[i]->ie_rbd_next = MK_16(MEM, ie->rbuffs[(i + 1) % ie->nrxbufs]); } /* Tag EOF on the last one */ ie->rbuffs[ie->nrxbufs - 1]->ie_rbd_length |= IE_RBD_LAST; /* * We use the head and tail pointers on receive to keep track of the * order in which RFDs and RBDs are used. */ ie->rfhead = 0; ie->rftail = ie->nframes - 1; ie->rbhead = 0; ie->rbtail = ie->nrxbufs - 1; ie->scb->ie_recv_list = MK_16(MEM, ie->rframes[0]); ie->rframes[0]->ie_fd_buf_desc = MK_16(MEM, ie->rbuffs[0]); ptr = Align(ptr); return (ptr); } /* * Run the multicast setup command. * Call at splimp(). */ static int mc_setup(int unit, caddr_t ptr, volatile struct ie_sys_ctl_block * scb) { struct ie_softc *ie = &ie_softc[unit]; volatile struct ie_mcast_cmd *cmd = (void *) ptr; cmd->com.ie_cmd_status = 0; cmd->com.ie_cmd_cmd = IE_CMD_MCAST | IE_CMD_LAST; cmd->com.ie_cmd_link = 0xffff; /* ignore cast-qual */ bcopy((caddr_t) ie->mcast_addrs, (caddr_t) cmd->ie_mcast_addrs, ie->mcast_count * sizeof *ie->mcast_addrs); cmd->ie_mcast_bytes = ie->mcast_count * 6; /* grrr... */ scb->ie_command_list = MK_16(MEM, cmd); if (command_and_wait(unit, IE_CU_START, cmd, IE_STAT_COMPL) || !(cmd->com.ie_cmd_status & IE_STAT_OK)) { printf("ie%d: multicast address setup command failed\n", unit); return (0); } return (1); } /* * This routine takes the environment generated by check_ie_present() * and adds to it all the other structures we need to operate the adapter. * This includes executing the CONFIGURE, IA-SETUP, and MC-SETUP commands, * starting the receiver unit, and clearing interrupts. * * THIS ROUTINE MUST BE CALLED AT splimp() OR HIGHER. */ static void ieinit(int unit) { struct ie_softc *ie = &ie_softc[unit]; volatile struct ie_sys_ctl_block *scb = ie->scb; caddr_t ptr; int i; ptr = (caddr_t) Align((caddr_t) scb + sizeof *scb); /* * Send the configure command first. */ { volatile struct ie_config_cmd *cmd = (void *) ptr; ie_setup_config(cmd, ie->promisc, ie->hard_type == IE_STARLAN10); cmd->com.ie_cmd_status = 0; cmd->com.ie_cmd_cmd = IE_CMD_CONFIG | IE_CMD_LAST; cmd->com.ie_cmd_link = 0xffff; scb->ie_command_list = MK_16(MEM, cmd); if (command_and_wait(unit, IE_CU_START, cmd, IE_STAT_COMPL) || !(cmd->com.ie_cmd_status & IE_STAT_OK)) { printf("ie%d: configure command failed\n", unit); return; } } /* * Now send the Individual Address Setup command. */ { volatile struct ie_iasetup_cmd *cmd = (void *) ptr; cmd->com.ie_cmd_status = 0; cmd->com.ie_cmd_cmd = IE_CMD_IASETUP | IE_CMD_LAST; cmd->com.ie_cmd_link = 0xffff; bcopy((char *)ie_softc[unit].arpcom.ac_enaddr, (char *)&cmd->ie_address, sizeof cmd->ie_address); scb->ie_command_list = MK_16(MEM, cmd); if (command_and_wait(unit, IE_CU_START, cmd, IE_STAT_COMPL) || !(cmd->com.ie_cmd_status & IE_STAT_OK)) { printf("ie%d: individual address " "setup command failed\n", unit); return; } } /* * Now run the time-domain reflectometer. */ run_tdr(unit, (void *) ptr); /* * Acknowledge any interrupts we have generated thus far. */ ie_ack(ie->scb, IE_ST_WHENCE, unit, ie->ie_chan_attn); /* * Set up the RFA. */ ptr = setup_rfa(ptr, ie); /* * Finally, the transmit command and buffer are the last little bit * of work. */ /* transmit command buffers */ for (i = 0; i < ie->ntxbufs; i++) { ie->xmit_cmds[i] = (void *) ptr; ptr += sizeof *ie->xmit_cmds[i]; ptr = Align(ptr); ie->xmit_buffs[i] = (void *)ptr; ptr += sizeof *ie->xmit_buffs[i]; ptr = Align(ptr); } /* transmit buffers */ for (i = 0; i < ie->ntxbufs - 1; i++) { ie->xmit_cbuffs[i] = (void *)ptr; ptr += IE_BUF_LEN; ptr = Align(ptr); } ie->xmit_cbuffs[ie->ntxbufs - 1] = (void *) ptr; for (i = 1; i < ie->ntxbufs; i++) { bzero((caddr_t) ie->xmit_cmds[i], sizeof *ie->xmit_cmds[i]); bzero((caddr_t) ie->xmit_buffs[i], sizeof *ie->xmit_buffs[i]); } /* * This must be coordinated with iestart() and ietint(). */ ie->xmit_cmds[0]->ie_xmit_status = IE_STAT_COMPL; /* take the ee16 out of loopback */ if (ie->hard_type == IE_EE16) { u_int8_t bart_config; bart_config = inb(PORT + IEE16_CONFIG); bart_config &= ~IEE16_BART_LOOPBACK; /* inb doesn't get bit! */ bart_config |= IEE16_BART_MCS16_TEST; outb(PORT + IEE16_CONFIG, bart_config); ee16_interrupt_enable(ie); ee16_chan_attn(unit); } ie->arpcom.ac_if.if_flags |= IFF_RUNNING; /* tell higher levels * we're here */ start_receiver(unit); return; } static void ie_stop(int unit) { command_and_wait(unit, IE_RU_DISABLE, 0, 0); } static int ieioctl(struct ifnet *ifp, u_long command, caddr_t data) { struct ifaddr *ifa = (struct ifaddr *) data; struct ie_softc *ie = ifp->if_softc; struct ifreq *ifr = (struct ifreq *) data; int s, error = 0; s = splimp(); switch (command) { case SIOCSIFADDR: ifp->if_flags |= IFF_UP; switch (ifa->ifa_addr->sa_family) { #ifdef INET case AF_INET: ieinit(ifp->if_unit); arp_ifinit((struct arpcom *) ifp, ifa); break; #endif /* INET */ #ifdef IPX /* * This magic copied from if_is.c; I don't use XNS, * so I have no way of telling if this actually * works or not. */ case AF_IPX: { struct ipx_addr *ina = &(IA_SIPX(ifa)->sipx_addr); if (ipx_nullhost(*ina)) { ina->x_host = *(union ipx_host *) (ie->arpcom.ac_enaddr); } else { ifp->if_flags &= ~IFF_RUNNING; bcopy((caddr_t) ina->x_host.c_host, (caddr_t) ie->arpcom.ac_enaddr, sizeof ie->arpcom.ac_enaddr); } ieinit(ifp->if_unit); } break; #endif /* IPX */ #ifdef NS /* * This magic copied from if_is.c; I don't use XNS, * so I have no way of telling if this actually * works or not. */ case AF_NS: { struct ns_addr *ina = &(IA_SNS(ifa)->sns_addr); if (ns_nullhost(*ina)) { ina->x_host = *(union ns_host *)(ie->arpcom.ac_enaddr); } else { ifp->if_flags &= ~IFF_RUNNING; bcopy((caddr_t) ina->x_host.c_host, (caddr_t) ie->arpcom.ac_enaddr, sizeof ie->arpcom.ac_enaddr); } ieinit(ifp->if_unit); } break; #endif /* NS */ default: ieinit(ifp->if_unit); break; } break; case SIOCSIFFLAGS: /* * Note that this device doesn't have an "all multicast" * mode, so we must turn on promiscuous mode and do the * filtering manually. */ if ((ifp->if_flags & IFF_UP) == 0 && (ifp->if_flags & IFF_RUNNING)) { ifp->if_flags &= ~IFF_RUNNING; ie_stop(ifp->if_unit); } else if ((ifp->if_flags & IFF_UP) && (ifp->if_flags & IFF_RUNNING) == 0) { ie_softc[ifp->if_unit].promisc = ifp->if_flags & (IFF_PROMISC | IFF_ALLMULTI); ieinit(ifp->if_unit); } else if (ie_softc[ifp->if_unit].promisc ^ (ifp->if_flags & (IFF_PROMISC | IFF_ALLMULTI))) { ie_softc[ifp->if_unit].promisc = ifp->if_flags & (IFF_PROMISC | IFF_ALLMULTI); ieinit(ifp->if_unit); } break; case SIOCADDMULTI: case SIOCDELMULTI: /* * Update multicast listeners */ /* reset multicast filtering */ ie_mc_reset(ifp->if_unit); error = 0; break; case SIOCSIFMTU: /* * Set the interface MTU. */ if (ifr->ifr_mtu > ETHERMTU) { error = EINVAL; } else { ifp->if_mtu = ifr->ifr_mtu; } break; default: error = EINVAL; } splx(s); return (error); } static void ie_mc_reset(int unit) { struct ie_softc *ie = &ie_softc[unit]; struct ifmultiaddr *ifma; /* * Step through the list of addresses. */ ie->mcast_count = 0; for (ifma = ie->arpcom.ac_if.if_multiaddrs.lh_first; ifma; ifma = ifma->ifma_link.le_next) { if (ifma->ifma_addr->sa_family != AF_LINK) continue; /* XXX - this is broken... */ if (ie->mcast_count >= MAXMCAST) { ie->arpcom.ac_if.if_flags |= IFF_ALLMULTI; ieioctl(&ie->arpcom.ac_if, SIOCSIFFLAGS, (void *) 0); goto setflag; } bcopy(LLADDR((struct sockaddr_dl *) ifma->ifma_addr), &(ie->mcast_addrs[ie->mcast_count]), 6); ie->mcast_count++; } setflag: ie->want_mcsetup = 1; } #ifdef DEBUG static void print_rbd(volatile struct ie_recv_buf_desc * rbd) { printf("RBD at %p:\n" "actual %04x, next %04x, buffer %p\n" "length %04x, mbz %04x\n", (void *) rbd, rbd->ie_rbd_actual, rbd->ie_rbd_next, (void *) rbd->ie_rbd_buffer, rbd->ie_rbd_length, rbd->mbz); } #endif /* DEBUG */ #endif /* NIE > 0 */ Index: head/sys/pci/isp_pci.c =================================================================== --- head/sys/pci/isp_pci.c (revision 38231) +++ head/sys/pci/isp_pci.c (revision 38232) @@ -1,559 +1,559 @@ /* $FreeBSD$ */ -/* $Id: isp_pci.c,v 1.1 1998/04/22 18:10:34 mjacob Exp $ */ +/* $Id: isp_pci.c,v 1.2 1998/07/13 09:53:09 bde Exp $ */ /* * PCI specific probe and attach routines for Qlogic ISP SCSI adapters. * FreeBSD Version. * *--------------------------------------- * Copyright (c) 1997, 1998 by Matthew Jacob * NASA/Ames Research Center * All rights reserved. *--------------------------------------- * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice immediately at the beginning of the file, without modification, * this list of conditions, and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include #if NPCI > 0 #include #include #include #include static u_int16_t isp_pci_rd_reg __P((struct ispsoftc *, int)); static void isp_pci_wr_reg __P((struct ispsoftc *, int, u_int16_t)); static int isp_pci_mbxdma __P((struct ispsoftc *)); static int isp_pci_dmasetup __P((struct ispsoftc *, ISP_SCSI_XFER_T *, ispreq_t *, u_int8_t *, u_int8_t)); static void isp_pci_reset1 __P((struct ispsoftc *)); static void isp_pci_dumpregs __P((struct ispsoftc *)); static struct ispmdvec mdvec = { isp_pci_rd_reg, isp_pci_wr_reg, isp_pci_mbxdma, isp_pci_dmasetup, NULL, NULL, isp_pci_reset1, isp_pci_dumpregs, ISP_RISC_CODE, ISP_CODE_LENGTH, ISP_CODE_ORG, ISP_CODE_VERSION, BIU_PCI_CONF1_FIFO_64 | BIU_BURST_ENABLE, 60 /* MAGIC- all known PCI card implementations are 60MHz */ }; static struct ispmdvec mdvec_2100 = { isp_pci_rd_reg, isp_pci_wr_reg, isp_pci_mbxdma, isp_pci_dmasetup, NULL, NULL, isp_pci_reset1, isp_pci_dumpregs, ISP2100_RISC_CODE, ISP2100_CODE_LENGTH, ISP2100_CODE_ORG, ISP2100_CODE_VERSION, BIU_PCI_CONF1_FIFO_64 | BIU_BURST_ENABLE, 60 /* MAGIC- all known PCI card implementations are 60MHz */ }; #ifndef PCIM_CMD_INVEN #define PCIM_CMD_INVEN 0x10 #endif #ifndef PCIM_CMD_BUSMASTEREN #define PCIM_CMD_BUSMASTEREN 0x0004 #endif #ifndef PCI_VENDOR_QLOGIC #define PCI_VENDOR_QLOGIC 0x1077 #endif #ifndef PCI_PRODUCT_QLOGIC_ISP1020 #define PCI_PRODUCT_QLOGIC_ISP1020 0x1020 #endif #define PCI_QLOGIC_ISP \ ((PCI_PRODUCT_QLOGIC_ISP1020 << 16) | PCI_VENDOR_QLOGIC) #ifndef PCI_PRODUCT_QLOGIC_ISP2100 #define PCI_PRODUCT_QLOGIC_ISP2100 0x2100 #endif #define PCI_QLOGIC_ISP2100 \ ((PCI_PRODUCT_QLOGIC_ISP2100 << 16) | PCI_VENDOR_QLOGIC) #define IO_MAP_REG 0x10 #define MEM_MAP_REG 0x14 static char *isp_pci_probe __P((pcici_t tag, pcidi_t type)); static void isp_pci_attach __P((pcici_t config_d, int unit)); #define I386_BUS_SPACE_IO 0 #define I386_BUS_SPACE_MEM 1 typedef int bus_space_tag_t; typedef u_long bus_space_handle_t; #define bus_space_read_2(st, sh, offset) \ (st == I386_BUS_SPACE_IO)? \ - inw((u_int16_t)sh + offset) : *((u_int16_t *) sh) + inw((u_int16_t)sh + offset) : *((u_int16_t *)(uintptr_t)sh) #define bus_space_write_2(st, sh, offset, val) \ if (st == I386_BUS_SPACE_IO) outw((u_int16_t)sh + offset, val); else \ - *((u_int16_t *) sh) = val + *((u_int16_t *)(uintptr_t)sh) = val struct isp_pcisoftc { struct ispsoftc pci_isp; pcici_t pci_id; bus_space_tag_t pci_st; bus_space_handle_t pci_sh; union { sdparam _x; struct { fcparam _a; char _b[ISP2100_SCRLEN]; } _y; } _z; }; static u_long isp_unit; struct pci_device isp_pci_driver = { "isp", isp_pci_probe, isp_pci_attach, &isp_unit, NULL }; DATA_SET (pcidevice_set, isp_pci_driver); static char * isp_pci_probe(tag, type) pcici_t tag; pcidi_t type; { static int oneshot = 1; char *x; switch (type) { case PCI_QLOGIC_ISP: x = "Qlogic ISP 10X0 PCI SCSI Adapter"; break; case PCI_QLOGIC_ISP2100: x = "Qlogic ISP 2100 PCI FC-AL Adapter"; break; default: return (NULL); } if (oneshot) { oneshot = 0; printf("***Qlogic ISP Driver, FreeBSD NonCam Version\n***%s\n", ISP_VERSION_STRING); } return (x); } static void isp_pci_attach(config_id, unit) pcici_t config_id; int unit; { int mapped; u_int16_t io_port; u_int32_t data; struct isp_pcisoftc *pcs; struct ispsoftc *isp; vm_offset_t vaddr, paddr; ISP_LOCKVAL_DECL; pcs = malloc(sizeof (struct isp_pcisoftc), M_DEVBUF, M_NOWAIT); if (pcs == NULL) { printf("isp%d: cannot allocate softc\n", unit); return; } bzero(pcs, sizeof (struct isp_pcisoftc)); vaddr = paddr = NULL; mapped = 0; data = pci_conf_read(config_id, PCI_COMMAND_STATUS_REG); if (mapped == 0 && (data & PCI_COMMAND_IO_ENABLE)) { if (pci_map_port(config_id, PCI_MAP_REG_START, &io_port)) { pcs->pci_st = I386_BUS_SPACE_IO; pcs->pci_sh = io_port; mapped++; } } if (mapped == 0 && (data & PCI_COMMAND_MEM_ENABLE)) { if (pci_map_mem(config_id, PCI_MAP_REG_START, &vaddr, &paddr)) { pcs->pci_st = I386_BUS_SPACE_MEM; pcs->pci_sh = vaddr; mapped++; } } if (mapped == 0) { printf("isp%d: unable to map any ports!\n", unit); free(pcs, M_DEVBUF); return; } printf("isp%d: using %s space register mapping\n", unit, pcs->pci_st == I386_BUS_SPACE_IO? "I/O" : "Memory"); isp = &pcs->pci_isp; (void) sprintf(isp->isp_name, "isp%d", unit); isp->isp_osinfo.unit = unit; data = pci_conf_read(config_id, PCI_ID_REG); if (data == PCI_QLOGIC_ISP) { isp->isp_mdvec = &mdvec; isp->isp_type = ISP_HA_SCSI_UNKNOWN; isp->isp_param = &pcs->_z._x; } else if (data == PCI_QLOGIC_ISP2100) { isp->isp_mdvec = &mdvec_2100; isp->isp_type = ISP_HA_FC_2100; isp->isp_param = &pcs->_z._y._a; ISP_LOCK; data = pci_conf_read(config_id, PCI_COMMAND_STATUS_REG); data |= PCIM_CMD_BUSMASTEREN | PCIM_CMD_INVEN; pci_conf_write(config_id, PCI_COMMAND_STATUS_REG, data); /* * Wierd- we need to clear the lsb in offset 0x30 to take the * chip out of reset state. */ data = pci_conf_read(config_id, 0x30); data &= ~1; pci_conf_write(config_id, 0x30, data); ISP_UNLOCK; } else { free(pcs, M_DEVBUF); return; } if (pci_map_int(config_id, (void (*)(void *))isp_intr, (void *)isp, &IMASK) == 0) { printf("%s: could not map interrupt\n", isp->isp_name); free(pcs, M_DEVBUF); return; } pcs->pci_id = config_id; ISP_LOCK; isp_reset(isp); if (isp->isp_state != ISP_RESETSTATE) { ISP_UNLOCK; free(pcs, M_DEVBUF); return; } isp_init(isp); if (isp->isp_state != ISP_INITSTATE) { isp_uninit(isp); ISP_UNLOCK; free(pcs, M_DEVBUF); return; } isp_attach(isp); if (isp->isp_state != ISP_RUNSTATE) { isp_uninit(isp); ISP_UNLOCK; free(pcs, M_DEVBUF); return; } ISP_UNLOCK; } #define PCI_BIU_REGS_OFF BIU_REGS_OFF static u_int16_t isp_pci_rd_reg(isp, regoff) struct ispsoftc *isp; int regoff; { u_int16_t rv; struct isp_pcisoftc *pcs = (struct isp_pcisoftc *) isp; int offset, oldsxp = 0; if ((regoff & BIU_BLOCK) != 0) { offset = PCI_BIU_REGS_OFF; } else if ((regoff & MBOX_BLOCK) != 0) { if (isp->isp_type & ISP_HA_SCSI) offset = PCI_MBOX_REGS_OFF; else offset = PCI_MBOX_REGS2100_OFF; } else if ((regoff & SXP_BLOCK) != 0) { offset = PCI_SXP_REGS_OFF; /* * We will assume that someone has paused the RISC processor. */ oldsxp = isp_pci_rd_reg(isp, BIU_CONF1); isp_pci_wr_reg(isp, BIU_CONF1, oldsxp & ~BIU_PCI_CONF1_SXP); } else { offset = PCI_RISC_REGS_OFF; } regoff &= 0xff; offset += regoff; rv = bus_space_read_2(pcs->pci_st, pcs->pci_sh, offset); if ((regoff & SXP_BLOCK) != 0) { isp_pci_wr_reg(isp, BIU_CONF1, oldsxp); } return (rv); } static void isp_pci_wr_reg(isp, regoff, val) struct ispsoftc *isp; int regoff; u_int16_t val; { struct isp_pcisoftc *pcs = (struct isp_pcisoftc *) isp; int offset, oldsxp = 0; if ((regoff & BIU_BLOCK) != 0) { offset = PCI_BIU_REGS_OFF; } else if ((regoff & MBOX_BLOCK) != 0) { if (isp->isp_type & ISP_HA_SCSI) offset = PCI_MBOX_REGS_OFF; else offset = PCI_MBOX_REGS2100_OFF; } else if ((regoff & SXP_BLOCK) != 0) { offset = PCI_SXP_REGS_OFF; /* * We will assume that someone has paused the RISC processor. */ oldsxp = isp_pci_rd_reg(isp, BIU_CONF1); isp_pci_wr_reg(isp, BIU_CONF1, oldsxp & ~BIU_PCI_CONF1_SXP); } else { offset = PCI_RISC_REGS_OFF; } regoff &= 0xff; offset += regoff; bus_space_write_2(pcs->pci_st, pcs->pci_sh, offset, val); if ((regoff & SXP_BLOCK) != 0) { isp_pci_wr_reg(isp, BIU_CONF1, oldsxp); } } static int isp_pci_mbxdma(isp) struct ispsoftc *isp; { struct isp_pcisoftc *pci = (struct isp_pcisoftc *)isp; u_int32_t len; int rseg; /* XXXX CHECK FOR ALIGNMENT */ /* * Allocate and map the request queue. */ len = ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp)); isp->isp_rquest = malloc(len, M_DEVBUF, M_NOWAIT); if (isp->isp_rquest == NULL) { printf("%s: cannot malloc request queue\n", isp->isp_name); return (1); } isp->isp_rquest_dma = vtophys(isp->isp_rquest); #if 0 printf("RQUEST=0x%x (0x%x)...", isp->isp_rquest, isp->isp_rquest_dma); #endif /* * Allocate and map the result queue. */ len = ISP_QUEUE_SIZE(RESULT_QUEUE_LEN(isp)); isp->isp_result = malloc(len, M_DEVBUF, M_NOWAIT); if (isp->isp_result == NULL) { free(isp->isp_rquest, M_DEVBUF); printf("%s: cannot malloc result queue\n", isp->isp_name); return (1); } isp->isp_result_dma = vtophys(isp->isp_result); #if 0 printf("RESULT=0x%x (0x%x)\n", isp->isp_result, isp->isp_result_dma); #endif if (isp->isp_type & ISP_HA_FC) { fcparam *fcp = isp->isp_param; len = ISP2100_SCRLEN; fcp->isp_scratch = (volatile caddr_t) &pci->_z._y._b; fcp->isp_scdma = vtophys(fcp->isp_scratch); } return (0); } static int isp_pci_dmasetup(isp, xs, rq, iptrp, optr) struct ispsoftc *isp; ISP_SCSI_XFER_T *xs; ispreq_t *rq; u_int8_t *iptrp; u_int8_t optr; { struct isp_pcisoftc *pci = (struct isp_pcisoftc *)isp; ispcontreq_t *crq; vm_offset_t vaddr; int drq, seglim; u_int32_t paddr, nextpaddr, datalen, size, *ctrp; if (xs->datalen == 0) { rq->req_seg_count = 1; return (0); } if (xs->flags & SCSI_DATA_IN) { drq = REQFLAG_DATA_IN; } else { drq = REQFLAG_DATA_OUT; } if (isp->isp_type & ISP_HA_FC) { seglim = ISP_RQDSEG_T2; ((ispreqt2_t *)rq)->req_totalcnt = xs->datalen; ((ispreqt2_t *)rq)->req_flags |= drq; } else { seglim = ISP_RQDSEG; rq->req_flags |= drq; } datalen = xs->datalen;; vaddr = (vm_offset_t) xs->data; paddr = vtophys(vaddr); while (datalen != 0 && rq->req_seg_count < seglim) { if (isp->isp_type & ISP_HA_FC) { ispreqt2_t *rq2 = (ispreqt2_t *)rq; rq2->req_dataseg[rq2->req_seg_count].ds_base = paddr; ctrp = &rq2->req_dataseg[rq2->req_seg_count].ds_count; } else { rq->req_dataseg[rq->req_seg_count].ds_base = paddr; ctrp = &rq->req_dataseg[rq->req_seg_count].ds_count; } nextpaddr = paddr; *(ctrp) = 0; while (datalen != 0 && paddr == nextpaddr) { nextpaddr = (paddr & (~PAGE_MASK)) + PAGE_SIZE; size = nextpaddr - paddr; if (size > datalen) size = datalen; *(ctrp) += size; vaddr += size; datalen -= size; if (datalen != 0) paddr = vtophys(vaddr); } #if 0 if (isp->isp_type & ISP_HA_FC) { ispreqt2_t *rq2 = (ispreqt2_t *)rq; printf("%s: seg0[%d] cnt 0x%x paddr 0x%08x\n", isp->isp_name, rq->req_seg_count, rq2->req_dataseg[rq2->req_seg_count].ds_count, rq2->req_dataseg[rq2->req_seg_count].ds_base); } else { printf("%s: seg0[%d] cnt 0x%x paddr 0x%08x\n", isp->isp_name, rq->req_seg_count, rq->req_dataseg[rq->req_seg_count].ds_count, rq->req_dataseg[rq->req_seg_count].ds_base); } #endif rq->req_seg_count++; } if (datalen == 0) return (0); paddr = vtophys(vaddr); while (datalen > 0) { crq = (ispcontreq_t *) ISP_QUEUE_ENTRY(isp->isp_rquest, *iptrp); *iptrp = (*iptrp + 1) & (RQUEST_QUEUE_LEN(isp) - 1); if (*iptrp == optr) { printf("%s: Request Queue Overflow\n", isp->isp_name); return (EFBIG); } rq->req_header.rqs_entry_count++; bzero((void *)crq, sizeof (*crq)); crq->req_header.rqs_entry_count = 1; crq->req_header.rqs_entry_type = RQSTYPE_DATASEG; for (seglim = 0; datalen != 0 && seglim < ISP_CDSEG; seglim++) { crq->req_dataseg[seglim].ds_base = paddr; ctrp = &crq->req_dataseg[seglim].ds_count; *(ctrp) = 0; nextpaddr = paddr; while (datalen != 0 && paddr == nextpaddr) { nextpaddr = (paddr & (~PAGE_MASK)) + PAGE_SIZE; size = nextpaddr - paddr; if (size > datalen) size = datalen; *(ctrp) += size; vaddr += size; datalen -= size; if (datalen != 0) paddr = vtophys(vaddr); } #if 0 printf("%s: seg%d[%d] cnt 0x%x paddr 0x%08x\n", isp->isp_name, rq->req_header.rqs_entry_count-1, seglim, crq->req_dataseg[seglim].ds_count, crq->req_dataseg[seglim].ds_base); #endif rq->req_seg_count++; } } return (0); } static void isp_pci_reset1(isp) struct ispsoftc *isp; { /* Make sure the BIOS is disabled */ isp_pci_wr_reg(isp, HCCR, PCI_HCCR_CMD_BIOS); } static void isp_pci_dumpregs(isp) struct ispsoftc *isp; { struct isp_pcisoftc *pci = (struct isp_pcisoftc *)isp; printf("%s: PCI Status Command/Status=%lx\n", pci->pci_isp.isp_name, pci_conf_read(pci->pci_id, PCI_COMMAND_STATUS_REG)); } #endif Index: head/sys/pci/scsiiom.c =================================================================== --- head/sys/pci/scsiiom.c (revision 38231) +++ head/sys/pci/scsiiom.c (revision 38232) @@ -1,1511 +1,1511 @@ /*********************************************************************** * FILE NAME : SCSIIOM.C * * BY : C.L. Huang (ching@tekram.com.tw) * * Description: Device Driver for Tekram DC-390 (T) PCI SCSI * * Bus Master Host Adapter * ***********************************************************************/ static USHORT DC390_StartSCSI( PACB pACB, PDCB pDCB, PSRB pSRB ) { USHORT ioport, rc; UCHAR bval, bval1, i, cnt; PUCHAR ptr; ULONG wlval; pSRB->TagNumber = 31; ioport = pACB->IOPortBase; bval = pDCB->UnitSCSIID; OutB(bval,ioport+Scsi_Dest_ID); bval = pDCB->SyncPeriod; OutB(bval,ioport+Sync_Period); bval = pDCB->SyncOffset; OutB(bval,ioport+Sync_Offset); bval = pDCB->CtrlR1; OutB(bval,ioport+CtrlReg1); bval = pDCB->CtrlR3; OutB(bval,ioport+CtrlReg3); bval = pDCB->CtrlR4; OutB(bval,ioport+CtrlReg4); bval = CLEAR_FIFO_CMD; /* Flush FIFO */ OutB(bval,ioport+ScsiCmd); pSRB->ScsiPhase = SCSI_NOP0; bval = pDCB->IdentifyMsg; if( !(pDCB->SyncMode & EN_ATN_STOP) ) { if( (pSRB->CmdBlock[0] == INQUIRY) || (pSRB->CmdBlock[0] == REQUEST_SENSE) || (pSRB->SRBFlag & AUTO_REQSENSE) ) { bval &= 0xBF; /* NO disconnection */ OutB(bval,ioport+ScsiFifo); bval1 = SELECT_W_ATN; pSRB->SRBState = SRB_START_; if( pDCB->SyncMode & SYNC_ENABLE ) { if( !(pDCB->IdentifyMsg & 7) || (pSRB->CmdBlock[0] != INQUIRY) ) { bval1 = SEL_W_ATN_STOP; pSRB->SRBState = SRB_MSGOUT; } } } else { if(pDCB->SyncMode & EN_TAG_QUEUING) { OutB(bval,ioport+ScsiFifo); bval = MSG_SIMPLE_QTAG; OutB(bval,ioport+ScsiFifo); wlval = 1; bval = 0; while( wlval & pDCB->TagMask ) { wlval = wlval << 1; bval++; } OutB(bval,ioport+ScsiFifo); pDCB->TagMask |= wlval; pSRB->TagNumber = bval; bval1 = SEL_W_ATN2; pSRB->SRBState = SRB_START_; } else { OutB(bval,ioport+ScsiFifo); bval1 = SELECT_W_ATN; pSRB->SRBState = SRB_START_; } } if( pSRB->SRBFlag & AUTO_REQSENSE ) { bval = REQUEST_SENSE; OutB(bval,ioport+ScsiFifo); bval = pDCB->IdentifyMsg << 5; OutB(bval,ioport+ScsiFifo); bval = 0; OutB(bval,ioport+ScsiFifo); OutB(bval,ioport+ScsiFifo); bval = sizeof(struct scsi_sense_data); OutB(bval,ioport+ScsiFifo); bval = 0; OutB(bval,ioport+ScsiFifo); } else { cnt = pSRB->ScsiCmdLen; ptr = (PUCHAR) pSRB->CmdBlock; for(i=0; iCmdBlock[0] == INQUIRY) || (pSRB->CmdBlock[0] == REQUEST_SENSE) || (pSRB->SRBFlag & AUTO_REQSENSE) ) { bval &= 0xBF; OutB(bval,ioport+ScsiFifo); bval1 = SELECT_W_ATN; pSRB->SRBState = SRB_START_; if( pDCB->SyncMode & SYNC_ENABLE ) { if( !(pDCB->IdentifyMsg & 7) || (pSRB->CmdBlock[0] != INQUIRY) ) { bval1 = SEL_W_ATN_STOP; pSRB->SRBState = SRB_MSGOUT; } } } else { if(pDCB->SyncMode & EN_TAG_QUEUING) { OutB(bval,ioport+ScsiFifo); pSRB->MsgOutBuf[0] = MSG_SIMPLE_QTAG; wlval = 1; bval = 0; while( wlval & pDCB->TagMask ) { wlval = wlval << 1; bval++; } pDCB->TagMask |= wlval; pSRB->TagNumber = bval; pSRB->MsgOutBuf[1] = bval; pSRB->MsgCnt = 2; bval1 = SEL_W_ATN_STOP; pSRB->SRBState = SRB_START_; } else { OutB(bval,ioport+ScsiFifo); pSRB->MsgOutBuf[0] = MSG_NOP; pSRB->MsgCnt = 1; pSRB->SRBState = SRB_START_; bval1 = SEL_W_ATN_STOP; } } } bval = inb( ioport+Scsi_Status ); if( bval & INTERRUPT ) { pSRB->SRBState = SRB_READY; pDCB->TagMask &= ~( 1 << pSRB->TagNumber ); rc = 1; } else { pSRB->ScsiPhase = SCSI_NOP1; pACB->pActiveDCB = pDCB; pDCB->pActiveSRB = pSRB; rc = 0; OutB(bval1,ioport+ScsiCmd); } return( rc ); } #ifdef REL_2_1_0 static int DC390_Interrupt( PACB pACB ) #endif #ifdef REL_2_1_5 static void DC390_Interrupt( PACB pACB ) #endif { PDCB pDCB; PSRB pSRB; USHORT ioport = 0; USHORT phase; void (*stateV)( PACB, PSRB, PUCHAR ); UCHAR istate = 0; UCHAR sstatus=0, istatus; if( pACB == NULL ) #ifdef REL_2_1_0 return 0; #endif #ifdef REL_2_1_5 return; #endif ioport = pACB->IOPortBase; sstatus = inb( ioport+Scsi_Status ); if( !(sstatus & INTERRUPT) ) #ifdef REL_2_1_0 return 0; #endif #ifdef REL_2_1_5 return; #endif #ifdef DC390_DEBUG1 printf("sstatus=%2x,",sstatus); #endif istate = inb( ioport+Intern_State ); istatus = inb( ioport+INT_Status ); #ifdef DC390_DEBUG1 printf("Istatus=%2x,",istatus); #endif if(istatus & DISCONNECTED) { DC390_Disconnect( pACB ); #ifdef REL_2_1_0 return 1; #endif #ifdef REL_2_1_5 return; #endif } if(istatus & RESELECTED) { DC390_Reselect( pACB ); #ifdef REL_2_1_0 return 1; #endif #ifdef REL_2_1_5 return; #endif } if(istatus & INVALID_CMD) { DC390_InvalidCmd( pACB ); #ifdef REL_2_1_0 return 1; #endif #ifdef REL_2_1_5 return; #endif } if(istatus & SCSI_RESET_) { DC390_ScsiRstDetect( pACB ); #ifdef REL_2_1_0 return 1; #endif #ifdef REL_2_1_5 return; #endif } if( istatus & (SUCCESSFUL_OP+SERVICE_REQUEST) ) { pDCB = pACB->pActiveDCB; pSRB = pDCB->pActiveSRB; if( pDCB ) { if( pDCB->DCBFlag & ABORT_DEV_ ) EnableMsgOut( pACB, pSRB ); } phase = (USHORT) pSRB->ScsiPhase; stateV = (void *) DC390_phase0[phase]; stateV( pACB, pSRB, &sstatus ); pSRB->ScsiPhase = sstatus & 7; phase = (USHORT) sstatus & 7; stateV = (void *) DC390_phase1[phase]; stateV( pACB, pSRB, &sstatus ); } #ifdef REL_2_1_0 return 1; #endif } static void DC390_DataOut_0( PACB pACB, PSRB pSRB, PUCHAR psstatus) { UCHAR sstatus, bval; USHORT ioport; PSEG psgl; ULONG ResidCnt, xferCnt; ioport = pACB->IOPortBase; sstatus = *psstatus; if( !(pSRB->SRBState & SRB_XFERPAD) ) { if( sstatus & PARITY_ERR ) pSRB->SRBStatus |= PARITY_ERROR; if( sstatus & COUNT_2_ZERO ) { bval = inb(ioport+DMA_Status); while( !(bval & DMA_XFER_DONE) ) bval = inb(ioport+DMA_Status); pSRB->TotalXferredLen += pSRB->SGToBeXferLen; pSRB->SGIndex++; if( pSRB->SGIndex < pSRB->SGcount ) { pSRB->pSegmentList++; psgl = pSRB->pSegmentList; pSRB->SGPhysAddr = psgl->SGXPtr; pSRB->SGToBeXferLen = psgl->SGXLen; } else pSRB->SGToBeXferLen = 0; } else { bval = inb( ioport+Current_Fifo ); bval &= 0x1f; ResidCnt = (ULONG) inb(ioport+CtcReg_High); ResidCnt = ResidCnt << 8; ResidCnt |= (ULONG) inb(ioport+CtcReg_Mid); ResidCnt = ResidCnt << 8; ResidCnt |= (ULONG) inb(ioport+CtcReg_Low); ResidCnt += (ULONG) bval; xferCnt = pSRB->SGToBeXferLen - ResidCnt; pSRB->SGPhysAddr += xferCnt; pSRB->TotalXferredLen += xferCnt; pSRB->SGToBeXferLen = ResidCnt; } } bval = WRITE_DIRECTION+DMA_IDLE_CMD; OutB( bval, ioport+DMA_Cmd); } static void DC390_DataIn_0( PACB pACB, PSRB pSRB, PUCHAR psstatus) { UCHAR sstatus, bval; USHORT i, ioport, residual; PSEG psgl; ULONG ResidCnt, xferCnt; PUCHAR ptr; ioport = pACB->IOPortBase; sstatus = *psstatus; if( !(pSRB->SRBState & SRB_XFERPAD) ) { if( sstatus & PARITY_ERR ) pSRB->SRBStatus |= PARITY_ERROR; if( sstatus & COUNT_2_ZERO ) { bval = inb(ioport+DMA_Status); while( !(bval & DMA_XFER_DONE) ) bval = inb(ioport+DMA_Status); bval = READ_DIRECTION+DMA_IDLE_CMD; OutB( bval, ioport+DMA_Cmd); pSRB->TotalXferredLen += pSRB->SGToBeXferLen; pSRB->SGIndex++; if( pSRB->SGIndex < pSRB->SGcount ) { pSRB->pSegmentList++; psgl = pSRB->pSegmentList; pSRB->SGPhysAddr = psgl->SGXPtr; pSRB->SGToBeXferLen = psgl->SGXLen; } else pSRB->SGToBeXferLen = 0; } else /* phase changed */ { residual = 0; bval = inb(ioport+Current_Fifo); while( bval & 0x1f ) { if( (bval & 0x1f) == 1 ) { for(i=0; i< 0x100; i++) { bval = inb(ioport+Current_Fifo); if( !(bval & 0x1f) ) goto din_1; else if( i == 0x0ff ) { residual = 1; /* ;1 residual byte */ goto din_1; } } } else bval = inb(ioport+Current_Fifo); } din_1: bval = READ_DIRECTION+DMA_BLAST_CMD; OutB(bval, ioport+DMA_Cmd); for(i=0; i<0x8000; i++) { bval = inb(ioport+DMA_Status); if(bval & BLAST_COMPLETE) break; } bval = READ_DIRECTION+DMA_IDLE_CMD; OutB(bval, ioport+DMA_Cmd); ResidCnt = (ULONG) inb(ioport+CtcReg_High); ResidCnt = ResidCnt << 8; ResidCnt |= (ULONG) inb(ioport+CtcReg_Mid); ResidCnt = ResidCnt << 8; ResidCnt |= (ULONG) inb(ioport+CtcReg_Low); xferCnt = pSRB->SGToBeXferLen - ResidCnt; pSRB->SGPhysAddr += xferCnt; pSRB->TotalXferredLen += xferCnt; pSRB->SGToBeXferLen = ResidCnt; if( residual ) { bval = inb(ioport+ScsiFifo); /* get residual byte */ ptr = phystovirt( pSRB, xferCnt); *ptr = bval; pSRB->SGPhysAddr++; pSRB->TotalXferredLen++; pSRB->SGToBeXferLen--; } } } } static void DC390_Command_0( PACB pACB, PSRB pSRB, PUCHAR psstatus) { } static void DC390_Status_0( PACB pACB, PSRB pSRB, PUCHAR psstatus) { UCHAR bval; USHORT ioport; ioport = pACB->IOPortBase; bval = inb(ioport+ScsiFifo); pSRB->TargetStatus = bval; bval++; bval = inb(ioport+ScsiFifo); /* get message */ pSRB->EndMessage = bval; *psstatus = SCSI_NOP0; pSRB->SRBState = SRB_COMPLETED; bval = MSG_ACCEPTED_CMD; OutB(bval, ioport+ScsiCmd); } static void DC390_MsgOut_0( PACB pACB, PSRB pSRB, PUCHAR psstatus) { if( pSRB->SRBState & (SRB_UNEXPECT_RESEL+SRB_ABORT_SENT) ) *psstatus = SCSI_NOP0; } static void DC390_MsgIn_0( PACB pACB, PSRB pSRB, PUCHAR psstatus) { UCHAR bval; USHORT ioport, wval, wval1; PDCB pDCB; PSRB psrb; ioport = pACB->IOPortBase; pDCB = pACB->pActiveDCB; bval = inb( ioport+ScsiFifo ); if( !(pSRB->SRBState & SRB_MSGIN_MULTI) ) { if(bval == MSG_DISCONNECT) { pSRB->SRBState = SRB_DISCONNECT; } else if( bval == MSG_SAVE_PTR ) goto min6; else if( (bval == MSG_EXTENDED) || ((bval >= MSG_SIMPLE_QTAG) && (bval <= MSG_ORDER_QTAG)) ) { pSRB->SRBState |= SRB_MSGIN_MULTI; pSRB->MsgInBuf[0] = bval; pSRB->MsgCnt = 1; pSRB->pMsgPtr = &pSRB->MsgInBuf[1]; } else if(bval == MSG_REJECT_) { bval = RESET_ATN_CMD; OutB(bval, ioport+ScsiCmd); if( pSRB->SRBState & DO_SYNC_NEGO) goto set_async; } else if( bval == MSG_RESTORE_PTR) goto min6; else goto min6; } else { /* minx: */ *pSRB->pMsgPtr = bval; pSRB->MsgCnt++; pSRB->pMsgPtr++; if( (pSRB->MsgInBuf[0] >= MSG_SIMPLE_QTAG) && (pSRB->MsgInBuf[0] <= MSG_ORDER_QTAG) ) { if( pSRB->MsgCnt == 2) { pSRB->SRBState = 0; bval = pSRB->MsgInBuf[1]; pSRB = pDCB->pGoingSRB; psrb = pDCB->pGoingLast; if( pSRB ) { for( ;; ) { if(pSRB->TagNumber != bval) { if( pSRB == psrb ) goto mingx0; pSRB = pSRB->pNextSRB; } else break; } if( pDCB->DCBFlag & ABORT_DEV_ ) { pSRB->SRBState = SRB_ABORT_SENT; EnableMsgOut( pACB, pSRB ); } if( !(pSRB->SRBState & SRB_DISCONNECT) ) goto mingx0; pDCB->pActiveSRB = pSRB; pSRB->SRBState = SRB_DATA_XFER; } else { mingx0: pSRB = pACB->pTmpSRB; pSRB->SRBState = SRB_UNEXPECT_RESEL; pDCB->pActiveSRB = pSRB; pSRB->MsgOutBuf[0] = MSG_ABORT_TAG; EnableMsgOut2( pACB, pSRB ); } } } else if( (pSRB->MsgInBuf[0] == MSG_EXTENDED) && (pSRB->MsgCnt == 5) ) { pSRB->SRBState &= ~(SRB_MSGIN_MULTI+DO_SYNC_NEGO); if( (pSRB->MsgInBuf[1] != 3) || (pSRB->MsgInBuf[2] != 1) ) { /* reject_msg: */ pSRB->MsgCnt = 1; pSRB->MsgInBuf[0] = MSG_REJECT_; bval = SET_ATN_CMD; OutB(bval, ioport+ScsiCmd); } else if( !(pSRB->MsgInBuf[3]) || !(pSRB->MsgInBuf[4]) ) { set_async: pDCB = pSRB->pSRBDCB; pDCB->SyncMode &= ~(SYNC_ENABLE+SYNC_NEGO_DONE); pDCB->SyncPeriod = 0; pDCB->SyncOffset = 0; pDCB->CtrlR3 = FAST_CLK; /* ;non_fast */ pDCB->CtrlR4 &= 0x3f; pDCB->CtrlR4 |= EATER_25NS; /* ; 25ns glitch eater */ goto re_prog; } else { /* set_sync: */ pDCB = pSRB->pSRBDCB; pDCB->SyncMode |= SYNC_ENABLE+SYNC_NEGO_DONE; pDCB->SyncOffset &= 0x0f0; pDCB->SyncOffset |= pSRB->MsgInBuf[4]; pDCB->NegoPeriod = pSRB->MsgInBuf[3]; wval = (USHORT) pSRB->MsgInBuf[3]; wval = wval << 2; wval--; wval1 = wval / 25; if( (wval1 * 25) != wval) wval1++; bval = FAST_CLK+FAST_SCSI; pDCB->CtrlR4 &= 0x3f; if(wval1 >= 8) { wval1--; bval = FAST_CLK; /* ;fast clock/normal scsi */ pDCB->CtrlR4 |= EATER_25NS; /* ;25 ns glitch eater */ } pDCB->CtrlR3 = bval; pDCB->SyncPeriod = (UCHAR)wval1; re_prog: bval = pDCB->SyncPeriod; OutB(bval, ioport+Sync_Period); bval = pDCB->SyncOffset; OutB(bval, ioport+Sync_Offset); bval = pDCB->CtrlR3; OutB(bval, ioport+CtrlReg3); bval = pDCB->CtrlR4; OutB(bval, ioport+CtrlReg4); SetXferRate( pACB, pDCB); } } } min6: *psstatus = SCSI_NOP0; bval = MSG_ACCEPTED_CMD; OutB(bval, ioport+ScsiCmd); } static void DataIO_Comm( PACB pACB, PSRB pSRB, UCHAR ioDir) { PSEG psgl; UCHAR bval; USHORT ioport; ULONG lval; ioport = pACB->IOPortBase; if( pSRB->SGIndex < pSRB->SGcount ) { bval = DMA_IDLE_CMD | ioDir; /* ;+EN_DMA_INT */ OutB( bval, ioport+DMA_Cmd); if( !pSRB->SGToBeXferLen ) { psgl = pSRB->pSegmentList; pSRB->SGPhysAddr = psgl->SGXPtr; pSRB->SGToBeXferLen = psgl->SGXLen; } lval = pSRB->SGToBeXferLen; bval = (UCHAR) lval; OutB(bval,ioport+CtcReg_Low); lval = lval >> 8; bval = (UCHAR) lval; OutB(bval,ioport+CtcReg_Mid); lval = lval >> 8; bval = (UCHAR) lval; OutB(bval,ioport+CtcReg_High); lval = pSRB->SGToBeXferLen; OutL(lval, ioport+DMA_XferCnt); lval = pSRB->SGPhysAddr; OutL( lval, ioport+DMA_XferAddr); pSRB->SRBState = SRB_DATA_XFER; bval = DMA_COMMAND+INFO_XFER_CMD; OutB(bval, ioport+ScsiCmd); bval = DMA_IDLE_CMD | ioDir; /* ;+EN_DMA_INT */ OutB(bval, ioport+DMA_Cmd); bval = DMA_START_CMD | ioDir; /* ;+EN_DMA_INT */ OutB(bval, ioport+DMA_Cmd); } else /* xfer pad */ { if( pSRB->SGcount ) { pSRB->AdaptStatus = H_OVER_UNDER_RUN; pSRB->SRBStatus |= OVER_RUN; } bval = 0; OutB(bval,ioport+CtcReg_Low); OutB(bval,ioport+CtcReg_Mid); OutB(bval,ioport+CtcReg_High); pSRB->SRBState |= SRB_XFERPAD; bval = DMA_COMMAND+XFER_PAD_BYTE; OutB(bval, ioport+ScsiCmd); /* bval = DMA_IDLE_CMD | ioDir; ;+EN_DMA_INT OutB(bval, ioport+DMA_Cmd); bval = DMA_START_CMD | ioDir; ;+EN_DMA_INT OutB(bval, ioport+DMA_Cmd); */ } } static void DC390_DataOutPhase( PACB pACB, PSRB pSRB, PUCHAR psstatus) { UCHAR ioDir; ioDir = WRITE_DIRECTION; DataIO_Comm( pACB, pSRB, ioDir); } static void DC390_DataInPhase( PACB pACB, PSRB pSRB, PUCHAR psstatus) { UCHAR ioDir; ioDir = READ_DIRECTION; DataIO_Comm( pACB, pSRB, ioDir); } static void DC390_CommandPhase( PACB pACB, PSRB pSRB, PUCHAR psstatus) { PDCB pDCB; UCHAR bval; PUCHAR ptr; USHORT ioport, i, cnt; ioport = pACB->IOPortBase; bval = RESET_ATN_CMD; OutB(bval, ioport+ScsiCmd); bval = CLEAR_FIFO_CMD; OutB(bval, ioport+ScsiCmd); if( !(pSRB->SRBFlag & AUTO_REQSENSE) ) { cnt = (USHORT) pSRB->ScsiCmdLen; ptr = (PUCHAR) pSRB->CmdBlock; for(i=0; i < cnt; i++) { OutB(*ptr, ioport+ScsiFifo); ptr++; } } else { bval = REQUEST_SENSE; OutB(bval, ioport+ScsiFifo); pDCB = pACB->pActiveDCB; bval = pDCB->IdentifyMsg << 5; OutB(bval, ioport+ScsiFifo); bval = 0; OutB(bval, ioport+ScsiFifo); OutB(bval, ioport+ScsiFifo); bval = sizeof(struct scsi_sense_data); OutB(bval, ioport+ScsiFifo); bval = 0; OutB(bval, ioport+ScsiFifo); } pSRB->SRBState = SRB_COMMAND; bval = INFO_XFER_CMD; OutB(bval, ioport+ScsiCmd); } static void DC390_StatusPhase( PACB pACB, PSRB pSRB, PUCHAR psstatus) { UCHAR bval; USHORT ioport; ioport = pACB->IOPortBase; bval = CLEAR_FIFO_CMD; OutB(bval, ioport+ScsiCmd); pSRB->SRBState = SRB_STATUS; bval = INITIATOR_CMD_CMPLTE; OutB(bval, ioport+ScsiCmd); } static void DC390_MsgOutPhase( PACB pACB, PSRB pSRB, PUCHAR psstatus) { UCHAR bval; USHORT ioport, i, cnt; PUCHAR ptr; PDCB pDCB; ioport = pACB->IOPortBase; bval = CLEAR_FIFO_CMD; OutB(bval, ioport+ScsiCmd); pDCB = pACB->pActiveDCB; if( !(pSRB->SRBState & SRB_MSGOUT) ) { cnt = pSRB->MsgCnt; if( cnt ) { ptr = (PUCHAR) pSRB->MsgOutBuf; for(i=0; i < cnt; i++) { OutB(*ptr, ioport+ScsiFifo); ptr++; } pSRB->MsgCnt = 0; if( (pDCB->DCBFlag & ABORT_DEV_) && (pSRB->MsgOutBuf[0] == MSG_ABORT) ) pSRB->SRBState = SRB_ABORT_SENT; } else { bval = MSG_ABORT; /* ??? MSG_NOP */ if( (pSRB->CmdBlock[0] == INQUIRY ) || (pSRB->CmdBlock[0] == REQUEST_SENSE) || (pSRB->SRBFlag & AUTO_REQSENSE) ) { if( pDCB->SyncMode & SYNC_ENABLE ) goto mop1; } OutB(bval, ioport+ScsiFifo); } bval = INFO_XFER_CMD; OutB( bval, ioport+ScsiCmd); } else { mop1: bval = MSG_EXTENDED; OutB(bval, ioport+ScsiFifo); bval = 3; /* ;length of extended msg */ OutB(bval, ioport+ScsiFifo); bval = 1; /* ; sync nego */ OutB(bval, ioport+ScsiFifo); bval = pDCB->NegoPeriod; OutB(bval, ioport+ScsiFifo); bval = SYNC_NEGO_OFFSET; OutB(bval, ioport+ScsiFifo); pSRB->SRBState |= DO_SYNC_NEGO; bval = INFO_XFER_CMD; OutB(bval, ioport+ScsiCmd); } } static void DC390_MsgInPhase( PACB pACB, PSRB pSRB, PUCHAR psstatus) { UCHAR bval; USHORT ioport; ioport = pACB->IOPortBase; bval = CLEAR_FIFO_CMD; OutB(bval, ioport+ScsiCmd); if( !(pSRB->SRBState & SRB_MSGIN) ) { pSRB->SRBState &= SRB_DISCONNECT; pSRB->SRBState |= SRB_MSGIN; } bval = INFO_XFER_CMD; OutB(bval, ioport+ScsiCmd); } static void DC390_Nop_0( PACB pACB, PSRB pSRB, PUCHAR psstatus) { } static void DC390_Nop_1( PACB pACB, PSRB pSRB, PUCHAR psstatus) { } static void SetXferRate( PACB pACB, PDCB pDCB ) { UCHAR bval; USHORT cnt, i; PDCB ptr; if( !(pDCB->IdentifyMsg & 0x07) ) { if( pACB->scan_devices ) { CurrSyncOffset = pDCB->SyncOffset; } else { ptr = pACB->pLinkDCB; cnt = pACB->DeviceCnt; bval = pDCB->UnitSCSIID; for(i=0; iUnitSCSIID == bval ) { ptr->SyncPeriod = pDCB->SyncPeriod; ptr->SyncOffset = pDCB->SyncOffset; ptr->CtrlR3 = pDCB->CtrlR3; ptr->CtrlR4 = pDCB->CtrlR4; ptr->SyncMode = pDCB->SyncMode; } ptr = ptr->pNextDCB; } } } return; } static void DC390_Disconnect( PACB pACB ) { PDCB pDCB; PSRB pSRB, psrb; int flags; USHORT ioport, i, cnt; UCHAR bval; #ifdef DC390_DEBUG0 printf("DISC,"); #endif flags = splbio(); ioport = pACB->IOPortBase; pDCB = pACB->pActiveDCB; pSRB = pDCB->pActiveSRB; pACB->pActiveDCB = 0; pSRB->ScsiPhase = SCSI_NOP0; bval = EN_SEL_RESEL; OutB(bval, ioport+ScsiCmd); if( pSRB->SRBState & SRB_UNEXPECT_RESEL ) { pSRB->SRBState = 0; DoWaitingSRB( pACB ); } else if( pSRB->SRBState & SRB_ABORT_SENT ) { pDCB->TagMask = 0; pDCB->DCBFlag = 0; cnt = pDCB->GoingSRBCnt; pDCB->GoingSRBCnt = 0; pSRB = pDCB->pGoingSRB; for( i=0; i < cnt; i++) { psrb = pSRB->pNextSRB; pSRB->pNextSRB = pACB->pFreeSRB; pACB->pFreeSRB = pSRB; pSRB = psrb; } pDCB->pGoingSRB = 0; DoWaitingSRB( pACB ); } else { if( (pSRB->SRBState & (SRB_START_+SRB_MSGOUT)) || !(pSRB->SRBState & (SRB_DISCONNECT+SRB_COMPLETED)) ) { /* Selection time out */ if( !(pACB->scan_devices) ) { pSRB->SRBState = SRB_READY; RewaitSRB( pDCB, pSRB); } else { pSRB->TargetStatus = SCSI_STAT_SEL_TIMEOUT; goto disc1; } } else if( pSRB->SRBState & SRB_DISCONNECT ) { DoWaitingSRB( pACB ); } else if( pSRB->SRBState & SRB_COMPLETED ) { disc1: if(pDCB->MaxCommand > 1) { bval = pSRB->TagNumber; pDCB->TagMask &= (~(1 << bval)); /* free tag mask */ } pDCB->pActiveSRB = 0; pSRB->SRBState = SRB_FREE; SRBdone( pACB, pDCB, pSRB); } } splx(flags); return; } static void DC390_Reselect( PACB pACB ) { PDCB pDCB; PSRB pSRB; USHORT ioport, wval; UCHAR bval, bval1; #ifdef DC390_DEBUG0 printf("RSEL,"); #endif ioport = pACB->IOPortBase; pDCB = pACB->pActiveDCB; if( pDCB ) { /* Arbitration lost but Reselection win */ pSRB = pDCB->pActiveSRB; if( !( pACB->scan_devices ) ) { pSRB->SRBState = SRB_READY; RewaitSRB( pDCB, pSRB); } } bval = inb(ioport+ScsiFifo); /* get ID */ bval = bval ^ pACB->HostID_Bit; wval = 0; bval1 = 1; for(;;) { if( !(bval & bval1) ) { bval1 = bval1 << 1; wval++; } else break; } wval |= ( (USHORT) inb(ioport+ScsiFifo) & 7) << 8; /* get LUN */ pDCB = pACB->pLinkDCB; while( wval != *((PUSHORT) &pDCB->UnitSCSIID) ) pDCB = pDCB->pNextDCB; pACB->pActiveDCB = pDCB; if( pDCB->SyncMode & EN_TAG_QUEUING ) { pSRB = pACB->pTmpSRB; pDCB->pActiveSRB = pSRB; } else { pSRB = pDCB->pActiveSRB; if( !pSRB || !(pSRB->SRBState & SRB_DISCONNECT) ) { pSRB= pACB->pTmpSRB; pSRB->SRBState = SRB_UNEXPECT_RESEL; pDCB->pActiveSRB = pSRB; EnableMsgOut( pACB, pSRB ); } else { if( pDCB->DCBFlag & ABORT_DEV_ ) { pSRB->SRBState = SRB_ABORT_SENT; EnableMsgOut( pACB, pSRB ); } else pSRB->SRBState = SRB_DATA_XFER; } } pSRB->ScsiPhase = SCSI_NOP0; bval = pDCB->UnitSCSIID; OutB( bval, ioport+Scsi_Dest_ID); bval = pDCB->SyncPeriod; OutB(bval, ioport+Sync_Period); bval = pDCB->SyncOffset; OutB( bval, ioport+Sync_Offset); bval = pDCB->CtrlR1; OutB(bval, ioport+CtrlReg1); bval = pDCB->CtrlR3; OutB(bval, ioport+CtrlReg3); bval = pDCB->CtrlR4; /* ; Glitch eater */ OutB(bval, ioport+CtrlReg4); bval = MSG_ACCEPTED_CMD; /* ;to rls the /ACK signal */ OutB(bval, ioport+ScsiCmd); } static void SRBdone( PACB pACB, PDCB pDCB, PSRB pSRB ) { PSRB psrb; UCHAR bval, bval1, i, j, status; PSCSICMD pcmd; PSCLINK plink; PSCSI_INQDATA ptr; USHORT disable_tag; int flags; PSEG ptr2; ULONG swlval; pcmd = pSRB->pcmd; plink = pcmd->sc_link; status = pSRB->TargetStatus; if(pSRB->SRBFlag & AUTO_REQSENSE) { pSRB->SRBFlag &= ~AUTO_REQSENSE; pSRB->AdaptStatus = 0; pSRB->TargetStatus = SCSI_STAT_CHECKCOND; if(status == SCSI_STAT_CHECKCOND) { pcmd->error = XS_TIMEOUT; goto ckc_e; } if(pSRB->RetryCnt == 0) { *((PULONG) &(pSRB->CmdBlock[0])) = pSRB->Segment0[0]; pSRB->TotalXferredLen = pSRB->Segment1[1]; if( pSRB->TotalXferredLen ) { pcmd->resid = pcmd->datalen - pSRB->TotalXferredLen; pcmd->error = XS_SENSE; pcmd->flags |= SCSI_RESID_VALID; } else { pcmd->error = XS_SENSE; pcmd->status = SCSI_STAT_CHECKCOND; } goto ckc_e; } else { pSRB->RetryCnt--; pSRB->AdaptStatus = 0; pSRB->TargetStatus = 0; *((PULONG) &(pSRB->CmdBlock[0])) = pSRB->Segment0[0]; *((PULONG) &(pSRB->CmdBlock[4])) = pSRB->Segment0[1]; if( pSRB->CmdBlock[0] == TEST_UNIT_READY ) { pcmd->error = XS_SENSE; pcmd->status = SCSI_STAT_CHECKCOND; goto ckc_e; } pcmd->error = XS_SENSE; pSRB->SGcount = (UCHAR) pSRB->Segment1[0]; pSRB->ScsiCmdLen = (UCHAR) (pSRB->Segment1[0] >> 8); pSRB->pSegmentList = (PSEG) &pSRB->SGsegment[0]; pSRB->SGIndex = 0; pSRB->TotalXferredLen = 0; pSRB->SGToBeXferLen = 0; if( DC390_StartSCSI( pACB, pDCB, pSRB ) ) RewaitSRB( pDCB, pSRB ); return; } } if( status ) { if( status == SCSI_STAT_CHECKCOND) { if( (pSRB->SGIndex < pSRB->SGcount) && (pSRB->SGcount) && (pSRB->SGToBeXferLen) ) { bval = pSRB->SGcount; swlval = pSRB->SGToBeXferLen; ptr2 = pSRB->pSegmentList; ptr2++; for( i=pSRB->SGIndex+1; i < bval; i++) { swlval += ptr2->SGXLen; ptr2++; } #ifdef DC390_DEBUG0 printf("XferredLen=%8x,NotXferLen=%8x,", (UINT) pSRB->TotalXferredLen, (UINT) swlval); #endif } RequestSense( pACB, pDCB, pSRB ); return; } else if( status == SCSI_STAT_QUEUEFULL ) { bval = (UCHAR) pDCB->GoingSRBCnt; bval--; pDCB->MaxCommand = bval; RewaitSRB( pDCB, pSRB ); pSRB->AdaptStatus = 0; pSRB->TargetStatus = 0; return; } else if(status == SCSI_STAT_SEL_TIMEOUT) { pSRB->AdaptStatus = H_SEL_TIMEOUT; pSRB->TargetStatus = 0; pcmd->error = XS_TIMEOUT; } else if (status == SCSI_STAT_BUSY) { #ifdef DC390_DEBUG0 printf("DC390: target busy at %s %d\n", __FILE__, __LINE__); #endif pcmd->error = XS_BUSY; } else if (status == SCSI_STAT_RESCONFLICT) { #ifdef DC390_DEBUG0 printf("DC390: target reserved at %s %d\n", __FILE__, __LINE__); #endif pcmd->error = XS_BUSY; /*XXX*/ } else { pSRB->AdaptStatus = 0; if( pSRB->RetryCnt ) { pSRB->RetryCnt--; pSRB->TargetStatus = 0; pSRB->SGIndex = 0; pSRB->TotalXferredLen = 0; pSRB->SGToBeXferLen = 0; pSRB->pSegmentList = (PSEG) &pSRB->SGsegment[0]; if( DC390_StartSCSI( pACB, pDCB, pSRB ) ) RewaitSRB( pDCB, pSRB ); return; } else { #ifdef DC390_DEBUG0 printf("DC390: driver stuffup at %s %d\n", __FILE__, __LINE__); #endif pcmd->error = XS_DRIVER_STUFFUP; } } } else { status = pSRB->AdaptStatus; if(status & H_OVER_UNDER_RUN) { pSRB->TargetStatus = 0; pcmd->error = XS_LENGTH; } else if( pSRB->SRBStatus & PARITY_ERROR) { #ifdef DC390_DEBUG0 printf("DC390: driver stuffup %s %d\n", __FILE__, __LINE__); #endif pcmd->error = XS_DRIVER_STUFFUP; } else /* No error */ { pSRB->AdaptStatus = 0; pSRB->TargetStatus = 0; pcmd->error = XS_NOERROR; } } ckc_e: if( pACB->scan_devices ) { if( pSRB->CmdBlock[0] == TEST_UNIT_READY ) { if(pcmd->error == XS_TIMEOUT ) { pACB->DCBmap[plink->target] &= ~(1 << plink->lun); pPrevDCB->pNextDCB = pACB->pLinkDCB; } else { pPrevDCB->pNextDCB = pDCB; pDCB->pNextDCB = pACB->pLinkDCB; } } else if( pSRB->CmdBlock[0] == INQUIRY ) { if( (plink->target == pACB->max_id) && (plink->lun == pACB->max_lun) ) pACB->scan_devices = 0; if(pcmd->error == XS_TIMEOUT ) goto NO_DEV; ptr = (PSCSI_INQDATA) (pcmd->data); bval1 = ptr->DevType & SCSI_DEVTYPE; if(bval1 == SCSI_NODEV) { NO_DEV: pACB->DCBmap[plink->target] &= ~(1 << plink->lun); pPrevDCB->pNextDCB = pACB->pLinkDCB; } else { pACB->DeviceCnt++; pPrevDCB = pDCB; - pACB->pDCB_free = (PDCB) ((ULONG) (pACB->pDCB_free) + sizeof( DC390_DCB )); + pACB->pDCB_free = (PDCB) ((uintptr_t) (pACB->pDCB_free) + sizeof( DC390_DCB )); pDCB->DevType = bval1; if(bval1 == SCSI_DASD || bval1 == SCSI_OPTICAL) { if( (((ptr->Vers & 0x07) >= 2) || ((ptr->RDF & 0x0F) == 2)) && (ptr->Flags & SCSI_INQ_CMDQUEUE) && (pDCB->DevMode & TAG_QUEUING_) && (pDCB->DevMode & EN_DISCONNECT_) ) { disable_tag = 0; for(i=0; iMaxCommand = pACB->TagMaxNum; pDCB->SyncMode |= EN_TAG_QUEUING; pDCB->TagMask = 0; } else { pDCB->SyncMode |= EN_ATN_STOP; } } } } } } flags = splbio(); /* ReleaseSRB( pDCB, pSRB ); */ if(pSRB == pDCB->pGoingSRB ) { pDCB->pGoingSRB = pSRB->pNextSRB; } else { psrb = pDCB->pGoingSRB; while( psrb->pNextSRB != pSRB ) psrb = psrb->pNextSRB; psrb->pNextSRB = pSRB->pNextSRB; if( pSRB == pDCB->pGoingLast ) pDCB->pGoingLast = psrb; } pSRB->pNextSRB = pACB->pFreeSRB; pACB->pFreeSRB = pSRB; pDCB->GoingSRBCnt--; DoWaitingSRB( pACB ); splx(flags); pcmd->flags |= ITSDONE; /* Notify cmd done */ scsi_done( pcmd ); } static void DoingSRB_Done( PACB pACB ) { PDCB pDCB, pdcb; PSRB psrb, psrb2; USHORT cnt, i; PSCSICMD pcmd; pDCB = pACB->pLinkDCB; pdcb = pDCB; do { cnt = pdcb->GoingSRBCnt; psrb = pdcb->pGoingSRB; for( i=0; ipNextSRB; pcmd = psrb->pcmd; pcmd->error = XS_TIMEOUT; /* ReleaseSRB( pDCB, pSRB ); */ psrb->pNextSRB = pACB->pFreeSRB; pACB->pFreeSRB = psrb; scsi_done( pcmd ); psrb = psrb2; } pdcb->GoingSRBCnt = 0;; pdcb->pGoingSRB = NULL; pdcb->TagMask = 0; pdcb = pdcb->pNextDCB; } while( pdcb != pDCB ); } static void DC390_ResetSCSIBus( PACB pACB ) { USHORT ioport; UCHAR bval; int flags; flags = splbio(); pACB->ACBFlag |= RESET_DEV; ioport = pACB->IOPortBase; bval = DMA_IDLE_CMD; OutB(bval,ioport+DMA_Cmd); bval = RST_SCSI_BUS_CMD; OutB(bval,ioport+ScsiCmd); splx(flags); return; } static void DC390_ScsiRstDetect( PACB pACB ) { int flags; ULONG wlval; USHORT ioport; UCHAR bval; #ifdef DC390_DEBUG0 printf("RST_DETEC"); #endif wlval = 1000; while( --wlval ) /* delay 1 sec */ { DELAY(1000); } flags = splbio(); ioport = pACB->IOPortBase; bval = DMA_IDLE_CMD; OutB(bval,ioport+DMA_Cmd); bval = CLEAR_FIFO_CMD; OutB(bval,ioport+ScsiCmd); if( pACB->ACBFlag & RESET_DEV ) pACB->ACBFlag |= RESET_DONE; else { pACB->ACBFlag |= RESET_DETECT; ResetDevParam( pACB ); /* DoingSRB_Done( pACB ); ???? */ RecoverSRB( pACB ); pACB->pActiveDCB = NULL; pACB->ACBFlag = 0; DoWaitingSRB( pACB ); } splx(flags); return; } static void RequestSense( PACB pACB, PDCB pDCB, PSRB pSRB ) { PSCSICMD pcmd; pSRB->SRBFlag |= AUTO_REQSENSE; pSRB->Segment0[0] = *((PULONG) &(pSRB->CmdBlock[0])); pSRB->Segment0[1] = *((PULONG) &(pSRB->CmdBlock[4])); pSRB->Segment1[0] = (ULONG) ((pSRB->ScsiCmdLen << 8) + pSRB->SGcount); pSRB->Segment1[1] = pSRB->TotalXferredLen; pSRB->AdaptStatus = 0; pSRB->TargetStatus = 0; pcmd = pSRB->pcmd; pSRB->Segmentx.SGXPtr = (ULONG) vtophys(&pcmd->sense); pSRB->Segmentx.SGXLen = (ULONG) sizeof(struct scsi_sense_data); pSRB->pSegmentList = &pSRB->Segmentx; pSRB->SGcount = 1; pSRB->SGIndex = 0; *((PULONG) &(pSRB->CmdBlock[0])) = 0x00000003; pSRB->CmdBlock[1] = pDCB->IdentifyMsg << 5; *((PUSHORT) &(pSRB->CmdBlock[4])) = sizeof(struct scsi_sense_data); pSRB->ScsiCmdLen = 6; pSRB->TotalXferredLen = 0; pSRB->SGToBeXferLen = 0; if( DC390_StartSCSI( pACB, pDCB, pSRB ) ) RewaitSRB( pDCB, pSRB ); } static void EnableMsgOut2( PACB pACB, PSRB pSRB ) { USHORT ioport; UCHAR bval; ioport = pACB->IOPortBase; pSRB->MsgCnt = 1; bval = SET_ATN_CMD; OutB(bval, ioport+ScsiCmd); } static void EnableMsgOut( PACB pACB, PSRB pSRB ) { pSRB->MsgOutBuf[0] = MSG_ABORT; EnableMsgOut2( pACB, pSRB ); } static void DC390_InvalidCmd( PACB pACB ) { UCHAR bval; USHORT ioport; PSRB pSRB; pSRB = pACB->pActiveDCB->pActiveSRB; if( pSRB->SRBState & (SRB_START_+SRB_MSGOUT) ) { ioport = pACB->IOPortBase; bval = CLEAR_FIFO_CMD; OutB(bval,(ioport+ScsiCmd)); } }