qlcnic.h 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * QLogic qlcnic NIC Driver
  4. * Copyright (c) 2009-2013 QLogic Corporation
  5. */
  6. #ifndef _QLCNIC_H_
  7. #define _QLCNIC_H_
  8. #include <linux/module.h>
  9. #include <linux/kernel.h>
  10. #include <linux/types.h>
  11. #include <linux/ioport.h>
  12. #include <linux/pci.h>
  13. #include <linux/netdevice.h>
  14. #include <linux/etherdevice.h>
  15. #include <linux/ip.h>
  16. #include <linux/in.h>
  17. #include <linux/tcp.h>
  18. #include <linux/skbuff.h>
  19. #include <linux/firmware.h>
  20. #include <linux/ethtool.h>
  21. #include <linux/mii.h>
  22. #include <linux/timer.h>
  23. #include <linux/irq.h>
  24. #include <linux/vmalloc.h>
  25. #include <linux/io.h>
  26. #include <asm/byteorder.h>
  27. #include <linux/bitops.h>
  28. #include <linux/if_vlan.h>
  29. #include "qlcnic_hdr.h"
  30. #include "qlcnic_hw.h"
  31. #include "qlcnic_83xx_hw.h"
  32. #include "qlcnic_dcb.h"
  33. #define _QLCNIC_LINUX_MAJOR 5
  34. #define _QLCNIC_LINUX_MINOR 3
  35. #define _QLCNIC_LINUX_SUBVERSION 66
  36. #define QLCNIC_LINUX_VERSIONID "5.3.66"
  37. #define QLCNIC_DRV_IDC_VER 0x01
  38. #define QLCNIC_DRIVER_VERSION ((_QLCNIC_LINUX_MAJOR << 16) |\
  39. (_QLCNIC_LINUX_MINOR << 8) | (_QLCNIC_LINUX_SUBVERSION))
  40. #define QLCNIC_VERSION_CODE(a, b, c) (((a) << 24) + ((b) << 16) + (c))
  41. #define _major(v) (((v) >> 24) & 0xff)
  42. #define _minor(v) (((v) >> 16) & 0xff)
  43. #define _build(v) ((v) & 0xffff)
  44. /* version in image has weird encoding:
  45. * 7:0 - major
  46. * 15:8 - minor
  47. * 31:16 - build (little endian)
  48. */
  49. #define QLCNIC_DECODE_VERSION(v) \
  50. QLCNIC_VERSION_CODE(((v) & 0xff), (((v) >> 8) & 0xff), ((v) >> 16))
  51. #define QLCNIC_MIN_FW_VERSION QLCNIC_VERSION_CODE(4, 4, 2)
  52. #define QLCNIC_NUM_FLASH_SECTORS (64)
  53. #define QLCNIC_FLASH_SECTOR_SIZE (64 * 1024)
  54. #define QLCNIC_FLASH_TOTAL_SIZE (QLCNIC_NUM_FLASH_SECTORS \
  55. * QLCNIC_FLASH_SECTOR_SIZE)
  56. #define RCV_DESC_RINGSIZE(rds_ring) \
  57. (sizeof(struct rcv_desc) * (rds_ring)->num_desc)
  58. #define RCV_BUFF_RINGSIZE(rds_ring) \
  59. (sizeof(struct qlcnic_rx_buffer) * rds_ring->num_desc)
  60. #define STATUS_DESC_RINGSIZE(sds_ring) \
  61. (sizeof(struct status_desc) * (sds_ring)->num_desc)
  62. #define TX_BUFF_RINGSIZE(tx_ring) \
  63. (sizeof(struct qlcnic_cmd_buffer) * tx_ring->num_desc)
  64. #define TX_DESC_RINGSIZE(tx_ring) \
  65. (sizeof(struct cmd_desc_type0) * tx_ring->num_desc)
  66. #define QLCNIC_P3P_A0 0x50
  67. #define QLCNIC_P3P_C0 0x58
  68. #define QLCNIC_IS_REVISION_P3P(REVISION) (REVISION >= QLCNIC_P3P_A0)
  69. #define FIRST_PAGE_GROUP_START 0
  70. #define FIRST_PAGE_GROUP_END 0x100000
  71. #define P3P_MAX_MTU (9600)
  72. #define P3P_MIN_MTU (68)
  73. #define QLCNIC_MAX_ETHERHDR 32 /* This contains some padding */
  74. #define QLCNIC_P3P_RX_BUF_MAX_LEN (QLCNIC_MAX_ETHERHDR + ETH_DATA_LEN)
  75. #define QLCNIC_P3P_RX_JUMBO_BUF_MAX_LEN (QLCNIC_MAX_ETHERHDR + P3P_MAX_MTU)
  76. #define QLCNIC_CT_DEFAULT_RX_BUF_LEN 2048
  77. #define QLCNIC_LRO_BUFFER_EXTRA 2048
  78. /* Tx defines */
  79. #define QLCNIC_MAX_FRAGS_PER_TX 14
  80. #define MAX_TSO_HEADER_DESC 2
  81. #define MGMT_CMD_DESC_RESV 4
  82. #define TX_STOP_THRESH ((MAX_SKB_FRAGS >> 2) + MAX_TSO_HEADER_DESC \
  83. + MGMT_CMD_DESC_RESV)
  84. #define QLCNIC_MAX_TX_TIMEOUTS 2
  85. /* Driver will use 1 Tx ring in INT-x/MSI/SRIOV mode. */
  86. #define QLCNIC_SINGLE_RING 1
  87. #define QLCNIC_DEF_SDS_RINGS 4
  88. #define QLCNIC_DEF_TX_RINGS 4
  89. #define QLCNIC_MAX_VNIC_TX_RINGS 4
  90. #define QLCNIC_MAX_VNIC_SDS_RINGS 4
  91. #define QLCNIC_83XX_MINIMUM_VECTOR 3
  92. #define QLCNIC_82XX_MINIMUM_VECTOR 2
  93. enum qlcnic_queue_type {
  94. QLCNIC_TX_QUEUE = 1,
  95. QLCNIC_RX_QUEUE,
  96. };
  97. /* Operational mode for driver */
  98. #define QLCNIC_VNIC_MODE 0xFF
  99. #define QLCNIC_DEFAULT_MODE 0x0
  100. /* Virtual NIC function count */
  101. #define QLC_DEFAULT_VNIC_COUNT 8
  102. #define QLC_84XX_VNIC_COUNT 16
  103. /*
  104. * Following are the states of the Phantom. Phantom will set them and
  105. * Host will read to check if the fields are correct.
  106. */
  107. #define PHAN_INITIALIZE_FAILED 0xffff
  108. #define PHAN_INITIALIZE_COMPLETE 0xff01
  109. /* Host writes the following to notify that it has done the init-handshake */
  110. #define PHAN_INITIALIZE_ACK 0xf00f
  111. #define PHAN_PEG_RCV_INITIALIZED 0xff01
  112. #define NUM_RCV_DESC_RINGS 3
  113. #define RCV_RING_NORMAL 0
  114. #define RCV_RING_JUMBO 1
  115. #define MIN_CMD_DESCRIPTORS 64
  116. #define MIN_RCV_DESCRIPTORS 64
  117. #define MIN_JUMBO_DESCRIPTORS 32
  118. #define MAX_CMD_DESCRIPTORS 1024
  119. #define MAX_RCV_DESCRIPTORS_1G 4096
  120. #define MAX_RCV_DESCRIPTORS_10G 8192
  121. #define MAX_RCV_DESCRIPTORS_VF 2048
  122. #define MAX_JUMBO_RCV_DESCRIPTORS_1G 512
  123. #define MAX_JUMBO_RCV_DESCRIPTORS_10G 1024
  124. #define DEFAULT_RCV_DESCRIPTORS_1G 2048
  125. #define DEFAULT_RCV_DESCRIPTORS_10G 4096
  126. #define DEFAULT_RCV_DESCRIPTORS_VF 1024
  127. #define MAX_RDS_RINGS 2
  128. #define get_next_index(index, length) \
  129. (((index) + 1) & ((length) - 1))
  130. /*
  131. * Following data structures describe the descriptors that will be used.
  132. * Added fileds of tcpHdrSize and ipHdrSize, The driver needs to do it only when
  133. * we are doing LSO (above the 1500 size packet) only.
  134. */
  135. struct cmd_desc_type0 {
  136. u8 tcp_hdr_offset; /* For LSO only */
  137. u8 ip_hdr_offset; /* For LSO only */
  138. __le16 flags_opcode; /* 15:13 unused, 12:7 opcode, 6:0 flags */
  139. __le32 nfrags__length; /* 31:8 total len, 7:0 frag count */
  140. __le64 addr_buffer2;
  141. __le16 encap_descr; /* 15:10 offset of outer L3 header,
  142. * 9:6 number of 32bit words in outer L3 header,
  143. * 5 offload outer L4 checksum,
  144. * 4 offload outer L3 checksum,
  145. * 3 Inner L4 type, TCP=0, UDP=1,
  146. * 2 Inner L3 type, IPv4=0, IPv6=1,
  147. * 1 Outer L3 type,IPv4=0, IPv6=1,
  148. * 0 type of encapsulation, GRE=0, VXLAN=1
  149. */
  150. __le16 mss;
  151. u8 port_ctxid; /* 7:4 ctxid 3:0 port */
  152. u8 hdr_length; /* LSO only : MAC+IP+TCP Hdr size */
  153. u8 outer_hdr_length; /* Encapsulation only */
  154. u8 rsvd1;
  155. __le64 addr_buffer3;
  156. __le64 addr_buffer1;
  157. __le16 buffer_length[4];
  158. __le64 addr_buffer4;
  159. u8 eth_addr[ETH_ALEN];
  160. __le16 vlan_TCI; /* In case of encapsulation,
  161. * this is for outer VLAN
  162. */
  163. } __attribute__ ((aligned(64)));
  164. /* Note: sizeof(rcv_desc) should always be a mutliple of 2 */
  165. struct rcv_desc {
  166. __le16 reference_handle;
  167. __le16 reserved;
  168. __le32 buffer_length; /* allocated buffer length (usually 2K) */
  169. __le64 addr_buffer;
  170. } __packed;
  171. struct status_desc {
  172. __le64 status_desc_data[2];
  173. } __attribute__ ((aligned(16)));
  174. /* UNIFIED ROMIMAGE */
  175. #define QLCNIC_UNI_FW_MIN_SIZE 0xc8000
  176. #define QLCNIC_UNI_DIR_SECT_PRODUCT_TBL 0x0
  177. #define QLCNIC_UNI_DIR_SECT_BOOTLD 0x6
  178. #define QLCNIC_UNI_DIR_SECT_FW 0x7
  179. /*Offsets */
  180. #define QLCNIC_UNI_CHIP_REV_OFF 10
  181. #define QLCNIC_UNI_FLAGS_OFF 11
  182. #define QLCNIC_UNI_BIOS_VERSION_OFF 12
  183. #define QLCNIC_UNI_BOOTLD_IDX_OFF 27
  184. #define QLCNIC_UNI_FIRMWARE_IDX_OFF 29
  185. struct uni_table_desc{
  186. __le32 findex;
  187. __le32 num_entries;
  188. __le32 entry_size;
  189. __le32 reserved[5];
  190. };
  191. struct uni_data_desc{
  192. __le32 findex;
  193. __le32 size;
  194. __le32 reserved[5];
  195. };
  196. /* Flash Defines and Structures */
  197. #define QLCNIC_FLT_LOCATION 0x3F1000
  198. #define QLCNIC_FDT_LOCATION 0x3F0000
  199. #define QLCNIC_B0_FW_IMAGE_REGION 0x74
  200. #define QLCNIC_C0_FW_IMAGE_REGION 0x97
  201. #define QLCNIC_BOOTLD_REGION 0X72
  202. struct qlcnic_flt_header {
  203. u16 version;
  204. u16 len;
  205. u16 checksum;
  206. u16 reserved;
  207. };
  208. struct qlcnic_flt_entry {
  209. u8 region;
  210. u8 reserved0;
  211. u8 attrib;
  212. u8 reserved1;
  213. u32 size;
  214. u32 start_addr;
  215. u32 end_addr;
  216. };
  217. /* Flash Descriptor Table */
  218. struct qlcnic_fdt {
  219. u32 valid;
  220. u16 ver;
  221. u16 len;
  222. u16 cksum;
  223. u16 unused;
  224. u8 model[16];
  225. u8 mfg_id;
  226. u16 id;
  227. u8 flag;
  228. u8 erase_cmd;
  229. u8 alt_erase_cmd;
  230. u8 write_enable_cmd;
  231. u8 write_enable_bits;
  232. u8 write_statusreg_cmd;
  233. u8 unprotected_sec_cmd;
  234. u8 read_manuf_cmd;
  235. u32 block_size;
  236. u32 alt_block_size;
  237. u32 flash_size;
  238. u32 write_enable_data;
  239. u8 readid_addr_len;
  240. u8 write_disable_bits;
  241. u8 read_dev_id_len;
  242. u8 chip_erase_cmd;
  243. u16 read_timeo;
  244. u8 protected_sec_cmd;
  245. u8 resvd[65];
  246. };
  247. /* Magic number to let user know flash is programmed */
  248. #define QLCNIC_BDINFO_MAGIC 0x12345678
  249. #define QLCNIC_BRDTYPE_P3P_REF_QG 0x0021
  250. #define QLCNIC_BRDTYPE_P3P_HMEZ 0x0022
  251. #define QLCNIC_BRDTYPE_P3P_10G_CX4_LP 0x0023
  252. #define QLCNIC_BRDTYPE_P3P_4_GB 0x0024
  253. #define QLCNIC_BRDTYPE_P3P_IMEZ 0x0025
  254. #define QLCNIC_BRDTYPE_P3P_10G_SFP_PLUS 0x0026
  255. #define QLCNIC_BRDTYPE_P3P_10000_BASE_T 0x0027
  256. #define QLCNIC_BRDTYPE_P3P_XG_LOM 0x0028
  257. #define QLCNIC_BRDTYPE_P3P_4_GB_MM 0x0029
  258. #define QLCNIC_BRDTYPE_P3P_10G_SFP_CT 0x002a
  259. #define QLCNIC_BRDTYPE_P3P_10G_SFP_QT 0x002b
  260. #define QLCNIC_BRDTYPE_P3P_10G_CX4 0x0031
  261. #define QLCNIC_BRDTYPE_P3P_10G_XFP 0x0032
  262. #define QLCNIC_BRDTYPE_P3P_10G_TP 0x0080
  263. #define QLCNIC_MSIX_TABLE_OFFSET 0x44
  264. /* Flash memory map */
  265. #define QLCNIC_BRDCFG_START 0x4000 /* board config */
  266. #define QLCNIC_BOOTLD_START 0x10000 /* bootld */
  267. #define QLCNIC_IMAGE_START 0x43000 /* compressed image */
  268. #define QLCNIC_USER_START 0x3E8000 /* Firmware info */
  269. #define QLCNIC_FW_VERSION_OFFSET (QLCNIC_USER_START+0x408)
  270. #define QLCNIC_FW_SIZE_OFFSET (QLCNIC_USER_START+0x40c)
  271. #define QLCNIC_FW_SERIAL_NUM_OFFSET (QLCNIC_USER_START+0x81c)
  272. #define QLCNIC_BIOS_VERSION_OFFSET (QLCNIC_USER_START+0x83c)
  273. #define QLCNIC_BRDTYPE_OFFSET (QLCNIC_BRDCFG_START+0x8)
  274. #define QLCNIC_FW_MAGIC_OFFSET (QLCNIC_BRDCFG_START+0x128)
  275. #define QLCNIC_FW_MIN_SIZE (0x3fffff)
  276. #define QLCNIC_UNIFIED_ROMIMAGE 0
  277. #define QLCNIC_FLASH_ROMIMAGE 1
  278. #define QLCNIC_UNKNOWN_ROMIMAGE 0xff
  279. #define QLCNIC_UNIFIED_ROMIMAGE_NAME "phanfw.bin"
  280. #define QLCNIC_FLASH_ROMIMAGE_NAME "flash"
  281. extern char qlcnic_driver_name[];
  282. extern int qlcnic_use_msi;
  283. extern int qlcnic_use_msi_x;
  284. extern int qlcnic_auto_fw_reset;
  285. extern int qlcnic_load_fw_file;
  286. /* Number of status descriptors to handle per interrupt */
  287. #define MAX_STATUS_HANDLE (64)
  288. /*
  289. * qlcnic_skb_frag{} is to contain mapping info for each SG list. This
  290. * has to be freed when DMA is complete. This is part of qlcnic_tx_buffer{}.
  291. */
  292. struct qlcnic_skb_frag {
  293. u64 dma;
  294. u64 length;
  295. };
  296. /* Following defines are for the state of the buffers */
  297. #define QLCNIC_BUFFER_FREE 0
  298. #define QLCNIC_BUFFER_BUSY 1
  299. /*
  300. * There will be one qlcnic_buffer per skb packet. These will be
  301. * used to save the dma info for pci_unmap_page()
  302. */
  303. struct qlcnic_cmd_buffer {
  304. struct sk_buff *skb;
  305. struct qlcnic_skb_frag frag_array[MAX_SKB_FRAGS + 1];
  306. u32 frag_count;
  307. };
  308. /* In rx_buffer, we do not need multiple fragments as is a single buffer */
  309. struct qlcnic_rx_buffer {
  310. u16 ref_handle;
  311. struct sk_buff *skb;
  312. struct list_head list;
  313. u64 dma;
  314. };
  315. /* Board types */
  316. #define QLCNIC_GBE 0x01
  317. #define QLCNIC_XGBE 0x02
  318. /*
  319. * Interrupt coalescing defaults. The defaults are for 1500 MTU. It is
  320. * adjusted based on configured MTU.
  321. */
  322. #define QLCNIC_INTR_COAL_TYPE_RX 1
  323. #define QLCNIC_INTR_COAL_TYPE_TX 2
  324. #define QLCNIC_INTR_COAL_TYPE_RX_TX 3
  325. #define QLCNIC_DEF_INTR_COALESCE_RX_TIME_US 3
  326. #define QLCNIC_DEF_INTR_COALESCE_RX_PACKETS 256
  327. #define QLCNIC_DEF_INTR_COALESCE_TX_TIME_US 64
  328. #define QLCNIC_DEF_INTR_COALESCE_TX_PACKETS 64
  329. #define QLCNIC_INTR_DEFAULT 0x04
  330. #define QLCNIC_CONFIG_INTR_COALESCE 3
  331. #define QLCNIC_DEV_INFO_SIZE 2
  332. struct qlcnic_nic_intr_coalesce {
  333. u8 type;
  334. u8 sts_ring_mask;
  335. u16 rx_packets;
  336. u16 rx_time_us;
  337. u16 tx_packets;
  338. u16 tx_time_us;
  339. u16 flag;
  340. u32 timer_out;
  341. };
  342. struct qlcnic_83xx_dump_template_hdr {
  343. u32 type;
  344. u32 offset;
  345. u32 size;
  346. u32 cap_mask;
  347. u32 num_entries;
  348. u32 version;
  349. u32 timestamp;
  350. u32 checksum;
  351. u32 drv_cap_mask;
  352. u32 sys_info[3];
  353. u32 saved_state[16];
  354. u32 cap_sizes[8];
  355. u32 ocm_wnd_reg[16];
  356. u32 rsvd[];
  357. };
  358. struct qlcnic_82xx_dump_template_hdr {
  359. u32 type;
  360. u32 offset;
  361. u32 size;
  362. u32 cap_mask;
  363. u32 num_entries;
  364. u32 version;
  365. u32 timestamp;
  366. u32 checksum;
  367. u32 drv_cap_mask;
  368. u32 sys_info[3];
  369. u32 saved_state[16];
  370. u32 cap_sizes[8];
  371. u32 rsvd[7];
  372. u32 capabilities;
  373. u32 rsvd1[];
  374. };
  375. #define QLC_PEX_DMA_READ_SIZE (PAGE_SIZE * 16)
  376. struct qlcnic_fw_dump {
  377. u8 clr; /* flag to indicate if dump is cleared */
  378. bool enable; /* enable/disable dump */
  379. u32 size; /* total size of the dump */
  380. u32 cap_mask; /* Current capture mask */
  381. void *data; /* dump data area */
  382. void *tmpl_hdr;
  383. dma_addr_t phys_addr;
  384. void *dma_buffer;
  385. bool use_pex_dma;
  386. /* Read only elements which are common between 82xx and 83xx
  387. * template header. Update these values immediately after we read
  388. * template header from Firmware
  389. */
  390. u32 tmpl_hdr_size;
  391. u32 version;
  392. u32 num_entries;
  393. u32 offset;
  394. };
  395. /*
  396. * One hardware_context{} per adapter
  397. * contains interrupt info as well shared hardware info.
  398. */
  399. struct qlcnic_hardware_context {
  400. void __iomem *pci_base0;
  401. void __iomem *ocm_win_crb;
  402. unsigned long pci_len0;
  403. rwlock_t crb_lock;
  404. struct mutex mem_lock;
  405. u8 revision_id;
  406. u8 pci_func;
  407. u8 linkup;
  408. u8 loopback_state;
  409. u8 beacon_state;
  410. u8 has_link_events;
  411. u8 fw_type;
  412. u8 physical_port;
  413. u8 reset_context;
  414. u8 msix_supported;
  415. u8 max_mac_filters;
  416. u8 mc_enabled;
  417. u8 max_mc_count;
  418. u8 diag_test;
  419. u8 num_msix;
  420. u8 nic_mode;
  421. int diag_cnt;
  422. u16 max_uc_count;
  423. u16 port_type;
  424. u16 board_type;
  425. u16 supported_type;
  426. u32 link_speed;
  427. u16 link_duplex;
  428. u16 link_autoneg;
  429. u16 module_type;
  430. u16 op_mode;
  431. u16 switch_mode;
  432. u16 max_tx_ques;
  433. u16 max_rx_ques;
  434. u16 max_mtu;
  435. u32 msg_enable;
  436. u16 total_nic_func;
  437. u16 max_pci_func;
  438. u32 max_vnic_func;
  439. u32 total_pci_func;
  440. u32 capabilities;
  441. u32 extra_capability[3];
  442. u32 temp;
  443. u32 int_vec_bit;
  444. u32 fw_hal_version;
  445. u32 port_config;
  446. struct qlcnic_hardware_ops *hw_ops;
  447. struct qlcnic_nic_intr_coalesce coal;
  448. struct qlcnic_fw_dump fw_dump;
  449. struct qlcnic_fdt fdt;
  450. struct qlc_83xx_reset reset;
  451. struct qlc_83xx_idc idc;
  452. struct qlc_83xx_fw_info *fw_info;
  453. struct qlcnic_intrpt_config *intr_tbl;
  454. struct qlcnic_sriov *sriov;
  455. u32 *reg_tbl;
  456. u32 *ext_reg_tbl;
  457. u32 mbox_aen[QLC_83XX_MBX_AEN_CNT];
  458. u32 mbox_reg[4];
  459. struct qlcnic_mailbox *mailbox;
  460. u8 extend_lb_time;
  461. u8 phys_port_id[ETH_ALEN];
  462. u8 lb_mode;
  463. struct device *hwmon_dev;
  464. u32 post_mode;
  465. bool run_post;
  466. };
  467. struct qlcnic_adapter_stats {
  468. u64 xmitcalled;
  469. u64 xmitfinished;
  470. u64 rxdropped;
  471. u64 txdropped;
  472. u64 csummed;
  473. u64 rx_pkts;
  474. u64 lro_pkts;
  475. u64 rxbytes;
  476. u64 txbytes;
  477. u64 lrobytes;
  478. u64 lso_frames;
  479. u64 encap_lso_frames;
  480. u64 encap_tx_csummed;
  481. u64 encap_rx_csummed;
  482. u64 xmit_on;
  483. u64 xmit_off;
  484. u64 skb_alloc_failure;
  485. u64 null_rxbuf;
  486. u64 rx_dma_map_error;
  487. u64 tx_dma_map_error;
  488. u64 spurious_intr;
  489. u64 mac_filter_limit_overrun;
  490. u64 mbx_spurious_intr;
  491. };
  492. /*
  493. * Rcv Descriptor Context. One such per Rcv Descriptor. There may
  494. * be one Rcv Descriptor for normal packets, one for jumbo and may be others.
  495. */
  496. struct qlcnic_host_rds_ring {
  497. void __iomem *crb_rcv_producer;
  498. struct rcv_desc *desc_head;
  499. struct qlcnic_rx_buffer *rx_buf_arr;
  500. u32 num_desc;
  501. u32 producer;
  502. u32 dma_size;
  503. u32 skb_size;
  504. u32 flags;
  505. struct list_head free_list;
  506. spinlock_t lock;
  507. dma_addr_t phys_addr;
  508. } ____cacheline_internodealigned_in_smp;
  509. struct qlcnic_host_sds_ring {
  510. u32 consumer;
  511. u32 num_desc;
  512. void __iomem *crb_sts_consumer;
  513. struct qlcnic_host_tx_ring *tx_ring;
  514. struct status_desc *desc_head;
  515. struct qlcnic_adapter *adapter;
  516. struct napi_struct napi;
  517. struct list_head free_list[NUM_RCV_DESC_RINGS];
  518. void __iomem *crb_intr_mask;
  519. int irq;
  520. dma_addr_t phys_addr;
  521. char name[IFNAMSIZ + 12];
  522. } ____cacheline_internodealigned_in_smp;
  523. struct qlcnic_tx_queue_stats {
  524. u64 xmit_on;
  525. u64 xmit_off;
  526. u64 xmit_called;
  527. u64 xmit_finished;
  528. u64 tx_bytes;
  529. };
  530. struct qlcnic_host_tx_ring {
  531. int irq;
  532. void __iomem *crb_intr_mask;
  533. char name[IFNAMSIZ + 12];
  534. u16 ctx_id;
  535. u32 state;
  536. u32 producer;
  537. u32 sw_consumer;
  538. u32 num_desc;
  539. struct qlcnic_tx_queue_stats tx_stats;
  540. void __iomem *crb_cmd_producer;
  541. struct cmd_desc_type0 *desc_head;
  542. struct qlcnic_adapter *adapter;
  543. struct napi_struct napi;
  544. struct qlcnic_cmd_buffer *cmd_buf_arr;
  545. __le32 *hw_consumer;
  546. dma_addr_t phys_addr;
  547. dma_addr_t hw_cons_phys_addr;
  548. struct netdev_queue *txq;
  549. /* Lock to protect Tx descriptors cleanup */
  550. spinlock_t tx_clean_lock;
  551. } ____cacheline_internodealigned_in_smp;
  552. /*
  553. * Receive context. There is one such structure per instance of the
  554. * receive processing. Any state information that is relevant to
  555. * the receive, and is must be in this structure. The global data may be
  556. * present elsewhere.
  557. */
  558. struct qlcnic_recv_context {
  559. struct qlcnic_host_rds_ring *rds_rings;
  560. struct qlcnic_host_sds_ring *sds_rings;
  561. u32 state;
  562. u16 context_id;
  563. u16 virt_port;
  564. };
  565. /* HW context creation */
  566. #define QLCNIC_OS_CRB_RETRY_COUNT 4000
  567. #define QLCNIC_CDRP_CMD_BIT 0x80000000
  568. /*
  569. * All responses must have the QLCNIC_CDRP_CMD_BIT cleared
  570. * in the crb QLCNIC_CDRP_CRB_OFFSET.
  571. */
  572. #define QLCNIC_CDRP_FORM_RSP(rsp) (rsp)
  573. #define QLCNIC_CDRP_IS_RSP(rsp) (((rsp) & QLCNIC_CDRP_CMD_BIT) == 0)
  574. #define QLCNIC_CDRP_RSP_OK 0x00000001
  575. #define QLCNIC_CDRP_RSP_FAIL 0x00000002
  576. #define QLCNIC_CDRP_RSP_TIMEOUT 0x00000003
  577. /*
  578. * All commands must have the QLCNIC_CDRP_CMD_BIT set in
  579. * the crb QLCNIC_CDRP_CRB_OFFSET.
  580. */
  581. #define QLCNIC_CDRP_FORM_CMD(cmd) (QLCNIC_CDRP_CMD_BIT | (cmd))
  582. #define QLCNIC_RCODE_SUCCESS 0
  583. #define QLCNIC_RCODE_INVALID_ARGS 6
  584. #define QLCNIC_RCODE_NOT_SUPPORTED 9
  585. #define QLCNIC_RCODE_NOT_PERMITTED 10
  586. #define QLCNIC_RCODE_NOT_IMPL 15
  587. #define QLCNIC_RCODE_INVALID 16
  588. #define QLCNIC_RCODE_TIMEOUT 17
  589. #define QLCNIC_DESTROY_CTX_RESET 0
  590. /*
  591. * Capabilities Announced
  592. */
  593. #define QLCNIC_CAP0_LEGACY_CONTEXT (1)
  594. #define QLCNIC_CAP0_LEGACY_MN (1 << 2)
  595. #define QLCNIC_CAP0_LSO (1 << 6)
  596. #define QLCNIC_CAP0_JUMBO_CONTIGUOUS (1 << 7)
  597. #define QLCNIC_CAP0_LRO_CONTIGUOUS (1 << 8)
  598. #define QLCNIC_CAP0_VALIDOFF (1 << 11)
  599. #define QLCNIC_CAP0_LRO_MSS (1 << 21)
  600. #define QLCNIC_CAP0_TX_MULTI (1 << 22)
  601. /*
  602. * Context state
  603. */
  604. #define QLCNIC_HOST_CTX_STATE_FREED 0
  605. #define QLCNIC_HOST_CTX_STATE_ACTIVE 2
  606. /*
  607. * Rx context
  608. */
  609. struct qlcnic_hostrq_sds_ring {
  610. __le64 host_phys_addr; /* Ring base addr */
  611. __le32 ring_size; /* Ring entries */
  612. __le16 msi_index;
  613. __le16 rsvd; /* Padding */
  614. } __packed;
  615. struct qlcnic_hostrq_rds_ring {
  616. __le64 host_phys_addr; /* Ring base addr */
  617. __le64 buff_size; /* Packet buffer size */
  618. __le32 ring_size; /* Ring entries */
  619. __le32 ring_kind; /* Class of ring */
  620. } __packed;
  621. struct qlcnic_hostrq_rx_ctx {
  622. __le64 host_rsp_dma_addr; /* Response dma'd here */
  623. __le32 capabilities[4]; /* Flag bit vector */
  624. __le32 host_int_crb_mode; /* Interrupt crb usage */
  625. __le32 host_rds_crb_mode; /* RDS crb usage */
  626. /* These ring offsets are relative to data[0] below */
  627. __le32 rds_ring_offset; /* Offset to RDS config */
  628. __le32 sds_ring_offset; /* Offset to SDS config */
  629. __le16 num_rds_rings; /* Count of RDS rings */
  630. __le16 num_sds_rings; /* Count of SDS rings */
  631. __le16 valid_field_offset;
  632. u8 txrx_sds_binding;
  633. u8 msix_handler;
  634. u8 reserved[128]; /* reserve space for future expansion*/
  635. /* MUST BE 64-bit aligned.
  636. The following is packed:
  637. - N hostrq_rds_rings
  638. - N hostrq_sds_rings */
  639. char data[];
  640. } __packed;
  641. struct qlcnic_cardrsp_rds_ring{
  642. __le32 host_producer_crb; /* Crb to use */
  643. __le32 rsvd1; /* Padding */
  644. } __packed;
  645. struct qlcnic_cardrsp_sds_ring {
  646. __le32 host_consumer_crb; /* Crb to use */
  647. __le32 interrupt_crb; /* Crb to use */
  648. } __packed;
  649. struct qlcnic_cardrsp_rx_ctx {
  650. /* These ring offsets are relative to data[0] below */
  651. __le32 rds_ring_offset; /* Offset to RDS config */
  652. __le32 sds_ring_offset; /* Offset to SDS config */
  653. __le32 host_ctx_state; /* Starting State */
  654. __le32 num_fn_per_port; /* How many PCI fn share the port */
  655. __le16 num_rds_rings; /* Count of RDS rings */
  656. __le16 num_sds_rings; /* Count of SDS rings */
  657. __le16 context_id; /* Handle for context */
  658. u8 phys_port; /* Physical id of port */
  659. u8 virt_port; /* Virtual/Logical id of port */
  660. u8 reserved[128]; /* save space for future expansion */
  661. /* MUST BE 64-bit aligned.
  662. The following is packed:
  663. - N cardrsp_rds_rings
  664. - N cardrs_sds_rings */
  665. char data[];
  666. } __packed;
  667. #define SIZEOF_HOSTRQ_RX(HOSTRQ_RX, rds_rings, sds_rings) \
  668. (sizeof(HOSTRQ_RX) + \
  669. (rds_rings)*(sizeof(struct qlcnic_hostrq_rds_ring)) + \
  670. (sds_rings)*(sizeof(struct qlcnic_hostrq_sds_ring)))
  671. #define SIZEOF_CARDRSP_RX(CARDRSP_RX, rds_rings, sds_rings) \
  672. (sizeof(CARDRSP_RX) + \
  673. (rds_rings)*(sizeof(struct qlcnic_cardrsp_rds_ring)) + \
  674. (sds_rings)*(sizeof(struct qlcnic_cardrsp_sds_ring)))
  675. /*
  676. * Tx context
  677. */
  678. struct qlcnic_hostrq_cds_ring {
  679. __le64 host_phys_addr; /* Ring base addr */
  680. __le32 ring_size; /* Ring entries */
  681. __le32 rsvd; /* Padding */
  682. } __packed;
  683. struct qlcnic_hostrq_tx_ctx {
  684. __le64 host_rsp_dma_addr; /* Response dma'd here */
  685. __le64 cmd_cons_dma_addr; /* */
  686. __le64 dummy_dma_addr; /* */
  687. __le32 capabilities[4]; /* Flag bit vector */
  688. __le32 host_int_crb_mode; /* Interrupt crb usage */
  689. __le32 rsvd1; /* Padding */
  690. __le16 rsvd2; /* Padding */
  691. __le16 interrupt_ctl;
  692. __le16 msi_index;
  693. __le16 rsvd3; /* Padding */
  694. struct qlcnic_hostrq_cds_ring cds_ring; /* Desc of cds ring */
  695. u8 reserved[128]; /* future expansion */
  696. } __packed;
  697. struct qlcnic_cardrsp_cds_ring {
  698. __le32 host_producer_crb; /* Crb to use */
  699. __le32 interrupt_crb; /* Crb to use */
  700. } __packed;
  701. struct qlcnic_cardrsp_tx_ctx {
  702. __le32 host_ctx_state; /* Starting state */
  703. __le16 context_id; /* Handle for context */
  704. u8 phys_port; /* Physical id of port */
  705. u8 virt_port; /* Virtual/Logical id of port */
  706. struct qlcnic_cardrsp_cds_ring cds_ring; /* Card cds settings */
  707. u8 reserved[128]; /* future expansion */
  708. } __packed;
  709. #define SIZEOF_HOSTRQ_TX(HOSTRQ_TX) (sizeof(HOSTRQ_TX))
  710. #define SIZEOF_CARDRSP_TX(CARDRSP_TX) (sizeof(CARDRSP_TX))
  711. /* CRB */
  712. #define QLCNIC_HOST_RDS_CRB_MODE_UNIQUE 0
  713. #define QLCNIC_HOST_RDS_CRB_MODE_SHARED 1
  714. #define QLCNIC_HOST_RDS_CRB_MODE_CUSTOM 2
  715. #define QLCNIC_HOST_RDS_CRB_MODE_MAX 3
  716. #define QLCNIC_HOST_INT_CRB_MODE_UNIQUE 0
  717. #define QLCNIC_HOST_INT_CRB_MODE_SHARED 1
  718. #define QLCNIC_HOST_INT_CRB_MODE_NORX 2
  719. #define QLCNIC_HOST_INT_CRB_MODE_NOTX 3
  720. #define QLCNIC_HOST_INT_CRB_MODE_NORXTX 4
  721. /* MAC */
  722. #define MC_COUNT_P3P 38
  723. #define QLCNIC_MAC_NOOP 0
  724. #define QLCNIC_MAC_ADD 1
  725. #define QLCNIC_MAC_DEL 2
  726. #define QLCNIC_MAC_VLAN_ADD 3
  727. #define QLCNIC_MAC_VLAN_DEL 4
  728. enum qlcnic_mac_type {
  729. QLCNIC_UNICAST_MAC,
  730. QLCNIC_MULTICAST_MAC,
  731. QLCNIC_BROADCAST_MAC,
  732. };
  733. struct qlcnic_mac_vlan_list {
  734. struct list_head list;
  735. uint8_t mac_addr[ETH_ALEN+2];
  736. u16 vlan_id;
  737. enum qlcnic_mac_type mac_type;
  738. };
  739. /* MAC Learn */
  740. #define NO_MAC_LEARN 0
  741. #define DRV_MAC_LEARN 1
  742. #define FDB_MAC_LEARN 2
  743. #define QLCNIC_HOST_REQUEST 0x13
  744. #define QLCNIC_REQUEST 0x14
  745. #define QLCNIC_MAC_EVENT 0x1
  746. #define QLCNIC_IP_UP 2
  747. #define QLCNIC_IP_DOWN 3
  748. #define QLCNIC_ILB_MODE 0x1
  749. #define QLCNIC_ELB_MODE 0x2
  750. #define QLCNIC_LB_MODE_MASK 0x3
  751. #define QLCNIC_LINKEVENT 0x1
  752. #define QLCNIC_LB_RESPONSE 0x2
  753. #define QLCNIC_IS_LB_CONFIGURED(VAL) \
  754. (VAL == (QLCNIC_LINKEVENT | QLCNIC_LB_RESPONSE))
  755. /*
  756. * Driver --> Firmware
  757. */
  758. #define QLCNIC_H2C_OPCODE_CONFIG_RSS 0x1
  759. #define QLCNIC_H2C_OPCODE_CONFIG_INTR_COALESCE 0x3
  760. #define QLCNIC_H2C_OPCODE_CONFIG_LED 0x4
  761. #define QLCNIC_H2C_OPCODE_LRO_REQUEST 0x7
  762. #define QLCNIC_H2C_OPCODE_SET_MAC_RECEIVE_MODE 0xc
  763. #define QLCNIC_H2C_OPCODE_CONFIG_IPADDR 0x12
  764. #define QLCNIC_H2C_OPCODE_GET_LINKEVENT 0x15
  765. #define QLCNIC_H2C_OPCODE_CONFIG_BRIDGING 0x17
  766. #define QLCNIC_H2C_OPCODE_CONFIG_HW_LRO 0x18
  767. #define QLCNIC_H2C_OPCODE_CONFIG_LOOPBACK 0x13
  768. /*
  769. * Firmware --> Driver
  770. */
  771. #define QLCNIC_C2H_OPCODE_CONFIG_LOOPBACK 0x8f
  772. #define QLCNIC_C2H_OPCODE_GET_LINKEVENT_RESPONSE 0x8D
  773. #define QLCNIC_C2H_OPCODE_GET_DCB_AEN 0x90
  774. #define VPORT_MISS_MODE_DROP 0 /* drop all unmatched */
  775. #define VPORT_MISS_MODE_ACCEPT_ALL 1 /* accept all packets */
  776. #define VPORT_MISS_MODE_ACCEPT_MULTI 2 /* accept unmatched multicast */
  777. #define QLCNIC_LRO_REQUEST_CLEANUP 4
  778. /* Capabilites received */
  779. #define QLCNIC_FW_CAPABILITY_TSO BIT_1
  780. #define QLCNIC_FW_CAPABILITY_BDG BIT_8
  781. #define QLCNIC_FW_CAPABILITY_FVLANTX BIT_9
  782. #define QLCNIC_FW_CAPABILITY_HW_LRO BIT_10
  783. #define QLCNIC_FW_CAPABILITY_2_MULTI_TX BIT_4
  784. #define QLCNIC_FW_CAPABILITY_MULTI_LOOPBACK BIT_27
  785. #define QLCNIC_FW_CAPABILITY_MORE_CAPS BIT_31
  786. #define QLCNIC_FW_CAPABILITY_2_LRO_MAX_TCP_SEG BIT_2
  787. #define QLCNIC_FW_CAP2_HW_LRO_IPV6 BIT_3
  788. #define QLCNIC_FW_CAPABILITY_SET_DRV_VER BIT_5
  789. #define QLCNIC_FW_CAPABILITY_2_BEACON BIT_7
  790. #define QLCNIC_FW_CAPABILITY_2_PER_PORT_ESWITCH_CFG BIT_9
  791. #define QLCNIC_FW_CAPABILITY_2_EXT_ISCSI_DUMP BIT_13
  792. #define QLCNIC_83XX_FW_CAPAB_ENCAP_RX_OFFLOAD BIT_0
  793. #define QLCNIC_83XX_FW_CAPAB_ENCAP_TX_OFFLOAD BIT_1
  794. #define QLCNIC_83XX_FW_CAPAB_ENCAP_CKO_OFFLOAD BIT_4
  795. /* module types */
  796. #define LINKEVENT_MODULE_NOT_PRESENT 1
  797. #define LINKEVENT_MODULE_OPTICAL_UNKNOWN 2
  798. #define LINKEVENT_MODULE_OPTICAL_SRLR 3
  799. #define LINKEVENT_MODULE_OPTICAL_LRM 4
  800. #define LINKEVENT_MODULE_OPTICAL_SFP_1G 5
  801. #define LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLE 6
  802. #define LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLELEN 7
  803. #define LINKEVENT_MODULE_TWINAX 8
  804. #define LINKSPEED_10GBPS 10000
  805. #define LINKSPEED_1GBPS 1000
  806. #define LINKSPEED_100MBPS 100
  807. #define LINKSPEED_10MBPS 10
  808. #define LINKSPEED_ENCODED_10MBPS 0
  809. #define LINKSPEED_ENCODED_100MBPS 1
  810. #define LINKSPEED_ENCODED_1GBPS 2
  811. #define LINKEVENT_AUTONEG_DISABLED 0
  812. #define LINKEVENT_AUTONEG_ENABLED 1
  813. #define LINKEVENT_HALF_DUPLEX 0
  814. #define LINKEVENT_FULL_DUPLEX 1
  815. #define LINKEVENT_LINKSPEED_MBPS 0
  816. #define LINKEVENT_LINKSPEED_ENCODED 1
  817. /* firmware response header:
  818. * 63:58 - message type
  819. * 57:56 - owner
  820. * 55:53 - desc count
  821. * 52:48 - reserved
  822. * 47:40 - completion id
  823. * 39:32 - opcode
  824. * 31:16 - error code
  825. * 15:00 - reserved
  826. */
  827. #define qlcnic_get_nic_msg_opcode(msg_hdr) \
  828. ((msg_hdr >> 32) & 0xFF)
  829. struct qlcnic_fw_msg {
  830. union {
  831. struct {
  832. u64 hdr;
  833. u64 body[7];
  834. };
  835. u64 words[8];
  836. };
  837. };
  838. struct qlcnic_nic_req {
  839. __le64 qhdr;
  840. __le64 req_hdr;
  841. __le64 words[6];
  842. } __packed;
  843. struct qlcnic_mac_req {
  844. u8 op;
  845. u8 tag;
  846. u8 mac_addr[6];
  847. };
  848. struct qlcnic_vlan_req {
  849. __le16 vlan_id;
  850. __le16 rsvd[3];
  851. } __packed;
  852. struct qlcnic_ipaddr {
  853. __be32 ipv4;
  854. __be32 ipv6[4];
  855. };
  856. #define QLCNIC_MSI_ENABLED 0x02
  857. #define QLCNIC_MSIX_ENABLED 0x04
  858. #define QLCNIC_LRO_ENABLED 0x01
  859. #define QLCNIC_LRO_DISABLED 0x00
  860. #define QLCNIC_BRIDGE_ENABLED 0X10
  861. #define QLCNIC_DIAG_ENABLED 0x20
  862. #define QLCNIC_ESWITCH_ENABLED 0x40
  863. #define QLCNIC_ADAPTER_INITIALIZED 0x80
  864. #define QLCNIC_TAGGING_ENABLED 0x100
  865. #define QLCNIC_MACSPOOF 0x200
  866. #define QLCNIC_MAC_OVERRIDE_DISABLED 0x400
  867. #define QLCNIC_PROMISC_DISABLED 0x800
  868. #define QLCNIC_NEED_FLR 0x1000
  869. #define QLCNIC_FW_RESET_OWNER 0x2000
  870. #define QLCNIC_FW_HANG 0x4000
  871. #define QLCNIC_FW_LRO_MSS_CAP 0x8000
  872. #define QLCNIC_TX_INTR_SHARED 0x10000
  873. #define QLCNIC_APP_CHANGED_FLAGS 0x20000
  874. #define QLCNIC_HAS_PHYS_PORT_ID 0x40000
  875. #define QLCNIC_TSS_RSS 0x80000
  876. #define QLCNIC_VLAN_FILTERING 0x800000
  877. #define QLCNIC_IS_MSI_FAMILY(adapter) \
  878. ((adapter)->flags & (QLCNIC_MSI_ENABLED | QLCNIC_MSIX_ENABLED))
  879. #define QLCNIC_IS_TSO_CAPABLE(adapter) \
  880. ((adapter)->ahw->capabilities & QLCNIC_FW_CAPABILITY_TSO)
  881. #define QLCNIC_BEACON_EANBLE 0xC
  882. #define QLCNIC_BEACON_DISABLE 0xD
  883. #define QLCNIC_BEACON_ON 2
  884. #define QLCNIC_BEACON_OFF 0
  885. #define QLCNIC_MSIX_TBL_SPACE 8192
  886. #define QLCNIC_PCI_REG_MSIX_TBL 0x44
  887. #define QLCNIC_MSIX_TBL_PGSIZE 4096
  888. #define QLCNIC_ADAPTER_UP_MAGIC 777
  889. #define __QLCNIC_FW_ATTACHED 0
  890. #define __QLCNIC_DEV_UP 1
  891. #define __QLCNIC_RESETTING 2
  892. #define __QLCNIC_START_FW 4
  893. #define __QLCNIC_AER 5
  894. #define __QLCNIC_DIAG_RES_ALLOC 6
  895. #define __QLCNIC_LED_ENABLE 7
  896. #define __QLCNIC_ELB_INPROGRESS 8
  897. #define __QLCNIC_MULTI_TX_UNIQUE 9
  898. #define __QLCNIC_SRIOV_ENABLE 10
  899. #define __QLCNIC_SRIOV_CAPABLE 11
  900. #define __QLCNIC_MBX_POLL_ENABLE 12
  901. #define __QLCNIC_DIAG_MODE 13
  902. #define __QLCNIC_MAINTENANCE_MODE 16
  903. #define QLCNIC_INTERRUPT_TEST 1
  904. #define QLCNIC_LOOPBACK_TEST 2
  905. #define QLCNIC_LED_TEST 3
  906. #define QLCNIC_FILTER_AGE 80
  907. #define QLCNIC_READD_AGE 20
  908. #define QLCNIC_LB_MAX_FILTERS 64
  909. #define QLCNIC_LB_BUCKET_SIZE 32
  910. #define QLCNIC_ILB_MAX_RCV_LOOP 10
  911. struct qlcnic_filter {
  912. struct hlist_node fnode;
  913. u8 faddr[ETH_ALEN];
  914. u16 vlan_id;
  915. unsigned long ftime;
  916. };
  917. struct qlcnic_filter_hash {
  918. struct hlist_head *fhead;
  919. u8 fnum;
  920. u16 fmax;
  921. u16 fbucket_size;
  922. };
  923. /* Mailbox specific data structures */
  924. struct qlcnic_mailbox {
  925. struct workqueue_struct *work_q;
  926. struct qlcnic_adapter *adapter;
  927. const struct qlcnic_mbx_ops *ops;
  928. struct work_struct work;
  929. struct completion completion;
  930. struct list_head cmd_q;
  931. unsigned long status;
  932. spinlock_t queue_lock; /* Mailbox queue lock */
  933. spinlock_t aen_lock; /* Mailbox response/AEN lock */
  934. u32 rsp_status;
  935. u32 num_cmds;
  936. };
  937. struct qlcnic_adapter {
  938. struct qlcnic_hardware_context *ahw;
  939. struct qlcnic_recv_context *recv_ctx;
  940. struct qlcnic_host_tx_ring *tx_ring;
  941. struct net_device *netdev;
  942. struct pci_dev *pdev;
  943. unsigned long state;
  944. u32 flags;
  945. u16 num_txd;
  946. u16 num_rxd;
  947. u16 num_jumbo_rxd;
  948. u16 max_rxd;
  949. u16 max_jumbo_rxd;
  950. u8 max_rds_rings;
  951. u8 max_sds_rings; /* max sds rings supported by adapter */
  952. u8 max_tx_rings; /* max tx rings supported by adapter */
  953. u8 drv_tx_rings; /* max tx rings supported by driver */
  954. u8 drv_sds_rings; /* max sds rings supported by driver */
  955. u8 drv_tss_rings; /* tss ring input */
  956. u8 drv_rss_rings; /* rss ring input */
  957. u8 rx_csum;
  958. u8 portnum;
  959. u8 fw_wait_cnt;
  960. u8 fw_fail_cnt;
  961. u8 tx_timeo_cnt;
  962. u8 need_fw_reset;
  963. u8 reset_ctx_cnt;
  964. u16 is_up;
  965. u16 rx_pvid;
  966. u16 tx_pvid;
  967. u32 irq;
  968. u32 heartbeat;
  969. u8 dev_state;
  970. u8 reset_ack_timeo;
  971. u8 dev_init_timeo;
  972. u8 mac_addr[ETH_ALEN];
  973. u64 dev_rst_time;
  974. bool drv_mac_learn;
  975. bool fdb_mac_learn;
  976. bool rx_mac_learn;
  977. unsigned long vlans[BITS_TO_LONGS(VLAN_N_VID)];
  978. u8 flash_mfg_id;
  979. struct qlcnic_npar_info *npars;
  980. struct qlcnic_eswitch *eswitch;
  981. struct qlcnic_nic_template *nic_ops;
  982. struct qlcnic_adapter_stats stats;
  983. struct list_head mac_list;
  984. void __iomem *tgt_mask_reg;
  985. void __iomem *tgt_status_reg;
  986. void __iomem *crb_int_state_reg;
  987. void __iomem *isr_int_vec;
  988. struct msix_entry *msix_entries;
  989. struct workqueue_struct *qlcnic_wq;
  990. struct delayed_work fw_work;
  991. struct delayed_work idc_aen_work;
  992. struct delayed_work mbx_poll_work;
  993. struct qlcnic_dcb *dcb;
  994. struct qlcnic_filter_hash fhash;
  995. struct qlcnic_filter_hash rx_fhash;
  996. struct list_head vf_mc_list;
  997. spinlock_t mac_learn_lock;
  998. /* spinlock for catching rcv filters for eswitch traffic */
  999. spinlock_t rx_mac_learn_lock;
  1000. u32 file_prd_off; /*File fw product offset*/
  1001. u32 fw_version;
  1002. u32 offload_flags;
  1003. const struct firmware *fw;
  1004. };
  1005. struct qlcnic_info_le {
  1006. __le16 pci_func;
  1007. __le16 op_mode; /* 1 = Priv, 2 = NP, 3 = NP passthru */
  1008. __le16 phys_port;
  1009. __le16 switch_mode; /* 0 = disabled, 1 = int, 2 = ext */
  1010. __le32 capabilities;
  1011. u8 max_mac_filters;
  1012. u8 reserved1;
  1013. __le16 max_mtu;
  1014. __le16 max_tx_ques;
  1015. __le16 max_rx_ques;
  1016. __le16 min_tx_bw;
  1017. __le16 max_tx_bw;
  1018. __le32 op_type;
  1019. __le16 max_bw_reg_offset;
  1020. __le16 max_linkspeed_reg_offset;
  1021. __le32 capability1;
  1022. __le32 capability2;
  1023. __le32 capability3;
  1024. __le16 max_tx_mac_filters;
  1025. __le16 max_rx_mcast_mac_filters;
  1026. __le16 max_rx_ucast_mac_filters;
  1027. __le16 max_rx_ip_addr;
  1028. __le16 max_rx_lro_flow;
  1029. __le16 max_rx_status_rings;
  1030. __le16 max_rx_buf_rings;
  1031. __le16 max_tx_vlan_keys;
  1032. u8 total_pf;
  1033. u8 total_rss_engines;
  1034. __le16 max_vports;
  1035. __le16 linkstate_reg_offset;
  1036. __le16 bit_offsets;
  1037. __le16 max_local_ipv6_addrs;
  1038. __le16 max_remote_ipv6_addrs;
  1039. u8 reserved2[56];
  1040. } __packed;
  1041. struct qlcnic_info {
  1042. u16 pci_func;
  1043. u16 op_mode;
  1044. u16 phys_port;
  1045. u16 switch_mode;
  1046. u32 capabilities;
  1047. u8 max_mac_filters;
  1048. u16 max_mtu;
  1049. u16 max_tx_ques;
  1050. u16 max_rx_ques;
  1051. u16 min_tx_bw;
  1052. u16 max_tx_bw;
  1053. u32 op_type;
  1054. u16 max_bw_reg_offset;
  1055. u16 max_linkspeed_reg_offset;
  1056. u32 capability1;
  1057. u32 capability2;
  1058. u32 capability3;
  1059. u16 max_tx_mac_filters;
  1060. u16 max_rx_mcast_mac_filters;
  1061. u16 max_rx_ucast_mac_filters;
  1062. u16 max_rx_ip_addr;
  1063. u16 max_rx_lro_flow;
  1064. u16 max_rx_status_rings;
  1065. u16 max_rx_buf_rings;
  1066. u16 max_tx_vlan_keys;
  1067. u8 total_pf;
  1068. u8 total_rss_engines;
  1069. u16 max_vports;
  1070. u16 linkstate_reg_offset;
  1071. u16 bit_offsets;
  1072. u16 max_local_ipv6_addrs;
  1073. u16 max_remote_ipv6_addrs;
  1074. };
  1075. struct qlcnic_pci_info_le {
  1076. __le16 id; /* pci function id */
  1077. __le16 active; /* 1 = Enabled */
  1078. __le16 type; /* 1 = NIC, 2 = FCoE, 3 = iSCSI */
  1079. __le16 default_port; /* default port number */
  1080. __le16 tx_min_bw; /* Multiple of 100mbpc */
  1081. __le16 tx_max_bw;
  1082. __le16 reserved1[2];
  1083. u8 mac[ETH_ALEN];
  1084. __le16 func_count;
  1085. u8 reserved2[104];
  1086. } __packed;
  1087. struct qlcnic_pci_info {
  1088. u16 id;
  1089. u16 active;
  1090. u16 type;
  1091. u16 default_port;
  1092. u16 tx_min_bw;
  1093. u16 tx_max_bw;
  1094. u8 mac[ETH_ALEN];
  1095. u16 func_count;
  1096. };
  1097. struct qlcnic_npar_info {
  1098. bool eswitch_status;
  1099. u16 pvid;
  1100. u16 min_bw;
  1101. u16 max_bw;
  1102. u8 phy_port;
  1103. u8 type;
  1104. u8 active;
  1105. u8 enable_pm;
  1106. u8 dest_npar;
  1107. u8 discard_tagged;
  1108. u8 mac_override;
  1109. u8 mac_anti_spoof;
  1110. u8 promisc_mode;
  1111. u8 offload_flags;
  1112. u8 pci_func;
  1113. u8 mac[ETH_ALEN];
  1114. };
  1115. struct qlcnic_eswitch {
  1116. u8 port;
  1117. u8 active_vports;
  1118. u8 active_vlans;
  1119. u8 active_ucast_filters;
  1120. u8 max_ucast_filters;
  1121. u8 max_active_vlans;
  1122. u32 flags;
  1123. #define QLCNIC_SWITCH_ENABLE BIT_1
  1124. #define QLCNIC_SWITCH_VLAN_FILTERING BIT_2
  1125. #define QLCNIC_SWITCH_PROMISC_MODE BIT_3
  1126. #define QLCNIC_SWITCH_PORT_MIRRORING BIT_4
  1127. };
  1128. #define MAX_BW 100 /* % of link speed */
  1129. #define MIN_BW 1 /* % of link speed */
  1130. #define MAX_VLAN_ID 4095
  1131. #define MIN_VLAN_ID 2
  1132. #define DEFAULT_MAC_LEARN 1
  1133. #define IS_VALID_VLAN(vlan) (vlan >= MIN_VLAN_ID && vlan < MAX_VLAN_ID)
  1134. #define IS_VALID_BW(bw) (bw <= MAX_BW)
  1135. struct qlcnic_pci_func_cfg {
  1136. u16 func_type;
  1137. u16 min_bw;
  1138. u16 max_bw;
  1139. u16 port_num;
  1140. u8 pci_func;
  1141. u8 func_state;
  1142. u8 def_mac_addr[ETH_ALEN];
  1143. };
  1144. struct qlcnic_npar_func_cfg {
  1145. u32 fw_capab;
  1146. u16 port_num;
  1147. u16 min_bw;
  1148. u16 max_bw;
  1149. u16 max_tx_queues;
  1150. u16 max_rx_queues;
  1151. u8 pci_func;
  1152. u8 op_mode;
  1153. };
  1154. struct qlcnic_pm_func_cfg {
  1155. u8 pci_func;
  1156. u8 action;
  1157. u8 dest_npar;
  1158. u8 reserved[5];
  1159. };
  1160. struct qlcnic_esw_func_cfg {
  1161. u16 vlan_id;
  1162. u8 op_mode;
  1163. u8 op_type;
  1164. u8 pci_func;
  1165. u8 host_vlan_tag;
  1166. u8 promisc_mode;
  1167. u8 discard_tagged;
  1168. u8 mac_override;
  1169. u8 mac_anti_spoof;
  1170. u8 offload_flags;
  1171. u8 reserved[5];
  1172. };
  1173. #define QLCNIC_STATS_VERSION 1
  1174. #define QLCNIC_STATS_PORT 1
  1175. #define QLCNIC_STATS_ESWITCH 2
  1176. #define QLCNIC_QUERY_RX_COUNTER 0
  1177. #define QLCNIC_QUERY_TX_COUNTER 1
  1178. #define QLCNIC_STATS_NOT_AVAIL 0xffffffffffffffffULL
  1179. #define QLCNIC_FILL_STATS(VAL1) \
  1180. (((VAL1) == QLCNIC_STATS_NOT_AVAIL) ? 0 : VAL1)
  1181. #define QLCNIC_MAC_STATS 1
  1182. #define QLCNIC_ESW_STATS 2
  1183. #define QLCNIC_ADD_ESW_STATS(VAL1, VAL2)\
  1184. do { \
  1185. if (((VAL1) == QLCNIC_STATS_NOT_AVAIL) && \
  1186. ((VAL2) != QLCNIC_STATS_NOT_AVAIL)) \
  1187. (VAL1) = (VAL2); \
  1188. else if (((VAL1) != QLCNIC_STATS_NOT_AVAIL) && \
  1189. ((VAL2) != QLCNIC_STATS_NOT_AVAIL)) \
  1190. (VAL1) += (VAL2); \
  1191. } while (0)
  1192. struct qlcnic_mac_statistics_le {
  1193. __le64 mac_tx_frames;
  1194. __le64 mac_tx_bytes;
  1195. __le64 mac_tx_mcast_pkts;
  1196. __le64 mac_tx_bcast_pkts;
  1197. __le64 mac_tx_pause_cnt;
  1198. __le64 mac_tx_ctrl_pkt;
  1199. __le64 mac_tx_lt_64b_pkts;
  1200. __le64 mac_tx_lt_127b_pkts;
  1201. __le64 mac_tx_lt_255b_pkts;
  1202. __le64 mac_tx_lt_511b_pkts;
  1203. __le64 mac_tx_lt_1023b_pkts;
  1204. __le64 mac_tx_lt_1518b_pkts;
  1205. __le64 mac_tx_gt_1518b_pkts;
  1206. __le64 rsvd1[3];
  1207. __le64 mac_rx_frames;
  1208. __le64 mac_rx_bytes;
  1209. __le64 mac_rx_mcast_pkts;
  1210. __le64 mac_rx_bcast_pkts;
  1211. __le64 mac_rx_pause_cnt;
  1212. __le64 mac_rx_ctrl_pkt;
  1213. __le64 mac_rx_lt_64b_pkts;
  1214. __le64 mac_rx_lt_127b_pkts;
  1215. __le64 mac_rx_lt_255b_pkts;
  1216. __le64 mac_rx_lt_511b_pkts;
  1217. __le64 mac_rx_lt_1023b_pkts;
  1218. __le64 mac_rx_lt_1518b_pkts;
  1219. __le64 mac_rx_gt_1518b_pkts;
  1220. __le64 rsvd2[3];
  1221. __le64 mac_rx_length_error;
  1222. __le64 mac_rx_length_small;
  1223. __le64 mac_rx_length_large;
  1224. __le64 mac_rx_jabber;
  1225. __le64 mac_rx_dropped;
  1226. __le64 mac_rx_crc_error;
  1227. __le64 mac_align_error;
  1228. } __packed;
  1229. struct qlcnic_mac_statistics {
  1230. u64 mac_tx_frames;
  1231. u64 mac_tx_bytes;
  1232. u64 mac_tx_mcast_pkts;
  1233. u64 mac_tx_bcast_pkts;
  1234. u64 mac_tx_pause_cnt;
  1235. u64 mac_tx_ctrl_pkt;
  1236. u64 mac_tx_lt_64b_pkts;
  1237. u64 mac_tx_lt_127b_pkts;
  1238. u64 mac_tx_lt_255b_pkts;
  1239. u64 mac_tx_lt_511b_pkts;
  1240. u64 mac_tx_lt_1023b_pkts;
  1241. u64 mac_tx_lt_1518b_pkts;
  1242. u64 mac_tx_gt_1518b_pkts;
  1243. u64 rsvd1[3];
  1244. u64 mac_rx_frames;
  1245. u64 mac_rx_bytes;
  1246. u64 mac_rx_mcast_pkts;
  1247. u64 mac_rx_bcast_pkts;
  1248. u64 mac_rx_pause_cnt;
  1249. u64 mac_rx_ctrl_pkt;
  1250. u64 mac_rx_lt_64b_pkts;
  1251. u64 mac_rx_lt_127b_pkts;
  1252. u64 mac_rx_lt_255b_pkts;
  1253. u64 mac_rx_lt_511b_pkts;
  1254. u64 mac_rx_lt_1023b_pkts;
  1255. u64 mac_rx_lt_1518b_pkts;
  1256. u64 mac_rx_gt_1518b_pkts;
  1257. u64 rsvd2[3];
  1258. u64 mac_rx_length_error;
  1259. u64 mac_rx_length_small;
  1260. u64 mac_rx_length_large;
  1261. u64 mac_rx_jabber;
  1262. u64 mac_rx_dropped;
  1263. u64 mac_rx_crc_error;
  1264. u64 mac_align_error;
  1265. };
  1266. struct qlcnic_esw_stats_le {
  1267. __le16 context_id;
  1268. __le16 version;
  1269. __le16 size;
  1270. __le16 unused;
  1271. __le64 unicast_frames;
  1272. __le64 multicast_frames;
  1273. __le64 broadcast_frames;
  1274. __le64 dropped_frames;
  1275. __le64 errors;
  1276. __le64 local_frames;
  1277. __le64 numbytes;
  1278. __le64 rsvd[3];
  1279. } __packed;
  1280. struct __qlcnic_esw_statistics {
  1281. u16 context_id;
  1282. u16 version;
  1283. u16 size;
  1284. u16 unused;
  1285. u64 unicast_frames;
  1286. u64 multicast_frames;
  1287. u64 broadcast_frames;
  1288. u64 dropped_frames;
  1289. u64 errors;
  1290. u64 local_frames;
  1291. u64 numbytes;
  1292. u64 rsvd[3];
  1293. };
  1294. struct qlcnic_esw_statistics {
  1295. struct __qlcnic_esw_statistics rx;
  1296. struct __qlcnic_esw_statistics tx;
  1297. };
  1298. #define QLCNIC_FORCE_FW_DUMP_KEY 0xdeadfeed
  1299. #define QLCNIC_ENABLE_FW_DUMP 0xaddfeed
  1300. #define QLCNIC_DISABLE_FW_DUMP 0xbadfeed
  1301. #define QLCNIC_FORCE_FW_RESET 0xdeaddead
  1302. #define QLCNIC_SET_QUIESCENT 0xadd00010
  1303. #define QLCNIC_RESET_QUIESCENT 0xadd00020
  1304. struct _cdrp_cmd {
  1305. u32 num;
  1306. u32 *arg;
  1307. };
  1308. struct qlcnic_cmd_args {
  1309. struct completion completion;
  1310. struct list_head list;
  1311. struct _cdrp_cmd req;
  1312. struct _cdrp_cmd rsp;
  1313. atomic_t rsp_status;
  1314. int pay_size;
  1315. u32 rsp_opcode;
  1316. u32 total_cmds;
  1317. u32 op_type;
  1318. u32 type;
  1319. u32 cmd_op;
  1320. u32 *hdr; /* Back channel message header */
  1321. u32 *pay; /* Back channel message payload */
  1322. u8 func_num;
  1323. };
  1324. int qlcnic_fw_cmd_get_minidump_temp(struct qlcnic_adapter *adapter);
  1325. int qlcnic_fw_cmd_set_port(struct qlcnic_adapter *adapter, u32 config);
  1326. int qlcnic_pci_mem_write_2M(struct qlcnic_adapter *, u64 off, u64 data);
  1327. int qlcnic_pci_mem_read_2M(struct qlcnic_adapter *, u64 off, u64 *data);
  1328. #define ADDR_IN_RANGE(addr, low, high) \
  1329. (((addr) < (high)) && ((addr) >= (low)))
  1330. #define QLCRD32(adapter, off, err) \
  1331. (adapter->ahw->hw_ops->read_reg)(adapter, off, err)
  1332. #define QLCWR32(adapter, off, val) \
  1333. adapter->ahw->hw_ops->write_reg(adapter, off, val)
  1334. int qlcnic_pcie_sem_lock(struct qlcnic_adapter *, int, u32);
  1335. void qlcnic_pcie_sem_unlock(struct qlcnic_adapter *, int);
  1336. #define qlcnic_rom_lock(a) \
  1337. qlcnic_pcie_sem_lock((a), 2, QLCNIC_ROM_LOCK_ID)
  1338. #define qlcnic_rom_unlock(a) \
  1339. qlcnic_pcie_sem_unlock((a), 2)
  1340. #define qlcnic_phy_lock(a) \
  1341. qlcnic_pcie_sem_lock((a), 3, QLCNIC_PHY_LOCK_ID)
  1342. #define qlcnic_phy_unlock(a) \
  1343. qlcnic_pcie_sem_unlock((a), 3)
  1344. #define qlcnic_sw_lock(a) \
  1345. qlcnic_pcie_sem_lock((a), 6, 0)
  1346. #define qlcnic_sw_unlock(a) \
  1347. qlcnic_pcie_sem_unlock((a), 6)
  1348. #define crb_win_lock(a) \
  1349. qlcnic_pcie_sem_lock((a), 7, QLCNIC_CRB_WIN_LOCK_ID)
  1350. #define crb_win_unlock(a) \
  1351. qlcnic_pcie_sem_unlock((a), 7)
  1352. #define __QLCNIC_MAX_LED_RATE 0xf
  1353. #define __QLCNIC_MAX_LED_STATE 0x2
  1354. #define MAX_CTL_CHECK 1000
  1355. void qlcnic_prune_lb_filters(struct qlcnic_adapter *adapter);
  1356. void qlcnic_delete_lb_filters(struct qlcnic_adapter *adapter);
  1357. int qlcnic_dump_fw(struct qlcnic_adapter *);
  1358. int qlcnic_enable_fw_dump_state(struct qlcnic_adapter *);
  1359. bool qlcnic_check_fw_dump_state(struct qlcnic_adapter *);
  1360. /* Functions from qlcnic_init.c */
  1361. void qlcnic_schedule_work(struct qlcnic_adapter *, work_func_t, int);
  1362. int qlcnic_load_firmware(struct qlcnic_adapter *adapter);
  1363. int qlcnic_need_fw_reset(struct qlcnic_adapter *adapter);
  1364. void qlcnic_request_firmware(struct qlcnic_adapter *adapter);
  1365. void qlcnic_release_firmware(struct qlcnic_adapter *adapter);
  1366. int qlcnic_pinit_from_rom(struct qlcnic_adapter *adapter);
  1367. int qlcnic_setup_idc_param(struct qlcnic_adapter *adapter);
  1368. int qlcnic_check_flash_fw_ver(struct qlcnic_adapter *adapter);
  1369. int qlcnic_rom_fast_read(struct qlcnic_adapter *adapter, u32 addr, u32 *valp);
  1370. int qlcnic_rom_fast_read_words(struct qlcnic_adapter *adapter, int addr,
  1371. u8 *bytes, size_t size);
  1372. int qlcnic_alloc_sw_resources(struct qlcnic_adapter *adapter);
  1373. void qlcnic_free_sw_resources(struct qlcnic_adapter *adapter);
  1374. void __iomem *qlcnic_get_ioaddr(struct qlcnic_hardware_context *, u32);
  1375. int qlcnic_alloc_hw_resources(struct qlcnic_adapter *adapter);
  1376. void qlcnic_free_hw_resources(struct qlcnic_adapter *adapter);
  1377. int qlcnic_fw_create_ctx(struct qlcnic_adapter *adapter);
  1378. void qlcnic_fw_destroy_ctx(struct qlcnic_adapter *adapter);
  1379. void qlcnic_reset_rx_buffers_list(struct qlcnic_adapter *adapter);
  1380. void qlcnic_release_rx_buffers(struct qlcnic_adapter *adapter);
  1381. void qlcnic_release_tx_buffers(struct qlcnic_adapter *,
  1382. struct qlcnic_host_tx_ring *);
  1383. int qlcnic_check_fw_status(struct qlcnic_adapter *adapter);
  1384. void qlcnic_watchdog_task(struct work_struct *work);
  1385. void qlcnic_post_rx_buffers(struct qlcnic_adapter *adapter,
  1386. struct qlcnic_host_rds_ring *rds_ring, u8 ring_id);
  1387. void qlcnic_set_multi(struct net_device *netdev);
  1388. void qlcnic_flush_mcast_mac(struct qlcnic_adapter *);
  1389. int qlcnic_nic_add_mac(struct qlcnic_adapter *, const u8 *, u16,
  1390. enum qlcnic_mac_type);
  1391. int qlcnic_nic_del_mac(struct qlcnic_adapter *, const u8 *);
  1392. void qlcnic_82xx_free_mac_list(struct qlcnic_adapter *adapter);
  1393. int qlcnic_82xx_read_phys_port_id(struct qlcnic_adapter *);
  1394. int qlcnic_fw_cmd_set_mtu(struct qlcnic_adapter *adapter, int mtu);
  1395. int qlcnic_fw_cmd_set_drv_version(struct qlcnic_adapter *, u32);
  1396. int qlcnic_change_mtu(struct net_device *netdev, int new_mtu);
  1397. netdev_features_t qlcnic_fix_features(struct net_device *netdev,
  1398. netdev_features_t features);
  1399. int qlcnic_set_features(struct net_device *netdev, netdev_features_t features);
  1400. int qlcnic_config_bridged_mode(struct qlcnic_adapter *adapter, u32 enable);
  1401. void qlcnic_update_cmd_producer(struct qlcnic_host_tx_ring *);
  1402. /* Functions from qlcnic_ethtool.c */
  1403. int qlcnic_check_loopback_buff(unsigned char *, u8 []);
  1404. int qlcnic_do_lb_test(struct qlcnic_adapter *, u8);
  1405. /* Functions from qlcnic_main.c */
  1406. int qlcnic_reset_context(struct qlcnic_adapter *);
  1407. void qlcnic_diag_free_res(struct net_device *netdev, int);
  1408. int qlcnic_diag_alloc_res(struct net_device *netdev, int);
  1409. netdev_tx_t qlcnic_xmit_frame(struct sk_buff *, struct net_device *);
  1410. void qlcnic_set_tx_ring_count(struct qlcnic_adapter *, u8);
  1411. void qlcnic_set_sds_ring_count(struct qlcnic_adapter *, u8);
  1412. int qlcnic_setup_rings(struct qlcnic_adapter *);
  1413. int qlcnic_validate_rings(struct qlcnic_adapter *, __u32, int);
  1414. void qlcnic_alloc_lb_filters_mem(struct qlcnic_adapter *adapter);
  1415. int qlcnic_enable_msix(struct qlcnic_adapter *, u32);
  1416. void qlcnic_set_drv_version(struct qlcnic_adapter *);
  1417. /* eSwitch management functions */
  1418. int qlcnic_config_switch_port(struct qlcnic_adapter *,
  1419. struct qlcnic_esw_func_cfg *);
  1420. int qlcnic_get_eswitch_port_config(struct qlcnic_adapter *,
  1421. struct qlcnic_esw_func_cfg *);
  1422. int qlcnic_config_port_mirroring(struct qlcnic_adapter *, u8, u8, u8);
  1423. int qlcnic_get_port_stats(struct qlcnic_adapter *, const u8, const u8,
  1424. struct __qlcnic_esw_statistics *);
  1425. int qlcnic_get_eswitch_stats(struct qlcnic_adapter *, const u8, u8,
  1426. struct __qlcnic_esw_statistics *);
  1427. int qlcnic_clear_esw_stats(struct qlcnic_adapter *adapter, u8, u8, u8);
  1428. int qlcnic_get_mac_stats(struct qlcnic_adapter *, struct qlcnic_mac_statistics *);
  1429. void qlcnic_free_mbx_args(struct qlcnic_cmd_args *cmd);
  1430. int qlcnic_alloc_sds_rings(struct qlcnic_recv_context *, int);
  1431. void qlcnic_free_sds_rings(struct qlcnic_recv_context *);
  1432. void qlcnic_advert_link_change(struct qlcnic_adapter *, int);
  1433. void qlcnic_free_tx_rings(struct qlcnic_adapter *);
  1434. int qlcnic_alloc_tx_rings(struct qlcnic_adapter *, struct net_device *);
  1435. void qlcnic_dump_mbx(struct qlcnic_adapter *, struct qlcnic_cmd_args *);
  1436. void qlcnic_create_sysfs_entries(struct qlcnic_adapter *adapter);
  1437. void qlcnic_remove_sysfs_entries(struct qlcnic_adapter *adapter);
  1438. void qlcnic_82xx_add_sysfs(struct qlcnic_adapter *adapter);
  1439. void qlcnic_82xx_remove_sysfs(struct qlcnic_adapter *adapter);
  1440. int qlcnicvf_config_bridged_mode(struct qlcnic_adapter *, u32);
  1441. int qlcnicvf_config_led(struct qlcnic_adapter *, u32, u32);
  1442. void qlcnic_set_vlan_config(struct qlcnic_adapter *,
  1443. struct qlcnic_esw_func_cfg *);
  1444. void qlcnic_set_eswitch_port_features(struct qlcnic_adapter *,
  1445. struct qlcnic_esw_func_cfg *);
  1446. int qlcnic_setup_tss_rss_intr(struct qlcnic_adapter *);
  1447. void qlcnic_down(struct qlcnic_adapter *, struct net_device *);
  1448. int qlcnic_up(struct qlcnic_adapter *, struct net_device *);
  1449. void __qlcnic_down(struct qlcnic_adapter *, struct net_device *);
  1450. void qlcnic_detach(struct qlcnic_adapter *);
  1451. void qlcnic_teardown_intr(struct qlcnic_adapter *);
  1452. int qlcnic_attach(struct qlcnic_adapter *);
  1453. int __qlcnic_up(struct qlcnic_adapter *, struct net_device *);
  1454. void qlcnic_restore_indev_addr(struct net_device *, unsigned long);
  1455. int qlcnic_check_temp(struct qlcnic_adapter *);
  1456. int qlcnic_init_pci_info(struct qlcnic_adapter *);
  1457. int qlcnic_set_default_offload_settings(struct qlcnic_adapter *);
  1458. int qlcnic_reset_npar_config(struct qlcnic_adapter *);
  1459. int qlcnic_set_eswitch_port_config(struct qlcnic_adapter *);
  1460. int qlcnic_set_vxlan_port(struct qlcnic_adapter *adapter, u16 port);
  1461. int qlcnic_set_vxlan_parsing(struct qlcnic_adapter *adapter, u16 port);
  1462. int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter);
  1463. int qlcnic_read_mac_addr(struct qlcnic_adapter *);
  1464. int qlcnic_setup_netdev(struct qlcnic_adapter *, struct net_device *);
  1465. void qlcnic_set_netdev_features(struct qlcnic_adapter *,
  1466. struct qlcnic_esw_func_cfg *);
  1467. void qlcnic_sriov_vf_set_multi(struct net_device *);
  1468. int qlcnic_is_valid_nic_func(struct qlcnic_adapter *, u8);
  1469. int qlcnic_get_pci_func_type(struct qlcnic_adapter *, u16, u16 *, u16 *,
  1470. u16 *);
  1471. /*
  1472. * QLOGIC Board information
  1473. */
  1474. #define QLCNIC_MAX_BOARD_NAME_LEN 100
  1475. struct qlcnic_board_info {
  1476. unsigned short vendor;
  1477. unsigned short device;
  1478. unsigned short sub_vendor;
  1479. unsigned short sub_device;
  1480. char short_name[QLCNIC_MAX_BOARD_NAME_LEN];
  1481. };
  1482. static inline u32 qlcnic_tx_avail(struct qlcnic_host_tx_ring *tx_ring)
  1483. {
  1484. if (likely(tx_ring->producer < tx_ring->sw_consumer))
  1485. return tx_ring->sw_consumer - tx_ring->producer;
  1486. else
  1487. return tx_ring->sw_consumer + tx_ring->num_desc -
  1488. tx_ring->producer;
  1489. }
  1490. struct qlcnic_nic_template {
  1491. int (*config_bridged_mode) (struct qlcnic_adapter *, u32);
  1492. int (*config_led) (struct qlcnic_adapter *, u32, u32);
  1493. int (*start_firmware) (struct qlcnic_adapter *);
  1494. int (*init_driver) (struct qlcnic_adapter *);
  1495. void (*request_reset) (struct qlcnic_adapter *, u32);
  1496. void (*cancel_idc_work) (struct qlcnic_adapter *);
  1497. int (*napi_add)(struct qlcnic_adapter *, struct net_device *);
  1498. void (*napi_del)(struct qlcnic_adapter *);
  1499. void (*config_ipaddr)(struct qlcnic_adapter *, __be32, int);
  1500. irqreturn_t (*clear_legacy_intr)(struct qlcnic_adapter *);
  1501. int (*shutdown)(struct pci_dev *);
  1502. int (*resume)(struct qlcnic_adapter *);
  1503. };
  1504. struct qlcnic_mbx_ops {
  1505. int (*enqueue_cmd) (struct qlcnic_adapter *,
  1506. struct qlcnic_cmd_args *, unsigned long *);
  1507. void (*dequeue_cmd) (struct qlcnic_adapter *, struct qlcnic_cmd_args *);
  1508. void (*decode_resp) (struct qlcnic_adapter *, struct qlcnic_cmd_args *);
  1509. void (*encode_cmd) (struct qlcnic_adapter *, struct qlcnic_cmd_args *);
  1510. void (*nofity_fw) (struct qlcnic_adapter *, u8);
  1511. };
  1512. int qlcnic_83xx_init_mailbox_work(struct qlcnic_adapter *);
  1513. void qlcnic_83xx_detach_mailbox_work(struct qlcnic_adapter *);
  1514. void qlcnic_83xx_reinit_mbx_work(struct qlcnic_mailbox *mbx);
  1515. void qlcnic_83xx_free_mailbox(struct qlcnic_mailbox *mbx);
  1516. void qlcnic_update_stats(struct qlcnic_adapter *);
  1517. /* Adapter hardware abstraction */
  1518. struct qlcnic_hardware_ops {
  1519. void (*read_crb) (struct qlcnic_adapter *, char *, loff_t, size_t);
  1520. void (*write_crb) (struct qlcnic_adapter *, char *, loff_t, size_t);
  1521. int (*read_reg) (struct qlcnic_adapter *, ulong, int *);
  1522. int (*write_reg) (struct qlcnic_adapter *, ulong, u32);
  1523. void (*get_ocm_win) (struct qlcnic_hardware_context *);
  1524. int (*get_mac_address) (struct qlcnic_adapter *, u8 *, u8);
  1525. int (*setup_intr) (struct qlcnic_adapter *);
  1526. int (*alloc_mbx_args)(struct qlcnic_cmd_args *,
  1527. struct qlcnic_adapter *, u32);
  1528. int (*mbx_cmd) (struct qlcnic_adapter *, struct qlcnic_cmd_args *);
  1529. void (*get_func_no) (struct qlcnic_adapter *);
  1530. int (*api_lock) (struct qlcnic_adapter *);
  1531. void (*api_unlock) (struct qlcnic_adapter *);
  1532. void (*add_sysfs) (struct qlcnic_adapter *);
  1533. void (*remove_sysfs) (struct qlcnic_adapter *);
  1534. void (*process_lb_rcv_ring_diag) (struct qlcnic_host_sds_ring *);
  1535. int (*create_rx_ctx) (struct qlcnic_adapter *);
  1536. int (*create_tx_ctx) (struct qlcnic_adapter *,
  1537. struct qlcnic_host_tx_ring *, int);
  1538. void (*del_rx_ctx) (struct qlcnic_adapter *);
  1539. void (*del_tx_ctx) (struct qlcnic_adapter *,
  1540. struct qlcnic_host_tx_ring *);
  1541. int (*setup_link_event) (struct qlcnic_adapter *, int);
  1542. int (*get_nic_info) (struct qlcnic_adapter *, struct qlcnic_info *, u8);
  1543. int (*get_pci_info) (struct qlcnic_adapter *, struct qlcnic_pci_info *);
  1544. int (*set_nic_info) (struct qlcnic_adapter *, struct qlcnic_info *);
  1545. int (*change_macvlan) (struct qlcnic_adapter *, u8*, u16, u8);
  1546. void (*napi_enable) (struct qlcnic_adapter *);
  1547. void (*napi_disable) (struct qlcnic_adapter *);
  1548. int (*config_intr_coal) (struct qlcnic_adapter *,
  1549. struct ethtool_coalesce *);
  1550. int (*config_rss) (struct qlcnic_adapter *, int);
  1551. int (*config_hw_lro) (struct qlcnic_adapter *, int);
  1552. int (*config_loopback) (struct qlcnic_adapter *, u8);
  1553. int (*clear_loopback) (struct qlcnic_adapter *, u8);
  1554. int (*config_promisc_mode) (struct qlcnic_adapter *, u32);
  1555. void (*change_l2_filter)(struct qlcnic_adapter *adapter, u64 *addr,
  1556. u16 vlan, struct qlcnic_host_tx_ring *tx_ring);
  1557. int (*get_board_info) (struct qlcnic_adapter *);
  1558. void (*set_mac_filter_count) (struct qlcnic_adapter *);
  1559. void (*free_mac_list) (struct qlcnic_adapter *);
  1560. int (*read_phys_port_id) (struct qlcnic_adapter *);
  1561. pci_ers_result_t (*io_error_detected) (struct pci_dev *,
  1562. pci_channel_state_t);
  1563. pci_ers_result_t (*io_slot_reset) (struct pci_dev *);
  1564. void (*io_resume) (struct pci_dev *);
  1565. void (*get_beacon_state)(struct qlcnic_adapter *);
  1566. void (*enable_sds_intr) (struct qlcnic_adapter *,
  1567. struct qlcnic_host_sds_ring *);
  1568. void (*disable_sds_intr) (struct qlcnic_adapter *,
  1569. struct qlcnic_host_sds_ring *);
  1570. void (*enable_tx_intr) (struct qlcnic_adapter *,
  1571. struct qlcnic_host_tx_ring *);
  1572. void (*disable_tx_intr) (struct qlcnic_adapter *,
  1573. struct qlcnic_host_tx_ring *);
  1574. u32 (*get_saved_state)(void *, u32);
  1575. void (*set_saved_state)(void *, u32, u32);
  1576. void (*cache_tmpl_hdr_values)(struct qlcnic_fw_dump *);
  1577. u32 (*get_cap_size)(void *, int);
  1578. void (*set_sys_info)(void *, int, u32);
  1579. void (*store_cap_mask)(void *, u32);
  1580. bool (*encap_rx_offload) (struct qlcnic_adapter *adapter);
  1581. bool (*encap_tx_offload) (struct qlcnic_adapter *adapter);
  1582. };
  1583. extern struct qlcnic_nic_template qlcnic_vf_ops;
  1584. static inline bool qlcnic_83xx_encap_tx_offload(struct qlcnic_adapter *adapter)
  1585. {
  1586. return adapter->ahw->extra_capability[0] &
  1587. QLCNIC_83XX_FW_CAPAB_ENCAP_TX_OFFLOAD;
  1588. }
  1589. static inline bool qlcnic_83xx_encap_rx_offload(struct qlcnic_adapter *adapter)
  1590. {
  1591. return adapter->ahw->extra_capability[0] &
  1592. QLCNIC_83XX_FW_CAPAB_ENCAP_RX_OFFLOAD;
  1593. }
  1594. static inline bool qlcnic_82xx_encap_tx_offload(struct qlcnic_adapter *adapter)
  1595. {
  1596. return false;
  1597. }
  1598. static inline bool qlcnic_82xx_encap_rx_offload(struct qlcnic_adapter *adapter)
  1599. {
  1600. return false;
  1601. }
  1602. static inline bool qlcnic_encap_rx_offload(struct qlcnic_adapter *adapter)
  1603. {
  1604. return adapter->ahw->hw_ops->encap_rx_offload(adapter);
  1605. }
  1606. static inline bool qlcnic_encap_tx_offload(struct qlcnic_adapter *adapter)
  1607. {
  1608. return adapter->ahw->hw_ops->encap_tx_offload(adapter);
  1609. }
  1610. static inline int qlcnic_start_firmware(struct qlcnic_adapter *adapter)
  1611. {
  1612. return adapter->nic_ops->start_firmware(adapter);
  1613. }
  1614. static inline void qlcnic_read_crb(struct qlcnic_adapter *adapter, char *buf,
  1615. loff_t offset, size_t size)
  1616. {
  1617. adapter->ahw->hw_ops->read_crb(adapter, buf, offset, size);
  1618. }
  1619. static inline void qlcnic_write_crb(struct qlcnic_adapter *adapter, char *buf,
  1620. loff_t offset, size_t size)
  1621. {
  1622. adapter->ahw->hw_ops->write_crb(adapter, buf, offset, size);
  1623. }
  1624. static inline int qlcnic_get_mac_address(struct qlcnic_adapter *adapter,
  1625. u8 *mac, u8 function)
  1626. {
  1627. return adapter->ahw->hw_ops->get_mac_address(adapter, mac, function);
  1628. }
  1629. static inline int qlcnic_setup_intr(struct qlcnic_adapter *adapter)
  1630. {
  1631. return adapter->ahw->hw_ops->setup_intr(adapter);
  1632. }
  1633. static inline int qlcnic_alloc_mbx_args(struct qlcnic_cmd_args *mbx,
  1634. struct qlcnic_adapter *adapter, u32 arg)
  1635. {
  1636. return adapter->ahw->hw_ops->alloc_mbx_args(mbx, adapter, arg);
  1637. }
  1638. static inline int qlcnic_issue_cmd(struct qlcnic_adapter *adapter,
  1639. struct qlcnic_cmd_args *cmd)
  1640. {
  1641. if (adapter->ahw->hw_ops->mbx_cmd)
  1642. return adapter->ahw->hw_ops->mbx_cmd(adapter, cmd);
  1643. return -EIO;
  1644. }
  1645. static inline void qlcnic_get_func_no(struct qlcnic_adapter *adapter)
  1646. {
  1647. adapter->ahw->hw_ops->get_func_no(adapter);
  1648. }
  1649. static inline int qlcnic_api_lock(struct qlcnic_adapter *adapter)
  1650. {
  1651. return adapter->ahw->hw_ops->api_lock(adapter);
  1652. }
  1653. static inline void qlcnic_api_unlock(struct qlcnic_adapter *adapter)
  1654. {
  1655. adapter->ahw->hw_ops->api_unlock(adapter);
  1656. }
  1657. static inline void qlcnic_add_sysfs(struct qlcnic_adapter *adapter)
  1658. {
  1659. if (adapter->ahw->hw_ops->add_sysfs)
  1660. adapter->ahw->hw_ops->add_sysfs(adapter);
  1661. }
  1662. static inline void qlcnic_remove_sysfs(struct qlcnic_adapter *adapter)
  1663. {
  1664. if (adapter->ahw->hw_ops->remove_sysfs)
  1665. adapter->ahw->hw_ops->remove_sysfs(adapter);
  1666. }
  1667. static inline void
  1668. qlcnic_process_rcv_ring_diag(struct qlcnic_host_sds_ring *sds_ring)
  1669. {
  1670. sds_ring->adapter->ahw->hw_ops->process_lb_rcv_ring_diag(sds_ring);
  1671. }
  1672. static inline int qlcnic_fw_cmd_create_rx_ctx(struct qlcnic_adapter *adapter)
  1673. {
  1674. return adapter->ahw->hw_ops->create_rx_ctx(adapter);
  1675. }
  1676. static inline int qlcnic_fw_cmd_create_tx_ctx(struct qlcnic_adapter *adapter,
  1677. struct qlcnic_host_tx_ring *ptr,
  1678. int ring)
  1679. {
  1680. return adapter->ahw->hw_ops->create_tx_ctx(adapter, ptr, ring);
  1681. }
  1682. static inline void qlcnic_fw_cmd_del_rx_ctx(struct qlcnic_adapter *adapter)
  1683. {
  1684. return adapter->ahw->hw_ops->del_rx_ctx(adapter);
  1685. }
  1686. static inline void qlcnic_fw_cmd_del_tx_ctx(struct qlcnic_adapter *adapter,
  1687. struct qlcnic_host_tx_ring *ptr)
  1688. {
  1689. return adapter->ahw->hw_ops->del_tx_ctx(adapter, ptr);
  1690. }
  1691. static inline int qlcnic_linkevent_request(struct qlcnic_adapter *adapter,
  1692. int enable)
  1693. {
  1694. return adapter->ahw->hw_ops->setup_link_event(adapter, enable);
  1695. }
  1696. static inline int qlcnic_get_nic_info(struct qlcnic_adapter *adapter,
  1697. struct qlcnic_info *info, u8 id)
  1698. {
  1699. return adapter->ahw->hw_ops->get_nic_info(adapter, info, id);
  1700. }
  1701. static inline int qlcnic_get_pci_info(struct qlcnic_adapter *adapter,
  1702. struct qlcnic_pci_info *info)
  1703. {
  1704. return adapter->ahw->hw_ops->get_pci_info(adapter, info);
  1705. }
  1706. static inline int qlcnic_set_nic_info(struct qlcnic_adapter *adapter,
  1707. struct qlcnic_info *info)
  1708. {
  1709. return adapter->ahw->hw_ops->set_nic_info(adapter, info);
  1710. }
  1711. static inline int qlcnic_sre_macaddr_change(struct qlcnic_adapter *adapter,
  1712. u8 *addr, u16 id, u8 cmd)
  1713. {
  1714. return adapter->ahw->hw_ops->change_macvlan(adapter, addr, id, cmd);
  1715. }
  1716. static inline int qlcnic_napi_add(struct qlcnic_adapter *adapter,
  1717. struct net_device *netdev)
  1718. {
  1719. return adapter->nic_ops->napi_add(adapter, netdev);
  1720. }
  1721. static inline void qlcnic_napi_del(struct qlcnic_adapter *adapter)
  1722. {
  1723. adapter->nic_ops->napi_del(adapter);
  1724. }
  1725. static inline void qlcnic_napi_enable(struct qlcnic_adapter *adapter)
  1726. {
  1727. adapter->ahw->hw_ops->napi_enable(adapter);
  1728. }
  1729. static inline int __qlcnic_shutdown(struct pci_dev *pdev)
  1730. {
  1731. struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
  1732. return adapter->nic_ops->shutdown(pdev);
  1733. }
  1734. static inline int __qlcnic_resume(struct qlcnic_adapter *adapter)
  1735. {
  1736. return adapter->nic_ops->resume(adapter);
  1737. }
  1738. static inline void qlcnic_napi_disable(struct qlcnic_adapter *adapter)
  1739. {
  1740. adapter->ahw->hw_ops->napi_disable(adapter);
  1741. }
  1742. static inline int qlcnic_config_intr_coalesce(struct qlcnic_adapter *adapter,
  1743. struct ethtool_coalesce *ethcoal)
  1744. {
  1745. return adapter->ahw->hw_ops->config_intr_coal(adapter, ethcoal);
  1746. }
  1747. static inline int qlcnic_config_rss(struct qlcnic_adapter *adapter, int enable)
  1748. {
  1749. return adapter->ahw->hw_ops->config_rss(adapter, enable);
  1750. }
  1751. static inline int qlcnic_config_hw_lro(struct qlcnic_adapter *adapter,
  1752. int enable)
  1753. {
  1754. return adapter->ahw->hw_ops->config_hw_lro(adapter, enable);
  1755. }
  1756. static inline int qlcnic_set_lb_mode(struct qlcnic_adapter *adapter, u8 mode)
  1757. {
  1758. return adapter->ahw->hw_ops->config_loopback(adapter, mode);
  1759. }
  1760. static inline int qlcnic_clear_lb_mode(struct qlcnic_adapter *adapter, u8 mode)
  1761. {
  1762. return adapter->ahw->hw_ops->clear_loopback(adapter, mode);
  1763. }
  1764. static inline int qlcnic_nic_set_promisc(struct qlcnic_adapter *adapter,
  1765. u32 mode)
  1766. {
  1767. return adapter->ahw->hw_ops->config_promisc_mode(adapter, mode);
  1768. }
  1769. static inline void qlcnic_change_filter(struct qlcnic_adapter *adapter,
  1770. u64 *addr, u16 vlan,
  1771. struct qlcnic_host_tx_ring *tx_ring)
  1772. {
  1773. adapter->ahw->hw_ops->change_l2_filter(adapter, addr, vlan, tx_ring);
  1774. }
  1775. static inline int qlcnic_get_board_info(struct qlcnic_adapter *adapter)
  1776. {
  1777. return adapter->ahw->hw_ops->get_board_info(adapter);
  1778. }
  1779. static inline void qlcnic_free_mac_list(struct qlcnic_adapter *adapter)
  1780. {
  1781. return adapter->ahw->hw_ops->free_mac_list(adapter);
  1782. }
  1783. static inline void qlcnic_set_mac_filter_count(struct qlcnic_adapter *adapter)
  1784. {
  1785. if (adapter->ahw->hw_ops->set_mac_filter_count)
  1786. adapter->ahw->hw_ops->set_mac_filter_count(adapter);
  1787. }
  1788. static inline void qlcnic_get_beacon_state(struct qlcnic_adapter *adapter)
  1789. {
  1790. adapter->ahw->hw_ops->get_beacon_state(adapter);
  1791. }
  1792. static inline void qlcnic_read_phys_port_id(struct qlcnic_adapter *adapter)
  1793. {
  1794. if (adapter->ahw->hw_ops->read_phys_port_id)
  1795. adapter->ahw->hw_ops->read_phys_port_id(adapter);
  1796. }
  1797. static inline u32 qlcnic_get_saved_state(struct qlcnic_adapter *adapter,
  1798. void *t_hdr, u32 index)
  1799. {
  1800. return adapter->ahw->hw_ops->get_saved_state(t_hdr, index);
  1801. }
  1802. static inline void qlcnic_set_saved_state(struct qlcnic_adapter *adapter,
  1803. void *t_hdr, u32 index, u32 value)
  1804. {
  1805. adapter->ahw->hw_ops->set_saved_state(t_hdr, index, value);
  1806. }
  1807. static inline void qlcnic_cache_tmpl_hdr_values(struct qlcnic_adapter *adapter,
  1808. struct qlcnic_fw_dump *fw_dump)
  1809. {
  1810. adapter->ahw->hw_ops->cache_tmpl_hdr_values(fw_dump);
  1811. }
  1812. static inline u32 qlcnic_get_cap_size(struct qlcnic_adapter *adapter,
  1813. void *tmpl_hdr, int index)
  1814. {
  1815. return adapter->ahw->hw_ops->get_cap_size(tmpl_hdr, index);
  1816. }
  1817. static inline void qlcnic_set_sys_info(struct qlcnic_adapter *adapter,
  1818. void *tmpl_hdr, int idx, u32 value)
  1819. {
  1820. adapter->ahw->hw_ops->set_sys_info(tmpl_hdr, idx, value);
  1821. }
  1822. static inline void qlcnic_store_cap_mask(struct qlcnic_adapter *adapter,
  1823. void *tmpl_hdr, u32 mask)
  1824. {
  1825. adapter->ahw->hw_ops->store_cap_mask(tmpl_hdr, mask);
  1826. }
  1827. static inline void qlcnic_dev_request_reset(struct qlcnic_adapter *adapter,
  1828. u32 key)
  1829. {
  1830. if (adapter->nic_ops->request_reset)
  1831. adapter->nic_ops->request_reset(adapter, key);
  1832. }
  1833. static inline void qlcnic_cancel_idc_work(struct qlcnic_adapter *adapter)
  1834. {
  1835. if (adapter->nic_ops->cancel_idc_work)
  1836. adapter->nic_ops->cancel_idc_work(adapter);
  1837. }
  1838. static inline irqreturn_t
  1839. qlcnic_clear_legacy_intr(struct qlcnic_adapter *adapter)
  1840. {
  1841. return adapter->nic_ops->clear_legacy_intr(adapter);
  1842. }
  1843. static inline int qlcnic_config_led(struct qlcnic_adapter *adapter, u32 state,
  1844. u32 rate)
  1845. {
  1846. return adapter->nic_ops->config_led(adapter, state, rate);
  1847. }
  1848. static inline void qlcnic_config_ipaddr(struct qlcnic_adapter *adapter,
  1849. __be32 ip, int cmd)
  1850. {
  1851. adapter->nic_ops->config_ipaddr(adapter, ip, cmd);
  1852. }
  1853. static inline bool qlcnic_check_multi_tx(struct qlcnic_adapter *adapter)
  1854. {
  1855. return test_bit(__QLCNIC_MULTI_TX_UNIQUE, &adapter->state);
  1856. }
  1857. static inline void
  1858. qlcnic_82xx_enable_tx_intr(struct qlcnic_adapter *adapter,
  1859. struct qlcnic_host_tx_ring *tx_ring)
  1860. {
  1861. if (qlcnic_check_multi_tx(adapter) &&
  1862. !adapter->ahw->diag_test)
  1863. writel(0x0, tx_ring->crb_intr_mask);
  1864. }
  1865. static inline void
  1866. qlcnic_82xx_disable_tx_intr(struct qlcnic_adapter *adapter,
  1867. struct qlcnic_host_tx_ring *tx_ring)
  1868. {
  1869. if (qlcnic_check_multi_tx(adapter) &&
  1870. !adapter->ahw->diag_test)
  1871. writel(1, tx_ring->crb_intr_mask);
  1872. }
  1873. static inline void
  1874. qlcnic_83xx_enable_tx_intr(struct qlcnic_adapter *adapter,
  1875. struct qlcnic_host_tx_ring *tx_ring)
  1876. {
  1877. writel(0, tx_ring->crb_intr_mask);
  1878. }
  1879. static inline void
  1880. qlcnic_83xx_disable_tx_intr(struct qlcnic_adapter *adapter,
  1881. struct qlcnic_host_tx_ring *tx_ring)
  1882. {
  1883. writel(1, tx_ring->crb_intr_mask);
  1884. }
  1885. /* Enable MSI-x and INT-x interrupts */
  1886. static inline void
  1887. qlcnic_83xx_enable_sds_intr(struct qlcnic_adapter *adapter,
  1888. struct qlcnic_host_sds_ring *sds_ring)
  1889. {
  1890. writel(0, sds_ring->crb_intr_mask);
  1891. }
  1892. /* Disable MSI-x and INT-x interrupts */
  1893. static inline void
  1894. qlcnic_83xx_disable_sds_intr(struct qlcnic_adapter *adapter,
  1895. struct qlcnic_host_sds_ring *sds_ring)
  1896. {
  1897. writel(1, sds_ring->crb_intr_mask);
  1898. }
  1899. static inline void qlcnic_disable_multi_tx(struct qlcnic_adapter *adapter)
  1900. {
  1901. test_and_clear_bit(__QLCNIC_MULTI_TX_UNIQUE, &adapter->state);
  1902. adapter->drv_tx_rings = QLCNIC_SINGLE_RING;
  1903. }
  1904. /* When operating in a muti tx mode, driver needs to write 0x1
  1905. * to src register, instead of 0x0 to disable receiving interrupt.
  1906. */
  1907. static inline void
  1908. qlcnic_82xx_disable_sds_intr(struct qlcnic_adapter *adapter,
  1909. struct qlcnic_host_sds_ring *sds_ring)
  1910. {
  1911. if (qlcnic_check_multi_tx(adapter) &&
  1912. !adapter->ahw->diag_test &&
  1913. (adapter->flags & QLCNIC_MSIX_ENABLED))
  1914. writel(0x1, sds_ring->crb_intr_mask);
  1915. else
  1916. writel(0, sds_ring->crb_intr_mask);
  1917. }
  1918. static inline void qlcnic_enable_sds_intr(struct qlcnic_adapter *adapter,
  1919. struct qlcnic_host_sds_ring *sds_ring)
  1920. {
  1921. if (adapter->ahw->hw_ops->enable_sds_intr)
  1922. adapter->ahw->hw_ops->enable_sds_intr(adapter, sds_ring);
  1923. }
  1924. static inline void
  1925. qlcnic_disable_sds_intr(struct qlcnic_adapter *adapter,
  1926. struct qlcnic_host_sds_ring *sds_ring)
  1927. {
  1928. if (adapter->ahw->hw_ops->disable_sds_intr)
  1929. adapter->ahw->hw_ops->disable_sds_intr(adapter, sds_ring);
  1930. }
  1931. static inline void qlcnic_enable_tx_intr(struct qlcnic_adapter *adapter,
  1932. struct qlcnic_host_tx_ring *tx_ring)
  1933. {
  1934. if (adapter->ahw->hw_ops->enable_tx_intr)
  1935. adapter->ahw->hw_ops->enable_tx_intr(adapter, tx_ring);
  1936. }
  1937. static inline void qlcnic_disable_tx_intr(struct qlcnic_adapter *adapter,
  1938. struct qlcnic_host_tx_ring *tx_ring)
  1939. {
  1940. if (adapter->ahw->hw_ops->disable_tx_intr)
  1941. adapter->ahw->hw_ops->disable_tx_intr(adapter, tx_ring);
  1942. }
  1943. /* When operating in a muti tx mode, driver needs to write 0x0
  1944. * to src register, instead of 0x1 to enable receiving interrupts.
  1945. */
  1946. static inline void
  1947. qlcnic_82xx_enable_sds_intr(struct qlcnic_adapter *adapter,
  1948. struct qlcnic_host_sds_ring *sds_ring)
  1949. {
  1950. if (qlcnic_check_multi_tx(adapter) &&
  1951. !adapter->ahw->diag_test &&
  1952. (adapter->flags & QLCNIC_MSIX_ENABLED))
  1953. writel(0, sds_ring->crb_intr_mask);
  1954. else
  1955. writel(0x1, sds_ring->crb_intr_mask);
  1956. if (!QLCNIC_IS_MSI_FAMILY(adapter))
  1957. writel(0xfbff, adapter->tgt_mask_reg);
  1958. }
  1959. static inline int qlcnic_get_diag_lock(struct qlcnic_adapter *adapter)
  1960. {
  1961. return test_and_set_bit(__QLCNIC_DIAG_MODE, &adapter->state);
  1962. }
  1963. static inline void qlcnic_release_diag_lock(struct qlcnic_adapter *adapter)
  1964. {
  1965. clear_bit(__QLCNIC_DIAG_MODE, &adapter->state);
  1966. }
  1967. static inline int qlcnic_check_diag_status(struct qlcnic_adapter *adapter)
  1968. {
  1969. return test_bit(__QLCNIC_DIAG_MODE, &adapter->state);
  1970. }
  1971. extern const struct ethtool_ops qlcnic_sriov_vf_ethtool_ops;
  1972. extern const struct ethtool_ops qlcnic_ethtool_ops;
  1973. extern const struct ethtool_ops qlcnic_ethtool_failed_ops;
  1974. #define QLCDB(adapter, lvl, _fmt, _args...) do { \
  1975. if (NETIF_MSG_##lvl & adapter->ahw->msg_enable) \
  1976. printk(KERN_INFO "%s: %s: " _fmt, \
  1977. dev_name(&adapter->pdev->dev), \
  1978. __func__, ##_args); \
  1979. } while (0)
  1980. #define PCI_DEVICE_ID_QLOGIC_QLE824X 0x8020
  1981. #define PCI_DEVICE_ID_QLOGIC_QLE834X 0x8030
  1982. #define PCI_DEVICE_ID_QLOGIC_VF_QLE834X 0x8430
  1983. #define PCI_DEVICE_ID_QLOGIC_QLE8830 0x8830
  1984. #define PCI_DEVICE_ID_QLOGIC_VF_QLE8C30 0x8C30
  1985. #define PCI_DEVICE_ID_QLOGIC_QLE844X 0x8040
  1986. #define PCI_DEVICE_ID_QLOGIC_VF_QLE844X 0x8440
  1987. static inline bool qlcnic_82xx_check(struct qlcnic_adapter *adapter)
  1988. {
  1989. unsigned short device = adapter->pdev->device;
  1990. return (device == PCI_DEVICE_ID_QLOGIC_QLE824X) ? true : false;
  1991. }
  1992. static inline bool qlcnic_84xx_check(struct qlcnic_adapter *adapter)
  1993. {
  1994. unsigned short device = adapter->pdev->device;
  1995. return ((device == PCI_DEVICE_ID_QLOGIC_QLE844X) ||
  1996. (device == PCI_DEVICE_ID_QLOGIC_VF_QLE844X)) ? true : false;
  1997. }
  1998. static inline bool qlcnic_83xx_check(struct qlcnic_adapter *adapter)
  1999. {
  2000. unsigned short device = adapter->pdev->device;
  2001. bool status;
  2002. status = ((device == PCI_DEVICE_ID_QLOGIC_QLE834X) ||
  2003. (device == PCI_DEVICE_ID_QLOGIC_QLE8830) ||
  2004. (device == PCI_DEVICE_ID_QLOGIC_QLE844X) ||
  2005. (device == PCI_DEVICE_ID_QLOGIC_VF_QLE844X) ||
  2006. (device == PCI_DEVICE_ID_QLOGIC_VF_QLE834X) ||
  2007. (device == PCI_DEVICE_ID_QLOGIC_VF_QLE8C30)) ? true : false;
  2008. return status;
  2009. }
  2010. static inline bool qlcnic_sriov_pf_check(struct qlcnic_adapter *adapter)
  2011. {
  2012. return (adapter->ahw->op_mode == QLCNIC_SRIOV_PF_FUNC) ? true : false;
  2013. }
  2014. static inline bool qlcnic_sriov_vf_check(struct qlcnic_adapter *adapter)
  2015. {
  2016. unsigned short device = adapter->pdev->device;
  2017. bool status;
  2018. status = ((device == PCI_DEVICE_ID_QLOGIC_VF_QLE834X) ||
  2019. (device == PCI_DEVICE_ID_QLOGIC_VF_QLE844X) ||
  2020. (device == PCI_DEVICE_ID_QLOGIC_VF_QLE8C30)) ? true : false;
  2021. return status;
  2022. }
  2023. static inline bool qlcnic_83xx_pf_check(struct qlcnic_adapter *adapter)
  2024. {
  2025. unsigned short device = adapter->pdev->device;
  2026. return (device == PCI_DEVICE_ID_QLOGIC_QLE834X) ? true : false;
  2027. }
  2028. static inline bool qlcnic_83xx_vf_check(struct qlcnic_adapter *adapter)
  2029. {
  2030. unsigned short device = adapter->pdev->device;
  2031. return ((device == PCI_DEVICE_ID_QLOGIC_VF_QLE834X) ||
  2032. (device == PCI_DEVICE_ID_QLOGIC_VF_QLE8C30)) ? true : false;
  2033. }
  2034. static inline bool qlcnic_sriov_check(struct qlcnic_adapter *adapter)
  2035. {
  2036. bool status;
  2037. status = (qlcnic_sriov_pf_check(adapter) ||
  2038. qlcnic_sriov_vf_check(adapter)) ? true : false;
  2039. return status;
  2040. }
  2041. static inline u32 qlcnic_get_vnic_func_count(struct qlcnic_adapter *adapter)
  2042. {
  2043. if (qlcnic_84xx_check(adapter))
  2044. return QLC_84XX_VNIC_COUNT;
  2045. else
  2046. return QLC_DEFAULT_VNIC_COUNT;
  2047. }
  2048. static inline void qlcnic_swap32_buffer(u32 *buffer, int count)
  2049. {
  2050. #if defined(__BIG_ENDIAN)
  2051. u32 *tmp = buffer;
  2052. int i;
  2053. for (i = 0; i < count; i++) {
  2054. *tmp = swab32(*tmp);
  2055. tmp++;
  2056. }
  2057. #endif
  2058. }
  2059. #ifdef CONFIG_QLCNIC_HWMON
  2060. void qlcnic_register_hwmon_dev(struct qlcnic_adapter *);
  2061. void qlcnic_unregister_hwmon_dev(struct qlcnic_adapter *);
  2062. #else
  2063. static inline void qlcnic_register_hwmon_dev(struct qlcnic_adapter *adapter)
  2064. {
  2065. return;
  2066. }
  2067. static inline void qlcnic_unregister_hwmon_dev(struct qlcnic_adapter *adapter)
  2068. {
  2069. return;
  2070. }
  2071. #endif
  2072. #endif /* __QLCNIC_H_ */