gonzui


Format: Advanced Search

t2ex/t2ex_source/driver/tef_em1d/netdrv/src/netdrv.hbare sourcepermlink (0.02 seconds)

Search this content:

    1: /*
    2:  *----------------------------------------------------------------------
    3:  *    T2EX Software Package
    4:  *
    5:  *    Copyright 2012 by Ken Sakamura.
    6:  *    This software is distributed under the latest version of T-License 2.x.
    7:  *----------------------------------------------------------------------
    8:  *
    9:  *    Released by T-Engine Forum(http://www.t-engine.org/) at 2012/12/12.
   10:  *    Modified by TRON Forum(http://www.tron.org/) at 2015/06/04.
   11:  *
   12:  *----------------------------------------------------------------------
   13:  */
   14: /*
   15:  * This software package is available for use, modification, 
   16:  * and redistribution in accordance with the terms of the attached 
   17:  * T-License 2.x.
   18:  * If you want to redistribute the source code, you need to attach 
   19:  * the T-License 2.x document.
   20:  * There's no obligation to publish the content, and no obligation 
   21:  * to disclose it to the TRON Forum if you have modified the 
   22:  * software package.
   23:  * You can also distribute the modified source code. In this case, 
   24:  * please register the modification to T-Kernel traceability service.
   25:  * People can know the history of modifications by the service, 
   26:  * and can be sure that the version you have inherited some 
   27:  * modification of a particular version or not.
   28:  *
   29:  *    http://trace.tron.org/tk/?lang=en
   30:  *    http://trace.tron.org/tk/?lang=ja
   31:  *
   32:  * As per the provisions of the T-License 2.x, TRON Forum ensures that 
   33:  * the portion of the software that is copyrighted by Ken Sakamura or 
   34:  * the TRON Forum does not infringe the copyrights of a third party.
   35:  * However, it does not make any warranty other than this.
   36:  * DISCLAIMER: TRON Forum and Ken Sakamura shall not be held
   37:  * responsible for any consequences or damages caused directly or
   38:  * indirectly by the use of this software package.
   39:  *
   40:  * The source codes in bsd_source.tar.gz in this software package are 
   41:  * derived from NetBSD or OpenBSD and not covered under T-License 2.x.
   42:  * They need to be changed or redistributed according to the 
   43:  * representation of each source header.
   44:  */
   45: 
   46: /*
   47:  *      @(#)netdrv.h
   48:  *
   49:  */
   50: 
   51: #include        <tk/tkernel.h>
   52: #include        <tk/util.h>
   53: #include        <libstr.h>
   54: #include        <device/gdrvif.h>
   55: #include        <device/netdrv.h>
   56: #include        <device/pcmcia.h>
   57: #include        <device/devconf.h>
   58: 
   59: #ifdef  DEBUG
   60: #define DP(exp)         printf exp
   61: #define DBG(exp)        exp
   62: #else
   63: #define DP(exp)         /**/
   64: #define DBG(exp)        /**/
   65: #endif
   66: 
   67: #define INVALID_ID      (0)          /* Invalid ID                   */
   68: #define INVALID_DEVID   (-1)              /* Invalid Device ID                */
   69: 
   70: /*
   71:  *      Task information
   72:  */
   73: #define DEFAULT_PRI     (25)                /* Default priority           */
   74: #ifdef  DEBUG
   75: #define TASK_STKSZ      (4096)               /* Stack size                        */
   76: #else
   77: #define TASK_STKSZ      (2048)               /* Stack size                        */
   78: #endif
   79: 
   80: /*
   81:  *      Other definitions
   82:  */
   83: #define MAX_NETDEV      2            /* Max numbers of network devices */
   84: 
   85: #define L_EADDR         (6)            /* Length of physical address     */
   86: 
   87: #define MAXPKTLEN       (1500+14+6)   /* Max packet length (16-byte units) */
   88: #define MINPKTLEN       (46+14)               /* Min packet length         */
   89: #define MINRXBUFSZ      (512+20+44)  /* Min receive buffer length     */
   90: 
   91: #define N_RXBUF         (64)           /* Max number of receive buffer  */
   92: 
   93: #define IOSTEP  1
   94: 
   95: /*
   96:  *      Network driver information
   97:  */
   98: typedef struct _netinf {
   99:         W      netno;                       /* Network number (0 -)             */
  100:         ID     devid;                      /* Device ID                       */
  101:         GDI    Gdi;                       /* Generic driver I/F handle        */
  102:         ID     mbfid;                      /* Event notification MBF ID       */
  103:         ID     tskid;                      /* My task ID                      */
  104: 
  105:         NetDevInfo di;                 /* Device information         */
  106:         W      pciadr;                      /* PCI address                     */
  107:         W      devix;                       /* Device index                     */
  108: 
  109:         NetAddr        eaddr;                 /* Ethernet address           */
  110:         NetStInfo stinf;               /* Statistical information   */
  111: 
  112:         W      opencnt;             /* Open counts                     */
  113:         W      tmout;                       /* Timeout                  */
  114: 
  115:         BOOL   exist:1;          /* Exist status                 */
  116:         BOOL   suspended:1;              /* Suspend status           */
  117:         BOOL   txbusy:1;         /* Transmit busy status                */
  118:         BOOL   poweroff:1;               /* Card power off status     */
  119:         BOOL   rsv1:12;
  120:         BOOL   wrkflg1:1;                /* Individual flags           */
  121:         BOOL   wrkflg2:1;
  122:         BOOL   wrkflg3:1;
  123:         BOOL   wrkflg4:1;
  124:         BOOL   rsv2:12;
  125: 
  126:         ID     cardid;                     /* PC card ID                     */
  127:         ID     mapid;                      /* PC card map     ID          */
  128:         UH     ccraddr;            /* PC card CCR address            */
  129:         UB     ccr[2];                     /* PC card CCR value              */
  130:         UW     orgbase;            /* PC card mapping address        */
  131: 
  132:         NetRxBufSz bufsz;              /* Receive buffer size              */
  133:         UW     ip_rxbuf;           /* Receive buffer set position   */
  134:         UW     op_rxbuf;           /* Receive buffer get position   */
  135:         VP     rxbuf[N_RXBUF];             /* Receive buffer list             */
  136: 
  137:         /* Individual functions */
  138:         ER     (*initfn)(struct _netinf *inf, W init);
  139:         void   (*inthdr)(struct _netinf *inf);
  140:         INT    (*sendfn)(struct _netinf *inf, UB *buf, W len);
  141:         void   (*reset)(struct _netinf *inf, BOOL start);
  142:         ER     (*cardchk)(struct _netinf *inf);
  143:         INT    (*misc)(struct _netinf *inf, W wrt, W par, VP buf, W len);
  144:         void   (*tmofn)(struct _netinf *inf);
  145:         UH     (*mii_read)(struct _netinf *inf, W adr, W reg);
  146:         void   (*mii_write)(struct _netinf *inf, W adr, W reg, W dat);
  147:         INT    (*mcast)(struct _netinf *inf, W wrt, W all, UB *buf, W len);
  148: 
  149:         union {                        /* Individual working area   */
  150:                 VP    vp[12];            /* Assume sizeof(VP) = sizeof(UW) */
  151:                 UW    uw[12];
  152:                 UH    uh[24];
  153:                 UB    ub[48];
  154:         } wrk;
  155:         VP     extwrk;                     /* Pointer to extended working area */
  156:         FastLock       lock;         /* Exclusive lock              */
  157: } NetInf;
  158: 
  159: #define NetUnit(inf)    ((inf)->netno + 'a')       /* for debug messages */
  160: 
  161: /*
  162:         PCI Device ID definition table
  163: */
  164: typedef struct {
  165:         UH     vendor;                     /* Vendor ID                      */
  166:         UH     devid;                      /* Device ID                       */
  167:         UH     idmask;                     /* Device ID mask         */
  168:         UH     devix;                      /* Device index                    */
  169: } PciTab;
  170: 
  171: #define PCI_NET_ETHER   0x0200            /* Ethernet device class  */
  172: 
  173: /*
  174:  *      Driver definition table
  175:  */
  176: typedef struct  {
  177:         UW     kind;                       /* Hardware kind            */
  178:         PciTab *pcitab;                /* PCI device definition      */
  179:         ER     (*initfn)(NetInf *inf, W init);     /* Initialize function      */
  180: } DrvDef;
  181: 
  182: /*
  183:  *      Hardware kind
  184:  */
  185: #define HK_MASK         (0x000007ff)
  186: #define HK_CHIPMASK     (0x000000ff)
  187: #define HK_ISA          (0x00000000)
  188: #define HK_PCI          (0x00000100)
  189: #define HK_PCCARD       (0x00000200)
  190: #define isPcCARD(inf)   (((inf)->di.kind & 0x00000700) == HK_PCCARD)
  191: #define isPCI(inf)      (((inf)->di.kind & 0x00000700) == HK_PCI)
  192: #define isISA(inf)      (((inf)->di.kind & 0x00000700) == HK_ISA)
  193: 
  194: #define isFORCE_OPEN(inf)       ( (inf)->di.kind & 0x00000800)
  195: #define IFC_TYPE(inf)           (((inf)->di.kind & 0x0000f000) >> 12)
  196: 
  197: #define HK_FDX          (0x00010000)
  198: #define isFDX(inf)      ((inf)->di.kind & HK_FDX)
  199: 
  200: /*
  201:  *      I/O MACRO definitions
  202:  */
  203: #define InB(ix)         in_b(IOB + ((ix) * IOSTEP))
  204: #define InH(ix)         in_h(IOB + ((ix) * IOSTEP))
  205: #define InW(ix)         in_w(IOB + ((ix) * IOSTEP))
  206: #define OutB(ix, dt)    out_b(IOB + ((ix) * IOSTEP), (dt))
  207: #define OutH(ix, dt)    out_h(IOB + ((ix) * IOSTEP), (dt))
  208: #define OutW(ix, dt)    out_w(IOB + ((ix) * IOSTEP), (dt))
  209: 
  210: /*
  211:  *      External functions
  212:  */
  213: 
  214: /* main.c */
  215: IMPORT  PRI      TskPri;
  216: IMPORT  ID       CreTask(FP entry, PRI pri, W name, UW par, W stksz);
  217: 
  218: /* accept.c */
  219: IMPORT  ER       OpenProc(ID devid, UINT omode, GDI gdi);
  220: IMPORT  ER       CloseProc(ID devid, UINT option, GDI gdi);
  221: IMPORT  INT      EventProc(INT evttyp, VP evtinf, GDI gdi);
  222: IMPORT  void     AcceptRequest(NetInf *inf);
  223: 
  224: /* card.c */
  225: IMPORT  void     CardPowerOff(NetInf *inf, BOOL close);
  226: IMPORT  ER       CardPowerOn(NetInf *inf, BOOL open);
  227: IMPORT  ER       CardEvent(NetInf *inf, CardReq *req);
  228: 
  229: /* io.c */
  230: IMPORT  void     OutMemB(UW iob, W ix, UB *buf, W cnt);
  231: IMPORT  void     InMemB(UW iob, W ix, UB *buf, W cnt);
  232: IMPORT  void     OutMemH(UW iob, W ix, UH *buf, W cnt);
  233: IMPORT  void     InMemH(UW iob, W ix, UH *buf, W cnt);
  234: IMPORT  void     OutMemW(UW iob, W ix, UW *buf, W cnt);
  235: IMPORT  void     InMemW(UW iob, W ix, UW *buf, W cnt);
  236: 
  237: /* inthdr.c */
  238: IMPORT  ER       DefIntHdr(NetInf *inf, BOOL regist);
  239: 
  240: /* pci.c */
  241: IMPORT  ER       PciAllocMem(W sz, VP *p);
  242: IMPORT  void     PciFreeMem(VP p);
  243: IMPORT  ER       PciProbe(NetInf *inf, PciTab *tab);
  244: IMPORT  void     PciEnable(W caddr, W iocmd, W latency);
  245: IMPORT  void     SetACPI(NetInf *inf, W state);
  246: IMPORT  INT      GetPCIAdr(VP addr, W len, VP *physical_addr);
  247: 
  248: /* misc.c */
  249: IMPORT  ER       AllocMem(W sz, VP *p);
  250: IMPORT  void     FreeMem(VP p);
  251: IMPORT  ER       SetRxBuf(NetInf *inf, VP bp);
  252: IMPORT  VP       GetRxBuf(NetInf *inf);
  253: IMPORT  ER       SendMsg(NetInf *inf, VP pb, W len);
  254: IMPORT  INT      MIIfind(NetInf *inf, W target);
  255: IMPORT  INT      MIIinit(NetInf *inf, W target);
  256: IMPORT  void     SetProdName(NetInf *inf, UB **nm1, UB **nm2);
  257: IMPORT  UW       CalcCRC32(UB *data, W len);
  258: 
  259: /* smsc9118.c */
  260: IMPORT  ER       InitSMSC9118(NetInf *inf, W init);
  261: