root/drivers/scsi/qla2xxx/qla_os.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. qla2x00_start_timer
  2. qla2x00_restart_timer
  3. qla2x00_stop_timer
  4. qla_init_base_qpair
  5. qla2x00_alloc_queues
  6. qla2x00_free_req_que
  7. qla2x00_free_rsp_que
  8. qla2x00_free_queues
  9. qla2x00_pci_info_str
  10. qla24xx_pci_info_str
  11. qla2x00_fw_version_str
  12. qla24xx_fw_version_str
  13. qla2x00_sp_free_dma
  14. qla2x00_sp_compl
  15. qla2xxx_qpair_sp_free_dma
  16. qla2xxx_qpair_sp_compl
  17. qla2xxx_queuecommand
  18. qla2xxx_mqueuecommand
  19. qla2x00_eh_wait_on_command
  20. qla2x00_wait_for_hba_online
  21. test_fcport_count
  22. qla2x00_wait_for_sess_deletion
  23. qla2x00_wait_for_hba_ready
  24. qla2x00_wait_for_chip_reset
  25. qla2x00_isp_reg_stat
  26. qla2xxx_eh_abort
  27. qla2x00_eh_wait_for_pending_commands
  28. __qla2xxx_eh_generic_reset
  29. qla2xxx_eh_device_reset
  30. qla2xxx_eh_target_reset
  31. qla2xxx_eh_bus_reset
  32. qla2xxx_eh_host_reset
  33. qla2x00_loop_reset
  34. qla2x00_abort_srb
  35. __qla2x00_abort_all_cmds
  36. qla2x00_abort_all_cmds
  37. qla2xxx_slave_alloc
  38. qla2xxx_slave_configure
  39. qla2xxx_slave_destroy
  40. qla2x00_config_dma_addressing
  41. qla2x00_enable_intrs
  42. qla2x00_disable_intrs
  43. qla24xx_enable_intrs
  44. qla24xx_disable_intrs
  45. qla2x00_iospace_config
  46. qla83xx_iospace_config
  47. qla2x00_set_isp_flags
  48. qla2xxx_scan_start
  49. qla2xxx_scan_finished
  50. qla2x00_iocb_work_fn
  51. qla2x00_probe_one
  52. qla2x00_shutdown
  53. qla2x00_delete_all_vps
  54. qla2x00_destroy_deferred_work
  55. qla2x00_unmap_iobases
  56. qla2x00_clear_drv_active
  57. qla2x00_remove_one
  58. qla2x00_free_device
  59. qla2x00_free_fcports
  60. qla2x00_schedule_rport_del
  61. qla2x00_mark_device_lost
  62. qla2x00_mark_all_devices_lost
  63. qla2x00_set_reserved_loop_ids
  64. qla2x00_mem_alloc
  65. qla2x00_set_exlogins_buffer
  66. qla2x00_free_exlogin_buffer
  67. qla2x00_number_of_exch
  68. qla2x00_set_exchoffld_buffer
  69. qla2x00_free_exchoffld_buffer
  70. qla2x00_free_fw_dump
  71. qla2x00_mem_free
  72. qla2x00_create_host
  73. qla2x00_alloc_work
  74. qla2x00_post_work
  75. qla2x00_post_aen_work
  76. qla2x00_post_idc_ack_work
  77. qla2x00_post_uevent_work
  78. qla2x00_uevent_emit
  79. qlafx00_post_aenfx_work
  80. qla24xx_sched_upd_fcport
  81. qla24xx_create_new_sess
  82. qla_sp_retry
  83. qla2x00_do_work
  84. qla24xx_post_relogin_work
  85. qla2x00_relogin
  86. qla83xx_schedule_work
  87. qla83xx_nic_core_unrecoverable_work
  88. qla83xx_idc_state_handler_work
  89. qla83xx_check_nic_core_fw_alive
  90. qla83xx_nic_core_reset_work
  91. qla83xx_service_idc_aen
  92. qla83xx_wait_logic
  93. qla83xx_force_lock_recovery
  94. qla83xx_idc_lock_recovery
  95. qla83xx_idc_lock
  96. qla83xx_idc_unlock
  97. __qla83xx_set_drv_presence
  98. qla83xx_set_drv_presence
  99. __qla83xx_clear_drv_presence
  100. qla83xx_clear_drv_presence
  101. qla83xx_need_reset_handler
  102. qla83xx_device_bootstrap
  103. qla83xx_idc_state_handler
  104. qla2x00_disable_board_on_pci_error
  105. qla2x00_do_dpc
  106. qla2xxx_wake_dpc
  107. qla2x00_rst_aen
  108. qla2x00_timer
  109. qla2x00_request_firmware
  110. qla2x00_release_firmware
  111. qla_pci_error_cleanup
  112. qla2xxx_pci_error_detected
  113. qla2xxx_pci_mmio_enabled
  114. qla2xxx_pci_slot_reset
  115. qla2xxx_pci_resume
  116. qla_pci_reset_prepare
  117. qla_pci_reset_done
  118. qla2xxx_map_queues
  119. qla2x00_module_init
  120. qla2x00_module_exit

   1 /*
   2  * QLogic Fibre Channel HBA Driver
   3  * Copyright (c)  2003-2014 QLogic Corporation
   4  *
   5  * See LICENSE.qla2xxx for copyright and licensing details.
   6  */
   7 #include "qla_def.h"
   8 
   9 #include <linux/moduleparam.h>
  10 #include <linux/vmalloc.h>
  11 #include <linux/delay.h>
  12 #include <linux/kthread.h>
  13 #include <linux/mutex.h>
  14 #include <linux/kobject.h>
  15 #include <linux/slab.h>
  16 #include <linux/blk-mq-pci.h>
  17 #include <linux/refcount.h>
  18 
  19 #include <scsi/scsi_tcq.h>
  20 #include <scsi/scsicam.h>
  21 #include <scsi/scsi_transport.h>
  22 #include <scsi/scsi_transport_fc.h>
  23 
  24 #include "qla_target.h"
  25 
  26 /*
  27  * Driver version
  28  */
  29 char qla2x00_version_str[40];
  30 
  31 static int apidev_major;
  32 
  33 /*
  34  * SRB allocation cache
  35  */
  36 struct kmem_cache *srb_cachep;
  37 
  38 /*
  39  * CT6 CTX allocation cache
  40  */
  41 static struct kmem_cache *ctx_cachep;
  42 /*
  43  * error level for logging
  44  */
  45 uint ql_errlev = 0x8001;
  46 
  47 static int ql2xenableclass2;
  48 module_param(ql2xenableclass2, int, S_IRUGO|S_IRUSR);
  49 MODULE_PARM_DESC(ql2xenableclass2,
  50                 "Specify if Class 2 operations are supported from the very "
  51                 "beginning. Default is 0 - class 2 not supported.");
  52 
  53 
  54 int ql2xlogintimeout = 20;
  55 module_param(ql2xlogintimeout, int, S_IRUGO);
  56 MODULE_PARM_DESC(ql2xlogintimeout,
  57                 "Login timeout value in seconds.");
  58 
  59 int qlport_down_retry;
  60 module_param(qlport_down_retry, int, S_IRUGO);
  61 MODULE_PARM_DESC(qlport_down_retry,
  62                 "Maximum number of command retries to a port that returns "
  63                 "a PORT-DOWN status.");
  64 
  65 int ql2xplogiabsentdevice;
  66 module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
  67 MODULE_PARM_DESC(ql2xplogiabsentdevice,
  68                 "Option to enable PLOGI to devices that are not present after "
  69                 "a Fabric scan.  This is needed for several broken switches. "
  70                 "Default is 0 - no PLOGI. 1 - perform PLOGI.");
  71 
  72 int ql2xloginretrycount;
  73 module_param(ql2xloginretrycount, int, S_IRUGO);
  74 MODULE_PARM_DESC(ql2xloginretrycount,
  75                 "Specify an alternate value for the NVRAM login retry count.");
  76 
  77 int ql2xallocfwdump = 1;
  78 module_param(ql2xallocfwdump, int, S_IRUGO);
  79 MODULE_PARM_DESC(ql2xallocfwdump,
  80                 "Option to enable allocation of memory for a firmware dump "
  81                 "during HBA initialization.  Memory allocation requirements "
  82                 "vary by ISP type.  Default is 1 - allocate memory.");
  83 
  84 int ql2xextended_error_logging;
  85 module_param(ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
  86 module_param_named(logging, ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
  87 MODULE_PARM_DESC(ql2xextended_error_logging,
  88                 "Option to enable extended error logging,\n"
  89                 "\t\tDefault is 0 - no logging.  0x40000000 - Module Init & Probe.\n"
  90                 "\t\t0x20000000 - Mailbox Cmnds. 0x10000000 - Device Discovery.\n"
  91                 "\t\t0x08000000 - IO tracing.    0x04000000 - DPC Thread.\n"
  92                 "\t\t0x02000000 - Async events.  0x01000000 - Timer routines.\n"
  93                 "\t\t0x00800000 - User space.    0x00400000 - Task Management.\n"
  94                 "\t\t0x00200000 - AER/EEH.       0x00100000 - Multi Q.\n"
  95                 "\t\t0x00080000 - P3P Specific.  0x00040000 - Virtual Port.\n"
  96                 "\t\t0x00020000 - Buffer Dump.   0x00010000 - Misc.\n"
  97                 "\t\t0x00008000 - Verbose.       0x00004000 - Target.\n"
  98                 "\t\t0x00002000 - Target Mgmt.   0x00001000 - Target TMF.\n"
  99                 "\t\t0x7fffffff - For enabling all logs, can be too many logs.\n"
 100                 "\t\t0x1e400000 - Preferred value for capturing essential "
 101                 "debug information (equivalent to old "
 102                 "ql2xextended_error_logging=1).\n"
 103                 "\t\tDo LOGICAL OR of the value to enable more than one level");
 104 
 105 int ql2xshiftctondsd = 6;
 106 module_param(ql2xshiftctondsd, int, S_IRUGO);
 107 MODULE_PARM_DESC(ql2xshiftctondsd,
 108                 "Set to control shifting of command type processing "
 109                 "based on total number of SG elements.");
 110 
 111 int ql2xfdmienable = 1;
 112 module_param(ql2xfdmienable, int, S_IRUGO|S_IWUSR);
 113 module_param_named(fdmi, ql2xfdmienable, int, S_IRUGO|S_IWUSR);
 114 MODULE_PARM_DESC(ql2xfdmienable,
 115                 "Enables FDMI registrations. "
 116                 "0 - no FDMI. Default is 1 - perform FDMI.");
 117 
 118 #define MAX_Q_DEPTH     64
 119 static int ql2xmaxqdepth = MAX_Q_DEPTH;
 120 module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
 121 MODULE_PARM_DESC(ql2xmaxqdepth,
 122                 "Maximum queue depth to set for each LUN. "
 123                 "Default is 64.");
 124 
 125 #if (IS_ENABLED(CONFIG_NVME_FC))
 126 int ql2xenabledif;
 127 #else
 128 int ql2xenabledif = 2;
 129 #endif
 130 module_param(ql2xenabledif, int, S_IRUGO);
 131 MODULE_PARM_DESC(ql2xenabledif,
 132                 " Enable T10-CRC-DIF:\n"
 133                 " Default is 2.\n"
 134                 "  0 -- No DIF Support\n"
 135                 "  1 -- Enable DIF for all types\n"
 136                 "  2 -- Enable DIF for all types, except Type 0.\n");
 137 
 138 #if (IS_ENABLED(CONFIG_NVME_FC))
 139 int ql2xnvmeenable = 1;
 140 #else
 141 int ql2xnvmeenable;
 142 #endif
 143 module_param(ql2xnvmeenable, int, 0644);
 144 MODULE_PARM_DESC(ql2xnvmeenable,
 145     "Enables NVME support. "
 146     "0 - no NVMe.  Default is Y");
 147 
 148 int ql2xenablehba_err_chk = 2;
 149 module_param(ql2xenablehba_err_chk, int, S_IRUGO|S_IWUSR);
 150 MODULE_PARM_DESC(ql2xenablehba_err_chk,
 151                 " Enable T10-CRC-DIF Error isolation by HBA:\n"
 152                 " Default is 2.\n"
 153                 "  0 -- Error isolation disabled\n"
 154                 "  1 -- Error isolation enabled only for DIX Type 0\n"
 155                 "  2 -- Error isolation enabled for all Types\n");
 156 
 157 int ql2xiidmaenable = 1;
 158 module_param(ql2xiidmaenable, int, S_IRUGO);
 159 MODULE_PARM_DESC(ql2xiidmaenable,
 160                 "Enables iIDMA settings "
 161                 "Default is 1 - perform iIDMA. 0 - no iIDMA.");
 162 
 163 int ql2xmqsupport = 1;
 164 module_param(ql2xmqsupport, int, S_IRUGO);
 165 MODULE_PARM_DESC(ql2xmqsupport,
 166                 "Enable on demand multiple queue pairs support "
 167                 "Default is 1 for supported. "
 168                 "Set it to 0 to turn off mq qpair support.");
 169 
 170 int ql2xfwloadbin;
 171 module_param(ql2xfwloadbin, int, S_IRUGO|S_IWUSR);
 172 module_param_named(fwload, ql2xfwloadbin, int, S_IRUGO|S_IWUSR);
 173 MODULE_PARM_DESC(ql2xfwloadbin,
 174                 "Option to specify location from which to load ISP firmware:.\n"
 175                 " 2 -- load firmware via the request_firmware() (hotplug).\n"
 176                 "      interface.\n"
 177                 " 1 -- load firmware from flash.\n"
 178                 " 0 -- use default semantics.\n");
 179 
 180 int ql2xetsenable;
 181 module_param(ql2xetsenable, int, S_IRUGO);
 182 MODULE_PARM_DESC(ql2xetsenable,
 183                 "Enables firmware ETS burst."
 184                 "Default is 0 - skip ETS enablement.");
 185 
 186 int ql2xdbwr = 1;
 187 module_param(ql2xdbwr, int, S_IRUGO|S_IWUSR);
 188 MODULE_PARM_DESC(ql2xdbwr,
 189                 "Option to specify scheme for request queue posting.\n"
 190                 " 0 -- Regular doorbell.\n"
 191                 " 1 -- CAMRAM doorbell (faster).\n");
 192 
 193 int ql2xtargetreset = 1;
 194 module_param(ql2xtargetreset, int, S_IRUGO);
 195 MODULE_PARM_DESC(ql2xtargetreset,
 196                  "Enable target reset."
 197                  "Default is 1 - use hw defaults.");
 198 
 199 int ql2xgffidenable;
 200 module_param(ql2xgffidenable, int, S_IRUGO);
 201 MODULE_PARM_DESC(ql2xgffidenable,
 202                 "Enables GFF_ID checks of port type. "
 203                 "Default is 0 - Do not use GFF_ID information.");
 204 
 205 int ql2xasynctmfenable = 1;
 206 module_param(ql2xasynctmfenable, int, S_IRUGO);
 207 MODULE_PARM_DESC(ql2xasynctmfenable,
 208                 "Enables issue of TM IOCBs asynchronously via IOCB mechanism"
 209                 "Default is 1 - Issue TM IOCBs via mailbox mechanism.");
 210 
 211 int ql2xdontresethba;
 212 module_param(ql2xdontresethba, int, S_IRUGO|S_IWUSR);
 213 MODULE_PARM_DESC(ql2xdontresethba,
 214                 "Option to specify reset behaviour.\n"
 215                 " 0 (Default) -- Reset on failure.\n"
 216                 " 1 -- Do not reset on failure.\n");
 217 
 218 uint64_t ql2xmaxlun = MAX_LUNS;
 219 module_param(ql2xmaxlun, ullong, S_IRUGO);
 220 MODULE_PARM_DESC(ql2xmaxlun,
 221                 "Defines the maximum LU number to register with the SCSI "
 222                 "midlayer. Default is 65535.");
 223 
 224 int ql2xmdcapmask = 0x1F;
 225 module_param(ql2xmdcapmask, int, S_IRUGO);
 226 MODULE_PARM_DESC(ql2xmdcapmask,
 227                 "Set the Minidump driver capture mask level. "
 228                 "Default is 0x1F - Can be set to 0x3, 0x7, 0xF, 0x1F, 0x7F.");
 229 
 230 int ql2xmdenable = 1;
 231 module_param(ql2xmdenable, int, S_IRUGO);
 232 MODULE_PARM_DESC(ql2xmdenable,
 233                 "Enable/disable MiniDump. "
 234                 "0 - MiniDump disabled. "
 235                 "1 (Default) - MiniDump enabled.");
 236 
 237 int ql2xexlogins;
 238 module_param(ql2xexlogins, uint, S_IRUGO|S_IWUSR);
 239 MODULE_PARM_DESC(ql2xexlogins,
 240                  "Number of extended Logins. "
 241                  "0 (Default)- Disabled.");
 242 
 243 int ql2xexchoffld = 1024;
 244 module_param(ql2xexchoffld, uint, 0644);
 245 MODULE_PARM_DESC(ql2xexchoffld,
 246         "Number of target exchanges.");
 247 
 248 int ql2xiniexchg = 1024;
 249 module_param(ql2xiniexchg, uint, 0644);
 250 MODULE_PARM_DESC(ql2xiniexchg,
 251         "Number of initiator exchanges.");
 252 
 253 int ql2xfwholdabts;
 254 module_param(ql2xfwholdabts, int, S_IRUGO);
 255 MODULE_PARM_DESC(ql2xfwholdabts,
 256                 "Allow FW to hold status IOCB until ABTS rsp received. "
 257                 "0 (Default) Do not set fw option. "
 258                 "1 - Set fw option to hold ABTS.");
 259 
 260 int ql2xmvasynctoatio = 1;
 261 module_param(ql2xmvasynctoatio, int, S_IRUGO|S_IWUSR);
 262 MODULE_PARM_DESC(ql2xmvasynctoatio,
 263                 "Move PUREX, ABTS RX and RIDA IOCBs to ATIOQ"
 264                 "0 (Default). Do not move IOCBs"
 265                 "1 - Move IOCBs.");
 266 
 267 int ql2xautodetectsfp = 1;
 268 module_param(ql2xautodetectsfp, int, 0444);
 269 MODULE_PARM_DESC(ql2xautodetectsfp,
 270                  "Detect SFP range and set appropriate distance.\n"
 271                  "1 (Default): Enable\n");
 272 
 273 int ql2xenablemsix = 1;
 274 module_param(ql2xenablemsix, int, 0444);
 275 MODULE_PARM_DESC(ql2xenablemsix,
 276                  "Set to enable MSI or MSI-X interrupt mechanism.\n"
 277                  " Default is 1, enable MSI-X interrupt mechanism.\n"
 278                  " 0 -- enable traditional pin-based mechanism.\n"
 279                  " 1 -- enable MSI-X interrupt mechanism.\n"
 280                  " 2 -- enable MSI interrupt mechanism.\n");
 281 
 282 int qla2xuseresexchforels;
 283 module_param(qla2xuseresexchforels, int, 0444);
 284 MODULE_PARM_DESC(qla2xuseresexchforels,
 285                  "Reserve 1/2 of emergency exchanges for ELS.\n"
 286                  " 0 (default): disabled");
 287 
 288 static int ql2xprotmask;
 289 module_param(ql2xprotmask, int, 0644);
 290 MODULE_PARM_DESC(ql2xprotmask,
 291                  "Override DIF/DIX protection capabilities mask\n"
 292                  "Default is 0 which sets protection mask based on "
 293                  "capabilities reported by HBA firmware.\n");
 294 
 295 static int ql2xprotguard;
 296 module_param(ql2xprotguard, int, 0644);
 297 MODULE_PARM_DESC(ql2xprotguard, "Override choice of DIX checksum\n"
 298                  "  0 -- Let HBA firmware decide\n"
 299                  "  1 -- Force T10 CRC\n"
 300                  "  2 -- Force IP checksum\n");
 301 
 302 int ql2xdifbundlinginternalbuffers;
 303 module_param(ql2xdifbundlinginternalbuffers, int, 0644);
 304 MODULE_PARM_DESC(ql2xdifbundlinginternalbuffers,
 305     "Force using internal buffers for DIF information\n"
 306     "0 (Default). Based on check.\n"
 307     "1 Force using internal buffers\n");
 308 
 309 static void qla2x00_clear_drv_active(struct qla_hw_data *);
 310 static void qla2x00_free_device(scsi_qla_host_t *);
 311 static int qla2xxx_map_queues(struct Scsi_Host *shost);
 312 static void qla2x00_destroy_deferred_work(struct qla_hw_data *);
 313 
 314 
 315 static struct scsi_transport_template *qla2xxx_transport_template = NULL;
 316 struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
 317 
 318 /* TODO Convert to inlines
 319  *
 320  * Timer routines
 321  */
 322 
 323 __inline__ void
 324 qla2x00_start_timer(scsi_qla_host_t *vha, unsigned long interval)
 325 {
 326         timer_setup(&vha->timer, qla2x00_timer, 0);
 327         vha->timer.expires = jiffies + interval * HZ;
 328         add_timer(&vha->timer);
 329         vha->timer_active = 1;
 330 }
 331 
 332 static inline void
 333 qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
 334 {
 335         /* Currently used for 82XX only. */
 336         if (vha->device_flags & DFLG_DEV_FAILED) {
 337                 ql_dbg(ql_dbg_timer, vha, 0x600d,
 338                     "Device in a failed state, returning.\n");
 339                 return;
 340         }
 341 
 342         mod_timer(&vha->timer, jiffies + interval * HZ);
 343 }
 344 
 345 static __inline__ void
 346 qla2x00_stop_timer(scsi_qla_host_t *vha)
 347 {
 348         del_timer_sync(&vha->timer);
 349         vha->timer_active = 0;
 350 }
 351 
 352 static int qla2x00_do_dpc(void *data);
 353 
 354 static void qla2x00_rst_aen(scsi_qla_host_t *);
 355 
 356 static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
 357         struct req_que **, struct rsp_que **);
 358 static void qla2x00_free_fw_dump(struct qla_hw_data *);
 359 static void qla2x00_mem_free(struct qla_hw_data *);
 360 int qla2xxx_mqueuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd,
 361         struct qla_qpair *qpair);
 362 
 363 /* -------------------------------------------------------------------------- */
 364 static void qla_init_base_qpair(struct scsi_qla_host *vha, struct req_que *req,
 365     struct rsp_que *rsp)
 366 {
 367         struct qla_hw_data *ha = vha->hw;
 368 
 369         rsp->qpair = ha->base_qpair;
 370         rsp->req = req;
 371         ha->base_qpair->hw = ha;
 372         ha->base_qpair->req = req;
 373         ha->base_qpair->rsp = rsp;
 374         ha->base_qpair->vha = vha;
 375         ha->base_qpair->qp_lock_ptr = &ha->hardware_lock;
 376         ha->base_qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
 377         ha->base_qpair->msix = &ha->msix_entries[QLA_MSIX_RSP_Q];
 378         ha->base_qpair->srb_mempool = ha->srb_mempool;
 379         INIT_LIST_HEAD(&ha->base_qpair->hints_list);
 380         ha->base_qpair->enable_class_2 = ql2xenableclass2;
 381         /* init qpair to this cpu. Will adjust at run time. */
 382         qla_cpu_update(rsp->qpair, raw_smp_processor_id());
 383         ha->base_qpair->pdev = ha->pdev;
 384 
 385         if (IS_QLA27XX(ha) || IS_QLA83XX(ha) || IS_QLA28XX(ha))
 386                 ha->base_qpair->reqq_start_iocbs = qla_83xx_start_iocbs;
 387 }
 388 
 389 static int qla2x00_alloc_queues(struct qla_hw_data *ha, struct req_que *req,
 390                                 struct rsp_que *rsp)
 391 {
 392         scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
 393 
 394         ha->req_q_map = kcalloc(ha->max_req_queues, sizeof(struct req_que *),
 395                                 GFP_KERNEL);
 396         if (!ha->req_q_map) {
 397                 ql_log(ql_log_fatal, vha, 0x003b,
 398                     "Unable to allocate memory for request queue ptrs.\n");
 399                 goto fail_req_map;
 400         }
 401 
 402         ha->rsp_q_map = kcalloc(ha->max_rsp_queues, sizeof(struct rsp_que *),
 403                                 GFP_KERNEL);
 404         if (!ha->rsp_q_map) {
 405                 ql_log(ql_log_fatal, vha, 0x003c,
 406                     "Unable to allocate memory for response queue ptrs.\n");
 407                 goto fail_rsp_map;
 408         }
 409 
 410         ha->base_qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
 411         if (ha->base_qpair == NULL) {
 412                 ql_log(ql_log_warn, vha, 0x00e0,
 413                     "Failed to allocate base queue pair memory.\n");
 414                 goto fail_base_qpair;
 415         }
 416 
 417         qla_init_base_qpair(vha, req, rsp);
 418 
 419         if ((ql2xmqsupport || ql2xnvmeenable) && ha->max_qpairs) {
 420                 ha->queue_pair_map = kcalloc(ha->max_qpairs, sizeof(struct qla_qpair *),
 421                         GFP_KERNEL);
 422                 if (!ha->queue_pair_map) {
 423                         ql_log(ql_log_fatal, vha, 0x0180,
 424                             "Unable to allocate memory for queue pair ptrs.\n");
 425                         goto fail_qpair_map;
 426                 }
 427         }
 428 
 429         /*
 430          * Make sure we record at least the request and response queue zero in
 431          * case we need to free them if part of the probe fails.
 432          */
 433         ha->rsp_q_map[0] = rsp;
 434         ha->req_q_map[0] = req;
 435         set_bit(0, ha->rsp_qid_map);
 436         set_bit(0, ha->req_qid_map);
 437         return 0;
 438 
 439 fail_qpair_map:
 440         kfree(ha->base_qpair);
 441         ha->base_qpair = NULL;
 442 fail_base_qpair:
 443         kfree(ha->rsp_q_map);
 444         ha->rsp_q_map = NULL;
 445 fail_rsp_map:
 446         kfree(ha->req_q_map);
 447         ha->req_q_map = NULL;
 448 fail_req_map:
 449         return -ENOMEM;
 450 }
 451 
 452 static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
 453 {
 454         if (IS_QLAFX00(ha)) {
 455                 if (req && req->ring_fx00)
 456                         dma_free_coherent(&ha->pdev->dev,
 457                             (req->length_fx00 + 1) * sizeof(request_t),
 458                             req->ring_fx00, req->dma_fx00);
 459         } else if (req && req->ring)
 460                 dma_free_coherent(&ha->pdev->dev,
 461                 (req->length + 1) * sizeof(request_t),
 462                 req->ring, req->dma);
 463 
 464         if (req)
 465                 kfree(req->outstanding_cmds);
 466 
 467         kfree(req);
 468 }
 469 
 470 static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
 471 {
 472         if (IS_QLAFX00(ha)) {
 473                 if (rsp && rsp->ring_fx00)
 474                         dma_free_coherent(&ha->pdev->dev,
 475                             (rsp->length_fx00 + 1) * sizeof(request_t),
 476                             rsp->ring_fx00, rsp->dma_fx00);
 477         } else if (rsp && rsp->ring) {
 478                 dma_free_coherent(&ha->pdev->dev,
 479                 (rsp->length + 1) * sizeof(response_t),
 480                 rsp->ring, rsp->dma);
 481         }
 482         kfree(rsp);
 483 }
 484 
 485 static void qla2x00_free_queues(struct qla_hw_data *ha)
 486 {
 487         struct req_que *req;
 488         struct rsp_que *rsp;
 489         int cnt;
 490         unsigned long flags;
 491 
 492         if (ha->queue_pair_map) {
 493                 kfree(ha->queue_pair_map);
 494                 ha->queue_pair_map = NULL;
 495         }
 496         if (ha->base_qpair) {
 497                 kfree(ha->base_qpair);
 498                 ha->base_qpair = NULL;
 499         }
 500 
 501         spin_lock_irqsave(&ha->hardware_lock, flags);
 502         for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
 503                 if (!test_bit(cnt, ha->req_qid_map))
 504                         continue;
 505 
 506                 req = ha->req_q_map[cnt];
 507                 clear_bit(cnt, ha->req_qid_map);
 508                 ha->req_q_map[cnt] = NULL;
 509 
 510                 spin_unlock_irqrestore(&ha->hardware_lock, flags);
 511                 qla2x00_free_req_que(ha, req);
 512                 spin_lock_irqsave(&ha->hardware_lock, flags);
 513         }
 514         spin_unlock_irqrestore(&ha->hardware_lock, flags);
 515 
 516         kfree(ha->req_q_map);
 517         ha->req_q_map = NULL;
 518 
 519 
 520         spin_lock_irqsave(&ha->hardware_lock, flags);
 521         for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
 522                 if (!test_bit(cnt, ha->rsp_qid_map))
 523                         continue;
 524 
 525                 rsp = ha->rsp_q_map[cnt];
 526                 clear_bit(cnt, ha->rsp_qid_map);
 527                 ha->rsp_q_map[cnt] =  NULL;
 528                 spin_unlock_irqrestore(&ha->hardware_lock, flags);
 529                 qla2x00_free_rsp_que(ha, rsp);
 530                 spin_lock_irqsave(&ha->hardware_lock, flags);
 531         }
 532         spin_unlock_irqrestore(&ha->hardware_lock, flags);
 533 
 534         kfree(ha->rsp_q_map);
 535         ha->rsp_q_map = NULL;
 536 }
 537 
 538 static char *
 539 qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str, size_t str_len)
 540 {
 541         struct qla_hw_data *ha = vha->hw;
 542         static const char *const pci_bus_modes[] = {
 543                 "33", "66", "100", "133",
 544         };
 545         uint16_t pci_bus;
 546 
 547         pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
 548         if (pci_bus) {
 549                 snprintf(str, str_len, "PCI-X (%s MHz)",
 550                          pci_bus_modes[pci_bus]);
 551         } else {
 552                 pci_bus = (ha->pci_attr & BIT_8) >> 8;
 553                 snprintf(str, str_len, "PCI (%s MHz)", pci_bus_modes[pci_bus]);
 554         }
 555 
 556         return str;
 557 }
 558 
 559 static char *
 560 qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str, size_t str_len)
 561 {
 562         static const char *const pci_bus_modes[] = {
 563                 "33", "66", "100", "133",
 564         };
 565         struct qla_hw_data *ha = vha->hw;
 566         uint32_t pci_bus;
 567 
 568         if (pci_is_pcie(ha->pdev)) {
 569                 uint32_t lstat, lspeed, lwidth;
 570                 const char *speed_str;
 571 
 572                 pcie_capability_read_dword(ha->pdev, PCI_EXP_LNKCAP, &lstat);
 573                 lspeed = lstat & PCI_EXP_LNKCAP_SLS;
 574                 lwidth = (lstat & PCI_EXP_LNKCAP_MLW) >> 4;
 575 
 576                 switch (lspeed) {
 577                 case 1:
 578                         speed_str = "2.5GT/s";
 579                         break;
 580                 case 2:
 581                         speed_str = "5.0GT/s";
 582                         break;
 583                 case 3:
 584                         speed_str = "8.0GT/s";
 585                         break;
 586                 default:
 587                         speed_str = "<unknown>";
 588                         break;
 589                 }
 590                 snprintf(str, str_len, "PCIe (%s x%d)", speed_str, lwidth);
 591 
 592                 return str;
 593         }
 594 
 595         pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
 596         if (pci_bus == 0 || pci_bus == 8)
 597                 snprintf(str, str_len, "PCI (%s MHz)",
 598                          pci_bus_modes[pci_bus >> 3]);
 599         else
 600                 snprintf(str, str_len, "PCI-X Mode %d (%s MHz)",
 601                          pci_bus & 4 ? 2 : 1,
 602                          pci_bus_modes[pci_bus & 3]);
 603 
 604         return str;
 605 }
 606 
 607 static char *
 608 qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
 609 {
 610         char un_str[10];
 611         struct qla_hw_data *ha = vha->hw;
 612 
 613         snprintf(str, size, "%d.%02d.%02d ", ha->fw_major_version,
 614             ha->fw_minor_version, ha->fw_subminor_version);
 615 
 616         if (ha->fw_attributes & BIT_9) {
 617                 strcat(str, "FLX");
 618                 return (str);
 619         }
 620 
 621         switch (ha->fw_attributes & 0xFF) {
 622         case 0x7:
 623                 strcat(str, "EF");
 624                 break;
 625         case 0x17:
 626                 strcat(str, "TP");
 627                 break;
 628         case 0x37:
 629                 strcat(str, "IP");
 630                 break;
 631         case 0x77:
 632                 strcat(str, "VI");
 633                 break;
 634         default:
 635                 sprintf(un_str, "(%x)", ha->fw_attributes);
 636                 strcat(str, un_str);
 637                 break;
 638         }
 639         if (ha->fw_attributes & 0x100)
 640                 strcat(str, "X");
 641 
 642         return (str);
 643 }
 644 
 645 static char *
 646 qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
 647 {
 648         struct qla_hw_data *ha = vha->hw;
 649 
 650         snprintf(str, size, "%d.%02d.%02d (%x)", ha->fw_major_version,
 651             ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
 652         return str;
 653 }
 654 
 655 void qla2x00_sp_free_dma(srb_t *sp)
 656 {
 657         struct qla_hw_data *ha = sp->vha->hw;
 658         struct scsi_cmnd *cmd = GET_CMD_SP(sp);
 659 
 660         if (sp->flags & SRB_DMA_VALID) {
 661                 scsi_dma_unmap(cmd);
 662                 sp->flags &= ~SRB_DMA_VALID;
 663         }
 664 
 665         if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
 666                 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
 667                     scsi_prot_sg_count(cmd), cmd->sc_data_direction);
 668                 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
 669         }
 670 
 671         if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
 672                 /* List assured to be having elements */
 673                 qla2x00_clean_dsd_pool(ha, sp->u.scmd.crc_ctx);
 674                 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
 675         }
 676 
 677         if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
 678                 struct crc_context *ctx0 = sp->u.scmd.crc_ctx;
 679 
 680                 dma_pool_free(ha->dl_dma_pool, ctx0, ctx0->crc_ctx_dma);
 681                 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
 682         }
 683 
 684         if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
 685                 struct ct6_dsd *ctx1 = sp->u.scmd.ct6_ctx;
 686 
 687                 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
 688                     ctx1->fcp_cmnd_dma);
 689                 list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
 690                 ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
 691                 ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
 692                 mempool_free(ctx1, ha->ctx_mempool);
 693         }
 694 }
 695 
 696 void qla2x00_sp_compl(srb_t *sp, int res)
 697 {
 698         struct scsi_cmnd *cmd = GET_CMD_SP(sp);
 699         struct completion *comp = sp->comp;
 700 
 701         sp->free(sp);
 702         cmd->result = res;
 703         CMD_SP(cmd) = NULL;
 704         cmd->scsi_done(cmd);
 705         if (comp)
 706                 complete(comp);
 707 }
 708 
 709 void qla2xxx_qpair_sp_free_dma(srb_t *sp)
 710 {
 711         struct scsi_cmnd *cmd = GET_CMD_SP(sp);
 712         struct qla_hw_data *ha = sp->fcport->vha->hw;
 713 
 714         if (sp->flags & SRB_DMA_VALID) {
 715                 scsi_dma_unmap(cmd);
 716                 sp->flags &= ~SRB_DMA_VALID;
 717         }
 718 
 719         if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
 720                 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
 721                     scsi_prot_sg_count(cmd), cmd->sc_data_direction);
 722                 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
 723         }
 724 
 725         if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
 726                 /* List assured to be having elements */
 727                 qla2x00_clean_dsd_pool(ha, sp->u.scmd.crc_ctx);
 728                 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
 729         }
 730 
 731         if (sp->flags & SRB_DIF_BUNDL_DMA_VALID) {
 732                 struct crc_context *difctx = sp->u.scmd.crc_ctx;
 733                 struct dsd_dma *dif_dsd, *nxt_dsd;
 734 
 735                 list_for_each_entry_safe(dif_dsd, nxt_dsd,
 736                     &difctx->ldif_dma_hndl_list, list) {
 737                         list_del(&dif_dsd->list);
 738                         dma_pool_free(ha->dif_bundl_pool, dif_dsd->dsd_addr,
 739                             dif_dsd->dsd_list_dma);
 740                         kfree(dif_dsd);
 741                         difctx->no_dif_bundl--;
 742                 }
 743 
 744                 list_for_each_entry_safe(dif_dsd, nxt_dsd,
 745                     &difctx->ldif_dsd_list, list) {
 746                         list_del(&dif_dsd->list);
 747                         dma_pool_free(ha->dl_dma_pool, dif_dsd->dsd_addr,
 748                             dif_dsd->dsd_list_dma);
 749                         kfree(dif_dsd);
 750                         difctx->no_ldif_dsd--;
 751                 }
 752 
 753                 if (difctx->no_ldif_dsd) {
 754                         ql_dbg(ql_dbg_tgt+ql_dbg_verbose, sp->vha, 0xe022,
 755                             "%s: difctx->no_ldif_dsd=%x\n",
 756                             __func__, difctx->no_ldif_dsd);
 757                 }
 758 
 759                 if (difctx->no_dif_bundl) {
 760                         ql_dbg(ql_dbg_tgt+ql_dbg_verbose, sp->vha, 0xe022,
 761                             "%s: difctx->no_dif_bundl=%x\n",
 762                             __func__, difctx->no_dif_bundl);
 763                 }
 764                 sp->flags &= ~SRB_DIF_BUNDL_DMA_VALID;
 765         }
 766 
 767         if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
 768                 struct ct6_dsd *ctx1 = sp->u.scmd.ct6_ctx;
 769 
 770                 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
 771                     ctx1->fcp_cmnd_dma);
 772                 list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
 773                 ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
 774                 ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
 775                 mempool_free(ctx1, ha->ctx_mempool);
 776                 sp->flags &= ~SRB_FCP_CMND_DMA_VALID;
 777         }
 778 
 779         if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
 780                 struct crc_context *ctx0 = sp->u.scmd.crc_ctx;
 781 
 782                 dma_pool_free(ha->dl_dma_pool, ctx0, ctx0->crc_ctx_dma);
 783                 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
 784         }
 785 }
 786 
 787 void qla2xxx_qpair_sp_compl(srb_t *sp, int res)
 788 {
 789         struct scsi_cmnd *cmd = GET_CMD_SP(sp);
 790         struct completion *comp = sp->comp;
 791 
 792         sp->free(sp);
 793         cmd->result = res;
 794         CMD_SP(cmd) = NULL;
 795         cmd->scsi_done(cmd);
 796         if (comp)
 797                 complete(comp);
 798 }
 799 
 800 static int
 801 qla2xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
 802 {
 803         scsi_qla_host_t *vha = shost_priv(host);
 804         fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
 805         struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
 806         struct qla_hw_data *ha = vha->hw;
 807         struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
 808         srb_t *sp;
 809         int rval;
 810 
 811         if (unlikely(test_bit(UNLOADING, &base_vha->dpc_flags)) ||
 812             WARN_ON_ONCE(!rport)) {
 813                 cmd->result = DID_NO_CONNECT << 16;
 814                 goto qc24_fail_command;
 815         }
 816 
 817         if (ha->mqenable) {
 818                 uint32_t tag;
 819                 uint16_t hwq;
 820                 struct qla_qpair *qpair = NULL;
 821 
 822                 tag = blk_mq_unique_tag(cmd->request);
 823                 hwq = blk_mq_unique_tag_to_hwq(tag);
 824                 qpair = ha->queue_pair_map[hwq];
 825 
 826                 if (qpair)
 827                         return qla2xxx_mqueuecommand(host, cmd, qpair);
 828         }
 829 
 830         if (ha->flags.eeh_busy) {
 831                 if (ha->flags.pci_channel_io_perm_failure) {
 832                         ql_dbg(ql_dbg_aer, vha, 0x9010,
 833                             "PCI Channel IO permanent failure, exiting "
 834                             "cmd=%p.\n", cmd);
 835                         cmd->result = DID_NO_CONNECT << 16;
 836                 } else {
 837                         ql_dbg(ql_dbg_aer, vha, 0x9011,
 838                             "EEH_Busy, Requeuing the cmd=%p.\n", cmd);
 839                         cmd->result = DID_REQUEUE << 16;
 840                 }
 841                 goto qc24_fail_command;
 842         }
 843 
 844         rval = fc_remote_port_chkready(rport);
 845         if (rval) {
 846                 cmd->result = rval;
 847                 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3003,
 848                     "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
 849                     cmd, rval);
 850                 goto qc24_fail_command;
 851         }
 852 
 853         if (!vha->flags.difdix_supported &&
 854                 scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
 855                         ql_dbg(ql_dbg_io, vha, 0x3004,
 856                             "DIF Cap not reg, fail DIF capable cmd's:%p.\n",
 857                             cmd);
 858                         cmd->result = DID_NO_CONNECT << 16;
 859                         goto qc24_fail_command;
 860         }
 861 
 862         if (!fcport) {
 863                 cmd->result = DID_NO_CONNECT << 16;
 864                 goto qc24_fail_command;
 865         }
 866 
 867         if (atomic_read(&fcport->state) != FCS_ONLINE) {
 868                 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
 869                         atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
 870                         ql_dbg(ql_dbg_io, vha, 0x3005,
 871                             "Returning DNC, fcport_state=%d loop_state=%d.\n",
 872                             atomic_read(&fcport->state),
 873                             atomic_read(&base_vha->loop_state));
 874                         cmd->result = DID_NO_CONNECT << 16;
 875                         goto qc24_fail_command;
 876                 }
 877                 goto qc24_target_busy;
 878         }
 879 
 880         /*
 881          * Return target busy if we've received a non-zero retry_delay_timer
 882          * in a FCP_RSP.
 883          */
 884         if (fcport->retry_delay_timestamp == 0) {
 885                 /* retry delay not set */
 886         } else if (time_after(jiffies, fcport->retry_delay_timestamp))
 887                 fcport->retry_delay_timestamp = 0;
 888         else
 889                 goto qc24_target_busy;
 890 
 891         sp = scsi_cmd_priv(cmd);
 892         qla2xxx_init_sp(sp, vha, vha->hw->base_qpair, fcport);
 893 
 894         sp->u.scmd.cmd = cmd;
 895         sp->type = SRB_SCSI_CMD;
 896 
 897         CMD_SP(cmd) = (void *)sp;
 898         sp->free = qla2x00_sp_free_dma;
 899         sp->done = qla2x00_sp_compl;
 900 
 901         rval = ha->isp_ops->start_scsi(sp);
 902         if (rval != QLA_SUCCESS) {
 903                 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3013,
 904                     "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
 905                 goto qc24_host_busy_free_sp;
 906         }
 907 
 908         return 0;
 909 
 910 qc24_host_busy_free_sp:
 911         sp->free(sp);
 912 
 913 qc24_target_busy:
 914         return SCSI_MLQUEUE_TARGET_BUSY;
 915 
 916 qc24_fail_command:
 917         cmd->scsi_done(cmd);
 918 
 919         return 0;
 920 }
 921 
 922 /* For MQ supported I/O */
 923 int
 924 qla2xxx_mqueuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd,
 925     struct qla_qpair *qpair)
 926 {
 927         scsi_qla_host_t *vha = shost_priv(host);
 928         fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
 929         struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
 930         struct qla_hw_data *ha = vha->hw;
 931         struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
 932         srb_t *sp;
 933         int rval;
 934 
 935         rval = rport ? fc_remote_port_chkready(rport) : FC_PORTSTATE_OFFLINE;
 936         if (rval) {
 937                 cmd->result = rval;
 938                 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3076,
 939                     "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
 940                     cmd, rval);
 941                 goto qc24_fail_command;
 942         }
 943 
 944         if (!fcport) {
 945                 cmd->result = DID_NO_CONNECT << 16;
 946                 goto qc24_fail_command;
 947         }
 948 
 949         if (atomic_read(&fcport->state) != FCS_ONLINE) {
 950                 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
 951                         atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
 952                         ql_dbg(ql_dbg_io, vha, 0x3077,
 953                             "Returning DNC, fcport_state=%d loop_state=%d.\n",
 954                             atomic_read(&fcport->state),
 955                             atomic_read(&base_vha->loop_state));
 956                         cmd->result = DID_NO_CONNECT << 16;
 957                         goto qc24_fail_command;
 958                 }
 959                 goto qc24_target_busy;
 960         }
 961 
 962         /*
 963          * Return target busy if we've received a non-zero retry_delay_timer
 964          * in a FCP_RSP.
 965          */
 966         if (fcport->retry_delay_timestamp == 0) {
 967                 /* retry delay not set */
 968         } else if (time_after(jiffies, fcport->retry_delay_timestamp))
 969                 fcport->retry_delay_timestamp = 0;
 970         else
 971                 goto qc24_target_busy;
 972 
 973         sp = scsi_cmd_priv(cmd);
 974         qla2xxx_init_sp(sp, vha, qpair, fcport);
 975 
 976         sp->u.scmd.cmd = cmd;
 977         sp->type = SRB_SCSI_CMD;
 978         CMD_SP(cmd) = (void *)sp;
 979         sp->free = qla2xxx_qpair_sp_free_dma;
 980         sp->done = qla2xxx_qpair_sp_compl;
 981 
 982         rval = ha->isp_ops->start_scsi_mq(sp);
 983         if (rval != QLA_SUCCESS) {
 984                 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3078,
 985                     "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
 986                 if (rval == QLA_INTERFACE_ERROR)
 987                         goto qc24_free_sp_fail_command;
 988                 goto qc24_host_busy_free_sp;
 989         }
 990 
 991         return 0;
 992 
 993 qc24_host_busy_free_sp:
 994         sp->free(sp);
 995 
 996 qc24_target_busy:
 997         return SCSI_MLQUEUE_TARGET_BUSY;
 998 
 999 qc24_free_sp_fail_command:
1000         sp->free(sp);
1001         CMD_SP(cmd) = NULL;
1002         qla2xxx_rel_qpair_sp(sp->qpair, sp);
1003 
1004 qc24_fail_command:
1005         cmd->scsi_done(cmd);
1006 
1007         return 0;
1008 }
1009 
1010 /*
1011  * qla2x00_eh_wait_on_command
1012  *    Waits for the command to be returned by the Firmware for some
1013  *    max time.
1014  *
1015  * Input:
1016  *    cmd = Scsi Command to wait on.
1017  *
1018  * Return:
1019  *    Completed in time : QLA_SUCCESS
1020  *    Did not complete in time : QLA_FUNCTION_FAILED
1021  */
1022 static int
1023 qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
1024 {
1025 #define ABORT_POLLING_PERIOD    1000
1026 #define ABORT_WAIT_ITER         ((2 * 1000) / (ABORT_POLLING_PERIOD))
1027         unsigned long wait_iter = ABORT_WAIT_ITER;
1028         scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1029         struct qla_hw_data *ha = vha->hw;
1030         int ret = QLA_SUCCESS;
1031 
1032         if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) {
1033                 ql_dbg(ql_dbg_taskm, vha, 0x8005,
1034                     "Return:eh_wait.\n");
1035                 return ret;
1036         }
1037 
1038         while (CMD_SP(cmd) && wait_iter--) {
1039                 msleep(ABORT_POLLING_PERIOD);
1040         }
1041         if (CMD_SP(cmd))
1042                 ret = QLA_FUNCTION_FAILED;
1043 
1044         return ret;
1045 }
1046 
1047 /*
1048  * qla2x00_wait_for_hba_online
1049  *    Wait till the HBA is online after going through
1050  *    <= MAX_RETRIES_OF_ISP_ABORT  or
1051  *    finally HBA is disabled ie marked offline
1052  *
1053  * Input:
1054  *     ha - pointer to host adapter structure
1055  *
1056  * Note:
1057  *    Does context switching-Release SPIN_LOCK
1058  *    (if any) before calling this routine.
1059  *
1060  * Return:
1061  *    Success (Adapter is online) : 0
1062  *    Failed  (Adapter is offline/disabled) : 1
1063  */
1064 int
1065 qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
1066 {
1067         int             return_status;
1068         unsigned long   wait_online;
1069         struct qla_hw_data *ha = vha->hw;
1070         scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1071 
1072         wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
1073         while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
1074             test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
1075             test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
1076             ha->dpc_active) && time_before(jiffies, wait_online)) {
1077 
1078                 msleep(1000);
1079         }
1080         if (base_vha->flags.online)
1081                 return_status = QLA_SUCCESS;
1082         else
1083                 return_status = QLA_FUNCTION_FAILED;
1084 
1085         return (return_status);
1086 }
1087 
1088 static inline int test_fcport_count(scsi_qla_host_t *vha)
1089 {
1090         struct qla_hw_data *ha = vha->hw;
1091         unsigned long flags;
1092         int res;
1093 
1094         spin_lock_irqsave(&ha->tgt.sess_lock, flags);
1095         ql_dbg(ql_dbg_init, vha, 0x00ec,
1096             "tgt %p, fcport_count=%d\n",
1097             vha, vha->fcport_count);
1098         res = (vha->fcport_count == 0);
1099         spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
1100 
1101         return res;
1102 }
1103 
1104 /*
1105  * qla2x00_wait_for_sess_deletion can only be called from remove_one.
1106  * it has dependency on UNLOADING flag to stop device discovery
1107  */
1108 void
1109 qla2x00_wait_for_sess_deletion(scsi_qla_host_t *vha)
1110 {
1111         u8 i;
1112 
1113         qla2x00_mark_all_devices_lost(vha, 0);
1114 
1115         for (i = 0; i < 10; i++) {
1116                 if (wait_event_timeout(vha->fcport_waitQ,
1117                     test_fcport_count(vha), HZ) > 0)
1118                         break;
1119         }
1120 
1121         flush_workqueue(vha->hw->wq);
1122 }
1123 
1124 /*
1125  * qla2x00_wait_for_hba_ready
1126  * Wait till the HBA is ready before doing driver unload
1127  *
1128  * Input:
1129  *     ha - pointer to host adapter structure
1130  *
1131  * Note:
1132  *    Does context switching-Release SPIN_LOCK
1133  *    (if any) before calling this routine.
1134  *
1135  */
1136 static void
1137 qla2x00_wait_for_hba_ready(scsi_qla_host_t *vha)
1138 {
1139         struct qla_hw_data *ha = vha->hw;
1140         scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1141 
1142         while ((qla2x00_reset_active(vha) || ha->dpc_active ||
1143                 ha->flags.mbox_busy) ||
1144                test_bit(FX00_RESET_RECOVERY, &vha->dpc_flags) ||
1145                test_bit(FX00_TARGET_SCAN, &vha->dpc_flags)) {
1146                 if (test_bit(UNLOADING, &base_vha->dpc_flags))
1147                         break;
1148                 msleep(1000);
1149         }
1150 }
1151 
1152 int
1153 qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
1154 {
1155         int             return_status;
1156         unsigned long   wait_reset;
1157         struct qla_hw_data *ha = vha->hw;
1158         scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1159 
1160         wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
1161         while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
1162             test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
1163             test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
1164             ha->dpc_active) && time_before(jiffies, wait_reset)) {
1165 
1166                 msleep(1000);
1167 
1168                 if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
1169                     ha->flags.chip_reset_done)
1170                         break;
1171         }
1172         if (ha->flags.chip_reset_done)
1173                 return_status = QLA_SUCCESS;
1174         else
1175                 return_status = QLA_FUNCTION_FAILED;
1176 
1177         return return_status;
1178 }
1179 
1180 #define ISP_REG_DISCONNECT 0xffffffffU
1181 /**************************************************************************
1182 * qla2x00_isp_reg_stat
1183 *
1184 * Description:
1185 *       Read the host status register of ISP before aborting the command.
1186 *
1187 * Input:
1188 *       ha = pointer to host adapter structure.
1189 *
1190 *
1191 * Returns:
1192 *       Either true or false.
1193 *
1194 * Note: Return true if there is register disconnect.
1195 **************************************************************************/
1196 static inline
1197 uint32_t qla2x00_isp_reg_stat(struct qla_hw_data *ha)
1198 {
1199         struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1200         struct device_reg_82xx __iomem *reg82 = &ha->iobase->isp82;
1201 
1202         if (IS_P3P_TYPE(ha))
1203                 return ((RD_REG_DWORD(&reg82->host_int)) == ISP_REG_DISCONNECT);
1204         else
1205                 return ((RD_REG_DWORD(&reg->host_status)) ==
1206                         ISP_REG_DISCONNECT);
1207 }
1208 
1209 /**************************************************************************
1210 * qla2xxx_eh_abort
1211 *
1212 * Description:
1213 *    The abort function will abort the specified command.
1214 *
1215 * Input:
1216 *    cmd = Linux SCSI command packet to be aborted.
1217 *
1218 * Returns:
1219 *    Either SUCCESS or FAILED.
1220 *
1221 * Note:
1222 *    Only return FAILED if command not returned by firmware.
1223 **************************************************************************/
1224 static int
1225 qla2xxx_eh_abort(struct scsi_cmnd *cmd)
1226 {
1227         scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1228         DECLARE_COMPLETION_ONSTACK(comp);
1229         srb_t *sp;
1230         int ret;
1231         unsigned int id;
1232         uint64_t lun;
1233         int rval;
1234         struct qla_hw_data *ha = vha->hw;
1235         uint32_t ratov_j;
1236         struct qla_qpair *qpair;
1237         unsigned long flags;
1238 
1239         if (qla2x00_isp_reg_stat(ha)) {
1240                 ql_log(ql_log_info, vha, 0x8042,
1241                     "PCI/Register disconnect, exiting.\n");
1242                 return FAILED;
1243         }
1244 
1245         ret = fc_block_scsi_eh(cmd);
1246         if (ret != 0)
1247                 return ret;
1248 
1249         sp = scsi_cmd_priv(cmd);
1250         qpair = sp->qpair;
1251 
1252         if ((sp->fcport && sp->fcport->deleted) || !qpair)
1253                 return SUCCESS;
1254 
1255         spin_lock_irqsave(qpair->qp_lock_ptr, flags);
1256         if (sp->completed) {
1257                 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
1258                 return SUCCESS;
1259         }
1260 
1261         if (sp->abort || sp->aborted) {
1262                 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
1263                 return FAILED;
1264         }
1265 
1266         sp->abort = 1;
1267         sp->comp = &comp;
1268         spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
1269 
1270 
1271         id = cmd->device->id;
1272         lun = cmd->device->lun;
1273 
1274         ql_dbg(ql_dbg_taskm, vha, 0x8002,
1275             "Aborting from RISC nexus=%ld:%d:%llu sp=%p cmd=%p handle=%x\n",
1276             vha->host_no, id, lun, sp, cmd, sp->handle);
1277 
1278         /*
1279          * Abort will release the original Command/sp from FW. Let the
1280          * original command call scsi_done. In return, he will wakeup
1281          * this sleeping thread.
1282          */
1283         rval = ha->isp_ops->abort_command(sp);
1284 
1285         ql_dbg(ql_dbg_taskm, vha, 0x8003,
1286                "Abort command mbx cmd=%p, rval=%x.\n", cmd, rval);
1287 
1288         /* Wait for the command completion. */
1289         ratov_j = ha->r_a_tov/10 * 4 * 1000;
1290         ratov_j = msecs_to_jiffies(ratov_j);
1291         switch (rval) {
1292         case QLA_SUCCESS:
1293                 if (!wait_for_completion_timeout(&comp, ratov_j)) {
1294                         ql_dbg(ql_dbg_taskm, vha, 0xffff,
1295                             "%s: Abort wait timer (4 * R_A_TOV[%d]) expired\n",
1296                             __func__, ha->r_a_tov/10);
1297                         ret = FAILED;
1298                 } else {
1299                         ret = SUCCESS;
1300                 }
1301                 break;
1302         default:
1303                 ret = FAILED;
1304                 break;
1305         }
1306 
1307         sp->comp = NULL;
1308 
1309         ql_log(ql_log_info, vha, 0x801c,
1310             "Abort command issued nexus=%ld:%d:%llu -- %x.\n",
1311             vha->host_no, id, lun, ret);
1312 
1313         return ret;
1314 }
1315 
1316 /*
1317  * Returns: QLA_SUCCESS or QLA_FUNCTION_FAILED.
1318  */
1319 int
1320 qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
1321         uint64_t l, enum nexus_wait_type type)
1322 {
1323         int cnt, match, status;
1324         unsigned long flags;
1325         struct qla_hw_data *ha = vha->hw;
1326         struct req_que *req;
1327         srb_t *sp;
1328         struct scsi_cmnd *cmd;
1329 
1330         status = QLA_SUCCESS;
1331 
1332         spin_lock_irqsave(&ha->hardware_lock, flags);
1333         req = vha->req;
1334         for (cnt = 1; status == QLA_SUCCESS &&
1335                 cnt < req->num_outstanding_cmds; cnt++) {
1336                 sp = req->outstanding_cmds[cnt];
1337                 if (!sp)
1338                         continue;
1339                 if (sp->type != SRB_SCSI_CMD)
1340                         continue;
1341                 if (vha->vp_idx != sp->vha->vp_idx)
1342                         continue;
1343                 match = 0;
1344                 cmd = GET_CMD_SP(sp);
1345                 switch (type) {
1346                 case WAIT_HOST:
1347                         match = 1;
1348                         break;
1349                 case WAIT_TARGET:
1350                         match = cmd->device->id == t;
1351                         break;
1352                 case WAIT_LUN:
1353                         match = (cmd->device->id == t &&
1354                                 cmd->device->lun == l);
1355                         break;
1356                 }
1357                 if (!match)
1358                         continue;
1359 
1360                 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1361                 status = qla2x00_eh_wait_on_command(cmd);
1362                 spin_lock_irqsave(&ha->hardware_lock, flags);
1363         }
1364         spin_unlock_irqrestore(&ha->hardware_lock, flags);
1365 
1366         return status;
1367 }
1368 
1369 static char *reset_errors[] = {
1370         "HBA not online",
1371         "HBA not ready",
1372         "Task management failed",
1373         "Waiting for command completions",
1374 };
1375 
1376 static int
1377 __qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
1378     struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, uint64_t, int))
1379 {
1380         scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1381         fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
1382         int err;
1383 
1384         if (!fcport) {
1385                 return FAILED;
1386         }
1387 
1388         err = fc_block_scsi_eh(cmd);
1389         if (err != 0)
1390                 return err;
1391 
1392         if (fcport->deleted)
1393                 return SUCCESS;
1394 
1395         ql_log(ql_log_info, vha, 0x8009,
1396             "%s RESET ISSUED nexus=%ld:%d:%llu cmd=%p.\n", name, vha->host_no,
1397             cmd->device->id, cmd->device->lun, cmd);
1398 
1399         err = 0;
1400         if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1401                 ql_log(ql_log_warn, vha, 0x800a,
1402                     "Wait for hba online failed for cmd=%p.\n", cmd);
1403                 goto eh_reset_failed;
1404         }
1405         err = 2;
1406         if (do_reset(fcport, cmd->device->lun, 1)
1407                 != QLA_SUCCESS) {
1408                 ql_log(ql_log_warn, vha, 0x800c,
1409                     "do_reset failed for cmd=%p.\n", cmd);
1410                 goto eh_reset_failed;
1411         }
1412         err = 3;
1413         if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
1414             cmd->device->lun, type) != QLA_SUCCESS) {
1415                 ql_log(ql_log_warn, vha, 0x800d,
1416                     "wait for pending cmds failed for cmd=%p.\n", cmd);
1417                 goto eh_reset_failed;
1418         }
1419 
1420         ql_log(ql_log_info, vha, 0x800e,
1421             "%s RESET SUCCEEDED nexus:%ld:%d:%llu cmd=%p.\n", name,
1422             vha->host_no, cmd->device->id, cmd->device->lun, cmd);
1423 
1424         return SUCCESS;
1425 
1426 eh_reset_failed:
1427         ql_log(ql_log_info, vha, 0x800f,
1428             "%s RESET FAILED: %s nexus=%ld:%d:%llu cmd=%p.\n", name,
1429             reset_errors[err], vha->host_no, cmd->device->id, cmd->device->lun,
1430             cmd);
1431         return FAILED;
1432 }
1433 
1434 static int
1435 qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
1436 {
1437         scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1438         struct qla_hw_data *ha = vha->hw;
1439 
1440         if (qla2x00_isp_reg_stat(ha)) {
1441                 ql_log(ql_log_info, vha, 0x803e,
1442                     "PCI/Register disconnect, exiting.\n");
1443                 return FAILED;
1444         }
1445 
1446         return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
1447             ha->isp_ops->lun_reset);
1448 }
1449 
1450 static int
1451 qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
1452 {
1453         scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1454         struct qla_hw_data *ha = vha->hw;
1455 
1456         if (qla2x00_isp_reg_stat(ha)) {
1457                 ql_log(ql_log_info, vha, 0x803f,
1458                     "PCI/Register disconnect, exiting.\n");
1459                 return FAILED;
1460         }
1461 
1462         return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
1463             ha->isp_ops->target_reset);
1464 }
1465 
1466 /**************************************************************************
1467 * qla2xxx_eh_bus_reset
1468 *
1469 * Description:
1470 *    The bus reset function will reset the bus and abort any executing
1471 *    commands.
1472 *
1473 * Input:
1474 *    cmd = Linux SCSI command packet of the command that cause the
1475 *          bus reset.
1476 *
1477 * Returns:
1478 *    SUCCESS/FAILURE (defined as macro in scsi.h).
1479 *
1480 **************************************************************************/
1481 static int
1482 qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
1483 {
1484         scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1485         fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
1486         int ret = FAILED;
1487         unsigned int id;
1488         uint64_t lun;
1489         struct qla_hw_data *ha = vha->hw;
1490 
1491         if (qla2x00_isp_reg_stat(ha)) {
1492                 ql_log(ql_log_info, vha, 0x8040,
1493                     "PCI/Register disconnect, exiting.\n");
1494                 return FAILED;
1495         }
1496 
1497         id = cmd->device->id;
1498         lun = cmd->device->lun;
1499 
1500         if (!fcport) {
1501                 return ret;
1502         }
1503 
1504         ret = fc_block_scsi_eh(cmd);
1505         if (ret != 0)
1506                 return ret;
1507         ret = FAILED;
1508 
1509         if (qla2x00_chip_is_down(vha))
1510                 return ret;
1511 
1512         ql_log(ql_log_info, vha, 0x8012,
1513             "BUS RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
1514 
1515         if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1516                 ql_log(ql_log_fatal, vha, 0x8013,
1517                     "Wait for hba online failed board disabled.\n");
1518                 goto eh_bus_reset_done;
1519         }
1520 
1521         if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
1522                 ret = SUCCESS;
1523 
1524         if (ret == FAILED)
1525                 goto eh_bus_reset_done;
1526 
1527         /* Flush outstanding commands. */
1528         if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) !=
1529             QLA_SUCCESS) {
1530                 ql_log(ql_log_warn, vha, 0x8014,
1531                     "Wait for pending commands failed.\n");
1532                 ret = FAILED;
1533         }
1534 
1535 eh_bus_reset_done:
1536         ql_log(ql_log_warn, vha, 0x802b,
1537             "BUS RESET %s nexus=%ld:%d:%llu.\n",
1538             (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
1539 
1540         return ret;
1541 }
1542 
1543 /**************************************************************************
1544 * qla2xxx_eh_host_reset
1545 *
1546 * Description:
1547 *    The reset function will reset the Adapter.
1548 *
1549 * Input:
1550 *      cmd = Linux SCSI command packet of the command that cause the
1551 *            adapter reset.
1552 *
1553 * Returns:
1554 *      Either SUCCESS or FAILED.
1555 *
1556 * Note:
1557 **************************************************************************/
1558 static int
1559 qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1560 {
1561         scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1562         struct qla_hw_data *ha = vha->hw;
1563         int ret = FAILED;
1564         unsigned int id;
1565         uint64_t lun;
1566         scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1567 
1568         if (qla2x00_isp_reg_stat(ha)) {
1569                 ql_log(ql_log_info, vha, 0x8041,
1570                     "PCI/Register disconnect, exiting.\n");
1571                 schedule_work(&ha->board_disable);
1572                 return SUCCESS;
1573         }
1574 
1575         id = cmd->device->id;
1576         lun = cmd->device->lun;
1577 
1578         ql_log(ql_log_info, vha, 0x8018,
1579             "ADAPTER RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
1580 
1581         /*
1582          * No point in issuing another reset if one is active.  Also do not
1583          * attempt a reset if we are updating flash.
1584          */
1585         if (qla2x00_reset_active(vha) || ha->optrom_state != QLA_SWAITING)
1586                 goto eh_host_reset_lock;
1587 
1588         if (vha != base_vha) {
1589                 if (qla2x00_vp_abort_isp(vha))
1590                         goto eh_host_reset_lock;
1591         } else {
1592                 if (IS_P3P_TYPE(vha->hw)) {
1593                         if (!qla82xx_fcoe_ctx_reset(vha)) {
1594                                 /* Ctx reset success */
1595                                 ret = SUCCESS;
1596                                 goto eh_host_reset_lock;
1597                         }
1598                         /* fall thru if ctx reset failed */
1599                 }
1600                 if (ha->wq)
1601                         flush_workqueue(ha->wq);
1602 
1603                 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1604                 if (ha->isp_ops->abort_isp(base_vha)) {
1605                         clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1606                         /* failed. schedule dpc to try */
1607                         set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1608 
1609                         if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1610                                 ql_log(ql_log_warn, vha, 0x802a,
1611                                     "wait for hba online failed.\n");
1612                                 goto eh_host_reset_lock;
1613                         }
1614                 }
1615                 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1616         }
1617 
1618         /* Waiting for command to be returned to OS.*/
1619         if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) ==
1620                 QLA_SUCCESS)
1621                 ret = SUCCESS;
1622 
1623 eh_host_reset_lock:
1624         ql_log(ql_log_info, vha, 0x8017,
1625             "ADAPTER RESET %s nexus=%ld:%d:%llu.\n",
1626             (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
1627 
1628         return ret;
1629 }
1630 
1631 /*
1632 * qla2x00_loop_reset
1633 *      Issue loop reset.
1634 *
1635 * Input:
1636 *      ha = adapter block pointer.
1637 *
1638 * Returns:
1639 *      0 = success
1640 */
1641 int
1642 qla2x00_loop_reset(scsi_qla_host_t *vha)
1643 {
1644         int ret;
1645         struct fc_port *fcport;
1646         struct qla_hw_data *ha = vha->hw;
1647 
1648         if (IS_QLAFX00(ha)) {
1649                 return qlafx00_loop_reset(vha);
1650         }
1651 
1652         if (ql2xtargetreset == 1 && ha->flags.enable_target_reset) {
1653                 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1654                         if (fcport->port_type != FCT_TARGET)
1655                                 continue;
1656 
1657                         ret = ha->isp_ops->target_reset(fcport, 0, 0);
1658                         if (ret != QLA_SUCCESS) {
1659                                 ql_dbg(ql_dbg_taskm, vha, 0x802c,
1660                                     "Bus Reset failed: Reset=%d "
1661                                     "d_id=%x.\n", ret, fcport->d_id.b24);
1662                         }
1663                 }
1664         }
1665 
1666 
1667         if (ha->flags.enable_lip_full_login && !IS_CNA_CAPABLE(ha)) {
1668                 atomic_set(&vha->loop_state, LOOP_DOWN);
1669                 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1670                 qla2x00_mark_all_devices_lost(vha, 0);
1671                 ret = qla2x00_full_login_lip(vha);
1672                 if (ret != QLA_SUCCESS) {
1673                         ql_dbg(ql_dbg_taskm, vha, 0x802d,
1674                             "full_login_lip=%d.\n", ret);
1675                 }
1676         }
1677 
1678         if (ha->flags.enable_lip_reset) {
1679                 ret = qla2x00_lip_reset(vha);
1680                 if (ret != QLA_SUCCESS)
1681                         ql_dbg(ql_dbg_taskm, vha, 0x802e,
1682                             "lip_reset failed (%d).\n", ret);
1683         }
1684 
1685         /* Issue marker command only when we are going to start the I/O */
1686         vha->marker_needed = 1;
1687 
1688         return QLA_SUCCESS;
1689 }
1690 
1691 static void qla2x00_abort_srb(struct qla_qpair *qp, srb_t *sp, const int res,
1692                               unsigned long *flags)
1693         __releases(qp->qp_lock_ptr)
1694         __acquires(qp->qp_lock_ptr)
1695 {
1696         DECLARE_COMPLETION_ONSTACK(comp);
1697         scsi_qla_host_t *vha = qp->vha;
1698         struct qla_hw_data *ha = vha->hw;
1699         int rval;
1700         bool ret_cmd;
1701         uint32_t ratov_j;
1702 
1703         if (qla2x00_chip_is_down(vha)) {
1704                 sp->done(sp, res);
1705                 return;
1706         }
1707 
1708         if (sp->type == SRB_NVME_CMD || sp->type == SRB_NVME_LS ||
1709             (sp->type == SRB_SCSI_CMD && !ha->flags.eeh_busy &&
1710              !test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) &&
1711              !qla2x00_isp_reg_stat(ha))) {
1712                 if (sp->comp) {
1713                         sp->done(sp, res);
1714                         return;
1715                 }
1716 
1717                 sp->comp = &comp;
1718                 sp->abort =  1;
1719                 spin_unlock_irqrestore(qp->qp_lock_ptr, *flags);
1720 
1721                 rval = ha->isp_ops->abort_command(sp);
1722                 /* Wait for command completion. */
1723                 ret_cmd = false;
1724                 ratov_j = ha->r_a_tov/10 * 4 * 1000;
1725                 ratov_j = msecs_to_jiffies(ratov_j);
1726                 switch (rval) {
1727                 case QLA_SUCCESS:
1728                         if (wait_for_completion_timeout(&comp, ratov_j)) {
1729                                 ql_dbg(ql_dbg_taskm, vha, 0xffff,
1730                                     "%s: Abort wait timer (4 * R_A_TOV[%d]) expired\n",
1731                                     __func__, ha->r_a_tov/10);
1732                                 ret_cmd = true;
1733                         }
1734                         /* else FW return SP to driver */
1735                         break;
1736                 default:
1737                         ret_cmd = true;
1738                         break;
1739                 }
1740 
1741                 spin_lock_irqsave(qp->qp_lock_ptr, *flags);
1742                 if (ret_cmd && (!sp->completed || !sp->aborted))
1743                         sp->done(sp, res);
1744         } else {
1745                 sp->done(sp, res);
1746         }
1747 }
1748 
1749 static void
1750 __qla2x00_abort_all_cmds(struct qla_qpair *qp, int res)
1751 {
1752         int cnt;
1753         unsigned long flags;
1754         srb_t *sp;
1755         scsi_qla_host_t *vha = qp->vha;
1756         struct qla_hw_data *ha = vha->hw;
1757         struct req_que *req;
1758         struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
1759         struct qla_tgt_cmd *cmd;
1760 
1761         if (!ha->req_q_map)
1762                 return;
1763         spin_lock_irqsave(qp->qp_lock_ptr, flags);
1764         req = qp->req;
1765         for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
1766                 sp = req->outstanding_cmds[cnt];
1767                 if (sp) {
1768                         switch (sp->cmd_type) {
1769                         case TYPE_SRB:
1770                                 qla2x00_abort_srb(qp, sp, res, &flags);
1771                                 break;
1772                         case TYPE_TGT_CMD:
1773                                 if (!vha->hw->tgt.tgt_ops || !tgt ||
1774                                     qla_ini_mode_enabled(vha)) {
1775                                         ql_dbg(ql_dbg_tgt_mgt, vha, 0xf003,
1776                                             "HOST-ABORT-HNDLR: dpc_flags=%lx. Target mode disabled\n",
1777                                             vha->dpc_flags);
1778                                         continue;
1779                                 }
1780                                 cmd = (struct qla_tgt_cmd *)sp;
1781                                 cmd->aborted = 1;
1782                                 break;
1783                         case TYPE_TGT_TMCMD:
1784                                 /* Skip task management functions. */
1785                                 break;
1786                         default:
1787                                 break;
1788                         }
1789                         req->outstanding_cmds[cnt] = NULL;
1790                 }
1791         }
1792         spin_unlock_irqrestore(qp->qp_lock_ptr, flags);
1793 }
1794 
1795 void
1796 qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
1797 {
1798         int que;
1799         struct qla_hw_data *ha = vha->hw;
1800 
1801         /* Continue only if initialization complete. */
1802         if (!ha->base_qpair)
1803                 return;
1804         __qla2x00_abort_all_cmds(ha->base_qpair, res);
1805 
1806         if (!ha->queue_pair_map)
1807                 return;
1808         for (que = 0; que < ha->max_qpairs; que++) {
1809                 if (!ha->queue_pair_map[que])
1810                         continue;
1811 
1812                 __qla2x00_abort_all_cmds(ha->queue_pair_map[que], res);
1813         }
1814 }
1815 
1816 static int
1817 qla2xxx_slave_alloc(struct scsi_device *sdev)
1818 {
1819         struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
1820 
1821         if (!rport || fc_remote_port_chkready(rport))
1822                 return -ENXIO;
1823 
1824         sdev->hostdata = *(fc_port_t **)rport->dd_data;
1825 
1826         return 0;
1827 }
1828 
1829 static int
1830 qla2xxx_slave_configure(struct scsi_device *sdev)
1831 {
1832         scsi_qla_host_t *vha = shost_priv(sdev->host);
1833         struct req_que *req = vha->req;
1834 
1835         if (IS_T10_PI_CAPABLE(vha->hw))
1836                 blk_queue_update_dma_alignment(sdev->request_queue, 0x7);
1837 
1838         scsi_change_queue_depth(sdev, req->max_q_depth);
1839         return 0;
1840 }
1841 
1842 static void
1843 qla2xxx_slave_destroy(struct scsi_device *sdev)
1844 {
1845         sdev->hostdata = NULL;
1846 }
1847 
1848 /**
1849  * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1850  * @ha: HA context
1851  *
1852  * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1853  * supported addressing method.
1854  */
1855 static void
1856 qla2x00_config_dma_addressing(struct qla_hw_data *ha)
1857 {
1858         /* Assume a 32bit DMA mask. */
1859         ha->flags.enable_64bit_addressing = 0;
1860 
1861         if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
1862                 /* Any upper-dword bits set? */
1863                 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
1864                     !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
1865                         /* Ok, a 64bit DMA mask is applicable. */
1866                         ha->flags.enable_64bit_addressing = 1;
1867                         ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1868                         ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
1869                         return;
1870                 }
1871         }
1872 
1873         dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1874         pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
1875 }
1876 
1877 static void
1878 qla2x00_enable_intrs(struct qla_hw_data *ha)
1879 {
1880         unsigned long flags = 0;
1881         struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1882 
1883         spin_lock_irqsave(&ha->hardware_lock, flags);
1884         ha->interrupts_on = 1;
1885         /* enable risc and host interrupts */
1886         WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1887         RD_REG_WORD(&reg->ictrl);
1888         spin_unlock_irqrestore(&ha->hardware_lock, flags);
1889 
1890 }
1891 
1892 static void
1893 qla2x00_disable_intrs(struct qla_hw_data *ha)
1894 {
1895         unsigned long flags = 0;
1896         struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1897 
1898         spin_lock_irqsave(&ha->hardware_lock, flags);
1899         ha->interrupts_on = 0;
1900         /* disable risc and host interrupts */
1901         WRT_REG_WORD(&reg->ictrl, 0);
1902         RD_REG_WORD(&reg->ictrl);
1903         spin_unlock_irqrestore(&ha->hardware_lock, flags);
1904 }
1905 
1906 static void
1907 qla24xx_enable_intrs(struct qla_hw_data *ha)
1908 {
1909         unsigned long flags = 0;
1910         struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1911 
1912         spin_lock_irqsave(&ha->hardware_lock, flags);
1913         ha->interrupts_on = 1;
1914         WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1915         RD_REG_DWORD(&reg->ictrl);
1916         spin_unlock_irqrestore(&ha->hardware_lock, flags);
1917 }
1918 
1919 static void
1920 qla24xx_disable_intrs(struct qla_hw_data *ha)
1921 {
1922         unsigned long flags = 0;
1923         struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1924 
1925         if (IS_NOPOLLING_TYPE(ha))
1926                 return;
1927         spin_lock_irqsave(&ha->hardware_lock, flags);
1928         ha->interrupts_on = 0;
1929         WRT_REG_DWORD(&reg->ictrl, 0);
1930         RD_REG_DWORD(&reg->ictrl);
1931         spin_unlock_irqrestore(&ha->hardware_lock, flags);
1932 }
1933 
1934 static int
1935 qla2x00_iospace_config(struct qla_hw_data *ha)
1936 {
1937         resource_size_t pio;
1938         uint16_t msix;
1939 
1940         if (pci_request_selected_regions(ha->pdev, ha->bars,
1941             QLA2XXX_DRIVER_NAME)) {
1942                 ql_log_pci(ql_log_fatal, ha->pdev, 0x0011,
1943                     "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1944                     pci_name(ha->pdev));
1945                 goto iospace_error_exit;
1946         }
1947         if (!(ha->bars & 1))
1948                 goto skip_pio;
1949 
1950         /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1951         pio = pci_resource_start(ha->pdev, 0);
1952         if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1953                 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1954                         ql_log_pci(ql_log_warn, ha->pdev, 0x0012,
1955                             "Invalid pci I/O region size (%s).\n",
1956                             pci_name(ha->pdev));
1957                         pio = 0;
1958                 }
1959         } else {
1960                 ql_log_pci(ql_log_warn, ha->pdev, 0x0013,
1961                     "Region #0 no a PIO resource (%s).\n",
1962                     pci_name(ha->pdev));
1963                 pio = 0;
1964         }
1965         ha->pio_address = pio;
1966         ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0014,
1967             "PIO address=%llu.\n",
1968             (unsigned long long)ha->pio_address);
1969 
1970 skip_pio:
1971         /* Use MMIO operations for all accesses. */
1972         if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
1973                 ql_log_pci(ql_log_fatal, ha->pdev, 0x0015,
1974                     "Region #1 not an MMIO resource (%s), aborting.\n",
1975                     pci_name(ha->pdev));
1976                 goto iospace_error_exit;
1977         }
1978         if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
1979                 ql_log_pci(ql_log_fatal, ha->pdev, 0x0016,
1980                     "Invalid PCI mem region size (%s), aborting.\n",
1981                     pci_name(ha->pdev));
1982                 goto iospace_error_exit;
1983         }
1984 
1985         ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
1986         if (!ha->iobase) {
1987                 ql_log_pci(ql_log_fatal, ha->pdev, 0x0017,
1988                     "Cannot remap MMIO (%s), aborting.\n",
1989                     pci_name(ha->pdev));
1990                 goto iospace_error_exit;
1991         }
1992 
1993         /* Determine queue resources */
1994         ha->max_req_queues = ha->max_rsp_queues = 1;
1995         ha->msix_count = QLA_BASE_VECTORS;
1996         if (!ql2xmqsupport || !ql2xnvmeenable ||
1997             (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
1998                 goto mqiobase_exit;
1999 
2000         ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
2001                         pci_resource_len(ha->pdev, 3));
2002         if (ha->mqiobase) {
2003                 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0018,
2004                     "MQIO Base=%p.\n", ha->mqiobase);
2005                 /* Read MSIX vector size of the board */
2006                 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
2007                 ha->msix_count = msix + 1;
2008                 /* Max queues are bounded by available msix vectors */
2009                 /* MB interrupt uses 1 vector */
2010                 ha->max_req_queues = ha->msix_count - 1;
2011                 ha->max_rsp_queues = ha->max_req_queues;
2012                 /* Queue pairs is the max value minus the base queue pair */
2013                 ha->max_qpairs = ha->max_rsp_queues - 1;
2014                 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0188,
2015                     "Max no of queues pairs: %d.\n", ha->max_qpairs);
2016 
2017                 ql_log_pci(ql_log_info, ha->pdev, 0x001a,
2018                     "MSI-X vector count: %d.\n", ha->msix_count);
2019         } else
2020                 ql_log_pci(ql_log_info, ha->pdev, 0x001b,
2021                     "BAR 3 not enabled.\n");
2022 
2023 mqiobase_exit:
2024         ql_dbg_pci(ql_dbg_init, ha->pdev, 0x001c,
2025             "MSIX Count: %d.\n", ha->msix_count);
2026         return (0);
2027 
2028 iospace_error_exit:
2029         return (-ENOMEM);
2030 }
2031 
2032 
2033 static int
2034 qla83xx_iospace_config(struct qla_hw_data *ha)
2035 {
2036         uint16_t msix;
2037 
2038         if (pci_request_selected_regions(ha->pdev, ha->bars,
2039             QLA2XXX_DRIVER_NAME)) {
2040                 ql_log_pci(ql_log_fatal, ha->pdev, 0x0117,
2041                     "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
2042                     pci_name(ha->pdev));
2043 
2044                 goto iospace_error_exit;
2045         }
2046 
2047         /* Use MMIO operations for all accesses. */
2048         if (!(pci_resource_flags(ha->pdev, 0) & IORESOURCE_MEM)) {
2049                 ql_log_pci(ql_log_warn, ha->pdev, 0x0118,
2050                     "Invalid pci I/O region size (%s).\n",
2051                     pci_name(ha->pdev));
2052                 goto iospace_error_exit;
2053         }
2054         if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
2055                 ql_log_pci(ql_log_warn, ha->pdev, 0x0119,
2056                     "Invalid PCI mem region size (%s), aborting\n",
2057                         pci_name(ha->pdev));
2058                 goto iospace_error_exit;
2059         }
2060 
2061         ha->iobase = ioremap(pci_resource_start(ha->pdev, 0), MIN_IOBASE_LEN);
2062         if (!ha->iobase) {
2063                 ql_log_pci(ql_log_fatal, ha->pdev, 0x011a,
2064                     "Cannot remap MMIO (%s), aborting.\n",
2065                     pci_name(ha->pdev));
2066                 goto iospace_error_exit;
2067         }
2068 
2069         /* 64bit PCI BAR - BAR2 will correspoond to region 4 */
2070         /* 83XX 26XX always use MQ type access for queues
2071          * - mbar 2, a.k.a region 4 */
2072         ha->max_req_queues = ha->max_rsp_queues = 1;
2073         ha->msix_count = QLA_BASE_VECTORS;
2074         ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 4),
2075                         pci_resource_len(ha->pdev, 4));
2076 
2077         if (!ha->mqiobase) {
2078                 ql_log_pci(ql_log_fatal, ha->pdev, 0x011d,
2079                     "BAR2/region4 not enabled\n");
2080                 goto mqiobase_exit;
2081         }
2082 
2083         ha->msixbase = ioremap(pci_resource_start(ha->pdev, 2),
2084                         pci_resource_len(ha->pdev, 2));
2085         if (ha->msixbase) {
2086                 /* Read MSIX vector size of the board */
2087                 pci_read_config_word(ha->pdev,
2088                     QLA_83XX_PCI_MSIX_CONTROL, &msix);
2089                 ha->msix_count = (msix & PCI_MSIX_FLAGS_QSIZE)  + 1;
2090                 /*
2091                  * By default, driver uses at least two msix vectors
2092                  * (default & rspq)
2093                  */
2094                 if (ql2xmqsupport || ql2xnvmeenable) {
2095                         /* MB interrupt uses 1 vector */
2096                         ha->max_req_queues = ha->msix_count - 1;
2097 
2098                         /* ATIOQ needs 1 vector. That's 1 less QPair */
2099                         if (QLA_TGT_MODE_ENABLED())
2100                                 ha->max_req_queues--;
2101 
2102                         ha->max_rsp_queues = ha->max_req_queues;
2103 
2104                         /* Queue pairs is the max value minus
2105                          * the base queue pair */
2106                         ha->max_qpairs = ha->max_req_queues - 1;
2107                         ql_dbg_pci(ql_dbg_init, ha->pdev, 0x00e3,
2108                             "Max no of queues pairs: %d.\n", ha->max_qpairs);
2109                 }
2110                 ql_log_pci(ql_log_info, ha->pdev, 0x011c,
2111                     "MSI-X vector count: %d.\n", ha->msix_count);
2112         } else
2113                 ql_log_pci(ql_log_info, ha->pdev, 0x011e,
2114                     "BAR 1 not enabled.\n");
2115 
2116 mqiobase_exit:
2117         ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011f,
2118             "MSIX Count: %d.\n", ha->msix_count);
2119         return 0;
2120 
2121 iospace_error_exit:
2122         return -ENOMEM;
2123 }
2124 
2125 static struct isp_operations qla2100_isp_ops = {
2126         .pci_config             = qla2100_pci_config,
2127         .reset_chip             = qla2x00_reset_chip,
2128         .chip_diag              = qla2x00_chip_diag,
2129         .config_rings           = qla2x00_config_rings,
2130         .reset_adapter          = qla2x00_reset_adapter,
2131         .nvram_config           = qla2x00_nvram_config,
2132         .update_fw_options      = qla2x00_update_fw_options,
2133         .load_risc              = qla2x00_load_risc,
2134         .pci_info_str           = qla2x00_pci_info_str,
2135         .fw_version_str         = qla2x00_fw_version_str,
2136         .intr_handler           = qla2100_intr_handler,
2137         .enable_intrs           = qla2x00_enable_intrs,
2138         .disable_intrs          = qla2x00_disable_intrs,
2139         .abort_command          = qla2x00_abort_command,
2140         .target_reset           = qla2x00_abort_target,
2141         .lun_reset              = qla2x00_lun_reset,
2142         .fabric_login           = qla2x00_login_fabric,
2143         .fabric_logout          = qla2x00_fabric_logout,
2144         .calc_req_entries       = qla2x00_calc_iocbs_32,
2145         .build_iocbs            = qla2x00_build_scsi_iocbs_32,
2146         .prep_ms_iocb           = qla2x00_prep_ms_iocb,
2147         .prep_ms_fdmi_iocb      = qla2x00_prep_ms_fdmi_iocb,
2148         .read_nvram             = qla2x00_read_nvram_data,
2149         .write_nvram            = qla2x00_write_nvram_data,
2150         .fw_dump                = qla2100_fw_dump,
2151         .beacon_on              = NULL,
2152         .beacon_off             = NULL,
2153         .beacon_blink           = NULL,
2154         .read_optrom            = qla2x00_read_optrom_data,
2155         .write_optrom           = qla2x00_write_optrom_data,
2156         .get_flash_version      = qla2x00_get_flash_version,
2157         .start_scsi             = qla2x00_start_scsi,
2158         .start_scsi_mq          = NULL,
2159         .abort_isp              = qla2x00_abort_isp,
2160         .iospace_config         = qla2x00_iospace_config,
2161         .initialize_adapter     = qla2x00_initialize_adapter,
2162 };
2163 
2164 static struct isp_operations qla2300_isp_ops = {
2165         .pci_config             = qla2300_pci_config,
2166         .reset_chip             = qla2x00_reset_chip,
2167         .chip_diag              = qla2x00_chip_diag,
2168         .config_rings           = qla2x00_config_rings,
2169         .reset_adapter          = qla2x00_reset_adapter,
2170         .nvram_config           = qla2x00_nvram_config,
2171         .update_fw_options      = qla2x00_update_fw_options,
2172         .load_risc              = qla2x00_load_risc,
2173         .pci_info_str           = qla2x00_pci_info_str,
2174         .fw_version_str         = qla2x00_fw_version_str,
2175         .intr_handler           = qla2300_intr_handler,
2176         .enable_intrs           = qla2x00_enable_intrs,
2177         .disable_intrs          = qla2x00_disable_intrs,
2178         .abort_command          = qla2x00_abort_command,
2179         .target_reset           = qla2x00_abort_target,
2180         .lun_reset              = qla2x00_lun_reset,
2181         .fabric_login           = qla2x00_login_fabric,
2182         .fabric_logout          = qla2x00_fabric_logout,
2183         .calc_req_entries       = qla2x00_calc_iocbs_32,
2184         .build_iocbs            = qla2x00_build_scsi_iocbs_32,
2185         .prep_ms_iocb           = qla2x00_prep_ms_iocb,
2186         .prep_ms_fdmi_iocb      = qla2x00_prep_ms_fdmi_iocb,
2187         .read_nvram             = qla2x00_read_nvram_data,
2188         .write_nvram            = qla2x00_write_nvram_data,
2189         .fw_dump                = qla2300_fw_dump,
2190         .beacon_on              = qla2x00_beacon_on,
2191         .beacon_off             = qla2x00_beacon_off,
2192         .beacon_blink           = qla2x00_beacon_blink,
2193         .read_optrom            = qla2x00_read_optrom_data,
2194         .write_optrom           = qla2x00_write_optrom_data,
2195         .get_flash_version      = qla2x00_get_flash_version,
2196         .start_scsi             = qla2x00_start_scsi,
2197         .start_scsi_mq          = NULL,
2198         .abort_isp              = qla2x00_abort_isp,
2199         .iospace_config         = qla2x00_iospace_config,
2200         .initialize_adapter     = qla2x00_initialize_adapter,
2201 };
2202 
2203 static struct isp_operations qla24xx_isp_ops = {
2204         .pci_config             = qla24xx_pci_config,
2205         .reset_chip             = qla24xx_reset_chip,
2206         .chip_diag              = qla24xx_chip_diag,
2207         .config_rings           = qla24xx_config_rings,
2208         .reset_adapter          = qla24xx_reset_adapter,
2209         .nvram_config           = qla24xx_nvram_config,
2210         .update_fw_options      = qla24xx_update_fw_options,
2211         .load_risc              = qla24xx_load_risc,
2212         .pci_info_str           = qla24xx_pci_info_str,
2213         .fw_version_str         = qla24xx_fw_version_str,
2214         .intr_handler           = qla24xx_intr_handler,
2215         .enable_intrs           = qla24xx_enable_intrs,
2216         .disable_intrs          = qla24xx_disable_intrs,
2217         .abort_command          = qla24xx_abort_command,
2218         .target_reset           = qla24xx_abort_target,
2219         .lun_reset              = qla24xx_lun_reset,
2220         .fabric_login           = qla24xx_login_fabric,
2221         .fabric_logout          = qla24xx_fabric_logout,
2222         .calc_req_entries       = NULL,
2223         .build_iocbs            = NULL,
2224         .prep_ms_iocb           = qla24xx_prep_ms_iocb,
2225         .prep_ms_fdmi_iocb      = qla24xx_prep_ms_fdmi_iocb,
2226         .read_nvram             = qla24xx_read_nvram_data,
2227         .write_nvram            = qla24xx_write_nvram_data,
2228         .fw_dump                = qla24xx_fw_dump,
2229         .beacon_on              = qla24xx_beacon_on,
2230         .beacon_off             = qla24xx_beacon_off,
2231         .beacon_blink           = qla24xx_beacon_blink,
2232         .read_optrom            = qla24xx_read_optrom_data,
2233         .write_optrom           = qla24xx_write_optrom_data,
2234         .get_flash_version      = qla24xx_get_flash_version,
2235         .start_scsi             = qla24xx_start_scsi,
2236         .start_scsi_mq          = NULL,
2237         .abort_isp              = qla2x00_abort_isp,
2238         .iospace_config         = qla2x00_iospace_config,
2239         .initialize_adapter     = qla2x00_initialize_adapter,
2240 };
2241 
2242 static struct isp_operations qla25xx_isp_ops = {
2243         .pci_config             = qla25xx_pci_config,
2244         .reset_chip             = qla24xx_reset_chip,
2245         .chip_diag              = qla24xx_chip_diag,
2246         .config_rings           = qla24xx_config_rings,
2247         .reset_adapter          = qla24xx_reset_adapter,
2248         .nvram_config           = qla24xx_nvram_config,
2249         .update_fw_options      = qla24xx_update_fw_options,
2250         .load_risc              = qla24xx_load_risc,
2251         .pci_info_str           = qla24xx_pci_info_str,
2252         .fw_version_str         = qla24xx_fw_version_str,
2253         .intr_handler           = qla24xx_intr_handler,
2254         .enable_intrs           = qla24xx_enable_intrs,
2255         .disable_intrs          = qla24xx_disable_intrs,
2256         .abort_command          = qla24xx_abort_command,
2257         .target_reset           = qla24xx_abort_target,
2258         .lun_reset              = qla24xx_lun_reset,
2259         .fabric_login           = qla24xx_login_fabric,
2260         .fabric_logout          = qla24xx_fabric_logout,
2261         .calc_req_entries       = NULL,
2262         .build_iocbs            = NULL,
2263         .prep_ms_iocb           = qla24xx_prep_ms_iocb,
2264         .prep_ms_fdmi_iocb      = qla24xx_prep_ms_fdmi_iocb,
2265         .read_nvram             = qla25xx_read_nvram_data,
2266         .write_nvram            = qla25xx_write_nvram_data,
2267         .fw_dump                = qla25xx_fw_dump,
2268         .beacon_on              = qla24xx_beacon_on,
2269         .beacon_off             = qla24xx_beacon_off,
2270         .beacon_blink           = qla24xx_beacon_blink,
2271         .read_optrom            = qla25xx_read_optrom_data,
2272         .write_optrom           = qla24xx_write_optrom_data,
2273         .get_flash_version      = qla24xx_get_flash_version,
2274         .start_scsi             = qla24xx_dif_start_scsi,
2275         .start_scsi_mq          = qla2xxx_dif_start_scsi_mq,
2276         .abort_isp              = qla2x00_abort_isp,
2277         .iospace_config         = qla2x00_iospace_config,
2278         .initialize_adapter     = qla2x00_initialize_adapter,
2279 };
2280 
2281 static struct isp_operations qla81xx_isp_ops = {
2282         .pci_config             = qla25xx_pci_config,
2283         .reset_chip             = qla24xx_reset_chip,
2284         .chip_diag              = qla24xx_chip_diag,
2285         .config_rings           = qla24xx_config_rings,
2286         .reset_adapter          = qla24xx_reset_adapter,
2287         .nvram_config           = qla81xx_nvram_config,
2288         .update_fw_options      = qla81xx_update_fw_options,
2289         .load_risc              = qla81xx_load_risc,
2290         .pci_info_str           = qla24xx_pci_info_str,
2291         .fw_version_str         = qla24xx_fw_version_str,
2292         .intr_handler           = qla24xx_intr_handler,
2293         .enable_intrs           = qla24xx_enable_intrs,
2294         .disable_intrs          = qla24xx_disable_intrs,
2295         .abort_command          = qla24xx_abort_command,
2296         .target_reset           = qla24xx_abort_target,
2297         .lun_reset              = qla24xx_lun_reset,
2298         .fabric_login           = qla24xx_login_fabric,
2299         .fabric_logout          = qla24xx_fabric_logout,
2300         .calc_req_entries       = NULL,
2301         .build_iocbs            = NULL,
2302         .prep_ms_iocb           = qla24xx_prep_ms_iocb,
2303         .prep_ms_fdmi_iocb      = qla24xx_prep_ms_fdmi_iocb,
2304         .read_nvram             = NULL,
2305         .write_nvram            = NULL,
2306         .fw_dump                = qla81xx_fw_dump,
2307         .beacon_on              = qla24xx_beacon_on,
2308         .beacon_off             = qla24xx_beacon_off,
2309         .beacon_blink           = qla83xx_beacon_blink,
2310         .read_optrom            = qla25xx_read_optrom_data,
2311         .write_optrom           = qla24xx_write_optrom_data,
2312         .get_flash_version      = qla24xx_get_flash_version,
2313         .start_scsi             = qla24xx_dif_start_scsi,
2314         .start_scsi_mq          = qla2xxx_dif_start_scsi_mq,
2315         .abort_isp              = qla2x00_abort_isp,
2316         .iospace_config         = qla2x00_iospace_config,
2317         .initialize_adapter     = qla2x00_initialize_adapter,
2318 };
2319 
2320 static struct isp_operations qla82xx_isp_ops = {
2321         .pci_config             = qla82xx_pci_config,
2322         .reset_chip             = qla82xx_reset_chip,
2323         .chip_diag              = qla24xx_chip_diag,
2324         .config_rings           = qla82xx_config_rings,
2325         .reset_adapter          = qla24xx_reset_adapter,
2326         .nvram_config           = qla81xx_nvram_config,
2327         .update_fw_options      = qla24xx_update_fw_options,
2328         .load_risc              = qla82xx_load_risc,
2329         .pci_info_str           = qla24xx_pci_info_str,
2330         .fw_version_str         = qla24xx_fw_version_str,
2331         .intr_handler           = qla82xx_intr_handler,
2332         .enable_intrs           = qla82xx_enable_intrs,
2333         .disable_intrs          = qla82xx_disable_intrs,
2334         .abort_command          = qla24xx_abort_command,
2335         .target_reset           = qla24xx_abort_target,
2336         .lun_reset              = qla24xx_lun_reset,
2337         .fabric_login           = qla24xx_login_fabric,
2338         .fabric_logout          = qla24xx_fabric_logout,
2339         .calc_req_entries       = NULL,
2340         .build_iocbs            = NULL,
2341         .prep_ms_iocb           = qla24xx_prep_ms_iocb,
2342         .prep_ms_fdmi_iocb      = qla24xx_prep_ms_fdmi_iocb,
2343         .read_nvram             = qla24xx_read_nvram_data,
2344         .write_nvram            = qla24xx_write_nvram_data,
2345         .fw_dump                = qla82xx_fw_dump,
2346         .beacon_on              = qla82xx_beacon_on,
2347         .beacon_off             = qla82xx_beacon_off,
2348         .beacon_blink           = NULL,
2349         .read_optrom            = qla82xx_read_optrom_data,
2350         .write_optrom           = qla82xx_write_optrom_data,
2351         .get_flash_version      = qla82xx_get_flash_version,
2352         .start_scsi             = qla82xx_start_scsi,
2353         .start_scsi_mq          = NULL,
2354         .abort_isp              = qla82xx_abort_isp,
2355         .iospace_config         = qla82xx_iospace_config,
2356         .initialize_adapter     = qla2x00_initialize_adapter,
2357 };
2358 
2359 static struct isp_operations qla8044_isp_ops = {
2360         .pci_config             = qla82xx_pci_config,
2361         .reset_chip             = qla82xx_reset_chip,
2362         .chip_diag              = qla24xx_chip_diag,
2363         .config_rings           = qla82xx_config_rings,
2364         .reset_adapter          = qla24xx_reset_adapter,
2365         .nvram_config           = qla81xx_nvram_config,
2366         .update_fw_options      = qla24xx_update_fw_options,
2367         .load_risc              = qla82xx_load_risc,
2368         .pci_info_str           = qla24xx_pci_info_str,
2369         .fw_version_str         = qla24xx_fw_version_str,
2370         .intr_handler           = qla8044_intr_handler,
2371         .enable_intrs           = qla82xx_enable_intrs,
2372         .disable_intrs          = qla82xx_disable_intrs,
2373         .abort_command          = qla24xx_abort_command,
2374         .target_reset           = qla24xx_abort_target,
2375         .lun_reset              = qla24xx_lun_reset,
2376         .fabric_login           = qla24xx_login_fabric,
2377         .fabric_logout          = qla24xx_fabric_logout,
2378         .calc_req_entries       = NULL,
2379         .build_iocbs            = NULL,
2380         .prep_ms_iocb           = qla24xx_prep_ms_iocb,
2381         .prep_ms_fdmi_iocb      = qla24xx_prep_ms_fdmi_iocb,
2382         .read_nvram             = NULL,
2383         .write_nvram            = NULL,
2384         .fw_dump                = qla8044_fw_dump,
2385         .beacon_on              = qla82xx_beacon_on,
2386         .beacon_off             = qla82xx_beacon_off,
2387         .beacon_blink           = NULL,
2388         .read_optrom            = qla8044_read_optrom_data,
2389         .write_optrom           = qla8044_write_optrom_data,
2390         .get_flash_version      = qla82xx_get_flash_version,
2391         .start_scsi             = qla82xx_start_scsi,
2392         .start_scsi_mq          = NULL,
2393         .abort_isp              = qla8044_abort_isp,
2394         .iospace_config         = qla82xx_iospace_config,
2395         .initialize_adapter     = qla2x00_initialize_adapter,
2396 };
2397 
2398 static struct isp_operations qla83xx_isp_ops = {
2399         .pci_config             = qla25xx_pci_config,
2400         .reset_chip             = qla24xx_reset_chip,
2401         .chip_diag              = qla24xx_chip_diag,
2402         .config_rings           = qla24xx_config_rings,
2403         .reset_adapter          = qla24xx_reset_adapter,
2404         .nvram_config           = qla81xx_nvram_config,
2405         .update_fw_options      = qla81xx_update_fw_options,
2406         .load_risc              = qla81xx_load_risc,
2407         .pci_info_str           = qla24xx_pci_info_str,
2408         .fw_version_str         = qla24xx_fw_version_str,
2409         .intr_handler           = qla24xx_intr_handler,
2410         .enable_intrs           = qla24xx_enable_intrs,
2411         .disable_intrs          = qla24xx_disable_intrs,
2412         .abort_command          = qla24xx_abort_command,
2413         .target_reset           = qla24xx_abort_target,
2414         .lun_reset              = qla24xx_lun_reset,
2415         .fabric_login           = qla24xx_login_fabric,
2416         .fabric_logout          = qla24xx_fabric_logout,
2417         .calc_req_entries       = NULL,
2418         .build_iocbs            = NULL,
2419         .prep_ms_iocb           = qla24xx_prep_ms_iocb,
2420         .prep_ms_fdmi_iocb      = qla24xx_prep_ms_fdmi_iocb,
2421         .read_nvram             = NULL,
2422         .write_nvram            = NULL,
2423         .fw_dump                = qla83xx_fw_dump,
2424         .beacon_on              = qla24xx_beacon_on,
2425         .beacon_off             = qla24xx_beacon_off,
2426         .beacon_blink           = qla83xx_beacon_blink,
2427         .read_optrom            = qla25xx_read_optrom_data,
2428         .write_optrom           = qla24xx_write_optrom_data,
2429         .get_flash_version      = qla24xx_get_flash_version,
2430         .start_scsi             = qla24xx_dif_start_scsi,
2431         .start_scsi_mq          = qla2xxx_dif_start_scsi_mq,
2432         .abort_isp              = qla2x00_abort_isp,
2433         .iospace_config         = qla83xx_iospace_config,
2434         .initialize_adapter     = qla2x00_initialize_adapter,
2435 };
2436 
2437 static struct isp_operations qlafx00_isp_ops = {
2438         .pci_config             = qlafx00_pci_config,
2439         .reset_chip             = qlafx00_soft_reset,
2440         .chip_diag              = qlafx00_chip_diag,
2441         .config_rings           = qlafx00_config_rings,
2442         .reset_adapter          = qlafx00_soft_reset,
2443         .nvram_config           = NULL,
2444         .update_fw_options      = NULL,
2445         .load_risc              = NULL,
2446         .pci_info_str           = qlafx00_pci_info_str,
2447         .fw_version_str         = qlafx00_fw_version_str,
2448         .intr_handler           = qlafx00_intr_handler,
2449         .enable_intrs           = qlafx00_enable_intrs,
2450         .disable_intrs          = qlafx00_disable_intrs,
2451         .abort_command          = qla24xx_async_abort_command,
2452         .target_reset           = qlafx00_abort_target,
2453         .lun_reset              = qlafx00_lun_reset,
2454         .fabric_login           = NULL,
2455         .fabric_logout          = NULL,
2456         .calc_req_entries       = NULL,
2457         .build_iocbs            = NULL,
2458         .prep_ms_iocb           = qla24xx_prep_ms_iocb,
2459         .prep_ms_fdmi_iocb      = qla24xx_prep_ms_fdmi_iocb,
2460         .read_nvram             = qla24xx_read_nvram_data,
2461         .write_nvram            = qla24xx_write_nvram_data,
2462         .fw_dump                = NULL,
2463         .beacon_on              = qla24xx_beacon_on,
2464         .beacon_off             = qla24xx_beacon_off,
2465         .beacon_blink           = NULL,
2466         .read_optrom            = qla24xx_read_optrom_data,
2467         .write_optrom           = qla24xx_write_optrom_data,
2468         .get_flash_version      = qla24xx_get_flash_version,
2469         .start_scsi             = qlafx00_start_scsi,
2470         .start_scsi_mq          = NULL,
2471         .abort_isp              = qlafx00_abort_isp,
2472         .iospace_config         = qlafx00_iospace_config,
2473         .initialize_adapter     = qlafx00_initialize_adapter,
2474 };
2475 
2476 static struct isp_operations qla27xx_isp_ops = {
2477         .pci_config             = qla25xx_pci_config,
2478         .reset_chip             = qla24xx_reset_chip,
2479         .chip_diag              = qla24xx_chip_diag,
2480         .config_rings           = qla24xx_config_rings,
2481         .reset_adapter          = qla24xx_reset_adapter,
2482         .nvram_config           = qla81xx_nvram_config,
2483         .update_fw_options      = qla24xx_update_fw_options,
2484         .load_risc              = qla81xx_load_risc,
2485         .pci_info_str           = qla24xx_pci_info_str,
2486         .fw_version_str         = qla24xx_fw_version_str,
2487         .intr_handler           = qla24xx_intr_handler,
2488         .enable_intrs           = qla24xx_enable_intrs,
2489         .disable_intrs          = qla24xx_disable_intrs,
2490         .abort_command          = qla24xx_abort_command,
2491         .target_reset           = qla24xx_abort_target,
2492         .lun_reset              = qla24xx_lun_reset,
2493         .fabric_login           = qla24xx_login_fabric,
2494         .fabric_logout          = qla24xx_fabric_logout,
2495         .calc_req_entries       = NULL,
2496         .build_iocbs            = NULL,
2497         .prep_ms_iocb           = qla24xx_prep_ms_iocb,
2498         .prep_ms_fdmi_iocb      = qla24xx_prep_ms_fdmi_iocb,
2499         .read_nvram             = NULL,
2500         .write_nvram            = NULL,
2501         .fw_dump                = qla27xx_fwdump,
2502         .beacon_on              = qla24xx_beacon_on,
2503         .beacon_off             = qla24xx_beacon_off,
2504         .beacon_blink           = qla83xx_beacon_blink,
2505         .read_optrom            = qla25xx_read_optrom_data,
2506         .write_optrom           = qla24xx_write_optrom_data,
2507         .get_flash_version      = qla24xx_get_flash_version,
2508         .start_scsi             = qla24xx_dif_start_scsi,
2509         .start_scsi_mq          = qla2xxx_dif_start_scsi_mq,
2510         .abort_isp              = qla2x00_abort_isp,
2511         .iospace_config         = qla83xx_iospace_config,
2512         .initialize_adapter     = qla2x00_initialize_adapter,
2513 };
2514 
2515 static inline void
2516 qla2x00_set_isp_flags(struct qla_hw_data *ha)
2517 {
2518         ha->device_type = DT_EXTENDED_IDS;
2519         switch (ha->pdev->device) {
2520         case PCI_DEVICE_ID_QLOGIC_ISP2100:
2521                 ha->isp_type |= DT_ISP2100;
2522                 ha->device_type &= ~DT_EXTENDED_IDS;
2523                 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
2524                 break;
2525         case PCI_DEVICE_ID_QLOGIC_ISP2200:
2526                 ha->isp_type |= DT_ISP2200;
2527                 ha->device_type &= ~DT_EXTENDED_IDS;
2528                 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
2529                 break;
2530         case PCI_DEVICE_ID_QLOGIC_ISP2300:
2531                 ha->isp_type |= DT_ISP2300;
2532                 ha->device_type |= DT_ZIO_SUPPORTED;
2533                 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
2534                 break;
2535         case PCI_DEVICE_ID_QLOGIC_ISP2312:
2536                 ha->isp_type |= DT_ISP2312;
2537                 ha->device_type |= DT_ZIO_SUPPORTED;
2538                 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
2539                 break;
2540         case PCI_DEVICE_ID_QLOGIC_ISP2322:
2541                 ha->isp_type |= DT_ISP2322;
2542                 ha->device_type |= DT_ZIO_SUPPORTED;
2543                 if (ha->pdev->subsystem_vendor == 0x1028 &&
2544                     ha->pdev->subsystem_device == 0x0170)
2545                         ha->device_type |= DT_OEM_001;
2546                 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
2547                 break;
2548         case PCI_DEVICE_ID_QLOGIC_ISP6312:
2549                 ha->isp_type |= DT_ISP6312;
2550                 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
2551                 break;
2552         case PCI_DEVICE_ID_QLOGIC_ISP6322:
2553                 ha->isp_type |= DT_ISP6322;
2554                 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
2555                 break;
2556         case PCI_DEVICE_ID_QLOGIC_ISP2422:
2557                 ha->isp_type |= DT_ISP2422;
2558                 ha->device_type |= DT_ZIO_SUPPORTED;
2559                 ha->device_type |= DT_FWI2;
2560                 ha->device_type |= DT_IIDMA;
2561                 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2562                 break;
2563         case PCI_DEVICE_ID_QLOGIC_ISP2432:
2564                 ha->isp_type |= DT_ISP2432;
2565                 ha->device_type |= DT_ZIO_SUPPORTED;
2566                 ha->device_type |= DT_FWI2;
2567                 ha->device_type |= DT_IIDMA;
2568                 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2569                 break;
2570         case PCI_DEVICE_ID_QLOGIC_ISP8432:
2571                 ha->isp_type |= DT_ISP8432;
2572                 ha->device_type |= DT_ZIO_SUPPORTED;
2573                 ha->device_type |= DT_FWI2;
2574                 ha->device_type |= DT_IIDMA;
2575                 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2576                 break;
2577         case PCI_DEVICE_ID_QLOGIC_ISP5422:
2578                 ha->isp_type |= DT_ISP5422;
2579                 ha->device_type |= DT_FWI2;
2580                 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2581                 break;
2582         case PCI_DEVICE_ID_QLOGIC_ISP5432:
2583                 ha->isp_type |= DT_ISP5432;
2584                 ha->device_type |= DT_FWI2;
2585                 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2586                 break;
2587         case PCI_DEVICE_ID_QLOGIC_ISP2532:
2588                 ha->isp_type |= DT_ISP2532;
2589                 ha->device_type |= DT_ZIO_SUPPORTED;
2590                 ha->device_type |= DT_FWI2;
2591                 ha->device_type |= DT_IIDMA;
2592                 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2593                 break;
2594         case PCI_DEVICE_ID_QLOGIC_ISP8001:
2595                 ha->isp_type |= DT_ISP8001;
2596                 ha->device_type |= DT_ZIO_SUPPORTED;
2597                 ha->device_type |= DT_FWI2;
2598                 ha->device_type |= DT_IIDMA;
2599                 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2600                 break;
2601         case PCI_DEVICE_ID_QLOGIC_ISP8021:
2602                 ha->isp_type |= DT_ISP8021;
2603                 ha->device_type |= DT_ZIO_SUPPORTED;
2604                 ha->device_type |= DT_FWI2;
2605                 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2606                 /* Initialize 82XX ISP flags */
2607                 qla82xx_init_flags(ha);
2608                 break;
2609          case PCI_DEVICE_ID_QLOGIC_ISP8044:
2610                 ha->isp_type |= DT_ISP8044;
2611                 ha->device_type |= DT_ZIO_SUPPORTED;
2612                 ha->device_type |= DT_FWI2;
2613                 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2614                 /* Initialize 82XX ISP flags */
2615                 qla82xx_init_flags(ha);
2616                 break;
2617         case PCI_DEVICE_ID_QLOGIC_ISP2031:
2618                 ha->isp_type |= DT_ISP2031;
2619                 ha->device_type |= DT_ZIO_SUPPORTED;
2620                 ha->device_type |= DT_FWI2;
2621                 ha->device_type |= DT_IIDMA;
2622                 ha->device_type |= DT_T10_PI;
2623                 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2624                 break;
2625         case PCI_DEVICE_ID_QLOGIC_ISP8031:
2626                 ha->isp_type |= DT_ISP8031;
2627                 ha->device_type |= DT_ZIO_SUPPORTED;
2628                 ha->device_type |= DT_FWI2;
2629                 ha->device_type |= DT_IIDMA;
2630                 ha->device_type |= DT_T10_PI;
2631                 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2632                 break;
2633         case PCI_DEVICE_ID_QLOGIC_ISPF001:
2634                 ha->isp_type |= DT_ISPFX00;
2635                 break;
2636         case PCI_DEVICE_ID_QLOGIC_ISP2071:
2637                 ha->isp_type |= DT_ISP2071;
2638                 ha->device_type |= DT_ZIO_SUPPORTED;
2639                 ha->device_type |= DT_FWI2;
2640                 ha->device_type |= DT_IIDMA;
2641                 ha->device_type |= DT_T10_PI;
2642                 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2643                 break;
2644         case PCI_DEVICE_ID_QLOGIC_ISP2271:
2645                 ha->isp_type |= DT_ISP2271;
2646                 ha->device_type |= DT_ZIO_SUPPORTED;
2647                 ha->device_type |= DT_FWI2;
2648                 ha->device_type |= DT_IIDMA;
2649                 ha->device_type |= DT_T10_PI;
2650                 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2651                 break;
2652         case PCI_DEVICE_ID_QLOGIC_ISP2261:
2653                 ha->isp_type |= DT_ISP2261;
2654                 ha->device_type |= DT_ZIO_SUPPORTED;
2655                 ha->device_type |= DT_FWI2;
2656                 ha->device_type |= DT_IIDMA;
2657                 ha->device_type |= DT_T10_PI;
2658                 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2659                 break;
2660         case PCI_DEVICE_ID_QLOGIC_ISP2081:
2661         case PCI_DEVICE_ID_QLOGIC_ISP2089:
2662                 ha->isp_type |= DT_ISP2081;
2663                 ha->device_type |= DT_ZIO_SUPPORTED;
2664                 ha->device_type |= DT_FWI2;
2665                 ha->device_type |= DT_IIDMA;
2666                 ha->device_type |= DT_T10_PI;
2667                 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2668                 break;
2669         case PCI_DEVICE_ID_QLOGIC_ISP2281:
2670         case PCI_DEVICE_ID_QLOGIC_ISP2289:
2671                 ha->isp_type |= DT_ISP2281;
2672                 ha->device_type |= DT_ZIO_SUPPORTED;
2673                 ha->device_type |= DT_FWI2;
2674                 ha->device_type |= DT_IIDMA;
2675                 ha->device_type |= DT_T10_PI;
2676                 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2677                 break;
2678         }
2679 
2680         if (IS_QLA82XX(ha))
2681                 ha->port_no = ha->portnum & 1;
2682         else {
2683                 /* Get adapter physical port no from interrupt pin register. */
2684                 pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
2685                 if (IS_QLA25XX(ha) || IS_QLA2031(ha) ||
2686                     IS_QLA27XX(ha) || IS_QLA28XX(ha))
2687                         ha->port_no--;
2688                 else
2689                         ha->port_no = !(ha->port_no & 1);
2690         }
2691 
2692         ql_dbg_pci(ql_dbg_init, ha->pdev, 0x000b,
2693             "device_type=0x%x port=%d fw_srisc_address=0x%x.\n",
2694             ha->device_type, ha->port_no, ha->fw_srisc_address);
2695 }
2696 
2697 static void
2698 qla2xxx_scan_start(struct Scsi_Host *shost)
2699 {
2700         scsi_qla_host_t *vha = shost_priv(shost);
2701 
2702         if (vha->hw->flags.running_gold_fw)
2703                 return;
2704 
2705         set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
2706         set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2707         set_bit(RSCN_UPDATE, &vha->dpc_flags);
2708         set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
2709 }
2710 
2711 static int
2712 qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
2713 {
2714         scsi_qla_host_t *vha = shost_priv(shost);
2715 
2716         if (test_bit(UNLOADING, &vha->dpc_flags))
2717                 return 1;
2718         if (!vha->host)
2719                 return 1;
2720         if (time > vha->hw->loop_reset_delay * HZ)
2721                 return 1;
2722 
2723         return atomic_read(&vha->loop_state) == LOOP_READY;
2724 }
2725 
2726 static void qla2x00_iocb_work_fn(struct work_struct *work)
2727 {
2728         struct scsi_qla_host *vha = container_of(work,
2729                 struct scsi_qla_host, iocb_work);
2730         struct qla_hw_data *ha = vha->hw;
2731         struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2732         int i = 2;
2733         unsigned long flags;
2734 
2735         if (test_bit(UNLOADING, &base_vha->dpc_flags))
2736                 return;
2737 
2738         while (!list_empty(&vha->work_list) && i > 0) {
2739                 qla2x00_do_work(vha);
2740                 i--;
2741         }
2742 
2743         spin_lock_irqsave(&vha->work_lock, flags);
2744         clear_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags);
2745         spin_unlock_irqrestore(&vha->work_lock, flags);
2746 }
2747 
2748 /*
2749  * PCI driver interface
2750  */
2751 static int
2752 qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
2753 {
2754         int     ret = -ENODEV;
2755         struct Scsi_Host *host;
2756         scsi_qla_host_t *base_vha = NULL;
2757         struct qla_hw_data *ha;
2758         char pci_info[30];
2759         char fw_str[30], wq_name[30];
2760         struct scsi_host_template *sht;
2761         int bars, mem_only = 0;
2762         uint16_t req_length = 0, rsp_length = 0;
2763         struct req_que *req = NULL;
2764         struct rsp_que *rsp = NULL;
2765         int i;
2766 
2767         bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
2768         sht = &qla2xxx_driver_template;
2769         if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
2770             pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
2771             pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
2772             pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
2773             pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
2774             pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
2775             pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 ||
2776             pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021 ||
2777             pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2031 ||
2778             pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8031 ||
2779             pdev->device == PCI_DEVICE_ID_QLOGIC_ISPF001 ||
2780             pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8044 ||
2781             pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2071 ||
2782             pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2271 ||
2783             pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2261 ||
2784             pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2081 ||
2785             pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2281 ||
2786             pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2089 ||
2787             pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2289) {
2788                 bars = pci_select_bars(pdev, IORESOURCE_MEM);
2789                 mem_only = 1;
2790                 ql_dbg_pci(ql_dbg_init, pdev, 0x0007,
2791                     "Mem only adapter.\n");
2792         }
2793         ql_dbg_pci(ql_dbg_init, pdev, 0x0008,
2794             "Bars=%d.\n", bars);
2795 
2796         if (mem_only) {
2797                 if (pci_enable_device_mem(pdev))
2798                         return ret;
2799         } else {
2800                 if (pci_enable_device(pdev))
2801                         return ret;
2802         }
2803 
2804         /* This may fail but that's ok */
2805         pci_enable_pcie_error_reporting(pdev);
2806 
2807         /* Turn off T10-DIF when FC-NVMe is enabled */
2808         if (ql2xnvmeenable)
2809                 ql2xenabledif = 0;
2810 
2811         ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
2812         if (!ha) {
2813                 ql_log_pci(ql_log_fatal, pdev, 0x0009,
2814                     "Unable to allocate memory for ha.\n");
2815                 goto disable_device;
2816         }
2817         ql_dbg_pci(ql_dbg_init, pdev, 0x000a,
2818             "Memory allocated for ha=%p.\n", ha);
2819         ha->pdev = pdev;
2820         INIT_LIST_HEAD(&ha->tgt.q_full_list);
2821         spin_lock_init(&ha->tgt.q_full_lock);
2822         spin_lock_init(&ha->tgt.sess_lock);
2823         spin_lock_init(&ha->tgt.atio_lock);
2824 
2825         atomic_set(&ha->nvme_active_aen_cnt, 0);
2826 
2827         /* Clear our data area */
2828         ha->bars = bars;
2829         ha->mem_only = mem_only;
2830         spin_lock_init(&ha->hardware_lock);
2831         spin_lock_init(&ha->vport_slock);
2832         mutex_init(&ha->selflogin_lock);
2833         mutex_init(&ha->optrom_mutex);
2834 
2835         /* Set ISP-type information. */
2836         qla2x00_set_isp_flags(ha);
2837 
2838         /* Set EEH reset type to fundamental if required by hba */
2839         if (IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha) ||
2840             IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))
2841                 pdev->needs_freset = 1;
2842 
2843         ha->prev_topology = 0;
2844         ha->init_cb_size = sizeof(init_cb_t);
2845         ha->link_data_rate = PORT_SPEED_UNKNOWN;
2846         ha->optrom_size = OPTROM_SIZE_2300;
2847         ha->max_exchg = FW_MAX_EXCHANGES_CNT;
2848         atomic_set(&ha->num_pend_mbx_stage1, 0);
2849         atomic_set(&ha->num_pend_mbx_stage2, 0);
2850         atomic_set(&ha->num_pend_mbx_stage3, 0);
2851         atomic_set(&ha->zio_threshold, DEFAULT_ZIO_THRESHOLD);
2852         ha->last_zio_threshold = DEFAULT_ZIO_THRESHOLD;
2853 
2854         /* Assign ISP specific operations. */
2855         if (IS_QLA2100(ha)) {
2856                 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
2857                 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
2858                 req_length = REQUEST_ENTRY_CNT_2100;
2859                 rsp_length = RESPONSE_ENTRY_CNT_2100;
2860                 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
2861                 ha->gid_list_info_size = 4;
2862                 ha->flash_conf_off = ~0;
2863                 ha->flash_data_off = ~0;
2864                 ha->nvram_conf_off = ~0;
2865                 ha->nvram_data_off = ~0;
2866                 ha->isp_ops = &qla2100_isp_ops;
2867         } else if (IS_QLA2200(ha)) {
2868                 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
2869                 ha->mbx_count = MAILBOX_REGISTER_COUNT_2200;
2870                 req_length = REQUEST_ENTRY_CNT_2200;
2871                 rsp_length = RESPONSE_ENTRY_CNT_2100;
2872                 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
2873                 ha->gid_list_info_size = 4;
2874                 ha->flash_conf_off = ~0;
2875                 ha->flash_data_off = ~0;
2876                 ha->nvram_conf_off = ~0;
2877                 ha->nvram_data_off = ~0;
2878                 ha->isp_ops = &qla2100_isp_ops;
2879         } else if (IS_QLA23XX(ha)) {
2880                 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
2881                 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2882                 req_length = REQUEST_ENTRY_CNT_2200;
2883                 rsp_length = RESPONSE_ENTRY_CNT_2300;
2884                 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2885                 ha->gid_list_info_size = 6;
2886                 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2887                         ha->optrom_size = OPTROM_SIZE_2322;
2888                 ha->flash_conf_off = ~0;
2889                 ha->flash_data_off = ~0;
2890                 ha->nvram_conf_off = ~0;
2891                 ha->nvram_data_off = ~0;
2892                 ha->isp_ops = &qla2300_isp_ops;
2893         } else if (IS_QLA24XX_TYPE(ha)) {
2894                 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2895                 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2896                 req_length = REQUEST_ENTRY_CNT_24XX;
2897                 rsp_length = RESPONSE_ENTRY_CNT_2300;
2898                 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
2899                 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2900                 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
2901                 ha->gid_list_info_size = 8;
2902                 ha->optrom_size = OPTROM_SIZE_24XX;
2903                 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
2904                 ha->isp_ops = &qla24xx_isp_ops;
2905                 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2906                 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2907                 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2908                 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2909         } else if (IS_QLA25XX(ha)) {
2910                 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2911                 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2912                 req_length = REQUEST_ENTRY_CNT_24XX;
2913                 rsp_length = RESPONSE_ENTRY_CNT_2300;
2914                 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
2915                 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2916                 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
2917                 ha->gid_list_info_size = 8;
2918                 ha->optrom_size = OPTROM_SIZE_25XX;
2919                 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2920                 ha->isp_ops = &qla25xx_isp_ops;
2921                 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2922                 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2923                 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2924                 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2925         } else if (IS_QLA81XX(ha)) {
2926                 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2927                 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2928                 req_length = REQUEST_ENTRY_CNT_24XX;
2929                 rsp_length = RESPONSE_ENTRY_CNT_2300;
2930                 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
2931                 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2932                 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2933                 ha->gid_list_info_size = 8;
2934                 ha->optrom_size = OPTROM_SIZE_81XX;
2935                 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2936                 ha->isp_ops = &qla81xx_isp_ops;
2937                 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2938                 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2939                 ha->nvram_conf_off = ~0;
2940                 ha->nvram_data_off = ~0;
2941         } else if (IS_QLA82XX(ha)) {
2942                 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2943                 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2944                 req_length = REQUEST_ENTRY_CNT_82XX;
2945                 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2946                 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2947                 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2948                 ha->gid_list_info_size = 8;
2949                 ha->optrom_size = OPTROM_SIZE_82XX;
2950                 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2951                 ha->isp_ops = &qla82xx_isp_ops;
2952                 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2953                 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2954                 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2955                 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2956         } else if (IS_QLA8044(ha)) {
2957                 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2958                 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2959                 req_length = REQUEST_ENTRY_CNT_82XX;
2960                 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2961                 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2962                 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2963                 ha->gid_list_info_size = 8;
2964                 ha->optrom_size = OPTROM_SIZE_83XX;
2965                 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2966                 ha->isp_ops = &qla8044_isp_ops;
2967                 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2968                 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2969                 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2970                 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2971         } else if (IS_QLA83XX(ha)) {
2972                 ha->portnum = PCI_FUNC(ha->pdev->devfn);
2973                 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2974                 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2975                 req_length = REQUEST_ENTRY_CNT_83XX;
2976                 rsp_length = RESPONSE_ENTRY_CNT_83XX;
2977                 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
2978                 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2979                 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2980                 ha->gid_list_info_size = 8;
2981                 ha->optrom_size = OPTROM_SIZE_83XX;
2982                 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2983                 ha->isp_ops = &qla83xx_isp_ops;
2984                 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2985                 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2986                 ha->nvram_conf_off = ~0;
2987                 ha->nvram_data_off = ~0;
2988         }  else if (IS_QLAFX00(ha)) {
2989                 ha->max_fibre_devices = MAX_FIBRE_DEVICES_FX00;
2990                 ha->mbx_count = MAILBOX_REGISTER_COUNT_FX00;
2991                 ha->aen_mbx_count = AEN_MAILBOX_REGISTER_COUNT_FX00;
2992                 req_length = REQUEST_ENTRY_CNT_FX00;
2993                 rsp_length = RESPONSE_ENTRY_CNT_FX00;
2994                 ha->isp_ops = &qlafx00_isp_ops;
2995                 ha->port_down_retry_count = 30; /* default value */
2996                 ha->mr.fw_hbt_cnt = QLAFX00_HEARTBEAT_INTERVAL;
2997                 ha->mr.fw_reset_timer_tick = QLAFX00_RESET_INTERVAL;
2998                 ha->mr.fw_critemp_timer_tick = QLAFX00_CRITEMP_INTERVAL;
2999                 ha->mr.fw_hbt_en = 1;
3000                 ha->mr.host_info_resend = false;
3001                 ha->mr.hinfo_resend_timer_tick = QLAFX00_HINFO_RESEND_INTERVAL;
3002         } else if (IS_QLA27XX(ha)) {
3003                 ha->portnum = PCI_FUNC(ha->pdev->devfn);
3004                 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
3005                 ha->mbx_count = MAILBOX_REGISTER_COUNT;
3006                 req_length = REQUEST_ENTRY_CNT_83XX;
3007                 rsp_length = RESPONSE_ENTRY_CNT_83XX;
3008                 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
3009                 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3010                 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3011                 ha->gid_list_info_size = 8;
3012                 ha->optrom_size = OPTROM_SIZE_83XX;
3013                 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
3014                 ha->isp_ops = &qla27xx_isp_ops;
3015                 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
3016                 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
3017                 ha->nvram_conf_off = ~0;
3018                 ha->nvram_data_off = ~0;
3019         } else if (IS_QLA28XX(ha)) {
3020                 ha->portnum = PCI_FUNC(ha->pdev->devfn);
3021                 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
3022                 ha->mbx_count = MAILBOX_REGISTER_COUNT;
3023                 req_length = REQUEST_ENTRY_CNT_24XX;
3024                 rsp_length = RESPONSE_ENTRY_CNT_2300;
3025                 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
3026                 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3027                 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3028                 ha->gid_list_info_size = 8;
3029                 ha->optrom_size = OPTROM_SIZE_28XX;
3030                 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
3031                 ha->isp_ops = &qla27xx_isp_ops;
3032                 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_28XX;
3033                 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_28XX;
3034                 ha->nvram_conf_off = ~0;
3035                 ha->nvram_data_off = ~0;
3036         }
3037 
3038         ql_dbg_pci(ql_dbg_init, pdev, 0x001e,
3039             "mbx_count=%d, req_length=%d, "
3040             "rsp_length=%d, max_loop_id=%d, init_cb_size=%d, "
3041             "gid_list_info_size=%d, optrom_size=%d, nvram_npiv_size=%d, "
3042             "max_fibre_devices=%d.\n",
3043             ha->mbx_count, req_length, rsp_length, ha->max_loop_id,
3044             ha->init_cb_size, ha->gid_list_info_size, ha->optrom_size,
3045             ha->nvram_npiv_size, ha->max_fibre_devices);
3046         ql_dbg_pci(ql_dbg_init, pdev, 0x001f,
3047             "isp_ops=%p, flash_conf_off=%d, "
3048             "flash_data_off=%d, nvram_conf_off=%d, nvram_data_off=%d.\n",
3049             ha->isp_ops, ha->flash_conf_off, ha->flash_data_off,
3050             ha->nvram_conf_off, ha->nvram_data_off);
3051 
3052         /* Configure PCI I/O space */
3053         ret = ha->isp_ops->iospace_config(ha);
3054         if (ret)
3055                 goto iospace_config_failed;
3056 
3057         ql_log_pci(ql_log_info, pdev, 0x001d,
3058             "Found an ISP%04X irq %d iobase 0x%p.\n",
3059             pdev->device, pdev->irq, ha->iobase);
3060         mutex_init(&ha->vport_lock);
3061         mutex_init(&ha->mq_lock);
3062         init_completion(&ha->mbx_cmd_comp);
3063         complete(&ha->mbx_cmd_comp);
3064         init_completion(&ha->mbx_intr_comp);
3065         init_completion(&ha->dcbx_comp);
3066         init_completion(&ha->lb_portup_comp);
3067 
3068         set_bit(0, (unsigned long *) ha->vp_idx_map);
3069 
3070         qla2x00_config_dma_addressing(ha);
3071         ql_dbg_pci(ql_dbg_init, pdev, 0x0020,
3072             "64 Bit addressing is %s.\n",
3073             ha->flags.enable_64bit_addressing ? "enable" :
3074             "disable");
3075         ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
3076         if (ret) {
3077                 ql_log_pci(ql_log_fatal, pdev, 0x0031,
3078                     "Failed to allocate memory for adapter, aborting.\n");
3079 
3080                 goto probe_hw_failed;
3081         }
3082 
3083         req->max_q_depth = MAX_Q_DEPTH;
3084         if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
3085                 req->max_q_depth = ql2xmaxqdepth;
3086 
3087 
3088         base_vha = qla2x00_create_host(sht, ha);
3089         if (!base_vha) {
3090                 ret = -ENOMEM;
3091                 goto probe_hw_failed;
3092         }
3093 
3094         pci_set_drvdata(pdev, base_vha);
3095         set_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
3096 
3097         host = base_vha->host;
3098         base_vha->req = req;
3099         if (IS_QLA2XXX_MIDTYPE(ha))
3100                 base_vha->mgmt_svr_loop_id =
3101                         qla2x00_reserve_mgmt_server_loop_id(base_vha);
3102         else
3103                 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
3104                                                 base_vha->vp_idx;
3105 
3106         /* Setup fcport template structure. */
3107         ha->mr.fcport.vha = base_vha;
3108         ha->mr.fcport.port_type = FCT_UNKNOWN;
3109         ha->mr.fcport.loop_id = FC_NO_LOOP_ID;
3110         qla2x00_set_fcport_state(&ha->mr.fcport, FCS_UNCONFIGURED);
3111         ha->mr.fcport.supported_classes = FC_COS_UNSPECIFIED;
3112         ha->mr.fcport.scan_state = 1;
3113 
3114         /* Set the SG table size based on ISP type */
3115         if (!IS_FWI2_CAPABLE(ha)) {
3116                 if (IS_QLA2100(ha))
3117                         host->sg_tablesize = 32;
3118         } else {
3119                 if (!IS_QLA82XX(ha))
3120                         host->sg_tablesize = QLA_SG_ALL;
3121         }
3122         host->max_id = ha->max_fibre_devices;
3123         host->cmd_per_lun = 3;
3124         host->unique_id = host->host_no;
3125         if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif)
3126                 host->max_cmd_len = 32;
3127         else
3128                 host->max_cmd_len = MAX_CMDSZ;
3129         host->max_channel = MAX_BUSES - 1;
3130         /* Older HBAs support only 16-bit LUNs */
3131         if (!IS_QLAFX00(ha) && !IS_FWI2_CAPABLE(ha) &&
3132             ql2xmaxlun > 0xffff)
3133                 host->max_lun = 0xffff;
3134         else
3135                 host->max_lun = ql2xmaxlun;
3136         host->transportt = qla2xxx_transport_template;
3137         sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
3138 
3139         ql_dbg(ql_dbg_init, base_vha, 0x0033,
3140             "max_id=%d this_id=%d "
3141             "cmd_per_len=%d unique_id=%d max_cmd_len=%d max_channel=%d "
3142             "max_lun=%llu transportt=%p, vendor_id=%llu.\n", host->max_id,
3143             host->this_id, host->cmd_per_lun, host->unique_id,
3144             host->max_cmd_len, host->max_channel, host->max_lun,
3145             host->transportt, sht->vendor_id);
3146 
3147         INIT_WORK(&base_vha->iocb_work, qla2x00_iocb_work_fn);
3148 
3149         /* Set up the irqs */
3150         ret = qla2x00_request_irqs(ha, rsp);
3151         if (ret)
3152                 goto probe_failed;
3153 
3154         /* Alloc arrays of request and response ring ptrs */
3155         ret = qla2x00_alloc_queues(ha, req, rsp);
3156         if (ret) {
3157                 ql_log(ql_log_fatal, base_vha, 0x003d,
3158                     "Failed to allocate memory for queue pointers..."
3159                     "aborting.\n");
3160                 ret = -ENODEV;
3161                 goto probe_failed;
3162         }
3163 
3164         if (ha->mqenable) {
3165                 /* number of hardware queues supported by blk/scsi-mq*/
3166                 host->nr_hw_queues = ha->max_qpairs;
3167 
3168                 ql_dbg(ql_dbg_init, base_vha, 0x0192,
3169                         "blk/scsi-mq enabled, HW queues = %d.\n", host->nr_hw_queues);
3170         } else {
3171                 if (ql2xnvmeenable) {
3172                         host->nr_hw_queues = ha->max_qpairs;
3173                         ql_dbg(ql_dbg_init, base_vha, 0x0194,
3174                             "FC-NVMe support is enabled, HW queues=%d\n",
3175                             host->nr_hw_queues);
3176                 } else {
3177                         ql_dbg(ql_dbg_init, base_vha, 0x0193,
3178                             "blk/scsi-mq disabled.\n");
3179                 }
3180         }
3181 
3182         qlt_probe_one_stage1(base_vha, ha);
3183 
3184         pci_save_state(pdev);
3185 
3186         /* Assign back pointers */
3187         rsp->req = req;
3188         req->rsp = rsp;
3189 
3190         if (IS_QLAFX00(ha)) {
3191                 ha->rsp_q_map[0] = rsp;
3192                 ha->req_q_map[0] = req;
3193                 set_bit(0, ha->req_qid_map);
3194                 set_bit(0, ha->rsp_qid_map);
3195         }
3196 
3197         /* FWI2-capable only. */
3198         req->req_q_in = &ha->iobase->isp24.req_q_in;
3199         req->req_q_out = &ha->iobase->isp24.req_q_out;
3200         rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
3201         rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
3202         if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
3203             IS_QLA28XX(ha)) {
3204                 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
3205                 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
3206                 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
3207                 rsp->rsp_q_out =  &ha->mqiobase->isp25mq.rsp_q_out;
3208         }
3209 
3210         if (IS_QLAFX00(ha)) {
3211                 req->req_q_in = &ha->iobase->ispfx00.req_q_in;
3212                 req->req_q_out = &ha->iobase->ispfx00.req_q_out;
3213                 rsp->rsp_q_in = &ha->iobase->ispfx00.rsp_q_in;
3214                 rsp->rsp_q_out = &ha->iobase->ispfx00.rsp_q_out;
3215         }
3216 
3217         if (IS_P3P_TYPE(ha)) {
3218                 req->req_q_out = &ha->iobase->isp82.req_q_out[0];
3219                 rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0];
3220                 rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0];
3221         }
3222 
3223         ql_dbg(ql_dbg_multiq, base_vha, 0xc009,
3224             "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
3225             ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
3226         ql_dbg(ql_dbg_multiq, base_vha, 0xc00a,
3227             "req->req_q_in=%p req->req_q_out=%p "
3228             "rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
3229             req->req_q_in, req->req_q_out,
3230             rsp->rsp_q_in, rsp->rsp_q_out);
3231         ql_dbg(ql_dbg_init, base_vha, 0x003e,
3232             "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
3233             ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
3234         ql_dbg(ql_dbg_init, base_vha, 0x003f,
3235             "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
3236             req->req_q_in, req->req_q_out, rsp->rsp_q_in, rsp->rsp_q_out);
3237 
3238         ha->wq = alloc_workqueue("qla2xxx_wq", 0, 0);
3239         if (unlikely(!ha->wq)) {
3240                 ret = -ENOMEM;
3241                 goto probe_failed;
3242         }
3243 
3244         if (ha->isp_ops->initialize_adapter(base_vha)) {
3245                 ql_log(ql_log_fatal, base_vha, 0x00d6,
3246                     "Failed to initialize adapter - Adapter flags %x.\n",
3247                     base_vha->device_flags);
3248 
3249                 if (IS_QLA82XX(ha)) {
3250                         qla82xx_idc_lock(ha);
3251                         qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
3252                                 QLA8XXX_DEV_FAILED);
3253                         qla82xx_idc_unlock(ha);
3254                         ql_log(ql_log_fatal, base_vha, 0x00d7,
3255                             "HW State: FAILED.\n");
3256                 } else if (IS_QLA8044(ha)) {
3257                         qla8044_idc_lock(ha);
3258                         qla8044_wr_direct(base_vha,
3259                                 QLA8044_CRB_DEV_STATE_INDEX,
3260                                 QLA8XXX_DEV_FAILED);
3261                         qla8044_idc_unlock(ha);
3262                         ql_log(ql_log_fatal, base_vha, 0x0150,
3263                             "HW State: FAILED.\n");
3264                 }
3265 
3266                 ret = -ENODEV;
3267                 goto probe_failed;
3268         }
3269 
3270         if (IS_QLAFX00(ha))
3271                 host->can_queue = QLAFX00_MAX_CANQUEUE;
3272         else
3273                 host->can_queue = req->num_outstanding_cmds - 10;
3274 
3275         ql_dbg(ql_dbg_init, base_vha, 0x0032,
3276             "can_queue=%d, req=%p, mgmt_svr_loop_id=%d, sg_tablesize=%d.\n",
3277             host->can_queue, base_vha->req,
3278             base_vha->mgmt_svr_loop_id, host->sg_tablesize);
3279 
3280         if (ha->mqenable) {
3281                 bool startit = false;
3282 
3283                 if (QLA_TGT_MODE_ENABLED())
3284                         startit = false;
3285 
3286                 if (ql2x_ini_mode == QLA2XXX_INI_MODE_ENABLED)
3287                         startit = true;
3288 
3289                 /* Create start of day qpairs for Block MQ */
3290                 for (i = 0; i < ha->max_qpairs; i++)
3291                         qla2xxx_create_qpair(base_vha, 5, 0, startit);
3292         }
3293 
3294         if (ha->flags.running_gold_fw)
3295                 goto skip_dpc;
3296 
3297         /*
3298          * Startup the kernel thread for this host adapter
3299          */
3300         ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
3301             "%s_dpc", base_vha->host_str);
3302         if (IS_ERR(ha->dpc_thread)) {
3303                 ql_log(ql_log_fatal, base_vha, 0x00ed,
3304                     "Failed to start DPC thread.\n");
3305                 ret = PTR_ERR(ha->dpc_thread);
3306                 ha->dpc_thread = NULL;
3307                 goto probe_failed;
3308         }
3309         ql_dbg(ql_dbg_init, base_vha, 0x00ee,
3310             "DPC thread started successfully.\n");
3311 
3312         /*
3313          * If we're not coming up in initiator mode, we might sit for
3314          * a while without waking up the dpc thread, which leads to a
3315          * stuck process warning.  So just kick the dpc once here and
3316          * let the kthread start (and go back to sleep in qla2x00_do_dpc).
3317          */
3318         qla2xxx_wake_dpc(base_vha);
3319 
3320         INIT_WORK(&ha->board_disable, qla2x00_disable_board_on_pci_error);
3321 
3322         if (IS_QLA8031(ha) || IS_MCTP_CAPABLE(ha)) {
3323                 sprintf(wq_name, "qla2xxx_%lu_dpc_lp_wq", base_vha->host_no);
3324                 ha->dpc_lp_wq = create_singlethread_workqueue(wq_name);
3325                 INIT_WORK(&ha->idc_aen, qla83xx_service_idc_aen);
3326 
3327                 sprintf(wq_name, "qla2xxx_%lu_dpc_hp_wq", base_vha->host_no);
3328                 ha->dpc_hp_wq = create_singlethread_workqueue(wq_name);
3329                 INIT_WORK(&ha->nic_core_reset, qla83xx_nic_core_reset_work);
3330                 INIT_WORK(&ha->idc_state_handler,
3331                     qla83xx_idc_state_handler_work);
3332                 INIT_WORK(&ha->nic_core_unrecoverable,
3333                     qla83xx_nic_core_unrecoverable_work);
3334         }
3335 
3336 skip_dpc:
3337         list_add_tail(&base_vha->list, &ha->vp_list);
3338         base_vha->host->irq = ha->pdev->irq;
3339 
3340         /* Initialized the timer */
3341         qla2x00_start_timer(base_vha, WATCH_INTERVAL);
3342         ql_dbg(ql_dbg_init, base_vha, 0x00ef,
3343             "Started qla2x00_timer with "
3344             "interval=%d.\n", WATCH_INTERVAL);
3345         ql_dbg(ql_dbg_init, base_vha, 0x00f0,
3346             "Detected hba at address=%p.\n",
3347             ha);
3348 
3349         if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
3350                 if (ha->fw_attributes & BIT_4) {
3351                         int prot = 0, guard;
3352 
3353                         base_vha->flags.difdix_supported = 1;
3354                         ql_dbg(ql_dbg_init, base_vha, 0x00f1,
3355                             "Registering for DIF/DIX type 1 and 3 protection.\n");
3356                         if (ql2xenabledif == 1)
3357                                 prot = SHOST_DIX_TYPE0_PROTECTION;
3358                         if (ql2xprotmask)
3359                                 scsi_host_set_prot(host, ql2xprotmask);
3360                         else
3361                                 scsi_host_set_prot(host,
3362                                     prot | SHOST_DIF_TYPE1_PROTECTION
3363                                     | SHOST_DIF_TYPE2_PROTECTION
3364                                     | SHOST_DIF_TYPE3_PROTECTION
3365                                     | SHOST_DIX_TYPE1_PROTECTION
3366                                     | SHOST_DIX_TYPE2_PROTECTION
3367                                     | SHOST_DIX_TYPE3_PROTECTION);
3368 
3369                         guard = SHOST_DIX_GUARD_CRC;
3370 
3371                         if (IS_PI_IPGUARD_CAPABLE(ha) &&
3372                             (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha)))
3373                                 guard |= SHOST_DIX_GUARD_IP;
3374 
3375                         if (ql2xprotguard)
3376                                 scsi_host_set_guard(host, ql2xprotguard);
3377                         else
3378                                 scsi_host_set_guard(host, guard);
3379                 } else
3380                         base_vha->flags.difdix_supported = 0;
3381         }
3382 
3383         ha->isp_ops->enable_intrs(ha);
3384 
3385         if (IS_QLAFX00(ha)) {
3386                 ret = qlafx00_fx_disc(base_vha,
3387                         &base_vha->hw->mr.fcport, FXDISC_GET_CONFIG_INFO);
3388                 host->sg_tablesize = (ha->mr.extended_io_enabled) ?
3389                     QLA_SG_ALL : 128;
3390         }
3391 
3392         ret = scsi_add_host(host, &pdev->dev);
3393         if (ret)
3394                 goto probe_failed;
3395 
3396         base_vha->flags.init_done = 1;
3397         base_vha->flags.online = 1;
3398         ha->prev_minidump_failed = 0;
3399 
3400         ql_dbg(ql_dbg_init, base_vha, 0x00f2,
3401             "Init done and hba is online.\n");
3402 
3403         if (qla_ini_mode_enabled(base_vha) ||
3404                 qla_dual_mode_enabled(base_vha))
3405                 scsi_scan_host(host);
3406         else
3407                 ql_dbg(ql_dbg_init, base_vha, 0x0122,
3408                         "skipping scsi_scan_host() for non-initiator port\n");
3409 
3410         qla2x00_alloc_sysfs_attr(base_vha);
3411 
3412         if (IS_QLAFX00(ha)) {
3413                 ret = qlafx00_fx_disc(base_vha,
3414                         &base_vha->hw->mr.fcport, FXDISC_GET_PORT_INFO);
3415 
3416                 /* Register system information */
3417                 ret =  qlafx00_fx_disc(base_vha,
3418                         &base_vha->hw->mr.fcport, FXDISC_REG_HOST_INFO);
3419         }
3420 
3421         qla2x00_init_host_attr(base_vha);
3422 
3423         qla2x00_dfs_setup(base_vha);
3424 
3425         ql_log(ql_log_info, base_vha, 0x00fb,
3426             "QLogic %s - %s.\n", ha->model_number, ha->model_desc);
3427         ql_log(ql_log_info, base_vha, 0x00fc,
3428             "ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n",
3429             pdev->device, ha->isp_ops->pci_info_str(base_vha, pci_info,
3430                                                        sizeof(pci_info)),
3431             pci_name(pdev), ha->flags.enable_64bit_addressing ? '+' : '-',
3432             base_vha->host_no,
3433             ha->isp_ops->fw_version_str(base_vha, fw_str, sizeof(fw_str)));
3434 
3435         qlt_add_target(ha, base_vha);
3436 
3437         clear_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
3438 
3439         if (test_bit(UNLOADING, &base_vha->dpc_flags))
3440                 return -ENODEV;
3441 
3442         if (ha->flags.detected_lr_sfp) {
3443                 ql_log(ql_log_info, base_vha, 0xffff,
3444                     "Reset chip to pick up LR SFP setting\n");
3445                 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
3446                 qla2xxx_wake_dpc(base_vha);
3447         }
3448 
3449         return 0;
3450 
3451 probe_failed:
3452         if (base_vha->gnl.l) {
3453                 dma_free_coherent(&ha->pdev->dev, base_vha->gnl.size,
3454                                 base_vha->gnl.l, base_vha->gnl.ldma);
3455                 base_vha->gnl.l = NULL;
3456         }
3457 
3458         if (base_vha->timer_active)
3459                 qla2x00_stop_timer(base_vha);
3460         base_vha->flags.online = 0;
3461         if (ha->dpc_thread) {
3462                 struct task_struct *t = ha->dpc_thread;
3463 
3464                 ha->dpc_thread = NULL;
3465                 kthread_stop(t);
3466         }
3467 
3468         qla2x00_free_device(base_vha);
3469         scsi_host_put(base_vha->host);
3470         /*
3471          * Need to NULL out local req/rsp after
3472          * qla2x00_free_device => qla2x00_free_queues frees
3473          * what these are pointing to. Or else we'll
3474          * fall over below in qla2x00_free_req/rsp_que.
3475          */
3476         req = NULL;
3477         rsp = NULL;
3478 
3479 probe_hw_failed:
3480         qla2x00_mem_free(ha);
3481         qla2x00_free_req_que(ha, req);
3482         qla2x00_free_rsp_que(ha, rsp);
3483         qla2x00_clear_drv_active(ha);
3484 
3485 iospace_config_failed:
3486         if (IS_P3P_TYPE(ha)) {
3487                 if (!ha->nx_pcibase)
3488                         iounmap((device_reg_t *)ha->nx_pcibase);
3489                 if (!ql2xdbwr)
3490                         iounmap((device_reg_t *)ha->nxdb_wr_ptr);
3491         } else {
3492                 if (ha->iobase)
3493                         iounmap(ha->iobase);
3494                 if (ha->cregbase)
3495                         iounmap(ha->cregbase);
3496         }
3497         pci_release_selected_regions(ha->pdev, ha->bars);
3498         kfree(ha);
3499 
3500 disable_device:
3501         pci_disable_device(pdev);
3502         return ret;
3503 }
3504 
3505 static void
3506 qla2x00_shutdown(struct pci_dev *pdev)
3507 {
3508         scsi_qla_host_t *vha;
3509         struct qla_hw_data  *ha;
3510 
3511         vha = pci_get_drvdata(pdev);
3512         ha = vha->hw;
3513 
3514         ql_log(ql_log_info, vha, 0xfffa,
3515                 "Adapter shutdown\n");
3516 
3517         /*
3518          * Prevent future board_disable and wait
3519          * until any pending board_disable has completed.
3520          */
3521         set_bit(PFLG_DRIVER_REMOVING, &vha->pci_flags);
3522         cancel_work_sync(&ha->board_disable);
3523 
3524         if (!atomic_read(&pdev->enable_cnt))
3525                 return;
3526 
3527         /* Notify ISPFX00 firmware */
3528         if (IS_QLAFX00(ha))
3529                 qlafx00_driver_shutdown(vha, 20);
3530 
3531         /* Turn-off FCE trace */
3532         if (ha->flags.fce_enabled) {
3533                 qla2x00_disable_fce_trace(vha, NULL, NULL);
3534                 ha->flags.fce_enabled = 0;
3535         }
3536 
3537         /* Turn-off EFT trace */
3538         if (ha->eft)
3539                 qla2x00_disable_eft_trace(vha);
3540 
3541         if (IS_QLA25XX(ha) ||  IS_QLA2031(ha) || IS_QLA27XX(ha) ||
3542             IS_QLA28XX(ha)) {
3543                 if (ha->flags.fw_started)
3544                         qla2x00_abort_isp_cleanup(vha);
3545         } else {
3546                 /* Stop currently executing firmware. */
3547                 qla2x00_try_to_stop_firmware(vha);
3548         }
3549 
3550         /* Disable timer */
3551         if (vha->timer_active)
3552                 qla2x00_stop_timer(vha);
3553 
3554         /* Turn adapter off line */
3555         vha->flags.online = 0;
3556 
3557         /* turn-off interrupts on the card */
3558         if (ha->interrupts_on) {
3559                 vha->flags.init_done = 0;
3560                 ha->isp_ops->disable_intrs(ha);
3561         }
3562 
3563         qla2x00_free_irqs(vha);
3564 
3565         qla2x00_free_fw_dump(ha);
3566 
3567         pci_disable_device(pdev);
3568         ql_log(ql_log_info, vha, 0xfffe,
3569                 "Adapter shutdown successfully.\n");
3570 }
3571 
3572 /* Deletes all the virtual ports for a given ha */
3573 static void
3574 qla2x00_delete_all_vps(struct qla_hw_data *ha, scsi_qla_host_t *base_vha)
3575 {
3576         scsi_qla_host_t *vha;
3577         unsigned long flags;
3578 
3579         mutex_lock(&ha->vport_lock);
3580         while (ha->cur_vport_count) {
3581                 spin_lock_irqsave(&ha->vport_slock, flags);
3582 
3583                 BUG_ON(base_vha->list.next == &ha->vp_list);
3584                 /* This assumes first entry in ha->vp_list is always base vha */
3585                 vha = list_first_entry(&base_vha->list, scsi_qla_host_t, list);
3586                 scsi_host_get(vha->host);
3587 
3588                 spin_unlock_irqrestore(&ha->vport_slock, flags);
3589                 mutex_unlock(&ha->vport_lock);
3590 
3591                 qla_nvme_delete(vha);
3592 
3593                 fc_vport_terminate(vha->fc_vport);
3594                 scsi_host_put(vha->host);
3595 
3596                 mutex_lock(&ha->vport_lock);
3597         }
3598         mutex_unlock(&ha->vport_lock);
3599 }
3600 
3601 /* Stops all deferred work threads */
3602 static void
3603 qla2x00_destroy_deferred_work(struct qla_hw_data *ha)
3604 {
3605         /* Cancel all work and destroy DPC workqueues */
3606         if (ha->dpc_lp_wq) {
3607                 cancel_work_sync(&ha->idc_aen);
3608                 destroy_workqueue(ha->dpc_lp_wq);
3609                 ha->dpc_lp_wq = NULL;
3610         }
3611 
3612         if (ha->dpc_hp_wq) {
3613                 cancel_work_sync(&ha->nic_core_reset);
3614                 cancel_work_sync(&ha->idc_state_handler);
3615                 cancel_work_sync(&ha->nic_core_unrecoverable);
3616                 destroy_workqueue(ha->dpc_hp_wq);
3617                 ha->dpc_hp_wq = NULL;
3618         }
3619 
3620         /* Kill the kernel thread for this host */
3621         if (ha->dpc_thread) {
3622                 struct task_struct *t = ha->dpc_thread;
3623 
3624                 /*
3625                  * qla2xxx_wake_dpc checks for ->dpc_thread
3626                  * so we need to zero it out.
3627                  */
3628                 ha->dpc_thread = NULL;
3629                 kthread_stop(t);
3630         }
3631 }
3632 
3633 static void
3634 qla2x00_unmap_iobases(struct qla_hw_data *ha)
3635 {
3636         if (IS_QLA82XX(ha)) {
3637 
3638                 iounmap((device_reg_t *)ha->nx_pcibase);
3639                 if (!ql2xdbwr)
3640                         iounmap((device_reg_t *)ha->nxdb_wr_ptr);
3641         } else {
3642                 if (ha->iobase)
3643                         iounmap(ha->iobase);
3644 
3645                 if (ha->cregbase)
3646                         iounmap(ha->cregbase);
3647 
3648                 if (ha->mqiobase)
3649                         iounmap(ha->mqiobase);
3650 
3651                 if ((IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) &&
3652                     ha->msixbase)
3653                         iounmap(ha->msixbase);
3654         }
3655 }
3656 
3657 static void
3658 qla2x00_clear_drv_active(struct qla_hw_data *ha)
3659 {
3660         if (IS_QLA8044(ha)) {
3661                 qla8044_idc_lock(ha);
3662                 qla8044_clear_drv_active(ha);
3663                 qla8044_idc_unlock(ha);
3664         } else if (IS_QLA82XX(ha)) {
3665                 qla82xx_idc_lock(ha);
3666                 qla82xx_clear_drv_active(ha);
3667                 qla82xx_idc_unlock(ha);
3668         }
3669 }
3670 
3671 static void
3672 qla2x00_remove_one(struct pci_dev *pdev)
3673 {
3674         scsi_qla_host_t *base_vha;
3675         struct qla_hw_data  *ha;
3676 
3677         base_vha = pci_get_drvdata(pdev);
3678         ha = base_vha->hw;
3679         ql_log(ql_log_info, base_vha, 0xb079,
3680             "Removing driver\n");
3681 
3682         /* Indicate device removal to prevent future board_disable and wait
3683          * until any pending board_disable has completed. */
3684         set_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags);
3685         cancel_work_sync(&ha->board_disable);
3686 
3687         /*
3688          * If the PCI device is disabled then there was a PCI-disconnect and
3689          * qla2x00_disable_board_on_pci_error has taken care of most of the
3690          * resources.
3691          */
3692         if (!atomic_read(&pdev->enable_cnt)) {
3693                 dma_free_coherent(&ha->pdev->dev, base_vha->gnl.size,
3694                     base_vha->gnl.l, base_vha->gnl.ldma);
3695                 base_vha->gnl.l = NULL;
3696                 scsi_host_put(base_vha->host);
3697                 kfree(ha);
3698                 pci_set_drvdata(pdev, NULL);
3699                 return;
3700         }
3701         qla2x00_wait_for_hba_ready(base_vha);
3702 
3703         /*
3704          * if UNLOADING flag is already set, then continue unload,
3705          * where it was set first.
3706          */
3707         if (test_and_set_bit(UNLOADING, &base_vha->dpc_flags))
3708                 return;
3709 
3710         if (IS_QLA25XX(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha) ||
3711             IS_QLA28XX(ha)) {
3712                 if (ha->flags.fw_started)
3713                         qla2x00_abort_isp_cleanup(base_vha);
3714         } else if (!IS_QLAFX00(ha)) {
3715                 if (IS_QLA8031(ha)) {
3716                         ql_dbg(ql_dbg_p3p, base_vha, 0xb07e,
3717                             "Clearing fcoe driver presence.\n");
3718                         if (qla83xx_clear_drv_presence(base_vha) != QLA_SUCCESS)
3719                                 ql_dbg(ql_dbg_p3p, base_vha, 0xb079,
3720                                     "Error while clearing DRV-Presence.\n");
3721                 }
3722 
3723                 qla2x00_try_to_stop_firmware(base_vha);
3724         }
3725 
3726         qla2x00_wait_for_sess_deletion(base_vha);
3727 
3728         qla_nvme_delete(base_vha);
3729 
3730         dma_free_coherent(&ha->pdev->dev,
3731                 base_vha->gnl.size, base_vha->gnl.l, base_vha->gnl.ldma);
3732 
3733         base_vha->gnl.l = NULL;
3734 
3735         vfree(base_vha->scan.l);
3736 
3737         if (IS_QLAFX00(ha))
3738                 qlafx00_driver_shutdown(base_vha, 20);
3739 
3740         qla2x00_delete_all_vps(ha, base_vha);
3741 
3742         qla2x00_dfs_remove(base_vha);
3743 
3744         qla84xx_put_chip(base_vha);
3745 
3746         /* Disable timer */
3747         if (base_vha->timer_active)
3748                 qla2x00_stop_timer(base_vha);
3749 
3750         base_vha->flags.online = 0;
3751 
3752         /* free DMA memory */
3753         if (ha->exlogin_buf)
3754                 qla2x00_free_exlogin_buffer(ha);
3755 
3756         /* free DMA memory */
3757         if (ha->exchoffld_buf)
3758                 qla2x00_free_exchoffld_buffer(ha);
3759 
3760         qla2x00_destroy_deferred_work(ha);
3761 
3762         qlt_remove_target(ha, base_vha);
3763 
3764         qla2x00_free_sysfs_attr(base_vha, true);
3765 
3766         fc_remove_host(base_vha->host);
3767         qlt_remove_target_resources(ha);
3768 
3769         scsi_remove_host(base_vha->host);
3770 
3771         qla2x00_free_device(base_vha);
3772 
3773         qla2x00_clear_drv_active(ha);
3774 
3775         scsi_host_put(base_vha->host);
3776 
3777         qla2x00_unmap_iobases(ha);
3778 
3779         pci_release_selected_regions(ha->pdev, ha->bars);
3780         kfree(ha);
3781 
3782         pci_disable_pcie_error_reporting(pdev);
3783 
3784         pci_disable_device(pdev);
3785 }
3786 
3787 static void
3788 qla2x00_free_device(scsi_qla_host_t *vha)
3789 {
3790         struct qla_hw_data *ha = vha->hw;
3791 
3792         qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
3793 
3794         /* Disable timer */
3795         if (vha->timer_active)
3796                 qla2x00_stop_timer(vha);
3797 
3798         qla25xx_delete_queues(vha);
3799         vha->flags.online = 0;
3800 
3801         /* turn-off interrupts on the card */
3802         if (ha->interrupts_on) {
3803                 vha->flags.init_done = 0;
3804                 ha->isp_ops->disable_intrs(ha);
3805         }
3806 
3807         qla2x00_free_fcports(vha);
3808 
3809         qla2x00_free_irqs(vha);
3810 
3811         /* Flush the work queue and remove it */
3812         if (ha->wq) {
3813                 flush_workqueue(ha->wq);
3814                 destroy_workqueue(ha->wq);
3815                 ha->wq = NULL;
3816         }
3817 
3818 
3819         qla2x00_mem_free(ha);
3820 
3821         qla82xx_md_free(vha);
3822 
3823         qla2x00_free_queues(ha);
3824 }
3825 
3826 void qla2x00_free_fcports(struct scsi_qla_host *vha)
3827 {
3828         fc_port_t *fcport, *tfcport;
3829 
3830         list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list)
3831                 qla2x00_free_fcport(fcport);
3832 }
3833 
3834 static inline void
3835 qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
3836     int defer)
3837 {
3838         struct fc_rport *rport;
3839         scsi_qla_host_t *base_vha;
3840         unsigned long flags;
3841 
3842         if (!fcport->rport)
3843                 return;
3844 
3845         rport = fcport->rport;
3846         if (defer) {
3847                 base_vha = pci_get_drvdata(vha->hw->pdev);
3848                 spin_lock_irqsave(vha->host->host_lock, flags);
3849                 fcport->drport = rport;
3850                 spin_unlock_irqrestore(vha->host->host_lock, flags);
3851                 qlt_do_generation_tick(vha, &base_vha->total_fcport_update_gen);
3852                 set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
3853                 qla2xxx_wake_dpc(base_vha);
3854         } else {
3855                 int now;
3856 
3857                 if (rport) {
3858                         ql_dbg(ql_dbg_disc, fcport->vha, 0x2109,
3859                             "%s %8phN. rport %p roles %x\n",
3860                             __func__, fcport->port_name, rport,
3861                             rport->roles);
3862                         fc_remote_port_delete(rport);
3863                 }
3864                 qlt_do_generation_tick(vha, &now);
3865         }
3866 }
3867 
3868 /*
3869  * qla2x00_mark_device_lost Updates fcport state when device goes offline.
3870  *
3871  * Input: ha = adapter block pointer.  fcport = port structure pointer.
3872  *
3873  * Return: None.
3874  *
3875  * Context:
3876  */
3877 void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
3878     int do_login, int defer)
3879 {
3880         if (IS_QLAFX00(vha->hw)) {
3881                 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
3882                 qla2x00_schedule_rport_del(vha, fcport, defer);
3883                 return;
3884         }
3885 
3886         if (atomic_read(&fcport->state) == FCS_ONLINE &&
3887             vha->vp_idx == fcport->vha->vp_idx) {
3888                 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
3889                 qla2x00_schedule_rport_del(vha, fcport, defer);
3890         }
3891         /*
3892          * We may need to retry the login, so don't change the state of the
3893          * port but do the retries.
3894          */
3895         if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
3896                 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
3897 
3898         if (!do_login)
3899                 return;
3900 
3901         set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
3902 }
3903 
3904 /*
3905  * qla2x00_mark_all_devices_lost
3906  *      Updates fcport state when device goes offline.
3907  *
3908  * Input:
3909  *      ha = adapter block pointer.
3910  *      fcport = port structure pointer.
3911  *
3912  * Return:
3913  *      None.
3914  *
3915  * Context:
3916  */
3917 void
3918 qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
3919 {
3920         fc_port_t *fcport;
3921 
3922         ql_dbg(ql_dbg_disc, vha, 0x20f1,
3923             "Mark all dev lost\n");
3924 
3925         list_for_each_entry(fcport, &vha->vp_fcports, list) {
3926                 fcport->scan_state = 0;
3927                 qlt_schedule_sess_for_deletion(fcport);
3928 
3929                 if (vha->vp_idx != 0 && vha->vp_idx != fcport->vha->vp_idx)
3930                         continue;
3931 
3932                 /*
3933                  * No point in marking the device as lost, if the device is
3934                  * already DEAD.
3935                  */
3936                 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
3937                         continue;
3938                 if (atomic_read(&fcport->state) == FCS_ONLINE) {
3939                         qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
3940                         if (defer)
3941                                 qla2x00_schedule_rport_del(vha, fcport, defer);
3942                         else if (vha->vp_idx == fcport->vha->vp_idx)
3943                                 qla2x00_schedule_rport_del(vha, fcport, defer);
3944                 }
3945         }
3946 }
3947 
3948 static void qla2x00_set_reserved_loop_ids(struct qla_hw_data *ha)
3949 {
3950         int i;
3951 
3952         if (IS_FWI2_CAPABLE(ha))
3953                 return;
3954 
3955         for (i = 0; i < SNS_FIRST_LOOP_ID; i++)
3956                 set_bit(i, ha->loop_id_map);
3957         set_bit(MANAGEMENT_SERVER, ha->loop_id_map);
3958         set_bit(BROADCAST, ha->loop_id_map);
3959 }
3960 
3961 /*
3962 * qla2x00_mem_alloc
3963 *      Allocates adapter memory.
3964 *
3965 * Returns:
3966 *      0  = success.
3967 *      !0  = failure.
3968 */
3969 static int
3970 qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
3971         struct req_que **req, struct rsp_que **rsp)
3972 {
3973         char    name[16];
3974 
3975         ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
3976                 &ha->init_cb_dma, GFP_KERNEL);
3977         if (!ha->init_cb)
3978                 goto fail;
3979 
3980         if (qlt_mem_alloc(ha) < 0)
3981                 goto fail_free_init_cb;
3982 
3983         ha->gid_list = dma_alloc_coherent(&ha->pdev->dev,
3984                 qla2x00_gid_list_size(ha), &ha->gid_list_dma, GFP_KERNEL);
3985         if (!ha->gid_list)
3986                 goto fail_free_tgt_mem;
3987 
3988         ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
3989         if (!ha->srb_mempool)
3990                 goto fail_free_gid_list;
3991 
3992         if (IS_P3P_TYPE(ha)) {
3993                 /* Allocate cache for CT6 Ctx. */
3994                 if (!ctx_cachep) {
3995                         ctx_cachep = kmem_cache_create("qla2xxx_ctx",
3996                                 sizeof(struct ct6_dsd), 0,
3997                                 SLAB_HWCACHE_ALIGN, NULL);
3998                         if (!ctx_cachep)
3999                                 goto fail_free_srb_mempool;
4000                 }
4001                 ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ,
4002                         ctx_cachep);
4003                 if (!ha->ctx_mempool)
4004                         goto fail_free_srb_mempool;
4005                 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0021,
4006                     "ctx_cachep=%p ctx_mempool=%p.\n",
4007                     ctx_cachep, ha->ctx_mempool);
4008         }
4009 
4010         /* Get memory for cached NVRAM */
4011         ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
4012         if (!ha->nvram)
4013                 goto fail_free_ctx_mempool;
4014 
4015         snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
4016                 ha->pdev->device);
4017         ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
4018                 DMA_POOL_SIZE, 8, 0);
4019         if (!ha->s_dma_pool)
4020                 goto fail_free_nvram;
4021 
4022         ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0022,
4023             "init_cb=%p gid_list=%p, srb_mempool=%p s_dma_pool=%p.\n",
4024             ha->init_cb, ha->gid_list, ha->srb_mempool, ha->s_dma_pool);
4025 
4026         if (IS_P3P_TYPE(ha) || ql2xenabledif) {
4027                 ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev,
4028                         DSD_LIST_DMA_POOL_SIZE, 8, 0);
4029                 if (!ha->dl_dma_pool) {
4030                         ql_log_pci(ql_log_fatal, ha->pdev, 0x0023,
4031                             "Failed to allocate memory for dl_dma_pool.\n");
4032                         goto fail_s_dma_pool;
4033                 }
4034 
4035                 ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev,
4036                         FCP_CMND_DMA_POOL_SIZE, 8, 0);
4037                 if (!ha->fcp_cmnd_dma_pool) {
4038                         ql_log_pci(ql_log_fatal, ha->pdev, 0x0024,
4039                             "Failed to allocate memory for fcp_cmnd_dma_pool.\n");
4040                         goto fail_dl_dma_pool;
4041                 }
4042 
4043                 if (ql2xenabledif) {
4044                         u64 bufsize = DIF_BUNDLING_DMA_POOL_SIZE;
4045                         struct dsd_dma *dsd, *nxt;
4046                         uint i;
4047                         /* Creata a DMA pool of buffers for DIF bundling */
4048                         ha->dif_bundl_pool = dma_pool_create(name,
4049                             &ha->pdev->dev, DIF_BUNDLING_DMA_POOL_SIZE, 8, 0);
4050                         if (!ha->dif_bundl_pool) {
4051                                 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0024,
4052                                     "%s: failed create dif_bundl_pool\n",
4053                                     __func__);
4054                                 goto fail_dif_bundl_dma_pool;
4055                         }
4056 
4057                         INIT_LIST_HEAD(&ha->pool.good.head);
4058                         INIT_LIST_HEAD(&ha->pool.unusable.head);
4059                         ha->pool.good.count = 0;
4060                         ha->pool.unusable.count = 0;
4061                         for (i = 0; i < 128; i++) {
4062                                 dsd = kzalloc(sizeof(*dsd), GFP_ATOMIC);
4063                                 if (!dsd) {
4064                                         ql_dbg_pci(ql_dbg_init, ha->pdev,
4065                                             0xe0ee, "%s: failed alloc dsd\n",
4066                                             __func__);
4067                                         return 1;
4068                                 }
4069                                 ha->dif_bundle_kallocs++;
4070 
4071                                 dsd->dsd_addr = dma_pool_alloc(
4072                                     ha->dif_bundl_pool, GFP_ATOMIC,
4073                                     &dsd->dsd_list_dma);
4074                                 if (!dsd->dsd_addr) {
4075                                         ql_dbg_pci(ql_dbg_init, ha->pdev,
4076                                             0xe0ee,
4077                                             "%s: failed alloc ->dsd_addr\n",
4078                                             __func__);
4079                                         kfree(dsd);
4080                                         ha->dif_bundle_kallocs--;
4081                                         continue;
4082                                 }
4083                                 ha->dif_bundle_dma_allocs++;
4084 
4085                                 /*
4086                                  * if DMA buffer crosses 4G boundary,
4087                                  * put it on bad list
4088                                  */
4089                                 if (MSD(dsd->dsd_list_dma) ^
4090                                     MSD(dsd->dsd_list_dma + bufsize)) {
4091                                         list_add_tail(&dsd->list,
4092                                             &ha->pool.unusable.head);
4093                                         ha->pool.unusable.count++;
4094                                 } else {
4095                                         list_add_tail(&dsd->list,
4096                                             &ha->pool.good.head);
4097                                         ha->pool.good.count++;
4098                                 }
4099                         }
4100 
4101                         /* return the good ones back to the pool */
4102                         list_for_each_entry_safe(dsd, nxt,
4103                             &ha->pool.good.head, list) {
4104                                 list_del(&dsd->list);
4105                                 dma_pool_free(ha->dif_bundl_pool,
4106                                     dsd->dsd_addr, dsd->dsd_list_dma);
4107                                 ha->dif_bundle_dma_allocs--;
4108                                 kfree(dsd);
4109                                 ha->dif_bundle_kallocs--;
4110                         }
4111 
4112                         ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0024,
4113                             "%s: dif dma pool (good=%u unusable=%u)\n",
4114                             __func__, ha->pool.good.count,
4115                             ha->pool.unusable.count);
4116                 }
4117 
4118                 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0025,
4119                     "dl_dma_pool=%p fcp_cmnd_dma_pool=%p dif_bundl_pool=%p.\n",
4120                     ha->dl_dma_pool, ha->fcp_cmnd_dma_pool,
4121                     ha->dif_bundl_pool);
4122         }
4123 
4124         /* Allocate memory for SNS commands */
4125         if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
4126         /* Get consistent memory allocated for SNS commands */
4127                 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
4128                 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
4129                 if (!ha->sns_cmd)
4130                         goto fail_dma_pool;
4131                 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0026,
4132                     "sns_cmd: %p.\n", ha->sns_cmd);
4133         } else {
4134         /* Get consistent memory allocated for MS IOCB */
4135                 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
4136                         &ha->ms_iocb_dma);
4137                 if (!ha->ms_iocb)
4138                         goto fail_dma_pool;
4139         /* Get consistent memory allocated for CT SNS commands */
4140                 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
4141                         sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
4142                 if (!ha->ct_sns)
4143                         goto fail_free_ms_iocb;
4144                 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0027,
4145                     "ms_iocb=%p ct_sns=%p.\n",
4146                     ha->ms_iocb, ha->ct_sns);
4147         }
4148 
4149         /* Allocate memory for request ring */
4150         *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
4151         if (!*req) {
4152                 ql_log_pci(ql_log_fatal, ha->pdev, 0x0028,
4153                     "Failed to allocate memory for req.\n");
4154                 goto fail_req;
4155         }
4156         (*req)->length = req_len;
4157         (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
4158                 ((*req)->length + 1) * sizeof(request_t),
4159                 &(*req)->dma, GFP_KERNEL);
4160         if (!(*req)->ring) {
4161                 ql_log_pci(ql_log_fatal, ha->pdev, 0x0029,
4162                     "Failed to allocate memory for req_ring.\n");
4163                 goto fail_req_ring;
4164         }
4165         /* Allocate memory for response ring */
4166         *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
4167         if (!*rsp) {
4168                 ql_log_pci(ql_log_fatal, ha->pdev, 0x002a,
4169                     "Failed to allocate memory for rsp.\n");
4170                 goto fail_rsp;
4171         }
4172         (*rsp)->hw = ha;
4173         (*rsp)->length = rsp_len;
4174         (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
4175                 ((*rsp)->length + 1) * sizeof(response_t),
4176                 &(*rsp)->dma, GFP_KERNEL);
4177         if (!(*rsp)->ring) {
4178                 ql_log_pci(ql_log_fatal, ha->pdev, 0x002b,
4179                     "Failed to allocate memory for rsp_ring.\n");
4180                 goto fail_rsp_ring;
4181         }
4182         (*req)->rsp = *rsp;
4183         (*rsp)->req = *req;
4184         ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002c,
4185             "req=%p req->length=%d req->ring=%p rsp=%p "
4186             "rsp->length=%d rsp->ring=%p.\n",
4187             *req, (*req)->length, (*req)->ring, *rsp, (*rsp)->length,
4188             (*rsp)->ring);
4189         /* Allocate memory for NVRAM data for vports */
4190         if (ha->nvram_npiv_size) {
4191                 ha->npiv_info = kcalloc(ha->nvram_npiv_size,
4192                                         sizeof(struct qla_npiv_entry),
4193                                         GFP_KERNEL);
4194                 if (!ha->npiv_info) {
4195                         ql_log_pci(ql_log_fatal, ha->pdev, 0x002d,
4196                             "Failed to allocate memory for npiv_info.\n");
4197                         goto fail_npiv_info;
4198                 }
4199         } else
4200                 ha->npiv_info = NULL;
4201 
4202         /* Get consistent memory allocated for EX-INIT-CB. */
4203         if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha) ||
4204             IS_QLA28XX(ha)) {
4205                 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
4206                     &ha->ex_init_cb_dma);
4207                 if (!ha->ex_init_cb)
4208                         goto fail_ex_init_cb;
4209                 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002e,
4210                     "ex_init_cb=%p.\n", ha->ex_init_cb);
4211         }
4212 
4213         INIT_LIST_HEAD(&ha->gbl_dsd_list);
4214 
4215         /* Get consistent memory allocated for Async Port-Database. */
4216         if (!IS_FWI2_CAPABLE(ha)) {
4217                 ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
4218                         &ha->async_pd_dma);
4219                 if (!ha->async_pd)
4220                         goto fail_async_pd;
4221                 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002f,
4222                     "async_pd=%p.\n", ha->async_pd);
4223         }
4224 
4225         INIT_LIST_HEAD(&ha->vp_list);
4226 
4227         /* Allocate memory for our loop_id bitmap */
4228         ha->loop_id_map = kcalloc(BITS_TO_LONGS(LOOPID_MAP_SIZE),
4229                                   sizeof(long),
4230                                   GFP_KERNEL);
4231         if (!ha->loop_id_map)
4232                 goto fail_loop_id_map;
4233         else {
4234                 qla2x00_set_reserved_loop_ids(ha);
4235                 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0123,
4236                     "loop_id_map=%p.\n", ha->loop_id_map);
4237         }
4238 
4239         ha->sfp_data = dma_alloc_coherent(&ha->pdev->dev,
4240             SFP_DEV_SIZE, &ha->sfp_data_dma, GFP_KERNEL);
4241         if (!ha->sfp_data) {
4242                 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
4243                     "Unable to allocate memory for SFP read-data.\n");
4244                 goto fail_sfp_data;
4245         }
4246 
4247         ha->flt = dma_alloc_coherent(&ha->pdev->dev,
4248             sizeof(struct qla_flt_header) + FLT_REGIONS_SIZE, &ha->flt_dma,
4249             GFP_KERNEL);
4250         if (!ha->flt) {
4251                 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
4252                     "Unable to allocate memory for FLT.\n");
4253                 goto fail_flt_buffer;
4254         }
4255 
4256         return 0;
4257 
4258 fail_flt_buffer:
4259         dma_free_coherent(&ha->pdev->dev, SFP_DEV_SIZE,
4260             ha->sfp_data, ha->sfp_data_dma);
4261 fail_sfp_data:
4262         kfree(ha->loop_id_map);
4263 fail_loop_id_map:
4264         dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
4265 fail_async_pd:
4266         dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
4267 fail_ex_init_cb:
4268         kfree(ha->npiv_info);
4269 fail_npiv_info:
4270         dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
4271                 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
4272         (*rsp)->ring = NULL;
4273         (*rsp)->dma = 0;
4274 fail_rsp_ring:
4275         kfree(*rsp);
4276         *rsp = NULL;
4277 fail_rsp:
4278         dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
4279                 sizeof(request_t), (*req)->ring, (*req)->dma);
4280         (*req)->ring = NULL;
4281         (*req)->dma = 0;
4282 fail_req_ring:
4283         kfree(*req);
4284         *req = NULL;
4285 fail_req:
4286         dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
4287                 ha->ct_sns, ha->ct_sns_dma);
4288         ha->ct_sns = NULL;
4289         ha->ct_sns_dma = 0;
4290 fail_free_ms_iocb:
4291         dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
4292         ha->ms_iocb = NULL;
4293         ha->ms_iocb_dma = 0;
4294 
4295         if (ha->sns_cmd)
4296                 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
4297                     ha->sns_cmd, ha->sns_cmd_dma);
4298 fail_dma_pool:
4299         if (ql2xenabledif) {
4300                 struct dsd_dma *dsd, *nxt;
4301 
4302                 list_for_each_entry_safe(dsd, nxt, &ha->pool.unusable.head,
4303                     list) {
4304                         list_del(&dsd->list);
4305                         dma_pool_free(ha->dif_bundl_pool, dsd->dsd_addr,
4306                             dsd->dsd_list_dma);
4307                         ha->dif_bundle_dma_allocs--;
4308                         kfree(dsd);
4309                         ha->dif_bundle_kallocs--;
4310                         ha->pool.unusable.count--;
4311                 }
4312                 dma_pool_destroy(ha->dif_bundl_pool);
4313                 ha->dif_bundl_pool = NULL;
4314         }
4315 
4316 fail_dif_bundl_dma_pool:
4317         if (IS_QLA82XX(ha) || ql2xenabledif) {
4318                 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
4319                 ha->fcp_cmnd_dma_pool = NULL;
4320         }
4321 fail_dl_dma_pool:
4322         if (IS_QLA82XX(ha) || ql2xenabledif) {
4323                 dma_pool_destroy(ha->dl_dma_pool);
4324                 ha->dl_dma_pool = NULL;
4325         }
4326 fail_s_dma_pool:
4327         dma_pool_destroy(ha->s_dma_pool);
4328         ha->s_dma_pool = NULL;
4329 fail_free_nvram:
4330         kfree(ha->nvram);
4331         ha->nvram = NULL;
4332 fail_free_ctx_mempool:
4333         mempool_destroy(ha->ctx_mempool);
4334         ha->ctx_mempool = NULL;
4335 fail_free_srb_mempool:
4336         mempool_destroy(ha->srb_mempool);
4337         ha->srb_mempool = NULL;
4338 fail_free_gid_list:
4339         dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
4340         ha->gid_list,
4341         ha->gid_list_dma);
4342         ha->gid_list = NULL;
4343         ha->gid_list_dma = 0;
4344 fail_free_tgt_mem:
4345         qlt_mem_free(ha);
4346 fail_free_init_cb:
4347         dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
4348         ha->init_cb_dma);
4349         ha->init_cb = NULL;
4350         ha->init_cb_dma = 0;
4351 fail:
4352         ql_log(ql_log_fatal, NULL, 0x0030,
4353             "Memory allocation failure.\n");
4354         return -ENOMEM;
4355 }
4356 
4357 int
4358 qla2x00_set_exlogins_buffer(scsi_qla_host_t *vha)
4359 {
4360         int rval;
4361         uint16_t        size, max_cnt, temp;
4362         struct qla_hw_data *ha = vha->hw;
4363 
4364         /* Return if we don't need to alloacate any extended logins */
4365         if (!ql2xexlogins)
4366                 return QLA_SUCCESS;
4367 
4368         if (!IS_EXLOGIN_OFFLD_CAPABLE(ha))
4369                 return QLA_SUCCESS;
4370 
4371         ql_log(ql_log_info, vha, 0xd021, "EXLOGIN count: %d.\n", ql2xexlogins);
4372         max_cnt = 0;
4373         rval = qla_get_exlogin_status(vha, &size, &max_cnt);
4374         if (rval != QLA_SUCCESS) {
4375                 ql_log_pci(ql_log_fatal, ha->pdev, 0xd029,
4376                     "Failed to get exlogin status.\n");
4377                 return rval;
4378         }
4379 
4380         temp = (ql2xexlogins > max_cnt) ? max_cnt : ql2xexlogins;
4381         temp *= size;
4382 
4383         if (temp != ha->exlogin_size) {
4384                 qla2x00_free_exlogin_buffer(ha);
4385                 ha->exlogin_size = temp;
4386 
4387                 ql_log(ql_log_info, vha, 0xd024,
4388                     "EXLOGIN: max_logins=%d, portdb=0x%x, total=%d.\n",
4389                     max_cnt, size, temp);
4390 
4391                 ql_log(ql_log_info, vha, 0xd025,
4392                     "EXLOGIN: requested size=0x%x\n", ha->exlogin_size);
4393 
4394                 /* Get consistent memory for extended logins */
4395                 ha->exlogin_buf = dma_alloc_coherent(&ha->pdev->dev,
4396                         ha->exlogin_size, &ha->exlogin_buf_dma, GFP_KERNEL);
4397                 if (!ha->exlogin_buf) {
4398                         ql_log_pci(ql_log_fatal, ha->pdev, 0xd02a,
4399                     "Failed to allocate memory for exlogin_buf_dma.\n");
4400                         return -ENOMEM;
4401                 }
4402         }
4403 
4404         /* Now configure the dma buffer */
4405         rval = qla_set_exlogin_mem_cfg(vha, ha->exlogin_buf_dma);
4406         if (rval) {
4407                 ql_log(ql_log_fatal, vha, 0xd033,
4408                     "Setup extended login buffer  ****FAILED****.\n");
4409                 qla2x00_free_exlogin_buffer(ha);
4410         }
4411 
4412         return rval;
4413 }
4414 
4415 /*
4416 * qla2x00_free_exlogin_buffer
4417 *
4418 * Input:
4419 *       ha = adapter block pointer
4420 */
4421 void
4422 qla2x00_free_exlogin_buffer(struct qla_hw_data *ha)
4423 {
4424         if (ha->exlogin_buf) {
4425                 dma_free_coherent(&ha->pdev->dev, ha->exlogin_size,
4426                     ha->exlogin_buf, ha->exlogin_buf_dma);
4427                 ha->exlogin_buf = NULL;
4428                 ha->exlogin_size = 0;
4429         }
4430 }
4431 
4432 static void
4433 qla2x00_number_of_exch(scsi_qla_host_t *vha, u32 *ret_cnt, u16 max_cnt)
4434 {
4435         u32 temp;
4436         struct init_cb_81xx *icb = (struct init_cb_81xx *)&vha->hw->init_cb;
4437         *ret_cnt = FW_DEF_EXCHANGES_CNT;
4438 
4439         if (max_cnt > vha->hw->max_exchg)
4440                 max_cnt = vha->hw->max_exchg;
4441 
4442         if (qla_ini_mode_enabled(vha)) {
4443                 if (vha->ql2xiniexchg > max_cnt)
4444                         vha->ql2xiniexchg = max_cnt;
4445 
4446                 if (vha->ql2xiniexchg > FW_DEF_EXCHANGES_CNT)
4447                         *ret_cnt = vha->ql2xiniexchg;
4448 
4449         } else if (qla_tgt_mode_enabled(vha)) {
4450                 if (vha->ql2xexchoffld > max_cnt) {
4451                         vha->ql2xexchoffld = max_cnt;
4452                         icb->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
4453                 }
4454 
4455                 if (vha->ql2xexchoffld > FW_DEF_EXCHANGES_CNT)
4456                         *ret_cnt = vha->ql2xexchoffld;
4457         } else if (qla_dual_mode_enabled(vha)) {
4458                 temp = vha->ql2xiniexchg + vha->ql2xexchoffld;
4459                 if (temp > max_cnt) {
4460                         vha->ql2xiniexchg -= (temp - max_cnt)/2;
4461                         vha->ql2xexchoffld -= (((temp - max_cnt)/2) + 1);
4462                         temp = max_cnt;
4463                         icb->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
4464                 }
4465 
4466                 if (temp > FW_DEF_EXCHANGES_CNT)
4467                         *ret_cnt = temp;
4468         }
4469 }
4470 
4471 int
4472 qla2x00_set_exchoffld_buffer(scsi_qla_host_t *vha)
4473 {
4474         int rval;
4475         u16     size, max_cnt;
4476         u32 actual_cnt, totsz;
4477         struct qla_hw_data *ha = vha->hw;
4478 
4479         if (!ha->flags.exchoffld_enabled)
4480                 return QLA_SUCCESS;
4481 
4482         if (!IS_EXCHG_OFFLD_CAPABLE(ha))
4483                 return QLA_SUCCESS;
4484 
4485         max_cnt = 0;
4486         rval = qla_get_exchoffld_status(vha, &size, &max_cnt);
4487         if (rval != QLA_SUCCESS) {
4488                 ql_log_pci(ql_log_fatal, ha->pdev, 0xd012,
4489                     "Failed to get exlogin status.\n");
4490                 return rval;
4491         }
4492 
4493         qla2x00_number_of_exch(vha, &actual_cnt, max_cnt);
4494         ql_log(ql_log_info, vha, 0xd014,
4495             "Actual exchange offload count: %d.\n", actual_cnt);
4496 
4497         totsz = actual_cnt * size;
4498 
4499         if (totsz != ha->exchoffld_size) {
4500                 qla2x00_free_exchoffld_buffer(ha);
4501                 if (actual_cnt <= FW_DEF_EXCHANGES_CNT) {
4502                         ha->exchoffld_size = 0;
4503                         ha->flags.exchoffld_enabled = 0;
4504                         return QLA_SUCCESS;
4505                 }
4506 
4507                 ha->exchoffld_size = totsz;
4508 
4509                 ql_log(ql_log_info, vha, 0xd016,
4510                     "Exchange offload: max_count=%d, actual count=%d entry sz=0x%x, total sz=0x%x\n",
4511                     max_cnt, actual_cnt, size, totsz);
4512 
4513                 ql_log(ql_log_info, vha, 0xd017,
4514                     "Exchange Buffers requested size = 0x%x\n",
4515                     ha->exchoffld_size);
4516 
4517                 /* Get consistent memory for extended logins */
4518                 ha->exchoffld_buf = dma_alloc_coherent(&ha->pdev->dev,
4519                         ha->exchoffld_size, &ha->exchoffld_buf_dma, GFP_KERNEL);
4520                 if (!ha->exchoffld_buf) {
4521                         ql_log_pci(ql_log_fatal, ha->pdev, 0xd013,
4522                         "Failed to allocate memory for Exchange Offload.\n");
4523 
4524                         if (ha->max_exchg >
4525                             (FW_DEF_EXCHANGES_CNT + REDUCE_EXCHANGES_CNT)) {
4526                                 ha->max_exchg -= REDUCE_EXCHANGES_CNT;
4527                         } else if (ha->max_exchg >
4528                             (FW_DEF_EXCHANGES_CNT + 512)) {
4529                                 ha->max_exchg -= 512;
4530                         } else {
4531                                 ha->flags.exchoffld_enabled = 0;
4532                                 ql_log_pci(ql_log_fatal, ha->pdev, 0xd013,
4533                                     "Disabling Exchange offload due to lack of memory\n");
4534                         }
4535                         ha->exchoffld_size = 0;
4536 
4537                         return -ENOMEM;
4538                 }
4539         } else if (!ha->exchoffld_buf || (actual_cnt <= FW_DEF_EXCHANGES_CNT)) {
4540                 /* pathological case */
4541                 qla2x00_free_exchoffld_buffer(ha);
4542                 ha->exchoffld_size = 0;
4543                 ha->flags.exchoffld_enabled = 0;
4544                 ql_log(ql_log_info, vha, 0xd016,
4545                     "Exchange offload not enable: offld size=%d, actual count=%d entry sz=0x%x, total sz=0x%x.\n",
4546                     ha->exchoffld_size, actual_cnt, size, totsz);
4547                 return 0;
4548         }
4549 
4550         /* Now configure the dma buffer */
4551         rval = qla_set_exchoffld_mem_cfg(vha);
4552         if (rval) {
4553                 ql_log(ql_log_fatal, vha, 0xd02e,
4554                     "Setup exchange offload buffer ****FAILED****.\n");
4555                 qla2x00_free_exchoffld_buffer(ha);
4556         } else {
4557                 /* re-adjust number of target exchange */
4558                 struct init_cb_81xx *icb = (struct init_cb_81xx *)ha->init_cb;
4559 
4560                 if (qla_ini_mode_enabled(vha))
4561                         icb->exchange_count = 0;
4562                 else
4563                         icb->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
4564         }
4565 
4566         return rval;
4567 }
4568 
4569 /*
4570 * qla2x00_free_exchoffld_buffer
4571 *
4572 * Input:
4573 *       ha = adapter block pointer
4574 */
4575 void
4576 qla2x00_free_exchoffld_buffer(struct qla_hw_data *ha)
4577 {
4578         if (ha->exchoffld_buf) {
4579                 dma_free_coherent(&ha->pdev->dev, ha->exchoffld_size,
4580                     ha->exchoffld_buf, ha->exchoffld_buf_dma);
4581                 ha->exchoffld_buf = NULL;
4582                 ha->exchoffld_size = 0;
4583         }
4584 }
4585 
4586 /*
4587 * qla2x00_free_fw_dump
4588 *       Frees fw dump stuff.
4589 *
4590 * Input:
4591 *       ha = adapter block pointer
4592 */
4593 static void
4594 qla2x00_free_fw_dump(struct qla_hw_data *ha)
4595 {
4596         struct fwdt *fwdt = ha->fwdt;
4597         uint j;
4598 
4599         if (ha->fce)
4600                 dma_free_coherent(&ha->pdev->dev,
4601                     FCE_SIZE, ha->fce, ha->fce_dma);
4602 
4603         if (ha->eft)
4604                 dma_free_coherent(&ha->pdev->dev,
4605                     EFT_SIZE, ha->eft, ha->eft_dma);
4606 
4607         if (ha->fw_dump)
4608                 vfree(ha->fw_dump);
4609 
4610         ha->fce = NULL;
4611         ha->fce_dma = 0;
4612         ha->flags.fce_enabled = 0;
4613         ha->eft = NULL;
4614         ha->eft_dma = 0;
4615         ha->fw_dumped = 0;
4616         ha->fw_dump_cap_flags = 0;
4617         ha->fw_dump_reading = 0;
4618         ha->fw_dump = NULL;
4619         ha->fw_dump_len = 0;
4620 
4621         for (j = 0; j < 2; j++, fwdt++) {
4622                 if (fwdt->template)
4623                         vfree(fwdt->template);
4624                 fwdt->template = NULL;
4625                 fwdt->length = 0;
4626         }
4627 }
4628 
4629 /*
4630 * qla2x00_mem_free
4631 *      Frees all adapter allocated memory.
4632 *
4633 * Input:
4634 *      ha = adapter block pointer.
4635 */
4636 static void
4637 qla2x00_mem_free(struct qla_hw_data *ha)
4638 {
4639         qla2x00_free_fw_dump(ha);
4640 
4641         if (ha->mctp_dump)
4642                 dma_free_coherent(&ha->pdev->dev, MCTP_DUMP_SIZE, ha->mctp_dump,
4643                     ha->mctp_dump_dma);
4644         ha->mctp_dump = NULL;
4645 
4646         mempool_destroy(ha->srb_mempool);
4647         ha->srb_mempool = NULL;
4648 
4649         if (ha->dcbx_tlv)
4650                 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
4651                     ha->dcbx_tlv, ha->dcbx_tlv_dma);
4652         ha->dcbx_tlv = NULL;
4653 
4654         if (ha->xgmac_data)
4655                 dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
4656                     ha->xgmac_data, ha->xgmac_data_dma);
4657         ha->xgmac_data = NULL;
4658 
4659         if (ha->sns_cmd)
4660                 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
4661                 ha->sns_cmd, ha->sns_cmd_dma);
4662         ha->sns_cmd = NULL;
4663         ha->sns_cmd_dma = 0;
4664 
4665         if (ha->ct_sns)
4666                 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
4667                 ha->ct_sns, ha->ct_sns_dma);
4668         ha->ct_sns = NULL;
4669         ha->ct_sns_dma = 0;
4670 
4671         if (ha->sfp_data)
4672                 dma_free_coherent(&ha->pdev->dev, SFP_DEV_SIZE, ha->sfp_data,
4673                     ha->sfp_data_dma);
4674         ha->sfp_data = NULL;
4675 
4676         if (ha->flt)
4677                 dma_free_coherent(&ha->pdev->dev,
4678                     sizeof(struct qla_flt_header) + FLT_REGIONS_SIZE,
4679                     ha->flt, ha->flt_dma);
4680         ha->flt = NULL;
4681         ha->flt_dma = 0;
4682 
4683         if (ha->ms_iocb)
4684                 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
4685         ha->ms_iocb = NULL;
4686         ha->ms_iocb_dma = 0;
4687 
4688         if (ha->ex_init_cb)
4689                 dma_pool_free(ha->s_dma_pool,
4690                         ha->ex_init_cb, ha->ex_init_cb_dma);
4691         ha->ex_init_cb = NULL;
4692         ha->ex_init_cb_dma = 0;
4693 
4694         if (ha->async_pd)
4695                 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
4696         ha->async_pd = NULL;
4697         ha->async_pd_dma = 0;
4698 
4699         dma_pool_destroy(ha->s_dma_pool);
4700         ha->s_dma_pool = NULL;
4701 
4702         if (ha->gid_list)
4703                 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
4704                 ha->gid_list, ha->gid_list_dma);
4705         ha->gid_list = NULL;
4706         ha->gid_list_dma = 0;
4707 
4708         if (IS_QLA82XX(ha)) {
4709                 if (!list_empty(&ha->gbl_dsd_list)) {
4710                         struct dsd_dma *dsd_ptr, *tdsd_ptr;
4711 
4712                         /* clean up allocated prev pool */
4713                         list_for_each_entry_safe(dsd_ptr,
4714                                 tdsd_ptr, &ha->gbl_dsd_list, list) {
4715                                 dma_pool_free(ha->dl_dma_pool,
4716                                 dsd_ptr->dsd_addr, dsd_ptr->dsd_list_dma);
4717                                 list_del(&dsd_ptr->list);
4718                                 kfree(dsd_ptr);
4719                         }
4720                 }
4721         }
4722 
4723         dma_pool_destroy(ha->dl_dma_pool);
4724         ha->dl_dma_pool = NULL;
4725 
4726         dma_pool_destroy(ha->fcp_cmnd_dma_pool);
4727         ha->fcp_cmnd_dma_pool = NULL;
4728 
4729         mempool_destroy(ha->ctx_mempool);
4730         ha->ctx_mempool = NULL;
4731 
4732         if (ql2xenabledif && ha->dif_bundl_pool) {
4733                 struct dsd_dma *dsd, *nxt;
4734 
4735                 list_for_each_entry_safe(dsd, nxt, &ha->pool.unusable.head,
4736                                          list) {
4737                         list_del(&dsd->list);
4738                         dma_pool_free(ha->dif_bundl_pool, dsd->dsd_addr,
4739                                       dsd->dsd_list_dma);
4740                         ha->dif_bundle_dma_allocs--;
4741                         kfree(dsd);
4742                         ha->dif_bundle_kallocs--;
4743                         ha->pool.unusable.count--;
4744                 }
4745                 list_for_each_entry_safe(dsd, nxt, &ha->pool.good.head, list) {
4746                         list_del(&dsd->list);
4747                         dma_pool_free(ha->dif_bundl_pool, dsd->dsd_addr,
4748                                       dsd->dsd_list_dma);
4749                         ha->dif_bundle_dma_allocs--;
4750                         kfree(dsd);
4751                         ha->dif_bundle_kallocs--;
4752                 }
4753         }
4754 
4755         dma_pool_destroy(ha->dif_bundl_pool);
4756         ha->dif_bundl_pool = NULL;
4757 
4758         qlt_mem_free(ha);
4759 
4760         if (ha->init_cb)
4761                 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
4762                         ha->init_cb, ha->init_cb_dma);
4763         ha->init_cb = NULL;
4764         ha->init_cb_dma = 0;
4765 
4766         vfree(ha->optrom_buffer);
4767         ha->optrom_buffer = NULL;
4768         kfree(ha->nvram);
4769         ha->nvram = NULL;
4770         kfree(ha->npiv_info);
4771         ha->npiv_info = NULL;
4772         kfree(ha->swl);
4773         ha->swl = NULL;
4774         kfree(ha->loop_id_map);
4775         ha->loop_id_map = NULL;
4776 }
4777 
4778 struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
4779                                                 struct qla_hw_data *ha)
4780 {
4781         struct Scsi_Host *host;
4782         struct scsi_qla_host *vha = NULL;
4783 
4784         host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
4785         if (!host) {
4786                 ql_log_pci(ql_log_fatal, ha->pdev, 0x0107,
4787                     "Failed to allocate host from the scsi layer, aborting.\n");
4788                 return NULL;
4789         }
4790 
4791         /* Clear our data area */
4792         vha = shost_priv(host);
4793         memset(vha, 0, sizeof(scsi_qla_host_t));
4794 
4795         vha->host = host;
4796         vha->host_no = host->host_no;
4797         vha->hw = ha;
4798 
4799         vha->qlini_mode = ql2x_ini_mode;
4800         vha->ql2xexchoffld = ql2xexchoffld;
4801         vha->ql2xiniexchg = ql2xiniexchg;
4802 
4803         INIT_LIST_HEAD(&vha->vp_fcports);
4804         INIT_LIST_HEAD(&vha->work_list);
4805         INIT_LIST_HEAD(&vha->list);
4806         INIT_LIST_HEAD(&vha->qla_cmd_list);
4807         INIT_LIST_HEAD(&vha->qla_sess_op_cmd_list);
4808         INIT_LIST_HEAD(&vha->logo_list);
4809         INIT_LIST_HEAD(&vha->plogi_ack_list);
4810         INIT_LIST_HEAD(&vha->qp_list);
4811         INIT_LIST_HEAD(&vha->gnl.fcports);
4812         INIT_LIST_HEAD(&vha->gpnid_list);
4813         INIT_WORK(&vha->iocb_work, qla2x00_iocb_work_fn);
4814 
4815         spin_lock_init(&vha->work_lock);
4816         spin_lock_init(&vha->cmd_list_lock);
4817         init_waitqueue_head(&vha->fcport_waitQ);
4818         init_waitqueue_head(&vha->vref_waitq);
4819 
4820         vha->gnl.size = sizeof(struct get_name_list_extended) *
4821                         (ha->max_loop_id + 1);
4822         vha->gnl.l = dma_alloc_coherent(&ha->pdev->dev,
4823             vha->gnl.size, &vha->gnl.ldma, GFP_KERNEL);
4824         if (!vha->gnl.l) {
4825                 ql_log(ql_log_fatal, vha, 0xd04a,
4826                     "Alloc failed for name list.\n");
4827                 scsi_host_put(vha->host);
4828                 return NULL;
4829         }
4830 
4831         /* todo: what about ext login? */
4832         vha->scan.size = ha->max_fibre_devices * sizeof(struct fab_scan_rp);
4833         vha->scan.l = vmalloc(vha->scan.size);
4834         if (!vha->scan.l) {
4835                 ql_log(ql_log_fatal, vha, 0xd04a,
4836                     "Alloc failed for scan database.\n");
4837                 dma_free_coherent(&ha->pdev->dev, vha->gnl.size,
4838                     vha->gnl.l, vha->gnl.ldma);
4839                 vha->gnl.l = NULL;
4840                 scsi_host_put(vha->host);
4841                 return NULL;
4842         }
4843         INIT_DELAYED_WORK(&vha->scan.scan_work, qla_scan_work_fn);
4844 
4845         sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
4846         ql_dbg(ql_dbg_init, vha, 0x0041,
4847             "Allocated the host=%p hw=%p vha=%p dev_name=%s",
4848             vha->host, vha->hw, vha,
4849             dev_name(&(ha->pdev->dev)));
4850 
4851         return vha;
4852 }
4853 
4854 struct qla_work_evt *
4855 qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
4856 {
4857         struct qla_work_evt *e;
4858         uint8_t bail;
4859 
4860         if (test_bit(UNLOADING, &vha->dpc_flags))
4861                 return NULL;
4862 
4863         QLA_VHA_MARK_BUSY(vha, bail);
4864         if (bail)
4865                 return NULL;
4866 
4867         e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
4868         if (!e) {
4869                 QLA_VHA_MARK_NOT_BUSY(vha);
4870                 return NULL;
4871         }
4872 
4873         INIT_LIST_HEAD(&e->list);
4874         e->type = type;
4875         e->flags = QLA_EVT_FLAG_FREE;
4876         return e;
4877 }
4878 
4879 int
4880 qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
4881 {
4882         unsigned long flags;
4883         bool q = false;
4884 
4885         spin_lock_irqsave(&vha->work_lock, flags);
4886         list_add_tail(&e->list, &vha->work_list);
4887 
4888         if (!test_and_set_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags))
4889                 q = true;
4890 
4891         spin_unlock_irqrestore(&vha->work_lock, flags);
4892 
4893         if (q)
4894                 queue_work(vha->hw->wq, &vha->iocb_work);
4895 
4896         return QLA_SUCCESS;
4897 }
4898 
4899 int
4900 qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
4901     u32 data)
4902 {
4903         struct qla_work_evt *e;
4904 
4905         e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
4906         if (!e)
4907                 return QLA_FUNCTION_FAILED;
4908 
4909         e->u.aen.code = code;
4910         e->u.aen.data = data;
4911         return qla2x00_post_work(vha, e);
4912 }
4913 
4914 int
4915 qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
4916 {
4917         struct qla_work_evt *e;
4918 
4919         e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
4920         if (!e)
4921                 return QLA_FUNCTION_FAILED;
4922 
4923         memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
4924         return qla2x00_post_work(vha, e);
4925 }
4926 
4927 #define qla2x00_post_async_work(name, type)     \
4928 int qla2x00_post_async_##name##_work(           \
4929     struct scsi_qla_host *vha,                  \
4930     fc_port_t *fcport, uint16_t *data)          \
4931 {                                               \
4932         struct qla_work_evt *e;                 \
4933                                                 \
4934         e = qla2x00_alloc_work(vha, type);      \
4935         if (!e)                                 \
4936                 return QLA_FUNCTION_FAILED;     \
4937                                                 \
4938         e->u.logio.fcport = fcport;             \
4939         if (data) {                             \
4940                 e->u.logio.data[0] = data[0];   \
4941                 e->u.logio.data[1] = data[1];   \
4942         }                                       \
4943         fcport->flags |= FCF_ASYNC_ACTIVE;      \
4944         return qla2x00_post_work(vha, e);       \
4945 }
4946 
4947 qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
4948 qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
4949 qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
4950 qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC);
4951 qla2x00_post_async_work(prlo, QLA_EVT_ASYNC_PRLO);
4952 qla2x00_post_async_work(prlo_done, QLA_EVT_ASYNC_PRLO_DONE);
4953 
4954 int
4955 qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
4956 {
4957         struct qla_work_evt *e;
4958 
4959         e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
4960         if (!e)
4961                 return QLA_FUNCTION_FAILED;
4962 
4963         e->u.uevent.code = code;
4964         return qla2x00_post_work(vha, e);
4965 }
4966 
4967 static void
4968 qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
4969 {
4970         char event_string[40];
4971         char *envp[] = { event_string, NULL };
4972 
4973         switch (code) {
4974         case QLA_UEVENT_CODE_FW_DUMP:
4975                 snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
4976                     vha->host_no);
4977                 break;
4978         default:
4979                 /* do nothing */
4980                 break;
4981         }
4982         kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
4983 }
4984 
4985 int
4986 qlafx00_post_aenfx_work(struct scsi_qla_host *vha,  uint32_t evtcode,
4987                         uint32_t *data, int cnt)
4988 {
4989         struct qla_work_evt *e;
4990 
4991         e = qla2x00_alloc_work(vha, QLA_EVT_AENFX);
4992         if (!e)
4993                 return QLA_FUNCTION_FAILED;
4994 
4995         e->u.aenfx.evtcode = evtcode;
4996         e->u.aenfx.count = cnt;
4997         memcpy(e->u.aenfx.mbx, data, sizeof(*data) * cnt);
4998         return qla2x00_post_work(vha, e);
4999 }
5000 
5001 void qla24xx_sched_upd_fcport(fc_port_t *fcport)
5002 {
5003         unsigned long flags;
5004 
5005         if (IS_SW_RESV_ADDR(fcport->d_id))
5006                 return;
5007 
5008         spin_lock_irqsave(&fcport->vha->work_lock, flags);
5009         if (fcport->disc_state == DSC_UPD_FCPORT) {
5010                 spin_unlock_irqrestore(&fcport->vha->work_lock, flags);
5011                 return;
5012         }
5013         fcport->jiffies_at_registration = jiffies;
5014         fcport->sec_since_registration = 0;
5015         fcport->next_disc_state = DSC_DELETED;
5016         fcport->disc_state = DSC_UPD_FCPORT;
5017         spin_unlock_irqrestore(&fcport->vha->work_lock, flags);
5018 
5019         queue_work(system_unbound_wq, &fcport->reg_work);
5020 }
5021 
5022 static
5023 void qla24xx_create_new_sess(struct scsi_qla_host *vha, struct qla_work_evt *e)
5024 {
5025         unsigned long flags;
5026         fc_port_t *fcport =  NULL, *tfcp;
5027         struct qlt_plogi_ack_t *pla =
5028             (struct qlt_plogi_ack_t *)e->u.new_sess.pla;
5029         uint8_t free_fcport = 0;
5030 
5031         ql_dbg(ql_dbg_disc, vha, 0xffff,
5032             "%s %d %8phC enter\n",
5033             __func__, __LINE__, e->u.new_sess.port_name);
5034 
5035         spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5036         fcport = qla2x00_find_fcport_by_wwpn(vha, e->u.new_sess.port_name, 1);
5037         if (fcport) {
5038                 fcport->d_id = e->u.new_sess.id;
5039                 if (pla) {
5040                         fcport->fw_login_state = DSC_LS_PLOGI_PEND;
5041                         memcpy(fcport->node_name,
5042                             pla->iocb.u.isp24.u.plogi.node_name,
5043                             WWN_SIZE);
5044                         qlt_plogi_ack_link(vha, pla, fcport, QLT_PLOGI_LINK_SAME_WWN);
5045                         /* we took an extra ref_count to prevent PLOGI ACK when
5046                          * fcport/sess has not been created.
5047                          */
5048                         pla->ref_count--;
5049                 }
5050         } else {
5051                 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5052                 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5053                 if (fcport) {
5054                         fcport->d_id = e->u.new_sess.id;
5055                         fcport->flags |= FCF_FABRIC_DEVICE;
5056                         fcport->fw_login_state = DSC_LS_PLOGI_PEND;
5057                         if (e->u.new_sess.fc4_type == FS_FC4TYPE_FCP)
5058                                 fcport->fc4_type = FC4_TYPE_FCP_SCSI;
5059 
5060                         if (e->u.new_sess.fc4_type == FS_FC4TYPE_NVME) {
5061                                 fcport->fc4_type = FC4_TYPE_OTHER;
5062                                 fcport->fc4f_nvme = FC4_TYPE_NVME;
5063                         }
5064 
5065                         memcpy(fcport->port_name, e->u.new_sess.port_name,
5066                             WWN_SIZE);
5067 
5068                         if (e->u.new_sess.fc4_type & FS_FCP_IS_N2N)
5069                                 fcport->n2n_flag = 1;
5070 
5071                 } else {
5072                         ql_dbg(ql_dbg_disc, vha, 0xffff,
5073                                    "%s %8phC mem alloc fail.\n",
5074                                    __func__, e->u.new_sess.port_name);
5075 
5076                         if (pla) {
5077                                 list_del(&pla->list);
5078                                 kmem_cache_free(qla_tgt_plogi_cachep, pla);
5079                         }
5080                         return;
5081                 }
5082 
5083                 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5084                 /* search again to make sure no one else got ahead */
5085                 tfcp = qla2x00_find_fcport_by_wwpn(vha,
5086                     e->u.new_sess.port_name, 1);
5087                 if (tfcp) {
5088                         /* should rarily happen */
5089                         ql_dbg(ql_dbg_disc, vha, 0xffff,
5090                             "%s %8phC found existing fcport b4 add. DS %d LS %d\n",
5091                             __func__, tfcp->port_name, tfcp->disc_state,
5092                             tfcp->fw_login_state);
5093 
5094                         free_fcport = 1;
5095                 } else {
5096                         list_add_tail(&fcport->list, &vha->vp_fcports);
5097 
5098                 }
5099                 if (pla) {
5100                         qlt_plogi_ack_link(vha, pla, fcport,
5101                             QLT_PLOGI_LINK_SAME_WWN);
5102                         pla->ref_count--;
5103                 }
5104         }
5105         spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5106 
5107         if (fcport) {
5108                 fcport->id_changed = 1;
5109                 fcport->scan_state = QLA_FCPORT_FOUND;
5110                 fcport->chip_reset = vha->hw->base_qpair->chip_reset;
5111                 memcpy(fcport->node_name, e->u.new_sess.node_name, WWN_SIZE);
5112 
5113                 if (pla) {
5114                         if (pla->iocb.u.isp24.status_subcode == ELS_PRLI) {
5115                                 u16 wd3_lo;
5116 
5117                                 fcport->fw_login_state = DSC_LS_PRLI_PEND;
5118                                 fcport->local = 0;
5119                                 fcport->loop_id =
5120                                         le16_to_cpu(
5121                                             pla->iocb.u.isp24.nport_handle);
5122                                 fcport->fw_login_state = DSC_LS_PRLI_PEND;
5123                                 wd3_lo =
5124                                     le16_to_cpu(
5125                                         pla->iocb.u.isp24.u.prli.wd3_lo);
5126 
5127                                 if (wd3_lo & BIT_7)
5128                                         fcport->conf_compl_supported = 1;
5129 
5130                                 if ((wd3_lo & BIT_4) == 0)
5131                                         fcport->port_type = FCT_INITIATOR;
5132                                 else
5133                                         fcport->port_type = FCT_TARGET;
5134                         }
5135                         qlt_plogi_ack_unref(vha, pla);
5136                 } else {
5137                         fc_port_t *dfcp = NULL;
5138 
5139                         spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5140                         tfcp = qla2x00_find_fcport_by_nportid(vha,
5141                             &e->u.new_sess.id, 1);
5142                         if (tfcp && (tfcp != fcport)) {
5143                                 /*
5144                                  * We have a conflict fcport with same NportID.
5145                                  */
5146                                 ql_dbg(ql_dbg_disc, vha, 0xffff,
5147                                     "%s %8phC found conflict b4 add. DS %d LS %d\n",
5148                                     __func__, tfcp->port_name, tfcp->disc_state,
5149                                     tfcp->fw_login_state);
5150 
5151                                 switch (tfcp->disc_state) {
5152                                 case DSC_DELETED:
5153                                         break;
5154                                 case DSC_DELETE_PEND:
5155                                         fcport->login_pause = 1;
5156                                         tfcp->conflict = fcport;
5157                                         break;
5158                                 default:
5159                                         fcport->login_pause = 1;
5160                                         tfcp->conflict = fcport;
5161                                         dfcp = tfcp;
5162                                         break;
5163                                 }
5164                         }
5165                         spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5166                         if (dfcp)
5167                                 qlt_schedule_sess_for_deletion(tfcp);
5168 
5169                         if (N2N_TOPO(vha->hw)) {
5170                                 fcport->flags &= ~FCF_FABRIC_DEVICE;
5171                                 fcport->keep_nport_handle = 1;
5172                                 if (vha->flags.nvme_enabled) {
5173                                         fcport->fc4f_nvme = 1;
5174                                         fcport->n2n_flag = 1;
5175                                 }
5176                                 fcport->fw_login_state = 0;
5177                                 /*
5178                                  * wait link init done before sending login
5179                                  */
5180                         } else {
5181                                 qla24xx_fcport_handle_login(vha, fcport);
5182                         }
5183                 }
5184         }
5185 
5186         if (free_fcport) {
5187                 qla2x00_free_fcport(fcport);
5188                 if (pla) {
5189                         list_del(&pla->list);
5190                         kmem_cache_free(qla_tgt_plogi_cachep, pla);
5191                 }
5192         }
5193 }
5194 
5195 static void qla_sp_retry(struct scsi_qla_host *vha, struct qla_work_evt *e)
5196 {
5197         struct srb *sp = e->u.iosb.sp;
5198         int rval;
5199 
5200         rval = qla2x00_start_sp(sp);
5201         if (rval != QLA_SUCCESS) {
5202                 ql_dbg(ql_dbg_disc, vha, 0x2043,
5203                     "%s: %s: Re-issue IOCB failed (%d).\n",
5204                     __func__, sp->name, rval);
5205                 qla24xx_sp_unmap(vha, sp);
5206         }
5207 }
5208 
5209 void
5210 qla2x00_do_work(struct scsi_qla_host *vha)
5211 {
5212         struct qla_work_evt *e, *tmp;
5213         unsigned long flags;
5214         LIST_HEAD(work);
5215         int rc;
5216 
5217         spin_lock_irqsave(&vha->work_lock, flags);
5218         list_splice_init(&vha->work_list, &work);
5219         spin_unlock_irqrestore(&vha->work_lock, flags);
5220 
5221         list_for_each_entry_safe(e, tmp, &work, list) {
5222                 rc = QLA_SUCCESS;
5223                 switch (e->type) {
5224                 case QLA_EVT_AEN:
5225                         fc_host_post_event(vha->host, fc_get_event_number(),
5226                             e->u.aen.code, e->u.aen.data);
5227                         break;
5228                 case QLA_EVT_IDC_ACK:
5229                         qla81xx_idc_ack(vha, e->u.idc_ack.mb);
5230                         break;
5231                 case QLA_EVT_ASYNC_LOGIN:
5232                         qla2x00_async_login(vha, e->u.logio.fcport,
5233                             e->u.logio.data);
5234                         break;
5235                 case QLA_EVT_ASYNC_LOGOUT:
5236                         rc = qla2x00_async_logout(vha, e->u.logio.fcport);
5237                         break;
5238                 case QLA_EVT_ASYNC_LOGOUT_DONE:
5239                         qla2x00_async_logout_done(vha, e->u.logio.fcport,
5240                             e->u.logio.data);
5241                         break;
5242                 case QLA_EVT_ASYNC_ADISC:
5243                         qla2x00_async_adisc(vha, e->u.logio.fcport,
5244                             e->u.logio.data);
5245                         break;
5246                 case QLA_EVT_UEVENT:
5247                         qla2x00_uevent_emit(vha, e->u.uevent.code);
5248                         break;
5249                 case QLA_EVT_AENFX:
5250                         qlafx00_process_aen(vha, e);
5251                         break;
5252                 case QLA_EVT_GPNID:
5253                         qla24xx_async_gpnid(vha, &e->u.gpnid.id);
5254                         break;
5255                 case QLA_EVT_UNMAP:
5256                         qla24xx_sp_unmap(vha, e->u.iosb.sp);
5257                         break;
5258                 case QLA_EVT_RELOGIN:
5259                         qla2x00_relogin(vha);
5260                         break;
5261                 case QLA_EVT_NEW_SESS:
5262                         qla24xx_create_new_sess(vha, e);
5263                         break;
5264                 case QLA_EVT_GPDB:
5265                         qla24xx_async_gpdb(vha, e->u.fcport.fcport,
5266                             e->u.fcport.opt);
5267                         break;
5268                 case QLA_EVT_PRLI:
5269                         qla24xx_async_prli(vha, e->u.fcport.fcport);
5270                         break;
5271                 case QLA_EVT_GPSC:
5272                         qla24xx_async_gpsc(vha, e->u.fcport.fcport);
5273                         break;
5274                 case QLA_EVT_GNL:
5275                         qla24xx_async_gnl(vha, e->u.fcport.fcport);
5276                         break;
5277                 case QLA_EVT_NACK:
5278                         qla24xx_do_nack_work(vha, e);
5279                         break;
5280                 case QLA_EVT_ASYNC_PRLO:
5281                         rc = qla2x00_async_prlo(vha, e->u.logio.fcport);
5282                         break;
5283                 case QLA_EVT_ASYNC_PRLO_DONE:
5284                         qla2x00_async_prlo_done(vha, e->u.logio.fcport,
5285                             e->u.logio.data);
5286                         break;
5287                 case QLA_EVT_GPNFT:
5288                         qla24xx_async_gpnft(vha, e->u.gpnft.fc4_type,
5289                             e->u.gpnft.sp);
5290                         break;
5291                 case QLA_EVT_GPNFT_DONE:
5292                         qla24xx_async_gpnft_done(vha, e->u.iosb.sp);
5293                         break;
5294                 case QLA_EVT_GNNFT_DONE:
5295                         qla24xx_async_gnnft_done(vha, e->u.iosb.sp);
5296                         break;
5297                 case QLA_EVT_GNNID:
5298                         qla24xx_async_gnnid(vha, e->u.fcport.fcport);
5299                         break;
5300                 case QLA_EVT_GFPNID:
5301                         qla24xx_async_gfpnid(vha, e->u.fcport.fcport);
5302                         break;
5303                 case QLA_EVT_SP_RETRY:
5304                         qla_sp_retry(vha, e);
5305                         break;
5306                 case QLA_EVT_IIDMA:
5307                         qla_do_iidma_work(vha, e->u.fcport.fcport);
5308                         break;
5309                 case QLA_EVT_ELS_PLOGI:
5310                         qla24xx_els_dcmd2_iocb(vha, ELS_DCMD_PLOGI,
5311                             e->u.fcport.fcport, false);
5312                         break;
5313                 }
5314 
5315                 if (rc == EAGAIN) {
5316                         /* put 'work' at head of 'vha->work_list' */
5317                         spin_lock_irqsave(&vha->work_lock, flags);
5318                         list_splice(&work, &vha->work_list);
5319                         spin_unlock_irqrestore(&vha->work_lock, flags);
5320                         break;
5321                 }
5322                 list_del_init(&e->list);
5323                 if (e->flags & QLA_EVT_FLAG_FREE)
5324                         kfree(e);
5325 
5326                 /* For each work completed decrement vha ref count */
5327                 QLA_VHA_MARK_NOT_BUSY(vha);
5328         }
5329 }
5330 
5331 int qla24xx_post_relogin_work(struct scsi_qla_host *vha)
5332 {
5333         struct qla_work_evt *e;
5334 
5335         e = qla2x00_alloc_work(vha, QLA_EVT_RELOGIN);
5336 
5337         if (!e) {
5338                 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5339                 return QLA_FUNCTION_FAILED;
5340         }
5341 
5342         return qla2x00_post_work(vha, e);
5343 }
5344 
5345 /* Relogins all the fcports of a vport
5346  * Context: dpc thread
5347  */
5348 void qla2x00_relogin(struct scsi_qla_host *vha)
5349 {
5350         fc_port_t       *fcport;
5351         int status, relogin_needed = 0;
5352         struct event_arg ea;
5353 
5354         list_for_each_entry(fcport, &vha->vp_fcports, list) {
5355                 /*
5356                  * If the port is not ONLINE then try to login
5357                  * to it if we haven't run out of retries.
5358                  */
5359                 if (atomic_read(&fcport->state) != FCS_ONLINE &&
5360                     fcport->login_retry) {
5361                         if (fcport->scan_state != QLA_FCPORT_FOUND ||
5362                             fcport->disc_state == DSC_LOGIN_COMPLETE)
5363                                 continue;
5364 
5365                         if (fcport->flags & (FCF_ASYNC_SENT|FCF_ASYNC_ACTIVE) ||
5366                                 fcport->disc_state == DSC_DELETE_PEND) {
5367                                 relogin_needed = 1;
5368                         } else {
5369                                 if (vha->hw->current_topology != ISP_CFG_NL) {
5370                                         memset(&ea, 0, sizeof(ea));
5371                                         ea.fcport = fcport;
5372                                         qla24xx_handle_relogin_event(vha, &ea);
5373                                 } else if (vha->hw->current_topology ==
5374                                     ISP_CFG_NL) {
5375                                         fcport->login_retry--;
5376                                         status =
5377                                             qla2x00_local_device_login(vha,
5378                                                 fcport);
5379                                         if (status == QLA_SUCCESS) {
5380                                                 fcport->old_loop_id =
5381                                                     fcport->loop_id;
5382                                                 ql_dbg(ql_dbg_disc, vha, 0x2003,
5383                                                     "Port login OK: logged in ID 0x%x.\n",
5384                                                     fcport->loop_id);
5385                                                 qla2x00_update_fcport
5386                                                         (vha, fcport);
5387                                         } else if (status == 1) {
5388                                                 set_bit(RELOGIN_NEEDED,
5389                                                     &vha->dpc_flags);
5390                                                 /* retry the login again */
5391                                                 ql_dbg(ql_dbg_disc, vha, 0x2007,
5392                                                     "Retrying %d login again loop_id 0x%x.\n",
5393                                                     fcport->login_retry,
5394                                                     fcport->loop_id);
5395                                         } else {
5396                                                 fcport->login_retry = 0;
5397                                         }
5398 
5399                                         if (fcport->login_retry == 0 &&
5400                                             status != QLA_SUCCESS)
5401                                                 qla2x00_clear_loop_id(fcport);
5402                                 }
5403                         }
5404                 }
5405                 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5406                         break;
5407         }
5408 
5409         if (relogin_needed)
5410                 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5411 
5412         ql_dbg(ql_dbg_disc, vha, 0x400e,
5413             "Relogin end.\n");
5414 }
5415 
5416 /* Schedule work on any of the dpc-workqueues */
5417 void
5418 qla83xx_schedule_work(scsi_qla_host_t *base_vha, int work_code)
5419 {
5420         struct qla_hw_data *ha = base_vha->hw;
5421 
5422         switch (work_code) {
5423         case MBA_IDC_AEN: /* 0x8200 */
5424                 if (ha->dpc_lp_wq)
5425                         queue_work(ha->dpc_lp_wq, &ha->idc_aen);
5426                 break;
5427 
5428         case QLA83XX_NIC_CORE_RESET: /* 0x1 */
5429                 if (!ha->flags.nic_core_reset_hdlr_active) {
5430                         if (ha->dpc_hp_wq)
5431                                 queue_work(ha->dpc_hp_wq, &ha->nic_core_reset);
5432                 } else
5433                         ql_dbg(ql_dbg_p3p, base_vha, 0xb05e,
5434                             "NIC Core reset is already active. Skip "
5435                             "scheduling it again.\n");
5436                 break;
5437         case QLA83XX_IDC_STATE_HANDLER: /* 0x2 */
5438                 if (ha->dpc_hp_wq)
5439                         queue_work(ha->dpc_hp_wq, &ha->idc_state_handler);
5440                 break;
5441         case QLA83XX_NIC_CORE_UNRECOVERABLE: /* 0x3 */
5442                 if (ha->dpc_hp_wq)
5443                         queue_work(ha->dpc_hp_wq, &ha->nic_core_unrecoverable);
5444                 break;
5445         default:
5446                 ql_log(ql_log_warn, base_vha, 0xb05f,
5447                     "Unknown work-code=0x%x.\n", work_code);
5448         }
5449 
5450         return;
5451 }
5452 
5453 /* Work: Perform NIC Core Unrecoverable state handling */
5454 void
5455 qla83xx_nic_core_unrecoverable_work(struct work_struct *work)
5456 {
5457         struct qla_hw_data *ha =
5458                 container_of(work, struct qla_hw_data, nic_core_unrecoverable);
5459         scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5460         uint32_t dev_state = 0;
5461 
5462         qla83xx_idc_lock(base_vha, 0);
5463         qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5464         qla83xx_reset_ownership(base_vha);
5465         if (ha->flags.nic_core_reset_owner) {
5466                 ha->flags.nic_core_reset_owner = 0;
5467                 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
5468                     QLA8XXX_DEV_FAILED);
5469                 ql_log(ql_log_info, base_vha, 0xb060, "HW State: FAILED.\n");
5470                 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
5471         }
5472         qla83xx_idc_unlock(base_vha, 0);
5473 }
5474 
5475 /* Work: Execute IDC state handler */
5476 void
5477 qla83xx_idc_state_handler_work(struct work_struct *work)
5478 {
5479         struct qla_hw_data *ha =
5480                 container_of(work, struct qla_hw_data, idc_state_handler);
5481         scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5482         uint32_t dev_state = 0;
5483 
5484         qla83xx_idc_lock(base_vha, 0);
5485         qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5486         if (dev_state == QLA8XXX_DEV_FAILED ||
5487                         dev_state == QLA8XXX_DEV_NEED_QUIESCENT)
5488                 qla83xx_idc_state_handler(base_vha);
5489         qla83xx_idc_unlock(base_vha, 0);
5490 }
5491 
5492 static int
5493 qla83xx_check_nic_core_fw_alive(scsi_qla_host_t *base_vha)
5494 {
5495         int rval = QLA_SUCCESS;
5496         unsigned long heart_beat_wait = jiffies + (1 * HZ);
5497         uint32_t heart_beat_counter1, heart_beat_counter2;
5498 
5499         do {
5500                 if (time_after(jiffies, heart_beat_wait)) {
5501                         ql_dbg(ql_dbg_p3p, base_vha, 0xb07c,
5502                             "Nic Core f/w is not alive.\n");
5503                         rval = QLA_FUNCTION_FAILED;
5504                         break;
5505                 }
5506 
5507                 qla83xx_idc_lock(base_vha, 0);
5508                 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
5509                     &heart_beat_counter1);
5510                 qla83xx_idc_unlock(base_vha, 0);
5511                 msleep(100);
5512                 qla83xx_idc_lock(base_vha, 0);
5513                 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
5514                     &heart_beat_counter2);
5515                 qla83xx_idc_unlock(base_vha, 0);
5516         } while (heart_beat_counter1 == heart_beat_counter2);
5517 
5518         return rval;
5519 }
5520 
5521 /* Work: Perform NIC Core Reset handling */
5522 void
5523 qla83xx_nic_core_reset_work(struct work_struct *work)
5524 {
5525         struct qla_hw_data *ha =
5526                 container_of(work, struct qla_hw_data, nic_core_reset);
5527         scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5528         uint32_t dev_state = 0;
5529 
5530         if (IS_QLA2031(ha)) {
5531                 if (qla2xxx_mctp_dump(base_vha) != QLA_SUCCESS)
5532                         ql_log(ql_log_warn, base_vha, 0xb081,
5533                             "Failed to dump mctp\n");
5534                 return;
5535         }
5536 
5537         if (!ha->flags.nic_core_reset_hdlr_active) {
5538                 if (qla83xx_check_nic_core_fw_alive(base_vha) == QLA_SUCCESS) {
5539                         qla83xx_idc_lock(base_vha, 0);
5540                         qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE,
5541                             &dev_state);
5542                         qla83xx_idc_unlock(base_vha, 0);
5543                         if (dev_state != QLA8XXX_DEV_NEED_RESET) {
5544                                 ql_dbg(ql_dbg_p3p, base_vha, 0xb07a,
5545                                     "Nic Core f/w is alive.\n");
5546                                 return;
5547                         }
5548                 }
5549 
5550                 ha->flags.nic_core_reset_hdlr_active = 1;
5551                 if (qla83xx_nic_core_reset(base_vha)) {
5552                         /* NIC Core reset failed. */
5553                         ql_dbg(ql_dbg_p3p, base_vha, 0xb061,
5554                             "NIC Core reset failed.\n");
5555                 }
5556                 ha->flags.nic_core_reset_hdlr_active = 0;
5557         }
5558 }
5559 
5560 /* Work: Handle 8200 IDC aens */
5561 void
5562 qla83xx_service_idc_aen(struct work_struct *work)
5563 {
5564         struct qla_hw_data *ha =
5565                 container_of(work, struct qla_hw_data, idc_aen);
5566         scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5567         uint32_t dev_state, idc_control;
5568 
5569         qla83xx_idc_lock(base_vha, 0);
5570         qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5571         qla83xx_rd_reg(base_vha, QLA83XX_IDC_CONTROL, &idc_control);
5572         qla83xx_idc_unlock(base_vha, 0);
5573         if (dev_state == QLA8XXX_DEV_NEED_RESET) {
5574                 if (idc_control & QLA83XX_IDC_GRACEFUL_RESET) {
5575                         ql_dbg(ql_dbg_p3p, base_vha, 0xb062,
5576                             "Application requested NIC Core Reset.\n");
5577                         qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
5578                 } else if (qla83xx_check_nic_core_fw_alive(base_vha) ==
5579                     QLA_SUCCESS) {
5580                         ql_dbg(ql_dbg_p3p, base_vha, 0xb07b,
5581                             "Other protocol driver requested NIC Core Reset.\n");
5582                         qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
5583                 }
5584         } else if (dev_state == QLA8XXX_DEV_FAILED ||
5585                         dev_state == QLA8XXX_DEV_NEED_QUIESCENT) {
5586                 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
5587         }
5588 }
5589 
5590 static void
5591 qla83xx_wait_logic(void)
5592 {
5593         int i;
5594 
5595         /* Yield CPU */
5596         if (!in_interrupt()) {
5597                 /*
5598                  * Wait about 200ms before retrying again.
5599                  * This controls the number of retries for single
5600                  * lock operation.
5601                  */
5602                 msleep(100);
5603                 schedule();
5604         } else {
5605                 for (i = 0; i < 20; i++)
5606                         cpu_relax(); /* This a nop instr on i386 */
5607         }
5608 }
5609 
5610 static int
5611 qla83xx_force_lock_recovery(scsi_qla_host_t *base_vha)
5612 {
5613         int rval;
5614         uint32_t data;
5615         uint32_t idc_lck_rcvry_stage_mask = 0x3;
5616         uint32_t idc_lck_rcvry_owner_mask = 0x3c;
5617         struct qla_hw_data *ha = base_vha->hw;
5618 
5619         ql_dbg(ql_dbg_p3p, base_vha, 0xb086,
5620             "Trying force recovery of the IDC lock.\n");
5621 
5622         rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY, &data);
5623         if (rval)
5624                 return rval;
5625 
5626         if ((data & idc_lck_rcvry_stage_mask) > 0) {
5627                 return QLA_SUCCESS;
5628         } else {
5629                 data = (IDC_LOCK_RECOVERY_STAGE1) | (ha->portnum << 2);
5630                 rval = qla83xx_wr_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
5631                     data);
5632                 if (rval)
5633                         return rval;
5634 
5635                 msleep(200);
5636 
5637                 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
5638                     &data);
5639                 if (rval)
5640                         return rval;
5641 
5642                 if (((data & idc_lck_rcvry_owner_mask) >> 2) == ha->portnum) {
5643                         data &= (IDC_LOCK_RECOVERY_STAGE2 |
5644                                         ~(idc_lck_rcvry_stage_mask));
5645                         rval = qla83xx_wr_reg(base_vha,
5646                             QLA83XX_IDC_LOCK_RECOVERY, data);
5647                         if (rval)
5648                                 return rval;
5649 
5650                         /* Forcefully perform IDC UnLock */
5651                         rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK,
5652                             &data);
5653                         if (rval)
5654                                 return rval;
5655                         /* Clear lock-id by setting 0xff */
5656                         rval = qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5657                             0xff);
5658                         if (rval)
5659                                 return rval;
5660                         /* Clear lock-recovery by setting 0x0 */
5661                         rval = qla83xx_wr_reg(base_vha,
5662                             QLA83XX_IDC_LOCK_RECOVERY, 0x0);
5663                         if (rval)
5664                                 return rval;
5665                 } else
5666                         return QLA_SUCCESS;
5667         }
5668 
5669         return rval;
5670 }
5671 
5672 static int
5673 qla83xx_idc_lock_recovery(scsi_qla_host_t *base_vha)
5674 {
5675         int rval = QLA_SUCCESS;
5676         uint32_t o_drv_lockid, n_drv_lockid;
5677         unsigned long lock_recovery_timeout;
5678 
5679         lock_recovery_timeout = jiffies + QLA83XX_MAX_LOCK_RECOVERY_WAIT;
5680 retry_lockid:
5681         rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &o_drv_lockid);
5682         if (rval)
5683                 goto exit;
5684 
5685         /* MAX wait time before forcing IDC Lock recovery = 2 secs */
5686         if (time_after_eq(jiffies, lock_recovery_timeout)) {
5687                 if (qla83xx_force_lock_recovery(base_vha) == QLA_SUCCESS)
5688                         return QLA_SUCCESS;
5689                 else
5690                         return QLA_FUNCTION_FAILED;
5691         }
5692 
5693         rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &n_drv_lockid);
5694         if (rval)
5695                 goto exit;
5696 
5697         if (o_drv_lockid == n_drv_lockid) {
5698                 qla83xx_wait_logic();
5699                 goto retry_lockid;
5700         } else
5701                 return QLA_SUCCESS;
5702 
5703 exit:
5704         return rval;
5705 }
5706 
5707 void
5708 qla83xx_idc_lock(scsi_qla_host_t *base_vha, uint16_t requester_id)
5709 {
5710         uint32_t data;
5711         uint32_t lock_owner;
5712         struct qla_hw_data *ha = base_vha->hw;
5713 
5714         /* IDC-lock implementation using driver-lock/lock-id remote registers */
5715 retry_lock:
5716         if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCK, &data)
5717             == QLA_SUCCESS) {
5718                 if (data) {
5719                         /* Setting lock-id to our function-number */
5720                         qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5721                             ha->portnum);
5722                 } else {
5723                         qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5724                             &lock_owner);
5725                         ql_dbg(ql_dbg_p3p, base_vha, 0xb063,
5726                             "Failed to acquire IDC lock, acquired by %d, "
5727                             "retrying...\n", lock_owner);
5728 
5729                         /* Retry/Perform IDC-Lock recovery */
5730                         if (qla83xx_idc_lock_recovery(base_vha)
5731                             == QLA_SUCCESS) {
5732                                 qla83xx_wait_logic();
5733                                 goto retry_lock;
5734                         } else
5735                                 ql_log(ql_log_warn, base_vha, 0xb075,
5736                                     "IDC Lock recovery FAILED.\n");
5737                 }
5738 
5739         }
5740 
5741         return;
5742 }
5743 
5744 void
5745 qla83xx_idc_unlock(scsi_qla_host_t *base_vha, uint16_t requester_id)
5746 {
5747 #if 0
5748         uint16_t options = (requester_id << 15) | BIT_7;
5749 #endif
5750         uint16_t retry;
5751         uint32_t data;
5752         struct qla_hw_data *ha = base_vha->hw;
5753 
5754         /* IDC-unlock implementation using driver-unlock/lock-id
5755          * remote registers
5756          */
5757         retry = 0;
5758 retry_unlock:
5759         if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &data)
5760             == QLA_SUCCESS) {
5761                 if (data == ha->portnum) {
5762                         qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK, &data);
5763                         /* Clearing lock-id by setting 0xff */
5764                         qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID, 0xff);
5765                 } else if (retry < 10) {
5766                         /* SV: XXX: IDC unlock retrying needed here? */
5767 
5768                         /* Retry for IDC-unlock */
5769                         qla83xx_wait_logic();
5770                         retry++;
5771                         ql_dbg(ql_dbg_p3p, base_vha, 0xb064,
5772                             "Failed to release IDC lock, retrying=%d\n", retry);
5773                         goto retry_unlock;
5774                 }
5775         } else if (retry < 10) {
5776                 /* Retry for IDC-unlock */
5777                 qla83xx_wait_logic();
5778                 retry++;
5779                 ql_dbg(ql_dbg_p3p, base_vha, 0xb065,
5780                     "Failed to read drv-lockid, retrying=%d\n", retry);
5781                 goto retry_unlock;
5782         }
5783 
5784         return;
5785 
5786 #if 0
5787         /* XXX: IDC-unlock implementation using access-control mbx */
5788         retry = 0;
5789 retry_unlock2:
5790         if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
5791                 if (retry < 10) {
5792                         /* Retry for IDC-unlock */
5793                         qla83xx_wait_logic();
5794                         retry++;
5795                         ql_dbg(ql_dbg_p3p, base_vha, 0xb066,
5796                             "Failed to release IDC lock, retrying=%d\n", retry);
5797                         goto retry_unlock2;
5798                 }
5799         }
5800 
5801         return;
5802 #endif
5803 }
5804 
5805 int
5806 __qla83xx_set_drv_presence(scsi_qla_host_t *vha)
5807 {
5808         int rval = QLA_SUCCESS;
5809         struct qla_hw_data *ha = vha->hw;
5810         uint32_t drv_presence;
5811 
5812         rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5813         if (rval == QLA_SUCCESS) {
5814                 drv_presence |= (1 << ha->portnum);
5815                 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5816                     drv_presence);
5817         }
5818 
5819         return rval;
5820 }
5821 
5822 int
5823 qla83xx_set_drv_presence(scsi_qla_host_t *vha)
5824 {
5825         int rval = QLA_SUCCESS;
5826 
5827         qla83xx_idc_lock(vha, 0);
5828         rval = __qla83xx_set_drv_presence(vha);
5829         qla83xx_idc_unlock(vha, 0);
5830 
5831         return rval;
5832 }
5833 
5834 int
5835 __qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
5836 {
5837         int rval = QLA_SUCCESS;
5838         struct qla_hw_data *ha = vha->hw;
5839         uint32_t drv_presence;
5840 
5841         rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5842         if (rval == QLA_SUCCESS) {
5843                 drv_presence &= ~(1 << ha->portnum);
5844                 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5845                     drv_presence);
5846         }
5847 
5848         return rval;
5849 }
5850 
5851 int
5852 qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
5853 {
5854         int rval = QLA_SUCCESS;
5855 
5856         qla83xx_idc_lock(vha, 0);
5857         rval = __qla83xx_clear_drv_presence(vha);
5858         qla83xx_idc_unlock(vha, 0);
5859 
5860         return rval;
5861 }
5862 
5863 static void
5864 qla83xx_need_reset_handler(scsi_qla_host_t *vha)
5865 {
5866         struct qla_hw_data *ha = vha->hw;
5867         uint32_t drv_ack, drv_presence;
5868         unsigned long ack_timeout;
5869 
5870         /* Wait for IDC ACK from all functions (DRV-ACK == DRV-PRESENCE) */
5871         ack_timeout = jiffies + (ha->fcoe_reset_timeout * HZ);
5872         while (1) {
5873                 qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
5874                 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5875                 if ((drv_ack & drv_presence) == drv_presence)
5876                         break;
5877 
5878                 if (time_after_eq(jiffies, ack_timeout)) {
5879                         ql_log(ql_log_warn, vha, 0xb067,
5880                             "RESET ACK TIMEOUT! drv_presence=0x%x "
5881                             "drv_ack=0x%x\n", drv_presence, drv_ack);
5882                         /*
5883                          * The function(s) which did not ack in time are forced
5884                          * to withdraw any further participation in the IDC
5885                          * reset.
5886                          */
5887                         if (drv_ack != drv_presence)
5888                                 qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5889                                     drv_ack);
5890                         break;
5891                 }
5892 
5893                 qla83xx_idc_unlock(vha, 0);
5894                 msleep(1000);
5895                 qla83xx_idc_lock(vha, 0);
5896         }
5897 
5898         qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_COLD);
5899         ql_log(ql_log_info, vha, 0xb068, "HW State: COLD/RE-INIT.\n");
5900 }
5901 
5902 static int
5903 qla83xx_device_bootstrap(scsi_qla_host_t *vha)
5904 {
5905         int rval = QLA_SUCCESS;
5906         uint32_t idc_control;
5907 
5908         qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_INITIALIZING);
5909         ql_log(ql_log_info, vha, 0xb069, "HW State: INITIALIZING.\n");
5910 
5911         /* Clearing IDC-Control Graceful-Reset Bit before resetting f/w */
5912         __qla83xx_get_idc_control(vha, &idc_control);
5913         idc_control &= ~QLA83XX_IDC_GRACEFUL_RESET;
5914         __qla83xx_set_idc_control(vha, 0);
5915 
5916         qla83xx_idc_unlock(vha, 0);
5917         rval = qla83xx_restart_nic_firmware(vha);
5918         qla83xx_idc_lock(vha, 0);
5919 
5920         if (rval != QLA_SUCCESS) {
5921                 ql_log(ql_log_fatal, vha, 0xb06a,
5922                     "Failed to restart NIC f/w.\n");
5923                 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_FAILED);
5924                 ql_log(ql_log_info, vha, 0xb06b, "HW State: FAILED.\n");
5925         } else {
5926                 ql_dbg(ql_dbg_p3p, vha, 0xb06c,
5927                     "Success in restarting nic f/w.\n");
5928                 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_READY);
5929                 ql_log(ql_log_info, vha, 0xb06d, "HW State: READY.\n");
5930         }
5931 
5932         return rval;
5933 }
5934 
5935 /* Assumes idc_lock always held on entry */
5936 int
5937 qla83xx_idc_state_handler(scsi_qla_host_t *base_vha)
5938 {
5939         struct qla_hw_data *ha = base_vha->hw;
5940         int rval = QLA_SUCCESS;
5941         unsigned long dev_init_timeout;
5942         uint32_t dev_state;
5943 
5944         /* Wait for MAX-INIT-TIMEOUT for the device to go ready */
5945         dev_init_timeout = jiffies + (ha->fcoe_dev_init_timeout * HZ);
5946 
5947         while (1) {
5948 
5949                 if (time_after_eq(jiffies, dev_init_timeout)) {
5950                         ql_log(ql_log_warn, base_vha, 0xb06e,
5951                             "Initialization TIMEOUT!\n");
5952                         /* Init timeout. Disable further NIC Core
5953                          * communication.
5954                          */
5955                         qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
5956                                 QLA8XXX_DEV_FAILED);
5957                         ql_log(ql_log_info, base_vha, 0xb06f,
5958                             "HW State: FAILED.\n");
5959                 }
5960 
5961                 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5962                 switch (dev_state) {
5963                 case QLA8XXX_DEV_READY:
5964                         if (ha->flags.nic_core_reset_owner)
5965                                 qla83xx_idc_audit(base_vha,
5966                                     IDC_AUDIT_COMPLETION);
5967                         ha->flags.nic_core_reset_owner = 0;
5968                         ql_dbg(ql_dbg_p3p, base_vha, 0xb070,
5969                             "Reset_owner reset by 0x%x.\n",
5970                             ha->portnum);
5971                         goto exit;
5972                 case QLA8XXX_DEV_COLD:
5973                         if (ha->flags.nic_core_reset_owner)
5974                                 rval = qla83xx_device_bootstrap(base_vha);
5975                         else {
5976                         /* Wait for AEN to change device-state */
5977                                 qla83xx_idc_unlock(base_vha, 0);
5978                                 msleep(1000);
5979                                 qla83xx_idc_lock(base_vha, 0);
5980                         }
5981                         break;
5982                 case QLA8XXX_DEV_INITIALIZING:
5983                         /* Wait for AEN to change device-state */
5984                         qla83xx_idc_unlock(base_vha, 0);
5985                         msleep(1000);
5986                         qla83xx_idc_lock(base_vha, 0);
5987                         break;
5988                 case QLA8XXX_DEV_NEED_RESET:
5989                         if (!ql2xdontresethba && ha->flags.nic_core_reset_owner)
5990                                 qla83xx_need_reset_handler(base_vha);
5991                         else {
5992                                 /* Wait for AEN to change device-state */
5993                                 qla83xx_idc_unlock(base_vha, 0);
5994                                 msleep(1000);
5995                                 qla83xx_idc_lock(base_vha, 0);
5996                         }
5997                         /* reset timeout value after need reset handler */
5998                         dev_init_timeout = jiffies +
5999                             (ha->fcoe_dev_init_timeout * HZ);
6000                         break;
6001                 case QLA8XXX_DEV_NEED_QUIESCENT:
6002                         /* XXX: DEBUG for now */
6003                         qla83xx_idc_unlock(base_vha, 0);
6004                         msleep(1000);
6005                         qla83xx_idc_lock(base_vha, 0);
6006                         break;
6007                 case QLA8XXX_DEV_QUIESCENT:
6008                         /* XXX: DEBUG for now */
6009                         if (ha->flags.quiesce_owner)
6010                                 goto exit;
6011 
6012                         qla83xx_idc_unlock(base_vha, 0);
6013                         msleep(1000);
6014                         qla83xx_idc_lock(base_vha, 0);
6015                         dev_init_timeout = jiffies +
6016                             (ha->fcoe_dev_init_timeout * HZ);
6017                         break;
6018                 case QLA8XXX_DEV_FAILED:
6019                         if (ha->flags.nic_core_reset_owner)
6020                                 qla83xx_idc_audit(base_vha,
6021                                     IDC_AUDIT_COMPLETION);
6022                         ha->flags.nic_core_reset_owner = 0;
6023                         __qla83xx_clear_drv_presence(base_vha);
6024                         qla83xx_idc_unlock(base_vha, 0);
6025                         qla8xxx_dev_failed_handler(base_vha);
6026                         rval = QLA_FUNCTION_FAILED;
6027                         qla83xx_idc_lock(base_vha, 0);
6028                         goto exit;
6029                 case QLA8XXX_BAD_VALUE:
6030                         qla83xx_idc_unlock(base_vha, 0);
6031                         msleep(1000);
6032                         qla83xx_idc_lock(base_vha, 0);
6033                         break;
6034                 default:
6035                         ql_log(ql_log_warn, base_vha, 0xb071,
6036                             "Unknown Device State: %x.\n", dev_state);
6037                         qla83xx_idc_unlock(base_vha, 0);
6038                         qla8xxx_dev_failed_handler(base_vha);
6039                         rval = QLA_FUNCTION_FAILED;
6040                         qla83xx_idc_lock(base_vha, 0);
6041                         goto exit;
6042                 }
6043         }
6044 
6045 exit:
6046         return rval;
6047 }
6048 
6049 void
6050 qla2x00_disable_board_on_pci_error(struct work_struct *work)
6051 {
6052         struct qla_hw_data *ha = container_of(work, struct qla_hw_data,
6053             board_disable);
6054         struct pci_dev *pdev = ha->pdev;
6055         scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
6056 
6057         ql_log(ql_log_warn, base_vha, 0x015b,
6058             "Disabling adapter.\n");
6059 
6060         if (!atomic_read(&pdev->enable_cnt)) {
6061                 ql_log(ql_log_info, base_vha, 0xfffc,
6062                     "PCI device disabled, no action req for PCI error=%lx\n",
6063                     base_vha->pci_flags);
6064                 return;
6065         }
6066 
6067         /*
6068          * if UNLOADING flag is already set, then continue unload,
6069          * where it was set first.
6070          */
6071         if (test_and_set_bit(UNLOADING, &base_vha->dpc_flags))
6072                 return;
6073 
6074         qla2x00_wait_for_sess_deletion(base_vha);
6075 
6076         qla2x00_delete_all_vps(ha, base_vha);
6077 
6078         qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
6079 
6080         qla2x00_dfs_remove(base_vha);
6081 
6082         qla84xx_put_chip(base_vha);
6083 
6084         if (base_vha->timer_active)
6085                 qla2x00_stop_timer(base_vha);
6086 
6087         base_vha->flags.online = 0;
6088 
6089         qla2x00_destroy_deferred_work(ha);
6090 
6091         /*
6092          * Do not try to stop beacon blink as it will issue a mailbox
6093          * command.
6094          */
6095         qla2x00_free_sysfs_attr(base_vha, false);
6096 
6097         fc_remove_host(base_vha->host);
6098 
6099         scsi_remove_host(base_vha->host);
6100 
6101         base_vha->flags.init_done = 0;
6102         qla25xx_delete_queues(base_vha);
6103         qla2x00_free_fcports(base_vha);
6104         qla2x00_free_irqs(base_vha);
6105         qla2x00_mem_free(ha);
6106         qla82xx_md_free(base_vha);
6107         qla2x00_free_queues(ha);
6108 
6109         qla2x00_unmap_iobases(ha);
6110 
6111         pci_release_selected_regions(ha->pdev, ha->bars);
6112         pci_disable_pcie_error_reporting(pdev);
6113         pci_disable_device(pdev);
6114 
6115         /*
6116          * Let qla2x00_remove_one cleanup qla_hw_data on device removal.
6117          */
6118 }
6119 
6120 /**************************************************************************
6121 * qla2x00_do_dpc
6122 *   This kernel thread is a task that is schedule by the interrupt handler
6123 *   to perform the background processing for interrupts.
6124 *
6125 * Notes:
6126 * This task always run in the context of a kernel thread.  It
6127 * is kick-off by the driver's detect code and starts up
6128 * up one per adapter. It immediately goes to sleep and waits for
6129 * some fibre event.  When either the interrupt handler or
6130 * the timer routine detects a event it will one of the task
6131 * bits then wake us up.
6132 **************************************************************************/
6133 static int
6134 qla2x00_do_dpc(void *data)
6135 {
6136         scsi_qla_host_t *base_vha;
6137         struct qla_hw_data *ha;
6138         uint32_t online;
6139         struct qla_qpair *qpair;
6140 
6141         ha = (struct qla_hw_data *)data;
6142         base_vha = pci_get_drvdata(ha->pdev);
6143 
6144         set_user_nice(current, MIN_NICE);
6145 
6146         set_current_state(TASK_INTERRUPTIBLE);
6147         while (!kthread_should_stop()) {
6148                 ql_dbg(ql_dbg_dpc, base_vha, 0x4000,
6149                     "DPC handler sleeping.\n");
6150 
6151                 schedule();
6152 
6153                 if (!base_vha->flags.init_done || ha->flags.mbox_busy)
6154                         goto end_loop;
6155 
6156                 if (ha->flags.eeh_busy) {
6157                         ql_dbg(ql_dbg_dpc, base_vha, 0x4003,
6158                             "eeh_busy=%d.\n", ha->flags.eeh_busy);
6159                         goto end_loop;
6160                 }
6161 
6162                 ha->dpc_active = 1;
6163 
6164                 ql_dbg(ql_dbg_dpc + ql_dbg_verbose, base_vha, 0x4001,
6165                     "DPC handler waking up, dpc_flags=0x%lx.\n",
6166                     base_vha->dpc_flags);
6167 
6168                 if (test_bit(UNLOADING, &base_vha->dpc_flags))
6169                         break;
6170 
6171                 if (IS_P3P_TYPE(ha)) {
6172                         if (IS_QLA8044(ha)) {
6173                                 if (test_and_clear_bit(ISP_UNRECOVERABLE,
6174                                         &base_vha->dpc_flags)) {
6175                                         qla8044_idc_lock(ha);
6176                                         qla8044_wr_direct(base_vha,
6177                                                 QLA8044_CRB_DEV_STATE_INDEX,
6178                                                 QLA8XXX_DEV_FAILED);
6179                                         qla8044_idc_unlock(ha);
6180                                         ql_log(ql_log_info, base_vha, 0x4004,
6181                                                 "HW State: FAILED.\n");
6182                                         qla8044_device_state_handler(base_vha);
6183                                         continue;
6184                                 }
6185 
6186                         } else {
6187                                 if (test_and_clear_bit(ISP_UNRECOVERABLE,
6188                                         &base_vha->dpc_flags)) {
6189                                         qla82xx_idc_lock(ha);
6190                                         qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
6191                                                 QLA8XXX_DEV_FAILED);
6192                                         qla82xx_idc_unlock(ha);
6193                                         ql_log(ql_log_info, base_vha, 0x0151,
6194                                                 "HW State: FAILED.\n");
6195                                         qla82xx_device_state_handler(base_vha);
6196                                         continue;
6197                                 }
6198                         }
6199 
6200                         if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED,
6201                                 &base_vha->dpc_flags)) {
6202 
6203                                 ql_dbg(ql_dbg_dpc, base_vha, 0x4005,
6204                                     "FCoE context reset scheduled.\n");
6205                                 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
6206                                         &base_vha->dpc_flags))) {
6207                                         if (qla82xx_fcoe_ctx_reset(base_vha)) {
6208                                                 /* FCoE-ctx reset failed.
6209                                                  * Escalate to chip-reset
6210                                                  */
6211                                                 set_bit(ISP_ABORT_NEEDED,
6212                                                         &base_vha->dpc_flags);
6213                                         }
6214                                         clear_bit(ABORT_ISP_ACTIVE,
6215                                                 &base_vha->dpc_flags);
6216                                 }
6217 
6218                                 ql_dbg(ql_dbg_dpc, base_vha, 0x4006,
6219                                     "FCoE context reset end.\n");
6220                         }
6221                 } else if (IS_QLAFX00(ha)) {
6222                         if (test_and_clear_bit(ISP_UNRECOVERABLE,
6223                                 &base_vha->dpc_flags)) {
6224                                 ql_dbg(ql_dbg_dpc, base_vha, 0x4020,
6225                                     "Firmware Reset Recovery\n");
6226                                 if (qlafx00_reset_initialize(base_vha)) {
6227                                         /* Failed. Abort isp later. */
6228                                         if (!test_bit(UNLOADING,
6229                                             &base_vha->dpc_flags)) {
6230                                                 set_bit(ISP_UNRECOVERABLE,
6231                                                     &base_vha->dpc_flags);
6232                                                 ql_dbg(ql_dbg_dpc, base_vha,
6233                                                     0x4021,
6234                                                     "Reset Recovery Failed\n");
6235                                         }
6236                                 }
6237                         }
6238 
6239                         if (test_and_clear_bit(FX00_TARGET_SCAN,
6240                                 &base_vha->dpc_flags)) {
6241                                 ql_dbg(ql_dbg_dpc, base_vha, 0x4022,
6242                                     "ISPFx00 Target Scan scheduled\n");
6243                                 if (qlafx00_rescan_isp(base_vha)) {
6244                                         if (!test_bit(UNLOADING,
6245                                             &base_vha->dpc_flags))
6246                                                 set_bit(ISP_UNRECOVERABLE,
6247                                                     &base_vha->dpc_flags);
6248                                         ql_dbg(ql_dbg_dpc, base_vha, 0x401e,
6249                                             "ISPFx00 Target Scan Failed\n");
6250                                 }
6251                                 ql_dbg(ql_dbg_dpc, base_vha, 0x401f,
6252                                     "ISPFx00 Target Scan End\n");
6253                         }
6254                         if (test_and_clear_bit(FX00_HOST_INFO_RESEND,
6255                                 &base_vha->dpc_flags)) {
6256                                 ql_dbg(ql_dbg_dpc, base_vha, 0x4023,
6257                                     "ISPFx00 Host Info resend scheduled\n");
6258                                 qlafx00_fx_disc(base_vha,
6259                                     &base_vha->hw->mr.fcport,
6260                                     FXDISC_REG_HOST_INFO);
6261                         }
6262                 }
6263 
6264                 if (test_and_clear_bit(DETECT_SFP_CHANGE,
6265                         &base_vha->dpc_flags) &&
6266                     !test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) {
6267                         qla24xx_detect_sfp(base_vha);
6268 
6269                         if (ha->flags.detected_lr_sfp !=
6270                             ha->flags.using_lr_setting)
6271                                 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
6272                 }
6273 
6274                 if (test_and_clear_bit
6275                     (ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
6276                     !test_bit(UNLOADING, &base_vha->dpc_flags)) {
6277                         bool do_reset = true;
6278 
6279                         switch (base_vha->qlini_mode) {
6280                         case QLA2XXX_INI_MODE_ENABLED:
6281                                 break;
6282                         case QLA2XXX_INI_MODE_DISABLED:
6283                                 if (!qla_tgt_mode_enabled(base_vha) &&
6284                                     !ha->flags.fw_started)
6285                                         do_reset = false;
6286                                 break;
6287                         case QLA2XXX_INI_MODE_DUAL:
6288                                 if (!qla_dual_mode_enabled(base_vha) &&
6289                                     !ha->flags.fw_started)
6290                                         do_reset = false;
6291                                 break;
6292                         default:
6293                                 break;
6294                         }
6295 
6296                         if (do_reset && !(test_and_set_bit(ABORT_ISP_ACTIVE,
6297                             &base_vha->dpc_flags))) {
6298                                 ql_dbg(ql_dbg_dpc, base_vha, 0x4007,
6299                                     "ISP abort scheduled.\n");
6300                                 if (ha->isp_ops->abort_isp(base_vha)) {
6301                                         /* failed. retry later */
6302                                         set_bit(ISP_ABORT_NEEDED,
6303                                             &base_vha->dpc_flags);
6304                                 }
6305                                 clear_bit(ABORT_ISP_ACTIVE,
6306                                                 &base_vha->dpc_flags);
6307                                 ql_dbg(ql_dbg_dpc, base_vha, 0x4008,
6308                                     "ISP abort end.\n");
6309                         }
6310                 }
6311 
6312                 if (test_and_clear_bit(FCPORT_UPDATE_NEEDED,
6313                     &base_vha->dpc_flags)) {
6314                         qla2x00_update_fcports(base_vha);
6315                 }
6316 
6317                 if (IS_QLAFX00(ha))
6318                         goto loop_resync_check;
6319 
6320                 if (test_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags)) {
6321                         ql_dbg(ql_dbg_dpc, base_vha, 0x4009,
6322                             "Quiescence mode scheduled.\n");
6323                         if (IS_P3P_TYPE(ha)) {
6324                                 if (IS_QLA82XX(ha))
6325                                         qla82xx_device_state_handler(base_vha);
6326                                 if (IS_QLA8044(ha))
6327                                         qla8044_device_state_handler(base_vha);
6328                                 clear_bit(ISP_QUIESCE_NEEDED,
6329                                     &base_vha->dpc_flags);
6330                                 if (!ha->flags.quiesce_owner) {
6331                                         qla2x00_perform_loop_resync(base_vha);
6332                                         if (IS_QLA82XX(ha)) {
6333                                                 qla82xx_idc_lock(ha);
6334                                                 qla82xx_clear_qsnt_ready(
6335                                                     base_vha);
6336                                                 qla82xx_idc_unlock(ha);
6337                                         } else if (IS_QLA8044(ha)) {
6338                                                 qla8044_idc_lock(ha);
6339                                                 qla8044_clear_qsnt_ready(
6340                                                     base_vha);
6341                                                 qla8044_idc_unlock(ha);
6342                                         }
6343                                 }
6344                         } else {
6345                                 clear_bit(ISP_QUIESCE_NEEDED,
6346                                     &base_vha->dpc_flags);
6347                                 qla2x00_quiesce_io(base_vha);
6348                         }
6349                         ql_dbg(ql_dbg_dpc, base_vha, 0x400a,
6350                             "Quiescence mode end.\n");
6351                 }
6352 
6353                 if (test_and_clear_bit(RESET_MARKER_NEEDED,
6354                                 &base_vha->dpc_flags) &&
6355                     (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
6356 
6357                         ql_dbg(ql_dbg_dpc, base_vha, 0x400b,
6358                             "Reset marker scheduled.\n");
6359                         qla2x00_rst_aen(base_vha);
6360                         clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
6361                         ql_dbg(ql_dbg_dpc, base_vha, 0x400c,
6362                             "Reset marker end.\n");
6363                 }
6364 
6365                 /* Retry each device up to login retry count */
6366                 if (test_bit(RELOGIN_NEEDED, &base_vha->dpc_flags) &&
6367                     !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
6368                     atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
6369 
6370                         if (!base_vha->relogin_jif ||
6371                             time_after_eq(jiffies, base_vha->relogin_jif)) {
6372                                 base_vha->relogin_jif = jiffies + HZ;
6373                                 clear_bit(RELOGIN_NEEDED, &base_vha->dpc_flags);
6374 
6375                                 ql_dbg(ql_dbg_disc, base_vha, 0x400d,
6376                                     "Relogin scheduled.\n");
6377                                 qla24xx_post_relogin_work(base_vha);
6378                         }
6379                 }
6380 loop_resync_check:
6381                 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
6382                     &base_vha->dpc_flags)) {
6383 
6384                         ql_dbg(ql_dbg_dpc, base_vha, 0x400f,
6385                             "Loop resync scheduled.\n");
6386 
6387                         if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
6388                             &base_vha->dpc_flags))) {
6389 
6390                                 qla2x00_loop_resync(base_vha);
6391 
6392                                 clear_bit(LOOP_RESYNC_ACTIVE,
6393                                                 &base_vha->dpc_flags);
6394                         }
6395 
6396                         ql_dbg(ql_dbg_dpc, base_vha, 0x4010,
6397                             "Loop resync end.\n");
6398                 }
6399 
6400                 if (IS_QLAFX00(ha))
6401                         goto intr_on_check;
6402 
6403                 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
6404                     atomic_read(&base_vha->loop_state) == LOOP_READY) {
6405                         clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
6406                         qla2xxx_flash_npiv_conf(base_vha);
6407                 }
6408 
6409 intr_on_check:
6410                 if (!ha->interrupts_on)
6411                         ha->isp_ops->enable_intrs(ha);
6412 
6413                 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
6414                                         &base_vha->dpc_flags)) {
6415                         if (ha->beacon_blink_led == 1)
6416                                 ha->isp_ops->beacon_blink(base_vha);
6417                 }
6418 
6419                 /* qpair online check */
6420                 if (test_and_clear_bit(QPAIR_ONLINE_CHECK_NEEDED,
6421                     &base_vha->dpc_flags)) {
6422                         if (ha->flags.eeh_busy ||
6423                             ha->flags.pci_channel_io_perm_failure)
6424                                 online = 0;
6425                         else
6426                                 online = 1;
6427 
6428                         mutex_lock(&ha->mq_lock);
6429                         list_for_each_entry(qpair, &base_vha->qp_list,
6430                             qp_list_elem)
6431                         qpair->online = online;
6432                         mutex_unlock(&ha->mq_lock);
6433                 }
6434 
6435                 if (test_and_clear_bit(SET_NVME_ZIO_THRESHOLD_NEEDED,
6436                     &base_vha->dpc_flags)) {
6437                         ql_log(ql_log_info, base_vha, 0xffffff,
6438                                 "nvme: SET ZIO Activity exchange threshold to %d.\n",
6439                                                 ha->nvme_last_rptd_aen);
6440                         if (qla27xx_set_zio_threshold(base_vha,
6441                             ha->nvme_last_rptd_aen)) {
6442                                 ql_log(ql_log_info, base_vha, 0xffffff,
6443                                     "nvme: Unable to SET ZIO Activity exchange threshold to %d.\n",
6444                                     ha->nvme_last_rptd_aen);
6445                         }
6446                 }
6447 
6448                 if (test_and_clear_bit(SET_ZIO_THRESHOLD_NEEDED,
6449                     &base_vha->dpc_flags)) {
6450                         ql_log(ql_log_info, base_vha, 0xffffff,
6451                             "SET ZIO Activity exchange threshold to %d.\n",
6452                             ha->last_zio_threshold);
6453                         qla27xx_set_zio_threshold(base_vha,
6454                             ha->last_zio_threshold);
6455                 }
6456 
6457                 if (!IS_QLAFX00(ha))
6458                         qla2x00_do_dpc_all_vps(base_vha);
6459 
6460                 if (test_and_clear_bit(N2N_LINK_RESET,
6461                         &base_vha->dpc_flags)) {
6462                         qla2x00_lip_reset(base_vha);
6463                 }
6464 
6465                 ha->dpc_active = 0;
6466 end_loop:
6467                 set_current_state(TASK_INTERRUPTIBLE);
6468         } /* End of while(1) */
6469         __set_current_state(TASK_RUNNING);
6470 
6471         ql_dbg(ql_dbg_dpc, base_vha, 0x4011,
6472             "DPC handler exiting.\n");
6473 
6474         /*
6475          * Make sure that nobody tries to wake us up again.
6476          */
6477         ha->dpc_active = 0;
6478 
6479         /* Cleanup any residual CTX SRBs. */
6480         qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
6481 
6482         return 0;
6483 }
6484 
6485 void
6486 qla2xxx_wake_dpc(struct scsi_qla_host *vha)
6487 {
6488         struct qla_hw_data *ha = vha->hw;
6489         struct task_struct *t = ha->dpc_thread;
6490 
6491         if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
6492                 wake_up_process(t);
6493 }
6494 
6495 /*
6496 *  qla2x00_rst_aen
6497 *      Processes asynchronous reset.
6498 *
6499 * Input:
6500 *      ha  = adapter block pointer.
6501 */
6502 static void
6503 qla2x00_rst_aen(scsi_qla_host_t *vha)
6504 {
6505         if (vha->flags.online && !vha->flags.reset_active &&
6506             !atomic_read(&vha->loop_down_timer) &&
6507             !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
6508                 do {
6509                         clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6510 
6511                         /*
6512                          * Issue marker command only when we are going to start
6513                          * the I/O.
6514                          */
6515                         vha->marker_needed = 1;
6516                 } while (!atomic_read(&vha->loop_down_timer) &&
6517                     (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
6518         }
6519 }
6520 
6521 /**************************************************************************
6522 *   qla2x00_timer
6523 *
6524 * Description:
6525 *   One second timer
6526 *
6527 * Context: Interrupt
6528 ***************************************************************************/
6529 void
6530 qla2x00_timer(struct timer_list *t)
6531 {
6532         scsi_qla_host_t *vha = from_timer(vha, t, timer);
6533         unsigned long   cpu_flags = 0;
6534         int             start_dpc = 0;
6535         int             index;
6536         srb_t           *sp;
6537         uint16_t        w;
6538         struct qla_hw_data *ha = vha->hw;
6539         struct req_que *req;
6540 
6541         if (ha->flags.eeh_busy) {
6542                 ql_dbg(ql_dbg_timer, vha, 0x6000,
6543                     "EEH = %d, restarting timer.\n",
6544                     ha->flags.eeh_busy);
6545                 qla2x00_restart_timer(vha, WATCH_INTERVAL);
6546                 return;
6547         }
6548 
6549         /*
6550          * Hardware read to raise pending EEH errors during mailbox waits. If
6551          * the read returns -1 then disable the board.
6552          */
6553         if (!pci_channel_offline(ha->pdev)) {
6554                 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
6555                 qla2x00_check_reg16_for_disconnect(vha, w);
6556         }
6557 
6558         /* Make sure qla82xx_watchdog is run only for physical port */
6559         if (!vha->vp_idx && IS_P3P_TYPE(ha)) {
6560                 if (test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags))
6561                         start_dpc++;
6562                 if (IS_QLA82XX(ha))
6563                         qla82xx_watchdog(vha);
6564                 else if (IS_QLA8044(ha))
6565                         qla8044_watchdog(vha);
6566         }
6567 
6568         if (!vha->vp_idx && IS_QLAFX00(ha))
6569                 qlafx00_timer_routine(vha);
6570 
6571         /* Loop down handler. */
6572         if (atomic_read(&vha->loop_down_timer) > 0 &&
6573             !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) &&
6574             !(test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags))
6575                 && vha->flags.online) {
6576 
6577                 if (atomic_read(&vha->loop_down_timer) ==
6578                     vha->loop_down_abort_time) {
6579 
6580                         ql_log(ql_log_info, vha, 0x6008,
6581                             "Loop down - aborting the queues before time expires.\n");
6582 
6583                         if (!IS_QLA2100(ha) && vha->link_down_timeout)
6584                                 atomic_set(&vha->loop_state, LOOP_DEAD);
6585 
6586                         /*
6587                          * Schedule an ISP abort to return any FCP2-device
6588                          * commands.
6589                          */
6590                         /* NPIV - scan physical port only */
6591                         if (!vha->vp_idx) {
6592                                 spin_lock_irqsave(&ha->hardware_lock,
6593                                     cpu_flags);
6594                                 req = ha->req_q_map[0];
6595                                 for (index = 1;
6596                                     index < req->num_outstanding_cmds;
6597                                     index++) {
6598                                         fc_port_t *sfcp;
6599 
6600                                         sp = req->outstanding_cmds[index];
6601                                         if (!sp)
6602                                                 continue;
6603                                         if (sp->cmd_type != TYPE_SRB)
6604                                                 continue;
6605                                         if (sp->type != SRB_SCSI_CMD)
6606                                                 continue;
6607                                         sfcp = sp->fcport;
6608                                         if (!(sfcp->flags & FCF_FCP2_DEVICE))
6609                                                 continue;
6610 
6611                                         if (IS_QLA82XX(ha))
6612                                                 set_bit(FCOE_CTX_RESET_NEEDED,
6613                                                         &vha->dpc_flags);
6614                                         else
6615                                                 set_bit(ISP_ABORT_NEEDED,
6616                                                         &vha->dpc_flags);
6617                                         break;
6618                                 }
6619                                 spin_unlock_irqrestore(&ha->hardware_lock,
6620                                                                 cpu_flags);
6621                         }
6622                         start_dpc++;
6623                 }
6624 
6625                 /* if the loop has been down for 4 minutes, reinit adapter */
6626                 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
6627                         if (!(vha->device_flags & DFLG_NO_CABLE)) {
6628                                 ql_log(ql_log_warn, vha, 0x6009,
6629                                     "Loop down - aborting ISP.\n");
6630 
6631                                 if (IS_QLA82XX(ha))
6632                                         set_bit(FCOE_CTX_RESET_NEEDED,
6633                                                 &vha->dpc_flags);
6634                                 else
6635                                         set_bit(ISP_ABORT_NEEDED,
6636                                                 &vha->dpc_flags);
6637                         }
6638                 }
6639                 ql_dbg(ql_dbg_timer, vha, 0x600a,
6640                     "Loop down - seconds remaining %d.\n",
6641                     atomic_read(&vha->loop_down_timer));
6642         }
6643         /* Check if beacon LED needs to be blinked for physical host only */
6644         if (!vha->vp_idx && (ha->beacon_blink_led == 1)) {
6645                 /* There is no beacon_blink function for ISP82xx */
6646                 if (!IS_P3P_TYPE(ha)) {
6647                         set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
6648                         start_dpc++;
6649                 }
6650         }
6651 
6652         /* Process any deferred work. */
6653         if (!list_empty(&vha->work_list)) {
6654                 unsigned long flags;
6655                 bool q = false;
6656 
6657                 spin_lock_irqsave(&vha->work_lock, flags);
6658                 if (!test_and_set_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags))
6659                         q = true;
6660                 spin_unlock_irqrestore(&vha->work_lock, flags);
6661                 if (q)
6662                         queue_work(vha->hw->wq, &vha->iocb_work);
6663         }
6664 
6665         /*
6666          * FC-NVME
6667          * see if the active AEN count has changed from what was last reported.
6668          */
6669         if (!vha->vp_idx &&
6670             (atomic_read(&ha->nvme_active_aen_cnt) != ha->nvme_last_rptd_aen) &&
6671             ha->zio_mode == QLA_ZIO_MODE_6 &&
6672             !ha->flags.host_shutting_down) {
6673                 ql_log(ql_log_info, vha, 0x3002,
6674                     "nvme: Sched: Set ZIO exchange threshold to %d.\n",
6675                     ha->nvme_last_rptd_aen);
6676                 ha->nvme_last_rptd_aen = atomic_read(&ha->nvme_active_aen_cnt);
6677                 set_bit(SET_NVME_ZIO_THRESHOLD_NEEDED, &vha->dpc_flags);
6678                 start_dpc++;
6679         }
6680 
6681         if (!vha->vp_idx &&
6682             (atomic_read(&ha->zio_threshold) != ha->last_zio_threshold) &&
6683             (ha->zio_mode == QLA_ZIO_MODE_6) &&
6684             (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))) {
6685                 ql_log(ql_log_info, vha, 0x3002,
6686                     "Sched: Set ZIO exchange threshold to %d.\n",
6687                     ha->last_zio_threshold);
6688                 ha->last_zio_threshold = atomic_read(&ha->zio_threshold);
6689                 set_bit(SET_ZIO_THRESHOLD_NEEDED, &vha->dpc_flags);
6690                 start_dpc++;
6691         }
6692 
6693         /* Schedule the DPC routine if needed */
6694         if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
6695             test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
6696             test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
6697             start_dpc ||
6698             test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
6699             test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
6700             test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) ||
6701             test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) ||
6702             test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
6703             test_bit(RELOGIN_NEEDED, &vha->dpc_flags))) {
6704                 ql_dbg(ql_dbg_timer, vha, 0x600b,
6705                     "isp_abort_needed=%d loop_resync_needed=%d "
6706                     "fcport_update_needed=%d start_dpc=%d "
6707                     "reset_marker_needed=%d",
6708                     test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags),
6709                     test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags),
6710                     test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags),
6711                     start_dpc,
6712                     test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags));
6713                 ql_dbg(ql_dbg_timer, vha, 0x600c,
6714                     "beacon_blink_needed=%d isp_unrecoverable=%d "
6715                     "fcoe_ctx_reset_needed=%d vp_dpc_needed=%d "
6716                     "relogin_needed=%d.\n",
6717                     test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags),
6718                     test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags),
6719                     test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags),
6720                     test_bit(VP_DPC_NEEDED, &vha->dpc_flags),
6721                     test_bit(RELOGIN_NEEDED, &vha->dpc_flags));
6722                 qla2xxx_wake_dpc(vha);
6723         }
6724 
6725         qla2x00_restart_timer(vha, WATCH_INTERVAL);
6726 }
6727 
6728 /* Firmware interface routines. */
6729 
6730 #define FW_ISP21XX      0
6731 #define FW_ISP22XX      1
6732 #define FW_ISP2300      2
6733 #define FW_ISP2322      3
6734 #define FW_ISP24XX      4
6735 #define FW_ISP25XX      5
6736 #define FW_ISP81XX      6
6737 #define FW_ISP82XX      7
6738 #define FW_ISP2031      8
6739 #define FW_ISP8031      9
6740 #define FW_ISP27XX      10
6741 #define FW_ISP28XX      11
6742 
6743 #define FW_FILE_ISP21XX "ql2100_fw.bin"
6744 #define FW_FILE_ISP22XX "ql2200_fw.bin"
6745 #define FW_FILE_ISP2300 "ql2300_fw.bin"
6746 #define FW_FILE_ISP2322 "ql2322_fw.bin"
6747 #define FW_FILE_ISP24XX "ql2400_fw.bin"
6748 #define FW_FILE_ISP25XX "ql2500_fw.bin"
6749 #define FW_FILE_ISP81XX "ql8100_fw.bin"
6750 #define FW_FILE_ISP82XX "ql8200_fw.bin"
6751 #define FW_FILE_ISP2031 "ql2600_fw.bin"
6752 #define FW_FILE_ISP8031 "ql8300_fw.bin"
6753 #define FW_FILE_ISP27XX "ql2700_fw.bin"
6754 #define FW_FILE_ISP28XX "ql2800_fw.bin"
6755 
6756 
6757 static DEFINE_MUTEX(qla_fw_lock);
6758 
6759 static struct fw_blob qla_fw_blobs[] = {
6760         { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
6761         { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
6762         { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
6763         { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
6764         { .name = FW_FILE_ISP24XX, },
6765         { .name = FW_FILE_ISP25XX, },
6766         { .name = FW_FILE_ISP81XX, },
6767         { .name = FW_FILE_ISP82XX, },
6768         { .name = FW_FILE_ISP2031, },
6769         { .name = FW_FILE_ISP8031, },
6770         { .name = FW_FILE_ISP27XX, },
6771         { .name = FW_FILE_ISP28XX, },
6772         { .name = NULL, },
6773 };
6774 
6775 struct fw_blob *
6776 qla2x00_request_firmware(scsi_qla_host_t *vha)
6777 {
6778         struct qla_hw_data *ha = vha->hw;
6779         struct fw_blob *blob;
6780 
6781         if (IS_QLA2100(ha)) {
6782                 blob = &qla_fw_blobs[FW_ISP21XX];
6783         } else if (IS_QLA2200(ha)) {
6784                 blob = &qla_fw_blobs[FW_ISP22XX];
6785         } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
6786                 blob = &qla_fw_blobs[FW_ISP2300];
6787         } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
6788                 blob = &qla_fw_blobs[FW_ISP2322];
6789         } else if (IS_QLA24XX_TYPE(ha)) {
6790                 blob = &qla_fw_blobs[FW_ISP24XX];
6791         } else if (IS_QLA25XX(ha)) {
6792                 blob = &qla_fw_blobs[FW_ISP25XX];
6793         } else if (IS_QLA81XX(ha)) {
6794                 blob = &qla_fw_blobs[FW_ISP81XX];
6795         } else if (IS_QLA82XX(ha)) {
6796                 blob = &qla_fw_blobs[FW_ISP82XX];
6797         } else if (IS_QLA2031(ha)) {
6798                 blob = &qla_fw_blobs[FW_ISP2031];
6799         } else if (IS_QLA8031(ha)) {
6800                 blob = &qla_fw_blobs[FW_ISP8031];
6801         } else if (IS_QLA27XX(ha)) {
6802                 blob = &qla_fw_blobs[FW_ISP27XX];
6803         } else if (IS_QLA28XX(ha)) {
6804                 blob = &qla_fw_blobs[FW_ISP28XX];
6805         } else {
6806                 return NULL;
6807         }
6808 
6809         if (!blob->name)
6810                 return NULL;
6811 
6812         mutex_lock(&qla_fw_lock);
6813         if (blob->fw)
6814                 goto out;
6815 
6816         if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
6817                 ql_log(ql_log_warn, vha, 0x0063,
6818                     "Failed to load firmware image (%s).\n", blob->name);
6819                 blob->fw = NULL;
6820                 blob = NULL;
6821         }
6822 
6823 out:
6824         mutex_unlock(&qla_fw_lock);
6825         return blob;
6826 }
6827 
6828 static void
6829 qla2x00_release_firmware(void)
6830 {
6831         struct fw_blob *blob;
6832 
6833         mutex_lock(&qla_fw_lock);
6834         for (blob = qla_fw_blobs; blob->name; blob++)
6835                 release_firmware(blob->fw);
6836         mutex_unlock(&qla_fw_lock);
6837 }
6838 
6839 static void qla_pci_error_cleanup(scsi_qla_host_t *vha)
6840 {
6841         struct qla_hw_data *ha = vha->hw;
6842         scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
6843         struct qla_qpair *qpair = NULL;
6844         struct scsi_qla_host *vp;
6845         fc_port_t *fcport;
6846         int i;
6847         unsigned long flags;
6848 
6849         ha->chip_reset++;
6850 
6851         ha->base_qpair->chip_reset = ha->chip_reset;
6852         for (i = 0; i < ha->max_qpairs; i++) {
6853                 if (ha->queue_pair_map[i])
6854                         ha->queue_pair_map[i]->chip_reset =
6855                             ha->base_qpair->chip_reset;
6856         }
6857 
6858         /* purge MBox commands */
6859         if (atomic_read(&ha->num_pend_mbx_stage3)) {
6860                 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
6861                 complete(&ha->mbx_intr_comp);
6862         }
6863 
6864         i = 0;
6865 
6866         while (atomic_read(&ha->num_pend_mbx_stage3) ||
6867             atomic_read(&ha->num_pend_mbx_stage2) ||
6868             atomic_read(&ha->num_pend_mbx_stage1)) {
6869                 msleep(20);
6870                 i++;
6871                 if (i > 50)
6872                         break;
6873         }
6874 
6875         ha->flags.purge_mbox = 0;
6876 
6877         mutex_lock(&ha->mq_lock);
6878         list_for_each_entry(qpair, &base_vha->qp_list, qp_list_elem)
6879                 qpair->online = 0;
6880         mutex_unlock(&ha->mq_lock);
6881 
6882         qla2x00_mark_all_devices_lost(vha, 0);
6883 
6884         spin_lock_irqsave(&ha->vport_slock, flags);
6885         list_for_each_entry(vp, &ha->vp_list, list) {
6886                 atomic_inc(&vp->vref_count);
6887                 spin_unlock_irqrestore(&ha->vport_slock, flags);
6888                 qla2x00_mark_all_devices_lost(vp, 0);
6889                 spin_lock_irqsave(&ha->vport_slock, flags);
6890                 atomic_dec(&vp->vref_count);
6891         }
6892         spin_unlock_irqrestore(&ha->vport_slock, flags);
6893 
6894         /* Clear all async request states across all VPs. */
6895         list_for_each_entry(fcport, &vha->vp_fcports, list)
6896                 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6897 
6898         spin_lock_irqsave(&ha->vport_slock, flags);
6899         list_for_each_entry(vp, &ha->vp_list, list) {
6900                 atomic_inc(&vp->vref_count);
6901                 spin_unlock_irqrestore(&ha->vport_slock, flags);
6902                 list_for_each_entry(fcport, &vp->vp_fcports, list)
6903                         fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6904                 spin_lock_irqsave(&ha->vport_slock, flags);
6905                 atomic_dec(&vp->vref_count);
6906         }
6907         spin_unlock_irqrestore(&ha->vport_slock, flags);
6908 }
6909 
6910 
6911 static pci_ers_result_t
6912 qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
6913 {
6914         scsi_qla_host_t *vha = pci_get_drvdata(pdev);
6915         struct qla_hw_data *ha = vha->hw;
6916 
6917         ql_dbg(ql_dbg_aer, vha, 0x9000,
6918             "PCI error detected, state %x.\n", state);
6919 
6920         if (!atomic_read(&pdev->enable_cnt)) {
6921                 ql_log(ql_log_info, vha, 0xffff,
6922                         "PCI device is disabled,state %x\n", state);
6923                 return PCI_ERS_RESULT_NEED_RESET;
6924         }
6925 
6926         switch (state) {
6927         case pci_channel_io_normal:
6928                 ha->flags.eeh_busy = 0;
6929                 if (ql2xmqsupport || ql2xnvmeenable) {
6930                         set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
6931                         qla2xxx_wake_dpc(vha);
6932                 }
6933                 return PCI_ERS_RESULT_CAN_RECOVER;
6934         case pci_channel_io_frozen:
6935                 ha->flags.eeh_busy = 1;
6936                 qla_pci_error_cleanup(vha);
6937                 return PCI_ERS_RESULT_NEED_RESET;
6938         case pci_channel_io_perm_failure:
6939                 ha->flags.pci_channel_io_perm_failure = 1;
6940                 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
6941                 if (ql2xmqsupport || ql2xnvmeenable) {
6942                         set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
6943                         qla2xxx_wake_dpc(vha);
6944                 }
6945                 return PCI_ERS_RESULT_DISCONNECT;
6946         }
6947         return PCI_ERS_RESULT_NEED_RESET;
6948 }
6949 
6950 static pci_ers_result_t
6951 qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
6952 {
6953         int risc_paused = 0;
6954         uint32_t stat;
6955         unsigned long flags;
6956         scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
6957         struct qla_hw_data *ha = base_vha->hw;
6958         struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
6959         struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
6960 
6961         if (IS_QLA82XX(ha))
6962                 return PCI_ERS_RESULT_RECOVERED;
6963 
6964         spin_lock_irqsave(&ha->hardware_lock, flags);
6965         if (IS_QLA2100(ha) || IS_QLA2200(ha)){
6966                 stat = RD_REG_DWORD(&reg->hccr);
6967                 if (stat & HCCR_RISC_PAUSE)
6968                         risc_paused = 1;
6969         } else if (IS_QLA23XX(ha)) {
6970                 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
6971                 if (stat & HSR_RISC_PAUSED)
6972                         risc_paused = 1;
6973         } else if (IS_FWI2_CAPABLE(ha)) {
6974                 stat = RD_REG_DWORD(&reg24->host_status);
6975                 if (stat & HSRX_RISC_PAUSED)
6976                         risc_paused = 1;
6977         }
6978         spin_unlock_irqrestore(&ha->hardware_lock, flags);
6979 
6980         if (risc_paused) {
6981                 ql_log(ql_log_info, base_vha, 0x9003,
6982                     "RISC paused -- mmio_enabled, Dumping firmware.\n");
6983                 ha->isp_ops->fw_dump(base_vha, 0);
6984 
6985                 return PCI_ERS_RESULT_NEED_RESET;
6986         } else
6987                 return PCI_ERS_RESULT_RECOVERED;
6988 }
6989 
6990 static pci_ers_result_t
6991 qla2xxx_pci_slot_reset(struct pci_dev *pdev)
6992 {
6993         pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
6994         scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
6995         struct qla_hw_data *ha = base_vha->hw;
6996         int rc;
6997         struct qla_qpair *qpair = NULL;
6998 
6999         ql_dbg(ql_dbg_aer, base_vha, 0x9004,
7000             "Slot Reset.\n");
7001 
7002         /* Workaround: qla2xxx driver which access hardware earlier
7003          * needs error state to be pci_channel_io_online.
7004          * Otherwise mailbox command timesout.
7005          */
7006         pdev->error_state = pci_channel_io_normal;
7007 
7008         pci_restore_state(pdev);
7009 
7010         /* pci_restore_state() clears the saved_state flag of the device
7011          * save restored state which resets saved_state flag
7012          */
7013         pci_save_state(pdev);
7014 
7015         if (ha->mem_only)
7016                 rc = pci_enable_device_mem(pdev);
7017         else
7018                 rc = pci_enable_device(pdev);
7019 
7020         if (rc) {
7021                 ql_log(ql_log_warn, base_vha, 0x9005,
7022                     "Can't re-enable PCI device after reset.\n");
7023                 goto exit_slot_reset;
7024         }
7025 
7026 
7027         if (ha->isp_ops->pci_config(base_vha))
7028                 goto exit_slot_reset;
7029 
7030         mutex_lock(&ha->mq_lock);
7031         list_for_each_entry(qpair, &base_vha->qp_list, qp_list_elem)
7032                 qpair->online = 1;
7033         mutex_unlock(&ha->mq_lock);
7034 
7035         base_vha->flags.online = 1;
7036         set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
7037         if (ha->isp_ops->abort_isp(base_vha) == QLA_SUCCESS)
7038                 ret =  PCI_ERS_RESULT_RECOVERED;
7039         clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
7040 
7041 
7042 exit_slot_reset:
7043         ql_dbg(ql_dbg_aer, base_vha, 0x900e,
7044             "slot_reset return %x.\n", ret);
7045 
7046         return ret;
7047 }
7048 
7049 static void
7050 qla2xxx_pci_resume(struct pci_dev *pdev)
7051 {
7052         scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
7053         struct qla_hw_data *ha = base_vha->hw;
7054         int ret;
7055 
7056         ql_dbg(ql_dbg_aer, base_vha, 0x900f,
7057             "pci_resume.\n");
7058 
7059         ha->flags.eeh_busy = 0;
7060 
7061         ret = qla2x00_wait_for_hba_online(base_vha);
7062         if (ret != QLA_SUCCESS) {
7063                 ql_log(ql_log_fatal, base_vha, 0x9002,
7064                     "The device failed to resume I/O from slot/link_reset.\n");
7065         }
7066 }
7067 
7068 static void
7069 qla_pci_reset_prepare(struct pci_dev *pdev)
7070 {
7071         scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
7072         struct qla_hw_data *ha = base_vha->hw;
7073         struct qla_qpair *qpair;
7074 
7075         ql_log(ql_log_warn, base_vha, 0xffff,
7076             "%s.\n", __func__);
7077 
7078         /*
7079          * PCI FLR/function reset is about to reset the
7080          * slot. Stop the chip to stop all DMA access.
7081          * It is assumed that pci_reset_done will be called
7082          * after FLR to resume Chip operation.
7083          */
7084         ha->flags.eeh_busy = 1;
7085         mutex_lock(&ha->mq_lock);
7086         list_for_each_entry(qpair, &base_vha->qp_list, qp_list_elem)
7087                 qpair->online = 0;
7088         mutex_unlock(&ha->mq_lock);
7089 
7090         set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
7091         qla2x00_abort_isp_cleanup(base_vha);
7092         qla2x00_abort_all_cmds(base_vha, DID_RESET << 16);
7093 }
7094 
7095 static void
7096 qla_pci_reset_done(struct pci_dev *pdev)
7097 {
7098         scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
7099         struct qla_hw_data *ha = base_vha->hw;
7100         struct qla_qpair *qpair;
7101 
7102         ql_log(ql_log_warn, base_vha, 0xffff,
7103             "%s.\n", __func__);
7104 
7105         /*
7106          * FLR just completed by PCI layer. Resume adapter
7107          */
7108         ha->flags.eeh_busy = 0;
7109         mutex_lock(&ha->mq_lock);
7110         list_for_each_entry(qpair, &base_vha->qp_list, qp_list_elem)
7111                 qpair->online = 1;
7112         mutex_unlock(&ha->mq_lock);
7113 
7114         base_vha->flags.online = 1;
7115         ha->isp_ops->abort_isp(base_vha);
7116         clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
7117 }
7118 
7119 static int qla2xxx_map_queues(struct Scsi_Host *shost)
7120 {
7121         int rc;
7122         scsi_qla_host_t *vha = (scsi_qla_host_t *)shost->hostdata;
7123         struct blk_mq_queue_map *qmap = &shost->tag_set.map[HCTX_TYPE_DEFAULT];
7124 
7125         if (USER_CTRL_IRQ(vha->hw) || !vha->hw->mqiobase)
7126                 rc = blk_mq_map_queues(qmap);
7127         else
7128                 rc = blk_mq_pci_map_queues(qmap, vha->hw->pdev, vha->irq_offset);
7129         return rc;
7130 }
7131 
7132 struct scsi_host_template qla2xxx_driver_template = {
7133         .module                 = THIS_MODULE,
7134         .name                   = QLA2XXX_DRIVER_NAME,
7135         .queuecommand           = qla2xxx_queuecommand,
7136 
7137         .eh_timed_out           = fc_eh_timed_out,
7138         .eh_abort_handler       = qla2xxx_eh_abort,
7139         .eh_device_reset_handler = qla2xxx_eh_device_reset,
7140         .eh_target_reset_handler = qla2xxx_eh_target_reset,
7141         .eh_bus_reset_handler   = qla2xxx_eh_bus_reset,
7142         .eh_host_reset_handler  = qla2xxx_eh_host_reset,
7143 
7144         .slave_configure        = qla2xxx_slave_configure,
7145 
7146         .slave_alloc            = qla2xxx_slave_alloc,
7147         .slave_destroy          = qla2xxx_slave_destroy,
7148         .scan_finished          = qla2xxx_scan_finished,
7149         .scan_start             = qla2xxx_scan_start,
7150         .change_queue_depth     = scsi_change_queue_depth,
7151         .map_queues             = qla2xxx_map_queues,
7152         .this_id                = -1,
7153         .cmd_per_lun            = 3,
7154         .sg_tablesize           = SG_ALL,
7155 
7156         .max_sectors            = 0xFFFF,
7157         .shost_attrs            = qla2x00_host_attrs,
7158 
7159         .supported_mode         = MODE_INITIATOR,
7160         .track_queue_depth      = 1,
7161         .cmd_size               = sizeof(srb_t),
7162 };
7163 
7164 static const struct pci_error_handlers qla2xxx_err_handler = {
7165         .error_detected = qla2xxx_pci_error_detected,
7166         .mmio_enabled = qla2xxx_pci_mmio_enabled,
7167         .slot_reset = qla2xxx_pci_slot_reset,
7168         .resume = qla2xxx_pci_resume,
7169         .reset_prepare = qla_pci_reset_prepare,
7170         .reset_done = qla_pci_reset_done,
7171 };
7172 
7173 static struct pci_device_id qla2xxx_pci_tbl[] = {
7174         { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
7175         { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
7176         { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
7177         { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
7178         { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
7179         { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
7180         { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
7181         { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
7182         { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
7183         { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
7184         { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
7185         { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
7186         { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
7187         { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2031) },
7188         { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
7189         { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) },
7190         { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8031) },
7191         { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISPF001) },
7192         { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8044) },
7193         { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2071) },
7194         { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2271) },
7195         { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2261) },
7196         { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2061) },
7197         { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2081) },
7198         { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2281) },
7199         { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2089) },
7200         { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2289) },
7201         { 0 },
7202 };
7203 MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
7204 
7205 static struct pci_driver qla2xxx_pci_driver = {
7206         .name           = QLA2XXX_DRIVER_NAME,
7207         .driver         = {
7208                 .owner          = THIS_MODULE,
7209         },
7210         .id_table       = qla2xxx_pci_tbl,
7211         .probe          = qla2x00_probe_one,
7212         .remove         = qla2x00_remove_one,
7213         .shutdown       = qla2x00_shutdown,
7214         .err_handler    = &qla2xxx_err_handler,
7215 };
7216 
7217 static const struct file_operations apidev_fops = {
7218         .owner = THIS_MODULE,
7219         .llseek = noop_llseek,
7220 };
7221 
7222 /**
7223  * qla2x00_module_init - Module initialization.
7224  **/
7225 static int __init
7226 qla2x00_module_init(void)
7227 {
7228         int ret = 0;
7229 
7230         BUILD_BUG_ON(sizeof(cmd_entry_t) != 64);
7231         BUILD_BUG_ON(sizeof(cont_a64_entry_t) != 64);
7232         BUILD_BUG_ON(sizeof(cont_entry_t) != 64);
7233         BUILD_BUG_ON(sizeof(init_cb_t) != 96);
7234         BUILD_BUG_ON(sizeof(ms_iocb_entry_t) != 64);
7235         BUILD_BUG_ON(sizeof(request_t) != 64);
7236         BUILD_BUG_ON(sizeof(struct access_chip_84xx) != 64);
7237         BUILD_BUG_ON(sizeof(struct cmd_bidir) != 64);
7238         BUILD_BUG_ON(sizeof(struct cmd_nvme) != 64);
7239         BUILD_BUG_ON(sizeof(struct cmd_type_6) != 64);
7240         BUILD_BUG_ON(sizeof(struct cmd_type_7) != 64);
7241         BUILD_BUG_ON(sizeof(struct cmd_type_7_fx00) != 64);
7242         BUILD_BUG_ON(sizeof(struct cmd_type_crc_2) != 64);
7243         BUILD_BUG_ON(sizeof(struct ct_entry_24xx) != 64);
7244         BUILD_BUG_ON(sizeof(struct ctio_crc2_to_fw) != 64);
7245         BUILD_BUG_ON(sizeof(struct els_entry_24xx) != 64);
7246         BUILD_BUG_ON(sizeof(struct fxdisc_entry_fx00) != 64);
7247         BUILD_BUG_ON(sizeof(struct init_cb_24xx) != 128);
7248         BUILD_BUG_ON(sizeof(struct init_cb_81xx) != 128);
7249         BUILD_BUG_ON(sizeof(struct pt_ls4_request) != 64);
7250         BUILD_BUG_ON(sizeof(struct sns_cmd_pkt) != 2064);
7251         BUILD_BUG_ON(sizeof(struct verify_chip_entry_84xx) != 64);
7252         BUILD_BUG_ON(sizeof(struct vf_evfp_entry_24xx) != 56);
7253 
7254         /* Allocate cache for SRBs. */
7255         srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
7256             SLAB_HWCACHE_ALIGN, NULL);
7257         if (srb_cachep == NULL) {
7258                 ql_log(ql_log_fatal, NULL, 0x0001,
7259                     "Unable to allocate SRB cache...Failing load!.\n");
7260                 return -ENOMEM;
7261         }
7262 
7263         /* Initialize target kmem_cache and mem_pools */
7264         ret = qlt_init();
7265         if (ret < 0) {
7266                 goto destroy_cache;
7267         } else if (ret > 0) {
7268                 /*
7269                  * If initiator mode is explictly disabled by qlt_init(),
7270                  * prevent scsi_transport_fc.c:fc_scsi_scan_rport() from
7271                  * performing scsi_scan_target() during LOOP UP event.
7272                  */
7273                 qla2xxx_transport_functions.disable_target_scan = 1;
7274                 qla2xxx_transport_vport_functions.disable_target_scan = 1;
7275         }
7276 
7277         /* Derive version string. */
7278         strcpy(qla2x00_version_str, QLA2XXX_VERSION);
7279         if (ql2xextended_error_logging)
7280                 strcat(qla2x00_version_str, "-debug");
7281         if (ql2xextended_error_logging == 1)
7282                 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
7283 
7284         if (ql2x_ini_mode == QLA2XXX_INI_MODE_DUAL)
7285                 qla_insert_tgt_attrs();
7286 
7287         qla2xxx_transport_template =
7288             fc_attach_transport(&qla2xxx_transport_functions);
7289         if (!qla2xxx_transport_template) {
7290                 ql_log(ql_log_fatal, NULL, 0x0002,
7291                     "fc_attach_transport failed...Failing load!.\n");
7292                 ret = -ENODEV;
7293                 goto qlt_exit;
7294         }
7295 
7296         apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops);
7297         if (apidev_major < 0) {
7298                 ql_log(ql_log_fatal, NULL, 0x0003,
7299                     "Unable to register char device %s.\n", QLA2XXX_APIDEV);
7300         }
7301 
7302         qla2xxx_transport_vport_template =
7303             fc_attach_transport(&qla2xxx_transport_vport_functions);
7304         if (!qla2xxx_transport_vport_template) {
7305                 ql_log(ql_log_fatal, NULL, 0x0004,
7306                     "fc_attach_transport vport failed...Failing load!.\n");
7307                 ret = -ENODEV;
7308                 goto unreg_chrdev;
7309         }
7310         ql_log(ql_log_info, NULL, 0x0005,
7311             "QLogic Fibre Channel HBA Driver: %s.\n",
7312             qla2x00_version_str);
7313         ret = pci_register_driver(&qla2xxx_pci_driver);
7314         if (ret) {
7315                 ql_log(ql_log_fatal, NULL, 0x0006,
7316                     "pci_register_driver failed...ret=%d Failing load!.\n",
7317                     ret);
7318                 goto release_vport_transport;
7319         }
7320         return ret;
7321 
7322 release_vport_transport:
7323         fc_release_transport(qla2xxx_transport_vport_template);
7324 
7325 unreg_chrdev:
7326         if (apidev_major >= 0)
7327                 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
7328         fc_release_transport(qla2xxx_transport_template);
7329 
7330 qlt_exit:
7331         qlt_exit();
7332 
7333 destroy_cache:
7334         kmem_cache_destroy(srb_cachep);
7335         return ret;
7336 }
7337 
7338 /**
7339  * qla2x00_module_exit - Module cleanup.
7340  **/
7341 static void __exit
7342 qla2x00_module_exit(void)
7343 {
7344         pci_unregister_driver(&qla2xxx_pci_driver);
7345         qla2x00_release_firmware();
7346         kmem_cache_destroy(ctx_cachep);
7347         fc_release_transport(qla2xxx_transport_vport_template);
7348         if (apidev_major >= 0)
7349                 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
7350         fc_release_transport(qla2xxx_transport_template);
7351         qlt_exit();
7352         kmem_cache_destroy(srb_cachep);
7353 }
7354 
7355 module_init(qla2x00_module_init);
7356 module_exit(qla2x00_module_exit);
7357 
7358 MODULE_AUTHOR("QLogic Corporation");
7359 MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
7360 MODULE_LICENSE("GPL");
7361 MODULE_VERSION(QLA2XXX_VERSION);
7362 MODULE_FIRMWARE(FW_FILE_ISP21XX);
7363 MODULE_FIRMWARE(FW_FILE_ISP22XX);
7364 MODULE_FIRMWARE(FW_FILE_ISP2300);
7365 MODULE_FIRMWARE(FW_FILE_ISP2322);
7366 MODULE_FIRMWARE(FW_FILE_ISP24XX);
7367 MODULE_FIRMWARE(FW_FILE_ISP25XX);

/* [<][>][^][v][top][bottom][index][help] */