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