s2io.h 29 KB

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