netxen_nic.h 51 KB

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