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