/drivers/scsi/lpfc/lpfc_init.c

https://bitbucket.org/alfredchen/linux-gc · C · 12172 lines · 8003 code · 1192 blank · 2977 comment · 1194 complexity · a0c3b4ae19d36e3c38b849d13cf70e37 MD5 · raw file

Large files are truncated click here to view the full file

  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2017 Broadcom. All Rights Reserved. The term *
  5. * “Broadcom” refers to Broadcom Limited and/or its subsidiaries. *
  6. * Copyright (C) 2004-2016 Emulex. All rights reserved. *
  7. * EMULEX and SLI are trademarks of Emulex. *
  8. * www.broadcom.com *
  9. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  10. * *
  11. * This program is free software; you can redistribute it and/or *
  12. * modify it under the terms of version 2 of the GNU General *
  13. * Public License as published by the Free Software Foundation. *
  14. * This program is distributed in the hope that it will be useful. *
  15. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  16. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  17. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  18. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  19. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  20. * more details, a copy of which can be found in the file COPYING *
  21. * included with this package. *
  22. *******************************************************************/
  23. #include <linux/blkdev.h>
  24. #include <linux/delay.h>
  25. #include <linux/dma-mapping.h>
  26. #include <linux/idr.h>
  27. #include <linux/interrupt.h>
  28. #include <linux/module.h>
  29. #include <linux/kthread.h>
  30. #include <linux/pci.h>
  31. #include <linux/spinlock.h>
  32. #include <linux/ctype.h>
  33. #include <linux/aer.h>
  34. #include <linux/slab.h>
  35. #include <linux/firmware.h>
  36. #include <linux/miscdevice.h>
  37. #include <linux/percpu.h>
  38. #include <linux/msi.h>
  39. #include <scsi/scsi.h>
  40. #include <scsi/scsi_device.h>
  41. #include <scsi/scsi_host.h>
  42. #include <scsi/scsi_transport_fc.h>
  43. #include "lpfc_hw4.h"
  44. #include "lpfc_hw.h"
  45. #include "lpfc_sli.h"
  46. #include "lpfc_sli4.h"
  47. #include "lpfc_nl.h"
  48. #include "lpfc_disc.h"
  49. #include "lpfc.h"
  50. #include "lpfc_scsi.h"
  51. #include "lpfc_nvme.h"
  52. #include "lpfc_logmsg.h"
  53. #include "lpfc_crtn.h"
  54. #include "lpfc_vport.h"
  55. #include "lpfc_version.h"
  56. #include "lpfc_ids.h"
  57. char *_dump_buf_data;
  58. unsigned long _dump_buf_data_order;
  59. char *_dump_buf_dif;
  60. unsigned long _dump_buf_dif_order;
  61. spinlock_t _dump_buf_lock;
  62. /* Used when mapping IRQ vectors in a driver centric manner */
  63. uint16_t *lpfc_used_cpu;
  64. uint32_t lpfc_present_cpu;
  65. static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
  66. static int lpfc_post_rcv_buf(struct lpfc_hba *);
  67. static int lpfc_sli4_queue_verify(struct lpfc_hba *);
  68. static int lpfc_create_bootstrap_mbox(struct lpfc_hba *);
  69. static int lpfc_setup_endian_order(struct lpfc_hba *);
  70. static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *);
  71. static void lpfc_free_els_sgl_list(struct lpfc_hba *);
  72. static void lpfc_free_nvmet_sgl_list(struct lpfc_hba *);
  73. static void lpfc_init_sgl_list(struct lpfc_hba *);
  74. static int lpfc_init_active_sgl_array(struct lpfc_hba *);
  75. static void lpfc_free_active_sgl(struct lpfc_hba *);
  76. static int lpfc_hba_down_post_s3(struct lpfc_hba *phba);
  77. static int lpfc_hba_down_post_s4(struct lpfc_hba *phba);
  78. static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *);
  79. static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *);
  80. static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *);
  81. static void lpfc_sli4_disable_intr(struct lpfc_hba *);
  82. static uint32_t lpfc_sli4_enable_intr(struct lpfc_hba *, uint32_t);
  83. static void lpfc_sli4_oas_verify(struct lpfc_hba *phba);
  84. static struct scsi_transport_template *lpfc_transport_template = NULL;
  85. static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
  86. static DEFINE_IDR(lpfc_hba_index);
  87. #define LPFC_NVMET_BUF_POST 254
  88. /**
  89. * lpfc_config_port_prep - Perform lpfc initialization prior to config port
  90. * @phba: pointer to lpfc hba data structure.
  91. *
  92. * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
  93. * mailbox command. It retrieves the revision information from the HBA and
  94. * collects the Vital Product Data (VPD) about the HBA for preparing the
  95. * configuration of the HBA.
  96. *
  97. * Return codes:
  98. * 0 - success.
  99. * -ERESTART - requests the SLI layer to reset the HBA and try again.
  100. * Any other value - indicates an error.
  101. **/
  102. int
  103. lpfc_config_port_prep(struct lpfc_hba *phba)
  104. {
  105. lpfc_vpd_t *vp = &phba->vpd;
  106. int i = 0, rc;
  107. LPFC_MBOXQ_t *pmb;
  108. MAILBOX_t *mb;
  109. char *lpfc_vpd_data = NULL;
  110. uint16_t offset = 0;
  111. static char licensed[56] =
  112. "key unlock for use with gnu public licensed code only\0";
  113. static int init_key = 1;
  114. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  115. if (!pmb) {
  116. phba->link_state = LPFC_HBA_ERROR;
  117. return -ENOMEM;
  118. }
  119. mb = &pmb->u.mb;
  120. phba->link_state = LPFC_INIT_MBX_CMDS;
  121. if (lpfc_is_LC_HBA(phba->pcidev->device)) {
  122. if (init_key) {
  123. uint32_t *ptext = (uint32_t *) licensed;
  124. for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
  125. *ptext = cpu_to_be32(*ptext);
  126. init_key = 0;
  127. }
  128. lpfc_read_nv(phba, pmb);
  129. memset((char*)mb->un.varRDnvp.rsvd3, 0,
  130. sizeof (mb->un.varRDnvp.rsvd3));
  131. memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
  132. sizeof (licensed));
  133. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  134. if (rc != MBX_SUCCESS) {
  135. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  136. "0324 Config Port initialization "
  137. "error, mbxCmd x%x READ_NVPARM, "
  138. "mbxStatus x%x\n",
  139. mb->mbxCommand, mb->mbxStatus);
  140. mempool_free(pmb, phba->mbox_mem_pool);
  141. return -ERESTART;
  142. }
  143. memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
  144. sizeof(phba->wwnn));
  145. memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
  146. sizeof(phba->wwpn));
  147. }
  148. phba->sli3_options = 0x0;
  149. /* Setup and issue mailbox READ REV command */
  150. lpfc_read_rev(phba, pmb);
  151. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  152. if (rc != MBX_SUCCESS) {
  153. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  154. "0439 Adapter failed to init, mbxCmd x%x "
  155. "READ_REV, mbxStatus x%x\n",
  156. mb->mbxCommand, mb->mbxStatus);
  157. mempool_free( pmb, phba->mbox_mem_pool);
  158. return -ERESTART;
  159. }
  160. /*
  161. * The value of rr must be 1 since the driver set the cv field to 1.
  162. * This setting requires the FW to set all revision fields.
  163. */
  164. if (mb->un.varRdRev.rr == 0) {
  165. vp->rev.rBit = 0;
  166. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  167. "0440 Adapter failed to init, READ_REV has "
  168. "missing revision information.\n");
  169. mempool_free(pmb, phba->mbox_mem_pool);
  170. return -ERESTART;
  171. }
  172. if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) {
  173. mempool_free(pmb, phba->mbox_mem_pool);
  174. return -EINVAL;
  175. }
  176. /* Save information as VPD data */
  177. vp->rev.rBit = 1;
  178. memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
  179. vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
  180. memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
  181. vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
  182. memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
  183. vp->rev.biuRev = mb->un.varRdRev.biuRev;
  184. vp->rev.smRev = mb->un.varRdRev.smRev;
  185. vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
  186. vp->rev.endecRev = mb->un.varRdRev.endecRev;
  187. vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
  188. vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
  189. vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
  190. vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
  191. vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
  192. vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
  193. /* If the sli feature level is less then 9, we must
  194. * tear down all RPIs and VPIs on link down if NPIV
  195. * is enabled.
  196. */
  197. if (vp->rev.feaLevelHigh < 9)
  198. phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
  199. if (lpfc_is_LC_HBA(phba->pcidev->device))
  200. memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
  201. sizeof (phba->RandomData));
  202. /* Get adapter VPD information */
  203. lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
  204. if (!lpfc_vpd_data)
  205. goto out_free_mbox;
  206. do {
  207. lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD);
  208. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  209. if (rc != MBX_SUCCESS) {
  210. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  211. "0441 VPD not present on adapter, "
  212. "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
  213. mb->mbxCommand, mb->mbxStatus);
  214. mb->un.varDmp.word_cnt = 0;
  215. }
  216. /* dump mem may return a zero when finished or we got a
  217. * mailbox error, either way we are done.
  218. */
  219. if (mb->un.varDmp.word_cnt == 0)
  220. break;
  221. if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
  222. mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
  223. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  224. lpfc_vpd_data + offset,
  225. mb->un.varDmp.word_cnt);
  226. offset += mb->un.varDmp.word_cnt;
  227. } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
  228. lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
  229. kfree(lpfc_vpd_data);
  230. out_free_mbox:
  231. mempool_free(pmb, phba->mbox_mem_pool);
  232. return 0;
  233. }
  234. /**
  235. * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd
  236. * @phba: pointer to lpfc hba data structure.
  237. * @pmboxq: pointer to the driver internal queue element for mailbox command.
  238. *
  239. * This is the completion handler for driver's configuring asynchronous event
  240. * mailbox command to the device. If the mailbox command returns successfully,
  241. * it will set internal async event support flag to 1; otherwise, it will
  242. * set internal async event support flag to 0.
  243. **/
  244. static void
  245. lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
  246. {
  247. if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS)
  248. phba->temp_sensor_support = 1;
  249. else
  250. phba->temp_sensor_support = 0;
  251. mempool_free(pmboxq, phba->mbox_mem_pool);
  252. return;
  253. }
  254. /**
  255. * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler
  256. * @phba: pointer to lpfc hba data structure.
  257. * @pmboxq: pointer to the driver internal queue element for mailbox command.
  258. *
  259. * This is the completion handler for dump mailbox command for getting
  260. * wake up parameters. When this command complete, the response contain
  261. * Option rom version of the HBA. This function translate the version number
  262. * into a human readable string and store it in OptionROMVersion.
  263. **/
  264. static void
  265. lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
  266. {
  267. struct prog_id *prg;
  268. uint32_t prog_id_word;
  269. char dist = ' ';
  270. /* character array used for decoding dist type. */
  271. char dist_char[] = "nabx";
  272. if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) {
  273. mempool_free(pmboxq, phba->mbox_mem_pool);
  274. return;
  275. }
  276. prg = (struct prog_id *) &prog_id_word;
  277. /* word 7 contain option rom version */
  278. prog_id_word = pmboxq->u.mb.un.varWords[7];
  279. /* Decode the Option rom version word to a readable string */
  280. if (prg->dist < 4)
  281. dist = dist_char[prg->dist];
  282. if ((prg->dist == 3) && (prg->num == 0))
  283. snprintf(phba->OptionROMVersion, 32, "%d.%d%d",
  284. prg->ver, prg->rev, prg->lev);
  285. else
  286. snprintf(phba->OptionROMVersion, 32, "%d.%d%d%c%d",
  287. prg->ver, prg->rev, prg->lev,
  288. dist, prg->num);
  289. mempool_free(pmboxq, phba->mbox_mem_pool);
  290. return;
  291. }
  292. /**
  293. * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname,
  294. * cfg_soft_wwnn, cfg_soft_wwpn
  295. * @vport: pointer to lpfc vport data structure.
  296. *
  297. *
  298. * Return codes
  299. * None.
  300. **/
  301. void
  302. lpfc_update_vport_wwn(struct lpfc_vport *vport)
  303. {
  304. /* If the soft name exists then update it using the service params */
  305. if (vport->phba->cfg_soft_wwnn)
  306. u64_to_wwn(vport->phba->cfg_soft_wwnn,
  307. vport->fc_sparam.nodeName.u.wwn);
  308. if (vport->phba->cfg_soft_wwpn)
  309. u64_to_wwn(vport->phba->cfg_soft_wwpn,
  310. vport->fc_sparam.portName.u.wwn);
  311. /*
  312. * If the name is empty or there exists a soft name
  313. * then copy the service params name, otherwise use the fc name
  314. */
  315. if (vport->fc_nodename.u.wwn[0] == 0 || vport->phba->cfg_soft_wwnn)
  316. memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
  317. sizeof(struct lpfc_name));
  318. else
  319. memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename,
  320. sizeof(struct lpfc_name));
  321. if (vport->fc_portname.u.wwn[0] == 0 || vport->phba->cfg_soft_wwpn)
  322. memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
  323. sizeof(struct lpfc_name));
  324. else
  325. memcpy(&vport->fc_sparam.portName, &vport->fc_portname,
  326. sizeof(struct lpfc_name));
  327. }
  328. /**
  329. * lpfc_config_port_post - Perform lpfc initialization after config port
  330. * @phba: pointer to lpfc hba data structure.
  331. *
  332. * This routine will do LPFC initialization after the CONFIG_PORT mailbox
  333. * command call. It performs all internal resource and state setups on the
  334. * port: post IOCB buffers, enable appropriate host interrupt attentions,
  335. * ELS ring timers, etc.
  336. *
  337. * Return codes
  338. * 0 - success.
  339. * Any other value - error.
  340. **/
  341. int
  342. lpfc_config_port_post(struct lpfc_hba *phba)
  343. {
  344. struct lpfc_vport *vport = phba->pport;
  345. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  346. LPFC_MBOXQ_t *pmb;
  347. MAILBOX_t *mb;
  348. struct lpfc_dmabuf *mp;
  349. struct lpfc_sli *psli = &phba->sli;
  350. uint32_t status, timeout;
  351. int i, j;
  352. int rc;
  353. spin_lock_irq(&phba->hbalock);
  354. /*
  355. * If the Config port completed correctly the HBA is not
  356. * over heated any more.
  357. */
  358. if (phba->over_temp_state == HBA_OVER_TEMP)
  359. phba->over_temp_state = HBA_NORMAL_TEMP;
  360. spin_unlock_irq(&phba->hbalock);
  361. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  362. if (!pmb) {
  363. phba->link_state = LPFC_HBA_ERROR;
  364. return -ENOMEM;
  365. }
  366. mb = &pmb->u.mb;
  367. /* Get login parameters for NID. */
  368. rc = lpfc_read_sparam(phba, pmb, 0);
  369. if (rc) {
  370. mempool_free(pmb, phba->mbox_mem_pool);
  371. return -ENOMEM;
  372. }
  373. pmb->vport = vport;
  374. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  375. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  376. "0448 Adapter failed init, mbxCmd x%x "
  377. "READ_SPARM mbxStatus x%x\n",
  378. mb->mbxCommand, mb->mbxStatus);
  379. phba->link_state = LPFC_HBA_ERROR;
  380. mp = (struct lpfc_dmabuf *) pmb->context1;
  381. mempool_free(pmb, phba->mbox_mem_pool);
  382. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  383. kfree(mp);
  384. return -EIO;
  385. }
  386. mp = (struct lpfc_dmabuf *) pmb->context1;
  387. memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
  388. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  389. kfree(mp);
  390. pmb->context1 = NULL;
  391. lpfc_update_vport_wwn(vport);
  392. /* Update the fc_host data structures with new wwn. */
  393. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  394. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  395. fc_host_max_npiv_vports(shost) = phba->max_vpi;
  396. /* If no serial number in VPD data, use low 6 bytes of WWNN */
  397. /* This should be consolidated into parse_vpd ? - mr */
  398. if (phba->SerialNumber[0] == 0) {
  399. uint8_t *outptr;
  400. outptr = &vport->fc_nodename.u.s.IEEE[0];
  401. for (i = 0; i < 12; i++) {
  402. status = *outptr++;
  403. j = ((status & 0xf0) >> 4);
  404. if (j <= 9)
  405. phba->SerialNumber[i] =
  406. (char)((uint8_t) 0x30 + (uint8_t) j);
  407. else
  408. phba->SerialNumber[i] =
  409. (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
  410. i++;
  411. j = (status & 0xf);
  412. if (j <= 9)
  413. phba->SerialNumber[i] =
  414. (char)((uint8_t) 0x30 + (uint8_t) j);
  415. else
  416. phba->SerialNumber[i] =
  417. (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
  418. }
  419. }
  420. lpfc_read_config(phba, pmb);
  421. pmb->vport = vport;
  422. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  423. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  424. "0453 Adapter failed to init, mbxCmd x%x "
  425. "READ_CONFIG, mbxStatus x%x\n",
  426. mb->mbxCommand, mb->mbxStatus);
  427. phba->link_state = LPFC_HBA_ERROR;
  428. mempool_free( pmb, phba->mbox_mem_pool);
  429. return -EIO;
  430. }
  431. /* Check if the port is disabled */
  432. lpfc_sli_read_link_ste(phba);
  433. /* Reset the DFT_HBA_Q_DEPTH to the max xri */
  434. i = (mb->un.varRdConfig.max_xri + 1);
  435. if (phba->cfg_hba_queue_depth > i) {
  436. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  437. "3359 HBA queue depth changed from %d to %d\n",
  438. phba->cfg_hba_queue_depth, i);
  439. phba->cfg_hba_queue_depth = i;
  440. }
  441. /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */
  442. i = (mb->un.varRdConfig.max_xri >> 3);
  443. if (phba->pport->cfg_lun_queue_depth > i) {
  444. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  445. "3360 LUN queue depth changed from %d to %d\n",
  446. phba->pport->cfg_lun_queue_depth, i);
  447. phba->pport->cfg_lun_queue_depth = i;
  448. }
  449. phba->lmt = mb->un.varRdConfig.lmt;
  450. /* Get the default values for Model Name and Description */
  451. lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
  452. phba->link_state = LPFC_LINK_DOWN;
  453. /* Only process IOCBs on ELS ring till hba_state is READY */
  454. if (psli->sli3_ring[LPFC_EXTRA_RING].sli.sli3.cmdringaddr)
  455. psli->sli3_ring[LPFC_EXTRA_RING].flag |= LPFC_STOP_IOCB_EVENT;
  456. if (psli->sli3_ring[LPFC_FCP_RING].sli.sli3.cmdringaddr)
  457. psli->sli3_ring[LPFC_FCP_RING].flag |= LPFC_STOP_IOCB_EVENT;
  458. /* Post receive buffers for desired rings */
  459. if (phba->sli_rev != 3)
  460. lpfc_post_rcv_buf(phba);
  461. /*
  462. * Configure HBA MSI-X attention conditions to messages if MSI-X mode
  463. */
  464. if (phba->intr_type == MSIX) {
  465. rc = lpfc_config_msi(phba, pmb);
  466. if (rc) {
  467. mempool_free(pmb, phba->mbox_mem_pool);
  468. return -EIO;
  469. }
  470. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  471. if (rc != MBX_SUCCESS) {
  472. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  473. "0352 Config MSI mailbox command "
  474. "failed, mbxCmd x%x, mbxStatus x%x\n",
  475. pmb->u.mb.mbxCommand,
  476. pmb->u.mb.mbxStatus);
  477. mempool_free(pmb, phba->mbox_mem_pool);
  478. return -EIO;
  479. }
  480. }
  481. spin_lock_irq(&phba->hbalock);
  482. /* Initialize ERATT handling flag */
  483. phba->hba_flag &= ~HBA_ERATT_HANDLED;
  484. /* Enable appropriate host interrupts */
  485. if (lpfc_readl(phba->HCregaddr, &status)) {
  486. spin_unlock_irq(&phba->hbalock);
  487. return -EIO;
  488. }
  489. status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
  490. if (psli->num_rings > 0)
  491. status |= HC_R0INT_ENA;
  492. if (psli->num_rings > 1)
  493. status |= HC_R1INT_ENA;
  494. if (psli->num_rings > 2)
  495. status |= HC_R2INT_ENA;
  496. if (psli->num_rings > 3)
  497. status |= HC_R3INT_ENA;
  498. if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
  499. (phba->cfg_poll & DISABLE_FCP_RING_INT))
  500. status &= ~(HC_R0INT_ENA);
  501. writel(status, phba->HCregaddr);
  502. readl(phba->HCregaddr); /* flush */
  503. spin_unlock_irq(&phba->hbalock);
  504. /* Set up ring-0 (ELS) timer */
  505. timeout = phba->fc_ratov * 2;
  506. mod_timer(&vport->els_tmofunc,
  507. jiffies + msecs_to_jiffies(1000 * timeout));
  508. /* Set up heart beat (HB) timer */
  509. mod_timer(&phba->hb_tmofunc,
  510. jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
  511. phba->hb_outstanding = 0;
  512. phba->last_completion_time = jiffies;
  513. /* Set up error attention (ERATT) polling timer */
  514. mod_timer(&phba->eratt_poll,
  515. jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval));
  516. if (phba->hba_flag & LINK_DISABLED) {
  517. lpfc_printf_log(phba,
  518. KERN_ERR, LOG_INIT,
  519. "2598 Adapter Link is disabled.\n");
  520. lpfc_down_link(phba, pmb);
  521. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  522. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  523. if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
  524. lpfc_printf_log(phba,
  525. KERN_ERR, LOG_INIT,
  526. "2599 Adapter failed to issue DOWN_LINK"
  527. " mbox command rc 0x%x\n", rc);
  528. mempool_free(pmb, phba->mbox_mem_pool);
  529. return -EIO;
  530. }
  531. } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
  532. mempool_free(pmb, phba->mbox_mem_pool);
  533. rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
  534. if (rc)
  535. return rc;
  536. }
  537. /* MBOX buffer will be freed in mbox compl */
  538. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  539. if (!pmb) {
  540. phba->link_state = LPFC_HBA_ERROR;
  541. return -ENOMEM;
  542. }
  543. lpfc_config_async(phba, pmb, LPFC_ELS_RING);
  544. pmb->mbox_cmpl = lpfc_config_async_cmpl;
  545. pmb->vport = phba->pport;
  546. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  547. if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
  548. lpfc_printf_log(phba,
  549. KERN_ERR,
  550. LOG_INIT,
  551. "0456 Adapter failed to issue "
  552. "ASYNCEVT_ENABLE mbox status x%x\n",
  553. rc);
  554. mempool_free(pmb, phba->mbox_mem_pool);
  555. }
  556. /* Get Option rom version */
  557. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  558. if (!pmb) {
  559. phba->link_state = LPFC_HBA_ERROR;
  560. return -ENOMEM;
  561. }
  562. lpfc_dump_wakeup_param(phba, pmb);
  563. pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl;
  564. pmb->vport = phba->pport;
  565. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  566. if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
  567. lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed "
  568. "to get Option ROM version status x%x\n", rc);
  569. mempool_free(pmb, phba->mbox_mem_pool);
  570. }
  571. return 0;
  572. }
  573. /**
  574. * lpfc_hba_init_link - Initialize the FC link
  575. * @phba: pointer to lpfc hba data structure.
  576. * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
  577. *
  578. * This routine will issue the INIT_LINK mailbox command call.
  579. * It is available to other drivers through the lpfc_hba data
  580. * structure for use as a delayed link up mechanism with the
  581. * module parameter lpfc_suppress_link_up.
  582. *
  583. * Return code
  584. * 0 - success
  585. * Any other value - error
  586. **/
  587. static int
  588. lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag)
  589. {
  590. return lpfc_hba_init_link_fc_topology(phba, phba->cfg_topology, flag);
  591. }
  592. /**
  593. * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology
  594. * @phba: pointer to lpfc hba data structure.
  595. * @fc_topology: desired fc topology.
  596. * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
  597. *
  598. * This routine will issue the INIT_LINK mailbox command call.
  599. * It is available to other drivers through the lpfc_hba data
  600. * structure for use as a delayed link up mechanism with the
  601. * module parameter lpfc_suppress_link_up.
  602. *
  603. * Return code
  604. * 0 - success
  605. * Any other value - error
  606. **/
  607. int
  608. lpfc_hba_init_link_fc_topology(struct lpfc_hba *phba, uint32_t fc_topology,
  609. uint32_t flag)
  610. {
  611. struct lpfc_vport *vport = phba->pport;
  612. LPFC_MBOXQ_t *pmb;
  613. MAILBOX_t *mb;
  614. int rc;
  615. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  616. if (!pmb) {
  617. phba->link_state = LPFC_HBA_ERROR;
  618. return -ENOMEM;
  619. }
  620. mb = &pmb->u.mb;
  621. pmb->vport = vport;
  622. if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_MAX) ||
  623. ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G) &&
  624. !(phba->lmt & LMT_1Gb)) ||
  625. ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G) &&
  626. !(phba->lmt & LMT_2Gb)) ||
  627. ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G) &&
  628. !(phba->lmt & LMT_4Gb)) ||
  629. ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G) &&
  630. !(phba->lmt & LMT_8Gb)) ||
  631. ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G) &&
  632. !(phba->lmt & LMT_10Gb)) ||
  633. ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) &&
  634. !(phba->lmt & LMT_16Gb)) ||
  635. ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_32G) &&
  636. !(phba->lmt & LMT_32Gb))) {
  637. /* Reset link speed to auto */
  638. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  639. "1302 Invalid speed for this board:%d "
  640. "Reset link speed to auto.\n",
  641. phba->cfg_link_speed);
  642. phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
  643. }
  644. lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed);
  645. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  646. if (phba->sli_rev < LPFC_SLI_REV4)
  647. lpfc_set_loopback_flag(phba);
  648. rc = lpfc_sli_issue_mbox(phba, pmb, flag);
  649. if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
  650. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  651. "0498 Adapter failed to init, mbxCmd x%x "
  652. "INIT_LINK, mbxStatus x%x\n",
  653. mb->mbxCommand, mb->mbxStatus);
  654. if (phba->sli_rev <= LPFC_SLI_REV3) {
  655. /* Clear all interrupt enable conditions */
  656. writel(0, phba->HCregaddr);
  657. readl(phba->HCregaddr); /* flush */
  658. /* Clear all pending interrupts */
  659. writel(0xffffffff, phba->HAregaddr);
  660. readl(phba->HAregaddr); /* flush */
  661. }
  662. phba->link_state = LPFC_HBA_ERROR;
  663. if (rc != MBX_BUSY || flag == MBX_POLL)
  664. mempool_free(pmb, phba->mbox_mem_pool);
  665. return -EIO;
  666. }
  667. phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK;
  668. if (flag == MBX_POLL)
  669. mempool_free(pmb, phba->mbox_mem_pool);
  670. return 0;
  671. }
  672. /**
  673. * lpfc_hba_down_link - this routine downs the FC link
  674. * @phba: pointer to lpfc hba data structure.
  675. * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
  676. *
  677. * This routine will issue the DOWN_LINK mailbox command call.
  678. * It is available to other drivers through the lpfc_hba data
  679. * structure for use to stop the link.
  680. *
  681. * Return code
  682. * 0 - success
  683. * Any other value - error
  684. **/
  685. static int
  686. lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag)
  687. {
  688. LPFC_MBOXQ_t *pmb;
  689. int rc;
  690. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  691. if (!pmb) {
  692. phba->link_state = LPFC_HBA_ERROR;
  693. return -ENOMEM;
  694. }
  695. lpfc_printf_log(phba,
  696. KERN_ERR, LOG_INIT,
  697. "0491 Adapter Link is disabled.\n");
  698. lpfc_down_link(phba, pmb);
  699. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  700. rc = lpfc_sli_issue_mbox(phba, pmb, flag);
  701. if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
  702. lpfc_printf_log(phba,
  703. KERN_ERR, LOG_INIT,
  704. "2522 Adapter failed to issue DOWN_LINK"
  705. " mbox command rc 0x%x\n", rc);
  706. mempool_free(pmb, phba->mbox_mem_pool);
  707. return -EIO;
  708. }
  709. if (flag == MBX_POLL)
  710. mempool_free(pmb, phba->mbox_mem_pool);
  711. return 0;
  712. }
  713. /**
  714. * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
  715. * @phba: pointer to lpfc HBA data structure.
  716. *
  717. * This routine will do LPFC uninitialization before the HBA is reset when
  718. * bringing down the SLI Layer.
  719. *
  720. * Return codes
  721. * 0 - success.
  722. * Any other value - error.
  723. **/
  724. int
  725. lpfc_hba_down_prep(struct lpfc_hba *phba)
  726. {
  727. struct lpfc_vport **vports;
  728. int i;
  729. if (phba->sli_rev <= LPFC_SLI_REV3) {
  730. /* Disable interrupts */
  731. writel(0, phba->HCregaddr);
  732. readl(phba->HCregaddr); /* flush */
  733. }
  734. if (phba->pport->load_flag & FC_UNLOADING)
  735. lpfc_cleanup_discovery_resources(phba->pport);
  736. else {
  737. vports = lpfc_create_vport_work_array(phba);
  738. if (vports != NULL)
  739. for (i = 0; i <= phba->max_vports &&
  740. vports[i] != NULL; i++)
  741. lpfc_cleanup_discovery_resources(vports[i]);
  742. lpfc_destroy_vport_work_array(phba, vports);
  743. }
  744. return 0;
  745. }
  746. /**
  747. * lpfc_sli4_free_sp_events - Cleanup sp_queue_events to free
  748. * rspiocb which got deferred
  749. *
  750. * @phba: pointer to lpfc HBA data structure.
  751. *
  752. * This routine will cleanup completed slow path events after HBA is reset
  753. * when bringing down the SLI Layer.
  754. *
  755. *
  756. * Return codes
  757. * void.
  758. **/
  759. static void
  760. lpfc_sli4_free_sp_events(struct lpfc_hba *phba)
  761. {
  762. struct lpfc_iocbq *rspiocbq;
  763. struct hbq_dmabuf *dmabuf;
  764. struct lpfc_cq_event *cq_event;
  765. spin_lock_irq(&phba->hbalock);
  766. phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
  767. spin_unlock_irq(&phba->hbalock);
  768. while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
  769. /* Get the response iocb from the head of work queue */
  770. spin_lock_irq(&phba->hbalock);
  771. list_remove_head(&phba->sli4_hba.sp_queue_event,
  772. cq_event, struct lpfc_cq_event, list);
  773. spin_unlock_irq(&phba->hbalock);
  774. switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
  775. case CQE_CODE_COMPL_WQE:
  776. rspiocbq = container_of(cq_event, struct lpfc_iocbq,
  777. cq_event);
  778. lpfc_sli_release_iocbq(phba, rspiocbq);
  779. break;
  780. case CQE_CODE_RECEIVE:
  781. case CQE_CODE_RECEIVE_V1:
  782. dmabuf = container_of(cq_event, struct hbq_dmabuf,
  783. cq_event);
  784. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  785. }
  786. }
  787. }
  788. /**
  789. * lpfc_hba_free_post_buf - Perform lpfc uninitialization after HBA reset
  790. * @phba: pointer to lpfc HBA data structure.
  791. *
  792. * This routine will cleanup posted ELS buffers after the HBA is reset
  793. * when bringing down the SLI Layer.
  794. *
  795. *
  796. * Return codes
  797. * void.
  798. **/
  799. static void
  800. lpfc_hba_free_post_buf(struct lpfc_hba *phba)
  801. {
  802. struct lpfc_sli *psli = &phba->sli;
  803. struct lpfc_sli_ring *pring;
  804. struct lpfc_dmabuf *mp, *next_mp;
  805. LIST_HEAD(buflist);
  806. int count;
  807. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
  808. lpfc_sli_hbqbuf_free_all(phba);
  809. else {
  810. /* Cleanup preposted buffers on the ELS ring */
  811. pring = &psli->sli3_ring[LPFC_ELS_RING];
  812. spin_lock_irq(&phba->hbalock);
  813. list_splice_init(&pring->postbufq, &buflist);
  814. spin_unlock_irq(&phba->hbalock);
  815. count = 0;
  816. list_for_each_entry_safe(mp, next_mp, &buflist, list) {
  817. list_del(&mp->list);
  818. count++;
  819. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  820. kfree(mp);
  821. }
  822. spin_lock_irq(&phba->hbalock);
  823. pring->postbufq_cnt -= count;
  824. spin_unlock_irq(&phba->hbalock);
  825. }
  826. }
  827. /**
  828. * lpfc_hba_clean_txcmplq - Perform lpfc uninitialization after HBA reset
  829. * @phba: pointer to lpfc HBA data structure.
  830. *
  831. * This routine will cleanup the txcmplq after the HBA is reset when bringing
  832. * down the SLI Layer.
  833. *
  834. * Return codes
  835. * void
  836. **/
  837. static void
  838. lpfc_hba_clean_txcmplq(struct lpfc_hba *phba)
  839. {
  840. struct lpfc_sli *psli = &phba->sli;
  841. struct lpfc_queue *qp = NULL;
  842. struct lpfc_sli_ring *pring;
  843. LIST_HEAD(completions);
  844. int i;
  845. if (phba->sli_rev != LPFC_SLI_REV4) {
  846. for (i = 0; i < psli->num_rings; i++) {
  847. pring = &psli->sli3_ring[i];
  848. spin_lock_irq(&phba->hbalock);
  849. /* At this point in time the HBA is either reset or DOA
  850. * Nothing should be on txcmplq as it will
  851. * NEVER complete.
  852. */
  853. list_splice_init(&pring->txcmplq, &completions);
  854. pring->txcmplq_cnt = 0;
  855. spin_unlock_irq(&phba->hbalock);
  856. lpfc_sli_abort_iocb_ring(phba, pring);
  857. }
  858. /* Cancel all the IOCBs from the completions list */
  859. lpfc_sli_cancel_iocbs(phba, &completions,
  860. IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
  861. return;
  862. }
  863. list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
  864. pring = qp->pring;
  865. if (!pring)
  866. continue;
  867. spin_lock_irq(&pring->ring_lock);
  868. list_splice_init(&pring->txcmplq, &completions);
  869. pring->txcmplq_cnt = 0;
  870. spin_unlock_irq(&pring->ring_lock);
  871. lpfc_sli_abort_iocb_ring(phba, pring);
  872. }
  873. /* Cancel all the IOCBs from the completions list */
  874. lpfc_sli_cancel_iocbs(phba, &completions,
  875. IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
  876. }
  877. /**
  878. * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
  879. int i;
  880. * @phba: pointer to lpfc HBA data structure.
  881. *
  882. * This routine will do uninitialization after the HBA is reset when bring
  883. * down the SLI Layer.
  884. *
  885. * Return codes
  886. * 0 - success.
  887. * Any other value - error.
  888. **/
  889. static int
  890. lpfc_hba_down_post_s3(struct lpfc_hba *phba)
  891. {
  892. lpfc_hba_free_post_buf(phba);
  893. lpfc_hba_clean_txcmplq(phba);
  894. return 0;
  895. }
  896. /**
  897. * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
  898. * @phba: pointer to lpfc HBA data structure.
  899. *
  900. * This routine will do uninitialization after the HBA is reset when bring
  901. * down the SLI Layer.
  902. *
  903. * Return codes
  904. * 0 - success.
  905. * Any other value - error.
  906. **/
  907. static int
  908. lpfc_hba_down_post_s4(struct lpfc_hba *phba)
  909. {
  910. struct lpfc_scsi_buf *psb, *psb_next;
  911. LIST_HEAD(aborts);
  912. LIST_HEAD(nvme_aborts);
  913. unsigned long iflag = 0;
  914. struct lpfc_sglq *sglq_entry = NULL;
  915. lpfc_sli_hbqbuf_free_all(phba);
  916. lpfc_hba_clean_txcmplq(phba);
  917. /* At this point in time the HBA is either reset or DOA. Either
  918. * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
  919. * on the lpfc_els_sgl_list so that it can either be freed if the
  920. * driver is unloading or reposted if the driver is restarting
  921. * the port.
  922. */
  923. spin_lock_irq(&phba->hbalock); /* required for lpfc_els_sgl_list and */
  924. /* scsl_buf_list */
  925. /* sgl_list_lock required because worker thread uses this
  926. * list.
  927. */
  928. spin_lock(&phba->sli4_hba.sgl_list_lock);
  929. list_for_each_entry(sglq_entry,
  930. &phba->sli4_hba.lpfc_abts_els_sgl_list, list)
  931. sglq_entry->state = SGL_FREED;
  932. list_for_each_entry(sglq_entry,
  933. &phba->sli4_hba.lpfc_abts_nvmet_sgl_list, list)
  934. sglq_entry->state = SGL_FREED;
  935. list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list,
  936. &phba->sli4_hba.lpfc_els_sgl_list);
  937. if (phba->sli4_hba.nvme_wq)
  938. list_splice_init(&phba->sli4_hba.lpfc_abts_nvmet_sgl_list,
  939. &phba->sli4_hba.lpfc_nvmet_sgl_list);
  940. spin_unlock(&phba->sli4_hba.sgl_list_lock);
  941. /* abts_scsi_buf_list_lock required because worker thread uses this
  942. * list.
  943. */
  944. if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
  945. spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock);
  946. list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list,
  947. &aborts);
  948. spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock);
  949. }
  950. if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
  951. spin_lock(&phba->sli4_hba.abts_nvme_buf_list_lock);
  952. list_splice_init(&phba->sli4_hba.lpfc_abts_nvme_buf_list,
  953. &nvme_aborts);
  954. spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock);
  955. }
  956. spin_unlock_irq(&phba->hbalock);
  957. list_for_each_entry_safe(psb, psb_next, &aborts, list) {
  958. psb->pCmd = NULL;
  959. psb->status = IOSTAT_SUCCESS;
  960. }
  961. spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag);
  962. list_splice(&aborts, &phba->lpfc_scsi_buf_list_put);
  963. spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag);
  964. list_for_each_entry_safe(psb, psb_next, &nvme_aborts, list) {
  965. psb->pCmd = NULL;
  966. psb->status = IOSTAT_SUCCESS;
  967. }
  968. spin_lock_irqsave(&phba->nvme_buf_list_put_lock, iflag);
  969. list_splice(&nvme_aborts, &phba->lpfc_nvme_buf_list_put);
  970. spin_unlock_irqrestore(&phba->nvme_buf_list_put_lock, iflag);
  971. lpfc_sli4_free_sp_events(phba);
  972. return 0;
  973. }
  974. /**
  975. * lpfc_hba_down_post - Wrapper func for hba down post routine
  976. * @phba: pointer to lpfc HBA data structure.
  977. *
  978. * This routine wraps the actual SLI3 or SLI4 routine for performing
  979. * uninitialization after the HBA is reset when bring down the SLI Layer.
  980. *
  981. * Return codes
  982. * 0 - success.
  983. * Any other value - error.
  984. **/
  985. int
  986. lpfc_hba_down_post(struct lpfc_hba *phba)
  987. {
  988. return (*phba->lpfc_hba_down_post)(phba);
  989. }
  990. /**
  991. * lpfc_hb_timeout - The HBA-timer timeout handler
  992. * @ptr: unsigned long holds the pointer to lpfc hba data structure.
  993. *
  994. * This is the HBA-timer timeout handler registered to the lpfc driver. When
  995. * this timer fires, a HBA timeout event shall be posted to the lpfc driver
  996. * work-port-events bitmap and the worker thread is notified. This timeout
  997. * event will be used by the worker thread to invoke the actual timeout
  998. * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
  999. * be performed in the timeout handler and the HBA timeout event bit shall
  1000. * be cleared by the worker thread after it has taken the event bitmap out.
  1001. **/
  1002. static void
  1003. lpfc_hb_timeout(unsigned long ptr)
  1004. {
  1005. struct lpfc_hba *phba;
  1006. uint32_t tmo_posted;
  1007. unsigned long iflag;
  1008. phba = (struct lpfc_hba *)ptr;
  1009. /* Check for heart beat timeout conditions */
  1010. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  1011. tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
  1012. if (!tmo_posted)
  1013. phba->pport->work_port_events |= WORKER_HB_TMO;
  1014. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  1015. /* Tell the worker thread there is work to do */
  1016. if (!tmo_posted)
  1017. lpfc_worker_wake_up(phba);
  1018. return;
  1019. }
  1020. /**
  1021. * lpfc_rrq_timeout - The RRQ-timer timeout handler
  1022. * @ptr: unsigned long holds the pointer to lpfc hba data structure.
  1023. *
  1024. * This is the RRQ-timer timeout handler registered to the lpfc driver. When
  1025. * this timer fires, a RRQ timeout event shall be posted to the lpfc driver
  1026. * work-port-events bitmap and the worker thread is notified. This timeout
  1027. * event will be used by the worker thread to invoke the actual timeout
  1028. * handler routine, lpfc_rrq_handler. Any periodical operations will
  1029. * be performed in the timeout handler and the RRQ timeout event bit shall
  1030. * be cleared by the worker thread after it has taken the event bitmap out.
  1031. **/
  1032. static void
  1033. lpfc_rrq_timeout(unsigned long ptr)
  1034. {
  1035. struct lpfc_hba *phba;
  1036. unsigned long iflag;
  1037. phba = (struct lpfc_hba *)ptr;
  1038. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  1039. if (!(phba->pport->load_flag & FC_UNLOADING))
  1040. phba->hba_flag |= HBA_RRQ_ACTIVE;
  1041. else
  1042. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  1043. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  1044. if (!(phba->pport->load_flag & FC_UNLOADING))
  1045. lpfc_worker_wake_up(phba);
  1046. }
  1047. /**
  1048. * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
  1049. * @phba: pointer to lpfc hba data structure.
  1050. * @pmboxq: pointer to the driver internal queue element for mailbox command.
  1051. *
  1052. * This is the callback function to the lpfc heart-beat mailbox command.
  1053. * If configured, the lpfc driver issues the heart-beat mailbox command to
  1054. * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
  1055. * heart-beat mailbox command is issued, the driver shall set up heart-beat
  1056. * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
  1057. * heart-beat outstanding state. Once the mailbox command comes back and
  1058. * no error conditions detected, the heart-beat mailbox command timer is
  1059. * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
  1060. * state is cleared for the next heart-beat. If the timer expired with the
  1061. * heart-beat outstanding state set, the driver will put the HBA offline.
  1062. **/
  1063. static void
  1064. lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
  1065. {
  1066. unsigned long drvr_flag;
  1067. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  1068. phba->hb_outstanding = 0;
  1069. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  1070. /* Check and reset heart-beat timer is necessary */
  1071. mempool_free(pmboxq, phba->mbox_mem_pool);
  1072. if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
  1073. !(phba->link_state == LPFC_HBA_ERROR) &&
  1074. !(phba->pport->load_flag & FC_UNLOADING))
  1075. mod_timer(&phba->hb_tmofunc,
  1076. jiffies +
  1077. msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
  1078. return;
  1079. }
  1080. /**
  1081. * lpfc_hb_timeout_handler - The HBA-timer timeout handler
  1082. * @phba: pointer to lpfc hba data structure.
  1083. *
  1084. * This is the actual HBA-timer timeout handler to be invoked by the worker
  1085. * thread whenever the HBA timer fired and HBA-timeout event posted. This
  1086. * handler performs any periodic operations needed for the device. If such
  1087. * periodic event has already been attended to either in the interrupt handler
  1088. * or by processing slow-ring or fast-ring events within the HBA-timer
  1089. * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
  1090. * the timer for the next timeout period. If lpfc heart-beat mailbox command
  1091. * is configured and there is no heart-beat mailbox command outstanding, a
  1092. * heart-beat mailbox is issued and timer set properly. Otherwise, if there
  1093. * has been a heart-beat mailbox command outstanding, the HBA shall be put
  1094. * to offline.
  1095. **/
  1096. void
  1097. lpfc_hb_timeout_handler(struct lpfc_hba *phba)
  1098. {
  1099. struct lpfc_vport **vports;
  1100. LPFC_MBOXQ_t *pmboxq;
  1101. struct lpfc_dmabuf *buf_ptr;
  1102. int retval, i;
  1103. struct lpfc_sli *psli = &phba->sli;
  1104. LIST_HEAD(completions);
  1105. vports = lpfc_create_vport_work_array(phba);
  1106. if (vports != NULL)
  1107. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  1108. lpfc_rcv_seq_check_edtov(vports[i]);
  1109. lpfc_fdmi_num_disc_check(vports[i]);
  1110. }
  1111. lpfc_destroy_vport_work_array(phba, vports);
  1112. if ((phba->link_state == LPFC_HBA_ERROR) ||
  1113. (phba->pport->load_flag & FC_UNLOADING) ||
  1114. (phba->pport->fc_flag & FC_OFFLINE_MODE))
  1115. return;
  1116. spin_lock_irq(&phba->pport->work_port_lock);
  1117. if (time_after(phba->last_completion_time +
  1118. msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL),
  1119. jiffies)) {
  1120. spin_unlock_irq(&phba->pport->work_port_lock);
  1121. if (!phba->hb_outstanding)
  1122. mod_timer(&phba->hb_tmofunc,
  1123. jiffies +
  1124. msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
  1125. else
  1126. mod_timer(&phba->hb_tmofunc,
  1127. jiffies +
  1128. msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
  1129. return;
  1130. }
  1131. spin_unlock_irq(&phba->pport->work_port_lock);
  1132. if (phba->elsbuf_cnt &&
  1133. (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
  1134. spin_lock_irq(&phba->hbalock);
  1135. list_splice_init(&phba->elsbuf, &completions);
  1136. phba->elsbuf_cnt = 0;
  1137. phba->elsbuf_prev_cnt = 0;
  1138. spin_unlock_irq(&phba->hbalock);
  1139. while (!list_empty(&completions)) {
  1140. list_remove_head(&completions, buf_ptr,
  1141. struct lpfc_dmabuf, list);
  1142. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  1143. kfree(buf_ptr);
  1144. }
  1145. }
  1146. phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
  1147. /* If there is no heart beat outstanding, issue a heartbeat command */
  1148. if (phba->cfg_enable_hba_heartbeat) {
  1149. if (!phba->hb_outstanding) {
  1150. if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) &&
  1151. (list_empty(&psli->mboxq))) {
  1152. pmboxq = mempool_alloc(phba->mbox_mem_pool,
  1153. GFP_KERNEL);
  1154. if (!pmboxq) {
  1155. mod_timer(&phba->hb_tmofunc,
  1156. jiffies +
  1157. msecs_to_jiffies(1000 *
  1158. LPFC_HB_MBOX_INTERVAL));
  1159. return;
  1160. }
  1161. lpfc_heart_beat(phba, pmboxq);
  1162. pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
  1163. pmboxq->vport = phba->pport;
  1164. retval = lpfc_sli_issue_mbox(phba, pmboxq,
  1165. MBX_NOWAIT);
  1166. if (retval != MBX_BUSY &&
  1167. retval != MBX_SUCCESS) {
  1168. mempool_free(pmboxq,
  1169. phba->mbox_mem_pool);
  1170. mod_timer(&phba->hb_tmofunc,
  1171. jiffies +
  1172. msecs_to_jiffies(1000 *
  1173. LPFC_HB_MBOX_INTERVAL));
  1174. return;
  1175. }
  1176. phba->skipped_hb = 0;
  1177. phba->hb_outstanding = 1;
  1178. } else if (time_before_eq(phba->last_completion_time,
  1179. phba->skipped_hb)) {
  1180. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  1181. "2857 Last completion time not "
  1182. " updated in %d ms\n",
  1183. jiffies_to_msecs(jiffies
  1184. - phba->last_completion_time));
  1185. } else
  1186. phba->skipped_hb = jiffies;
  1187. mod_timer(&phba->hb_tmofunc,
  1188. jiffies +
  1189. msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
  1190. return;
  1191. } else {
  1192. /*
  1193. * If heart beat timeout called with hb_outstanding set
  1194. * we need to give the hb mailbox cmd a chance to
  1195. * complete or TMO.
  1196. */
  1197. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  1198. "0459 Adapter heartbeat still out"
  1199. "standing:last compl time was %d ms.\n",
  1200. jiffies_to_msecs(jiffies
  1201. - phba->last_completion_time));
  1202. mod_timer(&phba->hb_tmofunc,
  1203. jiffies +
  1204. msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
  1205. }
  1206. } else {
  1207. mod_timer(&phba->hb_tmofunc,
  1208. jiffies +
  1209. msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
  1210. }
  1211. }
  1212. /**
  1213. * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
  1214. * @phba: pointer to lpfc hba data structure.
  1215. *
  1216. * This routine is called to bring the HBA offline when HBA hardware error
  1217. * other than Port Error 6 has been detected.
  1218. **/
  1219. static void
  1220. lpfc_offline_eratt(struct lpfc_hba *phba)
  1221. {
  1222. struct lpfc_sli *psli = &phba->sli;
  1223. spin_lock_irq(&phba->hbalock);
  1224. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  1225. spin_unlock_irq(&phba->hbalock);
  1226. lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
  1227. lpfc_offline(phba);
  1228. lpfc_reset_barrier(phba);
  1229. spin_lock_irq(&phba->hbalock);
  1230. lpfc_sli_brdreset(phba);
  1231. spin_unlock_irq(&phba->hbalock);
  1232. lpfc_hba_down_post(phba);
  1233. lpfc_sli_brdready(phba, HS_MBRDY);
  1234. lpfc_unblock_mgmt_io(phba);
  1235. phba->link_state = LPFC_HBA_ERROR;
  1236. return;
  1237. }
  1238. /**
  1239. * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
  1240. * @phba: pointer to lpfc hba data structure.
  1241. *
  1242. * This routine is called to bring a SLI4 HBA offline when HBA hardware error
  1243. * other than Port Error 6 has been detected.
  1244. **/
  1245. void
  1246. lpfc_sli4_offline_eratt(struct lpfc_hba *phba)
  1247. {
  1248. spin_lock_irq(&phba->hbalock);
  1249. phba->link_state = LPFC_HBA_ERROR;
  1250. spin_unlock_irq(&phba->hbalock);
  1251. lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
  1252. lpfc_offline(phba);
  1253. lpfc_hba_down_post(phba);
  1254. lpfc_unblock_mgmt_io(phba);
  1255. }
  1256. /**
  1257. * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
  1258. * @phba: pointer to lpfc hba data structure.
  1259. *
  1260. * This routine is invoked to handle the deferred HBA hardware error
  1261. * conditions. This type of error is indicated by HBA by setting ER1
  1262. * and another ER bit in the host status register. The driver will
  1263. * wait until the ER1 bit clears before handling the error condition.
  1264. **/
  1265. static void
  1266. lpfc_handle_deferred_eratt(struct lpfc_hba *phba)
  1267. {
  1268. uint32_t old_host_status = phba->work_hs;
  1269. struct lpfc_sli *psli = &phba->sli;
  1270. /* If the pci channel is offline, ignore possible errors,
  1271. * since we cannot communicate with the pci card anyway.
  1272. */
  1273. if (pci_channel_offline(phba->pcidev)) {
  1274. spin_lock_irq(&phba->hbalock);
  1275. phba->hba_flag &= ~DEFER_ERATT;
  1276. spin_unlock_irq(&phba->hbalock);
  1277. return;
  1278. }
  1279. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1280. "0479 Deferred Adapter Hardware Error "
  1281. "Data: x%x x%x x%x\n",
  1282. phba->work_hs,
  1283. phba->work_status[0], phba->work_status[1]);
  1284. spin_lock_irq(&phba->hbalock);
  1285. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  1286. spin_unlock_irq(&phba->hbalock);
  1287. /*
  1288. * Firmware stops when it triggred erratt. That could cause the I/Os
  1289. * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
  1290. * SCSI layer retry it after re-establishing link.
  1291. */
  1292. lpfc_sli_abort_fcp_rings(phba);
  1293. /*
  1294. * There was a firmware error. Take the hba offline and then
  1295. * attempt to restart it.
  1296. */
  1297. lpfc_offline_prep(phba, LPFC_MBX_WAIT);
  1298. lpfc_offline(phba);
  1299. /* Wait for the ER1 bit to clear.*/
  1300. while (phba->work_hs & HS_FFER1) {
  1301. msleep(100);
  1302. if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) {
  1303. phba->work_hs = UNPLUG_ERR ;
  1304. break;
  1305. }
  1306. /* If driver is unloading let the worker thread continue */
  1307. if (phba->pport->load_flag & FC_UNLOADING) {
  1308. phba->work_hs = 0;
  1309. break;
  1310. }
  1311. }
  1312. /*
  1313. * This is to ptrotect against a race condition in which
  1314. * first write to the host attention register clear the
  1315. * host status register.
  1316. */
  1317. if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING)))
  1318. phba->work_hs = old_host_status & ~HS_FFER1;
  1319. spin_lock_irq(&phba->hbalock);
  1320. phba->hba_flag &= ~DEFER_ERATT;
  1321. spin_unlock_irq(&phba->hbalock);
  1322. phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
  1323. phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
  1324. }
  1325. static void
  1326. lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba)
  1327. {
  1328. struct lpfc_board_event_header board_event;
  1329. struct Scsi_Host *shost;
  1330. board_event.event_type = FC_REG_BOARD_EVENT;
  1331. board_event.subcategory = LPFC_EVENT_PORTINTERR;
  1332. shost = lpfc_shost_from_vport(phba->pport);
  1333. fc_host_post_vendor_event(shost, fc_get_event_number(),
  1334. sizeof(board_event),
  1335. (char *) &board_event,
  1336. LPFC_NL_VENDOR_ID);
  1337. }
  1338. /**
  1339. * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
  1340. * @phba: pointer to lpfc hba data structure.
  1341. *
  1342. * This routine is invoked to handle the following HBA hardware error
  1343. * conditions:
  1344. * 1 - HBA error attention interrupt
  1345. * 2 - DMA ring index out of range
  1346. * 3 - Mailbox command came back as unknown
  1347. **/
  1348. static void
  1349. lpfc_handle_eratt_s3(struct lpfc_hba *phba)
  1350. {
  1351. struct lpfc_vport *vport = phba->pport;
  1352. struct lpfc_sli *psli = &phba->sli;
  1353. uint32_t event_data;
  1354. unsigned long temperature;
  1355. struct temp_event temp_event_data;
  1356. struct Scsi_Host *shost;
  1357. /* If the pci channel is offline, ignore possible errors,
  1358. * since we cannot communicate with the pci card anyway.
  1359. */
  1360. if (pci_channel_offline(phba->pcidev)) {
  1361. spin_lock_irq(&phba->hbalock);
  1362. phba->hba_flag &= ~DEFER_ERATT;
  1363. spin_unlock_irq(&phba->hbalock);
  1364. return;
  1365. }
  1366. /* If resets are disabled then leave the HBA alone and return */
  1367. if (!phba->cfg_enable_hba_reset)
  1368. return;
  1369. /* Send an internal error event to mgmt application */
  1370. lpfc_board_errevt_to_mgmt(phba);
  1371. if (phba->hba_flag & DEFER_ERATT)
  1372. lpfc_handle_deferred_eratt(phba);
  1373. if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) {
  1374. if (phba->work_hs & HS_FFER6)
  1375. /* Re-establishing Link */
  1376. lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
  1377. "1301 Re-establishing Link "
  1378. "Data: x%x x%x x%x\n",
  1379. phba->work_hs, phba->work_status[0],
  1380. phba->work_status[1]);
  1381. if (phba->work_hs & HS_FFER8)
  1382. /* Device Zeroization */
  1383. lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
  1384. "2861 Host Authentication device "
  1385. "zeroization Data:x%x x%x x%x\n",
  1386. phba->work_hs, phba->work_status[0],
  1387. phba->work_status[1]);
  1388. spin_lock_irq(&phba->hbalock);
  1389. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  1390. spin_unlock_irq(&phba->hbalock);
  1391. /*
  1392. * Firmware stops when it triggled erratt with HS_FFER6.
  1393. * That could cause the I/Os dropped by the firmware.
  1394. * Error iocb (I/O) on txcmplq and let the SCSI layer
  1395. * retry it after re-establishing link.
  1396. */
  1397. lpfc_sli_abort_fcp_rings(phba);
  1398. /*
  1399. * There was a firmware error. Take the hba offline and then
  1400. * attempt to restart it.
  1401. */
  1402. lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
  1403. lpfc_offline(phba);
  1404. lpfc_sli_brdrestart(phba);
  1405. if (lpfc_online(phba) == 0) { /* Initialize the HBA */
  1406. lpfc_unblock_mgmt_io(phba);
  1407. return;
  1408. }
  1409. lpfc_unblock_mgmt_io(phba);
  1410. } else if (phba->work_hs & HS_CRIT_TEMP) {
  1411. temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
  1412. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  1413. temp_event_data.event_code = LPFC_CRIT_TEMP;
  1414. temp_event_data.data = (uint32_t)temperature;
  1415. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1416. "0406 Adapter maximum temperature exceeded "
  1417. "(%ld), taking this port offline "
  1418. "Data: x%x x%x x%x\n",
  1419. temperature, phba->work_hs,
  1420. phba->work_status[0], phba->work_status[1]);
  1421. shost = lpfc_shost_from_vport(phba->pport);
  1422. fc_host_post_vendor_event(shost, fc_get_event_number(),
  1423. sizeof(temp_event_data),
  1424. (char *) &temp_event_data,
  1425. SCSI_NL_VID_TYPE_PCI
  1426. | PCI_VENDOR_ID_EMULEX);
  1427. spin_lock_irq(&phba->hbalock);
  1428. phba->over_temp_state = HBA_OVER_TEMP;
  1429. spin_unlock_irq(&phba->hbalock);
  1430. lpfc_offline_eratt(phba);
  1431. } else {
  1432. /* The if clause above forces this code path when the status
  1433. * failure is a value other than FFER6. Do not call the offline
  1434. * twice. This is the adapter hardware error path.
  1435. */
  1436. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1437. "0457 Adapter Hardware Error "
  1438. "Data: x%x x%x x%x\n",
  1439. phba->work_hs,
  1440. phba->work_status[0], phba->work_status[1]);
  1441. event_data = FC_REG_DUMP_EVENT;
  1442. shost = lpfc_shost_from_vport(vport);
  1443. fc_host_post_vendor_event(shost, fc_get_event_number(),
  1444. sizeof(event_data), (char *) &event_data,
  1445. SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
  1446. lpfc_offline_eratt(phba);
  1447. }
  1448. return;
  1449. }
  1450. /**
  1451. * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg
  1452. * @phba: pointer to lpfc hba data structure.
  1453. * @mbx_action: flag for mailbox shutdown action.
  1454. *
  1455. * This routine is invoked to perform an SLI4 port PCI function reset in
  1456. * response to port status register polli…