lpfc_vport.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  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_vlog(vport, KERN_ERR, LOG_INIT | LOG_VPORT,
  117. "1818 VPort failed init, mbxCmd x%x "
  118. "READ_SPARM mbxStatus x%x, rc = x%x\n",
  119. mb->mbxCommand, mb->mbxStatus, rc);
  120. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  121. kfree(mp);
  122. if (rc != MBX_TIMEOUT)
  123. mempool_free(pmb, phba->mbox_mem_pool);
  124. return -EIO;
  125. }
  126. memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
  127. memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
  128. sizeof (struct lpfc_name));
  129. memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
  130. sizeof (struct lpfc_name));
  131. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  132. kfree(mp);
  133. mempool_free(pmb, phba->mbox_mem_pool);
  134. return 0;
  135. }
  136. static int
  137. lpfc_valid_wwn_format(struct lpfc_hba *phba, struct lpfc_name *wwn,
  138. const char *name_type)
  139. {
  140. /* ensure that IEEE format 1 addresses
  141. * contain zeros in bits 59-48
  142. */
  143. if (!((wwn->u.wwn[0] >> 4) == 1 &&
  144. ((wwn->u.wwn[0] & 0xf) != 0 || (wwn->u.wwn[1] & 0xf) != 0)))
  145. return 1;
  146. lpfc_printf_log(phba, KERN_ERR, LOG_VPORT,
  147. "1822 Invalid %s: %02x:%02x:%02x:%02x:"
  148. "%02x:%02x:%02x:%02x\n",
  149. name_type,
  150. wwn->u.wwn[0], wwn->u.wwn[1],
  151. wwn->u.wwn[2], wwn->u.wwn[3],
  152. wwn->u.wwn[4], wwn->u.wwn[5],
  153. wwn->u.wwn[6], wwn->u.wwn[7]);
  154. return 0;
  155. }
  156. static int
  157. lpfc_unique_wwpn(struct lpfc_hba *phba, struct lpfc_vport *new_vport)
  158. {
  159. struct lpfc_vport *vport;
  160. unsigned long flags;
  161. spin_lock_irqsave(&phba->hbalock, flags);
  162. list_for_each_entry(vport, &phba->port_list, listentry) {
  163. if (vport == new_vport)
  164. continue;
  165. /* If they match, return not unique */
  166. if (memcmp(&vport->fc_sparam.portName,
  167. &new_vport->fc_sparam.portName,
  168. sizeof(struct lpfc_name)) == 0) {
  169. spin_unlock_irqrestore(&phba->hbalock, flags);
  170. return 0;
  171. }
  172. }
  173. spin_unlock_irqrestore(&phba->hbalock, flags);
  174. return 1;
  175. }
  176. int
  177. lpfc_vport_create(struct fc_vport *fc_vport, bool disable)
  178. {
  179. struct lpfc_nodelist *ndlp;
  180. struct Scsi_Host *shost = fc_vport->shost;
  181. struct lpfc_vport *pport = (struct lpfc_vport *) shost->hostdata;
  182. struct lpfc_hba *phba = pport->phba;
  183. struct lpfc_vport *vport = NULL;
  184. int instance;
  185. int vpi;
  186. int rc = VPORT_ERROR;
  187. if ((phba->sli_rev < 3) ||
  188. !(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) {
  189. lpfc_printf_log(phba, KERN_ERR, LOG_VPORT,
  190. "1808 Create VPORT failed: "
  191. "NPIV is not enabled: SLImode:%d\n",
  192. phba->sli_rev);
  193. rc = VPORT_INVAL;
  194. goto error_out;
  195. }
  196. vpi = lpfc_alloc_vpi(phba);
  197. if (vpi == 0) {
  198. lpfc_printf_log(phba, KERN_ERR, LOG_VPORT,
  199. "1809 Create VPORT failed: "
  200. "Max VPORTs (%d) exceeded\n",
  201. phba->max_vpi);
  202. rc = VPORT_NORESOURCES;
  203. goto error_out;
  204. }
  205. /* Assign an unused board number */
  206. if ((instance = lpfc_get_instance()) < 0) {
  207. lpfc_printf_log(phba, KERN_ERR, LOG_VPORT,
  208. "1810 Create VPORT failed: Cannot get "
  209. "instance number\n");
  210. lpfc_free_vpi(phba, vpi);
  211. rc = VPORT_NORESOURCES;
  212. goto error_out;
  213. }
  214. vport = lpfc_create_port(phba, instance, &fc_vport->dev);
  215. if (!vport) {
  216. lpfc_printf_log(phba, KERN_ERR, LOG_VPORT,
  217. "1811 Create VPORT failed: vpi x%x\n", vpi);
  218. lpfc_free_vpi(phba, vpi);
  219. rc = VPORT_NORESOURCES;
  220. goto error_out;
  221. }
  222. vport->vpi = vpi;
  223. lpfc_debugfs_initialize(vport);
  224. if (lpfc_vport_sparm(phba, vport)) {
  225. lpfc_printf_vlog(vport, KERN_ERR, LOG_VPORT,
  226. "1813 Create VPORT failed. "
  227. "Cannot get sparam\n");
  228. lpfc_free_vpi(phba, vpi);
  229. destroy_port(vport);
  230. rc = VPORT_NORESOURCES;
  231. goto error_out;
  232. }
  233. memcpy(vport->fc_portname.u.wwn, vport->fc_sparam.portName.u.wwn, 8);
  234. memcpy(vport->fc_nodename.u.wwn, vport->fc_sparam.nodeName.u.wwn, 8);
  235. if (fc_vport->node_name != 0)
  236. u64_to_wwn(fc_vport->node_name, vport->fc_nodename.u.wwn);
  237. if (fc_vport->port_name != 0)
  238. u64_to_wwn(fc_vport->port_name, vport->fc_portname.u.wwn);
  239. memcpy(&vport->fc_sparam.portName, vport->fc_portname.u.wwn, 8);
  240. memcpy(&vport->fc_sparam.nodeName, vport->fc_nodename.u.wwn, 8);
  241. if (!lpfc_valid_wwn_format(phba, &vport->fc_sparam.nodeName, "WWNN") ||
  242. !lpfc_valid_wwn_format(phba, &vport->fc_sparam.portName, "WWPN")) {
  243. lpfc_printf_vlog(vport, KERN_ERR, LOG_VPORT,
  244. "1821 Create VPORT failed. "
  245. "Invalid WWN format\n");
  246. lpfc_free_vpi(phba, vpi);
  247. destroy_port(vport);
  248. rc = VPORT_INVAL;
  249. goto error_out;
  250. }
  251. if (!lpfc_unique_wwpn(phba, vport)) {
  252. lpfc_printf_vlog(vport, KERN_ERR, LOG_VPORT,
  253. "1823 Create VPORT failed. "
  254. "Duplicate WWN on HBA\n");
  255. lpfc_free_vpi(phba, vpi);
  256. destroy_port(vport);
  257. rc = VPORT_INVAL;
  258. goto error_out;
  259. }
  260. *(struct lpfc_vport **)fc_vport->dd_data = vport;
  261. vport->fc_vport = fc_vport;
  262. if ((phba->link_state < LPFC_LINK_UP) ||
  263. (phba->fc_topology == TOPOLOGY_LOOP)) {
  264. lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN);
  265. rc = VPORT_OK;
  266. goto out;
  267. }
  268. if (disable) {
  269. rc = VPORT_OK;
  270. goto out;
  271. }
  272. /* Use the Physical nodes Fabric NDLP to determine if the link is
  273. * up and ready to FDISC.
  274. */
  275. ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
  276. if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
  277. if (phba->link_flag & LS_NPIV_FAB_SUPPORTED) {
  278. lpfc_set_disctmo(vport);
  279. lpfc_initial_fdisc(vport);
  280. } else {
  281. lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP);
  282. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  283. "0262 No NPIV Fabric support\n");
  284. }
  285. } else {
  286. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  287. }
  288. rc = VPORT_OK;
  289. out:
  290. lpfc_printf_vlog(vport, KERN_ERR, LOG_VPORT,
  291. "1825 Vport Created.\n");
  292. lpfc_host_attrib_init(lpfc_shost_from_vport(vport));
  293. error_out:
  294. return rc;
  295. }
  296. static int
  297. disable_vport(struct fc_vport *fc_vport)
  298. {
  299. struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
  300. struct lpfc_hba *phba = vport->phba;
  301. struct lpfc_nodelist *ndlp = NULL, *next_ndlp = NULL;
  302. long timeout;
  303. ndlp = lpfc_findnode_did(vport, Fabric_DID);
  304. if (ndlp && phba->link_state >= LPFC_LINK_UP) {
  305. vport->unreg_vpi_cmpl = VPORT_INVAL;
  306. timeout = msecs_to_jiffies(phba->fc_ratov * 2000);
  307. if (!lpfc_issue_els_npiv_logo(vport, ndlp))
  308. while (vport->unreg_vpi_cmpl == VPORT_INVAL && timeout)
  309. timeout = schedule_timeout(timeout);
  310. }
  311. lpfc_sli_host_down(vport);
  312. /* Mark all nodes for discovery so we can remove them by
  313. * calling lpfc_cleanup_rpis(vport, 1)
  314. */
  315. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  316. if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
  317. continue;
  318. lpfc_disc_state_machine(vport, ndlp, NULL,
  319. NLP_EVT_DEVICE_RECOVERY);
  320. }
  321. lpfc_cleanup_rpis(vport, 1);
  322. lpfc_stop_vport_timers(vport);
  323. lpfc_unreg_all_rpis(vport);
  324. lpfc_unreg_default_rpis(vport);
  325. /*
  326. * Completion of unreg_vpi (lpfc_mbx_cmpl_unreg_vpi) does the
  327. * scsi_host_put() to release the vport.
  328. */
  329. lpfc_mbx_unreg_vpi(vport);
  330. lpfc_vport_set_state(vport, FC_VPORT_DISABLED);
  331. lpfc_printf_vlog(vport, KERN_ERR, LOG_VPORT,
  332. "1826 Vport Disabled.\n");
  333. return VPORT_OK;
  334. }
  335. static int
  336. enable_vport(struct fc_vport *fc_vport)
  337. {
  338. struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
  339. struct lpfc_hba *phba = vport->phba;
  340. struct lpfc_nodelist *ndlp = NULL;
  341. if ((phba->link_state < LPFC_LINK_UP) ||
  342. (phba->fc_topology == TOPOLOGY_LOOP)) {
  343. lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN);
  344. return VPORT_OK;
  345. }
  346. vport->load_flag |= FC_LOADING;
  347. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  348. /* Use the Physical nodes Fabric NDLP to determine if the link is
  349. * up and ready to FDISC.
  350. */
  351. ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
  352. if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
  353. if (phba->link_flag & LS_NPIV_FAB_SUPPORTED) {
  354. lpfc_set_disctmo(vport);
  355. lpfc_initial_fdisc(vport);
  356. } else {
  357. lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP);
  358. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  359. "0264 No NPIV Fabric support\n");
  360. }
  361. } else {
  362. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  363. }
  364. lpfc_printf_vlog(vport, KERN_ERR, LOG_VPORT,
  365. "1827 Vport Enabled.\n");
  366. return VPORT_OK;
  367. }
  368. int
  369. lpfc_vport_disable(struct fc_vport *fc_vport, bool disable)
  370. {
  371. if (disable)
  372. return disable_vport(fc_vport);
  373. else
  374. return enable_vport(fc_vport);
  375. }
  376. int
  377. lpfc_vport_delete(struct fc_vport *fc_vport)
  378. {
  379. struct lpfc_nodelist *ndlp = NULL;
  380. struct lpfc_nodelist *next_ndlp;
  381. struct Scsi_Host *shost = (struct Scsi_Host *) fc_vport->shost;
  382. struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
  383. struct lpfc_hba *phba = vport->phba;
  384. long timeout;
  385. if (vport->port_type == LPFC_PHYSICAL_PORT) {
  386. lpfc_printf_vlog(vport, KERN_ERR, LOG_VPORT,
  387. "1812 vport_delete failed: Cannot delete "
  388. "physical host\n");
  389. return VPORT_ERROR;
  390. }
  391. /*
  392. * If we are not unloading the driver then prevent the vport_delete
  393. * from happening until after this vport's discovery is finished.
  394. */
  395. if (!(phba->pport->load_flag & FC_UNLOADING)) {
  396. int check_count = 0;
  397. while (check_count < ((phba->fc_ratov * 3) + 3) &&
  398. vport->port_state > LPFC_VPORT_FAILED &&
  399. vport->port_state < LPFC_VPORT_READY) {
  400. check_count++;
  401. msleep(1000);
  402. }
  403. if (vport->port_state > LPFC_VPORT_FAILED &&
  404. vport->port_state < LPFC_VPORT_READY)
  405. return -EAGAIN;
  406. }
  407. /*
  408. * This is a bit of a mess. We want to ensure the shost doesn't get
  409. * torn down until we're done with the embedded lpfc_vport structure.
  410. *
  411. * Beyond holding a reference for this function, we also need a
  412. * reference for outstanding I/O requests we schedule during delete
  413. * processing. But once we scsi_remove_host() we can no longer obtain
  414. * a reference through scsi_host_get().
  415. *
  416. * So we take two references here. We release one reference at the
  417. * bottom of the function -- after delinking the vport. And we
  418. * release the other at the completion of the unreg_vpi that get's
  419. * initiated after we've disposed of all other resources associated
  420. * with the port.
  421. */
  422. if (!scsi_host_get(shost) || !scsi_host_get(shost))
  423. return VPORT_INVAL;
  424. spin_lock_irq(&phba->hbalock);
  425. vport->load_flag |= FC_UNLOADING;
  426. spin_unlock_irq(&phba->hbalock);
  427. kfree(vport->vname);
  428. lpfc_debugfs_terminate(vport);
  429. fc_remove_host(lpfc_shost_from_vport(vport));
  430. scsi_remove_host(lpfc_shost_from_vport(vport));
  431. ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
  432. if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE &&
  433. phba->link_state >= LPFC_LINK_UP) {
  434. /* First look for the Fabric ndlp */
  435. ndlp = lpfc_findnode_did(vport, Fabric_DID);
  436. if (!ndlp) {
  437. /* Cannot find existing Fabric ndlp, allocate one */
  438. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  439. if (!ndlp)
  440. goto skip_logo;
  441. lpfc_nlp_init(vport, ndlp, Fabric_DID);
  442. } else {
  443. lpfc_dequeue_node(vport, ndlp);
  444. }
  445. vport->unreg_vpi_cmpl = VPORT_INVAL;
  446. timeout = msecs_to_jiffies(phba->fc_ratov * 2000);
  447. if (!lpfc_issue_els_npiv_logo(vport, ndlp))
  448. while (vport->unreg_vpi_cmpl == VPORT_INVAL && timeout)
  449. timeout = schedule_timeout(timeout);
  450. }
  451. skip_logo:
  452. lpfc_sli_host_down(vport);
  453. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  454. lpfc_disc_state_machine(vport, ndlp, NULL,
  455. NLP_EVT_DEVICE_RECOVERY);
  456. lpfc_disc_state_machine(vport, ndlp, NULL,
  457. NLP_EVT_DEVICE_RM);
  458. }
  459. lpfc_stop_vport_timers(vport);
  460. lpfc_unreg_all_rpis(vport);
  461. lpfc_unreg_default_rpis(vport);
  462. /*
  463. * Completion of unreg_vpi (lpfc_mbx_cmpl_unreg_vpi) does the
  464. * scsi_host_put() to release the vport.
  465. */
  466. lpfc_mbx_unreg_vpi(vport);
  467. lpfc_free_vpi(phba, vport->vpi);
  468. vport->work_port_events = 0;
  469. spin_lock_irq(&phba->hbalock);
  470. list_del_init(&vport->listentry);
  471. spin_unlock_irq(&phba->hbalock);
  472. lpfc_printf_vlog(vport, KERN_ERR, LOG_VPORT,
  473. "1828 Vport Deleted.\n");
  474. scsi_host_put(shost);
  475. return VPORT_OK;
  476. }
  477. EXPORT_SYMBOL(lpfc_vport_create);
  478. EXPORT_SYMBOL(lpfc_vport_delete);
  479. struct lpfc_vport **
  480. lpfc_create_vport_work_array(struct lpfc_hba *phba)
  481. {
  482. struct lpfc_vport *port_iterator;
  483. struct lpfc_vport **vports;
  484. int index = 0;
  485. vports = kzalloc(LPFC_MAX_VPORTS * sizeof(struct lpfc_vport *),
  486. GFP_KERNEL);
  487. if (vports == NULL)
  488. return NULL;
  489. spin_lock_irq(&phba->hbalock);
  490. list_for_each_entry(port_iterator, &phba->port_list, listentry) {
  491. if (!scsi_host_get(lpfc_shost_from_vport(port_iterator))) {
  492. lpfc_printf_vlog(port_iterator, KERN_WARNING, LOG_VPORT,
  493. "1801 Create vport work array FAILED: "
  494. "cannot do scsi_host_get\n");
  495. continue;
  496. }
  497. vports[index++] = port_iterator;
  498. }
  499. spin_unlock_irq(&phba->hbalock);
  500. return vports;
  501. }
  502. void
  503. lpfc_destroy_vport_work_array(struct lpfc_vport **vports)
  504. {
  505. int i;
  506. if (vports == NULL)
  507. return;
  508. for (i=0; vports[i] != NULL && i < LPFC_MAX_VPORTS; i++)
  509. scsi_host_put(lpfc_shost_from_vport(vports[i]));
  510. kfree(vports);
  511. }