s2io.h 22 KB

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