netxen_nic.h 25 KB

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