netxen_nic.h 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402
  1. /*
  2. * Copyright (C) 2003 - 2009 NetXen, Inc.
  3. * Copyright (C) 2009 - QLogic Corporation.
  4. * All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
  19. * MA 02111-1307, USA.
  20. *
  21. * The full GNU General Public License is included in this distribution
  22. * in the file called LICENSE.
  23. *
  24. */
  25. #ifndef _NETXEN_NIC_H_
  26. #define _NETXEN_NIC_H_
  27. #include <linux/module.h>
  28. #include <linux/kernel.h>
  29. #include <linux/types.h>
  30. #include <linux/ioport.h>
  31. #include <linux/pci.h>
  32. #include <linux/netdevice.h>
  33. #include <linux/etherdevice.h>
  34. #include <linux/ip.h>
  35. #include <linux/in.h>
  36. #include <linux/tcp.h>
  37. #include <linux/skbuff.h>
  38. #include <linux/firmware.h>
  39. #include <linux/ethtool.h>
  40. #include <linux/mii.h>
  41. #include <linux/timer.h>
  42. #include <linux/vmalloc.h>
  43. #include <asm/io.h>
  44. #include <asm/byteorder.h>
  45. #include "netxen_nic_hdr.h"
  46. #include "netxen_nic_hw.h"
  47. #define _NETXEN_NIC_LINUX_MAJOR 4
  48. #define _NETXEN_NIC_LINUX_MINOR 0
  49. #define _NETXEN_NIC_LINUX_SUBVERSION 50
  50. #define NETXEN_NIC_LINUX_VERSIONID "4.0.50"
  51. #define NETXEN_VERSION_CODE(a, b, c) (((a) << 24) + ((b) << 16) + (c))
  52. #define _major(v) (((v) >> 24) & 0xff)
  53. #define _minor(v) (((v) >> 16) & 0xff)
  54. #define _build(v) ((v) & 0xffff)
  55. /* version in image has weird encoding:
  56. * 7:0 - major
  57. * 15:8 - minor
  58. * 31:16 - build (little endian)
  59. */
  60. #define NETXEN_DECODE_VERSION(v) \
  61. NETXEN_VERSION_CODE(((v) & 0xff), (((v) >> 8) & 0xff), ((v) >> 16))
  62. #define NETXEN_NUM_FLASH_SECTORS (64)
  63. #define NETXEN_FLASH_SECTOR_SIZE (64 * 1024)
  64. #define NETXEN_FLASH_TOTAL_SIZE (NETXEN_NUM_FLASH_SECTORS \
  65. * NETXEN_FLASH_SECTOR_SIZE)
  66. #define PHAN_VENDOR_ID 0x4040
  67. #define RCV_DESC_RINGSIZE(rds_ring) \
  68. (sizeof(struct rcv_desc) * (rds_ring)->num_desc)
  69. #define RCV_BUFF_RINGSIZE(rds_ring) \
  70. (sizeof(struct netxen_rx_buffer) * rds_ring->num_desc)
  71. #define STATUS_DESC_RINGSIZE(sds_ring) \
  72. (sizeof(struct status_desc) * (sds_ring)->num_desc)
  73. #define TX_BUFF_RINGSIZE(tx_ring) \
  74. (sizeof(struct netxen_cmd_buffer) * tx_ring->num_desc)
  75. #define TX_DESC_RINGSIZE(tx_ring) \
  76. (sizeof(struct cmd_desc_type0) * tx_ring->num_desc)
  77. #define find_diff_among(a,b,range) ((a)<(b)?((b)-(a)):((b)+(range)-(a)))
  78. #define NETXEN_RCV_PRODUCER_OFFSET 0
  79. #define NETXEN_RCV_PEG_DB_ID 2
  80. #define NETXEN_HOST_DUMMY_DMA_SIZE 1024
  81. #define FLASH_SUCCESS 0
  82. #define ADDR_IN_WINDOW1(off) \
  83. ((off > NETXEN_CRB_PCIX_HOST2) && (off < NETXEN_CRB_MAX)) ? 1 : 0
  84. /*
  85. * normalize a 64MB crb address to 32MB PCI window
  86. * To use NETXEN_CRB_NORMALIZE, window _must_ be set to 1
  87. */
  88. #define NETXEN_CRB_NORMAL(reg) \
  89. ((reg) - NETXEN_CRB_PCIX_HOST2 + NETXEN_CRB_PCIX_HOST)
  90. #define NETXEN_CRB_NORMALIZE(adapter, reg) \
  91. pci_base_offset(adapter, NETXEN_CRB_NORMAL(reg))
  92. #define DB_NORMALIZE(adapter, off) \
  93. (adapter->ahw.db_base + (off))
  94. #define NX_P2_C0 0x24
  95. #define NX_P2_C1 0x25
  96. #define NX_P3_A0 0x30
  97. #define NX_P3_A2 0x30
  98. #define NX_P3_B0 0x40
  99. #define NX_P3_B1 0x41
  100. #define NX_P3_B2 0x42
  101. #define NX_IS_REVISION_P2(REVISION) (REVISION <= NX_P2_C1)
  102. #define NX_IS_REVISION_P3(REVISION) (REVISION >= NX_P3_A0)
  103. #define FIRST_PAGE_GROUP_START 0
  104. #define FIRST_PAGE_GROUP_END 0x100000
  105. #define SECOND_PAGE_GROUP_START 0x6000000
  106. #define SECOND_PAGE_GROUP_END 0x68BC000
  107. #define THIRD_PAGE_GROUP_START 0x70E4000
  108. #define THIRD_PAGE_GROUP_END 0x8000000
  109. #define FIRST_PAGE_GROUP_SIZE FIRST_PAGE_GROUP_END - FIRST_PAGE_GROUP_START
  110. #define SECOND_PAGE_GROUP_SIZE SECOND_PAGE_GROUP_END - SECOND_PAGE_GROUP_START
  111. #define THIRD_PAGE_GROUP_SIZE THIRD_PAGE_GROUP_END - THIRD_PAGE_GROUP_START
  112. #define P2_MAX_MTU (8000)
  113. #define P3_MAX_MTU (9600)
  114. #define NX_ETHERMTU 1500
  115. #define NX_MAX_ETHERHDR 32 /* This contains some padding */
  116. #define NX_P2_RX_BUF_MAX_LEN 1760
  117. #define NX_P3_RX_BUF_MAX_LEN (NX_MAX_ETHERHDR + NX_ETHERMTU)
  118. #define NX_P2_RX_JUMBO_BUF_MAX_LEN (NX_MAX_ETHERHDR + P2_MAX_MTU)
  119. #define NX_P3_RX_JUMBO_BUF_MAX_LEN (NX_MAX_ETHERHDR + P3_MAX_MTU)
  120. #define NX_CT_DEFAULT_RX_BUF_LEN 2048
  121. #define NX_LRO_BUFFER_EXTRA 2048
  122. #define NX_RX_LRO_BUFFER_LENGTH (8060)
  123. /*
  124. * Maximum number of ring contexts
  125. */
  126. #define MAX_RING_CTX 1
  127. /* Opcodes to be used with the commands */
  128. #define TX_ETHER_PKT 0x01
  129. #define TX_TCP_PKT 0x02
  130. #define TX_UDP_PKT 0x03
  131. #define TX_IP_PKT 0x04
  132. #define TX_TCP_LSO 0x05
  133. #define TX_TCP_LSO6 0x06
  134. #define TX_IPSEC 0x07
  135. #define TX_IPSEC_CMD 0x0a
  136. #define TX_TCPV6_PKT 0x0b
  137. #define TX_UDPV6_PKT 0x0c
  138. /* The following opcodes are for internal consumption. */
  139. #define NETXEN_CONTROL_OP 0x10
  140. #define PEGNET_REQUEST 0x11
  141. #define MAX_NUM_CARDS 4
  142. #define MAX_BUFFERS_PER_CMD 32
  143. #define TX_STOP_THRESH ((MAX_SKB_FRAGS >> 2) + 4)
  144. #define NX_MAX_TX_TIMEOUTS 2
  145. /*
  146. * Following are the states of the Phantom. Phantom will set them and
  147. * Host will read to check if the fields are correct.
  148. */
  149. #define PHAN_INITIALIZE_START 0xff00
  150. #define PHAN_INITIALIZE_FAILED 0xffff
  151. #define PHAN_INITIALIZE_COMPLETE 0xff01
  152. /* Host writes the following to notify that it has done the init-handshake */
  153. #define PHAN_INITIALIZE_ACK 0xf00f
  154. #define NUM_RCV_DESC_RINGS 3
  155. #define NUM_STS_DESC_RINGS 4
  156. #define RCV_RING_NORMAL 0
  157. #define RCV_RING_JUMBO 1
  158. #define RCV_RING_LRO 2
  159. #define MIN_CMD_DESCRIPTORS 64
  160. #define MIN_RCV_DESCRIPTORS 64
  161. #define MIN_JUMBO_DESCRIPTORS 32
  162. #define MAX_CMD_DESCRIPTORS 1024
  163. #define MAX_RCV_DESCRIPTORS_1G 4096
  164. #define MAX_RCV_DESCRIPTORS_10G 8192
  165. #define MAX_JUMBO_RCV_DESCRIPTORS_1G 512
  166. #define MAX_JUMBO_RCV_DESCRIPTORS_10G 1024
  167. #define MAX_LRO_RCV_DESCRIPTORS 8
  168. #define DEFAULT_RCV_DESCRIPTORS_1G 2048
  169. #define DEFAULT_RCV_DESCRIPTORS_10G 4096
  170. #define NETXEN_CTX_SIGNATURE 0xdee0
  171. #define NETXEN_CTX_SIGNATURE_V2 0x0002dee0
  172. #define NETXEN_CTX_RESET 0xbad0
  173. #define NETXEN_CTX_D3_RESET 0xacc0
  174. #define NETXEN_RCV_PRODUCER(ringid) (ringid)
  175. #define PHAN_PEG_RCV_INITIALIZED 0xff01
  176. #define PHAN_PEG_RCV_START_INITIALIZE 0xff00
  177. #define get_next_index(index, length) \
  178. (((index) + 1) & ((length) - 1))
  179. #define get_index_range(index,length,count) \
  180. (((index) + (count)) & ((length) - 1))
  181. #define MPORT_SINGLE_FUNCTION_MODE 0x1111
  182. #define MPORT_MULTI_FUNCTION_MODE 0x2222
  183. #define NX_MAX_PCI_FUNC 8
  184. /*
  185. * NetXen host-peg signal message structure
  186. *
  187. * Bit 0-1 : peg_id => 0x2 for tx and 01 for rx
  188. * Bit 2 : priv_id => must be 1
  189. * Bit 3-17 : count => for doorbell
  190. * Bit 18-27 : ctx_id => Context id
  191. * Bit 28-31 : opcode
  192. */
  193. typedef u32 netxen_ctx_msg;
  194. #define netxen_set_msg_peg_id(config_word, val) \
  195. ((config_word) &= ~3, (config_word) |= val & 3)
  196. #define netxen_set_msg_privid(config_word) \
  197. ((config_word) |= 1 << 2)
  198. #define netxen_set_msg_count(config_word, val) \
  199. ((config_word) &= ~(0x7fff<<3), (config_word) |= (val & 0x7fff) << 3)
  200. #define netxen_set_msg_ctxid(config_word, val) \
  201. ((config_word) &= ~(0x3ff<<18), (config_word) |= (val & 0x3ff) << 18)
  202. #define netxen_set_msg_opcode(config_word, val) \
  203. ((config_word) &= ~(0xf<<28), (config_word) |= (val & 0xf) << 28)
  204. struct netxen_rcv_ring {
  205. __le64 addr;
  206. __le32 size;
  207. __le32 rsrvd;
  208. };
  209. struct netxen_sts_ring {
  210. __le64 addr;
  211. __le32 size;
  212. __le16 msi_index;
  213. __le16 rsvd;
  214. } ;
  215. struct netxen_ring_ctx {
  216. /* one command ring */
  217. __le64 cmd_consumer_offset;
  218. __le64 cmd_ring_addr;
  219. __le32 cmd_ring_size;
  220. __le32 rsrvd;
  221. /* three receive rings */
  222. struct netxen_rcv_ring rcv_rings[NUM_RCV_DESC_RINGS];
  223. __le64 sts_ring_addr;
  224. __le32 sts_ring_size;
  225. __le32 ctx_id;
  226. __le64 rsrvd_2[3];
  227. __le32 sts_ring_count;
  228. __le32 rsrvd_3;
  229. struct netxen_sts_ring sts_rings[NUM_STS_DESC_RINGS];
  230. } __attribute__ ((aligned(64)));
  231. /*
  232. * Following data structures describe the descriptors that will be used.
  233. * Added fileds of tcpHdrSize and ipHdrSize, The driver needs to do it only when
  234. * we are doing LSO (above the 1500 size packet) only.
  235. */
  236. /*
  237. * The size of reference handle been changed to 16 bits to pass the MSS fields
  238. * for the LSO packet
  239. */
  240. #define FLAGS_CHECKSUM_ENABLED 0x01
  241. #define FLAGS_LSO_ENABLED 0x02
  242. #define FLAGS_IPSEC_SA_ADD 0x04
  243. #define FLAGS_IPSEC_SA_DELETE 0x08
  244. #define FLAGS_VLAN_TAGGED 0x10
  245. #define FLAGS_VLAN_OOB 0x40
  246. #define netxen_set_tx_vlan_tci(cmd_desc, v) \
  247. (cmd_desc)->vlan_TCI = cpu_to_le16(v);
  248. #define netxen_set_cmd_desc_port(cmd_desc, var) \
  249. ((cmd_desc)->port_ctxid |= ((var) & 0x0F))
  250. #define netxen_set_cmd_desc_ctxid(cmd_desc, var) \
  251. ((cmd_desc)->port_ctxid |= ((var) << 4 & 0xF0))
  252. #define netxen_set_tx_port(_desc, _port) \
  253. (_desc)->port_ctxid = ((_port) & 0xf) | (((_port) << 4) & 0xf0)
  254. #define netxen_set_tx_flags_opcode(_desc, _flags, _opcode) \
  255. (_desc)->flags_opcode = \
  256. cpu_to_le16(((_flags) & 0x7f) | (((_opcode) & 0x3f) << 7))
  257. #define netxen_set_tx_frags_len(_desc, _frags, _len) \
  258. (_desc)->nfrags__length = \
  259. cpu_to_le32(((_frags) & 0xff) | (((_len) & 0xffffff) << 8))
  260. struct cmd_desc_type0 {
  261. u8 tcp_hdr_offset; /* For LSO only */
  262. u8 ip_hdr_offset; /* For LSO only */
  263. __le16 flags_opcode; /* 15:13 unused, 12:7 opcode, 6:0 flags */
  264. __le32 nfrags__length; /* 31:8 total len, 7:0 frag count */
  265. __le64 addr_buffer2;
  266. __le16 reference_handle;
  267. __le16 mss;
  268. u8 port_ctxid; /* 7:4 ctxid 3:0 port */
  269. u8 total_hdr_length; /* LSO only : MAC+IP+TCP Hdr size */
  270. __le16 conn_id; /* IPSec offoad only */
  271. __le64 addr_buffer3;
  272. __le64 addr_buffer1;
  273. __le16 buffer_length[4];
  274. __le64 addr_buffer4;
  275. __le32 reserved2;
  276. __le16 reserved;
  277. __le16 vlan_TCI;
  278. } __attribute__ ((aligned(64)));
  279. /* Note: sizeof(rcv_desc) should always be a mutliple of 2 */
  280. struct rcv_desc {
  281. __le16 reference_handle;
  282. __le16 reserved;
  283. __le32 buffer_length; /* allocated buffer length (usually 2K) */
  284. __le64 addr_buffer;
  285. };
  286. /* opcode field in status_desc */
  287. #define NETXEN_NIC_SYN_OFFLOAD 0x03
  288. #define NETXEN_NIC_RXPKT_DESC 0x04
  289. #define NETXEN_OLD_RXPKT_DESC 0x3f
  290. #define NETXEN_NIC_RESPONSE_DESC 0x05
  291. #define NETXEN_NIC_LRO_DESC 0x12
  292. /* for status field in status_desc */
  293. #define STATUS_NEED_CKSUM (1)
  294. #define STATUS_CKSUM_OK (2)
  295. /* owner bits of status_desc */
  296. #define STATUS_OWNER_HOST (0x1ULL << 56)
  297. #define STATUS_OWNER_PHANTOM (0x2ULL << 56)
  298. /* Status descriptor:
  299. 0-3 port, 4-7 status, 8-11 type, 12-27 total_length
  300. 28-43 reference_handle, 44-47 protocol, 48-52 pkt_offset
  301. 53-55 desc_cnt, 56-57 owner, 58-63 opcode
  302. */
  303. #define netxen_get_sts_port(sts_data) \
  304. ((sts_data) & 0x0F)
  305. #define netxen_get_sts_status(sts_data) \
  306. (((sts_data) >> 4) & 0x0F)
  307. #define netxen_get_sts_type(sts_data) \
  308. (((sts_data) >> 8) & 0x0F)
  309. #define netxen_get_sts_totallength(sts_data) \
  310. (((sts_data) >> 12) & 0xFFFF)
  311. #define netxen_get_sts_refhandle(sts_data) \
  312. (((sts_data) >> 28) & 0xFFFF)
  313. #define netxen_get_sts_prot(sts_data) \
  314. (((sts_data) >> 44) & 0x0F)
  315. #define netxen_get_sts_pkt_offset(sts_data) \
  316. (((sts_data) >> 48) & 0x1F)
  317. #define netxen_get_sts_desc_cnt(sts_data) \
  318. (((sts_data) >> 53) & 0x7)
  319. #define netxen_get_sts_opcode(sts_data) \
  320. (((sts_data) >> 58) & 0x03F)
  321. #define netxen_get_lro_sts_refhandle(sts_data) \
  322. ((sts_data) & 0x0FFFF)
  323. #define netxen_get_lro_sts_length(sts_data) \
  324. (((sts_data) >> 16) & 0x0FFFF)
  325. #define netxen_get_lro_sts_l2_hdr_offset(sts_data) \
  326. (((sts_data) >> 32) & 0x0FF)
  327. #define netxen_get_lro_sts_l4_hdr_offset(sts_data) \
  328. (((sts_data) >> 40) & 0x0FF)
  329. #define netxen_get_lro_sts_timestamp(sts_data) \
  330. (((sts_data) >> 48) & 0x1)
  331. #define netxen_get_lro_sts_type(sts_data) \
  332. (((sts_data) >> 49) & 0x7)
  333. #define netxen_get_lro_sts_push_flag(sts_data) \
  334. (((sts_data) >> 52) & 0x1)
  335. #define netxen_get_lro_sts_seq_number(sts_data) \
  336. ((sts_data) & 0x0FFFFFFFF)
  337. struct status_desc {
  338. __le64 status_desc_data[2];
  339. } __attribute__ ((aligned(16)));
  340. /* The version of the main data structure */
  341. #define NETXEN_BDINFO_VERSION 1
  342. /* Magic number to let user know flash is programmed */
  343. #define NETXEN_BDINFO_MAGIC 0x12345678
  344. /* Max number of Gig ports on a Phantom board */
  345. #define NETXEN_MAX_PORTS 4
  346. #define NETXEN_BRDTYPE_P1_BD 0x0000
  347. #define NETXEN_BRDTYPE_P1_SB 0x0001
  348. #define NETXEN_BRDTYPE_P1_SMAX 0x0002
  349. #define NETXEN_BRDTYPE_P1_SOCK 0x0003
  350. #define NETXEN_BRDTYPE_P2_SOCK_31 0x0008
  351. #define NETXEN_BRDTYPE_P2_SOCK_35 0x0009
  352. #define NETXEN_BRDTYPE_P2_SB35_4G 0x000a
  353. #define NETXEN_BRDTYPE_P2_SB31_10G 0x000b
  354. #define NETXEN_BRDTYPE_P2_SB31_2G 0x000c
  355. #define NETXEN_BRDTYPE_P2_SB31_10G_IMEZ 0x000d
  356. #define NETXEN_BRDTYPE_P2_SB31_10G_HMEZ 0x000e
  357. #define NETXEN_BRDTYPE_P2_SB31_10G_CX4 0x000f
  358. #define NETXEN_BRDTYPE_P3_REF_QG 0x0021
  359. #define NETXEN_BRDTYPE_P3_HMEZ 0x0022
  360. #define NETXEN_BRDTYPE_P3_10G_CX4_LP 0x0023
  361. #define NETXEN_BRDTYPE_P3_4_GB 0x0024
  362. #define NETXEN_BRDTYPE_P3_IMEZ 0x0025
  363. #define NETXEN_BRDTYPE_P3_10G_SFP_PLUS 0x0026
  364. #define NETXEN_BRDTYPE_P3_10000_BASE_T 0x0027
  365. #define NETXEN_BRDTYPE_P3_XG_LOM 0x0028
  366. #define NETXEN_BRDTYPE_P3_4_GB_MM 0x0029
  367. #define NETXEN_BRDTYPE_P3_10G_SFP_CT 0x002a
  368. #define NETXEN_BRDTYPE_P3_10G_SFP_QT 0x002b
  369. #define NETXEN_BRDTYPE_P3_10G_CX4 0x0031
  370. #define NETXEN_BRDTYPE_P3_10G_XFP 0x0032
  371. #define NETXEN_BRDTYPE_P3_10G_TP 0x0080
  372. /* Flash memory map */
  373. #define NETXEN_CRBINIT_START 0 /* crbinit section */
  374. #define NETXEN_BRDCFG_START 0x4000 /* board config */
  375. #define NETXEN_INITCODE_START 0x6000 /* pegtune code */
  376. #define NETXEN_BOOTLD_START 0x10000 /* bootld */
  377. #define NETXEN_IMAGE_START 0x43000 /* compressed image */
  378. #define NETXEN_SECONDARY_START 0x200000 /* backup images */
  379. #define NETXEN_PXE_START 0x3E0000 /* PXE boot rom */
  380. #define NETXEN_USER_START 0x3E8000 /* Firmare info */
  381. #define NETXEN_FIXED_START 0x3F0000 /* backup of crbinit */
  382. #define NETXEN_USER_START_OLD NETXEN_PXE_START /* very old flash */
  383. #define NX_OLD_MAC_ADDR_OFFSET (NETXEN_USER_START)
  384. #define NX_FW_VERSION_OFFSET (NETXEN_USER_START+0x408)
  385. #define NX_FW_SIZE_OFFSET (NETXEN_USER_START+0x40c)
  386. #define NX_FW_MAC_ADDR_OFFSET (NETXEN_USER_START+0x418)
  387. #define NX_FW_SERIAL_NUM_OFFSET (NETXEN_USER_START+0x81c)
  388. #define NX_BIOS_VERSION_OFFSET (NETXEN_USER_START+0x83c)
  389. #define NX_HDR_VERSION_OFFSET (NETXEN_BRDCFG_START)
  390. #define NX_BRDTYPE_OFFSET (NETXEN_BRDCFG_START+0x8)
  391. #define NX_FW_MAGIC_OFFSET (NETXEN_BRDCFG_START+0x128)
  392. #define NX_FW_MIN_SIZE (0x3fffff)
  393. #define NX_P2_MN_ROMIMAGE 0
  394. #define NX_P3_CT_ROMIMAGE 1
  395. #define NX_P3_MN_ROMIMAGE 2
  396. #define NX_FLASH_ROMIMAGE 3
  397. extern char netxen_nic_driver_name[];
  398. /* Number of status descriptors to handle per interrupt */
  399. #define MAX_STATUS_HANDLE (64)
  400. /*
  401. * netxen_skb_frag{} is to contain mapping info for each SG list. This
  402. * has to be freed when DMA is complete. This is part of netxen_tx_buffer{}.
  403. */
  404. struct netxen_skb_frag {
  405. u64 dma;
  406. u64 length;
  407. };
  408. struct netxen_recv_crb {
  409. u32 crb_rcv_producer[NUM_RCV_DESC_RINGS];
  410. u32 crb_sts_consumer[NUM_STS_DESC_RINGS];
  411. u32 sw_int_mask[NUM_STS_DESC_RINGS];
  412. };
  413. /* Following defines are for the state of the buffers */
  414. #define NETXEN_BUFFER_FREE 0
  415. #define NETXEN_BUFFER_BUSY 1
  416. /*
  417. * There will be one netxen_buffer per skb packet. These will be
  418. * used to save the dma info for pci_unmap_page()
  419. */
  420. struct netxen_cmd_buffer {
  421. struct sk_buff *skb;
  422. struct netxen_skb_frag frag_array[MAX_BUFFERS_PER_CMD + 1];
  423. u32 frag_count;
  424. };
  425. /* In rx_buffer, we do not need multiple fragments as is a single buffer */
  426. struct netxen_rx_buffer {
  427. struct list_head list;
  428. struct sk_buff *skb;
  429. u64 dma;
  430. u16 ref_handle;
  431. u16 state;
  432. };
  433. /* Board types */
  434. #define NETXEN_NIC_GBE 0x01
  435. #define NETXEN_NIC_XGBE 0x02
  436. /*
  437. * One hardware_context{} per adapter
  438. * contains interrupt info as well shared hardware info.
  439. */
  440. struct netxen_hardware_context {
  441. void __iomem *pci_base0;
  442. void __iomem *pci_base1;
  443. void __iomem *pci_base2;
  444. void __iomem *db_base;
  445. unsigned long db_len;
  446. unsigned long pci_len0;
  447. int qdr_sn_window;
  448. int ddr_mn_window;
  449. u32 mn_win_crb;
  450. u32 ms_win_crb;
  451. u8 cut_through;
  452. u8 revision_id;
  453. u8 pci_func;
  454. u8 linkup;
  455. u16 port_type;
  456. u16 board_type;
  457. };
  458. #define MINIMUM_ETHERNET_FRAME_SIZE 64 /* With FCS */
  459. #define ETHERNET_FCS_SIZE 4
  460. struct netxen_adapter_stats {
  461. u64 xmitcalled;
  462. u64 xmitfinished;
  463. u64 rxdropped;
  464. u64 txdropped;
  465. u64 csummed;
  466. u64 rx_pkts;
  467. u64 lro_pkts;
  468. u64 rxbytes;
  469. u64 txbytes;
  470. };
  471. /*
  472. * Rcv Descriptor Context. One such per Rcv Descriptor. There may
  473. * be one Rcv Descriptor for normal packets, one for jumbo and may be others.
  474. */
  475. struct nx_host_rds_ring {
  476. u32 producer;
  477. u32 num_desc;
  478. u32 dma_size;
  479. u32 skb_size;
  480. u32 flags;
  481. void __iomem *crb_rcv_producer;
  482. struct rcv_desc *desc_head;
  483. struct netxen_rx_buffer *rx_buf_arr;
  484. struct list_head free_list;
  485. spinlock_t lock;
  486. dma_addr_t phys_addr;
  487. };
  488. struct nx_host_sds_ring {
  489. u32 consumer;
  490. u32 num_desc;
  491. void __iomem *crb_sts_consumer;
  492. void __iomem *crb_intr_mask;
  493. struct status_desc *desc_head;
  494. struct netxen_adapter *adapter;
  495. struct napi_struct napi;
  496. struct list_head free_list[NUM_RCV_DESC_RINGS];
  497. int irq;
  498. dma_addr_t phys_addr;
  499. char name[IFNAMSIZ+4];
  500. };
  501. struct nx_host_tx_ring {
  502. u32 producer;
  503. __le32 *hw_consumer;
  504. u32 sw_consumer;
  505. void __iomem *crb_cmd_producer;
  506. void __iomem *crb_cmd_consumer;
  507. u32 num_desc;
  508. struct netdev_queue *txq;
  509. struct netxen_cmd_buffer *cmd_buf_arr;
  510. struct cmd_desc_type0 *desc_head;
  511. dma_addr_t phys_addr;
  512. };
  513. /*
  514. * Receive context. There is one such structure per instance of the
  515. * receive processing. Any state information that is relevant to
  516. * the receive, and is must be in this structure. The global data may be
  517. * present elsewhere.
  518. */
  519. struct netxen_recv_context {
  520. u32 state;
  521. u16 context_id;
  522. u16 virt_port;
  523. struct nx_host_rds_ring *rds_rings;
  524. struct nx_host_sds_ring *sds_rings;
  525. struct netxen_ring_ctx *hwctx;
  526. dma_addr_t phys_addr;
  527. };
  528. /* New HW context creation */
  529. #define NX_OS_CRB_RETRY_COUNT 4000
  530. #define NX_CDRP_SIGNATURE_MAKE(pcifn, version) \
  531. (((pcifn) & 0xff) | (((version) & 0xff) << 8) | (0xcafe << 16))
  532. #define NX_CDRP_CLEAR 0x00000000
  533. #define NX_CDRP_CMD_BIT 0x80000000
  534. /*
  535. * All responses must have the NX_CDRP_CMD_BIT cleared
  536. * in the crb NX_CDRP_CRB_OFFSET.
  537. */
  538. #define NX_CDRP_FORM_RSP(rsp) (rsp)
  539. #define NX_CDRP_IS_RSP(rsp) (((rsp) & NX_CDRP_CMD_BIT) == 0)
  540. #define NX_CDRP_RSP_OK 0x00000001
  541. #define NX_CDRP_RSP_FAIL 0x00000002
  542. #define NX_CDRP_RSP_TIMEOUT 0x00000003
  543. /*
  544. * All commands must have the NX_CDRP_CMD_BIT set in
  545. * the crb NX_CDRP_CRB_OFFSET.
  546. */
  547. #define NX_CDRP_FORM_CMD(cmd) (NX_CDRP_CMD_BIT | (cmd))
  548. #define NX_CDRP_IS_CMD(cmd) (((cmd) & NX_CDRP_CMD_BIT) != 0)
  549. #define NX_CDRP_CMD_SUBMIT_CAPABILITIES 0x00000001
  550. #define NX_CDRP_CMD_READ_MAX_RDS_PER_CTX 0x00000002
  551. #define NX_CDRP_CMD_READ_MAX_SDS_PER_CTX 0x00000003
  552. #define NX_CDRP_CMD_READ_MAX_RULES_PER_CTX 0x00000004
  553. #define NX_CDRP_CMD_READ_MAX_RX_CTX 0x00000005
  554. #define NX_CDRP_CMD_READ_MAX_TX_CTX 0x00000006
  555. #define NX_CDRP_CMD_CREATE_RX_CTX 0x00000007
  556. #define NX_CDRP_CMD_DESTROY_RX_CTX 0x00000008
  557. #define NX_CDRP_CMD_CREATE_TX_CTX 0x00000009
  558. #define NX_CDRP_CMD_DESTROY_TX_CTX 0x0000000a
  559. #define NX_CDRP_CMD_SETUP_STATISTICS 0x0000000e
  560. #define NX_CDRP_CMD_GET_STATISTICS 0x0000000f
  561. #define NX_CDRP_CMD_DELETE_STATISTICS 0x00000010
  562. #define NX_CDRP_CMD_SET_MTU 0x00000012
  563. #define NX_CDRP_CMD_READ_PHY 0x00000013
  564. #define NX_CDRP_CMD_WRITE_PHY 0x00000014
  565. #define NX_CDRP_CMD_READ_HW_REG 0x00000015
  566. #define NX_CDRP_CMD_GET_FLOW_CTL 0x00000016
  567. #define NX_CDRP_CMD_SET_FLOW_CTL 0x00000017
  568. #define NX_CDRP_CMD_READ_MAX_MTU 0x00000018
  569. #define NX_CDRP_CMD_READ_MAX_LRO 0x00000019
  570. #define NX_CDRP_CMD_CONFIGURE_TOE 0x0000001a
  571. #define NX_CDRP_CMD_FUNC_ATTRIB 0x0000001b
  572. #define NX_CDRP_CMD_READ_PEXQ_PARAMETERS 0x0000001c
  573. #define NX_CDRP_CMD_GET_LIC_CAPABILITIES 0x0000001d
  574. #define NX_CDRP_CMD_READ_MAX_LRO_PER_BOARD 0x0000001e
  575. #define NX_CDRP_CMD_MAX 0x0000001f
  576. #define NX_RCODE_SUCCESS 0
  577. #define NX_RCODE_NO_HOST_MEM 1
  578. #define NX_RCODE_NO_HOST_RESOURCE 2
  579. #define NX_RCODE_NO_CARD_CRB 3
  580. #define NX_RCODE_NO_CARD_MEM 4
  581. #define NX_RCODE_NO_CARD_RESOURCE 5
  582. #define NX_RCODE_INVALID_ARGS 6
  583. #define NX_RCODE_INVALID_ACTION 7
  584. #define NX_RCODE_INVALID_STATE 8
  585. #define NX_RCODE_NOT_SUPPORTED 9
  586. #define NX_RCODE_NOT_PERMITTED 10
  587. #define NX_RCODE_NOT_READY 11
  588. #define NX_RCODE_DOES_NOT_EXIST 12
  589. #define NX_RCODE_ALREADY_EXISTS 13
  590. #define NX_RCODE_BAD_SIGNATURE 14
  591. #define NX_RCODE_CMD_NOT_IMPL 15
  592. #define NX_RCODE_CMD_INVALID 16
  593. #define NX_RCODE_TIMEOUT 17
  594. #define NX_RCODE_CMD_FAILED 18
  595. #define NX_RCODE_MAX_EXCEEDED 19
  596. #define NX_RCODE_MAX 20
  597. #define NX_DESTROY_CTX_RESET 0
  598. #define NX_DESTROY_CTX_D3_RESET 1
  599. #define NX_DESTROY_CTX_MAX 2
  600. /*
  601. * Capabilities
  602. */
  603. #define NX_CAP_BIT(class, bit) (1 << bit)
  604. #define NX_CAP0_LEGACY_CONTEXT NX_CAP_BIT(0, 0)
  605. #define NX_CAP0_MULTI_CONTEXT NX_CAP_BIT(0, 1)
  606. #define NX_CAP0_LEGACY_MN NX_CAP_BIT(0, 2)
  607. #define NX_CAP0_LEGACY_MS NX_CAP_BIT(0, 3)
  608. #define NX_CAP0_CUT_THROUGH NX_CAP_BIT(0, 4)
  609. #define NX_CAP0_LRO NX_CAP_BIT(0, 5)
  610. #define NX_CAP0_LSO NX_CAP_BIT(0, 6)
  611. #define NX_CAP0_JUMBO_CONTIGUOUS NX_CAP_BIT(0, 7)
  612. #define NX_CAP0_LRO_CONTIGUOUS NX_CAP_BIT(0, 8)
  613. #define NX_CAP0_HW_LRO NX_CAP_BIT(0, 10)
  614. /*
  615. * Context state
  616. */
  617. #define NX_HOST_CTX_STATE_FREED 0
  618. #define NX_HOST_CTX_STATE_ALLOCATED 1
  619. #define NX_HOST_CTX_STATE_ACTIVE 2
  620. #define NX_HOST_CTX_STATE_DISABLED 3
  621. #define NX_HOST_CTX_STATE_QUIESCED 4
  622. #define NX_HOST_CTX_STATE_MAX 5
  623. /*
  624. * Rx context
  625. */
  626. typedef struct {
  627. __le64 host_phys_addr; /* Ring base addr */
  628. __le32 ring_size; /* Ring entries */
  629. __le16 msi_index;
  630. __le16 rsvd; /* Padding */
  631. } nx_hostrq_sds_ring_t;
  632. typedef struct {
  633. __le64 host_phys_addr; /* Ring base addr */
  634. __le64 buff_size; /* Packet buffer size */
  635. __le32 ring_size; /* Ring entries */
  636. __le32 ring_kind; /* Class of ring */
  637. } nx_hostrq_rds_ring_t;
  638. typedef struct {
  639. __le64 host_rsp_dma_addr; /* Response dma'd here */
  640. __le32 capabilities[4]; /* Flag bit vector */
  641. __le32 host_int_crb_mode; /* Interrupt crb usage */
  642. __le32 host_rds_crb_mode; /* RDS crb usage */
  643. /* These ring offsets are relative to data[0] below */
  644. __le32 rds_ring_offset; /* Offset to RDS config */
  645. __le32 sds_ring_offset; /* Offset to SDS config */
  646. __le16 num_rds_rings; /* Count of RDS rings */
  647. __le16 num_sds_rings; /* Count of SDS rings */
  648. __le16 rsvd1; /* Padding */
  649. __le16 rsvd2; /* Padding */
  650. u8 reserved[128]; /* reserve space for future expansion*/
  651. /* MUST BE 64-bit aligned.
  652. The following is packed:
  653. - N hostrq_rds_rings
  654. - N hostrq_sds_rings */
  655. char data[0];
  656. } nx_hostrq_rx_ctx_t;
  657. typedef struct {
  658. __le32 host_producer_crb; /* Crb to use */
  659. __le32 rsvd1; /* Padding */
  660. } nx_cardrsp_rds_ring_t;
  661. typedef struct {
  662. __le32 host_consumer_crb; /* Crb to use */
  663. __le32 interrupt_crb; /* Crb to use */
  664. } nx_cardrsp_sds_ring_t;
  665. typedef struct {
  666. /* These ring offsets are relative to data[0] below */
  667. __le32 rds_ring_offset; /* Offset to RDS config */
  668. __le32 sds_ring_offset; /* Offset to SDS config */
  669. __le32 host_ctx_state; /* Starting State */
  670. __le32 num_fn_per_port; /* How many PCI fn share the port */
  671. __le16 num_rds_rings; /* Count of RDS rings */
  672. __le16 num_sds_rings; /* Count of SDS rings */
  673. __le16 context_id; /* Handle for context */
  674. u8 phys_port; /* Physical id of port */
  675. u8 virt_port; /* Virtual/Logical id of port */
  676. u8 reserved[128]; /* save space for future expansion */
  677. /* MUST BE 64-bit aligned.
  678. The following is packed:
  679. - N cardrsp_rds_rings
  680. - N cardrs_sds_rings */
  681. char data[0];
  682. } nx_cardrsp_rx_ctx_t;
  683. #define SIZEOF_HOSTRQ_RX(HOSTRQ_RX, rds_rings, sds_rings) \
  684. (sizeof(HOSTRQ_RX) + \
  685. (rds_rings)*(sizeof(nx_hostrq_rds_ring_t)) + \
  686. (sds_rings)*(sizeof(nx_hostrq_sds_ring_t)))
  687. #define SIZEOF_CARDRSP_RX(CARDRSP_RX, rds_rings, sds_rings) \
  688. (sizeof(CARDRSP_RX) + \
  689. (rds_rings)*(sizeof(nx_cardrsp_rds_ring_t)) + \
  690. (sds_rings)*(sizeof(nx_cardrsp_sds_ring_t)))
  691. /*
  692. * Tx context
  693. */
  694. typedef struct {
  695. __le64 host_phys_addr; /* Ring base addr */
  696. __le32 ring_size; /* Ring entries */
  697. __le32 rsvd; /* Padding */
  698. } nx_hostrq_cds_ring_t;
  699. typedef struct {
  700. __le64 host_rsp_dma_addr; /* Response dma'd here */
  701. __le64 cmd_cons_dma_addr; /* */
  702. __le64 dummy_dma_addr; /* */
  703. __le32 capabilities[4]; /* Flag bit vector */
  704. __le32 host_int_crb_mode; /* Interrupt crb usage */
  705. __le32 rsvd1; /* Padding */
  706. __le16 rsvd2; /* Padding */
  707. __le16 interrupt_ctl;
  708. __le16 msi_index;
  709. __le16 rsvd3; /* Padding */
  710. nx_hostrq_cds_ring_t cds_ring; /* Desc of cds ring */
  711. u8 reserved[128]; /* future expansion */
  712. } nx_hostrq_tx_ctx_t;
  713. typedef struct {
  714. __le32 host_producer_crb; /* Crb to use */
  715. __le32 interrupt_crb; /* Crb to use */
  716. } nx_cardrsp_cds_ring_t;
  717. typedef struct {
  718. __le32 host_ctx_state; /* Starting state */
  719. __le16 context_id; /* Handle for context */
  720. u8 phys_port; /* Physical id of port */
  721. u8 virt_port; /* Virtual/Logical id of port */
  722. nx_cardrsp_cds_ring_t cds_ring; /* Card cds settings */
  723. u8 reserved[128]; /* future expansion */
  724. } nx_cardrsp_tx_ctx_t;
  725. #define SIZEOF_HOSTRQ_TX(HOSTRQ_TX) (sizeof(HOSTRQ_TX))
  726. #define SIZEOF_CARDRSP_TX(CARDRSP_TX) (sizeof(CARDRSP_TX))
  727. /* CRB */
  728. #define NX_HOST_RDS_CRB_MODE_UNIQUE 0
  729. #define NX_HOST_RDS_CRB_MODE_SHARED 1
  730. #define NX_HOST_RDS_CRB_MODE_CUSTOM 2
  731. #define NX_HOST_RDS_CRB_MODE_MAX 3
  732. #define NX_HOST_INT_CRB_MODE_UNIQUE 0
  733. #define NX_HOST_INT_CRB_MODE_SHARED 1
  734. #define NX_HOST_INT_CRB_MODE_NORX 2
  735. #define NX_HOST_INT_CRB_MODE_NOTX 3
  736. #define NX_HOST_INT_CRB_MODE_NORXTX 4
  737. /* MAC */
  738. #define MC_COUNT_P2 16
  739. #define MC_COUNT_P3 38
  740. #define NETXEN_MAC_NOOP 0
  741. #define NETXEN_MAC_ADD 1
  742. #define NETXEN_MAC_DEL 2
  743. typedef struct nx_mac_list_s {
  744. struct list_head list;
  745. uint8_t mac_addr[ETH_ALEN+2];
  746. } nx_mac_list_t;
  747. /*
  748. * Interrupt coalescing defaults. The defaults are for 1500 MTU. It is
  749. * adjusted based on configured MTU.
  750. */
  751. #define NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US 3
  752. #define NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS 256
  753. #define NETXEN_DEFAULT_INTR_COALESCE_TX_PACKETS 64
  754. #define NETXEN_DEFAULT_INTR_COALESCE_TX_TIME_US 4
  755. #define NETXEN_NIC_INTR_DEFAULT 0x04
  756. typedef union {
  757. struct {
  758. uint16_t rx_packets;
  759. uint16_t rx_time_us;
  760. uint16_t tx_packets;
  761. uint16_t tx_time_us;
  762. } data;
  763. uint64_t word;
  764. } nx_nic_intr_coalesce_data_t;
  765. typedef struct {
  766. uint16_t stats_time_us;
  767. uint16_t rate_sample_time;
  768. uint16_t flags;
  769. uint16_t rsvd_1;
  770. uint32_t low_threshold;
  771. uint32_t high_threshold;
  772. nx_nic_intr_coalesce_data_t normal;
  773. nx_nic_intr_coalesce_data_t low;
  774. nx_nic_intr_coalesce_data_t high;
  775. nx_nic_intr_coalesce_data_t irq;
  776. } nx_nic_intr_coalesce_t;
  777. #define NX_HOST_REQUEST 0x13
  778. #define NX_NIC_REQUEST 0x14
  779. #define NX_MAC_EVENT 0x1
  780. #define NX_IP_UP 2
  781. #define NX_IP_DOWN 3
  782. /*
  783. * Driver --> Firmware
  784. */
  785. #define NX_NIC_H2C_OPCODE_START 0
  786. #define NX_NIC_H2C_OPCODE_CONFIG_RSS 1
  787. #define NX_NIC_H2C_OPCODE_CONFIG_RSS_TBL 2
  788. #define NX_NIC_H2C_OPCODE_CONFIG_INTR_COALESCE 3
  789. #define NX_NIC_H2C_OPCODE_CONFIG_LED 4
  790. #define NX_NIC_H2C_OPCODE_CONFIG_PROMISCUOUS 5
  791. #define NX_NIC_H2C_OPCODE_CONFIG_L2_MAC 6
  792. #define NX_NIC_H2C_OPCODE_LRO_REQUEST 7
  793. #define NX_NIC_H2C_OPCODE_GET_SNMP_STATS 8
  794. #define NX_NIC_H2C_OPCODE_PROXY_START_REQUEST 9
  795. #define NX_NIC_H2C_OPCODE_PROXY_STOP_REQUEST 10
  796. #define NX_NIC_H2C_OPCODE_PROXY_SET_MTU 11
  797. #define NX_NIC_H2C_OPCODE_PROXY_SET_VPORT_MISS_MODE 12
  798. #define NX_NIC_H2C_OPCODE_GET_FINGER_PRINT_REQUEST 13
  799. #define NX_NIC_H2C_OPCODE_INSTALL_LICENSE_REQUEST 14
  800. #define NX_NIC_H2C_OPCODE_GET_LICENSE_CAPABILITY_REQUEST 15
  801. #define NX_NIC_H2C_OPCODE_GET_NET_STATS 16
  802. #define NX_NIC_H2C_OPCODE_PROXY_UPDATE_P2V 17
  803. #define NX_NIC_H2C_OPCODE_CONFIG_IPADDR 18
  804. #define NX_NIC_H2C_OPCODE_CONFIG_LOOPBACK 19
  805. #define NX_NIC_H2C_OPCODE_PROXY_STOP_DONE 20
  806. #define NX_NIC_H2C_OPCODE_GET_LINKEVENT 21
  807. #define NX_NIC_C2C_OPCODE 22
  808. #define NX_NIC_H2C_OPCODE_CONFIG_BRIDGING 23
  809. #define NX_NIC_H2C_OPCODE_CONFIG_HW_LRO 24
  810. #define NX_NIC_H2C_OPCODE_LAST 25
  811. /*
  812. * Firmware --> Driver
  813. */
  814. #define NX_NIC_C2H_OPCODE_START 128
  815. #define NX_NIC_C2H_OPCODE_CONFIG_RSS_RESPONSE 129
  816. #define NX_NIC_C2H_OPCODE_CONFIG_RSS_TBL_RESPONSE 130
  817. #define NX_NIC_C2H_OPCODE_CONFIG_MAC_RESPONSE 131
  818. #define NX_NIC_C2H_OPCODE_CONFIG_PROMISCUOUS_RESPONSE 132
  819. #define NX_NIC_C2H_OPCODE_CONFIG_L2_MAC_RESPONSE 133
  820. #define NX_NIC_C2H_OPCODE_LRO_DELETE_RESPONSE 134
  821. #define NX_NIC_C2H_OPCODE_LRO_ADD_FAILURE_RESPONSE 135
  822. #define NX_NIC_C2H_OPCODE_GET_SNMP_STATS 136
  823. #define NX_NIC_C2H_OPCODE_GET_FINGER_PRINT_REPLY 137
  824. #define NX_NIC_C2H_OPCODE_INSTALL_LICENSE_REPLY 138
  825. #define NX_NIC_C2H_OPCODE_GET_LICENSE_CAPABILITIES_REPLY 139
  826. #define NX_NIC_C2H_OPCODE_GET_NET_STATS_RESPONSE 140
  827. #define NX_NIC_C2H_OPCODE_GET_LINKEVENT_RESPONSE 141
  828. #define NX_NIC_C2H_OPCODE_LAST 142
  829. #define VPORT_MISS_MODE_DROP 0 /* drop all unmatched */
  830. #define VPORT_MISS_MODE_ACCEPT_ALL 1 /* accept all packets */
  831. #define VPORT_MISS_MODE_ACCEPT_MULTI 2 /* accept unmatched multicast */
  832. #define NX_NIC_LRO_REQUEST_FIRST 0
  833. #define NX_NIC_LRO_REQUEST_ADD_FLOW 1
  834. #define NX_NIC_LRO_REQUEST_DELETE_FLOW 2
  835. #define NX_NIC_LRO_REQUEST_TIMER 3
  836. #define NX_NIC_LRO_REQUEST_CLEANUP 4
  837. #define NX_NIC_LRO_REQUEST_ADD_FLOW_SCHEDULED 5
  838. #define NX_TOE_LRO_REQUEST_ADD_FLOW 6
  839. #define NX_TOE_LRO_REQUEST_ADD_FLOW_RESPONSE 7
  840. #define NX_TOE_LRO_REQUEST_DELETE_FLOW 8
  841. #define NX_TOE_LRO_REQUEST_DELETE_FLOW_RESPONSE 9
  842. #define NX_TOE_LRO_REQUEST_TIMER 10
  843. #define NX_NIC_LRO_REQUEST_LAST 11
  844. #define NX_FW_CAPABILITY_LINK_NOTIFICATION (1 << 5)
  845. #define NX_FW_CAPABILITY_SWITCHING (1 << 6)
  846. #define NX_FW_CAPABILITY_PEXQ (1 << 7)
  847. #define NX_FW_CAPABILITY_BDG (1 << 8)
  848. #define NX_FW_CAPABILITY_FVLANTX (1 << 9)
  849. #define NX_FW_CAPABILITY_HW_LRO (1 << 10)
  850. /* module types */
  851. #define LINKEVENT_MODULE_NOT_PRESENT 1
  852. #define LINKEVENT_MODULE_OPTICAL_UNKNOWN 2
  853. #define LINKEVENT_MODULE_OPTICAL_SRLR 3
  854. #define LINKEVENT_MODULE_OPTICAL_LRM 4
  855. #define LINKEVENT_MODULE_OPTICAL_SFP_1G 5
  856. #define LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLE 6
  857. #define LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLELEN 7
  858. #define LINKEVENT_MODULE_TWINAX 8
  859. #define LINKSPEED_10GBPS 10000
  860. #define LINKSPEED_1GBPS 1000
  861. #define LINKSPEED_100MBPS 100
  862. #define LINKSPEED_10MBPS 10
  863. #define LINKSPEED_ENCODED_10MBPS 0
  864. #define LINKSPEED_ENCODED_100MBPS 1
  865. #define LINKSPEED_ENCODED_1GBPS 2
  866. #define LINKEVENT_AUTONEG_DISABLED 0
  867. #define LINKEVENT_AUTONEG_ENABLED 1
  868. #define LINKEVENT_HALF_DUPLEX 0
  869. #define LINKEVENT_FULL_DUPLEX 1
  870. #define LINKEVENT_LINKSPEED_MBPS 0
  871. #define LINKEVENT_LINKSPEED_ENCODED 1
  872. /* firmware response header:
  873. * 63:58 - message type
  874. * 57:56 - owner
  875. * 55:53 - desc count
  876. * 52:48 - reserved
  877. * 47:40 - completion id
  878. * 39:32 - opcode
  879. * 31:16 - error code
  880. * 15:00 - reserved
  881. */
  882. #define netxen_get_nic_msgtype(msg_hdr) \
  883. ((msg_hdr >> 58) & 0x3F)
  884. #define netxen_get_nic_msg_compid(msg_hdr) \
  885. ((msg_hdr >> 40) & 0xFF)
  886. #define netxen_get_nic_msg_opcode(msg_hdr) \
  887. ((msg_hdr >> 32) & 0xFF)
  888. #define netxen_get_nic_msg_errcode(msg_hdr) \
  889. ((msg_hdr >> 16) & 0xFFFF)
  890. typedef struct {
  891. union {
  892. struct {
  893. u64 hdr;
  894. u64 body[7];
  895. };
  896. u64 words[8];
  897. };
  898. } nx_fw_msg_t;
  899. typedef struct {
  900. __le64 qhdr;
  901. __le64 req_hdr;
  902. __le64 words[6];
  903. } nx_nic_req_t;
  904. typedef struct {
  905. u8 op;
  906. u8 tag;
  907. u8 mac_addr[6];
  908. } nx_mac_req_t;
  909. #define MAX_PENDING_DESC_BLOCK_SIZE 64
  910. #define NETXEN_NIC_MSI_ENABLED 0x02
  911. #define NETXEN_NIC_MSIX_ENABLED 0x04
  912. #define NETXEN_NIC_LRO_ENABLED 0x08
  913. #define NETXEN_NIC_BRIDGE_ENABLED 0X10
  914. #define NETXEN_IS_MSI_FAMILY(adapter) \
  915. ((adapter)->flags & (NETXEN_NIC_MSI_ENABLED | NETXEN_NIC_MSIX_ENABLED))
  916. #define MSIX_ENTRIES_PER_ADAPTER NUM_STS_DESC_RINGS
  917. #define NETXEN_MSIX_TBL_SPACE 8192
  918. #define NETXEN_PCI_REG_MSIX_TBL 0x44
  919. #define NETXEN_DB_MAPSIZE_BYTES 0x1000
  920. #define NETXEN_NETDEV_WEIGHT 128
  921. #define NETXEN_ADAPTER_UP_MAGIC 777
  922. #define NETXEN_NIC_PEG_TUNE 0
  923. #define __NX_FW_ATTACHED 0
  924. #define __NX_DEV_UP 1
  925. #define __NX_RESETTING 2
  926. struct netxen_dummy_dma {
  927. void *addr;
  928. dma_addr_t phys_addr;
  929. };
  930. struct netxen_adapter {
  931. struct netxen_hardware_context ahw;
  932. struct net_device *netdev;
  933. struct pci_dev *pdev;
  934. struct list_head mac_list;
  935. u32 curr_window;
  936. u32 crb_win;
  937. rwlock_t adapter_lock;
  938. spinlock_t tx_clean_lock;
  939. u16 num_txd;
  940. u16 num_rxd;
  941. u16 num_jumbo_rxd;
  942. u16 num_lro_rxd;
  943. u8 max_rds_rings;
  944. u8 max_sds_rings;
  945. u8 driver_mismatch;
  946. u8 msix_supported;
  947. u8 rx_csum;
  948. u8 pci_using_dac;
  949. u8 portnum;
  950. u8 physical_port;
  951. u8 mc_enabled;
  952. u8 max_mc_count;
  953. u8 rss_supported;
  954. u8 link_changed;
  955. u8 fw_wait_cnt;
  956. u8 fw_fail_cnt;
  957. u8 tx_timeo_cnt;
  958. u8 need_fw_reset;
  959. u8 has_link_events;
  960. u8 fw_type;
  961. u16 tx_context_id;
  962. u16 mtu;
  963. u16 is_up;
  964. u16 link_speed;
  965. u16 link_duplex;
  966. u16 link_autoneg;
  967. u16 module_type;
  968. u32 capabilities;
  969. u32 flags;
  970. u32 irq;
  971. u32 temp;
  972. u32 int_vec_bit;
  973. u32 heartbit;
  974. u8 mac_addr[ETH_ALEN];
  975. struct netxen_adapter_stats stats;
  976. struct netxen_recv_context recv_ctx;
  977. struct nx_host_tx_ring *tx_ring;
  978. int (*macaddr_set) (struct netxen_adapter *, u8 *);
  979. int (*set_mtu) (struct netxen_adapter *, int);
  980. int (*set_promisc) (struct netxen_adapter *, u32);
  981. void (*set_multi) (struct net_device *);
  982. int (*phy_read) (struct netxen_adapter *, u32 reg, u32 *);
  983. int (*phy_write) (struct netxen_adapter *, u32 reg, u32 val);
  984. int (*init_port) (struct netxen_adapter *, int);
  985. int (*stop_port) (struct netxen_adapter *);
  986. u32 (*crb_read)(struct netxen_adapter *, ulong);
  987. int (*crb_write)(struct netxen_adapter *, ulong, u32);
  988. int (*pci_mem_read)(struct netxen_adapter *, u64, void *, int);
  989. int (*pci_mem_write)(struct netxen_adapter *, u64, void *, int);
  990. unsigned long (*pci_set_window)(struct netxen_adapter *,
  991. unsigned long long);
  992. u32 (*io_read)(struct netxen_adapter *, void __iomem *);
  993. void (*io_write)(struct netxen_adapter *, void __iomem *, u32);
  994. void __iomem *tgt_mask_reg;
  995. void __iomem *pci_int_reg;
  996. void __iomem *tgt_status_reg;
  997. void __iomem *crb_int_state_reg;
  998. void __iomem *isr_int_vec;
  999. struct msix_entry msix_entries[MSIX_ENTRIES_PER_ADAPTER];
  1000. struct netxen_dummy_dma dummy_dma;
  1001. struct delayed_work fw_work;
  1002. struct work_struct tx_timeout_task;
  1003. struct net_device_stats net_stats;
  1004. nx_nic_intr_coalesce_t coal;
  1005. unsigned long state;
  1006. u32 resv5;
  1007. u32 fw_version;
  1008. const struct firmware *fw;
  1009. };
  1010. int netxen_niu_xg_init_port(struct netxen_adapter *adapter, int port);
  1011. int netxen_niu_disable_xg_port(struct netxen_adapter *adapter);
  1012. int nx_fw_cmd_query_phy(struct netxen_adapter *adapter, u32 reg, u32 *val);
  1013. int nx_fw_cmd_set_phy(struct netxen_adapter *adapter, u32 reg, u32 val);
  1014. /* Functions available from netxen_nic_hw.c */
  1015. int netxen_nic_set_mtu_xgb(struct netxen_adapter *adapter, int new_mtu);
  1016. int netxen_nic_set_mtu_gb(struct netxen_adapter *adapter, int new_mtu);
  1017. int netxen_p2_nic_set_mac_addr(struct netxen_adapter *adapter, u8 *addr);
  1018. int netxen_p3_nic_set_mac_addr(struct netxen_adapter *adapter, u8 *addr);
  1019. #define NXRD32(adapter, off) \
  1020. (adapter->crb_read(adapter, off))
  1021. #define NXWR32(adapter, off, val) \
  1022. (adapter->crb_write(adapter, off, val))
  1023. #define NXRDIO(adapter, addr) \
  1024. (adapter->io_read(adapter, addr))
  1025. #define NXWRIO(adapter, addr, val) \
  1026. (adapter->io_write(adapter, addr, val))
  1027. int netxen_pcie_sem_lock(struct netxen_adapter *, int, u32);
  1028. void netxen_pcie_sem_unlock(struct netxen_adapter *, int);
  1029. #define netxen_rom_lock(a) \
  1030. netxen_pcie_sem_lock((a), 2, NETXEN_ROM_LOCK_ID)
  1031. #define netxen_rom_unlock(a) \
  1032. netxen_pcie_sem_unlock((a), 2)
  1033. #define netxen_phy_lock(a) \
  1034. netxen_pcie_sem_lock((a), 3, NETXEN_PHY_LOCK_ID)
  1035. #define netxen_phy_unlock(a) \
  1036. netxen_pcie_sem_unlock((a), 3)
  1037. #define netxen_api_lock(a) \
  1038. netxen_pcie_sem_lock((a), 5, 0)
  1039. #define netxen_api_unlock(a) \
  1040. netxen_pcie_sem_unlock((a), 5)
  1041. #define netxen_sw_lock(a) \
  1042. netxen_pcie_sem_lock((a), 6, 0)
  1043. #define netxen_sw_unlock(a) \
  1044. netxen_pcie_sem_unlock((a), 6)
  1045. #define crb_win_lock(a) \
  1046. netxen_pcie_sem_lock((a), 7, NETXEN_CRB_WIN_LOCK_ID)
  1047. #define crb_win_unlock(a) \
  1048. netxen_pcie_sem_unlock((a), 7)
  1049. int netxen_nic_get_board_info(struct netxen_adapter *adapter);
  1050. int netxen_nic_wol_supported(struct netxen_adapter *adapter);
  1051. /* Functions from netxen_nic_init.c */
  1052. int netxen_init_dummy_dma(struct netxen_adapter *adapter);
  1053. void netxen_free_dummy_dma(struct netxen_adapter *adapter);
  1054. int netxen_phantom_init(struct netxen_adapter *adapter, int pegtune_val);
  1055. int netxen_load_firmware(struct netxen_adapter *adapter);
  1056. int netxen_need_fw_reset(struct netxen_adapter *adapter);
  1057. void netxen_request_firmware(struct netxen_adapter *adapter);
  1058. void netxen_release_firmware(struct netxen_adapter *adapter);
  1059. int netxen_pinit_from_rom(struct netxen_adapter *adapter, int verbose);
  1060. int netxen_rom_fast_read(struct netxen_adapter *adapter, int addr, int *valp);
  1061. int netxen_rom_fast_read_words(struct netxen_adapter *adapter, int addr,
  1062. u8 *bytes, size_t size);
  1063. int netxen_rom_fast_write_words(struct netxen_adapter *adapter, int addr,
  1064. u8 *bytes, size_t size);
  1065. int netxen_flash_unlock(struct netxen_adapter *adapter);
  1066. int netxen_backup_crbinit(struct netxen_adapter *adapter);
  1067. int netxen_flash_erase_secondary(struct netxen_adapter *adapter);
  1068. int netxen_flash_erase_primary(struct netxen_adapter *adapter);
  1069. void netxen_halt_pegs(struct netxen_adapter *adapter);
  1070. int netxen_rom_se(struct netxen_adapter *adapter, int addr);
  1071. int netxen_alloc_sw_resources(struct netxen_adapter *adapter);
  1072. void netxen_free_sw_resources(struct netxen_adapter *adapter);
  1073. void netxen_setup_hwops(struct netxen_adapter *adapter);
  1074. void __iomem *netxen_get_ioaddr(struct netxen_adapter *, u32);
  1075. int netxen_alloc_hw_resources(struct netxen_adapter *adapter);
  1076. void netxen_free_hw_resources(struct netxen_adapter *adapter);
  1077. void netxen_release_rx_buffers(struct netxen_adapter *adapter);
  1078. void netxen_release_tx_buffers(struct netxen_adapter *adapter);
  1079. int netxen_init_firmware(struct netxen_adapter *adapter);
  1080. void netxen_nic_clear_stats(struct netxen_adapter *adapter);
  1081. void netxen_watchdog_task(struct work_struct *work);
  1082. void netxen_post_rx_buffers(struct netxen_adapter *adapter, u32 ringid,
  1083. struct nx_host_rds_ring *rds_ring);
  1084. int netxen_process_cmd_ring(struct netxen_adapter *adapter);
  1085. int netxen_process_rcv_ring(struct nx_host_sds_ring *sds_ring, int max);
  1086. void netxen_p2_nic_set_multi(struct net_device *netdev);
  1087. void netxen_p3_nic_set_multi(struct net_device *netdev);
  1088. void netxen_p3_free_mac_list(struct netxen_adapter *adapter);
  1089. int netxen_p2_nic_set_promisc(struct netxen_adapter *adapter, u32 mode);
  1090. int netxen_p3_nic_set_promisc(struct netxen_adapter *adapter, u32);
  1091. int netxen_config_intr_coalesce(struct netxen_adapter *adapter);
  1092. int netxen_config_rss(struct netxen_adapter *adapter, int enable);
  1093. int netxen_config_ipaddr(struct netxen_adapter *adapter, u32 ip, int cmd);
  1094. int netxen_linkevent_request(struct netxen_adapter *adapter, int enable);
  1095. void netxen_advert_link_change(struct netxen_adapter *adapter, int linkup);
  1096. int nx_fw_cmd_set_mtu(struct netxen_adapter *adapter, int mtu);
  1097. int netxen_nic_change_mtu(struct net_device *netdev, int new_mtu);
  1098. int netxen_config_hw_lro(struct netxen_adapter *adapter, int enable);
  1099. int netxen_config_bridged_mode(struct netxen_adapter *adapter, int enable);
  1100. int netxen_send_lro_cleanup(struct netxen_adapter *adapter);
  1101. int netxen_nic_set_mac(struct net_device *netdev, void *p);
  1102. struct net_device_stats *netxen_nic_get_stats(struct net_device *netdev);
  1103. void netxen_nic_update_cmd_producer(struct netxen_adapter *adapter,
  1104. struct nx_host_tx_ring *tx_ring);
  1105. /* Functions from netxen_nic_main.c */
  1106. int netxen_nic_reset_context(struct netxen_adapter *);
  1107. /*
  1108. * NetXen Board information
  1109. */
  1110. #define NETXEN_MAX_SHORT_NAME 32
  1111. struct netxen_brdinfo {
  1112. int brdtype; /* type of board */
  1113. long ports; /* max no of physical ports */
  1114. char short_name[NETXEN_MAX_SHORT_NAME];
  1115. };
  1116. static const struct netxen_brdinfo netxen_boards[] = {
  1117. {NETXEN_BRDTYPE_P2_SB31_10G_CX4, 1, "XGb CX4"},
  1118. {NETXEN_BRDTYPE_P2_SB31_10G_HMEZ, 1, "XGb HMEZ"},
  1119. {NETXEN_BRDTYPE_P2_SB31_10G_IMEZ, 2, "XGb IMEZ"},
  1120. {NETXEN_BRDTYPE_P2_SB31_10G, 1, "XGb XFP"},
  1121. {NETXEN_BRDTYPE_P2_SB35_4G, 4, "Quad Gb"},
  1122. {NETXEN_BRDTYPE_P2_SB31_2G, 2, "Dual Gb"},
  1123. {NETXEN_BRDTYPE_P3_REF_QG, 4, "Reference Quad Gig "},
  1124. {NETXEN_BRDTYPE_P3_HMEZ, 2, "Dual XGb HMEZ"},
  1125. {NETXEN_BRDTYPE_P3_10G_CX4_LP, 2, "Dual XGb CX4 LP"},
  1126. {NETXEN_BRDTYPE_P3_4_GB, 4, "Quad Gig LP"},
  1127. {NETXEN_BRDTYPE_P3_IMEZ, 2, "Dual XGb IMEZ"},
  1128. {NETXEN_BRDTYPE_P3_10G_SFP_PLUS, 2, "Dual XGb SFP+ LP"},
  1129. {NETXEN_BRDTYPE_P3_10000_BASE_T, 1, "XGB 10G BaseT LP"},
  1130. {NETXEN_BRDTYPE_P3_XG_LOM, 2, "Dual XGb LOM"},
  1131. {NETXEN_BRDTYPE_P3_4_GB_MM, 4, "NX3031 Gigabit Ethernet"},
  1132. {NETXEN_BRDTYPE_P3_10G_SFP_CT, 2, "NX3031 10 Gigabit Ethernet"},
  1133. {NETXEN_BRDTYPE_P3_10G_SFP_QT, 2, "Quanta Dual XGb SFP+"},
  1134. {NETXEN_BRDTYPE_P3_10G_CX4, 2, "Reference Dual CX4 Option"},
  1135. {NETXEN_BRDTYPE_P3_10G_XFP, 1, "Reference Single XFP Option"}
  1136. };
  1137. #define NUM_SUPPORTED_BOARDS ARRAY_SIZE(netxen_boards)
  1138. static inline void get_brd_name_by_type(u32 type, char *name)
  1139. {
  1140. int i, found = 0;
  1141. for (i = 0; i < NUM_SUPPORTED_BOARDS; ++i) {
  1142. if (netxen_boards[i].brdtype == type) {
  1143. strcpy(name, netxen_boards[i].short_name);
  1144. found = 1;
  1145. break;
  1146. }
  1147. }
  1148. if (!found)
  1149. name = "Unknown";
  1150. }
  1151. static inline u32 netxen_tx_avail(struct nx_host_tx_ring *tx_ring)
  1152. {
  1153. smp_mb();
  1154. return find_diff_among(tx_ring->producer,
  1155. tx_ring->sw_consumer, tx_ring->num_desc);
  1156. }
  1157. int netxen_get_flash_mac_addr(struct netxen_adapter *adapter, __le64 *mac);
  1158. int netxen_p3_get_mac_addr(struct netxen_adapter *adapter, __le64 *mac);
  1159. extern void netxen_change_ringparam(struct netxen_adapter *adapter);
  1160. extern int netxen_rom_fast_read(struct netxen_adapter *adapter, int addr,
  1161. int *valp);
  1162. extern const struct ethtool_ops netxen_nic_ethtool_ops;
  1163. #endif /* __NETXEN_NIC_H_ */