James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1 | /******************************************************************* |
| 2 | * This file is part of the Emulex Linux Device Driver for * |
| 3 | * Fibre Channel Host Bus Adapters. * |
James Smart | a89a96b | 2013-07-15 18:35:40 -0400 | [diff] [blame] | 4 | * Copyright (C) 2004-2013 Emulex. All rights reserved. * |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 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> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 29 | #include <linux/slab.h> |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 30 | #include <linux/spinlock.h> |
| 31 | |
| 32 | #include <scsi/scsi.h> |
| 33 | #include <scsi/scsi_device.h> |
| 34 | #include <scsi/scsi_host.h> |
| 35 | #include <scsi/scsi_transport_fc.h> |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 36 | #include "lpfc_hw4.h" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 37 | #include "lpfc_hw.h" |
| 38 | #include "lpfc_sli.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 39 | #include "lpfc_sli4.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 40 | #include "lpfc_nl.h" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 41 | #include "lpfc_disc.h" |
| 42 | #include "lpfc_scsi.h" |
| 43 | #include "lpfc.h" |
| 44 | #include "lpfc_logmsg.h" |
| 45 | #include "lpfc_crtn.h" |
| 46 | #include "lpfc_version.h" |
| 47 | #include "lpfc_vport.h" |
| 48 | |
| 49 | inline void lpfc_vport_set_state(struct lpfc_vport *vport, |
| 50 | enum fc_vport_state new_state) |
| 51 | { |
| 52 | struct fc_vport *fc_vport = vport->fc_vport; |
| 53 | |
| 54 | if (fc_vport) { |
| 55 | /* |
| 56 | * When the transport defines fc_vport_set state we will replace |
| 57 | * this code with the following line |
| 58 | */ |
| 59 | /* fc_vport_set_state(fc_vport, new_state); */ |
| 60 | if (new_state != FC_VPORT_INITIALIZING) |
| 61 | fc_vport->vport_last_state = fc_vport->vport_state; |
| 62 | fc_vport->vport_state = new_state; |
| 63 | } |
| 64 | |
| 65 | /* for all the error states we will set the invternal state to FAILED */ |
| 66 | switch (new_state) { |
| 67 | case FC_VPORT_NO_FABRIC_SUPP: |
| 68 | case FC_VPORT_NO_FABRIC_RSCS: |
| 69 | case FC_VPORT_FABRIC_LOGOUT: |
| 70 | case FC_VPORT_FABRIC_REJ_WWN: |
| 71 | case FC_VPORT_FAILED: |
| 72 | vport->port_state = LPFC_VPORT_FAILED; |
| 73 | break; |
| 74 | case FC_VPORT_LINKDOWN: |
| 75 | vport->port_state = LPFC_VPORT_UNKNOWN; |
| 76 | break; |
| 77 | default: |
| 78 | /* do nothing */ |
| 79 | break; |
| 80 | } |
| 81 | } |
| 82 | |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 83 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 84 | lpfc_alloc_vpi(struct lpfc_hba *phba) |
| 85 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 86 | unsigned long vpi; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 87 | |
| 88 | spin_lock_irq(&phba->hbalock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 89 | /* Start at bit 1 because vpi zero is reserved for the physical port */ |
| 90 | vpi = find_next_zero_bit(phba->vpi_bmask, (phba->max_vpi + 1), 1); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 91 | if (vpi > phba->max_vpi) |
| 92 | vpi = 0; |
| 93 | else |
| 94 | set_bit(vpi, phba->vpi_bmask); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 95 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 96 | phba->sli4_hba.max_cfg_param.vpi_used++; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 97 | spin_unlock_irq(&phba->hbalock); |
| 98 | return vpi; |
| 99 | } |
| 100 | |
| 101 | static void |
| 102 | lpfc_free_vpi(struct lpfc_hba *phba, int vpi) |
| 103 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 104 | if (vpi == 0) |
| 105 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 106 | spin_lock_irq(&phba->hbalock); |
| 107 | clear_bit(vpi, phba->vpi_bmask); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 108 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 109 | phba->sli4_hba.max_cfg_param.vpi_used--; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 110 | spin_unlock_irq(&phba->hbalock); |
| 111 | } |
| 112 | |
| 113 | static int |
| 114 | lpfc_vport_sparm(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 115 | { |
| 116 | LPFC_MBOXQ_t *pmb; |
| 117 | MAILBOX_t *mb; |
| 118 | struct lpfc_dmabuf *mp; |
| 119 | int rc; |
| 120 | |
| 121 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 122 | if (!pmb) { |
| 123 | return -ENOMEM; |
| 124 | } |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 125 | mb = &pmb->u.mb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 126 | |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 127 | rc = lpfc_read_sparam(phba, pmb, vport->vpi); |
| 128 | if (rc) { |
| 129 | mempool_free(pmb, phba->mbox_mem_pool); |
| 130 | return -ENOMEM; |
| 131 | } |
| 132 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 133 | /* |
| 134 | * Grab buffer pointer and clear context1 so we can use |
| 135 | * lpfc_sli_issue_box_wait |
| 136 | */ |
| 137 | mp = (struct lpfc_dmabuf *) pmb->context1; |
| 138 | pmb->context1 = NULL; |
| 139 | |
| 140 | pmb->vport = vport; |
| 141 | rc = lpfc_sli_issue_mbox_wait(phba, pmb, phba->fc_ratov * 2); |
| 142 | if (rc != MBX_SUCCESS) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 143 | if (signal_pending(current)) { |
| 144 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT | LOG_VPORT, |
| 145 | "1830 Signal aborted mbxCmd x%x\n", |
| 146 | mb->mbxCommand); |
| 147 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 148 | kfree(mp); |
| 149 | if (rc != MBX_TIMEOUT) |
| 150 | mempool_free(pmb, phba->mbox_mem_pool); |
| 151 | return -EINTR; |
| 152 | } else { |
| 153 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT | LOG_VPORT, |
| 154 | "1818 VPort failed init, mbxCmd x%x " |
| 155 | "READ_SPARM mbxStatus x%x, rc = x%x\n", |
| 156 | mb->mbxCommand, mb->mbxStatus, rc); |
| 157 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 158 | kfree(mp); |
| 159 | if (rc != MBX_TIMEOUT) |
| 160 | mempool_free(pmb, phba->mbox_mem_pool); |
| 161 | return -EIO; |
| 162 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm)); |
| 166 | memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName, |
| 167 | sizeof (struct lpfc_name)); |
| 168 | memcpy(&vport->fc_portname, &vport->fc_sparam.portName, |
| 169 | sizeof (struct lpfc_name)); |
| 170 | |
| 171 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 172 | kfree(mp); |
| 173 | mempool_free(pmb, phba->mbox_mem_pool); |
| 174 | |
| 175 | return 0; |
| 176 | } |
| 177 | |
| 178 | static int |
| 179 | lpfc_valid_wwn_format(struct lpfc_hba *phba, struct lpfc_name *wwn, |
| 180 | const char *name_type) |
| 181 | { |
| 182 | /* ensure that IEEE format 1 addresses |
| 183 | * contain zeros in bits 59-48 |
| 184 | */ |
| 185 | if (!((wwn->u.wwn[0] >> 4) == 1 && |
| 186 | ((wwn->u.wwn[0] & 0xf) != 0 || (wwn->u.wwn[1] & 0xf) != 0))) |
| 187 | return 1; |
| 188 | |
| 189 | lpfc_printf_log(phba, KERN_ERR, LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 190 | "1822 Invalid %s: %02x:%02x:%02x:%02x:" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 191 | "%02x:%02x:%02x:%02x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 192 | name_type, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 193 | wwn->u.wwn[0], wwn->u.wwn[1], |
| 194 | wwn->u.wwn[2], wwn->u.wwn[3], |
| 195 | wwn->u.wwn[4], wwn->u.wwn[5], |
| 196 | wwn->u.wwn[6], wwn->u.wwn[7]); |
| 197 | return 0; |
| 198 | } |
| 199 | |
| 200 | static int |
| 201 | lpfc_unique_wwpn(struct lpfc_hba *phba, struct lpfc_vport *new_vport) |
| 202 | { |
| 203 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 204 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 205 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 206 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 207 | list_for_each_entry(vport, &phba->port_list, listentry) { |
| 208 | if (vport == new_vport) |
| 209 | continue; |
| 210 | /* If they match, return not unique */ |
| 211 | if (memcmp(&vport->fc_sparam.portName, |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 212 | &new_vport->fc_sparam.portName, |
| 213 | sizeof(struct lpfc_name)) == 0) { |
| 214 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 215 | return 0; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 216 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 217 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 218 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 219 | return 1; |
| 220 | } |
| 221 | |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 222 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 223 | * lpfc_discovery_wait - Wait for driver discovery to quiesce |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 224 | * @vport: The virtual port for which this call is being executed. |
| 225 | * |
| 226 | * This driver calls this routine specifically from lpfc_vport_delete |
| 227 | * to enforce a synchronous execution of vport |
| 228 | * delete relative to discovery activities. The |
| 229 | * lpfc_vport_delete routine should not return until it |
| 230 | * can reasonably guarantee that discovery has quiesced. |
| 231 | * Post FDISC LOGO, the driver must wait until its SAN teardown is |
| 232 | * complete and all resources recovered before allowing |
| 233 | * cleanup. |
| 234 | * |
| 235 | * This routine does not require any locks held. |
| 236 | **/ |
| 237 | static void lpfc_discovery_wait(struct lpfc_vport *vport) |
| 238 | { |
| 239 | struct lpfc_hba *phba = vport->phba; |
| 240 | uint32_t wait_flags = 0; |
| 241 | unsigned long wait_time_max; |
| 242 | unsigned long start_time; |
| 243 | |
| 244 | wait_flags = FC_RSCN_MODE | FC_RSCN_DISCOVERY | FC_NLP_MORE | |
| 245 | FC_RSCN_DEFERRED | FC_NDISC_ACTIVE | FC_DISC_TMO; |
| 246 | |
| 247 | /* |
| 248 | * The time constraint on this loop is a balance between the |
| 249 | * fabric RA_TOV value and dev_loss tmo. The driver's |
| 250 | * devloss_tmo is 10 giving this loop a 3x multiplier minimally. |
| 251 | */ |
| 252 | wait_time_max = msecs_to_jiffies(((phba->fc_ratov * 3) + 3) * 1000); |
| 253 | wait_time_max += jiffies; |
| 254 | start_time = jiffies; |
| 255 | while (time_before(jiffies, wait_time_max)) { |
| 256 | if ((vport->num_disc_nodes > 0) || |
| 257 | (vport->fc_flag & wait_flags) || |
| 258 | ((vport->port_state > LPFC_VPORT_FAILED) && |
| 259 | (vport->port_state < LPFC_VPORT_READY))) { |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 260 | lpfc_printf_vlog(vport, KERN_INFO, LOG_VPORT, |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 261 | "1833 Vport discovery quiesce Wait:" |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 262 | " state x%x fc_flags x%x" |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 263 | " num_nodes x%x, waiting 1000 msecs" |
| 264 | " total wait msecs x%x\n", |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 265 | vport->port_state, vport->fc_flag, |
| 266 | vport->num_disc_nodes, |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 267 | jiffies_to_msecs(jiffies - start_time)); |
| 268 | msleep(1000); |
| 269 | } else { |
| 270 | /* Base case. Wait variants satisfied. Break out */ |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 271 | lpfc_printf_vlog(vport, KERN_INFO, LOG_VPORT, |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 272 | "1834 Vport discovery quiesced:" |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 273 | " state x%x fc_flags x%x" |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 274 | " wait msecs x%x\n", |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 275 | vport->port_state, vport->fc_flag, |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 276 | jiffies_to_msecs(jiffies |
| 277 | - start_time)); |
| 278 | break; |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | if (time_after(jiffies, wait_time_max)) |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 283 | lpfc_printf_vlog(vport, KERN_ERR, LOG_VPORT, |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 284 | "1835 Vport discovery quiesce failed:" |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 285 | " state x%x fc_flags x%x wait msecs x%x\n", |
| 286 | vport->port_state, vport->fc_flag, |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 287 | jiffies_to_msecs(jiffies - start_time)); |
| 288 | } |
| 289 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 290 | int |
| 291 | lpfc_vport_create(struct fc_vport *fc_vport, bool disable) |
| 292 | { |
| 293 | struct lpfc_nodelist *ndlp; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 294 | struct Scsi_Host *shost = fc_vport->shost; |
| 295 | struct lpfc_vport *pport = (struct lpfc_vport *) shost->hostdata; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 296 | struct lpfc_hba *phba = pport->phba; |
| 297 | struct lpfc_vport *vport = NULL; |
| 298 | int instance; |
| 299 | int vpi; |
| 300 | int rc = VPORT_ERROR; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 301 | int status; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 302 | |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 303 | if ((phba->sli_rev < 3) || !(phba->cfg_enable_npiv)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 304 | lpfc_printf_log(phba, KERN_ERR, LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 305 | "1808 Create VPORT failed: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 306 | "NPIV is not enabled: SLImode:%d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 307 | phba->sli_rev); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 308 | rc = VPORT_INVAL; |
| 309 | goto error_out; |
| 310 | } |
| 311 | |
| 312 | vpi = lpfc_alloc_vpi(phba); |
| 313 | if (vpi == 0) { |
| 314 | lpfc_printf_log(phba, KERN_ERR, LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 315 | "1809 Create VPORT failed: " |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 316 | "Max VPORTs (%d) exceeded\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 317 | phba->max_vpi); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 318 | rc = VPORT_NORESOURCES; |
| 319 | goto error_out; |
| 320 | } |
| 321 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 322 | /* Assign an unused board number */ |
| 323 | if ((instance = lpfc_get_instance()) < 0) { |
| 324 | lpfc_printf_log(phba, KERN_ERR, LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 325 | "1810 Create VPORT failed: Cannot get " |
| 326 | "instance number\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 327 | lpfc_free_vpi(phba, vpi); |
| 328 | rc = VPORT_NORESOURCES; |
| 329 | goto error_out; |
| 330 | } |
| 331 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 332 | vport = lpfc_create_port(phba, instance, &fc_vport->dev); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 333 | if (!vport) { |
| 334 | lpfc_printf_log(phba, KERN_ERR, LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 335 | "1811 Create VPORT failed: vpi x%x\n", vpi); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 336 | lpfc_free_vpi(phba, vpi); |
| 337 | rc = VPORT_NORESOURCES; |
| 338 | goto error_out; |
| 339 | } |
| 340 | |
| 341 | vport->vpi = vpi; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 342 | lpfc_debugfs_initialize(vport); |
| 343 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 344 | if ((status = lpfc_vport_sparm(phba, vport))) { |
| 345 | if (status == -EINTR) { |
| 346 | lpfc_printf_vlog(vport, KERN_ERR, LOG_VPORT, |
| 347 | "1831 Create VPORT Interrupted.\n"); |
| 348 | rc = VPORT_ERROR; |
| 349 | } else { |
| 350 | lpfc_printf_vlog(vport, KERN_ERR, LOG_VPORT, |
| 351 | "1813 Create VPORT failed. " |
| 352 | "Cannot get sparam\n"); |
| 353 | rc = VPORT_NORESOURCES; |
| 354 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 355 | lpfc_free_vpi(phba, vpi); |
| 356 | destroy_port(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 357 | goto error_out; |
| 358 | } |
| 359 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 360 | u64_to_wwn(fc_vport->node_name, vport->fc_nodename.u.wwn); |
| 361 | u64_to_wwn(fc_vport->port_name, vport->fc_portname.u.wwn); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 362 | |
| 363 | memcpy(&vport->fc_sparam.portName, vport->fc_portname.u.wwn, 8); |
| 364 | memcpy(&vport->fc_sparam.nodeName, vport->fc_nodename.u.wwn, 8); |
| 365 | |
| 366 | if (!lpfc_valid_wwn_format(phba, &vport->fc_sparam.nodeName, "WWNN") || |
| 367 | !lpfc_valid_wwn_format(phba, &vport->fc_sparam.portName, "WWPN")) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 368 | lpfc_printf_vlog(vport, KERN_ERR, LOG_VPORT, |
| 369 | "1821 Create VPORT failed. " |
| 370 | "Invalid WWN format\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 371 | lpfc_free_vpi(phba, vpi); |
| 372 | destroy_port(vport); |
| 373 | rc = VPORT_INVAL; |
| 374 | goto error_out; |
| 375 | } |
| 376 | |
| 377 | if (!lpfc_unique_wwpn(phba, vport)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 378 | lpfc_printf_vlog(vport, KERN_ERR, LOG_VPORT, |
| 379 | "1823 Create VPORT failed. " |
| 380 | "Duplicate WWN on HBA\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 381 | lpfc_free_vpi(phba, vpi); |
| 382 | destroy_port(vport); |
| 383 | rc = VPORT_INVAL; |
| 384 | goto error_out; |
| 385 | } |
| 386 | |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 387 | /* Create binary sysfs attribute for vport */ |
| 388 | lpfc_alloc_sysfs_attr(vport); |
| 389 | |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 390 | /* Set the DFT_LUN_Q_DEPTH accordingly */ |
| 391 | vport->cfg_lun_queue_depth = phba->pport->cfg_lun_queue_depth; |
| 392 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 393 | *(struct lpfc_vport **)fc_vport->dd_data = vport; |
| 394 | vport->fc_vport = fc_vport; |
| 395 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 396 | /* |
| 397 | * In SLI4, the vpi must be activated before it can be used |
| 398 | * by the port. |
| 399 | */ |
| 400 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 401 | (pport->fc_flag & FC_VFI_REGISTERED)) { |
| 402 | rc = lpfc_sli4_init_vpi(vport); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 403 | if (rc) { |
| 404 | lpfc_printf_log(phba, KERN_ERR, LOG_VPORT, |
| 405 | "1838 Failed to INIT_VPI on vpi %d " |
| 406 | "status %d\n", vpi, rc); |
| 407 | rc = VPORT_NORESOURCES; |
| 408 | lpfc_free_vpi(phba, vpi); |
| 409 | goto error_out; |
| 410 | } |
| 411 | } else if (phba->sli_rev == LPFC_SLI_REV4) { |
| 412 | /* |
| 413 | * Driver cannot INIT_VPI now. Set the flags to |
| 414 | * init_vpi when reg_vfi complete. |
| 415 | */ |
| 416 | vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
| 417 | lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN); |
| 418 | rc = VPORT_OK; |
| 419 | goto out; |
| 420 | } |
| 421 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 422 | if ((phba->link_state < LPFC_LINK_UP) || |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 423 | (pport->port_state < LPFC_FABRIC_CFG_LINK) || |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 424 | (phba->fc_topology == LPFC_TOPOLOGY_LOOP)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 425 | lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN); |
| 426 | rc = VPORT_OK; |
| 427 | goto out; |
| 428 | } |
| 429 | |
| 430 | if (disable) { |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 431 | lpfc_vport_set_state(vport, FC_VPORT_DISABLED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 432 | rc = VPORT_OK; |
| 433 | goto out; |
| 434 | } |
| 435 | |
| 436 | /* Use the Physical nodes Fabric NDLP to determine if the link is |
| 437 | * up and ready to FDISC. |
| 438 | */ |
| 439 | ndlp = lpfc_findnode_did(phba->pport, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 440 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 441 | ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 442 | if (phba->link_flag & LS_NPIV_FAB_SUPPORTED) { |
| 443 | lpfc_set_disctmo(vport); |
| 444 | lpfc_initial_fdisc(vport); |
| 445 | } else { |
| 446 | lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 447 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 448 | "0262 No NPIV Fabric support\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 449 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 450 | } else { |
| 451 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 452 | } |
| 453 | rc = VPORT_OK; |
| 454 | |
| 455 | out: |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 456 | lpfc_printf_vlog(vport, KERN_ERR, LOG_VPORT, |
| 457 | "1825 Vport Created.\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 458 | lpfc_host_attrib_init(lpfc_shost_from_vport(vport)); |
| 459 | error_out: |
| 460 | return rc; |
| 461 | } |
| 462 | |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 463 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 464 | disable_vport(struct fc_vport *fc_vport) |
| 465 | { |
| 466 | struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data; |
| 467 | struct lpfc_hba *phba = vport->phba; |
| 468 | struct lpfc_nodelist *ndlp = NULL, *next_ndlp = NULL; |
| 469 | long timeout; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 470 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 471 | |
| 472 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 473 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) |
| 474 | && phba->link_state >= LPFC_LINK_UP) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 475 | vport->unreg_vpi_cmpl = VPORT_INVAL; |
| 476 | timeout = msecs_to_jiffies(phba->fc_ratov * 2000); |
| 477 | if (!lpfc_issue_els_npiv_logo(vport, ndlp)) |
| 478 | while (vport->unreg_vpi_cmpl == VPORT_INVAL && timeout) |
| 479 | timeout = schedule_timeout(timeout); |
| 480 | } |
| 481 | |
| 482 | lpfc_sli_host_down(vport); |
| 483 | |
| 484 | /* Mark all nodes for discovery so we can remove them by |
| 485 | * calling lpfc_cleanup_rpis(vport, 1) |
| 486 | */ |
| 487 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 488 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 489 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 490 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 491 | continue; |
| 492 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 493 | NLP_EVT_DEVICE_RECOVERY); |
| 494 | } |
| 495 | lpfc_cleanup_rpis(vport, 1); |
| 496 | |
| 497 | lpfc_stop_vport_timers(vport); |
| 498 | lpfc_unreg_all_rpis(vport); |
| 499 | lpfc_unreg_default_rpis(vport); |
| 500 | /* |
| 501 | * Completion of unreg_vpi (lpfc_mbx_cmpl_unreg_vpi) does the |
| 502 | * scsi_host_put() to release the vport. |
| 503 | */ |
| 504 | lpfc_mbx_unreg_vpi(vport); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 505 | spin_lock_irq(shost->host_lock); |
| 506 | vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
| 507 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 508 | |
| 509 | lpfc_vport_set_state(vport, FC_VPORT_DISABLED); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 510 | lpfc_printf_vlog(vport, KERN_ERR, LOG_VPORT, |
| 511 | "1826 Vport Disabled.\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 512 | return VPORT_OK; |
| 513 | } |
| 514 | |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 515 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 516 | enable_vport(struct fc_vport *fc_vport) |
| 517 | { |
| 518 | struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data; |
| 519 | struct lpfc_hba *phba = vport->phba; |
| 520 | struct lpfc_nodelist *ndlp = NULL; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 521 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 522 | |
| 523 | if ((phba->link_state < LPFC_LINK_UP) || |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 524 | (phba->fc_topology == LPFC_TOPOLOGY_LOOP)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 525 | lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN); |
| 526 | return VPORT_OK; |
| 527 | } |
| 528 | |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 529 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 530 | vport->load_flag |= FC_LOADING; |
| 531 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 532 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 533 | |
| 534 | /* Use the Physical nodes Fabric NDLP to determine if the link is |
| 535 | * up and ready to FDISC. |
| 536 | */ |
| 537 | ndlp = lpfc_findnode_did(phba->pport, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 538 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) |
| 539 | && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 540 | if (phba->link_flag & LS_NPIV_FAB_SUPPORTED) { |
| 541 | lpfc_set_disctmo(vport); |
| 542 | lpfc_initial_fdisc(vport); |
| 543 | } else { |
| 544 | lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 545 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 546 | "0264 No NPIV Fabric support\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 547 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 548 | } else { |
| 549 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 550 | } |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 551 | lpfc_printf_vlog(vport, KERN_ERR, LOG_VPORT, |
| 552 | "1827 Vport Enabled.\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 553 | return VPORT_OK; |
| 554 | } |
| 555 | |
| 556 | int |
| 557 | lpfc_vport_disable(struct fc_vport *fc_vport, bool disable) |
| 558 | { |
| 559 | if (disable) |
| 560 | return disable_vport(fc_vport); |
| 561 | else |
| 562 | return enable_vport(fc_vport); |
| 563 | } |
| 564 | |
| 565 | |
| 566 | int |
| 567 | lpfc_vport_delete(struct fc_vport *fc_vport) |
| 568 | { |
| 569 | struct lpfc_nodelist *ndlp = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 570 | struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data; |
James Smart | cc82355 | 2015-05-21 13:55:26 -0400 | [diff] [blame] | 571 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 572 | struct lpfc_hba *phba = vport->phba; |
| 573 | long timeout; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 574 | bool ns_ndlp_referenced = false; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 575 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 576 | if (vport->port_type == LPFC_PHYSICAL_PORT) { |
| 577 | lpfc_printf_vlog(vport, KERN_ERR, LOG_VPORT, |
| 578 | "1812 vport_delete failed: Cannot delete " |
| 579 | "physical host\n"); |
| 580 | return VPORT_ERROR; |
| 581 | } |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 582 | |
| 583 | /* If the vport is a static vport fail the deletion. */ |
| 584 | if ((vport->vport_flag & STATIC_VPORT) && |
| 585 | !(phba->pport->load_flag & FC_UNLOADING)) { |
| 586 | lpfc_printf_vlog(vport, KERN_ERR, LOG_VPORT, |
| 587 | "1837 vport_delete failed: Cannot delete " |
| 588 | "static vport.\n"); |
| 589 | return VPORT_ERROR; |
| 590 | } |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 591 | spin_lock_irq(&phba->hbalock); |
| 592 | vport->load_flag |= FC_UNLOADING; |
| 593 | spin_unlock_irq(&phba->hbalock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 594 | /* |
| 595 | * If we are not unloading the driver then prevent the vport_delete |
| 596 | * from happening until after this vport's discovery is finished. |
| 597 | */ |
| 598 | if (!(phba->pport->load_flag & FC_UNLOADING)) { |
| 599 | int check_count = 0; |
| 600 | while (check_count < ((phba->fc_ratov * 3) + 3) && |
| 601 | vport->port_state > LPFC_VPORT_FAILED && |
| 602 | vport->port_state < LPFC_VPORT_READY) { |
| 603 | check_count++; |
| 604 | msleep(1000); |
| 605 | } |
| 606 | if (vport->port_state > LPFC_VPORT_FAILED && |
| 607 | vport->port_state < LPFC_VPORT_READY) |
| 608 | return -EAGAIN; |
| 609 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 610 | /* |
| 611 | * This is a bit of a mess. We want to ensure the shost doesn't get |
| 612 | * torn down until we're done with the embedded lpfc_vport structure. |
| 613 | * |
| 614 | * Beyond holding a reference for this function, we also need a |
| 615 | * reference for outstanding I/O requests we schedule during delete |
| 616 | * processing. But once we scsi_remove_host() we can no longer obtain |
| 617 | * a reference through scsi_host_get(). |
| 618 | * |
| 619 | * So we take two references here. We release one reference at the |
| 620 | * bottom of the function -- after delinking the vport. And we |
| 621 | * release the other at the completion of the unreg_vpi that get's |
| 622 | * initiated after we've disposed of all other resources associated |
| 623 | * with the port. |
| 624 | */ |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 625 | if (!scsi_host_get(shost)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 626 | return VPORT_INVAL; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 627 | if (!scsi_host_get(shost)) { |
| 628 | scsi_host_put(shost); |
| 629 | return VPORT_INVAL; |
| 630 | } |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 631 | lpfc_free_sysfs_attr(vport); |
| 632 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 633 | lpfc_debugfs_terminate(vport); |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 634 | |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 635 | /* |
| 636 | * The call to fc_remove_host might release the NameServer ndlp. Since |
| 637 | * we might need to use the ndlp to send the DA_ID CT command, |
| 638 | * increment the reference for the NameServer ndlp to prevent it from |
| 639 | * being released. |
| 640 | */ |
| 641 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
| 642 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
| 643 | lpfc_nlp_get(ndlp); |
| 644 | ns_ndlp_referenced = true; |
| 645 | } |
| 646 | |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 647 | /* Remove FC host and then SCSI host with the vport */ |
James Smart | cc82355 | 2015-05-21 13:55:26 -0400 | [diff] [blame] | 648 | fc_remove_host(shost); |
| 649 | scsi_remove_host(shost); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 650 | |
| 651 | ndlp = lpfc_findnode_did(phba->pport, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 652 | |
| 653 | /* In case of driver unload, we shall not perform fabric logo as the |
| 654 | * worker thread already stopped at this stage and, in this case, we |
| 655 | * can safely skip the fabric logo. |
| 656 | */ |
| 657 | if (phba->pport->load_flag & FC_UNLOADING) { |
| 658 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 659 | ndlp->nlp_state == NLP_STE_UNMAPPED_NODE && |
| 660 | phba->link_state >= LPFC_LINK_UP) { |
| 661 | /* First look for the Fabric ndlp */ |
| 662 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 663 | if (!ndlp) |
| 664 | goto skip_logo; |
| 665 | else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 666 | ndlp = lpfc_enable_node(vport, ndlp, |
| 667 | NLP_STE_UNUSED_NODE); |
| 668 | if (!ndlp) |
| 669 | goto skip_logo; |
| 670 | } |
| 671 | /* Remove ndlp from vport npld list */ |
| 672 | lpfc_dequeue_node(vport, ndlp); |
| 673 | |
| 674 | /* Indicate free memory when release */ |
| 675 | spin_lock_irq(&phba->ndlp_lock); |
| 676 | NLP_SET_FREE_REQ(ndlp); |
| 677 | spin_unlock_irq(&phba->ndlp_lock); |
| 678 | /* Kick off release ndlp when it can be safely done */ |
| 679 | lpfc_nlp_put(ndlp); |
| 680 | } |
| 681 | goto skip_logo; |
| 682 | } |
| 683 | |
| 684 | /* Otherwise, we will perform fabric logo as needed */ |
| 685 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 686 | ndlp->nlp_state == NLP_STE_UNMAPPED_NODE && |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 687 | phba->link_state >= LPFC_LINK_UP && |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 688 | phba->fc_topology != LPFC_TOPOLOGY_LOOP) { |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 689 | if (vport->cfg_enable_da_id) { |
| 690 | timeout = msecs_to_jiffies(phba->fc_ratov * 2000); |
| 691 | if (!lpfc_ns_cmd(vport, SLI_CTNS_DA_ID, 0, 0)) |
| 692 | while (vport->ct_flags && timeout) |
| 693 | timeout = schedule_timeout(timeout); |
| 694 | else |
| 695 | lpfc_printf_log(vport->phba, KERN_WARNING, |
| 696 | LOG_VPORT, |
| 697 | "1829 CT command failed to " |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 698 | "delete objects on fabric\n"); |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 699 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 700 | /* First look for the Fabric ndlp */ |
| 701 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 702 | if (!ndlp) { |
| 703 | /* Cannot find existing Fabric ndlp, allocate one */ |
| 704 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 705 | if (!ndlp) |
| 706 | goto skip_logo; |
| 707 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 708 | /* Indicate free memory when release */ |
| 709 | NLP_SET_FREE_REQ(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 710 | } else { |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 711 | if (!NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 712 | ndlp = lpfc_enable_node(vport, ndlp, |
| 713 | NLP_STE_UNUSED_NODE); |
| 714 | if (!ndlp) |
| 715 | goto skip_logo; |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 716 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 717 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 718 | /* Remove ndlp from vport list */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 719 | lpfc_dequeue_node(vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 720 | spin_lock_irq(&phba->ndlp_lock); |
| 721 | if (!NLP_CHK_FREE_REQ(ndlp)) |
| 722 | /* Indicate free memory when release */ |
| 723 | NLP_SET_FREE_REQ(ndlp); |
| 724 | else { |
| 725 | /* Skip this if ndlp is already in free mode */ |
| 726 | spin_unlock_irq(&phba->ndlp_lock); |
| 727 | goto skip_logo; |
| 728 | } |
| 729 | spin_unlock_irq(&phba->ndlp_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 730 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 731 | |
| 732 | /* |
| 733 | * If the vpi is not registered, then a valid FDISC doesn't |
| 734 | * exist and there is no need for a ELS LOGO. Just cleanup |
| 735 | * the ndlp. |
| 736 | */ |
| 737 | if (!(vport->vpi_state & LPFC_VPI_REGISTERED)) { |
| 738 | lpfc_nlp_put(ndlp); |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 739 | goto skip_logo; |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 740 | } |
| 741 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 742 | vport->unreg_vpi_cmpl = VPORT_INVAL; |
| 743 | timeout = msecs_to_jiffies(phba->fc_ratov * 2000); |
| 744 | if (!lpfc_issue_els_npiv_logo(vport, ndlp)) |
| 745 | while (vport->unreg_vpi_cmpl == VPORT_INVAL && timeout) |
| 746 | timeout = schedule_timeout(timeout); |
| 747 | } |
| 748 | |
James Smart | 90160e0 | 2008-08-24 21:49:45 -0400 | [diff] [blame] | 749 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 750 | lpfc_discovery_wait(vport); |
| 751 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 752 | skip_logo: |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 753 | |
| 754 | /* |
| 755 | * If the NameServer ndlp has been incremented to allow the DA_ID CT |
| 756 | * command to be sent, decrement the ndlp now. |
| 757 | */ |
| 758 | if (ns_ndlp_referenced) { |
| 759 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
| 760 | lpfc_nlp_put(ndlp); |
| 761 | } |
| 762 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 763 | lpfc_cleanup(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 764 | lpfc_sli_host_down(vport); |
| 765 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 766 | lpfc_stop_vport_timers(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 767 | |
| 768 | if (!(phba->pport->load_flag & FC_UNLOADING)) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 769 | lpfc_unreg_all_rpis(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 770 | lpfc_unreg_default_rpis(vport); |
| 771 | /* |
| 772 | * Completion of unreg_vpi (lpfc_mbx_cmpl_unreg_vpi) |
| 773 | * does the scsi_host_put() to release the vport. |
| 774 | */ |
James Smart | cc82355 | 2015-05-21 13:55:26 -0400 | [diff] [blame] | 775 | if (!(vport->vpi_state & LPFC_VPI_REGISTERED) || |
| 776 | lpfc_mbx_unreg_vpi(vport)) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 777 | scsi_host_put(shost); |
| 778 | } else |
| 779 | scsi_host_put(shost); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 780 | |
| 781 | lpfc_free_vpi(phba, vport->vpi); |
| 782 | vport->work_port_events = 0; |
| 783 | spin_lock_irq(&phba->hbalock); |
| 784 | list_del_init(&vport->listentry); |
| 785 | spin_unlock_irq(&phba->hbalock); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 786 | lpfc_printf_vlog(vport, KERN_ERR, LOG_VPORT, |
| 787 | "1828 Vport Deleted.\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 788 | scsi_host_put(shost); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 789 | return VPORT_OK; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 790 | } |
| 791 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 792 | struct lpfc_vport ** |
| 793 | lpfc_create_vport_work_array(struct lpfc_hba *phba) |
| 794 | { |
| 795 | struct lpfc_vport *port_iterator; |
| 796 | struct lpfc_vport **vports; |
| 797 | int index = 0; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 798 | vports = kzalloc((phba->max_vports + 1) * sizeof(struct lpfc_vport *), |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 799 | GFP_KERNEL); |
| 800 | if (vports == NULL) |
| 801 | return NULL; |
| 802 | spin_lock_irq(&phba->hbalock); |
| 803 | list_for_each_entry(port_iterator, &phba->port_list, listentry) { |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 804 | if (port_iterator->load_flag & FC_UNLOADING) |
| 805 | continue; |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 806 | if (!scsi_host_get(lpfc_shost_from_vport(port_iterator))) { |
James Smart | df9e1b5 | 2011-12-13 13:22:17 -0500 | [diff] [blame] | 807 | lpfc_printf_vlog(port_iterator, KERN_ERR, LOG_VPORT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 808 | "1801 Create vport work array FAILED: " |
| 809 | "cannot do scsi_host_get\n"); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 810 | continue; |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 811 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 812 | vports[index++] = port_iterator; |
| 813 | } |
| 814 | spin_unlock_irq(&phba->hbalock); |
| 815 | return vports; |
| 816 | } |
| 817 | |
| 818 | void |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 819 | lpfc_destroy_vport_work_array(struct lpfc_hba *phba, struct lpfc_vport **vports) |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 820 | { |
| 821 | int i; |
| 822 | if (vports == NULL) |
| 823 | return; |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 824 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 825 | scsi_host_put(lpfc_shost_from_vport(vports[i])); |
| 826 | kfree(vports); |
| 827 | } |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 828 | |
| 829 | |
| 830 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 831 | * lpfc_vport_reset_stat_data - Reset the statistical data for the vport |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 832 | * @vport: Pointer to vport object. |
| 833 | * |
| 834 | * This function resets the statistical data for the vport. This function |
| 835 | * is called with the host_lock held |
| 836 | **/ |
| 837 | void |
| 838 | lpfc_vport_reset_stat_data(struct lpfc_vport *vport) |
| 839 | { |
| 840 | struct lpfc_nodelist *ndlp = NULL, *next_ndlp = NULL; |
| 841 | |
| 842 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { |
| 843 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 844 | continue; |
| 845 | if (ndlp->lat_data) |
| 846 | memset(ndlp->lat_data, 0, LPFC_MAX_BUCKET_COUNT * |
| 847 | sizeof(struct lpfc_scsicmd_bkt)); |
| 848 | } |
| 849 | } |
| 850 | |
| 851 | |
| 852 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 853 | * lpfc_alloc_bucket - Allocate data buffer required for statistical data |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 854 | * @vport: Pointer to vport object. |
| 855 | * |
| 856 | * This function allocates data buffer required for all the FC |
| 857 | * nodes of the vport to collect statistical data. |
| 858 | **/ |
| 859 | void |
| 860 | lpfc_alloc_bucket(struct lpfc_vport *vport) |
| 861 | { |
| 862 | struct lpfc_nodelist *ndlp = NULL, *next_ndlp = NULL; |
| 863 | |
| 864 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { |
| 865 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 866 | continue; |
| 867 | |
| 868 | kfree(ndlp->lat_data); |
| 869 | ndlp->lat_data = NULL; |
| 870 | |
| 871 | if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) { |
| 872 | ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT, |
| 873 | sizeof(struct lpfc_scsicmd_bkt), |
| 874 | GFP_ATOMIC); |
| 875 | |
| 876 | if (!ndlp->lat_data) |
| 877 | lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE, |
| 878 | "0287 lpfc_alloc_bucket failed to " |
| 879 | "allocate statistical data buffer DID " |
| 880 | "0x%x\n", ndlp->nlp_DID); |
| 881 | } |
| 882 | } |
| 883 | } |
| 884 | |
| 885 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 886 | * lpfc_free_bucket - Free data buffer required for statistical data |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 887 | * @vport: Pointer to vport object. |
| 888 | * |
| 889 | * Th function frees statistical data buffer of all the FC |
| 890 | * nodes of the vport. |
| 891 | **/ |
| 892 | void |
| 893 | lpfc_free_bucket(struct lpfc_vport *vport) |
| 894 | { |
| 895 | struct lpfc_nodelist *ndlp = NULL, *next_ndlp = NULL; |
| 896 | |
| 897 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { |
| 898 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 899 | continue; |
| 900 | |
| 901 | kfree(ndlp->lat_data); |
| 902 | ndlp->lat_data = NULL; |
| 903 | } |
| 904 | } |