1*17b08548Sskrll /* $NetBSD: i82596var.h,v 1.15 2009/12/01 23:16:01 skrll Exp $ */ 217e4dce3Sjkunz 317e4dce3Sjkunz /* 417e4dce3Sjkunz * Copyright (c) 2003 Jochen Kunz. 517e4dce3Sjkunz * All rights reserved. 617e4dce3Sjkunz * 717e4dce3Sjkunz * Redistribution and use in source and binary forms, with or without 817e4dce3Sjkunz * modification, are permitted provided that the following conditions 917e4dce3Sjkunz * are met: 1017e4dce3Sjkunz * 1. Redistributions of source code must retain the above copyright 1117e4dce3Sjkunz * notice, this list of conditions and the following disclaimer. 1217e4dce3Sjkunz * 2. Redistributions in binary form must reproduce the above copyright 1317e4dce3Sjkunz * notice, this list of conditions and the following disclaimer in the 1417e4dce3Sjkunz * documentation and/or other materials provided with the distribution. 1517e4dce3Sjkunz * 3. The name of Jochen Kunz may not be used to endorse or promote 1617e4dce3Sjkunz * products derived from this software without specific prior 1717e4dce3Sjkunz * written permission. 1817e4dce3Sjkunz * 1917e4dce3Sjkunz * THIS SOFTWARE IS PROVIDED BY JOCHEN KUNZ 2017e4dce3Sjkunz * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 2117e4dce3Sjkunz * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 2217e4dce3Sjkunz * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JOCHEN KUNZ 2317e4dce3Sjkunz * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2417e4dce3Sjkunz * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2517e4dce3Sjkunz * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2617e4dce3Sjkunz * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2717e4dce3Sjkunz * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2817e4dce3Sjkunz * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2917e4dce3Sjkunz * POSSIBILITY OF SUCH DAMAGE. 3017e4dce3Sjkunz */ 3117e4dce3Sjkunz 3217e4dce3Sjkunz /* All definitions are for a Intel 82596 DX/SX / CA in linear 32 bit mode. */ 3317e4dce3Sjkunz 3417e4dce3Sjkunz 3517e4dce3Sjkunz 3617e4dce3Sjkunz /* Supported chip variants */ 3788aa783dSskrll extern const char *i82596_typenames[]; 3817e4dce3Sjkunz enum i82596_types { I82596_UNKNOWN, I82596_DX, I82596_CA }; 3917e4dce3Sjkunz 4017e4dce3Sjkunz 4117e4dce3Sjkunz 4217e4dce3Sjkunz /* System Configuration Pointer */ 4317e4dce3Sjkunz struct iee_scp { 4411b735f2Stsutsui volatile uint16_t scp_pad1; 4511b735f2Stsutsui volatile uint16_t scp_sysbus; /* Sysbus Byte */ 4611b735f2Stsutsui volatile uint32_t scp_pad2; 4711b735f2Stsutsui volatile uint32_t scp_iscp_addr; /* Int. Sys. Conf. Pointer */ 48b6a2ef75Sperry } __packed; 4917e4dce3Sjkunz 5017e4dce3Sjkunz 5117e4dce3Sjkunz 5217e4dce3Sjkunz /* Intermediate System Configuration Pointer */ 5317e4dce3Sjkunz struct iee_iscp { 54*17b08548Sskrll volatile uint16_t iscp_busy; /* Even Word, bits 0..15 */ 5511b735f2Stsutsui volatile uint16_t iscp_pad; /* Odd Word, bits 16..32 */ 5611b735f2Stsutsui volatile uint32_t iscp_scb_addr; /* address of SCB */ 57b6a2ef75Sperry } __packed; 5817e4dce3Sjkunz 5917e4dce3Sjkunz 6017e4dce3Sjkunz 6117e4dce3Sjkunz /* System Control Block */ 6217e4dce3Sjkunz struct iee_scb { 6311b735f2Stsutsui volatile uint16_t scb_status; /* Status Bits */ 6411b735f2Stsutsui volatile uint16_t scb_cmd; /* Command Bits */ 6511b735f2Stsutsui volatile uint32_t scb_cmd_blk_addr; /* Command Block Address */ 6611b735f2Stsutsui volatile uint32_t scb_rfa_addr; /* Receive Frame Area Address */ 6711b735f2Stsutsui volatile uint32_t scb_crc_err; /* CRC Errors */ 6811b735f2Stsutsui volatile uint32_t scb_align_err; /* Alignment Errors */ 6911b735f2Stsutsui volatile uint32_t scb_resource_err; /* Resource Errors [1] */ 7011b735f2Stsutsui volatile uint32_t scb_overrun_err; /* Overrun Errors [1] */ 7111b735f2Stsutsui volatile uint32_t scb_rcvcdt_err; /* RCVCDT Errors [1] */ 7211b735f2Stsutsui volatile uint32_t scb_short_fr_err; /* Short Frame Errors */ 7311b735f2Stsutsui volatile uint16_t scb_tt_off; /* Bus Throtle Off Timer */ 7411b735f2Stsutsui volatile uint16_t scb_tt_on; /* Bus Throtle On Timer */ 75b6a2ef75Sperry } __packed; 7617e4dce3Sjkunz /* [1] In MONITOR mode these counters change function. */ 7717e4dce3Sjkunz 7817e4dce3Sjkunz 7917e4dce3Sjkunz 8017e4dce3Sjkunz /* Command Block */ 8117e4dce3Sjkunz struct iee_cb { 8211b735f2Stsutsui volatile uint16_t cb_status; /* Status Bits */ 8311b735f2Stsutsui volatile uint16_t cb_cmd; /* Command Bits */ 8411b735f2Stsutsui volatile uint32_t cb_link_addr; /* Link Address to next CMD */ 8517e4dce3Sjkunz union { 8611b735f2Stsutsui volatile uint8_t cb_ind_addr[8];/* Individual Address */ 8711b735f2Stsutsui volatile uint8_t cb_cf[16]; /* Configuration Bytes */ 8817e4dce3Sjkunz struct { 8911b735f2Stsutsui volatile uint16_t mc_size;/* Num bytes of Mcast Addr.*/ 9011b735f2Stsutsui volatile uint8_t mc_addrs[6]; /* List of Mcast Addr. */ 9117e4dce3Sjkunz } cb_mcast; 9217e4dce3Sjkunz struct { 9311b735f2Stsutsui volatile uint32_t tx_tbd_addr;/* TX Buf. Descr. Addr.*/ 9411b735f2Stsutsui volatile uint16_t tx_tcb_count; /* Len. of opt. data */ 9511b735f2Stsutsui volatile uint16_t tx_pad; 9611b735f2Stsutsui volatile uint8_t tx_dest_addr[6]; /* Dest. Addr. */ 9711b735f2Stsutsui volatile uint16_t tx_length; /* Length of data */ 9811b735f2Stsutsui /* uint8_t data; Data to send, optional */ 9917e4dce3Sjkunz } cb_transmit; 10011b735f2Stsutsui volatile uint32_t cb_tdr; /* Time & Flags from TDR CMD */ 10111b735f2Stsutsui volatile uint32_t cb_dump_addr; /* Address of Dump buffer */ 10217e4dce3Sjkunz }; 103b6a2ef75Sperry } __packed; 10417e4dce3Sjkunz 10517e4dce3Sjkunz 10617e4dce3Sjkunz 10717e4dce3Sjkunz /* Transmit Buffer Descriptor */ 10817e4dce3Sjkunz struct iee_tbd { 10911b735f2Stsutsui volatile uint16_t tbd_size; /* Size of buffer & Flags */ 11011b735f2Stsutsui volatile uint16_t tbd_pad; 11111b735f2Stsutsui volatile uint32_t tbd_link_addr; /* Link Address to next RFD */ 11211b735f2Stsutsui volatile uint32_t tbd_tb_addr; /* Transmit Buffer Address */ 113b6a2ef75Sperry } __packed; 11417e4dce3Sjkunz 11517e4dce3Sjkunz 11617e4dce3Sjkunz 11717e4dce3Sjkunz /* Receive Frame Descriptor */ 11817e4dce3Sjkunz struct iee_rfd { 11911b735f2Stsutsui volatile uint16_t rfd_status; /* Status Bits */ 12011b735f2Stsutsui volatile uint16_t rfd_cmd; /* Command Bits */ 12111b735f2Stsutsui volatile uint32_t rfd_link_addr; /* Link Address to next RFD */ 12211b735f2Stsutsui volatile uint32_t rfd_rbd_addr; /* Address of first free RBD */ 12311b735f2Stsutsui volatile uint16_t rfd_count; /* Actual Count */ 12411b735f2Stsutsui volatile uint16_t rfd_size; /* Size */ 125e5a112d8Sskrll volatile uint8_t rfd_dest_addr[6]; /* Destination Address */ 12611b735f2Stsutsui volatile uint8_t rfd_src_addr[6]; /* Source Address */ 12711b735f2Stsutsui volatile uint16_t rfd_length; /* Length Field */ 12811b735f2Stsutsui volatile uint16_t rfd_pad; /* Optional Data */ 129b6a2ef75Sperry } __packed; 13017e4dce3Sjkunz 13117e4dce3Sjkunz 13217e4dce3Sjkunz 13317e4dce3Sjkunz /* Receive Buffer Descriptor */ 13417e4dce3Sjkunz struct iee_rbd { 13511b735f2Stsutsui volatile uint16_t rbd_count; /* Actual Cont of bytes */ 13611b735f2Stsutsui volatile uint16_t rbd_pad1; 13711b735f2Stsutsui volatile uint32_t rbd_next_rbd; /* Address of Next RBD */ 13811b735f2Stsutsui volatile uint32_t rbd_rb_addr; /* Receive Buffer Address */ 13911b735f2Stsutsui volatile uint16_t rbd_size; /* Size of Receive Buffer */ 14011b735f2Stsutsui volatile uint16_t rbd_pad2; 141b6a2ef75Sperry } __packed; 14217e4dce3Sjkunz 14317e4dce3Sjkunz 14417e4dce3Sjkunz 14517e4dce3Sjkunz #define IEE_NRFD 32 /* Number of RFDs == length of receive queue */ 14617e4dce3Sjkunz #define IEE_NCB 32 /* Number of Command Blocks == transmit queue */ 14717e4dce3Sjkunz #define IEE_NTBD 16 /* Number of TBDs per CB */ 14817e4dce3Sjkunz 14917e4dce3Sjkunz 15017e4dce3Sjkunz 15117e4dce3Sjkunz struct iee_softc { 152a3fc79baStsutsui device_t sc_dev; /* common device data */ 15317e4dce3Sjkunz struct ifmedia sc_ifmedia; /* media interface */ 154e5a112d8Sskrll struct ethercom sc_ethercom; /* ethernet specific stuff */ 15517e4dce3Sjkunz enum i82596_types sc_type; 15617e4dce3Sjkunz bus_dma_tag_t sc_dmat; 15717e4dce3Sjkunz bus_dmamap_t sc_shmem_map; 15817e4dce3Sjkunz bus_dma_segment_t sc_dma_segs; 1590eda417bStsutsui int sc_dma_rsegs; 16017e4dce3Sjkunz bus_dmamap_t sc_rx_map[IEE_NRFD]; 16117e4dce3Sjkunz bus_dmamap_t sc_tx_map[IEE_NCB]; 16217e4dce3Sjkunz struct mbuf *sc_rx_mbuf[IEE_NRFD]; 16317e4dce3Sjkunz struct mbuf *sc_tx_mbuf[IEE_NCB]; 16428eef664Stsutsui uint8_t *sc_shmem_addr; 16517e4dce3Sjkunz int sc_next_cb; 16617e4dce3Sjkunz int sc_next_tbd; 16717e4dce3Sjkunz int sc_rx_done; 16811b735f2Stsutsui uint8_t sc_cf[14]; 16917e4dce3Sjkunz int sc_flags; 17017e4dce3Sjkunz int sc_cl_align; 171f76d0651Stsutsui int sc_scp_off; 172f76d0651Stsutsui int sc_scp_sz; 173f76d0651Stsutsui int sc_iscp_off; 174f76d0651Stsutsui int sc_iscp_sz; 175f76d0651Stsutsui int sc_scb_off; 176f76d0651Stsutsui int sc_scb_sz; 177f76d0651Stsutsui int sc_rfd_off; 178f76d0651Stsutsui int sc_rfd_sz; 179f76d0651Stsutsui int sc_rbd_off; 180f76d0651Stsutsui int sc_rbd_sz; 181f76d0651Stsutsui int sc_cb_off; 182f76d0651Stsutsui int sc_cb_sz; 183f76d0651Stsutsui int sc_tbd_off; 184f76d0651Stsutsui int sc_tbd_sz; 185f76d0651Stsutsui int sc_shmem_sz; 1860eda417bStsutsui uint32_t sc_sysbus; 18711b735f2Stsutsui uint32_t sc_crc_err; 18811b735f2Stsutsui uint32_t sc_align_err; 18911b735f2Stsutsui uint32_t sc_resource_err; 19011b735f2Stsutsui uint32_t sc_overrun_err; 19111b735f2Stsutsui uint32_t sc_rcvcdt_err; 19211b735f2Stsutsui uint32_t sc_short_fr_err; 19311b735f2Stsutsui uint32_t sc_receive_err; 19411b735f2Stsutsui uint32_t sc_tx_col; 19511b735f2Stsutsui uint32_t sc_rx_err; 19611b735f2Stsutsui uint32_t sc_cmd_err; 19711b735f2Stsutsui uint32_t sc_tx_timeout; 19811b735f2Stsutsui uint32_t sc_setup_timeout; 19911b735f2Stsutsui int (*sc_iee_cmd)(struct iee_softc *, uint32_t); 20017e4dce3Sjkunz int (*sc_iee_reset)(struct iee_softc *); 20117e4dce3Sjkunz void (*sc_mediastatus)(struct ifnet *, struct ifmediareq *); 20217e4dce3Sjkunz int (*sc_mediachange)(struct ifnet *); 20317e4dce3Sjkunz }; 20417e4dce3Sjkunz 20517e4dce3Sjkunz 20617e4dce3Sjkunz 20717e4dce3Sjkunz /* Flags */ 20817e4dce3Sjkunz #define IEE_NEED_SWAP 0x01 20917e4dce3Sjkunz #define IEE_WANT_MCAST 0x02 2101ad41325Stsutsui #define IEE_REV_A 0x04 21117e4dce3Sjkunz 2121ad41325Stsutsui /* 2131ad41325Stsutsui * Rev A1 chip doesn't have 32-bit BE mode and all 32 bit pointers are 2141ad41325Stsutsui * treated as two 16-bit big endian entities. 2151ad41325Stsutsui */ 2161ad41325Stsutsui #define IEE_SWAPA32(x) ((sc->sc_flags & (IEE_NEED_SWAP|IEE_REV_A)) == \ 2171ad41325Stsutsui (IEE_NEED_SWAP|IEE_REV_A) ? \ 2181ad41325Stsutsui (((x) << 16) | ((x) >> 16)) : (x)) 2191ad41325Stsutsui /* 2201ad41325Stsutsui * The SCB absolute address and statistical counters are 2211ad41325Stsutsui * always treated as two 16-bit big endian entities 2221ad41325Stsutsui * even in 32-bit BE mode supported by Rev B and C chips. 2231ad41325Stsutsui */ 2241ad41325Stsutsui #define IEE_SWAP32(x) ((sc->sc_flags & IEE_NEED_SWAP) != 0 ? \ 2251ad41325Stsutsui (((x) << 16) | ((x) >> 16)) : (x)) 22611b735f2Stsutsui #define IEE_PHYS_SHMEM(x) ((uint32_t) (sc->sc_shmem_map->dm_segs[0].ds_addr \ 22717e4dce3Sjkunz + (x))) 22817e4dce3Sjkunz 229f76d0651Stsutsui #define SC_SCP(sc) ((struct iee_scp *)((sc)->sc_shmem_addr + \ 230f76d0651Stsutsui (sc)->sc_scp_off)) 231f76d0651Stsutsui #define SC_ISCP(sc) ((struct iee_iscp *)((sc)->sc_shmem_addr + \ 232f76d0651Stsutsui (sc)->sc_iscp_off)) 233f76d0651Stsutsui #define SC_SCB(sc) ((struct iee_scb *)((sc)->sc_shmem_addr + \ 234f76d0651Stsutsui (sc)->sc_scb_off)) 235f76d0651Stsutsui #define SC_RFD(sc, n) ((struct iee_rfd *)((sc)->sc_shmem_addr + \ 236f76d0651Stsutsui (sc)->sc_rfd_off + \ 237f76d0651Stsutsui (n) * (sc)->sc_rfd_sz)) 238f76d0651Stsutsui #define SC_RBD(sc, n) ((struct iee_rbd *)((sc)->sc_shmem_addr + \ 239f76d0651Stsutsui (sc)->sc_rbd_off + \ 240f76d0651Stsutsui (n) * (sc)->sc_rbd_sz)) 241f76d0651Stsutsui #define SC_CB(sc, n) ((struct iee_cb *)((sc)->sc_shmem_addr + \ 242f76d0651Stsutsui (sc)->sc_cb_off + \ 243f76d0651Stsutsui (n) * (sc)->sc_cb_sz)) 244f76d0651Stsutsui #define SC_TBD(sc, n) ((struct iee_tbd *)((sc)->sc_shmem_addr + \ 245f76d0651Stsutsui (sc)->sc_tbd_off + \ 246f76d0651Stsutsui (n) * (sc)->sc_tbd_sz)) 24717e4dce3Sjkunz 248f76d0651Stsutsui #define IEE_SCPSYNC(sc, ops) \ 249f76d0651Stsutsui bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_shmem_map, \ 250f76d0651Stsutsui (sc)->sc_scb_off, (sc)->sc_scp_sz, (ops)) 251f76d0651Stsutsui #define IEE_ISCPSYNC(sc, ops) \ 252f76d0651Stsutsui bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_shmem_map, \ 253f76d0651Stsutsui (sc)->sc_iscp_off, (sc)->sc_iscp_sz, (ops)) 254f76d0651Stsutsui #define IEE_SCBSYNC(sc, ops) \ 255f76d0651Stsutsui bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_shmem_map, \ 256f76d0651Stsutsui (sc)->sc_scb_off, (sc)->sc_scb_sz, (ops)) 257f76d0651Stsutsui #define IEE_RFDSYNC(sc, n, ops) \ 258f76d0651Stsutsui bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_shmem_map, \ 259f76d0651Stsutsui (sc)->sc_rfd_off + (n) * (sc)->sc_rfd_sz, \ 260f76d0651Stsutsui (sc)->sc_rfd_sz, (ops)) 261f76d0651Stsutsui #define IEE_RBDSYNC(sc, n, ops) \ 262f76d0651Stsutsui bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_shmem_map, \ 263f76d0651Stsutsui (sc)->sc_rbd_off + (n) * (sc)->sc_rbd_sz, \ 264f76d0651Stsutsui (sc)->sc_rbd_sz, (ops)) 265f76d0651Stsutsui #define IEE_CBSYNC(sc, n, ops) \ 266f76d0651Stsutsui bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_shmem_map, \ 267f76d0651Stsutsui (sc)->sc_cb_off + (n) * (sc)->sc_cb_sz, \ 268f76d0651Stsutsui (sc)->sc_cb_sz, (ops)) 269f76d0651Stsutsui #define IEE_TBDSYNC(sc, n, ops) \ 270f76d0651Stsutsui bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_shmem_map, \ 271f76d0651Stsutsui (sc)->sc_tbd_off + (n) * (sc)->sc_tbd_sz, \ 272f76d0651Stsutsui (sc)->sc_tbd_sz, (ops)) 27317e4dce3Sjkunz 27411b735f2Stsutsui void iee_attach(struct iee_softc *, uint8_t *, int *, int, int); 27517e4dce3Sjkunz void iee_detach(struct iee_softc *, int); 27617e4dce3Sjkunz int iee_intr(void *); 27717e4dce3Sjkunz 27817e4dce3Sjkunz 27917e4dce3Sjkunz 28017e4dce3Sjkunz 281