lpfc.h 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2017-2024 Broadcom. All Rights Reserved. The term *
  5. * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
  6. * Copyright (C) 2004-2016 Emulex. All rights reserved. *
  7. * EMULEX and SLI are trademarks of Emulex. *
  8. * www.broadcom.com *
  9. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  10. * *
  11. * This program is free software; you can redistribute it and/or *
  12. * modify it under the terms of version 2 of the GNU General *
  13. * Public License as published by the Free Software Foundation. *
  14. * This program is distributed in the hope that it will be useful. *
  15. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  16. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  17. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  18. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  19. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  20. * more details, a copy of which can be found in the file COPYING *
  21. * included with this package. *
  22. *******************************************************************/
  23. #include <scsi/scsi_host.h>
  24. #include <linux/hashtable.h>
  25. #include <linux/ktime.h>
  26. #include <linux/workqueue.h>
  27. #if defined(CONFIG_DEBUG_FS) && !defined(CONFIG_SCSI_LPFC_DEBUG_FS)
  28. #define CONFIG_SCSI_LPFC_DEBUG_FS
  29. #endif
  30. struct lpfc_sli2_slim;
  31. #define ELX_MODEL_NAME_SIZE 80
  32. #define ELX_FW_NAME_SIZE 84
  33. #define LPFC_PCI_DEV_LP 0x1
  34. #define LPFC_PCI_DEV_OC 0x2
  35. #define LPFC_SLI_REV2 2
  36. #define LPFC_SLI_REV3 3
  37. #define LPFC_SLI_REV4 4
  38. #define LPFC_MAX_TARGET 4096 /* max number of targets supported */
  39. #define LPFC_MAX_DISC_THREADS 64 /* max outstanding discovery els
  40. requests */
  41. #define LPFC_MAX_NS_RETRY 3 /* Number of retry attempts to contact
  42. the NameServer before giving up. */
  43. #define LPFC_CMD_PER_LUN 3 /* max outstanding cmds per lun */
  44. #define LPFC_DEFAULT_SG_SEG_CNT 64 /* sg element count per scsi cmnd */
  45. #define LPFC_DEFAULT_XPSGL_SIZE 256
  46. #define LPFC_MAX_SG_TABLESIZE 0xffff
  47. #define LPFC_MIN_SG_SLI4_BUF_SZ 0x800 /* based on LPFC_DEFAULT_SG_SEG_CNT */
  48. #define LPFC_MAX_BG_SLI4_SEG_CNT_DIF 128 /* sg element count for BlockGuard */
  49. #define LPFC_MAX_SG_SEG_CNT_DIF 512 /* sg element count per scsi cmnd */
  50. #define LPFC_MAX_SG_SEG_CNT 4096 /* sg element count per scsi cmnd */
  51. #define LPFC_MIN_SG_SEG_CNT 32 /* sg element count per scsi cmnd */
  52. #define LPFC_MAX_SGL_SEG_CNT 512 /* SGL element count per scsi cmnd */
  53. #define LPFC_MAX_BPL_SEG_CNT 4096 /* BPL element count per scsi cmnd */
  54. #define LPFC_MAX_NVME_SEG_CNT 256 /* max SGL element cnt per NVME cmnd */
  55. #define LPFC_MAX_SGE_SIZE 0x80000000 /* Maximum data allowed in a SGE */
  56. #define LPFC_IOCB_LIST_CNT 2250 /* list of IOCBs for fast-path usage. */
  57. #define LPFC_Q_RAMP_UP_INTERVAL 120 /* lun q_depth ramp up interval */
  58. #define LPFC_VNAME_LEN 100 /* vport symbolic name length */
  59. #define LPFC_TGTQ_RAMPUP_PCENT 5 /* Target queue rampup in percentage */
  60. #define LPFC_MIN_TGT_QDEPTH 10
  61. #define LPFC_MAX_TGT_QDEPTH 0xFFFF
  62. /*
  63. * Following time intervals are used of adjusting SCSI device
  64. * queue depths when there are driver resource error or Firmware
  65. * resource error.
  66. */
  67. /* 1 Second */
  68. #define QUEUE_RAMP_DOWN_INTERVAL (msecs_to_jiffies(1000 * 1))
  69. /* Number of exchanges reserved for discovery to complete */
  70. #define LPFC_DISC_IOCB_BUFF_COUNT 20
  71. #define LPFC_HB_MBOX_INTERVAL 5 /* Heart beat interval in seconds. */
  72. #define LPFC_HB_MBOX_TIMEOUT 30 /* Heart beat timeout in seconds. */
  73. /* Error Attention event polling interval */
  74. #define LPFC_ERATT_POLL_INTERVAL 5 /* EATT poll interval in seconds */
  75. /* Define macros for 64 bit support */
  76. #define putPaddrLow(addr) ((uint32_t) (0xffffffff & (u64)(addr)))
  77. #define putPaddrHigh(addr) ((uint32_t) (0xffffffff & (((u64)(addr))>>32)))
  78. #define getPaddr(high, low) ((dma_addr_t)( \
  79. (( (u64)(high)<<16 ) << 16)|( (u64)(low))))
  80. /* Provide maximum configuration definitions. */
  81. #define LPFC_DRVR_TIMEOUT 16 /* driver iocb timeout value in sec */
  82. #define FC_MAX_ADPTMSG 64
  83. #define MAX_HBAEVT 32
  84. #define MAX_HBAS_NO_RESET 16
  85. /* Number of MSI-X vectors the driver uses */
  86. #define LPFC_MSIX_VECTORS 2
  87. /* lpfc wait event data ready flag */
  88. #define LPFC_DATA_READY 0 /* bit 0 */
  89. /* queue dump line buffer size */
  90. #define LPFC_LBUF_SZ 128
  91. /* mailbox system shutdown options */
  92. #define LPFC_MBX_NO_WAIT 0
  93. #define LPFC_MBX_WAIT 1
  94. #define LPFC_CFG_PARAM_MAGIC_NUM 0xFEAA0005
  95. #define LPFC_PORT_CFG_NAME "/cfg/port.cfg"
  96. #define lpfc_rangecheck(val, min, max) \
  97. ((uint)(val) >= (uint)(min) && (val) <= (max))
  98. enum lpfc_polling_flags {
  99. ENABLE_FCP_RING_POLLING = 0x1,
  100. DISABLE_FCP_RING_INT = 0x2
  101. };
  102. struct perf_prof {
  103. uint16_t cmd_cpu[40];
  104. uint16_t rsp_cpu[40];
  105. uint16_t qh_cpu[40];
  106. uint16_t wqidx[40];
  107. };
  108. /*
  109. * Provide for FC4 TYPE x28 - NVME. The
  110. * bit mask for FCP and NVME is 0x8 identically
  111. * because they are 32 bit positions distance.
  112. */
  113. #define LPFC_FC4_TYPE_BITMASK 0x00000100
  114. /* Provide DMA memory definitions the driver uses per port instance. */
  115. struct lpfc_dmabuf {
  116. struct list_head list;
  117. void *virt; /* virtual address ptr */
  118. dma_addr_t phys; /* mapped address */
  119. uint32_t buffer_tag; /* used for tagged queue ring */
  120. };
  121. struct lpfc_nvmet_ctxbuf {
  122. struct list_head list;
  123. struct lpfc_async_xchg_ctx *context;
  124. struct lpfc_iocbq *iocbq;
  125. struct lpfc_sglq *sglq;
  126. struct work_struct defer_work;
  127. };
  128. struct lpfc_dma_pool {
  129. struct lpfc_dmabuf *elements;
  130. uint32_t max_count;
  131. uint32_t current_count;
  132. };
  133. struct hbq_dmabuf {
  134. struct lpfc_dmabuf hbuf;
  135. struct lpfc_dmabuf dbuf;
  136. uint16_t total_size;
  137. uint16_t bytes_recv;
  138. uint32_t tag;
  139. struct lpfc_cq_event cq_event;
  140. unsigned long time_stamp;
  141. void *context;
  142. };
  143. struct rqb_dmabuf {
  144. struct lpfc_dmabuf hbuf;
  145. struct lpfc_dmabuf dbuf;
  146. uint16_t total_size;
  147. uint16_t bytes_recv;
  148. uint16_t idx;
  149. struct lpfc_queue *hrq; /* ptr to associated Header RQ */
  150. struct lpfc_queue *drq; /* ptr to associated Data RQ */
  151. };
  152. /* Priority bit. Set value to exceed low water mark in lpfc_mem. */
  153. #define MEM_PRI 0x100
  154. /****************************************************************************/
  155. /* Device VPD save area */
  156. /****************************************************************************/
  157. typedef struct lpfc_vpd {
  158. uint32_t status; /* vpd status value */
  159. uint32_t length; /* number of bytes actually returned */
  160. struct {
  161. uint32_t rsvd1; /* Revision numbers */
  162. uint32_t biuRev;
  163. uint32_t smRev;
  164. uint32_t smFwRev;
  165. uint32_t endecRev;
  166. uint16_t rBit;
  167. uint8_t fcphHigh;
  168. uint8_t fcphLow;
  169. uint8_t feaLevelHigh;
  170. uint8_t feaLevelLow;
  171. uint32_t postKernRev;
  172. uint32_t opFwRev;
  173. uint8_t opFwName[16];
  174. uint32_t sli1FwRev;
  175. uint8_t sli1FwName[16];
  176. uint32_t sli2FwRev;
  177. uint8_t sli2FwName[16];
  178. } rev;
  179. struct {
  180. #ifdef __BIG_ENDIAN_BITFIELD
  181. uint32_t rsvd3 :20; /* Reserved */
  182. uint32_t rsvd2 : 3; /* Reserved */
  183. uint32_t cbg : 1; /* Configure BlockGuard */
  184. uint32_t cmv : 1; /* Configure Max VPIs */
  185. uint32_t ccrp : 1; /* Config Command Ring Polling */
  186. uint32_t csah : 1; /* Configure Synchronous Abort Handling */
  187. uint32_t chbs : 1; /* Cofigure Host Backing store */
  188. uint32_t cinb : 1; /* Enable Interrupt Notification Block */
  189. uint32_t cerbm : 1; /* Configure Enhanced Receive Buf Mgmt */
  190. uint32_t cmx : 1; /* Configure Max XRIs */
  191. uint32_t cmr : 1; /* Configure Max RPIs */
  192. #else /* __LITTLE_ENDIAN */
  193. uint32_t cmr : 1; /* Configure Max RPIs */
  194. uint32_t cmx : 1; /* Configure Max XRIs */
  195. uint32_t cerbm : 1; /* Configure Enhanced Receive Buf Mgmt */
  196. uint32_t cinb : 1; /* Enable Interrupt Notification Block */
  197. uint32_t chbs : 1; /* Cofigure Host Backing store */
  198. uint32_t csah : 1; /* Configure Synchronous Abort Handling */
  199. uint32_t ccrp : 1; /* Config Command Ring Polling */
  200. uint32_t cmv : 1; /* Configure Max VPIs */
  201. uint32_t cbg : 1; /* Configure BlockGuard */
  202. uint32_t rsvd2 : 3; /* Reserved */
  203. uint32_t rsvd3 :20; /* Reserved */
  204. #endif
  205. } sli3Feat;
  206. } lpfc_vpd_t;
  207. /*
  208. * lpfc stat counters
  209. */
  210. struct lpfc_stats {
  211. /* Statistics for ELS commands */
  212. uint32_t elsLogiCol;
  213. uint32_t elsRetryExceeded;
  214. uint32_t elsXmitRetry;
  215. uint32_t elsDelayRetry;
  216. uint32_t elsRcvDrop;
  217. uint32_t elsRcvFrame;
  218. uint32_t elsRcvRSCN;
  219. uint32_t elsRcvRNID;
  220. uint32_t elsRcvFARP;
  221. uint32_t elsRcvFARPR;
  222. uint32_t elsRcvFLOGI;
  223. uint32_t elsRcvPLOGI;
  224. uint32_t elsRcvADISC;
  225. uint32_t elsRcvPDISC;
  226. uint32_t elsRcvFAN;
  227. uint32_t elsRcvLOGO;
  228. uint32_t elsRcvPRLO;
  229. uint32_t elsRcvPRLI;
  230. uint32_t elsRcvLIRR;
  231. uint32_t elsRcvRLS;
  232. uint32_t elsRcvRPL;
  233. uint32_t elsRcvRRQ;
  234. uint32_t elsRcvRTV;
  235. uint32_t elsRcvECHO;
  236. uint32_t elsRcvLCB;
  237. uint32_t elsRcvRDP;
  238. uint32_t elsRcvRDF;
  239. uint32_t elsXmitFLOGI;
  240. uint32_t elsXmitFDISC;
  241. uint32_t elsXmitPLOGI;
  242. uint32_t elsXmitPRLI;
  243. uint32_t elsXmitADISC;
  244. uint32_t elsXmitLOGO;
  245. uint32_t elsXmitSCR;
  246. uint32_t elsXmitRSCN;
  247. uint32_t elsXmitRNID;
  248. uint32_t elsXmitFARP;
  249. uint32_t elsXmitFARPR;
  250. uint32_t elsXmitACC;
  251. uint32_t elsXmitLSRJT;
  252. uint32_t frameRcvBcast;
  253. uint32_t frameRcvMulti;
  254. uint32_t strayXmitCmpl;
  255. uint32_t frameXmitDelay;
  256. uint32_t xriCmdCmpl;
  257. uint32_t xriStatErr;
  258. uint32_t LinkUp;
  259. uint32_t LinkDown;
  260. uint32_t LinkMultiEvent;
  261. uint32_t NoRcvBuf;
  262. uint32_t fcpCmd;
  263. uint32_t fcpCmpl;
  264. uint32_t fcpRspErr;
  265. uint32_t fcpRemoteStop;
  266. uint32_t fcpPortRjt;
  267. uint32_t fcpPortBusy;
  268. uint32_t fcpError;
  269. uint32_t fcpLocalErr;
  270. };
  271. struct lpfc_hba;
  272. /* Data structure to keep withheld FLOGI_ACC information */
  273. struct lpfc_defer_flogi_acc {
  274. bool flag;
  275. u16 rx_id;
  276. u16 ox_id;
  277. struct lpfc_nodelist *ndlp;
  278. };
  279. #define LPFC_VMID_TIMER 300 /* timer interval in seconds */
  280. #define LPFC_MAX_VMID_SIZE 256
  281. union lpfc_vmid_io_tag {
  282. u32 app_id; /* App Id vmid */
  283. u8 cs_ctl_vmid; /* Priority tag vmid */
  284. };
  285. #define JIFFIES_PER_HR (HZ * 60 * 60)
  286. struct lpfc_vmid {
  287. u8 flag;
  288. #define LPFC_VMID_SLOT_FREE 0x0
  289. #define LPFC_VMID_SLOT_USED 0x1
  290. #define LPFC_VMID_REQ_REGISTER 0x2
  291. #define LPFC_VMID_REGISTERED 0x4
  292. #define LPFC_VMID_DE_REGISTER 0x8
  293. char host_vmid[LPFC_MAX_VMID_SIZE];
  294. union lpfc_vmid_io_tag un;
  295. struct hlist_node hnode;
  296. u64 io_rd_cnt;
  297. u64 io_wr_cnt;
  298. u8 vmid_len;
  299. u8 delete_inactive; /* Delete if inactive flag 0 = no, 1 = yes */
  300. u32 hash_index;
  301. u64 __percpu *last_io_time;
  302. };
  303. #define lpfc_vmid_is_type_priority_tag(vport)\
  304. (vport->vmid_priority_tagging ? 1 : 0)
  305. #define LPFC_VMID_HASH_SIZE 256
  306. #define LPFC_VMID_HASH_MASK 255
  307. #define LPFC_VMID_HASH_SHIFT 6
  308. struct lpfc_vmid_context {
  309. struct lpfc_vmid *vmp;
  310. struct lpfc_nodelist *nlp;
  311. bool instantiated;
  312. };
  313. struct lpfc_vmid_priority_range {
  314. u8 low;
  315. u8 high;
  316. u8 qos;
  317. };
  318. struct lpfc_vmid_priority_info {
  319. u32 num_descriptors;
  320. struct lpfc_vmid_priority_range *vmid_range;
  321. };
  322. #define QFPA_EVEN_ONLY 0x01
  323. #define QFPA_ODD_ONLY 0x02
  324. #define QFPA_EVEN_ODD 0x03
  325. enum discovery_state {
  326. LPFC_VPORT_UNKNOWN = 0, /* vport state is unknown */
  327. LPFC_VPORT_FAILED = 1, /* vport has failed */
  328. LPFC_LOCAL_CFG_LINK = 6, /* local NPORT Id configured */
  329. LPFC_FLOGI = 7, /* FLOGI sent to Fabric */
  330. LPFC_FDISC = 8, /* FDISC sent for vport */
  331. LPFC_FABRIC_CFG_LINK = 9, /* Fabric assigned NPORT Id
  332. * configured */
  333. LPFC_NS_REG = 10, /* Register with NameServer */
  334. LPFC_NS_QRY = 11, /* Query NameServer for NPort ID list */
  335. LPFC_BUILD_DISC_LIST = 12, /* Build ADISC and PLOGI lists for
  336. * device authentication / discovery */
  337. LPFC_DISC_AUTH = 13, /* Processing ADISC list */
  338. LPFC_VPORT_READY = 32,
  339. };
  340. enum hba_state {
  341. LPFC_LINK_UNKNOWN = 0, /* HBA state is unknown */
  342. LPFC_WARM_START = 1, /* HBA state after selective reset */
  343. LPFC_INIT_START = 2, /* Initial state after board reset */
  344. LPFC_INIT_MBX_CMDS = 3, /* Initialize HBA with mbox commands */
  345. LPFC_LINK_DOWN = 4, /* HBA initialized, link is down */
  346. LPFC_LINK_UP = 5, /* Link is up - issue READ_LA */
  347. LPFC_CLEAR_LA = 6, /* authentication cmplt - issue
  348. * CLEAR_LA */
  349. LPFC_HBA_READY = 32,
  350. LPFC_HBA_ERROR = -1
  351. };
  352. enum lpfc_hba_flag { /* hba generic flags */
  353. HBA_ERATT_HANDLED = 0, /* This flag is set when eratt handled */
  354. DEFER_ERATT = 1, /* Deferred error attn in progress */
  355. HBA_FCOE_MODE = 2, /* HBA function in FCoE Mode */
  356. HBA_SP_QUEUE_EVT = 3, /* Slow-path qevt posted to worker thread*/
  357. HBA_POST_RECEIVE_BUFFER = 4, /* Rcv buffers need to be posted */
  358. HBA_PERSISTENT_TOPO = 5, /* Persistent topology support in hba */
  359. ELS_XRI_ABORT_EVENT = 6, /* ELS_XRI abort event was queued */
  360. ASYNC_EVENT = 7,
  361. LINK_DISABLED = 8, /* Link disabled by user */
  362. FCF_TS_INPROG = 9, /* FCF table scan in progress */
  363. FCF_RR_INPROG = 10, /* FCF roundrobin flogi in progress */
  364. HBA_FIP_SUPPORT = 11, /* FIP support in HBA */
  365. HBA_DEVLOSS_TMO = 13, /* HBA in devloss timeout */
  366. HBA_RRQ_ACTIVE = 14, /* process the rrq active list */
  367. HBA_IOQ_FLUSH = 15, /* I/O queues being flushed */
  368. HBA_RECOVERABLE_UE = 17, /* FW supports recoverable UE */
  369. HBA_FORCED_LINK_SPEED = 18, /*
  370. * Firmware supports Forced Link
  371. * Speed capability
  372. */
  373. HBA_FLOGI_ISSUED = 20, /* FLOGI was issued */
  374. HBA_DEFER_FLOGI = 23, /* Defer FLOGI till read_sparm cmpl */
  375. HBA_SETUP = 24, /* HBA setup completed */
  376. HBA_NEEDS_CFG_PORT = 25, /* SLI3: CONFIG_PORT mbox needed */
  377. HBA_HBEAT_INP = 26, /* mbox HBEAT is in progress */
  378. HBA_HBEAT_TMO = 27, /* HBEAT initiated after timeout */
  379. HBA_FLOGI_OUTSTANDING = 28, /* FLOGI is outstanding */
  380. HBA_RHBA_CMPL = 29, /* RHBA FDMI cmd is successful */
  381. };
  382. struct lpfc_trunk_link_state {
  383. enum hba_state state;
  384. uint8_t fault;
  385. };
  386. struct lpfc_trunk_link {
  387. struct lpfc_trunk_link_state link0,
  388. link1,
  389. link2,
  390. link3;
  391. u32 phy_lnk_speed;
  392. };
  393. /* Format of congestion module parameters */
  394. struct lpfc_cgn_param {
  395. uint32_t cgn_param_magic;
  396. uint8_t cgn_param_version; /* version 1 */
  397. uint8_t cgn_param_mode; /* 0=off 1=managed 2=monitor only */
  398. #define LPFC_CFG_OFF 0
  399. #define LPFC_CFG_MANAGED 1
  400. #define LPFC_CFG_MONITOR 2
  401. uint8_t cgn_rsvd1;
  402. uint8_t cgn_rsvd2;
  403. uint8_t cgn_param_level0;
  404. uint8_t cgn_param_level1;
  405. uint8_t cgn_param_level2;
  406. uint8_t byte11;
  407. uint8_t byte12;
  408. uint8_t byte13;
  409. uint8_t byte14;
  410. uint8_t byte15;
  411. };
  412. /* Max number of days of congestion data */
  413. #define LPFC_MAX_CGN_DAYS 10
  414. struct lpfc_cgn_ts {
  415. uint8_t month;
  416. uint8_t day;
  417. uint8_t year;
  418. uint8_t hour;
  419. uint8_t minute;
  420. uint8_t second;
  421. };
  422. /* Format of congestion buffer info
  423. * This structure defines memory thats allocated and registered with
  424. * the HBA firmware. When adding or removing fields from this structure
  425. * the alignment must match the HBA firmware.
  426. */
  427. struct lpfc_cgn_info {
  428. /* Header */
  429. __le16 cgn_info_size; /* is sizeof(struct lpfc_cgn_info) */
  430. uint8_t cgn_info_version; /* represents format of structure */
  431. #define LPFC_CGN_INFO_V1 1
  432. #define LPFC_CGN_INFO_V2 2
  433. #define LPFC_CGN_INFO_V3 3
  434. #define LPFC_CGN_INFO_V4 4
  435. uint8_t cgn_info_mode; /* 0=off 1=managed 2=monitor only */
  436. uint8_t cgn_info_detect;
  437. uint8_t cgn_info_action;
  438. uint8_t cgn_info_level0;
  439. uint8_t cgn_info_level1;
  440. uint8_t cgn_info_level2;
  441. /* Start Time */
  442. struct lpfc_cgn_ts base_time;
  443. /* minute / hours / daily indices */
  444. uint8_t cgn_index_minute;
  445. uint8_t cgn_index_hour;
  446. uint8_t cgn_index_day;
  447. __le16 cgn_warn_freq;
  448. __le16 cgn_alarm_freq;
  449. __le16 cgn_lunq;
  450. uint8_t cgn_pad1[8];
  451. /* Driver Information */
  452. __le16 cgn_drvr_min[60];
  453. __le32 cgn_drvr_hr[24];
  454. __le32 cgn_drvr_day[LPFC_MAX_CGN_DAYS];
  455. /* Congestion Warnings */
  456. __le16 cgn_warn_min[60];
  457. __le32 cgn_warn_hr[24];
  458. __le32 cgn_warn_day[LPFC_MAX_CGN_DAYS];
  459. /* Latency Information */
  460. __le32 cgn_latency_min[60];
  461. __le32 cgn_latency_hr[24];
  462. __le32 cgn_latency_day[LPFC_MAX_CGN_DAYS];
  463. /* Bandwidth Information */
  464. __le16 cgn_bw_min[60];
  465. __le16 cgn_bw_hr[24];
  466. __le16 cgn_bw_day[LPFC_MAX_CGN_DAYS];
  467. /* Congestion Alarms */
  468. __le16 cgn_alarm_min[60];
  469. __le32 cgn_alarm_hr[24];
  470. __le32 cgn_alarm_day[LPFC_MAX_CGN_DAYS];
  471. struct_group(cgn_stat,
  472. uint8_t cgn_stat_npm; /* Notifications per minute */
  473. /* Start Time */
  474. struct lpfc_cgn_ts stat_start; /* Base time */
  475. uint8_t cgn_pad2;
  476. __le32 cgn_notification;
  477. __le32 cgn_peer_notification;
  478. __le32 link_integ_notification;
  479. __le32 delivery_notification;
  480. struct lpfc_cgn_ts stat_fpin; /* Last congestion notification FPIN */
  481. struct lpfc_cgn_ts stat_peer; /* Last peer congestion FPIN */
  482. struct lpfc_cgn_ts stat_lnk; /* Last link integrity FPIN */
  483. struct lpfc_cgn_ts stat_delivery; /* Last delivery notification FPIN */
  484. );
  485. __le32 cgn_info_crc;
  486. #define LPFC_CGN_CRC32_MAGIC_NUMBER 0x1EDC6F41
  487. #define LPFC_CGN_CRC32_SEED 0xFFFFFFFF
  488. };
  489. #define LPFC_CGN_INFO_SZ (sizeof(struct lpfc_cgn_info) - \
  490. sizeof(uint32_t))
  491. struct lpfc_cgn_stat {
  492. atomic64_t total_bytes;
  493. atomic64_t rcv_bytes;
  494. atomic64_t rx_latency;
  495. #define LPFC_CGN_NOT_SENT 0xFFFFFFFFFFFFFFFFLL
  496. atomic_t rx_io_cnt;
  497. };
  498. struct lpfc_cgn_acqe_stat {
  499. atomic64_t alarm;
  500. atomic64_t warn;
  501. };
  502. enum lpfc_fc_flag {
  503. /* Several of these flags are HBA centric and should be moved to
  504. * phba->link_flag (e.g. FC_PTP, FC_PUBLIC_LOOP)
  505. */
  506. FC_PT2PT, /* pt2pt with no fabric */
  507. FC_PT2PT_PLOGI, /* pt2pt initiate PLOGI */
  508. FC_DISC_TMO, /* Discovery timer running */
  509. FC_PUBLIC_LOOP, /* Public loop */
  510. FC_LBIT, /* LOGIN bit in loopinit set */
  511. FC_RSCN_MODE, /* RSCN cmd rcv'ed */
  512. FC_NLP_MORE, /* More node to process in node tbl */
  513. FC_OFFLINE_MODE, /* Interface is offline for diag */
  514. FC_FABRIC, /* We are fabric attached */
  515. FC_VPORT_LOGO_RCVD, /* LOGO received on vport */
  516. FC_RSCN_DISCOVERY, /* Auth all devices after RSCN */
  517. FC_LOGO_RCVD_DID_CHNG, /* FDISC on phys port detect DID chng */
  518. FC_PT2PT_NO_NVME, /* Don't send NVME PRLI */
  519. FC_SCSI_SCAN_TMO, /* scsi scan timer running */
  520. FC_ABORT_DISCOVERY, /* we want to abort discovery */
  521. FC_NDISC_ACTIVE, /* NPort discovery active */
  522. FC_BYPASSED_MODE, /* NPort is in bypassed mode */
  523. FC_VPORT_NEEDS_REG_VPI, /* Needs to have its vpi registered */
  524. FC_RSCN_DEFERRED, /* A deferred RSCN being processed */
  525. FC_VPORT_NEEDS_INIT_VPI, /* Need to INIT_VPI before FDISC */
  526. FC_VPORT_CVL_RCVD, /* VLink failed due to CVL */
  527. FC_VFI_REGISTERED, /* VFI is registered */
  528. FC_FDISC_COMPLETED, /* FDISC completed */
  529. FC_DISC_DELAYED, /* Delay NPort discovery */
  530. };
  531. enum lpfc_load_flag {
  532. FC_LOADING, /* HBA in process of loading drvr */
  533. FC_UNLOADING, /* HBA in process of unloading drvr */
  534. FC_ALLOW_FDMI, /* port is ready for FDMI requests */
  535. FC_ALLOW_VMID, /* Allow VMID I/Os */
  536. FC_DEREGISTER_ALL_APP_ID /* Deregister all VMIDs */
  537. };
  538. struct lpfc_vport {
  539. struct lpfc_hba *phba;
  540. struct list_head listentry;
  541. uint8_t port_type;
  542. #define LPFC_PHYSICAL_PORT 1
  543. #define LPFC_NPIV_PORT 2
  544. #define LPFC_FABRIC_PORT 3
  545. enum discovery_state port_state;
  546. uint16_t vpi;
  547. uint16_t vfi;
  548. uint8_t vpi_state;
  549. #define LPFC_VPI_REGISTERED 0x1
  550. unsigned long fc_flag; /* FC flags */
  551. uint32_t ct_flags;
  552. #define FC_CT_RFF_ID 0x1 /* RFF_ID accepted by switch */
  553. #define FC_CT_RNN_ID 0x2 /* RNN_ID accepted by switch */
  554. #define FC_CT_RSNN_NN 0x4 /* RSNN_NN accepted by switch */
  555. #define FC_CT_RSPN_ID 0x8 /* RSPN_ID accepted by switch */
  556. #define FC_CT_RFT_ID 0x10 /* RFT_ID accepted by switch */
  557. #define FC_CT_RPRT_DEFER 0x20 /* Defer issuing FDMI RPRT */
  558. struct list_head fc_nodes;
  559. spinlock_t fc_nodes_list_lock; /* spinlock for fc_nodes list */
  560. /* Keep counters for the number of entries in each list. */
  561. atomic_t fc_plogi_cnt;
  562. atomic_t fc_adisc_cnt;
  563. atomic_t fc_reglogin_cnt;
  564. atomic_t fc_prli_cnt;
  565. atomic_t fc_unmap_cnt;
  566. atomic_t fc_map_cnt;
  567. atomic_t fc_npr_cnt;
  568. atomic_t fc_unused_cnt;
  569. struct serv_parm fc_sparam; /* buffer for our service parameters */
  570. uint32_t fc_myDID; /* fibre channel S_ID */
  571. uint32_t fc_prevDID; /* previous fibre channel S_ID */
  572. struct lpfc_name fabric_portname;
  573. struct lpfc_name fabric_nodename;
  574. int32_t stopped; /* HBA has not been restarted since last ERATT */
  575. uint8_t fc_linkspeed; /* Link speed after last READ_LA */
  576. uint32_t num_disc_nodes; /* in addition to hba_state */
  577. uint32_t gidft_inp; /* cnt of outstanding GID_FTs */
  578. uint32_t fc_nlp_cnt; /* outstanding NODELIST requests */
  579. uint32_t fc_rscn_id_cnt; /* count of RSCNs payloads in list */
  580. uint32_t fc_rscn_flush; /* flag use of fc_rscn_id_list */
  581. struct lpfc_dmabuf *fc_rscn_id_list[FC_MAX_HOLD_RSCN];
  582. struct lpfc_name fc_nodename; /* fc nodename */
  583. struct lpfc_name fc_portname; /* fc portname */
  584. struct lpfc_work_evt disc_timeout_evt;
  585. struct timer_list fc_disctmo; /* Discovery rescue timer */
  586. uint8_t fc_ns_retry; /* retries for fabric nameserver */
  587. uint32_t fc_prli_sent; /* cntr for outstanding PRLIs */
  588. spinlock_t work_port_lock;
  589. uint32_t work_port_events; /* Timeout to be handled */
  590. #define WORKER_DISC_TMO 0x1 /* vport: Discovery timeout */
  591. #define WORKER_ELS_TMO 0x2 /* vport: ELS timeout */
  592. #define WORKER_DELAYED_DISC_TMO 0x8 /* vport: delayed discovery */
  593. #define WORKER_MBOX_TMO 0x100 /* hba: MBOX timeout */
  594. #define WORKER_HB_TMO 0x200 /* hba: Heart beat timeout */
  595. #define WORKER_FABRIC_BLOCK_TMO 0x400 /* hba: fabric block timeout */
  596. #define WORKER_RAMP_DOWN_QUEUE 0x800 /* hba: Decrease Q depth */
  597. #define WORKER_RAMP_UP_QUEUE 0x1000 /* hba: Increase Q depth */
  598. #define WORKER_SERVICE_TXQ 0x2000 /* hba: IOCBs on the txq */
  599. #define WORKER_CHECK_INACTIVE_VMID 0x4000 /* hba: check inactive vmids */
  600. #define WORKER_CHECK_VMID_ISSUE_QFPA 0x8000 /* vport: Check if qfpa needs
  601. * to be issued */
  602. struct timer_list els_tmofunc;
  603. struct timer_list delayed_disc_tmo;
  604. unsigned long load_flag;
  605. /* Vport Config Parameters */
  606. uint32_t cfg_scan_down;
  607. uint32_t cfg_lun_queue_depth;
  608. uint32_t cfg_nodev_tmo;
  609. uint32_t cfg_devloss_tmo;
  610. uint32_t cfg_restrict_login;
  611. uint32_t cfg_peer_port_login;
  612. uint32_t cfg_fcp_class;
  613. uint32_t cfg_use_adisc;
  614. uint32_t cfg_discovery_threads;
  615. uint32_t cfg_log_verbose;
  616. uint32_t cfg_enable_fc4_type;
  617. uint32_t cfg_max_luns;
  618. uint32_t cfg_enable_da_id;
  619. uint32_t cfg_max_scsicmpl_time;
  620. uint32_t cfg_tgt_queue_depth;
  621. uint32_t cfg_first_burst_size;
  622. uint32_t dev_loss_tmo_changed;
  623. /* VMID parameters */
  624. u8 lpfc_vmid_host_uuid[16];
  625. u32 max_vmid; /* maximum VMIDs allowed per port */
  626. u32 cur_vmid_cnt; /* Current VMID count */
  627. #define LPFC_MIN_VMID 4
  628. #define LPFC_MAX_VMID 255
  629. u32 vmid_inactivity_timeout; /* Time after which the VMID */
  630. /* deregisters from switch */
  631. u32 vmid_priority_tagging;
  632. #define LPFC_VMID_PRIO_TAG_DISABLE 0 /* Disable */
  633. #define LPFC_VMID_PRIO_TAG_SUP_TARGETS 1 /* Allow supported targets only */
  634. #define LPFC_VMID_PRIO_TAG_ALL_TARGETS 2 /* Allow all targets */
  635. unsigned long *vmid_priority_range;
  636. #define LPFC_VMID_MAX_PRIORITY_RANGE 256
  637. #define LPFC_VMID_PRIORITY_BITMAP_SIZE 32
  638. u8 vmid_flag;
  639. #define LPFC_VMID_IN_USE 0x1
  640. #define LPFC_VMID_ISSUE_QFPA 0x2
  641. #define LPFC_VMID_QFPA_CMPL 0x4
  642. #define LPFC_VMID_QOS_ENABLED 0x8
  643. #define LPFC_VMID_TIMER_ENBLD 0x10
  644. #define LPFC_VMID_TYPE_PRIO 0x20
  645. struct fc_qfpa_res *qfpa_res;
  646. struct fc_vport *fc_vport;
  647. struct lpfc_vmid *vmid;
  648. DECLARE_HASHTABLE(hash_table, 8);
  649. rwlock_t vmid_lock;
  650. struct lpfc_vmid_priority_info vmid_priority;
  651. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  652. struct dentry *debug_disc_trc;
  653. struct dentry *debug_nodelist;
  654. struct dentry *debug_nvmestat;
  655. struct dentry *debug_scsistat;
  656. struct dentry *debug_ioktime;
  657. struct dentry *debug_hdwqstat;
  658. struct dentry *vport_debugfs_root;
  659. struct lpfc_debugfs_trc *disc_trc;
  660. atomic_t disc_trc_cnt;
  661. #endif
  662. struct list_head rcv_buffer_list;
  663. unsigned long rcv_buffer_time_stamp;
  664. uint32_t vport_flag;
  665. #define STATIC_VPORT 0x1
  666. #define FAWWPN_PARAM_CHG 0x2
  667. uint16_t fdmi_num_disc;
  668. uint32_t fdmi_hba_mask;
  669. uint32_t fdmi_port_mask;
  670. /* There is a single nvme instance per vport. */
  671. struct nvme_fc_local_port *localport;
  672. uint8_t nvmei_support; /* driver supports NVME Initiator */
  673. uint32_t last_fcp_wqidx;
  674. uint32_t rcv_flogi_cnt; /* How many unsol FLOGIs ACK'd. */
  675. };
  676. struct hbq_s {
  677. uint16_t entry_count; /* Current number of HBQ slots */
  678. uint16_t buffer_count; /* Current number of buffers posted */
  679. uint32_t next_hbqPutIdx; /* Index to next HBQ slot to use */
  680. uint32_t hbqPutIdx; /* HBQ slot to use */
  681. uint32_t local_hbqGetIdx; /* Local copy of Get index from Port */
  682. void *hbq_virt; /* Virtual ptr to this hbq */
  683. struct list_head hbq_buffer_list; /* buffers assigned to this HBQ */
  684. /* Callback for HBQ buffer allocation */
  685. struct hbq_dmabuf *(*hbq_alloc_buffer) (struct lpfc_hba *);
  686. /* Callback for HBQ buffer free */
  687. void (*hbq_free_buffer) (struct lpfc_hba *,
  688. struct hbq_dmabuf *);
  689. };
  690. /* this matches the position in the lpfc_hbq_defs array */
  691. #define LPFC_ELS_HBQ 0
  692. #define LPFC_MAX_HBQS 1
  693. enum hba_temp_state {
  694. HBA_NORMAL_TEMP,
  695. HBA_OVER_TEMP
  696. };
  697. enum intr_type_t {
  698. NONE = 0,
  699. INTx,
  700. MSI,
  701. MSIX,
  702. };
  703. #define LPFC_CT_CTX_MAX 64
  704. struct unsol_rcv_ct_ctx {
  705. uint32_t ctxt_id;
  706. uint32_t SID;
  707. uint32_t valid;
  708. #define UNSOL_INVALID 0
  709. #define UNSOL_VALID 1
  710. uint16_t oxid;
  711. uint16_t rxid;
  712. };
  713. #define LPFC_USER_LINK_SPEED_AUTO 0 /* auto select (default)*/
  714. #define LPFC_USER_LINK_SPEED_1G 1 /* 1 Gigabaud */
  715. #define LPFC_USER_LINK_SPEED_2G 2 /* 2 Gigabaud */
  716. #define LPFC_USER_LINK_SPEED_4G 4 /* 4 Gigabaud */
  717. #define LPFC_USER_LINK_SPEED_8G 8 /* 8 Gigabaud */
  718. #define LPFC_USER_LINK_SPEED_10G 10 /* 10 Gigabaud */
  719. #define LPFC_USER_LINK_SPEED_16G 16 /* 16 Gigabaud */
  720. #define LPFC_USER_LINK_SPEED_32G 32 /* 32 Gigabaud */
  721. #define LPFC_USER_LINK_SPEED_64G 64 /* 64 Gigabaud */
  722. #define LPFC_USER_LINK_SPEED_MAX LPFC_USER_LINK_SPEED_64G
  723. #define LPFC_LINK_SPEED_STRING "0, 1, 2, 4, 8, 10, 16, 32, 64"
  724. enum nemb_type {
  725. nemb_mse = 1,
  726. nemb_hbd
  727. };
  728. enum mbox_type {
  729. mbox_rd = 1,
  730. mbox_wr
  731. };
  732. enum dma_type {
  733. dma_mbox = 1,
  734. dma_ebuf
  735. };
  736. enum sta_type {
  737. sta_pre_addr = 1,
  738. sta_pos_addr
  739. };
  740. struct lpfc_mbox_ext_buf_ctx {
  741. uint32_t state;
  742. #define LPFC_BSG_MBOX_IDLE 0
  743. #define LPFC_BSG_MBOX_HOST 1
  744. #define LPFC_BSG_MBOX_PORT 2
  745. #define LPFC_BSG_MBOX_DONE 3
  746. #define LPFC_BSG_MBOX_ABTS 4
  747. enum nemb_type nembType;
  748. enum mbox_type mboxType;
  749. uint32_t numBuf;
  750. uint32_t mbxTag;
  751. uint32_t seqNum;
  752. struct lpfc_dmabuf *mbx_dmabuf;
  753. struct list_head ext_dmabuf_list;
  754. };
  755. struct lpfc_epd_pool {
  756. /* Expedite pool */
  757. struct list_head list;
  758. u32 count;
  759. spinlock_t lock; /* lock for expedite pool */
  760. };
  761. enum ras_state {
  762. INACTIVE,
  763. REG_INPROGRESS,
  764. ACTIVE
  765. };
  766. struct lpfc_ras_fwlog {
  767. uint8_t *fwlog_buff;
  768. uint32_t fw_buffcount; /* Buffer size posted to FW */
  769. #define LPFC_RAS_BUFF_ENTERIES 16 /* Each entry can hold max of 64k */
  770. #define LPFC_RAS_MAX_ENTRY_SIZE (64 * 1024)
  771. #define LPFC_RAS_MIN_BUFF_POST_SIZE (256 * 1024)
  772. #define LPFC_RAS_MAX_BUFF_POST_SIZE (1024 * 1024)
  773. uint32_t fw_loglevel; /* Log level set */
  774. struct lpfc_dmabuf lwpd;
  775. struct list_head fwlog_buff_list;
  776. /* RAS support status on adapter */
  777. bool ras_hwsupport; /* RAS Support available on HW or not */
  778. bool ras_enabled; /* Ras Enabled for the function */
  779. #define LPFC_RAS_DISABLE_LOGGING 0x00
  780. #define LPFC_RAS_ENABLE_LOGGING 0x01
  781. enum ras_state state; /* RAS logging running state */
  782. };
  783. #define DBG_LOG_STR_SZ 256
  784. #define DBG_LOG_SZ 256
  785. struct dbg_log_ent {
  786. char log[DBG_LOG_STR_SZ];
  787. u64 t_ns;
  788. };
  789. enum lpfc_irq_chann_mode {
  790. /* Assign IRQs to all possible cpus that have hardware queues */
  791. NORMAL_MODE,
  792. /* Assign IRQs only to cpus on the same numa node as HBA */
  793. NUMA_MODE,
  794. /* Assign IRQs only on non-hyperthreaded CPUs. This is the
  795. * same as normal_mode, but assign IRQS only on physical CPUs.
  796. */
  797. NHT_MODE,
  798. };
  799. enum lpfc_hba_bit_flags {
  800. FABRIC_COMANDS_BLOCKED,
  801. HBA_PCI_ERR,
  802. MBX_TMO_ERR,
  803. };
  804. struct lpfc_hba {
  805. /* SCSI interface function jump table entries */
  806. struct lpfc_io_buf * (*lpfc_get_scsi_buf)
  807. (struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  808. struct scsi_cmnd *cmnd);
  809. int (*lpfc_scsi_prep_dma_buf)
  810. (struct lpfc_hba *, struct lpfc_io_buf *);
  811. void (*lpfc_scsi_unprep_dma_buf)
  812. (struct lpfc_hba *, struct lpfc_io_buf *);
  813. void (*lpfc_release_scsi_buf)
  814. (struct lpfc_hba *, struct lpfc_io_buf *);
  815. void (*lpfc_rampdown_queue_depth)
  816. (struct lpfc_hba *);
  817. void (*lpfc_scsi_prep_cmnd)
  818. (struct lpfc_vport *, struct lpfc_io_buf *,
  819. struct lpfc_nodelist *);
  820. int (*lpfc_scsi_prep_cmnd_buf)
  821. (struct lpfc_vport *vport,
  822. struct lpfc_io_buf *lpfc_cmd,
  823. uint8_t tmo);
  824. int (*lpfc_scsi_prep_task_mgmt_cmd)
  825. (struct lpfc_vport *vport,
  826. struct lpfc_io_buf *lpfc_cmd,
  827. u64 lun, u8 task_mgmt_cmd);
  828. /* IOCB interface function jump table entries */
  829. int (*__lpfc_sli_issue_iocb)
  830. (struct lpfc_hba *, uint32_t,
  831. struct lpfc_iocbq *, uint32_t);
  832. int (*__lpfc_sli_issue_fcp_io)
  833. (struct lpfc_hba *phba, uint32_t ring_number,
  834. struct lpfc_iocbq *piocb, uint32_t flag);
  835. void (*__lpfc_sli_release_iocbq)(struct lpfc_hba *,
  836. struct lpfc_iocbq *);
  837. int (*lpfc_hba_down_post)(struct lpfc_hba *phba);
  838. /* MBOX interface function jump table entries */
  839. int (*lpfc_sli_issue_mbox)
  840. (struct lpfc_hba *, LPFC_MBOXQ_t *, uint32_t);
  841. /* Slow-path IOCB process function jump table entries */
  842. void (*lpfc_sli_handle_slow_ring_event)
  843. (struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  844. uint32_t mask);
  845. /* INIT device interface function jump table entries */
  846. int (*lpfc_sli_hbq_to_firmware)
  847. (struct lpfc_hba *, uint32_t, struct hbq_dmabuf *);
  848. int (*lpfc_sli_brdrestart)
  849. (struct lpfc_hba *);
  850. int (*lpfc_sli_brdready)
  851. (struct lpfc_hba *, uint32_t);
  852. void (*lpfc_handle_eratt)
  853. (struct lpfc_hba *);
  854. void (*lpfc_stop_port)
  855. (struct lpfc_hba *);
  856. int (*lpfc_hba_init_link)
  857. (struct lpfc_hba *, uint32_t);
  858. int (*lpfc_hba_down_link)
  859. (struct lpfc_hba *, uint32_t);
  860. int (*lpfc_selective_reset)
  861. (struct lpfc_hba *);
  862. int (*lpfc_bg_scsi_prep_dma_buf)
  863. (struct lpfc_hba *, struct lpfc_io_buf *);
  864. /* Prep SLI WQE/IOCB jump table entries */
  865. void (*__lpfc_sli_prep_els_req_rsp)(struct lpfc_iocbq *cmdiocbq,
  866. struct lpfc_vport *vport,
  867. struct lpfc_dmabuf *bmp,
  868. u16 cmd_size, u32 did, u32 elscmd,
  869. u8 tmo, u8 expect_rsp);
  870. void (*__lpfc_sli_prep_gen_req)(struct lpfc_iocbq *cmdiocbq,
  871. struct lpfc_dmabuf *bmp, u16 rpi,
  872. u32 num_entry, u8 tmo);
  873. void (*__lpfc_sli_prep_xmit_seq64)(struct lpfc_iocbq *cmdiocbq,
  874. struct lpfc_dmabuf *bmp, u16 rpi,
  875. u16 ox_id, u32 num_entry, u8 rctl,
  876. u8 last_seq, u8 cr_cx_cmd);
  877. void (*__lpfc_sli_prep_abort_xri)(struct lpfc_iocbq *cmdiocbq,
  878. u16 ulp_context, u16 iotag,
  879. u8 ulp_class, u16 cqid, bool ia,
  880. bool wqec);
  881. /* expedite pool */
  882. struct lpfc_epd_pool epd_pool;
  883. /* SLI4 specific HBA data structure */
  884. struct lpfc_sli4_hba sli4_hba;
  885. struct workqueue_struct *wq;
  886. struct delayed_work eq_delay_work;
  887. #define LPFC_IDLE_STAT_DELAY 1000
  888. struct delayed_work idle_stat_delay_work;
  889. struct lpfc_sli sli;
  890. uint8_t pci_dev_grp; /* lpfc PCI dev group: 0x0, 0x1, 0x2,... */
  891. uint32_t sli_rev; /* SLI2, SLI3, or SLI4 */
  892. uint32_t sli3_options; /* Mask of enabled SLI3 options */
  893. #define LPFC_SLI3_HBQ_ENABLED 0x01
  894. #define LPFC_SLI3_NPIV_ENABLED 0x02
  895. #define LPFC_SLI3_VPORT_TEARDOWN 0x04
  896. #define LPFC_SLI3_CRP_ENABLED 0x08
  897. #define LPFC_SLI3_BG_ENABLED 0x20
  898. #define LPFC_SLI3_DSS_ENABLED 0x40
  899. #define LPFC_SLI4_PERFH_ENABLED 0x80
  900. #define LPFC_SLI4_PHWQ_ENABLED 0x100
  901. uint32_t iocb_cmd_size;
  902. uint32_t iocb_rsp_size;
  903. struct lpfc_trunk_link trunk_link;
  904. enum hba_state link_state;
  905. uint32_t link_flag; /* link state flags */
  906. #define LS_LOOPBACK_MODE 0x1 /* NPort is in Loopback mode */
  907. /* This flag is set while issuing */
  908. /* INIT_LINK mailbox command */
  909. #define LS_NPIV_FAB_SUPPORTED 0x2 /* Fabric supports NPIV */
  910. #define LS_IGNORE_ERATT 0x4 /* intr handler should ignore ERATT */
  911. #define LS_MDS_LINK_DOWN 0x8 /* MDS Diagnostics Link Down */
  912. #define LS_MDS_LOOPBACK 0x10 /* MDS Diagnostics Link Up (Loopback) */
  913. #define LS_CT_VEN_RPA 0x20 /* Vendor RPA sent to switch */
  914. #define LS_EXTERNAL_LOOPBACK 0x40 /* External loopback plug inserted */
  915. unsigned long hba_flag; /* hba generic flags */
  916. struct completion *fw_dump_cmpl; /* cmpl event tracker for fw_dump */
  917. uint32_t fcp_ring_in_use; /* When polling test if intr-hndlr active*/
  918. struct lpfc_dmabuf slim2p;
  919. MAILBOX_t *mbox;
  920. uint32_t *mbox_ext;
  921. struct lpfc_mbox_ext_buf_ctx mbox_ext_buf_ctx;
  922. uint32_t ha_copy;
  923. struct _PCB *pcb;
  924. struct _IOCB *IOCBs;
  925. struct lpfc_dmabuf hbqslimp;
  926. uint16_t pci_cfg_value;
  927. uint8_t fc_linkspeed; /* Link speed after last READ_LA */
  928. uint32_t fc_eventTag; /* event tag for link attention */
  929. uint32_t link_events;
  930. /* These fields used to be binfo */
  931. uint32_t fc_pref_DID; /* preferred D_ID */
  932. uint8_t fc_pref_ALPA; /* preferred AL_PA */
  933. uint32_t fc_edtovResol; /* E_D_TOV timer resolution */
  934. uint32_t fc_edtov; /* E_D_TOV timer value */
  935. uint32_t fc_arbtov; /* ARB_TOV timer value */
  936. uint32_t fc_ratov; /* R_A_TOV timer value */
  937. uint32_t fc_rttov; /* R_T_TOV timer value */
  938. uint32_t fc_altov; /* AL_TOV timer value */
  939. uint32_t fc_crtov; /* C_R_TOV timer value */
  940. struct serv_parm fc_fabparam; /* fabric service parameters buffer */
  941. uint8_t alpa_map[128]; /* AL_PA map from READ_LA */
  942. uint32_t lmt;
  943. uint32_t fc_topology; /* link topology, from LINK INIT */
  944. uint32_t fc_topology_changed; /* link topology, from LINK INIT */
  945. struct lpfc_stats fc_stat;
  946. struct lpfc_nodelist fc_fcpnodev; /* nodelist entry for no device */
  947. uint32_t nport_event_cnt; /* timestamp for nlplist entry */
  948. uint8_t wwnn[8];
  949. uint8_t wwpn[8];
  950. uint32_t RandomData[7];
  951. uint8_t fcp_embed_io;
  952. uint8_t nvmet_support; /* driver supports NVMET */
  953. #define LPFC_NVMET_MAX_PORTS 32
  954. uint8_t mds_diags_support;
  955. uint8_t bbcredit_support;
  956. uint8_t enab_exp_wqcq_pages;
  957. u8 nsler; /* Firmware supports FC-NVMe-2 SLER */
  958. /* HBA Config Parameters */
  959. uint32_t cfg_ack0;
  960. uint32_t cfg_xri_rebalancing;
  961. uint32_t cfg_xpsgl;
  962. uint32_t cfg_enable_npiv;
  963. uint32_t cfg_enable_rrq;
  964. uint32_t cfg_topology;
  965. uint32_t cfg_link_speed;
  966. #define LPFC_FCF_FOV 1 /* Fast fcf failover */
  967. #define LPFC_FCF_PRIORITY 2 /* Priority fcf failover */
  968. uint32_t cfg_fcf_failover_policy;
  969. uint32_t cfg_fcp_io_sched;
  970. uint32_t cfg_ns_query;
  971. uint32_t cfg_fcp2_no_tgt_reset;
  972. uint32_t cfg_cr_delay;
  973. uint32_t cfg_cr_count;
  974. uint32_t cfg_multi_ring_support;
  975. uint32_t cfg_multi_ring_rctl;
  976. uint32_t cfg_multi_ring_type;
  977. uint32_t cfg_poll;
  978. uint32_t cfg_poll_tmo;
  979. uint32_t cfg_task_mgmt_tmo;
  980. uint32_t cfg_use_msi;
  981. uint32_t cfg_auto_imax;
  982. uint32_t cfg_fcp_imax;
  983. uint32_t cfg_force_rscn;
  984. uint32_t cfg_cq_poll_threshold;
  985. uint32_t cfg_cq_max_proc_limit;
  986. uint32_t cfg_fcp_cpu_map;
  987. uint32_t cfg_fcp_mq_threshold;
  988. uint32_t cfg_hdw_queue;
  989. uint32_t cfg_irq_chann;
  990. uint32_t cfg_suppress_rsp;
  991. uint32_t cfg_nvme_oas;
  992. uint32_t cfg_nvme_embed_cmd;
  993. uint32_t cfg_nvmet_mrq_post;
  994. uint32_t cfg_nvmet_mrq;
  995. uint32_t cfg_enable_nvmet;
  996. uint32_t cfg_nvme_enable_fb;
  997. uint32_t cfg_nvmet_fb_size;
  998. uint32_t cfg_total_seg_cnt;
  999. uint32_t cfg_sg_seg_cnt;
  1000. uint32_t cfg_nvme_seg_cnt;
  1001. uint32_t cfg_scsi_seg_cnt;
  1002. uint32_t cfg_sg_dma_buf_size;
  1003. uint32_t cfg_hba_queue_depth;
  1004. uint32_t cfg_enable_hba_reset;
  1005. uint32_t cfg_enable_hba_heartbeat;
  1006. uint32_t cfg_fof;
  1007. uint32_t cfg_EnableXLane;
  1008. uint8_t cfg_oas_tgt_wwpn[8];
  1009. uint8_t cfg_oas_vpt_wwpn[8];
  1010. uint32_t cfg_oas_lun_state;
  1011. #define OAS_LUN_ENABLE 1
  1012. #define OAS_LUN_DISABLE 0
  1013. uint32_t cfg_oas_lun_status;
  1014. #define OAS_LUN_STATUS_EXISTS 0x01
  1015. uint32_t cfg_oas_flags;
  1016. #define OAS_FIND_ANY_VPORT 0x01
  1017. #define OAS_FIND_ANY_TARGET 0x02
  1018. #define OAS_LUN_VALID 0x04
  1019. uint32_t cfg_oas_priority;
  1020. uint32_t cfg_XLanePriority;
  1021. uint32_t cfg_enable_bg;
  1022. uint32_t cfg_prot_mask;
  1023. uint32_t cfg_prot_guard;
  1024. uint32_t cfg_hostmem_hgp;
  1025. uint32_t cfg_log_verbose;
  1026. uint32_t cfg_enable_fc4_type;
  1027. #define LPFC_ENABLE_FCP 1
  1028. #define LPFC_ENABLE_NVME 2
  1029. #define LPFC_ENABLE_BOTH 3
  1030. #if (IS_ENABLED(CONFIG_NVME_FC))
  1031. #define LPFC_MAX_ENBL_FC4_TYPE LPFC_ENABLE_BOTH
  1032. #define LPFC_DEF_ENBL_FC4_TYPE LPFC_ENABLE_BOTH
  1033. #else
  1034. #define LPFC_MAX_ENBL_FC4_TYPE LPFC_ENABLE_FCP
  1035. #define LPFC_DEF_ENBL_FC4_TYPE LPFC_ENABLE_FCP
  1036. #endif
  1037. uint32_t cfg_sriov_nr_virtfn;
  1038. uint32_t cfg_request_firmware_upgrade;
  1039. uint32_t cfg_suppress_link_up;
  1040. uint32_t cfg_rrq_xri_bitmap_sz;
  1041. u32 cfg_fcp_wait_abts_rsp;
  1042. uint32_t cfg_delay_discovery;
  1043. uint32_t cfg_sli_mode;
  1044. #define LPFC_INITIALIZE_LINK 0 /* do normal init_link mbox */
  1045. #define LPFC_DELAY_INIT_LINK 1 /* layered driver hold off */
  1046. #define LPFC_DELAY_INIT_LINK_INDEFINITELY 2 /* wait, manual intervention */
  1047. uint32_t cfg_fdmi_on;
  1048. #define LPFC_FDMI_NO_SUPPORT 0 /* FDMI not supported */
  1049. #define LPFC_FDMI_SUPPORT 1 /* FDMI supported? */
  1050. uint32_t cfg_enable_SmartSAN;
  1051. uint32_t cfg_enable_mds_diags;
  1052. uint32_t cfg_ras_fwlog_level;
  1053. uint32_t cfg_ras_fwlog_buffsize;
  1054. uint32_t cfg_ras_fwlog_func;
  1055. uint32_t cfg_enable_bbcr; /* Enable BB Credit Recovery */
  1056. uint32_t cfg_enable_dpp; /* Enable Direct Packet Push */
  1057. uint32_t cfg_enable_pbde;
  1058. uint32_t cfg_enable_mi;
  1059. struct nvmet_fc_target_port *targetport;
  1060. lpfc_vpd_t vpd; /* vital product data */
  1061. u32 cfg_max_vmid; /* maximum VMIDs allowed per port */
  1062. u32 cfg_vmid_app_header;
  1063. #define LPFC_VMID_APP_HEADER_DISABLE 0
  1064. #define LPFC_VMID_APP_HEADER_ENABLE 1
  1065. u32 cfg_vmid_priority_tagging;
  1066. u32 cfg_vmid_inactivity_timeout; /* Time after which the VMID */
  1067. /* deregisters from switch */
  1068. struct pci_dev *pcidev;
  1069. struct list_head work_list;
  1070. uint32_t work_ha; /* Host Attention Bits for WT */
  1071. uint32_t work_ha_mask; /* HA Bits owned by WT */
  1072. uint32_t work_hs; /* HS stored in case of ERRAT */
  1073. uint32_t work_status[2]; /* Extra status from SLIM */
  1074. wait_queue_head_t work_waitq;
  1075. struct task_struct *worker_thread;
  1076. unsigned long data_flags;
  1077. uint32_t border_sge_num;
  1078. uint32_t hbq_in_use; /* HBQs in use flag */
  1079. uint32_t hbq_count; /* Count of configured HBQs */
  1080. struct hbq_s hbqs[LPFC_MAX_HBQS]; /* local copy of hbq indicies */
  1081. atomic_t fcp_qidx; /* next FCP WQ (RR Policy) */
  1082. atomic_t nvme_qidx; /* next NVME WQ (RR Policy) */
  1083. phys_addr_t pci_bar0_map; /* Physical address for PCI BAR0 */
  1084. phys_addr_t pci_bar1_map; /* Physical address for PCI BAR1 */
  1085. phys_addr_t pci_bar2_map; /* Physical address for PCI BAR2 */
  1086. void __iomem *slim_memmap_p; /* Kernel memory mapped address for
  1087. PCI BAR0 */
  1088. void __iomem *ctrl_regs_memmap_p;/* Kernel memory mapped address for
  1089. PCI BAR2 */
  1090. void __iomem *pci_bar0_memmap_p; /* Kernel memory mapped address for
  1091. PCI BAR0 with dual-ULP support */
  1092. void __iomem *pci_bar2_memmap_p; /* Kernel memory mapped address for
  1093. PCI BAR2 with dual-ULP support */
  1094. void __iomem *pci_bar4_memmap_p; /* Kernel memory mapped address for
  1095. PCI BAR4 with dual-ULP support */
  1096. #define PCI_64BIT_BAR0 0
  1097. #define PCI_64BIT_BAR2 2
  1098. #define PCI_64BIT_BAR4 4
  1099. void __iomem *MBslimaddr; /* virtual address for mbox cmds */
  1100. void __iomem *HAregaddr; /* virtual address for host attn reg */
  1101. void __iomem *CAregaddr; /* virtual address for chip attn reg */
  1102. void __iomem *HSregaddr; /* virtual address for host status
  1103. reg */
  1104. void __iomem *HCregaddr; /* virtual address for host ctl reg */
  1105. struct lpfc_hgp __iomem *host_gp; /* Host side get/put pointers */
  1106. struct lpfc_pgp *port_gp;
  1107. uint32_t __iomem *hbq_put; /* Address in SLIM to HBQ put ptrs */
  1108. uint32_t *hbq_get; /* Host mem address of HBQ get ptrs */
  1109. int brd_no; /* FC board number */
  1110. char SerialNumber[32]; /* adapter Serial Number */
  1111. char OptionROMVersion[32]; /* adapter BIOS / Fcode version */
  1112. char BIOSVersion[16]; /* Boot BIOS version */
  1113. char ModelDesc[256]; /* Model Description */
  1114. char ModelName[80]; /* Model Name */
  1115. char ProgramType[256]; /* Program Type */
  1116. char Port[20]; /* Port No */
  1117. uint8_t vpd_flag; /* VPD data flag */
  1118. #define VPD_MODEL_DESC 0x1 /* valid vpd model description */
  1119. #define VPD_MODEL_NAME 0x2 /* valid vpd model name */
  1120. #define VPD_PROGRAM_TYPE 0x4 /* valid vpd program type */
  1121. #define VPD_PORT 0x8 /* valid vpd port data */
  1122. #define VPD_MASK 0xf /* mask for any vpd data */
  1123. struct timer_list fcp_poll_timer;
  1124. struct timer_list eratt_poll;
  1125. uint32_t eratt_poll_interval;
  1126. uint64_t bg_guard_err_cnt;
  1127. uint64_t bg_apptag_err_cnt;
  1128. uint64_t bg_reftag_err_cnt;
  1129. /* fastpath list. */
  1130. spinlock_t scsi_buf_list_get_lock; /* SCSI buf alloc list lock */
  1131. spinlock_t scsi_buf_list_put_lock; /* SCSI buf free list lock */
  1132. struct list_head lpfc_scsi_buf_list_get;
  1133. struct list_head lpfc_scsi_buf_list_put;
  1134. uint32_t total_scsi_bufs;
  1135. struct list_head lpfc_iocb_list;
  1136. uint32_t total_iocbq_bufs;
  1137. spinlock_t rrq_list_lock; /* lock for active_rrq_list */
  1138. struct list_head active_rrq_list;
  1139. spinlock_t hbalock;
  1140. struct work_struct unblock_request_work; /* SCSI layer unblock IOs */
  1141. /* dma_mem_pools */
  1142. struct dma_pool *lpfc_sg_dma_buf_pool;
  1143. struct dma_pool *lpfc_mbuf_pool;
  1144. struct dma_pool *lpfc_hrb_pool; /* header receive buffer pool */
  1145. struct dma_pool *lpfc_drb_pool; /* data receive buffer pool */
  1146. struct dma_pool *lpfc_nvmet_drb_pool; /* data receive buffer pool */
  1147. struct dma_pool *lpfc_hbq_pool; /* SLI3 hbq buffer pool */
  1148. struct dma_pool *lpfc_cmd_rsp_buf_pool;
  1149. struct lpfc_dma_pool lpfc_mbuf_safety_pool;
  1150. mempool_t *mbox_mem_pool;
  1151. mempool_t *nlp_mem_pool;
  1152. mempool_t *rrq_pool;
  1153. mempool_t *active_rrq_pool;
  1154. struct fc_host_statistics link_stats;
  1155. enum lpfc_irq_chann_mode irq_chann_mode;
  1156. enum intr_type_t intr_type;
  1157. uint32_t intr_mode;
  1158. #define LPFC_INTR_ERROR 0xFFFFFFFF
  1159. struct list_head port_list;
  1160. spinlock_t port_list_lock; /* lock for port_list mutations */
  1161. struct lpfc_vport *pport; /* physical lpfc_vport pointer */
  1162. uint16_t max_vpi; /* Maximum virtual nports */
  1163. #define LPFC_MAX_VPI 0xFF /* Max number VPI supported 0 - 0xff */
  1164. #define LPFC_MAX_VPORTS 0x100 /* Max vports per port, with pport */
  1165. uint16_t max_vports; /*
  1166. * For IOV HBAs max_vpi can change
  1167. * after a reset. max_vports is max
  1168. * number of vports present. This can
  1169. * be greater than max_vpi.
  1170. */
  1171. uint16_t vpi_base;
  1172. uint16_t vfi_base;
  1173. unsigned long *vpi_bmask; /* vpi allocation table */
  1174. uint16_t *vpi_ids;
  1175. uint16_t vpi_count;
  1176. struct list_head lpfc_vpi_blk_list;
  1177. /* Data structure used by fabric iocb scheduler */
  1178. struct list_head fabric_iocb_list;
  1179. atomic_t fabric_iocb_count;
  1180. struct timer_list fabric_block_timer;
  1181. unsigned long bit_flags;
  1182. atomic_t num_rsrc_err;
  1183. unsigned long last_rsrc_error_time;
  1184. unsigned long last_ramp_down_time;
  1185. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  1186. struct dentry *hba_debugfs_root;
  1187. atomic_t debugfs_vport_count;
  1188. struct dentry *debug_multixri_pools;
  1189. struct dentry *debug_hbqinfo;
  1190. struct dentry *debug_dumpHostSlim;
  1191. struct dentry *debug_dumpHBASlim;
  1192. struct dentry *debug_InjErrLBA; /* LBA to inject errors at */
  1193. struct dentry *debug_InjErrNPortID; /* NPortID to inject errors at */
  1194. struct dentry *debug_InjErrWWPN; /* WWPN to inject errors at */
  1195. struct dentry *debug_writeGuard; /* inject write guard_tag errors */
  1196. struct dentry *debug_writeApp; /* inject write app_tag errors */
  1197. struct dentry *debug_writeRef; /* inject write ref_tag errors */
  1198. struct dentry *debug_readGuard; /* inject read guard_tag errors */
  1199. struct dentry *debug_readApp; /* inject read app_tag errors */
  1200. struct dentry *debug_readRef; /* inject read ref_tag errors */
  1201. struct dentry *debug_nvmeio_trc;
  1202. struct lpfc_debugfs_nvmeio_trc *nvmeio_trc;
  1203. struct dentry *debug_hdwqinfo;
  1204. #ifdef LPFC_HDWQ_LOCK_STAT
  1205. struct dentry *debug_lockstat;
  1206. #endif
  1207. struct dentry *debug_cgn_buffer;
  1208. struct dentry *debug_rx_monitor;
  1209. struct dentry *debug_ras_log;
  1210. atomic_t nvmeio_trc_cnt;
  1211. uint32_t nvmeio_trc_size;
  1212. uint32_t nvmeio_trc_output_idx;
  1213. /* T10 DIF error injection */
  1214. uint32_t lpfc_injerr_wgrd_cnt;
  1215. uint32_t lpfc_injerr_wapp_cnt;
  1216. uint32_t lpfc_injerr_wref_cnt;
  1217. uint32_t lpfc_injerr_rgrd_cnt;
  1218. uint32_t lpfc_injerr_rapp_cnt;
  1219. uint32_t lpfc_injerr_rref_cnt;
  1220. uint32_t lpfc_injerr_nportid;
  1221. struct lpfc_name lpfc_injerr_wwpn;
  1222. sector_t lpfc_injerr_lba;
  1223. #define LPFC_INJERR_LBA_OFF (sector_t)(-1)
  1224. struct dentry *debug_slow_ring_trc;
  1225. struct lpfc_debugfs_trc *slow_ring_trc;
  1226. atomic_t slow_ring_trc_cnt;
  1227. /* iDiag debugfs sub-directory */
  1228. struct dentry *idiag_root;
  1229. struct dentry *idiag_pci_cfg;
  1230. struct dentry *idiag_bar_acc;
  1231. struct dentry *idiag_que_info;
  1232. struct dentry *idiag_que_acc;
  1233. struct dentry *idiag_drb_acc;
  1234. struct dentry *idiag_ctl_acc;
  1235. struct dentry *idiag_mbx_acc;
  1236. struct dentry *idiag_ext_acc;
  1237. uint8_t lpfc_idiag_last_eq;
  1238. #endif
  1239. uint16_t nvmeio_trc_on;
  1240. /* Used for deferred freeing of ELS data buffers */
  1241. struct list_head elsbuf;
  1242. int elsbuf_cnt;
  1243. int elsbuf_prev_cnt;
  1244. uint8_t temp_sensor_support;
  1245. /* Fields used for heart beat. */
  1246. unsigned long last_completion_time;
  1247. unsigned long skipped_hb;
  1248. struct timer_list hb_tmofunc;
  1249. struct timer_list rrq_tmr;
  1250. enum hba_temp_state over_temp_state;
  1251. /*
  1252. * Following bit will be set for all buffer tags which are not
  1253. * associated with any HBQ.
  1254. */
  1255. #define QUE_BUFTAG_BIT (1<<31)
  1256. uint32_t buffer_tag_count;
  1257. /* Maximum number of events that can be outstanding at any time*/
  1258. #define LPFC_MAX_EVT_COUNT 512
  1259. atomic_t fast_event_count;
  1260. uint32_t fcoe_eventtag;
  1261. uint32_t fcoe_eventtag_at_fcf_scan;
  1262. uint32_t fcoe_cvl_eventtag;
  1263. uint32_t fcoe_cvl_eventtag_attn;
  1264. struct lpfc_fcf fcf;
  1265. uint8_t fc_map[3];
  1266. uint8_t valid_vlan;
  1267. uint16_t vlan_id;
  1268. struct list_head fcf_conn_rec_list;
  1269. struct lpfc_defer_flogi_acc defer_flogi_acc;
  1270. spinlock_t ct_ev_lock; /* synchronize access to ct_ev_waiters */
  1271. struct list_head ct_ev_waiters;
  1272. struct unsol_rcv_ct_ctx ct_ctx[LPFC_CT_CTX_MAX];
  1273. uint32_t ctx_idx;
  1274. struct timer_list inactive_vmid_poll;
  1275. /* RAS Support */
  1276. spinlock_t ras_fwlog_lock; /* do not take while holding another lock */
  1277. struct lpfc_ras_fwlog ras_fwlog;
  1278. uint32_t iocb_cnt;
  1279. uint32_t iocb_max;
  1280. atomic_t sdev_cnt;
  1281. spinlock_t devicelock; /* lock for luns list */
  1282. mempool_t *device_data_mem_pool;
  1283. struct list_head luns;
  1284. #define LPFC_TRANSGRESSION_HIGH_TEMPERATURE 0x0080
  1285. #define LPFC_TRANSGRESSION_LOW_TEMPERATURE 0x0040
  1286. #define LPFC_TRANSGRESSION_HIGH_VOLTAGE 0x0020
  1287. #define LPFC_TRANSGRESSION_LOW_VOLTAGE 0x0010
  1288. #define LPFC_TRANSGRESSION_HIGH_TXBIAS 0x0008
  1289. #define LPFC_TRANSGRESSION_LOW_TXBIAS 0x0004
  1290. #define LPFC_TRANSGRESSION_HIGH_TXPOWER 0x0002
  1291. #define LPFC_TRANSGRESSION_LOW_TXPOWER 0x0001
  1292. #define LPFC_TRANSGRESSION_HIGH_RXPOWER 0x8000
  1293. #define LPFC_TRANSGRESSION_LOW_RXPOWER 0x4000
  1294. uint16_t sfp_alarm;
  1295. uint16_t sfp_warning;
  1296. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  1297. uint16_t hdwqstat_on;
  1298. #define LPFC_CHECK_OFF 0
  1299. #define LPFC_CHECK_NVME_IO 1
  1300. #define LPFC_CHECK_NVMET_IO 2
  1301. #define LPFC_CHECK_SCSI_IO 4
  1302. uint16_t ktime_on;
  1303. uint64_t ktime_data_samples;
  1304. uint64_t ktime_status_samples;
  1305. uint64_t ktime_last_cmd;
  1306. uint64_t ktime_seg1_total;
  1307. uint64_t ktime_seg1_min;
  1308. uint64_t ktime_seg1_max;
  1309. uint64_t ktime_seg2_total;
  1310. uint64_t ktime_seg2_min;
  1311. uint64_t ktime_seg2_max;
  1312. uint64_t ktime_seg3_total;
  1313. uint64_t ktime_seg3_min;
  1314. uint64_t ktime_seg3_max;
  1315. uint64_t ktime_seg4_total;
  1316. uint64_t ktime_seg4_min;
  1317. uint64_t ktime_seg4_max;
  1318. uint64_t ktime_seg5_total;
  1319. uint64_t ktime_seg5_min;
  1320. uint64_t ktime_seg5_max;
  1321. uint64_t ktime_seg6_total;
  1322. uint64_t ktime_seg6_min;
  1323. uint64_t ktime_seg6_max;
  1324. uint64_t ktime_seg7_total;
  1325. uint64_t ktime_seg7_min;
  1326. uint64_t ktime_seg7_max;
  1327. uint64_t ktime_seg8_total;
  1328. uint64_t ktime_seg8_min;
  1329. uint64_t ktime_seg8_max;
  1330. uint64_t ktime_seg9_total;
  1331. uint64_t ktime_seg9_min;
  1332. uint64_t ktime_seg9_max;
  1333. uint64_t ktime_seg10_total;
  1334. uint64_t ktime_seg10_min;
  1335. uint64_t ktime_seg10_max;
  1336. #endif
  1337. /* CMF objects */
  1338. struct lpfc_cgn_stat __percpu *cmf_stat;
  1339. uint32_t cmf_interval_rate; /* timer interval limit in ms */
  1340. uint32_t cmf_timer_cnt;
  1341. #define LPFC_CMF_INTERVAL 90
  1342. uint64_t cmf_link_byte_count;
  1343. uint64_t cmf_max_line_rate;
  1344. uint64_t cmf_max_bytes_per_interval;
  1345. uint64_t cmf_last_sync_bw;
  1346. #define LPFC_CMF_BLK_SIZE 512
  1347. struct hrtimer cmf_timer;
  1348. struct hrtimer cmf_stats_timer; /* 1 minute stats timer */
  1349. atomic_t cmf_bw_wait;
  1350. atomic_t cmf_busy;
  1351. atomic_t cmf_stop_io; /* To block request and stop IO's */
  1352. uint32_t cmf_active_mode;
  1353. uint32_t cmf_info_per_interval;
  1354. #define LPFC_MAX_CMF_INFO 32
  1355. struct timespec64 cmf_latency; /* Interval congestion timestamp */
  1356. uint32_t cmf_last_ts; /* Interval congestion time (ms) */
  1357. uint32_t cmf_active_info;
  1358. /* Signal / FPIN handling for Congestion Mgmt */
  1359. u8 cgn_reg_fpin; /* Negotiated value from RDF */
  1360. u8 cgn_init_reg_fpin; /* Initial value from READ_CONFIG */
  1361. #define LPFC_CGN_FPIN_NONE 0x0
  1362. #define LPFC_CGN_FPIN_WARN 0x1
  1363. #define LPFC_CGN_FPIN_ALARM 0x2
  1364. #define LPFC_CGN_FPIN_BOTH (LPFC_CGN_FPIN_WARN | LPFC_CGN_FPIN_ALARM)
  1365. u8 cgn_reg_signal; /* Negotiated value from EDC */
  1366. u8 cgn_init_reg_signal; /* Initial value from READ_CONFIG */
  1367. /* cgn_reg_signal and cgn_init_reg_signal use
  1368. * enum fc_edc_cg_signal_cap_types
  1369. */
  1370. u16 cgn_fpin_frequency; /* In units of msecs */
  1371. #define LPFC_FPIN_INIT_FREQ 0xffff
  1372. u32 cgn_sig_freq;
  1373. u32 cgn_acqe_cnt;
  1374. /* RX monitor handling for CMF */
  1375. struct lpfc_rx_info_monitor *rx_monitor;
  1376. atomic_t rx_max_read_cnt; /* Maximum read bytes */
  1377. uint64_t rx_block_cnt;
  1378. /* Congestion parameters from flash */
  1379. struct lpfc_cgn_param cgn_p;
  1380. /* Statistics counter for ACQE cgn alarms and warnings */
  1381. struct lpfc_cgn_acqe_stat cgn_acqe_stat;
  1382. /* Congestion buffer information */
  1383. struct lpfc_dmabuf *cgn_i; /* Congestion Info buffer */
  1384. atomic_t cgn_fabric_warn_cnt; /* Total warning cgn events for info */
  1385. atomic_t cgn_fabric_alarm_cnt; /* Total alarm cgn events for info */
  1386. atomic_t cgn_sync_warn_cnt; /* Total warning events for SYNC wqe */
  1387. atomic_t cgn_sync_alarm_cnt; /* Total alarm events for SYNC wqe */
  1388. atomic_t cgn_driver_evt_cnt; /* Total driver cgn events for fmw */
  1389. atomic_t cgn_latency_evt_cnt;
  1390. atomic64_t cgn_latency_evt; /* Avg latency per minute */
  1391. unsigned long cgn_evt_timestamp;
  1392. #define LPFC_CGN_TIMER_TO_MIN 60000 /* ms in a minute */
  1393. uint32_t cgn_evt_minute;
  1394. #define LPFC_SEC_MIN 60UL
  1395. #define LPFC_MIN_HOUR 60
  1396. #define LPFC_HOUR_DAY 24
  1397. #define LPFC_MIN_DAY (LPFC_MIN_HOUR * LPFC_HOUR_DAY)
  1398. struct hlist_node cpuhp; /* used for cpuhp per hba callback */
  1399. struct timer_list cpuhp_poll_timer;
  1400. struct list_head poll_list; /* slowpath eq polling list */
  1401. #define LPFC_POLL_HB 1 /* slowpath heartbeat */
  1402. char os_host_name[MAXHOSTNAMELEN];
  1403. /* LD Signaling */
  1404. u32 degrade_activate_threshold;
  1405. u32 degrade_deactivate_threshold;
  1406. u32 fec_degrade_interval;
  1407. atomic_t dbg_log_idx;
  1408. atomic_t dbg_log_cnt;
  1409. atomic_t dbg_log_dmping;
  1410. struct dbg_log_ent dbg_log[DBG_LOG_SZ];
  1411. };
  1412. #define LPFC_MAX_RXMONITOR_ENTRY 800
  1413. #define LPFC_MAX_RXMONITOR_DUMP 32
  1414. struct rx_info_entry {
  1415. uint64_t cmf_bytes; /* Total no of read bytes for CMF_SYNC_WQE */
  1416. uint64_t total_bytes; /* Total no of read bytes requested */
  1417. uint64_t rcv_bytes; /* Total no of read bytes completed */
  1418. uint64_t avg_io_size;
  1419. uint64_t avg_io_latency;/* Average io latency in microseconds */
  1420. uint64_t max_read_cnt; /* Maximum read bytes */
  1421. uint64_t max_bytes_per_interval;
  1422. uint32_t cmf_busy;
  1423. uint32_t cmf_info; /* CMF_SYNC_WQE info */
  1424. uint32_t io_cnt;
  1425. uint32_t timer_utilization;
  1426. uint32_t timer_interval;
  1427. };
  1428. struct lpfc_rx_info_monitor {
  1429. struct rx_info_entry *ring; /* info organized in a circular buffer */
  1430. u32 head_idx, tail_idx; /* index to head/tail of ring */
  1431. spinlock_t lock; /* spinlock for ring */
  1432. u32 entries; /* storing number entries/size of ring */
  1433. };
  1434. static inline struct Scsi_Host *
  1435. lpfc_shost_from_vport(struct lpfc_vport *vport)
  1436. {
  1437. return container_of((void *) vport, struct Scsi_Host, hostdata[0]);
  1438. }
  1439. static inline void
  1440. lpfc_set_loopback_flag(struct lpfc_hba *phba)
  1441. {
  1442. if (phba->cfg_topology == FLAGS_LOCAL_LB)
  1443. phba->link_flag |= LS_LOOPBACK_MODE;
  1444. else
  1445. phba->link_flag &= ~LS_LOOPBACK_MODE;
  1446. }
  1447. static inline int
  1448. lpfc_is_link_up(struct lpfc_hba *phba)
  1449. {
  1450. return phba->link_state == LPFC_LINK_UP ||
  1451. phba->link_state == LPFC_CLEAR_LA ||
  1452. phba->link_state == LPFC_HBA_READY;
  1453. }
  1454. static inline void
  1455. lpfc_worker_wake_up(struct lpfc_hba *phba)
  1456. {
  1457. /* Set the lpfc data pending flag */
  1458. set_bit(LPFC_DATA_READY, &phba->data_flags);
  1459. /* Wake up worker thread */
  1460. wake_up(&phba->work_waitq);
  1461. return;
  1462. }
  1463. static inline int
  1464. lpfc_readl(void __iomem *addr, uint32_t *data)
  1465. {
  1466. uint32_t temp;
  1467. temp = readl(addr);
  1468. if (temp == 0xffffffff)
  1469. return -EIO;
  1470. *data = temp;
  1471. return 0;
  1472. }
  1473. static inline int
  1474. lpfc_sli_read_hs(struct lpfc_hba *phba)
  1475. {
  1476. /*
  1477. * There was a link/board error. Read the status register to retrieve
  1478. * the error event and process it.
  1479. */
  1480. phba->sli.slistat.err_attn_event++;
  1481. /* Save status info and check for unplug error */
  1482. if (lpfc_readl(phba->HSregaddr, &phba->work_hs) ||
  1483. lpfc_readl(phba->MBslimaddr + 0xa8, &phba->work_status[0]) ||
  1484. lpfc_readl(phba->MBslimaddr + 0xac, &phba->work_status[1])) {
  1485. return -EIO;
  1486. }
  1487. /* Clear chip Host Attention error bit */
  1488. writel(HA_ERATT, phba->HAregaddr);
  1489. readl(phba->HAregaddr); /* flush */
  1490. phba->pport->stopped = 1;
  1491. return 0;
  1492. }
  1493. static inline struct lpfc_sli_ring *
  1494. lpfc_phba_elsring(struct lpfc_hba *phba)
  1495. {
  1496. /* Return NULL if sli_rev has become invalid due to bad fw */
  1497. if (phba->sli_rev != LPFC_SLI_REV4 &&
  1498. phba->sli_rev != LPFC_SLI_REV3 &&
  1499. phba->sli_rev != LPFC_SLI_REV2)
  1500. return NULL;
  1501. if (phba->sli_rev == LPFC_SLI_REV4) {
  1502. if (phba->sli4_hba.els_wq)
  1503. return phba->sli4_hba.els_wq->pring;
  1504. else
  1505. return NULL;
  1506. }
  1507. return &phba->sli.sli3_ring[LPFC_ELS_RING];
  1508. }
  1509. /**
  1510. * lpfc_next_online_cpu - Finds next online CPU on cpumask
  1511. * @mask: Pointer to phba's cpumask member.
  1512. * @start: starting cpu index
  1513. *
  1514. * Note: If no valid cpu found, then nr_cpu_ids is returned.
  1515. *
  1516. **/
  1517. static inline unsigned int
  1518. lpfc_next_online_cpu(const struct cpumask *mask, unsigned int start)
  1519. {
  1520. unsigned int cpu_it;
  1521. for_each_cpu_wrap(cpu_it, mask, start) {
  1522. if (cpu_online(cpu_it))
  1523. break;
  1524. }
  1525. return cpu_it;
  1526. }
  1527. /**
  1528. * lpfc_next_present_cpu - Finds next present CPU after n
  1529. * @n: the cpu prior to search
  1530. *
  1531. * Note: If no next present cpu, then fallback to first present cpu.
  1532. *
  1533. **/
  1534. static inline unsigned int lpfc_next_present_cpu(int n)
  1535. {
  1536. unsigned int cpu;
  1537. cpu = cpumask_next(n, cpu_present_mask);
  1538. if (cpu >= nr_cpu_ids)
  1539. cpu = cpumask_first(cpu_present_mask);
  1540. return cpu;
  1541. }
  1542. /**
  1543. * lpfc_sli4_mod_hba_eq_delay - update EQ delay
  1544. * @phba: Pointer to HBA context object.
  1545. * @q: The Event Queue to update.
  1546. * @delay: The delay value (in us) to be written.
  1547. *
  1548. **/
  1549. static inline void
  1550. lpfc_sli4_mod_hba_eq_delay(struct lpfc_hba *phba, struct lpfc_queue *eq,
  1551. u32 delay)
  1552. {
  1553. struct lpfc_register reg_data;
  1554. reg_data.word0 = 0;
  1555. bf_set(lpfc_sliport_eqdelay_id, &reg_data, eq->queue_id);
  1556. bf_set(lpfc_sliport_eqdelay_delay, &reg_data, delay);
  1557. writel(reg_data.word0, phba->sli4_hba.u.if_type2.EQDregaddr);
  1558. eq->q_mode = delay;
  1559. }
  1560. /*
  1561. * Macro that declares tables and a routine to perform enum type to
  1562. * ascii string lookup.
  1563. *
  1564. * Defines a <key,value> table for an enum. Uses xxx_INIT defines for
  1565. * the enum to populate the table. Macro defines a routine (named
  1566. * by caller) that will search all elements of the table for the key
  1567. * and return the name string if found or "Unrecognized" if not found.
  1568. */
  1569. #define DECLARE_ENUM2STR_LOOKUP(routine, enum_name, enum_init) \
  1570. static struct { \
  1571. enum enum_name value; \
  1572. char *name; \
  1573. } fc_##enum_name##_e2str_names[] = enum_init; \
  1574. static const char *routine(enum enum_name table_key) \
  1575. { \
  1576. int i; \
  1577. char *name = "Unrecognized"; \
  1578. \
  1579. for (i = 0; i < ARRAY_SIZE(fc_##enum_name##_e2str_names); i++) {\
  1580. if (fc_##enum_name##_e2str_names[i].value == table_key) {\
  1581. name = fc_##enum_name##_e2str_names[i].name; \
  1582. break; \
  1583. } \
  1584. } \
  1585. return name; \
  1586. }
  1587. /**
  1588. * lpfc_is_vmid_enabled - returns if VMID is enabled for either switch types
  1589. * @phba: Pointer to HBA context object.
  1590. *
  1591. * Relationship between the enable, target support and if vmid tag is required
  1592. * for the particular combination
  1593. * ---------------------------------------------------
  1594. * Switch Enable Flag Target Support VMID Needed
  1595. * ---------------------------------------------------
  1596. * App Id 0 NA N
  1597. * App Id 1 0 N
  1598. * App Id 1 1 Y
  1599. * Pr Tag 0 NA N
  1600. * Pr Tag 1 0 N
  1601. * Pr Tag 1 1 Y
  1602. * Pr Tag 2 * Y
  1603. ---------------------------------------------------
  1604. *
  1605. **/
  1606. static inline int lpfc_is_vmid_enabled(struct lpfc_hba *phba)
  1607. {
  1608. return phba->cfg_vmid_app_header || phba->cfg_vmid_priority_tagging;
  1609. }
  1610. static inline
  1611. u8 get_job_ulpstatus(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  1612. {
  1613. if (phba->sli_rev == LPFC_SLI_REV4)
  1614. return bf_get(lpfc_wcqe_c_status, &iocbq->wcqe_cmpl);
  1615. else
  1616. return iocbq->iocb.ulpStatus;
  1617. }
  1618. static inline
  1619. u32 get_job_word4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  1620. {
  1621. if (phba->sli_rev == LPFC_SLI_REV4)
  1622. return iocbq->wcqe_cmpl.parameter;
  1623. else
  1624. return iocbq->iocb.un.ulpWord[4];
  1625. }
  1626. static inline
  1627. u8 get_job_cmnd(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  1628. {
  1629. if (phba->sli_rev == LPFC_SLI_REV4)
  1630. return bf_get(wqe_cmnd, &iocbq->wqe.generic.wqe_com);
  1631. else
  1632. return iocbq->iocb.ulpCommand;
  1633. }
  1634. static inline
  1635. u16 get_job_ulpcontext(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  1636. {
  1637. if (phba->sli_rev == LPFC_SLI_REV4)
  1638. return bf_get(wqe_ctxt_tag, &iocbq->wqe.generic.wqe_com);
  1639. else
  1640. return iocbq->iocb.ulpContext;
  1641. }
  1642. static inline
  1643. u16 get_job_rcvoxid(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  1644. {
  1645. if (phba->sli_rev == LPFC_SLI_REV4)
  1646. return bf_get(wqe_rcvoxid, &iocbq->wqe.generic.wqe_com);
  1647. else
  1648. return iocbq->iocb.unsli3.rcvsli3.ox_id;
  1649. }
  1650. static inline
  1651. u32 get_job_data_placed(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  1652. {
  1653. if (phba->sli_rev == LPFC_SLI_REV4)
  1654. return iocbq->wcqe_cmpl.total_data_placed;
  1655. else
  1656. return iocbq->iocb.un.genreq64.bdl.bdeSize;
  1657. }
  1658. static inline
  1659. u32 get_job_abtsiotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  1660. {
  1661. if (phba->sli_rev == LPFC_SLI_REV4)
  1662. return iocbq->wqe.abort_cmd.wqe_com.abort_tag;
  1663. else
  1664. return iocbq->iocb.un.acxri.abortIoTag;
  1665. }
  1666. static inline
  1667. u32 get_job_els_rsp64_did(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  1668. {
  1669. if (phba->sli_rev == LPFC_SLI_REV4)
  1670. return bf_get(wqe_els_did, &iocbq->wqe.els_req.wqe_dest);
  1671. else
  1672. return iocbq->iocb.un.elsreq64.remoteID;
  1673. }