1 | /*
|
---|
2 | * Copyright (c) 2009 Lukas Mejdrech
|
---|
3 | * Copyright (c) 2011 Martin Decky
|
---|
4 | * All rights reserved.
|
---|
5 | *
|
---|
6 | * Redistribution and use in source and binary forms, with or without
|
---|
7 | * modification, are permitted provided that the following conditions
|
---|
8 | * are met:
|
---|
9 | *
|
---|
10 | * - Redistributions of source code must retain the above copyright
|
---|
11 | * notice, this list of conditions and the following disclaimer.
|
---|
12 | * - Redistributions in binary form must reproduce the above copyright
|
---|
13 | * notice, this list of conditions and the following disclaimer in the
|
---|
14 | * documentation and/or other materials provided with the distribution.
|
---|
15 | * - The name of the author may not be used to endorse or promote products
|
---|
16 | * derived from this software without specific prior written permission.
|
---|
17 | *
|
---|
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
28 | */
|
---|
29 |
|
---|
30 | /*
|
---|
31 | * This code is based upon the NE2000 driver for MINIX,
|
---|
32 | * distributed according to a BSD-style license.
|
---|
33 | *
|
---|
34 | * Copyright (c) 1987, 1997, 2006 Vrije Universiteit
|
---|
35 | * Copyright (c) 1992, 1994 Philip Homburg
|
---|
36 | * Copyright (c) 1996 G. Falzoni
|
---|
37 | *
|
---|
38 | */
|
---|
39 |
|
---|
40 | /** @addtogroup dp8390
|
---|
41 | * @{
|
---|
42 | */
|
---|
43 |
|
---|
44 | /** @file
|
---|
45 | * DP8390 network interface definitions.
|
---|
46 | */
|
---|
47 |
|
---|
48 | #ifndef __NET_NETIF_DP8390_H__
|
---|
49 | #define __NET_NETIF_DP8390_H__
|
---|
50 |
|
---|
51 | #include <net/packet.h>
|
---|
52 | #include "dp8390_port.h"
|
---|
53 |
|
---|
54 | /** Input/output size */
|
---|
55 | #define DP8390_IO_SIZE 0x0020
|
---|
56 |
|
---|
57 | /* National Semiconductor DP8390 Network Interface Controller. */
|
---|
58 |
|
---|
59 | /** Page 0, for reading */
|
---|
60 | #define DP_CR 0x00 /**< Command Register */
|
---|
61 | #define DP_CLDA0 0x01 /**< Current Local DMA Address 0 */
|
---|
62 | #define DP_CLDA1 0x02 /**< Current Local DMA Address 1 */
|
---|
63 | #define DP_BNRY 0x03 /**< Boundary Pointer */
|
---|
64 | #define DP_TSR 0x04 /**< Transmit Status Register */
|
---|
65 | #define DP_NCR 0x05 /**< Number of Collisions Register */
|
---|
66 | #define DP_FIFO 0x06 /**< FIFO */
|
---|
67 | #define DP_ISR 0x07 /**< Interrupt Status Register */
|
---|
68 | #define DP_CRDA0 0x08 /**< Current Remote DMA Address 0 */
|
---|
69 | #define DP_CRDA1 0x09 /**< Current Remote DMA Address 1 */
|
---|
70 | #define DP_RSR 0x0c /**< Receive Status Register */
|
---|
71 | #define DP_CNTR0 0x0d /**< Tally Counter 0 */
|
---|
72 | #define DP_CNTR1 0x0e /**< Tally Counter 1 */
|
---|
73 | #define DP_CNTR2 0x0f /**< Tally Counter 2 */
|
---|
74 |
|
---|
75 | /** Page 0, for writing */
|
---|
76 | #define DP_PSTART 0x01 /**< Page Start Register*/
|
---|
77 | #define DP_PSTOP 0x02 /**< Page Stop Register */
|
---|
78 | #define DP_TPSR 0x04 /**< Transmit Page Start Register */
|
---|
79 | #define DP_TBCR0 0x05 /**< Transmit Byte Count Register 0 */
|
---|
80 | #define DP_TBCR1 0x06 /**< Transmit Byte Count Register 1 */
|
---|
81 | #define DP_RSAR0 0x08 /**< Remote Start Address Register 0 */
|
---|
82 | #define DP_RSAR1 0x09 /**< Remote Start Address Register 1 */
|
---|
83 | #define DP_RBCR0 0x0a /**< Remote Byte Count Register 0 */
|
---|
84 | #define DP_RBCR1 0x0b /**< Remote Byte Count Register 1 */
|
---|
85 | #define DP_RCR 0x0c /**< Receive Configuration Register */
|
---|
86 | #define DP_TCR 0x0d /**< Transmit Configuration Register */
|
---|
87 | #define DP_DCR 0x0e /**< Data Configuration Register */
|
---|
88 | #define DP_IMR 0x0f /**< Interrupt Mask Register */
|
---|
89 |
|
---|
90 | /** Page 1, read/write */
|
---|
91 | #define DP_PAR0 0x01 /**< Physical Address Register 0 */
|
---|
92 | #define DP_PAR1 0x02 /**< Physical Address Register 1 */
|
---|
93 | #define DP_PAR2 0x03 /**< Physical Address Register 2 */
|
---|
94 | #define DP_PAR3 0x04 /**< Physical Address Register 3 */
|
---|
95 | #define DP_PAR4 0x05 /**< Physical Address Register 4 */
|
---|
96 | #define DP_PAR5 0x06 /**< Physical Address Register 5 */
|
---|
97 | #define DP_CURR 0x07 /**< Current Page Register */
|
---|
98 | #define DP_MAR0 0x08 /**< Multicast Address Register 0 */
|
---|
99 | #define DP_MAR1 0x09 /**< Multicast Address Register 1 */
|
---|
100 | #define DP_MAR2 0x0a /**< Multicast Address Register 2 */
|
---|
101 | #define DP_MAR3 0x0b /**< Multicast Address Register 3 */
|
---|
102 | #define DP_MAR4 0x0c /**< Multicast Address Register 4 */
|
---|
103 | #define DP_MAR5 0x0d /**< Multicast Address Register 5 */
|
---|
104 | #define DP_MAR6 0x0e /**< Multicast Address Register 6 */
|
---|
105 | #define DP_MAR7 0x0f /**< Multicast Address Register 7 */
|
---|
106 |
|
---|
107 | /* Bits in dp_cr */
|
---|
108 | #define CR_STP 0x01 /* Stop: software reset */
|
---|
109 | #define CR_STA 0x02 /* Start: activate NIC */
|
---|
110 | #define CR_TXP 0x04 /* Transmit Packet */
|
---|
111 | #define CR_DMA 0x38 /* Mask for DMA control */
|
---|
112 | #define CR_DM_NOP 0x00 /* DMA: No Operation */
|
---|
113 | #define CR_DM_RR 0x08 /* DMA: Remote Read */
|
---|
114 | #define CR_DM_RW 0x10 /* DMA: Remote Write */
|
---|
115 | #define CR_DM_SP 0x18 /* DMA: Send Packet */
|
---|
116 | #define CR_DM_ABORT 0x20 /* DMA: Abort Remote DMA Operation */
|
---|
117 | #define CR_PS 0xC0 /* Mask for Page Select */
|
---|
118 | #define CR_PS_P0 0x00 /* Register Page 0 */
|
---|
119 | #define CR_PS_P1 0x40 /* Register Page 1 */
|
---|
120 | #define CR_PS_P2 0x80 /* Register Page 2 */
|
---|
121 | #define CR_PS_T1 0xC0 /* Test Mode Register Map */
|
---|
122 |
|
---|
123 | /* Bits in dp_isr */
|
---|
124 | #define ISR_PRX 0x01 /* Packet Received with no errors */
|
---|
125 | #define ISR_PTX 0x02 /* Packet Transmitted with no errors */
|
---|
126 | #define ISR_RXE 0x04 /* Receive Error */
|
---|
127 | #define ISR_TXE 0x08 /* Transmit Error */
|
---|
128 | #define ISR_OVW 0x10 /* Overwrite Warning */
|
---|
129 | #define ISR_CNT 0x20 /* Counter Overflow */
|
---|
130 | #define ISR_RDC 0x40 /* Remote DMA Complete */
|
---|
131 | #define ISR_RST 0x80 /* Reset Status */
|
---|
132 |
|
---|
133 | /* Bits in dp_imr */
|
---|
134 | #define IMR_PRXE 0x01 /* Packet Received iEnable */
|
---|
135 | #define IMR_PTXE 0x02 /* Packet Transmitted iEnable */
|
---|
136 | #define IMR_RXEE 0x04 /* Receive Error iEnable */
|
---|
137 | #define IMR_TXEE 0x08 /* Transmit Error iEnable */
|
---|
138 | #define IMR_OVWE 0x10 /* Overwrite Warning iEnable */
|
---|
139 | #define IMR_CNTE 0x20 /* Counter Overflow iEnable */
|
---|
140 | #define IMR_RDCE 0x40 /* DMA Complete iEnable */
|
---|
141 |
|
---|
142 | /* Bits in dp_dcr */
|
---|
143 | #define DCR_WTS 0x01 /* Word Transfer Select */
|
---|
144 | #define DCR_BYTEWIDE 0x00 /* WTS: byte wide transfers */
|
---|
145 | #define DCR_WORDWIDE 0x01 /* WTS: word wide transfers */
|
---|
146 | #define DCR_BOS 0x02 /* Byte Order Select */
|
---|
147 | #define DCR_LTLENDIAN 0x00 /* BOS: Little Endian */
|
---|
148 | #define DCR_BIGENDIAN 0x02 /* BOS: Big Endian */
|
---|
149 | #define DCR_LAS 0x04 /* Long Address Select */
|
---|
150 | #define DCR_BMS 0x08 /* Burst Mode Select
|
---|
151 | * Called Loopback Select (LS) in
|
---|
152 | * later manuals. Should be set. */
|
---|
153 | #define DCR_AR 0x10 /* Autoinitialize Remote */
|
---|
154 | #define DCR_FTS 0x60 /* Fifo Threshold Select */
|
---|
155 | #define DCR_2BYTES 0x00 /* 2 bytes */
|
---|
156 | #define DCR_4BYTES 0x40 /* 4 bytes */
|
---|
157 | #define DCR_8BYTES 0x20 /* 8 bytes */
|
---|
158 | #define DCR_12BYTES 0x60 /* 12 bytes */
|
---|
159 |
|
---|
160 | /* Bits in dp_tcr */
|
---|
161 | #define TCR_CRC 0x01 /* Inhibit CRC */
|
---|
162 | #define TCR_ELC 0x06 /* Encoded Loopback Control */
|
---|
163 | #define TCR_NORMAL 0x00 /* ELC: Normal Operation */
|
---|
164 | #define TCR_INTERNAL 0x02 /* ELC: Internal Loopback */
|
---|
165 | #define TCR_0EXTERNAL 0x04 /* ELC: External Loopback LPBK=0 */
|
---|
166 | #define TCR_1EXTERNAL 0x06 /* ELC: External Loopback LPBK=1 */
|
---|
167 | #define TCR_ATD 0x08 /* Auto Transmit Disable */
|
---|
168 | #define TCR_OFST 0x10 /* Collision Offset Enable (be nice) */
|
---|
169 |
|
---|
170 | /* Bits in dp_tsr */
|
---|
171 | #define TSR_PTX 0x01 /* Packet Transmitted (without error)*/
|
---|
172 | #define TSR_DFR 0x02 /* Transmit Deferred, reserved in
|
---|
173 | * later manuals. */
|
---|
174 | #define TSR_COL 0x04 /* Transmit Collided */
|
---|
175 | #define TSR_ABT 0x08 /* Transmit Aborted */
|
---|
176 | #define TSR_CRS 0x10 /* Carrier Sense Lost */
|
---|
177 | #define TSR_FU 0x20 /* FIFO Underrun */
|
---|
178 | #define TSR_CDH 0x40 /* CD Heartbeat */
|
---|
179 | #define TSR_OWC 0x80 /* Out of Window Collision */
|
---|
180 |
|
---|
181 | /* Bits in tp_rcr */
|
---|
182 | #define RCR_SEP 0x01 /* Save Errored Packets */
|
---|
183 | #define RCR_AR 0x02 /* Accept Runt Packets */
|
---|
184 | #define RCR_AB 0x04 /* Accept Broadcast */
|
---|
185 | #define RCR_AM 0x08 /* Accept Multicast */
|
---|
186 | #define RCR_PRO 0x10 /* Physical Promiscuous */
|
---|
187 | #define RCR_MON 0x20 /* Monitor Mode */
|
---|
188 |
|
---|
189 | /* Bits in dp_rsr */
|
---|
190 | #define RSR_PRX 0x01 /* Packet Received Intact */
|
---|
191 | #define RSR_CRC 0x02 /* CRC Error */
|
---|
192 | #define RSR_FAE 0x04 /* Frame Alignment Error */
|
---|
193 | #define RSR_FO 0x08 /* FIFO Overrun */
|
---|
194 | #define RSR_MPA 0x10 /* Missed Packet */
|
---|
195 | #define RSR_PHY 0x20 /* Multicast Address Match */
|
---|
196 | #define RSR_DIS 0x40 /* Receiver Disabled */
|
---|
197 | #define RSR_DFR 0x80 /* In later manuals: Deferring */
|
---|
198 |
|
---|
199 | /** Type definition of the receive header
|
---|
200 | *
|
---|
201 | */
|
---|
202 | typedef struct dp_rcvhdr {
|
---|
203 | /** Copy of rsr */
|
---|
204 | uint8_t dr_status;
|
---|
205 |
|
---|
206 | /** Pointer to next packet */
|
---|
207 | uint8_t dr_next;
|
---|
208 |
|
---|
209 | /** Receive Byte Count Low */
|
---|
210 | uint8_t dr_rbcl;
|
---|
211 |
|
---|
212 | /** Receive Byte Count High */
|
---|
213 | uint8_t dr_rbch;
|
---|
214 | } dp_rcvhdr_t;
|
---|
215 |
|
---|
216 | /** Page size */
|
---|
217 | #define DP_PAGESIZE 256
|
---|
218 |
|
---|
219 | /** Read 1 byte from the zero page register.
|
---|
220 | * @param[in] dep The network interface structure.
|
---|
221 | * @param[in] reg The register offset.
|
---|
222 | * @returns The read value.
|
---|
223 | */
|
---|
224 | #define inb_reg0(dep, reg) (inb(dep->de_dp8390_port + reg))
|
---|
225 |
|
---|
226 | /** Write 1 byte zero page register.
|
---|
227 | * @param[in] dep The network interface structure.
|
---|
228 | * @param[in] reg The register offset.
|
---|
229 | * @param[in] data The value to be written.
|
---|
230 | */
|
---|
231 | #define outb_reg0(dep, reg, data) (outb(dep->de_dp8390_port + reg, data))
|
---|
232 |
|
---|
233 | /** Read 1 byte from the first page register.
|
---|
234 | * @param[in] dep The network interface structure.
|
---|
235 | * @param[in] reg The register offset.
|
---|
236 | * @returns The read value.
|
---|
237 | */
|
---|
238 | #define inb_reg1(dep, reg) (inb(dep->de_dp8390_port + reg))
|
---|
239 |
|
---|
240 | /** Write 1 byte first page register.
|
---|
241 | * @param[in] dep The network interface structure.
|
---|
242 | * @param[in] reg The register offset.
|
---|
243 | * @param[in] data The value to be written.
|
---|
244 | */
|
---|
245 | #define outb_reg1(dep, reg, data) (outb(dep->de_dp8390_port + reg, data))
|
---|
246 |
|
---|
247 | #define SENDQ_NR 2 /* Maximum size of the send queue */
|
---|
248 | #define SENDQ_PAGES 6 /* 6 * DP_PAGESIZE >= 1514 bytes */
|
---|
249 |
|
---|
250 | typedef struct dpeth {
|
---|
251 | /*
|
---|
252 | * The de_base_port field is the starting point of the probe.
|
---|
253 | * The conf routine also fills de_irq. If the probe
|
---|
254 | * routine knows the irq and/or memory address because they are
|
---|
255 | * hardwired in the board, the probe should modify these fields.
|
---|
256 | */
|
---|
257 | port_t de_base_port;
|
---|
258 | int de_irq;
|
---|
259 |
|
---|
260 | ether_addr_t de_address;
|
---|
261 | port_t de_dp8390_port;
|
---|
262 | port_t de_data_port;
|
---|
263 | int de_16bit;
|
---|
264 | long de_ramsize;
|
---|
265 | int de_offset_page;
|
---|
266 | int de_startpage;
|
---|
267 | int de_stoppage;
|
---|
268 |
|
---|
269 | /* Do it yourself send queue */
|
---|
270 | struct sendq {
|
---|
271 | int sq_filled; /* this buffer contains a packet */
|
---|
272 | int sq_size; /* with this size */
|
---|
273 | int sq_sendpage; /* starting page of the buffer */
|
---|
274 | } de_sendq[SENDQ_NR];
|
---|
275 |
|
---|
276 | int de_sendq_nr;
|
---|
277 | int de_sendq_head; /* Enqueue at the head */
|
---|
278 | int de_sendq_tail; /* Dequeue at the tail */
|
---|
279 |
|
---|
280 | /* Fields for internal use by the dp8390 driver. */
|
---|
281 | eth_stat_t de_stat;
|
---|
282 |
|
---|
283 | /* Driver flags */
|
---|
284 | bool up;
|
---|
285 | bool enabled;
|
---|
286 | bool stopped;
|
---|
287 | bool sending;
|
---|
288 | bool send_avail;
|
---|
289 | } dpeth_t;
|
---|
290 |
|
---|
291 | #endif
|
---|
292 |
|
---|
293 | /** @}
|
---|
294 | */
|
---|