1 1.16 andvar /* $NetBSD: i82596var.h,v 1.16 2025/02/26 05:03:55 andvar Exp $ */ 2 1.1 jkunz 3 1.1 jkunz /* 4 1.1 jkunz * Copyright (c) 2003 Jochen Kunz. 5 1.1 jkunz * All rights reserved. 6 1.1 jkunz * 7 1.1 jkunz * Redistribution and use in source and binary forms, with or without 8 1.1 jkunz * modification, are permitted provided that the following conditions 9 1.1 jkunz * are met: 10 1.1 jkunz * 1. Redistributions of source code must retain the above copyright 11 1.1 jkunz * notice, this list of conditions and the following disclaimer. 12 1.1 jkunz * 2. Redistributions in binary form must reproduce the above copyright 13 1.1 jkunz * notice, this list of conditions and the following disclaimer in the 14 1.1 jkunz * documentation and/or other materials provided with the distribution. 15 1.1 jkunz * 3. The name of Jochen Kunz may not be used to endorse or promote 16 1.1 jkunz * products derived from this software without specific prior 17 1.1 jkunz * written permission. 18 1.1 jkunz * 19 1.1 jkunz * THIS SOFTWARE IS PROVIDED BY JOCHEN KUNZ 20 1.1 jkunz * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 1.1 jkunz * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 1.1 jkunz * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JOCHEN KUNZ 23 1.1 jkunz * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 1.1 jkunz * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 1.1 jkunz * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 1.1 jkunz * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 1.1 jkunz * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 1.1 jkunz * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 1.1 jkunz * POSSIBILITY OF SUCH DAMAGE. 30 1.1 jkunz */ 31 1.1 jkunz 32 1.1 jkunz /* All definitions are for a Intel 82596 DX/SX / CA in linear 32 bit mode. */ 33 1.1 jkunz 34 1.1 jkunz 35 1.1 jkunz 36 1.1 jkunz /* Supported chip variants */ 37 1.4 skrll extern const char *i82596_typenames[]; 38 1.1 jkunz enum i82596_types { I82596_UNKNOWN, I82596_DX, I82596_CA }; 39 1.1 jkunz 40 1.1 jkunz 41 1.1 jkunz 42 1.1 jkunz /* System Configuration Pointer */ 43 1.1 jkunz struct iee_scp { 44 1.3 tsutsui volatile uint16_t scp_pad1; 45 1.3 tsutsui volatile uint16_t scp_sysbus; /* Sysbus Byte */ 46 1.3 tsutsui volatile uint32_t scp_pad2; 47 1.3 tsutsui volatile uint32_t scp_iscp_addr; /* Int. Sys. Conf. Pointer */ 48 1.9 perry } __packed; 49 1.1 jkunz 50 1.1 jkunz 51 1.1 jkunz 52 1.1 jkunz /* Intermediate System Configuration Pointer */ 53 1.1 jkunz struct iee_iscp { 54 1.15 skrll volatile uint16_t iscp_busy; /* Even Word, bits 0..15 */ 55 1.3 tsutsui volatile uint16_t iscp_pad; /* Odd Word, bits 16..32 */ 56 1.3 tsutsui volatile uint32_t iscp_scb_addr; /* address of SCB */ 57 1.9 perry } __packed; 58 1.1 jkunz 59 1.1 jkunz 60 1.1 jkunz 61 1.1 jkunz /* System Control Block */ 62 1.1 jkunz struct iee_scb { 63 1.3 tsutsui volatile uint16_t scb_status; /* Status Bits */ 64 1.3 tsutsui volatile uint16_t scb_cmd; /* Command Bits */ 65 1.3 tsutsui volatile uint32_t scb_cmd_blk_addr; /* Command Block Address */ 66 1.3 tsutsui volatile uint32_t scb_rfa_addr; /* Receive Frame Area Address */ 67 1.3 tsutsui volatile uint32_t scb_crc_err; /* CRC Errors */ 68 1.3 tsutsui volatile uint32_t scb_align_err; /* Alignment Errors */ 69 1.3 tsutsui volatile uint32_t scb_resource_err; /* Resource Errors [1] */ 70 1.3 tsutsui volatile uint32_t scb_overrun_err; /* Overrun Errors [1] */ 71 1.3 tsutsui volatile uint32_t scb_rcvcdt_err; /* RCVCDT Errors [1] */ 72 1.3 tsutsui volatile uint32_t scb_short_fr_err; /* Short Frame Errors */ 73 1.3 tsutsui volatile uint16_t scb_tt_off; /* Bus Throtle Off Timer */ 74 1.3 tsutsui volatile uint16_t scb_tt_on; /* Bus Throtle On Timer */ 75 1.9 perry } __packed; 76 1.1 jkunz /* [1] In MONITOR mode these counters change function. */ 77 1.1 jkunz 78 1.1 jkunz 79 1.1 jkunz 80 1.1 jkunz /* Command Block */ 81 1.1 jkunz struct iee_cb { 82 1.3 tsutsui volatile uint16_t cb_status; /* Status Bits */ 83 1.3 tsutsui volatile uint16_t cb_cmd; /* Command Bits */ 84 1.3 tsutsui volatile uint32_t cb_link_addr; /* Link Address to next CMD */ 85 1.1 jkunz union { 86 1.3 tsutsui volatile uint8_t cb_ind_addr[8];/* Individual Address */ 87 1.3 tsutsui volatile uint8_t cb_cf[16]; /* Configuration Bytes */ 88 1.1 jkunz struct { 89 1.3 tsutsui volatile uint16_t mc_size;/* Num bytes of Mcast Addr.*/ 90 1.3 tsutsui volatile uint8_t mc_addrs[6]; /* List of Mcast Addr. */ 91 1.1 jkunz } cb_mcast; 92 1.1 jkunz struct { 93 1.3 tsutsui volatile uint32_t tx_tbd_addr;/* TX Buf. Descr. Addr.*/ 94 1.3 tsutsui volatile uint16_t tx_tcb_count; /* Len. of opt. data */ 95 1.3 tsutsui volatile uint16_t tx_pad; 96 1.3 tsutsui volatile uint8_t tx_dest_addr[6]; /* Dest. Addr. */ 97 1.3 tsutsui volatile uint16_t tx_length; /* Length of data */ 98 1.3 tsutsui /* uint8_t data; Data to send, optional */ 99 1.1 jkunz } cb_transmit; 100 1.3 tsutsui volatile uint32_t cb_tdr; /* Time & Flags from TDR CMD */ 101 1.3 tsutsui volatile uint32_t cb_dump_addr; /* Address of Dump buffer */ 102 1.1 jkunz }; 103 1.9 perry } __packed; 104 1.1 jkunz 105 1.1 jkunz 106 1.1 jkunz 107 1.1 jkunz /* Transmit Buffer Descriptor */ 108 1.1 jkunz struct iee_tbd { 109 1.3 tsutsui volatile uint16_t tbd_size; /* Size of buffer & Flags */ 110 1.3 tsutsui volatile uint16_t tbd_pad; 111 1.3 tsutsui volatile uint32_t tbd_link_addr; /* Link Address to next RFD */ 112 1.3 tsutsui volatile uint32_t tbd_tb_addr; /* Transmit Buffer Address */ 113 1.9 perry } __packed; 114 1.1 jkunz 115 1.1 jkunz 116 1.1 jkunz 117 1.1 jkunz /* Receive Frame Descriptor */ 118 1.1 jkunz struct iee_rfd { 119 1.3 tsutsui volatile uint16_t rfd_status; /* Status Bits */ 120 1.3 tsutsui volatile uint16_t rfd_cmd; /* Command Bits */ 121 1.3 tsutsui volatile uint32_t rfd_link_addr; /* Link Address to next RFD */ 122 1.3 tsutsui volatile uint32_t rfd_rbd_addr; /* Address of first free RBD */ 123 1.3 tsutsui volatile uint16_t rfd_count; /* Actual Count */ 124 1.3 tsutsui volatile uint16_t rfd_size; /* Size */ 125 1.6 skrll volatile uint8_t rfd_dest_addr[6]; /* Destination Address */ 126 1.3 tsutsui volatile uint8_t rfd_src_addr[6]; /* Source Address */ 127 1.3 tsutsui volatile uint16_t rfd_length; /* Length Field */ 128 1.3 tsutsui volatile uint16_t rfd_pad; /* Optional Data */ 129 1.9 perry } __packed; 130 1.1 jkunz 131 1.1 jkunz 132 1.1 jkunz 133 1.1 jkunz /* Receive Buffer Descriptor */ 134 1.1 jkunz struct iee_rbd { 135 1.16 andvar volatile uint16_t rbd_count; /* Actual Count of bytes */ 136 1.3 tsutsui volatile uint16_t rbd_pad1; 137 1.3 tsutsui volatile uint32_t rbd_next_rbd; /* Address of Next RBD */ 138 1.3 tsutsui volatile uint32_t rbd_rb_addr; /* Receive Buffer Address */ 139 1.3 tsutsui volatile uint16_t rbd_size; /* Size of Receive Buffer */ 140 1.3 tsutsui volatile uint16_t rbd_pad2; 141 1.9 perry } __packed; 142 1.1 jkunz 143 1.1 jkunz 144 1.1 jkunz 145 1.1 jkunz #define IEE_NRFD 32 /* Number of RFDs == length of receive queue */ 146 1.1 jkunz #define IEE_NCB 32 /* Number of Command Blocks == transmit queue */ 147 1.1 jkunz #define IEE_NTBD 16 /* Number of TBDs per CB */ 148 1.1 jkunz 149 1.1 jkunz 150 1.1 jkunz 151 1.1 jkunz struct iee_softc { 152 1.10 tsutsui device_t sc_dev; /* common device data */ 153 1.1 jkunz struct ifmedia sc_ifmedia; /* media interface */ 154 1.6 skrll struct ethercom sc_ethercom; /* ethernet specific stuff */ 155 1.1 jkunz enum i82596_types sc_type; 156 1.1 jkunz bus_dma_tag_t sc_dmat; 157 1.1 jkunz bus_dmamap_t sc_shmem_map; 158 1.1 jkunz bus_dma_segment_t sc_dma_segs; 159 1.12 tsutsui int sc_dma_rsegs; 160 1.1 jkunz bus_dmamap_t sc_rx_map[IEE_NRFD]; 161 1.1 jkunz bus_dmamap_t sc_tx_map[IEE_NCB]; 162 1.1 jkunz struct mbuf *sc_rx_mbuf[IEE_NRFD]; 163 1.1 jkunz struct mbuf *sc_tx_mbuf[IEE_NCB]; 164 1.8 tsutsui uint8_t *sc_shmem_addr; 165 1.1 jkunz int sc_next_cb; 166 1.1 jkunz int sc_next_tbd; 167 1.1 jkunz int sc_rx_done; 168 1.3 tsutsui uint8_t sc_cf[14]; 169 1.1 jkunz int sc_flags; 170 1.1 jkunz int sc_cl_align; 171 1.14 tsutsui int sc_scp_off; 172 1.14 tsutsui int sc_scp_sz; 173 1.14 tsutsui int sc_iscp_off; 174 1.14 tsutsui int sc_iscp_sz; 175 1.14 tsutsui int sc_scb_off; 176 1.14 tsutsui int sc_scb_sz; 177 1.14 tsutsui int sc_rfd_off; 178 1.14 tsutsui int sc_rfd_sz; 179 1.14 tsutsui int sc_rbd_off; 180 1.14 tsutsui int sc_rbd_sz; 181 1.14 tsutsui int sc_cb_off; 182 1.14 tsutsui int sc_cb_sz; 183 1.14 tsutsui int sc_tbd_off; 184 1.14 tsutsui int sc_tbd_sz; 185 1.14 tsutsui int sc_shmem_sz; 186 1.12 tsutsui uint32_t sc_sysbus; 187 1.3 tsutsui uint32_t sc_crc_err; 188 1.3 tsutsui uint32_t sc_align_err; 189 1.3 tsutsui uint32_t sc_resource_err; 190 1.3 tsutsui uint32_t sc_overrun_err; 191 1.3 tsutsui uint32_t sc_rcvcdt_err; 192 1.3 tsutsui uint32_t sc_short_fr_err; 193 1.3 tsutsui uint32_t sc_receive_err; 194 1.3 tsutsui uint32_t sc_tx_col; 195 1.3 tsutsui uint32_t sc_rx_err; 196 1.3 tsutsui uint32_t sc_cmd_err; 197 1.3 tsutsui uint32_t sc_tx_timeout; 198 1.3 tsutsui uint32_t sc_setup_timeout; 199 1.3 tsutsui int (*sc_iee_cmd)(struct iee_softc *, uint32_t); 200 1.1 jkunz int (*sc_iee_reset)(struct iee_softc *); 201 1.1 jkunz void (*sc_mediastatus)(struct ifnet *, struct ifmediareq *); 202 1.1 jkunz int (*sc_mediachange)(struct ifnet *); 203 1.1 jkunz }; 204 1.1 jkunz 205 1.1 jkunz 206 1.1 jkunz 207 1.1 jkunz /* Flags */ 208 1.1 jkunz #define IEE_NEED_SWAP 0x01 209 1.11 tsutsui #define IEE_WANT_MCAST 0x02 210 1.11 tsutsui #define IEE_REV_A 0x04 211 1.1 jkunz 212 1.11 tsutsui /* 213 1.11 tsutsui * Rev A1 chip doesn't have 32-bit BE mode and all 32 bit pointers are 214 1.11 tsutsui * treated as two 16-bit big endian entities. 215 1.11 tsutsui */ 216 1.11 tsutsui #define IEE_SWAPA32(x) ((sc->sc_flags & (IEE_NEED_SWAP|IEE_REV_A)) == \ 217 1.11 tsutsui (IEE_NEED_SWAP|IEE_REV_A) ? \ 218 1.11 tsutsui (((x) << 16) | ((x) >> 16)) : (x)) 219 1.11 tsutsui /* 220 1.11 tsutsui * The SCB absolute address and statistical counters are 221 1.11 tsutsui * always treated as two 16-bit big endian entities 222 1.11 tsutsui * even in 32-bit BE mode supported by Rev B and C chips. 223 1.11 tsutsui */ 224 1.11 tsutsui #define IEE_SWAP32(x) ((sc->sc_flags & IEE_NEED_SWAP) != 0 ? \ 225 1.11 tsutsui (((x) << 16) | ((x) >> 16)) : (x)) 226 1.3 tsutsui #define IEE_PHYS_SHMEM(x) ((uint32_t) (sc->sc_shmem_map->dm_segs[0].ds_addr \ 227 1.1 jkunz + (x))) 228 1.1 jkunz 229 1.14 tsutsui #define SC_SCP(sc) ((struct iee_scp *)((sc)->sc_shmem_addr + \ 230 1.14 tsutsui (sc)->sc_scp_off)) 231 1.14 tsutsui #define SC_ISCP(sc) ((struct iee_iscp *)((sc)->sc_shmem_addr + \ 232 1.14 tsutsui (sc)->sc_iscp_off)) 233 1.14 tsutsui #define SC_SCB(sc) ((struct iee_scb *)((sc)->sc_shmem_addr + \ 234 1.14 tsutsui (sc)->sc_scb_off)) 235 1.14 tsutsui #define SC_RFD(sc, n) ((struct iee_rfd *)((sc)->sc_shmem_addr + \ 236 1.14 tsutsui (sc)->sc_rfd_off + \ 237 1.14 tsutsui (n) * (sc)->sc_rfd_sz)) 238 1.14 tsutsui #define SC_RBD(sc, n) ((struct iee_rbd *)((sc)->sc_shmem_addr + \ 239 1.14 tsutsui (sc)->sc_rbd_off + \ 240 1.14 tsutsui (n) * (sc)->sc_rbd_sz)) 241 1.14 tsutsui #define SC_CB(sc, n) ((struct iee_cb *)((sc)->sc_shmem_addr + \ 242 1.14 tsutsui (sc)->sc_cb_off + \ 243 1.14 tsutsui (n) * (sc)->sc_cb_sz)) 244 1.14 tsutsui #define SC_TBD(sc, n) ((struct iee_tbd *)((sc)->sc_shmem_addr + \ 245 1.14 tsutsui (sc)->sc_tbd_off + \ 246 1.14 tsutsui (n) * (sc)->sc_tbd_sz)) 247 1.14 tsutsui 248 1.14 tsutsui #define IEE_SCPSYNC(sc, ops) \ 249 1.14 tsutsui bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_shmem_map, \ 250 1.14 tsutsui (sc)->sc_scb_off, (sc)->sc_scp_sz, (ops)) 251 1.14 tsutsui #define IEE_ISCPSYNC(sc, ops) \ 252 1.14 tsutsui bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_shmem_map, \ 253 1.14 tsutsui (sc)->sc_iscp_off, (sc)->sc_iscp_sz, (ops)) 254 1.14 tsutsui #define IEE_SCBSYNC(sc, ops) \ 255 1.14 tsutsui bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_shmem_map, \ 256 1.14 tsutsui (sc)->sc_scb_off, (sc)->sc_scb_sz, (ops)) 257 1.14 tsutsui #define IEE_RFDSYNC(sc, n, ops) \ 258 1.14 tsutsui bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_shmem_map, \ 259 1.14 tsutsui (sc)->sc_rfd_off + (n) * (sc)->sc_rfd_sz, \ 260 1.14 tsutsui (sc)->sc_rfd_sz, (ops)) 261 1.14 tsutsui #define IEE_RBDSYNC(sc, n, ops) \ 262 1.14 tsutsui bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_shmem_map, \ 263 1.14 tsutsui (sc)->sc_rbd_off + (n) * (sc)->sc_rbd_sz, \ 264 1.14 tsutsui (sc)->sc_rbd_sz, (ops)) 265 1.14 tsutsui #define IEE_CBSYNC(sc, n, ops) \ 266 1.14 tsutsui bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_shmem_map, \ 267 1.14 tsutsui (sc)->sc_cb_off + (n) * (sc)->sc_cb_sz, \ 268 1.14 tsutsui (sc)->sc_cb_sz, (ops)) 269 1.14 tsutsui #define IEE_TBDSYNC(sc, n, ops) \ 270 1.14 tsutsui bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_shmem_map, \ 271 1.14 tsutsui (sc)->sc_tbd_off + (n) * (sc)->sc_tbd_sz, \ 272 1.14 tsutsui (sc)->sc_tbd_sz, (ops)) 273 1.1 jkunz 274 1.3 tsutsui void iee_attach(struct iee_softc *, uint8_t *, int *, int, int); 275 1.1 jkunz void iee_detach(struct iee_softc *, int); 276 1.1 jkunz int iee_intr(void *); 277 1.1 jkunz 278 1.1 jkunz 279 1.1 jkunz 280 1.1 jkunz 281