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