aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/lpfc/lpfc_els.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/lpfc/lpfc_els.c')
-rw-r--r--drivers/scsi/lpfc/lpfc_els.c3377
1 files changed, 2276 insertions, 1101 deletions
diff --git a/drivers/scsi/lpfc/lpfc_els.c b/drivers/scsi/lpfc/lpfc_els.c
index 638b3cd677bd..33fbc1666946 100644
--- a/drivers/scsi/lpfc/lpfc_els.c
+++ b/drivers/scsi/lpfc/lpfc_els.c
@@ -35,38 +35,38 @@
35#include "lpfc.h" 35#include "lpfc.h"
36#include "lpfc_logmsg.h" 36#include "lpfc_logmsg.h"
37#include "lpfc_crtn.h" 37#include "lpfc_crtn.h"
38#include "lpfc_vport.h"
39#include "lpfc_debugfs.h"
38 40
39static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *, 41static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
40 struct lpfc_iocbq *); 42 struct lpfc_iocbq *);
43static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
44 struct lpfc_iocbq *);
45
41static int lpfc_max_els_tries = 3; 46static int lpfc_max_els_tries = 3;
42 47
43static int 48int
44lpfc_els_chk_latt(struct lpfc_hba * phba) 49lpfc_els_chk_latt(struct lpfc_vport *vport)
45{ 50{
46 struct lpfc_sli *psli; 51 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
47 LPFC_MBOXQ_t *mbox; 52 struct lpfc_hba *phba = vport->phba;
48 uint32_t ha_copy; 53 uint32_t ha_copy;
49 int rc;
50 54
51 psli = &phba->sli; 55 if (vport->port_state >= LPFC_VPORT_READY ||
52 56 phba->link_state == LPFC_LINK_DOWN)
53 if ((phba->hba_state >= LPFC_HBA_READY) ||
54 (phba->hba_state == LPFC_LINK_DOWN))
55 return 0; 57 return 0;
56 58
57 /* Read the HBA Host Attention Register */ 59 /* Read the HBA Host Attention Register */
58 spin_lock_irq(phba->host->host_lock);
59 ha_copy = readl(phba->HAregaddr); 60 ha_copy = readl(phba->HAregaddr);
60 spin_unlock_irq(phba->host->host_lock);
61 61
62 if (!(ha_copy & HA_LATT)) 62 if (!(ha_copy & HA_LATT))
63 return 0; 63 return 0;
64 64
65 /* Pending Link Event during Discovery */ 65 /* Pending Link Event during Discovery */
66 lpfc_printf_log(phba, KERN_WARNING, LOG_DISCOVERY, 66 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
67 "%d:0237 Pending Link Event during " 67 "%d (%d):0237 Pending Link Event during "
68 "Discovery: State x%x\n", 68 "Discovery: State x%x\n",
69 phba->brd_no, phba->hba_state); 69 phba->brd_no, vport->vpi, phba->pport->port_state);
70 70
71 /* CLEAR_LA should re-enable link attention events and 71 /* CLEAR_LA should re-enable link attention events and
72 * we should then imediately take a LATT event. The 72 * we should then imediately take a LATT event. The
@@ -74,48 +74,34 @@ lpfc_els_chk_latt(struct lpfc_hba * phba)
74 * will cleanup any left over in-progress discovery 74 * will cleanup any left over in-progress discovery
75 * events. 75 * events.
76 */ 76 */
77 spin_lock_irq(phba->host->host_lock); 77 spin_lock_irq(shost->host_lock);
78 phba->fc_flag |= FC_ABORT_DISCOVERY; 78 vport->fc_flag |= FC_ABORT_DISCOVERY;
79 spin_unlock_irq(phba->host->host_lock); 79 spin_unlock_irq(shost->host_lock);
80
81 if (phba->hba_state != LPFC_CLEAR_LA) {
82 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
83 phba->hba_state = LPFC_CLEAR_LA;
84 lpfc_clear_la(phba, mbox);
85 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
86 rc = lpfc_sli_issue_mbox (phba, mbox,
87 (MBX_NOWAIT | MBX_STOP_IOCB));
88 if (rc == MBX_NOT_FINISHED) {
89 mempool_free(mbox, phba->mbox_mem_pool);
90 phba->hba_state = LPFC_HBA_ERROR;
91 }
92 }
93 }
94 80
95 return 1; 81 if (phba->link_state != LPFC_CLEAR_LA)
82 lpfc_issue_clear_la(phba, vport);
96 83
84 return 1;
97} 85}
98 86
99static struct lpfc_iocbq * 87static struct lpfc_iocbq *
100lpfc_prep_els_iocb(struct lpfc_hba * phba, uint8_t expectRsp, 88lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
101 uint16_t cmdSize, uint8_t retry, struct lpfc_nodelist * ndlp, 89 uint16_t cmdSize, uint8_t retry,
102 uint32_t did, uint32_t elscmd) 90 struct lpfc_nodelist *ndlp, uint32_t did,
91 uint32_t elscmd)
103{ 92{
104 struct lpfc_sli_ring *pring; 93 struct lpfc_hba *phba = vport->phba;
105 struct lpfc_iocbq *elsiocb; 94 struct lpfc_iocbq *elsiocb;
106 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist; 95 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
107 struct ulp_bde64 *bpl; 96 struct ulp_bde64 *bpl;
108 IOCB_t *icmd; 97 IOCB_t *icmd;
109 98
110 pring = &phba->sli.ring[LPFC_ELS_RING];
111 99
112 if (phba->hba_state < LPFC_LINK_UP) 100 if (!lpfc_is_link_up(phba))
113 return NULL; 101 return NULL;
114 102
115 /* Allocate buffer for command iocb */ 103 /* Allocate buffer for command iocb */
116 spin_lock_irq(phba->host->host_lock);
117 elsiocb = lpfc_sli_get_iocbq(phba); 104 elsiocb = lpfc_sli_get_iocbq(phba);
118 spin_unlock_irq(phba->host->host_lock);
119 105
120 if (elsiocb == NULL) 106 if (elsiocb == NULL)
121 return NULL; 107 return NULL;
@@ -123,14 +109,12 @@ lpfc_prep_els_iocb(struct lpfc_hba * phba, uint8_t expectRsp,
123 109
124 /* fill in BDEs for command */ 110 /* fill in BDEs for command */
125 /* Allocate buffer for command payload */ 111 /* Allocate buffer for command payload */
126 if (((pcmd = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL)) == 0) || 112 if (((pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL)) == 0) ||
127 ((pcmd->virt = lpfc_mbuf_alloc(phba, 113 ((pcmd->virt = lpfc_mbuf_alloc(phba,
128 MEM_PRI, &(pcmd->phys))) == 0)) { 114 MEM_PRI, &(pcmd->phys))) == 0)) {
129 kfree(pcmd); 115 kfree(pcmd);
130 116
131 spin_lock_irq(phba->host->host_lock);
132 lpfc_sli_release_iocbq(phba, elsiocb); 117 lpfc_sli_release_iocbq(phba, elsiocb);
133 spin_unlock_irq(phba->host->host_lock);
134 return NULL; 118 return NULL;
135 } 119 }
136 120
@@ -138,7 +122,7 @@ lpfc_prep_els_iocb(struct lpfc_hba * phba, uint8_t expectRsp,
138 122
139 /* Allocate buffer for response payload */ 123 /* Allocate buffer for response payload */
140 if (expectRsp) { 124 if (expectRsp) {
141 prsp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); 125 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
142 if (prsp) 126 if (prsp)
143 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, 127 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
144 &prsp->phys); 128 &prsp->phys);
@@ -146,9 +130,7 @@ lpfc_prep_els_iocb(struct lpfc_hba * phba, uint8_t expectRsp,
146 kfree(prsp); 130 kfree(prsp);
147 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys); 131 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
148 kfree(pcmd); 132 kfree(pcmd);
149 spin_lock_irq(phba->host->host_lock);
150 lpfc_sli_release_iocbq(phba, elsiocb); 133 lpfc_sli_release_iocbq(phba, elsiocb);
151 spin_unlock_irq(phba->host->host_lock);
152 return NULL; 134 return NULL;
153 } 135 }
154 INIT_LIST_HEAD(&prsp->list); 136 INIT_LIST_HEAD(&prsp->list);
@@ -157,14 +139,12 @@ lpfc_prep_els_iocb(struct lpfc_hba * phba, uint8_t expectRsp,
157 } 139 }
158 140
159 /* Allocate buffer for Buffer ptr list */ 141 /* Allocate buffer for Buffer ptr list */
160 pbuflist = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); 142 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
161 if (pbuflist) 143 if (pbuflist)
162 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI, 144 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
163 &pbuflist->phys); 145 &pbuflist->phys);
164 if (pbuflist == 0 || pbuflist->virt == 0) { 146 if (pbuflist == 0 || pbuflist->virt == 0) {
165 spin_lock_irq(phba->host->host_lock);
166 lpfc_sli_release_iocbq(phba, elsiocb); 147 lpfc_sli_release_iocbq(phba, elsiocb);
167 spin_unlock_irq(phba->host->host_lock);
168 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys); 148 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
169 lpfc_mbuf_free(phba, prsp->virt, prsp->phys); 149 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
170 kfree(pcmd); 150 kfree(pcmd);
@@ -178,20 +158,28 @@ lpfc_prep_els_iocb(struct lpfc_hba * phba, uint8_t expectRsp,
178 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys); 158 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
179 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys); 159 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
180 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BDL; 160 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BDL;
161 icmd->un.elsreq64.remoteID = did; /* DID */
181 if (expectRsp) { 162 if (expectRsp) {
182 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof (struct ulp_bde64)); 163 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
183 icmd->un.elsreq64.remoteID = did; /* DID */
184 icmd->ulpCommand = CMD_ELS_REQUEST64_CR; 164 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
185 icmd->ulpTimeout = phba->fc_ratov * 2; 165 icmd->ulpTimeout = phba->fc_ratov * 2;
186 } else { 166 } else {
187 icmd->un.elsreq64.bdl.bdeSize = sizeof (struct ulp_bde64); 167 icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64);
188 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX; 168 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
189 } 169 }
190
191 icmd->ulpBdeCount = 1; 170 icmd->ulpBdeCount = 1;
192 icmd->ulpLe = 1; 171 icmd->ulpLe = 1;
193 icmd->ulpClass = CLASS3; 172 icmd->ulpClass = CLASS3;
194 173
174 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
175 icmd->un.elsreq64.myID = vport->fc_myDID;
176
177 /* For ELS_REQUEST64_CR, use the VPI by default */
178 icmd->ulpContext = vport->vpi;
179 icmd->ulpCt_h = 0;
180 icmd->ulpCt_l = 1;
181 }
182
195 bpl = (struct ulp_bde64 *) pbuflist->virt; 183 bpl = (struct ulp_bde64 *) pbuflist->virt;
196 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys)); 184 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
197 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys)); 185 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
@@ -209,10 +197,12 @@ lpfc_prep_els_iocb(struct lpfc_hba * phba, uint8_t expectRsp,
209 } 197 }
210 198
211 /* Save for completion so we can release these resources */ 199 /* Save for completion so we can release these resources */
212 elsiocb->context1 = lpfc_nlp_get(ndlp); 200 if (elscmd != ELS_CMD_LS_RJT)
201 elsiocb->context1 = lpfc_nlp_get(ndlp);
213 elsiocb->context2 = pcmd; 202 elsiocb->context2 = pcmd;
214 elsiocb->context3 = pbuflist; 203 elsiocb->context3 = pbuflist;
215 elsiocb->retry = retry; 204 elsiocb->retry = retry;
205 elsiocb->vport = vport;
216 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT; 206 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
217 207
218 if (prsp) { 208 if (prsp) {
@@ -222,16 +212,16 @@ lpfc_prep_els_iocb(struct lpfc_hba * phba, uint8_t expectRsp,
222 if (expectRsp) { 212 if (expectRsp) {
223 /* Xmit ELS command <elsCmd> to remote NPORT <did> */ 213 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
224 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 214 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
225 "%d:0116 Xmit ELS command x%x to remote " 215 "%d (%d):0116 Xmit ELS command x%x to remote "
226 "NPORT x%x I/O tag: x%x, HBA state: x%x\n", 216 "NPORT x%x I/O tag: x%x, port state: x%x\n",
227 phba->brd_no, elscmd, 217 phba->brd_no, vport->vpi, elscmd, did,
228 did, elsiocb->iotag, phba->hba_state); 218 elsiocb->iotag, vport->port_state);
229 } else { 219 } else {
230 /* Xmit ELS response <elsCmd> to remote NPORT <did> */ 220 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
231 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 221 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
232 "%d:0117 Xmit ELS response x%x to remote " 222 "%d (%d):0117 Xmit ELS response x%x to remote "
233 "NPORT x%x I/O tag: x%x, size: x%x\n", 223 "NPORT x%x I/O tag: x%x, size: x%x\n",
234 phba->brd_no, elscmd, 224 phba->brd_no, vport->vpi, elscmd,
235 ndlp->nlp_DID, elsiocb->iotag, cmdSize); 225 ndlp->nlp_DID, elsiocb->iotag, cmdSize);
236 } 226 }
237 227
@@ -240,16 +230,79 @@ lpfc_prep_els_iocb(struct lpfc_hba * phba, uint8_t expectRsp,
240 230
241 231
242static int 232static int
243lpfc_cmpl_els_flogi_fabric(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, 233lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
244 struct serv_parm *sp, IOCB_t *irsp)
245{ 234{
235 struct lpfc_hba *phba = vport->phba;
246 LPFC_MBOXQ_t *mbox; 236 LPFC_MBOXQ_t *mbox;
247 struct lpfc_dmabuf *mp; 237 struct lpfc_dmabuf *mp;
238 struct lpfc_nodelist *ndlp;
239 struct serv_parm *sp;
248 int rc; 240 int rc;
249 241
250 spin_lock_irq(phba->host->host_lock); 242 sp = &phba->fc_fabparam;
251 phba->fc_flag |= FC_FABRIC; 243 ndlp = lpfc_findnode_did(vport, Fabric_DID);
252 spin_unlock_irq(phba->host->host_lock); 244 if (!ndlp)
245 goto fail;
246
247 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
248 if (!mbox)
249 goto fail;
250
251 vport->port_state = LPFC_FABRIC_CFG_LINK;
252 lpfc_config_link(phba, mbox);
253 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
254 mbox->vport = vport;
255
256 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT | MBX_STOP_IOCB);
257 if (rc == MBX_NOT_FINISHED)
258 goto fail_free_mbox;
259
260 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
261 if (!mbox)
262 goto fail;
263 rc = lpfc_reg_login(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
264 0);
265 if (rc)
266 goto fail_free_mbox;
267
268 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
269 mbox->vport = vport;
270 mbox->context2 = lpfc_nlp_get(ndlp);
271
272 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT | MBX_STOP_IOCB);
273 if (rc == MBX_NOT_FINISHED)
274 goto fail_issue_reg_login;
275
276 return 0;
277
278fail_issue_reg_login:
279 lpfc_nlp_put(ndlp);
280 mp = (struct lpfc_dmabuf *) mbox->context1;
281 lpfc_mbuf_free(phba, mp->virt, mp->phys);
282 kfree(mp);
283fail_free_mbox:
284 mempool_free(mbox, phba->mbox_mem_pool);
285
286fail:
287 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
288 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
289 "%d (%d):0249 Cannot issue Register Fabric login\n",
290 phba->brd_no, vport->vpi);
291 return -ENXIO;
292}
293
294static int
295lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
296 struct serv_parm *sp, IOCB_t *irsp)
297{
298 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
299 struct lpfc_hba *phba = vport->phba;
300 struct lpfc_nodelist *np;
301 struct lpfc_nodelist *next_np;
302
303 spin_lock_irq(shost->host_lock);
304 vport->fc_flag |= FC_FABRIC;
305 spin_unlock_irq(shost->host_lock);
253 306
254 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov); 307 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
255 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */ 308 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
@@ -258,20 +311,20 @@ lpfc_cmpl_els_flogi_fabric(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
258 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000; 311 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
259 312
260 if (phba->fc_topology == TOPOLOGY_LOOP) { 313 if (phba->fc_topology == TOPOLOGY_LOOP) {
261 spin_lock_irq(phba->host->host_lock); 314 spin_lock_irq(shost->host_lock);
262 phba->fc_flag |= FC_PUBLIC_LOOP; 315 vport->fc_flag |= FC_PUBLIC_LOOP;
263 spin_unlock_irq(phba->host->host_lock); 316 spin_unlock_irq(shost->host_lock);
264 } else { 317 } else {
265 /* 318 /*
266 * If we are a N-port connected to a Fabric, fixup sparam's so 319 * If we are a N-port connected to a Fabric, fixup sparam's so
267 * logins to devices on remote loops work. 320 * logins to devices on remote loops work.
268 */ 321 */
269 phba->fc_sparam.cmn.altBbCredit = 1; 322 vport->fc_sparam.cmn.altBbCredit = 1;
270 } 323 }
271 324
272 phba->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; 325 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
273 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name)); 326 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
274 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name)); 327 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
275 ndlp->nlp_class_sup = 0; 328 ndlp->nlp_class_sup = 0;
276 if (sp->cls1.classValid) 329 if (sp->cls1.classValid)
277 ndlp->nlp_class_sup |= FC_COS_CLASS1; 330 ndlp->nlp_class_sup |= FC_COS_CLASS1;
@@ -285,68 +338,85 @@ lpfc_cmpl_els_flogi_fabric(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
285 sp->cmn.bbRcvSizeLsb; 338 sp->cmn.bbRcvSizeLsb;
286 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); 339 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
287 340
288 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 341 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
289 if (!mbox) 342 if (sp->cmn.response_multiple_NPort) {
290 goto fail; 343 lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_VPORT,
291 344 "%d:1816 FLOGI NPIV supported, "
292 phba->hba_state = LPFC_FABRIC_CFG_LINK; 345 "response data 0x%x\n",
293 lpfc_config_link(phba, mbox); 346 phba->brd_no,
294 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; 347 sp->cmn.response_multiple_NPort);
348 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
295 349
296 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT | MBX_STOP_IOCB); 350 } else {
297 if (rc == MBX_NOT_FINISHED) 351 /* Because we asked f/w for NPIV it still expects us
298 goto fail_free_mbox; 352 to call reg_vnpid atleast for the physcial host */
299 353 lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_VPORT,
300 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 354 "%d:1817 Fabric does not support NPIV "
301 if (!mbox) 355 "- configuring single port mode.\n",
302 goto fail; 356 phba->brd_no);
357 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
358 }
359 }
303 360
304 if (lpfc_reg_login(phba, Fabric_DID, (uint8_t *) sp, mbox, 0)) 361 if ((vport->fc_prevDID != vport->fc_myDID) &&
305 goto fail_free_mbox; 362 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
306 363
307 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login; 364 /* If our NportID changed, we need to ensure all
308 mbox->context2 = lpfc_nlp_get(ndlp); 365 * remaining NPORTs get unreg_login'ed.
366 */
367 list_for_each_entry_safe(np, next_np,
368 &vport->fc_nodes, nlp_listp) {
369 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
370 !(np->nlp_flag & NLP_NPR_ADISC))
371 continue;
372 spin_lock_irq(shost->host_lock);
373 np->nlp_flag &= ~NLP_NPR_ADISC;
374 spin_unlock_irq(shost->host_lock);
375 lpfc_unreg_rpi(vport, np);
376 }
377 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
378 lpfc_mbx_unreg_vpi(vport);
379 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
380 }
381 }
309 382
310 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT | MBX_STOP_IOCB); 383 ndlp->nlp_sid = irsp->un.ulpWord[4] & Mask_DID;
311 if (rc == MBX_NOT_FINISHED) 384 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
312 goto fail_issue_reg_login;
313 385
386 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
387 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) {
388 lpfc_register_new_vport(phba, vport, ndlp);
389 return 0;
390 }
391 lpfc_issue_fabric_reglogin(vport);
314 return 0; 392 return 0;
315
316 fail_issue_reg_login:
317 lpfc_nlp_put(ndlp);
318 mp = (struct lpfc_dmabuf *) mbox->context1;
319 lpfc_mbuf_free(phba, mp->virt, mp->phys);
320 kfree(mp);
321 fail_free_mbox:
322 mempool_free(mbox, phba->mbox_mem_pool);
323 fail:
324 return -ENXIO;
325} 393}
326 394
327/* 395/*
328 * We FLOGIed into an NPort, initiate pt2pt protocol 396 * We FLOGIed into an NPort, initiate pt2pt protocol
329 */ 397 */
330static int 398static int
331lpfc_cmpl_els_flogi_nport(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, 399lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
332 struct serv_parm *sp) 400 struct serv_parm *sp)
333{ 401{
402 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
403 struct lpfc_hba *phba = vport->phba;
334 LPFC_MBOXQ_t *mbox; 404 LPFC_MBOXQ_t *mbox;
335 int rc; 405 int rc;
336 406
337 spin_lock_irq(phba->host->host_lock); 407 spin_lock_irq(shost->host_lock);
338 phba->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); 408 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
339 spin_unlock_irq(phba->host->host_lock); 409 spin_unlock_irq(shost->host_lock);
340 410
341 phba->fc_edtov = FF_DEF_EDTOV; 411 phba->fc_edtov = FF_DEF_EDTOV;
342 phba->fc_ratov = FF_DEF_RATOV; 412 phba->fc_ratov = FF_DEF_RATOV;
343 rc = memcmp(&phba->fc_portname, &sp->portName, 413 rc = memcmp(&vport->fc_portname, &sp->portName,
344 sizeof(struct lpfc_name)); 414 sizeof(vport->fc_portname));
345 if (rc >= 0) { 415 if (rc >= 0) {
346 /* This side will initiate the PLOGI */ 416 /* This side will initiate the PLOGI */
347 spin_lock_irq(phba->host->host_lock); 417 spin_lock_irq(shost->host_lock);
348 phba->fc_flag |= FC_PT2PT_PLOGI; 418 vport->fc_flag |= FC_PT2PT_PLOGI;
349 spin_unlock_irq(phba->host->host_lock); 419 spin_unlock_irq(shost->host_lock);
350 420
351 /* 421 /*
352 * N_Port ID cannot be 0, set our to LocalID the other 422 * N_Port ID cannot be 0, set our to LocalID the other
@@ -355,7 +425,7 @@ lpfc_cmpl_els_flogi_nport(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
355 425
356 /* not equal */ 426 /* not equal */
357 if (rc) 427 if (rc)
358 phba->fc_myDID = PT2PT_LocalID; 428 vport->fc_myDID = PT2PT_LocalID;
359 429
360 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 430 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
361 if (!mbox) 431 if (!mbox)
@@ -364,15 +434,16 @@ lpfc_cmpl_els_flogi_nport(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
364 lpfc_config_link(phba, mbox); 434 lpfc_config_link(phba, mbox);
365 435
366 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; 436 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
437 mbox->vport = vport;
367 rc = lpfc_sli_issue_mbox(phba, mbox, 438 rc = lpfc_sli_issue_mbox(phba, mbox,
368 MBX_NOWAIT | MBX_STOP_IOCB); 439 MBX_NOWAIT | MBX_STOP_IOCB);
369 if (rc == MBX_NOT_FINISHED) { 440 if (rc == MBX_NOT_FINISHED) {
370 mempool_free(mbox, phba->mbox_mem_pool); 441 mempool_free(mbox, phba->mbox_mem_pool);
371 goto fail; 442 goto fail;
372 } 443 }
373 lpfc_nlp_put(ndlp); 444 lpfc_nlp_put(ndlp);
374 445
375 ndlp = lpfc_findnode_did(phba, PT2PT_RemoteID); 446 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
376 if (!ndlp) { 447 if (!ndlp) {
377 /* 448 /*
378 * Cannot find existing Fabric ndlp, so allocate a 449 * Cannot find existing Fabric ndlp, so allocate a
@@ -382,28 +453,30 @@ lpfc_cmpl_els_flogi_nport(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
382 if (!ndlp) 453 if (!ndlp)
383 goto fail; 454 goto fail;
384 455
385 lpfc_nlp_init(phba, ndlp, PT2PT_RemoteID); 456 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
386 } 457 }
387 458
388 memcpy(&ndlp->nlp_portname, &sp->portName, 459 memcpy(&ndlp->nlp_portname, &sp->portName,
389 sizeof(struct lpfc_name)); 460 sizeof(struct lpfc_name));
390 memcpy(&ndlp->nlp_nodename, &sp->nodeName, 461 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
391 sizeof(struct lpfc_name)); 462 sizeof(struct lpfc_name));
392 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE); 463 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
464 spin_lock_irq(shost->host_lock);
393 ndlp->nlp_flag |= NLP_NPR_2B_DISC; 465 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
466 spin_unlock_irq(shost->host_lock);
394 } else { 467 } else {
395 /* This side will wait for the PLOGI */ 468 /* This side will wait for the PLOGI */
396 lpfc_nlp_put(ndlp); 469 lpfc_nlp_put(ndlp);
397 } 470 }
398 471
399 spin_lock_irq(phba->host->host_lock); 472 spin_lock_irq(shost->host_lock);
400 phba->fc_flag |= FC_PT2PT; 473 vport->fc_flag |= FC_PT2PT;
401 spin_unlock_irq(phba->host->host_lock); 474 spin_unlock_irq(shost->host_lock);
402 475
403 /* Start discovery - this should just do CLEAR_LA */ 476 /* Start discovery - this should just do CLEAR_LA */
404 lpfc_disc_start(phba); 477 lpfc_disc_start(vport);
405 return 0; 478 return 0;
406 fail: 479fail:
407 return -ENXIO; 480 return -ENXIO;
408} 481}
409 482
@@ -411,6 +484,8 @@ static void
411lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 484lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
412 struct lpfc_iocbq *rspiocb) 485 struct lpfc_iocbq *rspiocb)
413{ 486{
487 struct lpfc_vport *vport = cmdiocb->vport;
488 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
414 IOCB_t *irsp = &rspiocb->iocb; 489 IOCB_t *irsp = &rspiocb->iocb;
415 struct lpfc_nodelist *ndlp = cmdiocb->context1; 490 struct lpfc_nodelist *ndlp = cmdiocb->context1;
416 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp; 491 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
@@ -418,21 +493,25 @@ lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
418 int rc; 493 int rc;
419 494
420 /* Check to see if link went down during discovery */ 495 /* Check to see if link went down during discovery */
421 if (lpfc_els_chk_latt(phba)) { 496 if (lpfc_els_chk_latt(vport)) {
422 lpfc_nlp_put(ndlp); 497 lpfc_nlp_put(ndlp);
423 goto out; 498 goto out;
424 } 499 }
425 500
501 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
502 "FLOGI cmpl: status:x%x/x%x state:x%x",
503 irsp->ulpStatus, irsp->un.ulpWord[4],
504 vport->port_state);
505
426 if (irsp->ulpStatus) { 506 if (irsp->ulpStatus) {
427 /* Check for retry */ 507 /* Check for retry */
428 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { 508 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
429 /* ELS command is being retried */
430 goto out; 509 goto out;
431 } 510
432 /* FLOGI failed, so there is no fabric */ 511 /* FLOGI failed, so there is no fabric */
433 spin_lock_irq(phba->host->host_lock); 512 spin_lock_irq(shost->host_lock);
434 phba->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); 513 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
435 spin_unlock_irq(phba->host->host_lock); 514 spin_unlock_irq(shost->host_lock);
436 515
437 /* If private loop, then allow max outstanding els to be 516 /* If private loop, then allow max outstanding els to be
438 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no 517 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
@@ -443,11 +522,10 @@ lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
443 } 522 }
444 523
445 /* FLOGI failure */ 524 /* FLOGI failure */
446 lpfc_printf_log(phba, 525 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
447 KERN_INFO, 526 "%d (%d):0100 FLOGI failure Data: x%x x%x "
448 LOG_ELS, 527 "x%x\n",
449 "%d:0100 FLOGI failure Data: x%x x%x x%x\n", 528 phba->brd_no, vport->vpi,
450 phba->brd_no,
451 irsp->ulpStatus, irsp->un.ulpWord[4], 529 irsp->ulpStatus, irsp->un.ulpWord[4],
452 irsp->ulpTimeout); 530 irsp->ulpTimeout);
453 goto flogifail; 531 goto flogifail;
@@ -463,21 +541,21 @@ lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
463 541
464 /* FLOGI completes successfully */ 542 /* FLOGI completes successfully */
465 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 543 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
466 "%d:0101 FLOGI completes sucessfully " 544 "%d (%d):0101 FLOGI completes sucessfully "
467 "Data: x%x x%x x%x x%x\n", 545 "Data: x%x x%x x%x x%x\n",
468 phba->brd_no, 546 phba->brd_no, vport->vpi,
469 irsp->un.ulpWord[4], sp->cmn.e_d_tov, 547 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
470 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution); 548 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
471 549
472 if (phba->hba_state == LPFC_FLOGI) { 550 if (vport->port_state == LPFC_FLOGI) {
473 /* 551 /*
474 * If Common Service Parameters indicate Nport 552 * If Common Service Parameters indicate Nport
475 * we are point to point, if Fport we are Fabric. 553 * we are point to point, if Fport we are Fabric.
476 */ 554 */
477 if (sp->cmn.fPort) 555 if (sp->cmn.fPort)
478 rc = lpfc_cmpl_els_flogi_fabric(phba, ndlp, sp, irsp); 556 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
479 else 557 else
480 rc = lpfc_cmpl_els_flogi_nport(phba, ndlp, sp); 558 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
481 559
482 if (!rc) 560 if (!rc)
483 goto out; 561 goto out;
@@ -486,14 +564,12 @@ lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
486flogifail: 564flogifail:
487 lpfc_nlp_put(ndlp); 565 lpfc_nlp_put(ndlp);
488 566
489 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT || 567 if (!lpfc_error_lost_link(irsp)) {
490 (irsp->un.ulpWord[4] != IOERR_SLI_ABORTED &&
491 irsp->un.ulpWord[4] != IOERR_SLI_DOWN)) {
492 /* FLOGI failed, so just use loop map to make discovery list */ 568 /* FLOGI failed, so just use loop map to make discovery list */
493 lpfc_disc_list_loopmap(phba); 569 lpfc_disc_list_loopmap(vport);
494 570
495 /* Start discovery */ 571 /* Start discovery */
496 lpfc_disc_start(phba); 572 lpfc_disc_start(vport);
497 } 573 }
498 574
499out: 575out:
@@ -501,9 +577,10 @@ out:
501} 577}
502 578
503static int 579static int
504lpfc_issue_els_flogi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, 580lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
505 uint8_t retry) 581 uint8_t retry)
506{ 582{
583 struct lpfc_hba *phba = vport->phba;
507 struct serv_parm *sp; 584 struct serv_parm *sp;
508 IOCB_t *icmd; 585 IOCB_t *icmd;
509 struct lpfc_iocbq *elsiocb; 586 struct lpfc_iocbq *elsiocb;
@@ -515,9 +592,10 @@ lpfc_issue_els_flogi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
515 592
516 pring = &phba->sli.ring[LPFC_ELS_RING]; 593 pring = &phba->sli.ring[LPFC_ELS_RING];
517 594
518 cmdsize = (sizeof (uint32_t) + sizeof (struct serv_parm)); 595 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
519 elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp, 596 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
520 ndlp->nlp_DID, ELS_CMD_FLOGI); 597 ndlp->nlp_DID, ELS_CMD_FLOGI);
598
521 if (!elsiocb) 599 if (!elsiocb)
522 return 1; 600 return 1;
523 601
@@ -526,8 +604,8 @@ lpfc_issue_els_flogi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
526 604
527 /* For FLOGI request, remainder of payload is service parameters */ 605 /* For FLOGI request, remainder of payload is service parameters */
528 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI; 606 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
529 pcmd += sizeof (uint32_t); 607 pcmd += sizeof(uint32_t);
530 memcpy(pcmd, &phba->fc_sparam, sizeof (struct serv_parm)); 608 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
531 sp = (struct serv_parm *) pcmd; 609 sp = (struct serv_parm *) pcmd;
532 610
533 /* Setup CSPs accordingly for Fabric */ 611 /* Setup CSPs accordingly for Fabric */
@@ -541,16 +619,32 @@ lpfc_issue_els_flogi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
541 if (sp->cmn.fcphHigh < FC_PH3) 619 if (sp->cmn.fcphHigh < FC_PH3)
542 sp->cmn.fcphHigh = FC_PH3; 620 sp->cmn.fcphHigh = FC_PH3;
543 621
622 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
623 sp->cmn.request_multiple_Nport = 1;
624
625 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
626 icmd->ulpCt_h = 1;
627 icmd->ulpCt_l = 0;
628 }
629
630 if (phba->fc_topology != TOPOLOGY_LOOP) {
631 icmd->un.elsreq64.myID = 0;
632 icmd->un.elsreq64.fl = 1;
633 }
634
544 tmo = phba->fc_ratov; 635 tmo = phba->fc_ratov;
545 phba->fc_ratov = LPFC_DISC_FLOGI_TMO; 636 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
546 lpfc_set_disctmo(phba); 637 lpfc_set_disctmo(vport);
547 phba->fc_ratov = tmo; 638 phba->fc_ratov = tmo;
548 639
549 phba->fc_stat.elsXmitFLOGI++; 640 phba->fc_stat.elsXmitFLOGI++;
550 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi; 641 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
551 spin_lock_irq(phba->host->host_lock); 642
552 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); 643 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
553 spin_unlock_irq(phba->host->host_lock); 644 "Issue FLOGI: opt:x%x",
645 phba->sli3_options, 0, 0);
646
647 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
554 if (rc == IOCB_ERROR) { 648 if (rc == IOCB_ERROR) {
555 lpfc_els_free_iocb(phba, elsiocb); 649 lpfc_els_free_iocb(phba, elsiocb);
556 return 1; 650 return 1;
@@ -559,7 +653,7 @@ lpfc_issue_els_flogi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
559} 653}
560 654
561int 655int
562lpfc_els_abort_flogi(struct lpfc_hba * phba) 656lpfc_els_abort_flogi(struct lpfc_hba *phba)
563{ 657{
564 struct lpfc_sli_ring *pring; 658 struct lpfc_sli_ring *pring;
565 struct lpfc_iocbq *iocb, *next_iocb; 659 struct lpfc_iocbq *iocb, *next_iocb;
@@ -577,73 +671,99 @@ lpfc_els_abort_flogi(struct lpfc_hba * phba)
577 * Check the txcmplq for an iocb that matches the nport the driver is 671 * Check the txcmplq for an iocb that matches the nport the driver is
578 * searching for. 672 * searching for.
579 */ 673 */
580 spin_lock_irq(phba->host->host_lock); 674 spin_lock_irq(&phba->hbalock);
581 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { 675 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
582 icmd = &iocb->iocb; 676 icmd = &iocb->iocb;
583 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) { 677 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
678 icmd->un.elsreq64.bdl.ulpIoTag32) {
584 ndlp = (struct lpfc_nodelist *)(iocb->context1); 679 ndlp = (struct lpfc_nodelist *)(iocb->context1);
585 if (ndlp && (ndlp->nlp_DID == Fabric_DID)) 680 if (ndlp && (ndlp->nlp_DID == Fabric_DID)) {
586 lpfc_sli_issue_abort_iotag(phba, pring, iocb); 681 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
682 }
587 } 683 }
588 } 684 }
589 spin_unlock_irq(phba->host->host_lock); 685 spin_unlock_irq(&phba->hbalock);
590 686
591 return 0; 687 return 0;
592} 688}
593 689
594int 690int
595lpfc_initial_flogi(struct lpfc_hba *phba) 691lpfc_initial_flogi(struct lpfc_vport *vport)
596{ 692{
693 struct lpfc_hba *phba = vport->phba;
597 struct lpfc_nodelist *ndlp; 694 struct lpfc_nodelist *ndlp;
598 695
599 /* First look for the Fabric ndlp */ 696 /* First look for the Fabric ndlp */
600 ndlp = lpfc_findnode_did(phba, Fabric_DID); 697 ndlp = lpfc_findnode_did(vport, Fabric_DID);
601 if (!ndlp) { 698 if (!ndlp) {
602 /* Cannot find existing Fabric ndlp, so allocate a new one */ 699 /* Cannot find existing Fabric ndlp, so allocate a new one */
603 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); 700 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
604 if (!ndlp) 701 if (!ndlp)
605 return 0; 702 return 0;
606 lpfc_nlp_init(phba, ndlp, Fabric_DID); 703 lpfc_nlp_init(vport, ndlp, Fabric_DID);
607 } else { 704 } else {
608 lpfc_dequeue_node(phba, ndlp); 705 lpfc_dequeue_node(vport, ndlp);
609 } 706 }
610 if (lpfc_issue_els_flogi(phba, ndlp, 0)) { 707 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
611 lpfc_nlp_put(ndlp); 708 lpfc_nlp_put(ndlp);
612 } 709 }
613 return 1; 710 return 1;
614} 711}
615 712
713int
714lpfc_initial_fdisc(struct lpfc_vport *vport)
715{
716 struct lpfc_hba *phba = vport->phba;
717 struct lpfc_nodelist *ndlp;
718
719 /* First look for the Fabric ndlp */
720 ndlp = lpfc_findnode_did(vport, Fabric_DID);
721 if (!ndlp) {
722 /* Cannot find existing Fabric ndlp, so allocate a new one */
723 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
724 if (!ndlp)
725 return 0;
726 lpfc_nlp_init(vport, ndlp, Fabric_DID);
727 } else {
728 lpfc_dequeue_node(vport, ndlp);
729 }
730 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
731 lpfc_nlp_put(ndlp);
732 }
733 return 1;
734}
616static void 735static void
617lpfc_more_plogi(struct lpfc_hba * phba) 736lpfc_more_plogi(struct lpfc_vport *vport)
618{ 737{
619 int sentplogi; 738 int sentplogi;
739 struct lpfc_hba *phba = vport->phba;
620 740
621 if (phba->num_disc_nodes) 741 if (vport->num_disc_nodes)
622 phba->num_disc_nodes--; 742 vport->num_disc_nodes--;
623 743
624 /* Continue discovery with <num_disc_nodes> PLOGIs to go */ 744 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
625 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, 745 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
626 "%d:0232 Continue discovery with %d PLOGIs to go " 746 "%d (%d):0232 Continue discovery with %d PLOGIs to go "
627 "Data: x%x x%x x%x\n", 747 "Data: x%x x%x x%x\n",
628 phba->brd_no, phba->num_disc_nodes, phba->fc_plogi_cnt, 748 phba->brd_no, vport->vpi, vport->num_disc_nodes,
629 phba->fc_flag, phba->hba_state); 749 vport->fc_plogi_cnt, vport->fc_flag, vport->port_state);
630 750
631 /* Check to see if there are more PLOGIs to be sent */ 751 /* Check to see if there are more PLOGIs to be sent */
632 if (phba->fc_flag & FC_NLP_MORE) { 752 if (vport->fc_flag & FC_NLP_MORE)
633 /* go thru NPR list and issue any remaining ELS PLOGIs */ 753 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
634 sentplogi = lpfc_els_disc_plogi(phba); 754 sentplogi = lpfc_els_disc_plogi(vport);
635 } 755
636 return; 756 return;
637} 757}
638 758
639static struct lpfc_nodelist * 759static struct lpfc_nodelist *
640lpfc_plogi_confirm_nport(struct lpfc_hba *phba, struct lpfc_dmabuf *prsp, 760lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
641 struct lpfc_nodelist *ndlp) 761 struct lpfc_nodelist *ndlp)
642{ 762{
763 struct lpfc_vport *vport = ndlp->vport;
643 struct lpfc_nodelist *new_ndlp; 764 struct lpfc_nodelist *new_ndlp;
644 uint32_t *lp;
645 struct serv_parm *sp; 765 struct serv_parm *sp;
646 uint8_t name[sizeof (struct lpfc_name)]; 766 uint8_t name[sizeof(struct lpfc_name)];
647 uint32_t rc; 767 uint32_t rc;
648 768
649 /* Fabric nodes can have the same WWPN so we don't bother searching 769 /* Fabric nodes can have the same WWPN so we don't bother searching
@@ -652,50 +772,51 @@ lpfc_plogi_confirm_nport(struct lpfc_hba *phba, struct lpfc_dmabuf *prsp,
652 if (ndlp->nlp_type & NLP_FABRIC) 772 if (ndlp->nlp_type & NLP_FABRIC)
653 return ndlp; 773 return ndlp;
654 774
655 lp = (uint32_t *) prsp->virt; 775 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
656 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
657 memset(name, 0, sizeof(struct lpfc_name)); 776 memset(name, 0, sizeof(struct lpfc_name));
658 777
659 /* Now we find out if the NPort we are logging into, matches the WWPN 778 /* Now we find out if the NPort we are logging into, matches the WWPN
660 * we have for that ndlp. If not, we have some work to do. 779 * we have for that ndlp. If not, we have some work to do.
661 */ 780 */
662 new_ndlp = lpfc_findnode_wwpn(phba, &sp->portName); 781 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
663 782
664 if (new_ndlp == ndlp) 783 if (new_ndlp == ndlp)
665 return ndlp; 784 return ndlp;
666 785
667 if (!new_ndlp) { 786 if (!new_ndlp) {
668 rc = 787 rc = memcmp(&ndlp->nlp_portname, name,
669 memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)); 788 sizeof(struct lpfc_name));
670 if (!rc) 789 if (!rc)
671 return ndlp; 790 return ndlp;
672 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC); 791 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
673 if (!new_ndlp) 792 if (!new_ndlp)
674 return ndlp; 793 return ndlp;
675 794
676 lpfc_nlp_init(phba, new_ndlp, ndlp->nlp_DID); 795 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
677 } 796 }
678 797
679 lpfc_unreg_rpi(phba, new_ndlp); 798 lpfc_unreg_rpi(vport, new_ndlp);
680 new_ndlp->nlp_DID = ndlp->nlp_DID; 799 new_ndlp->nlp_DID = ndlp->nlp_DID;
681 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state; 800 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
682 lpfc_nlp_set_state(phba, new_ndlp, ndlp->nlp_state); 801 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
683 802
684 /* Move this back to NPR list */ 803 /* Move this back to NPR state */
685 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) 804 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0)
686 lpfc_drop_node(phba, ndlp); 805 lpfc_drop_node(vport, ndlp);
687 else { 806 else {
688 lpfc_unreg_rpi(phba, ndlp); 807 lpfc_unreg_rpi(vport, ndlp);
689 ndlp->nlp_DID = 0; /* Two ndlps cannot have the same did */ 808 ndlp->nlp_DID = 0; /* Two ndlps cannot have the same did */
690 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE); 809 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
691 } 810 }
692 return new_ndlp; 811 return new_ndlp;
693} 812}
694 813
695static void 814static void
696lpfc_cmpl_els_plogi(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb, 815lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
697 struct lpfc_iocbq * rspiocb) 816 struct lpfc_iocbq *rspiocb)
698{ 817{
818 struct lpfc_vport *vport = cmdiocb->vport;
819 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
699 IOCB_t *irsp; 820 IOCB_t *irsp;
700 struct lpfc_nodelist *ndlp; 821 struct lpfc_nodelist *ndlp;
701 struct lpfc_dmabuf *prsp; 822 struct lpfc_dmabuf *prsp;
@@ -705,32 +826,43 @@ lpfc_cmpl_els_plogi(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
705 cmdiocb->context_un.rsp_iocb = rspiocb; 826 cmdiocb->context_un.rsp_iocb = rspiocb;
706 827
707 irsp = &rspiocb->iocb; 828 irsp = &rspiocb->iocb;
708 ndlp = lpfc_findnode_did(phba, irsp->un.elsreq64.remoteID); 829 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
709 if (!ndlp) 830 "PLOGI cmpl: status:x%x/x%x did:x%x",
831 irsp->ulpStatus, irsp->un.ulpWord[4],
832 irsp->un.elsreq64.remoteID);
833
834 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
835 if (!ndlp) {
836 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
837 "%d (%d):0136 PLOGI completes to NPort x%x "
838 "with no ndlp. Data: x%x x%x x%x\n",
839 phba->brd_no, vport->vpi, irsp->un.elsreq64.remoteID,
840 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->ulpIoTag);
710 goto out; 841 goto out;
842 }
711 843
712 /* Since ndlp can be freed in the disc state machine, note if this node 844 /* Since ndlp can be freed in the disc state machine, note if this node
713 * is being used during discovery. 845 * is being used during discovery.
714 */ 846 */
847 spin_lock_irq(shost->host_lock);
715 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); 848 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
716 spin_lock_irq(phba->host->host_lock);
717 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; 849 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
718 spin_unlock_irq(phba->host->host_lock); 850 spin_unlock_irq(shost->host_lock);
719 rc = 0; 851 rc = 0;
720 852
721 /* PLOGI completes to NPort <nlp_DID> */ 853 /* PLOGI completes to NPort <nlp_DID> */
722 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 854 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
723 "%d:0102 PLOGI completes to NPort x%x " 855 "%d (%d):0102 PLOGI completes to NPort x%x "
724 "Data: x%x x%x x%x x%x x%x\n", 856 "Data: x%x x%x x%x x%x x%x\n",
725 phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus, 857 phba->brd_no, vport->vpi, ndlp->nlp_DID,
726 irsp->un.ulpWord[4], irsp->ulpTimeout, disc, 858 irsp->ulpStatus, irsp->un.ulpWord[4],
727 phba->num_disc_nodes); 859 irsp->ulpTimeout, disc, vport->num_disc_nodes);
728 860
729 /* Check to see if link went down during discovery */ 861 /* Check to see if link went down during discovery */
730 if (lpfc_els_chk_latt(phba)) { 862 if (lpfc_els_chk_latt(vport)) {
731 spin_lock_irq(phba->host->host_lock); 863 spin_lock_irq(shost->host_lock);
732 ndlp->nlp_flag |= NLP_NPR_2B_DISC; 864 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
733 spin_unlock_irq(phba->host->host_lock); 865 spin_unlock_irq(shost->host_lock);
734 goto out; 866 goto out;
735 } 867 }
736 868
@@ -743,56 +875,62 @@ lpfc_cmpl_els_plogi(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
743 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { 875 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
744 /* ELS command is being retried */ 876 /* ELS command is being retried */
745 if (disc) { 877 if (disc) {
746 spin_lock_irq(phba->host->host_lock); 878 spin_lock_irq(shost->host_lock);
747 ndlp->nlp_flag |= NLP_NPR_2B_DISC; 879 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
748 spin_unlock_irq(phba->host->host_lock); 880 spin_unlock_irq(shost->host_lock);
749 } 881 }
750 goto out; 882 goto out;
751 } 883 }
752 884
753 /* PLOGI failed */ 885 /* PLOGI failed */
886 if (ndlp->nlp_DID == NameServer_DID) {
887 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
888 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
889 "%d (%d):0250 Nameserver login error: "
890 "0x%x / 0x%x\n",
891 phba->brd_no, vport->vpi,
892 irsp->ulpStatus, irsp->un.ulpWord[4]);
893 }
894
754 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ 895 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
755 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && 896 if (lpfc_error_lost_link(irsp)) {
756 ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
757 (irsp->un.ulpWord[4] == IOERR_LINK_DOWN) ||
758 (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) {
759 rc = NLP_STE_FREED_NODE; 897 rc = NLP_STE_FREED_NODE;
760 } else { 898 } else {
761 rc = lpfc_disc_state_machine(phba, ndlp, cmdiocb, 899 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
762 NLP_EVT_CMPL_PLOGI); 900 NLP_EVT_CMPL_PLOGI);
763 } 901 }
764 } else { 902 } else {
765 /* Good status, call state machine */ 903 /* Good status, call state machine */
766 prsp = list_entry(((struct lpfc_dmabuf *) 904 prsp = list_entry(((struct lpfc_dmabuf *)
767 cmdiocb->context2)->list.next, 905 cmdiocb->context2)->list.next,
768 struct lpfc_dmabuf, list); 906 struct lpfc_dmabuf, list);
769 ndlp = lpfc_plogi_confirm_nport(phba, prsp, ndlp); 907 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
770 rc = lpfc_disc_state_machine(phba, ndlp, cmdiocb, 908 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
771 NLP_EVT_CMPL_PLOGI); 909 NLP_EVT_CMPL_PLOGI);
772 } 910 }
773 911
774 if (disc && phba->num_disc_nodes) { 912 if (disc && vport->num_disc_nodes) {
775 /* Check to see if there are more PLOGIs to be sent */ 913 /* Check to see if there are more PLOGIs to be sent */
776 lpfc_more_plogi(phba); 914 lpfc_more_plogi(vport);
777 915
778 if (phba->num_disc_nodes == 0) { 916 if (vport->num_disc_nodes == 0) {
779 spin_lock_irq(phba->host->host_lock); 917 spin_lock_irq(shost->host_lock);
780 phba->fc_flag &= ~FC_NDISC_ACTIVE; 918 vport->fc_flag &= ~FC_NDISC_ACTIVE;
781 spin_unlock_irq(phba->host->host_lock); 919 spin_unlock_irq(shost->host_lock);
782 920
783 lpfc_can_disctmo(phba); 921 lpfc_can_disctmo(vport);
784 if (phba->fc_flag & FC_RSCN_MODE) { 922 if (vport->fc_flag & FC_RSCN_MODE) {
785 /* 923 /*
786 * Check to see if more RSCNs came in while 924 * Check to see if more RSCNs came in while
787 * we were processing this one. 925 * we were processing this one.
788 */ 926 */
789 if ((phba->fc_rscn_id_cnt == 0) && 927 if ((vport->fc_rscn_id_cnt == 0) &&
790 (!(phba->fc_flag & FC_RSCN_DISCOVERY))) { 928 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
791 spin_lock_irq(phba->host->host_lock); 929 spin_lock_irq(shost->host_lock);
792 phba->fc_flag &= ~FC_RSCN_MODE; 930 vport->fc_flag &= ~FC_RSCN_MODE;
793 spin_unlock_irq(phba->host->host_lock); 931 spin_unlock_irq(shost->host_lock);
794 } else { 932 } else {
795 lpfc_els_handle_rscn(phba); 933 lpfc_els_handle_rscn(vport);
796 } 934 }
797 } 935 }
798 } 936 }
@@ -804,8 +942,9 @@ out:
804} 942}
805 943
806int 944int
807lpfc_issue_els_plogi(struct lpfc_hba * phba, uint32_t did, uint8_t retry) 945lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
808{ 946{
947 struct lpfc_hba *phba = vport->phba;
809 struct serv_parm *sp; 948 struct serv_parm *sp;
810 IOCB_t *icmd; 949 IOCB_t *icmd;
811 struct lpfc_iocbq *elsiocb; 950 struct lpfc_iocbq *elsiocb;
@@ -813,13 +952,14 @@ lpfc_issue_els_plogi(struct lpfc_hba * phba, uint32_t did, uint8_t retry)
813 struct lpfc_sli *psli; 952 struct lpfc_sli *psli;
814 uint8_t *pcmd; 953 uint8_t *pcmd;
815 uint16_t cmdsize; 954 uint16_t cmdsize;
955 int ret;
816 956
817 psli = &phba->sli; 957 psli = &phba->sli;
818 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ 958 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
819 959
820 cmdsize = (sizeof (uint32_t) + sizeof (struct serv_parm)); 960 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
821 elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, NULL, did, 961 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, NULL, did,
822 ELS_CMD_PLOGI); 962 ELS_CMD_PLOGI);
823 if (!elsiocb) 963 if (!elsiocb)
824 return 1; 964 return 1;
825 965
@@ -828,8 +968,8 @@ lpfc_issue_els_plogi(struct lpfc_hba * phba, uint32_t did, uint8_t retry)
828 968
829 /* For PLOGI request, remainder of payload is service parameters */ 969 /* For PLOGI request, remainder of payload is service parameters */
830 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI; 970 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
831 pcmd += sizeof (uint32_t); 971 pcmd += sizeof(uint32_t);
832 memcpy(pcmd, &phba->fc_sparam, sizeof (struct serv_parm)); 972 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
833 sp = (struct serv_parm *) pcmd; 973 sp = (struct serv_parm *) pcmd;
834 974
835 if (sp->cmn.fcphLow < FC_PH_4_3) 975 if (sp->cmn.fcphLow < FC_PH_4_3)
@@ -838,22 +978,27 @@ lpfc_issue_els_plogi(struct lpfc_hba * phba, uint32_t did, uint8_t retry)
838 if (sp->cmn.fcphHigh < FC_PH3) 978 if (sp->cmn.fcphHigh < FC_PH3)
839 sp->cmn.fcphHigh = FC_PH3; 979 sp->cmn.fcphHigh = FC_PH3;
840 980
981 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
982 "Issue PLOGI: did:x%x",
983 did, 0, 0);
984
841 phba->fc_stat.elsXmitPLOGI++; 985 phba->fc_stat.elsXmitPLOGI++;
842 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi; 986 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
843 spin_lock_irq(phba->host->host_lock); 987 ret = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
844 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { 988
845 spin_unlock_irq(phba->host->host_lock); 989 if (ret == IOCB_ERROR) {
846 lpfc_els_free_iocb(phba, elsiocb); 990 lpfc_els_free_iocb(phba, elsiocb);
847 return 1; 991 return 1;
848 } 992 }
849 spin_unlock_irq(phba->host->host_lock);
850 return 0; 993 return 0;
851} 994}
852 995
853static void 996static void
854lpfc_cmpl_els_prli(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb, 997lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
855 struct lpfc_iocbq * rspiocb) 998 struct lpfc_iocbq *rspiocb)
856{ 999{
1000 struct lpfc_vport *vport = cmdiocb->vport;
1001 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
857 IOCB_t *irsp; 1002 IOCB_t *irsp;
858 struct lpfc_sli *psli; 1003 struct lpfc_sli *psli;
859 struct lpfc_nodelist *ndlp; 1004 struct lpfc_nodelist *ndlp;
@@ -864,21 +1009,26 @@ lpfc_cmpl_els_prli(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
864 1009
865 irsp = &(rspiocb->iocb); 1010 irsp = &(rspiocb->iocb);
866 ndlp = (struct lpfc_nodelist *) cmdiocb->context1; 1011 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
867 spin_lock_irq(phba->host->host_lock); 1012 spin_lock_irq(shost->host_lock);
868 ndlp->nlp_flag &= ~NLP_PRLI_SND; 1013 ndlp->nlp_flag &= ~NLP_PRLI_SND;
869 spin_unlock_irq(phba->host->host_lock); 1014 spin_unlock_irq(shost->host_lock);
1015
1016 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1017 "PRLI cmpl: status:x%x/x%x did:x%x",
1018 irsp->ulpStatus, irsp->un.ulpWord[4],
1019 ndlp->nlp_DID);
870 1020
871 /* PRLI completes to NPort <nlp_DID> */ 1021 /* PRLI completes to NPort <nlp_DID> */
872 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 1022 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
873 "%d:0103 PRLI completes to NPort x%x " 1023 "%d (%d):0103 PRLI completes to NPort x%x "
874 "Data: x%x x%x x%x x%x\n", 1024 "Data: x%x x%x x%x x%x\n",
875 phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus, 1025 phba->brd_no, vport->vpi, ndlp->nlp_DID,
876 irsp->un.ulpWord[4], irsp->ulpTimeout, 1026 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->ulpTimeout,
877 phba->num_disc_nodes); 1027 vport->num_disc_nodes);
878 1028
879 phba->fc_prli_sent--; 1029 vport->fc_prli_sent--;
880 /* Check to see if link went down during discovery */ 1030 /* Check to see if link went down during discovery */
881 if (lpfc_els_chk_latt(phba)) 1031 if (lpfc_els_chk_latt(vport))
882 goto out; 1032 goto out;
883 1033
884 if (irsp->ulpStatus) { 1034 if (irsp->ulpStatus) {
@@ -889,18 +1039,16 @@ lpfc_cmpl_els_prli(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
889 } 1039 }
890 /* PRLI failed */ 1040 /* PRLI failed */
891 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ 1041 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
892 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && 1042 if (lpfc_error_lost_link(irsp)) {
893 ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
894 (irsp->un.ulpWord[4] == IOERR_LINK_DOWN) ||
895 (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) {
896 goto out; 1043 goto out;
897 } else { 1044 } else {
898 lpfc_disc_state_machine(phba, ndlp, cmdiocb, 1045 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
899 NLP_EVT_CMPL_PRLI); 1046 NLP_EVT_CMPL_PRLI);
900 } 1047 }
901 } else { 1048 } else {
902 /* Good status, call state machine */ 1049 /* Good status, call state machine */
903 lpfc_disc_state_machine(phba, ndlp, cmdiocb, NLP_EVT_CMPL_PRLI); 1050 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1051 NLP_EVT_CMPL_PRLI);
904 } 1052 }
905 1053
906out: 1054out:
@@ -909,9 +1057,11 @@ out:
909} 1057}
910 1058
911int 1059int
912lpfc_issue_els_prli(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, 1060lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
913 uint8_t retry) 1061 uint8_t retry)
914{ 1062{
1063 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1064 struct lpfc_hba *phba = vport->phba;
915 PRLI *npr; 1065 PRLI *npr;
916 IOCB_t *icmd; 1066 IOCB_t *icmd;
917 struct lpfc_iocbq *elsiocb; 1067 struct lpfc_iocbq *elsiocb;
@@ -923,9 +1073,9 @@ lpfc_issue_els_prli(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
923 psli = &phba->sli; 1073 psli = &phba->sli;
924 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ 1074 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
925 1075
926 cmdsize = (sizeof (uint32_t) + sizeof (PRLI)); 1076 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
927 elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp, 1077 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
928 ndlp->nlp_DID, ELS_CMD_PRLI); 1078 ndlp->nlp_DID, ELS_CMD_PRLI);
929 if (!elsiocb) 1079 if (!elsiocb)
930 return 1; 1080 return 1;
931 1081
@@ -933,9 +1083,9 @@ lpfc_issue_els_prli(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
933 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); 1083 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
934 1084
935 /* For PRLI request, remainder of payload is service parameters */ 1085 /* For PRLI request, remainder of payload is service parameters */
936 memset(pcmd, 0, (sizeof (PRLI) + sizeof (uint32_t))); 1086 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
937 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI; 1087 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
938 pcmd += sizeof (uint32_t); 1088 pcmd += sizeof(uint32_t);
939 1089
940 /* For PRLI, remainder of payload is PRLI parameter page */ 1090 /* For PRLI, remainder of payload is PRLI parameter page */
941 npr = (PRLI *) pcmd; 1091 npr = (PRLI *) pcmd;
@@ -955,81 +1105,88 @@ lpfc_issue_els_prli(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
955 npr->prliType = PRLI_FCP_TYPE; 1105 npr->prliType = PRLI_FCP_TYPE;
956 npr->initiatorFunc = 1; 1106 npr->initiatorFunc = 1;
957 1107
1108 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1109 "Issue PRLI: did:x%x",
1110 ndlp->nlp_DID, 0, 0);
1111
958 phba->fc_stat.elsXmitPRLI++; 1112 phba->fc_stat.elsXmitPRLI++;
959 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli; 1113 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
960 spin_lock_irq(phba->host->host_lock); 1114 spin_lock_irq(shost->host_lock);
961 ndlp->nlp_flag |= NLP_PRLI_SND; 1115 ndlp->nlp_flag |= NLP_PRLI_SND;
1116 spin_unlock_irq(shost->host_lock);
962 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { 1117 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1118 spin_lock_irq(shost->host_lock);
963 ndlp->nlp_flag &= ~NLP_PRLI_SND; 1119 ndlp->nlp_flag &= ~NLP_PRLI_SND;
964 spin_unlock_irq(phba->host->host_lock); 1120 spin_unlock_irq(shost->host_lock);
965 lpfc_els_free_iocb(phba, elsiocb); 1121 lpfc_els_free_iocb(phba, elsiocb);
966 return 1; 1122 return 1;
967 } 1123 }
968 spin_unlock_irq(phba->host->host_lock); 1124 vport->fc_prli_sent++;
969 phba->fc_prli_sent++;
970 return 0; 1125 return 0;
971} 1126}
972 1127
973static void 1128static void
974lpfc_more_adisc(struct lpfc_hba * phba) 1129lpfc_more_adisc(struct lpfc_vport *vport)
975{ 1130{
976 int sentadisc; 1131 int sentadisc;
1132 struct lpfc_hba *phba = vport->phba;
977 1133
978 if (phba->num_disc_nodes) 1134 if (vport->num_disc_nodes)
979 phba->num_disc_nodes--; 1135 vport->num_disc_nodes--;
980 1136
981 /* Continue discovery with <num_disc_nodes> ADISCs to go */ 1137 /* Continue discovery with <num_disc_nodes> ADISCs to go */
982 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, 1138 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
983 "%d:0210 Continue discovery with %d ADISCs to go " 1139 "%d (%d):0210 Continue discovery with %d ADISCs to go "
984 "Data: x%x x%x x%x\n", 1140 "Data: x%x x%x x%x\n",
985 phba->brd_no, phba->num_disc_nodes, phba->fc_adisc_cnt, 1141 phba->brd_no, vport->vpi, vport->num_disc_nodes,
986 phba->fc_flag, phba->hba_state); 1142 vport->fc_adisc_cnt, vport->fc_flag, vport->port_state);
987 1143
988 /* Check to see if there are more ADISCs to be sent */ 1144 /* Check to see if there are more ADISCs to be sent */
989 if (phba->fc_flag & FC_NLP_MORE) { 1145 if (vport->fc_flag & FC_NLP_MORE) {
990 lpfc_set_disctmo(phba); 1146 lpfc_set_disctmo(vport);
991 1147 /* go thru NPR nodes and issue any remaining ELS ADISCs */
992 /* go thru NPR list and issue any remaining ELS ADISCs */ 1148 sentadisc = lpfc_els_disc_adisc(vport);
993 sentadisc = lpfc_els_disc_adisc(phba);
994 } 1149 }
995 return; 1150 return;
996} 1151}
997 1152
998static void 1153static void
999lpfc_rscn_disc(struct lpfc_hba * phba) 1154lpfc_rscn_disc(struct lpfc_vport *vport)
1000{ 1155{
1156 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1157
1158 lpfc_can_disctmo(vport);
1159
1001 /* RSCN discovery */ 1160 /* RSCN discovery */
1002 /* go thru NPR list and issue ELS PLOGIs */ 1161 /* go thru NPR nodes and issue ELS PLOGIs */
1003 if (phba->fc_npr_cnt) { 1162 if (vport->fc_npr_cnt)
1004 if (lpfc_els_disc_plogi(phba)) 1163 if (lpfc_els_disc_plogi(vport))
1005 return; 1164 return;
1006 } 1165
1007 if (phba->fc_flag & FC_RSCN_MODE) { 1166 if (vport->fc_flag & FC_RSCN_MODE) {
1008 /* Check to see if more RSCNs came in while we were 1167 /* Check to see if more RSCNs came in while we were
1009 * processing this one. 1168 * processing this one.
1010 */ 1169 */
1011 if ((phba->fc_rscn_id_cnt == 0) && 1170 if ((vport->fc_rscn_id_cnt == 0) &&
1012 (!(phba->fc_flag & FC_RSCN_DISCOVERY))) { 1171 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
1013 spin_lock_irq(phba->host->host_lock); 1172 spin_lock_irq(shost->host_lock);
1014 phba->fc_flag &= ~FC_RSCN_MODE; 1173 vport->fc_flag &= ~FC_RSCN_MODE;
1015 spin_unlock_irq(phba->host->host_lock); 1174 spin_unlock_irq(shost->host_lock);
1016 } else { 1175 } else {
1017 lpfc_els_handle_rscn(phba); 1176 lpfc_els_handle_rscn(vport);
1018 } 1177 }
1019 } 1178 }
1020} 1179}
1021 1180
1022static void 1181static void
1023lpfc_cmpl_els_adisc(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb, 1182lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1024 struct lpfc_iocbq * rspiocb) 1183 struct lpfc_iocbq *rspiocb)
1025{ 1184{
1185 struct lpfc_vport *vport = cmdiocb->vport;
1186 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1026 IOCB_t *irsp; 1187 IOCB_t *irsp;
1027 struct lpfc_sli *psli;
1028 struct lpfc_nodelist *ndlp; 1188 struct lpfc_nodelist *ndlp;
1029 LPFC_MBOXQ_t *mbox; 1189 int disc;
1030 int disc, rc;
1031
1032 psli = &phba->sli;
1033 1190
1034 /* we pass cmdiocb to state machine which needs rspiocb as well */ 1191 /* we pass cmdiocb to state machine which needs rspiocb as well */
1035 cmdiocb->context_un.rsp_iocb = rspiocb; 1192 cmdiocb->context_un.rsp_iocb = rspiocb;
@@ -1037,27 +1194,32 @@ lpfc_cmpl_els_adisc(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1037 irsp = &(rspiocb->iocb); 1194 irsp = &(rspiocb->iocb);
1038 ndlp = (struct lpfc_nodelist *) cmdiocb->context1; 1195 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1039 1196
1197 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1198 "ADISC cmpl: status:x%x/x%x did:x%x",
1199 irsp->ulpStatus, irsp->un.ulpWord[4],
1200 ndlp->nlp_DID);
1201
1040 /* Since ndlp can be freed in the disc state machine, note if this node 1202 /* Since ndlp can be freed in the disc state machine, note if this node
1041 * is being used during discovery. 1203 * is being used during discovery.
1042 */ 1204 */
1205 spin_lock_irq(shost->host_lock);
1043 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC); 1206 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
1044 spin_lock_irq(phba->host->host_lock);
1045 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC); 1207 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
1046 spin_unlock_irq(phba->host->host_lock); 1208 spin_unlock_irq(shost->host_lock);
1047 1209
1048 /* ADISC completes to NPort <nlp_DID> */ 1210 /* ADISC completes to NPort <nlp_DID> */
1049 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 1211 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1050 "%d:0104 ADISC completes to NPort x%x " 1212 "%d (%d):0104 ADISC completes to NPort x%x "
1051 "Data: x%x x%x x%x x%x x%x\n", 1213 "Data: x%x x%x x%x x%x x%x\n",
1052 phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus, 1214 phba->brd_no, vport->vpi, ndlp->nlp_DID,
1053 irsp->un.ulpWord[4], irsp->ulpTimeout, disc, 1215 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->ulpTimeout,
1054 phba->num_disc_nodes); 1216 disc, vport->num_disc_nodes);
1055 1217
1056 /* Check to see if link went down during discovery */ 1218 /* Check to see if link went down during discovery */
1057 if (lpfc_els_chk_latt(phba)) { 1219 if (lpfc_els_chk_latt(vport)) {
1058 spin_lock_irq(phba->host->host_lock); 1220 spin_lock_irq(shost->host_lock);
1059 ndlp->nlp_flag |= NLP_NPR_2B_DISC; 1221 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1060 spin_unlock_irq(phba->host->host_lock); 1222 spin_unlock_irq(shost->host_lock);
1061 goto out; 1223 goto out;
1062 } 1224 }
1063 1225
@@ -1066,67 +1228,68 @@ lpfc_cmpl_els_adisc(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1066 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { 1228 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1067 /* ELS command is being retried */ 1229 /* ELS command is being retried */
1068 if (disc) { 1230 if (disc) {
1069 spin_lock_irq(phba->host->host_lock); 1231 spin_lock_irq(shost->host_lock);
1070 ndlp->nlp_flag |= NLP_NPR_2B_DISC; 1232 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1071 spin_unlock_irq(phba->host->host_lock); 1233 spin_unlock_irq(shost->host_lock);
1072 lpfc_set_disctmo(phba); 1234 lpfc_set_disctmo(vport);
1073 } 1235 }
1074 goto out; 1236 goto out;
1075 } 1237 }
1076 /* ADISC failed */ 1238 /* ADISC failed */
1077 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ 1239 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1078 if ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) || 1240 if (!lpfc_error_lost_link(irsp)) {
1079 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) && 1241 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1080 (irsp->un.ulpWord[4] != IOERR_LINK_DOWN) && 1242 NLP_EVT_CMPL_ADISC);
1081 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) {
1082 lpfc_disc_state_machine(phba, ndlp, cmdiocb,
1083 NLP_EVT_CMPL_ADISC);
1084 } 1243 }
1085 } else { 1244 } else {
1086 /* Good status, call state machine */ 1245 /* Good status, call state machine */
1087 lpfc_disc_state_machine(phba, ndlp, cmdiocb, 1246 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1088 NLP_EVT_CMPL_ADISC); 1247 NLP_EVT_CMPL_ADISC);
1089 } 1248 }
1090 1249
1091 if (disc && phba->num_disc_nodes) { 1250 if (disc && vport->num_disc_nodes) {
1092 /* Check to see if there are more ADISCs to be sent */ 1251 /* Check to see if there are more ADISCs to be sent */
1093 lpfc_more_adisc(phba); 1252 lpfc_more_adisc(vport);
1094 1253
1095 /* Check to see if we are done with ADISC authentication */ 1254 /* Check to see if we are done with ADISC authentication */
1096 if (phba->num_disc_nodes == 0) { 1255 if (vport->num_disc_nodes == 0) {
1097 lpfc_can_disctmo(phba); 1256 /* If we get here, there is nothing left to ADISC */
1098 /* If we get here, there is nothing left to wait for */ 1257 /*
1099 if ((phba->hba_state < LPFC_HBA_READY) && 1258 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1100 (phba->hba_state != LPFC_CLEAR_LA)) { 1259 * and continue discovery.
1101 /* Link up discovery */ 1260 */
1102 if ((mbox = mempool_alloc(phba->mbox_mem_pool, 1261 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1103 GFP_KERNEL))) { 1262 !(vport->fc_flag & FC_RSCN_MODE)) {
1104 phba->hba_state = LPFC_CLEAR_LA; 1263 lpfc_issue_reg_vpi(phba, vport);
1105 lpfc_clear_la(phba, mbox); 1264 goto out;
1106 mbox->mbox_cmpl = 1265 }
1107 lpfc_mbx_cmpl_clear_la; 1266 /*
1108 rc = lpfc_sli_issue_mbox 1267 * For SLI2, we need to set port_state to READY
1109 (phba, mbox, 1268 * and continue discovery.
1110 (MBX_NOWAIT | MBX_STOP_IOCB)); 1269 */
1111 if (rc == MBX_NOT_FINISHED) { 1270 if (vport->port_state < LPFC_VPORT_READY) {
1112 mempool_free(mbox, 1271 /* If we get here, there is nothing to ADISC */
1113 phba->mbox_mem_pool); 1272 if (vport->port_type == LPFC_PHYSICAL_PORT)
1114 lpfc_disc_flush_list(phba); 1273 lpfc_issue_clear_la(phba, vport);
1115 psli->ring[(psli->extra_ring)]. 1274
1116 flag &= 1275 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
1117 ~LPFC_STOP_IOCB_EVENT; 1276 vport->num_disc_nodes = 0;
1118 psli->ring[(psli->fcp_ring)]. 1277 /* go thru NPR list, issue ELS PLOGIs */
1119 flag &= 1278 if (vport->fc_npr_cnt)
1120 ~LPFC_STOP_IOCB_EVENT; 1279 lpfc_els_disc_plogi(vport);
1121 psli->ring[(psli->next_ring)]. 1280
1122 flag &= 1281 if (!vport->num_disc_nodes) {
1123 ~LPFC_STOP_IOCB_EVENT; 1282 spin_lock_irq(shost->host_lock);
1124 phba->hba_state = 1283 vport->fc_flag &=
1125 LPFC_HBA_READY; 1284 ~FC_NDISC_ACTIVE;
1285 spin_unlock_irq(
1286 shost->host_lock);
1287 lpfc_can_disctmo(vport);
1126 } 1288 }
1127 } 1289 }
1290 vport->port_state = LPFC_VPORT_READY;
1128 } else { 1291 } else {
1129 lpfc_rscn_disc(phba); 1292 lpfc_rscn_disc(vport);
1130 } 1293 }
1131 } 1294 }
1132 } 1295 }
@@ -1136,23 +1299,22 @@ out:
1136} 1299}
1137 1300
1138int 1301int
1139lpfc_issue_els_adisc(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, 1302lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1140 uint8_t retry) 1303 uint8_t retry)
1141{ 1304{
1305 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1306 struct lpfc_hba *phba = vport->phba;
1142 ADISC *ap; 1307 ADISC *ap;
1143 IOCB_t *icmd; 1308 IOCB_t *icmd;
1144 struct lpfc_iocbq *elsiocb; 1309 struct lpfc_iocbq *elsiocb;
1145 struct lpfc_sli_ring *pring; 1310 struct lpfc_sli *psli = &phba->sli;
1146 struct lpfc_sli *psli; 1311 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
1147 uint8_t *pcmd; 1312 uint8_t *pcmd;
1148 uint16_t cmdsize; 1313 uint16_t cmdsize;
1149 1314
1150 psli = &phba->sli; 1315 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
1151 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ 1316 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1152 1317 ndlp->nlp_DID, ELS_CMD_ADISC);
1153 cmdsize = (sizeof (uint32_t) + sizeof (ADISC));
1154 elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp,
1155 ndlp->nlp_DID, ELS_CMD_ADISC);
1156 if (!elsiocb) 1318 if (!elsiocb)
1157 return 1; 1319 return 1;
1158 1320
@@ -1161,81 +1323,97 @@ lpfc_issue_els_adisc(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
1161 1323
1162 /* For ADISC request, remainder of payload is service parameters */ 1324 /* For ADISC request, remainder of payload is service parameters */
1163 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC; 1325 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
1164 pcmd += sizeof (uint32_t); 1326 pcmd += sizeof(uint32_t);
1165 1327
1166 /* Fill in ADISC payload */ 1328 /* Fill in ADISC payload */
1167 ap = (ADISC *) pcmd; 1329 ap = (ADISC *) pcmd;
1168 ap->hardAL_PA = phba->fc_pref_ALPA; 1330 ap->hardAL_PA = phba->fc_pref_ALPA;
1169 memcpy(&ap->portName, &phba->fc_portname, sizeof (struct lpfc_name)); 1331 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
1170 memcpy(&ap->nodeName, &phba->fc_nodename, sizeof (struct lpfc_name)); 1332 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
1171 ap->DID = be32_to_cpu(phba->fc_myDID); 1333 ap->DID = be32_to_cpu(vport->fc_myDID);
1334
1335 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1336 "Issue ADISC: did:x%x",
1337 ndlp->nlp_DID, 0, 0);
1172 1338
1173 phba->fc_stat.elsXmitADISC++; 1339 phba->fc_stat.elsXmitADISC++;
1174 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc; 1340 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
1175 spin_lock_irq(phba->host->host_lock); 1341 spin_lock_irq(shost->host_lock);
1176 ndlp->nlp_flag |= NLP_ADISC_SND; 1342 ndlp->nlp_flag |= NLP_ADISC_SND;
1343 spin_unlock_irq(shost->host_lock);
1177 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { 1344 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1345 spin_lock_irq(shost->host_lock);
1178 ndlp->nlp_flag &= ~NLP_ADISC_SND; 1346 ndlp->nlp_flag &= ~NLP_ADISC_SND;
1179 spin_unlock_irq(phba->host->host_lock); 1347 spin_unlock_irq(shost->host_lock);
1180 lpfc_els_free_iocb(phba, elsiocb); 1348 lpfc_els_free_iocb(phba, elsiocb);
1181 return 1; 1349 return 1;
1182 } 1350 }
1183 spin_unlock_irq(phba->host->host_lock);
1184 return 0; 1351 return 0;
1185} 1352}
1186 1353
1187static void 1354static void
1188lpfc_cmpl_els_logo(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb, 1355lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1189 struct lpfc_iocbq * rspiocb) 1356 struct lpfc_iocbq *rspiocb)
1190{ 1357{
1358 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1359 struct lpfc_vport *vport = ndlp->vport;
1360 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1191 IOCB_t *irsp; 1361 IOCB_t *irsp;
1192 struct lpfc_sli *psli; 1362 struct lpfc_sli *psli;
1193 struct lpfc_nodelist *ndlp;
1194 1363
1195 psli = &phba->sli; 1364 psli = &phba->sli;
1196 /* we pass cmdiocb to state machine which needs rspiocb as well */ 1365 /* we pass cmdiocb to state machine which needs rspiocb as well */
1197 cmdiocb->context_un.rsp_iocb = rspiocb; 1366 cmdiocb->context_un.rsp_iocb = rspiocb;
1198 1367
1199 irsp = &(rspiocb->iocb); 1368 irsp = &(rspiocb->iocb);
1200 ndlp = (struct lpfc_nodelist *) cmdiocb->context1; 1369 spin_lock_irq(shost->host_lock);
1201 spin_lock_irq(phba->host->host_lock);
1202 ndlp->nlp_flag &= ~NLP_LOGO_SND; 1370 ndlp->nlp_flag &= ~NLP_LOGO_SND;
1203 spin_unlock_irq(phba->host->host_lock); 1371 spin_unlock_irq(shost->host_lock);
1372
1373 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1374 "LOGO cmpl: status:x%x/x%x did:x%x",
1375 irsp->ulpStatus, irsp->un.ulpWord[4],
1376 ndlp->nlp_DID);
1204 1377
1205 /* LOGO completes to NPort <nlp_DID> */ 1378 /* LOGO completes to NPort <nlp_DID> */
1206 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 1379 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1207 "%d:0105 LOGO completes to NPort x%x " 1380 "%d (%d):0105 LOGO completes to NPort x%x "
1208 "Data: x%x x%x x%x x%x\n", 1381 "Data: x%x x%x x%x x%x\n",
1209 phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus, 1382 phba->brd_no, vport->vpi, ndlp->nlp_DID,
1210 irsp->un.ulpWord[4], irsp->ulpTimeout, 1383 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->ulpTimeout,
1211 phba->num_disc_nodes); 1384 vport->num_disc_nodes);
1212 1385
1213 /* Check to see if link went down during discovery */ 1386 /* Check to see if link went down during discovery */
1214 if (lpfc_els_chk_latt(phba)) 1387 if (lpfc_els_chk_latt(vport))
1215 goto out; 1388 goto out;
1216 1389
1390 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
1391 /* NLP_EVT_DEVICE_RM should unregister the RPI
1392 * which should abort all outstanding IOs.
1393 */
1394 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1395 NLP_EVT_DEVICE_RM);
1396 goto out;
1397 }
1398
1217 if (irsp->ulpStatus) { 1399 if (irsp->ulpStatus) {
1218 /* Check for retry */ 1400 /* Check for retry */
1219 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { 1401 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
1220 /* ELS command is being retried */ 1402 /* ELS command is being retried */
1221 goto out; 1403 goto out;
1222 }
1223 /* LOGO failed */ 1404 /* LOGO failed */
1224 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ 1405 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1225 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && 1406 if (lpfc_error_lost_link(irsp))
1226 ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
1227 (irsp->un.ulpWord[4] == IOERR_LINK_DOWN) ||
1228 (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) {
1229 goto out; 1407 goto out;
1230 } else { 1408 else
1231 lpfc_disc_state_machine(phba, ndlp, cmdiocb, 1409 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1232 NLP_EVT_CMPL_LOGO); 1410 NLP_EVT_CMPL_LOGO);
1233 }
1234 } else { 1411 } else {
1235 /* Good status, call state machine. 1412 /* Good status, call state machine.
1236 * This will unregister the rpi if needed. 1413 * This will unregister the rpi if needed.
1237 */ 1414 */
1238 lpfc_disc_state_machine(phba, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO); 1415 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1416 NLP_EVT_CMPL_LOGO);
1239 } 1417 }
1240 1418
1241out: 1419out:
@@ -1244,75 +1422,91 @@ out:
1244} 1422}
1245 1423
1246int 1424int
1247lpfc_issue_els_logo(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, 1425lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1248 uint8_t retry) 1426 uint8_t retry)
1249{ 1427{
1428 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1429 struct lpfc_hba *phba = vport->phba;
1250 IOCB_t *icmd; 1430 IOCB_t *icmd;
1251 struct lpfc_iocbq *elsiocb; 1431 struct lpfc_iocbq *elsiocb;
1252 struct lpfc_sli_ring *pring; 1432 struct lpfc_sli_ring *pring;
1253 struct lpfc_sli *psli; 1433 struct lpfc_sli *psli;
1254 uint8_t *pcmd; 1434 uint8_t *pcmd;
1255 uint16_t cmdsize; 1435 uint16_t cmdsize;
1436 int rc;
1256 1437
1257 psli = &phba->sli; 1438 psli = &phba->sli;
1258 pring = &psli->ring[LPFC_ELS_RING]; 1439 pring = &psli->ring[LPFC_ELS_RING];
1259 1440
1260 cmdsize = (2 * sizeof (uint32_t)) + sizeof (struct lpfc_name); 1441 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
1261 elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp, 1442 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1262 ndlp->nlp_DID, ELS_CMD_LOGO); 1443 ndlp->nlp_DID, ELS_CMD_LOGO);
1263 if (!elsiocb) 1444 if (!elsiocb)
1264 return 1; 1445 return 1;
1265 1446
1266 icmd = &elsiocb->iocb; 1447 icmd = &elsiocb->iocb;
1267 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); 1448 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1268 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; 1449 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
1269 pcmd += sizeof (uint32_t); 1450 pcmd += sizeof(uint32_t);
1270 1451
1271 /* Fill in LOGO payload */ 1452 /* Fill in LOGO payload */
1272 *((uint32_t *) (pcmd)) = be32_to_cpu(phba->fc_myDID); 1453 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
1273 pcmd += sizeof (uint32_t); 1454 pcmd += sizeof(uint32_t);
1274 memcpy(pcmd, &phba->fc_portname, sizeof (struct lpfc_name)); 1455 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
1456
1457 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1458 "Issue LOGO: did:x%x",
1459 ndlp->nlp_DID, 0, 0);
1275 1460
1276 phba->fc_stat.elsXmitLOGO++; 1461 phba->fc_stat.elsXmitLOGO++;
1277 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo; 1462 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
1278 spin_lock_irq(phba->host->host_lock); 1463 spin_lock_irq(shost->host_lock);
1279 ndlp->nlp_flag |= NLP_LOGO_SND; 1464 ndlp->nlp_flag |= NLP_LOGO_SND;
1280 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { 1465 spin_unlock_irq(shost->host_lock);
1466 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
1467
1468 if (rc == IOCB_ERROR) {
1469 spin_lock_irq(shost->host_lock);
1281 ndlp->nlp_flag &= ~NLP_LOGO_SND; 1470 ndlp->nlp_flag &= ~NLP_LOGO_SND;
1282 spin_unlock_irq(phba->host->host_lock); 1471 spin_unlock_irq(shost->host_lock);
1283 lpfc_els_free_iocb(phba, elsiocb); 1472 lpfc_els_free_iocb(phba, elsiocb);
1284 return 1; 1473 return 1;
1285 } 1474 }
1286 spin_unlock_irq(phba->host->host_lock);
1287 return 0; 1475 return 0;
1288} 1476}
1289 1477
1290static void 1478static void
1291lpfc_cmpl_els_cmd(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb, 1479lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1292 struct lpfc_iocbq * rspiocb) 1480 struct lpfc_iocbq *rspiocb)
1293{ 1481{
1482 struct lpfc_vport *vport = cmdiocb->vport;
1294 IOCB_t *irsp; 1483 IOCB_t *irsp;
1295 1484
1296 irsp = &rspiocb->iocb; 1485 irsp = &rspiocb->iocb;
1297 1486
1487 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1488 "ELS cmd cmpl: status:x%x/x%x did:x%x",
1489 irsp->ulpStatus, irsp->un.ulpWord[4],
1490 irsp->un.elsreq64.remoteID);
1491
1298 /* ELS cmd tag <ulpIoTag> completes */ 1492 /* ELS cmd tag <ulpIoTag> completes */
1299 lpfc_printf_log(phba, 1493 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1300 KERN_INFO, 1494 "%d (%d):0106 ELS cmd tag x%x completes Data: x%x x%x "
1301 LOG_ELS, 1495 "x%x\n",
1302 "%d:0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n", 1496 phba->brd_no, vport->vpi,
1303 phba->brd_no,
1304 irsp->ulpIoTag, irsp->ulpStatus, 1497 irsp->ulpIoTag, irsp->ulpStatus,
1305 irsp->un.ulpWord[4], irsp->ulpTimeout); 1498 irsp->un.ulpWord[4], irsp->ulpTimeout);
1306 1499
1307 /* Check to see if link went down during discovery */ 1500 /* Check to see if link went down during discovery */
1308 lpfc_els_chk_latt(phba); 1501 lpfc_els_chk_latt(vport);
1309 lpfc_els_free_iocb(phba, cmdiocb); 1502 lpfc_els_free_iocb(phba, cmdiocb);
1310 return; 1503 return;
1311} 1504}
1312 1505
1313int 1506int
1314lpfc_issue_els_scr(struct lpfc_hba * phba, uint32_t nportid, uint8_t retry) 1507lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
1315{ 1508{
1509 struct lpfc_hba *phba = vport->phba;
1316 IOCB_t *icmd; 1510 IOCB_t *icmd;
1317 struct lpfc_iocbq *elsiocb; 1511 struct lpfc_iocbq *elsiocb;
1318 struct lpfc_sli_ring *pring; 1512 struct lpfc_sli_ring *pring;
@@ -1323,15 +1517,16 @@ lpfc_issue_els_scr(struct lpfc_hba * phba, uint32_t nportid, uint8_t retry)
1323 1517
1324 psli = &phba->sli; 1518 psli = &phba->sli;
1325 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ 1519 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1326 cmdsize = (sizeof (uint32_t) + sizeof (SCR)); 1520 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
1327 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); 1521 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1328 if (!ndlp) 1522 if (!ndlp)
1329 return 1; 1523 return 1;
1330 1524
1331 lpfc_nlp_init(phba, ndlp, nportid); 1525 lpfc_nlp_init(vport, ndlp, nportid);
1526
1527 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1528 ndlp->nlp_DID, ELS_CMD_SCR);
1332 1529
1333 elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp,
1334 ndlp->nlp_DID, ELS_CMD_SCR);
1335 if (!elsiocb) { 1530 if (!elsiocb) {
1336 lpfc_nlp_put(ndlp); 1531 lpfc_nlp_put(ndlp);
1337 return 1; 1532 return 1;
@@ -1341,29 +1536,31 @@ lpfc_issue_els_scr(struct lpfc_hba * phba, uint32_t nportid, uint8_t retry)
1341 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); 1536 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1342 1537
1343 *((uint32_t *) (pcmd)) = ELS_CMD_SCR; 1538 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
1344 pcmd += sizeof (uint32_t); 1539 pcmd += sizeof(uint32_t);
1345 1540
1346 /* For SCR, remainder of payload is SCR parameter page */ 1541 /* For SCR, remainder of payload is SCR parameter page */
1347 memset(pcmd, 0, sizeof (SCR)); 1542 memset(pcmd, 0, sizeof(SCR));
1348 ((SCR *) pcmd)->Function = SCR_FUNC_FULL; 1543 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
1349 1544
1545 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1546 "Issue SCR: did:x%x",
1547 ndlp->nlp_DID, 0, 0);
1548
1350 phba->fc_stat.elsXmitSCR++; 1549 phba->fc_stat.elsXmitSCR++;
1351 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; 1550 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
1352 spin_lock_irq(phba->host->host_lock);
1353 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { 1551 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1354 spin_unlock_irq(phba->host->host_lock);
1355 lpfc_nlp_put(ndlp); 1552 lpfc_nlp_put(ndlp);
1356 lpfc_els_free_iocb(phba, elsiocb); 1553 lpfc_els_free_iocb(phba, elsiocb);
1357 return 1; 1554 return 1;
1358 } 1555 }
1359 spin_unlock_irq(phba->host->host_lock);
1360 lpfc_nlp_put(ndlp); 1556 lpfc_nlp_put(ndlp);
1361 return 0; 1557 return 0;
1362} 1558}
1363 1559
1364static int 1560static int
1365lpfc_issue_els_farpr(struct lpfc_hba * phba, uint32_t nportid, uint8_t retry) 1561lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
1366{ 1562{
1563 struct lpfc_hba *phba = vport->phba;
1367 IOCB_t *icmd; 1564 IOCB_t *icmd;
1368 struct lpfc_iocbq *elsiocb; 1565 struct lpfc_iocbq *elsiocb;
1369 struct lpfc_sli_ring *pring; 1566 struct lpfc_sli_ring *pring;
@@ -1377,14 +1574,15 @@ lpfc_issue_els_farpr(struct lpfc_hba * phba, uint32_t nportid, uint8_t retry)
1377 1574
1378 psli = &phba->sli; 1575 psli = &phba->sli;
1379 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ 1576 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1380 cmdsize = (sizeof (uint32_t) + sizeof (FARP)); 1577 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
1381 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); 1578 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1382 if (!ndlp) 1579 if (!ndlp)
1383 return 1; 1580 return 1;
1384 lpfc_nlp_init(phba, ndlp, nportid);
1385 1581
1386 elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp, 1582 lpfc_nlp_init(vport, ndlp, nportid);
1387 ndlp->nlp_DID, ELS_CMD_RNID); 1583
1584 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1585 ndlp->nlp_DID, ELS_CMD_RNID);
1388 if (!elsiocb) { 1586 if (!elsiocb) {
1389 lpfc_nlp_put(ndlp); 1587 lpfc_nlp_put(ndlp);
1390 return 1; 1588 return 1;
@@ -1394,44 +1592,71 @@ lpfc_issue_els_farpr(struct lpfc_hba * phba, uint32_t nportid, uint8_t retry)
1394 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); 1592 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1395 1593
1396 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR; 1594 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
1397 pcmd += sizeof (uint32_t); 1595 pcmd += sizeof(uint32_t);
1398 1596
1399 /* Fill in FARPR payload */ 1597 /* Fill in FARPR payload */
1400 fp = (FARP *) (pcmd); 1598 fp = (FARP *) (pcmd);
1401 memset(fp, 0, sizeof (FARP)); 1599 memset(fp, 0, sizeof(FARP));
1402 lp = (uint32_t *) pcmd; 1600 lp = (uint32_t *) pcmd;
1403 *lp++ = be32_to_cpu(nportid); 1601 *lp++ = be32_to_cpu(nportid);
1404 *lp++ = be32_to_cpu(phba->fc_myDID); 1602 *lp++ = be32_to_cpu(vport->fc_myDID);
1405 fp->Rflags = 0; 1603 fp->Rflags = 0;
1406 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE); 1604 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
1407 1605
1408 memcpy(&fp->RportName, &phba->fc_portname, sizeof (struct lpfc_name)); 1606 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
1409 memcpy(&fp->RnodeName, &phba->fc_nodename, sizeof (struct lpfc_name)); 1607 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
1410 if ((ondlp = lpfc_findnode_did(phba, nportid))) { 1608 ondlp = lpfc_findnode_did(vport, nportid);
1609 if (ondlp) {
1411 memcpy(&fp->OportName, &ondlp->nlp_portname, 1610 memcpy(&fp->OportName, &ondlp->nlp_portname,
1412 sizeof (struct lpfc_name)); 1611 sizeof(struct lpfc_name));
1413 memcpy(&fp->OnodeName, &ondlp->nlp_nodename, 1612 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
1414 sizeof (struct lpfc_name)); 1613 sizeof(struct lpfc_name));
1415 } 1614 }
1416 1615
1616 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1617 "Issue FARPR: did:x%x",
1618 ndlp->nlp_DID, 0, 0);
1619
1417 phba->fc_stat.elsXmitFARPR++; 1620 phba->fc_stat.elsXmitFARPR++;
1418 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd; 1621 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
1419 spin_lock_irq(phba->host->host_lock);
1420 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { 1622 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1421 spin_unlock_irq(phba->host->host_lock);
1422 lpfc_nlp_put(ndlp); 1623 lpfc_nlp_put(ndlp);
1423 lpfc_els_free_iocb(phba, elsiocb); 1624 lpfc_els_free_iocb(phba, elsiocb);
1424 return 1; 1625 return 1;
1425 } 1626 }
1426 spin_unlock_irq(phba->host->host_lock);
1427 lpfc_nlp_put(ndlp); 1627 lpfc_nlp_put(ndlp);
1428 return 0; 1628 return 0;
1429} 1629}
1430 1630
1631static void
1632lpfc_end_rscn(struct lpfc_vport *vport)
1633{
1634 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1635
1636 if (vport->fc_flag & FC_RSCN_MODE) {
1637 /*
1638 * Check to see if more RSCNs came in while we were
1639 * processing this one.
1640 */
1641 if (vport->fc_rscn_id_cnt ||
1642 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1643 lpfc_els_handle_rscn(vport);
1644 else {
1645 spin_lock_irq(shost->host_lock);
1646 vport->fc_flag &= ~FC_RSCN_MODE;
1647 spin_unlock_irq(shost->host_lock);
1648 }
1649 }
1650}
1651
1431void 1652void
1432lpfc_cancel_retry_delay_tmo(struct lpfc_hba *phba, struct lpfc_nodelist * nlp) 1653lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
1433{ 1654{
1655 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1656
1657 spin_lock_irq(shost->host_lock);
1434 nlp->nlp_flag &= ~NLP_DELAY_TMO; 1658 nlp->nlp_flag &= ~NLP_DELAY_TMO;
1659 spin_unlock_irq(shost->host_lock);
1435 del_timer_sync(&nlp->nlp_delayfunc); 1660 del_timer_sync(&nlp->nlp_delayfunc);
1436 nlp->nlp_last_elscmd = 0; 1661 nlp->nlp_last_elscmd = 0;
1437 1662
@@ -1439,30 +1664,21 @@ lpfc_cancel_retry_delay_tmo(struct lpfc_hba *phba, struct lpfc_nodelist * nlp)
1439 list_del_init(&nlp->els_retry_evt.evt_listp); 1664 list_del_init(&nlp->els_retry_evt.evt_listp);
1440 1665
1441 if (nlp->nlp_flag & NLP_NPR_2B_DISC) { 1666 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
1667 spin_lock_irq(shost->host_lock);
1442 nlp->nlp_flag &= ~NLP_NPR_2B_DISC; 1668 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1443 if (phba->num_disc_nodes) { 1669 spin_unlock_irq(shost->host_lock);
1670 if (vport->num_disc_nodes) {
1444 /* Check to see if there are more 1671 /* Check to see if there are more
1445 * PLOGIs to be sent 1672 * PLOGIs to be sent
1446 */ 1673 */
1447 lpfc_more_plogi(phba); 1674 lpfc_more_plogi(vport);
1448 1675
1449 if (phba->num_disc_nodes == 0) { 1676 if (vport->num_disc_nodes == 0) {
1450 phba->fc_flag &= ~FC_NDISC_ACTIVE; 1677 spin_lock_irq(shost->host_lock);
1451 lpfc_can_disctmo(phba); 1678 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1452 if (phba->fc_flag & FC_RSCN_MODE) { 1679 spin_unlock_irq(shost->host_lock);
1453 /* 1680 lpfc_can_disctmo(vport);
1454 * Check to see if more RSCNs 1681 lpfc_end_rscn(vport);
1455 * came in while we were
1456 * processing this one.
1457 */
1458 if((phba->fc_rscn_id_cnt==0) &&
1459 !(phba->fc_flag & FC_RSCN_DISCOVERY)) {
1460 phba->fc_flag &= ~FC_RSCN_MODE;
1461 }
1462 else {
1463 lpfc_els_handle_rscn(phba);
1464 }
1465 }
1466 } 1682 }
1467 } 1683 }
1468 } 1684 }
@@ -1472,18 +1688,19 @@ lpfc_cancel_retry_delay_tmo(struct lpfc_hba *phba, struct lpfc_nodelist * nlp)
1472void 1688void
1473lpfc_els_retry_delay(unsigned long ptr) 1689lpfc_els_retry_delay(unsigned long ptr)
1474{ 1690{
1475 struct lpfc_nodelist *ndlp; 1691 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
1476 struct lpfc_hba *phba; 1692 struct lpfc_vport *vport = ndlp->vport;
1477 unsigned long iflag; 1693 struct lpfc_hba *phba = vport->phba;
1478 struct lpfc_work_evt *evtp; 1694 unsigned long flags;
1479 1695 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
1480 ndlp = (struct lpfc_nodelist *)ptr; 1696
1481 phba = ndlp->nlp_phba; 1697 ndlp = (struct lpfc_nodelist *) ptr;
1698 phba = ndlp->vport->phba;
1482 evtp = &ndlp->els_retry_evt; 1699 evtp = &ndlp->els_retry_evt;
1483 1700
1484 spin_lock_irqsave(phba->host->host_lock, iflag); 1701 spin_lock_irqsave(&phba->hbalock, flags);
1485 if (!list_empty(&evtp->evt_listp)) { 1702 if (!list_empty(&evtp->evt_listp)) {
1486 spin_unlock_irqrestore(phba->host->host_lock, iflag); 1703 spin_unlock_irqrestore(&phba->hbalock, flags);
1487 return; 1704 return;
1488 } 1705 }
1489 1706
@@ -1491,33 +1708,31 @@ lpfc_els_retry_delay(unsigned long ptr)
1491 evtp->evt = LPFC_EVT_ELS_RETRY; 1708 evtp->evt = LPFC_EVT_ELS_RETRY;
1492 list_add_tail(&evtp->evt_listp, &phba->work_list); 1709 list_add_tail(&evtp->evt_listp, &phba->work_list);
1493 if (phba->work_wait) 1710 if (phba->work_wait)
1494 wake_up(phba->work_wait); 1711 lpfc_worker_wake_up(phba);
1495 1712
1496 spin_unlock_irqrestore(phba->host->host_lock, iflag); 1713 spin_unlock_irqrestore(&phba->hbalock, flags);
1497 return; 1714 return;
1498} 1715}
1499 1716
1500void 1717void
1501lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp) 1718lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
1502{ 1719{
1503 struct lpfc_hba *phba; 1720 struct lpfc_vport *vport = ndlp->vport;
1504 uint32_t cmd; 1721 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1505 uint32_t did; 1722 uint32_t cmd, did, retry;
1506 uint8_t retry;
1507 1723
1508 phba = ndlp->nlp_phba; 1724 spin_lock_irq(shost->host_lock);
1509 spin_lock_irq(phba->host->host_lock);
1510 did = ndlp->nlp_DID; 1725 did = ndlp->nlp_DID;
1511 cmd = ndlp->nlp_last_elscmd; 1726 cmd = ndlp->nlp_last_elscmd;
1512 ndlp->nlp_last_elscmd = 0; 1727 ndlp->nlp_last_elscmd = 0;
1513 1728
1514 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) { 1729 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1515 spin_unlock_irq(phba->host->host_lock); 1730 spin_unlock_irq(shost->host_lock);
1516 return; 1731 return;
1517 } 1732 }
1518 1733
1519 ndlp->nlp_flag &= ~NLP_DELAY_TMO; 1734 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
1520 spin_unlock_irq(phba->host->host_lock); 1735 spin_unlock_irq(shost->host_lock);
1521 /* 1736 /*
1522 * If a discovery event readded nlp_delayfunc after timer 1737 * If a discovery event readded nlp_delayfunc after timer
1523 * firing and before processing the timer, cancel the 1738 * firing and before processing the timer, cancel the
@@ -1528,57 +1743,54 @@ lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
1528 1743
1529 switch (cmd) { 1744 switch (cmd) {
1530 case ELS_CMD_FLOGI: 1745 case ELS_CMD_FLOGI:
1531 lpfc_issue_els_flogi(phba, ndlp, retry); 1746 lpfc_issue_els_flogi(vport, ndlp, retry);
1532 break; 1747 break;
1533 case ELS_CMD_PLOGI: 1748 case ELS_CMD_PLOGI:
1534 if(!lpfc_issue_els_plogi(phba, ndlp->nlp_DID, retry)) { 1749 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
1535 ndlp->nlp_prev_state = ndlp->nlp_state; 1750 ndlp->nlp_prev_state = ndlp->nlp_state;
1536 lpfc_nlp_set_state(phba, ndlp, NLP_STE_PLOGI_ISSUE); 1751 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1537 } 1752 }
1538 break; 1753 break;
1539 case ELS_CMD_ADISC: 1754 case ELS_CMD_ADISC:
1540 if (!lpfc_issue_els_adisc(phba, ndlp, retry)) { 1755 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
1541 ndlp->nlp_prev_state = ndlp->nlp_state; 1756 ndlp->nlp_prev_state = ndlp->nlp_state;
1542 lpfc_nlp_set_state(phba, ndlp, NLP_STE_ADISC_ISSUE); 1757 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
1543 } 1758 }
1544 break; 1759 break;
1545 case ELS_CMD_PRLI: 1760 case ELS_CMD_PRLI:
1546 if (!lpfc_issue_els_prli(phba, ndlp, retry)) { 1761 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
1547 ndlp->nlp_prev_state = ndlp->nlp_state; 1762 ndlp->nlp_prev_state = ndlp->nlp_state;
1548 lpfc_nlp_set_state(phba, ndlp, NLP_STE_PRLI_ISSUE); 1763 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1549 } 1764 }
1550 break; 1765 break;
1551 case ELS_CMD_LOGO: 1766 case ELS_CMD_LOGO:
1552 if (!lpfc_issue_els_logo(phba, ndlp, retry)) { 1767 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
1553 ndlp->nlp_prev_state = ndlp->nlp_state; 1768 ndlp->nlp_prev_state = ndlp->nlp_state;
1554 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE); 1769 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1555 } 1770 }
1556 break; 1771 break;
1772 case ELS_CMD_FDISC:
1773 lpfc_issue_els_fdisc(vport, ndlp, retry);
1774 break;
1557 } 1775 }
1558 return; 1776 return;
1559} 1777}
1560 1778
1561static int 1779static int
1562lpfc_els_retry(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb, 1780lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1563 struct lpfc_iocbq * rspiocb) 1781 struct lpfc_iocbq *rspiocb)
1564{ 1782{
1565 IOCB_t *irsp; 1783 struct lpfc_vport *vport = cmdiocb->vport;
1566 struct lpfc_dmabuf *pcmd; 1784 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1567 struct lpfc_nodelist *ndlp; 1785 IOCB_t *irsp = &rspiocb->iocb;
1786 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1787 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
1568 uint32_t *elscmd; 1788 uint32_t *elscmd;
1569 struct ls_rjt stat; 1789 struct ls_rjt stat;
1570 int retry, maxretry; 1790 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
1571 int delay; 1791 uint32_t cmd = 0;
1572 uint32_t cmd;
1573 uint32_t did; 1792 uint32_t did;
1574 1793
1575 retry = 0;
1576 delay = 0;
1577 maxretry = lpfc_max_els_tries;
1578 irsp = &rspiocb->iocb;
1579 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1580 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
1581 cmd = 0;
1582 1794
1583 /* Note: context2 may be 0 for internal driver abort 1795 /* Note: context2 may be 0 for internal driver abort
1584 * of delays ELS command. 1796 * of delays ELS command.
@@ -1594,11 +1806,15 @@ lpfc_els_retry(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1594 else { 1806 else {
1595 /* We should only hit this case for retrying PLOGI */ 1807 /* We should only hit this case for retrying PLOGI */
1596 did = irsp->un.elsreq64.remoteID; 1808 did = irsp->un.elsreq64.remoteID;
1597 ndlp = lpfc_findnode_did(phba, did); 1809 ndlp = lpfc_findnode_did(vport, did);
1598 if (!ndlp && (cmd != ELS_CMD_PLOGI)) 1810 if (!ndlp && (cmd != ELS_CMD_PLOGI))
1599 return 1; 1811 return 1;
1600 } 1812 }
1601 1813
1814 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1815 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
1816 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
1817
1602 switch (irsp->ulpStatus) { 1818 switch (irsp->ulpStatus) {
1603 case IOSTAT_FCP_RSP_ERROR: 1819 case IOSTAT_FCP_RSP_ERROR:
1604 case IOSTAT_REMOTE_STOP: 1820 case IOSTAT_REMOTE_STOP:
@@ -1607,25 +1823,37 @@ lpfc_els_retry(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1607 case IOSTAT_LOCAL_REJECT: 1823 case IOSTAT_LOCAL_REJECT:
1608 switch ((irsp->un.ulpWord[4] & 0xff)) { 1824 switch ((irsp->un.ulpWord[4] & 0xff)) {
1609 case IOERR_LOOP_OPEN_FAILURE: 1825 case IOERR_LOOP_OPEN_FAILURE:
1610 if (cmd == ELS_CMD_PLOGI) { 1826 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
1611 if (cmdiocb->retry == 0) { 1827 delay = 1000;
1612 delay = 1;
1613 }
1614 }
1615 retry = 1; 1828 retry = 1;
1616 break; 1829 break;
1617 1830
1618 case IOERR_SEQUENCE_TIMEOUT: 1831 case IOERR_ILLEGAL_COMMAND:
1619 retry = 1; 1832 if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) &&
1833 (cmd == ELS_CMD_FDISC)) {
1834 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
1835 "%d (%d):0124 FDISC failed (3/6) retrying...\n",
1836 phba->brd_no, vport->vpi);
1837 lpfc_mbx_unreg_vpi(vport);
1838 retry = 1;
1839 /* Always retry for this case */
1840 cmdiocb->retry = 0;
1841 }
1620 break; 1842 break;
1621 1843
1622 case IOERR_NO_RESOURCES: 1844 case IOERR_NO_RESOURCES:
1623 if (cmd == ELS_CMD_PLOGI) { 1845 retry = 1;
1624 delay = 1; 1846 if (cmdiocb->retry > 100)
1625 } 1847 delay = 100;
1848 maxretry = 250;
1849 break;
1850
1851 case IOERR_ILLEGAL_FRAME:
1852 delay = 100;
1626 retry = 1; 1853 retry = 1;
1627 break; 1854 break;
1628 1855
1856 case IOERR_SEQUENCE_TIMEOUT:
1629 case IOERR_INVALID_RPI: 1857 case IOERR_INVALID_RPI:
1630 retry = 1; 1858 retry = 1;
1631 break; 1859 break;
@@ -1655,27 +1883,57 @@ lpfc_els_retry(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1655 if (stat.un.b.lsRjtRsnCodeExp == 1883 if (stat.un.b.lsRjtRsnCodeExp ==
1656 LSEXP_CMD_IN_PROGRESS) { 1884 LSEXP_CMD_IN_PROGRESS) {
1657 if (cmd == ELS_CMD_PLOGI) { 1885 if (cmd == ELS_CMD_PLOGI) {
1658 delay = 1; 1886 delay = 1000;
1659 maxretry = 48; 1887 maxretry = 48;
1660 } 1888 }
1661 retry = 1; 1889 retry = 1;
1662 break; 1890 break;
1663 } 1891 }
1664 if (cmd == ELS_CMD_PLOGI) { 1892 if (cmd == ELS_CMD_PLOGI) {
1665 delay = 1; 1893 delay = 1000;
1666 maxretry = lpfc_max_els_tries + 1; 1894 maxretry = lpfc_max_els_tries + 1;
1667 retry = 1; 1895 retry = 1;
1668 break; 1896 break;
1669 } 1897 }
1898 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1899 (cmd == ELS_CMD_FDISC) &&
1900 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
1901 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
1902 "%d (%d):0125 FDISC Failed (x%x)."
1903 " Fabric out of resources\n",
1904 phba->brd_no, vport->vpi, stat.un.lsRjtError);
1905 lpfc_vport_set_state(vport,
1906 FC_VPORT_NO_FABRIC_RSCS);
1907 }
1670 break; 1908 break;
1671 1909
1672 case LSRJT_LOGICAL_BSY: 1910 case LSRJT_LOGICAL_BSY:
1673 if (cmd == ELS_CMD_PLOGI) { 1911 if ((cmd == ELS_CMD_PLOGI) ||
1674 delay = 1; 1912 (cmd == ELS_CMD_PRLI)) {
1913 delay = 1000;
1675 maxretry = 48; 1914 maxretry = 48;
1915 } else if (cmd == ELS_CMD_FDISC) {
1916 /* Always retry for this case */
1917 cmdiocb->retry = 0;
1676 } 1918 }
1677 retry = 1; 1919 retry = 1;
1678 break; 1920 break;
1921
1922 case LSRJT_LOGICAL_ERR:
1923 case LSRJT_PROTOCOL_ERR:
1924 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1925 (cmd == ELS_CMD_FDISC) &&
1926 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
1927 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
1928 ) {
1929 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
1930 "%d (%d):0123 FDISC Failed (x%x)."
1931 " Fabric Detected Bad WWN\n",
1932 phba->brd_no, vport->vpi, stat.un.lsRjtError);
1933 lpfc_vport_set_state(vport,
1934 FC_VPORT_FABRIC_REJ_WWN);
1935 }
1936 break;
1679 } 1937 }
1680 break; 1938 break;
1681 1939
@@ -1695,21 +1953,27 @@ lpfc_els_retry(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1695 retry = 0; 1953 retry = 0;
1696 } 1954 }
1697 1955
1956 if ((vport->load_flag & FC_UNLOADING) != 0)
1957 retry = 0;
1958
1698 if (retry) { 1959 if (retry) {
1699 1960
1700 /* Retry ELS command <elsCmd> to remote NPORT <did> */ 1961 /* Retry ELS command <elsCmd> to remote NPORT <did> */
1701 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 1962 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1702 "%d:0107 Retry ELS command x%x to remote " 1963 "%d (%d):0107 Retry ELS command x%x to remote "
1703 "NPORT x%x Data: x%x x%x\n", 1964 "NPORT x%x Data: x%x x%x\n",
1704 phba->brd_no, 1965 phba->brd_no, vport->vpi,
1705 cmd, did, cmdiocb->retry, delay); 1966 cmd, did, cmdiocb->retry, delay);
1706 1967
1707 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) { 1968 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
1969 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1970 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
1971 /* Don't reset timer for no resources */
1972
1708 /* If discovery / RSCN timer is running, reset it */ 1973 /* If discovery / RSCN timer is running, reset it */
1709 if (timer_pending(&phba->fc_disctmo) || 1974 if (timer_pending(&vport->fc_disctmo) ||
1710 (phba->fc_flag & FC_RSCN_MODE)) { 1975 (vport->fc_flag & FC_RSCN_MODE))
1711 lpfc_set_disctmo(phba); 1976 lpfc_set_disctmo(vport);
1712 }
1713 } 1977 }
1714 1978
1715 phba->fc_stat.elsXmitRetry++; 1979 phba->fc_stat.elsXmitRetry++;
@@ -1717,50 +1981,62 @@ lpfc_els_retry(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1717 phba->fc_stat.elsDelayRetry++; 1981 phba->fc_stat.elsDelayRetry++;
1718 ndlp->nlp_retry = cmdiocb->retry; 1982 ndlp->nlp_retry = cmdiocb->retry;
1719 1983
1720 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ); 1984 /* delay is specified in milliseconds */
1985 mod_timer(&ndlp->nlp_delayfunc,
1986 jiffies + msecs_to_jiffies(delay));
1987 spin_lock_irq(shost->host_lock);
1721 ndlp->nlp_flag |= NLP_DELAY_TMO; 1988 ndlp->nlp_flag |= NLP_DELAY_TMO;
1989 spin_unlock_irq(shost->host_lock);
1722 1990
1723 ndlp->nlp_prev_state = ndlp->nlp_state; 1991 ndlp->nlp_prev_state = ndlp->nlp_state;
1724 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE); 1992 if (cmd == ELS_CMD_PRLI)
1993 lpfc_nlp_set_state(vport, ndlp,
1994 NLP_STE_REG_LOGIN_ISSUE);
1995 else
1996 lpfc_nlp_set_state(vport, ndlp,
1997 NLP_STE_NPR_NODE);
1725 ndlp->nlp_last_elscmd = cmd; 1998 ndlp->nlp_last_elscmd = cmd;
1726 1999
1727 return 1; 2000 return 1;
1728 } 2001 }
1729 switch (cmd) { 2002 switch (cmd) {
1730 case ELS_CMD_FLOGI: 2003 case ELS_CMD_FLOGI:
1731 lpfc_issue_els_flogi(phba, ndlp, cmdiocb->retry); 2004 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
2005 return 1;
2006 case ELS_CMD_FDISC:
2007 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
1732 return 1; 2008 return 1;
1733 case ELS_CMD_PLOGI: 2009 case ELS_CMD_PLOGI:
1734 if (ndlp) { 2010 if (ndlp) {
1735 ndlp->nlp_prev_state = ndlp->nlp_state; 2011 ndlp->nlp_prev_state = ndlp->nlp_state;
1736 lpfc_nlp_set_state(phba, ndlp, 2012 lpfc_nlp_set_state(vport, ndlp,
1737 NLP_STE_PLOGI_ISSUE); 2013 NLP_STE_PLOGI_ISSUE);
1738 } 2014 }
1739 lpfc_issue_els_plogi(phba, did, cmdiocb->retry); 2015 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
1740 return 1; 2016 return 1;
1741 case ELS_CMD_ADISC: 2017 case ELS_CMD_ADISC:
1742 ndlp->nlp_prev_state = ndlp->nlp_state; 2018 ndlp->nlp_prev_state = ndlp->nlp_state;
1743 lpfc_nlp_set_state(phba, ndlp, NLP_STE_ADISC_ISSUE); 2019 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
1744 lpfc_issue_els_adisc(phba, ndlp, cmdiocb->retry); 2020 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
1745 return 1; 2021 return 1;
1746 case ELS_CMD_PRLI: 2022 case ELS_CMD_PRLI:
1747 ndlp->nlp_prev_state = ndlp->nlp_state; 2023 ndlp->nlp_prev_state = ndlp->nlp_state;
1748 lpfc_nlp_set_state(phba, ndlp, NLP_STE_PRLI_ISSUE); 2024 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1749 lpfc_issue_els_prli(phba, ndlp, cmdiocb->retry); 2025 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
1750 return 1; 2026 return 1;
1751 case ELS_CMD_LOGO: 2027 case ELS_CMD_LOGO:
1752 ndlp->nlp_prev_state = ndlp->nlp_state; 2028 ndlp->nlp_prev_state = ndlp->nlp_state;
1753 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE); 2029 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1754 lpfc_issue_els_logo(phba, ndlp, cmdiocb->retry); 2030 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
1755 return 1; 2031 return 1;
1756 } 2032 }
1757 } 2033 }
1758 2034
1759 /* No retry ELS command <elsCmd> to remote NPORT <did> */ 2035 /* No retry ELS command <elsCmd> to remote NPORT <did> */
1760 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 2036 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1761 "%d:0108 No retry ELS command x%x to remote NPORT x%x " 2037 "%d (%d):0108 No retry ELS command x%x to remote "
1762 "Data: x%x\n", 2038 "NPORT x%x Data: x%x\n",
1763 phba->brd_no, 2039 phba->brd_no, vport->vpi,
1764 cmd, did, cmdiocb->retry); 2040 cmd, did, cmdiocb->retry);
1765 2041
1766 return 0; 2042 return 0;
@@ -1795,33 +2071,36 @@ lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
1795 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); 2071 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1796 kfree(buf_ptr); 2072 kfree(buf_ptr);
1797 } 2073 }
1798 spin_lock_irq(phba->host->host_lock);
1799 lpfc_sli_release_iocbq(phba, elsiocb); 2074 lpfc_sli_release_iocbq(phba, elsiocb);
1800 spin_unlock_irq(phba->host->host_lock);
1801 return 0; 2075 return 0;
1802} 2076}
1803 2077
1804static void 2078static void
1805lpfc_cmpl_els_logo_acc(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb, 2079lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1806 struct lpfc_iocbq * rspiocb) 2080 struct lpfc_iocbq *rspiocb)
1807{ 2081{
1808 struct lpfc_nodelist *ndlp; 2082 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2083 struct lpfc_vport *vport = cmdiocb->vport;
2084 IOCB_t *irsp;
1809 2085
1810 ndlp = (struct lpfc_nodelist *) cmdiocb->context1; 2086 irsp = &rspiocb->iocb;
2087 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2088 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
2089 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
1811 2090
1812 /* ACC to LOGO completes to NPort <nlp_DID> */ 2091 /* ACC to LOGO completes to NPort <nlp_DID> */
1813 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 2092 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1814 "%d:0109 ACC to LOGO completes to NPort x%x " 2093 "%d (%d):0109 ACC to LOGO completes to NPort x%x "
1815 "Data: x%x x%x x%x\n", 2094 "Data: x%x x%x x%x\n",
1816 phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag, 2095 phba->brd_no, vport->vpi, ndlp->nlp_DID,
1817 ndlp->nlp_state, ndlp->nlp_rpi); 2096 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
1818 2097
1819 switch (ndlp->nlp_state) { 2098 switch (ndlp->nlp_state) {
1820 case NLP_STE_UNUSED_NODE: /* node is just allocated */ 2099 case NLP_STE_UNUSED_NODE: /* node is just allocated */
1821 lpfc_drop_node(phba, ndlp); 2100 lpfc_drop_node(vport, ndlp);
1822 break; 2101 break;
1823 case NLP_STE_NPR_NODE: /* NPort Recovery mode */ 2102 case NLP_STE_NPR_NODE: /* NPort Recovery mode */
1824 lpfc_unreg_rpi(phba, ndlp); 2103 lpfc_unreg_rpi(vport, ndlp);
1825 break; 2104 break;
1826 default: 2105 default:
1827 break; 2106 break;
@@ -1830,24 +2109,38 @@ lpfc_cmpl_els_logo_acc(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1830 return; 2109 return;
1831} 2110}
1832 2111
2112void
2113lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2114{
2115 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
2116 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
2117
2118 pmb->context1 = NULL;
2119 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2120 kfree(mp);
2121 mempool_free(pmb, phba->mbox_mem_pool);
2122 lpfc_nlp_put(ndlp);
2123 return;
2124}
2125
1833static void 2126static void
1834lpfc_cmpl_els_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 2127lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1835 struct lpfc_iocbq *rspiocb) 2128 struct lpfc_iocbq *rspiocb)
1836{ 2129{
2130 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2131 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
2132 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
1837 IOCB_t *irsp; 2133 IOCB_t *irsp;
1838 struct lpfc_nodelist *ndlp;
1839 LPFC_MBOXQ_t *mbox = NULL; 2134 LPFC_MBOXQ_t *mbox = NULL;
1840 struct lpfc_dmabuf *mp; 2135 struct lpfc_dmabuf *mp = NULL;
1841 2136
1842 irsp = &rspiocb->iocb; 2137 irsp = &rspiocb->iocb;
1843 2138
1844 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1845 if (cmdiocb->context_un.mbox) 2139 if (cmdiocb->context_un.mbox)
1846 mbox = cmdiocb->context_un.mbox; 2140 mbox = cmdiocb->context_un.mbox;
1847 2141
1848
1849 /* Check to see if link went down during discovery */ 2142 /* Check to see if link went down during discovery */
1850 if (lpfc_els_chk_latt(phba) || !ndlp) { 2143 if (!ndlp || lpfc_els_chk_latt(vport)) {
1851 if (mbox) { 2144 if (mbox) {
1852 mp = (struct lpfc_dmabuf *) mbox->context1; 2145 mp = (struct lpfc_dmabuf *) mbox->context1;
1853 if (mp) { 2146 if (mp) {
@@ -1859,24 +2152,37 @@ lpfc_cmpl_els_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1859 goto out; 2152 goto out;
1860 } 2153 }
1861 2154
2155 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2156 "ACC cmpl: status:x%x/x%x did:x%x",
2157 irsp->ulpStatus, irsp->un.ulpWord[4],
2158 irsp->un.rcvels.remoteID);
2159
1862 /* ELS response tag <ulpIoTag> completes */ 2160 /* ELS response tag <ulpIoTag> completes */
1863 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 2161 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1864 "%d:0110 ELS response tag x%x completes " 2162 "%d (%d):0110 ELS response tag x%x completes "
1865 "Data: x%x x%x x%x x%x x%x x%x x%x\n", 2163 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
1866 phba->brd_no, 2164 phba->brd_no, vport->vpi,
1867 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus, 2165 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
1868 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout, 2166 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
1869 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, 2167 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
1870 ndlp->nlp_rpi); 2168 ndlp->nlp_rpi);
1871 2169
1872 if (mbox) { 2170 if (mbox) {
1873 if ((rspiocb->iocb.ulpStatus == 0) 2171 if ((rspiocb->iocb.ulpStatus == 0)
1874 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) { 2172 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
1875 lpfc_unreg_rpi(phba, ndlp); 2173 lpfc_unreg_rpi(vport, ndlp);
1876 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
1877 mbox->context2 = lpfc_nlp_get(ndlp); 2174 mbox->context2 = lpfc_nlp_get(ndlp);
1878 ndlp->nlp_prev_state = ndlp->nlp_state; 2175 mbox->vport = vport;
1879 lpfc_nlp_set_state(phba, ndlp, NLP_STE_REG_LOGIN_ISSUE); 2176 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
2177 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
2178 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
2179 }
2180 else {
2181 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
2182 ndlp->nlp_prev_state = ndlp->nlp_state;
2183 lpfc_nlp_set_state(vport, ndlp,
2184 NLP_STE_REG_LOGIN_ISSUE);
2185 }
1880 if (lpfc_sli_issue_mbox(phba, mbox, 2186 if (lpfc_sli_issue_mbox(phba, mbox,
1881 (MBX_NOWAIT | MBX_STOP_IOCB)) 2187 (MBX_NOWAIT | MBX_STOP_IOCB))
1882 != MBX_NOT_FINISHED) { 2188 != MBX_NOT_FINISHED) {
@@ -1886,15 +2192,11 @@ lpfc_cmpl_els_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1886 /* NOTE: we should have messages for unsuccessful 2192 /* NOTE: we should have messages for unsuccessful
1887 reglogin */ 2193 reglogin */
1888 } else { 2194 } else {
1889 /* Do not call NO_LIST for lpfc_els_abort'ed ELS cmds */ 2195 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
1890 if (!((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && 2196 if (!lpfc_error_lost_link(irsp) &&
1891 ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) || 2197 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
1892 (irsp->un.ulpWord[4] == IOERR_LINK_DOWN) || 2198 lpfc_drop_node(vport, ndlp);
1893 (irsp->un.ulpWord[4] == IOERR_SLI_DOWN)))) { 2199 ndlp = NULL;
1894 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
1895 lpfc_drop_node(phba, ndlp);
1896 ndlp = NULL;
1897 }
1898 } 2200 }
1899 } 2201 }
1900 mp = (struct lpfc_dmabuf *) mbox->context1; 2202 mp = (struct lpfc_dmabuf *) mbox->context1;
@@ -1906,19 +2208,21 @@ lpfc_cmpl_els_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1906 } 2208 }
1907out: 2209out:
1908 if (ndlp) { 2210 if (ndlp) {
1909 spin_lock_irq(phba->host->host_lock); 2211 spin_lock_irq(shost->host_lock);
1910 ndlp->nlp_flag &= ~NLP_ACC_REGLOGIN; 2212 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
1911 spin_unlock_irq(phba->host->host_lock); 2213 spin_unlock_irq(shost->host_lock);
1912 } 2214 }
1913 lpfc_els_free_iocb(phba, cmdiocb); 2215 lpfc_els_free_iocb(phba, cmdiocb);
1914 return; 2216 return;
1915} 2217}
1916 2218
1917int 2219int
1918lpfc_els_rsp_acc(struct lpfc_hba * phba, uint32_t flag, 2220lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
1919 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp, 2221 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
1920 LPFC_MBOXQ_t * mbox, uint8_t newnode) 2222 LPFC_MBOXQ_t *mbox, uint8_t newnode)
1921{ 2223{
2224 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2225 struct lpfc_hba *phba = vport->phba;
1922 IOCB_t *icmd; 2226 IOCB_t *icmd;
1923 IOCB_t *oldcmd; 2227 IOCB_t *oldcmd;
1924 struct lpfc_iocbq *elsiocb; 2228 struct lpfc_iocbq *elsiocb;
@@ -1935,23 +2239,30 @@ lpfc_els_rsp_acc(struct lpfc_hba * phba, uint32_t flag,
1935 2239
1936 switch (flag) { 2240 switch (flag) {
1937 case ELS_CMD_ACC: 2241 case ELS_CMD_ACC:
1938 cmdsize = sizeof (uint32_t); 2242 cmdsize = sizeof(uint32_t);
1939 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry, 2243 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
1940 ndlp, ndlp->nlp_DID, ELS_CMD_ACC); 2244 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
1941 if (!elsiocb) { 2245 if (!elsiocb) {
2246 spin_lock_irq(shost->host_lock);
1942 ndlp->nlp_flag &= ~NLP_LOGO_ACC; 2247 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
2248 spin_unlock_irq(shost->host_lock);
1943 return 1; 2249 return 1;
1944 } 2250 }
2251
1945 icmd = &elsiocb->iocb; 2252 icmd = &elsiocb->iocb;
1946 icmd->ulpContext = oldcmd->ulpContext; /* Xri */ 2253 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
1947 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); 2254 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1948 *((uint32_t *) (pcmd)) = ELS_CMD_ACC; 2255 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
1949 pcmd += sizeof (uint32_t); 2256 pcmd += sizeof(uint32_t);
2257
2258 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2259 "Issue ACC: did:x%x flg:x%x",
2260 ndlp->nlp_DID, ndlp->nlp_flag, 0);
1950 break; 2261 break;
1951 case ELS_CMD_PLOGI: 2262 case ELS_CMD_PLOGI:
1952 cmdsize = (sizeof (struct serv_parm) + sizeof (uint32_t)); 2263 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
1953 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry, 2264 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
1954 ndlp, ndlp->nlp_DID, ELS_CMD_ACC); 2265 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
1955 if (!elsiocb) 2266 if (!elsiocb)
1956 return 1; 2267 return 1;
1957 2268
@@ -1963,12 +2274,16 @@ lpfc_els_rsp_acc(struct lpfc_hba * phba, uint32_t flag,
1963 elsiocb->context_un.mbox = mbox; 2274 elsiocb->context_un.mbox = mbox;
1964 2275
1965 *((uint32_t *) (pcmd)) = ELS_CMD_ACC; 2276 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
1966 pcmd += sizeof (uint32_t); 2277 pcmd += sizeof(uint32_t);
1967 memcpy(pcmd, &phba->fc_sparam, sizeof (struct serv_parm)); 2278 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
2279
2280 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2281 "Issue ACC PLOGI: did:x%x flg:x%x",
2282 ndlp->nlp_DID, ndlp->nlp_flag, 0);
1968 break; 2283 break;
1969 case ELS_CMD_PRLO: 2284 case ELS_CMD_PRLO:
1970 cmdsize = sizeof (uint32_t) + sizeof (PRLO); 2285 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
1971 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry, 2286 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
1972 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO); 2287 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
1973 if (!elsiocb) 2288 if (!elsiocb)
1974 return 1; 2289 return 1;
@@ -1978,10 +2293,14 @@ lpfc_els_rsp_acc(struct lpfc_hba * phba, uint32_t flag,
1978 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); 2293 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1979 2294
1980 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt, 2295 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
1981 sizeof (uint32_t) + sizeof (PRLO)); 2296 sizeof(uint32_t) + sizeof(PRLO));
1982 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC; 2297 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
1983 els_pkt_ptr = (ELS_PKT *) pcmd; 2298 els_pkt_ptr = (ELS_PKT *) pcmd;
1984 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED; 2299 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
2300
2301 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2302 "Issue ACC PRLO: did:x%x flg:x%x",
2303 ndlp->nlp_DID, ndlp->nlp_flag, 0);
1985 break; 2304 break;
1986 default: 2305 default:
1987 return 1; 2306 return 1;
@@ -1994,25 +2313,23 @@ lpfc_els_rsp_acc(struct lpfc_hba * phba, uint32_t flag,
1994 2313
1995 /* Xmit ELS ACC response tag <ulpIoTag> */ 2314 /* Xmit ELS ACC response tag <ulpIoTag> */
1996 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 2315 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1997 "%d:0128 Xmit ELS ACC response tag x%x, XRI: x%x, " 2316 "%d (%d):0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
1998 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n", 2317 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
1999 phba->brd_no, elsiocb->iotag, 2318 phba->brd_no, vport->vpi, elsiocb->iotag,
2000 elsiocb->iocb.ulpContext, ndlp->nlp_DID, 2319 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2001 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); 2320 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2002 2321
2003 if (ndlp->nlp_flag & NLP_LOGO_ACC) { 2322 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
2004 spin_lock_irq(phba->host->host_lock); 2323 spin_lock_irq(shost->host_lock);
2005 ndlp->nlp_flag &= ~NLP_LOGO_ACC; 2324 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
2006 spin_unlock_irq(phba->host->host_lock); 2325 spin_unlock_irq(shost->host_lock);
2007 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc; 2326 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
2008 } else { 2327 } else {
2009 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc; 2328 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
2010 } 2329 }
2011 2330
2012 phba->fc_stat.elsXmitACC++; 2331 phba->fc_stat.elsXmitACC++;
2013 spin_lock_irq(phba->host->host_lock);
2014 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); 2332 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2015 spin_unlock_irq(phba->host->host_lock);
2016 if (rc == IOCB_ERROR) { 2333 if (rc == IOCB_ERROR) {
2017 lpfc_els_free_iocb(phba, elsiocb); 2334 lpfc_els_free_iocb(phba, elsiocb);
2018 return 1; 2335 return 1;
@@ -2021,9 +2338,11 @@ lpfc_els_rsp_acc(struct lpfc_hba * phba, uint32_t flag,
2021} 2338}
2022 2339
2023int 2340int
2024lpfc_els_rsp_reject(struct lpfc_hba * phba, uint32_t rejectError, 2341lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
2025 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp) 2342 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
2343 LPFC_MBOXQ_t *mbox)
2026{ 2344{
2345 struct lpfc_hba *phba = vport->phba;
2027 IOCB_t *icmd; 2346 IOCB_t *icmd;
2028 IOCB_t *oldcmd; 2347 IOCB_t *oldcmd;
2029 struct lpfc_iocbq *elsiocb; 2348 struct lpfc_iocbq *elsiocb;
@@ -2036,9 +2355,9 @@ lpfc_els_rsp_reject(struct lpfc_hba * phba, uint32_t rejectError,
2036 psli = &phba->sli; 2355 psli = &phba->sli;
2037 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ 2356 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2038 2357
2039 cmdsize = 2 * sizeof (uint32_t); 2358 cmdsize = 2 * sizeof(uint32_t);
2040 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry, 2359 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2041 ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT); 2360 ndlp->nlp_DID, ELS_CMD_LS_RJT);
2042 if (!elsiocb) 2361 if (!elsiocb)
2043 return 1; 2362 return 1;
2044 2363
@@ -2048,22 +2367,30 @@ lpfc_els_rsp_reject(struct lpfc_hba * phba, uint32_t rejectError,
2048 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); 2367 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2049 2368
2050 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; 2369 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
2051 pcmd += sizeof (uint32_t); 2370 pcmd += sizeof(uint32_t);
2052 *((uint32_t *) (pcmd)) = rejectError; 2371 *((uint32_t *) (pcmd)) = rejectError;
2053 2372
2373 if (mbox) {
2374 elsiocb->context_un.mbox = mbox;
2375 elsiocb->context1 = lpfc_nlp_get(ndlp);
2376 }
2377
2054 /* Xmit ELS RJT <err> response tag <ulpIoTag> */ 2378 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
2055 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 2379 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2056 "%d:0129 Xmit ELS RJT x%x response tag x%x xri x%x, " 2380 "%d (%d):0129 Xmit ELS RJT x%x response tag x%x "
2057 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", 2381 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
2058 phba->brd_no, rejectError, elsiocb->iotag, 2382 "rpi x%x\n",
2383 phba->brd_no, vport->vpi, rejectError, elsiocb->iotag,
2059 elsiocb->iocb.ulpContext, ndlp->nlp_DID, 2384 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2060 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); 2385 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2061 2386
2387 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2388 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
2389 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
2390
2062 phba->fc_stat.elsXmitLSRJT++; 2391 phba->fc_stat.elsXmitLSRJT++;
2063 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc; 2392 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
2064 spin_lock_irq(phba->host->host_lock);
2065 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); 2393 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2066 spin_unlock_irq(phba->host->host_lock);
2067 if (rc == IOCB_ERROR) { 2394 if (rc == IOCB_ERROR) {
2068 lpfc_els_free_iocb(phba, elsiocb); 2395 lpfc_els_free_iocb(phba, elsiocb);
2069 return 1; 2396 return 1;
@@ -2072,25 +2399,22 @@ lpfc_els_rsp_reject(struct lpfc_hba * phba, uint32_t rejectError,
2072} 2399}
2073 2400
2074int 2401int
2075lpfc_els_rsp_adisc_acc(struct lpfc_hba * phba, 2402lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
2076 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp) 2403 struct lpfc_nodelist *ndlp)
2077{ 2404{
2405 struct lpfc_hba *phba = vport->phba;
2406 struct lpfc_sli *psli = &phba->sli;
2407 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
2078 ADISC *ap; 2408 ADISC *ap;
2079 IOCB_t *icmd; 2409 IOCB_t *icmd, *oldcmd;
2080 IOCB_t *oldcmd;
2081 struct lpfc_iocbq *elsiocb; 2410 struct lpfc_iocbq *elsiocb;
2082 struct lpfc_sli_ring *pring;
2083 struct lpfc_sli *psli;
2084 uint8_t *pcmd; 2411 uint8_t *pcmd;
2085 uint16_t cmdsize; 2412 uint16_t cmdsize;
2086 int rc; 2413 int rc;
2087 2414
2088 psli = &phba->sli; 2415 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
2089 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ 2416 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2090 2417 ndlp->nlp_DID, ELS_CMD_ACC);
2091 cmdsize = sizeof (uint32_t) + sizeof (ADISC);
2092 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
2093 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
2094 if (!elsiocb) 2418 if (!elsiocb)
2095 return 1; 2419 return 1;
2096 2420
@@ -2100,28 +2424,30 @@ lpfc_els_rsp_adisc_acc(struct lpfc_hba * phba,
2100 2424
2101 /* Xmit ADISC ACC response tag <ulpIoTag> */ 2425 /* Xmit ADISC ACC response tag <ulpIoTag> */
2102 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 2426 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2103 "%d:0130 Xmit ADISC ACC response iotag x%x xri: " 2427 "%d (%d):0130 Xmit ADISC ACC response iotag x%x xri: "
2104 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n", 2428 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
2105 phba->brd_no, elsiocb->iotag, 2429 phba->brd_no, vport->vpi, elsiocb->iotag,
2106 elsiocb->iocb.ulpContext, ndlp->nlp_DID, 2430 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2107 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); 2431 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2108 2432
2109 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); 2433 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2110 2434
2111 *((uint32_t *) (pcmd)) = ELS_CMD_ACC; 2435 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2112 pcmd += sizeof (uint32_t); 2436 pcmd += sizeof(uint32_t);
2113 2437
2114 ap = (ADISC *) (pcmd); 2438 ap = (ADISC *) (pcmd);
2115 ap->hardAL_PA = phba->fc_pref_ALPA; 2439 ap->hardAL_PA = phba->fc_pref_ALPA;
2116 memcpy(&ap->portName, &phba->fc_portname, sizeof (struct lpfc_name)); 2440 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2117 memcpy(&ap->nodeName, &phba->fc_nodename, sizeof (struct lpfc_name)); 2441 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2118 ap->DID = be32_to_cpu(phba->fc_myDID); 2442 ap->DID = be32_to_cpu(vport->fc_myDID);
2443
2444 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2445 "Issue ACC ADISC: did:x%x flg:x%x",
2446 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2119 2447
2120 phba->fc_stat.elsXmitACC++; 2448 phba->fc_stat.elsXmitACC++;
2121 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc; 2449 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
2122 spin_lock_irq(phba->host->host_lock);
2123 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); 2450 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2124 spin_unlock_irq(phba->host->host_lock);
2125 if (rc == IOCB_ERROR) { 2451 if (rc == IOCB_ERROR) {
2126 lpfc_els_free_iocb(phba, elsiocb); 2452 lpfc_els_free_iocb(phba, elsiocb);
2127 return 1; 2453 return 1;
@@ -2130,9 +2456,10 @@ lpfc_els_rsp_adisc_acc(struct lpfc_hba * phba,
2130} 2456}
2131 2457
2132int 2458int
2133lpfc_els_rsp_prli_acc(struct lpfc_hba *phba, struct lpfc_iocbq *oldiocb, 2459lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
2134 struct lpfc_nodelist *ndlp) 2460 struct lpfc_nodelist *ndlp)
2135{ 2461{
2462 struct lpfc_hba *phba = vport->phba;
2136 PRLI *npr; 2463 PRLI *npr;
2137 lpfc_vpd_t *vpd; 2464 lpfc_vpd_t *vpd;
2138 IOCB_t *icmd; 2465 IOCB_t *icmd;
@@ -2147,8 +2474,8 @@ lpfc_els_rsp_prli_acc(struct lpfc_hba *phba, struct lpfc_iocbq *oldiocb,
2147 psli = &phba->sli; 2474 psli = &phba->sli;
2148 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ 2475 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2149 2476
2150 cmdsize = sizeof (uint32_t) + sizeof (PRLI); 2477 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
2151 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry, ndlp, 2478 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2152 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK))); 2479 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
2153 if (!elsiocb) 2480 if (!elsiocb)
2154 return 1; 2481 return 1;
@@ -2159,19 +2486,19 @@ lpfc_els_rsp_prli_acc(struct lpfc_hba *phba, struct lpfc_iocbq *oldiocb,
2159 2486
2160 /* Xmit PRLI ACC response tag <ulpIoTag> */ 2487 /* Xmit PRLI ACC response tag <ulpIoTag> */
2161 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 2488 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2162 "%d:0131 Xmit PRLI ACC response tag x%x xri x%x, " 2489 "%d (%d):0131 Xmit PRLI ACC response tag x%x xri x%x, "
2163 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", 2490 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
2164 phba->brd_no, elsiocb->iotag, 2491 phba->brd_no, vport->vpi, elsiocb->iotag,
2165 elsiocb->iocb.ulpContext, ndlp->nlp_DID, 2492 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2166 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); 2493 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2167 2494
2168 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); 2495 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2169 2496
2170 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)); 2497 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
2171 pcmd += sizeof (uint32_t); 2498 pcmd += sizeof(uint32_t);
2172 2499
2173 /* For PRLI, remainder of payload is PRLI parameter page */ 2500 /* For PRLI, remainder of payload is PRLI parameter page */
2174 memset(pcmd, 0, sizeof (PRLI)); 2501 memset(pcmd, 0, sizeof(PRLI));
2175 2502
2176 npr = (PRLI *) pcmd; 2503 npr = (PRLI *) pcmd;
2177 vpd = &phba->vpd; 2504 vpd = &phba->vpd;
@@ -2193,12 +2520,14 @@ lpfc_els_rsp_prli_acc(struct lpfc_hba *phba, struct lpfc_iocbq *oldiocb,
2193 npr->prliType = PRLI_FCP_TYPE; 2520 npr->prliType = PRLI_FCP_TYPE;
2194 npr->initiatorFunc = 1; 2521 npr->initiatorFunc = 1;
2195 2522
2523 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2524 "Issue ACC PRLI: did:x%x flg:x%x",
2525 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2526
2196 phba->fc_stat.elsXmitACC++; 2527 phba->fc_stat.elsXmitACC++;
2197 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc; 2528 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
2198 2529
2199 spin_lock_irq(phba->host->host_lock);
2200 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); 2530 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2201 spin_unlock_irq(phba->host->host_lock);
2202 if (rc == IOCB_ERROR) { 2531 if (rc == IOCB_ERROR) {
2203 lpfc_els_free_iocb(phba, elsiocb); 2532 lpfc_els_free_iocb(phba, elsiocb);
2204 return 1; 2533 return 1;
@@ -2207,12 +2536,12 @@ lpfc_els_rsp_prli_acc(struct lpfc_hba *phba, struct lpfc_iocbq *oldiocb,
2207} 2536}
2208 2537
2209static int 2538static int
2210lpfc_els_rsp_rnid_acc(struct lpfc_hba *phba, uint8_t format, 2539lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
2211 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp) 2540 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
2212{ 2541{
2542 struct lpfc_hba *phba = vport->phba;
2213 RNID *rn; 2543 RNID *rn;
2214 IOCB_t *icmd; 2544 IOCB_t *icmd, *oldcmd;
2215 IOCB_t *oldcmd;
2216 struct lpfc_iocbq *elsiocb; 2545 struct lpfc_iocbq *elsiocb;
2217 struct lpfc_sli_ring *pring; 2546 struct lpfc_sli_ring *pring;
2218 struct lpfc_sli *psli; 2547 struct lpfc_sli *psli;
@@ -2223,13 +2552,13 @@ lpfc_els_rsp_rnid_acc(struct lpfc_hba *phba, uint8_t format,
2223 psli = &phba->sli; 2552 psli = &phba->sli;
2224 pring = &psli->ring[LPFC_ELS_RING]; 2553 pring = &psli->ring[LPFC_ELS_RING];
2225 2554
2226 cmdsize = sizeof (uint32_t) + sizeof (uint32_t) 2555 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
2227 + (2 * sizeof (struct lpfc_name)); 2556 + (2 * sizeof(struct lpfc_name));
2228 if (format) 2557 if (format)
2229 cmdsize += sizeof (RNID_TOP_DISC); 2558 cmdsize += sizeof(RNID_TOP_DISC);
2230 2559
2231 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry, 2560 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2232 ndlp, ndlp->nlp_DID, ELS_CMD_ACC); 2561 ndlp->nlp_DID, ELS_CMD_ACC);
2233 if (!elsiocb) 2562 if (!elsiocb)
2234 return 1; 2563 return 1;
2235 2564
@@ -2239,30 +2568,30 @@ lpfc_els_rsp_rnid_acc(struct lpfc_hba *phba, uint8_t format,
2239 2568
2240 /* Xmit RNID ACC response tag <ulpIoTag> */ 2569 /* Xmit RNID ACC response tag <ulpIoTag> */
2241 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 2570 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2242 "%d:0132 Xmit RNID ACC response tag x%x " 2571 "%d (%d):0132 Xmit RNID ACC response tag x%x "
2243 "xri x%x\n", 2572 "xri x%x\n",
2244 phba->brd_no, elsiocb->iotag, 2573 phba->brd_no, vport->vpi, elsiocb->iotag,
2245 elsiocb->iocb.ulpContext); 2574 elsiocb->iocb.ulpContext);
2246 2575
2247 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); 2576 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2248 2577
2249 *((uint32_t *) (pcmd)) = ELS_CMD_ACC; 2578 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2250 pcmd += sizeof (uint32_t); 2579 pcmd += sizeof(uint32_t);
2251 2580
2252 memset(pcmd, 0, sizeof (RNID)); 2581 memset(pcmd, 0, sizeof(RNID));
2253 rn = (RNID *) (pcmd); 2582 rn = (RNID *) (pcmd);
2254 rn->Format = format; 2583 rn->Format = format;
2255 rn->CommonLen = (2 * sizeof (struct lpfc_name)); 2584 rn->CommonLen = (2 * sizeof(struct lpfc_name));
2256 memcpy(&rn->portName, &phba->fc_portname, sizeof (struct lpfc_name)); 2585 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2257 memcpy(&rn->nodeName, &phba->fc_nodename, sizeof (struct lpfc_name)); 2586 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2258 switch (format) { 2587 switch (format) {
2259 case 0: 2588 case 0:
2260 rn->SpecificLen = 0; 2589 rn->SpecificLen = 0;
2261 break; 2590 break;
2262 case RNID_TOPOLOGY_DISC: 2591 case RNID_TOPOLOGY_DISC:
2263 rn->SpecificLen = sizeof (RNID_TOP_DISC); 2592 rn->SpecificLen = sizeof(RNID_TOP_DISC);
2264 memcpy(&rn->un.topologyDisc.portName, 2593 memcpy(&rn->un.topologyDisc.portName,
2265 &phba->fc_portname, sizeof (struct lpfc_name)); 2594 &vport->fc_portname, sizeof(struct lpfc_name));
2266 rn->un.topologyDisc.unitType = RNID_HBA; 2595 rn->un.topologyDisc.unitType = RNID_HBA;
2267 rn->un.topologyDisc.physPort = 0; 2596 rn->un.topologyDisc.physPort = 0;
2268 rn->un.topologyDisc.attachedNodes = 0; 2597 rn->un.topologyDisc.attachedNodes = 0;
@@ -2273,15 +2602,17 @@ lpfc_els_rsp_rnid_acc(struct lpfc_hba *phba, uint8_t format,
2273 break; 2602 break;
2274 } 2603 }
2275 2604
2605 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2606 "Issue ACC RNID: did:x%x flg:x%x",
2607 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2608
2276 phba->fc_stat.elsXmitACC++; 2609 phba->fc_stat.elsXmitACC++;
2277 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc; 2610 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
2278 lpfc_nlp_put(ndlp); 2611 lpfc_nlp_put(ndlp);
2279 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl, 2612 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
2280 * it could be freed */ 2613 * it could be freed */
2281 2614
2282 spin_lock_irq(phba->host->host_lock);
2283 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); 2615 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2284 spin_unlock_irq(phba->host->host_lock);
2285 if (rc == IOCB_ERROR) { 2616 if (rc == IOCB_ERROR) {
2286 lpfc_els_free_iocb(phba, elsiocb); 2617 lpfc_els_free_iocb(phba, elsiocb);
2287 return 1; 2618 return 1;
@@ -2290,168 +2621,153 @@ lpfc_els_rsp_rnid_acc(struct lpfc_hba *phba, uint8_t format,
2290} 2621}
2291 2622
2292int 2623int
2293lpfc_els_disc_adisc(struct lpfc_hba *phba) 2624lpfc_els_disc_adisc(struct lpfc_vport *vport)
2294{ 2625{
2295 int sentadisc; 2626 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2296 struct lpfc_nodelist *ndlp, *next_ndlp; 2627 struct lpfc_nodelist *ndlp, *next_ndlp;
2628 int sentadisc = 0;
2297 2629
2298 sentadisc = 0;
2299 /* go thru NPR nodes and issue any remaining ELS ADISCs */ 2630 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2300 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nodes, nlp_listp) { 2631 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
2301 if (ndlp->nlp_state == NLP_STE_NPR_NODE && 2632 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
2302 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && 2633 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
2303 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) { 2634 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
2304 spin_lock_irq(phba->host->host_lock); 2635 spin_lock_irq(shost->host_lock);
2305 ndlp->nlp_flag &= ~NLP_NPR_ADISC; 2636 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2306 spin_unlock_irq(phba->host->host_lock); 2637 spin_unlock_irq(shost->host_lock);
2307 ndlp->nlp_prev_state = ndlp->nlp_state; 2638 ndlp->nlp_prev_state = ndlp->nlp_state;
2308 lpfc_nlp_set_state(phba, ndlp, NLP_STE_ADISC_ISSUE); 2639 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2309 lpfc_issue_els_adisc(phba, ndlp, 0); 2640 lpfc_issue_els_adisc(vport, ndlp, 0);
2310 sentadisc++; 2641 sentadisc++;
2311 phba->num_disc_nodes++; 2642 vport->num_disc_nodes++;
2312 if (phba->num_disc_nodes >= 2643 if (vport->num_disc_nodes >=
2313 phba->cfg_discovery_threads) { 2644 vport->phba->cfg_discovery_threads) {
2314 spin_lock_irq(phba->host->host_lock); 2645 spin_lock_irq(shost->host_lock);
2315 phba->fc_flag |= FC_NLP_MORE; 2646 vport->fc_flag |= FC_NLP_MORE;
2316 spin_unlock_irq(phba->host->host_lock); 2647 spin_unlock_irq(shost->host_lock);
2317 break; 2648 break;
2318 } 2649 }
2319 } 2650 }
2320 } 2651 }
2321 if (sentadisc == 0) { 2652 if (sentadisc == 0) {
2322 spin_lock_irq(phba->host->host_lock); 2653 spin_lock_irq(shost->host_lock);
2323 phba->fc_flag &= ~FC_NLP_MORE; 2654 vport->fc_flag &= ~FC_NLP_MORE;
2324 spin_unlock_irq(phba->host->host_lock); 2655 spin_unlock_irq(shost->host_lock);
2325 } 2656 }
2326 return sentadisc; 2657 return sentadisc;
2327} 2658}
2328 2659
2329int 2660int
2330lpfc_els_disc_plogi(struct lpfc_hba * phba) 2661lpfc_els_disc_plogi(struct lpfc_vport *vport)
2331{ 2662{
2332 int sentplogi; 2663 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2333 struct lpfc_nodelist *ndlp, *next_ndlp; 2664 struct lpfc_nodelist *ndlp, *next_ndlp;
2665 int sentplogi = 0;
2334 2666
2335 sentplogi = 0; 2667 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
2336 /* go thru NPR list and issue any remaining ELS PLOGIs */ 2668 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
2337 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nodes, nlp_listp) {
2338 if (ndlp->nlp_state == NLP_STE_NPR_NODE && 2669 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
2339 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 && 2670 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
2340 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 && 2671 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
2341 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) { 2672 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
2342 ndlp->nlp_prev_state = ndlp->nlp_state; 2673 ndlp->nlp_prev_state = ndlp->nlp_state;
2343 lpfc_nlp_set_state(phba, ndlp, NLP_STE_PLOGI_ISSUE); 2674 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2344 lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0); 2675 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2345 sentplogi++; 2676 sentplogi++;
2346 phba->num_disc_nodes++; 2677 vport->num_disc_nodes++;
2347 if (phba->num_disc_nodes >= 2678 if (vport->num_disc_nodes >=
2348 phba->cfg_discovery_threads) { 2679 vport->phba->cfg_discovery_threads) {
2349 spin_lock_irq(phba->host->host_lock); 2680 spin_lock_irq(shost->host_lock);
2350 phba->fc_flag |= FC_NLP_MORE; 2681 vport->fc_flag |= FC_NLP_MORE;
2351 spin_unlock_irq(phba->host->host_lock); 2682 spin_unlock_irq(shost->host_lock);
2352 break; 2683 break;
2353 } 2684 }
2354 } 2685 }
2355 } 2686 }
2356 if (sentplogi == 0) { 2687 if (sentplogi == 0) {
2357 spin_lock_irq(phba->host->host_lock); 2688 spin_lock_irq(shost->host_lock);
2358 phba->fc_flag &= ~FC_NLP_MORE; 2689 vport->fc_flag &= ~FC_NLP_MORE;
2359 spin_unlock_irq(phba->host->host_lock); 2690 spin_unlock_irq(shost->host_lock);
2360 } 2691 }
2361 return sentplogi; 2692 return sentplogi;
2362} 2693}
2363 2694
2364int 2695void
2365lpfc_els_flush_rscn(struct lpfc_hba * phba) 2696lpfc_els_flush_rscn(struct lpfc_vport *vport)
2366{ 2697{
2367 struct lpfc_dmabuf *mp; 2698 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2699 struct lpfc_hba *phba = vport->phba;
2368 int i; 2700 int i;
2369 2701
2370 for (i = 0; i < phba->fc_rscn_id_cnt; i++) { 2702 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
2371 mp = phba->fc_rscn_id_list[i]; 2703 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
2372 lpfc_mbuf_free(phba, mp->virt, mp->phys); 2704 vport->fc_rscn_id_list[i] = NULL;
2373 kfree(mp); 2705 }
2374 phba->fc_rscn_id_list[i] = NULL; 2706 spin_lock_irq(shost->host_lock);
2375 } 2707 vport->fc_rscn_id_cnt = 0;
2376 phba->fc_rscn_id_cnt = 0; 2708 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
2377 spin_lock_irq(phba->host->host_lock); 2709 spin_unlock_irq(shost->host_lock);
2378 phba->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY); 2710 lpfc_can_disctmo(vport);
2379 spin_unlock_irq(phba->host->host_lock);
2380 lpfc_can_disctmo(phba);
2381 return 0;
2382} 2711}
2383 2712
2384int 2713int
2385lpfc_rscn_payload_check(struct lpfc_hba * phba, uint32_t did) 2714lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
2386{ 2715{
2387 D_ID ns_did; 2716 D_ID ns_did;
2388 D_ID rscn_did; 2717 D_ID rscn_did;
2389 struct lpfc_dmabuf *mp;
2390 uint32_t *lp; 2718 uint32_t *lp;
2391 uint32_t payload_len, cmd, i, match; 2719 uint32_t payload_len, i;
2720 struct lpfc_hba *phba = vport->phba;
2392 2721
2393 ns_did.un.word = did; 2722 ns_did.un.word = did;
2394 match = 0;
2395 2723
2396 /* Never match fabric nodes for RSCNs */ 2724 /* Never match fabric nodes for RSCNs */
2397 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) 2725 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
2398 return(0); 2726 return 0;
2399 2727
2400 /* If we are doing a FULL RSCN rediscovery, match everything */ 2728 /* If we are doing a FULL RSCN rediscovery, match everything */
2401 if (phba->fc_flag & FC_RSCN_DISCOVERY) { 2729 if (vport->fc_flag & FC_RSCN_DISCOVERY)
2402 return did; 2730 return did;
2403 }
2404 2731
2405 for (i = 0; i < phba->fc_rscn_id_cnt; i++) { 2732 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
2406 mp = phba->fc_rscn_id_list[i]; 2733 lp = vport->fc_rscn_id_list[i]->virt;
2407 lp = (uint32_t *) mp->virt; 2734 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
2408 cmd = *lp++; 2735 payload_len -= sizeof(uint32_t); /* take off word 0 */
2409 payload_len = be32_to_cpu(cmd) & 0xffff; /* payload length */
2410 payload_len -= sizeof (uint32_t); /* take off word 0 */
2411 while (payload_len) { 2736 while (payload_len) {
2412 rscn_did.un.word = *lp++; 2737 rscn_did.un.word = be32_to_cpu(*lp++);
2413 rscn_did.un.word = be32_to_cpu(rscn_did.un.word); 2738 payload_len -= sizeof(uint32_t);
2414 payload_len -= sizeof (uint32_t);
2415 switch (rscn_did.un.b.resv) { 2739 switch (rscn_did.un.b.resv) {
2416 case 0: /* Single N_Port ID effected */ 2740 case 0: /* Single N_Port ID effected */
2417 if (ns_did.un.word == rscn_did.un.word) { 2741 if (ns_did.un.word == rscn_did.un.word)
2418 match = did; 2742 return did;
2419 }
2420 break; 2743 break;
2421 case 1: /* Whole N_Port Area effected */ 2744 case 1: /* Whole N_Port Area effected */
2422 if ((ns_did.un.b.domain == rscn_did.un.b.domain) 2745 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
2423 && (ns_did.un.b.area == rscn_did.un.b.area)) 2746 && (ns_did.un.b.area == rscn_did.un.b.area))
2424 { 2747 return did;
2425 match = did;
2426 }
2427 break; 2748 break;
2428 case 2: /* Whole N_Port Domain effected */ 2749 case 2: /* Whole N_Port Domain effected */
2429 if (ns_did.un.b.domain == rscn_did.un.b.domain) 2750 if (ns_did.un.b.domain == rscn_did.un.b.domain)
2430 { 2751 return did;
2431 match = did;
2432 }
2433 break;
2434 case 3: /* Whole Fabric effected */
2435 match = did;
2436 break; 2752 break;
2437 default: 2753 default:
2438 /* Unknown Identifier in RSCN list */ 2754 /* Unknown Identifier in RSCN node */
2439 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, 2755 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2440 "%d:0217 Unknown Identifier in " 2756 "%d (%d):0217 Unknown "
2441 "RSCN payload Data: x%x\n", 2757 "Identifier in RSCN payload "
2442 phba->brd_no, rscn_did.un.word); 2758 "Data: x%x\n",
2443 break; 2759 phba->brd_no, vport->vpi,
2444 } 2760 rscn_did.un.word);
2445 if (match) { 2761 case 3: /* Whole Fabric effected */
2446 break; 2762 return did;
2447 } 2763 }
2448 } 2764 }
2449 } 2765 }
2450 return match; 2766 return 0;
2451} 2767}
2452 2768
2453static int 2769static int
2454lpfc_rscn_recovery_check(struct lpfc_hba *phba) 2770lpfc_rscn_recovery_check(struct lpfc_vport *vport)
2455{ 2771{
2456 struct lpfc_nodelist *ndlp = NULL; 2772 struct lpfc_nodelist *ndlp = NULL;
2457 2773
@@ -2459,188 +2775,261 @@ lpfc_rscn_recovery_check(struct lpfc_hba *phba)
2459 * them to NPR state. 2775 * them to NPR state.
2460 */ 2776 */
2461 2777
2462 list_for_each_entry(ndlp, &phba->fc_nodes, nlp_listp) { 2778 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
2463 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE || 2779 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE ||
2464 lpfc_rscn_payload_check(phba, ndlp->nlp_DID) == 0) 2780 lpfc_rscn_payload_check(vport, ndlp->nlp_DID) == 0)
2465 continue; 2781 continue;
2466 2782
2467 lpfc_disc_state_machine(phba, ndlp, NULL, 2783 lpfc_disc_state_machine(vport, ndlp, NULL,
2468 NLP_EVT_DEVICE_RECOVERY); 2784 NLP_EVT_DEVICE_RECOVERY);
2469 2785
2470 /* 2786 /*
2471 * Make sure NLP_DELAY_TMO is NOT running after a device 2787 * Make sure NLP_DELAY_TMO is NOT running after a device
2472 * recovery event. 2788 * recovery event.
2473 */ 2789 */
2474 if (ndlp->nlp_flag & NLP_DELAY_TMO) 2790 if (ndlp->nlp_flag & NLP_DELAY_TMO)
2475 lpfc_cancel_retry_delay_tmo(phba, ndlp); 2791 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2476 } 2792 }
2477 2793
2478 return 0; 2794 return 0;
2479} 2795}
2480 2796
2481static int 2797static int
2482lpfc_els_rcv_rscn(struct lpfc_hba * phba, 2798lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
2483 struct lpfc_iocbq * cmdiocb, 2799 struct lpfc_nodelist *ndlp, uint8_t newnode)
2484 struct lpfc_nodelist * ndlp, uint8_t newnode)
2485{ 2800{
2801 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2802 struct lpfc_hba *phba = vport->phba;
2486 struct lpfc_dmabuf *pcmd; 2803 struct lpfc_dmabuf *pcmd;
2487 uint32_t *lp; 2804 struct lpfc_vport *next_vport;
2805 uint32_t *lp, *datap;
2488 IOCB_t *icmd; 2806 IOCB_t *icmd;
2489 uint32_t payload_len, cmd; 2807 uint32_t payload_len, length, nportid, *cmd;
2808 int rscn_cnt = vport->fc_rscn_id_cnt;
2809 int rscn_id = 0, hba_id = 0;
2490 int i; 2810 int i;
2491 2811
2492 icmd = &cmdiocb->iocb; 2812 icmd = &cmdiocb->iocb;
2493 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; 2813 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2494 lp = (uint32_t *) pcmd->virt; 2814 lp = (uint32_t *) pcmd->virt;
2495 2815
2496 cmd = *lp++; 2816 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
2497 payload_len = be32_to_cpu(cmd) & 0xffff; /* payload length */ 2817 payload_len -= sizeof(uint32_t); /* take off word 0 */
2498 payload_len -= sizeof (uint32_t); /* take off word 0 */
2499 cmd &= ELS_CMD_MASK;
2500 2818
2501 /* RSCN received */ 2819 /* RSCN received */
2502 lpfc_printf_log(phba, 2820 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
2503 KERN_INFO, 2821 "%d (%d):0214 RSCN received Data: x%x x%x x%x x%x\n",
2504 LOG_DISCOVERY, 2822 phba->brd_no, vport->vpi, vport->fc_flag, payload_len,
2505 "%d:0214 RSCN received Data: x%x x%x x%x x%x\n", 2823 *lp, rscn_cnt);
2506 phba->brd_no,
2507 phba->fc_flag, payload_len, *lp, phba->fc_rscn_id_cnt);
2508 2824
2509 for (i = 0; i < payload_len/sizeof(uint32_t); i++) 2825 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
2510 fc_host_post_event(phba->host, fc_get_event_number(), 2826 fc_host_post_event(shost, fc_get_event_number(),
2511 FCH_EVT_RSCN, lp[i]); 2827 FCH_EVT_RSCN, lp[i]);
2512 2828
2513 /* If we are about to begin discovery, just ACC the RSCN. 2829 /* If we are about to begin discovery, just ACC the RSCN.
2514 * Discovery processing will satisfy it. 2830 * Discovery processing will satisfy it.
2515 */ 2831 */
2516 if (phba->hba_state <= LPFC_NS_QRY) { 2832 if (vport->port_state <= LPFC_NS_QRY) {
2517 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 2833 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
2518 newnode); 2834 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
2835 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
2836
2837 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL,
2838 newnode);
2519 return 0; 2839 return 0;
2520 } 2840 }
2521 2841
2842 /* If this RSCN just contains NPortIDs for other vports on this HBA,
2843 * just ACC and ignore it.
2844 */
2845 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2846 !(phba->cfg_peer_port_login)) {
2847 i = payload_len;
2848 datap = lp;
2849 while (i > 0) {
2850 nportid = *datap++;
2851 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
2852 i -= sizeof(uint32_t);
2853 rscn_id++;
2854 list_for_each_entry(next_vport, &phba->port_list,
2855 listentry) {
2856 if (nportid == next_vport->fc_myDID) {
2857 hba_id++;
2858 break;
2859 }
2860 }
2861 }
2862 if (rscn_id == hba_id) {
2863 /* ALL NPortIDs in RSCN are on HBA */
2864 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
2865 "%d (%d):0214 Ignore RSCN Data: x%x x%x x%x x%x\n",
2866 phba->brd_no, vport->vpi, vport->fc_flag, payload_len,
2867 *lp, rscn_cnt);
2868
2869 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
2870 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
2871 ndlp->nlp_DID, vport->port_state,
2872 ndlp->nlp_flag);
2873
2874 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
2875 ndlp, NULL, newnode);
2876 return 0;
2877 }
2878 }
2879
2522 /* If we are already processing an RSCN, save the received 2880 /* If we are already processing an RSCN, save the received
2523 * RSCN payload buffer, cmdiocb->context2 to process later. 2881 * RSCN payload buffer, cmdiocb->context2 to process later.
2524 */ 2882 */
2525 if (phba->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) { 2883 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
2526 if ((phba->fc_rscn_id_cnt < FC_MAX_HOLD_RSCN) && 2884 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
2527 !(phba->fc_flag & FC_RSCN_DISCOVERY)) { 2885 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
2528 spin_lock_irq(phba->host->host_lock); 2886 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
2529 phba->fc_flag |= FC_RSCN_MODE; 2887
2530 spin_unlock_irq(phba->host->host_lock); 2888 vport->fc_flag |= FC_RSCN_DEFERRED;
2531 phba->fc_rscn_id_list[phba->fc_rscn_id_cnt++] = pcmd; 2889 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
2532 2890 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
2533 /* If we zero, cmdiocb->context2, the calling 2891 spin_lock_irq(shost->host_lock);
2534 * routine will not try to free it. 2892 vport->fc_flag |= FC_RSCN_MODE;
2535 */ 2893 spin_unlock_irq(shost->host_lock);
2536 cmdiocb->context2 = NULL; 2894 if (rscn_cnt) {
2895 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
2896 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
2897 }
2898 if ((rscn_cnt) &&
2899 (payload_len + length <= LPFC_BPL_SIZE)) {
2900 *cmd &= ELS_CMD_MASK;
2901 *cmd |= be32_to_cpu(payload_len + length);
2902 memcpy(((uint8_t *)cmd) + length, lp,
2903 payload_len);
2904 } else {
2905 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
2906 vport->fc_rscn_id_cnt++;
2907 /* If we zero, cmdiocb->context2, the calling
2908 * routine will not try to free it.
2909 */
2910 cmdiocb->context2 = NULL;
2911 }
2537 2912
2538 /* Deferred RSCN */ 2913 /* Deferred RSCN */
2539 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, 2914 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
2540 "%d:0235 Deferred RSCN " 2915 "%d (%d):0235 Deferred RSCN "
2541 "Data: x%x x%x x%x\n", 2916 "Data: x%x x%x x%x\n",
2542 phba->brd_no, phba->fc_rscn_id_cnt, 2917 phba->brd_no, vport->vpi,
2543 phba->fc_flag, phba->hba_state); 2918 vport->fc_rscn_id_cnt, vport->fc_flag,
2919 vport->port_state);
2544 } else { 2920 } else {
2545 spin_lock_irq(phba->host->host_lock); 2921 spin_lock_irq(shost->host_lock);
2546 phba->fc_flag |= FC_RSCN_DISCOVERY; 2922 vport->fc_flag |= FC_RSCN_DISCOVERY;
2547 spin_unlock_irq(phba->host->host_lock); 2923 spin_unlock_irq(shost->host_lock);
2548 /* ReDiscovery RSCN */ 2924 /* ReDiscovery RSCN */
2549 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, 2925 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
2550 "%d:0234 ReDiscovery RSCN " 2926 "%d (%d):0234 ReDiscovery RSCN "
2551 "Data: x%x x%x x%x\n", 2927 "Data: x%x x%x x%x\n",
2552 phba->brd_no, phba->fc_rscn_id_cnt, 2928 phba->brd_no, vport->vpi,
2553 phba->fc_flag, phba->hba_state); 2929 vport->fc_rscn_id_cnt, vport->fc_flag,
2930 vport->port_state);
2554 } 2931 }
2555 /* Send back ACC */ 2932 /* Send back ACC */
2556 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 2933 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL,
2557 newnode); 2934 newnode);
2558 2935
2559 /* send RECOVERY event for ALL nodes that match RSCN payload */ 2936 /* send RECOVERY event for ALL nodes that match RSCN payload */
2560 lpfc_rscn_recovery_check(phba); 2937 lpfc_rscn_recovery_check(vport);
2938 vport->fc_flag &= ~FC_RSCN_DEFERRED;
2561 return 0; 2939 return 0;
2562 } 2940 }
2563 2941
2564 phba->fc_flag |= FC_RSCN_MODE; 2942 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
2565 phba->fc_rscn_id_list[phba->fc_rscn_id_cnt++] = pcmd; 2943 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
2944 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
2945
2946 spin_lock_irq(shost->host_lock);
2947 vport->fc_flag |= FC_RSCN_MODE;
2948 spin_unlock_irq(shost->host_lock);
2949 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
2566 /* 2950 /*
2567 * If we zero, cmdiocb->context2, the calling routine will 2951 * If we zero, cmdiocb->context2, the calling routine will
2568 * not try to free it. 2952 * not try to free it.
2569 */ 2953 */
2570 cmdiocb->context2 = NULL; 2954 cmdiocb->context2 = NULL;
2571 2955
2572 lpfc_set_disctmo(phba); 2956 lpfc_set_disctmo(vport);
2573 2957
2574 /* Send back ACC */ 2958 /* Send back ACC */
2575 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, newnode); 2959 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL, newnode);
2576 2960
2577 /* send RECOVERY event for ALL nodes that match RSCN payload */ 2961 /* send RECOVERY event for ALL nodes that match RSCN payload */
2578 lpfc_rscn_recovery_check(phba); 2962 lpfc_rscn_recovery_check(vport);
2579 2963
2580 return lpfc_els_handle_rscn(phba); 2964 return lpfc_els_handle_rscn(vport);
2581} 2965}
2582 2966
2583int 2967int
2584lpfc_els_handle_rscn(struct lpfc_hba * phba) 2968lpfc_els_handle_rscn(struct lpfc_vport *vport)
2585{ 2969{
2586 struct lpfc_nodelist *ndlp; 2970 struct lpfc_nodelist *ndlp;
2971 struct lpfc_hba *phba = vport->phba;
2972
2973 /* Ignore RSCN if the port is being torn down. */
2974 if (vport->load_flag & FC_UNLOADING) {
2975 lpfc_els_flush_rscn(vport);
2976 return 0;
2977 }
2587 2978
2588 /* Start timer for RSCN processing */ 2979 /* Start timer for RSCN processing */
2589 lpfc_set_disctmo(phba); 2980 lpfc_set_disctmo(vport);
2590 2981
2591 /* RSCN processed */ 2982 /* RSCN processed */
2592 lpfc_printf_log(phba, 2983 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
2593 KERN_INFO, 2984 "%d (%d):0215 RSCN processed Data: x%x x%x x%x x%x\n",
2594 LOG_DISCOVERY, 2985 phba->brd_no, vport->vpi,
2595 "%d:0215 RSCN processed Data: x%x x%x x%x x%x\n", 2986 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
2596 phba->brd_no, 2987 vport->port_state);
2597 phba->fc_flag, 0, phba->fc_rscn_id_cnt,
2598 phba->hba_state);
2599 2988
2600 /* To process RSCN, first compare RSCN data with NameServer */ 2989 /* To process RSCN, first compare RSCN data with NameServer */
2601 phba->fc_ns_retry = 0; 2990 vport->fc_ns_retry = 0;
2602 ndlp = lpfc_findnode_did(phba, NameServer_DID); 2991 ndlp = lpfc_findnode_did(vport, NameServer_DID);
2603 if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) { 2992 if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
2604 /* Good ndlp, issue CT Request to NameServer */ 2993 /* Good ndlp, issue CT Request to NameServer */
2605 if (lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT) == 0) { 2994 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
2606 /* Wait for NameServer query cmpl before we can 2995 /* Wait for NameServer query cmpl before we can
2607 continue */ 2996 continue */
2608 return 1; 2997 return 1;
2609 }
2610 } else { 2998 } else {
2611 /* If login to NameServer does not exist, issue one */ 2999 /* If login to NameServer does not exist, issue one */
2612 /* Good status, issue PLOGI to NameServer */ 3000 /* Good status, issue PLOGI to NameServer */
2613 ndlp = lpfc_findnode_did(phba, NameServer_DID); 3001 ndlp = lpfc_findnode_did(vport, NameServer_DID);
2614 if (ndlp) { 3002 if (ndlp)
2615 /* Wait for NameServer login cmpl before we can 3003 /* Wait for NameServer login cmpl before we can
2616 continue */ 3004 continue */
2617 return 1; 3005 return 1;
2618 } 3006
2619 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); 3007 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2620 if (!ndlp) { 3008 if (!ndlp) {
2621 lpfc_els_flush_rscn(phba); 3009 lpfc_els_flush_rscn(vport);
2622 return 0; 3010 return 0;
2623 } else { 3011 } else {
2624 lpfc_nlp_init(phba, ndlp, NameServer_DID); 3012 lpfc_nlp_init(vport, ndlp, NameServer_DID);
2625 ndlp->nlp_type |= NLP_FABRIC; 3013 ndlp->nlp_type |= NLP_FABRIC;
2626 ndlp->nlp_prev_state = ndlp->nlp_state; 3014 ndlp->nlp_prev_state = ndlp->nlp_state;
2627 lpfc_nlp_set_state(phba, ndlp, NLP_STE_PLOGI_ISSUE); 3015 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2628 lpfc_issue_els_plogi(phba, NameServer_DID, 0); 3016 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
2629 /* Wait for NameServer login cmpl before we can 3017 /* Wait for NameServer login cmpl before we can
2630 continue */ 3018 continue */
2631 return 1; 3019 return 1;
2632 } 3020 }
2633 } 3021 }
2634 3022
2635 lpfc_els_flush_rscn(phba); 3023 lpfc_els_flush_rscn(vport);
2636 return 0; 3024 return 0;
2637} 3025}
2638 3026
2639static int 3027static int
2640lpfc_els_rcv_flogi(struct lpfc_hba * phba, 3028lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
2641 struct lpfc_iocbq * cmdiocb, 3029 struct lpfc_nodelist *ndlp, uint8_t newnode)
2642 struct lpfc_nodelist * ndlp, uint8_t newnode)
2643{ 3030{
3031 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3032 struct lpfc_hba *phba = vport->phba;
2644 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; 3033 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2645 uint32_t *lp = (uint32_t *) pcmd->virt; 3034 uint32_t *lp = (uint32_t *) pcmd->virt;
2646 IOCB_t *icmd = &cmdiocb->iocb; 3035 IOCB_t *icmd = &cmdiocb->iocb;
@@ -2655,7 +3044,7 @@ lpfc_els_rcv_flogi(struct lpfc_hba * phba,
2655 3044
2656 /* FLOGI received */ 3045 /* FLOGI received */
2657 3046
2658 lpfc_set_disctmo(phba); 3047 lpfc_set_disctmo(vport);
2659 3048
2660 if (phba->fc_topology == TOPOLOGY_LOOP) { 3049 if (phba->fc_topology == TOPOLOGY_LOOP) {
2661 /* We should never receive a FLOGI in loop mode, ignore it */ 3050 /* We should never receive a FLOGI in loop mode, ignore it */
@@ -2664,33 +3053,34 @@ lpfc_els_rcv_flogi(struct lpfc_hba * phba,
2664 /* An FLOGI ELS command <elsCmd> was received from DID <did> in 3053 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
2665 Loop Mode */ 3054 Loop Mode */
2666 lpfc_printf_log(phba, KERN_ERR, LOG_ELS, 3055 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
2667 "%d:0113 An FLOGI ELS command x%x was received " 3056 "%d (%d):0113 An FLOGI ELS command x%x was "
2668 "from DID x%x in Loop Mode\n", 3057 "received from DID x%x in Loop Mode\n",
2669 phba->brd_no, cmd, did); 3058 phba->brd_no, vport->vpi, cmd, did);
2670 return 1; 3059 return 1;
2671 } 3060 }
2672 3061
2673 did = Fabric_DID; 3062 did = Fabric_DID;
2674 3063
2675 if ((lpfc_check_sparm(phba, ndlp, sp, CLASS3))) { 3064 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3))) {
2676 /* For a FLOGI we accept, then if our portname is greater 3065 /* For a FLOGI we accept, then if our portname is greater
2677 * then the remote portname we initiate Nport login. 3066 * then the remote portname we initiate Nport login.
2678 */ 3067 */
2679 3068
2680 rc = memcmp(&phba->fc_portname, &sp->portName, 3069 rc = memcmp(&vport->fc_portname, &sp->portName,
2681 sizeof (struct lpfc_name)); 3070 sizeof(struct lpfc_name));
2682 3071
2683 if (!rc) { 3072 if (!rc) {
2684 if ((mbox = mempool_alloc(phba->mbox_mem_pool, 3073 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2685 GFP_KERNEL)) == 0) { 3074 if (!mbox)
2686 return 1; 3075 return 1;
2687 } 3076
2688 lpfc_linkdown(phba); 3077 lpfc_linkdown(phba);
2689 lpfc_init_link(phba, mbox, 3078 lpfc_init_link(phba, mbox,
2690 phba->cfg_topology, 3079 phba->cfg_topology,
2691 phba->cfg_link_speed); 3080 phba->cfg_link_speed);
2692 mbox->mb.un.varInitLnk.lipsr_AL_PA = 0; 3081 mbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
2693 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; 3082 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
3083 mbox->vport = vport;
2694 rc = lpfc_sli_issue_mbox 3084 rc = lpfc_sli_issue_mbox
2695 (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB)); 3085 (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
2696 lpfc_set_loopback_flag(phba); 3086 lpfc_set_loopback_flag(phba);
@@ -2699,31 +3089,34 @@ lpfc_els_rcv_flogi(struct lpfc_hba * phba,
2699 } 3089 }
2700 return 1; 3090 return 1;
2701 } else if (rc > 0) { /* greater than */ 3091 } else if (rc > 0) { /* greater than */
2702 spin_lock_irq(phba->host->host_lock); 3092 spin_lock_irq(shost->host_lock);
2703 phba->fc_flag |= FC_PT2PT_PLOGI; 3093 vport->fc_flag |= FC_PT2PT_PLOGI;
2704 spin_unlock_irq(phba->host->host_lock); 3094 spin_unlock_irq(shost->host_lock);
2705 } 3095 }
2706 phba->fc_flag |= FC_PT2PT; 3096 spin_lock_irq(shost->host_lock);
2707 phba->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); 3097 vport->fc_flag |= FC_PT2PT;
3098 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
3099 spin_unlock_irq(shost->host_lock);
2708 } else { 3100 } else {
2709 /* Reject this request because invalid parameters */ 3101 /* Reject this request because invalid parameters */
2710 stat.un.b.lsRjtRsvd0 = 0; 3102 stat.un.b.lsRjtRsvd0 = 0;
2711 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; 3103 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2712 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS; 3104 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
2713 stat.un.b.vendorUnique = 0; 3105 stat.un.b.vendorUnique = 0;
2714 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp); 3106 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3107 NULL);
2715 return 1; 3108 return 1;
2716 } 3109 }
2717 3110
2718 /* Send back ACC */ 3111 /* Send back ACC */
2719 lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL, newnode); 3112 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL, newnode);
2720 3113
2721 return 0; 3114 return 0;
2722} 3115}
2723 3116
2724static int 3117static int
2725lpfc_els_rcv_rnid(struct lpfc_hba * phba, 3118lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
2726 struct lpfc_iocbq * cmdiocb, struct lpfc_nodelist * ndlp) 3119 struct lpfc_nodelist *ndlp)
2727{ 3120{
2728 struct lpfc_dmabuf *pcmd; 3121 struct lpfc_dmabuf *pcmd;
2729 uint32_t *lp; 3122 uint32_t *lp;
@@ -2746,7 +3139,7 @@ lpfc_els_rcv_rnid(struct lpfc_hba * phba,
2746 case 0: 3139 case 0:
2747 case RNID_TOPOLOGY_DISC: 3140 case RNID_TOPOLOGY_DISC:
2748 /* Send back ACC */ 3141 /* Send back ACC */
2749 lpfc_els_rsp_rnid_acc(phba, rn->Format, cmdiocb, ndlp); 3142 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
2750 break; 3143 break;
2751 default: 3144 default:
2752 /* Reject this request because format not supported */ 3145 /* Reject this request because format not supported */
@@ -2754,14 +3147,15 @@ lpfc_els_rcv_rnid(struct lpfc_hba * phba,
2754 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; 3147 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2755 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; 3148 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
2756 stat.un.b.vendorUnique = 0; 3149 stat.un.b.vendorUnique = 0;
2757 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp); 3150 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3151 NULL);
2758 } 3152 }
2759 return 0; 3153 return 0;
2760} 3154}
2761 3155
2762static int 3156static int
2763lpfc_els_rcv_lirr(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 3157lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
2764 struct lpfc_nodelist *ndlp) 3158 struct lpfc_nodelist *ndlp)
2765{ 3159{
2766 struct ls_rjt stat; 3160 struct ls_rjt stat;
2767 3161
@@ -2770,15 +3164,15 @@ lpfc_els_rcv_lirr(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2770 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; 3164 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2771 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; 3165 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
2772 stat.un.b.vendorUnique = 0; 3166 stat.un.b.vendorUnique = 0;
2773 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp); 3167 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2774 return 0; 3168 return 0;
2775} 3169}
2776 3170
2777static void 3171static void
2778lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) 3172lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2779{ 3173{
2780 struct lpfc_sli *psli; 3174 struct lpfc_sli *psli = &phba->sli;
2781 struct lpfc_sli_ring *pring; 3175 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
2782 MAILBOX_t *mb; 3176 MAILBOX_t *mb;
2783 IOCB_t *icmd; 3177 IOCB_t *icmd;
2784 RPS_RSP *rps_rsp; 3178 RPS_RSP *rps_rsp;
@@ -2788,8 +3182,6 @@ lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2788 uint16_t xri, status; 3182 uint16_t xri, status;
2789 uint32_t cmdsize; 3183 uint32_t cmdsize;
2790 3184
2791 psli = &phba->sli;
2792 pring = &psli->ring[LPFC_ELS_RING];
2793 mb = &pmb->mb; 3185 mb = &pmb->mb;
2794 3186
2795 ndlp = (struct lpfc_nodelist *) pmb->context2; 3187 ndlp = (struct lpfc_nodelist *) pmb->context2;
@@ -2804,8 +3196,9 @@ lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2804 3196
2805 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t); 3197 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
2806 mempool_free(pmb, phba->mbox_mem_pool); 3198 mempool_free(pmb, phba->mbox_mem_pool);
2807 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, lpfc_max_els_tries, ndlp, 3199 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
2808 ndlp->nlp_DID, ELS_CMD_ACC); 3200 lpfc_max_els_tries, ndlp,
3201 ndlp->nlp_DID, ELS_CMD_ACC);
2809 lpfc_nlp_put(ndlp); 3202 lpfc_nlp_put(ndlp);
2810 if (!elsiocb) 3203 if (!elsiocb)
2811 return; 3204 return;
@@ -2815,14 +3208,14 @@ lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2815 3208
2816 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); 3209 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2817 *((uint32_t *) (pcmd)) = ELS_CMD_ACC; 3210 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2818 pcmd += sizeof (uint32_t); /* Skip past command */ 3211 pcmd += sizeof(uint32_t); /* Skip past command */
2819 rps_rsp = (RPS_RSP *)pcmd; 3212 rps_rsp = (RPS_RSP *)pcmd;
2820 3213
2821 if (phba->fc_topology != TOPOLOGY_LOOP) 3214 if (phba->fc_topology != TOPOLOGY_LOOP)
2822 status = 0x10; 3215 status = 0x10;
2823 else 3216 else
2824 status = 0x8; 3217 status = 0x8;
2825 if (phba->fc_flag & FC_FABRIC) 3218 if (phba->pport->fc_flag & FC_FABRIC)
2826 status |= 0x4; 3219 status |= 0x4;
2827 3220
2828 rps_rsp->rsvd1 = 0; 3221 rps_rsp->rsvd1 = 0;
@@ -2836,25 +3229,25 @@ lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2836 3229
2837 /* Xmit ELS RPS ACC response tag <ulpIoTag> */ 3230 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
2838 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 3231 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2839 "%d:0118 Xmit ELS RPS ACC response tag x%x xri x%x, " 3232 "%d (%d):0118 Xmit ELS RPS ACC response tag x%x "
2840 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", 3233 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
2841 phba->brd_no, elsiocb->iotag, 3234 "rpi x%x\n",
3235 phba->brd_no, ndlp->vport->vpi, elsiocb->iotag,
2842 elsiocb->iocb.ulpContext, ndlp->nlp_DID, 3236 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2843 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); 3237 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2844 3238
2845 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc; 3239 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
2846 phba->fc_stat.elsXmitACC++; 3240 phba->fc_stat.elsXmitACC++;
2847 3241 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR)
2848 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
2849 lpfc_els_free_iocb(phba, elsiocb); 3242 lpfc_els_free_iocb(phba, elsiocb);
2850 }
2851 return; 3243 return;
2852} 3244}
2853 3245
2854static int 3246static int
2855lpfc_els_rcv_rps(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb, 3247lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
2856 struct lpfc_nodelist * ndlp) 3248 struct lpfc_nodelist *ndlp)
2857{ 3249{
3250 struct lpfc_hba *phba = vport->phba;
2858 uint32_t *lp; 3251 uint32_t *lp;
2859 uint8_t flag; 3252 uint8_t flag;
2860 LPFC_MBOXQ_t *mbox; 3253 LPFC_MBOXQ_t *mbox;
@@ -2868,7 +3261,8 @@ lpfc_els_rcv_rps(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
2868 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; 3261 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2869 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; 3262 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
2870 stat.un.b.vendorUnique = 0; 3263 stat.un.b.vendorUnique = 0;
2871 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp); 3264 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3265 NULL);
2872 } 3266 }
2873 3267
2874 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; 3268 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
@@ -2878,19 +3272,24 @@ lpfc_els_rcv_rps(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
2878 3272
2879 if ((flag == 0) || 3273 if ((flag == 0) ||
2880 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) || 3274 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
2881 ((flag == 2) && (memcmp(&rps->un.portName, &phba->fc_portname, 3275 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
2882 sizeof (struct lpfc_name)) == 0))) { 3276 sizeof(struct lpfc_name)) == 0))) {
2883 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC))) { 3277
3278 printk("Fix me....\n");
3279 dump_stack();
3280 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
3281 if (mbox) {
2884 lpfc_read_lnk_stat(phba, mbox); 3282 lpfc_read_lnk_stat(phba, mbox);
2885 mbox->context1 = 3283 mbox->context1 =
2886 (void *)((unsigned long)cmdiocb->iocb.ulpContext); 3284 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
2887 mbox->context2 = lpfc_nlp_get(ndlp); 3285 mbox->context2 = lpfc_nlp_get(ndlp);
3286 mbox->vport = vport;
2888 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc; 3287 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
2889 if (lpfc_sli_issue_mbox (phba, mbox, 3288 if (lpfc_sli_issue_mbox (phba, mbox,
2890 (MBX_NOWAIT | MBX_STOP_IOCB)) != MBX_NOT_FINISHED) { 3289 (MBX_NOWAIT | MBX_STOP_IOCB)) != MBX_NOT_FINISHED)
2891 /* Mbox completion will send ELS Response */ 3290 /* Mbox completion will send ELS Response */
2892 return 0; 3291 return 0;
2893 } 3292
2894 lpfc_nlp_put(ndlp); 3293 lpfc_nlp_put(ndlp);
2895 mempool_free(mbox, phba->mbox_mem_pool); 3294 mempool_free(mbox, phba->mbox_mem_pool);
2896 } 3295 }
@@ -2899,27 +3298,25 @@ lpfc_els_rcv_rps(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
2899 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; 3298 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2900 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; 3299 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
2901 stat.un.b.vendorUnique = 0; 3300 stat.un.b.vendorUnique = 0;
2902 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp); 3301 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
2903 return 0; 3302 return 0;
2904} 3303}
2905 3304
2906static int 3305static int
2907lpfc_els_rsp_rpl_acc(struct lpfc_hba * phba, uint16_t cmdsize, 3306lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
2908 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp) 3307 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
2909{ 3308{
2910 IOCB_t *icmd; 3309 struct lpfc_hba *phba = vport->phba;
2911 IOCB_t *oldcmd; 3310 IOCB_t *icmd, *oldcmd;
2912 RPL_RSP rpl_rsp; 3311 RPL_RSP rpl_rsp;
2913 struct lpfc_iocbq *elsiocb; 3312 struct lpfc_iocbq *elsiocb;
2914 struct lpfc_sli_ring *pring; 3313 struct lpfc_sli *psli = &phba->sli;
2915 struct lpfc_sli *psli; 3314 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
2916 uint8_t *pcmd; 3315 uint8_t *pcmd;
2917 3316
2918 psli = &phba->sli; 3317 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2919 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ 3318 ndlp->nlp_DID, ELS_CMD_ACC);
2920 3319
2921 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
2922 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
2923 if (!elsiocb) 3320 if (!elsiocb)
2924 return 1; 3321 return 1;
2925 3322
@@ -2929,7 +3326,7 @@ lpfc_els_rsp_rpl_acc(struct lpfc_hba * phba, uint16_t cmdsize,
2929 3326
2930 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); 3327 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2931 *((uint32_t *) (pcmd)) = ELS_CMD_ACC; 3328 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2932 pcmd += sizeof (uint16_t); 3329 pcmd += sizeof(uint16_t);
2933 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize); 3330 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
2934 pcmd += sizeof(uint16_t); 3331 pcmd += sizeof(uint16_t);
2935 3332
@@ -2937,8 +3334,8 @@ lpfc_els_rsp_rpl_acc(struct lpfc_hba * phba, uint16_t cmdsize,
2937 rpl_rsp.listLen = be32_to_cpu(1); 3334 rpl_rsp.listLen = be32_to_cpu(1);
2938 rpl_rsp.index = 0; 3335 rpl_rsp.index = 0;
2939 rpl_rsp.port_num_blk.portNum = 0; 3336 rpl_rsp.port_num_blk.portNum = 0;
2940 rpl_rsp.port_num_blk.portID = be32_to_cpu(phba->fc_myDID); 3337 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
2941 memcpy(&rpl_rsp.port_num_blk.portName, &phba->fc_portname, 3338 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
2942 sizeof(struct lpfc_name)); 3339 sizeof(struct lpfc_name));
2943 3340
2944 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t)); 3341 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
@@ -2946,13 +3343,14 @@ lpfc_els_rsp_rpl_acc(struct lpfc_hba * phba, uint16_t cmdsize,
2946 3343
2947 /* Xmit ELS RPL ACC response tag <ulpIoTag> */ 3344 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
2948 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 3345 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2949 "%d:0120 Xmit ELS RPL ACC response tag x%x xri x%x, " 3346 "%d (%d):0120 Xmit ELS RPL ACC response tag x%x "
2950 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", 3347 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
2951 phba->brd_no, elsiocb->iotag, 3348 "rpi x%x\n",
3349 phba->brd_no, vport->vpi, elsiocb->iotag,
2952 elsiocb->iocb.ulpContext, ndlp->nlp_DID, 3350 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2953 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); 3351 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2954 3352
2955 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc; 3353 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
2956 3354
2957 phba->fc_stat.elsXmitACC++; 3355 phba->fc_stat.elsXmitACC++;
2958 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { 3356 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
@@ -2963,8 +3361,8 @@ lpfc_els_rsp_rpl_acc(struct lpfc_hba * phba, uint16_t cmdsize,
2963} 3361}
2964 3362
2965static int 3363static int
2966lpfc_els_rcv_rpl(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb, 3364lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
2967 struct lpfc_nodelist * ndlp) 3365 struct lpfc_nodelist *ndlp)
2968{ 3366{
2969 struct lpfc_dmabuf *pcmd; 3367 struct lpfc_dmabuf *pcmd;
2970 uint32_t *lp; 3368 uint32_t *lp;
@@ -2979,7 +3377,8 @@ lpfc_els_rcv_rpl(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
2979 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; 3377 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2980 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA; 3378 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
2981 stat.un.b.vendorUnique = 0; 3379 stat.un.b.vendorUnique = 0;
2982 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp); 3380 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3381 NULL);
2983 } 3382 }
2984 3383
2985 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; 3384 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
@@ -2996,15 +3395,16 @@ lpfc_els_rcv_rpl(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
2996 } else { 3395 } else {
2997 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t); 3396 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
2998 } 3397 }
2999 lpfc_els_rsp_rpl_acc(phba, cmdsize, cmdiocb, ndlp); 3398 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
3000 3399
3001 return 0; 3400 return 0;
3002} 3401}
3003 3402
3004static int 3403static int
3005lpfc_els_rcv_farp(struct lpfc_hba * phba, 3404lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3006 struct lpfc_iocbq * cmdiocb, struct lpfc_nodelist * ndlp) 3405 struct lpfc_nodelist *ndlp)
3007{ 3406{
3407 struct lpfc_hba *phba = vport->phba;
3008 struct lpfc_dmabuf *pcmd; 3408 struct lpfc_dmabuf *pcmd;
3009 uint32_t *lp; 3409 uint32_t *lp;
3010 IOCB_t *icmd; 3410 IOCB_t *icmd;
@@ -3020,11 +3420,9 @@ lpfc_els_rcv_farp(struct lpfc_hba * phba,
3020 fp = (FARP *) lp; 3420 fp = (FARP *) lp;
3021 3421
3022 /* FARP-REQ received from DID <did> */ 3422 /* FARP-REQ received from DID <did> */
3023 lpfc_printf_log(phba, 3423 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
3024 KERN_INFO, 3424 "%d (%d):0601 FARP-REQ received from DID x%x\n",
3025 LOG_ELS, 3425 phba->brd_no, vport->vpi, did);
3026 "%d:0601 FARP-REQ received from DID x%x\n",
3027 phba->brd_no, did);
3028 3426
3029 /* We will only support match on WWPN or WWNN */ 3427 /* We will only support match on WWPN or WWNN */
3030 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) { 3428 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
@@ -3034,15 +3432,15 @@ lpfc_els_rcv_farp(struct lpfc_hba * phba,
3034 cnt = 0; 3432 cnt = 0;
3035 /* If this FARP command is searching for my portname */ 3433 /* If this FARP command is searching for my portname */
3036 if (fp->Mflags & FARP_MATCH_PORT) { 3434 if (fp->Mflags & FARP_MATCH_PORT) {
3037 if (memcmp(&fp->RportName, &phba->fc_portname, 3435 if (memcmp(&fp->RportName, &vport->fc_portname,
3038 sizeof (struct lpfc_name)) == 0) 3436 sizeof(struct lpfc_name)) == 0)
3039 cnt = 1; 3437 cnt = 1;
3040 } 3438 }
3041 3439
3042 /* If this FARP command is searching for my nodename */ 3440 /* If this FARP command is searching for my nodename */
3043 if (fp->Mflags & FARP_MATCH_NODE) { 3441 if (fp->Mflags & FARP_MATCH_NODE) {
3044 if (memcmp(&fp->RnodeName, &phba->fc_nodename, 3442 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
3045 sizeof (struct lpfc_name)) == 0) 3443 sizeof(struct lpfc_name)) == 0)
3046 cnt = 1; 3444 cnt = 1;
3047 } 3445 }
3048 3446
@@ -3052,28 +3450,28 @@ lpfc_els_rcv_farp(struct lpfc_hba * phba,
3052 /* Log back into the node before sending the FARP. */ 3450 /* Log back into the node before sending the FARP. */
3053 if (fp->Rflags & FARP_REQUEST_PLOGI) { 3451 if (fp->Rflags & FARP_REQUEST_PLOGI) {
3054 ndlp->nlp_prev_state = ndlp->nlp_state; 3452 ndlp->nlp_prev_state = ndlp->nlp_state;
3055 lpfc_nlp_set_state(phba, ndlp, 3453 lpfc_nlp_set_state(vport, ndlp,
3056 NLP_STE_PLOGI_ISSUE); 3454 NLP_STE_PLOGI_ISSUE);
3057 lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0); 3455 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
3058 } 3456 }
3059 3457
3060 /* Send a FARP response to that node */ 3458 /* Send a FARP response to that node */
3061 if (fp->Rflags & FARP_REQUEST_FARPR) { 3459 if (fp->Rflags & FARP_REQUEST_FARPR)
3062 lpfc_issue_els_farpr(phba, did, 0); 3460 lpfc_issue_els_farpr(vport, did, 0);
3063 }
3064 } 3461 }
3065 } 3462 }
3066 return 0; 3463 return 0;
3067} 3464}
3068 3465
3069static int 3466static int
3070lpfc_els_rcv_farpr(struct lpfc_hba * phba, 3467lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3071 struct lpfc_iocbq * cmdiocb, struct lpfc_nodelist * ndlp) 3468 struct lpfc_nodelist *ndlp)
3072{ 3469{
3073 struct lpfc_dmabuf *pcmd; 3470 struct lpfc_dmabuf *pcmd;
3074 uint32_t *lp; 3471 uint32_t *lp;
3075 IOCB_t *icmd; 3472 IOCB_t *icmd;
3076 uint32_t cmd, did; 3473 uint32_t cmd, did;
3474 struct lpfc_hba *phba = vport->phba;
3077 3475
3078 icmd = &cmdiocb->iocb; 3476 icmd = &cmdiocb->iocb;
3079 did = icmd->un.elsreq64.remoteID; 3477 did = icmd->un.elsreq64.remoteID;
@@ -3082,21 +3480,18 @@ lpfc_els_rcv_farpr(struct lpfc_hba * phba,
3082 3480
3083 cmd = *lp++; 3481 cmd = *lp++;
3084 /* FARP-RSP received from DID <did> */ 3482 /* FARP-RSP received from DID <did> */
3085 lpfc_printf_log(phba, 3483 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
3086 KERN_INFO, 3484 "%d (%d):0600 FARP-RSP received from DID x%x\n",
3087 LOG_ELS, 3485 phba->brd_no, vport->vpi, did);
3088 "%d:0600 FARP-RSP received from DID x%x\n",
3089 phba->brd_no, did);
3090
3091 /* ACCEPT the Farp resp request */ 3486 /* ACCEPT the Farp resp request */
3092 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0); 3487 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
3093 3488
3094 return 0; 3489 return 0;
3095} 3490}
3096 3491
3097static int 3492static int
3098lpfc_els_rcv_fan(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb, 3493lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3099 struct lpfc_nodelist * fan_ndlp) 3494 struct lpfc_nodelist *fan_ndlp)
3100{ 3495{
3101 struct lpfc_dmabuf *pcmd; 3496 struct lpfc_dmabuf *pcmd;
3102 uint32_t *lp; 3497 uint32_t *lp;
@@ -3104,10 +3499,12 @@ lpfc_els_rcv_fan(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
3104 uint32_t cmd, did; 3499 uint32_t cmd, did;
3105 FAN *fp; 3500 FAN *fp;
3106 struct lpfc_nodelist *ndlp, *next_ndlp; 3501 struct lpfc_nodelist *ndlp, *next_ndlp;
3502 struct lpfc_hba *phba = vport->phba;
3107 3503
3108 /* FAN received */ 3504 /* FAN received */
3109 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, "%d:0265 FAN received\n", 3505 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
3110 phba->brd_no); 3506 "%d (%d):0265 FAN received\n",
3507 phba->brd_no, vport->vpi);
3111 3508
3112 icmd = &cmdiocb->iocb; 3509 icmd = &cmdiocb->iocb;
3113 did = icmd->un.elsreq64.remoteID; 3510 did = icmd->un.elsreq64.remoteID;
@@ -3115,11 +3512,11 @@ lpfc_els_rcv_fan(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
3115 lp = (uint32_t *)pcmd->virt; 3512 lp = (uint32_t *)pcmd->virt;
3116 3513
3117 cmd = *lp++; 3514 cmd = *lp++;
3118 fp = (FAN *)lp; 3515 fp = (FAN *) lp;
3119 3516
3120 /* FAN received; Fan does not have a reply sequence */ 3517 /* FAN received; Fan does not have a reply sequence */
3121 3518
3122 if (phba->hba_state == LPFC_LOCAL_CFG_LINK) { 3519 if (phba->pport->port_state == LPFC_LOCAL_CFG_LINK) {
3123 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName, 3520 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
3124 sizeof(struct lpfc_name)) != 0) || 3521 sizeof(struct lpfc_name)) != 0) ||
3125 (memcmp(&phba->fc_fabparam.portName, &fp->FportName, 3522 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
@@ -3130,7 +3527,7 @@ lpfc_els_rcv_fan(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
3130 */ 3527 */
3131 3528
3132 list_for_each_entry_safe(ndlp, next_ndlp, 3529 list_for_each_entry_safe(ndlp, next_ndlp,
3133 &phba->fc_nodes, nlp_listp) { 3530 &vport->fc_nodes, nlp_listp) {
3134 if (ndlp->nlp_state != NLP_STE_NPR_NODE) 3531 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
3135 continue; 3532 continue;
3136 if (ndlp->nlp_type & NLP_FABRIC) { 3533 if (ndlp->nlp_type & NLP_FABRIC) {
@@ -3138,24 +3535,24 @@ lpfc_els_rcv_fan(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
3138 * Clean up old Fabric, Nameserver and 3535 * Clean up old Fabric, Nameserver and
3139 * other NLP_FABRIC logins 3536 * other NLP_FABRIC logins
3140 */ 3537 */
3141 lpfc_drop_node(phba, ndlp); 3538 lpfc_drop_node(vport, ndlp);
3142 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) { 3539 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
3143 /* Fail outstanding I/O now since this 3540 /* Fail outstanding I/O now since this
3144 * device is marked for PLOGI 3541 * device is marked for PLOGI
3145 */ 3542 */
3146 lpfc_unreg_rpi(phba, ndlp); 3543 lpfc_unreg_rpi(vport, ndlp);
3147 } 3544 }
3148 } 3545 }
3149 3546
3150 phba->hba_state = LPFC_FLOGI; 3547 vport->port_state = LPFC_FLOGI;
3151 lpfc_set_disctmo(phba); 3548 lpfc_set_disctmo(vport);
3152 lpfc_initial_flogi(phba); 3549 lpfc_initial_flogi(vport);
3153 return 0; 3550 return 0;
3154 } 3551 }
3155 /* Discovery not needed, 3552 /* Discovery not needed,
3156 * move the nodes to their original state. 3553 * move the nodes to their original state.
3157 */ 3554 */
3158 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nodes, 3555 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
3159 nlp_listp) { 3556 nlp_listp) {
3160 if (ndlp->nlp_state != NLP_STE_NPR_NODE) 3557 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
3161 continue; 3558 continue;
@@ -3163,13 +3560,13 @@ lpfc_els_rcv_fan(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
3163 switch (ndlp->nlp_prev_state) { 3560 switch (ndlp->nlp_prev_state) {
3164 case NLP_STE_UNMAPPED_NODE: 3561 case NLP_STE_UNMAPPED_NODE:
3165 ndlp->nlp_prev_state = NLP_STE_NPR_NODE; 3562 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
3166 lpfc_nlp_set_state(phba, ndlp, 3563 lpfc_nlp_set_state(vport, ndlp,
3167 NLP_STE_UNMAPPED_NODE); 3564 NLP_STE_UNMAPPED_NODE);
3168 break; 3565 break;
3169 3566
3170 case NLP_STE_MAPPED_NODE: 3567 case NLP_STE_MAPPED_NODE:
3171 ndlp->nlp_prev_state = NLP_STE_NPR_NODE; 3568 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
3172 lpfc_nlp_set_state(phba, ndlp, 3569 lpfc_nlp_set_state(vport, ndlp,
3173 NLP_STE_MAPPED_NODE); 3570 NLP_STE_MAPPED_NODE);
3174 break; 3571 break;
3175 3572
@@ -3179,7 +3576,7 @@ lpfc_els_rcv_fan(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
3179 } 3576 }
3180 3577
3181 /* Start discovery - this should just do CLEAR_LA */ 3578 /* Start discovery - this should just do CLEAR_LA */
3182 lpfc_disc_start(phba); 3579 lpfc_disc_start(vport);
3183 } 3580 }
3184 return 0; 3581 return 0;
3185} 3582}
@@ -3187,42 +3584,42 @@ lpfc_els_rcv_fan(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
3187void 3584void
3188lpfc_els_timeout(unsigned long ptr) 3585lpfc_els_timeout(unsigned long ptr)
3189{ 3586{
3190 struct lpfc_hba *phba; 3587 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
3588 struct lpfc_hba *phba = vport->phba;
3191 unsigned long iflag; 3589 unsigned long iflag;
3192 3590
3193 phba = (struct lpfc_hba *)ptr; 3591 spin_lock_irqsave(&vport->work_port_lock, iflag);
3194 if (phba == 0) 3592 if ((vport->work_port_events & WORKER_ELS_TMO) == 0) {
3195 return; 3593 vport->work_port_events |= WORKER_ELS_TMO;
3196 spin_lock_irqsave(phba->host->host_lock, iflag); 3594 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
3197 if (!(phba->work_hba_events & WORKER_ELS_TMO)) { 3595
3198 phba->work_hba_events |= WORKER_ELS_TMO; 3596 spin_lock_irqsave(&phba->hbalock, iflag);
3199 if (phba->work_wait) 3597 if (phba->work_wait)
3200 wake_up(phba->work_wait); 3598 lpfc_worker_wake_up(phba);
3599 spin_unlock_irqrestore(&phba->hbalock, iflag);
3201 } 3600 }
3202 spin_unlock_irqrestore(phba->host->host_lock, iflag); 3601 else
3602 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
3203 return; 3603 return;
3204} 3604}
3205 3605
3206void 3606void
3207lpfc_els_timeout_handler(struct lpfc_hba *phba) 3607lpfc_els_timeout_handler(struct lpfc_vport *vport)
3208{ 3608{
3609 struct lpfc_hba *phba = vport->phba;
3209 struct lpfc_sli_ring *pring; 3610 struct lpfc_sli_ring *pring;
3210 struct lpfc_iocbq *tmp_iocb, *piocb; 3611 struct lpfc_iocbq *tmp_iocb, *piocb;
3211 IOCB_t *cmd = NULL; 3612 IOCB_t *cmd = NULL;
3212 struct lpfc_dmabuf *pcmd; 3613 struct lpfc_dmabuf *pcmd;
3213 uint32_t *elscmd; 3614 uint32_t els_command = 0;
3214 uint32_t els_command=0;
3215 uint32_t timeout; 3615 uint32_t timeout;
3216 uint32_t remote_ID; 3616 uint32_t remote_ID = 0xffffffff;
3217 3617
3218 if (phba == 0)
3219 return;
3220 spin_lock_irq(phba->host->host_lock);
3221 /* If the timer is already canceled do nothing */ 3618 /* If the timer is already canceled do nothing */
3222 if (!(phba->work_hba_events & WORKER_ELS_TMO)) { 3619 if ((vport->work_port_events & WORKER_ELS_TMO) == 0) {
3223 spin_unlock_irq(phba->host->host_lock);
3224 return; 3620 return;
3225 } 3621 }
3622 spin_lock_irq(&phba->hbalock);
3226 timeout = (uint32_t)(phba->fc_ratov << 1); 3623 timeout = (uint32_t)(phba->fc_ratov << 1);
3227 3624
3228 pring = &phba->sli.ring[LPFC_ELS_RING]; 3625 pring = &phba->sli.ring[LPFC_ELS_RING];
@@ -3230,63 +3627,70 @@ lpfc_els_timeout_handler(struct lpfc_hba *phba)
3230 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { 3627 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
3231 cmd = &piocb->iocb; 3628 cmd = &piocb->iocb;
3232 3629
3233 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) || 3630 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
3234 (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN) || 3631 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
3235 (piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)) { 3632 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
3236 continue; 3633 continue;
3237 } 3634
3635 if (piocb->vport != vport)
3636 continue;
3637
3238 pcmd = (struct lpfc_dmabuf *) piocb->context2; 3638 pcmd = (struct lpfc_dmabuf *) piocb->context2;
3239 if (pcmd) { 3639 if (pcmd)
3240 elscmd = (uint32_t *) (pcmd->virt); 3640 els_command = *(uint32_t *) (pcmd->virt);
3241 els_command = *elscmd;
3242 }
3243 3641
3244 if ((els_command == ELS_CMD_FARP) 3642 if (els_command == ELS_CMD_FARP ||
3245 || (els_command == ELS_CMD_FARPR)) { 3643 els_command == ELS_CMD_FARPR ||
3644 els_command == ELS_CMD_FDISC)
3645 continue;
3646
3647 if (vport != piocb->vport)
3246 continue; 3648 continue;
3247 }
3248 3649
3249 if (piocb->drvrTimeout > 0) { 3650 if (piocb->drvrTimeout > 0) {
3250 if (piocb->drvrTimeout >= timeout) { 3651 if (piocb->drvrTimeout >= timeout)
3251 piocb->drvrTimeout -= timeout; 3652 piocb->drvrTimeout -= timeout;
3252 } else { 3653 else
3253 piocb->drvrTimeout = 0; 3654 piocb->drvrTimeout = 0;
3254 }
3255 continue; 3655 continue;
3256 } 3656 }
3257 3657
3258 if (cmd->ulpCommand == CMD_GEN_REQUEST64_CR) { 3658 remote_ID = 0xffffffff;
3259 struct lpfc_nodelist *ndlp; 3659 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
3260 ndlp = __lpfc_findnode_rpi(phba, cmd->ulpContext);
3261 remote_ID = ndlp->nlp_DID;
3262 } else {
3263 remote_ID = cmd->un.elsreq64.remoteID; 3660 remote_ID = cmd->un.elsreq64.remoteID;
3661 else {
3662 struct lpfc_nodelist *ndlp;
3663 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
3664 if (ndlp)
3665 remote_ID = ndlp->nlp_DID;
3264 } 3666 }
3265 3667
3266 lpfc_printf_log(phba, 3668 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
3267 KERN_ERR, 3669 "%d (%d):0127 ELS timeout Data: x%x x%x x%x "
3268 LOG_ELS, 3670 "x%x\n",
3269 "%d:0127 ELS timeout Data: x%x x%x x%x x%x\n", 3671 phba->brd_no, vport->vpi, els_command,
3270 phba->brd_no, els_command,
3271 remote_ID, cmd->ulpCommand, cmd->ulpIoTag); 3672 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
3272 3673
3273 lpfc_sli_issue_abort_iotag(phba, pring, piocb); 3674 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
3274 } 3675 }
3275 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt) 3676 spin_unlock_irq(&phba->hbalock);
3276 mod_timer(&phba->els_tmofunc, jiffies + HZ * timeout);
3277 3677
3278 spin_unlock_irq(phba->host->host_lock); 3678 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
3679 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
3279} 3680}
3280 3681
3281void 3682void
3282lpfc_els_flush_cmd(struct lpfc_hba *phba) 3683lpfc_els_flush_cmd(struct lpfc_vport *vport)
3283{ 3684{
3284 LIST_HEAD(completions); 3685 LIST_HEAD(completions);
3686 struct lpfc_hba *phba = vport->phba;
3285 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; 3687 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
3286 struct lpfc_iocbq *tmp_iocb, *piocb; 3688 struct lpfc_iocbq *tmp_iocb, *piocb;
3287 IOCB_t *cmd = NULL; 3689 IOCB_t *cmd = NULL;
3288 3690
3289 spin_lock_irq(phba->host->host_lock); 3691 lpfc_fabric_abort_vport(vport);
3692
3693 spin_lock_irq(&phba->hbalock);
3290 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { 3694 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
3291 cmd = &piocb->iocb; 3695 cmd = &piocb->iocb;
3292 3696
@@ -3301,271 +3705,1042 @@ lpfc_els_flush_cmd(struct lpfc_hba *phba)
3301 cmd->ulpCommand == CMD_ABORT_XRI_CN) 3705 cmd->ulpCommand == CMD_ABORT_XRI_CN)
3302 continue; 3706 continue;
3303 3707
3708 if (piocb->vport != vport)
3709 continue;
3710
3304 list_move_tail(&piocb->list, &completions); 3711 list_move_tail(&piocb->list, &completions);
3305 pring->txq_cnt--; 3712 pring->txq_cnt--;
3306
3307 } 3713 }
3308 3714
3309 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { 3715 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
3310 cmd = &piocb->iocb;
3311
3312 if (piocb->iocb_flag & LPFC_IO_LIBDFC) { 3716 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3313 continue; 3717 continue;
3314 } 3718 }
3315 3719
3720 if (piocb->vport != vport)
3721 continue;
3722
3316 lpfc_sli_issue_abort_iotag(phba, pring, piocb); 3723 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
3317 } 3724 }
3318 spin_unlock_irq(phba->host->host_lock); 3725 spin_unlock_irq(&phba->hbalock);
3319 3726
3320 while(!list_empty(&completions)) { 3727 while (!list_empty(&completions)) {
3321 piocb = list_get_first(&completions, struct lpfc_iocbq, list); 3728 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
3322 cmd = &piocb->iocb; 3729 cmd = &piocb->iocb;
3323 list_del(&piocb->list); 3730 list_del_init(&piocb->list);
3324 3731
3325 if (piocb->iocb_cmpl) { 3732 if (!piocb->iocb_cmpl)
3733 lpfc_sli_release_iocbq(phba, piocb);
3734 else {
3326 cmd->ulpStatus = IOSTAT_LOCAL_REJECT; 3735 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3327 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; 3736 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
3328 (piocb->iocb_cmpl) (phba, piocb, piocb); 3737 (piocb->iocb_cmpl) (phba, piocb, piocb);
3329 } else 3738 }
3330 lpfc_sli_release_iocbq(phba, piocb);
3331 } 3739 }
3332 3740
3333 return; 3741 return;
3334} 3742}
3335 3743
3336void 3744static void
3337lpfc_els_unsol_event(struct lpfc_hba * phba, 3745lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3338 struct lpfc_sli_ring * pring, struct lpfc_iocbq * elsiocb) 3746 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
3339{ 3747{
3340 struct lpfc_sli *psli;
3341 struct lpfc_nodelist *ndlp; 3748 struct lpfc_nodelist *ndlp;
3342 struct lpfc_dmabuf *mp;
3343 uint32_t *lp;
3344 IOCB_t *icmd;
3345 struct ls_rjt stat; 3749 struct ls_rjt stat;
3346 uint32_t cmd; 3750 uint32_t *payload;
3347 uint32_t did; 3751 uint32_t cmd, did, newnode, rjt_err = 0;
3348 uint32_t newnode; 3752 IOCB_t *icmd = &elsiocb->iocb;
3349 uint32_t drop_cmd = 0; /* by default do NOT drop received cmd */
3350 uint32_t rjt_err = 0;
3351
3352 psli = &phba->sli;
3353 icmd = &elsiocb->iocb;
3354
3355 if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
3356 ((icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING)) {
3357 /* Not enough posted buffers; Try posting more buffers */
3358 phba->fc_stat.NoRcvBuf++;
3359 lpfc_post_buffer(phba, pring, 0, 1);
3360 return;
3361 }
3362
3363 /* If there are no BDEs associated with this IOCB,
3364 * there is nothing to do.
3365 */
3366 if (icmd->ulpBdeCount == 0)
3367 return;
3368 3753
3369 /* type of ELS cmd is first 32bit word in packet */ 3754 if (vport == NULL || elsiocb->context2 == NULL)
3370 mp = lpfc_sli_ringpostbuf_get(phba, pring, getPaddr(icmd->un.
3371 cont64[0].
3372 addrHigh,
3373 icmd->un.
3374 cont64[0].addrLow));
3375 if (mp == 0) {
3376 drop_cmd = 1;
3377 goto dropit; 3755 goto dropit;
3378 }
3379 3756
3380 newnode = 0; 3757 newnode = 0;
3381 lp = (uint32_t *) mp->virt; 3758 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
3382 cmd = *lp++; 3759 cmd = *payload;
3383 lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], 1, 1); 3760 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
3761 lpfc_post_buffer(phba, pring, 1, 1);
3384 3762
3763 did = icmd->un.rcvels.remoteID;
3385 if (icmd->ulpStatus) { 3764 if (icmd->ulpStatus) {
3386 lpfc_mbuf_free(phba, mp->virt, mp->phys); 3765 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3387 kfree(mp); 3766 "RCV Unsol ELS: status:x%x/x%x did:x%x",
3388 drop_cmd = 1; 3767 icmd->ulpStatus, icmd->un.ulpWord[4], did);
3389 goto dropit; 3768 goto dropit;
3390 } 3769 }
3391 3770
3392 /* Check to see if link went down during discovery */ 3771 /* Check to see if link went down during discovery */
3393 if (lpfc_els_chk_latt(phba)) { 3772 if (lpfc_els_chk_latt(vport))
3394 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3395 kfree(mp);
3396 drop_cmd = 1;
3397 goto dropit; 3773 goto dropit;
3398 }
3399 3774
3400 did = icmd->un.rcvels.remoteID; 3775 /* Ignore traffic recevied during vport shutdown. */
3401 ndlp = lpfc_findnode_did(phba, did); 3776 if (vport->load_flag & FC_UNLOADING)
3777 goto dropit;
3778
3779 ndlp = lpfc_findnode_did(vport, did);
3402 if (!ndlp) { 3780 if (!ndlp) {
3403 /* Cannot find existing Fabric ndlp, so allocate a new one */ 3781 /* Cannot find existing Fabric ndlp, so allocate a new one */
3404 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); 3782 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
3405 if (!ndlp) { 3783 if (!ndlp)
3406 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3407 kfree(mp);
3408 drop_cmd = 1;
3409 goto dropit; 3784 goto dropit;
3410 }
3411 3785
3412 lpfc_nlp_init(phba, ndlp, did); 3786 lpfc_nlp_init(vport, ndlp, did);
3413 newnode = 1; 3787 newnode = 1;
3414 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) { 3788 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) {
3415 ndlp->nlp_type |= NLP_FABRIC; 3789 ndlp->nlp_type |= NLP_FABRIC;
3416 } 3790 }
3417 lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNUSED_NODE); 3791 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
3418 } 3792 }
3419 3793
3420 phba->fc_stat.elsRcvFrame++; 3794 phba->fc_stat.elsRcvFrame++;
3421 if (elsiocb->context1) 3795 if (elsiocb->context1)
3422 lpfc_nlp_put(elsiocb->context1); 3796 lpfc_nlp_put(elsiocb->context1);
3423 elsiocb->context1 = lpfc_nlp_get(ndlp); 3797 elsiocb->context1 = lpfc_nlp_get(ndlp);
3424 elsiocb->context2 = mp; 3798 elsiocb->vport = vport;
3425 3799
3426 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) { 3800 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
3427 cmd &= ELS_CMD_MASK; 3801 cmd &= ELS_CMD_MASK;
3428 } 3802 }
3429 /* ELS command <elsCmd> received from NPORT <did> */ 3803 /* ELS command <elsCmd> received from NPORT <did> */
3430 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 3804 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
3431 "%d:0112 ELS command x%x received from NPORT x%x " 3805 "%d (%d):0112 ELS command x%x received from NPORT x%x "
3432 "Data: x%x\n", phba->brd_no, cmd, did, phba->hba_state); 3806 "Data: x%x\n", phba->brd_no, vport->vpi, cmd, did,
3807 vport->port_state);
3433 3808
3434 switch (cmd) { 3809 switch (cmd) {
3435 case ELS_CMD_PLOGI: 3810 case ELS_CMD_PLOGI:
3811 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3812 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
3813 did, vport->port_state, ndlp->nlp_flag);
3814
3436 phba->fc_stat.elsRcvPLOGI++; 3815 phba->fc_stat.elsRcvPLOGI++;
3437 if (phba->hba_state < LPFC_DISC_AUTH) { 3816 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
3438 rjt_err = 1; 3817
3818 if (vport->port_state < LPFC_DISC_AUTH) {
3819 rjt_err = LSRJT_UNABLE_TPC;
3439 break; 3820 break;
3440 } 3821 }
3441 ndlp = lpfc_plogi_confirm_nport(phba, mp, ndlp); 3822 lpfc_disc_state_machine(vport, ndlp, elsiocb,
3442 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PLOGI); 3823 NLP_EVT_RCV_PLOGI);
3824
3443 break; 3825 break;
3444 case ELS_CMD_FLOGI: 3826 case ELS_CMD_FLOGI:
3827 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3828 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
3829 did, vport->port_state, ndlp->nlp_flag);
3830
3445 phba->fc_stat.elsRcvFLOGI++; 3831 phba->fc_stat.elsRcvFLOGI++;
3446 lpfc_els_rcv_flogi(phba, elsiocb, ndlp, newnode); 3832 lpfc_els_rcv_flogi(vport, elsiocb, ndlp, newnode);
3447 if (newnode) 3833 if (newnode)
3448 lpfc_drop_node(phba, ndlp); 3834 lpfc_drop_node(vport, ndlp);
3449 break; 3835 break;
3450 case ELS_CMD_LOGO: 3836 case ELS_CMD_LOGO:
3837 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3838 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
3839 did, vport->port_state, ndlp->nlp_flag);
3840
3451 phba->fc_stat.elsRcvLOGO++; 3841 phba->fc_stat.elsRcvLOGO++;
3452 if (phba->hba_state < LPFC_DISC_AUTH) { 3842 if (vport->port_state < LPFC_DISC_AUTH) {
3453 rjt_err = 1; 3843 rjt_err = LSRJT_UNABLE_TPC;
3454 break; 3844 break;
3455 } 3845 }
3456 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_LOGO); 3846 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
3457 break; 3847 break;
3458 case ELS_CMD_PRLO: 3848 case ELS_CMD_PRLO:
3849 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3850 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
3851 did, vport->port_state, ndlp->nlp_flag);
3852
3459 phba->fc_stat.elsRcvPRLO++; 3853 phba->fc_stat.elsRcvPRLO++;
3460 if (phba->hba_state < LPFC_DISC_AUTH) { 3854 if (vport->port_state < LPFC_DISC_AUTH) {
3461 rjt_err = 1; 3855 rjt_err = LSRJT_UNABLE_TPC;
3462 break; 3856 break;
3463 } 3857 }
3464 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PRLO); 3858 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
3465 break; 3859 break;
3466 case ELS_CMD_RSCN: 3860 case ELS_CMD_RSCN:
3467 phba->fc_stat.elsRcvRSCN++; 3861 phba->fc_stat.elsRcvRSCN++;
3468 lpfc_els_rcv_rscn(phba, elsiocb, ndlp, newnode); 3862 lpfc_els_rcv_rscn(vport, elsiocb, ndlp, newnode);
3469 if (newnode) 3863 if (newnode)
3470 lpfc_drop_node(phba, ndlp); 3864 lpfc_drop_node(vport, ndlp);
3471 break; 3865 break;
3472 case ELS_CMD_ADISC: 3866 case ELS_CMD_ADISC:
3867 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3868 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
3869 did, vport->port_state, ndlp->nlp_flag);
3870
3473 phba->fc_stat.elsRcvADISC++; 3871 phba->fc_stat.elsRcvADISC++;
3474 if (phba->hba_state < LPFC_DISC_AUTH) { 3872 if (vport->port_state < LPFC_DISC_AUTH) {
3475 rjt_err = 1; 3873 rjt_err = LSRJT_UNABLE_TPC;
3476 break; 3874 break;
3477 } 3875 }
3478 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_ADISC); 3876 lpfc_disc_state_machine(vport, ndlp, elsiocb,
3877 NLP_EVT_RCV_ADISC);
3479 break; 3878 break;
3480 case ELS_CMD_PDISC: 3879 case ELS_CMD_PDISC:
3880 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3881 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
3882 did, vport->port_state, ndlp->nlp_flag);
3883
3481 phba->fc_stat.elsRcvPDISC++; 3884 phba->fc_stat.elsRcvPDISC++;
3482 if (phba->hba_state < LPFC_DISC_AUTH) { 3885 if (vport->port_state < LPFC_DISC_AUTH) {
3483 rjt_err = 1; 3886 rjt_err = LSRJT_UNABLE_TPC;
3484 break; 3887 break;
3485 } 3888 }
3486 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PDISC); 3889 lpfc_disc_state_machine(vport, ndlp, elsiocb,
3890 NLP_EVT_RCV_PDISC);
3487 break; 3891 break;
3488 case ELS_CMD_FARPR: 3892 case ELS_CMD_FARPR:
3893 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3894 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
3895 did, vport->port_state, ndlp->nlp_flag);
3896
3489 phba->fc_stat.elsRcvFARPR++; 3897 phba->fc_stat.elsRcvFARPR++;
3490 lpfc_els_rcv_farpr(phba, elsiocb, ndlp); 3898 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
3491 break; 3899 break;
3492 case ELS_CMD_FARP: 3900 case ELS_CMD_FARP:
3901 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3902 "RCV FARP: did:x%x/ste:x%x flg:x%x",
3903 did, vport->port_state, ndlp->nlp_flag);
3904
3493 phba->fc_stat.elsRcvFARP++; 3905 phba->fc_stat.elsRcvFARP++;
3494 lpfc_els_rcv_farp(phba, elsiocb, ndlp); 3906 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
3495 break; 3907 break;
3496 case ELS_CMD_FAN: 3908 case ELS_CMD_FAN:
3909 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3910 "RCV FAN: did:x%x/ste:x%x flg:x%x",
3911 did, vport->port_state, ndlp->nlp_flag);
3912
3497 phba->fc_stat.elsRcvFAN++; 3913 phba->fc_stat.elsRcvFAN++;
3498 lpfc_els_rcv_fan(phba, elsiocb, ndlp); 3914 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
3499 break; 3915 break;
3500 case ELS_CMD_PRLI: 3916 case ELS_CMD_PRLI:
3917 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3918 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
3919 did, vport->port_state, ndlp->nlp_flag);
3920
3501 phba->fc_stat.elsRcvPRLI++; 3921 phba->fc_stat.elsRcvPRLI++;
3502 if (phba->hba_state < LPFC_DISC_AUTH) { 3922 if (vport->port_state < LPFC_DISC_AUTH) {
3503 rjt_err = 1; 3923 rjt_err = LSRJT_UNABLE_TPC;
3504 break; 3924 break;
3505 } 3925 }
3506 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PRLI); 3926 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
3507 break; 3927 break;
3508 case ELS_CMD_LIRR: 3928 case ELS_CMD_LIRR:
3929 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3930 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
3931 did, vport->port_state, ndlp->nlp_flag);
3932
3509 phba->fc_stat.elsRcvLIRR++; 3933 phba->fc_stat.elsRcvLIRR++;
3510 lpfc_els_rcv_lirr(phba, elsiocb, ndlp); 3934 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
3511 if (newnode) 3935 if (newnode)
3512 lpfc_drop_node(phba, ndlp); 3936 lpfc_drop_node(vport, ndlp);
3513 break; 3937 break;
3514 case ELS_CMD_RPS: 3938 case ELS_CMD_RPS:
3939 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3940 "RCV RPS: did:x%x/ste:x%x flg:x%x",
3941 did, vport->port_state, ndlp->nlp_flag);
3942
3515 phba->fc_stat.elsRcvRPS++; 3943 phba->fc_stat.elsRcvRPS++;
3516 lpfc_els_rcv_rps(phba, elsiocb, ndlp); 3944 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
3517 if (newnode) 3945 if (newnode)
3518 lpfc_drop_node(phba, ndlp); 3946 lpfc_drop_node(vport, ndlp);
3519 break; 3947 break;
3520 case ELS_CMD_RPL: 3948 case ELS_CMD_RPL:
3949 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3950 "RCV RPL: did:x%x/ste:x%x flg:x%x",
3951 did, vport->port_state, ndlp->nlp_flag);
3952
3521 phba->fc_stat.elsRcvRPL++; 3953 phba->fc_stat.elsRcvRPL++;
3522 lpfc_els_rcv_rpl(phba, elsiocb, ndlp); 3954 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
3523 if (newnode) 3955 if (newnode)
3524 lpfc_drop_node(phba, ndlp); 3956 lpfc_drop_node(vport, ndlp);
3525 break; 3957 break;
3526 case ELS_CMD_RNID: 3958 case ELS_CMD_RNID:
3959 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3960 "RCV RNID: did:x%x/ste:x%x flg:x%x",
3961 did, vport->port_state, ndlp->nlp_flag);
3962
3527 phba->fc_stat.elsRcvRNID++; 3963 phba->fc_stat.elsRcvRNID++;
3528 lpfc_els_rcv_rnid(phba, elsiocb, ndlp); 3964 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
3529 if (newnode) 3965 if (newnode)
3530 lpfc_drop_node(phba, ndlp); 3966 lpfc_drop_node(vport, ndlp);
3531 break; 3967 break;
3532 default: 3968 default:
3969 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3970 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
3971 cmd, did, vport->port_state);
3972
3533 /* Unsupported ELS command, reject */ 3973 /* Unsupported ELS command, reject */
3534 rjt_err = 1; 3974 rjt_err = LSRJT_INVALID_CMD;
3535 3975
3536 /* Unknown ELS command <elsCmd> received from NPORT <did> */ 3976 /* Unknown ELS command <elsCmd> received from NPORT <did> */
3537 lpfc_printf_log(phba, KERN_ERR, LOG_ELS, 3977 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
3538 "%d:0115 Unknown ELS command x%x received from " 3978 "%d (%d):0115 Unknown ELS command x%x "
3539 "NPORT x%x\n", phba->brd_no, cmd, did); 3979 "received from NPORT x%x\n",
3980 phba->brd_no, vport->vpi, cmd, did);
3540 if (newnode) 3981 if (newnode)
3541 lpfc_drop_node(phba, ndlp); 3982 lpfc_drop_node(vport, ndlp);
3542 break; 3983 break;
3543 } 3984 }
3544 3985
3545 /* check if need to LS_RJT received ELS cmd */ 3986 /* check if need to LS_RJT received ELS cmd */
3546 if (rjt_err) { 3987 if (rjt_err) {
3547 stat.un.b.lsRjtRsvd0 = 0; 3988 memset(&stat, 0, sizeof(stat));
3548 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; 3989 stat.un.b.lsRjtRsnCode = rjt_err;
3549 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE; 3990 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
3550 stat.un.b.vendorUnique = 0; 3991 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
3551 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, elsiocb, ndlp); 3992 NULL);
3993 if (newnode)
3994 lpfc_drop_node(vport, ndlp);
3995 }
3996
3997 return;
3998
3999dropit:
4000 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
4001 "%d (%d):0111 Dropping received ELS cmd "
4002 "Data: x%x x%x x%x\n",
4003 phba->brd_no, vport ? vport->vpi : 0xffff,
4004 icmd->ulpStatus, icmd->un.ulpWord[4],
4005 icmd->ulpTimeout);
4006 phba->fc_stat.elsRcvDrop++;
4007}
4008
4009static struct lpfc_vport *
4010lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
4011{
4012 struct lpfc_vport *vport;
4013
4014 list_for_each_entry(vport, &phba->port_list, listentry) {
4015 if (vport->vpi == vpi)
4016 return vport;
4017 }
4018 return NULL;
4019}
4020
4021void
4022lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
4023 struct lpfc_iocbq *elsiocb)
4024{
4025 struct lpfc_vport *vport = phba->pport;
4026 IOCB_t *icmd = &elsiocb->iocb;
4027 dma_addr_t paddr;
4028 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
4029 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
4030
4031 elsiocb->context2 = NULL;
4032 elsiocb->context3 = NULL;
4033
4034 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
4035 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
4036 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
4037 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
4038 phba->fc_stat.NoRcvBuf++;
4039 /* Not enough posted buffers; Try posting more buffers */
4040 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
4041 lpfc_post_buffer(phba, pring, 0, 1);
4042 return;
4043 }
4044
4045 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
4046 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
4047 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
4048 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
4049 vport = phba->pport;
4050 else {
4051 uint16_t vpi = icmd->unsli3.rcvsli3.vpi;
4052 vport = lpfc_find_vport_by_vpid(phba, vpi);
4053 }
4054 }
4055 /* If there are no BDEs associated
4056 * with this IOCB, there is nothing to do.
4057 */
4058 if (icmd->ulpBdeCount == 0)
4059 return;
4060
4061 /* type of ELS cmd is first 32bit word
4062 * in packet
4063 */
4064 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
4065 elsiocb->context2 = bdeBuf1;
4066 } else {
4067 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
4068 icmd->un.cont64[0].addrLow);
4069 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
4070 paddr);
3552 } 4071 }
3553 4072
4073 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
4074 /*
4075 * The different unsolicited event handlers would tell us
4076 * if they are done with "mp" by setting context2 to NULL.
4077 */
3554 lpfc_nlp_put(elsiocb->context1); 4078 lpfc_nlp_put(elsiocb->context1);
3555 elsiocb->context1 = NULL; 4079 elsiocb->context1 = NULL;
3556 if (elsiocb->context2) { 4080 if (elsiocb->context2) {
3557 lpfc_mbuf_free(phba, mp->virt, mp->phys); 4081 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
3558 kfree(mp); 4082 elsiocb->context2 = NULL;
3559 } 4083 }
3560dropit: 4084
3561 /* check if need to drop received ELS cmd */ 4085 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
3562 if (drop_cmd == 1) { 4086 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
4087 icmd->ulpBdeCount == 2) {
4088 elsiocb->context2 = bdeBuf2;
4089 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
4090 /* free mp if we are done with it */
4091 if (elsiocb->context2) {
4092 lpfc_in_buf_free(phba, elsiocb->context2);
4093 elsiocb->context2 = NULL;
4094 }
4095 }
4096}
4097
4098void
4099lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
4100{
4101 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
4102
4103 ndlp = lpfc_findnode_did(vport, NameServer_DID);
4104 if (!ndlp) {
4105 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4106 if (!ndlp) {
4107 if (phba->fc_topology == TOPOLOGY_LOOP) {
4108 lpfc_disc_start(vport);
4109 return;
4110 }
4111 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4112 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
4113 "%d (%d):0251 NameServer login: no memory\n",
4114 phba->brd_no, vport->vpi);
4115 return;
4116 }
4117 lpfc_nlp_init(vport, ndlp, NameServer_DID);
4118 ndlp->nlp_type |= NLP_FABRIC;
4119 }
4120
4121 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4122
4123 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
4124 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3563 lpfc_printf_log(phba, KERN_ERR, LOG_ELS, 4125 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
3564 "%d:0111 Dropping received ELS cmd " 4126 "%d (%d):0252 Cannot issue NameServer login\n",
3565 "Data: x%x x%x x%x\n", phba->brd_no, 4127 phba->brd_no, vport->vpi);
3566 icmd->ulpStatus, icmd->un.ulpWord[4], 4128 return;
3567 icmd->ulpTimeout); 4129 }
3568 phba->fc_stat.elsRcvDrop++; 4130
4131 if (phba->cfg_fdmi_on) {
4132 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
4133 GFP_KERNEL);
4134 if (ndlp_fdmi) {
4135 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
4136 ndlp_fdmi->nlp_type |= NLP_FABRIC;
4137 ndlp_fdmi->nlp_state =
4138 NLP_STE_PLOGI_ISSUE;
4139 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID,
4140 0);
4141 }
4142 }
4143 return;
4144}
4145
4146static void
4147lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4148{
4149 struct lpfc_vport *vport = pmb->vport;
4150 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4151 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
4152 MAILBOX_t *mb = &pmb->mb;
4153
4154 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
4155 lpfc_nlp_put(ndlp);
4156
4157 if (mb->mbxStatus) {
4158 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
4159 "%d (%d):0915 Register VPI failed: 0x%x\n",
4160 phba->brd_no, vport->vpi, mb->mbxStatus);
4161
4162 switch (mb->mbxStatus) {
4163 case 0x11: /* unsupported feature */
4164 case 0x9603: /* max_vpi exceeded */
4165 /* giving up on vport registration */
4166 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4167 spin_lock_irq(shost->host_lock);
4168 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4169 spin_unlock_irq(shost->host_lock);
4170 lpfc_can_disctmo(vport);
4171 break;
4172 default:
4173 /* Try to recover from this error */
4174 lpfc_mbx_unreg_vpi(vport);
4175 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
4176 lpfc_initial_fdisc(vport);
4177 break;
4178 }
4179
4180 } else {
4181 if (vport == phba->pport)
4182 lpfc_issue_fabric_reglogin(vport);
4183 else
4184 lpfc_do_scr_ns_plogi(phba, vport);
3569 } 4185 }
4186 mempool_free(pmb, phba->mbox_mem_pool);
3570 return; 4187 return;
3571} 4188}
4189
4190void
4191lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
4192 struct lpfc_nodelist *ndlp)
4193{
4194 LPFC_MBOXQ_t *mbox;
4195
4196 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4197 if (mbox) {
4198 lpfc_reg_vpi(phba, vport->vpi, vport->fc_myDID, mbox);
4199 mbox->vport = vport;
4200 mbox->context2 = lpfc_nlp_get(ndlp);
4201 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
4202 if (lpfc_sli_issue_mbox(phba, mbox,
4203 MBX_NOWAIT | MBX_STOP_IOCB)
4204 == MBX_NOT_FINISHED) {
4205 mempool_free(mbox, phba->mbox_mem_pool);
4206 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
4207
4208 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4209
4210 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
4211 "%d (%d):0253 Register VPI: Cannot send mbox\n",
4212 phba->brd_no, vport->vpi);
4213 }
4214 } else {
4215 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4216
4217 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
4218 "%d (%d):0254 Register VPI: no memory\n",
4219 phba->brd_no, vport->vpi);
4220
4221 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
4222 lpfc_nlp_put(ndlp);
4223 }
4224}
4225
4226static void
4227lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4228 struct lpfc_iocbq *rspiocb)
4229{
4230 struct lpfc_vport *vport = cmdiocb->vport;
4231 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4232 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
4233 struct lpfc_nodelist *np;
4234 struct lpfc_nodelist *next_np;
4235 IOCB_t *irsp = &rspiocb->iocb;
4236 struct lpfc_iocbq *piocb;
4237
4238 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
4239 "%d (%d):0123 FDISC completes. x%x/x%x prevDID: x%x\n",
4240 phba->brd_no, vport->vpi,
4241 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
4242
4243 /* Since all FDISCs are being single threaded, we
4244 * must reset the discovery timer for ALL vports
4245 * waiting to send FDISC when one completes.
4246 */
4247 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
4248 lpfc_set_disctmo(piocb->vport);
4249 }
4250
4251 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4252 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
4253 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
4254
4255 if (irsp->ulpStatus) {
4256 /* Check for retry */
4257 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
4258 goto out;
4259
4260 /* FDISC failed */
4261 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
4262 "%d (%d):0124 FDISC failed. (%d/%d)\n",
4263 phba->brd_no, vport->vpi,
4264 irsp->ulpStatus, irsp->un.ulpWord[4]);
4265
4266 if (vport->fc_vport->vport_state == FC_VPORT_INITIALIZING)
4267 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4268
4269 lpfc_nlp_put(ndlp);
4270 /* giving up on FDISC. Cancel discovery timer */
4271 lpfc_can_disctmo(vport);
4272 } else {
4273 spin_lock_irq(shost->host_lock);
4274 vport->fc_flag |= FC_FABRIC;
4275 if (vport->phba->fc_topology == TOPOLOGY_LOOP)
4276 vport->fc_flag |= FC_PUBLIC_LOOP;
4277 spin_unlock_irq(shost->host_lock);
4278
4279 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
4280 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
4281 if ((vport->fc_prevDID != vport->fc_myDID) &&
4282 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
4283 /* If our NportID changed, we need to ensure all
4284 * remaining NPORTs get unreg_login'ed so we can
4285 * issue unreg_vpi.
4286 */
4287 list_for_each_entry_safe(np, next_np,
4288 &vport->fc_nodes, nlp_listp) {
4289 if (np->nlp_state != NLP_STE_NPR_NODE
4290 || !(np->nlp_flag & NLP_NPR_ADISC))
4291 continue;
4292 spin_lock_irq(shost->host_lock);
4293 np->nlp_flag &= ~NLP_NPR_ADISC;
4294 spin_unlock_irq(shost->host_lock);
4295 lpfc_unreg_rpi(vport, np);
4296 }
4297 lpfc_mbx_unreg_vpi(vport);
4298 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
4299 }
4300
4301 if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
4302 lpfc_register_new_vport(phba, vport, ndlp);
4303 else
4304 lpfc_do_scr_ns_plogi(phba, vport);
4305
4306 lpfc_nlp_put(ndlp); /* Free Fabric ndlp for vports */
4307 }
4308
4309out:
4310 lpfc_els_free_iocb(phba, cmdiocb);
4311}
4312
4313int
4314lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4315 uint8_t retry)
4316{
4317 struct lpfc_hba *phba = vport->phba;
4318 IOCB_t *icmd;
4319 struct lpfc_iocbq *elsiocb;
4320 struct serv_parm *sp;
4321 uint8_t *pcmd;
4322 uint16_t cmdsize;
4323 int did = ndlp->nlp_DID;
4324 int rc;
4325
4326 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
4327 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
4328 ELS_CMD_FDISC);
4329 if (!elsiocb) {
4330 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4331
4332 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
4333 "%d (%d):0255 Issue FDISC: no IOCB\n",
4334 phba->brd_no, vport->vpi);
4335 return 1;
4336 }
4337
4338 icmd = &elsiocb->iocb;
4339 icmd->un.elsreq64.myID = 0;
4340 icmd->un.elsreq64.fl = 1;
4341
4342 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
4343 icmd->ulpCt_h = 1;
4344 icmd->ulpCt_l = 0;
4345
4346 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4347 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
4348 pcmd += sizeof(uint32_t); /* CSP Word 1 */
4349 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
4350 sp = (struct serv_parm *) pcmd;
4351 /* Setup CSPs accordingly for Fabric */
4352 sp->cmn.e_d_tov = 0;
4353 sp->cmn.w2.r_a_tov = 0;
4354 sp->cls1.classValid = 0;
4355 sp->cls2.seqDelivery = 1;
4356 sp->cls3.seqDelivery = 1;
4357
4358 pcmd += sizeof(uint32_t); /* CSP Word 2 */
4359 pcmd += sizeof(uint32_t); /* CSP Word 3 */
4360 pcmd += sizeof(uint32_t); /* CSP Word 4 */
4361 pcmd += sizeof(uint32_t); /* Port Name */
4362 memcpy(pcmd, &vport->fc_portname, 8);
4363 pcmd += sizeof(uint32_t); /* Node Name */
4364 pcmd += sizeof(uint32_t); /* Node Name */
4365 memcpy(pcmd, &vport->fc_nodename, 8);
4366
4367 lpfc_set_disctmo(vport);
4368
4369 phba->fc_stat.elsXmitFDISC++;
4370 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
4371
4372 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4373 "Issue FDISC: did:x%x",
4374 did, 0, 0);
4375
4376 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
4377 if (rc == IOCB_ERROR) {
4378 lpfc_els_free_iocb(phba, elsiocb);
4379 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4380
4381 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
4382 "%d (%d):0256 Issue FDISC: Cannot send IOCB\n",
4383 phba->brd_no, vport->vpi);
4384
4385 return 1;
4386 }
4387 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
4388 vport->port_state = LPFC_FDISC;
4389 return 0;
4390}
4391
4392static void
4393lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4394 struct lpfc_iocbq *rspiocb)
4395{
4396 struct lpfc_vport *vport = cmdiocb->vport;
4397 IOCB_t *irsp;
4398
4399 irsp = &rspiocb->iocb;
4400 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4401 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
4402 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
4403
4404 lpfc_els_free_iocb(phba, cmdiocb);
4405 vport->unreg_vpi_cmpl = VPORT_ERROR;
4406}
4407
4408int
4409lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4410{
4411 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4412 struct lpfc_hba *phba = vport->phba;
4413 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4414 IOCB_t *icmd;
4415 struct lpfc_iocbq *elsiocb;
4416 uint8_t *pcmd;
4417 uint16_t cmdsize;
4418
4419 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
4420 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
4421 ELS_CMD_LOGO);
4422 if (!elsiocb)
4423 return 1;
4424
4425 icmd = &elsiocb->iocb;
4426 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4427 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
4428 pcmd += sizeof(uint32_t);
4429
4430 /* Fill in LOGO payload */
4431 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
4432 pcmd += sizeof(uint32_t);
4433 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
4434
4435 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4436 "Issue LOGO npiv did:x%x flg:x%x",
4437 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4438
4439 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
4440 spin_lock_irq(shost->host_lock);
4441 ndlp->nlp_flag |= NLP_LOGO_SND;
4442 spin_unlock_irq(shost->host_lock);
4443 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
4444 spin_lock_irq(shost->host_lock);
4445 ndlp->nlp_flag &= ~NLP_LOGO_SND;
4446 spin_unlock_irq(shost->host_lock);
4447 lpfc_els_free_iocb(phba, elsiocb);
4448 return 1;
4449 }
4450 return 0;
4451}
4452
4453void
4454lpfc_fabric_block_timeout(unsigned long ptr)
4455{
4456 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
4457 unsigned long iflags;
4458 uint32_t tmo_posted;
4459 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
4460 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
4461 if (!tmo_posted)
4462 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
4463 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
4464
4465 if (!tmo_posted) {
4466 spin_lock_irqsave(&phba->hbalock, iflags);
4467 if (phba->work_wait)
4468 lpfc_worker_wake_up(phba);
4469 spin_unlock_irqrestore(&phba->hbalock, iflags);
4470 }
4471}
4472
4473static void
4474lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
4475{
4476 struct lpfc_iocbq *iocb;
4477 unsigned long iflags;
4478 int ret;
4479 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4480 IOCB_t *cmd;
4481
4482repeat:
4483 iocb = NULL;
4484 spin_lock_irqsave(&phba->hbalock, iflags);
4485 /* Post any pending iocb to the SLI layer */
4486 if (atomic_read(&phba->fabric_iocb_count) == 0) {
4487 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
4488 list);
4489 if (iocb)
4490 atomic_inc(&phba->fabric_iocb_count);
4491 }
4492 spin_unlock_irqrestore(&phba->hbalock, iflags);
4493 if (iocb) {
4494 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
4495 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
4496 iocb->iocb_flag |= LPFC_IO_FABRIC;
4497
4498 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
4499 "Fabric sched1: ste:x%x",
4500 iocb->vport->port_state, 0, 0);
4501
4502 ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
4503
4504 if (ret == IOCB_ERROR) {
4505 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
4506 iocb->fabric_iocb_cmpl = NULL;
4507 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
4508 cmd = &iocb->iocb;
4509 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4510 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4511 iocb->iocb_cmpl(phba, iocb, iocb);
4512
4513 atomic_dec(&phba->fabric_iocb_count);
4514 goto repeat;
4515 }
4516 }
4517
4518 return;
4519}
4520
4521void
4522lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
4523{
4524 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
4525
4526 lpfc_resume_fabric_iocbs(phba);
4527 return;
4528}
4529
4530static void
4531lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
4532{
4533 int blocked;
4534
4535 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
4536 /* Start a timer to unblock fabric
4537 * iocbs after 100ms
4538 */
4539 if (!blocked)
4540 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
4541
4542 return;
4543}
4544
4545static void
4546lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4547 struct lpfc_iocbq *rspiocb)
4548{
4549 struct ls_rjt stat;
4550
4551 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
4552 BUG();
4553
4554 switch (rspiocb->iocb.ulpStatus) {
4555 case IOSTAT_NPORT_RJT:
4556 case IOSTAT_FABRIC_RJT:
4557 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
4558 lpfc_block_fabric_iocbs(phba);
4559 }
4560 break;
4561
4562 case IOSTAT_NPORT_BSY:
4563 case IOSTAT_FABRIC_BSY:
4564 lpfc_block_fabric_iocbs(phba);
4565 break;
4566
4567 case IOSTAT_LS_RJT:
4568 stat.un.lsRjtError =
4569 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
4570 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
4571 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
4572 lpfc_block_fabric_iocbs(phba);
4573 break;
4574 }
4575
4576 if (atomic_read(&phba->fabric_iocb_count) == 0)
4577 BUG();
4578
4579 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
4580 cmdiocb->fabric_iocb_cmpl = NULL;
4581 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
4582 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
4583
4584 atomic_dec(&phba->fabric_iocb_count);
4585 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
4586 /* Post any pending iocbs to HBA */
4587 lpfc_resume_fabric_iocbs(phba);
4588 }
4589}
4590
4591int
4592lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
4593{
4594 unsigned long iflags;
4595 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4596 int ready;
4597 int ret;
4598
4599 if (atomic_read(&phba->fabric_iocb_count) > 1)
4600 BUG();
4601
4602 spin_lock_irqsave(&phba->hbalock, iflags);
4603 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
4604 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
4605
4606 spin_unlock_irqrestore(&phba->hbalock, iflags);
4607 if (ready) {
4608 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
4609 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
4610 iocb->iocb_flag |= LPFC_IO_FABRIC;
4611
4612 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
4613 "Fabric sched2: ste:x%x",
4614 iocb->vport->port_state, 0, 0);
4615
4616 atomic_inc(&phba->fabric_iocb_count);
4617 ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
4618
4619 if (ret == IOCB_ERROR) {
4620 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
4621 iocb->fabric_iocb_cmpl = NULL;
4622 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
4623 atomic_dec(&phba->fabric_iocb_count);
4624 }
4625 } else {
4626 spin_lock_irqsave(&phba->hbalock, iflags);
4627 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
4628 spin_unlock_irqrestore(&phba->hbalock, iflags);
4629 ret = IOCB_SUCCESS;
4630 }
4631 return ret;
4632}
4633
4634
4635void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
4636{
4637 LIST_HEAD(completions);
4638 struct lpfc_hba *phba = vport->phba;
4639 struct lpfc_iocbq *tmp_iocb, *piocb;
4640 IOCB_t *cmd;
4641
4642 spin_lock_irq(&phba->hbalock);
4643 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
4644 list) {
4645
4646 if (piocb->vport != vport)
4647 continue;
4648
4649 list_move_tail(&piocb->list, &completions);
4650 }
4651 spin_unlock_irq(&phba->hbalock);
4652
4653 while (!list_empty(&completions)) {
4654 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4655 list_del_init(&piocb->list);
4656
4657 cmd = &piocb->iocb;
4658 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4659 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4660 (piocb->iocb_cmpl) (phba, piocb, piocb);
4661 }
4662}
4663
4664void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
4665{
4666 LIST_HEAD(completions);
4667 struct lpfc_hba *phba = ndlp->vport->phba;
4668 struct lpfc_iocbq *tmp_iocb, *piocb;
4669 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4670 IOCB_t *cmd;
4671
4672 spin_lock_irq(&phba->hbalock);
4673 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
4674 list) {
4675 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
4676
4677 list_move_tail(&piocb->list, &completions);
4678 }
4679 }
4680 spin_unlock_irq(&phba->hbalock);
4681
4682 while (!list_empty(&completions)) {
4683 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4684 list_del_init(&piocb->list);
4685
4686 cmd = &piocb->iocb;
4687 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4688 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4689 (piocb->iocb_cmpl) (phba, piocb, piocb);
4690 }
4691}
4692
4693void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
4694{
4695 LIST_HEAD(completions);
4696 struct lpfc_iocbq *piocb;
4697 IOCB_t *cmd;
4698
4699 spin_lock_irq(&phba->hbalock);
4700 list_splice_init(&phba->fabric_iocb_list, &completions);
4701 spin_unlock_irq(&phba->hbalock);
4702
4703 while (!list_empty(&completions)) {
4704 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4705 list_del_init(&piocb->list);
4706
4707 cmd = &piocb->iocb;
4708 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4709 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4710 (piocb->iocb_cmpl) (phba, piocb, piocb);
4711 }
4712}
4713
4714
4715void lpfc_fabric_abort_flogi(struct lpfc_hba *phba)
4716{
4717 LIST_HEAD(completions);
4718 struct lpfc_iocbq *tmp_iocb, *piocb;
4719 IOCB_t *cmd;
4720 struct lpfc_nodelist *ndlp;
4721
4722 spin_lock_irq(&phba->hbalock);
4723 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
4724 list) {
4725
4726 cmd = &piocb->iocb;
4727 ndlp = (struct lpfc_nodelist *) piocb->context1;
4728 if (cmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
4729 ndlp != NULL &&
4730 ndlp->nlp_DID == Fabric_DID)
4731 list_move_tail(&piocb->list, &completions);
4732 }
4733 spin_unlock_irq(&phba->hbalock);
4734
4735 while (!list_empty(&completions)) {
4736 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4737 list_del_init(&piocb->list);
4738
4739 cmd = &piocb->iocb;
4740 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4741 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4742 (piocb->iocb_cmpl) (phba, piocb, piocb);
4743 }
4744}
4745
4746