PageRenderTime 96ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 1ms

/drivers/scsi/qla2xxx/qla_os.c

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