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. 11 ** 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 16 ** 17 ** Revision 1.3 2005/08/03 11:53:34 jnherder 18 ** Miscellaneous cleanups. 19 ** 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. 25 ** 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>. 29 ** 30 ** Revision 2.0 2005/06/26 16:16:46 lsodgf0 31 ** Initial revision for Minix 3.0.6 32 */ 33 34 #include <sys/null.h> 35 36 #undef ENABLE_3C501 37 #undef ENABLE_3C503 38 #undef ENABLE_3C509 39 #undef ENABLE_NE2000 40 #undef ENABLE_WDETH 41 #undef ENABLE_DP8390 42 43 #define ENABLE_3C501 1 /* enable 3Com Etherlink I board */ 44 #define ENABLE_3C503 1 /* enable 3Com Etherlink II board */ 45 #define ENABLE_3C509 1 /* enable 3Com Etherlink III board */ 46 #define ENABLE_NE2000 1 /* enable Novell N2000 board */ 47 #define ENABLE_WDETH 1 /* enable Western Digital WD80x3 */ 48 49 #define ENABLE_DP8390 (ENABLE_3C503|ENABLE_WDETH|ENABLE_NE2000) 50 #define HAVE_BUFFERS (ENABLE_3C501|ENABLE_3C509) 51 52 #define NOT(x) (~(x)) 53 54 #if debug == 1 55 # define DEBUG(statm) statm 56 #else 57 # define DEBUG(statm) 58 #endif 59 60 typedef struct _m_hdr_t { /* Buffer handling header */ 61 struct _m_hdr_t *next; 62 int size; 63 } m_hdr_t; 64 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; 71 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); 76 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 82 83 #define SENDQ_NR 2 /* Size of the send queue */ 84 #define IOVEC_NR 16 /* Number of IOVEC entries at a time */ 85 86 typedef struct iovec_dat_s { 87 iovec_s_t iod_iovec[IOVEC_NR]; 88 int iod_iovec_s; 89 endpoint_t iod_proc_nr; 90 cp_grant_id_t iod_grant; 91 vir_bytes iod_iovec_offset; 92 } iovec_dat_s_t; 93 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. 102 * 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. */ 106 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 */ 110 111 int de_irq; 112 int de_int_pending; 113 int de_hook; /* interrupt hook at kernel */ 114 115 char de_name[8]; 116 117 #define DEI_DEFAULT 0x8000 118 119 phys_bytes de_linmem; /* For boards using shared memory */ 120 vir_bytes de_memoffs; 121 int de_ramsize; /* Size of on board memory */ 122 int de_offset_page; /* Offset of shared memory page */ 123 124 /* Board specific functions */ 125 dp_eth_t de_initf; 126 dp_eth_t de_stopf; 127 dp_eth_t de_resetf; 128 dp_eth_t de_flagsf; 129 dp_eth_t de_getstatsf; 130 dp_eth_t de_dumpstatsf; 131 dp_eth_t de_interruptf; 132 dp_send_recv_t de_recvf; 133 dp_send_recv_t de_sendf; 134 135 ether_addr_t de_address; /* Ethernet Address */ 136 eth_stat_t de_stat; /* Ethernet Statistics */ 137 unsigned long bytes_Tx; /* Total bytes sent/received */ 138 unsigned long bytes_Rx; 139 140 #define SA_ADDR_LEN sizeof(ether_addr_t) 141 142 int de_flags; /* Send/Receive mode (Configuration) */ 143 144 #define DEF_EMPTY 0x0000 145 #define DEF_READING 0x0001 146 #define DEF_RECV_BUSY 0x0002 147 #define DEF_ACK_RECV 0x0004 148 #define DEF_SENDING 0x0010 149 #define DEF_XMIT_BUSY 0x0020 150 #define DEF_ACK_SEND 0x0040 151 #define DEF_PROMISC 0x0100 152 #define DEF_MULTI 0x0200 153 #define DEF_BROAD 0x0400 154 #define DEF_ENABLED 0x2000 155 #define DEF_STOPPED 0x4000 156 157 int de_mode; /* Status of the Interface */ 158 159 #define DEM_DISABLED 0x0000 160 #define DEM_SINK 0x0001 161 #define DEM_ENABLED 0x0002 162 163 /* Temporary storage for RECV/SEND requests */ 164 iovec_dat_s_t de_read_iovec; 165 iovec_dat_s_t de_write_iovec; 166 vir_bytes de_read_s; 167 vir_bytes de_send_s; 168 int de_client; 169 /* 170 message de_sendmsg; 171 iovec_dat_t de_tmp_iovec; 172 */ 173 #if ENABLE_DP8390 == 1 174 /* For use by NS DP8390 driver */ 175 port_t de_dp8390_port; 176 int de_prog_IO; 177 int de_16bit; 178 int de_startpage; 179 int de_stoppage; 180 181 /* Do it yourself send queue */ 182 struct sendq { 183 int sq_filled; /* This buffer contains a packet */ 184 int sq_size; /* with this size */ 185 int sq_sendpage; /* starting page of the buffer */ 186 } de_sendq[SENDQ_NR]; 187 int de_sendq_nr; 188 int de_sendq_head; /* Enqueue at the head */ 189 int de_sendq_tail; /* Dequeue at the tail */ 190 191 dp_user2nicf_t de_user2nicf; 192 dp_nic2userf_t de_nic2userf; 193 dp_getblock_t de_getblockf; 194 #endif 195 196 #if ENABLE_3C509 == 1 197 /* For use by 3Com Etherlink III (3c509) driver */ 198 port_t de_id_port; 199 port_t de_if_port; 200 #endif 201 202 #if ENABLE_3C501 == 1 || ENABLE_3C509 == 1 203 /* For use by 3Com Etherlink (3c501 and 3c509) driver */ 204 buff_t *de_recvq_head; 205 buff_t *de_recvq_tail; 206 buff_t *de_xmitq_head; 207 buff_t *de_xmitq_tail; 208 u16_t de_recv_mode; 209 clock_t de_xmit_start; 210 #endif 211 212 } dpeth_t; 213 214 /* 215 * Function definitions 216 */ 217 218 /* dp.c */ 219 void dp_next_iovec(iovec_dat_s_t * iovp); 220 221 /* devio.c */ 222 #if defined USE_IOPL 223 #include <machine/portio.h> 224 #else 225 unsigned int inb(unsigned short int); 226 unsigned int inw(unsigned short int); 227 void insb(unsigned short int, endpoint_t, void *, int); 228 void insw(unsigned short int, int, void *, int); 229 void outb(unsigned short int, unsigned long); 230 void outw(unsigned short int, unsigned long); 231 void outsb(unsigned short int, endpoint_t, void *, int); 232 void outsw(unsigned short int, int, void *, int); 233 #endif 234 235 /* netbuff.c */ 236 void *alloc_buff(dpeth_t *, int); 237 void free_buff(dpeth_t *, void *); 238 void init_buff(dpeth_t *, buff_t **); 239 void mem2user(dpeth_t *, buff_t *); 240 void user2mem(dpeth_t *, buff_t *); 241 242 /* 3c501.c */ 243 #if ENABLE_3C501 == 1 244 int el1_probe(dpeth_t *); 245 #else 246 #define el1_probe(x) (0) 247 #endif 248 249 /* 3c503.c */ 250 #if ENABLE_3C503 == 1 251 int el2_probe(dpeth_t *); 252 #else 253 #define el2_probe(x) (0) 254 #endif 255 256 /* 3c509.c */ 257 #if ENABLE_3C509 == 1 258 int el3_probe(dpeth_t *); 259 #else 260 #define el3_probe(x) (0) 261 #endif 262 263 /* ne.c */ 264 #if ENABLE_NE2000 == 1 265 int ne_probe(dpeth_t * dep); 266 #else 267 #define ne_probe(x) (0) 268 #endif 269 270 /* wd.c */ 271 #if ENABLE_WDETH == 1 272 int wdeth_probe(dpeth_t * dep); 273 #else 274 #define wdeth_probe(x) (0) 275 #endif 276 277 #define lock() (++dep->de_int_pending,sys_irqdisable(&dep->de_hook)) 278 #define unlock() do{int i=(--dep->de_int_pending)?0:sys_irqenable(&dep->de_hook);(void) i;}while(0) 279 #define milli_delay(t) tickdelay(1) 280 281 /** dp.h **/ 282