s2io.h 28 KB

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