netxen_nic.h 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022
  1. /*
  2. * Copyright (C) 2003 - 2006 NetXen, Inc.
  3. * All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version 2
  8. * of the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
  18. * MA 02111-1307, USA.
  19. *
  20. * The full GNU General Public License is included in this distribution
  21. * in the file called LICENSE.
  22. *
  23. * Contact Information:
  24. * info@netxen.com
  25. * NetXen,
  26. * 3965 Freedom Circle, Fourth floor,
  27. * Santa Clara, CA 95054
  28. */
  29. #ifndef _NETXEN_NIC_H_
  30. #define _NETXEN_NIC_H_
  31. #include <linux/module.h>
  32. #include <linux/kernel.h>
  33. #include <linux/types.h>
  34. #include <linux/compiler.h>
  35. #include <linux/slab.h>
  36. #include <linux/delay.h>
  37. #include <linux/init.h>
  38. #include <linux/ioport.h>
  39. #include <linux/pci.h>
  40. #include <linux/netdevice.h>
  41. #include <linux/etherdevice.h>
  42. #include <linux/ip.h>
  43. #include <linux/in.h>
  44. #include <linux/tcp.h>
  45. #include <linux/skbuff.h>
  46. #include <linux/version.h>
  47. #include <linux/ethtool.h>
  48. #include <linux/mii.h>
  49. #include <linux/interrupt.h>
  50. #include <linux/timer.h>
  51. #include <linux/mm.h>
  52. #include <linux/mman.h>
  53. #include <asm/system.h>
  54. #include <asm/io.h>
  55. #include <asm/byteorder.h>
  56. #include <asm/uaccess.h>
  57. #include <asm/pgtable.h>
  58. #include "netxen_nic_hw.h"
  59. #define NETXEN_NIC_BUILD_NO "5"
  60. #define _NETXEN_NIC_LINUX_MAJOR 2
  61. #define _NETXEN_NIC_LINUX_MINOR 3
  62. #define _NETXEN_NIC_LINUX_SUBVERSION 59
  63. #define NETXEN_NIC_LINUX_VERSIONID "2.3.59" "-" NETXEN_NIC_BUILD_NO
  64. #define NETXEN_NIC_FW_VERSIONID "2.3.59"
  65. #define RCV_DESC_RINGSIZE \
  66. (sizeof(struct rcv_desc) * adapter->max_rx_desc_count)
  67. #define STATUS_DESC_RINGSIZE \
  68. (sizeof(struct status_desc)* adapter->max_rx_desc_count)
  69. #define TX_RINGSIZE \
  70. (sizeof(struct netxen_cmd_buffer) * adapter->max_tx_desc_count)
  71. #define RCV_BUFFSIZE \
  72. (sizeof(struct netxen_rx_buffer) * rcv_desc->max_rx_desc_count)
  73. #define find_diff_among(a,b,range) ((a)<(b)?((b)-(a)):((b)+(range)-(a)))
  74. #define NETXEN_NETDEV_STATUS 0x1
  75. #define ADDR_IN_WINDOW1(off) \
  76. ((off > NETXEN_CRB_PCIX_HOST2) && (off < NETXEN_CRB_MAX)) ? 1 : 0
  77. /*
  78. * normalize a 64MB crb address to 32MB PCI window
  79. * To use NETXEN_CRB_NORMALIZE, window _must_ be set to 1
  80. */
  81. #define NETXEN_CRB_NORMAL(reg) \
  82. ((reg) - NETXEN_CRB_PCIX_HOST2 + NETXEN_CRB_PCIX_HOST)
  83. #define NETXEN_CRB_NORMALIZE(adapter, reg) \
  84. pci_base_offset(adapter, NETXEN_CRB_NORMAL(reg))
  85. #define FIRST_PAGE_GROUP_START 0
  86. #define FIRST_PAGE_GROUP_END 0x400000
  87. #define SECOND_PAGE_GROUP_START 0x4000000
  88. #define SECOND_PAGE_GROUP_END 0x66BC000
  89. #define THIRD_PAGE_GROUP_START 0x70E4000
  90. #define THIRD_PAGE_GROUP_END 0x8000000
  91. #define FIRST_PAGE_GROUP_SIZE FIRST_PAGE_GROUP_END - FIRST_PAGE_GROUP_START
  92. #define SECOND_PAGE_GROUP_SIZE SECOND_PAGE_GROUP_END - SECOND_PAGE_GROUP_START
  93. #define THIRD_PAGE_GROUP_SIZE THIRD_PAGE_GROUP_END - THIRD_PAGE_GROUP_START
  94. #define MAX_RX_BUFFER_LENGTH 2000
  95. #define MAX_RX_JUMBO_BUFFER_LENGTH 9046
  96. #define RX_DMA_MAP_LEN (MAX_RX_BUFFER_LENGTH - NET_IP_ALIGN)
  97. #define RX_JUMBO_DMA_MAP_LEN \
  98. (MAX_RX_JUMBO_BUFFER_LENGTH - NET_IP_ALIGN)
  99. #define NETXEN_ROM_ROUNDUP 0x80000000ULL
  100. /*
  101. * Maximum number of ring contexts
  102. */
  103. #define MAX_RING_CTX 1
  104. /* Opcodes to be used with the commands */
  105. enum {
  106. TX_ETHER_PKT = 0x01,
  107. /* The following opcodes are for IP checksum */
  108. TX_TCP_PKT,
  109. TX_UDP_PKT,
  110. TX_IP_PKT,
  111. TX_TCP_LSO,
  112. TX_IPSEC,
  113. TX_IPSEC_CMD
  114. };
  115. /* The following opcodes are for internal consumption. */
  116. #define NETXEN_CONTROL_OP 0x10
  117. #define PEGNET_REQUEST 0x11
  118. #define MAX_NUM_CARDS 4
  119. #define MAX_BUFFERS_PER_CMD 32
  120. /*
  121. * Following are the states of the Phantom. Phantom will set them and
  122. * Host will read to check if the fields are correct.
  123. */
  124. #define PHAN_INITIALIZE_START 0xff00
  125. #define PHAN_INITIALIZE_FAILED 0xffff
  126. #define PHAN_INITIALIZE_COMPLETE 0xff01
  127. /* Host writes the following to notify that it has done the init-handshake */
  128. #define PHAN_INITIALIZE_ACK 0xf00f
  129. #define NUM_RCV_DESC_RINGS 2 /* No of Rcv Descriptor contexts */
  130. /* descriptor types */
  131. #define RCV_DESC_NORMAL 0x01
  132. #define RCV_DESC_JUMBO 0x02
  133. #define RCV_DESC_NORMAL_CTXID 0
  134. #define RCV_DESC_JUMBO_CTXID 1
  135. #define RCV_DESC_TYPE(ID) \
  136. ((ID == RCV_DESC_JUMBO_CTXID) ? RCV_DESC_JUMBO : RCV_DESC_NORMAL)
  137. #define MAX_CMD_DESCRIPTORS 1024
  138. #define MAX_RCV_DESCRIPTORS 32768
  139. #define MAX_JUMBO_RCV_DESCRIPTORS 4096
  140. #define MAX_RCVSTATUS_DESCRIPTORS MAX_RCV_DESCRIPTORS
  141. #define MAX_JUMBO_RCV_DESC MAX_JUMBO_RCV_DESCRIPTORS
  142. #define MAX_RCV_DESC MAX_RCV_DESCRIPTORS
  143. #define MAX_RCVSTATUS_DESC MAX_RCV_DESCRIPTORS
  144. #define NUM_RCV_DESC (MAX_RCV_DESC + MAX_JUMBO_RCV_DESCRIPTORS)
  145. #define MAX_EPG_DESCRIPTORS (MAX_CMD_DESCRIPTORS * 8)
  146. #define MIN_TX_COUNT 4096
  147. #define MIN_RX_COUNT 4096
  148. #define MAX_FRAME_SIZE 0x10000 /* 64K MAX size for LSO */
  149. #define PHAN_PEG_RCV_INITIALIZED 0xff01
  150. #define PHAN_PEG_RCV_START_INITIALIZE 0xff00
  151. #define get_next_index(index, length) \
  152. (((index) + 1) & ((length) - 1))
  153. #define get_index_range(index,length,count) \
  154. (((index) + (count)) & ((length) - 1))
  155. /*
  156. * Following data structures describe the descriptors that will be used.
  157. * Added fileds of tcpHdrSize and ipHdrSize, The driver needs to do it only when
  158. * we are doing LSO (above the 1500 size packet) only.
  159. */
  160. /*
  161. * The size of reference handle been changed to 16 bits to pass the MSS fields
  162. * for the LSO packet
  163. */
  164. #define FLAGS_CHECKSUM_ENABLED 0x01
  165. #define FLAGS_LSO_ENABLED 0x02
  166. #define FLAGS_IPSEC_SA_ADD 0x04
  167. #define FLAGS_IPSEC_SA_DELETE 0x08
  168. #define FLAGS_VLAN_TAGGED 0x10
  169. #define CMD_DESC_TOTAL_LENGTH(cmd_desc) \
  170. ((cmd_desc)->length_tcp_hdr & 0x00FFFFFF)
  171. #define CMD_DESC_TCP_HDR_OFFSET(cmd_desc) \
  172. (((cmd_desc)->length_tcp_hdr >> 24) & 0x0FF)
  173. #define CMD_DESC_PORT(cmd_desc) ((cmd_desc)->port_ctxid & 0x0F)
  174. #define CMD_DESC_CTX_ID(cmd_desc) (((cmd_desc)->port_ctxid >> 4) & 0x0F)
  175. #define CMD_DESC_TOTAL_LENGTH_WRT(cmd_desc, var) \
  176. ((cmd_desc)->length_tcp_hdr |= ((var) & 0x00FFFFFF))
  177. #define CMD_DESC_TCP_HDR_OFFSET_WRT(cmd_desc, var) \
  178. ((cmd_desc)->length_tcp_hdr |= (((var) << 24) & 0xFF000000))
  179. #define CMD_DESC_PORT_WRT(cmd_desc, var) \
  180. ((cmd_desc)->port_ctxid |= ((var) & 0x0F))
  181. struct cmd_desc_type0 {
  182. u64 netxen_next; /* for fragments handled by Phantom */
  183. union {
  184. struct {
  185. u32 addr_low_part2;
  186. u32 addr_high_part2;
  187. };
  188. u64 addr_buffer2;
  189. };
  190. /* Bit pattern: 0-23 total length, 24-32 tcp header offset */
  191. u32 length_tcp_hdr;
  192. u8 ip_hdr_offset; /* For LSO only */
  193. u8 num_of_buffers; /* total number of segments */
  194. u8 flags; /* as defined above */
  195. u8 opcode;
  196. u16 reference_handle; /* changed to u16 to add mss */
  197. u16 mss; /* passed by NDIS_PACKET for LSO */
  198. /* Bit pattern 0-3 port, 0-3 ctx id */
  199. u8 port_ctxid;
  200. u8 total_hdr_length; /* LSO only : MAC+IP+TCP Hdr size */
  201. u16 conn_id; /* IPSec offoad only */
  202. union {
  203. struct {
  204. u32 addr_low_part3;
  205. u32 addr_high_part3;
  206. };
  207. u64 addr_buffer3;
  208. };
  209. union {
  210. struct {
  211. u32 addr_low_part1;
  212. u32 addr_high_part1;
  213. };
  214. u64 addr_buffer1;
  215. };
  216. u16 buffer1_length;
  217. u16 buffer2_length;
  218. u16 buffer3_length;
  219. u16 buffer4_length;
  220. union {
  221. struct {
  222. u32 addr_low_part4;
  223. u32 addr_high_part4;
  224. };
  225. u64 addr_buffer4;
  226. };
  227. } __attribute__ ((aligned(64)));
  228. /* Note: sizeof(rcv_desc) should always be a mutliple of 2 */
  229. struct rcv_desc {
  230. u16 reference_handle;
  231. u16 reserved;
  232. u32 buffer_length; /* allocated buffer length (usually 2K) */
  233. u64 addr_buffer;
  234. };
  235. /* opcode field in status_desc */
  236. #define RCV_NIC_PKT (0xA)
  237. #define STATUS_NIC_PKT ((RCV_NIC_PKT) << 12)
  238. /* for status field in status_desc */
  239. #define STATUS_NEED_CKSUM (1)
  240. #define STATUS_CKSUM_OK (2)
  241. /* owner bits of status_desc */
  242. #define STATUS_OWNER_HOST (0x1)
  243. #define STATUS_OWNER_PHANTOM (0x2)
  244. #define NETXEN_PROT_IP (1)
  245. #define NETXEN_PROT_UNKNOWN (0)
  246. /* Note: sizeof(status_desc) should always be a mutliple of 2 */
  247. #define STATUS_DESC_PORT(status_desc) \
  248. ((status_desc)->port_status_type_op & 0x0F)
  249. #define STATUS_DESC_STATUS(status_desc) \
  250. (((status_desc)->port_status_type_op >> 4) & 0x0F)
  251. #define STATUS_DESC_TYPE(status_desc) \
  252. (((status_desc)->port_status_type_op >> 8) & 0x0F)
  253. #define STATUS_DESC_OPCODE(status_desc) \
  254. (((status_desc)->port_status_type_op >> 12) & 0x0F)
  255. struct status_desc {
  256. /* Bit pattern: 0-3 port, 4-7 status, 8-11 type, 12-15 opcode */
  257. u16 port_status_type_op;
  258. u16 total_length; /* NIC mode */
  259. u16 reference_handle; /* handle for the associated packet */
  260. /* Bit pattern: 0-1 owner, 2-5 protocol */
  261. u16 owner; /* Owner of the descriptor */
  262. } __attribute__ ((aligned(8)));
  263. enum {
  264. NETXEN_RCV_PEG_0 = 0,
  265. NETXEN_RCV_PEG_1
  266. };
  267. /* The version of the main data structure */
  268. #define NETXEN_BDINFO_VERSION 1
  269. /* Magic number to let user know flash is programmed */
  270. #define NETXEN_BDINFO_MAGIC 0x12345678
  271. /* Max number of Gig ports on a Phantom board */
  272. #define NETXEN_MAX_PORTS 4
  273. typedef enum {
  274. NETXEN_BRDTYPE_P1_BD = 0x0000,
  275. NETXEN_BRDTYPE_P1_SB = 0x0001,
  276. NETXEN_BRDTYPE_P1_SMAX = 0x0002,
  277. NETXEN_BRDTYPE_P1_SOCK = 0x0003,
  278. NETXEN_BRDTYPE_P2_SOCK_31 = 0x0008,
  279. NETXEN_BRDTYPE_P2_SOCK_35 = 0x0009,
  280. NETXEN_BRDTYPE_P2_SB35_4G = 0x000a,
  281. NETXEN_BRDTYPE_P2_SB31_10G = 0x000b,
  282. NETXEN_BRDTYPE_P2_SB31_2G = 0x000c,
  283. NETXEN_BRDTYPE_P2_SB31_10G_IMEZ = 0x000d,
  284. NETXEN_BRDTYPE_P2_SB31_10G_HMEZ = 0x000e,
  285. NETXEN_BRDTYPE_P2_SB31_10G_CX4 = 0x000f
  286. } netxen_brdtype_t;
  287. typedef enum {
  288. NETXEN_BRDMFG_INVENTEC = 1
  289. } netxen_brdmfg;
  290. typedef enum {
  291. MEM_ORG_128Mbx4 = 0x0, /* DDR1 only */
  292. MEM_ORG_128Mbx8 = 0x1, /* DDR1 only */
  293. MEM_ORG_128Mbx16 = 0x2, /* DDR1 only */
  294. MEM_ORG_256Mbx4 = 0x3,
  295. MEM_ORG_256Mbx8 = 0x4,
  296. MEM_ORG_256Mbx16 = 0x5,
  297. MEM_ORG_512Mbx4 = 0x6,
  298. MEM_ORG_512Mbx8 = 0x7,
  299. MEM_ORG_512Mbx16 = 0x8,
  300. MEM_ORG_1Gbx4 = 0x9,
  301. MEM_ORG_1Gbx8 = 0xa,
  302. MEM_ORG_1Gbx16 = 0xb,
  303. MEM_ORG_2Gbx4 = 0xc,
  304. MEM_ORG_2Gbx8 = 0xd,
  305. MEM_ORG_2Gbx16 = 0xe,
  306. MEM_ORG_128Mbx32 = 0x10002, /* GDDR only */
  307. MEM_ORG_256Mbx32 = 0x10005 /* GDDR only */
  308. } netxen_mn_mem_org_t;
  309. typedef enum {
  310. MEM_ORG_512Kx36 = 0x0,
  311. MEM_ORG_1Mx36 = 0x1,
  312. MEM_ORG_2Mx36 = 0x2
  313. } netxen_sn_mem_org_t;
  314. typedef enum {
  315. MEM_DEPTH_4MB = 0x1,
  316. MEM_DEPTH_8MB = 0x2,
  317. MEM_DEPTH_16MB = 0x3,
  318. MEM_DEPTH_32MB = 0x4,
  319. MEM_DEPTH_64MB = 0x5,
  320. MEM_DEPTH_128MB = 0x6,
  321. MEM_DEPTH_256MB = 0x7,
  322. MEM_DEPTH_512MB = 0x8,
  323. MEM_DEPTH_1GB = 0x9,
  324. MEM_DEPTH_2GB = 0xa,
  325. MEM_DEPTH_4GB = 0xb,
  326. MEM_DEPTH_8GB = 0xc,
  327. MEM_DEPTH_16GB = 0xd,
  328. MEM_DEPTH_32GB = 0xe
  329. } netxen_mem_depth_t;
  330. struct netxen_board_info {
  331. u32 header_version;
  332. u32 board_mfg;
  333. u32 board_type;
  334. u32 board_num;
  335. u32 chip_id;
  336. u32 chip_minor;
  337. u32 chip_major;
  338. u32 chip_pkg;
  339. u32 chip_lot;
  340. u32 port_mask; /* available niu ports */
  341. u32 peg_mask; /* available pegs */
  342. u32 icache_ok; /* can we run with icache? */
  343. u32 dcache_ok; /* can we run with dcache? */
  344. u32 casper_ok;
  345. u32 mac_addr_lo_0;
  346. u32 mac_addr_lo_1;
  347. u32 mac_addr_lo_2;
  348. u32 mac_addr_lo_3;
  349. /* MN-related config */
  350. u32 mn_sync_mode; /* enable/ sync shift cclk/ sync shift mclk */
  351. u32 mn_sync_shift_cclk;
  352. u32 mn_sync_shift_mclk;
  353. u32 mn_wb_en;
  354. u32 mn_crystal_freq; /* in MHz */
  355. u32 mn_speed; /* in MHz */
  356. u32 mn_org;
  357. u32 mn_depth;
  358. u32 mn_ranks_0; /* ranks per slot */
  359. u32 mn_ranks_1; /* ranks per slot */
  360. u32 mn_rd_latency_0;
  361. u32 mn_rd_latency_1;
  362. u32 mn_rd_latency_2;
  363. u32 mn_rd_latency_3;
  364. u32 mn_rd_latency_4;
  365. u32 mn_rd_latency_5;
  366. u32 mn_rd_latency_6;
  367. u32 mn_rd_latency_7;
  368. u32 mn_rd_latency_8;
  369. u32 mn_dll_val[18];
  370. u32 mn_mode_reg; /* MIU DDR Mode Register */
  371. u32 mn_ext_mode_reg; /* MIU DDR Extended Mode Register */
  372. u32 mn_timing_0; /* MIU Memory Control Timing Rgister */
  373. u32 mn_timing_1; /* MIU Extended Memory Ctrl Timing Register */
  374. u32 mn_timing_2; /* MIU Extended Memory Ctrl Timing2 Register */
  375. /* SN-related config */
  376. u32 sn_sync_mode; /* enable/ sync shift cclk / sync shift mclk */
  377. u32 sn_pt_mode; /* pass through mode */
  378. u32 sn_ecc_en;
  379. u32 sn_wb_en;
  380. u32 sn_crystal_freq;
  381. u32 sn_speed;
  382. u32 sn_org;
  383. u32 sn_depth;
  384. u32 sn_dll_tap;
  385. u32 sn_rd_latency;
  386. u32 mac_addr_hi_0;
  387. u32 mac_addr_hi_1;
  388. u32 mac_addr_hi_2;
  389. u32 mac_addr_hi_3;
  390. u32 magic; /* indicates flash has been initialized */
  391. u32 mn_rdimm;
  392. u32 mn_dll_override;
  393. };
  394. #define FLASH_NUM_PORTS (4)
  395. struct netxen_flash_mac_addr {
  396. u32 flash_addr[32];
  397. };
  398. struct netxen_user_old_info {
  399. u8 flash_md5[16];
  400. u8 crbinit_md5[16];
  401. u8 brdcfg_md5[16];
  402. /* bootloader */
  403. u32 bootld_version;
  404. u32 bootld_size;
  405. u8 bootld_md5[16];
  406. /* image */
  407. u32 image_version;
  408. u32 image_size;
  409. u8 image_md5[16];
  410. /* primary image status */
  411. u32 primary_status;
  412. u32 secondary_present;
  413. /* MAC address , 4 ports */
  414. struct netxen_flash_mac_addr mac_addr[FLASH_NUM_PORTS];
  415. };
  416. #define FLASH_NUM_MAC_PER_PORT 32
  417. struct netxen_user_info {
  418. u8 flash_md5[16 * 64];
  419. /* bootloader */
  420. u32 bootld_version;
  421. u32 bootld_size;
  422. /* image */
  423. u32 image_version;
  424. u32 image_size;
  425. /* primary image status */
  426. u32 primary_status;
  427. u32 secondary_present;
  428. /* MAC address , 4 ports, 32 address per port */
  429. u64 mac_addr[FLASH_NUM_PORTS * FLASH_NUM_MAC_PER_PORT];
  430. u32 sub_sys_id;
  431. u8 serial_num[32];
  432. /* Any user defined data */
  433. };
  434. /*
  435. * Flash Layout - new format.
  436. */
  437. struct netxen_new_user_info {
  438. u8 flash_md5[16 * 64];
  439. /* bootloader */
  440. u32 bootld_version;
  441. u32 bootld_size;
  442. /* image */
  443. u32 image_version;
  444. u32 image_size;
  445. /* primary image status */
  446. u32 primary_status;
  447. u32 secondary_present;
  448. /* MAC address , 4 ports, 32 address per port */
  449. u64 mac_addr[FLASH_NUM_PORTS * FLASH_NUM_MAC_PER_PORT];
  450. u32 sub_sys_id;
  451. u8 serial_num[32];
  452. /* Any user defined data */
  453. };
  454. #define SECONDARY_IMAGE_PRESENT 0xb3b4b5b6
  455. #define SECONDARY_IMAGE_ABSENT 0xffffffff
  456. #define PRIMARY_IMAGE_GOOD 0x5a5a5a5a
  457. #define PRIMARY_IMAGE_BAD 0xffffffff
  458. /* Flash memory map */
  459. typedef enum {
  460. CRBINIT_START = 0, /* Crbinit section */
  461. BRDCFG_START = 0x4000, /* board config */
  462. INITCODE_START = 0x6000, /* pegtune code */
  463. BOOTLD_START = 0x10000, /* bootld */
  464. IMAGE_START = 0x43000, /* compressed image */
  465. SECONDARY_START = 0x200000, /* backup images */
  466. PXE_START = 0x3E0000, /* user defined region */
  467. USER_START = 0x3E8000, /* User defined region for new boards */
  468. FIXED_START = 0x3F0000 /* backup of crbinit */
  469. } netxen_flash_map_t;
  470. #define USER_START_OLD PXE_START /* for backward compatibility */
  471. #define FLASH_START (CRBINIT_START)
  472. #define INIT_SECTOR (0)
  473. #define PRIMARY_START (BOOTLD_START)
  474. #define FLASH_CRBINIT_SIZE (0x4000)
  475. #define FLASH_BRDCFG_SIZE (sizeof(struct netxen_board_info))
  476. #define FLASH_USER_SIZE (sizeof(struct netxen_user_info)/sizeof(u32))
  477. #define FLASH_SECONDARY_SIZE (USER_START-SECONDARY_START)
  478. #define NUM_PRIMARY_SECTORS (0x20)
  479. #define NUM_CONFIG_SECTORS (1)
  480. #define PFX "netxen: "
  481. /* Note: Make sure to not call this before adapter->port is valid */
  482. #if !defined(NETXEN_DEBUG)
  483. #define DPRINTK(klevel, fmt, args...) do { \
  484. } while (0)
  485. #else
  486. #define DPRINTK(klevel, fmt, args...) do { \
  487. printk(KERN_##klevel PFX "%s: %s: " fmt, __FUNCTION__,\
  488. (adapter != NULL && \
  489. adapter->port[0] != NULL && \
  490. adapter->port[0]->netdev != NULL) ? \
  491. adapter->port[0]->netdev->name : NULL, \
  492. ## args); } while(0)
  493. #endif
  494. /* Number of status descriptors to handle per interrupt */
  495. #define MAX_STATUS_HANDLE (128)
  496. /*
  497. * netxen_skb_frag{} is to contain mapping info for each SG list. This
  498. * has to be freed when DMA is complete. This is part of netxen_tx_buffer{}.
  499. */
  500. struct netxen_skb_frag {
  501. u64 dma;
  502. u32 length;
  503. };
  504. /* Following defines are for the state of the buffers */
  505. #define NETXEN_BUFFER_FREE 0
  506. #define NETXEN_BUFFER_BUSY 1
  507. /*
  508. * There will be one netxen_buffer per skb packet. These will be
  509. * used to save the dma info for pci_unmap_page()
  510. */
  511. struct netxen_cmd_buffer {
  512. struct sk_buff *skb;
  513. struct netxen_skb_frag frag_array[MAX_BUFFERS_PER_CMD + 1];
  514. u32 total_length;
  515. u32 mss;
  516. u16 port;
  517. u8 cmd;
  518. u8 frag_count;
  519. unsigned long time_stamp;
  520. u32 state;
  521. u32 no_of_descriptors;
  522. };
  523. /* In rx_buffer, we do not need multiple fragments as is a single buffer */
  524. struct netxen_rx_buffer {
  525. struct sk_buff *skb;
  526. u64 dma;
  527. u16 ref_handle;
  528. u16 state;
  529. };
  530. /* Board types */
  531. #define NETXEN_NIC_GBE 0x01
  532. #define NETXEN_NIC_XGBE 0x02
  533. /*
  534. * One hardware_context{} per adapter
  535. * contains interrupt info as well shared hardware info.
  536. */
  537. struct netxen_hardware_context {
  538. struct pci_dev *pdev;
  539. void __iomem *pci_base0;
  540. void __iomem *pci_base1;
  541. void __iomem *pci_base2;
  542. u8 revision_id;
  543. u16 board_type;
  544. u16 max_ports;
  545. struct netxen_board_info boardcfg;
  546. u32 xg_linkup;
  547. u32 qg_linksup;
  548. /* Address of cmd ring in Phantom */
  549. struct cmd_desc_type0 *cmd_desc_head;
  550. char *pauseaddr;
  551. struct pci_dev *cmd_desc_pdev;
  552. dma_addr_t cmd_desc_phys_addr;
  553. dma_addr_t pause_physaddr;
  554. struct pci_dev *pause_pdev;
  555. struct netxen_adapter *adapter;
  556. };
  557. #define MINIMUM_ETHERNET_FRAME_SIZE 64 /* With FCS */
  558. #define ETHERNET_FCS_SIZE 4
  559. struct netxen_adapter_stats {
  560. u64 ints;
  561. u64 hostints;
  562. u64 otherints;
  563. u64 process_rcv;
  564. u64 process_xmit;
  565. u64 noxmitdone;
  566. u64 xmitcsummed;
  567. u64 post_called;
  568. u64 posted;
  569. u64 lastposted;
  570. u64 goodskbposts;
  571. };
  572. /*
  573. * Rcv Descriptor Context. One such per Rcv Descriptor. There may
  574. * be one Rcv Descriptor for normal packets, one for jumbo and may be others.
  575. */
  576. struct netxen_rcv_desc_ctx {
  577. u32 flags;
  578. u32 producer;
  579. u32 rcv_pending; /* Num of bufs posted in phantom */
  580. u32 rcv_free; /* Num of bufs in free list */
  581. dma_addr_t phys_addr;
  582. struct pci_dev *phys_pdev;
  583. struct rcv_desc *desc_head; /* address of rx ring in Phantom */
  584. u32 max_rx_desc_count;
  585. u32 dma_size;
  586. u32 skb_size;
  587. struct netxen_rx_buffer *rx_buf_arr; /* rx buffers for receive */
  588. int begin_alloc;
  589. };
  590. /*
  591. * Receive context. There is one such structure per instance of the
  592. * receive processing. Any state information that is relevant to
  593. * the receive, and is must be in this structure. The global data may be
  594. * present elsewhere.
  595. */
  596. struct netxen_recv_context {
  597. struct netxen_rcv_desc_ctx rcv_desc[NUM_RCV_DESC_RINGS];
  598. u32 status_rx_producer;
  599. u32 status_rx_consumer;
  600. dma_addr_t rcv_status_desc_phys_addr;
  601. struct pci_dev *rcv_status_desc_pdev;
  602. struct status_desc *rcv_status_desc_head;
  603. };
  604. #define NETXEN_NIC_MSI_ENABLED 0x02
  605. struct netxen_adapter {
  606. struct netxen_hardware_context ahw;
  607. int port_count; /* Number of configured ports */
  608. int active_ports; /* Number of open ports */
  609. struct netxen_port *port[NETXEN_MAX_PORTS]; /* ptr to each port */
  610. spinlock_t tx_lock;
  611. spinlock_t lock;
  612. struct work_struct watchdog_task;
  613. struct work_struct tx_timeout_task;
  614. struct timer_list watchdog_timer;
  615. u32 curr_window;
  616. u32 cmd_producer;
  617. u32 cmd_consumer;
  618. u32 last_cmd_consumer;
  619. u32 max_tx_desc_count;
  620. u32 max_rx_desc_count;
  621. u32 max_jumbo_rx_desc_count;
  622. /* Num of instances active on cmd buffer ring */
  623. u32 proc_cmd_buf_counter;
  624. u32 num_threads, total_threads; /*Use to keep track of xmit threads */
  625. u32 flags;
  626. u32 irq;
  627. int driver_mismatch;
  628. u32 temp;
  629. struct netxen_adapter_stats stats;
  630. struct netxen_cmd_buffer *cmd_buf_arr; /* Command buffers for xmit */
  631. /*
  632. * Receive instances. These can be either one per port,
  633. * or one per peg, etc.
  634. */
  635. struct netxen_recv_context recv_ctx[MAX_RCV_CTX];
  636. int is_up;
  637. int (*enable_phy_interrupts) (struct netxen_adapter *, int);
  638. int (*disable_phy_interrupts) (struct netxen_adapter *, int);
  639. void (*handle_phy_intr) (struct netxen_adapter *);
  640. int (*macaddr_set) (struct netxen_port *, netxen_ethernet_macaddr_t);
  641. int (*set_mtu) (struct netxen_port *, int);
  642. int (*set_promisc) (struct netxen_adapter *, int,
  643. netxen_niu_prom_mode_t);
  644. int (*unset_promisc) (struct netxen_adapter *, int,
  645. netxen_niu_prom_mode_t);
  646. int (*phy_read) (struct netxen_adapter *, long phy, long reg, u32 *);
  647. int (*phy_write) (struct netxen_adapter *, long phy, long reg, u32 val);
  648. int (*init_port) (struct netxen_adapter *, int);
  649. void (*init_niu) (struct netxen_adapter *);
  650. int (*stop_port) (struct netxen_adapter *, int);
  651. }; /* netxen_adapter structure */
  652. /* Max number of xmit producer threads that can run simultaneously */
  653. #define MAX_XMIT_PRODUCERS 16
  654. struct netxen_port_stats {
  655. u64 rcvdbadskb;
  656. u64 xmitcalled;
  657. u64 xmitedframes;
  658. u64 xmitfinished;
  659. u64 badskblen;
  660. u64 nocmddescriptor;
  661. u64 polled;
  662. u64 uphappy;
  663. u64 updropped;
  664. u64 uplcong;
  665. u64 uphcong;
  666. u64 upmcong;
  667. u64 updunno;
  668. u64 skbfreed;
  669. u64 txdropped;
  670. u64 txnullskb;
  671. u64 csummed;
  672. u64 no_rcv;
  673. u64 rxbytes;
  674. u64 txbytes;
  675. };
  676. struct netxen_port {
  677. struct netxen_adapter *adapter;
  678. u16 portnum; /* GBE port number */
  679. u16 link_speed;
  680. u16 link_duplex;
  681. u16 link_autoneg;
  682. int flags;
  683. struct net_device *netdev;
  684. struct pci_dev *pdev;
  685. struct net_device_stats net_stats;
  686. struct netxen_port_stats stats;
  687. };
  688. #define PCI_OFFSET_FIRST_RANGE(adapter, off) \
  689. ((adapter)->ahw.pci_base0 + (off))
  690. #define PCI_OFFSET_SECOND_RANGE(adapter, off) \
  691. ((adapter)->ahw.pci_base1 + (off) - SECOND_PAGE_GROUP_START)
  692. #define PCI_OFFSET_THIRD_RANGE(adapter, off) \
  693. ((adapter)->ahw.pci_base2 + (off) - THIRD_PAGE_GROUP_START)
  694. static inline void __iomem *pci_base_offset(struct netxen_adapter *adapter,
  695. unsigned long off)
  696. {
  697. if ((off < FIRST_PAGE_GROUP_END) && (off >= FIRST_PAGE_GROUP_START)) {
  698. return (adapter->ahw.pci_base0 + off);
  699. } else if ((off < SECOND_PAGE_GROUP_END) &&
  700. (off >= SECOND_PAGE_GROUP_START)) {
  701. return (adapter->ahw.pci_base1 + off - SECOND_PAGE_GROUP_START);
  702. } else if ((off < THIRD_PAGE_GROUP_END) &&
  703. (off >= THIRD_PAGE_GROUP_START)) {
  704. return (adapter->ahw.pci_base2 + off - THIRD_PAGE_GROUP_START);
  705. }
  706. return NULL;
  707. }
  708. static inline void __iomem *pci_base(struct netxen_adapter *adapter,
  709. unsigned long off)
  710. {
  711. if ((off < FIRST_PAGE_GROUP_END) && (off >= FIRST_PAGE_GROUP_START)) {
  712. return adapter->ahw.pci_base0;
  713. } else if ((off < SECOND_PAGE_GROUP_END) &&
  714. (off >= SECOND_PAGE_GROUP_START)) {
  715. return adapter->ahw.pci_base1;
  716. } else if ((off < THIRD_PAGE_GROUP_END) &&
  717. (off >= THIRD_PAGE_GROUP_START)) {
  718. return adapter->ahw.pci_base2;
  719. }
  720. return NULL;
  721. }
  722. extern char netxen_nic_driver_name[];
  723. int netxen_niu_xgbe_enable_phy_interrupts(struct netxen_adapter *adapter,
  724. int port);
  725. int netxen_niu_gbe_enable_phy_interrupts(struct netxen_adapter *adapter,
  726. int port);
  727. int netxen_niu_xgbe_disable_phy_interrupts(struct netxen_adapter *adapter,
  728. int port);
  729. int netxen_niu_gbe_disable_phy_interrupts(struct netxen_adapter *adapter,
  730. int port);
  731. int netxen_niu_xgbe_clear_phy_interrupts(struct netxen_adapter *adapter,
  732. int port);
  733. int netxen_niu_gbe_clear_phy_interrupts(struct netxen_adapter *adapter,
  734. int port);
  735. void netxen_nic_xgbe_handle_phy_intr(struct netxen_adapter *adapter);
  736. void netxen_nic_gbe_handle_phy_intr(struct netxen_adapter *adapter);
  737. void netxen_niu_gbe_set_mii_mode(struct netxen_adapter *adapter, int port,
  738. long enable);
  739. void netxen_niu_gbe_set_gmii_mode(struct netxen_adapter *adapter, int port,
  740. long enable);
  741. int netxen_niu_gbe_phy_read(struct netxen_adapter *adapter, long phy, long reg,
  742. __le32 * readval);
  743. int netxen_niu_gbe_phy_write(struct netxen_adapter *adapter, long phy,
  744. long reg, __le32 val);
  745. /* Functions available from netxen_nic_hw.c */
  746. int netxen_nic_set_mtu_xgb(struct netxen_port *port, int new_mtu);
  747. int netxen_nic_set_mtu_gb(struct netxen_port *port, int new_mtu);
  748. void netxen_nic_init_niu_gb(struct netxen_adapter *adapter);
  749. void netxen_nic_pci_change_crbwindow(struct netxen_adapter *adapter, u32 wndw);
  750. void netxen_nic_reg_write(struct netxen_adapter *adapter, u64 off, u32 val);
  751. int netxen_nic_reg_read(struct netxen_adapter *adapter, u64 off);
  752. void netxen_nic_write_w0(struct netxen_adapter *adapter, u32 index, u32 value);
  753. void netxen_nic_read_w0(struct netxen_adapter *adapter, u32 index, u32 * value);
  754. int netxen_nic_get_board_info(struct netxen_adapter *adapter);
  755. int netxen_nic_hw_read_wx(struct netxen_adapter *adapter, u64 off, void *data,
  756. int len);
  757. int netxen_nic_hw_write_wx(struct netxen_adapter *adapter, u64 off, void *data,
  758. int len);
  759. void netxen_crb_writelit_adapter(struct netxen_adapter *adapter,
  760. unsigned long off, int data);
  761. /* Functions from netxen_nic_init.c */
  762. void netxen_phantom_init(struct netxen_adapter *adapter, int pegtune_val);
  763. void netxen_load_firmware(struct netxen_adapter *adapter);
  764. int netxen_pinit_from_rom(struct netxen_adapter *adapter, int verbose);
  765. int netxen_rom_fast_read(struct netxen_adapter *adapter, int addr, int *valp);
  766. int netxen_rom_fast_write(struct netxen_adapter *adapter, int addr, int data);
  767. int netxen_rom_se(struct netxen_adapter *adapter, int addr);
  768. int netxen_do_rom_se(struct netxen_adapter *adapter, int addr);
  769. /* Functions from netxen_nic_isr.c */
  770. void netxen_nic_isr_other(struct netxen_adapter *adapter);
  771. void netxen_indicate_link_status(struct netxen_adapter *adapter, u32 port,
  772. u32 link);
  773. void netxen_handle_port_int(struct netxen_adapter *adapter, u32 port,
  774. u32 enable);
  775. void netxen_nic_stop_all_ports(struct netxen_adapter *adapter);
  776. void netxen_initialize_adapter_sw(struct netxen_adapter *adapter);
  777. void netxen_initialize_adapter_hw(struct netxen_adapter *adapter);
  778. void *netxen_alloc(struct pci_dev *pdev, size_t sz, dma_addr_t * ptr,
  779. struct pci_dev **used_dev);
  780. void netxen_initialize_adapter_ops(struct netxen_adapter *adapter);
  781. int netxen_init_firmware(struct netxen_adapter *adapter);
  782. void netxen_free_hw_resources(struct netxen_adapter *adapter);
  783. void netxen_tso_check(struct netxen_adapter *adapter,
  784. struct cmd_desc_type0 *desc, struct sk_buff *skb);
  785. int netxen_nic_hw_resources(struct netxen_adapter *adapter);
  786. void netxen_nic_clear_stats(struct netxen_adapter *adapter);
  787. int
  788. netxen_nic_do_ioctl(struct netxen_adapter *adapter, void *u_data,
  789. struct netxen_port *port);
  790. int netxen_nic_rx_has_work(struct netxen_adapter *adapter);
  791. int netxen_nic_tx_has_work(struct netxen_adapter *adapter);
  792. void netxen_watchdog_task(unsigned long v);
  793. void netxen_post_rx_buffers(struct netxen_adapter *adapter, u32 ctx,
  794. u32 ringid);
  795. void netxen_process_cmd_ring(unsigned long data);
  796. u32 netxen_process_rcv_ring(struct netxen_adapter *adapter, int ctx, int max);
  797. void netxen_nic_set_multi(struct net_device *netdev);
  798. int netxen_nic_change_mtu(struct net_device *netdev, int new_mtu);
  799. int netxen_nic_set_mac(struct net_device *netdev, void *p);
  800. struct net_device_stats *netxen_nic_get_stats(struct net_device *netdev);
  801. static inline void netxen_nic_disable_int(struct netxen_adapter *adapter)
  802. {
  803. /*
  804. * ISR_INT_MASK: Can be read from window 0 or 1.
  805. */
  806. writel(0x7ff, PCI_OFFSET_SECOND_RANGE(adapter, ISR_INT_MASK));
  807. }
  808. static inline void netxen_nic_enable_int(struct netxen_adapter *adapter)
  809. {
  810. u32 mask;
  811. switch (adapter->ahw.board_type) {
  812. case NETXEN_NIC_GBE:
  813. mask = 0x77b;
  814. break;
  815. case NETXEN_NIC_XGBE:
  816. mask = 0x77f;
  817. break;
  818. default:
  819. mask = 0x7ff;
  820. break;
  821. }
  822. writel(mask, PCI_OFFSET_SECOND_RANGE(adapter, ISR_INT_MASK));
  823. if (!(adapter->flags & NETXEN_NIC_MSI_ENABLED)) {
  824. mask = 0xbff;
  825. writel(mask, PCI_OFFSET_SECOND_RANGE(adapter,
  826. ISR_INT_TARGET_MASK));
  827. }
  828. }
  829. /*
  830. * NetXen Board information
  831. */
  832. #define NETXEN_MAX_SHORT_NAME 16
  833. struct netxen_brdinfo {
  834. netxen_brdtype_t brdtype; /* type of board */
  835. long ports; /* max no of physical ports */
  836. char short_name[NETXEN_MAX_SHORT_NAME];
  837. };
  838. static const struct netxen_brdinfo netxen_boards[] = {
  839. {NETXEN_BRDTYPE_P2_SB31_10G_CX4, 1, "XGb CX4"},
  840. {NETXEN_BRDTYPE_P2_SB31_10G_HMEZ, 1, "XGb HMEZ"},
  841. {NETXEN_BRDTYPE_P2_SB31_10G_IMEZ, 2, "XGb IMEZ"},
  842. {NETXEN_BRDTYPE_P2_SB31_10G, 1, "XGb XFP"},
  843. {NETXEN_BRDTYPE_P2_SB35_4G, 4, "Quad Gb"},
  844. {NETXEN_BRDTYPE_P2_SB31_2G, 2, "Dual Gb"},
  845. };
  846. #define NUM_SUPPORTED_BOARDS (sizeof(netxen_boards)/sizeof(struct netxen_brdinfo))
  847. static inline void get_brd_port_by_type(u32 type, int *ports)
  848. {
  849. int i, found = 0;
  850. for (i = 0; i < NUM_SUPPORTED_BOARDS; ++i) {
  851. if (netxen_boards[i].brdtype == type) {
  852. *ports = netxen_boards[i].ports;
  853. found = 1;
  854. break;
  855. }
  856. }
  857. if (!found)
  858. *ports = 0;
  859. }
  860. static inline void get_brd_name_by_type(u32 type, char *name)
  861. {
  862. int i, found = 0;
  863. for (i = 0; i < NUM_SUPPORTED_BOARDS; ++i) {
  864. if (netxen_boards[i].brdtype == type) {
  865. strcpy(name, netxen_boards[i].short_name);
  866. found = 1;
  867. break;
  868. }
  869. }
  870. if (!found)
  871. name = "Unknown";
  872. }
  873. int netxen_is_flash_supported(struct netxen_adapter *adapter);
  874. int netxen_get_flash_mac_addr(struct netxen_adapter *adapter, u64 mac[]);
  875. extern void netxen_change_ringparam(struct netxen_adapter *adapter);
  876. extern int netxen_rom_fast_read(struct netxen_adapter *adapter, int addr,
  877. int *valp);
  878. extern struct ethtool_ops netxen_nic_ethtool_ops;
  879. #endif /* __NETXEN_NIC_H_ */