3.1.7 branch.
[minix.git] / drivers / dpeth / dp.h
bloba13c96ce0703a426c21f68fcf7d527208b194416
1 /*
2 ** File: eth.h Version 1.00, Jan. 14, 1997
3 **
4 ** Author: Giovanni Falzoni <gfalzoni@inwind.it>
5 **
6 ** Interface description for ethernet device driver
7 **
8 ** $Log$
9 ** Revision 1.5 2006/07/10 12:43:38 philip
10 ** Safecopy support in ethernet drivers.
12 ** Revision 1.4 2005/09/04 18:52:16 beng
13 ** Giovanni's fixes to dpeth:
14 ** Date: Sat, 03 Sep 2005 11:05:22 +0200
15 ** Subject: Minix 3.0.8
17 ** Revision 1.3 2005/08/03 11:53:34 jnherder
18 ** Miscellaneous cleanups.
20 ** Revision 1.2 2005/08/02 15:30:35 jnherder
21 ** Various updates to support dynamically starting drivers.
22 ** Output during initialization should be suppressed. Unless an error occurs.
23 ** Note that main() can now be main(int argc, char **argv) and arguments can
24 ** be passed when bringing up the driver.
26 ** Revision 1.1 2005/06/29 10:16:46 beng
27 ** Import of dpeth 3c501/3c509b/.. ethernet driver by
28 ** Giovanni Falzoni <fgalzoni@inwind.it>.
30 ** Revision 2.0 2005/06/26 16:16:46 lsodgf0
31 ** Initial revision for Minix 3.0.6
34 #undef ENABLE_3C501
35 #undef ENABLE_3C503
36 #undef ENABLE_3C509
37 #undef ENABLE_NE2000
38 #undef ENABLE_WDETH
39 #undef ENABLE_DP8390
41 #define ENABLE_3C501 1 /* enable 3Com Etherlink I board */
42 #define ENABLE_3C503 1 /* enable 3Com Etherlink II board */
43 #define ENABLE_3C509 1 /* enable 3Com Etherlink III board */
44 #define ENABLE_NE2000 1 /* enable Novell N2000 board */
45 #define ENABLE_WDETH 1 /* enable Western Digital WD80x3 */
47 #define ENABLE_DP8390 (ENABLE_3C503|ENABLE_WDETH|ENABLE_NE2000)
48 #define HAVE_BUFFERS (ENABLE_3C501|ENABLE_3C509)
50 #undef NULL
51 #define NULL ((void *)0)
52 #define NOT(x) (~(x))
54 #if debug == 1
55 # define DEBUG(statm) statm
56 #else
57 # define DEBUG(statm)
58 #endif
60 typedef struct _m_hdr_t { /* Buffer handling header */
61 struct _m_hdr_t *next;
62 int size;
63 } m_hdr_t;
65 typedef struct _buff_t { /* Receive/Transmit buffer header */
66 struct _buff_t *next;
67 int size;
68 int client;
69 char buffer[2];
70 } buff_t;
72 struct dpeth;
73 struct iovec_dat;
74 typedef void (*dp_eth_t) (struct dpeth *);
75 typedef void (*dp_send_recv_t) (struct dpeth *, int, int);
77 #if ENABLE_DP8390 == 1
78 typedef void (*dp_user2nicf_t) (struct dpeth *, int, int);
79 typedef void (*dp_nic2userf_t) (struct dpeth *, int, int);
80 typedef void (*dp_getblock_t) (struct dpeth *, u16_t, int, void *);
81 #endif
83 #define SENDQ_NR 2 /* Size of the send queue */
84 #define IOVEC_NR 16 /* Number of IOVEC entries at a time */
86 typedef struct iovec_dat_s {
87 iovec_s_t iod_iovec[IOVEC_NR];
88 int iod_iovec_s;
89 int iod_proc_nr;
90 cp_grant_id_t iod_grant;
91 vir_bytes iod_iovec_offset;
92 } iovec_dat_s_t;
94 typedef struct dpeth {
95 /* The de_base_port field is the starting point of the probe. The
96 * conf routine also fills de_linmem and de_irq. If the probe routine
97 * knows the irq and/or memory address because they are hardwired in
98 * the board, the probe should modify these fields. Futhermore, the
99 * probe routine should also fill in de_initf and de_stopf fields
100 * with the appropriate function pointers and set de_prog_IO iff
101 * programmed I/O is to be used.
103 * The initf function fills the following fields. Only cards that do
104 * programmed I/O fill in the de_data_port field. In addition, the
105 * init routine has to fill in the sendq data structures. */
107 /* Board hardware interface */
108 port_t de_base_port;
109 port_t de_data_port; /* For boards using Prog. I/O for xmit/recv */
111 int de_irq;
112 int de_int_pending;
113 int de_hook; /* interrupt hook at kernel */
115 char de_name[8];
117 #define DEI_DEFAULT 0x8000
119 phys_bytes de_linmem; /* For boards using shared memory */
120 unsigned short de_memsegm;
121 vir_bytes de_memoffs;
122 int de_ramsize; /* Size of on board memory */
123 int de_offset_page; /* Offset of shared memory page */
125 /* Board specific functions */
126 dp_eth_t de_initf;
127 dp_eth_t de_stopf;
128 dp_eth_t de_resetf;
129 dp_eth_t de_flagsf;
130 dp_eth_t de_getstatsf;
131 dp_eth_t de_dumpstatsf;
132 dp_eth_t de_interruptf;
133 dp_send_recv_t de_recvf;
134 dp_send_recv_t de_sendf;
136 ether_addr_t de_address; /* Ethernet Address */
137 eth_stat_t de_stat; /* Ethernet Statistics */
138 unsigned long bytes_Tx; /* Total bytes sent/received */
139 unsigned long bytes_Rx;
141 #define SA_ADDR_LEN sizeof(ether_addr_t)
143 int de_flags; /* Send/Receive mode (Configuration) */
145 #define DEF_EMPTY 0x0000
146 #define DEF_READING 0x0001
147 #define DEF_RECV_BUSY 0x0002
148 #define DEF_ACK_RECV 0x0004
149 #define DEF_SENDING 0x0010
150 #define DEF_XMIT_BUSY 0x0020
151 #define DEF_ACK_SEND 0x0040
152 #define DEF_PROMISC 0x0100
153 #define DEF_MULTI 0x0200
154 #define DEF_BROAD 0x0400
155 #define DEF_ENABLED 0x2000
156 #define DEF_STOPPED 0x4000
158 int de_mode; /* Status of the Interface */
160 #define DEM_DISABLED 0x0000
161 #define DEM_SINK 0x0001
162 #define DEM_ENABLED 0x0002
164 /* Temporary storage for RECV/SEND requests */
165 iovec_dat_s_t de_read_iovec;
166 iovec_dat_s_t de_write_iovec;
167 vir_bytes de_read_s;
168 vir_bytes de_send_s;
169 int de_client;
171 message de_sendmsg;
172 iovec_dat_t de_tmp_iovec;
174 #if ENABLE_DP8390 == 1
175 /* For use by NS DP8390 driver */
176 port_t de_dp8390_port;
177 int de_prog_IO;
178 int de_16bit;
179 int de_startpage;
180 int de_stoppage;
182 /* Do it yourself send queue */
183 struct sendq {
184 int sq_filled; /* This buffer contains a packet */
185 int sq_size; /* with this size */
186 int sq_sendpage; /* starting page of the buffer */
187 } de_sendq[SENDQ_NR];
188 int de_sendq_nr;
189 int de_sendq_head; /* Enqueue at the head */
190 int de_sendq_tail; /* Dequeue at the tail */
192 dp_user2nicf_t de_user2nicf;
193 dp_nic2userf_t de_nic2userf;
194 dp_getblock_t de_getblockf;
195 #endif
197 #if ENABLE_3C509 == 1
198 /* For use by 3Com Etherlink III (3c509) driver */
199 port_t de_id_port;
200 port_t de_if_port;
201 #endif
203 #if ENABLE_3C501 == 1 || ENABLE_3C509 == 1
204 /* For use by 3Com Etherlink (3c501 and 3c509) driver */
205 buff_t *de_recvq_head;
206 buff_t *de_recvq_tail;
207 buff_t *de_xmitq_head;
208 buff_t *de_xmitq_tail;
209 u16_t de_recv_mode;
210 clock_t de_xmit_start;
211 #endif
213 } dpeth_t;
216 * Function definitions
219 /* dp.c */
220 void dp_next_iovec(iovec_dat_s_t * iovp);
222 /* devio.c */
223 #if defined USE_IOPL
224 #include <machine/portio.h>
225 #else
226 unsigned int inb(unsigned short int);
227 unsigned int inw(unsigned short int);
228 void insb(unsigned short int, endpoint_t, void *, int);
229 void insw(unsigned short int, int, void *, int);
230 void outb(unsigned short int, unsigned long);
231 void outw(unsigned short int, unsigned long);
232 void outsb(unsigned short int, endpoint_t, void *, int);
233 void outsw(unsigned short int, int, void *, int);
234 #endif
236 /* netbuff.c */
237 void *alloc_buff(dpeth_t *, int);
238 void free_buff(dpeth_t *, void *);
239 void init_buff(dpeth_t *, buff_t **);
240 void mem2user(dpeth_t *, buff_t *);
241 void user2mem(dpeth_t *, buff_t *);
243 /* 3c501.c */
244 #if ENABLE_3C501 == 1
245 int el1_probe(dpeth_t *);
246 #else
247 #define el1_probe(x) (0)
248 #endif
250 /* 3c503.c */
251 #if ENABLE_3C503 == 1
252 int el2_probe(dpeth_t *);
253 #else
254 #define el2_probe(x) (0)
255 #endif
257 /* 3c509.c */
258 #if ENABLE_3C509 == 1
259 int el3_probe(dpeth_t *);
260 #else
261 #define el3_probe(x) (0)
262 #endif
264 /* ne.c */
265 #if ENABLE_NE2000 == 1
266 int ne_probe(dpeth_t * dep);
267 #else
268 #define ne_probe(x) (0)
269 #endif
271 /* wd.c */
272 #if ENABLE_WDETH == 1
273 int wdeth_probe(dpeth_t * dep);
274 #else
275 #define wdeth_probe(x) (0)
276 #endif
278 #define lock() (++dep->de_int_pending,sys_irqdisable(&dep->de_hook))
279 #define unlock() do{int i=(--dep->de_int_pending)?0:sys_irqenable(&dep->de_hook);(void) i;}while(0)
280 #define milli_delay(t) tickdelay(1)
282 /** dp.h **/