s2io.h 28 KB

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