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