lpfc_vport.c 19 KB

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