lpfc_vport.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2006 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  8. * *
  9. * This program is free software; you can redistribute it and/or *
  10. * modify it under the terms of version 2 of the GNU General *
  11. * Public License as published by the Free Software Foundation. *
  12. * This program is distributed in the hope that it will be useful. *
  13. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  14. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  15. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  16. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  17. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  18. * more details, a copy of which can be found in the file COPYING *
  19. * included with this package. *
  20. *******************************************************************/
  21. #include <linux/blkdev.h>
  22. #include <linux/delay.h>
  23. #include <linux/dma-mapping.h>
  24. #include <linux/idr.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/kthread.h>
  27. #include <linux/pci.h>
  28. #include <linux/spinlock.h>
  29. #include <scsi/scsi.h>
  30. #include <scsi/scsi_device.h>
  31. #include <scsi/scsi_host.h>
  32. #include <scsi/scsi_transport_fc.h>
  33. #include "lpfc_hw.h"
  34. #include "lpfc_sli.h"
  35. #include "lpfc_disc.h"
  36. #include "lpfc_scsi.h"
  37. #include "lpfc.h"
  38. #include "lpfc_logmsg.h"
  39. #include "lpfc_crtn.h"
  40. #include "lpfc_version.h"
  41. #include "lpfc_vport.h"
  42. inline void lpfc_vport_set_state(struct lpfc_vport *vport,
  43. enum fc_vport_state new_state)
  44. {
  45. struct fc_vport *fc_vport = vport->fc_vport;
  46. if (fc_vport) {
  47. /*
  48. * When the transport defines fc_vport_set state we will replace
  49. * this code with the following line
  50. */
  51. /* fc_vport_set_state(fc_vport, new_state); */
  52. if (new_state != FC_VPORT_INITIALIZING)
  53. fc_vport->vport_last_state = fc_vport->vport_state;
  54. fc_vport->vport_state = new_state;
  55. }
  56. /* for all the error states we will set the invternal state to FAILED */
  57. switch (new_state) {
  58. case FC_VPORT_NO_FABRIC_SUPP:
  59. case FC_VPORT_NO_FABRIC_RSCS:
  60. case FC_VPORT_FABRIC_LOGOUT:
  61. case FC_VPORT_FABRIC_REJ_WWN:
  62. case FC_VPORT_FAILED:
  63. vport->port_state = LPFC_VPORT_FAILED;
  64. break;
  65. case FC_VPORT_LINKDOWN:
  66. vport->port_state = LPFC_VPORT_UNKNOWN;
  67. break;
  68. default:
  69. /* do nothing */
  70. break;
  71. }
  72. }
  73. static int
  74. lpfc_alloc_vpi(struct lpfc_hba *phba)
  75. {
  76. int vpi;
  77. spin_lock_irq(&phba->hbalock);
  78. /* Start at bit 1 because vpi zero is reserved for the physical port */
  79. vpi = find_next_zero_bit(phba->vpi_bmask, (phba->max_vpi + 1), 1);
  80. if (vpi > phba->max_vpi)
  81. vpi = 0;
  82. else
  83. set_bit(vpi, phba->vpi_bmask);
  84. spin_unlock_irq(&phba->hbalock);
  85. return vpi;
  86. }
  87. static void
  88. lpfc_free_vpi(struct lpfc_hba *phba, int vpi)
  89. {
  90. spin_lock_irq(&phba->hbalock);
  91. clear_bit(vpi, phba->vpi_bmask);
  92. spin_unlock_irq(&phba->hbalock);
  93. }
  94. static int
  95. lpfc_vport_sparm(struct lpfc_hba *phba, struct lpfc_vport *vport)
  96. {
  97. LPFC_MBOXQ_t *pmb;
  98. MAILBOX_t *mb;
  99. struct lpfc_dmabuf *mp;
  100. int rc;
  101. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  102. if (!pmb) {
  103. return -ENOMEM;
  104. }
  105. mb = &pmb->mb;
  106. lpfc_read_sparam(phba, pmb, vport->vpi);
  107. /*
  108. * Grab buffer pointer and clear context1 so we can use
  109. * lpfc_sli_issue_box_wait
  110. */
  111. mp = (struct lpfc_dmabuf *) pmb->context1;
  112. pmb->context1 = NULL;
  113. pmb->vport = vport;
  114. rc = lpfc_sli_issue_mbox_wait(phba, pmb, phba->fc_ratov * 2);
  115. if (rc != MBX_SUCCESS) {
  116. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  117. "%d (%d):1818 VPort failed init, mbxCmd x%x "
  118. "READ_SPARM mbxStatus x%x, rc = x%x\n",
  119. phba->brd_no, vport->vpi,
  120. mb->mbxCommand, mb->mbxStatus, rc);
  121. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  122. kfree(mp);
  123. if (rc != MBX_TIMEOUT)
  124. mempool_free(pmb, phba->mbox_mem_pool);
  125. return -EIO;
  126. }
  127. memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
  128. memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
  129. sizeof (struct lpfc_name));
  130. memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
  131. sizeof (struct lpfc_name));
  132. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  133. kfree(mp);
  134. mempool_free(pmb, phba->mbox_mem_pool);
  135. return 0;
  136. }
  137. static int
  138. lpfc_valid_wwn_format(struct lpfc_hba *phba, struct lpfc_name *wwn,
  139. const char *name_type)
  140. {
  141. /* ensure that IEEE format 1 addresses
  142. * contain zeros in bits 59-48
  143. */
  144. if (!((wwn->u.wwn[0] >> 4) == 1 &&
  145. ((wwn->u.wwn[0] & 0xf) != 0 || (wwn->u.wwn[1] & 0xf) != 0)))
  146. return 1;
  147. lpfc_printf_log(phba, KERN_ERR, LOG_VPORT,
  148. "%d:1822 Invalid %s: %02x:%02x:%02x:%02x:"
  149. "%02x:%02x:%02x:%02x\n",
  150. phba->brd_no, name_type,
  151. wwn->u.wwn[0], wwn->u.wwn[1],
  152. wwn->u.wwn[2], wwn->u.wwn[3],
  153. wwn->u.wwn[4], wwn->u.wwn[5],
  154. wwn->u.wwn[6], wwn->u.wwn[7]);
  155. return 0;
  156. }
  157. static int
  158. lpfc_unique_wwpn(struct lpfc_hba *phba, struct lpfc_vport *new_vport)
  159. {
  160. struct lpfc_vport *vport;
  161. unsigned long flags;
  162. spin_lock_irqsave(&phba->hbalock, flags);
  163. list_for_each_entry(vport, &phba->port_list, listentry) {
  164. if (vport == new_vport)
  165. continue;
  166. /* If they match, return not unique */
  167. if (memcmp(&vport->fc_sparam.portName,
  168. &new_vport->fc_sparam.portName,
  169. sizeof(struct lpfc_name)) == 0) {
  170. spin_unlock_irqrestore(&phba->hbalock, flags);
  171. return 0;
  172. }
  173. }
  174. spin_unlock_irqrestore(&phba->hbalock, flags);
  175. return 1;
  176. }
  177. int
  178. lpfc_vport_create(struct fc_vport *fc_vport, bool disable)
  179. {
  180. struct lpfc_nodelist *ndlp;
  181. struct lpfc_vport *pport =
  182. (struct lpfc_vport *) fc_vport->shost->hostdata;
  183. struct lpfc_hba *phba = pport->phba;
  184. struct lpfc_vport *vport = NULL;
  185. int instance;
  186. int vpi;
  187. int rc = VPORT_ERROR;
  188. if ((phba->sli_rev < 3) ||
  189. !(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) {
  190. lpfc_printf_log(phba, KERN_ERR, LOG_VPORT,
  191. "%d:1808 Create VPORT failed: "
  192. "NPIV is not enabled: SLImode:%d\n",
  193. phba->brd_no, phba->sli_rev);
  194. rc = VPORT_INVAL;
  195. goto error_out;
  196. }
  197. vpi = lpfc_alloc_vpi(phba);
  198. if (vpi == 0) {
  199. lpfc_printf_log(phba, KERN_ERR, LOG_VPORT,
  200. "%d:1809 Create VPORT failed: "
  201. "Max VPORTs (%d) exceeded\n",
  202. phba->brd_no, phba->max_vpi);
  203. rc = VPORT_NORESOURCES;
  204. goto error_out;
  205. }
  206. /* Assign an unused board number */
  207. if ((instance = lpfc_get_instance()) < 0) {
  208. lpfc_printf_log(phba, KERN_ERR, LOG_VPORT,
  209. "%d:1810 Create VPORT failed: Cannot get "
  210. "instance number\n", phba->brd_no);
  211. lpfc_free_vpi(phba, vpi);
  212. rc = VPORT_NORESOURCES;
  213. goto error_out;
  214. }
  215. vport = lpfc_create_port(phba, instance, fc_vport);
  216. if (!vport) {
  217. lpfc_printf_log(phba, KERN_ERR, LOG_VPORT,
  218. "%d:1811 Create VPORT failed: vpi x%x\n",
  219. phba->brd_no, vpi);
  220. lpfc_free_vpi(phba, vpi);
  221. rc = VPORT_NORESOURCES;
  222. goto error_out;
  223. }
  224. vport->vpi = vpi;
  225. lpfc_debugfs_initialize(vport);
  226. if (lpfc_vport_sparm(phba, vport)) {
  227. lpfc_printf_log(phba, KERN_ERR, LOG_VPORT,
  228. "%d:1813 Create VPORT failed: vpi:%d "
  229. "Cannot get sparam\n",
  230. phba->brd_no, vpi);
  231. lpfc_free_vpi(phba, vpi);
  232. destroy_port(vport);
  233. rc = VPORT_NORESOURCES;
  234. goto error_out;
  235. }
  236. memcpy(vport->fc_portname.u.wwn, vport->fc_sparam.portName.u.wwn, 8);
  237. memcpy(vport->fc_nodename.u.wwn, vport->fc_sparam.nodeName.u.wwn, 8);
  238. if (fc_vport->node_name != 0)
  239. u64_to_wwn(fc_vport->node_name, vport->fc_nodename.u.wwn);
  240. if (fc_vport->port_name != 0)
  241. u64_to_wwn(fc_vport->port_name, vport->fc_portname.u.wwn);
  242. memcpy(&vport->fc_sparam.portName, vport->fc_portname.u.wwn, 8);
  243. memcpy(&vport->fc_sparam.nodeName, vport->fc_nodename.u.wwn, 8);
  244. if (!lpfc_valid_wwn_format(phba, &vport->fc_sparam.nodeName, "WWNN") ||
  245. !lpfc_valid_wwn_format(phba, &vport->fc_sparam.portName, "WWPN")) {
  246. lpfc_printf_log(phba, KERN_ERR, LOG_VPORT,
  247. "%d:1821 Create VPORT failed: vpi:%d "
  248. "Invalid WWN format\n",
  249. phba->brd_no, vpi);
  250. lpfc_free_vpi(phba, vpi);
  251. destroy_port(vport);
  252. rc = VPORT_INVAL;
  253. goto error_out;
  254. }
  255. if (!lpfc_unique_wwpn(phba, vport)) {
  256. lpfc_printf_log(phba, KERN_ERR, LOG_VPORT,
  257. "%d:1823 Create VPORT failed: vpi:%d "
  258. "Duplicate WWN on HBA\n",
  259. phba->brd_no, vpi);
  260. lpfc_free_vpi(phba, vpi);
  261. destroy_port(vport);
  262. rc = VPORT_INVAL;
  263. goto error_out;
  264. }
  265. *(struct lpfc_vport **)fc_vport->dd_data = vport;
  266. vport->fc_vport = fc_vport;
  267. if ((phba->link_state < LPFC_LINK_UP) ||
  268. (phba->fc_topology == TOPOLOGY_LOOP)) {
  269. lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN);
  270. rc = VPORT_OK;
  271. goto out;
  272. }
  273. if (disable) {
  274. rc = VPORT_OK;
  275. goto out;
  276. }
  277. /* Use the Physical nodes Fabric NDLP to determine if the link is
  278. * up and ready to FDISC.
  279. */
  280. ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
  281. if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
  282. if (phba->link_flag & LS_NPIV_FAB_SUPPORTED) {
  283. lpfc_set_disctmo(vport);
  284. lpfc_initial_fdisc(vport);
  285. } else {
  286. lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP);
  287. lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
  288. "%d (%d):0262 No NPIV Fabric "
  289. "support\n",
  290. phba->brd_no, vport->vpi);
  291. }
  292. } else {
  293. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  294. }
  295. rc = VPORT_OK;
  296. out:
  297. lpfc_printf_vlog(vport, KERN_ERR, LOG_VPORT,
  298. "1825 Vport Created.\n");
  299. lpfc_host_attrib_init(lpfc_shost_from_vport(vport));
  300. error_out:
  301. return rc;
  302. }
  303. int
  304. disable_vport(struct fc_vport *fc_vport)
  305. {
  306. struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
  307. struct lpfc_hba *phba = vport->phba;
  308. struct lpfc_nodelist *ndlp = NULL, *next_ndlp = NULL;
  309. long timeout;
  310. ndlp = lpfc_findnode_did(vport, Fabric_DID);
  311. if (ndlp && phba->link_state >= LPFC_LINK_UP) {
  312. vport->unreg_vpi_cmpl = VPORT_INVAL;
  313. timeout = msecs_to_jiffies(phba->fc_ratov * 2000);
  314. if (!lpfc_issue_els_npiv_logo(vport, ndlp))
  315. while (vport->unreg_vpi_cmpl == VPORT_INVAL && timeout)
  316. timeout = schedule_timeout(timeout);
  317. }
  318. lpfc_sli_host_down(vport);
  319. /* Mark all nodes for discovery so we can remove them by
  320. * calling lpfc_cleanup_rpis(vport, 1)
  321. */
  322. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  323. if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
  324. continue;
  325. lpfc_disc_state_machine(vport, ndlp, NULL,
  326. NLP_EVT_DEVICE_RECOVERY);
  327. }
  328. lpfc_cleanup_rpis(vport, 1);
  329. lpfc_stop_vport_timers(vport);
  330. lpfc_unreg_all_rpis(vport);
  331. lpfc_unreg_default_rpis(vport);
  332. /*
  333. * Completion of unreg_vpi (lpfc_mbx_cmpl_unreg_vpi) does the
  334. * scsi_host_put() to release the vport.
  335. */
  336. lpfc_mbx_unreg_vpi(vport);
  337. lpfc_vport_set_state(vport, FC_VPORT_DISABLED);
  338. lpfc_printf_vlog(vport, KERN_ERR, LOG_VPORT,
  339. "1826 Vport Disabled.\n");
  340. return VPORT_OK;
  341. }
  342. int
  343. enable_vport(struct fc_vport *fc_vport)
  344. {
  345. struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
  346. struct lpfc_hba *phba = vport->phba;
  347. struct lpfc_nodelist *ndlp = NULL;
  348. if ((phba->link_state < LPFC_LINK_UP) ||
  349. (phba->fc_topology == TOPOLOGY_LOOP)) {
  350. lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN);
  351. return VPORT_OK;
  352. }
  353. vport->load_flag |= FC_LOADING;
  354. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  355. /* Use the Physical nodes Fabric NDLP to determine if the link is
  356. * up and ready to FDISC.
  357. */
  358. ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
  359. if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
  360. if (phba->link_flag & LS_NPIV_FAB_SUPPORTED) {
  361. lpfc_set_disctmo(vport);
  362. lpfc_initial_fdisc(vport);
  363. } else {
  364. lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP);
  365. lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
  366. "%d (%d):0264 No NPIV Fabric "
  367. "support\n",
  368. phba->brd_no, vport->vpi);
  369. }
  370. } else {
  371. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  372. }
  373. lpfc_printf_vlog(vport, KERN_ERR, LOG_VPORT,
  374. "1827 Vport Enabled.\n");
  375. return VPORT_OK;
  376. }
  377. int
  378. lpfc_vport_disable(struct fc_vport *fc_vport, bool disable)
  379. {
  380. if (disable)
  381. return disable_vport(fc_vport);
  382. else
  383. return enable_vport(fc_vport);
  384. }
  385. int
  386. lpfc_vport_delete(struct fc_vport *fc_vport)
  387. {
  388. struct lpfc_nodelist *ndlp = NULL;
  389. struct lpfc_nodelist *next_ndlp;
  390. struct Scsi_Host *shost = (struct Scsi_Host *) fc_vport->shost;
  391. struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
  392. struct lpfc_hba *phba = vport->phba;
  393. long timeout;
  394. int rc = VPORT_ERROR;
  395. /*
  396. * This is a bit of a mess. We want to ensure the shost doesn't get
  397. * torn down until we're done with the embedded lpfc_vport structure.
  398. *
  399. * Beyond holding a reference for this function, we also need a
  400. * reference for outstanding I/O requests we schedule during delete
  401. * processing. But once we scsi_remove_host() we can no longer obtain
  402. * a reference through scsi_host_get().
  403. *
  404. * So we take two references here. We release one reference at the
  405. * bottom of the function -- after delinking the vport. And we
  406. * release the other at the completion of the unreg_vpi that get's
  407. * initiated after we've disposed of all other resources associated
  408. * with the port.
  409. */
  410. if (!scsi_host_get(shost) || !scsi_host_get(shost))
  411. return VPORT_INVAL;
  412. if (vport->port_type == LPFC_PHYSICAL_PORT) {
  413. lpfc_printf_log(phba, KERN_ERR, LOG_VPORT,
  414. "%d:1812 vport_delete failed: Cannot delete "
  415. "physical host\n", phba->brd_no);
  416. goto out;
  417. }
  418. vport->load_flag |= FC_UNLOADING;
  419. kfree(vport->vname);
  420. lpfc_debugfs_terminate(vport);
  421. fc_remove_host(lpfc_shost_from_vport(vport));
  422. scsi_remove_host(lpfc_shost_from_vport(vport));
  423. ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
  424. if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE &&
  425. phba->link_state >= LPFC_LINK_UP) {
  426. /* First look for the Fabric ndlp */
  427. ndlp = lpfc_findnode_did(vport, Fabric_DID);
  428. if (!ndlp) {
  429. /* Cannot find existing Fabric ndlp, allocate one */
  430. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  431. if (!ndlp)
  432. goto skip_logo;
  433. lpfc_nlp_init(vport, ndlp, Fabric_DID);
  434. } else {
  435. lpfc_dequeue_node(vport, ndlp);
  436. }
  437. vport->unreg_vpi_cmpl = VPORT_INVAL;
  438. timeout = msecs_to_jiffies(phba->fc_ratov * 2000);
  439. if (!lpfc_issue_els_npiv_logo(vport, ndlp))
  440. while (vport->unreg_vpi_cmpl == VPORT_INVAL && timeout)
  441. timeout = schedule_timeout(timeout);
  442. }
  443. skip_logo:
  444. lpfc_sli_host_down(vport);
  445. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  446. lpfc_disc_state_machine(vport, ndlp, NULL,
  447. NLP_EVT_DEVICE_RECOVERY);
  448. lpfc_disc_state_machine(vport, ndlp, NULL,
  449. NLP_EVT_DEVICE_RM);
  450. }
  451. lpfc_stop_vport_timers(vport);
  452. lpfc_unreg_all_rpis(vport);
  453. lpfc_unreg_default_rpis(vport);
  454. /*
  455. * Completion of unreg_vpi (lpfc_mbx_cmpl_unreg_vpi) does the
  456. * scsi_host_put() to release the vport.
  457. */
  458. lpfc_mbx_unreg_vpi(vport);
  459. lpfc_free_vpi(phba, vport->vpi);
  460. vport->work_port_events = 0;
  461. spin_lock_irq(&phba->hbalock);
  462. list_del_init(&vport->listentry);
  463. spin_unlock_irq(&phba->hbalock);
  464. lpfc_printf_vlog(vport, KERN_ERR, LOG_VPORT,
  465. "1828 Vport Deleted.\n");
  466. rc = VPORT_OK;
  467. out:
  468. scsi_host_put(shost);
  469. return rc;
  470. }
  471. EXPORT_SYMBOL(lpfc_vport_create);
  472. EXPORT_SYMBOL(lpfc_vport_delete);
  473. struct lpfc_vport **
  474. lpfc_create_vport_work_array(struct lpfc_hba *phba)
  475. {
  476. struct lpfc_vport *port_iterator;
  477. struct lpfc_vport **vports;
  478. int index = 0;
  479. vports = kzalloc(LPFC_MAX_VPORTS * sizeof(struct lpfc_vport *),
  480. GFP_KERNEL);
  481. if (vports == NULL)
  482. return NULL;
  483. spin_lock_irq(&phba->hbalock);
  484. list_for_each_entry(port_iterator, &phba->port_list, listentry) {
  485. if (!scsi_host_get(lpfc_shost_from_vport(port_iterator)))
  486. continue;
  487. vports[index++] = port_iterator;
  488. }
  489. spin_unlock_irq(&phba->hbalock);
  490. return vports;
  491. }
  492. void
  493. lpfc_destroy_vport_work_array(struct lpfc_vport **vports)
  494. {
  495. int i;
  496. if (vports == NULL)
  497. return;
  498. for (i=0; vports[i] != NULL && i < LPFC_MAX_VPORTS; i++)
  499. scsi_host_put(lpfc_shost_from_vport(vports[i]));
  500. kfree(vports);
  501. }