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