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