s2io.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830
  1. /************************************************************************
  2. * s2io.h: A Linux PCI-X Ethernet driver for S2IO 10GbE Server NIC
  3. * Copyright(c) 2002-2005 Neterion Inc.
  4. * This software may be used and distributed according to the terms of
  5. * the GNU General Public License (GPL), incorporated herein by reference.
  6. * Drivers based on or derived from this code fall under the GPL and must
  7. * retain the authorship, copyright and license notice. This file is not
  8. * a complete program and may only be used when the entire operating
  9. * system is licensed under the GPL.
  10. * See the file COPYING in this distribution for more information.
  11. ************************************************************************/
  12. #ifndef _S2IO_H
  13. #define _S2IO_H
  14. /* Enable 2 buffer mode by default for SGI system */
  15. #ifdef CONFIG_IA64_SGI_SN2
  16. #define CONFIG_2BUFF_MODE
  17. #endif
  18. #define TBD 0
  19. #define BIT(loc) (0x8000000000000000ULL >> (loc))
  20. #define vBIT(val, loc, sz) (((u64)val) << (64-loc-sz))
  21. #define INV(d) ((d&0xff)<<24) | (((d>>8)&0xff)<<16) | (((d>>16)&0xff)<<8)| ((d>>24)&0xff)
  22. #ifndef BOOL
  23. #define BOOL int
  24. #endif
  25. #ifndef TRUE
  26. #define TRUE 1
  27. #define FALSE 0
  28. #endif
  29. #undef SUCCESS
  30. #define SUCCESS 0
  31. #define FAILURE -1
  32. /* Maximum time to flicker LED when asked to identify NIC using ethtool */
  33. #define MAX_FLICKER_TIME 60000 /* 60 Secs */
  34. /* Maximum outstanding splits to be configured into xena. */
  35. typedef enum xena_max_outstanding_splits {
  36. XENA_ONE_SPLIT_TRANSACTION = 0,
  37. XENA_TWO_SPLIT_TRANSACTION = 1,
  38. XENA_THREE_SPLIT_TRANSACTION = 2,
  39. XENA_FOUR_SPLIT_TRANSACTION = 3,
  40. XENA_EIGHT_SPLIT_TRANSACTION = 4,
  41. XENA_TWELVE_SPLIT_TRANSACTION = 5,
  42. XENA_SIXTEEN_SPLIT_TRANSACTION = 6,
  43. XENA_THIRTYTWO_SPLIT_TRANSACTION = 7
  44. } xena_max_outstanding_splits;
  45. #define XENA_MAX_OUTSTANDING_SPLITS(n) (n << 4)
  46. /* OS concerned variables and constants */
  47. #define WATCH_DOG_TIMEOUT 15*HZ
  48. #define EFILL 0x1234
  49. #define ALIGN_SIZE 127
  50. #define PCIX_COMMAND_REGISTER 0x62
  51. /*
  52. * Debug related variables.
  53. */
  54. /* different debug levels. */
  55. #define ERR_DBG 0
  56. #define INIT_DBG 1
  57. #define INFO_DBG 2
  58. #define TX_DBG 3
  59. #define INTR_DBG 4
  60. /* Global variable that defines the present debug level of the driver. */
  61. int debug_level = ERR_DBG; /* Default level. */
  62. /* DEBUG message print. */
  63. #define DBG_PRINT(dbg_level, args...) if(!(debug_level<dbg_level)) printk(args)
  64. /* Protocol assist features of the NIC */
  65. #define L3_CKSUM_OK 0xFFFF
  66. #define L4_CKSUM_OK 0xFFFF
  67. #define S2IO_JUMBO_SIZE 9600
  68. /* Driver statistics maintained by driver */
  69. typedef struct {
  70. unsigned long long single_ecc_errs;
  71. unsigned long long double_ecc_errs;
  72. } swStat_t;
  73. /* The statistics block of Xena */
  74. typedef struct stat_block {
  75. /* Tx MAC statistics counters. */
  76. u32 tmac_data_octets;
  77. u32 tmac_frms;
  78. u64 tmac_drop_frms;
  79. u32 tmac_bcst_frms;
  80. u32 tmac_mcst_frms;
  81. u64 tmac_pause_ctrl_frms;
  82. u32 tmac_ucst_frms;
  83. u32 tmac_ttl_octets;
  84. u32 tmac_any_err_frms;
  85. u32 tmac_nucst_frms;
  86. u64 tmac_ttl_less_fb_octets;
  87. u64 tmac_vld_ip_octets;
  88. u32 tmac_drop_ip;
  89. u32 tmac_vld_ip;
  90. u32 tmac_rst_tcp;
  91. u32 tmac_icmp;
  92. u64 tmac_tcp;
  93. u32 reserved_0;
  94. u32 tmac_udp;
  95. /* Rx MAC Statistics counters. */
  96. u32 rmac_data_octets;
  97. u32 rmac_vld_frms;
  98. u64 rmac_fcs_err_frms;
  99. u64 rmac_drop_frms;
  100. u32 rmac_vld_bcst_frms;
  101. u32 rmac_vld_mcst_frms;
  102. u32 rmac_out_rng_len_err_frms;
  103. u32 rmac_in_rng_len_err_frms;
  104. u64 rmac_long_frms;
  105. u64 rmac_pause_ctrl_frms;
  106. u64 rmac_unsup_ctrl_frms;
  107. u32 rmac_accepted_ucst_frms;
  108. u32 rmac_ttl_octets;
  109. u32 rmac_discarded_frms;
  110. u32 rmac_accepted_nucst_frms;
  111. u32 reserved_1;
  112. u32 rmac_drop_events;
  113. u64 rmac_ttl_less_fb_octets;
  114. u64 rmac_ttl_frms;
  115. u64 reserved_2;
  116. u32 rmac_usized_frms;
  117. u32 reserved_3;
  118. u32 rmac_frag_frms;
  119. u32 rmac_osized_frms;
  120. u32 reserved_4;
  121. u32 rmac_jabber_frms;
  122. u64 rmac_ttl_64_frms;
  123. u64 rmac_ttl_65_127_frms;
  124. u64 reserved_5;
  125. u64 rmac_ttl_128_255_frms;
  126. u64 rmac_ttl_256_511_frms;
  127. u64 reserved_6;
  128. u64 rmac_ttl_512_1023_frms;
  129. u64 rmac_ttl_1024_1518_frms;
  130. u32 rmac_ip;
  131. u32 reserved_7;
  132. u64 rmac_ip_octets;
  133. u32 rmac_drop_ip;
  134. u32 rmac_hdr_err_ip;
  135. u32 reserved_8;
  136. u32 rmac_icmp;
  137. u64 rmac_tcp;
  138. u32 rmac_err_drp_udp;
  139. u32 rmac_udp;
  140. u64 rmac_xgmii_err_sym;
  141. u64 rmac_frms_q0;
  142. u64 rmac_frms_q1;
  143. u64 rmac_frms_q2;
  144. u64 rmac_frms_q3;
  145. u64 rmac_frms_q4;
  146. u64 rmac_frms_q5;
  147. u64 rmac_frms_q6;
  148. u64 rmac_frms_q7;
  149. u16 rmac_full_q3;
  150. u16 rmac_full_q2;
  151. u16 rmac_full_q1;
  152. u16 rmac_full_q0;
  153. u16 rmac_full_q7;
  154. u16 rmac_full_q6;
  155. u16 rmac_full_q5;
  156. u16 rmac_full_q4;
  157. u32 reserved_9;
  158. u32 rmac_pause_cnt;
  159. u64 rmac_xgmii_data_err_cnt;
  160. u64 rmac_xgmii_ctrl_err_cnt;
  161. u32 rmac_err_tcp;
  162. u32 rmac_accepted_ip;
  163. /* PCI/PCI-X Read transaction statistics. */
  164. u32 new_rd_req_cnt;
  165. u32 rd_req_cnt;
  166. u32 rd_rtry_cnt;
  167. u32 new_rd_req_rtry_cnt;
  168. /* PCI/PCI-X Write/Read transaction statistics. */
  169. u32 wr_req_cnt;
  170. u32 wr_rtry_rd_ack_cnt;
  171. u32 new_wr_req_rtry_cnt;
  172. u32 new_wr_req_cnt;
  173. u32 wr_disc_cnt;
  174. u32 wr_rtry_cnt;
  175. /* PCI/PCI-X Write / DMA Transaction statistics. */
  176. u32 txp_wr_cnt;
  177. u32 rd_rtry_wr_ack_cnt;
  178. u32 txd_wr_cnt;
  179. u32 txd_rd_cnt;
  180. u32 rxd_wr_cnt;
  181. u32 rxd_rd_cnt;
  182. u32 rxf_wr_cnt;
  183. u32 txf_rd_cnt;
  184. /* Software statistics maintained by driver */
  185. swStat_t sw_stat;
  186. } StatInfo_t;
  187. /*
  188. * Structures representing different init time configuration
  189. * parameters of the NIC.
  190. */
  191. #define MAX_TX_FIFOS 8
  192. #define MAX_RX_RINGS 8
  193. /* FIFO mappings for all possible number of fifos configured */
  194. int fifo_map[][MAX_TX_FIFOS] = {
  195. {0, 0, 0, 0, 0, 0, 0, 0},
  196. {0, 0, 0, 0, 1, 1, 1, 1},
  197. {0, 0, 0, 1, 1, 1, 2, 2},
  198. {0, 0, 1, 1, 2, 2, 3, 3},
  199. {0, 0, 1, 1, 2, 2, 3, 4},
  200. {0, 0, 1, 1, 2, 3, 4, 5},
  201. {0, 0, 1, 2, 3, 4, 5, 6},
  202. {0, 1, 2, 3, 4, 5, 6, 7},
  203. };
  204. /* Maintains Per FIFO related information. */
  205. typedef struct tx_fifo_config {
  206. #define MAX_AVAILABLE_TXDS 8192
  207. u32 fifo_len; /* specifies len of FIFO upto 8192, ie no of TxDLs */
  208. /* Priority definition */
  209. #define TX_FIFO_PRI_0 0 /*Highest */
  210. #define TX_FIFO_PRI_1 1
  211. #define TX_FIFO_PRI_2 2
  212. #define TX_FIFO_PRI_3 3
  213. #define TX_FIFO_PRI_4 4
  214. #define TX_FIFO_PRI_5 5
  215. #define TX_FIFO_PRI_6 6
  216. #define TX_FIFO_PRI_7 7 /*lowest */
  217. u8 fifo_priority; /* specifies pointer level for FIFO */
  218. /* user should not set twos fifos with same pri */
  219. u8 f_no_snoop;
  220. #define NO_SNOOP_TXD 0x01
  221. #define NO_SNOOP_TXD_BUFFER 0x02
  222. } tx_fifo_config_t;
  223. /* Maintains per Ring related information */
  224. typedef struct rx_ring_config {
  225. u32 num_rxd; /*No of RxDs per Rx Ring */
  226. #define RX_RING_PRI_0 0 /* highest */
  227. #define RX_RING_PRI_1 1
  228. #define RX_RING_PRI_2 2
  229. #define RX_RING_PRI_3 3
  230. #define RX_RING_PRI_4 4
  231. #define RX_RING_PRI_5 5
  232. #define RX_RING_PRI_6 6
  233. #define RX_RING_PRI_7 7 /* lowest */
  234. u8 ring_priority; /*Specifies service priority of ring */
  235. /* OSM should not set any two rings with same priority */
  236. u8 ring_org; /*Organization of ring */
  237. #define RING_ORG_BUFF1 0x01
  238. #define RX_RING_ORG_BUFF3 0x03
  239. #define RX_RING_ORG_BUFF5 0x05
  240. u8 f_no_snoop;
  241. #define NO_SNOOP_RXD 0x01
  242. #define NO_SNOOP_RXD_BUFFER 0x02
  243. } rx_ring_config_t;
  244. /* This structure provides contains values of the tunable parameters
  245. * of the H/W
  246. */
  247. struct config_param {
  248. /* Tx Side */
  249. u32 tx_fifo_num; /*Number of Tx FIFOs */
  250. u8 fifo_mapping[MAX_TX_FIFOS];
  251. tx_fifo_config_t tx_cfg[MAX_TX_FIFOS]; /*Per-Tx FIFO config */
  252. u32 max_txds; /*Max no. of Tx buffer descriptor per TxDL */
  253. u64 tx_intr_type;
  254. /* Specifies if Tx Intr is UTILZ or PER_LIST type. */
  255. /* Rx Side */
  256. u32 rx_ring_num; /*Number of receive rings */
  257. #define MAX_RX_BLOCKS_PER_RING 150
  258. rx_ring_config_t rx_cfg[MAX_RX_RINGS]; /*Per-Rx Ring config */
  259. #define HEADER_ETHERNET_II_802_3_SIZE 14
  260. #define HEADER_802_2_SIZE 3
  261. #define HEADER_SNAP_SIZE 5
  262. #define HEADER_VLAN_SIZE 4
  263. #define MIN_MTU 46
  264. #define MAX_PYLD 1500
  265. #define MAX_MTU (MAX_PYLD+18)
  266. #define MAX_MTU_VLAN (MAX_PYLD+22)
  267. #define MAX_PYLD_JUMBO 9600
  268. #define MAX_MTU_JUMBO (MAX_PYLD_JUMBO+18)
  269. #define MAX_MTU_JUMBO_VLAN (MAX_PYLD_JUMBO+22)
  270. u16 bus_speed;
  271. };
  272. /* Structure representing MAC Addrs */
  273. typedef struct mac_addr {
  274. u8 mac_addr[ETH_ALEN];
  275. } macaddr_t;
  276. /* Structure that represent every FIFO element in the BAR1
  277. * Address location.
  278. */
  279. typedef struct _TxFIFO_element {
  280. u64 TxDL_Pointer;
  281. u64 List_Control;
  282. #define TX_FIFO_LAST_TXD_NUM( val) vBIT(val,0,8)
  283. #define TX_FIFO_FIRST_LIST BIT(14)
  284. #define TX_FIFO_LAST_LIST BIT(15)
  285. #define TX_FIFO_FIRSTNLAST_LIST vBIT(3,14,2)
  286. #define TX_FIFO_SPECIAL_FUNC BIT(23)
  287. #define TX_FIFO_DS_NO_SNOOP BIT(31)
  288. #define TX_FIFO_BUFF_NO_SNOOP BIT(30)
  289. } TxFIFO_element_t;
  290. /* Tx descriptor structure */
  291. typedef struct _TxD {
  292. u64 Control_1;
  293. /* bit mask */
  294. #define TXD_LIST_OWN_XENA BIT(7)
  295. #define TXD_T_CODE (BIT(12)|BIT(13)|BIT(14)|BIT(15))
  296. #define TXD_T_CODE_OK(val) (|(val & TXD_T_CODE))
  297. #define GET_TXD_T_CODE(val) ((val & TXD_T_CODE)<<12)
  298. #define TXD_GATHER_CODE (BIT(22) | BIT(23))
  299. #define TXD_GATHER_CODE_FIRST BIT(22)
  300. #define TXD_GATHER_CODE_LAST BIT(23)
  301. #define TXD_TCP_LSO_EN BIT(30)
  302. #define TXD_UDP_COF_EN BIT(31)
  303. #define TXD_TCP_LSO_MSS(val) vBIT(val,34,14)
  304. #define TXD_BUFFER0_SIZE(val) vBIT(val,48,16)
  305. u64 Control_2;
  306. #define TXD_TX_CKO_CONTROL (BIT(5)|BIT(6)|BIT(7))
  307. #define TXD_TX_CKO_IPV4_EN BIT(5)
  308. #define TXD_TX_CKO_TCP_EN BIT(6)
  309. #define TXD_TX_CKO_UDP_EN BIT(7)
  310. #define TXD_VLAN_ENABLE BIT(15)
  311. #define TXD_VLAN_TAG(val) vBIT(val,16,16)
  312. #define TXD_INT_NUMBER(val) vBIT(val,34,6)
  313. #define TXD_INT_TYPE_PER_LIST BIT(47)
  314. #define TXD_INT_TYPE_UTILZ BIT(46)
  315. #define TXD_SET_MARKER vBIT(0x6,0,4)
  316. u64 Buffer_Pointer;
  317. u64 Host_Control; /* reserved for host */
  318. } TxD_t;
  319. /* Structure to hold the phy and virt addr of every TxDL. */
  320. typedef struct list_info_hold {
  321. dma_addr_t list_phy_addr;
  322. void *list_virt_addr;
  323. } list_info_hold_t;
  324. /* Rx descriptor structure */
  325. typedef struct _RxD_t {
  326. u64 Host_Control; /* reserved for host */
  327. u64 Control_1;
  328. #define RXD_OWN_XENA BIT(7)
  329. #define RXD_T_CODE (BIT(12)|BIT(13)|BIT(14)|BIT(15))
  330. #define RXD_FRAME_PROTO vBIT(0xFFFF,24,8)
  331. #define RXD_FRAME_PROTO_IPV4 BIT(27)
  332. #define RXD_FRAME_PROTO_IPV6 BIT(28)
  333. #define RXD_FRAME_IP_FRAG BIT(29)
  334. #define RXD_FRAME_PROTO_TCP BIT(30)
  335. #define RXD_FRAME_PROTO_UDP BIT(31)
  336. #define TCP_OR_UDP_FRAME (RXD_FRAME_PROTO_TCP | RXD_FRAME_PROTO_UDP)
  337. #define RXD_GET_L3_CKSUM(val) ((u16)(val>> 16) & 0xFFFF)
  338. #define RXD_GET_L4_CKSUM(val) ((u16)(val) & 0xFFFF)
  339. u64 Control_2;
  340. #define THE_RXD_MARK 0x3
  341. #define SET_RXD_MARKER vBIT(THE_RXD_MARK, 0, 2)
  342. #define GET_RXD_MARKER(ctrl) ((ctrl & SET_RXD_MARKER) >> 62)
  343. #ifndef CONFIG_2BUFF_MODE
  344. #define MASK_BUFFER0_SIZE vBIT(0x3FFF,2,14)
  345. #define SET_BUFFER0_SIZE(val) vBIT(val,2,14)
  346. #else
  347. #define MASK_BUFFER0_SIZE vBIT(0xFF,2,14)
  348. #define MASK_BUFFER1_SIZE vBIT(0xFFFF,16,16)
  349. #define MASK_BUFFER2_SIZE vBIT(0xFFFF,32,16)
  350. #define SET_BUFFER0_SIZE(val) vBIT(val,8,8)
  351. #define SET_BUFFER1_SIZE(val) vBIT(val,16,16)
  352. #define SET_BUFFER2_SIZE(val) vBIT(val,32,16)
  353. #endif
  354. #define MASK_VLAN_TAG vBIT(0xFFFF,48,16)
  355. #define SET_VLAN_TAG(val) vBIT(val,48,16)
  356. #define SET_NUM_TAG(val) vBIT(val,16,32)
  357. #ifndef CONFIG_2BUFF_MODE
  358. #define RXD_GET_BUFFER0_SIZE(Control_2) (u64)((Control_2 & vBIT(0x3FFF,2,14)))
  359. #else
  360. #define RXD_GET_BUFFER0_SIZE(Control_2) (u8)((Control_2 & MASK_BUFFER0_SIZE) \
  361. >> 48)
  362. #define RXD_GET_BUFFER1_SIZE(Control_2) (u16)((Control_2 & MASK_BUFFER1_SIZE) \
  363. >> 32)
  364. #define RXD_GET_BUFFER2_SIZE(Control_2) (u16)((Control_2 & MASK_BUFFER2_SIZE) \
  365. >> 16)
  366. #define BUF0_LEN 40
  367. #define BUF1_LEN 1
  368. #endif
  369. u64 Buffer0_ptr;
  370. #ifdef CONFIG_2BUFF_MODE
  371. u64 Buffer1_ptr;
  372. u64 Buffer2_ptr;
  373. #endif
  374. } RxD_t;
  375. /* Structure that represents the Rx descriptor block which contains
  376. * 128 Rx descriptors.
  377. */
  378. #ifndef CONFIG_2BUFF_MODE
  379. typedef struct _RxD_block {
  380. #define MAX_RXDS_PER_BLOCK 127
  381. RxD_t rxd[MAX_RXDS_PER_BLOCK];
  382. u64 reserved_0;
  383. #define END_OF_BLOCK 0xFEFFFFFFFFFFFFFFULL
  384. u64 reserved_1; /* 0xFEFFFFFFFFFFFFFF to mark last
  385. * Rxd in this blk */
  386. u64 reserved_2_pNext_RxD_block; /* Logical ptr to next */
  387. u64 pNext_RxD_Blk_physical; /* Buff0_ptr.In a 32 bit arch
  388. * the upper 32 bits should
  389. * be 0 */
  390. } RxD_block_t;
  391. #else
  392. typedef struct _RxD_block {
  393. #define MAX_RXDS_PER_BLOCK 85
  394. RxD_t rxd[MAX_RXDS_PER_BLOCK];
  395. #define END_OF_BLOCK 0xFEFFFFFFFFFFFFFFULL
  396. u64 reserved_1; /* 0xFEFFFFFFFFFFFFFF to mark last Rxd
  397. * in this blk */
  398. u64 pNext_RxD_Blk_physical; /* Phy ponter to next blk. */
  399. } RxD_block_t;
  400. #define SIZE_OF_BLOCK 4096
  401. /* Structure to hold virtual addresses of Buf0 and Buf1 in
  402. * 2buf mode. */
  403. typedef struct bufAdd {
  404. void *ba_0_org;
  405. void *ba_1_org;
  406. void *ba_0;
  407. void *ba_1;
  408. } buffAdd_t;
  409. #endif
  410. /* Structure which stores all the MAC control parameters */
  411. /* This structure stores the offset of the RxD in the ring
  412. * from which the Rx Interrupt processor can start picking
  413. * up the RxDs for processing.
  414. */
  415. typedef struct _rx_curr_get_info_t {
  416. u32 block_index;
  417. u32 offset;
  418. u32 ring_len;
  419. } rx_curr_get_info_t;
  420. typedef rx_curr_get_info_t rx_curr_put_info_t;
  421. /* This structure stores the offset of the TxDl in the FIFO
  422. * from which the Tx Interrupt processor can start picking
  423. * up the TxDLs for send complete interrupt processing.
  424. */
  425. typedef struct {
  426. u32 offset;
  427. u32 fifo_len;
  428. } tx_curr_get_info_t;
  429. typedef tx_curr_get_info_t tx_curr_put_info_t;
  430. /* Structure that holds the Phy and virt addresses of the Blocks */
  431. typedef struct rx_block_info {
  432. RxD_t *block_virt_addr;
  433. dma_addr_t block_dma_addr;
  434. } rx_block_info_t;
  435. /* pre declaration of the nic structure */
  436. typedef struct s2io_nic nic_t;
  437. /* Ring specific structure */
  438. typedef struct ring_info {
  439. /* The ring number */
  440. int ring_no;
  441. /*
  442. * Place holders for the virtual and physical addresses of
  443. * all the Rx Blocks
  444. */
  445. rx_block_info_t rx_blocks[MAX_RX_BLOCKS_PER_RING];
  446. int block_count;
  447. int pkt_cnt;
  448. /*
  449. * Put pointer info which indictes which RxD has to be replenished
  450. * with a new buffer.
  451. */
  452. rx_curr_put_info_t rx_curr_put_info;
  453. /*
  454. * Get pointer info which indictes which is the last RxD that was
  455. * processed by the driver.
  456. */
  457. rx_curr_get_info_t rx_curr_get_info;
  458. #ifndef CONFIG_S2IO_NAPI
  459. /* Index to the absolute position of the put pointer of Rx ring */
  460. int put_pos;
  461. #endif
  462. #ifdef CONFIG_2BUFF_MODE
  463. /* Buffer Address store. */
  464. buffAdd_t **ba;
  465. #endif
  466. nic_t *nic;
  467. } ring_info_t;
  468. /* Fifo specific structure */
  469. typedef struct fifo_info {
  470. /* FIFO number */
  471. int fifo_no;
  472. /* Maximum TxDs per TxDL */
  473. int max_txds;
  474. /* Place holder of all the TX List's Phy and Virt addresses. */
  475. list_info_hold_t *list_info;
  476. /*
  477. * Current offset within the tx FIFO where driver would write
  478. * new Tx frame
  479. */
  480. tx_curr_put_info_t tx_curr_put_info;
  481. /*
  482. * Current offset within tx FIFO from where the driver would start freeing
  483. * the buffers
  484. */
  485. tx_curr_get_info_t tx_curr_get_info;
  486. nic_t *nic;
  487. }fifo_info_t;
  488. /* Infomation related to the Tx and Rx FIFOs and Rings of Xena
  489. * is maintained in this structure.
  490. */
  491. typedef struct mac_info {
  492. /* tx side stuff */
  493. /* logical pointer of start of each Tx FIFO */
  494. TxFIFO_element_t __iomem *tx_FIFO_start[MAX_TX_FIFOS];
  495. /* Fifo specific structure */
  496. fifo_info_t fifos[MAX_TX_FIFOS];
  497. /* rx side stuff */
  498. /* Ring specific structure */
  499. ring_info_t rings[MAX_RX_RINGS];
  500. u16 rmac_pause_time;
  501. u16 mc_pause_threshold_q0q3;
  502. u16 mc_pause_threshold_q4q7;
  503. void *stats_mem; /* orignal pointer to allocated mem */
  504. dma_addr_t stats_mem_phy; /* Physical address of the stat block */
  505. u32 stats_mem_sz;
  506. StatInfo_t *stats_info; /* Logical address of the stat block */
  507. } mac_info_t;
  508. /* structure representing the user defined MAC addresses */
  509. typedef struct {
  510. char addr[ETH_ALEN];
  511. int usage_cnt;
  512. } usr_addr_t;
  513. /* Default Tunable parameters of the NIC. */
  514. #define DEFAULT_FIFO_LEN 4096
  515. #define SMALL_RXD_CNT 30 * (MAX_RXDS_PER_BLOCK+1)
  516. #define LARGE_RXD_CNT 100 * (MAX_RXDS_PER_BLOCK+1)
  517. #define SMALL_BLK_CNT 30
  518. #define LARGE_BLK_CNT 100
  519. /* Structure representing one instance of the NIC */
  520. struct s2io_nic {
  521. #ifdef CONFIG_S2IO_NAPI
  522. /*
  523. * Count of packets to be processed in a given iteration, it will be indicated
  524. * by the quota field of the device structure when NAPI is enabled.
  525. */
  526. int pkts_to_process;
  527. #endif
  528. struct net_device *dev;
  529. mac_info_t mac_control;
  530. struct config_param config;
  531. struct pci_dev *pdev;
  532. void __iomem *bar0;
  533. void __iomem *bar1;
  534. #define MAX_MAC_SUPPORTED 16
  535. #define MAX_SUPPORTED_MULTICASTS MAX_MAC_SUPPORTED
  536. macaddr_t def_mac_addr[MAX_MAC_SUPPORTED];
  537. macaddr_t pre_mac_addr[MAX_MAC_SUPPORTED];
  538. struct net_device_stats stats;
  539. int high_dma_flag;
  540. int device_close_flag;
  541. int device_enabled_once;
  542. char name[50];
  543. struct tasklet_struct task;
  544. volatile unsigned long tasklet_status;
  545. /* Space to back up the PCI config space */
  546. u32 config_space[256 / sizeof(u32)];
  547. atomic_t rx_bufs_left[MAX_RX_RINGS];
  548. spinlock_t tx_lock;
  549. #ifndef CONFIG_S2IO_NAPI
  550. spinlock_t put_lock;
  551. #endif
  552. #define PROMISC 1
  553. #define ALL_MULTI 2
  554. #define MAX_ADDRS_SUPPORTED 64
  555. u16 usr_addr_count;
  556. u16 mc_addr_count;
  557. usr_addr_t usr_addrs[MAX_ADDRS_SUPPORTED];
  558. u16 m_cast_flg;
  559. u16 all_multi_pos;
  560. u16 promisc_flg;
  561. u16 tx_pkt_count;
  562. u16 rx_pkt_count;
  563. u16 tx_err_count;
  564. u16 rx_err_count;
  565. /* Id timer, used to blink NIC to physically identify NIC. */
  566. struct timer_list id_timer;
  567. /* Restart timer, used to restart NIC if the device is stuck and
  568. * a schedule task that will set the correct Link state once the
  569. * NIC's PHY has stabilized after a state change.
  570. */
  571. #ifdef INIT_TQUEUE
  572. struct tq_struct rst_timer_task;
  573. struct tq_struct set_link_task;
  574. #else
  575. struct work_struct rst_timer_task;
  576. struct work_struct set_link_task;
  577. #endif
  578. /* Flag that can be used to turn on or turn off the Rx checksum
  579. * offload feature.
  580. */
  581. int rx_csum;
  582. /* after blink, the adapter must be restored with original
  583. * values.
  584. */
  585. u64 adapt_ctrl_org;
  586. /* Last known link state. */
  587. u16 last_link_state;
  588. #define LINK_DOWN 1
  589. #define LINK_UP 2
  590. int task_flag;
  591. #define CARD_DOWN 1
  592. #define CARD_UP 2
  593. atomic_t card_state;
  594. volatile unsigned long link_state;
  595. spinlock_t rx_lock;
  596. atomic_t isr_cnt;
  597. };
  598. #define RESET_ERROR 1;
  599. #define CMD_ERROR 2;
  600. /* OS related system calls */
  601. #ifndef readq
  602. static inline u64 readq(void __iomem *addr)
  603. {
  604. u64 ret = 0;
  605. ret = readl(addr + 4);
  606. (u64) ret <<= 32;
  607. (u64) ret |= readl(addr);
  608. return ret;
  609. }
  610. #endif
  611. #ifndef writeq
  612. static inline void writeq(u64 val, void __iomem *addr)
  613. {
  614. writel((u32) (val), addr);
  615. writel((u32) (val >> 32), (addr + 4));
  616. }
  617. /* In 32 bit modes, some registers have to be written in a
  618. * particular order to expect correct hardware operation. The
  619. * macro SPECIAL_REG_WRITE is used to perform such ordered
  620. * writes. Defines UF (Upper First) and LF (Lower First) will
  621. * be used to specify the required write order.
  622. */
  623. #define UF 1
  624. #define LF 2
  625. static inline void SPECIAL_REG_WRITE(u64 val, void __iomem *addr, int order)
  626. {
  627. if (order == LF) {
  628. writel((u32) (val), addr);
  629. writel((u32) (val >> 32), (addr + 4));
  630. } else {
  631. writel((u32) (val >> 32), (addr + 4));
  632. writel((u32) (val), addr);
  633. }
  634. }
  635. #else
  636. #define SPECIAL_REG_WRITE(val, addr, dummy) writeq(val, addr)
  637. #endif
  638. /* Interrupt related values of Xena */
  639. #define ENABLE_INTRS 1
  640. #define DISABLE_INTRS 2
  641. /* Highest level interrupt blocks */
  642. #define TX_PIC_INTR (0x0001<<0)
  643. #define TX_DMA_INTR (0x0001<<1)
  644. #define TX_MAC_INTR (0x0001<<2)
  645. #define TX_XGXS_INTR (0x0001<<3)
  646. #define TX_TRAFFIC_INTR (0x0001<<4)
  647. #define RX_PIC_INTR (0x0001<<5)
  648. #define RX_DMA_INTR (0x0001<<6)
  649. #define RX_MAC_INTR (0x0001<<7)
  650. #define RX_XGXS_INTR (0x0001<<8)
  651. #define RX_TRAFFIC_INTR (0x0001<<9)
  652. #define MC_INTR (0x0001<<10)
  653. #define ENA_ALL_INTRS ( TX_PIC_INTR | \
  654. TX_DMA_INTR | \
  655. TX_MAC_INTR | \
  656. TX_XGXS_INTR | \
  657. TX_TRAFFIC_INTR | \
  658. RX_PIC_INTR | \
  659. RX_DMA_INTR | \
  660. RX_MAC_INTR | \
  661. RX_XGXS_INTR | \
  662. RX_TRAFFIC_INTR | \
  663. MC_INTR )
  664. /* Interrupt masks for the general interrupt mask register */
  665. #define DISABLE_ALL_INTRS 0xFFFFFFFFFFFFFFFFULL
  666. #define TXPIC_INT_M BIT(0)
  667. #define TXDMA_INT_M BIT(1)
  668. #define TXMAC_INT_M BIT(2)
  669. #define TXXGXS_INT_M BIT(3)
  670. #define TXTRAFFIC_INT_M BIT(8)
  671. #define PIC_RX_INT_M BIT(32)
  672. #define RXDMA_INT_M BIT(33)
  673. #define RXMAC_INT_M BIT(34)
  674. #define MC_INT_M BIT(35)
  675. #define RXXGXS_INT_M BIT(36)
  676. #define RXTRAFFIC_INT_M BIT(40)
  677. /* PIC level Interrupts TODO*/
  678. /* DMA level Inressupts */
  679. #define TXDMA_PFC_INT_M BIT(0)
  680. #define TXDMA_PCC_INT_M BIT(2)
  681. /* PFC block interrupts */
  682. #define PFC_MISC_ERR_1 BIT(0) /* Interrupt to indicate FIFO full */
  683. /* PCC block interrupts. */
  684. #define PCC_FB_ECC_ERR vBIT(0xff, 16, 8) /* Interrupt to indicate
  685. PCC_FB_ECC Error. */
  686. #define RXD_GET_VLAN_TAG(Control_2) (u16)(Control_2 & MASK_VLAN_TAG)
  687. /*
  688. * Prototype declaration.
  689. */
  690. static int __devinit s2io_init_nic(struct pci_dev *pdev,
  691. const struct pci_device_id *pre);
  692. static void __devexit s2io_rem_nic(struct pci_dev *pdev);
  693. static int init_shared_mem(struct s2io_nic *sp);
  694. static void free_shared_mem(struct s2io_nic *sp);
  695. static int init_nic(struct s2io_nic *nic);
  696. static void rx_intr_handler(ring_info_t *ring_data);
  697. static void tx_intr_handler(fifo_info_t *fifo_data);
  698. static void alarm_intr_handler(struct s2io_nic *sp);
  699. static int s2io_starter(void);
  700. void s2io_closer(void);
  701. static void s2io_tx_watchdog(struct net_device *dev);
  702. static void s2io_tasklet(unsigned long dev_addr);
  703. static void s2io_set_multicast(struct net_device *dev);
  704. static int rx_osm_handler(ring_info_t *ring_data, RxD_t * rxdp);
  705. void s2io_link(nic_t * sp, int link);
  706. void s2io_reset(nic_t * sp);
  707. #if defined(CONFIG_S2IO_NAPI)
  708. static int s2io_poll(struct net_device *dev, int *budget);
  709. #endif
  710. static void s2io_init_pci(nic_t * sp);
  711. int s2io_set_mac_addr(struct net_device *dev, u8 * addr);
  712. static irqreturn_t s2io_isr(int irq, void *dev_id, struct pt_regs *regs);
  713. static int verify_xena_quiescence(nic_t *sp, u64 val64, int flag);
  714. static struct ethtool_ops netdev_ethtool_ops;
  715. static void s2io_set_link(unsigned long data);
  716. int s2io_set_swapper(nic_t * sp);
  717. static void s2io_card_down(nic_t *nic);
  718. static int s2io_card_up(nic_t *nic);
  719. int get_xena_rev_id(struct pci_dev *pdev);
  720. #endif /* _S2IO_H */