Annotation of lucent/sys/src/9/pc/ether.h, revision 1.1.1.1

1.1       root        1: /*
                      2:  * All the goo for PC ethernet cards.
                      3:  */
                      4: typedef struct Card Card;
                      5: typedef struct RingBuf RingBuf;
                      6: typedef struct Type Type;
                      7: typedef struct Ctlr Ctlr;
                      8: 
                      9: /*
                     10:  * Hardware interface.
                     11:  */
                     12: struct Card {
                     13:        ISAConf;
                     14: 
                     15:        int     (*reset)(Ctlr*);
                     16:        void    (*init)(Ctlr*);
                     17:        void    (*attach)(Ctlr*);
                     18:        void    (*mode)(Ctlr*, int);
                     19: 
                     20:        void    *(*read)(Ctlr*, void*, ulong, ulong);
                     21:        void    *(*write)(Ctlr*, ulong, void*, ulong);
                     22: 
                     23:        void    (*receive)(Ctlr*);
                     24:        void    (*transmit)(Ctlr*);
                     25:        void    (*intr)(Ctlr*);
                     26:        void    (*watch)(Ctlr*);
                     27:        void    (*overflow)(Ctlr*);
                     28: 
                     29:        uchar   bit16;                  /* true if a 16 bit interface */
                     30:        uchar   ram;                    /* true if card has shared memory */
                     31: 
                     32:        ulong   dp8390;                 /* I/O address of 8390 (if any) */
                     33:        ulong   data;                   /* I/O data port if no shared memory */
                     34:        uchar   nxtpkt;                 /* software bndry */
                     35:        uchar   tstart;                 /* 8390 ring addresses */
                     36:        uchar   pstart;
                     37:        uchar   pstop;
                     38: };
                     39: 
                     40: /*
                     41:  * Software ring buffer.
                     42:  */
                     43: struct RingBuf {
                     44:        uchar   owner;
                     45:        uchar   busy;                   /* unused */
                     46:        ushort  len;
                     47:        uchar   pkt[sizeof(Etherpkt)];
                     48: };
                     49: 
                     50: enum {
                     51:        Host            = 0,            /* buffer owned by host */
                     52:        Interface       = 1,            /* buffer owned by card */
                     53: 
                     54:        Nrb             = 16,           /* default number of receive buffers */
                     55:        Ntb             = 4,            /* default number of transmit buffers */
                     56: };
                     57: 
                     58: /*
                     59:  * One per ethernet packet type.
                     60:  */
                     61: struct Type {
                     62:        QLock;
                     63:        Netprot;                        /* stat info */
                     64:        int     type;                   /* ethernet type */
                     65:        int     prom;                   /* promiscuous mode */
                     66:        int     filter;                 /* address filter */
                     67:        uchar   ea[6];                  /* ethernet address */
                     68:        Queue   *q;
                     69:        int     inuse;
                     70:        Ctlr    *ctlr;
                     71: 
                     72:        Rendez  cr;                     /* rendezvous for close */
                     73:        Type    *clist;                 /* close list */
                     74: };
                     75: 
                     76: enum {
                     77:        NType           = 9,            /* types/card */
                     78: 
                     79:        Eaddrlen        = 6,            /* Ethernet address length */
                     80: };
                     81: 
                     82: /*
                     83:  * Software controller.
                     84:  */
                     85: struct Ctlr {
                     86:        QLock;
                     87:        int     ctlrno;
                     88:        Ctlr    *next;
                     89: 
                     90:        Card    card;                   /* hardware info */
                     91:        int     present;
                     92:        int     debug;
                     93: 
                     94:        ushort  nrb;                    /* number of software receive buffers */
                     95:        ushort  ntb;                    /* number of software transmit buffers */
                     96:        RingBuf *rb;                    /* software receive buffers */
                     97:        RingBuf *tb;                    /* software transmit buffers */
                     98: 
                     99:        uchar   ea[6];                  /* ethernet address */
                    100:        uchar   ba[6];                  /* broadcast address */
                    101: 
                    102:        Rendez  rr;                     /* rendezvous for a receive buffer */
                    103:        ushort  rh;                     /* first receive buffer belonging to host */
                    104:        ushort  ri;                     /* first receive buffer belonging to card */    
                    105: 
                    106:        Rendez  tr;                     /* rendezvous for a transmit buffer */
                    107:        QLock   tlock;                  /* semaphore on th */
                    108:        ushort  th;                     /* first transmit buffer belonging to host */   
                    109:        ushort  ti;                     /* first transmit buffer belonging to card */
                    110:        int     tbusy;                  /* transmitter is busy */       
                    111: 
                    112:        Type    type[NType];
                    113:        int     all;                    /* number of channels listening to all packets */
                    114:        Type    *clist;                 /* channels waiting to close */
                    115:        Lock    clock;                  /* lock for clist */
                    116:        int     prom;                   /* number of promiscuous channels */
                    117:        int     filter;                 /* number of address filters */
                    118:        int     early;                  /* true if ra set */
                    119:        uchar   ra[8];                  /* received address if filtering */
                    120:        int     kproc;                  /* true if kproc started */
                    121:        char    name[NAMELEN];          /* name of kproc */
                    122:        Network net;
                    123: 
                    124:        Queue   lbq;                    /* software loopback packet queue */
                    125: 
                    126:        int     inpackets;
                    127:        int     outpackets;
                    128:        int     crcs;                   /* input crc errors */
                    129:        int     oerrs;                  /* output errors */
                    130:        int     frames;                 /* framing errors */
                    131:        int     overflows;              /* packet overflows */
                    132:        int     buffs;                  /* buffering errors */
                    133: };
                    134: 
                    135: #define NEXT(x, l)     (((x)+1)%(l))
                    136: #define        HOWMANY(x, y)   (((x)+((y)-1))/(y))
                    137: #define ROUNDUP(x, y)  (HOWMANY((x), (y))*(y))
                    138: 
                    139: /*
                    140:  * The Western Digital 8003 and 8013 series, the NE2000
                    141:  * and the 3Com 503 all use the DP8390 Network Interface
                    142:  * Chip.
                    143:  */
                    144: extern void dp8390reset(Ctlr*);
                    145: extern void dp8390attach(Ctlr*);
                    146: extern void dp8390mode(Ctlr*, int);
                    147: extern void dp8390getea(Ctlr*);
                    148: extern void dp8390setea(Ctlr*);
                    149: extern void *dp8390read(Ctlr*, void*, ulong, ulong);
                    150: extern void *dp8390write(Ctlr*, ulong, void*, ulong);
                    151: extern void dp8390receive(Ctlr*);
                    152: extern void dp8390transmit(Ctlr*);
                    153: extern void dp8390intr(Ctlr*);
                    154: extern void dp8390watch(Ctlr*);
                    155: extern void dp8390overflow(Ctlr*);
                    156: 
                    157: extern void dp8390debug(Ctlr*);
                    158: 
                    159: /*
                    160:  * The DP8390 needs some time between successive 
                    161:  * chip selects, so we need special I/O routines.
                    162:  * See l.s.
                    163:  * These routines only need to be used for accessing
                    164:  * the chip registers. Data I/O, either through
                    165:  * remote DMA or shared memory, can use the normal
                    166:  * routines.
                    167:  */
                    168: extern int dp8390inb(ulong);
                    169: extern void dp8390outb(ulong, uchar);
                    170: 
                    171: enum {
                    172:        Dp8390BufSz     = 256,          /* hardware ring buffer size */
                    173: };
                    174: 
                    175: 
                    176: extern void    addethercard(char*, int (*)(Ctlr*));
                    177: extern int     eaddrmatch(Ctlr*, uchar*);
                    178: extern int     parseether(void*, void*);

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.