s2io.h 29 KB

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