lpfc.h 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2017-2018 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/ktime.h>
  25. #include <linux/workqueue.h>
  26. #if defined(CONFIG_DEBUG_FS) && !defined(CONFIG_SCSI_LPFC_DEBUG_FS)
  27. #define CONFIG_SCSI_LPFC_DEBUG_FS
  28. #endif
  29. struct lpfc_sli2_slim;
  30. #define ELX_MODEL_NAME_SIZE 80
  31. #define LPFC_PCI_DEV_LP 0x1
  32. #define LPFC_PCI_DEV_OC 0x2
  33. #define LPFC_SLI_REV2 2
  34. #define LPFC_SLI_REV3 3
  35. #define LPFC_SLI_REV4 4
  36. #define LPFC_MAX_TARGET 4096 /* max number of targets supported */
  37. #define LPFC_MAX_DISC_THREADS 64 /* max outstanding discovery els
  38. requests */
  39. #define LPFC_MAX_NS_RETRY 3 /* Number of retry attempts to contact
  40. the NameServer before giving up. */
  41. #define LPFC_CMD_PER_LUN 3 /* max outstanding cmds per lun */
  42. #define LPFC_DEFAULT_SG_SEG_CNT 64 /* sg element count per scsi cmnd */
  43. #define LPFC_DEFAULT_MENLO_SG_SEG_CNT 128 /* sg element count per scsi
  44. cmnd for menlo needs nearly twice as for firmware
  45. downloads using bsg */
  46. #define LPFC_MIN_SG_SLI4_BUF_SZ 0x800 /* based on LPFC_DEFAULT_SG_SEG_CNT */
  47. #define LPFC_MAX_SG_SLI4_SEG_CNT_DIF 128 /* sg element count per scsi cmnd */
  48. #define LPFC_MAX_SG_SEG_CNT_DIF 512 /* sg element count per scsi cmnd */
  49. #define LPFC_MAX_SG_SEG_CNT 4096 /* sg element count per scsi cmnd */
  50. #define LPFC_MIN_SG_SEG_CNT 32 /* sg element count per scsi cmnd */
  51. #define LPFC_MAX_SGL_SEG_CNT 512 /* SGL element count per scsi cmnd */
  52. #define LPFC_MAX_BPL_SEG_CNT 4096 /* BPL element count per scsi cmnd */
  53. #define LPFC_MAX_NVME_SEG_CNT 256 /* max SGL element cnt per NVME cmnd */
  54. #define LPFC_MAX_SGE_SIZE 0x80000000 /* Maximum data allowed in a SGE */
  55. #define LPFC_IOCB_LIST_CNT 2250 /* list of IOCBs for fast-path usage. */
  56. #define LPFC_Q_RAMP_UP_INTERVAL 120 /* lun q_depth ramp up interval */
  57. #define LPFC_VNAME_LEN 100 /* vport symbolic name length */
  58. #define LPFC_TGTQ_RAMPUP_PCENT 5 /* Target queue rampup in percentage */
  59. #define LPFC_MIN_TGT_QDEPTH 10
  60. #define LPFC_MAX_TGT_QDEPTH 0xFFFF
  61. #define LPFC_MAX_BUCKET_COUNT 20 /* Maximum no. of buckets for stat data
  62. collection. */
  63. /*
  64. * Following time intervals are used of adjusting SCSI device
  65. * queue depths when there are driver resource error or Firmware
  66. * resource error.
  67. */
  68. /* 1 Second */
  69. #define QUEUE_RAMP_DOWN_INTERVAL (msecs_to_jiffies(1000 * 1))
  70. /* Number of exchanges reserved for discovery to complete */
  71. #define LPFC_DISC_IOCB_BUFF_COUNT 20
  72. #define LPFC_HB_MBOX_INTERVAL 5 /* Heart beat interval in seconds. */
  73. #define LPFC_HB_MBOX_TIMEOUT 30 /* Heart beat timeout in seconds. */
  74. #define LPFC_LOOK_AHEAD_OFF 0 /* Look ahead logic is turned off */
  75. /* Error Attention event polling interval */
  76. #define LPFC_ERATT_POLL_INTERVAL 5 /* EATT poll interval in seconds */
  77. /* Define macros for 64 bit support */
  78. #define putPaddrLow(addr) ((uint32_t) (0xffffffff & (u64)(addr)))
  79. #define putPaddrHigh(addr) ((uint32_t) (0xffffffff & (((u64)(addr))>>32)))
  80. #define getPaddr(high, low) ((dma_addr_t)( \
  81. (( (u64)(high)<<16 ) << 16)|( (u64)(low))))
  82. /* Provide maximum configuration definitions. */
  83. #define LPFC_DRVR_TIMEOUT 16 /* driver iocb timeout value in sec */
  84. #define FC_MAX_ADPTMSG 64
  85. #define MAX_HBAEVT 32
  86. #define MAX_HBAS_NO_RESET 16
  87. /* Number of MSI-X vectors the driver uses */
  88. #define LPFC_MSIX_VECTORS 2
  89. /* lpfc wait event data ready flag */
  90. #define LPFC_DATA_READY 0 /* bit 0 */
  91. /* queue dump line buffer size */
  92. #define LPFC_LBUF_SZ 128
  93. /* mailbox system shutdown options */
  94. #define LPFC_MBX_NO_WAIT 0
  95. #define LPFC_MBX_WAIT 1
  96. enum lpfc_polling_flags {
  97. ENABLE_FCP_RING_POLLING = 0x1,
  98. DISABLE_FCP_RING_INT = 0x2
  99. };
  100. struct perf_prof {
  101. uint16_t cmd_cpu[40];
  102. uint16_t rsp_cpu[40];
  103. uint16_t qh_cpu[40];
  104. uint16_t wqidx[40];
  105. };
  106. /*
  107. * Provide for FC4 TYPE x28 - NVME. The
  108. * bit mask for FCP and NVME is 0x8 identically
  109. * because they are 32 bit positions distance.
  110. */
  111. #define LPFC_FC4_TYPE_BITMASK 0x00000100
  112. /* Provide DMA memory definitions the driver uses per port instance. */
  113. struct lpfc_dmabuf {
  114. struct list_head list;
  115. void *virt; /* virtual address ptr */
  116. dma_addr_t phys; /* mapped address */
  117. uint32_t buffer_tag; /* used for tagged queue ring */
  118. };
  119. struct lpfc_nvmet_ctxbuf {
  120. struct list_head list;
  121. struct lpfc_nvmet_rcv_ctx *context;
  122. struct lpfc_iocbq *iocbq;
  123. struct lpfc_sglq *sglq;
  124. };
  125. struct lpfc_dma_pool {
  126. struct lpfc_dmabuf *elements;
  127. uint32_t max_count;
  128. uint32_t current_count;
  129. };
  130. struct hbq_dmabuf {
  131. struct lpfc_dmabuf hbuf;
  132. struct lpfc_dmabuf dbuf;
  133. uint16_t total_size;
  134. uint16_t bytes_recv;
  135. uint32_t tag;
  136. struct lpfc_cq_event cq_event;
  137. unsigned long time_stamp;
  138. void *context;
  139. };
  140. struct rqb_dmabuf {
  141. struct lpfc_dmabuf hbuf;
  142. struct lpfc_dmabuf dbuf;
  143. uint16_t total_size;
  144. uint16_t bytes_recv;
  145. uint16_t idx;
  146. struct lpfc_queue *hrq; /* ptr to associated Header RQ */
  147. struct lpfc_queue *drq; /* ptr to associated Data RQ */
  148. };
  149. /* Priority bit. Set value to exceed low water mark in lpfc_mem. */
  150. #define MEM_PRI 0x100
  151. /****************************************************************************/
  152. /* Device VPD save area */
  153. /****************************************************************************/
  154. typedef struct lpfc_vpd {
  155. uint32_t status; /* vpd status value */
  156. uint32_t length; /* number of bytes actually returned */
  157. struct {
  158. uint32_t rsvd1; /* Revision numbers */
  159. uint32_t biuRev;
  160. uint32_t smRev;
  161. uint32_t smFwRev;
  162. uint32_t endecRev;
  163. uint16_t rBit;
  164. uint8_t fcphHigh;
  165. uint8_t fcphLow;
  166. uint8_t feaLevelHigh;
  167. uint8_t feaLevelLow;
  168. uint32_t postKernRev;
  169. uint32_t opFwRev;
  170. uint8_t opFwName[16];
  171. uint32_t sli1FwRev;
  172. uint8_t sli1FwName[16];
  173. uint32_t sli2FwRev;
  174. uint8_t sli2FwName[16];
  175. } rev;
  176. struct {
  177. #ifdef __BIG_ENDIAN_BITFIELD
  178. uint32_t rsvd3 :19; /* Reserved */
  179. uint32_t cdss : 1; /* Configure Data Security SLI */
  180. uint32_t rsvd2 : 3; /* Reserved */
  181. uint32_t cbg : 1; /* Configure BlockGuard */
  182. uint32_t cmv : 1; /* Configure Max VPIs */
  183. uint32_t ccrp : 1; /* Config Command Ring Polling */
  184. uint32_t csah : 1; /* Configure Synchronous Abort Handling */
  185. uint32_t chbs : 1; /* Cofigure Host Backing store */
  186. uint32_t cinb : 1; /* Enable Interrupt Notification Block */
  187. uint32_t cerbm : 1; /* Configure Enhanced Receive Buf Mgmt */
  188. uint32_t cmx : 1; /* Configure Max XRIs */
  189. uint32_t cmr : 1; /* Configure Max RPIs */
  190. #else /* __LITTLE_ENDIAN */
  191. uint32_t cmr : 1; /* Configure Max RPIs */
  192. uint32_t cmx : 1; /* Configure Max XRIs */
  193. uint32_t cerbm : 1; /* Configure Enhanced Receive Buf Mgmt */
  194. uint32_t cinb : 1; /* Enable Interrupt Notification Block */
  195. uint32_t chbs : 1; /* Cofigure Host Backing store */
  196. uint32_t csah : 1; /* Configure Synchronous Abort Handling */
  197. uint32_t ccrp : 1; /* Config Command Ring Polling */
  198. uint32_t cmv : 1; /* Configure Max VPIs */
  199. uint32_t cbg : 1; /* Configure BlockGuard */
  200. uint32_t rsvd2 : 3; /* Reserved */
  201. uint32_t cdss : 1; /* Configure Data Security SLI */
  202. uint32_t rsvd3 :19; /* Reserved */
  203. #endif
  204. } sli3Feat;
  205. } lpfc_vpd_t;
  206. struct lpfc_scsi_buf;
  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 elsRcvRPS;
  233. uint32_t elsRcvRPL;
  234. uint32_t elsRcvRRQ;
  235. uint32_t elsRcvRTV;
  236. uint32_t elsRcvECHO;
  237. uint32_t elsRcvLCB;
  238. uint32_t elsRcvRDP;
  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 elsXmitRNID;
  247. uint32_t elsXmitFARP;
  248. uint32_t elsXmitFARPR;
  249. uint32_t elsXmitACC;
  250. uint32_t elsXmitLSRJT;
  251. uint32_t frameRcvBcast;
  252. uint32_t frameRcvMulti;
  253. uint32_t strayXmitCmpl;
  254. uint32_t frameXmitDelay;
  255. uint32_t xriCmdCmpl;
  256. uint32_t xriStatErr;
  257. uint32_t LinkUp;
  258. uint32_t LinkDown;
  259. uint32_t LinkMultiEvent;
  260. uint32_t NoRcvBuf;
  261. uint32_t fcpCmd;
  262. uint32_t fcpCmpl;
  263. uint32_t fcpRspErr;
  264. uint32_t fcpRemoteStop;
  265. uint32_t fcpPortRjt;
  266. uint32_t fcpPortBusy;
  267. uint32_t fcpError;
  268. uint32_t fcpLocalErr;
  269. };
  270. struct lpfc_hba;
  271. enum discovery_state {
  272. LPFC_VPORT_UNKNOWN = 0, /* vport state is unknown */
  273. LPFC_VPORT_FAILED = 1, /* vport has failed */
  274. LPFC_LOCAL_CFG_LINK = 6, /* local NPORT Id configured */
  275. LPFC_FLOGI = 7, /* FLOGI sent to Fabric */
  276. LPFC_FDISC = 8, /* FDISC sent for vport */
  277. LPFC_FABRIC_CFG_LINK = 9, /* Fabric assigned NPORT Id
  278. * configured */
  279. LPFC_NS_REG = 10, /* Register with NameServer */
  280. LPFC_NS_QRY = 11, /* Query NameServer for NPort ID list */
  281. LPFC_BUILD_DISC_LIST = 12, /* Build ADISC and PLOGI lists for
  282. * device authentication / discovery */
  283. LPFC_DISC_AUTH = 13, /* Processing ADISC list */
  284. LPFC_VPORT_READY = 32,
  285. };
  286. enum hba_state {
  287. LPFC_LINK_UNKNOWN = 0, /* HBA state is unknown */
  288. LPFC_WARM_START = 1, /* HBA state after selective reset */
  289. LPFC_INIT_START = 2, /* Initial state after board reset */
  290. LPFC_INIT_MBX_CMDS = 3, /* Initialize HBA with mbox commands */
  291. LPFC_LINK_DOWN = 4, /* HBA initialized, link is down */
  292. LPFC_LINK_UP = 5, /* Link is up - issue READ_LA */
  293. LPFC_CLEAR_LA = 6, /* authentication cmplt - issue
  294. * CLEAR_LA */
  295. LPFC_HBA_READY = 32,
  296. LPFC_HBA_ERROR = -1
  297. };
  298. struct lpfc_vport {
  299. struct lpfc_hba *phba;
  300. struct list_head listentry;
  301. uint8_t port_type;
  302. #define LPFC_PHYSICAL_PORT 1
  303. #define LPFC_NPIV_PORT 2
  304. #define LPFC_FABRIC_PORT 3
  305. enum discovery_state port_state;
  306. uint16_t vpi;
  307. uint16_t vfi;
  308. uint8_t vpi_state;
  309. #define LPFC_VPI_REGISTERED 0x1
  310. uint32_t fc_flag; /* FC flags */
  311. /* Several of these flags are HBA centric and should be moved to
  312. * phba->link_flag (e.g. FC_PTP, FC_PUBLIC_LOOP)
  313. */
  314. #define FC_PT2PT 0x1 /* pt2pt with no fabric */
  315. #define FC_PT2PT_PLOGI 0x2 /* pt2pt initiate PLOGI */
  316. #define FC_DISC_TMO 0x4 /* Discovery timer running */
  317. #define FC_PUBLIC_LOOP 0x8 /* Public loop */
  318. #define FC_LBIT 0x10 /* LOGIN bit in loopinit set */
  319. #define FC_RSCN_MODE 0x20 /* RSCN cmd rcv'ed */
  320. #define FC_NLP_MORE 0x40 /* More node to process in node tbl */
  321. #define FC_OFFLINE_MODE 0x80 /* Interface is offline for diag */
  322. #define FC_FABRIC 0x100 /* We are fabric attached */
  323. #define FC_VPORT_LOGO_RCVD 0x200 /* LOGO received on vport */
  324. #define FC_RSCN_DISCOVERY 0x400 /* Auth all devices after RSCN */
  325. #define FC_LOGO_RCVD_DID_CHNG 0x800 /* FDISC on phys port detect DID chng*/
  326. #define FC_SCSI_SCAN_TMO 0x4000 /* scsi scan timer running */
  327. #define FC_ABORT_DISCOVERY 0x8000 /* we want to abort discovery */
  328. #define FC_NDISC_ACTIVE 0x10000 /* NPort discovery active */
  329. #define FC_BYPASSED_MODE 0x20000 /* NPort is in bypassed mode */
  330. #define FC_VPORT_NEEDS_REG_VPI 0x80000 /* Needs to have its vpi registered */
  331. #define FC_RSCN_DEFERRED 0x100000 /* A deferred RSCN being processed */
  332. #define FC_VPORT_NEEDS_INIT_VPI 0x200000 /* Need to INIT_VPI before FDISC */
  333. #define FC_VPORT_CVL_RCVD 0x400000 /* VLink failed due to CVL */
  334. #define FC_VFI_REGISTERED 0x800000 /* VFI is registered */
  335. #define FC_FDISC_COMPLETED 0x1000000/* FDISC completed */
  336. #define FC_DISC_DELAYED 0x2000000/* Delay NPort discovery */
  337. uint32_t ct_flags;
  338. #define FC_CT_RFF_ID 0x1 /* RFF_ID accepted by switch */
  339. #define FC_CT_RNN_ID 0x2 /* RNN_ID accepted by switch */
  340. #define FC_CT_RSNN_NN 0x4 /* RSNN_NN accepted by switch */
  341. #define FC_CT_RSPN_ID 0x8 /* RSPN_ID accepted by switch */
  342. #define FC_CT_RFT_ID 0x10 /* RFT_ID accepted by switch */
  343. struct list_head fc_nodes;
  344. /* Keep counters for the number of entries in each list. */
  345. uint16_t fc_plogi_cnt;
  346. uint16_t fc_adisc_cnt;
  347. uint16_t fc_reglogin_cnt;
  348. uint16_t fc_prli_cnt;
  349. uint16_t fc_unmap_cnt;
  350. uint16_t fc_map_cnt;
  351. uint16_t fc_npr_cnt;
  352. uint16_t fc_unused_cnt;
  353. struct serv_parm fc_sparam; /* buffer for our service parameters */
  354. uint32_t fc_myDID; /* fibre channel S_ID */
  355. uint32_t fc_prevDID; /* previous fibre channel S_ID */
  356. struct lpfc_name fabric_portname;
  357. struct lpfc_name fabric_nodename;
  358. int32_t stopped; /* HBA has not been restarted since last ERATT */
  359. uint8_t fc_linkspeed; /* Link speed after last READ_LA */
  360. uint32_t num_disc_nodes; /* in addition to hba_state */
  361. uint32_t gidft_inp; /* cnt of outstanding GID_FTs */
  362. uint32_t fc_nlp_cnt; /* outstanding NODELIST requests */
  363. uint32_t fc_rscn_id_cnt; /* count of RSCNs payloads in list */
  364. uint32_t fc_rscn_flush; /* flag use of fc_rscn_id_list */
  365. struct lpfc_dmabuf *fc_rscn_id_list[FC_MAX_HOLD_RSCN];
  366. struct lpfc_name fc_nodename; /* fc nodename */
  367. struct lpfc_name fc_portname; /* fc portname */
  368. struct lpfc_work_evt disc_timeout_evt;
  369. struct timer_list fc_disctmo; /* Discovery rescue timer */
  370. uint8_t fc_ns_retry; /* retries for fabric nameserver */
  371. uint32_t fc_prli_sent; /* cntr for outstanding PRLIs */
  372. spinlock_t work_port_lock;
  373. uint32_t work_port_events; /* Timeout to be handled */
  374. #define WORKER_DISC_TMO 0x1 /* vport: Discovery timeout */
  375. #define WORKER_ELS_TMO 0x2 /* vport: ELS timeout */
  376. #define WORKER_DELAYED_DISC_TMO 0x8 /* vport: delayed discovery */
  377. #define WORKER_MBOX_TMO 0x100 /* hba: MBOX timeout */
  378. #define WORKER_HB_TMO 0x200 /* hba: Heart beat timeout */
  379. #define WORKER_FABRIC_BLOCK_TMO 0x400 /* hba: fabric block timeout */
  380. #define WORKER_RAMP_DOWN_QUEUE 0x800 /* hba: Decrease Q depth */
  381. #define WORKER_RAMP_UP_QUEUE 0x1000 /* hba: Increase Q depth */
  382. #define WORKER_SERVICE_TXQ 0x2000 /* hba: IOCBs on the txq */
  383. struct timer_list els_tmofunc;
  384. struct timer_list delayed_disc_tmo;
  385. int unreg_vpi_cmpl;
  386. uint8_t load_flag;
  387. #define FC_LOADING 0x1 /* HBA in process of loading drvr */
  388. #define FC_UNLOADING 0x2 /* HBA in process of unloading drvr */
  389. #define FC_ALLOW_FDMI 0x4 /* port is ready for FDMI requests */
  390. /* Vport Config Parameters */
  391. uint32_t cfg_scan_down;
  392. uint32_t cfg_lun_queue_depth;
  393. uint32_t cfg_nodev_tmo;
  394. uint32_t cfg_devloss_tmo;
  395. uint32_t cfg_restrict_login;
  396. uint32_t cfg_peer_port_login;
  397. uint32_t cfg_fcp_class;
  398. uint32_t cfg_use_adisc;
  399. uint32_t cfg_discovery_threads;
  400. uint32_t cfg_log_verbose;
  401. uint32_t cfg_max_luns;
  402. uint32_t cfg_enable_da_id;
  403. uint32_t cfg_max_scsicmpl_time;
  404. uint32_t cfg_tgt_queue_depth;
  405. uint32_t cfg_first_burst_size;
  406. uint32_t dev_loss_tmo_changed;
  407. struct fc_vport *fc_vport;
  408. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  409. struct dentry *debug_disc_trc;
  410. struct dentry *debug_nodelist;
  411. struct dentry *debug_nvmestat;
  412. struct dentry *debug_nvmektime;
  413. struct dentry *debug_cpucheck;
  414. struct dentry *vport_debugfs_root;
  415. struct lpfc_debugfs_trc *disc_trc;
  416. atomic_t disc_trc_cnt;
  417. #endif
  418. uint8_t stat_data_enabled;
  419. uint8_t stat_data_blocked;
  420. struct list_head rcv_buffer_list;
  421. unsigned long rcv_buffer_time_stamp;
  422. uint32_t vport_flag;
  423. #define STATIC_VPORT 1
  424. #define FAWWPN_SET 2
  425. #define FAWWPN_PARAM_CHG 4
  426. uint16_t fdmi_num_disc;
  427. uint32_t fdmi_hba_mask;
  428. uint32_t fdmi_port_mask;
  429. /* There is a single nvme instance per vport. */
  430. struct nvme_fc_local_port *localport;
  431. uint8_t nvmei_support; /* driver supports NVME Initiator */
  432. uint32_t last_fcp_wqidx;
  433. uint32_t rcv_flogi_cnt; /* How many unsol FLOGIs ACK'd. */
  434. };
  435. struct hbq_s {
  436. uint16_t entry_count; /* Current number of HBQ slots */
  437. uint16_t buffer_count; /* Current number of buffers posted */
  438. uint32_t next_hbqPutIdx; /* Index to next HBQ slot to use */
  439. uint32_t hbqPutIdx; /* HBQ slot to use */
  440. uint32_t local_hbqGetIdx; /* Local copy of Get index from Port */
  441. void *hbq_virt; /* Virtual ptr to this hbq */
  442. struct list_head hbq_buffer_list; /* buffers assigned to this HBQ */
  443. /* Callback for HBQ buffer allocation */
  444. struct hbq_dmabuf *(*hbq_alloc_buffer) (struct lpfc_hba *);
  445. /* Callback for HBQ buffer free */
  446. void (*hbq_free_buffer) (struct lpfc_hba *,
  447. struct hbq_dmabuf *);
  448. };
  449. /* this matches the position in the lpfc_hbq_defs array */
  450. #define LPFC_ELS_HBQ 0
  451. #define LPFC_MAX_HBQS 1
  452. enum hba_temp_state {
  453. HBA_NORMAL_TEMP,
  454. HBA_OVER_TEMP
  455. };
  456. enum intr_type_t {
  457. NONE = 0,
  458. INTx,
  459. MSI,
  460. MSIX,
  461. };
  462. #define LPFC_CT_CTX_MAX 64
  463. struct unsol_rcv_ct_ctx {
  464. uint32_t ctxt_id;
  465. uint32_t SID;
  466. uint32_t valid;
  467. #define UNSOL_INVALID 0
  468. #define UNSOL_VALID 1
  469. uint16_t oxid;
  470. uint16_t rxid;
  471. };
  472. #define LPFC_USER_LINK_SPEED_AUTO 0 /* auto select (default)*/
  473. #define LPFC_USER_LINK_SPEED_1G 1 /* 1 Gigabaud */
  474. #define LPFC_USER_LINK_SPEED_2G 2 /* 2 Gigabaud */
  475. #define LPFC_USER_LINK_SPEED_4G 4 /* 4 Gigabaud */
  476. #define LPFC_USER_LINK_SPEED_8G 8 /* 8 Gigabaud */
  477. #define LPFC_USER_LINK_SPEED_10G 10 /* 10 Gigabaud */
  478. #define LPFC_USER_LINK_SPEED_16G 16 /* 16 Gigabaud */
  479. #define LPFC_USER_LINK_SPEED_32G 32 /* 32 Gigabaud */
  480. #define LPFC_USER_LINK_SPEED_64G 64 /* 64 Gigabaud */
  481. #define LPFC_USER_LINK_SPEED_MAX LPFC_USER_LINK_SPEED_64G
  482. #define LPFC_LINK_SPEED_STRING "0, 1, 2, 4, 8, 10, 16, 32, 64"
  483. enum nemb_type {
  484. nemb_mse = 1,
  485. nemb_hbd
  486. };
  487. enum mbox_type {
  488. mbox_rd = 1,
  489. mbox_wr
  490. };
  491. enum dma_type {
  492. dma_mbox = 1,
  493. dma_ebuf
  494. };
  495. enum sta_type {
  496. sta_pre_addr = 1,
  497. sta_pos_addr
  498. };
  499. struct lpfc_mbox_ext_buf_ctx {
  500. uint32_t state;
  501. #define LPFC_BSG_MBOX_IDLE 0
  502. #define LPFC_BSG_MBOX_HOST 1
  503. #define LPFC_BSG_MBOX_PORT 2
  504. #define LPFC_BSG_MBOX_DONE 3
  505. #define LPFC_BSG_MBOX_ABTS 4
  506. enum nemb_type nembType;
  507. enum mbox_type mboxType;
  508. uint32_t numBuf;
  509. uint32_t mbxTag;
  510. uint32_t seqNum;
  511. struct lpfc_dmabuf *mbx_dmabuf;
  512. struct list_head ext_dmabuf_list;
  513. };
  514. struct lpfc_hba {
  515. /* SCSI interface function jump table entries */
  516. int (*lpfc_new_scsi_buf)
  517. (struct lpfc_vport *, int);
  518. struct lpfc_scsi_buf * (*lpfc_get_scsi_buf)
  519. (struct lpfc_hba *, struct lpfc_nodelist *);
  520. int (*lpfc_scsi_prep_dma_buf)
  521. (struct lpfc_hba *, struct lpfc_scsi_buf *);
  522. void (*lpfc_scsi_unprep_dma_buf)
  523. (struct lpfc_hba *, struct lpfc_scsi_buf *);
  524. void (*lpfc_release_scsi_buf)
  525. (struct lpfc_hba *, struct lpfc_scsi_buf *);
  526. void (*lpfc_rampdown_queue_depth)
  527. (struct lpfc_hba *);
  528. void (*lpfc_scsi_prep_cmnd)
  529. (struct lpfc_vport *, struct lpfc_scsi_buf *,
  530. struct lpfc_nodelist *);
  531. /* IOCB interface function jump table entries */
  532. int (*__lpfc_sli_issue_iocb)
  533. (struct lpfc_hba *, uint32_t,
  534. struct lpfc_iocbq *, uint32_t);
  535. void (*__lpfc_sli_release_iocbq)(struct lpfc_hba *,
  536. struct lpfc_iocbq *);
  537. int (*lpfc_hba_down_post)(struct lpfc_hba *phba);
  538. IOCB_t * (*lpfc_get_iocb_from_iocbq)
  539. (struct lpfc_iocbq *);
  540. void (*lpfc_scsi_cmd_iocb_cmpl)
  541. (struct lpfc_hba *, struct lpfc_iocbq *, struct lpfc_iocbq *);
  542. /* MBOX interface function jump table entries */
  543. int (*lpfc_sli_issue_mbox)
  544. (struct lpfc_hba *, LPFC_MBOXQ_t *, uint32_t);
  545. /* Slow-path IOCB process function jump table entries */
  546. void (*lpfc_sli_handle_slow_ring_event)
  547. (struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  548. uint32_t mask);
  549. /* INIT device interface function jump table entries */
  550. int (*lpfc_sli_hbq_to_firmware)
  551. (struct lpfc_hba *, uint32_t, struct hbq_dmabuf *);
  552. int (*lpfc_sli_brdrestart)
  553. (struct lpfc_hba *);
  554. int (*lpfc_sli_brdready)
  555. (struct lpfc_hba *, uint32_t);
  556. void (*lpfc_handle_eratt)
  557. (struct lpfc_hba *);
  558. void (*lpfc_stop_port)
  559. (struct lpfc_hba *);
  560. int (*lpfc_hba_init_link)
  561. (struct lpfc_hba *, uint32_t);
  562. int (*lpfc_hba_down_link)
  563. (struct lpfc_hba *, uint32_t);
  564. int (*lpfc_selective_reset)
  565. (struct lpfc_hba *);
  566. int (*lpfc_bg_scsi_prep_dma_buf)
  567. (struct lpfc_hba *, struct lpfc_scsi_buf *);
  568. /* Add new entries here */
  569. /* SLI4 specific HBA data structure */
  570. struct lpfc_sli4_hba sli4_hba;
  571. struct workqueue_struct *wq;
  572. struct lpfc_sli sli;
  573. uint8_t pci_dev_grp; /* lpfc PCI dev group: 0x0, 0x1, 0x2,... */
  574. uint32_t sli_rev; /* SLI2, SLI3, or SLI4 */
  575. uint32_t sli3_options; /* Mask of enabled SLI3 options */
  576. #define LPFC_SLI3_HBQ_ENABLED 0x01
  577. #define LPFC_SLI3_NPIV_ENABLED 0x02
  578. #define LPFC_SLI3_VPORT_TEARDOWN 0x04
  579. #define LPFC_SLI3_CRP_ENABLED 0x08
  580. #define LPFC_SLI3_BG_ENABLED 0x20
  581. #define LPFC_SLI3_DSS_ENABLED 0x40
  582. #define LPFC_SLI4_PERFH_ENABLED 0x80
  583. #define LPFC_SLI4_PHWQ_ENABLED 0x100
  584. uint32_t iocb_cmd_size;
  585. uint32_t iocb_rsp_size;
  586. enum hba_state link_state;
  587. uint32_t link_flag; /* link state flags */
  588. #define LS_LOOPBACK_MODE 0x1 /* NPort is in Loopback mode */
  589. /* This flag is set while issuing */
  590. /* INIT_LINK mailbox command */
  591. #define LS_NPIV_FAB_SUPPORTED 0x2 /* Fabric supports NPIV */
  592. #define LS_IGNORE_ERATT 0x4 /* intr handler should ignore ERATT */
  593. #define LS_MDS_LINK_DOWN 0x8 /* MDS Diagnostics Link Down */
  594. #define LS_MDS_LOOPBACK 0x10 /* MDS Diagnostics Link Up (Loopback) */
  595. uint32_t hba_flag; /* hba generic flags */
  596. #define HBA_ERATT_HANDLED 0x1 /* This flag is set when eratt handled */
  597. #define DEFER_ERATT 0x2 /* Deferred error attention in progress */
  598. #define HBA_FCOE_MODE 0x4 /* HBA function in FCoE Mode */
  599. #define HBA_SP_QUEUE_EVT 0x8 /* Slow-path qevt posted to worker thread*/
  600. #define HBA_POST_RECEIVE_BUFFER 0x10 /* Rcv buffers need to be posted */
  601. #define FCP_XRI_ABORT_EVENT 0x20
  602. #define ELS_XRI_ABORT_EVENT 0x40
  603. #define ASYNC_EVENT 0x80
  604. #define LINK_DISABLED 0x100 /* Link disabled by user */
  605. #define FCF_TS_INPROG 0x200 /* FCF table scan in progress */
  606. #define FCF_RR_INPROG 0x400 /* FCF roundrobin flogi in progress */
  607. #define HBA_FIP_SUPPORT 0x800 /* FIP support in HBA */
  608. #define HBA_AER_ENABLED 0x1000 /* AER enabled with HBA */
  609. #define HBA_DEVLOSS_TMO 0x2000 /* HBA in devloss timeout */
  610. #define HBA_RRQ_ACTIVE 0x4000 /* process the rrq active list */
  611. #define HBA_FCP_IOQ_FLUSH 0x8000 /* FCP I/O queues being flushed */
  612. #define HBA_FW_DUMP_OP 0x10000 /* Skips fn reset before FW dump */
  613. #define HBA_RECOVERABLE_UE 0x20000 /* Firmware supports recoverable UE */
  614. #define HBA_FORCED_LINK_SPEED 0x40000 /*
  615. * Firmware supports Forced Link Speed
  616. * capability
  617. */
  618. #define HBA_NVME_IOQ_FLUSH 0x80000 /* NVME IO queues flushed. */
  619. uint32_t fcp_ring_in_use; /* When polling test if intr-hndlr active*/
  620. struct lpfc_dmabuf slim2p;
  621. MAILBOX_t *mbox;
  622. uint32_t *mbox_ext;
  623. struct lpfc_mbox_ext_buf_ctx mbox_ext_buf_ctx;
  624. uint32_t ha_copy;
  625. struct _PCB *pcb;
  626. struct _IOCB *IOCBs;
  627. struct lpfc_dmabuf hbqslimp;
  628. uint16_t pci_cfg_value;
  629. uint8_t fc_linkspeed; /* Link speed after last READ_LA */
  630. uint32_t fc_eventTag; /* event tag for link attention */
  631. uint32_t link_events;
  632. /* These fields used to be binfo */
  633. uint32_t fc_pref_DID; /* preferred D_ID */
  634. uint8_t fc_pref_ALPA; /* preferred AL_PA */
  635. uint32_t fc_edtovResol; /* E_D_TOV timer resolution */
  636. uint32_t fc_edtov; /* E_D_TOV timer value */
  637. uint32_t fc_arbtov; /* ARB_TOV timer value */
  638. uint32_t fc_ratov; /* R_A_TOV timer value */
  639. uint32_t fc_rttov; /* R_T_TOV timer value */
  640. uint32_t fc_altov; /* AL_TOV timer value */
  641. uint32_t fc_crtov; /* C_R_TOV timer value */
  642. struct serv_parm fc_fabparam; /* fabric service parameters buffer */
  643. uint8_t alpa_map[128]; /* AL_PA map from READ_LA */
  644. uint32_t lmt;
  645. uint32_t fc_topology; /* link topology, from LINK INIT */
  646. uint32_t fc_topology_changed; /* link topology, from LINK INIT */
  647. struct lpfc_stats fc_stat;
  648. struct lpfc_nodelist fc_fcpnodev; /* nodelist entry for no device */
  649. uint32_t nport_event_cnt; /* timestamp for nlplist entry */
  650. uint8_t wwnn[8];
  651. uint8_t wwpn[8];
  652. uint32_t RandomData[7];
  653. uint8_t fcp_embed_io;
  654. uint8_t nvme_support; /* Firmware supports NVME */
  655. uint8_t nvmet_support; /* driver supports NVMET */
  656. #define LPFC_NVMET_MAX_PORTS 32
  657. uint8_t mds_diags_support;
  658. uint32_t initial_imax;
  659. uint8_t bbcredit_support;
  660. uint8_t enab_exp_wqcq_pages;
  661. /* HBA Config Parameters */
  662. uint32_t cfg_ack0;
  663. uint32_t cfg_enable_npiv;
  664. uint32_t cfg_enable_rrq;
  665. uint32_t cfg_topology;
  666. uint32_t cfg_link_speed;
  667. #define LPFC_FCF_FOV 1 /* Fast fcf failover */
  668. #define LPFC_FCF_PRIORITY 2 /* Priority fcf failover */
  669. uint32_t cfg_fcf_failover_policy;
  670. uint32_t cfg_fcp_io_sched;
  671. uint32_t cfg_fcp2_no_tgt_reset;
  672. uint32_t cfg_cr_delay;
  673. uint32_t cfg_cr_count;
  674. uint32_t cfg_multi_ring_support;
  675. uint32_t cfg_multi_ring_rctl;
  676. uint32_t cfg_multi_ring_type;
  677. uint32_t cfg_poll;
  678. uint32_t cfg_poll_tmo;
  679. uint32_t cfg_task_mgmt_tmo;
  680. uint32_t cfg_use_msi;
  681. uint32_t cfg_auto_imax;
  682. uint32_t cfg_fcp_imax;
  683. uint32_t cfg_fcp_cpu_map;
  684. uint32_t cfg_fcp_io_channel;
  685. uint32_t cfg_suppress_rsp;
  686. uint32_t cfg_nvme_oas;
  687. uint32_t cfg_nvme_embed_cmd;
  688. uint32_t cfg_nvme_io_channel;
  689. uint32_t cfg_nvmet_mrq_post;
  690. uint32_t cfg_nvmet_mrq;
  691. uint32_t cfg_enable_nvmet;
  692. uint32_t cfg_nvme_enable_fb;
  693. uint32_t cfg_nvmet_fb_size;
  694. uint32_t cfg_total_seg_cnt;
  695. uint32_t cfg_sg_seg_cnt;
  696. uint32_t cfg_nvme_seg_cnt;
  697. uint32_t cfg_sg_dma_buf_size;
  698. uint64_t cfg_soft_wwnn;
  699. uint64_t cfg_soft_wwpn;
  700. uint32_t cfg_hba_queue_depth;
  701. uint32_t cfg_enable_hba_reset;
  702. uint32_t cfg_enable_hba_heartbeat;
  703. uint32_t cfg_fof;
  704. uint32_t cfg_EnableXLane;
  705. uint8_t cfg_oas_tgt_wwpn[8];
  706. uint8_t cfg_oas_vpt_wwpn[8];
  707. uint32_t cfg_oas_lun_state;
  708. #define OAS_LUN_ENABLE 1
  709. #define OAS_LUN_DISABLE 0
  710. uint32_t cfg_oas_lun_status;
  711. #define OAS_LUN_STATUS_EXISTS 0x01
  712. uint32_t cfg_oas_flags;
  713. #define OAS_FIND_ANY_VPORT 0x01
  714. #define OAS_FIND_ANY_TARGET 0x02
  715. #define OAS_LUN_VALID 0x04
  716. uint32_t cfg_oas_priority;
  717. uint32_t cfg_XLanePriority;
  718. uint32_t cfg_enable_bg;
  719. uint32_t cfg_prot_mask;
  720. uint32_t cfg_prot_guard;
  721. uint32_t cfg_hostmem_hgp;
  722. uint32_t cfg_log_verbose;
  723. uint32_t cfg_aer_support;
  724. uint32_t cfg_sriov_nr_virtfn;
  725. uint32_t cfg_request_firmware_upgrade;
  726. uint32_t cfg_iocb_cnt;
  727. uint32_t cfg_suppress_link_up;
  728. uint32_t cfg_rrq_xri_bitmap_sz;
  729. uint32_t cfg_delay_discovery;
  730. uint32_t cfg_sli_mode;
  731. #define LPFC_INITIALIZE_LINK 0 /* do normal init_link mbox */
  732. #define LPFC_DELAY_INIT_LINK 1 /* layered driver hold off */
  733. #define LPFC_DELAY_INIT_LINK_INDEFINITELY 2 /* wait, manual intervention */
  734. uint32_t cfg_enable_dss;
  735. uint32_t cfg_fdmi_on;
  736. #define LPFC_FDMI_NO_SUPPORT 0 /* FDMI not supported */
  737. #define LPFC_FDMI_SUPPORT 1 /* FDMI supported? */
  738. uint32_t cfg_enable_SmartSAN;
  739. uint32_t cfg_enable_mds_diags;
  740. uint32_t cfg_enable_fc4_type;
  741. uint32_t cfg_enable_bbcr; /* Enable BB Credit Recovery */
  742. uint32_t cfg_enable_dpp; /* Enable Direct Packet Push */
  743. uint32_t cfg_xri_split;
  744. #define LPFC_ENABLE_FCP 1
  745. #define LPFC_ENABLE_NVME 2
  746. #define LPFC_ENABLE_BOTH 3
  747. uint32_t cfg_enable_pbde;
  748. uint32_t io_channel_irqs; /* number of irqs for io channels */
  749. struct nvmet_fc_target_port *targetport;
  750. lpfc_vpd_t vpd; /* vital product data */
  751. struct pci_dev *pcidev;
  752. struct list_head work_list;
  753. uint32_t work_ha; /* Host Attention Bits for WT */
  754. uint32_t work_ha_mask; /* HA Bits owned by WT */
  755. uint32_t work_hs; /* HS stored in case of ERRAT */
  756. uint32_t work_status[2]; /* Extra status from SLIM */
  757. wait_queue_head_t work_waitq;
  758. struct task_struct *worker_thread;
  759. unsigned long data_flags;
  760. uint32_t hbq_in_use; /* HBQs in use flag */
  761. uint32_t hbq_count; /* Count of configured HBQs */
  762. struct hbq_s hbqs[LPFC_MAX_HBQS]; /* local copy of hbq indicies */
  763. atomic_t fcp_qidx; /* next FCP WQ (RR Policy) */
  764. atomic_t nvme_qidx; /* next NVME WQ (RR Policy) */
  765. phys_addr_t pci_bar0_map; /* Physical address for PCI BAR0 */
  766. phys_addr_t pci_bar1_map; /* Physical address for PCI BAR1 */
  767. phys_addr_t pci_bar2_map; /* Physical address for PCI BAR2 */
  768. void __iomem *slim_memmap_p; /* Kernel memory mapped address for
  769. PCI BAR0 */
  770. void __iomem *ctrl_regs_memmap_p;/* Kernel memory mapped address for
  771. PCI BAR2 */
  772. void __iomem *pci_bar0_memmap_p; /* Kernel memory mapped address for
  773. PCI BAR0 with dual-ULP support */
  774. void __iomem *pci_bar2_memmap_p; /* Kernel memory mapped address for
  775. PCI BAR2 with dual-ULP support */
  776. void __iomem *pci_bar4_memmap_p; /* Kernel memory mapped address for
  777. PCI BAR4 with dual-ULP support */
  778. #define PCI_64BIT_BAR0 0
  779. #define PCI_64BIT_BAR2 2
  780. #define PCI_64BIT_BAR4 4
  781. void __iomem *MBslimaddr; /* virtual address for mbox cmds */
  782. void __iomem *HAregaddr; /* virtual address for host attn reg */
  783. void __iomem *CAregaddr; /* virtual address for chip attn reg */
  784. void __iomem *HSregaddr; /* virtual address for host status
  785. reg */
  786. void __iomem *HCregaddr; /* virtual address for host ctl reg */
  787. struct lpfc_hgp __iomem *host_gp; /* Host side get/put pointers */
  788. struct lpfc_pgp *port_gp;
  789. uint32_t __iomem *hbq_put; /* Address in SLIM to HBQ put ptrs */
  790. uint32_t *hbq_get; /* Host mem address of HBQ get ptrs */
  791. int brd_no; /* FC board number */
  792. char SerialNumber[32]; /* adapter Serial Number */
  793. char OptionROMVersion[32]; /* adapter BIOS / Fcode version */
  794. char ModelDesc[256]; /* Model Description */
  795. char ModelName[80]; /* Model Name */
  796. char ProgramType[256]; /* Program Type */
  797. char Port[20]; /* Port No */
  798. uint8_t vpd_flag; /* VPD data flag */
  799. #define VPD_MODEL_DESC 0x1 /* valid vpd model description */
  800. #define VPD_MODEL_NAME 0x2 /* valid vpd model name */
  801. #define VPD_PROGRAM_TYPE 0x4 /* valid vpd program type */
  802. #define VPD_PORT 0x8 /* valid vpd port data */
  803. #define VPD_MASK 0xf /* mask for any vpd data */
  804. uint8_t soft_wwn_enable;
  805. struct timer_list fcp_poll_timer;
  806. struct timer_list eratt_poll;
  807. uint32_t eratt_poll_interval;
  808. /*
  809. * stat counters
  810. */
  811. atomic_t fc4ScsiInputRequests;
  812. atomic_t fc4ScsiOutputRequests;
  813. atomic_t fc4ScsiControlRequests;
  814. atomic_t fc4ScsiIoCmpls;
  815. uint64_t bg_guard_err_cnt;
  816. uint64_t bg_apptag_err_cnt;
  817. uint64_t bg_reftag_err_cnt;
  818. /* fastpath list. */
  819. spinlock_t scsi_buf_list_get_lock; /* SCSI buf alloc list lock */
  820. spinlock_t scsi_buf_list_put_lock; /* SCSI buf free list lock */
  821. struct list_head lpfc_scsi_buf_list_get;
  822. struct list_head lpfc_scsi_buf_list_put;
  823. uint32_t total_scsi_bufs;
  824. spinlock_t nvme_buf_list_get_lock; /* NVME buf alloc list lock */
  825. spinlock_t nvme_buf_list_put_lock; /* NVME buf free list lock */
  826. struct list_head lpfc_nvme_buf_list_get;
  827. struct list_head lpfc_nvme_buf_list_put;
  828. uint32_t total_nvme_bufs;
  829. uint32_t get_nvme_bufs;
  830. uint32_t put_nvme_bufs;
  831. struct list_head lpfc_iocb_list;
  832. uint32_t total_iocbq_bufs;
  833. struct list_head active_rrq_list;
  834. spinlock_t hbalock;
  835. /* dma_mem_pools */
  836. struct dma_pool *lpfc_sg_dma_buf_pool;
  837. struct dma_pool *lpfc_mbuf_pool;
  838. struct dma_pool *lpfc_hrb_pool; /* header receive buffer pool */
  839. struct dma_pool *lpfc_drb_pool; /* data receive buffer pool */
  840. struct dma_pool *lpfc_nvmet_drb_pool; /* data receive buffer pool */
  841. struct dma_pool *lpfc_hbq_pool; /* SLI3 hbq buffer pool */
  842. struct dma_pool *txrdy_payload_pool;
  843. struct lpfc_dma_pool lpfc_mbuf_safety_pool;
  844. mempool_t *mbox_mem_pool;
  845. mempool_t *nlp_mem_pool;
  846. mempool_t *rrq_pool;
  847. mempool_t *active_rrq_pool;
  848. struct fc_host_statistics link_stats;
  849. enum intr_type_t intr_type;
  850. uint32_t intr_mode;
  851. #define LPFC_INTR_ERROR 0xFFFFFFFF
  852. struct list_head port_list;
  853. struct lpfc_vport *pport; /* physical lpfc_vport pointer */
  854. uint16_t max_vpi; /* Maximum virtual nports */
  855. #define LPFC_MAX_VPI 0xFF /* Max number VPI supported 0 - 0xff */
  856. #define LPFC_MAX_VPORTS 0x100 /* Max vports per port, with pport */
  857. uint16_t max_vports; /*
  858. * For IOV HBAs max_vpi can change
  859. * after a reset. max_vports is max
  860. * number of vports present. This can
  861. * be greater than max_vpi.
  862. */
  863. uint16_t vpi_base;
  864. uint16_t vfi_base;
  865. unsigned long *vpi_bmask; /* vpi allocation table */
  866. uint16_t *vpi_ids;
  867. uint16_t vpi_count;
  868. struct list_head lpfc_vpi_blk_list;
  869. /* Data structure used by fabric iocb scheduler */
  870. struct list_head fabric_iocb_list;
  871. atomic_t fabric_iocb_count;
  872. struct timer_list fabric_block_timer;
  873. unsigned long bit_flags;
  874. #define FABRIC_COMANDS_BLOCKED 0
  875. atomic_t num_rsrc_err;
  876. atomic_t num_cmd_success;
  877. unsigned long last_rsrc_error_time;
  878. unsigned long last_ramp_down_time;
  879. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  880. struct dentry *hba_debugfs_root;
  881. atomic_t debugfs_vport_count;
  882. struct dentry *debug_hbqinfo;
  883. struct dentry *debug_dumpHostSlim;
  884. struct dentry *debug_dumpHBASlim;
  885. struct dentry *debug_dumpData; /* BlockGuard BPL */
  886. struct dentry *debug_dumpDif; /* BlockGuard BPL */
  887. struct dentry *debug_InjErrLBA; /* LBA to inject errors at */
  888. struct dentry *debug_InjErrNPortID; /* NPortID to inject errors at */
  889. struct dentry *debug_InjErrWWPN; /* WWPN to inject errors at */
  890. struct dentry *debug_writeGuard; /* inject write guard_tag errors */
  891. struct dentry *debug_writeApp; /* inject write app_tag errors */
  892. struct dentry *debug_writeRef; /* inject write ref_tag errors */
  893. struct dentry *debug_readGuard; /* inject read guard_tag errors */
  894. struct dentry *debug_readApp; /* inject read app_tag errors */
  895. struct dentry *debug_readRef; /* inject read ref_tag errors */
  896. struct dentry *debug_nvmeio_trc;
  897. struct lpfc_debugfs_nvmeio_trc *nvmeio_trc;
  898. atomic_t nvmeio_trc_cnt;
  899. uint32_t nvmeio_trc_size;
  900. uint32_t nvmeio_trc_output_idx;
  901. /* T10 DIF error injection */
  902. uint32_t lpfc_injerr_wgrd_cnt;
  903. uint32_t lpfc_injerr_wapp_cnt;
  904. uint32_t lpfc_injerr_wref_cnt;
  905. uint32_t lpfc_injerr_rgrd_cnt;
  906. uint32_t lpfc_injerr_rapp_cnt;
  907. uint32_t lpfc_injerr_rref_cnt;
  908. uint32_t lpfc_injerr_nportid;
  909. struct lpfc_name lpfc_injerr_wwpn;
  910. sector_t lpfc_injerr_lba;
  911. #define LPFC_INJERR_LBA_OFF (sector_t)(-1)
  912. struct dentry *debug_slow_ring_trc;
  913. struct lpfc_debugfs_trc *slow_ring_trc;
  914. atomic_t slow_ring_trc_cnt;
  915. /* iDiag debugfs sub-directory */
  916. struct dentry *idiag_root;
  917. struct dentry *idiag_pci_cfg;
  918. struct dentry *idiag_bar_acc;
  919. struct dentry *idiag_que_info;
  920. struct dentry *idiag_que_acc;
  921. struct dentry *idiag_drb_acc;
  922. struct dentry *idiag_ctl_acc;
  923. struct dentry *idiag_mbx_acc;
  924. struct dentry *idiag_ext_acc;
  925. uint8_t lpfc_idiag_last_eq;
  926. #endif
  927. uint16_t nvmeio_trc_on;
  928. /* Used for deferred freeing of ELS data buffers */
  929. struct list_head elsbuf;
  930. int elsbuf_cnt;
  931. int elsbuf_prev_cnt;
  932. uint8_t temp_sensor_support;
  933. /* Fields used for heart beat. */
  934. unsigned long last_eqdelay_time;
  935. unsigned long last_completion_time;
  936. unsigned long skipped_hb;
  937. struct timer_list hb_tmofunc;
  938. uint8_t hb_outstanding;
  939. struct timer_list rrq_tmr;
  940. enum hba_temp_state over_temp_state;
  941. /* ndlp reference management */
  942. spinlock_t ndlp_lock;
  943. /*
  944. * Following bit will be set for all buffer tags which are not
  945. * associated with any HBQ.
  946. */
  947. #define QUE_BUFTAG_BIT (1<<31)
  948. uint32_t buffer_tag_count;
  949. int wait_4_mlo_maint_flg;
  950. wait_queue_head_t wait_4_mlo_m_q;
  951. /* data structure used for latency data collection */
  952. #define LPFC_NO_BUCKET 0
  953. #define LPFC_LINEAR_BUCKET 1
  954. #define LPFC_POWER2_BUCKET 2
  955. uint8_t bucket_type;
  956. uint32_t bucket_base;
  957. uint32_t bucket_step;
  958. /* Maximum number of events that can be outstanding at any time*/
  959. #define LPFC_MAX_EVT_COUNT 512
  960. atomic_t fast_event_count;
  961. uint32_t fcoe_eventtag;
  962. uint32_t fcoe_eventtag_at_fcf_scan;
  963. uint32_t fcoe_cvl_eventtag;
  964. uint32_t fcoe_cvl_eventtag_attn;
  965. struct lpfc_fcf fcf;
  966. uint8_t fc_map[3];
  967. uint8_t valid_vlan;
  968. uint16_t vlan_id;
  969. struct list_head fcf_conn_rec_list;
  970. spinlock_t ct_ev_lock; /* synchronize access to ct_ev_waiters */
  971. struct list_head ct_ev_waiters;
  972. struct unsol_rcv_ct_ctx ct_ctx[LPFC_CT_CTX_MAX];
  973. uint32_t ctx_idx;
  974. uint8_t menlo_flag; /* menlo generic flags */
  975. #define HBA_MENLO_SUPPORT 0x1 /* HBA supports menlo commands */
  976. uint32_t iocb_cnt;
  977. uint32_t iocb_max;
  978. atomic_t sdev_cnt;
  979. uint8_t fips_spec_rev;
  980. uint8_t fips_level;
  981. spinlock_t devicelock; /* lock for luns list */
  982. mempool_t *device_data_mem_pool;
  983. struct list_head luns;
  984. #define LPFC_TRANSGRESSION_HIGH_TEMPERATURE 0x0080
  985. #define LPFC_TRANSGRESSION_LOW_TEMPERATURE 0x0040
  986. #define LPFC_TRANSGRESSION_HIGH_VOLTAGE 0x0020
  987. #define LPFC_TRANSGRESSION_LOW_VOLTAGE 0x0010
  988. #define LPFC_TRANSGRESSION_HIGH_TXBIAS 0x0008
  989. #define LPFC_TRANSGRESSION_LOW_TXBIAS 0x0004
  990. #define LPFC_TRANSGRESSION_HIGH_TXPOWER 0x0002
  991. #define LPFC_TRANSGRESSION_LOW_TXPOWER 0x0001
  992. #define LPFC_TRANSGRESSION_HIGH_RXPOWER 0x8000
  993. #define LPFC_TRANSGRESSION_LOW_RXPOWER 0x4000
  994. uint16_t sfp_alarm;
  995. uint16_t sfp_warning;
  996. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  997. #define LPFC_CHECK_CPU_CNT 32
  998. uint32_t cpucheck_rcv_io[LPFC_CHECK_CPU_CNT];
  999. uint32_t cpucheck_xmt_io[LPFC_CHECK_CPU_CNT];
  1000. uint32_t cpucheck_cmpl_io[LPFC_CHECK_CPU_CNT];
  1001. uint32_t cpucheck_ccmpl_io[LPFC_CHECK_CPU_CNT];
  1002. uint16_t cpucheck_on;
  1003. #define LPFC_CHECK_OFF 0
  1004. #define LPFC_CHECK_NVME_IO 1
  1005. #define LPFC_CHECK_NVMET_RCV 2
  1006. #define LPFC_CHECK_NVMET_IO 4
  1007. uint16_t ktime_on;
  1008. uint64_t ktime_data_samples;
  1009. uint64_t ktime_status_samples;
  1010. uint64_t ktime_last_cmd;
  1011. uint64_t ktime_seg1_total;
  1012. uint64_t ktime_seg1_min;
  1013. uint64_t ktime_seg1_max;
  1014. uint64_t ktime_seg2_total;
  1015. uint64_t ktime_seg2_min;
  1016. uint64_t ktime_seg2_max;
  1017. uint64_t ktime_seg3_total;
  1018. uint64_t ktime_seg3_min;
  1019. uint64_t ktime_seg3_max;
  1020. uint64_t ktime_seg4_total;
  1021. uint64_t ktime_seg4_min;
  1022. uint64_t ktime_seg4_max;
  1023. uint64_t ktime_seg5_total;
  1024. uint64_t ktime_seg5_min;
  1025. uint64_t ktime_seg5_max;
  1026. uint64_t ktime_seg6_total;
  1027. uint64_t ktime_seg6_min;
  1028. uint64_t ktime_seg6_max;
  1029. uint64_t ktime_seg7_total;
  1030. uint64_t ktime_seg7_min;
  1031. uint64_t ktime_seg7_max;
  1032. uint64_t ktime_seg8_total;
  1033. uint64_t ktime_seg8_min;
  1034. uint64_t ktime_seg8_max;
  1035. uint64_t ktime_seg9_total;
  1036. uint64_t ktime_seg9_min;
  1037. uint64_t ktime_seg9_max;
  1038. uint64_t ktime_seg10_total;
  1039. uint64_t ktime_seg10_min;
  1040. uint64_t ktime_seg10_max;
  1041. #endif
  1042. };
  1043. static inline struct Scsi_Host *
  1044. lpfc_shost_from_vport(struct lpfc_vport *vport)
  1045. {
  1046. return container_of((void *) vport, struct Scsi_Host, hostdata[0]);
  1047. }
  1048. static inline void
  1049. lpfc_set_loopback_flag(struct lpfc_hba *phba)
  1050. {
  1051. if (phba->cfg_topology == FLAGS_LOCAL_LB)
  1052. phba->link_flag |= LS_LOOPBACK_MODE;
  1053. else
  1054. phba->link_flag &= ~LS_LOOPBACK_MODE;
  1055. }
  1056. static inline int
  1057. lpfc_is_link_up(struct lpfc_hba *phba)
  1058. {
  1059. return phba->link_state == LPFC_LINK_UP ||
  1060. phba->link_state == LPFC_CLEAR_LA ||
  1061. phba->link_state == LPFC_HBA_READY;
  1062. }
  1063. static inline void
  1064. lpfc_worker_wake_up(struct lpfc_hba *phba)
  1065. {
  1066. /* Set the lpfc data pending flag */
  1067. set_bit(LPFC_DATA_READY, &phba->data_flags);
  1068. /* Wake up worker thread */
  1069. wake_up(&phba->work_waitq);
  1070. return;
  1071. }
  1072. static inline int
  1073. lpfc_readl(void __iomem *addr, uint32_t *data)
  1074. {
  1075. uint32_t temp;
  1076. temp = readl(addr);
  1077. if (temp == 0xffffffff)
  1078. return -EIO;
  1079. *data = temp;
  1080. return 0;
  1081. }
  1082. static inline int
  1083. lpfc_sli_read_hs(struct lpfc_hba *phba)
  1084. {
  1085. /*
  1086. * There was a link/board error. Read the status register to retrieve
  1087. * the error event and process it.
  1088. */
  1089. phba->sli.slistat.err_attn_event++;
  1090. /* Save status info and check for unplug error */
  1091. if (lpfc_readl(phba->HSregaddr, &phba->work_hs) ||
  1092. lpfc_readl(phba->MBslimaddr + 0xa8, &phba->work_status[0]) ||
  1093. lpfc_readl(phba->MBslimaddr + 0xac, &phba->work_status[1])) {
  1094. return -EIO;
  1095. }
  1096. /* Clear chip Host Attention error bit */
  1097. writel(HA_ERATT, phba->HAregaddr);
  1098. readl(phba->HAregaddr); /* flush */
  1099. phba->pport->stopped = 1;
  1100. return 0;
  1101. }
  1102. static inline struct lpfc_sli_ring *
  1103. lpfc_phba_elsring(struct lpfc_hba *phba)
  1104. {
  1105. /* Return NULL if sli_rev has become invalid due to bad fw */
  1106. if (phba->sli_rev != LPFC_SLI_REV4 &&
  1107. phba->sli_rev != LPFC_SLI_REV3 &&
  1108. phba->sli_rev != LPFC_SLI_REV2)
  1109. return NULL;
  1110. if (phba->sli_rev == LPFC_SLI_REV4) {
  1111. if (phba->sli4_hba.els_wq)
  1112. return phba->sli4_hba.els_wq->pring;
  1113. else
  1114. return NULL;
  1115. }
  1116. return &phba->sli.sli3_ring[LPFC_ELS_RING];
  1117. }