if_vcom.h
上传用户:luoyougen
上传日期:2008-05-12
资源大小:23136k
文件大小:18k
源码类别:

VxWorks

开发平台:

C/C++

  1. /* if_vcom.h - VLAN ethernet board transparent mode library */
  2. /* Copyright 1990-1994, PEP Modular Computers */
  3. /* Copyright 1984-1994, Wind River Systems, Inc. */
  4. /*
  5. modification history
  6. --------------------
  7. 01f,07jan94,haw  removed include of copyright, fixed spacing, indentation
  8. 01e,07jun93,haw  renamed to if_vcom.h (used to be vcomLib.h),
  9.                  moved it to this directory, copyied definition of
  10.                  VCOM structure to this file, moved all includes to the driver,
  11.                  now uses of volatile variables where necessary, added
  12.                  definitions for some registers
  13. 01d,07jan93,haw  made variables LOCAL
  14. 01c,09oct92,haw  added definitions for EEPROM
  15. 01b,12jul92,haw  added some casts to satisfy LINT
  16. 01a,11jun92,haw  written
  17. */
  18.  
  19. #ifndef __INCif_vcomh
  20. #define __INCif_vcomh
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif /* __cplusplus */
  24. #define EADDRS          6
  25.  
  26. #define GOTTRAILERTYPE  0
  27. #define GOTTYPE         1
  28. #define GOTNOTYPE       2
  29.  
  30. #define ETHER_MIN   (ETHERMIN + sizeof(struct ether_header))
  31. #define ETHER_MAX   (ETHERMTU + sizeof(struct ether_header))
  32. /* Intel 82596 specific definitions  */
  33.  
  34. /*
  35.  * RFD - receive frame descriptor: linear mode, simplified model
  36.  */
  37.  
  38. typedef struct rfd
  39.     {
  40.     volatile UINT16      rfdStat1;   /* first status word */
  41.     volatile UINT16      rfdStat2;   /* second status word */
  42.     struct rfd *pRfdLeNext;          /* ptr to next rfd (little-end) */
  43.     void       *pRfdRbd;             /* ptr to receive buffer descriptor */
  44.     volatile UINT16      rfdAcount;  /* number of actual bytes in buffer */
  45.     UINT16      rfdSize;             /* size of buffer */
  46.     volatile UINT8       rfdDa [6];  /* destination address */
  47.     volatile UINT8       rfdSa [6];  /* source address */
  48.     UINT16      rfdLength;           /* length/type from 802.3 frame */
  49.     UINT8       rfdData [ETHER_MAX]; /* ethernet received data */
  50.     struct rfd *pRfdBeNext;          /* ptr to next rfd (big-end for driver) */
  51.     struct rfd *pRfdBePrev;          /* ptr to prev rfd (big-end for driver) */
  52.     } RFD;
  53. /*
  54.  * TBD - Transmit buffer descriptor
  55.  */
  56.  
  57. typedef struct tbd
  58.     {
  59.     UINT16      tbdCnt;              /* number of bytes to xmit from this TBD */
  60.     UINT16      zeroes;
  61.     struct tbd *pTbdLeNext;          /* pointer to next tbd in xmit chain */
  62.     void       *pTbdData;            /* pointer to data to xmit */
  63.     UINT32      tbdPadd;             /* pad to 16 bytes */
  64.     UINT8       xmitData [1536];     /* xmit data buffer (lld + alignment) */
  65.     } TBD;
  66. typedef struct tcb
  67.     {
  68.     TBD        *pTbd;                /* ptr to transmit buffer descriptor */
  69.     UINT16      tcbCnt;              /* number of bytes to xmit from TCB */
  70.     UINT16      zeroes;              /* must be zeroes */
  71.     UINT8       da [6];              /* destination ethernet address */
  72.     UINT16      tcbLen;              /* length/type for 802.3 frame */
  73.     } TCB;
  74.  
  75. /*
  76.  * CB - Command block template
  77.  */
  78. typedef struct cb
  79.     {
  80.     volatile UINT16      cbStatus;   /* status word */
  81.     volatile UINT16      cbCommand;  /* command word */
  82.     struct cb *pCbLeNext;            /* ptr to nxt command block (little end) */
  83.     union
  84.         {
  85.         UINT8   ia [6];              /* ethernet address (for IA command) */
  86.         TCB     tcb;                 /* transmit command block */
  87.         } cmd;
  88.     struct cb  *pCbBeNext;           /* next cmd block (bigend for driver) */
  89.     struct cb  *pCbBePrev;           /* prev cmd block (bigend for driver) */
  90.     } CB;
  91. /*
  92.  * SCB - system control block template
  93.  */
  94.  
  95. typedef struct scb
  96.     {
  97.     volatile UINT16      scbStatus;  /* status word */
  98.     volatile UINT16      scbCmd;     /* command word */
  99.     CB         *pCbl;                /* command block list ptr */
  100.     RFD        *pRfa;                /* receive frame area ptr */
  101.     UINT32      crcErrs;             /* CRC errors */
  102.     UINT32      alignErrs;           /* alignment errors */
  103.     UINT32      resErrs;             /* resource errors */
  104.     UINT32      overrunErrs;         /* overrun errors */
  105.     UINT32      rcvcdtErrs;          /* receive collisions errors */
  106.     UINT32      sfErrs;              /* short frame errors */
  107.     UINT16      toffTimer;           /* throttle t-off timer */
  108.     UINT16      tonTimer;            /* throttle t-on timer */
  109.     UINT8       cbPadd [8];          /* padd to 16-byte bound */
  110.     } SCB;
  111.  
  112. /*
  113.  * ISCP - Intermediate System configuration pointer
  114.  */
  115.  
  116. typedef struct iscp
  117.     {
  118.     UINT8       iscpUnused1;
  119.     UINT8       iscpBusy;            /* busy indicator */
  120.     UINT16      iscpUnused2;
  121.     SCB        *pIscpLeSCB;          /* (little end) scb pointer */
  122.     SCB        *pIscpBeSCB;          /* (big end) scb pointer */
  123.     UINT8       iscpPadd [4];        /* padd to 16-byte bound */
  124.     } ISCP;
  125. /*
  126.  * SCP - System configuration pointer
  127.  */
  128.  
  129. typedef struct scp
  130.     {
  131.     UINT32      scpSysbus;           /* configuration goodies */
  132.     UINT32      scpUnused2;
  133.     ISCP       *pScpLeISCP;          /* (little end) iscp pointer */
  134.     ISCP       *pScpBeISCP;          /* (big end) iscp pointer */
  135.     } SCP;
  136.  
  137. /*
  138.  * template for selftest result
  139.  */
  140. typedef struct
  141.     {
  142.     volatile UINT32      strRomsig;  /* ROM signature */
  143.     volatile UINT32      strResult;  /* selftest result */
  144.     } STR;
  145.  
  146. /* defines for the TBD */
  147.  
  148. #define TBD_EOF             0x8000   /* last TBD in xmit list */
  149. #define TBD_CNTMASK         0x3fff   /* 14-bit count field */
  150.  
  151. #define TBD_NOT_USED    (void *)-1
  152.  
  153. /* defines for the TCB */
  154. #define TCB_EOF             0x8000   /* entire frame is in TCB */
  155. #define TCB_CNTMASK         0x3fff   /* 14-bit count field */
  156.  
  157. /* defines for the RFD */
  158.  
  159. #define RFD_COMPLETE        0x8000   /* reception complete */
  160. #define RFD_BUSY            0x4000   /* reception in progress */
  161. #define RFD_OK              0x2000   /* received frame has no errors */
  162.  
  163. #define RFD_LAST            0x8000   /* last rfd in rdl */
  164. #define RFD_SUSPEND         0x4000   /* suspend after receive */
  165. #define RFD_FLEXIBLE        0x0008   /* flexible/simple memory model */
  166.  
  167. #define RFD_RBD_NOTUSED (void *)-1
  168. #define RFD_EOF             0x8000   /* last buffer in frame */
  169. #define RFD_USED            0x4000   /* buffer has been used (and abused) */
  170.  
  171. #define RFD_SIZEMASK        0x3fff   /* size is 14-bits */
  172.  
  173. /* defines for the CB */
  174.  
  175. #define CB_COMPLETE         0x8000   /* 1=command complete */
  176. #define CB_BUSY             0x4000   /* 1=command in progress */
  177. #define CB_OK               0x2000   /* 1=completed without error */
  178. #define CB_ABORT            0x1000   /* 1=command aborted */
  179. #define XMIT_LCOL           0x0800   /* 1=late collision on xmit */
  180. #define XMIT_LCAR           0x0400   /* 1=no carrier sensed */
  181. #define XMIT_LCTS           0x0200   /* 1=lost clear to send */
  182. #define XMIT_UDMA           0x0100   /* 1=dma underrun */
  183. #define XMIT_DEFR           0x0080   /* 1=transmit deferred */
  184. #define XMIT_BEAT           0x0040   /* 1=CDT (heartbeat) active */
  185. #define XMIT_MTRY           0x0020   /* 1=exceeded maximum retries for xmit */
  186. #define XMIT_COLLMASK       0x000f   /* collision count field */
  187. #define CB_LAST             0x8000   /* last command in list */
  188. #define CB_SUSPEND          0x4000   /* suspend after this command */
  189. #define CB_IRQ              0x2000   /* generate IRQ after command */
  190. #define XMIT_NC             0x0010   /* 1=no CRC insertion enable */
  191. #define XMIT_SF             0x0008   /* 1=flexible, 0=simplified (sic) */
  192. #define CB_CMDMASK          0x0007   /* mask for command code */
  193. #define CB_CMD_NOP               0   /* NOP command */
  194. #define CB_CMD_IASETUP           1   /* Intermediate address setup command */
  195. #define CB_CMD_CONFIG            2   /* CONFIG command */
  196. #define CB_CMD_MCSETUP           3   /* Multicast setup command */
  197. #define CB_CMD_XMIT              4   /* Transmit command */
  198. #define CB_CMD_TDR               5   /* TDR command */
  199. #define CB_CMD_DUMP              6   /* Dump internals command */
  200. #define CB_CMD_DIAG              7   /* Diagnose command */
  201.  
  202. /* defines for the SCB */
  203.  
  204. #define SCB_STATUS_CX       0x8000   /* command complete interrupt */
  205. #define SCB_STATUS_FR       0x4000   /* finished receiving frame interrupt */
  206. #define SCB_STATUS_CNA      0x2000   /* CU left in active state */
  207. #define SCB_STATUS_RNR      0x1000   /* RU left in ready state */
  208. #define SCB_CU_ACTIVE       0x0200   /* CU in active state */
  209. #define SCB_CU_SUSPEND      0x0100   /* CU is suspended */
  210. #define SCB_CU_IDLE         0x0000   /* CU is idle */
  211. #define SCB_RU_NO_RBD       0x0080   /* RU is in no RBD state */
  212. #define SCB_RU_READY        0x0040   /* RU is in ready state */
  213. #define SCB_RU_NO_RES       0x0020   /* RU is in no resources state */
  214. #define SCB_RU_SUSPEND      0x0010   /* RU is suspended */
  215. #define SCB_RU_IDLE         0x0000   /* RU is idle */
  216. #define SCB_THROTTLE        0x0008   /* throttle timers loaded */
  217. #define SCB_CX_ACK          0x8000   /* complete complete int ack */
  218. #define SCB_FR_ACK          0x4000   /* frame reception int ack */
  219. #define SCB_CNA_ACK         0x2000   /* CU not ready int ack */
  220. #define SCB_RNR_ACK         0x1000   /* RU not ready int ack */
  221. #define SCB_CU_BUSTHRI      0x0600   /* load bus throttle timers */
  222. #define SCB_CU_BUSTHR       0x0500   /* load bus throttle timers */
  223. #define SCB_CU_ABORT_CMD    0x0400   /* abort CU cmd */
  224. #define SCB_CU_SUSPEND_CMD  0x0300   /* suspend CU cmd */
  225. #define SCB_CU_RESUME_CMD   0x0200   /* resume CU cmd */
  226. #define SCB_CU_START_CMD    0x0100   /* start CU cmd */
  227. #define SCB_CU_NOP_CMD      0x0000   /* CU nop cmd */
  228. #define SCB_CHIP_RESET_CMD  0x0080   /* chip reset */
  229. #define SCB_RU_ABORT_CMD    0x0040   /* RU abort cmd */
  230. #define SCB_RU_SUSPEND_CMD  0x0030   /* RU suspend cmd */
  231. #define SCB_RU_RESUME_CMD   0x0020   /* RU resume cmd */
  232. #define SCB_RU_START_CMD    0x0010   /* RU start cmd */
  233. #define SCB_RU_NOP_CMD      0x0000   /* RU nop cmd */
  234.  
  235. /* defines for the ISCP */
  236.  
  237. #define ISCP_NOT_BUSY            1
  238.  
  239. /* defines for the SCP */
  240.  
  241. #define SYSBUS_CSW      0x00000040   /* reserved */
  242. #define SYSBUS_INTLO    0x00000020   /* interrupt polarity */
  243. #define SYSBUS_INTHI    0x00000020   /* interrupt polarity */
  244. #define SYSBUS_LOCK     0x00000010   /* lock function */
  245. #define SYSBUS_TRG      0x00000008   /* bus throttle triggers */
  246. #define SYSBUS_MODEMASK 0x00000006   /* operation mode */
  247. #define SYSBUS_LINEAR   0x00000004   /* operation mode (linear) */
  248. typedef struct
  249.     {
  250.     UINT32      ramAddr;             /* base address for i82596 shared ram */
  251.     UINT32      ramOffset;           /* offset in window for i82596 */
  252.     UINT32      ramAdjust;           /* ramaddr-ramadjust = i82596 ram addr */
  253.     UINT32      ramSize;             /* size of ram for i82596 */
  254.     UINT32      idPromAddr;          /* address of ID prom */
  255.     UINT16      maxRfd;              /* max. receive frame descriptors */
  256.     UINT16      maxCbl;              /* max. xmit commands to queue */
  257.     UINT16      portOff;             /* offset (from dev addr) to port */
  258.     UINT16      caOff;               /* offset (from dev addr) to chan attn */
  259.     UINT16      irqOff;              /* offset (from dev addr) to clear IRQ */
  260.     UINT16      tOn;                 /* i82596 t-on  bus throttle value */
  261.     UINT16      tOff;                /* i82596 t-off bus throttle value */
  262.     UINT8       ramWidth;            /* 2=D16 (word) ram, 4=D32 (long) ram */
  263.     UINT8       portWidth;           /* i82596 port access width */
  264.     UINT8       caWidth;             /* i82596 channel access width */
  265.     UINT8       irqWidth;            /* i82596 clear IRQ width */
  266.     UINT8       sysbus;              /* i82596 SCP sysbus value */
  267.     } VCOM_DESC;
  268. /* chip access macros */
  269.  
  270. #define I82596_RESET(xx)
  271.     doportCommand((int) xx, (UINT8 *) 0, (UINT8) 0)
  272. #define I82596_SELFTEST(xx, addr)
  273.     doportCommand((int) xx, (UINT8 *) addr, (UINT8) 1)
  274. #define I82596_ASCP(xx, addr)
  275.     doportCommand((int) xx, (UINT8 *) addr, (UINT8) 2)
  276. #define I82596_DUMP(xx, addr)
  277.     doportCommand((int) xx, (UINT8 *) addr, (UINT8) 3)
  278.  
  279. #define I82596_CHANATTN(xx)
  280.     *((UINT8 *)xx->pCaAddr) = 0;
  281. /* board address offsets */
  282.  
  283. #define VCOM_RESET(port)      ((UINT8 *) port + 0x93)
  284. #define VCOM_SNOOP_IRQ(port)  ((UINT8 *) port + 0x17)
  285. #define VCOM_IRQ_VEC(port)    ((UINT8 *) port + 0x13)
  286. #define VCOM_VME_ACC(port)    ((UINT8 *) port + 0x0f)
  287. #define VCOM_LED_IRQ(port)    ((UINT8 *) port + 0x0b)
  288. /* defines for VCOM_SNOOP_IRQ */
  289. #define IROUT_VME   0x01
  290. #define IRQEN       0x02
  291. #define IRQL_5      0x04
  292. #define SC0         0x40
  293. #define SC1         0x80
  294. /* defines for VCOM_LED_IRQ */
  295. #define ENVRQ       0x01
  296. #define LED_ETHER   0x02
  297. #define LED_SCSI    0x04
  298.  
  299. /* EEPROM definitions */
  300.  
  301. #define DATA_ADDRESS       (UINT8 *) ((UINT8 *) port + 0x03)
  302. #define CS_ADDRESS         (UINT8 *) ((UINT8 *) port + 0x04)
  303. #define CS_ACTIVE          *(CS_ADDRESS) = 1
  304. #define CS_PASSIVE         dummyCS = *(CS_ADDRESS)
  305. #define SET_INPUT          *(UINT8 *) ((UINT8 *) port + 0x07) = 1
  306. #define TOGGLE
  307.     {
  308.     *(UINT8 *) ((UINT8 *) port + 0x06) = 1;
  309.     lnop ();
  310.     *(UINT8 *) ((UINT8 *) port + 0x06) = 1;
  311.     }
  312.  
  313. /* EEPROM command definition */
  314.  
  315. /*                    +------------------ start bit                 */
  316. /*                    |++---------------- opcode                    */
  317. /*                    |||++-------------- additional opcode         */
  318. /*                    |||||++++---------- address                   */
  319. /*                    |||||||||                                     */
  320. /*                    vvvvvvvvv                                     */
  321.  
  322. #define EREAD    /* 0%110000000 */ 0x188 /* read word from address  */
  323. #define WORD_ACC(a,b) a = b;
  324.  
  325. #define CONV(a) ((UINT32) vs->pSharedRam > 0x87000000 && 
  326.                  (UINT32) vs->pSharedRam < 0x88000000) ? 
  327.                  (((UINT32) (a) & 0x000fffff) | 0xD0000000) : 
  328.                  (UINT32) (a)
  329. /* some address definitions */
  330.  
  331. #define VCOM_LXB_RAM    0xD0000000
  332. #define VCOM_LXB_IO     0xC8000000
  333.  
  334. LOCAL UINT8 *vcomVmeRam [] =
  335.     {
  336.     (UINT8 *) 0x87400000,
  337.     (UINT8 *) 0x87600000,
  338.     (UINT8 *) 0x87800000,
  339.     (UINT8 *) 0x87A00000
  340.     };
  341. LOCAL UINT8 *vcomVmePort [] =
  342.     {
  343.     (UINT8 *) 0x87FE0000,
  344.     (UINT8 *) 0x87FE0100,
  345.     (UINT8 *) 0x87FF0000,
  346.     (UINT8 *) 0x87FF0100
  347.     };
  348. #define MHz
  349. LOCAL VCOM_DESC vcomDesc =
  350.     {
  351.     0,          /* ramAddr:    passed by call                   */
  352.     0,          /* ramOffset:  always 0                         */
  353.     0,          /* ramAdjust:  always 0                         */
  354.     256*1024,   /* ramSize:    size of ram for i82596           */
  355.     0,          /* idPromAddr: address of ID prom               */
  356.     32,         /* maxRfd:     max. receive frame descriptors   */
  357.     32,         /* maxCbl:     max. xmit commands to queue      */
  358.     0x60,       /* portOff:    offset to port access            */
  359.     0x61,       /* caOff:      offset to channel attention      */
  360.     0x00,       /* irqOff:     obsolete                         */
  361.     7*25 MHz,   /* tOn:        i82596 t-on  bus throttle value  */
  362.     1*25 MHz,   /* tOff:       i82596 t-off bus throttle value  */
  363.     4,          /* ramWidth:   longword                         */
  364.     2,          /* portWidth:  i82596 port access width         */
  365.     1,          /* caWidth:    i82596 channel access width      */
  366.     0,          /* irqWidth:   obsolete                         */
  367.     0x54        /* sysbus:     i82596 SCP sysbus value          */
  368.                 /* 0%01010100                                   */
  369.                 /*    ^^^^^^                                    */
  370.                 /*    ||||||                                    */
  371.                 /*    ||||++----- linear mode (never change)    */
  372.                 /*    |||+------- external/internal bus trigger */
  373.                 /*    ||+-------- lock disable/enable           */
  374.                 /*    |+--------- IRQ pin active low/high       */
  375.                 /*    +---------- CSW must be 1 (Intel Errata)  */
  376.     };
  377. typedef struct
  378.     {
  379.     struct  arpcom vs_ac;        /* common ethernet structures */
  380.     int vcomIntLevel;            /* vme interrupt level */
  381.     int vcomIntVec;              /* vme interrupt vector */
  382.     BOOL taskLevelActive;        /* netTask is currently processing packets */
  383.     UINT8 *pAddr;                /* base address for device */
  384.     UINT8 *pSharedRam;           /* base of shared CPU/VCOM RAM */
  385.     UINT8 *pZeroPad;             /* zero padding for short packets */
  386.     void *pPortAddr;             /* port access address */
  387.     void *pCaAddr;               /* channel access address */
  388.     SCP *pScp;                   /* ptr to chip SCP structure */
  389.     ISCP *pIscp;                 /* ptr to chip ISCP structure */
  390.     SCB *pScb;                   /* ptr to chip SCB structure */
  391.     CB *pCb;                     /* ptr to chip CB structure (list) */
  392.     CB *pCbTail;                 /* ptr to last CB in chip list to process */
  393.     CB *pCbHead;                 /* ptr to first CB in chip list to process */
  394.     CB *pCbNext;                 /* ptr to next CB entry to use */
  395.     RFD *pRfd;                   /* ptr to chip first RFD structure */
  396.     RFD *pRfdHead;               /* ptr to first RFD to receive from */
  397.     TBD *pXdHead;                /* ptr to xmit buffer pool */
  398.     TBD *pXdLast;                /* ptr to last xmit buffer */
  399.     TBD *pXdNext;                /* ptr to next xmit buffer to use */
  400.     BOOL running;                /* driver initialized and running */
  401.     UINT16 nRfd;                 /* number of RFDs in use */
  402.     UINT16 nCbl;                 /* number of CB entries in use */
  403.     VCOM_DESC desc;              /* copy of device descriptor goodies */
  404.     UINT8 ownEther [EADDRS];     /* own ethernet address */
  405.     SEM_ID semId;                /* semaphore for initialization */
  406.     } VCOM_SOFTC;
  407.  
  408. #define vs_if           vs_ac.ac_if     /* network-visible interface */
  409. #define vs_enaddr       vs_ac.ac_enaddr /* hardware ethernet address */
  410. /*
  411.  * the structure arpcom looks in detail this way:
  412.  *  struct ifnet ac_if;         struct ifnet
  413.  *  UINT8 ac_enaddr [6];        ethernet hardware address
  414.  *  UINT32 ac_ipaddr.s_addr;    copy of ip address
  415.  */
  416. #ifdef __cplusplus
  417. }
  418. #endif /* __cplusplus */
  419. #endif /* __INCif_vcomh */