netxen_nic.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050
  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 1024
  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. #define NUM_SUPPORTED_BOARDS (sizeof(netxen_boards)/sizeof(netxen_brdinfo_t))
  288. typedef enum {
  289. NETXEN_BRDMFG_INVENTEC = 1
  290. } netxen_brdmfg;
  291. typedef enum {
  292. MEM_ORG_128Mbx4 = 0x0, /* DDR1 only */
  293. MEM_ORG_128Mbx8 = 0x1, /* DDR1 only */
  294. MEM_ORG_128Mbx16 = 0x2, /* DDR1 only */
  295. MEM_ORG_256Mbx4 = 0x3,
  296. MEM_ORG_256Mbx8 = 0x4,
  297. MEM_ORG_256Mbx16 = 0x5,
  298. MEM_ORG_512Mbx4 = 0x6,
  299. MEM_ORG_512Mbx8 = 0x7,
  300. MEM_ORG_512Mbx16 = 0x8,
  301. MEM_ORG_1Gbx4 = 0x9,
  302. MEM_ORG_1Gbx8 = 0xa,
  303. MEM_ORG_1Gbx16 = 0xb,
  304. MEM_ORG_2Gbx4 = 0xc,
  305. MEM_ORG_2Gbx8 = 0xd,
  306. MEM_ORG_2Gbx16 = 0xe,
  307. MEM_ORG_128Mbx32 = 0x10002, /* GDDR only */
  308. MEM_ORG_256Mbx32 = 0x10005 /* GDDR only */
  309. } netxen_mn_mem_org_t;
  310. typedef enum {
  311. MEM_ORG_512Kx36 = 0x0,
  312. MEM_ORG_1Mx36 = 0x1,
  313. MEM_ORG_2Mx36 = 0x2
  314. } netxen_sn_mem_org_t;
  315. typedef enum {
  316. MEM_DEPTH_4MB = 0x1,
  317. MEM_DEPTH_8MB = 0x2,
  318. MEM_DEPTH_16MB = 0x3,
  319. MEM_DEPTH_32MB = 0x4,
  320. MEM_DEPTH_64MB = 0x5,
  321. MEM_DEPTH_128MB = 0x6,
  322. MEM_DEPTH_256MB = 0x7,
  323. MEM_DEPTH_512MB = 0x8,
  324. MEM_DEPTH_1GB = 0x9,
  325. MEM_DEPTH_2GB = 0xa,
  326. MEM_DEPTH_4GB = 0xb,
  327. MEM_DEPTH_8GB = 0xc,
  328. MEM_DEPTH_16GB = 0xd,
  329. MEM_DEPTH_32GB = 0xe
  330. } netxen_mem_depth_t;
  331. struct netxen_board_info {
  332. u32 header_version;
  333. u32 board_mfg;
  334. u32 board_type;
  335. u32 board_num;
  336. u32 chip_id;
  337. u32 chip_minor;
  338. u32 chip_major;
  339. u32 chip_pkg;
  340. u32 chip_lot;
  341. u32 port_mask; /* available niu ports */
  342. u32 peg_mask; /* available pegs */
  343. u32 icache_ok; /* can we run with icache? */
  344. u32 dcache_ok; /* can we run with dcache? */
  345. u32 casper_ok;
  346. u32 mac_addr_lo_0;
  347. u32 mac_addr_lo_1;
  348. u32 mac_addr_lo_2;
  349. u32 mac_addr_lo_3;
  350. /* MN-related config */
  351. u32 mn_sync_mode; /* enable/ sync shift cclk/ sync shift mclk */
  352. u32 mn_sync_shift_cclk;
  353. u32 mn_sync_shift_mclk;
  354. u32 mn_wb_en;
  355. u32 mn_crystal_freq; /* in MHz */
  356. u32 mn_speed; /* in MHz */
  357. u32 mn_org;
  358. u32 mn_depth;
  359. u32 mn_ranks_0; /* ranks per slot */
  360. u32 mn_ranks_1; /* ranks per slot */
  361. u32 mn_rd_latency_0;
  362. u32 mn_rd_latency_1;
  363. u32 mn_rd_latency_2;
  364. u32 mn_rd_latency_3;
  365. u32 mn_rd_latency_4;
  366. u32 mn_rd_latency_5;
  367. u32 mn_rd_latency_6;
  368. u32 mn_rd_latency_7;
  369. u32 mn_rd_latency_8;
  370. u32 mn_dll_val[18];
  371. u32 mn_mode_reg; /* MIU DDR Mode Register */
  372. u32 mn_ext_mode_reg; /* MIU DDR Extended Mode Register */
  373. u32 mn_timing_0; /* MIU Memory Control Timing Rgister */
  374. u32 mn_timing_1; /* MIU Extended Memory Ctrl Timing Register */
  375. u32 mn_timing_2; /* MIU Extended Memory Ctrl Timing2 Register */
  376. /* SN-related config */
  377. u32 sn_sync_mode; /* enable/ sync shift cclk / sync shift mclk */
  378. u32 sn_pt_mode; /* pass through mode */
  379. u32 sn_ecc_en;
  380. u32 sn_wb_en;
  381. u32 sn_crystal_freq;
  382. u32 sn_speed;
  383. u32 sn_org;
  384. u32 sn_depth;
  385. u32 sn_dll_tap;
  386. u32 sn_rd_latency;
  387. u32 mac_addr_hi_0;
  388. u32 mac_addr_hi_1;
  389. u32 mac_addr_hi_2;
  390. u32 mac_addr_hi_3;
  391. u32 magic; /* indicates flash has been initialized */
  392. u32 mn_rdimm;
  393. u32 mn_dll_override;
  394. };
  395. #define FLASH_NUM_PORTS (4)
  396. struct netxen_flash_mac_addr {
  397. u32 flash_addr[32];
  398. };
  399. struct netxen_user_old_info {
  400. u8 flash_md5[16];
  401. u8 crbinit_md5[16];
  402. u8 brdcfg_md5[16];
  403. /* bootloader */
  404. u32 bootld_version;
  405. u32 bootld_size;
  406. u8 bootld_md5[16];
  407. /* image */
  408. u32 image_version;
  409. u32 image_size;
  410. u8 image_md5[16];
  411. /* primary image status */
  412. u32 primary_status;
  413. u32 secondary_present;
  414. /* MAC address , 4 ports */
  415. struct netxen_flash_mac_addr mac_addr[FLASH_NUM_PORTS];
  416. };
  417. #define FLASH_NUM_MAC_PER_PORT 32
  418. struct netxen_user_info {
  419. u8 flash_md5[16 * 64];
  420. /* bootloader */
  421. u32 bootld_version;
  422. u32 bootld_size;
  423. /* image */
  424. u32 image_version;
  425. u32 image_size;
  426. /* primary image status */
  427. u32 primary_status;
  428. u32 secondary_present;
  429. /* MAC address , 4 ports, 32 address per port */
  430. u64 mac_addr[FLASH_NUM_PORTS * FLASH_NUM_MAC_PER_PORT];
  431. u32 sub_sys_id;
  432. u8 serial_num[32];
  433. /* Any user defined data */
  434. };
  435. /*
  436. * Flash Layout - new format.
  437. */
  438. struct netxen_new_user_info {
  439. u8 flash_md5[16 * 64];
  440. /* bootloader */
  441. u32 bootld_version;
  442. u32 bootld_size;
  443. /* image */
  444. u32 image_version;
  445. u32 image_size;
  446. /* primary image status */
  447. u32 primary_status;
  448. u32 secondary_present;
  449. /* MAC address , 4 ports, 32 address per port */
  450. u64 mac_addr[FLASH_NUM_PORTS * FLASH_NUM_MAC_PER_PORT];
  451. u32 sub_sys_id;
  452. u8 serial_num[32];
  453. /* Any user defined data */
  454. };
  455. #define SECONDARY_IMAGE_PRESENT 0xb3b4b5b6
  456. #define SECONDARY_IMAGE_ABSENT 0xffffffff
  457. #define PRIMARY_IMAGE_GOOD 0x5a5a5a5a
  458. #define PRIMARY_IMAGE_BAD 0xffffffff
  459. /* Flash memory map */
  460. typedef enum {
  461. CRBINIT_START = 0, /* Crbinit section */
  462. BRDCFG_START = 0x4000, /* board config */
  463. INITCODE_START = 0x6000, /* pegtune code */
  464. BOOTLD_START = 0x10000, /* bootld */
  465. IMAGE_START = 0x43000, /* compressed image */
  466. SECONDARY_START = 0x200000, /* backup images */
  467. PXE_START = 0x3E0000, /* user defined region */
  468. USER_START = 0x3E8000, /* User defined region for new boards */
  469. FIXED_START = 0x3F0000 /* backup of crbinit */
  470. } netxen_flash_map_t;
  471. #define USER_START_OLD PXE_START /* for backward compatibility */
  472. #define FLASH_START (CRBINIT_START)
  473. #define INIT_SECTOR (0)
  474. #define PRIMARY_START (BOOTLD_START)
  475. #define FLASH_CRBINIT_SIZE (0x4000)
  476. #define FLASH_BRDCFG_SIZE (sizeof(struct netxen_board_info))
  477. #define FLASH_USER_SIZE (sizeof(netxen_user_info)/sizeof(u32))
  478. #define FLASH_SECONDARY_SIZE (USER_START-SECONDARY_START)
  479. #define NUM_PRIMARY_SECTORS (0x20)
  480. #define NUM_CONFIG_SECTORS (1)
  481. #define PFX "netxen: "
  482. /* Note: Make sure to not call this before adapter->port is valid */
  483. #if !defined(NETXEN_DEBUG)
  484. #define DPRINTK(klevel, fmt, args...) do { \
  485. } while (0)
  486. #else
  487. #define DPRINTK(klevel, fmt, args...) do { \
  488. printk(KERN_##klevel PFX "%s: %s: " fmt, __FUNCTION__,\
  489. (adapter != NULL && adapter->port != NULL && \
  490. adapter->port[0] != NULL && \
  491. adapter->port[0]->netdev != NULL) ? \
  492. adapter->port[0]->netdev->name : NULL, \
  493. ## args); } while(0)
  494. #endif
  495. /* Number of status descriptors to handle per interrupt */
  496. #define MAX_STATUS_HANDLE (128)
  497. /*
  498. * netxen_skb_frag{} is to contain mapping info for each SG list. This
  499. * has to be freed when DMA is complete. This is part of netxen_tx_buffer{}.
  500. */
  501. struct netxen_skb_frag {
  502. u64 dma;
  503. u32 length;
  504. };
  505. /* Following defines are for the state of the buffers */
  506. #define NETXEN_BUFFER_FREE 0
  507. #define NETXEN_BUFFER_BUSY 1
  508. /*
  509. * There will be one netxen_buffer per skb packet. These will be
  510. * used to save the dma info for pci_unmap_page()
  511. */
  512. struct netxen_cmd_buffer {
  513. struct sk_buff *skb;
  514. struct netxen_skb_frag frag_array[MAX_BUFFERS_PER_CMD + 1];
  515. u32 total_length;
  516. u32 mss;
  517. u16 port;
  518. u8 cmd;
  519. u8 frag_count;
  520. unsigned long time_stamp;
  521. u32 state;
  522. u32 no_of_descriptors;
  523. };
  524. /* In rx_buffer, we do not need multiple fragments as is a single buffer */
  525. struct netxen_rx_buffer {
  526. struct sk_buff *skb;
  527. u64 dma;
  528. u16 ref_handle;
  529. u16 state;
  530. };
  531. /* Board types */
  532. #define NETXEN_NIC_GBE 0x01
  533. #define NETXEN_NIC_XGBE 0x02
  534. /*
  535. * One hardware_context{} per adapter
  536. * contains interrupt info as well shared hardware info.
  537. */
  538. struct netxen_hardware_context {
  539. struct pci_dev *pdev;
  540. void __iomem *pci_base0;
  541. void __iomem *pci_base1;
  542. void __iomem *pci_base2;
  543. u8 revision_id;
  544. u16 board_type;
  545. u16 max_ports;
  546. struct netxen_board_info boardcfg;
  547. u32 xg_linkup;
  548. u32 qg_linksup;
  549. /* Address of cmd ring in Phantom */
  550. struct cmd_desc_type0 *cmd_desc_head;
  551. char *pauseaddr;
  552. struct pci_dev *cmd_desc_pdev;
  553. dma_addr_t cmd_desc_phys_addr;
  554. dma_addr_t pause_physaddr;
  555. struct pci_dev *pause_pdev;
  556. struct netxen_adapter *adapter;
  557. };
  558. #define MINIMUM_ETHERNET_FRAME_SIZE 64 /* With FCS */
  559. #define ETHERNET_FCS_SIZE 4
  560. struct netxen_adapter_stats {
  561. u64 ints;
  562. u64 hostints;
  563. u64 otherints;
  564. u64 process_rcv;
  565. u64 process_xmit;
  566. u64 noxmitdone;
  567. u64 xmitcsummed;
  568. u64 post_called;
  569. u64 posted;
  570. u64 lastposted;
  571. u64 goodskbposts;
  572. };
  573. /*
  574. * Rcv Descriptor Context. One such per Rcv Descriptor. There may
  575. * be one Rcv Descriptor for normal packets, one for jumbo and may be others.
  576. */
  577. struct netxen_rcv_desc_ctx {
  578. u32 flags;
  579. u32 producer;
  580. u32 rcv_pending; /* Num of bufs posted in phantom */
  581. u32 rcv_free; /* Num of bufs in free list */
  582. dma_addr_t phys_addr;
  583. struct pci_dev *phys_pdev;
  584. struct rcv_desc *desc_head; /* address of rx ring in Phantom */
  585. u32 max_rx_desc_count;
  586. u32 dma_size;
  587. u32 skb_size;
  588. struct netxen_rx_buffer *rx_buf_arr; /* rx buffers for receive */
  589. int begin_alloc;
  590. };
  591. /*
  592. * Receive context. There is one such structure per instance of the
  593. * receive processing. Any state information that is relevant to
  594. * the receive, and is must be in this structure. The global data may be
  595. * present elsewhere.
  596. */
  597. struct netxen_recv_context {
  598. struct netxen_rcv_desc_ctx rcv_desc[NUM_RCV_DESC_RINGS];
  599. u32 status_rx_producer;
  600. u32 status_rx_consumer;
  601. dma_addr_t rcv_status_desc_phys_addr;
  602. struct pci_dev *rcv_status_desc_pdev;
  603. struct status_desc *rcv_status_desc_head;
  604. };
  605. #define NETXEN_NIC_MSI_ENABLED 0x02
  606. struct netxen_drvops;
  607. struct netxen_adapter {
  608. struct netxen_hardware_context ahw;
  609. int port_count; /* Number of configured ports */
  610. int active_ports; /* Number of open ports */
  611. struct netxen_port *port[NETXEN_MAX_PORTS]; /* ptr to each port */
  612. spinlock_t tx_lock;
  613. spinlock_t lock;
  614. struct work_struct watchdog_task;
  615. struct work_struct tx_timeout_task;
  616. struct timer_list watchdog_timer;
  617. u32 curr_window;
  618. u32 cmd_producer;
  619. u32 cmd_consumer;
  620. u32 last_cmd_consumer;
  621. u32 max_tx_desc_count;
  622. u32 max_rx_desc_count;
  623. u32 max_jumbo_rx_desc_count;
  624. /* Num of instances active on cmd buffer ring */
  625. u32 proc_cmd_buf_counter;
  626. u32 num_threads, total_threads; /*Use to keep track of xmit threads */
  627. u32 flags;
  628. u32 irq;
  629. int driver_mismatch;
  630. u32 temp;
  631. struct netxen_adapter_stats stats;
  632. struct netxen_cmd_buffer *cmd_buf_arr; /* Command buffers for xmit */
  633. /*
  634. * Receive instances. These can be either one per port,
  635. * or one per peg, etc.
  636. */
  637. struct netxen_recv_context recv_ctx[MAX_RCV_CTX];
  638. int is_up;
  639. int work_done;
  640. struct netxen_drvops *ops;
  641. }; /* netxen_adapter structure */
  642. /* Max number of xmit producer threads that can run simultaneously */
  643. #define MAX_XMIT_PRODUCERS 16
  644. struct netxen_port_stats {
  645. u64 rcvdbadskb;
  646. u64 xmitcalled;
  647. u64 xmitedframes;
  648. u64 xmitfinished;
  649. u64 badskblen;
  650. u64 nocmddescriptor;
  651. u64 polled;
  652. u64 uphappy;
  653. u64 updropped;
  654. u64 uplcong;
  655. u64 uphcong;
  656. u64 upmcong;
  657. u64 updunno;
  658. u64 skbfreed;
  659. u64 txdropped;
  660. u64 txnullskb;
  661. u64 csummed;
  662. u64 no_rcv;
  663. u64 rxbytes;
  664. u64 txbytes;
  665. };
  666. struct netxen_port {
  667. struct netxen_adapter *adapter;
  668. u16 portnum; /* GBE port number */
  669. u16 link_speed;
  670. u16 link_duplex;
  671. u16 link_autoneg;
  672. int flags;
  673. struct net_device *netdev;
  674. struct pci_dev *pdev;
  675. struct net_device_stats net_stats;
  676. struct netxen_port_stats stats;
  677. };
  678. #define PCI_OFFSET_FIRST_RANGE(adapter, off) \
  679. ((adapter)->ahw.pci_base0 + (off))
  680. #define PCI_OFFSET_SECOND_RANGE(adapter, off) \
  681. ((adapter)->ahw.pci_base1 + (off) - SECOND_PAGE_GROUP_START)
  682. #define PCI_OFFSET_THIRD_RANGE(adapter, off) \
  683. ((adapter)->ahw.pci_base2 + (off) - THIRD_PAGE_GROUP_START)
  684. static inline void __iomem *pci_base_offset(struct netxen_adapter *adapter,
  685. unsigned long off)
  686. {
  687. if ((off < FIRST_PAGE_GROUP_END) && (off >= FIRST_PAGE_GROUP_START)) {
  688. return (adapter->ahw.pci_base0 + off);
  689. } else if ((off < SECOND_PAGE_GROUP_END) &&
  690. (off >= SECOND_PAGE_GROUP_START)) {
  691. return (adapter->ahw.pci_base1 + off - SECOND_PAGE_GROUP_START);
  692. } else if ((off < THIRD_PAGE_GROUP_END) &&
  693. (off >= THIRD_PAGE_GROUP_START)) {
  694. return (adapter->ahw.pci_base2 + off - THIRD_PAGE_GROUP_START);
  695. }
  696. return NULL;
  697. }
  698. static inline void __iomem *pci_base(struct netxen_adapter *adapter,
  699. unsigned long off)
  700. {
  701. if ((off < FIRST_PAGE_GROUP_END) && (off >= FIRST_PAGE_GROUP_START)) {
  702. return adapter->ahw.pci_base0;
  703. } else if ((off < SECOND_PAGE_GROUP_END) &&
  704. (off >= SECOND_PAGE_GROUP_START)) {
  705. return adapter->ahw.pci_base1;
  706. } else if ((off < THIRD_PAGE_GROUP_END) &&
  707. (off >= THIRD_PAGE_GROUP_START)) {
  708. return adapter->ahw.pci_base2;
  709. }
  710. return NULL;
  711. }
  712. struct netxen_drvops {
  713. int (*enable_phy_interrupts) (struct netxen_adapter *, int);
  714. int (*disable_phy_interrupts) (struct netxen_adapter *, int);
  715. void (*handle_phy_intr) (struct netxen_adapter *);
  716. int (*macaddr_set) (struct netxen_port *, netxen_ethernet_macaddr_t);
  717. int (*set_mtu) (struct netxen_port *, int);
  718. int (*set_promisc) (struct netxen_adapter *, int,
  719. netxen_niu_prom_mode_t);
  720. int (*unset_promisc) (struct netxen_adapter *, int,
  721. netxen_niu_prom_mode_t);
  722. int (*phy_read) (struct netxen_adapter *, long phy, long reg, u32 *);
  723. int (*phy_write) (struct netxen_adapter *, long phy, long reg, u32 val);
  724. int (*init_port) (struct netxen_adapter *, int);
  725. void (*init_niu) (struct netxen_adapter *);
  726. int (*stop_port) (struct netxen_adapter *, int);
  727. };
  728. extern char netxen_nic_driver_name[];
  729. int netxen_niu_xgbe_enable_phy_interrupts(struct netxen_adapter *adapter,
  730. int port);
  731. int netxen_niu_gbe_enable_phy_interrupts(struct netxen_adapter *adapter,
  732. int port);
  733. int netxen_niu_xgbe_disable_phy_interrupts(struct netxen_adapter *adapter,
  734. int port);
  735. int netxen_niu_gbe_disable_phy_interrupts(struct netxen_adapter *adapter,
  736. int port);
  737. int netxen_niu_xgbe_clear_phy_interrupts(struct netxen_adapter *adapter,
  738. int port);
  739. int netxen_niu_gbe_clear_phy_interrupts(struct netxen_adapter *adapter,
  740. int port);
  741. void netxen_nic_xgbe_handle_phy_intr(struct netxen_adapter *adapter);
  742. void netxen_nic_gbe_handle_phy_intr(struct netxen_adapter *adapter);
  743. void netxen_niu_gbe_set_mii_mode(struct netxen_adapter *adapter, int port,
  744. long enable);
  745. void netxen_niu_gbe_set_gmii_mode(struct netxen_adapter *adapter, int port,
  746. long enable);
  747. int netxen_niu_gbe_phy_read(struct netxen_adapter *adapter, long phy, long reg,
  748. __le32 * readval);
  749. int netxen_niu_gbe_phy_write(struct netxen_adapter *adapter, long phy,
  750. long reg, __le32 val);
  751. /* Functions available from netxen_nic_hw.c */
  752. int netxen_nic_set_mtu_xgb(struct netxen_port *port, int new_mtu);
  753. int netxen_nic_set_mtu_gb(struct netxen_port *port, int new_mtu);
  754. void netxen_nic_init_niu_gb(struct netxen_adapter *adapter);
  755. void netxen_nic_pci_change_crbwindow(struct netxen_adapter *adapter, u32 wndw);
  756. void netxen_nic_reg_write(struct netxen_adapter *adapter, u64 off, u32 val);
  757. int netxen_nic_reg_read(struct netxen_adapter *adapter, u64 off);
  758. void netxen_nic_write_w0(struct netxen_adapter *adapter, u32 index, u32 value);
  759. void netxen_nic_read_w0(struct netxen_adapter *adapter, u32 index, u32 * value);
  760. int netxen_nic_get_board_info(struct netxen_adapter *adapter);
  761. int netxen_nic_hw_read_wx(struct netxen_adapter *adapter, u64 off, void *data,
  762. int len);
  763. int netxen_nic_hw_write_wx(struct netxen_adapter *adapter, u64 off, void *data,
  764. int len);
  765. void netxen_crb_writelit_adapter(struct netxen_adapter *adapter,
  766. unsigned long off, int data);
  767. /* Functions from netxen_nic_init.c */
  768. void netxen_phantom_init(struct netxen_adapter *adapter, int pegtune_val);
  769. void netxen_load_firmware(struct netxen_adapter *adapter);
  770. int netxen_pinit_from_rom(struct netxen_adapter *adapter, int verbose);
  771. int netxen_rom_fast_read(struct netxen_adapter *adapter, int addr, int *valp);
  772. int netxen_rom_fast_write(struct netxen_adapter *adapter, int addr, int data);
  773. int netxen_rom_se(struct netxen_adapter *adapter, int addr);
  774. int netxen_do_rom_se(struct netxen_adapter *adapter, int addr);
  775. /* Functions from netxen_nic_isr.c */
  776. void netxen_nic_isr_other(struct netxen_adapter *adapter);
  777. void netxen_indicate_link_status(struct netxen_adapter *adapter, u32 port,
  778. u32 link);
  779. void netxen_handle_port_int(struct netxen_adapter *adapter, u32 port,
  780. u32 enable);
  781. void netxen_nic_stop_all_ports(struct netxen_adapter *adapter);
  782. void netxen_initialize_adapter_sw(struct netxen_adapter *adapter);
  783. void netxen_initialize_adapter_hw(struct netxen_adapter *adapter);
  784. void *netxen_alloc(struct pci_dev *pdev, size_t sz, dma_addr_t * ptr,
  785. struct pci_dev **used_dev);
  786. void netxen_initialize_adapter_ops(struct netxen_adapter *adapter);
  787. int netxen_init_firmware(struct netxen_adapter *adapter);
  788. void netxen_free_hw_resources(struct netxen_adapter *adapter);
  789. void netxen_tso_check(struct netxen_adapter *adapter,
  790. struct cmd_desc_type0 *desc, struct sk_buff *skb);
  791. int netxen_nic_hw_resources(struct netxen_adapter *adapter);
  792. void netxen_nic_clear_stats(struct netxen_adapter *adapter);
  793. int
  794. netxen_nic_do_ioctl(struct netxen_adapter *adapter, void *u_data,
  795. struct netxen_port *port);
  796. int netxen_nic_rx_has_work(struct netxen_adapter *adapter);
  797. int netxen_nic_tx_has_work(struct netxen_adapter *adapter);
  798. void netxen_watchdog_task(unsigned long v);
  799. void netxen_post_rx_buffers(struct netxen_adapter *adapter, u32 ctx,
  800. u32 ringid);
  801. void netxen_process_cmd_ring(unsigned long data);
  802. u32 netxen_process_rcv_ring(struct netxen_adapter *adapter, int ctx, int max);
  803. void netxen_nic_set_multi(struct net_device *netdev);
  804. int netxen_nic_change_mtu(struct net_device *netdev, int new_mtu);
  805. int netxen_nic_set_mac(struct net_device *netdev, void *p);
  806. struct net_device_stats *netxen_nic_get_stats(struct net_device *netdev);
  807. static inline void netxen_nic_disable_int(struct netxen_adapter *adapter)
  808. {
  809. /*
  810. * ISR_INT_MASK: Can be read from window 0 or 1.
  811. */
  812. writel(0x7ff,
  813. (void __iomem
  814. *)(PCI_OFFSET_SECOND_RANGE(adapter, ISR_INT_MASK)));
  815. }
  816. static inline void netxen_nic_enable_int(struct netxen_adapter *adapter)
  817. {
  818. u32 mask;
  819. switch (adapter->ahw.board_type) {
  820. case NETXEN_NIC_GBE:
  821. mask = 0x77b;
  822. break;
  823. case NETXEN_NIC_XGBE:
  824. mask = 0x77f;
  825. break;
  826. default:
  827. mask = 0x7ff;
  828. break;
  829. }
  830. writel(mask,
  831. (void __iomem
  832. *)(PCI_OFFSET_SECOND_RANGE(adapter, ISR_INT_MASK)));
  833. if (!(adapter->flags & NETXEN_NIC_MSI_ENABLED)) {
  834. mask = 0xbff;
  835. writel(mask, (void __iomem *)
  836. (PCI_OFFSET_SECOND_RANGE(adapter, ISR_INT_TARGET_MASK)));
  837. }
  838. }
  839. /*
  840. * NetXen Board information
  841. */
  842. #define NETXEN_MAX_SHORT_NAME 16
  843. typedef struct {
  844. netxen_brdtype_t brdtype; /* type of board */
  845. long ports; /* max no of physical ports */
  846. char short_name[NETXEN_MAX_SHORT_NAME];
  847. } netxen_brdinfo_t;
  848. static const netxen_brdinfo_t netxen_boards[] = {
  849. {NETXEN_BRDTYPE_P2_SB31_10G_CX4, 1, "XGb CX4"},
  850. {NETXEN_BRDTYPE_P2_SB31_10G_HMEZ, 1, "XGb HMEZ"},
  851. {NETXEN_BRDTYPE_P2_SB31_10G_IMEZ, 2, "XGb IMEZ"},
  852. {NETXEN_BRDTYPE_P2_SB31_10G, 1, "XGb XFP"},
  853. {NETXEN_BRDTYPE_P2_SB35_4G, 4, "Quad Gb"},
  854. {NETXEN_BRDTYPE_P2_SB31_2G, 2, "Dual Gb"},
  855. };
  856. #define NUM_SUPPORTED_BOARDS (sizeof(netxen_boards)/sizeof(netxen_brdinfo_t))
  857. static inline void get_brd_ports_name_by_type(u32 type, int *ports, char *name)
  858. {
  859. int i, found = 0;
  860. for (i = 0; i < NUM_SUPPORTED_BOARDS; ++i) {
  861. if (netxen_boards[i].brdtype == type) {
  862. *ports = netxen_boards[i].ports;
  863. strcpy(name, netxen_boards[i].short_name);
  864. found = 1;
  865. break;
  866. }
  867. }
  868. if (!found) {
  869. *ports = 0;
  870. name = "Unknown";
  871. }
  872. }
  873. static inline void get_brd_port_by_type(u32 type, int *ports)
  874. {
  875. int i, found = 0;
  876. for (i = 0; i < NUM_SUPPORTED_BOARDS; ++i) {
  877. if (netxen_boards[i].brdtype == type) {
  878. *ports = netxen_boards[i].ports;
  879. found = 1;
  880. break;
  881. }
  882. }
  883. if (!found)
  884. *ports = 0;
  885. }
  886. static inline void get_brd_name_by_type(u32 type, char *name)
  887. {
  888. int i, found = 0;
  889. for (i = 0; i < NUM_SUPPORTED_BOARDS; ++i) {
  890. if (netxen_boards[i].brdtype == type) {
  891. strcpy(name, netxen_boards[i].short_name);
  892. found = 1;
  893. break;
  894. }
  895. }
  896. if (!found)
  897. name = "Unknown";
  898. }
  899. int netxen_is_flash_supported(struct netxen_adapter *adapter);
  900. int netxen_get_flash_mac_addr(struct netxen_adapter *adapter, u64 mac[]);
  901. extern void netxen_change_ringparam(struct netxen_adapter *adapter);
  902. extern int netxen_rom_fast_read(struct netxen_adapter *adapter, int addr,
  903. int *valp);
  904. extern struct ethtool_ops netxen_nic_ethtool_ops;
  905. #endif /* __NETXEN_NIC_H_ */