netxen_nic.h 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Copyright (C) 2003 - 2009 NetXen, Inc.
  4. * Copyright (C) 2009 - QLogic Corporation.
  5. * All rights reserved.
  6. */
  7. #ifndef _NETXEN_NIC_H_
  8. #define _NETXEN_NIC_H_
  9. #include <linux/module.h>
  10. #include <linux/kernel.h>
  11. #include <linux/types.h>
  12. #include <linux/ioport.h>
  13. #include <linux/pci.h>
  14. #include <linux/netdevice.h>
  15. #include <linux/etherdevice.h>
  16. #include <linux/ip.h>
  17. #include <linux/in.h>
  18. #include <linux/tcp.h>
  19. #include <linux/skbuff.h>
  20. #include <linux/firmware.h>
  21. #include <linux/ethtool.h>
  22. #include <linux/mii.h>
  23. #include <linux/timer.h>
  24. #include <linux/vmalloc.h>
  25. #include <asm/io.h>
  26. #include <asm/byteorder.h>
  27. #include "netxen_nic_hdr.h"
  28. #include "netxen_nic_hw.h"
  29. #define _NETXEN_NIC_LINUX_MAJOR 4
  30. #define _NETXEN_NIC_LINUX_MINOR 0
  31. #define _NETXEN_NIC_LINUX_SUBVERSION 82
  32. #define NETXEN_NIC_LINUX_VERSIONID "4.0.82"
  33. #define NETXEN_VERSION_CODE(a, b, c) (((a) << 24) + ((b) << 16) + (c))
  34. #define _major(v) (((v) >> 24) & 0xff)
  35. #define _minor(v) (((v) >> 16) & 0xff)
  36. #define _build(v) ((v) & 0xffff)
  37. /* version in image has weird encoding:
  38. * 7:0 - major
  39. * 15:8 - minor
  40. * 31:16 - build (little endian)
  41. */
  42. #define NETXEN_DECODE_VERSION(v) \
  43. NETXEN_VERSION_CODE(((v) & 0xff), (((v) >> 8) & 0xff), ((v) >> 16))
  44. #define NETXEN_NUM_FLASH_SECTORS (64)
  45. #define NETXEN_FLASH_SECTOR_SIZE (64 * 1024)
  46. #define NETXEN_FLASH_TOTAL_SIZE (NETXEN_NUM_FLASH_SECTORS \
  47. * NETXEN_FLASH_SECTOR_SIZE)
  48. #define RCV_DESC_RINGSIZE(rds_ring) \
  49. (sizeof(struct rcv_desc) * (rds_ring)->num_desc)
  50. #define RCV_BUFF_RINGSIZE(rds_ring) \
  51. (sizeof(struct netxen_rx_buffer) * rds_ring->num_desc)
  52. #define STATUS_DESC_RINGSIZE(sds_ring) \
  53. (sizeof(struct status_desc) * (sds_ring)->num_desc)
  54. #define TX_BUFF_RINGSIZE(tx_ring) \
  55. (sizeof(struct netxen_cmd_buffer) * tx_ring->num_desc)
  56. #define TX_DESC_RINGSIZE(tx_ring) \
  57. (sizeof(struct cmd_desc_type0) * tx_ring->num_desc)
  58. #define find_diff_among(a,b,range) ((a)<(b)?((b)-(a)):((b)+(range)-(a)))
  59. #define NETXEN_RCV_PRODUCER_OFFSET 0
  60. #define NETXEN_RCV_PEG_DB_ID 2
  61. #define NETXEN_HOST_DUMMY_DMA_SIZE 1024
  62. #define FLASH_SUCCESS 0
  63. #define ADDR_IN_WINDOW1(off) \
  64. ((off > NETXEN_CRB_PCIX_HOST2) && (off < NETXEN_CRB_MAX)) ? 1 : 0
  65. #define ADDR_IN_RANGE(addr, low, high) \
  66. (((addr) < (high)) && ((addr) >= (low)))
  67. /*
  68. * normalize a 64MB crb address to 32MB PCI window
  69. * To use NETXEN_CRB_NORMALIZE, window _must_ be set to 1
  70. */
  71. #define NETXEN_CRB_NORMAL(reg) \
  72. ((reg) - NETXEN_CRB_PCIX_HOST2 + NETXEN_CRB_PCIX_HOST)
  73. #define NETXEN_CRB_NORMALIZE(adapter, reg) \
  74. pci_base_offset(adapter, NETXEN_CRB_NORMAL(reg))
  75. #define DB_NORMALIZE(adapter, off) \
  76. (adapter->ahw.db_base + (off))
  77. #define NX_P2_C0 0x24
  78. #define NX_P2_C1 0x25
  79. #define NX_P3_A0 0x30
  80. #define NX_P3_A2 0x30
  81. #define NX_P3_B0 0x40
  82. #define NX_P3_B1 0x41
  83. #define NX_P3_B2 0x42
  84. #define NX_P3P_A0 0x50
  85. #define NX_IS_REVISION_P2(REVISION) (REVISION <= NX_P2_C1)
  86. #define NX_IS_REVISION_P3(REVISION) (REVISION >= NX_P3_A0)
  87. #define NX_IS_REVISION_P3P(REVISION) (REVISION >= NX_P3P_A0)
  88. #define FIRST_PAGE_GROUP_START 0
  89. #define FIRST_PAGE_GROUP_END 0x100000
  90. #define SECOND_PAGE_GROUP_START 0x6000000
  91. #define SECOND_PAGE_GROUP_END 0x68BC000
  92. #define THIRD_PAGE_GROUP_START 0x70E4000
  93. #define THIRD_PAGE_GROUP_END 0x8000000
  94. #define FIRST_PAGE_GROUP_SIZE FIRST_PAGE_GROUP_END - FIRST_PAGE_GROUP_START
  95. #define SECOND_PAGE_GROUP_SIZE SECOND_PAGE_GROUP_END - SECOND_PAGE_GROUP_START
  96. #define THIRD_PAGE_GROUP_SIZE THIRD_PAGE_GROUP_END - THIRD_PAGE_GROUP_START
  97. #define P2_MAX_MTU (8000)
  98. #define P3_MAX_MTU (9600)
  99. #define NX_ETHERMTU 1500
  100. #define NX_MAX_ETHERHDR 32 /* This contains some padding */
  101. #define NX_P2_RX_BUF_MAX_LEN 1760
  102. #define NX_P3_RX_BUF_MAX_LEN (NX_MAX_ETHERHDR + NX_ETHERMTU)
  103. #define NX_P2_RX_JUMBO_BUF_MAX_LEN (NX_MAX_ETHERHDR + P2_MAX_MTU)
  104. #define NX_P3_RX_JUMBO_BUF_MAX_LEN (NX_MAX_ETHERHDR + P3_MAX_MTU)
  105. #define NX_CT_DEFAULT_RX_BUF_LEN 2048
  106. #define NX_LRO_BUFFER_EXTRA 2048
  107. #define NX_RX_LRO_BUFFER_LENGTH (8060)
  108. /*
  109. * Maximum number of ring contexts
  110. */
  111. #define MAX_RING_CTX 1
  112. /* Opcodes to be used with the commands */
  113. #define TX_ETHER_PKT 0x01
  114. #define TX_TCP_PKT 0x02
  115. #define TX_UDP_PKT 0x03
  116. #define TX_IP_PKT 0x04
  117. #define TX_TCP_LSO 0x05
  118. #define TX_TCP_LSO6 0x06
  119. #define TX_IPSEC 0x07
  120. #define TX_IPSEC_CMD 0x0a
  121. #define TX_TCPV6_PKT 0x0b
  122. #define TX_UDPV6_PKT 0x0c
  123. /* The following opcodes are for internal consumption. */
  124. #define NETXEN_CONTROL_OP 0x10
  125. #define PEGNET_REQUEST 0x11
  126. #define MAX_NUM_CARDS 4
  127. #define NETXEN_MAX_FRAGS_PER_TX 14
  128. #define MAX_TSO_HEADER_DESC 2
  129. #define MGMT_CMD_DESC_RESV 4
  130. #define TX_STOP_THRESH ((MAX_SKB_FRAGS >> 2) + MAX_TSO_HEADER_DESC \
  131. + MGMT_CMD_DESC_RESV)
  132. #define NX_MAX_TX_TIMEOUTS 2
  133. /*
  134. * Following are the states of the Phantom. Phantom will set them and
  135. * Host will read to check if the fields are correct.
  136. */
  137. #define PHAN_INITIALIZE_START 0xff00
  138. #define PHAN_INITIALIZE_FAILED 0xffff
  139. #define PHAN_INITIALIZE_COMPLETE 0xff01
  140. /* Host writes the following to notify that it has done the init-handshake */
  141. #define PHAN_INITIALIZE_ACK 0xf00f
  142. #define NUM_RCV_DESC_RINGS 3
  143. #define NUM_STS_DESC_RINGS 4
  144. #define RCV_RING_NORMAL 0
  145. #define RCV_RING_JUMBO 1
  146. #define RCV_RING_LRO 2
  147. #define MIN_CMD_DESCRIPTORS 64
  148. #define MIN_RCV_DESCRIPTORS 64
  149. #define MIN_JUMBO_DESCRIPTORS 32
  150. #define MAX_CMD_DESCRIPTORS 1024
  151. #define MAX_RCV_DESCRIPTORS_1G 4096
  152. #define MAX_RCV_DESCRIPTORS_10G 8192
  153. #define MAX_JUMBO_RCV_DESCRIPTORS_1G 512
  154. #define MAX_JUMBO_RCV_DESCRIPTORS_10G 1024
  155. #define MAX_LRO_RCV_DESCRIPTORS 8
  156. #define DEFAULT_RCV_DESCRIPTORS_1G 2048
  157. #define DEFAULT_RCV_DESCRIPTORS_10G 4096
  158. #define NETXEN_CTX_SIGNATURE 0xdee0
  159. #define NETXEN_CTX_SIGNATURE_V2 0x0002dee0
  160. #define NETXEN_CTX_RESET 0xbad0
  161. #define NETXEN_CTX_D3_RESET 0xacc0
  162. #define NETXEN_RCV_PRODUCER(ringid) (ringid)
  163. #define PHAN_PEG_RCV_INITIALIZED 0xff01
  164. #define PHAN_PEG_RCV_START_INITIALIZE 0xff00
  165. #define get_next_index(index, length) \
  166. (((index) + 1) & ((length) - 1))
  167. #define get_index_range(index,length,count) \
  168. (((index) + (count)) & ((length) - 1))
  169. #define MPORT_SINGLE_FUNCTION_MODE 0x1111
  170. #define MPORT_MULTI_FUNCTION_MODE 0x2222
  171. #define NX_MAX_PCI_FUNC 8
  172. /*
  173. * NetXen host-peg signal message structure
  174. *
  175. * Bit 0-1 : peg_id => 0x2 for tx and 01 for rx
  176. * Bit 2 : priv_id => must be 1
  177. * Bit 3-17 : count => for doorbell
  178. * Bit 18-27 : ctx_id => Context id
  179. * Bit 28-31 : opcode
  180. */
  181. typedef u32 netxen_ctx_msg;
  182. #define netxen_set_msg_peg_id(config_word, val) \
  183. ((config_word) &= ~3, (config_word) |= val & 3)
  184. #define netxen_set_msg_privid(config_word) \
  185. ((config_word) |= 1 << 2)
  186. #define netxen_set_msg_count(config_word, val) \
  187. ((config_word) &= ~(0x7fff<<3), (config_word) |= (val & 0x7fff) << 3)
  188. #define netxen_set_msg_ctxid(config_word, val) \
  189. ((config_word) &= ~(0x3ff<<18), (config_word) |= (val & 0x3ff) << 18)
  190. #define netxen_set_msg_opcode(config_word, val) \
  191. ((config_word) &= ~(0xf<<28), (config_word) |= (val & 0xf) << 28)
  192. struct netxen_rcv_ring {
  193. __le64 addr;
  194. __le32 size;
  195. __le32 rsrvd;
  196. };
  197. struct netxen_sts_ring {
  198. __le64 addr;
  199. __le32 size;
  200. __le16 msi_index;
  201. __le16 rsvd;
  202. } ;
  203. struct netxen_ring_ctx {
  204. /* one command ring */
  205. __le64 cmd_consumer_offset;
  206. __le64 cmd_ring_addr;
  207. __le32 cmd_ring_size;
  208. __le32 rsrvd;
  209. /* three receive rings */
  210. struct netxen_rcv_ring rcv_rings[NUM_RCV_DESC_RINGS];
  211. __le64 sts_ring_addr;
  212. __le32 sts_ring_size;
  213. __le32 ctx_id;
  214. __le64 rsrvd_2[3];
  215. __le32 sts_ring_count;
  216. __le32 rsrvd_3;
  217. struct netxen_sts_ring sts_rings[NUM_STS_DESC_RINGS];
  218. } __attribute__ ((aligned(64)));
  219. /*
  220. * Following data structures describe the descriptors that will be used.
  221. * Added fileds of tcpHdrSize and ipHdrSize, The driver needs to do it only when
  222. * we are doing LSO (above the 1500 size packet) only.
  223. */
  224. /*
  225. * The size of reference handle been changed to 16 bits to pass the MSS fields
  226. * for the LSO packet
  227. */
  228. #define FLAGS_CHECKSUM_ENABLED 0x01
  229. #define FLAGS_LSO_ENABLED 0x02
  230. #define FLAGS_IPSEC_SA_ADD 0x04
  231. #define FLAGS_IPSEC_SA_DELETE 0x08
  232. #define FLAGS_VLAN_TAGGED 0x10
  233. #define FLAGS_VLAN_OOB 0x40
  234. #define netxen_set_tx_vlan_tci(cmd_desc, v) \
  235. (cmd_desc)->vlan_TCI = cpu_to_le16(v);
  236. #define netxen_set_cmd_desc_port(cmd_desc, var) \
  237. ((cmd_desc)->port_ctxid |= ((var) & 0x0F))
  238. #define netxen_set_cmd_desc_ctxid(cmd_desc, var) \
  239. ((cmd_desc)->port_ctxid |= ((var) << 4 & 0xF0))
  240. #define netxen_set_tx_port(_desc, _port) \
  241. (_desc)->port_ctxid = ((_port) & 0xf) | (((_port) << 4) & 0xf0)
  242. #define netxen_set_tx_flags_opcode(_desc, _flags, _opcode) \
  243. (_desc)->flags_opcode = \
  244. cpu_to_le16(((_flags) & 0x7f) | (((_opcode) & 0x3f) << 7))
  245. #define netxen_set_tx_frags_len(_desc, _frags, _len) \
  246. (_desc)->nfrags__length = \
  247. cpu_to_le32(((_frags) & 0xff) | (((_len) & 0xffffff) << 8))
  248. struct cmd_desc_type0 {
  249. u8 tcp_hdr_offset; /* For LSO only */
  250. u8 ip_hdr_offset; /* For LSO only */
  251. __le16 flags_opcode; /* 15:13 unused, 12:7 opcode, 6:0 flags */
  252. __le32 nfrags__length; /* 31:8 total len, 7:0 frag count */
  253. __le64 addr_buffer2;
  254. __le16 reference_handle;
  255. __le16 mss;
  256. u8 port_ctxid; /* 7:4 ctxid 3:0 port */
  257. u8 total_hdr_length; /* LSO only : MAC+IP+TCP Hdr size */
  258. __le16 conn_id; /* IPSec offoad only */
  259. __le64 addr_buffer3;
  260. __le64 addr_buffer1;
  261. __le16 buffer_length[4];
  262. __le64 addr_buffer4;
  263. __le32 reserved2;
  264. __le16 reserved;
  265. __le16 vlan_TCI;
  266. } __attribute__ ((aligned(64)));
  267. /* Note: sizeof(rcv_desc) should always be a multiple of 2 */
  268. struct rcv_desc {
  269. __le16 reference_handle;
  270. __le16 reserved;
  271. __le32 buffer_length; /* allocated buffer length (usually 2K) */
  272. __le64 addr_buffer;
  273. };
  274. /* opcode field in status_desc */
  275. #define NETXEN_NIC_SYN_OFFLOAD 0x03
  276. #define NETXEN_NIC_RXPKT_DESC 0x04
  277. #define NETXEN_OLD_RXPKT_DESC 0x3f
  278. #define NETXEN_NIC_RESPONSE_DESC 0x05
  279. #define NETXEN_NIC_LRO_DESC 0x12
  280. /* for status field in status_desc */
  281. #define STATUS_NEED_CKSUM (1)
  282. #define STATUS_CKSUM_OK (2)
  283. /* owner bits of status_desc */
  284. #define STATUS_OWNER_HOST (0x1ULL << 56)
  285. #define STATUS_OWNER_PHANTOM (0x2ULL << 56)
  286. /* Status descriptor:
  287. 0-3 port, 4-7 status, 8-11 type, 12-27 total_length
  288. 28-43 reference_handle, 44-47 protocol, 48-52 pkt_offset
  289. 53-55 desc_cnt, 56-57 owner, 58-63 opcode
  290. */
  291. #define netxen_get_sts_port(sts_data) \
  292. ((sts_data) & 0x0F)
  293. #define netxen_get_sts_status(sts_data) \
  294. (((sts_data) >> 4) & 0x0F)
  295. #define netxen_get_sts_type(sts_data) \
  296. (((sts_data) >> 8) & 0x0F)
  297. #define netxen_get_sts_totallength(sts_data) \
  298. (((sts_data) >> 12) & 0xFFFF)
  299. #define netxen_get_sts_refhandle(sts_data) \
  300. (((sts_data) >> 28) & 0xFFFF)
  301. #define netxen_get_sts_prot(sts_data) \
  302. (((sts_data) >> 44) & 0x0F)
  303. #define netxen_get_sts_pkt_offset(sts_data) \
  304. (((sts_data) >> 48) & 0x1F)
  305. #define netxen_get_sts_desc_cnt(sts_data) \
  306. (((sts_data) >> 53) & 0x7)
  307. #define netxen_get_sts_opcode(sts_data) \
  308. (((sts_data) >> 58) & 0x03F)
  309. #define netxen_get_lro_sts_refhandle(sts_data) \
  310. ((sts_data) & 0x0FFFF)
  311. #define netxen_get_lro_sts_length(sts_data) \
  312. (((sts_data) >> 16) & 0x0FFFF)
  313. #define netxen_get_lro_sts_l2_hdr_offset(sts_data) \
  314. (((sts_data) >> 32) & 0x0FF)
  315. #define netxen_get_lro_sts_l4_hdr_offset(sts_data) \
  316. (((sts_data) >> 40) & 0x0FF)
  317. #define netxen_get_lro_sts_timestamp(sts_data) \
  318. (((sts_data) >> 48) & 0x1)
  319. #define netxen_get_lro_sts_type(sts_data) \
  320. (((sts_data) >> 49) & 0x7)
  321. #define netxen_get_lro_sts_push_flag(sts_data) \
  322. (((sts_data) >> 52) & 0x1)
  323. #define netxen_get_lro_sts_seq_number(sts_data) \
  324. ((sts_data) & 0x0FFFFFFFF)
  325. #define netxen_get_lro_sts_mss(sts_data1) \
  326. ((sts_data1 >> 32) & 0x0FFFF)
  327. struct status_desc {
  328. __le64 status_desc_data[2];
  329. } __attribute__ ((aligned(16)));
  330. /* UNIFIED ROMIMAGE *************************/
  331. #define NX_UNI_DIR_SECT_PRODUCT_TBL 0x0
  332. #define NX_UNI_DIR_SECT_BOOTLD 0x6
  333. #define NX_UNI_DIR_SECT_FW 0x7
  334. /*Offsets */
  335. #define NX_UNI_CHIP_REV_OFF 10
  336. #define NX_UNI_FLAGS_OFF 11
  337. #define NX_UNI_BIOS_VERSION_OFF 12
  338. #define NX_UNI_BOOTLD_IDX_OFF 27
  339. #define NX_UNI_FIRMWARE_IDX_OFF 29
  340. struct uni_table_desc{
  341. uint32_t findex;
  342. uint32_t num_entries;
  343. uint32_t entry_size;
  344. uint32_t reserved[5];
  345. };
  346. struct uni_data_desc{
  347. uint32_t findex;
  348. uint32_t size;
  349. uint32_t reserved[5];
  350. };
  351. /* UNIFIED ROMIMAGE *************************/
  352. /* The version of the main data structure */
  353. #define NETXEN_BDINFO_VERSION 1
  354. /* Magic number to let user know flash is programmed */
  355. #define NETXEN_BDINFO_MAGIC 0x12345678
  356. /* Max number of Gig ports on a Phantom board */
  357. #define NETXEN_MAX_PORTS 4
  358. #define NETXEN_BRDTYPE_P1_BD 0x0000
  359. #define NETXEN_BRDTYPE_P1_SB 0x0001
  360. #define NETXEN_BRDTYPE_P1_SMAX 0x0002
  361. #define NETXEN_BRDTYPE_P1_SOCK 0x0003
  362. #define NETXEN_BRDTYPE_P2_SOCK_31 0x0008
  363. #define NETXEN_BRDTYPE_P2_SOCK_35 0x0009
  364. #define NETXEN_BRDTYPE_P2_SB35_4G 0x000a
  365. #define NETXEN_BRDTYPE_P2_SB31_10G 0x000b
  366. #define NETXEN_BRDTYPE_P2_SB31_2G 0x000c
  367. #define NETXEN_BRDTYPE_P2_SB31_10G_IMEZ 0x000d
  368. #define NETXEN_BRDTYPE_P2_SB31_10G_HMEZ 0x000e
  369. #define NETXEN_BRDTYPE_P2_SB31_10G_CX4 0x000f
  370. #define NETXEN_BRDTYPE_P3_REF_QG 0x0021
  371. #define NETXEN_BRDTYPE_P3_HMEZ 0x0022
  372. #define NETXEN_BRDTYPE_P3_10G_CX4_LP 0x0023
  373. #define NETXEN_BRDTYPE_P3_4_GB 0x0024
  374. #define NETXEN_BRDTYPE_P3_IMEZ 0x0025
  375. #define NETXEN_BRDTYPE_P3_10G_SFP_PLUS 0x0026
  376. #define NETXEN_BRDTYPE_P3_10000_BASE_T 0x0027
  377. #define NETXEN_BRDTYPE_P3_XG_LOM 0x0028
  378. #define NETXEN_BRDTYPE_P3_4_GB_MM 0x0029
  379. #define NETXEN_BRDTYPE_P3_10G_SFP_CT 0x002a
  380. #define NETXEN_BRDTYPE_P3_10G_SFP_QT 0x002b
  381. #define NETXEN_BRDTYPE_P3_10G_CX4 0x0031
  382. #define NETXEN_BRDTYPE_P3_10G_XFP 0x0032
  383. #define NETXEN_BRDTYPE_P3_10G_TP 0x0080
  384. /* Flash memory map */
  385. #define NETXEN_CRBINIT_START 0 /* crbinit section */
  386. #define NETXEN_BRDCFG_START 0x4000 /* board config */
  387. #define NETXEN_INITCODE_START 0x6000 /* pegtune code */
  388. #define NETXEN_BOOTLD_START 0x10000 /* bootld */
  389. #define NETXEN_IMAGE_START 0x43000 /* compressed image */
  390. #define NETXEN_SECONDARY_START 0x200000 /* backup images */
  391. #define NETXEN_PXE_START 0x3E0000 /* PXE boot rom */
  392. #define NETXEN_USER_START 0x3E8000 /* Firmware info */
  393. #define NETXEN_FIXED_START 0x3F0000 /* backup of crbinit */
  394. #define NETXEN_USER_START_OLD NETXEN_PXE_START /* very old flash */
  395. #define NX_OLD_MAC_ADDR_OFFSET (NETXEN_USER_START)
  396. #define NX_FW_VERSION_OFFSET (NETXEN_USER_START+0x408)
  397. #define NX_FW_SIZE_OFFSET (NETXEN_USER_START+0x40c)
  398. #define NX_FW_MAC_ADDR_OFFSET (NETXEN_USER_START+0x418)
  399. #define NX_FW_SERIAL_NUM_OFFSET (NETXEN_USER_START+0x81c)
  400. #define NX_BIOS_VERSION_OFFSET (NETXEN_USER_START+0x83c)
  401. #define NX_HDR_VERSION_OFFSET (NETXEN_BRDCFG_START)
  402. #define NX_BRDTYPE_OFFSET (NETXEN_BRDCFG_START+0x8)
  403. #define NX_FW_MAGIC_OFFSET (NETXEN_BRDCFG_START+0x128)
  404. #define NX_FW_MIN_SIZE (0x3fffff)
  405. #define NX_P2_MN_ROMIMAGE 0
  406. #define NX_P3_CT_ROMIMAGE 1
  407. #define NX_P3_MN_ROMIMAGE 2
  408. #define NX_UNIFIED_ROMIMAGE 3
  409. #define NX_FLASH_ROMIMAGE 4
  410. #define NX_UNKNOWN_ROMIMAGE 0xff
  411. #define NX_P2_MN_ROMIMAGE_NAME "nxromimg.bin"
  412. #define NX_P3_CT_ROMIMAGE_NAME "nx3fwct.bin"
  413. #define NX_P3_MN_ROMIMAGE_NAME "nx3fwmn.bin"
  414. #define NX_UNIFIED_ROMIMAGE_NAME "phanfw.bin"
  415. #define NX_FLASH_ROMIMAGE_NAME "flash"
  416. extern char netxen_nic_driver_name[];
  417. /* Number of status descriptors to handle per interrupt */
  418. #define MAX_STATUS_HANDLE (64)
  419. /*
  420. * netxen_skb_frag{} is to contain mapping info for each SG list. This
  421. * has to be freed when DMA is complete. This is part of netxen_tx_buffer{}.
  422. */
  423. struct netxen_skb_frag {
  424. u64 dma;
  425. u64 length;
  426. };
  427. struct netxen_recv_crb {
  428. u32 crb_rcv_producer[NUM_RCV_DESC_RINGS];
  429. u32 crb_sts_consumer[NUM_STS_DESC_RINGS];
  430. u32 sw_int_mask[NUM_STS_DESC_RINGS];
  431. };
  432. /* Following defines are for the state of the buffers */
  433. #define NETXEN_BUFFER_FREE 0
  434. #define NETXEN_BUFFER_BUSY 1
  435. /*
  436. * There will be one netxen_buffer per skb packet. These will be
  437. * used to save the dma info for pci_unmap_page()
  438. */
  439. struct netxen_cmd_buffer {
  440. struct sk_buff *skb;
  441. struct netxen_skb_frag frag_array[MAX_SKB_FRAGS + 1];
  442. u32 frag_count;
  443. };
  444. /* In rx_buffer, we do not need multiple fragments as is a single buffer */
  445. struct netxen_rx_buffer {
  446. struct list_head list;
  447. struct sk_buff *skb;
  448. u64 dma;
  449. u16 ref_handle;
  450. u16 state;
  451. };
  452. /* Board types */
  453. #define NETXEN_NIC_GBE 0x01
  454. #define NETXEN_NIC_XGBE 0x02
  455. /*
  456. * One hardware_context{} per adapter
  457. * contains interrupt info as well shared hardware info.
  458. */
  459. struct netxen_hardware_context {
  460. void __iomem *pci_base0;
  461. void __iomem *pci_base1;
  462. void __iomem *pci_base2;
  463. void __iomem *db_base;
  464. void __iomem *ocm_win_crb;
  465. unsigned long db_len;
  466. unsigned long pci_len0;
  467. u32 ocm_win;
  468. u32 crb_win;
  469. rwlock_t crb_lock;
  470. spinlock_t mem_lock;
  471. u8 cut_through;
  472. u8 revision_id;
  473. u8 pci_func;
  474. u8 linkup;
  475. u16 port_type;
  476. u16 board_type;
  477. };
  478. #define MINIMUM_ETHERNET_FRAME_SIZE 64 /* With FCS */
  479. #define ETHERNET_FCS_SIZE 4
  480. struct netxen_adapter_stats {
  481. u64 xmitcalled;
  482. u64 xmitfinished;
  483. u64 rxdropped;
  484. u64 txdropped;
  485. u64 csummed;
  486. u64 rx_pkts;
  487. u64 lro_pkts;
  488. u64 rxbytes;
  489. u64 txbytes;
  490. };
  491. /*
  492. * Rcv Descriptor Context. One such per Rcv Descriptor. There may
  493. * be one Rcv Descriptor for normal packets, one for jumbo and may be others.
  494. */
  495. struct nx_host_rds_ring {
  496. u32 producer;
  497. u32 num_desc;
  498. u32 dma_size;
  499. u32 skb_size;
  500. u32 flags;
  501. void __iomem *crb_rcv_producer;
  502. struct rcv_desc *desc_head;
  503. struct netxen_rx_buffer *rx_buf_arr;
  504. struct list_head free_list;
  505. spinlock_t lock;
  506. dma_addr_t phys_addr;
  507. };
  508. struct nx_host_sds_ring {
  509. u32 consumer;
  510. u32 num_desc;
  511. void __iomem *crb_sts_consumer;
  512. void __iomem *crb_intr_mask;
  513. struct status_desc *desc_head;
  514. struct netxen_adapter *adapter;
  515. struct napi_struct napi;
  516. struct list_head free_list[NUM_RCV_DESC_RINGS];
  517. int irq;
  518. dma_addr_t phys_addr;
  519. char name[IFNAMSIZ+4];
  520. };
  521. struct nx_host_tx_ring {
  522. u32 producer;
  523. __le32 *hw_consumer;
  524. u32 sw_consumer;
  525. void __iomem *crb_cmd_producer;
  526. void __iomem *crb_cmd_consumer;
  527. u32 num_desc;
  528. struct netdev_queue *txq;
  529. struct netxen_cmd_buffer *cmd_buf_arr;
  530. struct cmd_desc_type0 *desc_head;
  531. dma_addr_t phys_addr;
  532. };
  533. /*
  534. * Receive context. There is one such structure per instance of the
  535. * receive processing. Any state information that is relevant to
  536. * the receive, and is must be in this structure. The global data may be
  537. * present elsewhere.
  538. */
  539. struct netxen_recv_context {
  540. u32 state;
  541. u16 context_id;
  542. u16 virt_port;
  543. struct nx_host_rds_ring *rds_rings;
  544. struct nx_host_sds_ring *sds_rings;
  545. struct netxen_ring_ctx *hwctx;
  546. dma_addr_t phys_addr;
  547. };
  548. struct _cdrp_cmd {
  549. u32 cmd;
  550. u32 arg1;
  551. u32 arg2;
  552. u32 arg3;
  553. };
  554. struct netxen_cmd_args {
  555. struct _cdrp_cmd req;
  556. struct _cdrp_cmd rsp;
  557. };
  558. /* New HW context creation */
  559. #define NX_OS_CRB_RETRY_COUNT 4000
  560. #define NX_CDRP_SIGNATURE_MAKE(pcifn, version) \
  561. (((pcifn) & 0xff) | (((version) & 0xff) << 8) | (0xcafe << 16))
  562. #define NX_CDRP_CLEAR 0x00000000
  563. #define NX_CDRP_CMD_BIT 0x80000000
  564. /*
  565. * All responses must have the NX_CDRP_CMD_BIT cleared
  566. * in the crb NX_CDRP_CRB_OFFSET.
  567. */
  568. #define NX_CDRP_FORM_RSP(rsp) (rsp)
  569. #define NX_CDRP_IS_RSP(rsp) (((rsp) & NX_CDRP_CMD_BIT) == 0)
  570. #define NX_CDRP_RSP_OK 0x00000001
  571. #define NX_CDRP_RSP_FAIL 0x00000002
  572. #define NX_CDRP_RSP_TIMEOUT 0x00000003
  573. /*
  574. * All commands must have the NX_CDRP_CMD_BIT set in
  575. * the crb NX_CDRP_CRB_OFFSET.
  576. */
  577. #define NX_CDRP_FORM_CMD(cmd) (NX_CDRP_CMD_BIT | (cmd))
  578. #define NX_CDRP_IS_CMD(cmd) (((cmd) & NX_CDRP_CMD_BIT) != 0)
  579. #define NX_CDRP_CMD_SUBMIT_CAPABILITIES 0x00000001
  580. #define NX_CDRP_CMD_READ_MAX_RDS_PER_CTX 0x00000002
  581. #define NX_CDRP_CMD_READ_MAX_SDS_PER_CTX 0x00000003
  582. #define NX_CDRP_CMD_READ_MAX_RULES_PER_CTX 0x00000004
  583. #define NX_CDRP_CMD_READ_MAX_RX_CTX 0x00000005
  584. #define NX_CDRP_CMD_READ_MAX_TX_CTX 0x00000006
  585. #define NX_CDRP_CMD_CREATE_RX_CTX 0x00000007
  586. #define NX_CDRP_CMD_DESTROY_RX_CTX 0x00000008
  587. #define NX_CDRP_CMD_CREATE_TX_CTX 0x00000009
  588. #define NX_CDRP_CMD_DESTROY_TX_CTX 0x0000000a
  589. #define NX_CDRP_CMD_SETUP_STATISTICS 0x0000000e
  590. #define NX_CDRP_CMD_GET_STATISTICS 0x0000000f
  591. #define NX_CDRP_CMD_DELETE_STATISTICS 0x00000010
  592. #define NX_CDRP_CMD_SET_MTU 0x00000012
  593. #define NX_CDRP_CMD_READ_PHY 0x00000013
  594. #define NX_CDRP_CMD_WRITE_PHY 0x00000014
  595. #define NX_CDRP_CMD_READ_HW_REG 0x00000015
  596. #define NX_CDRP_CMD_GET_FLOW_CTL 0x00000016
  597. #define NX_CDRP_CMD_SET_FLOW_CTL 0x00000017
  598. #define NX_CDRP_CMD_READ_MAX_MTU 0x00000018
  599. #define NX_CDRP_CMD_READ_MAX_LRO 0x00000019
  600. #define NX_CDRP_CMD_CONFIGURE_TOE 0x0000001a
  601. #define NX_CDRP_CMD_FUNC_ATTRIB 0x0000001b
  602. #define NX_CDRP_CMD_READ_PEXQ_PARAMETERS 0x0000001c
  603. #define NX_CDRP_CMD_GET_LIC_CAPABILITIES 0x0000001d
  604. #define NX_CDRP_CMD_READ_MAX_LRO_PER_BOARD 0x0000001e
  605. #define NX_CDRP_CMD_CONFIG_GBE_PORT 0x0000001f
  606. #define NX_CDRP_CMD_MAX 0x00000020
  607. #define NX_RCODE_SUCCESS 0
  608. #define NX_RCODE_NO_HOST_MEM 1
  609. #define NX_RCODE_NO_HOST_RESOURCE 2
  610. #define NX_RCODE_NO_CARD_CRB 3
  611. #define NX_RCODE_NO_CARD_MEM 4
  612. #define NX_RCODE_NO_CARD_RESOURCE 5
  613. #define NX_RCODE_INVALID_ARGS 6
  614. #define NX_RCODE_INVALID_ACTION 7
  615. #define NX_RCODE_INVALID_STATE 8
  616. #define NX_RCODE_NOT_SUPPORTED 9
  617. #define NX_RCODE_NOT_PERMITTED 10
  618. #define NX_RCODE_NOT_READY 11
  619. #define NX_RCODE_DOES_NOT_EXIST 12
  620. #define NX_RCODE_ALREADY_EXISTS 13
  621. #define NX_RCODE_BAD_SIGNATURE 14
  622. #define NX_RCODE_CMD_NOT_IMPL 15
  623. #define NX_RCODE_CMD_INVALID 16
  624. #define NX_RCODE_TIMEOUT 17
  625. #define NX_RCODE_CMD_FAILED 18
  626. #define NX_RCODE_MAX_EXCEEDED 19
  627. #define NX_RCODE_MAX 20
  628. #define NX_DESTROY_CTX_RESET 0
  629. #define NX_DESTROY_CTX_D3_RESET 1
  630. #define NX_DESTROY_CTX_MAX 2
  631. /*
  632. * Capabilities
  633. */
  634. #define NX_CAP_BIT(class, bit) (1 << bit)
  635. #define NX_CAP0_LEGACY_CONTEXT NX_CAP_BIT(0, 0)
  636. #define NX_CAP0_MULTI_CONTEXT NX_CAP_BIT(0, 1)
  637. #define NX_CAP0_LEGACY_MN NX_CAP_BIT(0, 2)
  638. #define NX_CAP0_LEGACY_MS NX_CAP_BIT(0, 3)
  639. #define NX_CAP0_CUT_THROUGH NX_CAP_BIT(0, 4)
  640. #define NX_CAP0_LRO NX_CAP_BIT(0, 5)
  641. #define NX_CAP0_LSO NX_CAP_BIT(0, 6)
  642. #define NX_CAP0_JUMBO_CONTIGUOUS NX_CAP_BIT(0, 7)
  643. #define NX_CAP0_LRO_CONTIGUOUS NX_CAP_BIT(0, 8)
  644. #define NX_CAP0_HW_LRO NX_CAP_BIT(0, 10)
  645. #define NX_CAP0_HW_LRO_MSS NX_CAP_BIT(0, 21)
  646. /*
  647. * Context state
  648. */
  649. #define NX_HOST_CTX_STATE_FREED 0
  650. #define NX_HOST_CTX_STATE_ALLOCATED 1
  651. #define NX_HOST_CTX_STATE_ACTIVE 2
  652. #define NX_HOST_CTX_STATE_DISABLED 3
  653. #define NX_HOST_CTX_STATE_QUIESCED 4
  654. #define NX_HOST_CTX_STATE_MAX 5
  655. /*
  656. * Rx context
  657. */
  658. typedef struct {
  659. __le64 host_phys_addr; /* Ring base addr */
  660. __le32 ring_size; /* Ring entries */
  661. __le16 msi_index;
  662. __le16 rsvd; /* Padding */
  663. } nx_hostrq_sds_ring_t;
  664. typedef struct {
  665. __le64 host_phys_addr; /* Ring base addr */
  666. __le64 buff_size; /* Packet buffer size */
  667. __le32 ring_size; /* Ring entries */
  668. __le32 ring_kind; /* Class of ring */
  669. } nx_hostrq_rds_ring_t;
  670. typedef struct {
  671. __le64 host_rsp_dma_addr; /* Response dma'd here */
  672. __le32 capabilities[4]; /* Flag bit vector */
  673. __le32 host_int_crb_mode; /* Interrupt crb usage */
  674. __le32 host_rds_crb_mode; /* RDS crb usage */
  675. /* These ring offsets are relative to data[0] below */
  676. __le32 rds_ring_offset; /* Offset to RDS config */
  677. __le32 sds_ring_offset; /* Offset to SDS config */
  678. __le16 num_rds_rings; /* Count of RDS rings */
  679. __le16 num_sds_rings; /* Count of SDS rings */
  680. __le16 rsvd1; /* Padding */
  681. __le16 rsvd2; /* Padding */
  682. u8 reserved[128]; /* reserve space for future expansion*/
  683. /* MUST BE 64-bit aligned.
  684. The following is packed:
  685. - N hostrq_rds_rings
  686. - N hostrq_sds_rings */
  687. char data[0];
  688. } nx_hostrq_rx_ctx_t;
  689. typedef struct {
  690. __le32 host_producer_crb; /* Crb to use */
  691. __le32 rsvd1; /* Padding */
  692. } nx_cardrsp_rds_ring_t;
  693. typedef struct {
  694. __le32 host_consumer_crb; /* Crb to use */
  695. __le32 interrupt_crb; /* Crb to use */
  696. } nx_cardrsp_sds_ring_t;
  697. typedef struct {
  698. /* These ring offsets are relative to data[0] below */
  699. __le32 rds_ring_offset; /* Offset to RDS config */
  700. __le32 sds_ring_offset; /* Offset to SDS config */
  701. __le32 host_ctx_state; /* Starting State */
  702. __le32 num_fn_per_port; /* How many PCI fn share the port */
  703. __le16 num_rds_rings; /* Count of RDS rings */
  704. __le16 num_sds_rings; /* Count of SDS rings */
  705. __le16 context_id; /* Handle for context */
  706. u8 phys_port; /* Physical id of port */
  707. u8 virt_port; /* Virtual/Logical id of port */
  708. u8 reserved[128]; /* save space for future expansion */
  709. /* MUST BE 64-bit aligned.
  710. The following is packed:
  711. - N cardrsp_rds_rings
  712. - N cardrs_sds_rings */
  713. char data[0];
  714. } nx_cardrsp_rx_ctx_t;
  715. #define SIZEOF_HOSTRQ_RX(HOSTRQ_RX, rds_rings, sds_rings) \
  716. (sizeof(HOSTRQ_RX) + \
  717. (rds_rings)*(sizeof(nx_hostrq_rds_ring_t)) + \
  718. (sds_rings)*(sizeof(nx_hostrq_sds_ring_t)))
  719. #define SIZEOF_CARDRSP_RX(CARDRSP_RX, rds_rings, sds_rings) \
  720. (sizeof(CARDRSP_RX) + \
  721. (rds_rings)*(sizeof(nx_cardrsp_rds_ring_t)) + \
  722. (sds_rings)*(sizeof(nx_cardrsp_sds_ring_t)))
  723. /*
  724. * Tx context
  725. */
  726. typedef struct {
  727. __le64 host_phys_addr; /* Ring base addr */
  728. __le32 ring_size; /* Ring entries */
  729. __le32 rsvd; /* Padding */
  730. } nx_hostrq_cds_ring_t;
  731. typedef struct {
  732. __le64 host_rsp_dma_addr; /* Response dma'd here */
  733. __le64 cmd_cons_dma_addr; /* */
  734. __le64 dummy_dma_addr; /* */
  735. __le32 capabilities[4]; /* Flag bit vector */
  736. __le32 host_int_crb_mode; /* Interrupt crb usage */
  737. __le32 rsvd1; /* Padding */
  738. __le16 rsvd2; /* Padding */
  739. __le16 interrupt_ctl;
  740. __le16 msi_index;
  741. __le16 rsvd3; /* Padding */
  742. nx_hostrq_cds_ring_t cds_ring; /* Desc of cds ring */
  743. u8 reserved[128]; /* future expansion */
  744. } nx_hostrq_tx_ctx_t;
  745. typedef struct {
  746. __le32 host_producer_crb; /* Crb to use */
  747. __le32 interrupt_crb; /* Crb to use */
  748. } nx_cardrsp_cds_ring_t;
  749. typedef struct {
  750. __le32 host_ctx_state; /* Starting state */
  751. __le16 context_id; /* Handle for context */
  752. u8 phys_port; /* Physical id of port */
  753. u8 virt_port; /* Virtual/Logical id of port */
  754. nx_cardrsp_cds_ring_t cds_ring; /* Card cds settings */
  755. u8 reserved[128]; /* future expansion */
  756. } nx_cardrsp_tx_ctx_t;
  757. #define SIZEOF_HOSTRQ_TX(HOSTRQ_TX) (sizeof(HOSTRQ_TX))
  758. #define SIZEOF_CARDRSP_TX(CARDRSP_TX) (sizeof(CARDRSP_TX))
  759. /* CRB */
  760. #define NX_HOST_RDS_CRB_MODE_UNIQUE 0
  761. #define NX_HOST_RDS_CRB_MODE_SHARED 1
  762. #define NX_HOST_RDS_CRB_MODE_CUSTOM 2
  763. #define NX_HOST_RDS_CRB_MODE_MAX 3
  764. #define NX_HOST_INT_CRB_MODE_UNIQUE 0
  765. #define NX_HOST_INT_CRB_MODE_SHARED 1
  766. #define NX_HOST_INT_CRB_MODE_NORX 2
  767. #define NX_HOST_INT_CRB_MODE_NOTX 3
  768. #define NX_HOST_INT_CRB_MODE_NORXTX 4
  769. /* MAC */
  770. #define MC_COUNT_P2 16
  771. #define MC_COUNT_P3 38
  772. #define NETXEN_MAC_NOOP 0
  773. #define NETXEN_MAC_ADD 1
  774. #define NETXEN_MAC_DEL 2
  775. typedef struct nx_mac_list_s {
  776. struct list_head list;
  777. uint8_t mac_addr[ETH_ALEN+2];
  778. } nx_mac_list_t;
  779. struct nx_ip_list {
  780. struct list_head list;
  781. __be32 ip_addr;
  782. bool master;
  783. };
  784. /*
  785. * Interrupt coalescing defaults. The defaults are for 1500 MTU. It is
  786. * adjusted based on configured MTU.
  787. */
  788. #define NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US 3
  789. #define NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS 256
  790. #define NETXEN_DEFAULT_INTR_COALESCE_TX_PACKETS 64
  791. #define NETXEN_DEFAULT_INTR_COALESCE_TX_TIME_US 4
  792. #define NETXEN_NIC_INTR_DEFAULT 0x04
  793. typedef union {
  794. struct {
  795. uint16_t rx_packets;
  796. uint16_t rx_time_us;
  797. uint16_t tx_packets;
  798. uint16_t tx_time_us;
  799. } data;
  800. uint64_t word;
  801. } nx_nic_intr_coalesce_data_t;
  802. typedef struct {
  803. uint16_t stats_time_us;
  804. uint16_t rate_sample_time;
  805. uint16_t flags;
  806. uint16_t rsvd_1;
  807. uint32_t low_threshold;
  808. uint32_t high_threshold;
  809. nx_nic_intr_coalesce_data_t normal;
  810. nx_nic_intr_coalesce_data_t low;
  811. nx_nic_intr_coalesce_data_t high;
  812. nx_nic_intr_coalesce_data_t irq;
  813. } nx_nic_intr_coalesce_t;
  814. #define NX_HOST_REQUEST 0x13
  815. #define NX_NIC_REQUEST 0x14
  816. #define NX_MAC_EVENT 0x1
  817. #define NX_IP_UP 2
  818. #define NX_IP_DOWN 3
  819. /*
  820. * Driver --> Firmware
  821. */
  822. #define NX_NIC_H2C_OPCODE_START 0
  823. #define NX_NIC_H2C_OPCODE_CONFIG_RSS 1
  824. #define NX_NIC_H2C_OPCODE_CONFIG_RSS_TBL 2
  825. #define NX_NIC_H2C_OPCODE_CONFIG_INTR_COALESCE 3
  826. #define NX_NIC_H2C_OPCODE_CONFIG_LED 4
  827. #define NX_NIC_H2C_OPCODE_CONFIG_PROMISCUOUS 5
  828. #define NX_NIC_H2C_OPCODE_CONFIG_L2_MAC 6
  829. #define NX_NIC_H2C_OPCODE_LRO_REQUEST 7
  830. #define NX_NIC_H2C_OPCODE_GET_SNMP_STATS 8
  831. #define NX_NIC_H2C_OPCODE_PROXY_START_REQUEST 9
  832. #define NX_NIC_H2C_OPCODE_PROXY_STOP_REQUEST 10
  833. #define NX_NIC_H2C_OPCODE_PROXY_SET_MTU 11
  834. #define NX_NIC_H2C_OPCODE_PROXY_SET_VPORT_MISS_MODE 12
  835. #define NX_NIC_H2C_OPCODE_GET_FINGER_PRINT_REQUEST 13
  836. #define NX_NIC_H2C_OPCODE_INSTALL_LICENSE_REQUEST 14
  837. #define NX_NIC_H2C_OPCODE_GET_LICENSE_CAPABILITY_REQUEST 15
  838. #define NX_NIC_H2C_OPCODE_GET_NET_STATS 16
  839. #define NX_NIC_H2C_OPCODE_PROXY_UPDATE_P2V 17
  840. #define NX_NIC_H2C_OPCODE_CONFIG_IPADDR 18
  841. #define NX_NIC_H2C_OPCODE_CONFIG_LOOPBACK 19
  842. #define NX_NIC_H2C_OPCODE_PROXY_STOP_DONE 20
  843. #define NX_NIC_H2C_OPCODE_GET_LINKEVENT 21
  844. #define NX_NIC_C2C_OPCODE 22
  845. #define NX_NIC_H2C_OPCODE_CONFIG_BRIDGING 23
  846. #define NX_NIC_H2C_OPCODE_CONFIG_HW_LRO 24
  847. #define NX_NIC_H2C_OPCODE_LAST 25
  848. /*
  849. * Firmware --> Driver
  850. */
  851. #define NX_NIC_C2H_OPCODE_START 128
  852. #define NX_NIC_C2H_OPCODE_CONFIG_RSS_RESPONSE 129
  853. #define NX_NIC_C2H_OPCODE_CONFIG_RSS_TBL_RESPONSE 130
  854. #define NX_NIC_C2H_OPCODE_CONFIG_MAC_RESPONSE 131
  855. #define NX_NIC_C2H_OPCODE_CONFIG_PROMISCUOUS_RESPONSE 132
  856. #define NX_NIC_C2H_OPCODE_CONFIG_L2_MAC_RESPONSE 133
  857. #define NX_NIC_C2H_OPCODE_LRO_DELETE_RESPONSE 134
  858. #define NX_NIC_C2H_OPCODE_LRO_ADD_FAILURE_RESPONSE 135
  859. #define NX_NIC_C2H_OPCODE_GET_SNMP_STATS 136
  860. #define NX_NIC_C2H_OPCODE_GET_FINGER_PRINT_REPLY 137
  861. #define NX_NIC_C2H_OPCODE_INSTALL_LICENSE_REPLY 138
  862. #define NX_NIC_C2H_OPCODE_GET_LICENSE_CAPABILITIES_REPLY 139
  863. #define NX_NIC_C2H_OPCODE_GET_NET_STATS_RESPONSE 140
  864. #define NX_NIC_C2H_OPCODE_GET_LINKEVENT_RESPONSE 141
  865. #define NX_NIC_C2H_OPCODE_LAST 142
  866. #define VPORT_MISS_MODE_DROP 0 /* drop all unmatched */
  867. #define VPORT_MISS_MODE_ACCEPT_ALL 1 /* accept all packets */
  868. #define VPORT_MISS_MODE_ACCEPT_MULTI 2 /* accept unmatched multicast */
  869. #define NX_NIC_LRO_REQUEST_FIRST 0
  870. #define NX_NIC_LRO_REQUEST_ADD_FLOW 1
  871. #define NX_NIC_LRO_REQUEST_DELETE_FLOW 2
  872. #define NX_NIC_LRO_REQUEST_TIMER 3
  873. #define NX_NIC_LRO_REQUEST_CLEANUP 4
  874. #define NX_NIC_LRO_REQUEST_ADD_FLOW_SCHEDULED 5
  875. #define NX_TOE_LRO_REQUEST_ADD_FLOW 6
  876. #define NX_TOE_LRO_REQUEST_ADD_FLOW_RESPONSE 7
  877. #define NX_TOE_LRO_REQUEST_DELETE_FLOW 8
  878. #define NX_TOE_LRO_REQUEST_DELETE_FLOW_RESPONSE 9
  879. #define NX_TOE_LRO_REQUEST_TIMER 10
  880. #define NX_NIC_LRO_REQUEST_LAST 11
  881. #define NX_FW_CAPABILITY_LINK_NOTIFICATION (1 << 5)
  882. #define NX_FW_CAPABILITY_SWITCHING (1 << 6)
  883. #define NX_FW_CAPABILITY_PEXQ (1 << 7)
  884. #define NX_FW_CAPABILITY_BDG (1 << 8)
  885. #define NX_FW_CAPABILITY_FVLANTX (1 << 9)
  886. #define NX_FW_CAPABILITY_HW_LRO (1 << 10)
  887. #define NX_FW_CAPABILITY_GBE_LINK_CFG (1 << 11)
  888. #define NX_FW_CAPABILITY_MORE_CAPS (1 << 31)
  889. #define NX_FW_CAPABILITY_2_LRO_MAX_TCP_SEG (1 << 2)
  890. /* module types */
  891. #define LINKEVENT_MODULE_NOT_PRESENT 1
  892. #define LINKEVENT_MODULE_OPTICAL_UNKNOWN 2
  893. #define LINKEVENT_MODULE_OPTICAL_SRLR 3
  894. #define LINKEVENT_MODULE_OPTICAL_LRM 4
  895. #define LINKEVENT_MODULE_OPTICAL_SFP_1G 5
  896. #define LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLE 6
  897. #define LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLELEN 7
  898. #define LINKEVENT_MODULE_TWINAX 8
  899. #define LINKSPEED_10GBPS 10000
  900. #define LINKSPEED_1GBPS 1000
  901. #define LINKSPEED_100MBPS 100
  902. #define LINKSPEED_10MBPS 10
  903. #define LINKSPEED_ENCODED_10MBPS 0
  904. #define LINKSPEED_ENCODED_100MBPS 1
  905. #define LINKSPEED_ENCODED_1GBPS 2
  906. #define LINKEVENT_AUTONEG_DISABLED 0
  907. #define LINKEVENT_AUTONEG_ENABLED 1
  908. #define LINKEVENT_HALF_DUPLEX 0
  909. #define LINKEVENT_FULL_DUPLEX 1
  910. #define LINKEVENT_LINKSPEED_MBPS 0
  911. #define LINKEVENT_LINKSPEED_ENCODED 1
  912. #define AUTO_FW_RESET_ENABLED 0xEF10AF12
  913. #define AUTO_FW_RESET_DISABLED 0xDCBAAF12
  914. /* firmware response header:
  915. * 63:58 - message type
  916. * 57:56 - owner
  917. * 55:53 - desc count
  918. * 52:48 - reserved
  919. * 47:40 - completion id
  920. * 39:32 - opcode
  921. * 31:16 - error code
  922. * 15:00 - reserved
  923. */
  924. #define netxen_get_nic_msgtype(msg_hdr) \
  925. ((msg_hdr >> 58) & 0x3F)
  926. #define netxen_get_nic_msg_compid(msg_hdr) \
  927. ((msg_hdr >> 40) & 0xFF)
  928. #define netxen_get_nic_msg_opcode(msg_hdr) \
  929. ((msg_hdr >> 32) & 0xFF)
  930. #define netxen_get_nic_msg_errcode(msg_hdr) \
  931. ((msg_hdr >> 16) & 0xFFFF)
  932. typedef struct {
  933. union {
  934. struct {
  935. u64 hdr;
  936. u64 body[7];
  937. };
  938. u64 words[8];
  939. };
  940. } nx_fw_msg_t;
  941. typedef struct {
  942. __le64 qhdr;
  943. __le64 req_hdr;
  944. __le64 words[6];
  945. } nx_nic_req_t;
  946. typedef struct {
  947. u8 op;
  948. u8 tag;
  949. u8 mac_addr[6];
  950. } nx_mac_req_t;
  951. #define MAX_PENDING_DESC_BLOCK_SIZE 64
  952. #define NETXEN_NIC_MSI_ENABLED 0x02
  953. #define NETXEN_NIC_MSIX_ENABLED 0x04
  954. #define NETXEN_NIC_LRO_ENABLED 0x08
  955. #define NETXEN_NIC_LRO_DISABLED 0x00
  956. #define NETXEN_NIC_BRIDGE_ENABLED 0X10
  957. #define NETXEN_NIC_DIAG_ENABLED 0x20
  958. #define NETXEN_FW_RESET_OWNER 0x40
  959. #define NETXEN_FW_MSS_CAP 0x80
  960. #define NETXEN_IS_MSI_FAMILY(adapter) \
  961. ((adapter)->flags & (NETXEN_NIC_MSI_ENABLED | NETXEN_NIC_MSIX_ENABLED))
  962. #define MSIX_ENTRIES_PER_ADAPTER NUM_STS_DESC_RINGS
  963. #define NETXEN_MSIX_TBL_SPACE 8192
  964. #define NETXEN_PCI_REG_MSIX_TBL 0x44
  965. #define NETXEN_DB_MAPSIZE_BYTES 0x1000
  966. #define NETXEN_ADAPTER_UP_MAGIC 777
  967. #define NETXEN_NIC_PEG_TUNE 0
  968. #define __NX_FW_ATTACHED 0
  969. #define __NX_DEV_UP 1
  970. #define __NX_RESETTING 2
  971. /* Mini Coredump FW supported version */
  972. #define NX_MD_SUPPORT_MAJOR 4
  973. #define NX_MD_SUPPORT_MINOR 0
  974. #define NX_MD_SUPPORT_SUBVERSION 579
  975. #define LSW(x) ((uint16_t)(x))
  976. #define LSD(x) ((uint32_t)((uint64_t)(x)))
  977. #define MSD(x) ((uint32_t)((((uint64_t)(x)) >> 16) >> 16))
  978. /* Mini Coredump mask level */
  979. #define NX_DUMP_MASK_MIN 0x03
  980. #define NX_DUMP_MASK_DEF 0x1f
  981. #define NX_DUMP_MASK_MAX 0xff
  982. /* Mini Coredump CDRP commands */
  983. #define NX_CDRP_CMD_TEMP_SIZE 0x0000002f
  984. #define NX_CDRP_CMD_GET_TEMP_HDR 0x00000030
  985. #define NX_DUMP_STATE_ARRAY_LEN 16
  986. #define NX_DUMP_CAP_SIZE_ARRAY_LEN 8
  987. /* Mini Coredump sysfs entries flags*/
  988. #define NX_FORCE_FW_DUMP_KEY 0xdeadfeed
  989. #define NX_ENABLE_FW_DUMP 0xaddfeed
  990. #define NX_DISABLE_FW_DUMP 0xbadfeed
  991. #define NX_FORCE_FW_RESET 0xdeaddead
  992. /* Fw dump levels */
  993. static const u32 FW_DUMP_LEVELS[] = { 0x3, 0x7, 0xf, 0x1f, 0x3f, 0x7f, 0xff };
  994. /* Flash read/write address */
  995. #define NX_FW_DUMP_REG1 0x00130060
  996. #define NX_FW_DUMP_REG2 0x001e0000
  997. #define NX_FLASH_SEM2_LK 0x0013C010
  998. #define NX_FLASH_SEM2_ULK 0x0013C014
  999. #define NX_FLASH_LOCK_ID 0x001B2100
  1000. #define FLASH_ROM_WINDOW 0x42110030
  1001. #define FLASH_ROM_DATA 0x42150000
  1002. /* Mini Coredump register read/write routine */
  1003. #define NX_RD_DUMP_REG(addr, bar0, data) do { \
  1004. writel((addr & 0xFFFF0000), (void __iomem *) (bar0 + \
  1005. NX_FW_DUMP_REG1)); \
  1006. readl((void __iomem *) (bar0 + NX_FW_DUMP_REG1)); \
  1007. *data = readl((void __iomem *) (bar0 + NX_FW_DUMP_REG2 + \
  1008. LSW(addr))); \
  1009. } while (0)
  1010. #define NX_WR_DUMP_REG(addr, bar0, data) do { \
  1011. writel((addr & 0xFFFF0000), (void __iomem *) (bar0 + \
  1012. NX_FW_DUMP_REG1)); \
  1013. readl((void __iomem *) (bar0 + NX_FW_DUMP_REG1)); \
  1014. writel(data, (void __iomem *) (bar0 + NX_FW_DUMP_REG2 + LSW(addr)));\
  1015. readl((void __iomem *) (bar0 + NX_FW_DUMP_REG2 + LSW(addr))); \
  1016. } while (0)
  1017. /*
  1018. Entry Type Defines
  1019. */
  1020. #define RDNOP 0
  1021. #define RDCRB 1
  1022. #define RDMUX 2
  1023. #define QUEUE 3
  1024. #define BOARD 4
  1025. #define RDSRE 5
  1026. #define RDOCM 6
  1027. #define PREGS 7
  1028. #define L1DTG 8
  1029. #define L1ITG 9
  1030. #define CACHE 10
  1031. #define L1DAT 11
  1032. #define L1INS 12
  1033. #define RDSTK 13
  1034. #define RDCON 14
  1035. #define L2DTG 21
  1036. #define L2ITG 22
  1037. #define L2DAT 23
  1038. #define L2INS 24
  1039. #define RDOC3 25
  1040. #define MEMBK 32
  1041. #define RDROM 71
  1042. #define RDMEM 72
  1043. #define RDMN 73
  1044. #define INFOR 81
  1045. #define CNTRL 98
  1046. #define TLHDR 99
  1047. #define RDEND 255
  1048. #define PRIMQ 103
  1049. #define SQG2Q 104
  1050. #define SQG3Q 105
  1051. /*
  1052. * Opcodes for Control Entries.
  1053. * These Flags are bit fields.
  1054. */
  1055. #define NX_DUMP_WCRB 0x01
  1056. #define NX_DUMP_RWCRB 0x02
  1057. #define NX_DUMP_ANDCRB 0x04
  1058. #define NX_DUMP_ORCRB 0x08
  1059. #define NX_DUMP_POLLCRB 0x10
  1060. #define NX_DUMP_RD_SAVE 0x20
  1061. #define NX_DUMP_WRT_SAVED 0x40
  1062. #define NX_DUMP_MOD_SAVE_ST 0x80
  1063. /* Driver Flags */
  1064. #define NX_DUMP_SKIP 0x80 /* driver skipped this entry */
  1065. #define NX_DUMP_SIZE_ERR 0x40 /*entry size vs capture size mismatch*/
  1066. #define NX_PCI_READ_32(ADDR) readl((ADDR))
  1067. #define NX_PCI_WRITE_32(DATA, ADDR) writel(DATA, (ADDR))
  1068. struct netxen_minidump {
  1069. u32 pos; /* position in the dump buffer */
  1070. u8 fw_supports_md; /* FW supports Mini cordump */
  1071. u8 has_valid_dump; /* indicates valid dump */
  1072. u8 md_capture_mask; /* driver capture mask */
  1073. u8 md_enabled; /* Turn Mini Coredump on/off */
  1074. u32 md_dump_size; /* Total FW Mini Coredump size */
  1075. u32 md_capture_size; /* FW dump capture size */
  1076. u32 md_template_size; /* FW template size */
  1077. u32 md_template_ver; /* FW template version */
  1078. u64 md_timestamp; /* FW Mini dump timestamp */
  1079. void *md_template; /* FW template will be stored */
  1080. void *md_capture_buff; /* FW dump will be stored */
  1081. };
  1082. struct netxen_minidump_template_hdr {
  1083. u32 entry_type;
  1084. u32 first_entry_offset;
  1085. u32 size_of_template;
  1086. u32 capture_mask;
  1087. u32 num_of_entries;
  1088. u32 version;
  1089. u32 driver_timestamp;
  1090. u32 checksum;
  1091. u32 driver_capture_mask;
  1092. u32 driver_info_word2;
  1093. u32 driver_info_word3;
  1094. u32 driver_info_word4;
  1095. u32 saved_state_array[NX_DUMP_STATE_ARRAY_LEN];
  1096. u32 capture_size_array[NX_DUMP_CAP_SIZE_ARRAY_LEN];
  1097. u32 rsvd[0];
  1098. };
  1099. /* Common Entry Header: Common to All Entry Types */
  1100. /*
  1101. * Driver Code is for driver to write some info about the entry.
  1102. * Currently not used.
  1103. */
  1104. struct netxen_common_entry_hdr {
  1105. u32 entry_type;
  1106. u32 entry_size;
  1107. u32 entry_capture_size;
  1108. union {
  1109. struct {
  1110. u8 entry_capture_mask;
  1111. u8 entry_code;
  1112. u8 driver_code;
  1113. u8 driver_flags;
  1114. };
  1115. u32 entry_ctrl_word;
  1116. };
  1117. };
  1118. /* Generic Entry Including Header */
  1119. struct netxen_minidump_entry {
  1120. struct netxen_common_entry_hdr hdr;
  1121. u32 entry_data00;
  1122. u32 entry_data01;
  1123. u32 entry_data02;
  1124. u32 entry_data03;
  1125. u32 entry_data04;
  1126. u32 entry_data05;
  1127. u32 entry_data06;
  1128. u32 entry_data07;
  1129. };
  1130. /* Read ROM Header */
  1131. struct netxen_minidump_entry_rdrom {
  1132. struct netxen_common_entry_hdr h;
  1133. union {
  1134. struct {
  1135. u32 select_addr_reg;
  1136. };
  1137. u32 rsvd_0;
  1138. };
  1139. union {
  1140. struct {
  1141. u8 addr_stride;
  1142. u8 addr_cnt;
  1143. u16 data_size;
  1144. };
  1145. u32 rsvd_1;
  1146. };
  1147. union {
  1148. struct {
  1149. u32 op_count;
  1150. };
  1151. u32 rsvd_2;
  1152. };
  1153. union {
  1154. struct {
  1155. u32 read_addr_reg;
  1156. };
  1157. u32 rsvd_3;
  1158. };
  1159. union {
  1160. struct {
  1161. u32 write_mask;
  1162. };
  1163. u32 rsvd_4;
  1164. };
  1165. union {
  1166. struct {
  1167. u32 read_mask;
  1168. };
  1169. u32 rsvd_5;
  1170. };
  1171. u32 read_addr;
  1172. u32 read_data_size;
  1173. };
  1174. /* Read CRB and Control Entry Header */
  1175. struct netxen_minidump_entry_crb {
  1176. struct netxen_common_entry_hdr h;
  1177. u32 addr;
  1178. union {
  1179. struct {
  1180. u8 addr_stride;
  1181. u8 state_index_a;
  1182. u16 poll_timeout;
  1183. };
  1184. u32 addr_cntrl;
  1185. };
  1186. u32 data_size;
  1187. u32 op_count;
  1188. union {
  1189. struct {
  1190. u8 opcode;
  1191. u8 state_index_v;
  1192. u8 shl;
  1193. u8 shr;
  1194. };
  1195. u32 control_value;
  1196. };
  1197. u32 value_1;
  1198. u32 value_2;
  1199. u32 value_3;
  1200. };
  1201. /* Read Memory and MN Header */
  1202. struct netxen_minidump_entry_rdmem {
  1203. struct netxen_common_entry_hdr h;
  1204. union {
  1205. struct {
  1206. u32 select_addr_reg;
  1207. };
  1208. u32 rsvd_0;
  1209. };
  1210. union {
  1211. struct {
  1212. u8 addr_stride;
  1213. u8 addr_cnt;
  1214. u16 data_size;
  1215. };
  1216. u32 rsvd_1;
  1217. };
  1218. union {
  1219. struct {
  1220. u32 op_count;
  1221. };
  1222. u32 rsvd_2;
  1223. };
  1224. union {
  1225. struct {
  1226. u32 read_addr_reg;
  1227. };
  1228. u32 rsvd_3;
  1229. };
  1230. union {
  1231. struct {
  1232. u32 cntrl_addr_reg;
  1233. };
  1234. u32 rsvd_4;
  1235. };
  1236. union {
  1237. struct {
  1238. u8 wr_byte0;
  1239. u8 wr_byte1;
  1240. u8 poll_mask;
  1241. u8 poll_cnt;
  1242. };
  1243. u32 rsvd_5;
  1244. };
  1245. u32 read_addr;
  1246. u32 read_data_size;
  1247. };
  1248. /* Read Cache L1 and L2 Header */
  1249. struct netxen_minidump_entry_cache {
  1250. struct netxen_common_entry_hdr h;
  1251. u32 tag_reg_addr;
  1252. union {
  1253. struct {
  1254. u16 tag_value_stride;
  1255. u16 init_tag_value;
  1256. };
  1257. u32 select_addr_cntrl;
  1258. };
  1259. u32 data_size;
  1260. u32 op_count;
  1261. u32 control_addr;
  1262. union {
  1263. struct {
  1264. u16 write_value;
  1265. u8 poll_mask;
  1266. u8 poll_wait;
  1267. };
  1268. u32 control_value;
  1269. };
  1270. u32 read_addr;
  1271. union {
  1272. struct {
  1273. u8 read_addr_stride;
  1274. u8 read_addr_cnt;
  1275. u16 rsvd_1;
  1276. };
  1277. u32 read_addr_cntrl;
  1278. };
  1279. };
  1280. /* Read OCM Header */
  1281. struct netxen_minidump_entry_rdocm {
  1282. struct netxen_common_entry_hdr h;
  1283. u32 rsvd_0;
  1284. union {
  1285. struct {
  1286. u32 rsvd_1;
  1287. };
  1288. u32 select_addr_cntrl;
  1289. };
  1290. u32 data_size;
  1291. u32 op_count;
  1292. u32 rsvd_2;
  1293. u32 rsvd_3;
  1294. u32 read_addr;
  1295. union {
  1296. struct {
  1297. u32 read_addr_stride;
  1298. };
  1299. u32 read_addr_cntrl;
  1300. };
  1301. };
  1302. /* Read MUX Header */
  1303. struct netxen_minidump_entry_mux {
  1304. struct netxen_common_entry_hdr h;
  1305. u32 select_addr;
  1306. union {
  1307. struct {
  1308. u32 rsvd_0;
  1309. };
  1310. u32 select_addr_cntrl;
  1311. };
  1312. u32 data_size;
  1313. u32 op_count;
  1314. u32 select_value;
  1315. u32 select_value_stride;
  1316. u32 read_addr;
  1317. u32 rsvd_1;
  1318. };
  1319. /* Read Queue Header */
  1320. struct netxen_minidump_entry_queue {
  1321. struct netxen_common_entry_hdr h;
  1322. u32 select_addr;
  1323. union {
  1324. struct {
  1325. u16 queue_id_stride;
  1326. u16 rsvd_0;
  1327. };
  1328. u32 select_addr_cntrl;
  1329. };
  1330. u32 data_size;
  1331. u32 op_count;
  1332. u32 rsvd_1;
  1333. u32 rsvd_2;
  1334. u32 read_addr;
  1335. union {
  1336. struct {
  1337. u8 read_addr_stride;
  1338. u8 read_addr_cnt;
  1339. u16 rsvd_3;
  1340. };
  1341. u32 read_addr_cntrl;
  1342. };
  1343. };
  1344. struct netxen_dummy_dma {
  1345. void *addr;
  1346. dma_addr_t phys_addr;
  1347. };
  1348. struct netxen_adapter {
  1349. struct netxen_hardware_context ahw;
  1350. struct net_device *netdev;
  1351. struct pci_dev *pdev;
  1352. struct list_head mac_list;
  1353. struct list_head ip_list;
  1354. spinlock_t tx_clean_lock;
  1355. u16 num_txd;
  1356. u16 num_rxd;
  1357. u16 num_jumbo_rxd;
  1358. u16 num_lro_rxd;
  1359. u8 max_rds_rings;
  1360. u8 max_sds_rings;
  1361. u8 driver_mismatch;
  1362. u8 msix_supported;
  1363. u8 __pad;
  1364. u8 pci_using_dac;
  1365. u8 portnum;
  1366. u8 physical_port;
  1367. u8 mc_enabled;
  1368. u8 max_mc_count;
  1369. u8 rss_supported;
  1370. u8 link_changed;
  1371. u8 fw_wait_cnt;
  1372. u8 fw_fail_cnt;
  1373. u8 tx_timeo_cnt;
  1374. u8 need_fw_reset;
  1375. u8 has_link_events;
  1376. u8 fw_type;
  1377. u16 tx_context_id;
  1378. u16 mtu;
  1379. u16 is_up;
  1380. u16 link_speed;
  1381. u16 link_duplex;
  1382. u16 link_autoneg;
  1383. u16 module_type;
  1384. u32 capabilities;
  1385. u32 flags;
  1386. u32 irq;
  1387. u32 temp;
  1388. u32 int_vec_bit;
  1389. u32 heartbit;
  1390. u8 mac_addr[ETH_ALEN];
  1391. struct netxen_adapter_stats stats;
  1392. struct netxen_recv_context recv_ctx;
  1393. struct nx_host_tx_ring *tx_ring;
  1394. int (*macaddr_set) (struct netxen_adapter *, u8 *);
  1395. int (*set_mtu) (struct netxen_adapter *, int);
  1396. int (*set_promisc) (struct netxen_adapter *, u32);
  1397. void (*set_multi) (struct net_device *);
  1398. int (*phy_read) (struct netxen_adapter *, u32 reg, u32 *);
  1399. int (*phy_write) (struct netxen_adapter *, u32 reg, u32 val);
  1400. int (*init_port) (struct netxen_adapter *, int);
  1401. int (*stop_port) (struct netxen_adapter *);
  1402. u32 (*crb_read)(struct netxen_adapter *, ulong);
  1403. int (*crb_write)(struct netxen_adapter *, ulong, u32);
  1404. int (*pci_mem_read)(struct netxen_adapter *, u64, u64 *);
  1405. int (*pci_mem_write)(struct netxen_adapter *, u64, u64);
  1406. int (*pci_set_window)(struct netxen_adapter *, u64, u32 *);
  1407. u32 (*io_read)(struct netxen_adapter *, void __iomem *);
  1408. void (*io_write)(struct netxen_adapter *, void __iomem *, u32);
  1409. void __iomem *tgt_mask_reg;
  1410. void __iomem *pci_int_reg;
  1411. void __iomem *tgt_status_reg;
  1412. void __iomem *crb_int_state_reg;
  1413. void __iomem *isr_int_vec;
  1414. struct msix_entry msix_entries[MSIX_ENTRIES_PER_ADAPTER];
  1415. struct netxen_dummy_dma dummy_dma;
  1416. struct delayed_work fw_work;
  1417. struct work_struct tx_timeout_task;
  1418. nx_nic_intr_coalesce_t coal;
  1419. unsigned long state;
  1420. __le32 file_prd_off; /*File fw product offset*/
  1421. u32 fw_version;
  1422. const struct firmware *fw;
  1423. struct netxen_minidump mdump; /* mdump ptr */
  1424. int fw_mdump_rdy; /* for mdump ready */
  1425. };
  1426. int nx_fw_cmd_query_phy(struct netxen_adapter *adapter, u32 reg, u32 *val);
  1427. int nx_fw_cmd_set_phy(struct netxen_adapter *adapter, u32 reg, u32 val);
  1428. #define NXRD32(adapter, off) \
  1429. (adapter->crb_read(adapter, off))
  1430. #define NXWR32(adapter, off, val) \
  1431. (adapter->crb_write(adapter, off, val))
  1432. #define NXRDIO(adapter, addr) \
  1433. (adapter->io_read(adapter, addr))
  1434. #define NXWRIO(adapter, addr, val) \
  1435. (adapter->io_write(adapter, addr, val))
  1436. int netxen_pcie_sem_lock(struct netxen_adapter *, int, u32);
  1437. void netxen_pcie_sem_unlock(struct netxen_adapter *, int);
  1438. #define netxen_rom_lock(a) \
  1439. netxen_pcie_sem_lock((a), 2, NETXEN_ROM_LOCK_ID)
  1440. #define netxen_rom_unlock(a) \
  1441. netxen_pcie_sem_unlock((a), 2)
  1442. #define netxen_phy_lock(a) \
  1443. netxen_pcie_sem_lock((a), 3, NETXEN_PHY_LOCK_ID)
  1444. #define netxen_phy_unlock(a) \
  1445. netxen_pcie_sem_unlock((a), 3)
  1446. #define netxen_api_lock(a) \
  1447. netxen_pcie_sem_lock((a), 5, 0)
  1448. #define netxen_api_unlock(a) \
  1449. netxen_pcie_sem_unlock((a), 5)
  1450. #define netxen_sw_lock(a) \
  1451. netxen_pcie_sem_lock((a), 6, 0)
  1452. #define netxen_sw_unlock(a) \
  1453. netxen_pcie_sem_unlock((a), 6)
  1454. #define crb_win_lock(a) \
  1455. netxen_pcie_sem_lock((a), 7, NETXEN_CRB_WIN_LOCK_ID)
  1456. #define crb_win_unlock(a) \
  1457. netxen_pcie_sem_unlock((a), 7)
  1458. int netxen_nic_get_board_info(struct netxen_adapter *adapter);
  1459. int netxen_nic_wol_supported(struct netxen_adapter *adapter);
  1460. /* Functions from netxen_nic_init.c */
  1461. int netxen_init_dummy_dma(struct netxen_adapter *adapter);
  1462. void netxen_free_dummy_dma(struct netxen_adapter *adapter);
  1463. int netxen_check_flash_fw_compatibility(struct netxen_adapter *adapter);
  1464. int netxen_phantom_init(struct netxen_adapter *adapter, int pegtune_val);
  1465. int netxen_load_firmware(struct netxen_adapter *adapter);
  1466. int netxen_need_fw_reset(struct netxen_adapter *adapter);
  1467. void netxen_request_firmware(struct netxen_adapter *adapter);
  1468. void netxen_release_firmware(struct netxen_adapter *adapter);
  1469. int netxen_pinit_from_rom(struct netxen_adapter *adapter);
  1470. int netxen_rom_fast_read(struct netxen_adapter *adapter, int addr, int *valp);
  1471. int netxen_rom_fast_read_words(struct netxen_adapter *adapter, int addr,
  1472. u8 *bytes, size_t size);
  1473. int netxen_rom_fast_write_words(struct netxen_adapter *adapter, int addr,
  1474. u8 *bytes, size_t size);
  1475. int netxen_flash_unlock(struct netxen_adapter *adapter);
  1476. int netxen_backup_crbinit(struct netxen_adapter *adapter);
  1477. int netxen_flash_erase_secondary(struct netxen_adapter *adapter);
  1478. int netxen_flash_erase_primary(struct netxen_adapter *adapter);
  1479. void netxen_halt_pegs(struct netxen_adapter *adapter);
  1480. int netxen_rom_se(struct netxen_adapter *adapter, int addr);
  1481. int netxen_alloc_sw_resources(struct netxen_adapter *adapter);
  1482. void netxen_free_sw_resources(struct netxen_adapter *adapter);
  1483. void netxen_setup_hwops(struct netxen_adapter *adapter);
  1484. void __iomem *netxen_get_ioaddr(struct netxen_adapter *, u32);
  1485. int netxen_alloc_hw_resources(struct netxen_adapter *adapter);
  1486. void netxen_free_hw_resources(struct netxen_adapter *adapter);
  1487. void netxen_release_rx_buffers(struct netxen_adapter *adapter);
  1488. void netxen_release_tx_buffers(struct netxen_adapter *adapter);
  1489. int netxen_init_firmware(struct netxen_adapter *adapter);
  1490. void netxen_nic_clear_stats(struct netxen_adapter *adapter);
  1491. void netxen_watchdog_task(struct work_struct *work);
  1492. void netxen_post_rx_buffers(struct netxen_adapter *adapter, u32 ringid,
  1493. struct nx_host_rds_ring *rds_ring);
  1494. int netxen_process_cmd_ring(struct netxen_adapter *adapter);
  1495. int netxen_process_rcv_ring(struct nx_host_sds_ring *sds_ring, int max);
  1496. void netxen_p3_free_mac_list(struct netxen_adapter *adapter);
  1497. int netxen_config_intr_coalesce(struct netxen_adapter *adapter);
  1498. int netxen_config_rss(struct netxen_adapter *adapter, int enable);
  1499. int netxen_config_ipaddr(struct netxen_adapter *adapter, __be32 ip, int cmd);
  1500. int netxen_linkevent_request(struct netxen_adapter *adapter, int enable);
  1501. void netxen_advert_link_change(struct netxen_adapter *adapter, int linkup);
  1502. void netxen_pci_camqm_read_2M(struct netxen_adapter *, u64, u64 *);
  1503. void netxen_pci_camqm_write_2M(struct netxen_adapter *, u64, u64);
  1504. int nx_fw_cmd_set_gbe_port(struct netxen_adapter *adapter,
  1505. u32 speed, u32 duplex, u32 autoneg);
  1506. int nx_fw_cmd_set_mtu(struct netxen_adapter *adapter, int mtu);
  1507. int netxen_nic_change_mtu(struct net_device *netdev, int new_mtu);
  1508. int netxen_config_hw_lro(struct netxen_adapter *adapter, int enable);
  1509. int netxen_config_bridged_mode(struct netxen_adapter *adapter, int enable);
  1510. int netxen_send_lro_cleanup(struct netxen_adapter *adapter);
  1511. int netxen_setup_minidump(struct netxen_adapter *adapter);
  1512. void netxen_dump_fw(struct netxen_adapter *adapter);
  1513. void netxen_nic_update_cmd_producer(struct netxen_adapter *adapter,
  1514. struct nx_host_tx_ring *tx_ring);
  1515. /* Functions from netxen_nic_main.c */
  1516. int netxen_nic_reset_context(struct netxen_adapter *);
  1517. int nx_dev_request_reset(struct netxen_adapter *adapter);
  1518. /*
  1519. * NetXen Board information
  1520. */
  1521. #define NETXEN_MAX_SHORT_NAME 32
  1522. struct netxen_brdinfo {
  1523. int brdtype; /* type of board */
  1524. long ports; /* max no of physical ports */
  1525. char short_name[NETXEN_MAX_SHORT_NAME];
  1526. };
  1527. struct netxen_dimm_cfg {
  1528. u8 presence;
  1529. u8 mem_type;
  1530. u8 dimm_type;
  1531. u32 size;
  1532. };
  1533. static const struct netxen_brdinfo netxen_boards[] = {
  1534. {NETXEN_BRDTYPE_P2_SB31_10G_CX4, 1, "XGb CX4"},
  1535. {NETXEN_BRDTYPE_P2_SB31_10G_HMEZ, 1, "XGb HMEZ"},
  1536. {NETXEN_BRDTYPE_P2_SB31_10G_IMEZ, 2, "XGb IMEZ"},
  1537. {NETXEN_BRDTYPE_P2_SB31_10G, 1, "XGb XFP"},
  1538. {NETXEN_BRDTYPE_P2_SB35_4G, 4, "Quad Gb"},
  1539. {NETXEN_BRDTYPE_P2_SB31_2G, 2, "Dual Gb"},
  1540. {NETXEN_BRDTYPE_P3_REF_QG, 4, "Reference Quad Gig "},
  1541. {NETXEN_BRDTYPE_P3_HMEZ, 2, "Dual XGb HMEZ"},
  1542. {NETXEN_BRDTYPE_P3_10G_CX4_LP, 2, "Dual XGb CX4 LP"},
  1543. {NETXEN_BRDTYPE_P3_4_GB, 4, "Quad Gig LP"},
  1544. {NETXEN_BRDTYPE_P3_IMEZ, 2, "Dual XGb IMEZ"},
  1545. {NETXEN_BRDTYPE_P3_10G_SFP_PLUS, 2, "Dual XGb SFP+ LP"},
  1546. {NETXEN_BRDTYPE_P3_10000_BASE_T, 1, "XGB 10G BaseT LP"},
  1547. {NETXEN_BRDTYPE_P3_XG_LOM, 2, "Dual XGb LOM"},
  1548. {NETXEN_BRDTYPE_P3_4_GB_MM, 4, "NX3031 Gigabit Ethernet"},
  1549. {NETXEN_BRDTYPE_P3_10G_SFP_CT, 2, "NX3031 10 Gigabit Ethernet"},
  1550. {NETXEN_BRDTYPE_P3_10G_SFP_QT, 2, "Quanta Dual XGb SFP+"},
  1551. {NETXEN_BRDTYPE_P3_10G_CX4, 2, "Reference Dual CX4 Option"},
  1552. {NETXEN_BRDTYPE_P3_10G_XFP, 1, "Reference Single XFP Option"}
  1553. };
  1554. #define NUM_SUPPORTED_BOARDS ARRAY_SIZE(netxen_boards)
  1555. static inline int netxen_nic_get_brd_name_by_type(u32 type, char *name)
  1556. {
  1557. int i, found = 0;
  1558. for (i = 0; i < NUM_SUPPORTED_BOARDS; ++i) {
  1559. if (netxen_boards[i].brdtype == type) {
  1560. strcpy(name, netxen_boards[i].short_name);
  1561. found = 1;
  1562. break;
  1563. }
  1564. }
  1565. if (!found) {
  1566. strcpy(name, "Unknown");
  1567. return -EINVAL;
  1568. }
  1569. return 0;
  1570. }
  1571. static inline u32 netxen_tx_avail(struct nx_host_tx_ring *tx_ring)
  1572. {
  1573. smp_mb();
  1574. return find_diff_among(tx_ring->producer,
  1575. tx_ring->sw_consumer, tx_ring->num_desc);
  1576. }
  1577. int netxen_get_flash_mac_addr(struct netxen_adapter *adapter, u64 *mac);
  1578. int netxen_p3_get_mac_addr(struct netxen_adapter *adapter, u64 *mac);
  1579. void netxen_change_ringparam(struct netxen_adapter *adapter);
  1580. int netxen_rom_fast_read(struct netxen_adapter *adapter, int addr, int *valp);
  1581. extern const struct ethtool_ops netxen_nic_ethtool_ops;
  1582. #endif /* __NETXEN_NIC_H_ */