s2io.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978
  1. /************************************************************************
  2. * s2io.h: A Linux PCI-X Ethernet driver for Neterion 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. static int debug_level = ERR_DBG;
  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. /* LRO statistics */
  69. unsigned long long clubbed_frms_cnt;
  70. unsigned long long sending_both;
  71. unsigned long long outof_sequence_pkts;
  72. unsigned long long flush_max_pkts;
  73. unsigned long long sum_avg_pkts_aggregated;
  74. unsigned long long num_aggregations;
  75. } swStat_t;
  76. /* The statistics block of Xena */
  77. typedef struct stat_block {
  78. /* Tx MAC statistics counters. */
  79. u32 tmac_data_octets;
  80. u32 tmac_frms;
  81. u64 tmac_drop_frms;
  82. u32 tmac_bcst_frms;
  83. u32 tmac_mcst_frms;
  84. u64 tmac_pause_ctrl_frms;
  85. u32 tmac_ucst_frms;
  86. u32 tmac_ttl_octets;
  87. u32 tmac_any_err_frms;
  88. u32 tmac_nucst_frms;
  89. u64 tmac_ttl_less_fb_octets;
  90. u64 tmac_vld_ip_octets;
  91. u32 tmac_drop_ip;
  92. u32 tmac_vld_ip;
  93. u32 tmac_rst_tcp;
  94. u32 tmac_icmp;
  95. u64 tmac_tcp;
  96. u32 reserved_0;
  97. u32 tmac_udp;
  98. /* Rx MAC Statistics counters. */
  99. u32 rmac_data_octets;
  100. u32 rmac_vld_frms;
  101. u64 rmac_fcs_err_frms;
  102. u64 rmac_drop_frms;
  103. u32 rmac_vld_bcst_frms;
  104. u32 rmac_vld_mcst_frms;
  105. u32 rmac_out_rng_len_err_frms;
  106. u32 rmac_in_rng_len_err_frms;
  107. u64 rmac_long_frms;
  108. u64 rmac_pause_ctrl_frms;
  109. u64 rmac_unsup_ctrl_frms;
  110. u32 rmac_accepted_ucst_frms;
  111. u32 rmac_ttl_octets;
  112. u32 rmac_discarded_frms;
  113. u32 rmac_accepted_nucst_frms;
  114. u32 reserved_1;
  115. u32 rmac_drop_events;
  116. u64 rmac_ttl_less_fb_octets;
  117. u64 rmac_ttl_frms;
  118. u64 reserved_2;
  119. u32 rmac_usized_frms;
  120. u32 reserved_3;
  121. u32 rmac_frag_frms;
  122. u32 rmac_osized_frms;
  123. u32 reserved_4;
  124. u32 rmac_jabber_frms;
  125. u64 rmac_ttl_64_frms;
  126. u64 rmac_ttl_65_127_frms;
  127. u64 reserved_5;
  128. u64 rmac_ttl_128_255_frms;
  129. u64 rmac_ttl_256_511_frms;
  130. u64 reserved_6;
  131. u64 rmac_ttl_512_1023_frms;
  132. u64 rmac_ttl_1024_1518_frms;
  133. u32 rmac_ip;
  134. u32 reserved_7;
  135. u64 rmac_ip_octets;
  136. u32 rmac_drop_ip;
  137. u32 rmac_hdr_err_ip;
  138. u32 reserved_8;
  139. u32 rmac_icmp;
  140. u64 rmac_tcp;
  141. u32 rmac_err_drp_udp;
  142. u32 rmac_udp;
  143. u64 rmac_xgmii_err_sym;
  144. u64 rmac_frms_q0;
  145. u64 rmac_frms_q1;
  146. u64 rmac_frms_q2;
  147. u64 rmac_frms_q3;
  148. u64 rmac_frms_q4;
  149. u64 rmac_frms_q5;
  150. u64 rmac_frms_q6;
  151. u64 rmac_frms_q7;
  152. u16 rmac_full_q3;
  153. u16 rmac_full_q2;
  154. u16 rmac_full_q1;
  155. u16 rmac_full_q0;
  156. u16 rmac_full_q7;
  157. u16 rmac_full_q6;
  158. u16 rmac_full_q5;
  159. u16 rmac_full_q4;
  160. u32 reserved_9;
  161. u32 rmac_pause_cnt;
  162. u64 rmac_xgmii_data_err_cnt;
  163. u64 rmac_xgmii_ctrl_err_cnt;
  164. u32 rmac_err_tcp;
  165. u32 rmac_accepted_ip;
  166. /* PCI/PCI-X Read transaction statistics. */
  167. u32 new_rd_req_cnt;
  168. u32 rd_req_cnt;
  169. u32 rd_rtry_cnt;
  170. u32 new_rd_req_rtry_cnt;
  171. /* PCI/PCI-X Write/Read transaction statistics. */
  172. u32 wr_req_cnt;
  173. u32 wr_rtry_rd_ack_cnt;
  174. u32 new_wr_req_rtry_cnt;
  175. u32 new_wr_req_cnt;
  176. u32 wr_disc_cnt;
  177. u32 wr_rtry_cnt;
  178. /* PCI/PCI-X Write / DMA Transaction statistics. */
  179. u32 txp_wr_cnt;
  180. u32 rd_rtry_wr_ack_cnt;
  181. u32 txd_wr_cnt;
  182. u32 txd_rd_cnt;
  183. u32 rxd_wr_cnt;
  184. u32 rxd_rd_cnt;
  185. u32 rxf_wr_cnt;
  186. u32 txf_rd_cnt;
  187. /* Tx MAC statistics overflow counters. */
  188. u32 tmac_data_octets_oflow;
  189. u32 tmac_frms_oflow;
  190. u32 tmac_bcst_frms_oflow;
  191. u32 tmac_mcst_frms_oflow;
  192. u32 tmac_ucst_frms_oflow;
  193. u32 tmac_ttl_octets_oflow;
  194. u32 tmac_any_err_frms_oflow;
  195. u32 tmac_nucst_frms_oflow;
  196. u64 tmac_vlan_frms;
  197. u32 tmac_drop_ip_oflow;
  198. u32 tmac_vld_ip_oflow;
  199. u32 tmac_rst_tcp_oflow;
  200. u32 tmac_icmp_oflow;
  201. u32 tpa_unknown_protocol;
  202. u32 tmac_udp_oflow;
  203. u32 reserved_10;
  204. u32 tpa_parse_failure;
  205. /* Rx MAC Statistics overflow counters. */
  206. u32 rmac_data_octets_oflow;
  207. u32 rmac_vld_frms_oflow;
  208. u32 rmac_vld_bcst_frms_oflow;
  209. u32 rmac_vld_mcst_frms_oflow;
  210. u32 rmac_accepted_ucst_frms_oflow;
  211. u32 rmac_ttl_octets_oflow;
  212. u32 rmac_discarded_frms_oflow;
  213. u32 rmac_accepted_nucst_frms_oflow;
  214. u32 rmac_usized_frms_oflow;
  215. u32 rmac_drop_events_oflow;
  216. u32 rmac_frag_frms_oflow;
  217. u32 rmac_osized_frms_oflow;
  218. u32 rmac_ip_oflow;
  219. u32 rmac_jabber_frms_oflow;
  220. u32 rmac_icmp_oflow;
  221. u32 rmac_drop_ip_oflow;
  222. u32 rmac_err_drp_udp_oflow;
  223. u32 rmac_udp_oflow;
  224. u32 reserved_11;
  225. u32 rmac_pause_cnt_oflow;
  226. u64 rmac_ttl_1519_4095_frms;
  227. u64 rmac_ttl_4096_8191_frms;
  228. u64 rmac_ttl_8192_max_frms;
  229. u64 rmac_ttl_gt_max_frms;
  230. u64 rmac_osized_alt_frms;
  231. u64 rmac_jabber_alt_frms;
  232. u64 rmac_gt_max_alt_frms;
  233. u64 rmac_vlan_frms;
  234. u32 rmac_len_discard;
  235. u32 rmac_fcs_discard;
  236. u32 rmac_pf_discard;
  237. u32 rmac_da_discard;
  238. u32 rmac_red_discard;
  239. u32 rmac_rts_discard;
  240. u32 reserved_12;
  241. u32 rmac_ingm_full_discard;
  242. u32 reserved_13;
  243. u32 rmac_accepted_ip_oflow;
  244. u32 reserved_14;
  245. u32 link_fault_cnt;
  246. swStat_t sw_stat;
  247. } StatInfo_t;
  248. /*
  249. * Structures representing different init time configuration
  250. * parameters of the NIC.
  251. */
  252. #define MAX_TX_FIFOS 8
  253. #define MAX_RX_RINGS 8
  254. /* FIFO mappings for all possible number of fifos configured */
  255. static int fifo_map[][MAX_TX_FIFOS] = {
  256. {0, 0, 0, 0, 0, 0, 0, 0},
  257. {0, 0, 0, 0, 1, 1, 1, 1},
  258. {0, 0, 0, 1, 1, 1, 2, 2},
  259. {0, 0, 1, 1, 2, 2, 3, 3},
  260. {0, 0, 1, 1, 2, 2, 3, 4},
  261. {0, 0, 1, 1, 2, 3, 4, 5},
  262. {0, 0, 1, 2, 3, 4, 5, 6},
  263. {0, 1, 2, 3, 4, 5, 6, 7},
  264. };
  265. /* Maintains Per FIFO related information. */
  266. typedef struct tx_fifo_config {
  267. #define MAX_AVAILABLE_TXDS 8192
  268. u32 fifo_len; /* specifies len of FIFO upto 8192, ie no of TxDLs */
  269. /* Priority definition */
  270. #define TX_FIFO_PRI_0 0 /*Highest */
  271. #define TX_FIFO_PRI_1 1
  272. #define TX_FIFO_PRI_2 2
  273. #define TX_FIFO_PRI_3 3
  274. #define TX_FIFO_PRI_4 4
  275. #define TX_FIFO_PRI_5 5
  276. #define TX_FIFO_PRI_6 6
  277. #define TX_FIFO_PRI_7 7 /*lowest */
  278. u8 fifo_priority; /* specifies pointer level for FIFO */
  279. /* user should not set twos fifos with same pri */
  280. u8 f_no_snoop;
  281. #define NO_SNOOP_TXD 0x01
  282. #define NO_SNOOP_TXD_BUFFER 0x02
  283. } tx_fifo_config_t;
  284. /* Maintains per Ring related information */
  285. typedef struct rx_ring_config {
  286. u32 num_rxd; /*No of RxDs per Rx Ring */
  287. #define RX_RING_PRI_0 0 /* highest */
  288. #define RX_RING_PRI_1 1
  289. #define RX_RING_PRI_2 2
  290. #define RX_RING_PRI_3 3
  291. #define RX_RING_PRI_4 4
  292. #define RX_RING_PRI_5 5
  293. #define RX_RING_PRI_6 6
  294. #define RX_RING_PRI_7 7 /* lowest */
  295. u8 ring_priority; /*Specifies service priority of ring */
  296. /* OSM should not set any two rings with same priority */
  297. u8 ring_org; /*Organization of ring */
  298. #define RING_ORG_BUFF1 0x01
  299. #define RX_RING_ORG_BUFF3 0x03
  300. #define RX_RING_ORG_BUFF5 0x05
  301. u8 f_no_snoop;
  302. #define NO_SNOOP_RXD 0x01
  303. #define NO_SNOOP_RXD_BUFFER 0x02
  304. } rx_ring_config_t;
  305. /* This structure provides contains values of the tunable parameters
  306. * of the H/W
  307. */
  308. struct config_param {
  309. /* Tx Side */
  310. u32 tx_fifo_num; /*Number of Tx FIFOs */
  311. u8 fifo_mapping[MAX_TX_FIFOS];
  312. tx_fifo_config_t tx_cfg[MAX_TX_FIFOS]; /*Per-Tx FIFO config */
  313. u32 max_txds; /*Max no. of Tx buffer descriptor per TxDL */
  314. u64 tx_intr_type;
  315. /* Specifies if Tx Intr is UTILZ or PER_LIST type. */
  316. /* Rx Side */
  317. u32 rx_ring_num; /*Number of receive rings */
  318. #define MAX_RX_BLOCKS_PER_RING 150
  319. rx_ring_config_t rx_cfg[MAX_RX_RINGS]; /*Per-Rx Ring config */
  320. u8 bimodal; /*Flag for setting bimodal interrupts*/
  321. #define HEADER_ETHERNET_II_802_3_SIZE 14
  322. #define HEADER_802_2_SIZE 3
  323. #define HEADER_SNAP_SIZE 5
  324. #define HEADER_VLAN_SIZE 4
  325. #define MIN_MTU 46
  326. #define MAX_PYLD 1500
  327. #define MAX_MTU (MAX_PYLD+18)
  328. #define MAX_MTU_VLAN (MAX_PYLD+22)
  329. #define MAX_PYLD_JUMBO 9600
  330. #define MAX_MTU_JUMBO (MAX_PYLD_JUMBO+18)
  331. #define MAX_MTU_JUMBO_VLAN (MAX_PYLD_JUMBO+22)
  332. u16 bus_speed;
  333. };
  334. /* Structure representing MAC Addrs */
  335. typedef struct mac_addr {
  336. u8 mac_addr[ETH_ALEN];
  337. } macaddr_t;
  338. /* Structure that represent every FIFO element in the BAR1
  339. * Address location.
  340. */
  341. typedef struct _TxFIFO_element {
  342. u64 TxDL_Pointer;
  343. u64 List_Control;
  344. #define TX_FIFO_LAST_TXD_NUM( val) vBIT(val,0,8)
  345. #define TX_FIFO_FIRST_LIST BIT(14)
  346. #define TX_FIFO_LAST_LIST BIT(15)
  347. #define TX_FIFO_FIRSTNLAST_LIST vBIT(3,14,2)
  348. #define TX_FIFO_SPECIAL_FUNC BIT(23)
  349. #define TX_FIFO_DS_NO_SNOOP BIT(31)
  350. #define TX_FIFO_BUFF_NO_SNOOP BIT(30)
  351. } TxFIFO_element_t;
  352. /* Tx descriptor structure */
  353. typedef struct _TxD {
  354. u64 Control_1;
  355. /* bit mask */
  356. #define TXD_LIST_OWN_XENA BIT(7)
  357. #define TXD_T_CODE (BIT(12)|BIT(13)|BIT(14)|BIT(15))
  358. #define TXD_T_CODE_OK(val) (|(val & TXD_T_CODE))
  359. #define GET_TXD_T_CODE(val) ((val & TXD_T_CODE)<<12)
  360. #define TXD_GATHER_CODE (BIT(22) | BIT(23))
  361. #define TXD_GATHER_CODE_FIRST BIT(22)
  362. #define TXD_GATHER_CODE_LAST BIT(23)
  363. #define TXD_TCP_LSO_EN BIT(30)
  364. #define TXD_UDP_COF_EN BIT(31)
  365. #define TXD_UFO_EN BIT(31) | BIT(30)
  366. #define TXD_TCP_LSO_MSS(val) vBIT(val,34,14)
  367. #define TXD_UFO_MSS(val) vBIT(val,34,14)
  368. #define TXD_BUFFER0_SIZE(val) vBIT(val,48,16)
  369. u64 Control_2;
  370. #define TXD_TX_CKO_CONTROL (BIT(5)|BIT(6)|BIT(7))
  371. #define TXD_TX_CKO_IPV4_EN BIT(5)
  372. #define TXD_TX_CKO_TCP_EN BIT(6)
  373. #define TXD_TX_CKO_UDP_EN BIT(7)
  374. #define TXD_VLAN_ENABLE BIT(15)
  375. #define TXD_VLAN_TAG(val) vBIT(val,16,16)
  376. #define TXD_INT_NUMBER(val) vBIT(val,34,6)
  377. #define TXD_INT_TYPE_PER_LIST BIT(47)
  378. #define TXD_INT_TYPE_UTILZ BIT(46)
  379. #define TXD_SET_MARKER vBIT(0x6,0,4)
  380. u64 Buffer_Pointer;
  381. u64 Host_Control; /* reserved for host */
  382. } TxD_t;
  383. /* Structure to hold the phy and virt addr of every TxDL. */
  384. typedef struct list_info_hold {
  385. dma_addr_t list_phy_addr;
  386. void *list_virt_addr;
  387. } list_info_hold_t;
  388. /* Rx descriptor structure for 1 buffer mode */
  389. typedef struct _RxD_t {
  390. u64 Host_Control; /* reserved for host */
  391. u64 Control_1;
  392. #define RXD_OWN_XENA BIT(7)
  393. #define RXD_T_CODE (BIT(12)|BIT(13)|BIT(14)|BIT(15))
  394. #define RXD_FRAME_PROTO vBIT(0xFFFF,24,8)
  395. #define RXD_FRAME_PROTO_IPV4 BIT(27)
  396. #define RXD_FRAME_PROTO_IPV6 BIT(28)
  397. #define RXD_FRAME_IP_FRAG BIT(29)
  398. #define RXD_FRAME_PROTO_TCP BIT(30)
  399. #define RXD_FRAME_PROTO_UDP BIT(31)
  400. #define TCP_OR_UDP_FRAME (RXD_FRAME_PROTO_TCP | RXD_FRAME_PROTO_UDP)
  401. #define RXD_GET_L3_CKSUM(val) ((u16)(val>> 16) & 0xFFFF)
  402. #define RXD_GET_L4_CKSUM(val) ((u16)(val) & 0xFFFF)
  403. u64 Control_2;
  404. #define THE_RXD_MARK 0x3
  405. #define SET_RXD_MARKER vBIT(THE_RXD_MARK, 0, 2)
  406. #define GET_RXD_MARKER(ctrl) ((ctrl & SET_RXD_MARKER) >> 62)
  407. #define MASK_VLAN_TAG vBIT(0xFFFF,48,16)
  408. #define SET_VLAN_TAG(val) vBIT(val,48,16)
  409. #define SET_NUM_TAG(val) vBIT(val,16,32)
  410. } RxD_t;
  411. /* Rx descriptor structure for 1 buffer mode */
  412. typedef struct _RxD1_t {
  413. struct _RxD_t h;
  414. #define MASK_BUFFER0_SIZE_1 vBIT(0x3FFF,2,14)
  415. #define SET_BUFFER0_SIZE_1(val) vBIT(val,2,14)
  416. #define RXD_GET_BUFFER0_SIZE_1(_Control_2) \
  417. (u16)((_Control_2 & MASK_BUFFER0_SIZE_1) >> 48)
  418. u64 Buffer0_ptr;
  419. } RxD1_t;
  420. /* Rx descriptor structure for 3 or 2 buffer mode */
  421. typedef struct _RxD3_t {
  422. struct _RxD_t h;
  423. #define MASK_BUFFER0_SIZE_3 vBIT(0xFF,2,14)
  424. #define MASK_BUFFER1_SIZE_3 vBIT(0xFFFF,16,16)
  425. #define MASK_BUFFER2_SIZE_3 vBIT(0xFFFF,32,16)
  426. #define SET_BUFFER0_SIZE_3(val) vBIT(val,8,8)
  427. #define SET_BUFFER1_SIZE_3(val) vBIT(val,16,16)
  428. #define SET_BUFFER2_SIZE_3(val) vBIT(val,32,16)
  429. #define RXD_GET_BUFFER0_SIZE_3(Control_2) \
  430. (u8)((Control_2 & MASK_BUFFER0_SIZE_3) >> 48)
  431. #define RXD_GET_BUFFER1_SIZE_3(Control_2) \
  432. (u16)((Control_2 & MASK_BUFFER1_SIZE_3) >> 32)
  433. #define RXD_GET_BUFFER2_SIZE_3(Control_2) \
  434. (u16)((Control_2 & MASK_BUFFER2_SIZE_3) >> 16)
  435. #define BUF0_LEN 40
  436. #define BUF1_LEN 1
  437. u64 Buffer0_ptr;
  438. u64 Buffer1_ptr;
  439. u64 Buffer2_ptr;
  440. } RxD3_t;
  441. /* Structure that represents the Rx descriptor block which contains
  442. * 128 Rx descriptors.
  443. */
  444. typedef struct _RxD_block {
  445. #define MAX_RXDS_PER_BLOCK_1 127
  446. RxD1_t rxd[MAX_RXDS_PER_BLOCK_1];
  447. u64 reserved_0;
  448. #define END_OF_BLOCK 0xFEFFFFFFFFFFFFFFULL
  449. u64 reserved_1; /* 0xFEFFFFFFFFFFFFFF to mark last
  450. * Rxd in this blk */
  451. u64 reserved_2_pNext_RxD_block; /* Logical ptr to next */
  452. u64 pNext_RxD_Blk_physical; /* Buff0_ptr.In a 32 bit arch
  453. * the upper 32 bits should
  454. * be 0 */
  455. } RxD_block_t;
  456. #define SIZE_OF_BLOCK 4096
  457. #define RXD_MODE_1 0
  458. #define RXD_MODE_3A 1
  459. #define RXD_MODE_3B 2
  460. /* Structure to hold virtual addresses of Buf0 and Buf1 in
  461. * 2buf mode. */
  462. typedef struct bufAdd {
  463. void *ba_0_org;
  464. void *ba_1_org;
  465. void *ba_0;
  466. void *ba_1;
  467. } buffAdd_t;
  468. /* Structure which stores all the MAC control parameters */
  469. /* This structure stores the offset of the RxD in the ring
  470. * from which the Rx Interrupt processor can start picking
  471. * up the RxDs for processing.
  472. */
  473. typedef struct _rx_curr_get_info_t {
  474. u32 block_index;
  475. u32 offset;
  476. u32 ring_len;
  477. } rx_curr_get_info_t;
  478. typedef rx_curr_get_info_t rx_curr_put_info_t;
  479. /* This structure stores the offset of the TxDl in the FIFO
  480. * from which the Tx Interrupt processor can start picking
  481. * up the TxDLs for send complete interrupt processing.
  482. */
  483. typedef struct {
  484. u32 offset;
  485. u32 fifo_len;
  486. } tx_curr_get_info_t;
  487. typedef tx_curr_get_info_t tx_curr_put_info_t;
  488. typedef struct rxd_info {
  489. void *virt_addr;
  490. dma_addr_t dma_addr;
  491. }rxd_info_t;
  492. /* Structure that holds the Phy and virt addresses of the Blocks */
  493. typedef struct rx_block_info {
  494. void *block_virt_addr;
  495. dma_addr_t block_dma_addr;
  496. rxd_info_t *rxds;
  497. } rx_block_info_t;
  498. /* pre declaration of the nic structure */
  499. typedef struct s2io_nic nic_t;
  500. /* Ring specific structure */
  501. typedef struct ring_info {
  502. /* The ring number */
  503. int ring_no;
  504. /*
  505. * Place holders for the virtual and physical addresses of
  506. * all the Rx Blocks
  507. */
  508. rx_block_info_t rx_blocks[MAX_RX_BLOCKS_PER_RING];
  509. int block_count;
  510. int pkt_cnt;
  511. /*
  512. * Put pointer info which indictes which RxD has to be replenished
  513. * with a new buffer.
  514. */
  515. rx_curr_put_info_t rx_curr_put_info;
  516. /*
  517. * Get pointer info which indictes which is the last RxD that was
  518. * processed by the driver.
  519. */
  520. rx_curr_get_info_t rx_curr_get_info;
  521. #ifndef CONFIG_S2IO_NAPI
  522. /* Index to the absolute position of the put pointer of Rx ring */
  523. int put_pos;
  524. #endif
  525. /* Buffer Address store. */
  526. buffAdd_t **ba;
  527. nic_t *nic;
  528. } ring_info_t;
  529. /* Fifo specific structure */
  530. typedef struct fifo_info {
  531. /* FIFO number */
  532. int fifo_no;
  533. /* Maximum TxDs per TxDL */
  534. int max_txds;
  535. /* Place holder of all the TX List's Phy and Virt addresses. */
  536. list_info_hold_t *list_info;
  537. /*
  538. * Current offset within the tx FIFO where driver would write
  539. * new Tx frame
  540. */
  541. tx_curr_put_info_t tx_curr_put_info;
  542. /*
  543. * Current offset within tx FIFO from where the driver would start freeing
  544. * the buffers
  545. */
  546. tx_curr_get_info_t tx_curr_get_info;
  547. nic_t *nic;
  548. }fifo_info_t;
  549. /* Infomation related to the Tx and Rx FIFOs and Rings of Xena
  550. * is maintained in this structure.
  551. */
  552. typedef struct mac_info {
  553. /* tx side stuff */
  554. /* logical pointer of start of each Tx FIFO */
  555. TxFIFO_element_t __iomem *tx_FIFO_start[MAX_TX_FIFOS];
  556. /* Fifo specific structure */
  557. fifo_info_t fifos[MAX_TX_FIFOS];
  558. /* Save virtual address of TxD page with zero DMA addr(if any) */
  559. void *zerodma_virt_addr;
  560. /* rx side stuff */
  561. /* Ring specific structure */
  562. ring_info_t rings[MAX_RX_RINGS];
  563. u16 rmac_pause_time;
  564. u16 mc_pause_threshold_q0q3;
  565. u16 mc_pause_threshold_q4q7;
  566. void *stats_mem; /* orignal pointer to allocated mem */
  567. dma_addr_t stats_mem_phy; /* Physical address of the stat block */
  568. u32 stats_mem_sz;
  569. StatInfo_t *stats_info; /* Logical address of the stat block */
  570. } mac_info_t;
  571. /* structure representing the user defined MAC addresses */
  572. typedef struct {
  573. char addr[ETH_ALEN];
  574. int usage_cnt;
  575. } usr_addr_t;
  576. /* Default Tunable parameters of the NIC. */
  577. #define DEFAULT_FIFO_LEN 4096
  578. #define SMALL_BLK_CNT 30
  579. #define LARGE_BLK_CNT 100
  580. /*
  581. * Structure to keep track of the MSI-X vectors and the corresponding
  582. * argument registered against each vector
  583. */
  584. #define MAX_REQUESTED_MSI_X 17
  585. struct s2io_msix_entry
  586. {
  587. u16 vector;
  588. u16 entry;
  589. void *arg;
  590. u8 type;
  591. #define MSIX_FIFO_TYPE 1
  592. #define MSIX_RING_TYPE 2
  593. u8 in_use;
  594. #define MSIX_REGISTERED_SUCCESS 0xAA
  595. };
  596. struct msix_info_st {
  597. u64 addr;
  598. u64 data;
  599. };
  600. /* Data structure to represent a LRO session */
  601. typedef struct lro {
  602. struct sk_buff *parent;
  603. u8 *l2h;
  604. struct iphdr *iph;
  605. struct tcphdr *tcph;
  606. u32 tcp_next_seq;
  607. u32 tcp_ack;
  608. int total_len;
  609. int frags_len;
  610. int sg_num;
  611. int in_use;
  612. u16 window;
  613. u32 cur_tsval;
  614. u32 cur_tsecr;
  615. u8 saw_ts;
  616. }lro_t;
  617. /* Structure representing one instance of the NIC */
  618. struct s2io_nic {
  619. int rxd_mode;
  620. #ifdef CONFIG_S2IO_NAPI
  621. /*
  622. * Count of packets to be processed in a given iteration, it will be indicated
  623. * by the quota field of the device structure when NAPI is enabled.
  624. */
  625. int pkts_to_process;
  626. #endif
  627. struct net_device *dev;
  628. mac_info_t mac_control;
  629. struct config_param config;
  630. struct pci_dev *pdev;
  631. void __iomem *bar0;
  632. void __iomem *bar1;
  633. #define MAX_MAC_SUPPORTED 16
  634. #define MAX_SUPPORTED_MULTICASTS MAX_MAC_SUPPORTED
  635. macaddr_t def_mac_addr[MAX_MAC_SUPPORTED];
  636. macaddr_t pre_mac_addr[MAX_MAC_SUPPORTED];
  637. struct net_device_stats stats;
  638. int high_dma_flag;
  639. int device_close_flag;
  640. int device_enabled_once;
  641. char name[50];
  642. struct tasklet_struct task;
  643. volatile unsigned long tasklet_status;
  644. /* Timer that handles I/O errors/exceptions */
  645. struct timer_list alarm_timer;
  646. /* Space to back up the PCI config space */
  647. u32 config_space[256 / sizeof(u32)];
  648. atomic_t rx_bufs_left[MAX_RX_RINGS];
  649. spinlock_t tx_lock;
  650. #ifndef CONFIG_S2IO_NAPI
  651. spinlock_t put_lock;
  652. #endif
  653. #define PROMISC 1
  654. #define ALL_MULTI 2
  655. #define MAX_ADDRS_SUPPORTED 64
  656. u16 usr_addr_count;
  657. u16 mc_addr_count;
  658. usr_addr_t usr_addrs[MAX_ADDRS_SUPPORTED];
  659. u16 m_cast_flg;
  660. u16 all_multi_pos;
  661. u16 promisc_flg;
  662. u16 tx_pkt_count;
  663. u16 rx_pkt_count;
  664. u16 tx_err_count;
  665. u16 rx_err_count;
  666. /* Id timer, used to blink NIC to physically identify NIC. */
  667. struct timer_list id_timer;
  668. /* Restart timer, used to restart NIC if the device is stuck and
  669. * a schedule task that will set the correct Link state once the
  670. * NIC's PHY has stabilized after a state change.
  671. */
  672. struct work_struct rst_timer_task;
  673. struct work_struct set_link_task;
  674. /* Flag that can be used to turn on or turn off the Rx checksum
  675. * offload feature.
  676. */
  677. int rx_csum;
  678. /* after blink, the adapter must be restored with original
  679. * values.
  680. */
  681. u64 adapt_ctrl_org;
  682. /* Last known link state. */
  683. u16 last_link_state;
  684. #define LINK_DOWN 1
  685. #define LINK_UP 2
  686. int task_flag;
  687. #define CARD_DOWN 1
  688. #define CARD_UP 2
  689. atomic_t card_state;
  690. volatile unsigned long link_state;
  691. struct vlan_group *vlgrp;
  692. #define MSIX_FLG 0xA5
  693. struct msix_entry *entries;
  694. struct s2io_msix_entry *s2io_entries;
  695. char desc1[35];
  696. char desc2[35];
  697. struct msix_info_st msix_info[0x3f];
  698. #define XFRAME_I_DEVICE 1
  699. #define XFRAME_II_DEVICE 2
  700. u8 device_type;
  701. #define MAX_LRO_SESSIONS 32
  702. lro_t lro0_n[MAX_LRO_SESSIONS];
  703. unsigned long clubbed_frms_cnt;
  704. unsigned long sending_both;
  705. u8 lro;
  706. u16 lro_max_aggr_per_sess;
  707. #define INTA 0
  708. #define MSI 1
  709. #define MSI_X 2
  710. u8 intr_type;
  711. spinlock_t rx_lock;
  712. atomic_t isr_cnt;
  713. u64 *ufo_in_band_v;
  714. };
  715. #define RESET_ERROR 1;
  716. #define CMD_ERROR 2;
  717. /* OS related system calls */
  718. #ifndef readq
  719. static inline u64 readq(void __iomem *addr)
  720. {
  721. u64 ret = 0;
  722. ret = readl(addr + 4);
  723. ret <<= 32;
  724. ret |= readl(addr);
  725. return ret;
  726. }
  727. #endif
  728. #ifndef writeq
  729. static inline void writeq(u64 val, void __iomem *addr)
  730. {
  731. writel((u32) (val), addr);
  732. writel((u32) (val >> 32), (addr + 4));
  733. }
  734. /* In 32 bit modes, some registers have to be written in a
  735. * particular order to expect correct hardware operation. The
  736. * macro SPECIAL_REG_WRITE is used to perform such ordered
  737. * writes. Defines UF (Upper First) and LF (Lower First) will
  738. * be used to specify the required write order.
  739. */
  740. #define UF 1
  741. #define LF 2
  742. static inline void SPECIAL_REG_WRITE(u64 val, void __iomem *addr, int order)
  743. {
  744. if (order == LF) {
  745. writel((u32) (val), addr);
  746. writel((u32) (val >> 32), (addr + 4));
  747. } else {
  748. writel((u32) (val >> 32), (addr + 4));
  749. writel((u32) (val), addr);
  750. }
  751. }
  752. #else
  753. #define SPECIAL_REG_WRITE(val, addr, dummy) writeq(val, addr)
  754. #endif
  755. /* Interrupt related values of Xena */
  756. #define ENABLE_INTRS 1
  757. #define DISABLE_INTRS 2
  758. /* Highest level interrupt blocks */
  759. #define TX_PIC_INTR (0x0001<<0)
  760. #define TX_DMA_INTR (0x0001<<1)
  761. #define TX_MAC_INTR (0x0001<<2)
  762. #define TX_XGXS_INTR (0x0001<<3)
  763. #define TX_TRAFFIC_INTR (0x0001<<4)
  764. #define RX_PIC_INTR (0x0001<<5)
  765. #define RX_DMA_INTR (0x0001<<6)
  766. #define RX_MAC_INTR (0x0001<<7)
  767. #define RX_XGXS_INTR (0x0001<<8)
  768. #define RX_TRAFFIC_INTR (0x0001<<9)
  769. #define MC_INTR (0x0001<<10)
  770. #define ENA_ALL_INTRS ( TX_PIC_INTR | \
  771. TX_DMA_INTR | \
  772. TX_MAC_INTR | \
  773. TX_XGXS_INTR | \
  774. TX_TRAFFIC_INTR | \
  775. RX_PIC_INTR | \
  776. RX_DMA_INTR | \
  777. RX_MAC_INTR | \
  778. RX_XGXS_INTR | \
  779. RX_TRAFFIC_INTR | \
  780. MC_INTR )
  781. /* Interrupt masks for the general interrupt mask register */
  782. #define DISABLE_ALL_INTRS 0xFFFFFFFFFFFFFFFFULL
  783. #define TXPIC_INT_M BIT(0)
  784. #define TXDMA_INT_M BIT(1)
  785. #define TXMAC_INT_M BIT(2)
  786. #define TXXGXS_INT_M BIT(3)
  787. #define TXTRAFFIC_INT_M BIT(8)
  788. #define PIC_RX_INT_M BIT(32)
  789. #define RXDMA_INT_M BIT(33)
  790. #define RXMAC_INT_M BIT(34)
  791. #define MC_INT_M BIT(35)
  792. #define RXXGXS_INT_M BIT(36)
  793. #define RXTRAFFIC_INT_M BIT(40)
  794. /* PIC level Interrupts TODO*/
  795. /* DMA level Inressupts */
  796. #define TXDMA_PFC_INT_M BIT(0)
  797. #define TXDMA_PCC_INT_M BIT(2)
  798. /* PFC block interrupts */
  799. #define PFC_MISC_ERR_1 BIT(0) /* Interrupt to indicate FIFO full */
  800. /* PCC block interrupts. */
  801. #define PCC_FB_ECC_ERR vBIT(0xff, 16, 8) /* Interrupt to indicate
  802. PCC_FB_ECC Error. */
  803. #define RXD_GET_VLAN_TAG(Control_2) (u16)(Control_2 & MASK_VLAN_TAG)
  804. /*
  805. * Prototype declaration.
  806. */
  807. static int __devinit s2io_init_nic(struct pci_dev *pdev,
  808. const struct pci_device_id *pre);
  809. static void __devexit s2io_rem_nic(struct pci_dev *pdev);
  810. static int init_shared_mem(struct s2io_nic *sp);
  811. static void free_shared_mem(struct s2io_nic *sp);
  812. static int init_nic(struct s2io_nic *nic);
  813. static void rx_intr_handler(ring_info_t *ring_data);
  814. static void tx_intr_handler(fifo_info_t *fifo_data);
  815. static void alarm_intr_handler(struct s2io_nic *sp);
  816. static int s2io_starter(void);
  817. static void s2io_tx_watchdog(struct net_device *dev);
  818. static void s2io_tasklet(unsigned long dev_addr);
  819. static void s2io_set_multicast(struct net_device *dev);
  820. static int rx_osm_handler(ring_info_t *ring_data, RxD_t * rxdp);
  821. static void s2io_link(nic_t * sp, int link);
  822. #if defined(CONFIG_S2IO_NAPI)
  823. static int s2io_poll(struct net_device *dev, int *budget);
  824. #endif
  825. static void s2io_init_pci(nic_t * sp);
  826. static int s2io_set_mac_addr(struct net_device *dev, u8 * addr);
  827. static void s2io_alarm_handle(unsigned long data);
  828. static int s2io_enable_msi(nic_t *nic);
  829. static irqreturn_t s2io_msi_handle(int irq, void *dev_id, struct pt_regs *regs);
  830. static irqreturn_t
  831. s2io_msix_ring_handle(int irq, void *dev_id, struct pt_regs *regs);
  832. static irqreturn_t
  833. s2io_msix_fifo_handle(int irq, void *dev_id, struct pt_regs *regs);
  834. static irqreturn_t s2io_isr(int irq, void *dev_id, struct pt_regs *regs);
  835. static int verify_xena_quiescence(nic_t *sp, u64 val64, int flag);
  836. static struct ethtool_ops netdev_ethtool_ops;
  837. static void s2io_set_link(unsigned long data);
  838. static int s2io_set_swapper(nic_t * sp);
  839. static void s2io_card_down(nic_t *nic);
  840. static int s2io_card_up(nic_t *nic);
  841. static int get_xena_rev_id(struct pci_dev *pdev);
  842. static void restore_xmsi_data(nic_t *nic);
  843. static int s2io_club_tcp_session(u8 *buffer, u8 **tcp, u32 *tcp_len, lro_t **lro, RxD_t *rxdp, nic_t *sp);
  844. static void clear_lro_session(lro_t *lro);
  845. static void queue_rx_frame(struct sk_buff *skb);
  846. static void update_L3L4_header(nic_t *sp, lro_t *lro);
  847. static void lro_append_pkt(nic_t *sp, lro_t *lro, struct sk_buff *skb, u32 tcp_len);
  848. #endif /* _S2IO_H */