skdrv2nd.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. /******************************************************************************
  2. *
  3. * Name: skdrv2nd.h
  4. * Project: GEnesis, PCI Gigabit Ethernet Adapter
  5. * Version: $Revision: 1.10 $
  6. * Date: $Date: 2003/12/11 16:04:45 $
  7. * Purpose: Second header file for driver and all other modules
  8. *
  9. ******************************************************************************/
  10. /******************************************************************************
  11. *
  12. * (C)Copyright 1998-2002 SysKonnect GmbH.
  13. * (C)Copyright 2002-2003 Marvell.
  14. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License as published by
  17. * the Free Software Foundation; either version 2 of the License, or
  18. * (at your option) any later version.
  19. *
  20. * The information in this file is provided "AS IS" without warranty.
  21. *
  22. ******************************************************************************/
  23. /******************************************************************************
  24. *
  25. * Description:
  26. *
  27. * This is the second include file of the driver, which includes all other
  28. * neccessary files and defines all structures and constants used by the
  29. * driver and the common modules.
  30. *
  31. * Include File Hierarchy:
  32. *
  33. * see skge.c
  34. *
  35. ******************************************************************************/
  36. #ifndef __INC_SKDRV2ND_H
  37. #define __INC_SKDRV2ND_H
  38. #include "h/skqueue.h"
  39. #include "h/skgehwt.h"
  40. #include "h/sktimer.h"
  41. #include "h/ski2c.h"
  42. #include "h/skgepnmi.h"
  43. #include "h/skvpd.h"
  44. #include "h/skgehw.h"
  45. #include "h/skgeinit.h"
  46. #include "h/skaddr.h"
  47. #include "h/skgesirq.h"
  48. #include "h/skcsum.h"
  49. #include "h/skrlmt.h"
  50. #include "h/skgedrv.h"
  51. extern SK_MBUF *SkDrvAllocRlmtMbuf(SK_AC*, SK_IOC, unsigned);
  52. extern void SkDrvFreeRlmtMbuf(SK_AC*, SK_IOC, SK_MBUF*);
  53. extern SK_U64 SkOsGetTime(SK_AC*);
  54. extern int SkPciReadCfgDWord(SK_AC*, int, SK_U32*);
  55. extern int SkPciReadCfgWord(SK_AC*, int, SK_U16*);
  56. extern int SkPciReadCfgByte(SK_AC*, int, SK_U8*);
  57. extern int SkPciWriteCfgDWord(SK_AC*, int, SK_U32);
  58. extern int SkPciWriteCfgWord(SK_AC*, int, SK_U16);
  59. extern int SkPciWriteCfgByte(SK_AC*, int, SK_U8);
  60. extern int SkDrvEvent(SK_AC*, SK_IOC IoC, SK_U32, SK_EVPARA);
  61. #ifdef SK_DIAG_SUPPORT
  62. extern int SkDrvEnterDiagMode(SK_AC *pAc);
  63. extern int SkDrvLeaveDiagMode(SK_AC *pAc);
  64. #endif
  65. struct s_DrvRlmtMbuf {
  66. SK_MBUF *pNext; /* Pointer to next RLMT Mbuf. */
  67. SK_U8 *pData; /* Data buffer (virtually contig.). */
  68. unsigned Size; /* Data buffer size. */
  69. unsigned Length; /* Length of packet (<= Size). */
  70. SK_U32 PortIdx; /* Receiving/transmitting port. */
  71. #ifdef SK_RLMT_MBUF_PRIVATE
  72. SK_RLMT_MBUF Rlmt; /* Private part for RLMT. */
  73. #endif /* SK_RLMT_MBUF_PRIVATE */
  74. struct sk_buff *pOs; /* Pointer to message block */
  75. };
  76. /*
  77. * Time macros
  78. */
  79. #if SK_TICKS_PER_SEC == 100
  80. #define SK_PNMI_HUNDREDS_SEC(t) (t)
  81. #else
  82. #define SK_PNMI_HUNDREDS_SEC(t) ((((unsigned long)t) * 100) / \
  83. (SK_TICKS_PER_SEC))
  84. #endif
  85. /*
  86. * New SkOsGetTime
  87. */
  88. #define SkOsGetTimeCurrent(pAC, pUsec) {\
  89. struct timeval t;\
  90. do_gettimeofday(&t);\
  91. *pUsec = ((((t.tv_sec) * 1000000L)+t.tv_usec)/10000);\
  92. }
  93. /*
  94. * ioctl definitions
  95. */
  96. #define SK_IOCTL_BASE (SIOCDEVPRIVATE)
  97. #define SK_IOCTL_GETMIB (SK_IOCTL_BASE + 0)
  98. #define SK_IOCTL_SETMIB (SK_IOCTL_BASE + 1)
  99. #define SK_IOCTL_PRESETMIB (SK_IOCTL_BASE + 2)
  100. #define SK_IOCTL_GEN (SK_IOCTL_BASE + 3)
  101. #define SK_IOCTL_DIAG (SK_IOCTL_BASE + 4)
  102. typedef struct s_IOCTL SK_GE_IOCTL;
  103. struct s_IOCTL {
  104. char __user * pData;
  105. unsigned int Len;
  106. };
  107. /*
  108. * define sizes of descriptor rings in bytes
  109. */
  110. #define TX_RING_SIZE (8*1024)
  111. #define RX_RING_SIZE (24*1024)
  112. /*
  113. * Buffer size for ethernet packets
  114. */
  115. #define ETH_BUF_SIZE 1540
  116. #define ETH_MAX_MTU 1514
  117. #define ETH_MIN_MTU 60
  118. #define ETH_MULTICAST_BIT 0x01
  119. #define SK_JUMBO_MTU 9000
  120. /*
  121. * transmit priority selects the queue: LOW=asynchron, HIGH=synchron
  122. */
  123. #define TX_PRIO_LOW 0
  124. #define TX_PRIO_HIGH 1
  125. /*
  126. * alignment of rx/tx descriptors
  127. */
  128. #define DESCR_ALIGN 64
  129. /*
  130. * definitions for pnmi. TODO
  131. */
  132. #define SK_DRIVER_RESET(pAC, IoC) 0
  133. #define SK_DRIVER_SENDEVENT(pAC, IoC) 0
  134. #define SK_DRIVER_SELFTEST(pAC, IoC) 0
  135. /* For get mtu you must add an own function */
  136. #define SK_DRIVER_GET_MTU(pAc,IoC,i) 0
  137. #define SK_DRIVER_SET_MTU(pAc,IoC,i,v) 0
  138. #define SK_DRIVER_PRESET_MTU(pAc,IoC,i,v) 0
  139. /*
  140. ** Interim definition of SK_DRV_TIMER placed in this file until
  141. ** common modules have boon finallized
  142. */
  143. #define SK_DRV_TIMER 11
  144. #define SK_DRV_MODERATION_TIMER 1
  145. #define SK_DRV_MODERATION_TIMER_LENGTH 1000000 /* 1 second */
  146. #define SK_DRV_RX_CLEANUP_TIMER 2
  147. #define SK_DRV_RX_CLEANUP_TIMER_LENGTH 1000000 /* 100 millisecs */
  148. /*
  149. ** Definitions regarding transmitting frames
  150. ** any calculating any checksum.
  151. */
  152. #define C_LEN_ETHERMAC_HEADER_DEST_ADDR 6
  153. #define C_LEN_ETHERMAC_HEADER_SRC_ADDR 6
  154. #define C_LEN_ETHERMAC_HEADER_LENTYPE 2
  155. #define C_LEN_ETHERMAC_HEADER ( (C_LEN_ETHERMAC_HEADER_DEST_ADDR) + \
  156. (C_LEN_ETHERMAC_HEADER_SRC_ADDR) + \
  157. (C_LEN_ETHERMAC_HEADER_LENTYPE) )
  158. #define C_LEN_ETHERMTU_MINSIZE 46
  159. #define C_LEN_ETHERMTU_MAXSIZE_STD 1500
  160. #define C_LEN_ETHERMTU_MAXSIZE_JUMBO 9000
  161. #define C_LEN_ETHERNET_MINSIZE ( (C_LEN_ETHERMAC_HEADER) + \
  162. (C_LEN_ETHERMTU_MINSIZE) )
  163. #define C_OFFSET_IPHEADER C_LEN_ETHERMAC_HEADER
  164. #define C_OFFSET_IPHEADER_IPPROTO 9
  165. #define C_OFFSET_TCPHEADER_TCPCS 16
  166. #define C_OFFSET_UDPHEADER_UDPCS 6
  167. #define C_OFFSET_IPPROTO ( (C_LEN_ETHERMAC_HEADER) + \
  168. (C_OFFSET_IPHEADER_IPPROTO) )
  169. #define C_PROTO_ID_UDP 17 /* refer to RFC 790 or Stevens' */
  170. #define C_PROTO_ID_TCP 6 /* TCP/IP illustrated for details */
  171. /* TX and RX descriptors *****************************************************/
  172. typedef struct s_RxD RXD; /* the receive descriptor */
  173. struct s_RxD {
  174. volatile SK_U32 RBControl; /* Receive Buffer Control */
  175. SK_U32 VNextRxd; /* Next receive descriptor,low dword */
  176. SK_U32 VDataLow; /* Receive buffer Addr, low dword */
  177. SK_U32 VDataHigh; /* Receive buffer Addr, high dword */
  178. SK_U32 FrameStat; /* Receive Frame Status word */
  179. SK_U32 TimeStamp; /* Time stamp from XMAC */
  180. SK_U32 TcpSums; /* TCP Sum 2 / TCP Sum 1 */
  181. SK_U32 TcpSumStarts; /* TCP Sum Start 2 / TCP Sum Start 1 */
  182. RXD *pNextRxd; /* Pointer to next Rxd */
  183. struct sk_buff *pMBuf; /* Pointer to Linux' socket buffer */
  184. };
  185. typedef struct s_TxD TXD; /* the transmit descriptor */
  186. struct s_TxD {
  187. volatile SK_U32 TBControl; /* Transmit Buffer Control */
  188. SK_U32 VNextTxd; /* Next transmit descriptor,low dword */
  189. SK_U32 VDataLow; /* Transmit Buffer Addr, low dword */
  190. SK_U32 VDataHigh; /* Transmit Buffer Addr, high dword */
  191. SK_U32 FrameStat; /* Transmit Frame Status Word */
  192. SK_U32 TcpSumOfs; /* Reserved / TCP Sum Offset */
  193. SK_U16 TcpSumSt; /* TCP Sum Start */
  194. SK_U16 TcpSumWr; /* TCP Sum Write */
  195. SK_U32 TcpReserved; /* not used */
  196. TXD *pNextTxd; /* Pointer to next Txd */
  197. struct sk_buff *pMBuf; /* Pointer to Linux' socket buffer */
  198. };
  199. /* Used interrupt bits in the interrupts source register *********************/
  200. #define DRIVER_IRQS ((IS_IRQ_SW) | \
  201. (IS_R1_F) |(IS_R2_F) | \
  202. (IS_XS1_F) |(IS_XA1_F) | \
  203. (IS_XS2_F) |(IS_XA2_F))
  204. #define SPECIAL_IRQS ((IS_HW_ERR) |(IS_I2C_READY) | \
  205. (IS_EXT_REG) |(IS_TIMINT) | \
  206. (IS_PA_TO_RX1) |(IS_PA_TO_RX2) | \
  207. (IS_PA_TO_TX1) |(IS_PA_TO_TX2) | \
  208. (IS_MAC1) |(IS_LNK_SYNC_M1)| \
  209. (IS_MAC2) |(IS_LNK_SYNC_M2)| \
  210. (IS_R1_C) |(IS_R2_C) | \
  211. (IS_XS1_C) |(IS_XA1_C) | \
  212. (IS_XS2_C) |(IS_XA2_C))
  213. #define IRQ_MASK ((IS_IRQ_SW) | \
  214. (IS_R1_B) |(IS_R1_F) |(IS_R2_B) |(IS_R2_F) | \
  215. (IS_XS1_B) |(IS_XS1_F) |(IS_XA1_B)|(IS_XA1_F)| \
  216. (IS_XS2_B) |(IS_XS2_F) |(IS_XA2_B)|(IS_XA2_F)| \
  217. (IS_HW_ERR) |(IS_I2C_READY)| \
  218. (IS_EXT_REG) |(IS_TIMINT) | \
  219. (IS_PA_TO_RX1) |(IS_PA_TO_RX2)| \
  220. (IS_PA_TO_TX1) |(IS_PA_TO_TX2)| \
  221. (IS_MAC1) |(IS_MAC2) | \
  222. (IS_R1_C) |(IS_R2_C) | \
  223. (IS_XS1_C) |(IS_XA1_C) | \
  224. (IS_XS2_C) |(IS_XA2_C))
  225. #define IRQ_HWE_MASK (IS_ERR_MSK) /* enable all HW irqs */
  226. typedef struct s_DevNet DEV_NET;
  227. struct s_DevNet {
  228. int PortNr;
  229. int NetNr;
  230. int Mtu;
  231. int Up;
  232. SK_AC *pAC;
  233. };
  234. typedef struct s_TxPort TX_PORT;
  235. struct s_TxPort {
  236. /* the transmit descriptor rings */
  237. caddr_t pTxDescrRing; /* descriptor area memory */
  238. SK_U64 VTxDescrRing; /* descr. area bus virt. addr. */
  239. TXD *pTxdRingHead; /* Head of Tx rings */
  240. TXD *pTxdRingTail; /* Tail of Tx rings */
  241. TXD *pTxdRingPrev; /* descriptor sent previously */
  242. int TxdRingFree; /* # of free entrys */
  243. spinlock_t TxDesRingLock; /* serialize descriptor accesses */
  244. SK_IOC HwAddr; /* bmu registers address */
  245. int PortIndex; /* index number of port (0 or 1) */
  246. };
  247. typedef struct s_RxPort RX_PORT;
  248. struct s_RxPort {
  249. /* the receive descriptor rings */
  250. caddr_t pRxDescrRing; /* descriptor area memory */
  251. SK_U64 VRxDescrRing; /* descr. area bus virt. addr. */
  252. RXD *pRxdRingHead; /* Head of Rx rings */
  253. RXD *pRxdRingTail; /* Tail of Rx rings */
  254. RXD *pRxdRingPrev; /* descriptor given to BMU previously */
  255. int RxdRingFree; /* # of free entrys */
  256. spinlock_t RxDesRingLock; /* serialize descriptor accesses */
  257. int RxFillLimit; /* limit for buffers in ring */
  258. SK_IOC HwAddr; /* bmu registers address */
  259. int PortIndex; /* index number of port (0 or 1) */
  260. };
  261. /* Definitions needed for interrupt moderation *******************************/
  262. #define IRQ_EOF_AS_TX ((IS_XA1_F) | (IS_XA2_F))
  263. #define IRQ_EOF_SY_TX ((IS_XS1_F) | (IS_XS2_F))
  264. #define IRQ_MASK_TX_ONLY ((IRQ_EOF_AS_TX)| (IRQ_EOF_SY_TX))
  265. #define IRQ_MASK_RX_ONLY ((IS_R1_F) | (IS_R2_F))
  266. #define IRQ_MASK_SP_ONLY (SPECIAL_IRQS)
  267. #define IRQ_MASK_TX_RX ((IRQ_MASK_TX_ONLY)| (IRQ_MASK_RX_ONLY))
  268. #define IRQ_MASK_SP_RX ((SPECIAL_IRQS) | (IRQ_MASK_RX_ONLY))
  269. #define IRQ_MASK_SP_TX ((SPECIAL_IRQS) | (IRQ_MASK_TX_ONLY))
  270. #define IRQ_MASK_RX_TX_SP ((SPECIAL_IRQS) | (IRQ_MASK_TX_RX))
  271. #define C_INT_MOD_NONE 1
  272. #define C_INT_MOD_STATIC 2
  273. #define C_INT_MOD_DYNAMIC 4
  274. #define C_CLK_FREQ_GENESIS 53215000 /* shorter: 53.125 MHz */
  275. #define C_CLK_FREQ_YUKON 78215000 /* shorter: 78.125 MHz */
  276. #define C_INTS_PER_SEC_DEFAULT 2000
  277. #define C_INT_MOD_ENABLE_PERCENTAGE 50 /* if higher 50% enable */
  278. #define C_INT_MOD_DISABLE_PERCENTAGE 50 /* if lower 50% disable */
  279. #define C_INT_MOD_IPS_LOWER_RANGE 30
  280. #define C_INT_MOD_IPS_UPPER_RANGE 40000
  281. typedef struct s_DynIrqModInfo DIM_INFO;
  282. struct s_DynIrqModInfo {
  283. unsigned long PrevTimeVal;
  284. unsigned int PrevSysLoad;
  285. unsigned int PrevUsedTime;
  286. unsigned int PrevTotalTime;
  287. int PrevUsedDescrRatio;
  288. int NbrProcessedDescr;
  289. SK_U64 PrevPort0RxIntrCts;
  290. SK_U64 PrevPort1RxIntrCts;
  291. SK_U64 PrevPort0TxIntrCts;
  292. SK_U64 PrevPort1TxIntrCts;
  293. SK_BOOL ModJustEnabled; /* Moderation just enabled yes/no */
  294. int MaxModIntsPerSec; /* Moderation Threshold */
  295. int MaxModIntsPerSecUpperLimit; /* Upper limit for DIM */
  296. int MaxModIntsPerSecLowerLimit; /* Lower limit for DIM */
  297. long MaskIrqModeration; /* ModIrqType (eg. 'TxRx') */
  298. SK_BOOL DisplayStats; /* Stats yes/no */
  299. SK_BOOL AutoSizing; /* Resize DIM-timer on/off */
  300. int IntModTypeSelect; /* EnableIntMod (eg. 'dynamic') */
  301. SK_TIMER ModTimer; /* just some timer */
  302. };
  303. typedef struct s_PerStrm PER_STRM;
  304. #define SK_ALLOC_IRQ 0x00000001
  305. #ifdef SK_DIAG_SUPPORT
  306. #define DIAG_ACTIVE 1
  307. #define DIAG_NOTACTIVE 0
  308. #endif
  309. /****************************************************************************
  310. * Per board structure / Adapter Context structure:
  311. * Allocated within attach(9e) and freed within detach(9e).
  312. * Contains all 'per device' necessary handles, flags, locks etc.:
  313. */
  314. struct s_AC {
  315. SK_GEINIT GIni; /* GE init struct */
  316. SK_PNMI Pnmi; /* PNMI data struct */
  317. SK_VPD vpd; /* vpd data struct */
  318. SK_QUEUE Event; /* Event queue */
  319. SK_HWT Hwt; /* Hardware Timer control struct */
  320. SK_TIMCTRL Tim; /* Software Timer control struct */
  321. SK_I2C I2c; /* I2C relevant data structure */
  322. SK_ADDR Addr; /* for Address module */
  323. SK_CSUM Csum; /* for checksum module */
  324. SK_RLMT Rlmt; /* for rlmt module */
  325. spinlock_t SlowPathLock; /* Normal IRQ lock */
  326. struct timer_list BlinkTimer; /* for LED blinking */
  327. int LedsOn;
  328. SK_PNMI_STRUCT_DATA PnmiStruct; /* structure to get all Pnmi-Data */
  329. int RlmtMode; /* link check mode to set */
  330. int RlmtNets; /* Number of nets */
  331. SK_IOC IoBase; /* register set of adapter */
  332. int BoardLevel; /* level of active hw init (0-2) */
  333. char DeviceStr[80]; /* adapter string from vpd */
  334. SK_U32 AllocFlag; /* flag allocation of resources */
  335. struct pci_dev *PciDev; /* for access to pci config space */
  336. SK_U32 PciDevId; /* pci device id */
  337. struct SK_NET_DEVICE *dev[2]; /* pointer to device struct */
  338. char Name[30]; /* driver name */
  339. int RxBufSize; /* length of receive buffers */
  340. struct net_device_stats stats; /* linux 'netstat -i' statistics */
  341. int Index; /* internal board index number */
  342. /* adapter RAM sizes for queues of active port */
  343. int RxQueueSize; /* memory used for receive queue */
  344. int TxSQueueSize; /* memory used for sync. tx queue */
  345. int TxAQueueSize; /* memory used for async. tx queue */
  346. int PromiscCount; /* promiscuous mode counter */
  347. int AllMultiCount; /* allmulticast mode counter */
  348. int MulticCount; /* number of different MC */
  349. /* addresses for this board */
  350. /* (may be more than HW can)*/
  351. int HWRevision; /* Hardware revision */
  352. int ActivePort; /* the active XMAC port */
  353. int MaxPorts; /* number of activated ports */
  354. int TxDescrPerRing; /* # of descriptors per tx ring */
  355. int RxDescrPerRing; /* # of descriptors per rx ring */
  356. caddr_t pDescrMem; /* Pointer to the descriptor area */
  357. dma_addr_t pDescrMemDMA; /* PCI DMA address of area */
  358. /* the port structures with descriptor rings */
  359. TX_PORT TxPort[SK_MAX_MACS][2];
  360. RX_PORT RxPort[SK_MAX_MACS];
  361. unsigned int CsOfs1; /* for checksum calculation */
  362. unsigned int CsOfs2; /* for checksum calculation */
  363. SK_U32 CsOfs; /* for checksum calculation */
  364. SK_BOOL CheckQueue; /* check event queue soon */
  365. SK_TIMER DrvCleanupTimer;/* to check for pending descriptors */
  366. DIM_INFO DynIrqModInfo; /* all data related to DIM */
  367. /* Only for tests */
  368. int PortUp;
  369. int PortDown;
  370. int ChipsetType; /* Chipset family type
  371. * 0 == Genesis family support
  372. * 1 == Yukon family support
  373. */
  374. #ifdef SK_DIAG_SUPPORT
  375. SK_U32 DiagModeActive; /* is diag active? */
  376. SK_BOOL DiagFlowCtrl; /* for control purposes */
  377. SK_PNMI_STRUCT_DATA PnmiBackup; /* backup structure for all Pnmi-Data */
  378. SK_BOOL WasIfUp[SK_MAX_MACS]; /* for OpenClose while
  379. * DIAG is busy with NIC
  380. */
  381. #endif
  382. };
  383. #endif /* __INC_SKDRV2ND_H */