| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1 | /******************************************************************* |
| 2 | * This file is part of the Emulex Linux Device Driver for * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 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@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 5 | * EMULEX and SLI are trademarks of Emulex. * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6 | * www.emulex.com * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 7 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8 | * * |
| 9 | * This program is free software; you can redistribute it and/or * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 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. * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 20 | *******************************************************************/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 21 | /* See Fibre Channel protocol T11 FC-LS for details */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 22 | #include <linux/blkdev.h> |
| 23 | #include <linux/pci.h> |
| 24 | #include <linux/interrupt.h> |
| 25 | |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 26 | #include <scsi/scsi.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 27 | #include <scsi/scsi_device.h> |
| 28 | #include <scsi/scsi_host.h> |
| 29 | #include <scsi/scsi_transport_fc.h> |
| 30 | |
| 31 | #include "lpfc_hw.h" |
| 32 | #include "lpfc_sli.h" |
| 33 | #include "lpfc_disc.h" |
| 34 | #include "lpfc_scsi.h" |
| 35 | #include "lpfc.h" |
| 36 | #include "lpfc_logmsg.h" |
| 37 | #include "lpfc_crtn.h" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 38 | #include "lpfc_vport.h" |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 39 | #include "lpfc_debugfs.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 40 | |
| 41 | static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *, |
| 42 | struct lpfc_iocbq *); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 43 | static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *, |
| 44 | struct lpfc_iocbq *); |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 45 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport); |
| 46 | static int lpfc_issue_els_fdisc(struct lpfc_vport *vport, |
| 47 | struct lpfc_nodelist *ndlp, uint8_t retry); |
| 48 | static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba, |
| 49 | struct lpfc_iocbq *iocb); |
| 50 | static void lpfc_register_new_vport(struct lpfc_hba *phba, |
| 51 | struct lpfc_vport *vport, |
| 52 | struct lpfc_nodelist *ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 53 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 54 | static int lpfc_max_els_tries = 3; |
| 55 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 56 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 57 | lpfc_els_chk_latt(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 58 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 59 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 60 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 61 | uint32_t ha_copy; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 62 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 63 | if (vport->port_state >= LPFC_VPORT_READY || |
| 64 | phba->link_state == LPFC_LINK_DOWN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 65 | return 0; |
| 66 | |
| 67 | /* Read the HBA Host Attention Register */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 68 | ha_copy = readl(phba->HAregaddr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 69 | |
| 70 | if (!(ha_copy & HA_LATT)) |
| 71 | return 0; |
| 72 | |
| 73 | /* Pending Link Event during Discovery */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 74 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 75 | "0237 Pending Link Event during " |
| 76 | "Discovery: State x%x\n", |
| 77 | phba->pport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 78 | |
| 79 | /* CLEAR_LA should re-enable link attention events and |
| 80 | * we should then imediately take a LATT event. The |
| 81 | * LATT processing should call lpfc_linkdown() which |
| 82 | * will cleanup any left over in-progress discovery |
| 83 | * events. |
| 84 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 85 | spin_lock_irq(shost->host_lock); |
| 86 | vport->fc_flag |= FC_ABORT_DISCOVERY; |
| 87 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 88 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 89 | if (phba->link_state != LPFC_CLEAR_LA) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 90 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 91 | |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 92 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | static struct lpfc_iocbq * |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 96 | lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp, |
| 97 | uint16_t cmdSize, uint8_t retry, |
| 98 | struct lpfc_nodelist *ndlp, uint32_t did, |
| 99 | uint32_t elscmd) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 100 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 101 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 102 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 103 | struct lpfc_dmabuf *pcmd, *prsp, *pbuflist; |
| 104 | struct ulp_bde64 *bpl; |
| 105 | IOCB_t *icmd; |
| 106 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 107 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 108 | if (!lpfc_is_link_up(phba)) |
| 109 | return NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 110 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 111 | /* Allocate buffer for command iocb */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 112 | elsiocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 113 | |
| 114 | if (elsiocb == NULL) |
| 115 | return NULL; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 116 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 117 | icmd = &elsiocb->iocb; |
| 118 | |
| 119 | /* fill in BDEs for command */ |
| 120 | /* Allocate buffer for command payload */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 121 | pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 122 | if (pcmd) |
| 123 | pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 124 | if (!pcmd || !pcmd->virt) |
| 125 | goto els_iocb_free_pcmb_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 126 | |
| 127 | INIT_LIST_HEAD(&pcmd->list); |
| 128 | |
| 129 | /* Allocate buffer for response payload */ |
| 130 | if (expectRsp) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 131 | prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 132 | if (prsp) |
| 133 | prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 134 | &prsp->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 135 | if (!prsp || !prsp->virt) |
| 136 | goto els_iocb_free_prsp_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 137 | INIT_LIST_HEAD(&prsp->list); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 138 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 139 | prsp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 140 | |
| 141 | /* Allocate buffer for Buffer ptr list */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 142 | pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 143 | if (pbuflist) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 144 | pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 145 | &pbuflist->phys); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 146 | if (!pbuflist || !pbuflist->virt) |
| 147 | goto els_iocb_free_pbuf_exit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 148 | |
| 149 | INIT_LIST_HEAD(&pbuflist->list); |
| 150 | |
| 151 | icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys); |
| 152 | icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys); |
| 153 | icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BDL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 154 | icmd->un.elsreq64.remoteID = did; /* DID */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 155 | if (expectRsp) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 156 | icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 157 | icmd->ulpCommand = CMD_ELS_REQUEST64_CR; |
James Smart | 2680eea | 2007-04-25 09:52:55 -0400 | [diff] [blame] | 158 | icmd->ulpTimeout = phba->fc_ratov * 2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 159 | } else { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 160 | icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 161 | icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX; |
| 162 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 163 | icmd->ulpBdeCount = 1; |
| 164 | icmd->ulpLe = 1; |
| 165 | icmd->ulpClass = CLASS3; |
| 166 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 167 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 168 | icmd->un.elsreq64.myID = vport->fc_myDID; |
| 169 | |
| 170 | /* For ELS_REQUEST64_CR, use the VPI by default */ |
| 171 | icmd->ulpContext = vport->vpi; |
| 172 | icmd->ulpCt_h = 0; |
| 173 | icmd->ulpCt_l = 1; |
| 174 | } |
| 175 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 176 | bpl = (struct ulp_bde64 *) pbuflist->virt; |
| 177 | bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys)); |
| 178 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys)); |
| 179 | bpl->tus.f.bdeSize = cmdSize; |
| 180 | bpl->tus.f.bdeFlags = 0; |
| 181 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 182 | |
| 183 | if (expectRsp) { |
| 184 | bpl++; |
| 185 | bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys)); |
| 186 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys)); |
| 187 | bpl->tus.f.bdeSize = FCELSSIZE; |
| 188 | bpl->tus.f.bdeFlags = BUFF_USE_RCV; |
| 189 | bpl->tus.w = le32_to_cpu(bpl->tus.w); |
| 190 | } |
| 191 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 192 | /* prevent preparing iocb with NULL ndlp reference */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 193 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 194 | if (!elsiocb->context1) |
| 195 | goto els_iocb_free_pbuf_exit; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 196 | elsiocb->context2 = pcmd; |
| 197 | elsiocb->context3 = pbuflist; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 198 | elsiocb->retry = retry; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 199 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 200 | elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT; |
| 201 | |
| 202 | if (prsp) { |
| 203 | list_add(&prsp->list, &pcmd->list); |
| 204 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 205 | if (expectRsp) { |
| 206 | /* Xmit ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 207 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 208 | "0116 Xmit ELS command x%x to remote " |
| 209 | "NPORT x%x I/O tag: x%x, port state: x%x\n", |
| 210 | elscmd, did, elsiocb->iotag, |
| 211 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 212 | } else { |
| 213 | /* Xmit ELS response <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 214 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 215 | "0117 Xmit ELS response x%x to remote " |
| 216 | "NPORT x%x I/O tag: x%x, size: x%x\n", |
| 217 | elscmd, ndlp->nlp_DID, elsiocb->iotag, |
| 218 | cmdSize); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 219 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 220 | return elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 221 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 222 | els_iocb_free_pbuf_exit: |
| 223 | lpfc_mbuf_free(phba, prsp->virt, prsp->phys); |
| 224 | kfree(pbuflist); |
| 225 | |
| 226 | els_iocb_free_prsp_exit: |
| 227 | lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys); |
| 228 | kfree(prsp); |
| 229 | |
| 230 | els_iocb_free_pcmb_exit: |
| 231 | kfree(pcmd); |
| 232 | lpfc_sli_release_iocbq(phba, elsiocb); |
| 233 | return NULL; |
| 234 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 235 | |
| 236 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 237 | lpfc_issue_fabric_reglogin(struct lpfc_vport *vport) |
| 238 | { |
| 239 | struct lpfc_hba *phba = vport->phba; |
| 240 | LPFC_MBOXQ_t *mbox; |
| 241 | struct lpfc_dmabuf *mp; |
| 242 | struct lpfc_nodelist *ndlp; |
| 243 | struct serv_parm *sp; |
| 244 | int rc; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 245 | int err = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 246 | |
| 247 | sp = &phba->fc_fabparam; |
| 248 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 249 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 250 | err = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 251 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 252 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 253 | |
| 254 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 255 | if (!mbox) { |
| 256 | err = 2; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 257 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 258 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 259 | |
| 260 | vport->port_state = LPFC_FABRIC_CFG_LINK; |
| 261 | lpfc_config_link(phba, mbox); |
| 262 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 263 | mbox->vport = vport; |
| 264 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 265 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 266 | if (rc == MBX_NOT_FINISHED) { |
| 267 | err = 3; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 268 | goto fail_free_mbox; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 269 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 270 | |
| 271 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 272 | if (!mbox) { |
| 273 | err = 4; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 274 | goto fail; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 275 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 276 | rc = lpfc_reg_login(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox, |
| 277 | 0); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 278 | if (rc) { |
| 279 | err = 5; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 280 | goto fail_free_mbox; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 281 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 282 | |
| 283 | mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login; |
| 284 | mbox->vport = vport; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 285 | /* increment the reference count on ndlp to hold reference |
| 286 | * for the callback routine. |
| 287 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 288 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 289 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 290 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 291 | if (rc == MBX_NOT_FINISHED) { |
| 292 | err = 6; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 293 | goto fail_issue_reg_login; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 294 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 295 | |
| 296 | return 0; |
| 297 | |
| 298 | fail_issue_reg_login: |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 299 | /* decrement the reference count on ndlp just incremented |
| 300 | * for the failed mbox command. |
| 301 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 302 | lpfc_nlp_put(ndlp); |
| 303 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 304 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 305 | kfree(mp); |
| 306 | fail_free_mbox: |
| 307 | mempool_free(mbox, phba->mbox_mem_pool); |
| 308 | |
| 309 | fail: |
| 310 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 311 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 312 | "0249 Cannot issue Register Fabric login: Err %d\n", err); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 313 | return -ENXIO; |
| 314 | } |
| 315 | |
| 316 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 317 | lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 318 | struct serv_parm *sp, IOCB_t *irsp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 319 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 320 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 321 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 322 | struct lpfc_nodelist *np; |
| 323 | struct lpfc_nodelist *next_np; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 324 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 325 | spin_lock_irq(shost->host_lock); |
| 326 | vport->fc_flag |= FC_FABRIC; |
| 327 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 328 | |
| 329 | phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov); |
| 330 | if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */ |
| 331 | phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000; |
| 332 | |
| 333 | phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000; |
| 334 | |
| 335 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 336 | spin_lock_irq(shost->host_lock); |
| 337 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 338 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 339 | } else { |
| 340 | /* |
| 341 | * If we are a N-port connected to a Fabric, fixup sparam's so |
| 342 | * logins to devices on remote loops work. |
| 343 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 344 | vport->fc_sparam.cmn.altBbCredit = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 345 | } |
| 346 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 347 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 348 | memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 349 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 350 | ndlp->nlp_class_sup = 0; |
| 351 | if (sp->cls1.classValid) |
| 352 | ndlp->nlp_class_sup |= FC_COS_CLASS1; |
| 353 | if (sp->cls2.classValid) |
| 354 | ndlp->nlp_class_sup |= FC_COS_CLASS2; |
| 355 | if (sp->cls3.classValid) |
| 356 | ndlp->nlp_class_sup |= FC_COS_CLASS3; |
| 357 | if (sp->cls4.classValid) |
| 358 | ndlp->nlp_class_sup |= FC_COS_CLASS4; |
| 359 | ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 360 | sp->cmn.bbRcvSizeLsb; |
| 361 | memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); |
| 362 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 363 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 364 | if (sp->cmn.response_multiple_NPort) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 365 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 366 | LOG_ELS | LOG_VPORT, |
| 367 | "1816 FLOGI NPIV supported, " |
| 368 | "response data 0x%x\n", |
| 369 | sp->cmn.response_multiple_NPort); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 370 | phba->link_flag |= LS_NPIV_FAB_SUPPORTED; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 371 | } else { |
| 372 | /* Because we asked f/w for NPIV it still expects us |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 373 | to call reg_vnpid atleast for the physcial host */ |
| 374 | lpfc_printf_vlog(vport, KERN_WARNING, |
| 375 | LOG_ELS | LOG_VPORT, |
| 376 | "1817 Fabric does not support NPIV " |
| 377 | "- configuring single port mode.\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 378 | phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED; |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | if ((vport->fc_prevDID != vport->fc_myDID) && |
| 383 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 384 | |
| 385 | /* If our NportID changed, we need to ensure all |
| 386 | * remaining NPORTs get unreg_login'ed. |
| 387 | */ |
| 388 | list_for_each_entry_safe(np, next_np, |
| 389 | &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 390 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 391 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 392 | if ((np->nlp_state != NLP_STE_NPR_NODE) || |
| 393 | !(np->nlp_flag & NLP_NPR_ADISC)) |
| 394 | continue; |
| 395 | spin_lock_irq(shost->host_lock); |
| 396 | np->nlp_flag &= ~NLP_NPR_ADISC; |
| 397 | spin_unlock_irq(shost->host_lock); |
| 398 | lpfc_unreg_rpi(vport, np); |
| 399 | } |
| 400 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 401 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 402 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 403 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 404 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 405 | } |
| 406 | } |
| 407 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 408 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 409 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 410 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED && |
| 411 | vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) { |
| 412 | lpfc_register_new_vport(phba, vport, ndlp); |
| 413 | return 0; |
| 414 | } |
| 415 | lpfc_issue_fabric_reglogin(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 416 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | /* |
| 420 | * We FLOGIed into an NPort, initiate pt2pt protocol |
| 421 | */ |
| 422 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 423 | lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 424 | struct serv_parm *sp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 425 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 426 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 427 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 428 | LPFC_MBOXQ_t *mbox; |
| 429 | int rc; |
| 430 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 431 | spin_lock_irq(shost->host_lock); |
| 432 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 433 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 434 | |
| 435 | phba->fc_edtov = FF_DEF_EDTOV; |
| 436 | phba->fc_ratov = FF_DEF_RATOV; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 437 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 438 | sizeof(vport->fc_portname)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 439 | if (rc >= 0) { |
| 440 | /* This side will initiate the PLOGI */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 441 | spin_lock_irq(shost->host_lock); |
| 442 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 443 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 444 | |
| 445 | /* |
| 446 | * N_Port ID cannot be 0, set our to LocalID the other |
| 447 | * side will be RemoteID. |
| 448 | */ |
| 449 | |
| 450 | /* not equal */ |
| 451 | if (rc) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 452 | vport->fc_myDID = PT2PT_LocalID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 453 | |
| 454 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 455 | if (!mbox) |
| 456 | goto fail; |
| 457 | |
| 458 | lpfc_config_link(phba, mbox); |
| 459 | |
| 460 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 461 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 462 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 463 | if (rc == MBX_NOT_FINISHED) { |
| 464 | mempool_free(mbox, phba->mbox_mem_pool); |
| 465 | goto fail; |
| 466 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 467 | /* Decrement ndlp reference count indicating that ndlp can be |
| 468 | * safely released when other references to it are done. |
| 469 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 470 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 471 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 472 | ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 473 | if (!ndlp) { |
| 474 | /* |
| 475 | * Cannot find existing Fabric ndlp, so allocate a |
| 476 | * new one |
| 477 | */ |
| 478 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 479 | if (!ndlp) |
| 480 | goto fail; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 481 | lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 482 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 483 | ndlp = lpfc_enable_node(vport, ndlp, |
| 484 | NLP_STE_UNUSED_NODE); |
| 485 | if(!ndlp) |
| 486 | goto fail; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | memcpy(&ndlp->nlp_portname, &sp->portName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 490 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 491 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 492 | sizeof(struct lpfc_name)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 493 | /* Set state will put ndlp onto node list if not already done */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 494 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 495 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 496 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 497 | spin_unlock_irq(shost->host_lock); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 498 | } else |
| 499 | /* This side will wait for the PLOGI, decrement ndlp reference |
| 500 | * count indicating that ndlp can be released when other |
| 501 | * references to it are done. |
| 502 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 503 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 504 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 505 | /* If we are pt2pt with another NPort, force NPIV off! */ |
| 506 | phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED; |
| 507 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 508 | spin_lock_irq(shost->host_lock); |
| 509 | vport->fc_flag |= FC_PT2PT; |
| 510 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 511 | |
| 512 | /* Start discovery - this should just do CLEAR_LA */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 513 | lpfc_disc_start(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 514 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 515 | fail: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 516 | return -ENXIO; |
| 517 | } |
| 518 | |
| 519 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 520 | lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 521 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 522 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 523 | struct lpfc_vport *vport = cmdiocb->vport; |
| 524 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 525 | IOCB_t *irsp = &rspiocb->iocb; |
| 526 | struct lpfc_nodelist *ndlp = cmdiocb->context1; |
| 527 | struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; |
| 528 | struct serv_parm *sp; |
| 529 | int rc; |
| 530 | |
| 531 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 532 | if (lpfc_els_chk_latt(vport)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 533 | /* One additional decrement on node reference count to |
| 534 | * trigger the release of the node |
| 535 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 536 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 537 | goto out; |
| 538 | } |
| 539 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 540 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 541 | "FLOGI cmpl: status:x%x/x%x state:x%x", |
| 542 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 543 | vport->port_state); |
| 544 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 545 | if (irsp->ulpStatus) { |
| 546 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 547 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 548 | goto out; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 549 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 550 | /* FLOGI failed, so there is no fabric */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 551 | spin_lock_irq(shost->host_lock); |
| 552 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 553 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 554 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 555 | /* If private loop, then allow max outstanding els to be |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 556 | * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no |
| 557 | * alpa map would take too long otherwise. |
| 558 | */ |
| 559 | if (phba->alpa_map[0] == 0) { |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 560 | vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | /* FLOGI failure */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 564 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 565 | "0100 FLOGI failure Data: x%x x%x " |
| 566 | "x%x\n", |
| 567 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 568 | irsp->ulpTimeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 569 | goto flogifail; |
| 570 | } |
| 571 | |
| 572 | /* |
| 573 | * The FLogI succeeded. Sync the data for the CPU before |
| 574 | * accessing it. |
| 575 | */ |
| 576 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
| 577 | |
| 578 | sp = prsp->virt + sizeof(uint32_t); |
| 579 | |
| 580 | /* FLOGI completes successfully */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 581 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 582 | "0101 FLOGI completes sucessfully " |
| 583 | "Data: x%x x%x x%x x%x\n", |
| 584 | irsp->un.ulpWord[4], sp->cmn.e_d_tov, |
| 585 | sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 586 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 587 | if (vport->port_state == LPFC_FLOGI) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 588 | /* |
| 589 | * If Common Service Parameters indicate Nport |
| 590 | * we are point to point, if Fport we are Fabric. |
| 591 | */ |
| 592 | if (sp->cmn.fPort) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 593 | rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 594 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 595 | rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 596 | |
| 597 | if (!rc) |
| 598 | goto out; |
| 599 | } |
| 600 | |
| 601 | flogifail: |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 602 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 603 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 604 | if (!lpfc_error_lost_link(irsp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 605 | /* FLOGI failed, so just use loop map to make discovery list */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 606 | lpfc_disc_list_loopmap(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 607 | |
| 608 | /* Start discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 609 | lpfc_disc_start(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 610 | } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
| 611 | ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) && |
| 612 | (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) && |
| 613 | (phba->link_state != LPFC_CLEAR_LA)) { |
| 614 | /* If FLOGI failed enable link interrupt. */ |
| 615 | lpfc_issue_clear_la(phba, vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 616 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 617 | out: |
| 618 | lpfc_els_free_iocb(phba, cmdiocb); |
| 619 | } |
| 620 | |
| 621 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 622 | lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 623 | uint8_t retry) |
| 624 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 625 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 626 | struct serv_parm *sp; |
| 627 | IOCB_t *icmd; |
| 628 | struct lpfc_iocbq *elsiocb; |
| 629 | struct lpfc_sli_ring *pring; |
| 630 | uint8_t *pcmd; |
| 631 | uint16_t cmdsize; |
| 632 | uint32_t tmo; |
| 633 | int rc; |
| 634 | |
| 635 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 636 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 637 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 638 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 639 | ndlp->nlp_DID, ELS_CMD_FLOGI); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 640 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 641 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 642 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 643 | |
| 644 | icmd = &elsiocb->iocb; |
| 645 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 646 | |
| 647 | /* For FLOGI request, remainder of payload is service parameters */ |
| 648 | *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 649 | pcmd += sizeof(uint32_t); |
| 650 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 651 | sp = (struct serv_parm *) pcmd; |
| 652 | |
| 653 | /* Setup CSPs accordingly for Fabric */ |
| 654 | sp->cmn.e_d_tov = 0; |
| 655 | sp->cmn.w2.r_a_tov = 0; |
| 656 | sp->cls1.classValid = 0; |
| 657 | sp->cls2.seqDelivery = 1; |
| 658 | sp->cls3.seqDelivery = 1; |
| 659 | if (sp->cmn.fcphLow < FC_PH3) |
| 660 | sp->cmn.fcphLow = FC_PH3; |
| 661 | if (sp->cmn.fcphHigh < FC_PH3) |
| 662 | sp->cmn.fcphHigh = FC_PH3; |
| 663 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 664 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
| 665 | sp->cmn.request_multiple_Nport = 1; |
| 666 | |
| 667 | /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */ |
| 668 | icmd->ulpCt_h = 1; |
| 669 | icmd->ulpCt_l = 0; |
| 670 | } |
| 671 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 672 | if (phba->fc_topology != TOPOLOGY_LOOP) { |
| 673 | icmd->un.elsreq64.myID = 0; |
| 674 | icmd->un.elsreq64.fl = 1; |
| 675 | } |
| 676 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 677 | tmo = phba->fc_ratov; |
| 678 | phba->fc_ratov = LPFC_DISC_FLOGI_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 679 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 680 | phba->fc_ratov = tmo; |
| 681 | |
| 682 | phba->fc_stat.elsXmitFLOGI++; |
| 683 | elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 684 | |
| 685 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 686 | "Issue FLOGI: opt:x%x", |
| 687 | phba->sli3_options, 0, 0); |
| 688 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 689 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 690 | if (rc == IOCB_ERROR) { |
| 691 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 692 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 693 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 694 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 695 | } |
| 696 | |
| 697 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 698 | lpfc_els_abort_flogi(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 699 | { |
| 700 | struct lpfc_sli_ring *pring; |
| 701 | struct lpfc_iocbq *iocb, *next_iocb; |
| 702 | struct lpfc_nodelist *ndlp; |
| 703 | IOCB_t *icmd; |
| 704 | |
| 705 | /* Abort outstanding I/O on NPort <nlp_DID> */ |
| 706 | lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 707 | "0201 Abort outstanding I/O on NPort x%x\n", |
| 708 | Fabric_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 709 | |
| 710 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 711 | |
| 712 | /* |
| 713 | * Check the txcmplq for an iocb that matches the nport the driver is |
| 714 | * searching for. |
| 715 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 716 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 717 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
| 718 | icmd = &iocb->iocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 719 | if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR && |
| 720 | icmd->un.elsreq64.bdl.ulpIoTag32) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 721 | ndlp = (struct lpfc_nodelist *)(iocb->context1); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame^] | 722 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 723 | (ndlp->nlp_DID == Fabric_DID)) |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 724 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 725 | } |
| 726 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 727 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 728 | |
| 729 | return 0; |
| 730 | } |
| 731 | |
| 732 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 733 | lpfc_initial_flogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 734 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 735 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 736 | struct lpfc_nodelist *ndlp; |
| 737 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 738 | vport->port_state = LPFC_FLOGI; |
| 739 | lpfc_set_disctmo(vport); |
| 740 | |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 741 | /* First look for the Fabric ndlp */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 742 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 743 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 744 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 745 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 746 | if (!ndlp) |
| 747 | return 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 748 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 749 | /* Put ndlp onto node list */ |
| 750 | lpfc_enqueue_node(vport, ndlp); |
| 751 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 752 | /* re-setup ndlp without removing from node list */ |
| 753 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 754 | if (!ndlp) |
| 755 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 756 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 757 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 758 | if (lpfc_issue_els_flogi(vport, ndlp, 0)) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 759 | /* This decrement of reference count to node shall kick off |
| 760 | * the release of the node. |
| 761 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 762 | lpfc_nlp_put(ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 763 | |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 764 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 765 | } |
| 766 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 767 | int |
| 768 | lpfc_initial_fdisc(struct lpfc_vport *vport) |
| 769 | { |
| 770 | struct lpfc_hba *phba = vport->phba; |
| 771 | struct lpfc_nodelist *ndlp; |
| 772 | |
| 773 | /* First look for the Fabric ndlp */ |
| 774 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 775 | if (!ndlp) { |
| 776 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
| 777 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 778 | if (!ndlp) |
| 779 | return 0; |
| 780 | lpfc_nlp_init(vport, ndlp, Fabric_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 781 | /* Put ndlp onto node list */ |
| 782 | lpfc_enqueue_node(vport, ndlp); |
| 783 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 784 | /* re-setup ndlp without removing from node list */ |
| 785 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 786 | if (!ndlp) |
| 787 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 788 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 789 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 790 | if (lpfc_issue_els_fdisc(vport, ndlp, 0)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 791 | /* decrement node reference count to trigger the release of |
| 792 | * the node. |
| 793 | */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 794 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 795 | return 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 796 | } |
| 797 | return 1; |
| 798 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 799 | |
| 800 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 801 | lpfc_more_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 802 | { |
| 803 | int sentplogi; |
| 804 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 805 | if (vport->num_disc_nodes) |
| 806 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 807 | |
| 808 | /* Continue discovery with <num_disc_nodes> PLOGIs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 809 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 810 | "0232 Continue discovery with %d PLOGIs to go " |
| 811 | "Data: x%x x%x x%x\n", |
| 812 | vport->num_disc_nodes, vport->fc_plogi_cnt, |
| 813 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 814 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 815 | if (vport->fc_flag & FC_NLP_MORE) |
| 816 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 817 | sentplogi = lpfc_els_disc_plogi(vport); |
| 818 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 819 | return; |
| 820 | } |
| 821 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 822 | static struct lpfc_nodelist * |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 823 | lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp, |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 824 | struct lpfc_nodelist *ndlp) |
| 825 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 826 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 827 | struct lpfc_nodelist *new_ndlp; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 828 | struct lpfc_rport_data *rdata; |
| 829 | struct fc_rport *rport; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 830 | struct serv_parm *sp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 831 | uint8_t name[sizeof(struct lpfc_name)]; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame^] | 832 | uint32_t rc, keepDID = 0; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 833 | |
James Smart | 2fb9bd8 | 2006-12-02 13:33:57 -0500 | [diff] [blame] | 834 | /* Fabric nodes can have the same WWPN so we don't bother searching |
| 835 | * by WWPN. Just return the ndlp that was given to us. |
| 836 | */ |
| 837 | if (ndlp->nlp_type & NLP_FABRIC) |
| 838 | return ndlp; |
| 839 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 840 | sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t)); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 841 | memset(name, 0, sizeof(struct lpfc_name)); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 842 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 843 | /* Now we find out if the NPort we are logging into, matches the WWPN |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 844 | * we have for that ndlp. If not, we have some work to do. |
| 845 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 846 | new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 847 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 848 | if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 849 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 850 | |
| 851 | if (!new_ndlp) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 852 | rc = memcmp(&ndlp->nlp_portname, name, |
| 853 | sizeof(struct lpfc_name)); |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 854 | if (!rc) |
| 855 | return ndlp; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 856 | new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC); |
| 857 | if (!new_ndlp) |
| 858 | return ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 859 | lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 860 | } else if (!NLP_CHK_NODE_ACT(new_ndlp)) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame^] | 861 | rc = memcmp(&ndlp->nlp_portname, name, |
| 862 | sizeof(struct lpfc_name)); |
| 863 | if (!rc) |
| 864 | return ndlp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 865 | new_ndlp = lpfc_enable_node(vport, new_ndlp, |
| 866 | NLP_STE_UNUSED_NODE); |
| 867 | if (!new_ndlp) |
| 868 | return ndlp; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame^] | 869 | keepDID = new_ndlp->nlp_DID; |
| 870 | } else |
| 871 | keepDID = new_ndlp->nlp_DID; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 872 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 873 | lpfc_unreg_rpi(vport, new_ndlp); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 874 | new_ndlp->nlp_DID = ndlp->nlp_DID; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 875 | new_ndlp->nlp_prev_state = ndlp->nlp_prev_state; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 876 | |
| 877 | if (ndlp->nlp_flag & NLP_NPR_2B_DISC) |
| 878 | new_ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
| 879 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
| 880 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 881 | /* Set state will put new_ndlp on to node list if not already done */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 882 | lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 883 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 884 | /* Move this back to NPR state */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 885 | if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) { |
| 886 | /* The new_ndlp is replacing ndlp totally, so we need |
| 887 | * to put ndlp on UNUSED list and try to free it. |
| 888 | */ |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 889 | |
| 890 | /* Fix up the rport accordingly */ |
| 891 | rport = ndlp->rport; |
| 892 | if (rport) { |
| 893 | rdata = rport->dd_data; |
| 894 | if (rdata->pnode == ndlp) { |
| 895 | lpfc_nlp_put(ndlp); |
| 896 | ndlp->rport = NULL; |
| 897 | rdata->pnode = lpfc_nlp_get(new_ndlp); |
| 898 | new_ndlp->rport = rport; |
| 899 | } |
| 900 | new_ndlp->nlp_type = ndlp->nlp_type; |
| 901 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame^] | 902 | /* We shall actually free the ndlp with both nlp_DID and |
| 903 | * nlp_portname fields equals 0 to avoid any ndlp on the |
| 904 | * nodelist never to be used. |
| 905 | */ |
| 906 | if (ndlp->nlp_DID == 0) { |
| 907 | spin_lock_irq(&phba->ndlp_lock); |
| 908 | NLP_SET_FREE_REQ(ndlp); |
| 909 | spin_unlock_irq(&phba->ndlp_lock); |
| 910 | } |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 911 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame^] | 912 | /* Two ndlps cannot have the same did on the nodelist */ |
| 913 | ndlp->nlp_DID = keepDID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 914 | lpfc_drop_node(vport, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 915 | } |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 916 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 917 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame^] | 918 | /* Two ndlps cannot have the same did */ |
| 919 | ndlp->nlp_DID = keepDID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 920 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 921 | } |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 922 | return new_ndlp; |
| 923 | } |
| 924 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 925 | void |
| 926 | lpfc_end_rscn(struct lpfc_vport *vport) |
| 927 | { |
| 928 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 929 | |
| 930 | if (vport->fc_flag & FC_RSCN_MODE) { |
| 931 | /* |
| 932 | * Check to see if more RSCNs came in while we were |
| 933 | * processing this one. |
| 934 | */ |
| 935 | if (vport->fc_rscn_id_cnt || |
| 936 | (vport->fc_flag & FC_RSCN_DISCOVERY) != 0) |
| 937 | lpfc_els_handle_rscn(vport); |
| 938 | else { |
| 939 | spin_lock_irq(shost->host_lock); |
| 940 | vport->fc_flag &= ~FC_RSCN_MODE; |
| 941 | spin_unlock_irq(shost->host_lock); |
| 942 | } |
| 943 | } |
| 944 | } |
| 945 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 946 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 947 | lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 948 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 949 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 950 | struct lpfc_vport *vport = cmdiocb->vport; |
| 951 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 952 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 953 | struct lpfc_nodelist *ndlp; |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 954 | struct lpfc_dmabuf *prsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 955 | int disc, rc, did, type; |
| 956 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 957 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 958 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 959 | |
| 960 | irsp = &rspiocb->iocb; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 961 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 962 | "PLOGI cmpl: status:x%x/x%x did:x%x", |
| 963 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 964 | irsp->un.elsreq64.remoteID); |
| 965 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 966 | ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 967 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 968 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 969 | "0136 PLOGI completes to NPort x%x " |
| 970 | "with no ndlp. Data: x%x x%x x%x\n", |
| 971 | irsp->un.elsreq64.remoteID, |
| 972 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 973 | irsp->ulpIoTag); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 974 | goto out; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 975 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 976 | |
| 977 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 978 | * is being used during discovery. |
| 979 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 980 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 981 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 982 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 983 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 984 | rc = 0; |
| 985 | |
| 986 | /* PLOGI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 987 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 988 | "0102 PLOGI completes to NPort x%x " |
| 989 | "Data: x%x x%x x%x x%x x%x\n", |
| 990 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 991 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 992 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 993 | if (lpfc_els_chk_latt(vport)) { |
| 994 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 995 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 996 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 997 | goto out; |
| 998 | } |
| 999 | |
| 1000 | /* ndlp could be freed in DSM, save these values now */ |
| 1001 | type = ndlp->nlp_type; |
| 1002 | did = ndlp->nlp_DID; |
| 1003 | |
| 1004 | if (irsp->ulpStatus) { |
| 1005 | /* Check for retry */ |
| 1006 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1007 | /* ELS command is being retried */ |
| 1008 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1009 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1010 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1011 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1012 | } |
| 1013 | goto out; |
| 1014 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1015 | /* PLOGI failed */ |
| 1016 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1017 | if (lpfc_error_lost_link(irsp)) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1018 | rc = NLP_STE_FREED_NODE; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1019 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1020 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1021 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1022 | } else { |
| 1023 | /* Good status, call state machine */ |
James Smart | 9279565 | 2006-07-06 15:50:02 -0400 | [diff] [blame] | 1024 | prsp = list_entry(((struct lpfc_dmabuf *) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1025 | cmdiocb->context2)->list.next, |
| 1026 | struct lpfc_dmabuf, list); |
| 1027 | ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1028 | rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1029 | NLP_EVT_CMPL_PLOGI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1030 | } |
| 1031 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1032 | if (disc && vport->num_disc_nodes) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1033 | /* Check to see if there are more PLOGIs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1034 | lpfc_more_plogi(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1035 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1036 | if (vport->num_disc_nodes == 0) { |
| 1037 | spin_lock_irq(shost->host_lock); |
| 1038 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1039 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1040 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1041 | lpfc_can_disctmo(vport); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1042 | lpfc_end_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1043 | } |
| 1044 | } |
| 1045 | |
| 1046 | out: |
| 1047 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1048 | return; |
| 1049 | } |
| 1050 | |
| 1051 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1052 | lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1053 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1054 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1055 | struct serv_parm *sp; |
| 1056 | IOCB_t *icmd; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1057 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1058 | struct lpfc_iocbq *elsiocb; |
| 1059 | struct lpfc_sli_ring *pring; |
| 1060 | struct lpfc_sli *psli; |
| 1061 | uint8_t *pcmd; |
| 1062 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1063 | int ret; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1064 | |
| 1065 | psli = &phba->sli; |
| 1066 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ |
| 1067 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1068 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1069 | if (ndlp && !NLP_CHK_NODE_ACT(ndlp)) |
| 1070 | ndlp = NULL; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1071 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1072 | /* If ndlp is not NULL, we will bump the reference count on it */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1073 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1074 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1075 | ELS_CMD_PLOGI); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1076 | if (!elsiocb) |
| 1077 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1078 | |
| 1079 | icmd = &elsiocb->iocb; |
| 1080 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1081 | |
| 1082 | /* For PLOGI request, remainder of payload is service parameters */ |
| 1083 | *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1084 | pcmd += sizeof(uint32_t); |
| 1085 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1086 | sp = (struct serv_parm *) pcmd; |
| 1087 | |
| 1088 | if (sp->cmn.fcphLow < FC_PH_4_3) |
| 1089 | sp->cmn.fcphLow = FC_PH_4_3; |
| 1090 | |
| 1091 | if (sp->cmn.fcphHigh < FC_PH3) |
| 1092 | sp->cmn.fcphHigh = FC_PH3; |
| 1093 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1094 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1095 | "Issue PLOGI: did:x%x", |
| 1096 | did, 0, 0); |
| 1097 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1098 | phba->fc_stat.elsXmitPLOGI++; |
| 1099 | elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1100 | ret = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
| 1101 | |
| 1102 | if (ret == IOCB_ERROR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1103 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1104 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1105 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1106 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1107 | } |
| 1108 | |
| 1109 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1110 | lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1111 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1112 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1113 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1114 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1115 | IOCB_t *irsp; |
| 1116 | struct lpfc_sli *psli; |
| 1117 | struct lpfc_nodelist *ndlp; |
| 1118 | |
| 1119 | psli = &phba->sli; |
| 1120 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1121 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1122 | |
| 1123 | irsp = &(rspiocb->iocb); |
| 1124 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1125 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1126 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1127 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1128 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1129 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1130 | "PRLI cmpl: status:x%x/x%x did:x%x", |
| 1131 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1132 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1133 | /* PRLI completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1134 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1135 | "0103 PRLI completes to NPort x%x " |
| 1136 | "Data: x%x x%x x%x x%x\n", |
| 1137 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1138 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1139 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1140 | vport->fc_prli_sent--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1141 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1142 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1143 | goto out; |
| 1144 | |
| 1145 | if (irsp->ulpStatus) { |
| 1146 | /* Check for retry */ |
| 1147 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1148 | /* ELS command is being retried */ |
| 1149 | goto out; |
| 1150 | } |
| 1151 | /* PRLI failed */ |
| 1152 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1153 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1154 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1155 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1156 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1157 | NLP_EVT_CMPL_PRLI); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1158 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1159 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1160 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1161 | NLP_EVT_CMPL_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1162 | out: |
| 1163 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1164 | return; |
| 1165 | } |
| 1166 | |
| 1167 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1168 | lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1169 | uint8_t retry) |
| 1170 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1171 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1172 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1173 | PRLI *npr; |
| 1174 | IOCB_t *icmd; |
| 1175 | struct lpfc_iocbq *elsiocb; |
| 1176 | struct lpfc_sli_ring *pring; |
| 1177 | struct lpfc_sli *psli; |
| 1178 | uint8_t *pcmd; |
| 1179 | uint16_t cmdsize; |
| 1180 | |
| 1181 | psli = &phba->sli; |
| 1182 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ |
| 1183 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1184 | cmdsize = (sizeof(uint32_t) + sizeof(PRLI)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1185 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1186 | ndlp->nlp_DID, ELS_CMD_PRLI); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1187 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1188 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1189 | |
| 1190 | icmd = &elsiocb->iocb; |
| 1191 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1192 | |
| 1193 | /* For PRLI request, remainder of payload is service parameters */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1194 | memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t))); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1195 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1196 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1197 | |
| 1198 | /* For PRLI, remainder of payload is PRLI parameter page */ |
| 1199 | npr = (PRLI *) pcmd; |
| 1200 | /* |
| 1201 | * If our firmware version is 3.20 or later, |
| 1202 | * set the following bits for FC-TAPE support. |
| 1203 | */ |
| 1204 | if (phba->vpd.rev.feaLevelHigh >= 0x02) { |
| 1205 | npr->ConfmComplAllowed = 1; |
| 1206 | npr->Retry = 1; |
| 1207 | npr->TaskRetryIdReq = 1; |
| 1208 | } |
| 1209 | npr->estabImagePair = 1; |
| 1210 | npr->readXferRdyDis = 1; |
| 1211 | |
| 1212 | /* For FCP support */ |
| 1213 | npr->prliType = PRLI_FCP_TYPE; |
| 1214 | npr->initiatorFunc = 1; |
| 1215 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1216 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1217 | "Issue PRLI: did:x%x", |
| 1218 | ndlp->nlp_DID, 0, 0); |
| 1219 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1220 | phba->fc_stat.elsXmitPRLI++; |
| 1221 | elsiocb->iocb_cmpl = lpfc_cmpl_els_prli; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1222 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1223 | ndlp->nlp_flag |= NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1224 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1225 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1226 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1227 | ndlp->nlp_flag &= ~NLP_PRLI_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1228 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1229 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1230 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1231 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1232 | vport->fc_prli_sent++; |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1233 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1234 | } |
| 1235 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1236 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1237 | lpfc_more_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1238 | { |
| 1239 | int sentadisc; |
| 1240 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1241 | if (vport->num_disc_nodes) |
| 1242 | vport->num_disc_nodes--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1243 | /* Continue discovery with <num_disc_nodes> ADISCs to go */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1244 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 1245 | "0210 Continue discovery with %d ADISCs to go " |
| 1246 | "Data: x%x x%x x%x\n", |
| 1247 | vport->num_disc_nodes, vport->fc_adisc_cnt, |
| 1248 | vport->fc_flag, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1249 | /* Check to see if there are more ADISCs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1250 | if (vport->fc_flag & FC_NLP_MORE) { |
| 1251 | lpfc_set_disctmo(vport); |
| 1252 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
| 1253 | sentadisc = lpfc_els_disc_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1254 | } |
| 1255 | return; |
| 1256 | } |
| 1257 | |
| 1258 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1259 | lpfc_rscn_disc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1260 | { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1261 | lpfc_can_disctmo(vport); |
| 1262 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1263 | /* RSCN discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1264 | /* go thru NPR nodes and issue ELS PLOGIs */ |
| 1265 | if (vport->fc_npr_cnt) |
| 1266 | if (lpfc_els_disc_plogi(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1267 | return; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1268 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1269 | lpfc_end_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1270 | } |
| 1271 | |
| 1272 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1273 | lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1274 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1275 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1276 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1277 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1278 | IOCB_t *irsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1279 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1280 | int disc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1281 | |
| 1282 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1283 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1284 | |
| 1285 | irsp = &(rspiocb->iocb); |
| 1286 | ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1287 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1288 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1289 | "ADISC cmpl: status:x%x/x%x did:x%x", |
| 1290 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1291 | ndlp->nlp_DID); |
| 1292 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1293 | /* Since ndlp can be freed in the disc state machine, note if this node |
| 1294 | * is being used during discovery. |
| 1295 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1296 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1297 | disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1298 | ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1299 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1300 | /* ADISC completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1301 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1302 | "0104 ADISC completes to NPort x%x " |
| 1303 | "Data: x%x x%x x%x x%x x%x\n", |
| 1304 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1305 | irsp->ulpTimeout, disc, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1306 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1307 | if (lpfc_els_chk_latt(vport)) { |
| 1308 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1309 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1310 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1311 | goto out; |
| 1312 | } |
| 1313 | |
| 1314 | if (irsp->ulpStatus) { |
| 1315 | /* Check for retry */ |
| 1316 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { |
| 1317 | /* ELS command is being retried */ |
| 1318 | if (disc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1319 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1320 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1321 | spin_unlock_irq(shost->host_lock); |
| 1322 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1323 | } |
| 1324 | goto out; |
| 1325 | } |
| 1326 | /* ADISC failed */ |
| 1327 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1328 | if (!lpfc_error_lost_link(irsp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1329 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1330 | NLP_EVT_CMPL_ADISC); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1331 | } else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1332 | /* Good status, call state machine */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1333 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1334 | NLP_EVT_CMPL_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1335 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1336 | if (disc && vport->num_disc_nodes) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1337 | /* Check to see if there are more ADISCs to be sent */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1338 | lpfc_more_adisc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1339 | |
| 1340 | /* Check to see if we are done with ADISC authentication */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1341 | if (vport->num_disc_nodes == 0) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1342 | /* If we get here, there is nothing left to ADISC */ |
| 1343 | /* |
| 1344 | * For NPIV, cmpl_reg_vpi will set port_state to READY, |
| 1345 | * and continue discovery. |
| 1346 | */ |
| 1347 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 1348 | !(vport->fc_flag & FC_RSCN_MODE)) { |
| 1349 | lpfc_issue_reg_vpi(phba, vport); |
| 1350 | goto out; |
| 1351 | } |
| 1352 | /* |
| 1353 | * For SLI2, we need to set port_state to READY |
| 1354 | * and continue discovery. |
| 1355 | */ |
| 1356 | if (vport->port_state < LPFC_VPORT_READY) { |
| 1357 | /* If we get here, there is nothing to ADISC */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1358 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1359 | lpfc_issue_clear_la(phba, vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1360 | |
| 1361 | if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) { |
| 1362 | vport->num_disc_nodes = 0; |
| 1363 | /* go thru NPR list, issue ELS PLOGIs */ |
| 1364 | if (vport->fc_npr_cnt) |
| 1365 | lpfc_els_disc_plogi(vport); |
| 1366 | |
| 1367 | if (!vport->num_disc_nodes) { |
| 1368 | spin_lock_irq(shost->host_lock); |
| 1369 | vport->fc_flag &= |
| 1370 | ~FC_NDISC_ACTIVE; |
| 1371 | spin_unlock_irq( |
| 1372 | shost->host_lock); |
| 1373 | lpfc_can_disctmo(vport); |
| 1374 | } |
| 1375 | } |
| 1376 | vport->port_state = LPFC_VPORT_READY; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1377 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1378 | lpfc_rscn_disc(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1379 | } |
| 1380 | } |
| 1381 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1382 | out: |
| 1383 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1384 | return; |
| 1385 | } |
| 1386 | |
| 1387 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1388 | lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1389 | uint8_t retry) |
| 1390 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1391 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1392 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1393 | ADISC *ap; |
| 1394 | IOCB_t *icmd; |
| 1395 | struct lpfc_iocbq *elsiocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1396 | struct lpfc_sli *psli = &phba->sli; |
| 1397 | struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1398 | uint8_t *pcmd; |
| 1399 | uint16_t cmdsize; |
| 1400 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1401 | cmdsize = (sizeof(uint32_t) + sizeof(ADISC)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1402 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1403 | ndlp->nlp_DID, ELS_CMD_ADISC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1404 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1405 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1406 | |
| 1407 | icmd = &elsiocb->iocb; |
| 1408 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1409 | |
| 1410 | /* For ADISC request, remainder of payload is service parameters */ |
| 1411 | *((uint32_t *) (pcmd)) = ELS_CMD_ADISC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1412 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1413 | |
| 1414 | /* Fill in ADISC payload */ |
| 1415 | ap = (ADISC *) pcmd; |
| 1416 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1417 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 1418 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1419 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1420 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1421 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1422 | "Issue ADISC: did:x%x", |
| 1423 | ndlp->nlp_DID, 0, 0); |
| 1424 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1425 | phba->fc_stat.elsXmitADISC++; |
| 1426 | elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1427 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1428 | ndlp->nlp_flag |= NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1429 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1430 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1431 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1432 | ndlp->nlp_flag &= ~NLP_ADISC_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1433 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1434 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1435 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1436 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1437 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1438 | } |
| 1439 | |
| 1440 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1441 | lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1442 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1443 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1444 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 1445 | struct lpfc_vport *vport = ndlp->vport; |
| 1446 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1447 | IOCB_t *irsp; |
| 1448 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1449 | |
| 1450 | psli = &phba->sli; |
| 1451 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
| 1452 | cmdiocb->context_un.rsp_iocb = rspiocb; |
| 1453 | |
| 1454 | irsp = &(rspiocb->iocb); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1455 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1456 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1457 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1458 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1459 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1460 | "LOGO cmpl: status:x%x/x%x did:x%x", |
| 1461 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1462 | ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1463 | /* LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1464 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1465 | "0105 LOGO completes to NPort x%x " |
| 1466 | "Data: x%x x%x x%x x%x\n", |
| 1467 | ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1468 | irsp->ulpTimeout, vport->num_disc_nodes); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1469 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1470 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1471 | goto out; |
| 1472 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1473 | if (ndlp->nlp_flag & NLP_TARGET_REMOVE) { |
| 1474 | /* NLP_EVT_DEVICE_RM should unregister the RPI |
| 1475 | * which should abort all outstanding IOs. |
| 1476 | */ |
| 1477 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
| 1478 | NLP_EVT_DEVICE_RM); |
| 1479 | goto out; |
| 1480 | } |
| 1481 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1482 | if (irsp->ulpStatus) { |
| 1483 | /* Check for retry */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1484 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1485 | /* ELS command is being retried */ |
| 1486 | goto out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1487 | /* LOGO failed */ |
| 1488 | /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1489 | if (lpfc_error_lost_link(irsp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1490 | goto out; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1491 | else |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1492 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1493 | NLP_EVT_CMPL_LOGO); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1494 | } else |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 1495 | /* Good status, call state machine. |
| 1496 | * This will unregister the rpi if needed. |
| 1497 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1498 | lpfc_disc_state_machine(vport, ndlp, cmdiocb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1499 | NLP_EVT_CMPL_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1500 | out: |
| 1501 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1502 | return; |
| 1503 | } |
| 1504 | |
| 1505 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1506 | lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1507 | uint8_t retry) |
| 1508 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1509 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1510 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1511 | IOCB_t *icmd; |
| 1512 | struct lpfc_iocbq *elsiocb; |
| 1513 | struct lpfc_sli_ring *pring; |
| 1514 | struct lpfc_sli *psli; |
| 1515 | uint8_t *pcmd; |
| 1516 | uint16_t cmdsize; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1517 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1518 | |
| 1519 | psli = &phba->sli; |
| 1520 | pring = &psli->ring[LPFC_ELS_RING]; |
| 1521 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1522 | spin_lock_irq(shost->host_lock); |
| 1523 | if (ndlp->nlp_flag & NLP_LOGO_SND) { |
| 1524 | spin_unlock_irq(shost->host_lock); |
| 1525 | return 0; |
| 1526 | } |
| 1527 | spin_unlock_irq(shost->host_lock); |
| 1528 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1529 | cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1530 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1531 | ndlp->nlp_DID, ELS_CMD_LOGO); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1532 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1533 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1534 | |
| 1535 | icmd = &elsiocb->iocb; |
| 1536 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1537 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1538 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1539 | |
| 1540 | /* Fill in LOGO payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1541 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1542 | pcmd += sizeof(uint32_t); |
| 1543 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1544 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1545 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1546 | "Issue LOGO: did:x%x", |
| 1547 | ndlp->nlp_DID, 0, 0); |
| 1548 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1549 | phba->fc_stat.elsXmitLOGO++; |
| 1550 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1551 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1552 | ndlp->nlp_flag |= NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1553 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1554 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
| 1555 | |
| 1556 | if (rc == IOCB_ERROR) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1557 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1558 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1559 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1560 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1561 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1562 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1563 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1564 | } |
| 1565 | |
| 1566 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1567 | lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1568 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1569 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1570 | struct lpfc_vport *vport = cmdiocb->vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1571 | IOCB_t *irsp; |
| 1572 | |
| 1573 | irsp = &rspiocb->iocb; |
| 1574 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1575 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1576 | "ELS cmd cmpl: status:x%x/x%x did:x%x", |
| 1577 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 1578 | irsp->un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1579 | /* ELS cmd tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1580 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 1581 | "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n", |
| 1582 | irsp->ulpIoTag, irsp->ulpStatus, |
| 1583 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1584 | /* Check to see if link went down during discovery */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1585 | lpfc_els_chk_latt(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1586 | lpfc_els_free_iocb(phba, cmdiocb); |
| 1587 | return; |
| 1588 | } |
| 1589 | |
| 1590 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1591 | lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1592 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1593 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1594 | IOCB_t *icmd; |
| 1595 | struct lpfc_iocbq *elsiocb; |
| 1596 | struct lpfc_sli_ring *pring; |
| 1597 | struct lpfc_sli *psli; |
| 1598 | uint8_t *pcmd; |
| 1599 | uint16_t cmdsize; |
| 1600 | struct lpfc_nodelist *ndlp; |
| 1601 | |
| 1602 | psli = &phba->sli; |
| 1603 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1604 | cmdsize = (sizeof(uint32_t) + sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1605 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1606 | ndlp = lpfc_findnode_did(vport, nportid); |
| 1607 | if (!ndlp) { |
| 1608 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 1609 | if (!ndlp) |
| 1610 | return 1; |
| 1611 | lpfc_nlp_init(vport, ndlp, nportid); |
| 1612 | lpfc_enqueue_node(vport, ndlp); |
| 1613 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 1614 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 1615 | if (!ndlp) |
| 1616 | return 1; |
| 1617 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1618 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1619 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1620 | ndlp->nlp_DID, ELS_CMD_SCR); |
| 1621 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1622 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1623 | /* This will trigger the release of the node just |
| 1624 | * allocated |
| 1625 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1626 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1627 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1628 | } |
| 1629 | |
| 1630 | icmd = &elsiocb->iocb; |
| 1631 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1632 | |
| 1633 | *((uint32_t *) (pcmd)) = ELS_CMD_SCR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1634 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1635 | |
| 1636 | /* For SCR, remainder of payload is SCR parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1637 | memset(pcmd, 0, sizeof(SCR)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1638 | ((SCR *) pcmd)->Function = SCR_FUNC_FULL; |
| 1639 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1640 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1641 | "Issue SCR: did:x%x", |
| 1642 | ndlp->nlp_DID, 0, 0); |
| 1643 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1644 | phba->fc_stat.elsXmitSCR++; |
| 1645 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1646 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1647 | /* The additional lpfc_nlp_put will cause the following |
| 1648 | * lpfc_els_free_iocb routine to trigger the rlease of |
| 1649 | * the node. |
| 1650 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1651 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1652 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1653 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1654 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1655 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 1656 | * trigger the release of node. |
| 1657 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1658 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1659 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1660 | } |
| 1661 | |
| 1662 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1663 | lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1664 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1665 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1666 | IOCB_t *icmd; |
| 1667 | struct lpfc_iocbq *elsiocb; |
| 1668 | struct lpfc_sli_ring *pring; |
| 1669 | struct lpfc_sli *psli; |
| 1670 | FARP *fp; |
| 1671 | uint8_t *pcmd; |
| 1672 | uint32_t *lp; |
| 1673 | uint16_t cmdsize; |
| 1674 | struct lpfc_nodelist *ondlp; |
| 1675 | struct lpfc_nodelist *ndlp; |
| 1676 | |
| 1677 | psli = &phba->sli; |
| 1678 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1679 | cmdsize = (sizeof(uint32_t) + sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1680 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1681 | ndlp = lpfc_findnode_did(vport, nportid); |
| 1682 | if (!ndlp) { |
| 1683 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 1684 | if (!ndlp) |
| 1685 | return 1; |
| 1686 | lpfc_nlp_init(vport, ndlp, nportid); |
| 1687 | lpfc_enqueue_node(vport, ndlp); |
| 1688 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 1689 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 1690 | if (!ndlp) |
| 1691 | return 1; |
| 1692 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1693 | |
| 1694 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, |
| 1695 | ndlp->nlp_DID, ELS_CMD_RNID); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1696 | if (!elsiocb) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1697 | /* This will trigger the release of the node just |
| 1698 | * allocated |
| 1699 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1700 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1701 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1702 | } |
| 1703 | |
| 1704 | icmd = &elsiocb->iocb; |
| 1705 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 1706 | |
| 1707 | *((uint32_t *) (pcmd)) = ELS_CMD_FARPR; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1708 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1709 | |
| 1710 | /* Fill in FARPR payload */ |
| 1711 | fp = (FARP *) (pcmd); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1712 | memset(fp, 0, sizeof(FARP)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1713 | lp = (uint32_t *) pcmd; |
| 1714 | *lp++ = be32_to_cpu(nportid); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1715 | *lp++ = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1716 | fp->Rflags = 0; |
| 1717 | fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE); |
| 1718 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1719 | memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 1720 | memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1721 | ondlp = lpfc_findnode_did(vport, nportid); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1722 | if (ondlp && NLP_CHK_NODE_ACT(ondlp)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1723 | memcpy(&fp->OportName, &ondlp->nlp_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1724 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1725 | memcpy(&fp->OnodeName, &ondlp->nlp_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1726 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1727 | } |
| 1728 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1729 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1730 | "Issue FARPR: did:x%x", |
| 1731 | ndlp->nlp_DID, 0, 0); |
| 1732 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1733 | phba->fc_stat.elsXmitFARPR++; |
| 1734 | elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1735 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1736 | /* The additional lpfc_nlp_put will cause the following |
| 1737 | * lpfc_els_free_iocb routine to trigger the release of |
| 1738 | * the node. |
| 1739 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1740 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1741 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1742 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1743 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1744 | /* This will cause the callback-function lpfc_cmpl_els_cmd to |
| 1745 | * trigger the release of the node. |
| 1746 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 1747 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 1748 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1749 | } |
| 1750 | |
| 1751 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1752 | lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp) |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 1753 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1754 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1755 | struct lpfc_work_evt *evtp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1756 | |
| 1757 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 1758 | nlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1759 | spin_unlock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 1760 | del_timer_sync(&nlp->nlp_delayfunc); |
| 1761 | nlp->nlp_last_elscmd = 0; |
| 1762 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1763 | if (!list_empty(&nlp->els_retry_evt.evt_listp)) { |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 1764 | list_del_init(&nlp->els_retry_evt.evt_listp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1765 | /* Decrement nlp reference count held for the delayed retry */ |
| 1766 | evtp = &nlp->els_retry_evt; |
| 1767 | lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1); |
| 1768 | } |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 1769 | |
| 1770 | if (nlp->nlp_flag & NLP_NPR_2B_DISC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1771 | spin_lock_irq(shost->host_lock); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 1772 | nlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1773 | spin_unlock_irq(shost->host_lock); |
| 1774 | if (vport->num_disc_nodes) { |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 1775 | /* Check to see if there are more |
| 1776 | * PLOGIs to be sent |
| 1777 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1778 | lpfc_more_plogi(vport); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 1779 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1780 | if (vport->num_disc_nodes == 0) { |
| 1781 | spin_lock_irq(shost->host_lock); |
| 1782 | vport->fc_flag &= ~FC_NDISC_ACTIVE; |
| 1783 | spin_unlock_irq(shost->host_lock); |
| 1784 | lpfc_can_disctmo(vport); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1785 | lpfc_end_rscn(vport); |
James Smart | fdcebe2 | 2006-03-07 15:04:01 -0500 | [diff] [blame] | 1786 | } |
| 1787 | } |
| 1788 | } |
| 1789 | return; |
| 1790 | } |
| 1791 | |
| 1792 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1793 | lpfc_els_retry_delay(unsigned long ptr) |
| 1794 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1795 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr; |
| 1796 | struct lpfc_vport *vport = ndlp->vport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1797 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1798 | unsigned long flags; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1799 | struct lpfc_work_evt *evtp = &ndlp->els_retry_evt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1800 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1801 | ndlp = (struct lpfc_nodelist *) ptr; |
| 1802 | phba = ndlp->vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1803 | evtp = &ndlp->els_retry_evt; |
| 1804 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1805 | spin_lock_irqsave(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1806 | if (!list_empty(&evtp->evt_listp)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1807 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1808 | return; |
| 1809 | } |
| 1810 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 1811 | /* We need to hold the node by incrementing the reference |
| 1812 | * count until the queued work is done |
| 1813 | */ |
| 1814 | evtp->evt_arg1 = lpfc_nlp_get(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1815 | evtp->evt = LPFC_EVT_ELS_RETRY; |
| 1816 | list_add_tail(&evtp->evt_listp, &phba->work_list); |
| 1817 | if (phba->work_wait) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1818 | lpfc_worker_wake_up(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1819 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1820 | spin_unlock_irqrestore(&phba->hbalock, flags); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1821 | return; |
| 1822 | } |
| 1823 | |
| 1824 | void |
| 1825 | lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp) |
| 1826 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1827 | struct lpfc_vport *vport = ndlp->vport; |
| 1828 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1829 | uint32_t cmd, did, retry; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1830 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1831 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 1832 | did = ndlp->nlp_DID; |
| 1833 | cmd = ndlp->nlp_last_elscmd; |
| 1834 | ndlp->nlp_last_elscmd = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1835 | |
| 1836 | if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1837 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1838 | return; |
| 1839 | } |
| 1840 | |
| 1841 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1842 | spin_unlock_irq(shost->host_lock); |
James Smart | 1a16968 | 2006-03-07 15:04:06 -0500 | [diff] [blame] | 1843 | /* |
| 1844 | * If a discovery event readded nlp_delayfunc after timer |
| 1845 | * firing and before processing the timer, cancel the |
| 1846 | * nlp_delayfunc. |
| 1847 | */ |
| 1848 | del_timer_sync(&ndlp->nlp_delayfunc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1849 | retry = ndlp->nlp_retry; |
| 1850 | |
| 1851 | switch (cmd) { |
| 1852 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1853 | lpfc_issue_els_flogi(vport, ndlp, retry); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1854 | break; |
| 1855 | case ELS_CMD_PLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1856 | if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 1857 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1858 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 1859 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1860 | break; |
| 1861 | case ELS_CMD_ADISC: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1862 | if (!lpfc_issue_els_adisc(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 1863 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1864 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 1865 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1866 | break; |
| 1867 | case ELS_CMD_PRLI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1868 | if (!lpfc_issue_els_prli(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 1869 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1870 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 1871 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1872 | break; |
| 1873 | case ELS_CMD_LOGO: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1874 | if (!lpfc_issue_els_logo(vport, ndlp, retry)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 1875 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1876 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
Jamie Wellnitz | 6ad4253 | 2006-02-28 19:25:16 -0500 | [diff] [blame] | 1877 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1878 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1879 | case ELS_CMD_FDISC: |
| 1880 | lpfc_issue_els_fdisc(vport, ndlp, retry); |
| 1881 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1882 | } |
| 1883 | return; |
| 1884 | } |
| 1885 | |
| 1886 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1887 | lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 1888 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1889 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1890 | struct lpfc_vport *vport = cmdiocb->vport; |
| 1891 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 1892 | IOCB_t *irsp = &rspiocb->iocb; |
| 1893 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 1894 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1895 | uint32_t *elscmd; |
| 1896 | struct ls_rjt stat; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1897 | int retry = 0, maxretry = lpfc_max_els_tries, delay = 0; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1898 | int logerr = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1899 | uint32_t cmd = 0; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1900 | uint32_t did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1901 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1902 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1903 | /* Note: context2 may be 0 for internal driver abort |
| 1904 | * of delays ELS command. |
| 1905 | */ |
| 1906 | |
| 1907 | if (pcmd && pcmd->virt) { |
| 1908 | elscmd = (uint32_t *) (pcmd->virt); |
| 1909 | cmd = *elscmd++; |
| 1910 | } |
| 1911 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1912 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1913 | did = ndlp->nlp_DID; |
| 1914 | else { |
| 1915 | /* We should only hit this case for retrying PLOGI */ |
| 1916 | did = irsp->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1917 | ndlp = lpfc_findnode_did(vport, did); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1918 | if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
| 1919 | && (cmd != ELS_CMD_PLOGI)) |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 1920 | return 1; |
| 1921 | } |
| 1922 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1923 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 1924 | "Retry ELS: wd7:x%x wd4:x%x did:x%x", |
| 1925 | *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID); |
| 1926 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1927 | switch (irsp->ulpStatus) { |
| 1928 | case IOSTAT_FCP_RSP_ERROR: |
| 1929 | case IOSTAT_REMOTE_STOP: |
| 1930 | break; |
| 1931 | |
| 1932 | case IOSTAT_LOCAL_REJECT: |
| 1933 | switch ((irsp->un.ulpWord[4] & 0xff)) { |
| 1934 | case IOERR_LOOP_OPEN_FAILURE: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1935 | if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1936 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1937 | retry = 1; |
| 1938 | break; |
| 1939 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1940 | case IOERR_ILLEGAL_COMMAND: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 1941 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 1942 | "0124 Retry illegal cmd x%x " |
| 1943 | "retry:x%x delay:x%x\n", |
| 1944 | cmd, cmdiocb->retry, delay); |
| 1945 | retry = 1; |
| 1946 | /* All command's retry policy */ |
| 1947 | maxretry = 8; |
| 1948 | if (cmdiocb->retry > 2) |
| 1949 | delay = 1000; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1950 | break; |
| 1951 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1952 | case IOERR_NO_RESOURCES: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1953 | logerr = 1; /* HBA out of resources */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1954 | retry = 1; |
| 1955 | if (cmdiocb->retry > 100) |
| 1956 | delay = 100; |
| 1957 | maxretry = 250; |
| 1958 | break; |
| 1959 | |
| 1960 | case IOERR_ILLEGAL_FRAME: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1961 | delay = 100; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1962 | retry = 1; |
| 1963 | break; |
| 1964 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1965 | case IOERR_SEQUENCE_TIMEOUT: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1966 | case IOERR_INVALID_RPI: |
| 1967 | retry = 1; |
| 1968 | break; |
| 1969 | } |
| 1970 | break; |
| 1971 | |
| 1972 | case IOSTAT_NPORT_RJT: |
| 1973 | case IOSTAT_FABRIC_RJT: |
| 1974 | if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 1975 | retry = 1; |
| 1976 | break; |
| 1977 | } |
| 1978 | break; |
| 1979 | |
| 1980 | case IOSTAT_NPORT_BSY: |
| 1981 | case IOSTAT_FABRIC_BSY: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1982 | logerr = 1; /* Fabric / Remote NPort out of resources */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1983 | retry = 1; |
| 1984 | break; |
| 1985 | |
| 1986 | case IOSTAT_LS_RJT: |
| 1987 | stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]); |
| 1988 | /* Added for Vendor specifc support |
| 1989 | * Just keep retrying for these Rsn / Exp codes |
| 1990 | */ |
| 1991 | switch (stat.un.b.lsRjtRsnCode) { |
| 1992 | case LSRJT_UNABLE_TPC: |
| 1993 | if (stat.un.b.lsRjtRsnCodeExp == |
| 1994 | LSEXP_CMD_IN_PROGRESS) { |
| 1995 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1996 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1997 | maxretry = 48; |
| 1998 | } |
| 1999 | retry = 1; |
| 2000 | break; |
| 2001 | } |
| 2002 | if (cmd == ELS_CMD_PLOGI) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2003 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2004 | maxretry = lpfc_max_els_tries + 1; |
| 2005 | retry = 1; |
| 2006 | break; |
| 2007 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2008 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 2009 | (cmd == ELS_CMD_FDISC) && |
| 2010 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2011 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2012 | "0125 FDISC Failed (x%x). " |
| 2013 | "Fabric out of resources\n", |
| 2014 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2015 | lpfc_vport_set_state(vport, |
| 2016 | FC_VPORT_NO_FABRIC_RSCS); |
| 2017 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2018 | break; |
| 2019 | |
| 2020 | case LSRJT_LOGICAL_BSY: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2021 | if ((cmd == ELS_CMD_PLOGI) || |
| 2022 | (cmd == ELS_CMD_PRLI)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2023 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2024 | maxretry = 48; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2025 | } else if (cmd == ELS_CMD_FDISC) { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2026 | /* FDISC retry policy */ |
| 2027 | maxretry = 48; |
| 2028 | if (cmdiocb->retry >= 32) |
| 2029 | delay = 1000; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2030 | } |
| 2031 | retry = 1; |
| 2032 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2033 | |
| 2034 | case LSRJT_LOGICAL_ERR: |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 2035 | /* There are some cases where switches return this |
| 2036 | * error when they are not ready and should be returning |
| 2037 | * Logical Busy. We should delay every time. |
| 2038 | */ |
| 2039 | if (cmd == ELS_CMD_FDISC && |
| 2040 | stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) { |
| 2041 | maxretry = 3; |
| 2042 | delay = 1000; |
| 2043 | retry = 1; |
| 2044 | break; |
| 2045 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2046 | case LSRJT_PROTOCOL_ERR: |
| 2047 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 2048 | (cmd == ELS_CMD_FDISC) && |
| 2049 | ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) || |
| 2050 | (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID)) |
| 2051 | ) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2052 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2053 | "0123 FDISC Failed (x%x). " |
| 2054 | "Fabric Detected Bad WWN\n", |
| 2055 | stat.un.lsRjtError); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2056 | lpfc_vport_set_state(vport, |
| 2057 | FC_VPORT_FABRIC_REJ_WWN); |
| 2058 | } |
| 2059 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2060 | } |
| 2061 | break; |
| 2062 | |
| 2063 | case IOSTAT_INTERMED_RSP: |
| 2064 | case IOSTAT_BA_RJT: |
| 2065 | break; |
| 2066 | |
| 2067 | default: |
| 2068 | break; |
| 2069 | } |
| 2070 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2071 | if (did == FDMI_DID) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2072 | retry = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2073 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2074 | if ((cmd == ELS_CMD_FLOGI) && |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 2075 | (phba->fc_topology != TOPOLOGY_LOOP) && |
| 2076 | !lpfc_error_lost_link(irsp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2077 | /* FLOGI retry policy */ |
| 2078 | retry = 1; |
| 2079 | maxretry = 48; |
| 2080 | if (cmdiocb->retry >= 32) |
| 2081 | delay = 1000; |
| 2082 | } |
| 2083 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2084 | if ((++cmdiocb->retry) >= maxretry) { |
| 2085 | phba->fc_stat.elsRetryExceeded++; |
| 2086 | retry = 0; |
| 2087 | } |
| 2088 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2089 | if ((vport->load_flag & FC_UNLOADING) != 0) |
| 2090 | retry = 0; |
| 2091 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2092 | if (retry) { |
| 2093 | |
| 2094 | /* Retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2095 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2096 | "0107 Retry ELS command x%x to remote " |
| 2097 | "NPORT x%x Data: x%x x%x\n", |
| 2098 | cmd, did, cmdiocb->retry, delay); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2099 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2100 | if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) && |
| 2101 | ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || |
| 2102 | ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) { |
| 2103 | /* Don't reset timer for no resources */ |
| 2104 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2105 | /* If discovery / RSCN timer is running, reset it */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2106 | if (timer_pending(&vport->fc_disctmo) || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2107 | (vport->fc_flag & FC_RSCN_MODE)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2108 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2109 | } |
| 2110 | |
| 2111 | phba->fc_stat.elsXmitRetry++; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame^] | 2112 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2113 | phba->fc_stat.elsDelayRetry++; |
| 2114 | ndlp->nlp_retry = cmdiocb->retry; |
| 2115 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2116 | /* delay is specified in milliseconds */ |
| 2117 | mod_timer(&ndlp->nlp_delayfunc, |
| 2118 | jiffies + msecs_to_jiffies(delay)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2119 | spin_lock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2120 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2121 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2122 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2123 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2124 | if (cmd == ELS_CMD_PRLI) |
| 2125 | lpfc_nlp_set_state(vport, ndlp, |
| 2126 | NLP_STE_REG_LOGIN_ISSUE); |
| 2127 | else |
| 2128 | lpfc_nlp_set_state(vport, ndlp, |
| 2129 | NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2130 | ndlp->nlp_last_elscmd = cmd; |
| 2131 | |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2132 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2133 | } |
| 2134 | switch (cmd) { |
| 2135 | case ELS_CMD_FLOGI: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2136 | lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2137 | return 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2138 | case ELS_CMD_FDISC: |
| 2139 | lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry); |
| 2140 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2141 | case ELS_CMD_PLOGI: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame^] | 2142 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2143 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2144 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 2145 | NLP_STE_PLOGI_ISSUE); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2146 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2147 | lpfc_issue_els_plogi(vport, did, cmdiocb->retry); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2148 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2149 | case ELS_CMD_ADISC: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2150 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2151 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 2152 | lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2153 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2154 | case ELS_CMD_PRLI: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2155 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2156 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
| 2157 | lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2158 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2159 | case ELS_CMD_LOGO: |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2160 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2161 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 2162 | lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2163 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2164 | } |
| 2165 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2166 | /* No retry ELS command <elsCmd> to remote NPORT <did> */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2167 | if (logerr) { |
| 2168 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2169 | "0137 No retry ELS command x%x to remote " |
| 2170 | "NPORT x%x: Out of Resources: Error:x%x/%x\n", |
| 2171 | cmd, did, irsp->ulpStatus, |
| 2172 | irsp->un.ulpWord[4]); |
| 2173 | } |
| 2174 | else { |
| 2175 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 2176 | "0108 No retry ELS command x%x to remote " |
| 2177 | "NPORT x%x Retried:%d Error:x%x/%x\n", |
| 2178 | cmd, did, cmdiocb->retry, irsp->ulpStatus, |
| 2179 | irsp->un.ulpWord[4]); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2180 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2181 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2182 | } |
| 2183 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2184 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2185 | lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1) |
| 2186 | { |
| 2187 | struct lpfc_dmabuf *buf_ptr; |
| 2188 | |
| 2189 | /* Free the response before processing the command. */ |
| 2190 | if (!list_empty(&buf_ptr1->list)) { |
| 2191 | list_remove_head(&buf_ptr1->list, buf_ptr, |
| 2192 | struct lpfc_dmabuf, |
| 2193 | list); |
| 2194 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 2195 | kfree(buf_ptr); |
| 2196 | } |
| 2197 | lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys); |
| 2198 | kfree(buf_ptr1); |
| 2199 | return 0; |
| 2200 | } |
| 2201 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2202 | static int |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2203 | lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr) |
| 2204 | { |
| 2205 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 2206 | kfree(buf_ptr); |
| 2207 | return 0; |
| 2208 | } |
| 2209 | |
| 2210 | int |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2211 | lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2212 | { |
| 2213 | struct lpfc_dmabuf *buf_ptr, *buf_ptr1; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2214 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2215 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2216 | ndlp = (struct lpfc_nodelist *)elsiocb->context1; |
| 2217 | if (ndlp) { |
| 2218 | if (ndlp->nlp_flag & NLP_DEFER_RM) { |
| 2219 | lpfc_nlp_put(ndlp); |
| 2220 | |
| 2221 | /* If the ndlp is not being used by another discovery |
| 2222 | * thread, free it. |
| 2223 | */ |
| 2224 | if (!lpfc_nlp_not_used(ndlp)) { |
| 2225 | /* If ndlp is being used by another discovery |
| 2226 | * thread, just clear NLP_DEFER_RM |
| 2227 | */ |
| 2228 | ndlp->nlp_flag &= ~NLP_DEFER_RM; |
| 2229 | } |
| 2230 | } |
| 2231 | else |
| 2232 | lpfc_nlp_put(ndlp); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2233 | elsiocb->context1 = NULL; |
| 2234 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2235 | /* context2 = cmd, context2->next = rsp, context3 = bpl */ |
| 2236 | if (elsiocb->context2) { |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2237 | if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) { |
| 2238 | /* Firmware could still be in progress of DMAing |
| 2239 | * payload, so don't free data buffer till after |
| 2240 | * a hbeat. |
| 2241 | */ |
| 2242 | elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE; |
| 2243 | buf_ptr = elsiocb->context2; |
| 2244 | elsiocb->context2 = NULL; |
| 2245 | if (buf_ptr) { |
| 2246 | buf_ptr1 = NULL; |
| 2247 | spin_lock_irq(&phba->hbalock); |
| 2248 | if (!list_empty(&buf_ptr->list)) { |
| 2249 | list_remove_head(&buf_ptr->list, |
| 2250 | buf_ptr1, struct lpfc_dmabuf, |
| 2251 | list); |
| 2252 | INIT_LIST_HEAD(&buf_ptr1->list); |
| 2253 | list_add_tail(&buf_ptr1->list, |
| 2254 | &phba->elsbuf); |
| 2255 | phba->elsbuf_cnt++; |
| 2256 | } |
| 2257 | INIT_LIST_HEAD(&buf_ptr->list); |
| 2258 | list_add_tail(&buf_ptr->list, &phba->elsbuf); |
| 2259 | phba->elsbuf_cnt++; |
| 2260 | spin_unlock_irq(&phba->hbalock); |
| 2261 | } |
| 2262 | } else { |
| 2263 | buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2; |
| 2264 | lpfc_els_free_data(phba, buf_ptr1); |
| 2265 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2266 | } |
| 2267 | |
| 2268 | if (elsiocb->context3) { |
| 2269 | buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2270 | lpfc_els_free_bpl(phba, buf_ptr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2271 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2272 | lpfc_sli_release_iocbq(phba, elsiocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2273 | return 0; |
| 2274 | } |
| 2275 | |
| 2276 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2277 | lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 2278 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2279 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2280 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2281 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2282 | IOCB_t *irsp; |
| 2283 | |
| 2284 | irsp = &rspiocb->iocb; |
| 2285 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 2286 | "ACC LOGO cmpl: status:x%x/x%x did:x%x", |
| 2287 | irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2288 | /* ACC to LOGO completes to NPort <nlp_DID> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2289 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2290 | "0109 ACC to LOGO completes to NPort x%x " |
| 2291 | "Data: x%x x%x x%x\n", |
| 2292 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 2293 | ndlp->nlp_rpi); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2294 | |
| 2295 | if (ndlp->nlp_state == NLP_STE_NPR_NODE) { |
| 2296 | /* NPort Recovery mode or node is just allocated */ |
| 2297 | if (!lpfc_nlp_not_used(ndlp)) { |
| 2298 | /* If the ndlp is being used by another discovery |
| 2299 | * thread, just unregister the RPI. |
| 2300 | */ |
| 2301 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2302 | } else { |
| 2303 | /* Indicate the node has already released, should |
| 2304 | * not reference to it from within lpfc_els_free_iocb. |
| 2305 | */ |
| 2306 | cmdiocb->context1 = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2307 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2308 | } |
| 2309 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2310 | return; |
| 2311 | } |
| 2312 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2313 | void |
| 2314 | lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 2315 | { |
| 2316 | struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1); |
| 2317 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 2318 | |
| 2319 | pmb->context1 = NULL; |
| 2320 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2321 | kfree(mp); |
| 2322 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame^] | 2323 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2324 | lpfc_nlp_put(ndlp); |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2325 | /* This is the end of the default RPI cleanup logic for this |
| 2326 | * ndlp. If no other discovery threads are using this ndlp. |
| 2327 | * we should free all resources associated with it. |
| 2328 | */ |
| 2329 | lpfc_nlp_not_used(ndlp); |
| 2330 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2331 | return; |
| 2332 | } |
| 2333 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2334 | static void |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2335 | lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2336 | struct lpfc_iocbq *rspiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2337 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2338 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 2339 | struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL; |
| 2340 | struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2341 | IOCB_t *irsp; |
| 2342 | uint8_t *pcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2343 | LPFC_MBOXQ_t *mbox = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2344 | struct lpfc_dmabuf *mp = NULL; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2345 | uint32_t ls_rjt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2346 | |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 2347 | irsp = &rspiocb->iocb; |
| 2348 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2349 | if (cmdiocb->context_un.mbox) |
| 2350 | mbox = cmdiocb->context_un.mbox; |
| 2351 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2352 | /* First determine if this is a LS_RJT cmpl. Note, this callback |
| 2353 | * function can have cmdiocb->contest1 (ndlp) field set to NULL. |
| 2354 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2355 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame^] | 2356 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 2357 | (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2358 | /* A LS_RJT associated with Default RPI cleanup has its own |
| 2359 | * seperate code path. |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2360 | */ |
| 2361 | if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
| 2362 | ls_rjt = 1; |
| 2363 | } |
| 2364 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2365 | /* Check to see if link went down during discovery */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame^] | 2366 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2367 | if (mbox) { |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 2368 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 2369 | if (mp) { |
| 2370 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2371 | kfree(mp); |
| 2372 | } |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2373 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2374 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame^] | 2375 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
| 2376 | (ndlp->nlp_flag & NLP_RM_DFLT_RPI)) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2377 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2378 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2379 | /* Indicate the node has already released, |
| 2380 | * should not reference to it from within |
| 2381 | * the routine lpfc_els_free_iocb. |
| 2382 | */ |
| 2383 | cmdiocb->context1 = NULL; |
| 2384 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2385 | goto out; |
| 2386 | } |
| 2387 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2388 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2389 | "ELS rsp cmpl: status:x%x/x%x did:x%x", |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2390 | irsp->ulpStatus, irsp->un.ulpWord[4], |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2391 | cmdiocb->iocb.un.elsreq64.remoteID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2392 | /* ELS response tag <ulpIoTag> completes */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2393 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2394 | "0110 ELS response tag x%x completes " |
| 2395 | "Data: x%x x%x x%x x%x x%x x%x x%x\n", |
| 2396 | cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus, |
| 2397 | rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout, |
| 2398 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 2399 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2400 | if (mbox) { |
| 2401 | if ((rspiocb->iocb.ulpStatus == 0) |
| 2402 | && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2403 | lpfc_unreg_rpi(vport, ndlp); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2404 | /* Increment reference count to ndlp to hold the |
| 2405 | * reference to ndlp for the callback function. |
| 2406 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2407 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2408 | mbox->vport = vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2409 | if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) { |
| 2410 | mbox->mbox_flag |= LPFC_MBX_IMED_UNREG; |
| 2411 | mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; |
| 2412 | } |
| 2413 | else { |
| 2414 | mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login; |
| 2415 | ndlp->nlp_prev_state = ndlp->nlp_state; |
| 2416 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2417 | NLP_STE_REG_LOGIN_ISSUE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2418 | } |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 2419 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2420 | != MBX_NOT_FINISHED) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2421 | goto out; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2422 | else |
| 2423 | /* Decrement the ndlp reference count we |
| 2424 | * set for this failed mailbox command. |
| 2425 | */ |
| 2426 | lpfc_nlp_put(ndlp); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2427 | |
| 2428 | /* ELS rsp: Cannot issue reg_login for <NPortid> */ |
| 2429 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 2430 | "0138 ELS rsp: Cannot issue reg_login for x%x " |
| 2431 | "Data: x%x x%x x%x\n", |
| 2432 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 2433 | ndlp->nlp_rpi); |
| 2434 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2435 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2436 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2437 | /* Indicate node has already been released, |
| 2438 | * should not reference to it from within |
| 2439 | * the routine lpfc_els_free_iocb. |
| 2440 | */ |
| 2441 | cmdiocb->context1 = NULL; |
| 2442 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2443 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2444 | /* Do not drop node for lpfc_els_abort'ed ELS cmds */ |
| 2445 | if (!lpfc_error_lost_link(irsp) && |
| 2446 | ndlp->nlp_flag & NLP_ACC_REGLOGIN) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2447 | if (lpfc_nlp_not_used(ndlp)) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2448 | ndlp = NULL; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2449 | /* Indicate node has already been |
| 2450 | * released, should not reference |
| 2451 | * to it from within the routine |
| 2452 | * lpfc_els_free_iocb. |
| 2453 | */ |
| 2454 | cmdiocb->context1 = NULL; |
| 2455 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2456 | } |
| 2457 | } |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 2458 | mp = (struct lpfc_dmabuf *) mbox->context1; |
| 2459 | if (mp) { |
| 2460 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 2461 | kfree(mp); |
| 2462 | } |
| 2463 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2464 | } |
| 2465 | out: |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame^] | 2466 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2467 | spin_lock_irq(shost->host_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2468 | ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2469 | spin_unlock_irq(shost->host_lock); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2470 | |
| 2471 | /* If the node is not being used by another discovery thread, |
| 2472 | * and we are sending a reject, we are done with it. |
| 2473 | * Release driver reference count here and free associated |
| 2474 | * resources. |
| 2475 | */ |
| 2476 | if (ls_rjt) |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 2477 | if (lpfc_nlp_not_used(ndlp)) |
| 2478 | /* Indicate node has already been released, |
| 2479 | * should not reference to it from within |
| 2480 | * the routine lpfc_els_free_iocb. |
| 2481 | */ |
| 2482 | cmdiocb->context1 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2483 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2484 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2485 | lpfc_els_free_iocb(phba, cmdiocb); |
| 2486 | return; |
| 2487 | } |
| 2488 | |
| 2489 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2490 | lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag, |
| 2491 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2492 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2493 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2494 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2495 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2496 | IOCB_t *icmd; |
| 2497 | IOCB_t *oldcmd; |
| 2498 | struct lpfc_iocbq *elsiocb; |
| 2499 | struct lpfc_sli_ring *pring; |
| 2500 | struct lpfc_sli *psli; |
| 2501 | uint8_t *pcmd; |
| 2502 | uint16_t cmdsize; |
| 2503 | int rc; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 2504 | ELS_PKT *els_pkt_ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2505 | |
| 2506 | psli = &phba->sli; |
| 2507 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ |
| 2508 | oldcmd = &oldiocb->iocb; |
| 2509 | |
| 2510 | switch (flag) { |
| 2511 | case ELS_CMD_ACC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2512 | cmdsize = sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2513 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 2514 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2515 | if (!elsiocb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2516 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 2517 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2518 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2519 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2520 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2521 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2522 | icmd = &elsiocb->iocb; |
| 2523 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 2524 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2525 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2526 | pcmd += sizeof(uint32_t); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2527 | |
| 2528 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 2529 | "Issue ACC: did:x%x flg:x%x", |
| 2530 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2531 | break; |
| 2532 | case ELS_CMD_PLOGI: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2533 | cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2534 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
| 2535 | ndlp, ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2536 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2537 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2538 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2539 | icmd = &elsiocb->iocb; |
| 2540 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 2541 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2542 | |
| 2543 | if (mbox) |
| 2544 | elsiocb->context_un.mbox = mbox; |
| 2545 | |
| 2546 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2547 | pcmd += sizeof(uint32_t); |
| 2548 | memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2549 | |
| 2550 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 2551 | "Issue ACC PLOGI: did:x%x flg:x%x", |
| 2552 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2553 | break; |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 2554 | case ELS_CMD_PRLO: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2555 | cmdsize = sizeof(uint32_t) + sizeof(PRLO); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2556 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 2557 | ndlp, ndlp->nlp_DID, ELS_CMD_PRLO); |
| 2558 | if (!elsiocb) |
| 2559 | return 1; |
| 2560 | |
| 2561 | icmd = &elsiocb->iocb; |
| 2562 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 2563 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2564 | |
| 2565 | memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2566 | sizeof(uint32_t) + sizeof(PRLO)); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 2567 | *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC; |
| 2568 | els_pkt_ptr = (ELS_PKT *) pcmd; |
| 2569 | els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2570 | |
| 2571 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 2572 | "Issue ACC PRLO: did:x%x flg:x%x", |
| 2573 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
James Smart | 82d9a2a | 2006-04-15 11:53:05 -0400 | [diff] [blame] | 2574 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2575 | default: |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2576 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2577 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2578 | /* Xmit ELS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2579 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2580 | "0128 Xmit ELS ACC response tag x%x, XRI: x%x, " |
| 2581 | "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n", |
| 2582 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 2583 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 2584 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2585 | if (ndlp->nlp_flag & NLP_LOGO_ACC) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2586 | spin_lock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2587 | ndlp->nlp_flag &= ~NLP_LOGO_ACC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2588 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2589 | elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc; |
| 2590 | } else { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2591 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2592 | } |
| 2593 | |
| 2594 | phba->fc_stat.elsXmitACC++; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2595 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2596 | if (rc == IOCB_ERROR) { |
| 2597 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2598 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2599 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2600 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2601 | } |
| 2602 | |
| 2603 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2604 | lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError, |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2605 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp, |
| 2606 | LPFC_MBOXQ_t *mbox) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2607 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2608 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2609 | IOCB_t *icmd; |
| 2610 | IOCB_t *oldcmd; |
| 2611 | struct lpfc_iocbq *elsiocb; |
| 2612 | struct lpfc_sli_ring *pring; |
| 2613 | struct lpfc_sli *psli; |
| 2614 | uint8_t *pcmd; |
| 2615 | uint16_t cmdsize; |
| 2616 | int rc; |
| 2617 | |
| 2618 | psli = &phba->sli; |
| 2619 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ |
| 2620 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2621 | cmdsize = 2 * sizeof(uint32_t); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2622 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 2623 | ndlp->nlp_DID, ELS_CMD_LS_RJT); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2624 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2625 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2626 | |
| 2627 | icmd = &elsiocb->iocb; |
| 2628 | oldcmd = &oldiocb->iocb; |
| 2629 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 2630 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2631 | |
| 2632 | *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2633 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2634 | *((uint32_t *) (pcmd)) = rejectError; |
| 2635 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2636 | if (mbox) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2637 | elsiocb->context_un.mbox = mbox; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2638 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2639 | /* Xmit ELS RJT <err> response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2640 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2641 | "0129 Xmit ELS RJT x%x response tag x%x " |
| 2642 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 2643 | "rpi x%x\n", |
| 2644 | rejectError, elsiocb->iotag, |
| 2645 | elsiocb->iocb.ulpContext, ndlp->nlp_DID, |
| 2646 | ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2647 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 2648 | "Issue LS_RJT: did:x%x flg:x%x err:x%x", |
| 2649 | ndlp->nlp_DID, ndlp->nlp_flag, rejectError); |
| 2650 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2651 | phba->fc_stat.elsXmitLSRJT++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2652 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2653 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2654 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2655 | if (rc == IOCB_ERROR) { |
| 2656 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2657 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2658 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2659 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2660 | } |
| 2661 | |
| 2662 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2663 | lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, |
| 2664 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2665 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2666 | struct lpfc_hba *phba = vport->phba; |
| 2667 | struct lpfc_sli *psli = &phba->sli; |
| 2668 | struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2669 | ADISC *ap; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2670 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2671 | struct lpfc_iocbq *elsiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2672 | uint8_t *pcmd; |
| 2673 | uint16_t cmdsize; |
| 2674 | int rc; |
| 2675 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2676 | cmdsize = sizeof(uint32_t) + sizeof(ADISC); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2677 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 2678 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2679 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2680 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2681 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2682 | icmd = &elsiocb->iocb; |
| 2683 | oldcmd = &oldiocb->iocb; |
| 2684 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 2685 | |
| 2686 | /* Xmit ADISC ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2687 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2688 | "0130 Xmit ADISC ACC response iotag x%x xri: " |
| 2689 | "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n", |
| 2690 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 2691 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 2692 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2693 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2694 | |
| 2695 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2696 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2697 | |
| 2698 | ap = (ADISC *) (pcmd); |
| 2699 | ap->hardAL_PA = phba->fc_pref_ALPA; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2700 | memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2701 | memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2702 | ap->DID = be32_to_cpu(vport->fc_myDID); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2703 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2704 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 2705 | "Issue ACC ADISC: did:x%x flg:x%x", |
| 2706 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 2707 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2708 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2709 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2710 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2711 | if (rc == IOCB_ERROR) { |
| 2712 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2713 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2714 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2715 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2716 | } |
| 2717 | |
| 2718 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2719 | lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb, |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 2720 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2721 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2722 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2723 | PRLI *npr; |
| 2724 | lpfc_vpd_t *vpd; |
| 2725 | IOCB_t *icmd; |
| 2726 | IOCB_t *oldcmd; |
| 2727 | struct lpfc_iocbq *elsiocb; |
| 2728 | struct lpfc_sli_ring *pring; |
| 2729 | struct lpfc_sli *psli; |
| 2730 | uint8_t *pcmd; |
| 2731 | uint16_t cmdsize; |
| 2732 | int rc; |
| 2733 | |
| 2734 | psli = &phba->sli; |
| 2735 | pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ |
| 2736 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2737 | cmdsize = sizeof(uint32_t) + sizeof(PRLI); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2738 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2739 | ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK))); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2740 | if (!elsiocb) |
| 2741 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2742 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2743 | icmd = &elsiocb->iocb; |
| 2744 | oldcmd = &oldiocb->iocb; |
| 2745 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 2746 | /* Xmit PRLI ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2747 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2748 | "0131 Xmit PRLI ACC response tag x%x xri x%x, " |
| 2749 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 2750 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 2751 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 2752 | ndlp->nlp_rpi); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2753 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 2754 | |
| 2755 | *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2756 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2757 | |
| 2758 | /* For PRLI, remainder of payload is PRLI parameter page */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2759 | memset(pcmd, 0, sizeof(PRLI)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2760 | |
| 2761 | npr = (PRLI *) pcmd; |
| 2762 | vpd = &phba->vpd; |
| 2763 | /* |
| 2764 | * If our firmware version is 3.20 or later, |
| 2765 | * set the following bits for FC-TAPE support. |
| 2766 | */ |
| 2767 | if (vpd->rev.feaLevelHigh >= 0x02) { |
| 2768 | npr->ConfmComplAllowed = 1; |
| 2769 | npr->Retry = 1; |
| 2770 | npr->TaskRetryIdReq = 1; |
| 2771 | } |
| 2772 | |
| 2773 | npr->acceptRspCode = PRLI_REQ_EXECUTED; |
| 2774 | npr->estabImagePair = 1; |
| 2775 | npr->readXferRdyDis = 1; |
| 2776 | npr->ConfmComplAllowed = 1; |
| 2777 | |
| 2778 | npr->prliType = PRLI_FCP_TYPE; |
| 2779 | npr->initiatorFunc = 1; |
| 2780 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2781 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 2782 | "Issue ACC PRLI: did:x%x flg:x%x", |
| 2783 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 2784 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2785 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2786 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2787 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2788 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2789 | if (rc == IOCB_ERROR) { |
| 2790 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2791 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2792 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2793 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2794 | } |
| 2795 | |
| 2796 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2797 | lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format, |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2798 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2799 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2800 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2801 | RNID *rn; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2802 | IOCB_t *icmd, *oldcmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2803 | struct lpfc_iocbq *elsiocb; |
| 2804 | struct lpfc_sli_ring *pring; |
| 2805 | struct lpfc_sli *psli; |
| 2806 | uint8_t *pcmd; |
| 2807 | uint16_t cmdsize; |
| 2808 | int rc; |
| 2809 | |
| 2810 | psli = &phba->sli; |
| 2811 | pring = &psli->ring[LPFC_ELS_RING]; |
| 2812 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2813 | cmdsize = sizeof(uint32_t) + sizeof(uint32_t) |
| 2814 | + (2 * sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2815 | if (format) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2816 | cmdsize += sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2817 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2818 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 2819 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 2820 | if (!elsiocb) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2821 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2822 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2823 | icmd = &elsiocb->iocb; |
| 2824 | oldcmd = &oldiocb->iocb; |
| 2825 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 2826 | /* Xmit RNID ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2827 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 2828 | "0132 Xmit RNID ACC response tag x%x xri x%x\n", |
| 2829 | elsiocb->iotag, elsiocb->iocb.ulpContext); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2830 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2831 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2832 | pcmd += sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2833 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2834 | memset(pcmd, 0, sizeof(RNID)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2835 | rn = (RNID *) (pcmd); |
| 2836 | rn->Format = format; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2837 | rn->CommonLen = (2 * sizeof(struct lpfc_name)); |
| 2838 | memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2839 | memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2840 | switch (format) { |
| 2841 | case 0: |
| 2842 | rn->SpecificLen = 0; |
| 2843 | break; |
| 2844 | case RNID_TOPOLOGY_DISC: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2845 | rn->SpecificLen = sizeof(RNID_TOP_DISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2846 | memcpy(&rn->un.topologyDisc.portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2847 | &vport->fc_portname, sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2848 | rn->un.topologyDisc.unitType = RNID_HBA; |
| 2849 | rn->un.topologyDisc.physPort = 0; |
| 2850 | rn->un.topologyDisc.attachedNodes = 0; |
| 2851 | break; |
| 2852 | default: |
| 2853 | rn->CommonLen = 0; |
| 2854 | rn->SpecificLen = 0; |
| 2855 | break; |
| 2856 | } |
| 2857 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2858 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP, |
| 2859 | "Issue ACC RNID: did:x%x flg:x%x", |
| 2860 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 2861 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2862 | phba->fc_stat.elsXmitACC++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2863 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 2864 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2865 | elsiocb->context1 = NULL; /* Don't need ndlp for cmpl, |
| 2866 | * it could be freed */ |
| 2867 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2868 | rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2869 | if (rc == IOCB_ERROR) { |
| 2870 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2871 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2872 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 2873 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2874 | } |
| 2875 | |
| 2876 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2877 | lpfc_els_disc_adisc(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2878 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2879 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2880 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2881 | int sentadisc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2882 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2883 | /* go thru NPR nodes and issue any remaining ELS ADISCs */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2884 | 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] | 2885 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 2886 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2887 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 2888 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 2889 | (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2890 | spin_lock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2891 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2892 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2893 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2894 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
| 2895 | lpfc_issue_els_adisc(vport, ndlp, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2896 | sentadisc++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2897 | vport->num_disc_nodes++; |
| 2898 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2899 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2900 | spin_lock_irq(shost->host_lock); |
| 2901 | vport->fc_flag |= FC_NLP_MORE; |
| 2902 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2903 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2904 | } |
| 2905 | } |
| 2906 | } |
| 2907 | if (sentadisc == 0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2908 | spin_lock_irq(shost->host_lock); |
| 2909 | vport->fc_flag &= ~FC_NLP_MORE; |
| 2910 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2911 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 2912 | return sentadisc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2913 | } |
| 2914 | |
| 2915 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2916 | lpfc_els_disc_plogi(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2917 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2918 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2919 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2920 | int sentplogi = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2921 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2922 | /* go thru NPR nodes and issue any remaining ELS PLOGIs */ |
| 2923 | 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] | 2924 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 2925 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2926 | if (ndlp->nlp_state == NLP_STE_NPR_NODE && |
| 2927 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && |
| 2928 | (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 && |
| 2929 | (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) { |
| 2930 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2931 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 2932 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2933 | sentplogi++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2934 | vport->num_disc_nodes++; |
| 2935 | if (vport->num_disc_nodes >= |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2936 | vport->cfg_discovery_threads) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2937 | spin_lock_irq(shost->host_lock); |
| 2938 | vport->fc_flag |= FC_NLP_MORE; |
| 2939 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2940 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2941 | } |
| 2942 | } |
| 2943 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2944 | if (sentplogi) { |
| 2945 | lpfc_set_disctmo(vport); |
| 2946 | } |
| 2947 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2948 | spin_lock_irq(shost->host_lock); |
| 2949 | vport->fc_flag &= ~FC_NLP_MORE; |
| 2950 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2951 | } |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 2952 | return sentplogi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2953 | } |
| 2954 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2955 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2956 | lpfc_els_flush_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2957 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2958 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2959 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2960 | int i; |
| 2961 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 2962 | spin_lock_irq(shost->host_lock); |
| 2963 | if (vport->fc_rscn_flush) { |
| 2964 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 2965 | spin_unlock_irq(shost->host_lock); |
| 2966 | return; |
| 2967 | } |
| 2968 | /* Indicate we are walking lpfc_els_flush_rscn on this vport */ |
| 2969 | vport->fc_rscn_flush = 1; |
| 2970 | spin_unlock_irq(shost->host_lock); |
| 2971 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2972 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2973 | lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2974 | vport->fc_rscn_id_list[i] = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2975 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2976 | spin_lock_irq(shost->host_lock); |
| 2977 | vport->fc_rscn_id_cnt = 0; |
| 2978 | vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY); |
| 2979 | spin_unlock_irq(shost->host_lock); |
| 2980 | lpfc_can_disctmo(vport); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 2981 | /* Indicate we are done walking this fc_rscn_id_list */ |
| 2982 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2983 | } |
| 2984 | |
| 2985 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2986 | lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2987 | { |
| 2988 | D_ID ns_did; |
| 2989 | D_ID rscn_did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2990 | uint32_t *lp; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2991 | uint32_t payload_len, i; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 2992 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2993 | |
| 2994 | ns_did.un.word = did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2995 | |
| 2996 | /* Never match fabric nodes for RSCNs */ |
| 2997 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2998 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2999 | |
| 3000 | /* If we are doing a FULL RSCN rediscovery, match everything */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3001 | if (vport->fc_flag & FC_RSCN_DISCOVERY) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3002 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3003 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3004 | spin_lock_irq(shost->host_lock); |
| 3005 | if (vport->fc_rscn_flush) { |
| 3006 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 3007 | spin_unlock_irq(shost->host_lock); |
| 3008 | return 0; |
| 3009 | } |
| 3010 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 3011 | vport->fc_rscn_flush = 1; |
| 3012 | spin_unlock_irq(shost->host_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3013 | for (i = 0; i < vport->fc_rscn_id_cnt; i++) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3014 | lp = vport->fc_rscn_id_list[i]->virt; |
| 3015 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 3016 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3017 | while (payload_len) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3018 | rscn_did.un.word = be32_to_cpu(*lp++); |
| 3019 | payload_len -= sizeof(uint32_t); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3020 | switch (rscn_did.un.b.resv) { |
| 3021 | case 0: /* Single N_Port ID effected */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3022 | if (ns_did.un.word == rscn_did.un.word) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3023 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3024 | break; |
| 3025 | case 1: /* Whole N_Port Area effected */ |
| 3026 | if ((ns_did.un.b.domain == rscn_did.un.b.domain) |
| 3027 | && (ns_did.un.b.area == rscn_did.un.b.area)) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3028 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3029 | break; |
| 3030 | case 2: /* Whole N_Port Domain effected */ |
| 3031 | if (ns_did.un.b.domain == rscn_did.un.b.domain) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3032 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3033 | break; |
| 3034 | default: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3035 | /* Unknown Identifier in RSCN node */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3036 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
| 3037 | "0217 Unknown Identifier in " |
| 3038 | "RSCN payload Data: x%x\n", |
| 3039 | rscn_did.un.word); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3040 | case 3: /* Whole Fabric effected */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3041 | goto return_did_out; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3042 | } |
| 3043 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3044 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3045 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 3046 | vport->fc_rscn_flush = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3047 | return 0; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3048 | return_did_out: |
| 3049 | /* Indicate we are done with walking fc_rscn_id_list on this vport */ |
| 3050 | vport->fc_rscn_flush = 0; |
| 3051 | return did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3052 | } |
| 3053 | |
| 3054 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3055 | lpfc_rscn_recovery_check(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3056 | { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3057 | struct lpfc_nodelist *ndlp = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3058 | |
| 3059 | /* Look at all nodes effected by pending RSCNs and move |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3060 | * them to NPR state. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3061 | */ |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3062 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3063 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3064 | if (!NLP_CHK_NODE_ACT(ndlp) || |
| 3065 | ndlp->nlp_state == NLP_STE_UNUSED_NODE || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3066 | lpfc_rscn_payload_check(vport, ndlp->nlp_DID) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3067 | continue; |
| 3068 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3069 | lpfc_disc_state_machine(vport, ndlp, NULL, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3070 | NLP_EVT_DEVICE_RECOVERY); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3071 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3072 | /* |
| 3073 | * Make sure NLP_DELAY_TMO is NOT running after a device |
| 3074 | * recovery event. |
| 3075 | */ |
| 3076 | if (ndlp->nlp_flag & NLP_DELAY_TMO) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3077 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3078 | } |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3079 | |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3080 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3081 | } |
| 3082 | |
| 3083 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3084 | lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3085 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3086 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3087 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3088 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3089 | struct lpfc_dmabuf *pcmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3090 | uint32_t *lp, *datap; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3091 | IOCB_t *icmd; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3092 | uint32_t payload_len, length, nportid, *cmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3093 | int rscn_cnt; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3094 | int rscn_id = 0, hba_id = 0; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 3095 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3096 | |
| 3097 | icmd = &cmdiocb->iocb; |
| 3098 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 3099 | lp = (uint32_t *) pcmd->virt; |
| 3100 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3101 | payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK); |
| 3102 | payload_len -= sizeof(uint32_t); /* take off word 0 */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3103 | /* RSCN received */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3104 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 3105 | "0214 RSCN received Data: x%x x%x x%x x%x\n", |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3106 | vport->fc_flag, payload_len, *lp, |
| 3107 | vport->fc_rscn_id_cnt); |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 3108 | for (i = 0; i < payload_len/sizeof(uint32_t); i++) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3109 | fc_host_post_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 3110 | FCH_EVT_RSCN, lp[i]); |
| 3111 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3112 | /* If we are about to begin discovery, just ACC the RSCN. |
| 3113 | * Discovery processing will satisfy it. |
| 3114 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3115 | if (vport->port_state <= LPFC_NS_QRY) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3116 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 3117 | "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x", |
| 3118 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 3119 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3120 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3121 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3122 | } |
| 3123 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3124 | /* If this RSCN just contains NPortIDs for other vports on this HBA, |
| 3125 | * just ACC and ignore it. |
| 3126 | */ |
| 3127 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3128 | !(vport->cfg_peer_port_login)) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3129 | i = payload_len; |
| 3130 | datap = lp; |
| 3131 | while (i > 0) { |
| 3132 | nportid = *datap++; |
| 3133 | nportid = ((be32_to_cpu(nportid)) & Mask_DID); |
| 3134 | i -= sizeof(uint32_t); |
| 3135 | rscn_id++; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3136 | if (lpfc_find_vport_by_did(phba, nportid)) |
| 3137 | hba_id++; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3138 | } |
| 3139 | if (rscn_id == hba_id) { |
| 3140 | /* ALL NPortIDs in RSCN are on HBA */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3141 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 3142 | "0214 Ignore RSCN " |
| 3143 | "Data: x%x x%x x%x x%x\n", |
| 3144 | vport->fc_flag, payload_len, |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3145 | *lp, vport->fc_rscn_id_cnt); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3146 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 3147 | "RCV RSCN vport: did:x%x/ste:x%x flg:x%x", |
| 3148 | ndlp->nlp_DID, vport->port_state, |
| 3149 | ndlp->nlp_flag); |
| 3150 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3151 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3152 | ndlp, NULL); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3153 | return 0; |
| 3154 | } |
| 3155 | } |
| 3156 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3157 | spin_lock_irq(shost->host_lock); |
| 3158 | if (vport->fc_rscn_flush) { |
| 3159 | /* Another thread is walking fc_rscn_id_list on this vport */ |
| 3160 | spin_unlock_irq(shost->host_lock); |
| 3161 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame^] | 3162 | /* Send back ACC */ |
| 3163 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3164 | return 0; |
| 3165 | } |
| 3166 | /* Indicate we are walking fc_rscn_id_list on this vport */ |
| 3167 | vport->fc_rscn_flush = 1; |
| 3168 | spin_unlock_irq(shost->host_lock); |
| 3169 | /* Get the array count after sucessfully have the token */ |
| 3170 | rscn_cnt = vport->fc_rscn_id_cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3171 | /* If we are already processing an RSCN, save the received |
| 3172 | * RSCN payload buffer, cmdiocb->context2 to process later. |
| 3173 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3174 | if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3175 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 3176 | "RCV RSCN defer: did:x%x/ste:x%x flg:x%x", |
| 3177 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 3178 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3179 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3180 | vport->fc_flag |= FC_RSCN_DEFERRED; |
| 3181 | if ((rscn_cnt < FC_MAX_HOLD_RSCN) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3182 | !(vport->fc_flag & FC_RSCN_DISCOVERY)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3183 | vport->fc_flag |= FC_RSCN_MODE; |
| 3184 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3185 | if (rscn_cnt) { |
| 3186 | cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt; |
| 3187 | length = be32_to_cpu(*cmd & ~ELS_CMD_MASK); |
| 3188 | } |
| 3189 | if ((rscn_cnt) && |
| 3190 | (payload_len + length <= LPFC_BPL_SIZE)) { |
| 3191 | *cmd &= ELS_CMD_MASK; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3192 | *cmd |= cpu_to_be32(payload_len + length); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3193 | memcpy(((uint8_t *)cmd) + length, lp, |
| 3194 | payload_len); |
| 3195 | } else { |
| 3196 | vport->fc_rscn_id_list[rscn_cnt] = pcmd; |
| 3197 | vport->fc_rscn_id_cnt++; |
| 3198 | /* If we zero, cmdiocb->context2, the calling |
| 3199 | * routine will not try to free it. |
| 3200 | */ |
| 3201 | cmdiocb->context2 = NULL; |
| 3202 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3203 | /* Deferred RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3204 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 3205 | "0235 Deferred RSCN " |
| 3206 | "Data: x%x x%x x%x\n", |
| 3207 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 3208 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3209 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3210 | vport->fc_flag |= FC_RSCN_DISCOVERY; |
| 3211 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3212 | /* ReDiscovery RSCN */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3213 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 3214 | "0234 ReDiscovery RSCN " |
| 3215 | "Data: x%x x%x x%x\n", |
| 3216 | vport->fc_rscn_id_cnt, vport->fc_flag, |
| 3217 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3218 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3219 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 3220 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3221 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3222 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3223 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3224 | lpfc_rscn_recovery_check(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3225 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3226 | vport->fc_flag &= ~FC_RSCN_DEFERRED; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3227 | spin_unlock_irq(shost->host_lock); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3228 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3229 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3230 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 3231 | "RCV RSCN: did:x%x/ste:x%x flg:x%x", |
| 3232 | ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag); |
| 3233 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3234 | spin_lock_irq(shost->host_lock); |
| 3235 | vport->fc_flag |= FC_RSCN_MODE; |
| 3236 | spin_unlock_irq(shost->host_lock); |
| 3237 | vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3238 | /* Indicate we are done walking fc_rscn_id_list on this vport */ |
| 3239 | vport->fc_rscn_flush = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3240 | /* |
| 3241 | * If we zero, cmdiocb->context2, the calling routine will |
| 3242 | * not try to free it. |
| 3243 | */ |
| 3244 | cmdiocb->context2 = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3245 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3246 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3247 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3248 | /* send RECOVERY event for ALL nodes that match RSCN payload */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3249 | lpfc_rscn_recovery_check(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3250 | return lpfc_els_handle_rscn(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3251 | } |
| 3252 | |
| 3253 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3254 | lpfc_els_handle_rscn(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3255 | { |
| 3256 | struct lpfc_nodelist *ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3257 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3258 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3259 | /* Ignore RSCN if the port is being torn down. */ |
| 3260 | if (vport->load_flag & FC_UNLOADING) { |
| 3261 | lpfc_els_flush_rscn(vport); |
| 3262 | return 0; |
| 3263 | } |
| 3264 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3265 | /* Start timer for RSCN processing */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3266 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3267 | |
| 3268 | /* RSCN processed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3269 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
| 3270 | "0215 RSCN processed Data: x%x x%x x%x x%x\n", |
| 3271 | vport->fc_flag, 0, vport->fc_rscn_id_cnt, |
| 3272 | vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3273 | |
| 3274 | /* To process RSCN, first compare RSCN data with NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3275 | vport->fc_ns_retry = 0; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 3276 | vport->num_disc_nodes = 0; |
| 3277 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3278 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3279 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) |
| 3280 | && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3281 | /* Good ndlp, issue CT Request to NameServer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3282 | if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3283 | /* Wait for NameServer query cmpl before we can |
| 3284 | continue */ |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3285 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3286 | } else { |
| 3287 | /* If login to NameServer does not exist, issue one */ |
| 3288 | /* Good status, issue PLOGI to NameServer */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3289 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3290 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3291 | /* Wait for NameServer login cmpl before we can |
| 3292 | continue */ |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3293 | return 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3294 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3295 | if (ndlp) { |
| 3296 | ndlp = lpfc_enable_node(vport, ndlp, |
| 3297 | NLP_STE_PLOGI_ISSUE); |
| 3298 | if (!ndlp) { |
| 3299 | lpfc_els_flush_rscn(vport); |
| 3300 | return 0; |
| 3301 | } |
| 3302 | ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3303 | } else { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3304 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 3305 | if (!ndlp) { |
| 3306 | lpfc_els_flush_rscn(vport); |
| 3307 | return 0; |
| 3308 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3309 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3310 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3311 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3312 | } |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3313 | ndlp->nlp_type |= NLP_FABRIC; |
| 3314 | lpfc_issue_els_plogi(vport, NameServer_DID, 0); |
| 3315 | /* Wait for NameServer login cmpl before we can |
| 3316 | * continue |
| 3317 | */ |
| 3318 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3319 | } |
| 3320 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3321 | lpfc_els_flush_rscn(vport); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3322 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3323 | } |
| 3324 | |
| 3325 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3326 | lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3327 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3328 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3329 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3330 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3331 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 3332 | uint32_t *lp = (uint32_t *) pcmd->virt; |
| 3333 | IOCB_t *icmd = &cmdiocb->iocb; |
| 3334 | struct serv_parm *sp; |
| 3335 | LPFC_MBOXQ_t *mbox; |
| 3336 | struct ls_rjt stat; |
| 3337 | uint32_t cmd, did; |
| 3338 | int rc; |
| 3339 | |
| 3340 | cmd = *lp++; |
| 3341 | sp = (struct serv_parm *) lp; |
| 3342 | |
| 3343 | /* FLOGI received */ |
| 3344 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3345 | lpfc_set_disctmo(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3346 | |
| 3347 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 3348 | /* We should never receive a FLOGI in loop mode, ignore it */ |
| 3349 | did = icmd->un.elsreq64.remoteID; |
| 3350 | |
| 3351 | /* An FLOGI ELS command <elsCmd> was received from DID <did> in |
| 3352 | Loop Mode */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3353 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3354 | "0113 An FLOGI ELS command x%x was " |
| 3355 | "received from DID x%x in Loop Mode\n", |
| 3356 | cmd, did); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3357 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3358 | } |
| 3359 | |
| 3360 | did = Fabric_DID; |
| 3361 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3362 | if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3363 | /* For a FLOGI we accept, then if our portname is greater |
| 3364 | * then the remote portname we initiate Nport login. |
| 3365 | */ |
| 3366 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3367 | rc = memcmp(&vport->fc_portname, &sp->portName, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3368 | sizeof(struct lpfc_name)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3369 | |
| 3370 | if (!rc) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3371 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 3372 | if (!mbox) |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3373 | return 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3374 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3375 | lpfc_linkdown(phba); |
| 3376 | lpfc_init_link(phba, mbox, |
| 3377 | phba->cfg_topology, |
| 3378 | phba->cfg_link_speed); |
| 3379 | mbox->mb.un.varInitLnk.lipsr_AL_PA = 0; |
| 3380 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3381 | mbox->vport = vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3382 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 3383 | lpfc_set_loopback_flag(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3384 | if (rc == MBX_NOT_FINISHED) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3385 | mempool_free(mbox, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3386 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3387 | return 1; |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3388 | } else if (rc > 0) { /* greater than */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3389 | spin_lock_irq(shost->host_lock); |
| 3390 | vport->fc_flag |= FC_PT2PT_PLOGI; |
| 3391 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3392 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3393 | spin_lock_irq(shost->host_lock); |
| 3394 | vport->fc_flag |= FC_PT2PT; |
| 3395 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 3396 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3397 | } else { |
| 3398 | /* Reject this request because invalid parameters */ |
| 3399 | stat.un.b.lsRjtRsvd0 = 0; |
| 3400 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 3401 | stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS; |
| 3402 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3403 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 3404 | NULL); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3405 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3406 | } |
| 3407 | |
| 3408 | /* Send back ACC */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3409 | lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3410 | |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3411 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3412 | } |
| 3413 | |
| 3414 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3415 | lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 3416 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3417 | { |
| 3418 | struct lpfc_dmabuf *pcmd; |
| 3419 | uint32_t *lp; |
| 3420 | IOCB_t *icmd; |
| 3421 | RNID *rn; |
| 3422 | struct ls_rjt stat; |
| 3423 | uint32_t cmd, did; |
| 3424 | |
| 3425 | icmd = &cmdiocb->iocb; |
| 3426 | did = icmd->un.elsreq64.remoteID; |
| 3427 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 3428 | lp = (uint32_t *) pcmd->virt; |
| 3429 | |
| 3430 | cmd = *lp++; |
| 3431 | rn = (RNID *) lp; |
| 3432 | |
| 3433 | /* RNID received */ |
| 3434 | |
| 3435 | switch (rn->Format) { |
| 3436 | case 0: |
| 3437 | case RNID_TOPOLOGY_DISC: |
| 3438 | /* Send back ACC */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3439 | lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3440 | break; |
| 3441 | default: |
| 3442 | /* Reject this request because format not supported */ |
| 3443 | stat.un.b.lsRjtRsvd0 = 0; |
| 3444 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 3445 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 3446 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3447 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 3448 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3449 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3450 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3451 | } |
| 3452 | |
| 3453 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3454 | lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 3455 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3456 | { |
| 3457 | struct ls_rjt stat; |
| 3458 | |
| 3459 | /* For now, unconditionally reject this command */ |
| 3460 | stat.un.b.lsRjtRsvd0 = 0; |
| 3461 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 3462 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 3463 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3464 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3465 | return 0; |
| 3466 | } |
| 3467 | |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 3468 | static void |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3469 | lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3470 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3471 | struct lpfc_sli *psli = &phba->sli; |
| 3472 | struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING]; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3473 | MAILBOX_t *mb; |
| 3474 | IOCB_t *icmd; |
| 3475 | RPS_RSP *rps_rsp; |
| 3476 | uint8_t *pcmd; |
| 3477 | struct lpfc_iocbq *elsiocb; |
| 3478 | struct lpfc_nodelist *ndlp; |
| 3479 | uint16_t xri, status; |
| 3480 | uint32_t cmdsize; |
| 3481 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3482 | mb = &pmb->mb; |
| 3483 | |
| 3484 | ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 3485 | xri = (uint16_t) ((unsigned long)(pmb->context1)); |
Randy Dunlap | 041976f | 2006-06-25 01:58:51 -0700 | [diff] [blame] | 3486 | pmb->context1 = NULL; |
| 3487 | pmb->context2 = NULL; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3488 | |
| 3489 | if (mb->mbxStatus) { |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3490 | mempool_free(pmb, phba->mbox_mem_pool); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3491 | return; |
| 3492 | } |
| 3493 | |
| 3494 | cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3495 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3496 | elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize, |
| 3497 | lpfc_max_els_tries, ndlp, |
| 3498 | ndlp->nlp_DID, ELS_CMD_ACC); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3499 | |
| 3500 | /* Decrement the ndlp reference count from previous mbox command */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3501 | lpfc_nlp_put(ndlp); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3502 | |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3503 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3504 | return; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3505 | |
| 3506 | icmd = &elsiocb->iocb; |
| 3507 | icmd->ulpContext = xri; |
| 3508 | |
| 3509 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3510 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3511 | pcmd += sizeof(uint32_t); /* Skip past command */ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3512 | rps_rsp = (RPS_RSP *)pcmd; |
| 3513 | |
| 3514 | if (phba->fc_topology != TOPOLOGY_LOOP) |
| 3515 | status = 0x10; |
| 3516 | else |
| 3517 | status = 0x8; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3518 | if (phba->pport->fc_flag & FC_FABRIC) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3519 | status |= 0x4; |
| 3520 | |
| 3521 | rps_rsp->rsvd1 = 0; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3522 | rps_rsp->portStatus = cpu_to_be16(status); |
| 3523 | rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt); |
| 3524 | rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt); |
| 3525 | rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt); |
| 3526 | rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt); |
| 3527 | rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord); |
| 3528 | rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3529 | /* Xmit ELS RPS ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3530 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS, |
| 3531 | "0118 Xmit ELS RPS ACC response tag x%x xri x%x, " |
| 3532 | "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", |
| 3533 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3534 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3535 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3536 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3537 | phba->fc_stat.elsXmitACC++; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3538 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3539 | lpfc_els_free_iocb(phba, elsiocb); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3540 | return; |
| 3541 | } |
| 3542 | |
| 3543 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3544 | lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 3545 | struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3546 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3547 | struct lpfc_hba *phba = vport->phba; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3548 | uint32_t *lp; |
| 3549 | uint8_t flag; |
| 3550 | LPFC_MBOXQ_t *mbox; |
| 3551 | struct lpfc_dmabuf *pcmd; |
| 3552 | RPS *rps; |
| 3553 | struct ls_rjt stat; |
| 3554 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3555 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 3556 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3557 | stat.un.b.lsRjtRsvd0 = 0; |
| 3558 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 3559 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 3560 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3561 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 3562 | NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3563 | } |
| 3564 | |
| 3565 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 3566 | lp = (uint32_t *) pcmd->virt; |
| 3567 | flag = (be32_to_cpu(*lp++) & 0xf); |
| 3568 | rps = (RPS *) lp; |
| 3569 | |
| 3570 | if ((flag == 0) || |
| 3571 | ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) || |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3572 | ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3573 | sizeof(struct lpfc_name)) == 0))) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3574 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3575 | printk("Fix me....\n"); |
| 3576 | dump_stack(); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3577 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); |
| 3578 | if (mbox) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3579 | lpfc_read_lnk_stat(phba, mbox); |
| 3580 | mbox->context1 = |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3581 | (void *)((unsigned long) cmdiocb->iocb.ulpContext); |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3582 | mbox->context2 = lpfc_nlp_get(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3583 | mbox->vport = vport; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3584 | mbox->mbox_cmpl = lpfc_els_rsp_rps_acc; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3585 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 3586 | != MBX_NOT_FINISHED) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3587 | /* Mbox completion will send ELS Response */ |
| 3588 | return 0; |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 3589 | /* Decrement reference count used for the failed mbox |
| 3590 | * command. |
| 3591 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3592 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3593 | mempool_free(mbox, phba->mbox_mem_pool); |
| 3594 | } |
| 3595 | } |
| 3596 | stat.un.b.lsRjtRsvd0 = 0; |
| 3597 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 3598 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 3599 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3600 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3601 | return 0; |
| 3602 | } |
| 3603 | |
Jamie Wellnitz | 082c026 | 2006-02-28 19:25:30 -0500 | [diff] [blame] | 3604 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3605 | lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize, |
| 3606 | struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3607 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3608 | struct lpfc_hba *phba = vport->phba; |
| 3609 | IOCB_t *icmd, *oldcmd; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3610 | RPL_RSP rpl_rsp; |
| 3611 | struct lpfc_iocbq *elsiocb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3612 | struct lpfc_sli *psli = &phba->sli; |
| 3613 | struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING]; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3614 | uint8_t *pcmd; |
| 3615 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3616 | elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, |
| 3617 | ndlp->nlp_DID, ELS_CMD_ACC); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3618 | |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3619 | if (!elsiocb) |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3620 | return 1; |
James Smart | 488d146 | 2006-03-07 15:02:37 -0500 | [diff] [blame] | 3621 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3622 | icmd = &elsiocb->iocb; |
| 3623 | oldcmd = &oldiocb->iocb; |
| 3624 | icmd->ulpContext = oldcmd->ulpContext; /* Xri */ |
| 3625 | |
| 3626 | pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 3627 | *((uint32_t *) (pcmd)) = ELS_CMD_ACC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3628 | pcmd += sizeof(uint16_t); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3629 | *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize); |
| 3630 | pcmd += sizeof(uint16_t); |
| 3631 | |
| 3632 | /* Setup the RPL ACC payload */ |
| 3633 | rpl_rsp.listLen = be32_to_cpu(1); |
| 3634 | rpl_rsp.index = 0; |
| 3635 | rpl_rsp.port_num_blk.portNum = 0; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3636 | rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID); |
| 3637 | memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname, |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3638 | sizeof(struct lpfc_name)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3639 | memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t)); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3640 | /* Xmit ELS RPL ACC response tag <ulpIoTag> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3641 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3642 | "0120 Xmit ELS RPL ACC response tag x%x " |
| 3643 | "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, " |
| 3644 | "rpi x%x\n", |
| 3645 | elsiocb->iotag, elsiocb->iocb.ulpContext, |
| 3646 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, |
| 3647 | ndlp->nlp_rpi); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3648 | elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3649 | phba->fc_stat.elsXmitACC++; |
| 3650 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { |
| 3651 | lpfc_els_free_iocb(phba, elsiocb); |
| 3652 | return 1; |
| 3653 | } |
| 3654 | return 0; |
| 3655 | } |
| 3656 | |
| 3657 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3658 | lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 3659 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3660 | { |
| 3661 | struct lpfc_dmabuf *pcmd; |
| 3662 | uint32_t *lp; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3663 | uint32_t maxsize; |
| 3664 | uint16_t cmdsize; |
| 3665 | RPL *rpl; |
| 3666 | struct ls_rjt stat; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3667 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3668 | if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) && |
| 3669 | (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3670 | stat.un.b.lsRjtRsvd0 = 0; |
| 3671 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
| 3672 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; |
| 3673 | stat.un.b.vendorUnique = 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3674 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
| 3675 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3676 | } |
| 3677 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3678 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 3679 | lp = (uint32_t *) pcmd->virt; |
| 3680 | rpl = (RPL *) (lp + 1); |
| 3681 | |
| 3682 | maxsize = be32_to_cpu(rpl->maxsize); |
| 3683 | |
| 3684 | /* We support only one port */ |
| 3685 | if ((rpl->index == 0) && |
| 3686 | ((maxsize == 0) || |
| 3687 | ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) { |
| 3688 | cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP); |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3689 | } else { |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 3690 | cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t); |
| 3691 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3692 | lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3693 | |
| 3694 | return 0; |
| 3695 | } |
| 3696 | |
| 3697 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3698 | lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 3699 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3700 | { |
| 3701 | struct lpfc_dmabuf *pcmd; |
| 3702 | uint32_t *lp; |
| 3703 | IOCB_t *icmd; |
| 3704 | FARP *fp; |
| 3705 | uint32_t cmd, cnt, did; |
| 3706 | |
| 3707 | icmd = &cmdiocb->iocb; |
| 3708 | did = icmd->un.elsreq64.remoteID; |
| 3709 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 3710 | lp = (uint32_t *) pcmd->virt; |
| 3711 | |
| 3712 | cmd = *lp++; |
| 3713 | fp = (FARP *) lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3714 | /* FARP-REQ received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3715 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3716 | "0601 FARP-REQ received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3717 | /* We will only support match on WWPN or WWNN */ |
| 3718 | if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) { |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3719 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3720 | } |
| 3721 | |
| 3722 | cnt = 0; |
| 3723 | /* If this FARP command is searching for my portname */ |
| 3724 | if (fp->Mflags & FARP_MATCH_PORT) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3725 | if (memcmp(&fp->RportName, &vport->fc_portname, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3726 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3727 | cnt = 1; |
| 3728 | } |
| 3729 | |
| 3730 | /* If this FARP command is searching for my nodename */ |
| 3731 | if (fp->Mflags & FARP_MATCH_NODE) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3732 | if (memcmp(&fp->RnodeName, &vport->fc_nodename, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3733 | sizeof(struct lpfc_name)) == 0) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3734 | cnt = 1; |
| 3735 | } |
| 3736 | |
| 3737 | if (cnt) { |
| 3738 | if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) || |
| 3739 | (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) { |
| 3740 | /* Log back into the node before sending the FARP. */ |
| 3741 | if (fp->Rflags & FARP_REQUEST_PLOGI) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3742 | ndlp->nlp_prev_state = ndlp->nlp_state; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3743 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3744 | NLP_STE_PLOGI_ISSUE); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3745 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3746 | } |
| 3747 | |
| 3748 | /* Send a FARP response to that node */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3749 | if (fp->Rflags & FARP_REQUEST_FARPR) |
| 3750 | lpfc_issue_els_farpr(vport, did, 0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3751 | } |
| 3752 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3753 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3754 | } |
| 3755 | |
| 3756 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3757 | lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 3758 | struct lpfc_nodelist *ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3759 | { |
| 3760 | struct lpfc_dmabuf *pcmd; |
| 3761 | uint32_t *lp; |
| 3762 | IOCB_t *icmd; |
| 3763 | uint32_t cmd, did; |
| 3764 | |
| 3765 | icmd = &cmdiocb->iocb; |
| 3766 | did = icmd->un.elsreq64.remoteID; |
| 3767 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
| 3768 | lp = (uint32_t *) pcmd->virt; |
| 3769 | |
| 3770 | cmd = *lp++; |
| 3771 | /* FARP-RSP received from DID <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3772 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3773 | "0600 FARP-RSP received from DID x%x\n", did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3774 | /* ACCEPT the Farp resp request */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3775 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3776 | |
| 3777 | return 0; |
| 3778 | } |
| 3779 | |
| 3780 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3781 | lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, |
| 3782 | struct lpfc_nodelist *fan_ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3783 | { |
| 3784 | struct lpfc_dmabuf *pcmd; |
| 3785 | uint32_t *lp; |
| 3786 | IOCB_t *icmd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3787 | uint32_t cmd, did; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3788 | FAN *fp; |
| 3789 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3790 | struct lpfc_hba *phba = vport->phba; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3791 | |
| 3792 | /* FAN received */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3793 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 3794 | "0265 FAN received\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3795 | icmd = &cmdiocb->iocb; |
| 3796 | did = icmd->un.elsreq64.remoteID; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3797 | pcmd = (struct lpfc_dmabuf *)cmdiocb->context2; |
| 3798 | lp = (uint32_t *)pcmd->virt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3799 | |
| 3800 | cmd = *lp++; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3801 | fp = (FAN *) lp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3802 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3803 | /* FAN received; Fan does not have a reply sequence */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3804 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3805 | if (phba->pport->port_state == LPFC_LOCAL_CFG_LINK) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3806 | if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName, |
| 3807 | sizeof(struct lpfc_name)) != 0) || |
| 3808 | (memcmp(&phba->fc_fabparam.portName, &fp->FportName, |
| 3809 | sizeof(struct lpfc_name)) != 0)) { |
| 3810 | /* |
| 3811 | * This node has switched fabrics. FLOGI is required |
| 3812 | * Clean up the old rpi's |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3813 | */ |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3814 | |
| 3815 | list_for_each_entry_safe(ndlp, next_ndlp, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3816 | &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3817 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 3818 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3819 | if (ndlp->nlp_state != NLP_STE_NPR_NODE) |
| 3820 | continue; |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3821 | if (ndlp->nlp_type & NLP_FABRIC) { |
| 3822 | /* |
| 3823 | * Clean up old Fabric, Nameserver and |
| 3824 | * other NLP_FABRIC logins |
| 3825 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3826 | lpfc_drop_node(vport, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3827 | |
Jamie Wellnitz | 2fe165b | 2006-02-28 19:25:31 -0500 | [diff] [blame] | 3828 | } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) { |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3829 | /* Fail outstanding I/O now since this |
| 3830 | * device is marked for PLOGI |
| 3831 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3832 | lpfc_unreg_rpi(vport, ndlp); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3833 | } |
| 3834 | } |
| 3835 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3836 | lpfc_initial_flogi(vport); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3837 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3838 | } |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3839 | /* Discovery not needed, |
| 3840 | * move the nodes to their original state. |
| 3841 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3842 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3843 | nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3844 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 3845 | continue; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 3846 | if (ndlp->nlp_state != NLP_STE_NPR_NODE) |
| 3847 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3848 | |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3849 | switch (ndlp->nlp_prev_state) { |
| 3850 | case NLP_STE_UNMAPPED_NODE: |
| 3851 | ndlp->nlp_prev_state = NLP_STE_NPR_NODE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3852 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3853 | NLP_STE_UNMAPPED_NODE); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3854 | break; |
| 3855 | |
| 3856 | case NLP_STE_MAPPED_NODE: |
| 3857 | ndlp->nlp_prev_state = NLP_STE_NPR_NODE; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3858 | lpfc_nlp_set_state(vport, ndlp, |
James Smart | de0c5b3 | 2007-04-25 09:52:27 -0400 | [diff] [blame] | 3859 | NLP_STE_MAPPED_NODE); |
Jamie Wellnitz | 5024ab1 | 2006-02-28 19:25:28 -0500 | [diff] [blame] | 3860 | break; |
| 3861 | |
| 3862 | default: |
| 3863 | break; |
| 3864 | } |
| 3865 | } |
| 3866 | |
| 3867 | /* Start discovery - this should just do CLEAR_LA */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3868 | lpfc_disc_start(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3869 | } |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 3870 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3871 | } |
| 3872 | |
| 3873 | void |
| 3874 | lpfc_els_timeout(unsigned long ptr) |
| 3875 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3876 | struct lpfc_vport *vport = (struct lpfc_vport *) ptr; |
| 3877 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3878 | unsigned long iflag; |
| 3879 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3880 | spin_lock_irqsave(&vport->work_port_lock, iflag); |
| 3881 | if ((vport->work_port_events & WORKER_ELS_TMO) == 0) { |
| 3882 | vport->work_port_events |= WORKER_ELS_TMO; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3883 | spin_unlock_irqrestore(&vport->work_port_lock, iflag); |
| 3884 | |
| 3885 | spin_lock_irqsave(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3886 | if (phba->work_wait) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3887 | lpfc_worker_wake_up(phba); |
| 3888 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3889 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3890 | else |
| 3891 | spin_unlock_irqrestore(&vport->work_port_lock, iflag); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3892 | return; |
| 3893 | } |
| 3894 | |
| 3895 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3896 | lpfc_els_timeout_handler(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3897 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3898 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3899 | struct lpfc_sli_ring *pring; |
| 3900 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 3901 | IOCB_t *cmd = NULL; |
| 3902 | struct lpfc_dmabuf *pcmd; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3903 | uint32_t els_command = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3904 | uint32_t timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3905 | uint32_t remote_ID = 0xffffffff; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3906 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3907 | /* If the timer is already canceled do nothing */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3908 | if ((vport->work_port_events & WORKER_ELS_TMO) == 0) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3909 | return; |
| 3910 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3911 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3912 | timeout = (uint32_t)(phba->fc_ratov << 1); |
| 3913 | |
| 3914 | pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3915 | |
| 3916 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| 3917 | cmd = &piocb->iocb; |
| 3918 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3919 | if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 || |
| 3920 | piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || |
| 3921 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3922 | continue; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3923 | |
| 3924 | if (piocb->vport != vport) |
| 3925 | continue; |
| 3926 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3927 | pcmd = (struct lpfc_dmabuf *) piocb->context2; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3928 | if (pcmd) |
| 3929 | els_command = *(uint32_t *) (pcmd->virt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3930 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3931 | if (els_command == ELS_CMD_FARP || |
| 3932 | els_command == ELS_CMD_FARPR || |
| 3933 | els_command == ELS_CMD_FDISC) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3934 | continue; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3935 | |
| 3936 | if (vport != piocb->vport) |
| 3937 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3938 | |
| 3939 | if (piocb->drvrTimeout > 0) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3940 | if (piocb->drvrTimeout >= timeout) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3941 | piocb->drvrTimeout -= timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3942 | else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3943 | piocb->drvrTimeout = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3944 | continue; |
| 3945 | } |
| 3946 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3947 | remote_ID = 0xffffffff; |
| 3948 | if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3949 | remote_ID = cmd->un.elsreq64.remoteID; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3950 | else { |
| 3951 | struct lpfc_nodelist *ndlp; |
| 3952 | ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame^] | 3953 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3954 | remote_ID = ndlp->nlp_DID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3955 | } |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3956 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 3957 | "0127 ELS timeout Data: x%x x%x x%x " |
| 3958 | "x%x\n", els_command, |
| 3959 | remote_ID, cmd->ulpCommand, cmd->ulpIoTag); |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 3960 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3961 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3962 | spin_unlock_irq(&phba->hbalock); |
James Smart | 5a0e326 | 2006-07-06 15:49:16 -0400 | [diff] [blame] | 3963 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3964 | if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt) |
| 3965 | mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3966 | } |
| 3967 | |
| 3968 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3969 | lpfc_els_flush_cmd(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3970 | { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3971 | LIST_HEAD(completions); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3972 | struct lpfc_hba *phba = vport->phba; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3973 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3974 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 3975 | IOCB_t *cmd = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3976 | |
| 3977 | lpfc_fabric_abort_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3978 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3979 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3980 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 3981 | cmd = &piocb->iocb; |
| 3982 | |
| 3983 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 3984 | continue; |
| 3985 | } |
| 3986 | |
| 3987 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 3988 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 3989 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 3990 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 3991 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3992 | continue; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3993 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3994 | if (piocb->vport != vport) |
| 3995 | continue; |
| 3996 | |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 3997 | list_move_tail(&piocb->list, &completions); |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 3998 | pring->txq_cnt--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3999 | } |
| 4000 | |
| 4001 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4002 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) { |
| 4003 | continue; |
| 4004 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4005 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4006 | if (piocb->vport != vport) |
| 4007 | continue; |
| 4008 | |
James Smart | 0795107 | 2007-04-25 09:51:38 -0400 | [diff] [blame] | 4009 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4010 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4011 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4012 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4013 | while (!list_empty(&completions)) { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4014 | piocb = list_get_first(&completions, struct lpfc_iocbq, list); |
| 4015 | cmd = &piocb->iocb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4016 | list_del_init(&piocb->list); |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4017 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4018 | if (!piocb->iocb_cmpl) |
| 4019 | lpfc_sli_release_iocbq(phba, piocb); |
| 4020 | else { |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4021 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 4022 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 4023 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4024 | } |
James Smart | 2534ba7 | 2007-04-25 09:52:20 -0400 | [diff] [blame] | 4025 | } |
| 4026 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4027 | return; |
| 4028 | } |
| 4029 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 4030 | void |
| 4031 | lpfc_els_flush_all_cmd(struct lpfc_hba *phba) |
| 4032 | { |
| 4033 | LIST_HEAD(completions); |
| 4034 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 4035 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 4036 | IOCB_t *cmd = NULL; |
| 4037 | |
| 4038 | lpfc_fabric_abort_hba(phba); |
| 4039 | spin_lock_irq(&phba->hbalock); |
| 4040 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { |
| 4041 | cmd = &piocb->iocb; |
| 4042 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 4043 | continue; |
| 4044 | /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ |
| 4045 | if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN || |
| 4046 | cmd->ulpCommand == CMD_QUE_RING_BUF64_CN || |
| 4047 | cmd->ulpCommand == CMD_CLOSE_XRI_CN || |
| 4048 | cmd->ulpCommand == CMD_ABORT_XRI_CN) |
| 4049 | continue; |
| 4050 | list_move_tail(&piocb->list, &completions); |
| 4051 | pring->txq_cnt--; |
| 4052 | } |
| 4053 | list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { |
| 4054 | if (piocb->iocb_flag & LPFC_IO_LIBDFC) |
| 4055 | continue; |
| 4056 | lpfc_sli_issue_abort_iotag(phba, pring, piocb); |
| 4057 | } |
| 4058 | spin_unlock_irq(&phba->hbalock); |
| 4059 | while (!list_empty(&completions)) { |
| 4060 | piocb = list_get_first(&completions, struct lpfc_iocbq, list); |
| 4061 | cmd = &piocb->iocb; |
| 4062 | list_del_init(&piocb->list); |
| 4063 | if (!piocb->iocb_cmpl) |
| 4064 | lpfc_sli_release_iocbq(phba, piocb); |
| 4065 | else { |
| 4066 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 4067 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 4068 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 4069 | } |
| 4070 | } |
| 4071 | return; |
| 4072 | } |
| 4073 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4074 | static void |
| 4075 | lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4076 | struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4077 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4078 | struct Scsi_Host *shost; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4079 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4080 | struct ls_rjt stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4081 | uint32_t *payload; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4082 | uint32_t cmd, did, newnode, rjt_err = 0; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4083 | IOCB_t *icmd = &elsiocb->iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4084 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4085 | if (!vport || !(elsiocb->context2)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4086 | goto dropit; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4087 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4088 | newnode = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4089 | payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt; |
| 4090 | cmd = *payload; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4091 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0) |
| 4092 | lpfc_post_buffer(phba, pring, 1, 1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4093 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4094 | did = icmd->un.rcvels.remoteID; |
| 4095 | if (icmd->ulpStatus) { |
| 4096 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4097 | "RCV Unsol ELS: status:x%x/x%x did:x%x", |
| 4098 | icmd->ulpStatus, icmd->un.ulpWord[4], did); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4099 | goto dropit; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4100 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4101 | |
| 4102 | /* Check to see if link went down during discovery */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4103 | if (lpfc_els_chk_latt(vport)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4104 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4105 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4106 | /* Ignore traffic recevied during vport shutdown. */ |
| 4107 | if (vport->load_flag & FC_UNLOADING) |
| 4108 | goto dropit; |
| 4109 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4110 | ndlp = lpfc_findnode_did(vport, did); |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4111 | if (!ndlp) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4112 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
Jamie Wellnitz | c9f8735b | 2006-02-28 19:25:23 -0500 | [diff] [blame] | 4113 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4114 | if (!ndlp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4115 | goto dropit; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4116 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4117 | lpfc_nlp_init(vport, ndlp, did); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4118 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4119 | newnode = 1; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4120 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4121 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame^] | 4122 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 4123 | ndlp = lpfc_enable_node(vport, ndlp, |
| 4124 | NLP_STE_UNUSED_NODE); |
| 4125 | if (!ndlp) |
| 4126 | goto dropit; |
| 4127 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 4128 | newnode = 1; |
| 4129 | if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) |
| 4130 | ndlp->nlp_type |= NLP_FABRIC; |
| 4131 | } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
| 4132 | /* This is similar to the new node path */ |
| 4133 | ndlp = lpfc_nlp_get(ndlp); |
| 4134 | if (!ndlp) |
| 4135 | goto dropit; |
| 4136 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
| 4137 | newnode = 1; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4138 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4139 | |
| 4140 | phba->fc_stat.elsRcvFrame++; |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4141 | if (elsiocb->context1) |
| 4142 | lpfc_nlp_put(elsiocb->context1); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4143 | |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4144 | elsiocb->context1 = lpfc_nlp_get(ndlp); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4145 | elsiocb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4146 | |
| 4147 | if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) { |
| 4148 | cmd &= ELS_CMD_MASK; |
| 4149 | } |
| 4150 | /* ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4151 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4152 | "0112 ELS command x%x received from NPORT x%x " |
| 4153 | "Data: x%x\n", cmd, did, vport->port_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4154 | switch (cmd) { |
| 4155 | case ELS_CMD_PLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4156 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4157 | "RCV PLOGI: did:x%x/ste:x%x flg:x%x", |
| 4158 | did, vport->port_state, ndlp->nlp_flag); |
| 4159 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4160 | phba->fc_stat.elsRcvPLOGI++; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4161 | ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp); |
| 4162 | |
| 4163 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 4164 | if (!(phba->pport->fc_flag & FC_PT2PT) || |
| 4165 | (phba->pport->fc_flag & FC_PT2PT_PLOGI)) { |
| 4166 | rjt_err = LSRJT_UNABLE_TPC; |
| 4167 | break; |
| 4168 | } |
| 4169 | /* We get here, and drop thru, if we are PT2PT with |
| 4170 | * another NPort and the other side has initiated |
| 4171 | * the PLOGI before responding to our FLOGI. |
| 4172 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4173 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4174 | |
| 4175 | shost = lpfc_shost_from_vport(vport); |
| 4176 | spin_lock_irq(shost->host_lock); |
| 4177 | ndlp->nlp_flag &= ~NLP_TARGET_REMOVE; |
| 4178 | spin_unlock_irq(shost->host_lock); |
| 4179 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4180 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 4181 | NLP_EVT_RCV_PLOGI); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4182 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4183 | break; |
| 4184 | case ELS_CMD_FLOGI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4185 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4186 | "RCV FLOGI: did:x%x/ste:x%x flg:x%x", |
| 4187 | did, vport->port_state, ndlp->nlp_flag); |
| 4188 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4189 | phba->fc_stat.elsRcvFLOGI++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4190 | lpfc_els_rcv_flogi(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4191 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4192 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4193 | break; |
| 4194 | case ELS_CMD_LOGO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4195 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4196 | "RCV LOGO: did:x%x/ste:x%x flg:x%x", |
| 4197 | did, vport->port_state, ndlp->nlp_flag); |
| 4198 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4199 | phba->fc_stat.elsRcvLOGO++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4200 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4201 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4202 | break; |
| 4203 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4204 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4205 | break; |
| 4206 | case ELS_CMD_PRLO: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4207 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4208 | "RCV PRLO: did:x%x/ste:x%x flg:x%x", |
| 4209 | did, vport->port_state, ndlp->nlp_flag); |
| 4210 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4211 | phba->fc_stat.elsRcvPRLO++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4212 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4213 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4214 | break; |
| 4215 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4216 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4217 | break; |
| 4218 | case ELS_CMD_RSCN: |
| 4219 | phba->fc_stat.elsRcvRSCN++; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4220 | lpfc_els_rcv_rscn(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4221 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4222 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4223 | break; |
| 4224 | case ELS_CMD_ADISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4225 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4226 | "RCV ADISC: did:x%x/ste:x%x flg:x%x", |
| 4227 | did, vport->port_state, ndlp->nlp_flag); |
| 4228 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4229 | phba->fc_stat.elsRcvADISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4230 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4231 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4232 | break; |
| 4233 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4234 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 4235 | NLP_EVT_RCV_ADISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4236 | break; |
| 4237 | case ELS_CMD_PDISC: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4238 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4239 | "RCV PDISC: did:x%x/ste:x%x flg:x%x", |
| 4240 | did, vport->port_state, ndlp->nlp_flag); |
| 4241 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4242 | phba->fc_stat.elsRcvPDISC++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4243 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4244 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4245 | break; |
| 4246 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4247 | lpfc_disc_state_machine(vport, ndlp, elsiocb, |
| 4248 | NLP_EVT_RCV_PDISC); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4249 | break; |
| 4250 | case ELS_CMD_FARPR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4251 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4252 | "RCV FARPR: did:x%x/ste:x%x flg:x%x", |
| 4253 | did, vport->port_state, ndlp->nlp_flag); |
| 4254 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4255 | phba->fc_stat.elsRcvFARPR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4256 | lpfc_els_rcv_farpr(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4257 | break; |
| 4258 | case ELS_CMD_FARP: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4259 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4260 | "RCV FARP: did:x%x/ste:x%x flg:x%x", |
| 4261 | did, vport->port_state, ndlp->nlp_flag); |
| 4262 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4263 | phba->fc_stat.elsRcvFARP++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4264 | lpfc_els_rcv_farp(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4265 | break; |
| 4266 | case ELS_CMD_FAN: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4267 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4268 | "RCV FAN: did:x%x/ste:x%x flg:x%x", |
| 4269 | did, vport->port_state, ndlp->nlp_flag); |
| 4270 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4271 | phba->fc_stat.elsRcvFAN++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4272 | lpfc_els_rcv_fan(vport, elsiocb, ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4273 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4274 | case ELS_CMD_PRLI: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4275 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4276 | "RCV PRLI: did:x%x/ste:x%x flg:x%x", |
| 4277 | did, vport->port_state, ndlp->nlp_flag); |
| 4278 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4279 | phba->fc_stat.elsRcvPRLI++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4280 | if (vport->port_state < LPFC_DISC_AUTH) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4281 | rjt_err = LSRJT_UNABLE_TPC; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4282 | break; |
| 4283 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4284 | lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4285 | break; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4286 | case ELS_CMD_LIRR: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4287 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4288 | "RCV LIRR: did:x%x/ste:x%x flg:x%x", |
| 4289 | did, vport->port_state, ndlp->nlp_flag); |
| 4290 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4291 | phba->fc_stat.elsRcvLIRR++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4292 | lpfc_els_rcv_lirr(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4293 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4294 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4295 | break; |
| 4296 | case ELS_CMD_RPS: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4297 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4298 | "RCV RPS: did:x%x/ste:x%x flg:x%x", |
| 4299 | did, vport->port_state, ndlp->nlp_flag); |
| 4300 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4301 | phba->fc_stat.elsRcvRPS++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4302 | lpfc_els_rcv_rps(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4303 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4304 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4305 | break; |
| 4306 | case ELS_CMD_RPL: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4307 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4308 | "RCV RPL: did:x%x/ste:x%x flg:x%x", |
| 4309 | did, vport->port_state, ndlp->nlp_flag); |
| 4310 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4311 | phba->fc_stat.elsRcvRPL++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4312 | lpfc_els_rcv_rpl(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4313 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4314 | lpfc_nlp_put(ndlp); |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 4315 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4316 | case ELS_CMD_RNID: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4317 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4318 | "RCV RNID: did:x%x/ste:x%x flg:x%x", |
| 4319 | did, vport->port_state, ndlp->nlp_flag); |
| 4320 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4321 | phba->fc_stat.elsRcvRNID++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4322 | lpfc_els_rcv_rnid(vport, elsiocb, ndlp); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4323 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4324 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4325 | break; |
| 4326 | default: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4327 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL, |
| 4328 | "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x", |
| 4329 | cmd, did, vport->port_state); |
| 4330 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4331 | /* Unsupported ELS command, reject */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4332 | rjt_err = LSRJT_INVALID_CMD; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4333 | |
| 4334 | /* Unknown ELS command <elsCmd> received from NPORT <did> */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4335 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4336 | "0115 Unknown ELS command x%x " |
| 4337 | "received from NPORT x%x\n", cmd, did); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 4338 | if (newnode) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4339 | lpfc_nlp_put(ndlp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4340 | break; |
| 4341 | } |
| 4342 | |
| 4343 | /* check if need to LS_RJT received ELS cmd */ |
| 4344 | if (rjt_err) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4345 | memset(&stat, 0, sizeof(stat)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4346 | stat.un.b.lsRjtRsnCode = rjt_err; |
James.Smart@Emulex.Com | 1f679ca | 2005-06-25 10:34:27 -0400 | [diff] [blame] | 4347 | stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4348 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp, |
| 4349 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4350 | } |
| 4351 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4352 | return; |
| 4353 | |
| 4354 | dropit: |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4355 | if (vport && !(vport->load_flag & FC_UNLOADING)) |
| 4356 | lpfc_printf_log(phba, KERN_ERR, LOG_ELS, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4357 | "(%d):0111 Dropping received ELS cmd " |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4358 | "Data: x%x x%x x%x\n", |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 4359 | vport->vpi, icmd->ulpStatus, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4360 | icmd->un.ulpWord[4], icmd->ulpTimeout); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4361 | phba->fc_stat.elsRcvDrop++; |
| 4362 | } |
| 4363 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4364 | static struct lpfc_vport * |
| 4365 | lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi) |
| 4366 | { |
| 4367 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 4368 | unsigned long flags; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4369 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 4370 | spin_lock_irqsave(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4371 | list_for_each_entry(vport, &phba->port_list, listentry) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 4372 | if (vport->vpi == vpi) { |
| 4373 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4374 | return vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 4375 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4376 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 4377 | spin_unlock_irqrestore(&phba->hbalock, flags); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4378 | return NULL; |
| 4379 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4380 | |
| 4381 | void |
| 4382 | lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
| 4383 | struct lpfc_iocbq *elsiocb) |
| 4384 | { |
| 4385 | struct lpfc_vport *vport = phba->pport; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4386 | IOCB_t *icmd = &elsiocb->iocb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4387 | dma_addr_t paddr; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4388 | struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2; |
| 4389 | struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4390 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4391 | elsiocb->context2 = NULL; |
| 4392 | elsiocb->context3 = NULL; |
| 4393 | |
| 4394 | if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) { |
| 4395 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); |
| 4396 | } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT && |
| 4397 | (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4398 | phba->fc_stat.NoRcvBuf++; |
| 4399 | /* Not enough posted buffers; Try posting more buffers */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4400 | if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4401 | lpfc_post_buffer(phba, pring, 0, 1); |
| 4402 | return; |
| 4403 | } |
| 4404 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4405 | if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) && |
| 4406 | (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX || |
| 4407 | icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { |
| 4408 | if (icmd->unsli3.rcvsli3.vpi == 0xffff) |
| 4409 | vport = phba->pport; |
| 4410 | else { |
| 4411 | uint16_t vpi = icmd->unsli3.rcvsli3.vpi; |
| 4412 | vport = lpfc_find_vport_by_vpid(phba, vpi); |
| 4413 | } |
| 4414 | } |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4415 | /* If there are no BDEs associated |
| 4416 | * with this IOCB, there is nothing to do. |
| 4417 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4418 | if (icmd->ulpBdeCount == 0) |
| 4419 | return; |
| 4420 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4421 | /* type of ELS cmd is first 32bit word |
| 4422 | * in packet |
| 4423 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4424 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4425 | elsiocb->context2 = bdeBuf1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4426 | } else { |
| 4427 | paddr = getPaddr(icmd->un.cont64[0].addrHigh, |
| 4428 | icmd->un.cont64[0].addrLow); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4429 | elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring, |
| 4430 | paddr); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4431 | } |
| 4432 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4433 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
| 4434 | /* |
| 4435 | * The different unsolicited event handlers would tell us |
| 4436 | * if they are done with "mp" by setting context2 to NULL. |
| 4437 | */ |
James Smart | 329f9bc | 2007-04-25 09:53:01 -0400 | [diff] [blame] | 4438 | lpfc_nlp_put(elsiocb->context1); |
| 4439 | elsiocb->context1 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4440 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4441 | lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2); |
| 4442 | elsiocb->context2 = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4443 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4444 | |
| 4445 | /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4446 | if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) && |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4447 | icmd->ulpBdeCount == 2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4448 | elsiocb->context2 = bdeBuf2; |
| 4449 | lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4450 | /* free mp if we are done with it */ |
| 4451 | if (elsiocb->context2) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4452 | lpfc_in_buf_free(phba, elsiocb->context2); |
| 4453 | elsiocb->context2 = NULL; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 4454 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4455 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4456 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4457 | |
| 4458 | void |
| 4459 | lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 4460 | { |
| 4461 | struct lpfc_nodelist *ndlp, *ndlp_fdmi; |
| 4462 | |
| 4463 | ndlp = lpfc_findnode_did(vport, NameServer_DID); |
| 4464 | if (!ndlp) { |
| 4465 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); |
| 4466 | if (!ndlp) { |
| 4467 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 4468 | lpfc_disc_start(vport); |
| 4469 | return; |
| 4470 | } |
| 4471 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4472 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4473 | "0251 NameServer login: no memory\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4474 | return; |
| 4475 | } |
| 4476 | lpfc_nlp_init(vport, ndlp, NameServer_DID); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4477 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 4478 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 4479 | if (!ndlp) { |
| 4480 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 4481 | lpfc_disc_start(vport); |
| 4482 | return; |
| 4483 | } |
| 4484 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 4485 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4486 | "0348 NameServer login: node freed\n"); |
| 4487 | return; |
| 4488 | } |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4489 | } |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame^] | 4490 | ndlp->nlp_type |= NLP_FABRIC; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4491 | |
| 4492 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
| 4493 | |
| 4494 | if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) { |
| 4495 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4496 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4497 | "0252 Cannot issue NameServer login\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4498 | return; |
| 4499 | } |
| 4500 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4501 | if (vport->cfg_fdmi_on) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4502 | ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool, |
| 4503 | GFP_KERNEL); |
| 4504 | if (ndlp_fdmi) { |
| 4505 | lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID); |
| 4506 | ndlp_fdmi->nlp_type |= NLP_FABRIC; |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame^] | 4507 | lpfc_nlp_set_state(vport, ndlp_fdmi, |
| 4508 | NLP_STE_PLOGI_ISSUE); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4509 | lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, |
| 4510 | 0); |
| 4511 | } |
| 4512 | } |
| 4513 | return; |
| 4514 | } |
| 4515 | |
| 4516 | static void |
| 4517 | lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 4518 | { |
| 4519 | struct lpfc_vport *vport = pmb->vport; |
| 4520 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4521 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; |
| 4522 | MAILBOX_t *mb = &pmb->mb; |
| 4523 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4524 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4525 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4526 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4527 | |
| 4528 | if (mb->mbxStatus) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4529 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 4530 | "0915 Register VPI failed: 0x%x\n", |
| 4531 | mb->mbxStatus); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4532 | |
| 4533 | switch (mb->mbxStatus) { |
| 4534 | case 0x11: /* unsupported feature */ |
| 4535 | case 0x9603: /* max_vpi exceeded */ |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4536 | case 0x9602: /* Link event since CLEAR_LA */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4537 | /* giving up on vport registration */ |
| 4538 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 4539 | spin_lock_irq(shost->host_lock); |
| 4540 | vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); |
| 4541 | spin_unlock_irq(shost->host_lock); |
| 4542 | lpfc_can_disctmo(vport); |
| 4543 | break; |
| 4544 | default: |
| 4545 | /* Try to recover from this error */ |
| 4546 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4547 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4548 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4549 | spin_unlock_irq(shost->host_lock); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4550 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 4551 | lpfc_initial_flogi(vport); |
| 4552 | else |
| 4553 | lpfc_initial_fdisc(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4554 | break; |
| 4555 | } |
| 4556 | |
| 4557 | } else { |
| 4558 | if (vport == phba->pport) |
| 4559 | lpfc_issue_fabric_reglogin(vport); |
| 4560 | else |
| 4561 | lpfc_do_scr_ns_plogi(phba, vport); |
| 4562 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4563 | |
| 4564 | /* Now, we decrement the ndlp reference count held for this |
| 4565 | * callback function |
| 4566 | */ |
| 4567 | lpfc_nlp_put(ndlp); |
| 4568 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4569 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4570 | return; |
| 4571 | } |
| 4572 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 4573 | static void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4574 | lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport, |
| 4575 | struct lpfc_nodelist *ndlp) |
| 4576 | { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4577 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4578 | LPFC_MBOXQ_t *mbox; |
| 4579 | |
| 4580 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4581 | if (mbox) { |
| 4582 | lpfc_reg_vpi(phba, vport->vpi, vport->fc_myDID, mbox); |
| 4583 | mbox->vport = vport; |
| 4584 | mbox->context2 = lpfc_nlp_get(ndlp); |
| 4585 | mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 4586 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4587 | == MBX_NOT_FINISHED) { |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4588 | /* mailbox command not success, decrement ndlp |
| 4589 | * reference count for this command |
| 4590 | */ |
| 4591 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4592 | mempool_free(mbox, phba->mbox_mem_pool); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4593 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4594 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 4595 | "0253 Register VPI: Can't send mbox\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4596 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4597 | } |
| 4598 | } else { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4599 | lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, |
| 4600 | "0254 Register VPI: no memory\n"); |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4601 | goto mbox_err_exit; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4602 | } |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4603 | return; |
| 4604 | |
| 4605 | mbox_err_exit: |
| 4606 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
| 4607 | spin_lock_irq(shost->host_lock); |
| 4608 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; |
| 4609 | spin_unlock_irq(shost->host_lock); |
| 4610 | return; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4611 | } |
| 4612 | |
| 4613 | static void |
| 4614 | lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 4615 | struct lpfc_iocbq *rspiocb) |
| 4616 | { |
| 4617 | struct lpfc_vport *vport = cmdiocb->vport; |
| 4618 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4619 | struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1; |
| 4620 | struct lpfc_nodelist *np; |
| 4621 | struct lpfc_nodelist *next_np; |
| 4622 | IOCB_t *irsp = &rspiocb->iocb; |
| 4623 | struct lpfc_iocbq *piocb; |
| 4624 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4625 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
| 4626 | "0123 FDISC completes. x%x/x%x prevDID: x%x\n", |
| 4627 | irsp->ulpStatus, irsp->un.ulpWord[4], |
| 4628 | vport->fc_prevDID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4629 | /* Since all FDISCs are being single threaded, we |
| 4630 | * must reset the discovery timer for ALL vports |
| 4631 | * waiting to send FDISC when one completes. |
| 4632 | */ |
| 4633 | list_for_each_entry(piocb, &phba->fabric_iocb_list, list) { |
| 4634 | lpfc_set_disctmo(piocb->vport); |
| 4635 | } |
| 4636 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4637 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 4638 | "FDISC cmpl: status:x%x/x%x prevdid:x%x", |
| 4639 | irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID); |
| 4640 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4641 | if (irsp->ulpStatus) { |
| 4642 | /* Check for retry */ |
| 4643 | if (lpfc_els_retry(phba, cmdiocb, rspiocb)) |
| 4644 | goto out; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4645 | /* FDISC failed */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4646 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4647 | "0124 FDISC failed. (%d/%d)\n", |
| 4648 | irsp->ulpStatus, irsp->un.ulpWord[4]); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4649 | if (vport->fc_vport->vport_state == FC_VPORT_INITIALIZING) |
| 4650 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4651 | lpfc_nlp_put(ndlp); |
| 4652 | /* giving up on FDISC. Cancel discovery timer */ |
| 4653 | lpfc_can_disctmo(vport); |
| 4654 | } else { |
| 4655 | spin_lock_irq(shost->host_lock); |
| 4656 | vport->fc_flag |= FC_FABRIC; |
| 4657 | if (vport->phba->fc_topology == TOPOLOGY_LOOP) |
| 4658 | vport->fc_flag |= FC_PUBLIC_LOOP; |
| 4659 | spin_unlock_irq(shost->host_lock); |
| 4660 | |
| 4661 | vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; |
| 4662 | lpfc_vport_set_state(vport, FC_VPORT_ACTIVE); |
| 4663 | if ((vport->fc_prevDID != vport->fc_myDID) && |
| 4664 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) { |
| 4665 | /* If our NportID changed, we need to ensure all |
| 4666 | * remaining NPORTs get unreg_login'ed so we can |
| 4667 | * issue unreg_vpi. |
| 4668 | */ |
| 4669 | list_for_each_entry_safe(np, next_np, |
| 4670 | &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4671 | if (!NLP_CHK_NODE_ACT(ndlp) || |
| 4672 | (np->nlp_state != NLP_STE_NPR_NODE) || |
| 4673 | !(np->nlp_flag & NLP_NPR_ADISC)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4674 | continue; |
| 4675 | spin_lock_irq(shost->host_lock); |
| 4676 | np->nlp_flag &= ~NLP_NPR_ADISC; |
| 4677 | spin_unlock_irq(shost->host_lock); |
| 4678 | lpfc_unreg_rpi(vport, np); |
| 4679 | } |
| 4680 | lpfc_mbx_unreg_vpi(vport); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4681 | spin_lock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4682 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 4683 | spin_unlock_irq(shost->host_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4684 | } |
| 4685 | |
| 4686 | if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) |
| 4687 | lpfc_register_new_vport(phba, vport, ndlp); |
| 4688 | else |
| 4689 | lpfc_do_scr_ns_plogi(phba, vport); |
| 4690 | |
James Smart | fa4066b | 2008-01-11 01:53:27 -0500 | [diff] [blame] | 4691 | /* Unconditionaly kick off releasing fabric node for vports */ |
| 4692 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4693 | } |
| 4694 | |
| 4695 | out: |
| 4696 | lpfc_els_free_iocb(phba, cmdiocb); |
| 4697 | } |
| 4698 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 4699 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4700 | lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
| 4701 | uint8_t retry) |
| 4702 | { |
| 4703 | struct lpfc_hba *phba = vport->phba; |
| 4704 | IOCB_t *icmd; |
| 4705 | struct lpfc_iocbq *elsiocb; |
| 4706 | struct serv_parm *sp; |
| 4707 | uint8_t *pcmd; |
| 4708 | uint16_t cmdsize; |
| 4709 | int did = ndlp->nlp_DID; |
| 4710 | int rc; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4711 | |
| 4712 | cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); |
| 4713 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did, |
| 4714 | ELS_CMD_FDISC); |
| 4715 | if (!elsiocb) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4716 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4717 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4718 | "0255 Issue FDISC: no IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4719 | return 1; |
| 4720 | } |
| 4721 | |
| 4722 | icmd = &elsiocb->iocb; |
| 4723 | icmd->un.elsreq64.myID = 0; |
| 4724 | icmd->un.elsreq64.fl = 1; |
| 4725 | |
| 4726 | /* For FDISC, Let FDISC rsp set the NPortID for this VPI */ |
| 4727 | icmd->ulpCt_h = 1; |
| 4728 | icmd->ulpCt_l = 0; |
| 4729 | |
| 4730 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4731 | *((uint32_t *) (pcmd)) = ELS_CMD_FDISC; |
| 4732 | pcmd += sizeof(uint32_t); /* CSP Word 1 */ |
| 4733 | memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm)); |
| 4734 | sp = (struct serv_parm *) pcmd; |
| 4735 | /* Setup CSPs accordingly for Fabric */ |
| 4736 | sp->cmn.e_d_tov = 0; |
| 4737 | sp->cmn.w2.r_a_tov = 0; |
| 4738 | sp->cls1.classValid = 0; |
| 4739 | sp->cls2.seqDelivery = 1; |
| 4740 | sp->cls3.seqDelivery = 1; |
| 4741 | |
| 4742 | pcmd += sizeof(uint32_t); /* CSP Word 2 */ |
| 4743 | pcmd += sizeof(uint32_t); /* CSP Word 3 */ |
| 4744 | pcmd += sizeof(uint32_t); /* CSP Word 4 */ |
| 4745 | pcmd += sizeof(uint32_t); /* Port Name */ |
| 4746 | memcpy(pcmd, &vport->fc_portname, 8); |
| 4747 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 4748 | pcmd += sizeof(uint32_t); /* Node Name */ |
| 4749 | memcpy(pcmd, &vport->fc_nodename, 8); |
| 4750 | |
| 4751 | lpfc_set_disctmo(vport); |
| 4752 | |
| 4753 | phba->fc_stat.elsXmitFDISC++; |
| 4754 | elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc; |
| 4755 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4756 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 4757 | "Issue FDISC: did:x%x", |
| 4758 | did, 0, 0); |
| 4759 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4760 | rc = lpfc_issue_fabric_iocb(phba, elsiocb); |
| 4761 | if (rc == IOCB_ERROR) { |
| 4762 | lpfc_els_free_iocb(phba, elsiocb); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4763 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4764 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
| 4765 | "0256 Issue FDISC: Cannot send IOCB\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4766 | return 1; |
| 4767 | } |
| 4768 | lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING); |
| 4769 | vport->port_state = LPFC_FDISC; |
| 4770 | return 0; |
| 4771 | } |
| 4772 | |
| 4773 | static void |
| 4774 | lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 4775 | struct lpfc_iocbq *rspiocb) |
| 4776 | { |
| 4777 | struct lpfc_vport *vport = cmdiocb->vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4778 | IOCB_t *irsp; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4779 | struct lpfc_nodelist *ndlp; |
| 4780 | ndlp = (struct lpfc_nodelist *)cmdiocb->context1; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4781 | |
| 4782 | irsp = &rspiocb->iocb; |
| 4783 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 4784 | "LOGO npiv cmpl: status:x%x/x%x did:x%x", |
| 4785 | irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4786 | |
| 4787 | lpfc_els_free_iocb(phba, cmdiocb); |
| 4788 | vport->unreg_vpi_cmpl = VPORT_ERROR; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4789 | |
| 4790 | /* Trigger the release of the ndlp after logo */ |
| 4791 | lpfc_nlp_put(ndlp); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4792 | } |
| 4793 | |
| 4794 | int |
| 4795 | lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
| 4796 | { |
| 4797 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4798 | struct lpfc_hba *phba = vport->phba; |
| 4799 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 4800 | IOCB_t *icmd; |
| 4801 | struct lpfc_iocbq *elsiocb; |
| 4802 | uint8_t *pcmd; |
| 4803 | uint16_t cmdsize; |
| 4804 | |
| 4805 | cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name); |
| 4806 | elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID, |
| 4807 | ELS_CMD_LOGO); |
| 4808 | if (!elsiocb) |
| 4809 | return 1; |
| 4810 | |
| 4811 | icmd = &elsiocb->iocb; |
| 4812 | pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); |
| 4813 | *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; |
| 4814 | pcmd += sizeof(uint32_t); |
| 4815 | |
| 4816 | /* Fill in LOGO payload */ |
| 4817 | *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); |
| 4818 | pcmd += sizeof(uint32_t); |
| 4819 | memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 4820 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4821 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, |
| 4822 | "Issue LOGO npiv did:x%x flg:x%x", |
| 4823 | ndlp->nlp_DID, ndlp->nlp_flag, 0); |
| 4824 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4825 | elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo; |
| 4826 | spin_lock_irq(shost->host_lock); |
| 4827 | ndlp->nlp_flag |= NLP_LOGO_SND; |
| 4828 | spin_unlock_irq(shost->host_lock); |
| 4829 | if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { |
| 4830 | spin_lock_irq(shost->host_lock); |
| 4831 | ndlp->nlp_flag &= ~NLP_LOGO_SND; |
| 4832 | spin_unlock_irq(shost->host_lock); |
| 4833 | lpfc_els_free_iocb(phba, elsiocb); |
| 4834 | return 1; |
| 4835 | } |
| 4836 | return 0; |
| 4837 | } |
| 4838 | |
| 4839 | void |
| 4840 | lpfc_fabric_block_timeout(unsigned long ptr) |
| 4841 | { |
| 4842 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; |
| 4843 | unsigned long iflags; |
| 4844 | uint32_t tmo_posted; |
| 4845 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); |
| 4846 | tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO; |
| 4847 | if (!tmo_posted) |
| 4848 | phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO; |
| 4849 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); |
| 4850 | |
| 4851 | if (!tmo_posted) { |
| 4852 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 4853 | if (phba->work_wait) |
| 4854 | lpfc_worker_wake_up(phba); |
| 4855 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 4856 | } |
| 4857 | } |
| 4858 | |
| 4859 | static void |
| 4860 | lpfc_resume_fabric_iocbs(struct lpfc_hba *phba) |
| 4861 | { |
| 4862 | struct lpfc_iocbq *iocb; |
| 4863 | unsigned long iflags; |
| 4864 | int ret; |
| 4865 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 4866 | IOCB_t *cmd; |
| 4867 | |
| 4868 | repeat: |
| 4869 | iocb = NULL; |
| 4870 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4871 | /* Post any pending iocb to the SLI layer */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4872 | if (atomic_read(&phba->fabric_iocb_count) == 0) { |
| 4873 | list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb), |
| 4874 | list); |
| 4875 | if (iocb) |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4876 | /* Increment fabric iocb count to hold the position */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4877 | atomic_inc(&phba->fabric_iocb_count); |
| 4878 | } |
| 4879 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 4880 | if (iocb) { |
| 4881 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 4882 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 4883 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 4884 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4885 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 4886 | "Fabric sched1: ste:x%x", |
| 4887 | iocb->vport->port_state, 0, 0); |
| 4888 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4889 | ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0); |
| 4890 | |
| 4891 | if (ret == IOCB_ERROR) { |
| 4892 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 4893 | iocb->fabric_iocb_cmpl = NULL; |
| 4894 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 4895 | cmd = &iocb->iocb; |
| 4896 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 4897 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 4898 | iocb->iocb_cmpl(phba, iocb, iocb); |
| 4899 | |
| 4900 | atomic_dec(&phba->fabric_iocb_count); |
| 4901 | goto repeat; |
| 4902 | } |
| 4903 | } |
| 4904 | |
| 4905 | return; |
| 4906 | } |
| 4907 | |
| 4908 | void |
| 4909 | lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba) |
| 4910 | { |
| 4911 | clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 4912 | |
| 4913 | lpfc_resume_fabric_iocbs(phba); |
| 4914 | return; |
| 4915 | } |
| 4916 | |
| 4917 | static void |
| 4918 | lpfc_block_fabric_iocbs(struct lpfc_hba *phba) |
| 4919 | { |
| 4920 | int blocked; |
| 4921 | |
| 4922 | blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4923 | /* Start a timer to unblock fabric iocbs after 100ms */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4924 | if (!blocked) |
| 4925 | mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 ); |
| 4926 | |
| 4927 | return; |
| 4928 | } |
| 4929 | |
| 4930 | static void |
| 4931 | lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
| 4932 | struct lpfc_iocbq *rspiocb) |
| 4933 | { |
| 4934 | struct ls_rjt stat; |
| 4935 | |
| 4936 | if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC) |
| 4937 | BUG(); |
| 4938 | |
| 4939 | switch (rspiocb->iocb.ulpStatus) { |
| 4940 | case IOSTAT_NPORT_RJT: |
| 4941 | case IOSTAT_FABRIC_RJT: |
| 4942 | if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) { |
| 4943 | lpfc_block_fabric_iocbs(phba); |
| 4944 | } |
| 4945 | break; |
| 4946 | |
| 4947 | case IOSTAT_NPORT_BSY: |
| 4948 | case IOSTAT_FABRIC_BSY: |
| 4949 | lpfc_block_fabric_iocbs(phba); |
| 4950 | break; |
| 4951 | |
| 4952 | case IOSTAT_LS_RJT: |
| 4953 | stat.un.lsRjtError = |
| 4954 | be32_to_cpu(rspiocb->iocb.un.ulpWord[4]); |
| 4955 | if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) || |
| 4956 | (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY)) |
| 4957 | lpfc_block_fabric_iocbs(phba); |
| 4958 | break; |
| 4959 | } |
| 4960 | |
| 4961 | if (atomic_read(&phba->fabric_iocb_count) == 0) |
| 4962 | BUG(); |
| 4963 | |
| 4964 | cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl; |
| 4965 | cmdiocb->fabric_iocb_cmpl = NULL; |
| 4966 | cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 4967 | cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb); |
| 4968 | |
| 4969 | atomic_dec(&phba->fabric_iocb_count); |
| 4970 | if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) { |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4971 | /* Post any pending iocbs to HBA */ |
| 4972 | lpfc_resume_fabric_iocbs(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4973 | } |
| 4974 | } |
| 4975 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 4976 | static int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4977 | lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb) |
| 4978 | { |
| 4979 | unsigned long iflags; |
| 4980 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 4981 | int ready; |
| 4982 | int ret; |
| 4983 | |
| 4984 | if (atomic_read(&phba->fabric_iocb_count) > 1) |
| 4985 | BUG(); |
| 4986 | |
| 4987 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 4988 | ready = atomic_read(&phba->fabric_iocb_count) == 0 && |
| 4989 | !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags); |
| 4990 | |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4991 | if (ready) |
| 4992 | /* Increment fabric iocb count to hold the position */ |
| 4993 | atomic_inc(&phba->fabric_iocb_count); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4994 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 4995 | if (ready) { |
| 4996 | iocb->fabric_iocb_cmpl = iocb->iocb_cmpl; |
| 4997 | iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb; |
| 4998 | iocb->iocb_flag |= LPFC_IO_FABRIC; |
| 4999 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5000 | lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD, |
| 5001 | "Fabric sched2: ste:x%x", |
| 5002 | iocb->vport->port_state, 0, 0); |
| 5003 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5004 | ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0); |
| 5005 | |
| 5006 | if (ret == IOCB_ERROR) { |
| 5007 | iocb->iocb_cmpl = iocb->fabric_iocb_cmpl; |
| 5008 | iocb->fabric_iocb_cmpl = NULL; |
| 5009 | iocb->iocb_flag &= ~LPFC_IO_FABRIC; |
| 5010 | atomic_dec(&phba->fabric_iocb_count); |
| 5011 | } |
| 5012 | } else { |
| 5013 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 5014 | list_add_tail(&iocb->list, &phba->fabric_iocb_list); |
| 5015 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 5016 | ret = IOCB_SUCCESS; |
| 5017 | } |
| 5018 | return ret; |
| 5019 | } |
| 5020 | |
| 5021 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 5022 | static void lpfc_fabric_abort_vport(struct lpfc_vport *vport) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5023 | { |
| 5024 | LIST_HEAD(completions); |
| 5025 | struct lpfc_hba *phba = vport->phba; |
| 5026 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5027 | IOCB_t *cmd; |
| 5028 | |
| 5029 | spin_lock_irq(&phba->hbalock); |
| 5030 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 5031 | list) { |
| 5032 | |
| 5033 | if (piocb->vport != vport) |
| 5034 | continue; |
| 5035 | |
| 5036 | list_move_tail(&piocb->list, &completions); |
| 5037 | } |
| 5038 | spin_unlock_irq(&phba->hbalock); |
| 5039 | |
| 5040 | while (!list_empty(&completions)) { |
| 5041 | piocb = list_get_first(&completions, struct lpfc_iocbq, list); |
| 5042 | list_del_init(&piocb->list); |
| 5043 | |
| 5044 | cmd = &piocb->iocb; |
| 5045 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 5046 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 5047 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 5048 | } |
| 5049 | } |
| 5050 | |
| 5051 | void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp) |
| 5052 | { |
| 5053 | LIST_HEAD(completions); |
| 5054 | struct lpfc_hba *phba = ndlp->vport->phba; |
| 5055 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5056 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
| 5057 | IOCB_t *cmd; |
| 5058 | |
| 5059 | spin_lock_irq(&phba->hbalock); |
| 5060 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 5061 | list) { |
| 5062 | if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) { |
| 5063 | |
| 5064 | list_move_tail(&piocb->list, &completions); |
| 5065 | } |
| 5066 | } |
| 5067 | spin_unlock_irq(&phba->hbalock); |
| 5068 | |
| 5069 | while (!list_empty(&completions)) { |
| 5070 | piocb = list_get_first(&completions, struct lpfc_iocbq, list); |
| 5071 | list_del_init(&piocb->list); |
| 5072 | |
| 5073 | cmd = &piocb->iocb; |
| 5074 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 5075 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 5076 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 5077 | } |
| 5078 | } |
| 5079 | |
| 5080 | void lpfc_fabric_abort_hba(struct lpfc_hba *phba) |
| 5081 | { |
| 5082 | LIST_HEAD(completions); |
| 5083 | struct lpfc_iocbq *piocb; |
| 5084 | IOCB_t *cmd; |
| 5085 | |
| 5086 | spin_lock_irq(&phba->hbalock); |
| 5087 | list_splice_init(&phba->fabric_iocb_list, &completions); |
| 5088 | spin_unlock_irq(&phba->hbalock); |
| 5089 | |
| 5090 | while (!list_empty(&completions)) { |
| 5091 | piocb = list_get_first(&completions, struct lpfc_iocbq, list); |
| 5092 | list_del_init(&piocb->list); |
| 5093 | |
| 5094 | cmd = &piocb->iocb; |
| 5095 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 5096 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 5097 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 5098 | } |
| 5099 | } |
| 5100 | |
| 5101 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 5102 | #if 0 |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5103 | void lpfc_fabric_abort_flogi(struct lpfc_hba *phba) |
| 5104 | { |
| 5105 | LIST_HEAD(completions); |
| 5106 | struct lpfc_iocbq *tmp_iocb, *piocb; |
| 5107 | IOCB_t *cmd; |
| 5108 | struct lpfc_nodelist *ndlp; |
| 5109 | |
| 5110 | spin_lock_irq(&phba->hbalock); |
| 5111 | list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list, |
| 5112 | list) { |
| 5113 | |
| 5114 | cmd = &piocb->iocb; |
| 5115 | ndlp = (struct lpfc_nodelist *) piocb->context1; |
| 5116 | if (cmd->ulpCommand == CMD_ELS_REQUEST64_CR && |
| 5117 | ndlp != NULL && |
| 5118 | ndlp->nlp_DID == Fabric_DID) |
| 5119 | list_move_tail(&piocb->list, &completions); |
| 5120 | } |
| 5121 | spin_unlock_irq(&phba->hbalock); |
| 5122 | |
| 5123 | while (!list_empty(&completions)) { |
| 5124 | piocb = list_get_first(&completions, struct lpfc_iocbq, list); |
| 5125 | list_del_init(&piocb->list); |
| 5126 | |
| 5127 | cmd = &piocb->iocb; |
| 5128 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 5129 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 5130 | (piocb->iocb_cmpl) (phba, piocb, piocb); |
| 5131 | } |
| 5132 | } |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 5133 | #endif /* 0 */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 5134 | |
| 5135 | |