[80099c19] | 1 | /*
|
---|
[1c7b0db7] | 2 | * Copyright (c) 2025 Jiri Svoboda
|
---|
[80099c19] | 3 | * Copyright (c) 2009 Lukas Mejdrech
|
---|
| 4 | * Copyright (c) 2011 Martin Decky
|
---|
| 5 | * Copyright (c) 2011 Radim Vansa
|
---|
| 6 | * All rights reserved.
|
---|
| 7 | *
|
---|
| 8 | * Redistribution and use in source and binary forms, with or without
|
---|
| 9 | * modification, are permitted provided that the following conditions
|
---|
| 10 | * are met:
|
---|
| 11 | *
|
---|
| 12 | * - Redistributions of source code must retain the above copyright
|
---|
| 13 | * notice, this list of conditions and the following disclaimer.
|
---|
| 14 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 15 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 16 | * documentation and/or other materials provided with the distribution.
|
---|
| 17 | * - The name of the author may not be used to endorse or promote products
|
---|
| 18 | * derived from this software without specific prior written permission.
|
---|
| 19 | *
|
---|
| 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 21 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 22 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 23 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 24 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 27 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 29 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 30 | */
|
---|
| 31 |
|
---|
| 32 | /*
|
---|
| 33 | * This code is based upon the NE2000 driver for MINIX,
|
---|
| 34 | * distributed according to a BSD-style license.
|
---|
| 35 | *
|
---|
| 36 | * Copyright (c) 1987, 1997, 2006 Vrije Universiteit
|
---|
| 37 | * Copyright (c) 1992, 1994 Philip Homburg
|
---|
| 38 | * Copyright (c) 1996 G. Falzoni
|
---|
| 39 | *
|
---|
| 40 | */
|
---|
| 41 |
|
---|
| 42 | /** @addtogroup drv_ne2k
|
---|
| 43 | * @{
|
---|
| 44 | */
|
---|
| 45 |
|
---|
| 46 | /** @file
|
---|
| 47 | * DP8390 network interface definitions.
|
---|
| 48 | */
|
---|
| 49 |
|
---|
| 50 | #ifndef __NET_NETIF_DP8390_H__
|
---|
| 51 | #define __NET_NETIF_DP8390_H__
|
---|
| 52 |
|
---|
[d51838f] | 53 | #include <async.h>
|
---|
| 54 | #include <ddf/driver.h>
|
---|
[80099c19] | 55 | #include <fibril_synch.h>
|
---|
| 56 | #include <nic.h>
|
---|
| 57 | #include <ddf/interrupt.h>
|
---|
| 58 |
|
---|
| 59 | /** Input/output size */
|
---|
| 60 | #define NE2K_IO_SIZE 0x0020
|
---|
| 61 |
|
---|
| 62 | /* NE2000 implementation. */
|
---|
| 63 |
|
---|
| 64 | /** NE2000 Data Register */
|
---|
| 65 | #define NE2K_DATA 0x0010
|
---|
| 66 |
|
---|
| 67 | /** NE2000 Reset register */
|
---|
| 68 | #define NE2K_RESET 0x001f
|
---|
| 69 |
|
---|
| 70 | /** NE2000 data start */
|
---|
| 71 | #define NE2K_START 0x4000
|
---|
| 72 |
|
---|
| 73 | /** NE2000 data size */
|
---|
| 74 | #define NE2K_SIZE 0x4000
|
---|
| 75 |
|
---|
| 76 | /** NE2000 retry count */
|
---|
| 77 | #define NE2K_RETRY 0x1000
|
---|
| 78 |
|
---|
| 79 | /** NE2000 error messages rate limiting */
|
---|
| 80 | #define NE2K_ERL 10
|
---|
| 81 |
|
---|
| 82 | /** Minimum Ethernet packet size in bytes */
|
---|
| 83 | #define ETH_MIN_PACK_SIZE 60
|
---|
| 84 |
|
---|
| 85 | /** Maximum Ethernet packet size in bytes */
|
---|
| 86 | #define ETH_MAX_PACK_SIZE_TAGGED 1518
|
---|
| 87 |
|
---|
| 88 | /* National Semiconductor DP8390 Network Interface Controller. */
|
---|
| 89 |
|
---|
| 90 | /** Page 0, for reading */
|
---|
| 91 | #define DP_CR 0x00 /**< Command Register */
|
---|
| 92 | #define DP_CLDA0 0x01 /**< Current Local DMA Address 0 */
|
---|
| 93 | #define DP_CLDA1 0x02 /**< Current Local DMA Address 1 */
|
---|
| 94 | #define DP_BNRY 0x03 /**< Boundary Pointer */
|
---|
| 95 | #define DP_TSR 0x04 /**< Transmit Status Register */
|
---|
| 96 | #define DP_NCR 0x05 /**< Number of Collisions Register */
|
---|
| 97 | #define DP_FIFO 0x06 /**< FIFO */
|
---|
| 98 | #define DP_ISR 0x07 /**< Interrupt Status Register */
|
---|
| 99 | #define DP_CRDA0 0x08 /**< Current Remote DMA Address 0 */
|
---|
| 100 | #define DP_CRDA1 0x09 /**< Current Remote DMA Address 1 */
|
---|
| 101 | #define DP_RSR 0x0c /**< Receive Status Register */
|
---|
| 102 | #define DP_CNTR0 0x0d /**< Tally Counter 0 */
|
---|
| 103 | #define DP_CNTR1 0x0e /**< Tally Counter 1 */
|
---|
| 104 | #define DP_CNTR2 0x0f /**< Tally Counter 2 */
|
---|
| 105 |
|
---|
| 106 | /** Page 0, for writing */
|
---|
| 107 | #define DP_PSTART 0x01 /**< Page Start Register*/
|
---|
| 108 | #define DP_PSTOP 0x02 /**< Page Stop Register */
|
---|
| 109 | #define DP_TPSR 0x04 /**< Transmit Page Start Register */
|
---|
| 110 | #define DP_TBCR0 0x05 /**< Transmit Byte Count Register 0 */
|
---|
| 111 | #define DP_TBCR1 0x06 /**< Transmit Byte Count Register 1 */
|
---|
| 112 | #define DP_RSAR0 0x08 /**< Remote Start Address Register 0 */
|
---|
| 113 | #define DP_RSAR1 0x09 /**< Remote Start Address Register 1 */
|
---|
| 114 | #define DP_RBCR0 0x0a /**< Remote Byte Count Register 0 */
|
---|
| 115 | #define DP_RBCR1 0x0b /**< Remote Byte Count Register 1 */
|
---|
| 116 | #define DP_RCR 0x0c /**< Receive Configuration Register */
|
---|
| 117 | #define DP_TCR 0x0d /**< Transmit Configuration Register */
|
---|
| 118 | #define DP_DCR 0x0e /**< Data Configuration Register */
|
---|
| 119 | #define DP_IMR 0x0f /**< Interrupt Mask Register */
|
---|
| 120 |
|
---|
| 121 | /** Page 1, read/write */
|
---|
| 122 | #define DP_PAR0 0x01 /**< Physical Address Register 0 */
|
---|
| 123 | #define DP_PAR1 0x02 /**< Physical Address Register 1 */
|
---|
| 124 | #define DP_PAR2 0x03 /**< Physical Address Register 2 */
|
---|
| 125 | #define DP_PAR3 0x04 /**< Physical Address Register 3 */
|
---|
| 126 | #define DP_PAR4 0x05 /**< Physical Address Register 4 */
|
---|
| 127 | #define DP_PAR5 0x06 /**< Physical Address Register 5 */
|
---|
| 128 | #define DP_CURR 0x07 /**< Current Page Register */
|
---|
| 129 | #define DP_MAR0 0x08 /**< Multicast Address Register 0 */
|
---|
| 130 | #define DP_MAR1 0x09 /**< Multicast Address Register 1 */
|
---|
| 131 | #define DP_MAR2 0x0a /**< Multicast Address Register 2 */
|
---|
| 132 | #define DP_MAR3 0x0b /**< Multicast Address Register 3 */
|
---|
| 133 | #define DP_MAR4 0x0c /**< Multicast Address Register 4 */
|
---|
| 134 | #define DP_MAR5 0x0d /**< Multicast Address Register 5 */
|
---|
| 135 | #define DP_MAR6 0x0e /**< Multicast Address Register 6 */
|
---|
| 136 | #define DP_MAR7 0x0f /**< Multicast Address Register 7 */
|
---|
| 137 |
|
---|
| 138 | /* Bits in Command Register */
|
---|
| 139 | #define CR_STP 0x01 /**< Stop (software reset) */
|
---|
| 140 | #define CR_STA 0x02 /**< Start (activate NIC) */
|
---|
| 141 | #define CR_TXP 0x04 /**< Transmit Packet */
|
---|
| 142 | #define CR_DMA 0x38 /**< Mask for DMA control */
|
---|
| 143 | #define CR_DM_NOP 0x00 /**< DMA: No Operation */
|
---|
| 144 | #define CR_DM_RR 0x08 /**< DMA: Remote Read */
|
---|
| 145 | #define CR_DM_RW 0x10 /**< DMA: Remote Write */
|
---|
| 146 | #define CR_DM_SP 0x18 /**< DMA: Send Packet */
|
---|
| 147 | #define CR_DM_ABORT 0x20 /**< DMA: Abort Remote DMA Operation */
|
---|
| 148 | #define CR_PS 0xc0 /**< Mask for Page Select */
|
---|
| 149 | #define CR_PS_P0 0x00 /**< Register Page 0 */
|
---|
| 150 | #define CR_PS_P1 0x40 /**< Register Page 1 */
|
---|
| 151 | #define CR_PS_P2 0x80 /**< Register Page 2 */
|
---|
| 152 | #define CR_PS_T1 0xc0 /**< Test Mode Register Map */
|
---|
| 153 |
|
---|
| 154 | /* Bits in Interrupt State Register */
|
---|
| 155 | #define ISR_PRX 0x01 /**< Packet Received with no errors */
|
---|
| 156 | #define ISR_PTX 0x02 /**< Packet Transmitted with no errors */
|
---|
| 157 | #define ISR_RXE 0x04 /**< Receive Error */
|
---|
| 158 | #define ISR_TXE 0x08 /**< Transmit Error */
|
---|
| 159 | #define ISR_OVW 0x10 /**< Overwrite Warning */
|
---|
| 160 | #define ISR_CNT 0x20 /**< Counter Overflow */
|
---|
| 161 | #define ISR_RDC 0x40 /**< Remote DMA Complete */
|
---|
| 162 | #define ISR_RST 0x80 /**< Reset Status */
|
---|
| 163 |
|
---|
| 164 | /* Bits in Interrupt Mask Register */
|
---|
| 165 | #define IMR_PRXE 0x01 /**< Packet Received Interrupt Enable */
|
---|
| 166 | #define IMR_PTXE 0x02 /**< Packet Transmitted Interrupt Enable */
|
---|
| 167 | #define IMR_RXEE 0x04 /**< Receive Error Interrupt Enable */
|
---|
| 168 | #define IMR_TXEE 0x08 /**< Transmit Error Interrupt Enable */
|
---|
| 169 | #define IMR_OVWE 0x10 /**< Overwrite Warning Interrupt Enable */
|
---|
| 170 | #define IMR_CNTE 0x20 /**< Counter Overflow Interrupt Enable */
|
---|
| 171 | #define IMR_RDCE 0x40 /**< DMA Complete Interrupt Enable */
|
---|
| 172 |
|
---|
| 173 | /* Bits in Data Configuration Register */
|
---|
| 174 | #define DCR_WTS 0x01 /**< Word Transfer Select */
|
---|
| 175 | #define DCR_BYTEWIDE 0x00 /**< WTS: byte wide transfers */
|
---|
| 176 | #define DCR_WORDWIDE 0x01 /**< WTS: word wide transfers */
|
---|
| 177 | #define DCR_BOS 0x02 /**< Byte Order Select */
|
---|
| 178 | #define DCR_LTLENDIAN 0x00 /**< BOS: Little Endian */
|
---|
| 179 | #define DCR_BIGENDIAN 0x02 /**< BOS: Big Endian */
|
---|
| 180 | #define DCR_LAS 0x04 /**< Long Address Select */
|
---|
| 181 | #define DCR_BMS 0x08 /**< Burst Mode Select */
|
---|
| 182 | #define DCR_AR 0x10 /**< Autoinitialize Remote */
|
---|
| 183 | #define DCR_FTS 0x60 /**< Fifo Threshold Select */
|
---|
| 184 | #define DCR_2BYTES 0x00 /**< 2 bytes */
|
---|
| 185 | #define DCR_4BYTES 0x40 /**< 4 bytes */
|
---|
| 186 | #define DCR_8BYTES 0x20 /**< 8 bytes */
|
---|
| 187 | #define DCR_12BYTES 0x60 /**< 12 bytes */
|
---|
| 188 |
|
---|
| 189 | /* Bits in Transmit Configuration Register */
|
---|
| 190 | #define TCR_CRC 0x01 /**< Inhibit CRC */
|
---|
| 191 | #define TCR_ELC 0x06 /**< Encoded Loopback Control */
|
---|
| 192 | #define TCR_NORMAL 0x00 /**< ELC: Normal Operation */
|
---|
| 193 | #define TCR_INTERNAL 0x02 /**< ELC: Internal Loopback */
|
---|
| 194 | #define TCR_0EXTERNAL 0x04 /**< ELC: External Loopback LPBK=0 */
|
---|
| 195 | #define TCR_1EXTERNAL 0x06 /**< ELC: External Loopback LPBK=1 */
|
---|
| 196 | #define TCR_ATD 0x08 /**< Auto Transmit Disable */
|
---|
| 197 | #define TCR_OFST 0x10 /**< Collision Offset Enable (be nice) */
|
---|
| 198 |
|
---|
| 199 | /* Bits in Interrupt Status Register */
|
---|
| 200 | #define TSR_PTX 0x01 /**< Packet Transmitted (without error) */
|
---|
| 201 | #define TSR_DFR 0x02 /**< Transmit Deferred (reserved) */
|
---|
| 202 | #define TSR_COL 0x04 /**< Transmit Collided */
|
---|
| 203 | #define TSR_ABT 0x08 /**< Transmit Aborted */
|
---|
| 204 | #define TSR_CRS 0x10 /**< Carrier Sense Lost */
|
---|
| 205 | #define TSR_FU 0x20 /**< FIFO Underrun */
|
---|
| 206 | #define TSR_CDH 0x40 /**< CD Heartbeat */
|
---|
| 207 | #define TSR_OWC 0x80 /**< Out of Window Collision */
|
---|
| 208 |
|
---|
| 209 | /* Bits in Receive Configuration Register */
|
---|
| 210 | #define RCR_SEP 0x01 /**< Save Errored Packets */
|
---|
| 211 | #define RCR_AR 0x02 /**< Accept Runt Packets */
|
---|
| 212 | #define RCR_AB 0x04 /**< Accept Broadcast */
|
---|
| 213 | #define RCR_AM 0x08 /**< Accept Multicast */
|
---|
| 214 | #define RCR_PRO 0x10 /**< Physical Promiscuous */
|
---|
| 215 | #define RCR_MON 0x20 /**< Monitor Mode */
|
---|
| 216 |
|
---|
| 217 | /* Bits in Receive Status Register */
|
---|
| 218 | #define RSR_PRX 0x01 /**< Packet Received Intact */
|
---|
| 219 | #define RSR_CRC 0x02 /**< CRC Error */
|
---|
| 220 | #define RSR_FAE 0x04 /**< Frame Alignment Error */
|
---|
| 221 | #define RSR_FO 0x08 /**< FIFO Overrun */
|
---|
| 222 | #define RSR_MPA 0x10 /**< Missed Packet */
|
---|
| 223 | #define RSR_PHY 0x20 /**< Multicast Address Match */
|
---|
| 224 | #define RSR_DIS 0x40 /**< Receiver Disabled */
|
---|
| 225 | #define RSR_DFR 0x80 /**< In later manuals: Deferring */
|
---|
| 226 |
|
---|
| 227 | typedef struct {
|
---|
[d51838f] | 228 | /** DDF device */
|
---|
| 229 | ddf_dev_t *dev;
|
---|
| 230 | /** Parent session */
|
---|
| 231 | async_sess_t *parent_sess;
|
---|
[80099c19] | 232 | /* Device configuration */
|
---|
[d1582b50] | 233 | void *base_port; /**< Port assigned from ISA configuration */
|
---|
[80099c19] | 234 | void *port;
|
---|
| 235 | void *data_port;
|
---|
| 236 | int irq;
|
---|
| 237 | nic_address_t mac;
|
---|
[a35b458] | 238 |
|
---|
[80099c19] | 239 | uint8_t start_page; /**< Ring buffer start page */
|
---|
| 240 | uint8_t stop_page; /**< Ring buffer stop page */
|
---|
[a35b458] | 241 |
|
---|
[80099c19] | 242 | /* Send queue */
|
---|
| 243 | struct {
|
---|
| 244 | bool dirty; /**< Buffer contains a packet */
|
---|
| 245 | size_t size; /**< Packet size */
|
---|
| 246 | uint8_t page; /**< Starting page of the buffer */
|
---|
| 247 | } sq;
|
---|
| 248 | fibril_mutex_t sq_mutex;
|
---|
| 249 | fibril_condvar_t sq_cv;
|
---|
[a35b458] | 250 |
|
---|
[80099c19] | 251 | /* Driver run-time variables */
|
---|
| 252 | bool probed;
|
---|
| 253 | bool up;
|
---|
| 254 |
|
---|
| 255 | /* Irq code with assigned addresses for this device */
|
---|
| 256 | irq_code_t code;
|
---|
| 257 |
|
---|
| 258 | /* Copy of the receive configuration register */
|
---|
| 259 | uint8_t receive_configuration;
|
---|
| 260 |
|
---|
| 261 | /* Device statistics */
|
---|
| 262 | // TODO: shouldn't be these directly in device.h - nic_device_stats?
|
---|
| 263 | uint64_t misses; /**< Receive frame misses */
|
---|
| 264 | uint64_t underruns; /**< FIFO underruns */
|
---|
| 265 | uint64_t overruns; /**< FIFO overruns */
|
---|
| 266 | } ne2k_t;
|
---|
| 267 |
|
---|
[b7fd2a0] | 268 | extern errno_t ne2k_probe(ne2k_t *);
|
---|
| 269 | extern errno_t ne2k_up(ne2k_t *);
|
---|
[1c7b0db7] | 270 | extern void ne2k_quiesce(ne2k_t *);
|
---|
[80099c19] | 271 | extern void ne2k_down(ne2k_t *);
|
---|
[6d8455d] | 272 | extern void ne2k_send(nic_t *, void *, size_t);
|
---|
[80099c19] | 273 | extern void ne2k_interrupt(nic_t *, uint8_t, uint8_t);
|
---|
| 274 |
|
---|
| 275 | extern void ne2k_set_accept_mcast(ne2k_t *, int);
|
---|
| 276 | extern void ne2k_set_accept_bcast(ne2k_t *, int);
|
---|
| 277 | extern void ne2k_set_promisc_phys(ne2k_t *, int);
|
---|
| 278 | extern void ne2k_set_mcast_hash(ne2k_t *, uint64_t);
|
---|
| 279 | extern void ne2k_set_physical_address(ne2k_t *, const nic_address_t *address);
|
---|
| 280 |
|
---|
| 281 | #endif
|
---|
| 282 |
|
---|
| 283 | /** @}
|
---|
| 284 | */
|
---|