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