aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/lpfc/lpfc_els.c
diff options
context:
space:
mode:
authorJames Smart <James.Smart@Emulex.Com>2007-06-17 20:56:38 -0400
committerJames Bottomley <jejb@mulgrave.il.steeleye.com>2007-06-17 23:27:39 -0400
commit92d7f7b0cde3ad2260e7462b40867b57efd49851 (patch)
treefadb1d8f1a817c2f85937b5e9c3b830bdecb5555 /drivers/scsi/lpfc/lpfc_els.c
parented957684294618602b48f1950b0c9bbcb036583f (diff)
[SCSI] lpfc: NPIV: add NPIV support on top of SLI-3
NPIV support is added to the driver. It utilizes the interfaces of the fc transport for the creation and deletion of vports. Within the driver, a new Scsi_Host is created for each NPIV instance, and is paired with a new instance of a FC port. This allows N FC Port elements to share a single Adapter. Signed-off-by: James Smart <James.Smart@emulex.com> Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>
Diffstat (limited to 'drivers/scsi/lpfc/lpfc_els.c')
-rw-r--r--drivers/scsi/lpfc/lpfc_els.c1661
1 files changed, 1295 insertions, 366 deletions
diff --git a/drivers/scsi/lpfc/lpfc_els.c b/drivers/scsi/lpfc/lpfc_els.c
index d48247b3b654..f60c85d791c7 100644
--- a/drivers/scsi/lpfc/lpfc_els.c
+++ b/drivers/scsi/lpfc/lpfc_els.c
@@ -35,9 +35,13 @@
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"
38 39
39static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *, 40static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
40 struct lpfc_iocbq *); 41 struct lpfc_iocbq *);
42static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
43 struct lpfc_iocbq *);
44
41static int lpfc_max_els_tries = 3; 45static int lpfc_max_els_tries = 3;
42 46
43static int 47static int
@@ -58,10 +62,10 @@ lpfc_els_chk_latt(struct lpfc_vport *vport)
58 return 0; 62 return 0;
59 63
60 /* Pending Link Event during Discovery */ 64 /* Pending Link Event during Discovery */
61 lpfc_printf_log(phba, KERN_WARNING, LOG_DISCOVERY, 65 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
62 "%d:0237 Pending Link Event during " 66 "%d (%d):0237 Pending Link Event during "
63 "Discovery: State x%x\n", 67 "Discovery: State x%x\n",
64 phba->brd_no, phba->pport->port_state); 68 phba->brd_no, vport->vpi, phba->pport->port_state);
65 69
66 /* CLEAR_LA should re-enable link attention events and 70 /* CLEAR_LA should re-enable link attention events and
67 * we should then imediately take a LATT event. The 71 * we should then imediately take a LATT event. The
@@ -73,12 +77,10 @@ lpfc_els_chk_latt(struct lpfc_vport *vport)
73 vport->fc_flag |= FC_ABORT_DISCOVERY; 77 vport->fc_flag |= FC_ABORT_DISCOVERY;
74 spin_unlock_irq(shost->host_lock); 78 spin_unlock_irq(shost->host_lock);
75 79
76 if (phba->link_state != LPFC_CLEAR_LA) { 80 if (phba->link_state != LPFC_CLEAR_LA)
77 lpfc_issue_clear_la(phba, vport); 81 lpfc_issue_clear_la(phba, vport);
78 }
79 82
80 return 1; 83 return 1;
81
82} 84}
83 85
84static struct lpfc_iocbq * 86static struct lpfc_iocbq *
@@ -106,7 +108,7 @@ lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
106 108
107 /* fill in BDEs for command */ 109 /* fill in BDEs for command */
108 /* Allocate buffer for command payload */ 110 /* Allocate buffer for command payload */
109 if (((pcmd = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL)) == 0) || 111 if (((pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL)) == 0) ||
110 ((pcmd->virt = lpfc_mbuf_alloc(phba, 112 ((pcmd->virt = lpfc_mbuf_alloc(phba,
111 MEM_PRI, &(pcmd->phys))) == 0)) { 113 MEM_PRI, &(pcmd->phys))) == 0)) {
112 kfree(pcmd); 114 kfree(pcmd);
@@ -119,7 +121,7 @@ lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
119 121
120 /* Allocate buffer for response payload */ 122 /* Allocate buffer for response payload */
121 if (expectRsp) { 123 if (expectRsp) {
122 prsp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); 124 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
123 if (prsp) 125 if (prsp)
124 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, 126 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
125 &prsp->phys); 127 &prsp->phys);
@@ -136,7 +138,7 @@ lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
136 } 138 }
137 139
138 /* Allocate buffer for Buffer ptr list */ 140 /* Allocate buffer for Buffer ptr list */
139 pbuflist = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); 141 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
140 if (pbuflist) 142 if (pbuflist)
141 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI, 143 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
142 &pbuflist->phys); 144 &pbuflist->phys);
@@ -157,18 +159,26 @@ lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
157 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BDL; 159 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BDL;
158 icmd->un.elsreq64.remoteID = did; /* DID */ 160 icmd->un.elsreq64.remoteID = did; /* DID */
159 if (expectRsp) { 161 if (expectRsp) {
160 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof (struct ulp_bde64)); 162 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
161 icmd->ulpCommand = CMD_ELS_REQUEST64_CR; 163 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
162 icmd->ulpTimeout = phba->fc_ratov * 2; 164 icmd->ulpTimeout = phba->fc_ratov * 2;
163 } else { 165 } else {
164 icmd->un.elsreq64.bdl.bdeSize = sizeof (struct ulp_bde64); 166 icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64);
165 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX; 167 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
166 } 168 }
167
168 icmd->ulpBdeCount = 1; 169 icmd->ulpBdeCount = 1;
169 icmd->ulpLe = 1; 170 icmd->ulpLe = 1;
170 icmd->ulpClass = CLASS3; 171 icmd->ulpClass = CLASS3;
171 172
173 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
174 icmd->un.elsreq64.myID = vport->fc_myDID;
175
176 /* For ELS_REQUEST64_CR, use the VPI by default */
177 icmd->ulpContext = vport->vpi;
178 icmd->ulpCt_h = 0;
179 icmd->ulpCt_l = 1;
180 }
181
172 bpl = (struct ulp_bde64 *) pbuflist->virt; 182 bpl = (struct ulp_bde64 *) pbuflist->virt;
173 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys)); 183 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
174 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys)); 184 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
@@ -186,7 +196,8 @@ lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
186 } 196 }
187 197
188 /* Save for completion so we can release these resources */ 198 /* Save for completion so we can release these resources */
189 elsiocb->context1 = lpfc_nlp_get(ndlp); 199 if (elscmd != ELS_CMD_LS_RJT)
200 elsiocb->context1 = lpfc_nlp_get(ndlp);
190 elsiocb->context2 = pcmd; 201 elsiocb->context2 = pcmd;
191 elsiocb->context3 = pbuflist; 202 elsiocb->context3 = pbuflist;
192 elsiocb->retry = retry; 203 elsiocb->retry = retry;
@@ -200,16 +211,16 @@ lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
200 if (expectRsp) { 211 if (expectRsp) {
201 /* Xmit ELS command <elsCmd> to remote NPORT <did> */ 212 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
202 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 213 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
203 "%d:0116 Xmit ELS command x%x to remote " 214 "%d (%d):0116 Xmit ELS command x%x to remote "
204 "NPORT x%x I/O tag: x%x, port state: x%x\n", 215 "NPORT x%x I/O tag: x%x, port state: x%x\n",
205 phba->brd_no, elscmd, did, 216 phba->brd_no, vport->vpi, elscmd, did,
206 elsiocb->iotag, vport->port_state); 217 elsiocb->iotag, vport->port_state);
207 } else { 218 } else {
208 /* Xmit ELS response <elsCmd> to remote NPORT <did> */ 219 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
209 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 220 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
210 "%d:0117 Xmit ELS response x%x to remote " 221 "%d (%d):0117 Xmit ELS response x%x to remote "
211 "NPORT x%x I/O tag: x%x, size: x%x\n", 222 "NPORT x%x I/O tag: x%x, size: x%x\n",
212 phba->brd_no, elscmd, 223 phba->brd_no, vport->vpi, elscmd,
213 ndlp->nlp_DID, elsiocb->iotag, cmdSize); 224 ndlp->nlp_DID, elsiocb->iotag, cmdSize);
214 } 225 }
215 226
@@ -218,15 +229,76 @@ lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
218 229
219 230
220static int 231static int
221lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, 232lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
222 struct serv_parm *sp, IOCB_t *irsp)
223{ 233{
224 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
225 struct lpfc_hba *phba = vport->phba; 234 struct lpfc_hba *phba = vport->phba;
226 LPFC_MBOXQ_t *mbox; 235 LPFC_MBOXQ_t *mbox;
227 struct lpfc_dmabuf *mp; 236 struct lpfc_dmabuf *mp;
237 struct lpfc_nodelist *ndlp;
238 struct serv_parm *sp;
228 int rc; 239 int rc;
229 240
241 sp = &phba->fc_fabparam;
242 ndlp = lpfc_findnode_did(vport, Fabric_DID);
243 if (!ndlp)
244 goto fail;
245
246 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
247 if (!mbox)
248 goto fail;
249
250 vport->port_state = LPFC_FABRIC_CFG_LINK;
251 lpfc_config_link(phba, mbox);
252 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
253 mbox->vport = vport;
254
255 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT | MBX_STOP_IOCB);
256 if (rc == MBX_NOT_FINISHED)
257 goto fail_free_mbox;
258
259 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
260 if (!mbox)
261 goto fail;
262 rc = lpfc_reg_login(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
263 0);
264 if (rc)
265 goto fail_free_mbox;
266
267 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
268 mbox->vport = vport;
269 mbox->context2 = lpfc_nlp_get(ndlp);
270
271 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT | MBX_STOP_IOCB);
272 if (rc == MBX_NOT_FINISHED)
273 goto fail_issue_reg_login;
274
275 return 0;
276
277fail_issue_reg_login:
278 lpfc_nlp_put(ndlp);
279 mp = (struct lpfc_dmabuf *) mbox->context1;
280 lpfc_mbuf_free(phba, mp->virt, mp->phys);
281 kfree(mp);
282fail_free_mbox:
283 mempool_free(mbox, phba->mbox_mem_pool);
284
285fail:
286 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
287 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
288 "%d (%d):0249 Cannot issue Register Fabric login\n",
289 phba->brd_no, vport->vpi);
290 return -ENXIO;
291}
292
293static int
294lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
295 struct serv_parm *sp, IOCB_t *irsp)
296{
297 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
298 struct lpfc_hba *phba = vport->phba;
299 struct lpfc_nodelist *np;
300 struct lpfc_nodelist *next_np;
301
230 spin_lock_irq(shost->host_lock); 302 spin_lock_irq(shost->host_lock);
231 vport->fc_flag |= FC_FABRIC; 303 vport->fc_flag |= FC_FABRIC;
232 spin_unlock_irq(shost->host_lock); 304 spin_unlock_irq(shost->host_lock);
@@ -251,7 +323,7 @@ lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
251 323
252 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID; 324 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
253 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name)); 325 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
254 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name)); 326 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
255 ndlp->nlp_class_sup = 0; 327 ndlp->nlp_class_sup = 0;
256 if (sp->cls1.classValid) 328 if (sp->cls1.classValid)
257 ndlp->nlp_class_sup |= FC_COS_CLASS1; 329 ndlp->nlp_class_sup |= FC_COS_CLASS1;
@@ -265,47 +337,59 @@ lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
265 sp->cmn.bbRcvSizeLsb; 337 sp->cmn.bbRcvSizeLsb;
266 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); 338 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
267 339
268 ndlp->nlp_sid = irsp->un.ulpWord[4] & Mask_DID; 340 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
269 341 if (sp->cmn.response_multiple_NPort) {
270 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 342 lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_VPORT,
271 if (!mbox) 343 "%d:1816 FLOGI NPIV supported, "
272 goto fail; 344 "response data 0x%x\n",
345 phba->brd_no,
346 sp->cmn.response_multiple_NPort);
347 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
273 348
274 vport->port_state = LPFC_FABRIC_CFG_LINK; 349 } else {
275 lpfc_config_link(phba, mbox); 350 /* Because we asked f/w for NPIV it still expects us
276 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; 351 to call reg_vnpid atleast for the physcial host */
277 mbox->vport = vport; 352 lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_VPORT,
278 353 "%d:1817 Fabric does not support NPIV "
279 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT | MBX_STOP_IOCB); 354 "- configuring single port mode.\n",
280 if (rc == MBX_NOT_FINISHED) 355 phba->brd_no);
281 goto fail_free_mbox; 356 phba->vpi_cnt = 1;
357 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
358 }
359 }
282 360
283 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 361 if ((vport->fc_prevDID != vport->fc_myDID) &&
284 if (!mbox) 362 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
285 goto fail;
286 rc = lpfc_reg_login(phba, Fabric_DID, (uint8_t *) sp, mbox, 0);
287 if (rc)
288 goto fail_free_mbox;
289 363
290 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login; 364 /* If our NportID changed, we need to ensure all
291 mbox->vport = vport; 365 * remaining NPORTs get unreg_login'ed.
292 mbox->context2 = lpfc_nlp_get(ndlp); 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 }
293 382
294 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT | MBX_STOP_IOCB); 383 ndlp->nlp_sid = irsp->un.ulpWord[4] & Mask_DID;
295 if (rc == MBX_NOT_FINISHED) 384 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
296 goto fail_issue_reg_login;
297 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);
298 return 0; 392 return 0;
299
300 fail_issue_reg_login:
301 lpfc_nlp_put(ndlp);
302 mp = (struct lpfc_dmabuf *) mbox->context1;
303 lpfc_mbuf_free(phba, mp->virt, mp->phys);
304 kfree(mp);
305 fail_free_mbox:
306 mempool_free(mbox, phba->mbox_mem_pool);
307 fail:
308 return -ENXIO;
309} 393}
310 394
311/* 395/*
@@ -322,12 +406,13 @@ lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
322 406
323 spin_lock_irq(shost->host_lock); 407 spin_lock_irq(shost->host_lock);
324 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); 408 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
409 phba->vpi_cnt = 1;
325 spin_unlock_irq(shost->host_lock); 410 spin_unlock_irq(shost->host_lock);
326 411
327 phba->fc_edtov = FF_DEF_EDTOV; 412 phba->fc_edtov = FF_DEF_EDTOV;
328 phba->fc_ratov = FF_DEF_RATOV; 413 phba->fc_ratov = FF_DEF_RATOV;
329 rc = memcmp(&vport->fc_portname, &sp->portName, 414 rc = memcmp(&vport->fc_portname, &sp->portName,
330 sizeof(struct lpfc_name)); 415 sizeof(vport->fc_portname));
331 if (rc >= 0) { 416 if (rc >= 0) {
332 /* This side will initiate the PLOGI */ 417 /* This side will initiate the PLOGI */
333 spin_lock_irq(shost->host_lock); 418 spin_lock_irq(shost->host_lock);
@@ -352,7 +437,7 @@ lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
352 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; 437 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
353 mbox->vport = vport; 438 mbox->vport = vport;
354 rc = lpfc_sli_issue_mbox(phba, mbox, 439 rc = lpfc_sli_issue_mbox(phba, mbox,
355 MBX_NOWAIT | MBX_STOP_IOCB); 440 MBX_NOWAIT | MBX_STOP_IOCB);
356 if (rc == MBX_NOT_FINISHED) { 441 if (rc == MBX_NOT_FINISHED) {
357 mempool_free(mbox, phba->mbox_mem_pool); 442 mempool_free(mbox, phba->mbox_mem_pool);
358 goto fail; 443 goto fail;
@@ -392,7 +477,7 @@ lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
392 /* Start discovery - this should just do CLEAR_LA */ 477 /* Start discovery - this should just do CLEAR_LA */
393 lpfc_disc_start(vport); 478 lpfc_disc_start(vport);
394 return 0; 479 return 0;
395 fail: 480fail:
396 return -ENXIO; 481 return -ENXIO;
397} 482}
398 483
@@ -422,6 +507,7 @@ lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
422 /* FLOGI failed, so there is no fabric */ 507 /* FLOGI failed, so there is no fabric */
423 spin_lock_irq(shost->host_lock); 508 spin_lock_irq(shost->host_lock);
424 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); 509 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
510 phba->vpi_cnt = 1;
425 spin_unlock_irq(shost->host_lock); 511 spin_unlock_irq(shost->host_lock);
426 512
427 /* If private loop, then allow max outstanding els to be 513 /* If private loop, then allow max outstanding els to be
@@ -433,11 +519,10 @@ lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
433 } 519 }
434 520
435 /* FLOGI failure */ 521 /* FLOGI failure */
436 lpfc_printf_log(phba, 522 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
437 KERN_INFO, 523 "%d (%d):0100 FLOGI failure Data: x%x x%x "
438 LOG_ELS, 524 "x%x\n",
439 "%d:0100 FLOGI failure Data: x%x x%x x%x\n", 525 phba->brd_no, vport->vpi,
440 phba->brd_no,
441 irsp->ulpStatus, irsp->un.ulpWord[4], 526 irsp->ulpStatus, irsp->un.ulpWord[4],
442 irsp->ulpTimeout); 527 irsp->ulpTimeout);
443 goto flogifail; 528 goto flogifail;
@@ -453,9 +538,9 @@ lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
453 538
454 /* FLOGI completes successfully */ 539 /* FLOGI completes successfully */
455 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 540 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
456 "%d:0101 FLOGI completes sucessfully " 541 "%d (%d):0101 FLOGI completes sucessfully "
457 "Data: x%x x%x x%x x%x\n", 542 "Data: x%x x%x x%x x%x\n",
458 phba->brd_no, 543 phba->brd_no, vport->vpi,
459 irsp->un.ulpWord[4], sp->cmn.e_d_tov, 544 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
460 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution); 545 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
461 546
@@ -475,6 +560,7 @@ lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
475 560
476flogifail: 561flogifail:
477 lpfc_nlp_put(ndlp); 562 lpfc_nlp_put(ndlp);
563 phba->vpi_cnt = 1;
478 564
479 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT || 565 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
480 (irsp->un.ulpWord[4] != IOERR_SLI_ABORTED && 566 (irsp->un.ulpWord[4] != IOERR_SLI_ABORTED &&
@@ -506,9 +592,10 @@ lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
506 592
507 pring = &phba->sli.ring[LPFC_ELS_RING]; 593 pring = &phba->sli.ring[LPFC_ELS_RING];
508 594
509 cmdsize = (sizeof (uint32_t) + sizeof (struct serv_parm)); 595 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
510 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, 596 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
511 ndlp->nlp_DID, ELS_CMD_FLOGI); 597 ndlp->nlp_DID, ELS_CMD_FLOGI);
598
512 if (!elsiocb) 599 if (!elsiocb)
513 return 1; 600 return 1;
514 601
@@ -517,8 +604,8 @@ lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
517 604
518 /* For FLOGI request, remainder of payload is service parameters */ 605 /* For FLOGI request, remainder of payload is service parameters */
519 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI; 606 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
520 pcmd += sizeof (uint32_t); 607 pcmd += sizeof(uint32_t);
521 memcpy(pcmd, &vport->fc_sparam, sizeof (struct serv_parm)); 608 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
522 sp = (struct serv_parm *) pcmd; 609 sp = (struct serv_parm *) pcmd;
523 610
524 /* Setup CSPs accordingly for Fabric */ 611 /* Setup CSPs accordingly for Fabric */
@@ -532,6 +619,14 @@ lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
532 if (sp->cmn.fcphHigh < FC_PH3) 619 if (sp->cmn.fcphHigh < FC_PH3)
533 sp->cmn.fcphHigh = FC_PH3; 620 sp->cmn.fcphHigh = FC_PH3;
534 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
535 tmo = phba->fc_ratov; 630 tmo = phba->fc_ratov;
536 phba->fc_ratov = LPFC_DISC_FLOGI_TMO; 631 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
537 lpfc_set_disctmo(vport); 632 lpfc_set_disctmo(vport);
@@ -539,7 +634,7 @@ lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
539 634
540 phba->fc_stat.elsXmitFLOGI++; 635 phba->fc_stat.elsXmitFLOGI++;
541 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi; 636 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
542 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0); 637 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
543 if (rc == IOCB_ERROR) { 638 if (rc == IOCB_ERROR) {
544 lpfc_els_free_iocb(phba, elsiocb); 639 lpfc_els_free_iocb(phba, elsiocb);
545 return 1; 640 return 1;
@@ -572,8 +667,9 @@ lpfc_els_abort_flogi(struct lpfc_hba *phba)
572 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR && 667 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
573 icmd->un.elsreq64.bdl.ulpIoTag32) { 668 icmd->un.elsreq64.bdl.ulpIoTag32) {
574 ndlp = (struct lpfc_nodelist *)(iocb->context1); 669 ndlp = (struct lpfc_nodelist *)(iocb->context1);
575 if (ndlp && (ndlp->nlp_DID == Fabric_DID)) 670 if (ndlp && (ndlp->nlp_DID == Fabric_DID)) {
576 lpfc_sli_issue_abort_iotag(phba, pring, iocb); 671 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
672 }
577 } 673 }
578 } 674 }
579 spin_unlock_irq(&phba->hbalock); 675 spin_unlock_irq(&phba->hbalock);
@@ -604,6 +700,28 @@ lpfc_initial_flogi(struct lpfc_vport *vport)
604 return 1; 700 return 1;
605} 701}
606 702
703int
704lpfc_initial_fdisc(struct lpfc_vport *vport)
705{
706 struct lpfc_hba *phba = vport->phba;
707 struct lpfc_nodelist *ndlp;
708
709 /* First look for the Fabric ndlp */
710 ndlp = lpfc_findnode_did(vport, Fabric_DID);
711 if (!ndlp) {
712 /* Cannot find existing Fabric ndlp, so allocate a new one */
713 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
714 if (!ndlp)
715 return 0;
716 lpfc_nlp_init(vport, ndlp, Fabric_DID);
717 } else {
718 lpfc_dequeue_node(vport, ndlp);
719 }
720 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
721 lpfc_nlp_put(ndlp);
722 }
723 return 1;
724}
607static void 725static void
608lpfc_more_plogi(struct lpfc_vport *vport) 726lpfc_more_plogi(struct lpfc_vport *vport)
609{ 727{
@@ -615,9 +733,9 @@ lpfc_more_plogi(struct lpfc_vport *vport)
615 733
616 /* Continue discovery with <num_disc_nodes> PLOGIs to go */ 734 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
617 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, 735 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
618 "%d:0232 Continue discovery with %d PLOGIs to go " 736 "%d (%d):0232 Continue discovery with %d PLOGIs to go "
619 "Data: x%x x%x x%x\n", 737 "Data: x%x x%x x%x\n",
620 phba->brd_no, vport->num_disc_nodes, 738 phba->brd_no, vport->vpi, vport->num_disc_nodes,
621 vport->fc_plogi_cnt, vport->fc_flag, vport->port_state); 739 vport->fc_plogi_cnt, vport->fc_flag, vport->port_state);
622 740
623 /* Check to see if there are more PLOGIs to be sent */ 741 /* Check to see if there are more PLOGIs to be sent */
@@ -629,14 +747,13 @@ lpfc_more_plogi(struct lpfc_vport *vport)
629} 747}
630 748
631static struct lpfc_nodelist * 749static struct lpfc_nodelist *
632lpfc_plogi_confirm_nport(struct lpfc_hba *phba, struct lpfc_dmabuf *prsp, 750lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
633 struct lpfc_nodelist *ndlp) 751 struct lpfc_nodelist *ndlp)
634{ 752{
635 struct lpfc_vport *vport = ndlp->vport; 753 struct lpfc_vport *vport = ndlp->vport;
636 struct lpfc_nodelist *new_ndlp; 754 struct lpfc_nodelist *new_ndlp;
637 uint32_t *lp;
638 struct serv_parm *sp; 755 struct serv_parm *sp;
639 uint8_t name[sizeof (struct lpfc_name)]; 756 uint8_t name[sizeof(struct lpfc_name)];
640 uint32_t rc; 757 uint32_t rc;
641 758
642 /* Fabric nodes can have the same WWPN so we don't bother searching 759 /* Fabric nodes can have the same WWPN so we don't bother searching
@@ -645,8 +762,7 @@ lpfc_plogi_confirm_nport(struct lpfc_hba *phba, struct lpfc_dmabuf *prsp,
645 if (ndlp->nlp_type & NLP_FABRIC) 762 if (ndlp->nlp_type & NLP_FABRIC)
646 return ndlp; 763 return ndlp;
647 764
648 lp = (uint32_t *) prsp->virt; 765 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
649 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
650 memset(name, 0, sizeof(struct lpfc_name)); 766 memset(name, 0, sizeof(struct lpfc_name));
651 767
652 /* Now we find out if the NPort we are logging into, matches the WWPN 768 /* Now we find out if the NPort we are logging into, matches the WWPN
@@ -701,8 +817,12 @@ lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
701 817
702 irsp = &rspiocb->iocb; 818 irsp = &rspiocb->iocb;
703 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID); 819 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
704
705 if (!ndlp) { 820 if (!ndlp) {
821 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
822 "%d (%d):0136 PLOGI completes to NPort x%x "
823 "with no ndlp. Data: x%x x%x x%x\n",
824 phba->brd_no, vport->vpi, irsp->un.elsreq64.remoteID,
825 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->ulpIoTag);
706 goto out; 826 goto out;
707 } 827 }
708 828
@@ -717,11 +837,11 @@ lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
717 837
718 /* PLOGI completes to NPort <nlp_DID> */ 838 /* PLOGI completes to NPort <nlp_DID> */
719 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 839 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
720 "%d:0102 PLOGI completes to NPort x%x " 840 "%d (%d):0102 PLOGI completes to NPort x%x "
721 "Data: x%x x%x x%x x%x x%x\n", 841 "Data: x%x x%x x%x x%x x%x\n",
722 phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus, 842 phba->brd_no, vport->vpi, ndlp->nlp_DID,
723 irsp->un.ulpWord[4], irsp->ulpTimeout, disc, 843 irsp->ulpStatus, irsp->un.ulpWord[4],
724 vport->num_disc_nodes); 844 irsp->ulpTimeout, disc, vport->num_disc_nodes);
725 845
726 /* Check to see if link went down during discovery */ 846 /* Check to see if link went down during discovery */
727 if (lpfc_els_chk_latt(vport)) { 847 if (lpfc_els_chk_latt(vport)) {
@@ -748,24 +868,33 @@ lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
748 } 868 }
749 869
750 /* PLOGI failed */ 870 /* PLOGI failed */
871 if (ndlp->nlp_DID == NameServer_DID) {
872 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
873 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
874 "%d (%d):0250 Nameserver login error: "
875 "0x%x / 0x%x\n",
876 phba->brd_no, vport->vpi,
877 irsp->ulpStatus, irsp->un.ulpWord[4]);
878 }
879
751 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ 880 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
752 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && 881 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
753 ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) || 882 ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
754 (irsp->un.ulpWord[4] == IOERR_LINK_DOWN) || 883 (irsp->un.ulpWord[4] == IOERR_LINK_DOWN) ||
755 (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) { 884 (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) {
756 rc = NLP_STE_FREED_NODE; 885 rc = NLP_STE_FREED_NODE;
757 } else { 886 } else {
758 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, 887 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
759 NLP_EVT_CMPL_PLOGI); 888 NLP_EVT_CMPL_PLOGI);
760 } 889 }
761 } else { 890 } else {
762 /* Good status, call state machine */ 891 /* Good status, call state machine */
763 prsp = list_entry(((struct lpfc_dmabuf *) 892 prsp = list_entry(((struct lpfc_dmabuf *)
764 cmdiocb->context2)->list.next, 893 cmdiocb->context2)->list.next,
765 struct lpfc_dmabuf, list); 894 struct lpfc_dmabuf, list);
766 ndlp = lpfc_plogi_confirm_nport(phba, prsp, ndlp); 895 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
767 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb, 896 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
768 NLP_EVT_CMPL_PLOGI); 897 NLP_EVT_CMPL_PLOGI);
769 } 898 }
770 899
771 if (disc && vport->num_disc_nodes) { 900 if (disc && vport->num_disc_nodes) {
@@ -811,11 +940,12 @@ lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
811 struct lpfc_sli *psli; 940 struct lpfc_sli *psli;
812 uint8_t *pcmd; 941 uint8_t *pcmd;
813 uint16_t cmdsize; 942 uint16_t cmdsize;
943 int ret;
814 944
815 psli = &phba->sli; 945 psli = &phba->sli;
816 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ 946 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
817 947
818 cmdsize = (sizeof (uint32_t) + sizeof (struct serv_parm)); 948 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
819 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, NULL, did, 949 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, NULL, did,
820 ELS_CMD_PLOGI); 950 ELS_CMD_PLOGI);
821 if (!elsiocb) 951 if (!elsiocb)
@@ -826,8 +956,8 @@ lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
826 956
827 /* For PLOGI request, remainder of payload is service parameters */ 957 /* For PLOGI request, remainder of payload is service parameters */
828 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI; 958 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
829 pcmd += sizeof (uint32_t); 959 pcmd += sizeof(uint32_t);
830 memcpy(pcmd, &vport->fc_sparam, sizeof (struct serv_parm)); 960 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
831 sp = (struct serv_parm *) pcmd; 961 sp = (struct serv_parm *) pcmd;
832 962
833 if (sp->cmn.fcphLow < FC_PH_4_3) 963 if (sp->cmn.fcphLow < FC_PH_4_3)
@@ -838,7 +968,9 @@ lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
838 968
839 phba->fc_stat.elsXmitPLOGI++; 969 phba->fc_stat.elsXmitPLOGI++;
840 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi; 970 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
841 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { 971 ret = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
972
973 if (ret == IOCB_ERROR) {
842 lpfc_els_free_iocb(phba, elsiocb); 974 lpfc_els_free_iocb(phba, elsiocb);
843 return 1; 975 return 1;
844 } 976 }
@@ -867,10 +999,10 @@ lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
867 999
868 /* PRLI completes to NPort <nlp_DID> */ 1000 /* PRLI completes to NPort <nlp_DID> */
869 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 1001 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
870 "%d:0103 PRLI completes to NPort x%x " 1002 "%d (%d):0103 PRLI completes to NPort x%x "
871 "Data: x%x x%x x%x x%x\n", 1003 "Data: x%x x%x x%x x%x\n",
872 phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus, 1004 phba->brd_no, vport->vpi, ndlp->nlp_DID,
873 irsp->un.ulpWord[4], irsp->ulpTimeout, 1005 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->ulpTimeout,
874 vport->num_disc_nodes); 1006 vport->num_disc_nodes);
875 1007
876 vport->fc_prli_sent--; 1008 vport->fc_prli_sent--;
@@ -887,18 +1019,18 @@ lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
887 /* PRLI failed */ 1019 /* PRLI failed */
888 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ 1020 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
889 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && 1021 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
890 ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) || 1022 ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
891 (irsp->un.ulpWord[4] == IOERR_LINK_DOWN) || 1023 (irsp->un.ulpWord[4] == IOERR_LINK_DOWN) ||
892 (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) { 1024 (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) {
893 goto out; 1025 goto out;
894 } else { 1026 } else {
895 lpfc_disc_state_machine(vport, ndlp, cmdiocb, 1027 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
896 NLP_EVT_CMPL_PRLI); 1028 NLP_EVT_CMPL_PRLI);
897 } 1029 }
898 } else { 1030 } else {
899 /* Good status, call state machine */ 1031 /* Good status, call state machine */
900 lpfc_disc_state_machine(vport, ndlp, cmdiocb, 1032 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
901 NLP_EVT_CMPL_PRLI); 1033 NLP_EVT_CMPL_PRLI);
902 } 1034 }
903 1035
904out: 1036out:
@@ -923,7 +1055,7 @@ lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
923 psli = &phba->sli; 1055 psli = &phba->sli;
924 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ 1056 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
925 1057
926 cmdsize = (sizeof (uint32_t) + sizeof (PRLI)); 1058 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
927 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, 1059 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
928 ndlp->nlp_DID, ELS_CMD_PRLI); 1060 ndlp->nlp_DID, ELS_CMD_PRLI);
929 if (!elsiocb) 1061 if (!elsiocb)
@@ -933,9 +1065,9 @@ lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
933 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); 1065 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
934 1066
935 /* For PRLI request, remainder of payload is service parameters */ 1067 /* For PRLI request, remainder of payload is service parameters */
936 memset(pcmd, 0, (sizeof (PRLI) + sizeof (uint32_t))); 1068 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
937 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI; 1069 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
938 pcmd += sizeof (uint32_t); 1070 pcmd += sizeof(uint32_t);
939 1071
940 /* For PRLI, remainder of payload is PRLI parameter page */ 1072 /* For PRLI, remainder of payload is PRLI parameter page */
941 npr = (PRLI *) pcmd; 1073 npr = (PRLI *) pcmd;
@@ -982,9 +1114,9 @@ lpfc_more_adisc(struct lpfc_vport *vport)
982 1114
983 /* Continue discovery with <num_disc_nodes> ADISCs to go */ 1115 /* Continue discovery with <num_disc_nodes> ADISCs to go */
984 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, 1116 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
985 "%d:0210 Continue discovery with %d ADISCs to go " 1117 "%d (%d):0210 Continue discovery with %d ADISCs to go "
986 "Data: x%x x%x x%x\n", 1118 "Data: x%x x%x x%x\n",
987 phba->brd_no, vport->num_disc_nodes, 1119 phba->brd_no, vport->vpi, vport->num_disc_nodes,
988 vport->fc_adisc_cnt, vport->fc_flag, vport->port_state); 1120 vport->fc_adisc_cnt, vport->fc_flag, vport->port_state);
989 1121
990 /* Check to see if there are more ADISCs to be sent */ 1122 /* Check to see if there are more ADISCs to be sent */
@@ -1048,11 +1180,11 @@ lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1048 1180
1049 /* ADISC completes to NPort <nlp_DID> */ 1181 /* ADISC completes to NPort <nlp_DID> */
1050 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 1182 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1051 "%d:0104 ADISC completes to NPort x%x " 1183 "%d (%d):0104 ADISC completes to NPort x%x "
1052 "Data: x%x x%x x%x x%x x%x\n", 1184 "Data: x%x x%x x%x x%x x%x\n",
1053 phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus, 1185 phba->brd_no, vport->vpi, ndlp->nlp_DID,
1054 irsp->un.ulpWord[4], irsp->ulpTimeout, disc, 1186 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->ulpTimeout,
1055 vport->num_disc_nodes); 1187 disc, vport->num_disc_nodes);
1056 1188
1057 /* Check to see if link went down during discovery */ 1189 /* Check to see if link went down during discovery */
1058 if (lpfc_els_chk_latt(vport)) { 1190 if (lpfc_els_chk_latt(vport)) {
@@ -1095,12 +1227,41 @@ lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1095 1227
1096 /* Check to see if we are done with ADISC authentication */ 1228 /* Check to see if we are done with ADISC authentication */
1097 if (vport->num_disc_nodes == 0) { 1229 if (vport->num_disc_nodes == 0) {
1098 lpfc_can_disctmo(vport); 1230 /* If we get here, there is nothing left to ADISC */
1099 /* If we get here, there is nothing left to wait for */ 1231 /*
1100 if (vport->port_state < LPFC_VPORT_READY && 1232 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1101 phba->link_state != LPFC_CLEAR_LA) { 1233 * and continue discovery.
1234 */
1235 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1236 !(vport->fc_flag & FC_RSCN_MODE)) {
1237 lpfc_issue_reg_vpi(phba, vport);
1238 goto out;
1239 }
1240 /*
1241 * For SLI2, we need to set port_state to READY
1242 * and continue discovery.
1243 */
1244 if (vport->port_state < LPFC_VPORT_READY) {
1245 /* If we get here, there is nothing to ADISC */
1102 if (vport->port_type == LPFC_PHYSICAL_PORT) 1246 if (vport->port_type == LPFC_PHYSICAL_PORT)
1103 lpfc_issue_clear_la(phba, vport); 1247 lpfc_issue_clear_la(phba, vport);
1248
1249 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
1250 vport->num_disc_nodes = 0;
1251 /* go thru NPR list, issue ELS PLOGIs */
1252 if (vport->fc_npr_cnt)
1253 lpfc_els_disc_plogi(vport);
1254
1255 if (!vport->num_disc_nodes) {
1256 spin_lock_irq(shost->host_lock);
1257 vport->fc_flag &=
1258 ~FC_NDISC_ACTIVE;
1259 spin_unlock_irq(
1260 shost->host_lock);
1261 lpfc_can_disctmo(vport);
1262 }
1263 }
1264 vport->port_state = LPFC_VPORT_READY;
1104 } else { 1265 } else {
1105 lpfc_rscn_disc(vport); 1266 lpfc_rscn_disc(vport);
1106 } 1267 }
@@ -1125,7 +1286,7 @@ lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1125 uint8_t *pcmd; 1286 uint8_t *pcmd;
1126 uint16_t cmdsize; 1287 uint16_t cmdsize;
1127 1288
1128 cmdsize = (sizeof (uint32_t) + sizeof (ADISC)); 1289 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
1129 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, 1290 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1130 ndlp->nlp_DID, ELS_CMD_ADISC); 1291 ndlp->nlp_DID, ELS_CMD_ADISC);
1131 if (!elsiocb) 1292 if (!elsiocb)
@@ -1136,13 +1297,13 @@ lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1136 1297
1137 /* For ADISC request, remainder of payload is service parameters */ 1298 /* For ADISC request, remainder of payload is service parameters */
1138 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC; 1299 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
1139 pcmd += sizeof (uint32_t); 1300 pcmd += sizeof(uint32_t);
1140 1301
1141 /* Fill in ADISC payload */ 1302 /* Fill in ADISC payload */
1142 ap = (ADISC *) pcmd; 1303 ap = (ADISC *) pcmd;
1143 ap->hardAL_PA = phba->fc_pref_ALPA; 1304 ap->hardAL_PA = phba->fc_pref_ALPA;
1144 memcpy(&ap->portName, &vport->fc_portname, sizeof (struct lpfc_name)); 1305 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
1145 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof (struct lpfc_name)); 1306 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
1146 ap->DID = be32_to_cpu(vport->fc_myDID); 1307 ap->DID = be32_to_cpu(vport->fc_myDID);
1147 1308
1148 phba->fc_stat.elsXmitADISC++; 1309 phba->fc_stat.elsXmitADISC++;
@@ -1181,16 +1342,25 @@ lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1181 1342
1182 /* LOGO completes to NPort <nlp_DID> */ 1343 /* LOGO completes to NPort <nlp_DID> */
1183 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 1344 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1184 "%d:0105 LOGO completes to NPort x%x " 1345 "%d (%d):0105 LOGO completes to NPort x%x "
1185 "Data: x%x x%x x%x x%x\n", 1346 "Data: x%x x%x x%x x%x\n",
1186 phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus, 1347 phba->brd_no, vport->vpi, ndlp->nlp_DID,
1187 irsp->un.ulpWord[4], irsp->ulpTimeout, 1348 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->ulpTimeout,
1188 vport->num_disc_nodes); 1349 vport->num_disc_nodes);
1189 1350
1190 /* Check to see if link went down during discovery */ 1351 /* Check to see if link went down during discovery */
1191 if (lpfc_els_chk_latt(vport)) 1352 if (lpfc_els_chk_latt(vport))
1192 goto out; 1353 goto out;
1193 1354
1355 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
1356 /* NLP_EVT_DEVICE_RM should unregister the RPI
1357 * which should abort all outstanding IOs.
1358 */
1359 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1360 NLP_EVT_DEVICE_RM);
1361 goto out;
1362 }
1363
1194 if (irsp->ulpStatus) { 1364 if (irsp->ulpStatus) {
1195 /* Check for retry */ 1365 /* Check for retry */
1196 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) 1366 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
@@ -1199,20 +1369,20 @@ lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1199 /* LOGO failed */ 1369 /* LOGO failed */
1200 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ 1370 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1201 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && 1371 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1202 ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) || 1372 ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
1203 (irsp->un.ulpWord[4] == IOERR_LINK_DOWN) || 1373 (irsp->un.ulpWord[4] == IOERR_LINK_DOWN) ||
1204 (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) { 1374 (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) {
1205 goto out; 1375 goto out;
1206 } else { 1376 } else {
1207 lpfc_disc_state_machine(vport, ndlp, cmdiocb, 1377 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1208 NLP_EVT_CMPL_LOGO); 1378 NLP_EVT_CMPL_LOGO);
1209 } 1379 }
1210 } else { 1380 } else {
1211 /* Good status, call state machine. 1381 /* Good status, call state machine.
1212 * This will unregister the rpi if needed. 1382 * This will unregister the rpi if needed.
1213 */ 1383 */
1214 lpfc_disc_state_machine(vport, ndlp, cmdiocb, 1384 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1215 NLP_EVT_CMPL_LOGO); 1385 NLP_EVT_CMPL_LOGO);
1216 } 1386 }
1217 1387
1218out: 1388out:
@@ -1232,11 +1402,12 @@ lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1232 struct lpfc_sli *psli; 1402 struct lpfc_sli *psli;
1233 uint8_t *pcmd; 1403 uint8_t *pcmd;
1234 uint16_t cmdsize; 1404 uint16_t cmdsize;
1405 int rc;
1235 1406
1236 psli = &phba->sli; 1407 psli = &phba->sli;
1237 pring = &psli->ring[LPFC_ELS_RING]; 1408 pring = &psli->ring[LPFC_ELS_RING];
1238 1409
1239 cmdsize = (2 * sizeof (uint32_t)) + sizeof (struct lpfc_name); 1410 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
1240 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, 1411 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1241 ndlp->nlp_DID, ELS_CMD_LOGO); 1412 ndlp->nlp_DID, ELS_CMD_LOGO);
1242 if (!elsiocb) 1413 if (!elsiocb)
@@ -1245,19 +1416,21 @@ lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1245 icmd = &elsiocb->iocb; 1416 icmd = &elsiocb->iocb;
1246 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); 1417 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1247 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO; 1418 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
1248 pcmd += sizeof (uint32_t); 1419 pcmd += sizeof(uint32_t);
1249 1420
1250 /* Fill in LOGO payload */ 1421 /* Fill in LOGO payload */
1251 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID); 1422 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
1252 pcmd += sizeof (uint32_t); 1423 pcmd += sizeof(uint32_t);
1253 memcpy(pcmd, &vport->fc_portname, sizeof (struct lpfc_name)); 1424 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
1254 1425
1255 phba->fc_stat.elsXmitLOGO++; 1426 phba->fc_stat.elsXmitLOGO++;
1256 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo; 1427 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
1257 spin_lock_irq(shost->host_lock); 1428 spin_lock_irq(shost->host_lock);
1258 ndlp->nlp_flag |= NLP_LOGO_SND; 1429 ndlp->nlp_flag |= NLP_LOGO_SND;
1259 spin_unlock_irq(shost->host_lock); 1430 spin_unlock_irq(shost->host_lock);
1260 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { 1431 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
1432
1433 if (rc == IOCB_ERROR) {
1261 spin_lock_irq(shost->host_lock); 1434 spin_lock_irq(shost->host_lock);
1262 ndlp->nlp_flag &= ~NLP_LOGO_SND; 1435 ndlp->nlp_flag &= ~NLP_LOGO_SND;
1263 spin_unlock_irq(shost->host_lock); 1436 spin_unlock_irq(shost->host_lock);
@@ -1277,11 +1450,10 @@ lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1277 irsp = &rspiocb->iocb; 1450 irsp = &rspiocb->iocb;
1278 1451
1279 /* ELS cmd tag <ulpIoTag> completes */ 1452 /* ELS cmd tag <ulpIoTag> completes */
1280 lpfc_printf_log(phba, 1453 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1281 KERN_INFO, 1454 "%d (%d):0106 ELS cmd tag x%x completes Data: x%x x%x "
1282 LOG_ELS, 1455 "x%x\n",
1283 "%d:0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n", 1456 phba->brd_no, vport->vpi,
1284 phba->brd_no,
1285 irsp->ulpIoTag, irsp->ulpStatus, 1457 irsp->ulpIoTag, irsp->ulpStatus,
1286 irsp->un.ulpWord[4], irsp->ulpTimeout); 1458 irsp->un.ulpWord[4], irsp->ulpTimeout);
1287 1459
@@ -1305,7 +1477,7 @@ lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
1305 1477
1306 psli = &phba->sli; 1478 psli = &phba->sli;
1307 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ 1479 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1308 cmdsize = (sizeof (uint32_t) + sizeof (SCR)); 1480 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
1309 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); 1481 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1310 if (!ndlp) 1482 if (!ndlp)
1311 return 1; 1483 return 1;
@@ -1324,10 +1496,10 @@ lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
1324 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); 1496 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1325 1497
1326 *((uint32_t *) (pcmd)) = ELS_CMD_SCR; 1498 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
1327 pcmd += sizeof (uint32_t); 1499 pcmd += sizeof(uint32_t);
1328 1500
1329 /* For SCR, remainder of payload is SCR parameter page */ 1501 /* For SCR, remainder of payload is SCR parameter page */
1330 memset(pcmd, 0, sizeof (SCR)); 1502 memset(pcmd, 0, sizeof(SCR));
1331 ((SCR *) pcmd)->Function = SCR_FUNC_FULL; 1503 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
1332 1504
1333 phba->fc_stat.elsXmitSCR++; 1505 phba->fc_stat.elsXmitSCR++;
@@ -1358,7 +1530,7 @@ lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
1358 1530
1359 psli = &phba->sli; 1531 psli = &phba->sli;
1360 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ 1532 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1361 cmdsize = (sizeof (uint32_t) + sizeof (FARP)); 1533 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
1362 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); 1534 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1363 if (!ndlp) 1535 if (!ndlp)
1364 return 1; 1536 return 1;
@@ -1376,25 +1548,25 @@ lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
1376 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); 1548 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1377 1549
1378 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR; 1550 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
1379 pcmd += sizeof (uint32_t); 1551 pcmd += sizeof(uint32_t);
1380 1552
1381 /* Fill in FARPR payload */ 1553 /* Fill in FARPR payload */
1382 fp = (FARP *) (pcmd); 1554 fp = (FARP *) (pcmd);
1383 memset(fp, 0, sizeof (FARP)); 1555 memset(fp, 0, sizeof(FARP));
1384 lp = (uint32_t *) pcmd; 1556 lp = (uint32_t *) pcmd;
1385 *lp++ = be32_to_cpu(nportid); 1557 *lp++ = be32_to_cpu(nportid);
1386 *lp++ = be32_to_cpu(vport->fc_myDID); 1558 *lp++ = be32_to_cpu(vport->fc_myDID);
1387 fp->Rflags = 0; 1559 fp->Rflags = 0;
1388 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE); 1560 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
1389 1561
1390 memcpy(&fp->RportName, &vport->fc_portname, sizeof (struct lpfc_name)); 1562 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
1391 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof (struct lpfc_name)); 1563 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
1392 ondlp = lpfc_findnode_did(vport, nportid); 1564 ondlp = lpfc_findnode_did(vport, nportid);
1393 if (ondlp) { 1565 if (ondlp) {
1394 memcpy(&fp->OportName, &ondlp->nlp_portname, 1566 memcpy(&fp->OportName, &ondlp->nlp_portname,
1395 sizeof (struct lpfc_name)); 1567 sizeof(struct lpfc_name));
1396 memcpy(&fp->OnodeName, &ondlp->nlp_nodename, 1568 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
1397 sizeof (struct lpfc_name)); 1569 sizeof(struct lpfc_name));
1398 } 1570 }
1399 1571
1400 phba->fc_stat.elsXmitFARPR++; 1572 phba->fc_stat.elsXmitFARPR++;
@@ -1470,18 +1642,17 @@ lpfc_els_retry_delay(unsigned long ptr)
1470{ 1642{
1471 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr; 1643 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
1472 struct lpfc_vport *vport = ndlp->vport; 1644 struct lpfc_vport *vport = ndlp->vport;
1473 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1474 struct lpfc_hba *phba = vport->phba; 1645 struct lpfc_hba *phba = vport->phba;
1475 unsigned long iflag; 1646 unsigned long flags;
1476 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt; 1647 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
1477 1648
1478 ndlp = (struct lpfc_nodelist *) ptr; 1649 ndlp = (struct lpfc_nodelist *) ptr;
1479 phba = ndlp->vport->phba; 1650 phba = ndlp->vport->phba;
1480 evtp = &ndlp->els_retry_evt; 1651 evtp = &ndlp->els_retry_evt;
1481 1652
1482 spin_lock_irqsave(shost->host_lock, iflag); 1653 spin_lock_irqsave(&phba->hbalock, flags);
1483 if (!list_empty(&evtp->evt_listp)) { 1654 if (!list_empty(&evtp->evt_listp)) {
1484 spin_unlock_irqrestore(shost->host_lock, iflag); 1655 spin_unlock_irqrestore(&phba->hbalock, flags);
1485 return; 1656 return;
1486 } 1657 }
1487 1658
@@ -1489,9 +1660,9 @@ lpfc_els_retry_delay(unsigned long ptr)
1489 evtp->evt = LPFC_EVT_ELS_RETRY; 1660 evtp->evt = LPFC_EVT_ELS_RETRY;
1490 list_add_tail(&evtp->evt_listp, &phba->work_list); 1661 list_add_tail(&evtp->evt_listp, &phba->work_list);
1491 if (phba->work_wait) 1662 if (phba->work_wait)
1492 wake_up(phba->work_wait); 1663 lpfc_worker_wake_up(phba);
1493 1664
1494 spin_unlock_irqrestore(shost->host_lock, iflag); 1665 spin_unlock_irqrestore(&phba->hbalock, flags);
1495 return; 1666 return;
1496} 1667}
1497 1668
@@ -1550,6 +1721,9 @@ lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
1550 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); 1721 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1551 } 1722 }
1552 break; 1723 break;
1724 case ELS_CMD_FDISC:
1725 lpfc_issue_els_fdisc(vport, ndlp, retry);
1726 break;
1553 } 1727 }
1554 return; 1728 return;
1555} 1729}
@@ -1598,7 +1772,7 @@ lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1598 switch ((irsp->un.ulpWord[4] & 0xff)) { 1772 switch ((irsp->un.ulpWord[4] & 0xff)) {
1599 case IOERR_LOOP_OPEN_FAILURE: 1773 case IOERR_LOOP_OPEN_FAILURE:
1600 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0) 1774 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
1601 delay = 1; 1775 delay = 1000;
1602 retry = 1; 1776 retry = 1;
1603 break; 1777 break;
1604 1778
@@ -1606,9 +1780,21 @@ lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1606 retry = 1; 1780 retry = 1;
1607 break; 1781 break;
1608 1782
1783 case IOERR_ILLEGAL_COMMAND:
1784 if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) &&
1785 (cmd == ELS_CMD_FDISC)) {
1786 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
1787 "%d (%d):0124 FDISC failed (3/6) retrying...\n",
1788 phba->brd_no, vport->vpi);
1789 lpfc_mbx_unreg_vpi(vport);
1790 retry = 1;
1791 /* Always retry for this case */
1792 cmdiocb->retry = 0;
1793 }
1794 break;
1795
1609 case IOERR_NO_RESOURCES: 1796 case IOERR_NO_RESOURCES:
1610 if (cmd == ELS_CMD_PLOGI) 1797 delay = 100;
1611 delay = 1;
1612 retry = 1; 1798 retry = 1;
1613 break; 1799 break;
1614 1800
@@ -1641,27 +1827,56 @@ lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1641 if (stat.un.b.lsRjtRsnCodeExp == 1827 if (stat.un.b.lsRjtRsnCodeExp ==
1642 LSEXP_CMD_IN_PROGRESS) { 1828 LSEXP_CMD_IN_PROGRESS) {
1643 if (cmd == ELS_CMD_PLOGI) { 1829 if (cmd == ELS_CMD_PLOGI) {
1644 delay = 1; 1830 delay = 1000;
1645 maxretry = 48; 1831 maxretry = 48;
1646 } 1832 }
1647 retry = 1; 1833 retry = 1;
1648 break; 1834 break;
1649 } 1835 }
1650 if (cmd == ELS_CMD_PLOGI) { 1836 if (cmd == ELS_CMD_PLOGI) {
1651 delay = 1; 1837 delay = 1000;
1652 maxretry = lpfc_max_els_tries + 1; 1838 maxretry = lpfc_max_els_tries + 1;
1653 retry = 1; 1839 retry = 1;
1654 break; 1840 break;
1655 } 1841 }
1842 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1843 (cmd == ELS_CMD_FDISC) &&
1844 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
1845 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
1846 "%d (%d):0125 FDISC Failed (x%x)."
1847 " Fabric out of resources\n",
1848 phba->brd_no, vport->vpi, stat.un.lsRjtError);
1849 lpfc_vport_set_state(vport,
1850 FC_VPORT_NO_FABRIC_RSCS);
1851 }
1656 break; 1852 break;
1657 1853
1658 case LSRJT_LOGICAL_BSY: 1854 case LSRJT_LOGICAL_BSY:
1659 if (cmd == ELS_CMD_PLOGI) { 1855 if (cmd == ELS_CMD_PLOGI) {
1660 delay = 1; 1856 delay = 1000;
1661 maxretry = 48; 1857 maxretry = 48;
1858 } else if (cmd == ELS_CMD_FDISC) {
1859 /* Always retry for this case */
1860 cmdiocb->retry = 0;
1662 } 1861 }
1663 retry = 1; 1862 retry = 1;
1664 break; 1863 break;
1864
1865 case LSRJT_LOGICAL_ERR:
1866 case LSRJT_PROTOCOL_ERR:
1867 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1868 (cmd == ELS_CMD_FDISC) &&
1869 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
1870 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
1871 ) {
1872 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
1873 "%d (%d):0123 FDISC Failed (x%x)."
1874 " Fabric Detected Bad WWN\n",
1875 phba->brd_no, vport->vpi, stat.un.lsRjtError);
1876 lpfc_vport_set_state(vport,
1877 FC_VPORT_FABRIC_REJ_WWN);
1878 }
1879 break;
1665 } 1880 }
1666 break; 1881 break;
1667 1882
@@ -1688,15 +1903,15 @@ lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1688 1903
1689 /* Retry ELS command <elsCmd> to remote NPORT <did> */ 1904 /* Retry ELS command <elsCmd> to remote NPORT <did> */
1690 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 1905 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1691 "%d:0107 Retry ELS command x%x to remote " 1906 "%d (%d):0107 Retry ELS command x%x to remote "
1692 "NPORT x%x Data: x%x x%x\n", 1907 "NPORT x%x Data: x%x x%x\n",
1693 phba->brd_no, 1908 phba->brd_no, vport->vpi,
1694 cmd, did, cmdiocb->retry, delay); 1909 cmd, did, cmdiocb->retry, delay);
1695 1910
1696 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) { 1911 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) {
1697 /* If discovery / RSCN timer is running, reset it */ 1912 /* If discovery / RSCN timer is running, reset it */
1698 if (timer_pending(&vport->fc_disctmo) || 1913 if (timer_pending(&vport->fc_disctmo) ||
1699 (vport->fc_flag & FC_RSCN_MODE)) 1914 (vport->fc_flag & FC_RSCN_MODE))
1700 lpfc_set_disctmo(vport); 1915 lpfc_set_disctmo(vport);
1701 } 1916 }
1702 1917
@@ -1705,7 +1920,9 @@ lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1705 phba->fc_stat.elsDelayRetry++; 1920 phba->fc_stat.elsDelayRetry++;
1706 ndlp->nlp_retry = cmdiocb->retry; 1921 ndlp->nlp_retry = cmdiocb->retry;
1707 1922
1708 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ); 1923 /* delay is specified in milliseconds */
1924 mod_timer(&ndlp->nlp_delayfunc,
1925 jiffies + msecs_to_jiffies(delay));
1709 spin_lock_irq(shost->host_lock); 1926 spin_lock_irq(shost->host_lock);
1710 ndlp->nlp_flag |= NLP_DELAY_TMO; 1927 ndlp->nlp_flag |= NLP_DELAY_TMO;
1711 spin_unlock_irq(shost->host_lock); 1928 spin_unlock_irq(shost->host_lock);
@@ -1720,6 +1937,9 @@ lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1720 case ELS_CMD_FLOGI: 1937 case ELS_CMD_FLOGI:
1721 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry); 1938 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
1722 return 1; 1939 return 1;
1940 case ELS_CMD_FDISC:
1941 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
1942 return 1;
1723 case ELS_CMD_PLOGI: 1943 case ELS_CMD_PLOGI:
1724 if (ndlp) { 1944 if (ndlp) {
1725 ndlp->nlp_prev_state = ndlp->nlp_state; 1945 ndlp->nlp_prev_state = ndlp->nlp_state;
@@ -1748,9 +1968,9 @@ lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1748 1968
1749 /* No retry ELS command <elsCmd> to remote NPORT <did> */ 1969 /* No retry ELS command <elsCmd> to remote NPORT <did> */
1750 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 1970 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1751 "%d:0108 No retry ELS command x%x to remote NPORT x%x " 1971 "%d (%d):0108 No retry ELS command x%x to remote "
1752 "Data: x%x\n", 1972 "NPORT x%x Data: x%x\n",
1753 phba->brd_no, 1973 phba->brd_no, vport->vpi,
1754 cmd, did, cmdiocb->retry); 1974 cmd, did, cmdiocb->retry);
1755 1975
1756 return 0; 1976 return 0;
@@ -1798,10 +2018,10 @@ lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1798 2018
1799 /* ACC to LOGO completes to NPort <nlp_DID> */ 2019 /* ACC to LOGO completes to NPort <nlp_DID> */
1800 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 2020 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1801 "%d:0109 ACC to LOGO completes to NPort x%x " 2021 "%d (%d):0109 ACC to LOGO completes to NPort x%x "
1802 "Data: x%x x%x x%x\n", 2022 "Data: x%x x%x x%x\n",
1803 phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag, 2023 phba->brd_no, vport->vpi, ndlp->nlp_DID,
1804 ndlp->nlp_state, ndlp->nlp_rpi); 2024 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
1805 2025
1806 switch (ndlp->nlp_state) { 2026 switch (ndlp->nlp_state) {
1807 case NLP_STE_UNUSED_NODE: /* node is just allocated */ 2027 case NLP_STE_UNUSED_NODE: /* node is just allocated */
@@ -1848,9 +2068,9 @@ lpfc_cmpl_els_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1848 2068
1849 /* ELS response tag <ulpIoTag> completes */ 2069 /* ELS response tag <ulpIoTag> completes */
1850 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 2070 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1851 "%d:0110 ELS response tag x%x completes " 2071 "%d (%d):0110 ELS response tag x%x completes "
1852 "Data: x%x x%x x%x x%x x%x x%x x%x\n", 2072 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
1853 phba->brd_no, 2073 phba->brd_no, vport->vpi,
1854 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus, 2074 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
1855 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout, 2075 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
1856 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, 2076 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
@@ -1926,7 +2146,7 @@ lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
1926 2146
1927 switch (flag) { 2147 switch (flag) {
1928 case ELS_CMD_ACC: 2148 case ELS_CMD_ACC:
1929 cmdsize = sizeof (uint32_t); 2149 cmdsize = sizeof(uint32_t);
1930 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, 2150 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
1931 ndlp, ndlp->nlp_DID, ELS_CMD_ACC); 2151 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
1932 if (!elsiocb) { 2152 if (!elsiocb) {
@@ -1940,10 +2160,10 @@ lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
1940 icmd->ulpContext = oldcmd->ulpContext; /* Xri */ 2160 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
1941 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); 2161 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1942 *((uint32_t *) (pcmd)) = ELS_CMD_ACC; 2162 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
1943 pcmd += sizeof (uint32_t); 2163 pcmd += sizeof(uint32_t);
1944 break; 2164 break;
1945 case ELS_CMD_PLOGI: 2165 case ELS_CMD_PLOGI:
1946 cmdsize = (sizeof (struct serv_parm) + sizeof (uint32_t)); 2166 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
1947 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, 2167 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
1948 ndlp, ndlp->nlp_DID, ELS_CMD_ACC); 2168 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
1949 if (!elsiocb) 2169 if (!elsiocb)
@@ -1957,11 +2177,11 @@ lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
1957 elsiocb->context_un.mbox = mbox; 2177 elsiocb->context_un.mbox = mbox;
1958 2178
1959 *((uint32_t *) (pcmd)) = ELS_CMD_ACC; 2179 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
1960 pcmd += sizeof (uint32_t); 2180 pcmd += sizeof(uint32_t);
1961 memcpy(pcmd, &vport->fc_sparam, sizeof (struct serv_parm)); 2181 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
1962 break; 2182 break;
1963 case ELS_CMD_PRLO: 2183 case ELS_CMD_PRLO:
1964 cmdsize = sizeof (uint32_t) + sizeof (PRLO); 2184 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
1965 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, 2185 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
1966 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO); 2186 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
1967 if (!elsiocb) 2187 if (!elsiocb)
@@ -1972,7 +2192,7 @@ lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
1972 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); 2192 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1973 2193
1974 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt, 2194 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
1975 sizeof (uint32_t) + sizeof (PRLO)); 2195 sizeof(uint32_t) + sizeof(PRLO));
1976 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC; 2196 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
1977 els_pkt_ptr = (ELS_PKT *) pcmd; 2197 els_pkt_ptr = (ELS_PKT *) pcmd;
1978 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED; 2198 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
@@ -1988,9 +2208,9 @@ lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
1988 2208
1989 /* Xmit ELS ACC response tag <ulpIoTag> */ 2209 /* Xmit ELS ACC response tag <ulpIoTag> */
1990 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 2210 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1991 "%d:0128 Xmit ELS ACC response tag x%x, XRI: x%x, " 2211 "%d (%d):0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
1992 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n", 2212 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
1993 phba->brd_no, elsiocb->iotag, 2213 phba->brd_no, vport->vpi, elsiocb->iotag,
1994 elsiocb->iocb.ulpContext, ndlp->nlp_DID, 2214 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
1995 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); 2215 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
1996 2216
@@ -2029,7 +2249,7 @@ lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
2029 psli = &phba->sli; 2249 psli = &phba->sli;
2030 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ 2250 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2031 2251
2032 cmdsize = 2 * sizeof (uint32_t); 2252 cmdsize = 2 * sizeof(uint32_t);
2033 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, 2253 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2034 ndlp->nlp_DID, ELS_CMD_LS_RJT); 2254 ndlp->nlp_DID, ELS_CMD_LS_RJT);
2035 if (!elsiocb) 2255 if (!elsiocb)
@@ -2041,14 +2261,15 @@ lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
2041 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); 2261 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2042 2262
2043 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT; 2263 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
2044 pcmd += sizeof (uint32_t); 2264 pcmd += sizeof(uint32_t);
2045 *((uint32_t *) (pcmd)) = rejectError; 2265 *((uint32_t *) (pcmd)) = rejectError;
2046 2266
2047 /* Xmit ELS RJT <err> response tag <ulpIoTag> */ 2267 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
2048 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 2268 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2049 "%d:0129 Xmit ELS RJT x%x response tag x%x xri x%x, " 2269 "%d (%d):0129 Xmit ELS RJT x%x response tag x%x "
2050 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", 2270 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
2051 phba->brd_no, rejectError, elsiocb->iotag, 2271 "rpi x%x\n",
2272 phba->brd_no, vport->vpi, rejectError, elsiocb->iotag,
2052 elsiocb->iocb.ulpContext, ndlp->nlp_DID, 2273 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2053 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); 2274 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2054 2275
@@ -2076,7 +2297,7 @@ lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
2076 uint16_t cmdsize; 2297 uint16_t cmdsize;
2077 int rc; 2298 int rc;
2078 2299
2079 cmdsize = sizeof (uint32_t) + sizeof (ADISC); 2300 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
2080 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, 2301 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2081 ndlp->nlp_DID, ELS_CMD_ACC); 2302 ndlp->nlp_DID, ELS_CMD_ACC);
2082 if (!elsiocb) 2303 if (!elsiocb)
@@ -2088,21 +2309,21 @@ lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
2088 2309
2089 /* Xmit ADISC ACC response tag <ulpIoTag> */ 2310 /* Xmit ADISC ACC response tag <ulpIoTag> */
2090 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 2311 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2091 "%d:0130 Xmit ADISC ACC response iotag x%x xri: " 2312 "%d (%d):0130 Xmit ADISC ACC response iotag x%x xri: "
2092 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n", 2313 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
2093 phba->brd_no, elsiocb->iotag, 2314 phba->brd_no, vport->vpi, elsiocb->iotag,
2094 elsiocb->iocb.ulpContext, ndlp->nlp_DID, 2315 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2095 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); 2316 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2096 2317
2097 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); 2318 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2098 2319
2099 *((uint32_t *) (pcmd)) = ELS_CMD_ACC; 2320 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2100 pcmd += sizeof (uint32_t); 2321 pcmd += sizeof(uint32_t);
2101 2322
2102 ap = (ADISC *) (pcmd); 2323 ap = (ADISC *) (pcmd);
2103 ap->hardAL_PA = phba->fc_pref_ALPA; 2324 ap->hardAL_PA = phba->fc_pref_ALPA;
2104 memcpy(&ap->portName, &vport->fc_portname, sizeof (struct lpfc_name)); 2325 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2105 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof (struct lpfc_name)); 2326 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2106 ap->DID = be32_to_cpu(vport->fc_myDID); 2327 ap->DID = be32_to_cpu(vport->fc_myDID);
2107 2328
2108 phba->fc_stat.elsXmitACC++; 2329 phba->fc_stat.elsXmitACC++;
@@ -2134,9 +2355,9 @@ lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
2134 psli = &phba->sli; 2355 psli = &phba->sli;
2135 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */ 2356 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2136 2357
2137 cmdsize = sizeof (uint32_t) + sizeof (PRLI); 2358 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
2138 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, 2359 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2139 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK))); 2360 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
2140 if (!elsiocb) 2361 if (!elsiocb)
2141 return 1; 2362 return 1;
2142 2363
@@ -2146,19 +2367,19 @@ lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
2146 2367
2147 /* Xmit PRLI ACC response tag <ulpIoTag> */ 2368 /* Xmit PRLI ACC response tag <ulpIoTag> */
2148 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 2369 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2149 "%d:0131 Xmit PRLI ACC response tag x%x xri x%x, " 2370 "%d (%d):0131 Xmit PRLI ACC response tag x%x xri x%x, "
2150 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", 2371 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
2151 phba->brd_no, elsiocb->iotag, 2372 phba->brd_no, vport->vpi, elsiocb->iotag,
2152 elsiocb->iocb.ulpContext, ndlp->nlp_DID, 2373 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2153 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); 2374 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2154 2375
2155 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); 2376 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2156 2377
2157 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)); 2378 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
2158 pcmd += sizeof (uint32_t); 2379 pcmd += sizeof(uint32_t);
2159 2380
2160 /* For PRLI, remainder of payload is PRLI parameter page */ 2381 /* For PRLI, remainder of payload is PRLI parameter page */
2161 memset(pcmd, 0, sizeof (PRLI)); 2382 memset(pcmd, 0, sizeof(PRLI));
2162 2383
2163 npr = (PRLI *) pcmd; 2384 npr = (PRLI *) pcmd;
2164 vpd = &phba->vpd; 2385 vpd = &phba->vpd;
@@ -2208,10 +2429,10 @@ lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
2208 psli = &phba->sli; 2429 psli = &phba->sli;
2209 pring = &psli->ring[LPFC_ELS_RING]; 2430 pring = &psli->ring[LPFC_ELS_RING];
2210 2431
2211 cmdsize = sizeof (uint32_t) + sizeof (uint32_t) 2432 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
2212 + (2 * sizeof (struct lpfc_name)); 2433 + (2 * sizeof(struct lpfc_name));
2213 if (format) 2434 if (format)
2214 cmdsize += sizeof (RNID_TOP_DISC); 2435 cmdsize += sizeof(RNID_TOP_DISC);
2215 2436
2216 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp, 2437 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2217 ndlp->nlp_DID, ELS_CMD_ACC); 2438 ndlp->nlp_DID, ELS_CMD_ACC);
@@ -2224,30 +2445,30 @@ lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
2224 2445
2225 /* Xmit RNID ACC response tag <ulpIoTag> */ 2446 /* Xmit RNID ACC response tag <ulpIoTag> */
2226 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 2447 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2227 "%d:0132 Xmit RNID ACC response tag x%x " 2448 "%d (%d):0132 Xmit RNID ACC response tag x%x "
2228 "xri x%x\n", 2449 "xri x%x\n",
2229 phba->brd_no, elsiocb->iotag, 2450 phba->brd_no, vport->vpi, elsiocb->iotag,
2230 elsiocb->iocb.ulpContext); 2451 elsiocb->iocb.ulpContext);
2231 2452
2232 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); 2453 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2233 2454
2234 *((uint32_t *) (pcmd)) = ELS_CMD_ACC; 2455 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2235 pcmd += sizeof (uint32_t); 2456 pcmd += sizeof(uint32_t);
2236 2457
2237 memset(pcmd, 0, sizeof (RNID)); 2458 memset(pcmd, 0, sizeof(RNID));
2238 rn = (RNID *) (pcmd); 2459 rn = (RNID *) (pcmd);
2239 rn->Format = format; 2460 rn->Format = format;
2240 rn->CommonLen = (2 * sizeof (struct lpfc_name)); 2461 rn->CommonLen = (2 * sizeof(struct lpfc_name));
2241 memcpy(&rn->portName, &vport->fc_portname, sizeof (struct lpfc_name)); 2462 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2242 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof (struct lpfc_name)); 2463 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2243 switch (format) { 2464 switch (format) {
2244 case 0: 2465 case 0:
2245 rn->SpecificLen = 0; 2466 rn->SpecificLen = 0;
2246 break; 2467 break;
2247 case RNID_TOPOLOGY_DISC: 2468 case RNID_TOPOLOGY_DISC:
2248 rn->SpecificLen = sizeof (RNID_TOP_DISC); 2469 rn->SpecificLen = sizeof(RNID_TOP_DISC);
2249 memcpy(&rn->un.topologyDisc.portName, 2470 memcpy(&rn->un.topologyDisc.portName,
2250 &vport->fc_portname, sizeof (struct lpfc_name)); 2471 &vport->fc_portname, sizeof(struct lpfc_name));
2251 rn->un.topologyDisc.unitType = RNID_HBA; 2472 rn->un.topologyDisc.unitType = RNID_HBA;
2252 rn->un.topologyDisc.physPort = 0; 2473 rn->un.topologyDisc.physPort = 0;
2253 rn->un.topologyDisc.attachedNodes = 0; 2474 rn->un.topologyDisc.attachedNodes = 0;
@@ -2344,22 +2565,15 @@ lpfc_els_disc_plogi(struct lpfc_vport *vport)
2344 return sentplogi; 2565 return sentplogi;
2345} 2566}
2346 2567
2347int 2568void
2348lpfc_els_flush_rscn(struct lpfc_vport *vport) 2569lpfc_els_flush_rscn(struct lpfc_vport *vport)
2349{ 2570{
2350 struct Scsi_Host *shost = lpfc_shost_from_vport(vport); 2571 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2351 struct lpfc_hba *phba = vport->phba; 2572 struct lpfc_hba *phba = vport->phba;
2352 struct lpfc_dmabuf *mp;
2353 int i; 2573 int i;
2354 2574
2355 for (i = 0; i < vport->fc_rscn_id_cnt; i++) { 2575 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
2356 mp = vport->fc_rscn_id_list[i]; 2576 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
2357 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
2358 lpfc_sli_hbqbuf_free(phba, mp->virt, mp->phys);
2359 else {
2360 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2361 kfree(mp);
2362 }
2363 vport->fc_rscn_id_list[i] = NULL; 2577 vport->fc_rscn_id_list[i] = NULL;
2364 } 2578 }
2365 spin_lock_irq(shost->host_lock); 2579 spin_lock_irq(shost->host_lock);
@@ -2367,7 +2581,6 @@ lpfc_els_flush_rscn(struct lpfc_vport *vport)
2367 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY); 2581 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
2368 spin_unlock_irq(shost->host_lock); 2582 spin_unlock_irq(shost->host_lock);
2369 lpfc_can_disctmo(vport); 2583 lpfc_can_disctmo(vport);
2370 return 0;
2371} 2584}
2372 2585
2373int 2586int
@@ -2375,13 +2588,11 @@ lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
2375{ 2588{
2376 D_ID ns_did; 2589 D_ID ns_did;
2377 D_ID rscn_did; 2590 D_ID rscn_did;
2378 struct lpfc_dmabuf *mp;
2379 uint32_t *lp; 2591 uint32_t *lp;
2380 uint32_t payload_len, cmd, i, match; 2592 uint32_t payload_len, i;
2381 struct lpfc_hba *phba = vport->phba; 2593 struct lpfc_hba *phba = vport->phba;
2382 2594
2383 ns_did.un.word = did; 2595 ns_did.un.word = did;
2384 match = 0;
2385 2596
2386 /* Never match fabric nodes for RSCNs */ 2597 /* Never match fabric nodes for RSCNs */
2387 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) 2598 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
@@ -2392,45 +2603,40 @@ lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
2392 return did; 2603 return did;
2393 2604
2394 for (i = 0; i < vport->fc_rscn_id_cnt; i++) { 2605 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
2395 mp = vport->fc_rscn_id_list[i]; 2606 lp = vport->fc_rscn_id_list[i]->virt;
2396 lp = (uint32_t *) mp->virt; 2607 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
2397 cmd = *lp++; 2608 payload_len -= sizeof(uint32_t); /* take off word 0 */
2398 payload_len = be32_to_cpu(cmd) & 0xffff; /* payload length */
2399 payload_len -= sizeof (uint32_t); /* take off word 0 */
2400 while (payload_len) { 2609 while (payload_len) {
2401 rscn_did.un.word = *lp++; 2610 rscn_did.un.word = be32_to_cpu(*lp++);
2402 rscn_did.un.word = be32_to_cpu(rscn_did.un.word); 2611 payload_len -= sizeof(uint32_t);
2403 payload_len -= sizeof (uint32_t);
2404 switch (rscn_did.un.b.resv) { 2612 switch (rscn_did.un.b.resv) {
2405 case 0: /* Single N_Port ID effected */ 2613 case 0: /* Single N_Port ID effected */
2406 if (ns_did.un.word == rscn_did.un.word) 2614 if (ns_did.un.word == rscn_did.un.word)
2407 match = did; 2615 return did;
2408 break; 2616 break;
2409 case 1: /* Whole N_Port Area effected */ 2617 case 1: /* Whole N_Port Area effected */
2410 if ((ns_did.un.b.domain == rscn_did.un.b.domain) 2618 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
2411 && (ns_did.un.b.area == rscn_did.un.b.area)) 2619 && (ns_did.un.b.area == rscn_did.un.b.area))
2412 match = did; 2620 return did;
2413 break; 2621 break;
2414 case 2: /* Whole N_Port Domain effected */ 2622 case 2: /* Whole N_Port Domain effected */
2415 if (ns_did.un.b.domain == rscn_did.un.b.domain) 2623 if (ns_did.un.b.domain == rscn_did.un.b.domain)
2416 match = did; 2624 return did;
2417 break;
2418 case 3: /* Whole Fabric effected */
2419 match = did;
2420 break; 2625 break;
2421 default: 2626 default:
2422 /* Unknown Identifier in RSCN node */ 2627 /* Unknown Identifier in RSCN node */
2423 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, 2628 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2424 "%d:0217 Unknown Identifier in " 2629 "%d (%d):0217 Unknown "
2425 "RSCN payload Data: x%x\n", 2630 "Identifier in RSCN payload "
2426 phba->brd_no, rscn_did.un.word); 2631 "Data: x%x\n",
2427 break; 2632 phba->brd_no, vport->vpi,
2428 } 2633 rscn_did.un.word);
2429 if (match) 2634 case 3: /* Whole Fabric effected */
2430 break; 2635 return did;
2431 } 2636 }
2432 } 2637 }
2433 return match; 2638 }
2639 return 0;
2434} 2640}
2435 2641
2436static int 2642static int
@@ -2448,7 +2654,7 @@ lpfc_rscn_recovery_check(struct lpfc_vport *vport)
2448 continue; 2654 continue;
2449 2655
2450 lpfc_disc_state_machine(vport, ndlp, NULL, 2656 lpfc_disc_state_machine(vport, ndlp, NULL,
2451 NLP_EVT_DEVICE_RECOVERY); 2657 NLP_EVT_DEVICE_RECOVERY);
2452 2658
2453 /* 2659 /*
2454 * Make sure NLP_DELAY_TMO is NOT running after a device 2660 * Make sure NLP_DELAY_TMO is NOT running after a device
@@ -2468,25 +2674,26 @@ lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
2468 struct Scsi_Host *shost = lpfc_shost_from_vport(vport); 2674 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2469 struct lpfc_hba *phba = vport->phba; 2675 struct lpfc_hba *phba = vport->phba;
2470 struct lpfc_dmabuf *pcmd; 2676 struct lpfc_dmabuf *pcmd;
2471 uint32_t *lp; 2677 struct lpfc_vport *next_vport;
2678 uint32_t *lp, *datap;
2472 IOCB_t *icmd; 2679 IOCB_t *icmd;
2473 uint32_t payload_len, cmd; 2680 uint32_t payload_len, length, nportid, *cmd;
2681 int rscn_cnt = vport->fc_rscn_id_cnt;
2682 int rscn_id = 0, hba_id = 0;
2474 int i; 2683 int i;
2475 2684
2476 icmd = &cmdiocb->iocb; 2685 icmd = &cmdiocb->iocb;
2477 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; 2686 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2478 lp = (uint32_t *) pcmd->virt; 2687 lp = (uint32_t *) pcmd->virt;
2479 2688
2480 cmd = *lp++; 2689 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
2481 payload_len = be32_to_cpu(cmd) & 0xffff; /* payload length */ 2690 payload_len -= sizeof(uint32_t); /* take off word 0 */
2482 payload_len -= sizeof (uint32_t); /* take off word 0 */
2483 cmd &= ELS_CMD_MASK;
2484 2691
2485 /* RSCN received */ 2692 /* RSCN received */
2486 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, 2693 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
2487 "%d:0214 RSCN received Data: x%x x%x x%x x%x\n", 2694 "%d (%d):0214 RSCN received Data: x%x x%x x%x x%x\n",
2488 phba->brd_no, vport->fc_flag, payload_len, *lp, 2695 phba->brd_no, vport->vpi, vport->fc_flag, payload_len,
2489 vport->fc_rscn_id_cnt); 2696 *lp, rscn_cnt);
2490 2697
2491 for (i = 0; i < payload_len/sizeof(uint32_t); i++) 2698 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
2492 fc_host_post_event(shost, fc_get_event_number(), 2699 fc_host_post_event(shost, fc_get_event_number(),
@@ -2497,32 +2704,77 @@ lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
2497 */ 2704 */
2498 if (vport->port_state <= LPFC_NS_QRY) { 2705 if (vport->port_state <= LPFC_NS_QRY) {
2499 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 2706 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL,
2500 newnode); 2707 newnode);
2501 return 0; 2708 return 0;
2502 } 2709 }
2503 2710
2711 /* If this RSCN just contains NPortIDs for other vports on this HBA,
2712 * just ACC and ignore it.
2713 */
2714 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2715 !(phba->cfg_peer_port_login)) {
2716 i = payload_len;
2717 datap = lp;
2718 while (i > 0) {
2719 nportid = *datap++;
2720 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
2721 i -= sizeof(uint32_t);
2722 rscn_id++;
2723 list_for_each_entry(next_vport, &phba->port_list,
2724 listentry) {
2725 if (nportid == next_vport->fc_myDID) {
2726 hba_id++;
2727 break;
2728 }
2729 }
2730 }
2731 if (rscn_id == hba_id) {
2732 /* ALL NPortIDs in RSCN are on HBA */
2733 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
2734 "%d (%d):0214 Ignore RSCN Data: x%x x%x x%x x%x\n",
2735 phba->brd_no, vport->vpi, vport->fc_flag, payload_len,
2736 *lp, rscn_cnt);
2737 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
2738 ndlp, NULL, newnode);
2739 return 0;
2740 }
2741 }
2742
2504 /* If we are already processing an RSCN, save the received 2743 /* If we are already processing an RSCN, save the received
2505 * RSCN payload buffer, cmdiocb->context2 to process later. 2744 * RSCN payload buffer, cmdiocb->context2 to process later.
2506 */ 2745 */
2507 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) { 2746 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
2508 if ((vport->fc_rscn_id_cnt < FC_MAX_HOLD_RSCN) && 2747 vport->fc_flag |= FC_RSCN_DEFERRED;
2748 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
2509 !(vport->fc_flag & FC_RSCN_DISCOVERY)) { 2749 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
2510 spin_lock_irq(shost->host_lock); 2750 spin_lock_irq(shost->host_lock);
2511 vport->fc_flag |= FC_RSCN_MODE; 2751 vport->fc_flag |= FC_RSCN_MODE;
2512 spin_unlock_irq(shost->host_lock); 2752 spin_unlock_irq(shost->host_lock);
2513 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd; 2753 if (rscn_cnt) {
2514 2754 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
2515 /* If we zero, cmdiocb->context2, the calling 2755 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
2516 * routine will not try to free it. 2756 }
2517 */ 2757 if ((rscn_cnt) &&
2518 cmdiocb->context2 = NULL; 2758 (payload_len + length <= LPFC_BPL_SIZE)) {
2759 *cmd &= ELS_CMD_MASK;
2760 *cmd |= be32_to_cpu(payload_len + length);
2761 memcpy(((uint8_t *)cmd) + length, lp,
2762 payload_len);
2763 } else {
2764 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
2765 vport->fc_rscn_id_cnt++;
2766 /* If we zero, cmdiocb->context2, the calling
2767 * routine will not try to free it.
2768 */
2769 cmdiocb->context2 = NULL;
2770 }
2519 2771
2520 /* Deferred RSCN */ 2772 /* Deferred RSCN */
2521 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, 2773 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
2522 "%d:0235 Deferred RSCN " 2774 "%d (%d):0235 Deferred RSCN "
2523 "Data: x%x x%x x%x\n", 2775 "Data: x%x x%x x%x\n",
2524 phba->brd_no, vport->fc_rscn_id_cnt, 2776 phba->brd_no, vport->vpi,
2525 vport->fc_flag, 2777 vport->fc_rscn_id_cnt, vport->fc_flag,
2526 vport->port_state); 2778 vport->port_state);
2527 } else { 2779 } else {
2528 spin_lock_irq(shost->host_lock); 2780 spin_lock_irq(shost->host_lock);
@@ -2530,10 +2782,10 @@ lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
2530 spin_unlock_irq(shost->host_lock); 2782 spin_unlock_irq(shost->host_lock);
2531 /* ReDiscovery RSCN */ 2783 /* ReDiscovery RSCN */
2532 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, 2784 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
2533 "%d:0234 ReDiscovery RSCN " 2785 "%d (%d):0234 ReDiscovery RSCN "
2534 "Data: x%x x%x x%x\n", 2786 "Data: x%x x%x x%x\n",
2535 phba->brd_no, vport->fc_rscn_id_cnt, 2787 phba->brd_no, vport->vpi,
2536 vport->fc_flag, 2788 vport->fc_rscn_id_cnt, vport->fc_flag,
2537 vport->port_state); 2789 vport->port_state);
2538 } 2790 }
2539 /* Send back ACC */ 2791 /* Send back ACC */
@@ -2542,6 +2794,7 @@ lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
2542 2794
2543 /* send RECOVERY event for ALL nodes that match RSCN payload */ 2795 /* send RECOVERY event for ALL nodes that match RSCN payload */
2544 lpfc_rscn_recovery_check(vport); 2796 lpfc_rscn_recovery_check(vport);
2797 vport->fc_flag &= ~FC_RSCN_DEFERRED;
2545 return 0; 2798 return 0;
2546 } 2799 }
2547 2800
@@ -2572,13 +2825,19 @@ lpfc_els_handle_rscn(struct lpfc_vport *vport)
2572 struct lpfc_nodelist *ndlp; 2825 struct lpfc_nodelist *ndlp;
2573 struct lpfc_hba *phba = vport->phba; 2826 struct lpfc_hba *phba = vport->phba;
2574 2827
2828 /* Ignore RSCN if the port is being torn down. */
2829 if (vport->load_flag & FC_UNLOADING) {
2830 lpfc_els_flush_rscn(vport);
2831 return 0;
2832 }
2833
2575 /* Start timer for RSCN processing */ 2834 /* Start timer for RSCN processing */
2576 lpfc_set_disctmo(vport); 2835 lpfc_set_disctmo(vport);
2577 2836
2578 /* RSCN processed */ 2837 /* RSCN processed */
2579 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, 2838 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
2580 "%d:0215 RSCN processed Data: x%x x%x x%x x%x\n", 2839 "%d (%d):0215 RSCN processed Data: x%x x%x x%x x%x\n",
2581 phba->brd_no, 2840 phba->brd_no, vport->vpi,
2582 vport->fc_flag, 0, vport->fc_rscn_id_cnt, 2841 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
2583 vport->port_state); 2842 vport->port_state);
2584 2843
@@ -2587,7 +2846,7 @@ lpfc_els_handle_rscn(struct lpfc_vport *vport)
2587 ndlp = lpfc_findnode_did(vport, NameServer_DID); 2846 ndlp = lpfc_findnode_did(vport, NameServer_DID);
2588 if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) { 2847 if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
2589 /* Good ndlp, issue CT Request to NameServer */ 2848 /* Good ndlp, issue CT Request to NameServer */
2590 if (lpfc_ns_cmd(vport, ndlp, SLI_CTNS_GID_FT) == 0) 2849 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
2591 /* Wait for NameServer query cmpl before we can 2850 /* Wait for NameServer query cmpl before we can
2592 continue */ 2851 continue */
2593 return 1; 2852 return 1;
@@ -2649,9 +2908,9 @@ lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
2649 /* An FLOGI ELS command <elsCmd> was received from DID <did> in 2908 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
2650 Loop Mode */ 2909 Loop Mode */
2651 lpfc_printf_log(phba, KERN_ERR, LOG_ELS, 2910 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
2652 "%d:0113 An FLOGI ELS command x%x was received " 2911 "%d (%d):0113 An FLOGI ELS command x%x was "
2653 "from DID x%x in Loop Mode\n", 2912 "received from DID x%x in Loop Mode\n",
2654 phba->brd_no, cmd, did); 2913 phba->brd_no, vport->vpi, cmd, did);
2655 return 1; 2914 return 1;
2656 } 2915 }
2657 2916
@@ -2663,7 +2922,7 @@ lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
2663 */ 2922 */
2664 2923
2665 rc = memcmp(&vport->fc_portname, &sp->portName, 2924 rc = memcmp(&vport->fc_portname, &sp->portName,
2666 sizeof (struct lpfc_name)); 2925 sizeof(struct lpfc_name));
2667 2926
2668 if (!rc) { 2927 if (!rc) {
2669 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 2928 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
@@ -2802,7 +3061,7 @@ lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2802 3061
2803 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); 3062 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2804 *((uint32_t *) (pcmd)) = ELS_CMD_ACC; 3063 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2805 pcmd += sizeof (uint32_t); /* Skip past command */ 3064 pcmd += sizeof(uint32_t); /* Skip past command */
2806 rps_rsp = (RPS_RSP *)pcmd; 3065 rps_rsp = (RPS_RSP *)pcmd;
2807 3066
2808 if (phba->fc_topology != TOPOLOGY_LOOP) 3067 if (phba->fc_topology != TOPOLOGY_LOOP)
@@ -2823,9 +3082,10 @@ lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2823 3082
2824 /* Xmit ELS RPS ACC response tag <ulpIoTag> */ 3083 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
2825 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 3084 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2826 "%d:0118 Xmit ELS RPS ACC response tag x%x xri x%x, " 3085 "%d (%d):0118 Xmit ELS RPS ACC response tag x%x "
2827 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", 3086 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
2828 phba->brd_no, elsiocb->iotag, 3087 "rpi x%x\n",
3088 phba->brd_no, ndlp->vport->vpi, elsiocb->iotag,
2829 elsiocb->iocb.ulpContext, ndlp->nlp_DID, 3089 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2830 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); 3090 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2831 3091
@@ -2865,14 +3125,17 @@ lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
2865 if ((flag == 0) || 3125 if ((flag == 0) ||
2866 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) || 3126 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
2867 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname, 3127 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
2868 sizeof (struct lpfc_name)) == 0))) { 3128 sizeof(struct lpfc_name)) == 0))) {
2869 3129
3130 printk("Fix me....\n");
3131 dump_stack();
2870 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC); 3132 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
2871 if (mbox) { 3133 if (mbox) {
2872 lpfc_read_lnk_stat(phba, mbox); 3134 lpfc_read_lnk_stat(phba, mbox);
2873 mbox->context1 = 3135 mbox->context1 =
2874 (void *)((unsigned long)cmdiocb->iocb.ulpContext); 3136 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
2875 mbox->context2 = lpfc_nlp_get(ndlp); 3137 mbox->context2 = lpfc_nlp_get(ndlp);
3138 mbox->vport = vport;
2876 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc; 3139 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
2877 if (lpfc_sli_issue_mbox (phba, mbox, 3140 if (lpfc_sli_issue_mbox (phba, mbox,
2878 (MBX_NOWAIT | MBX_STOP_IOCB)) != MBX_NOT_FINISHED) 3141 (MBX_NOWAIT | MBX_STOP_IOCB)) != MBX_NOT_FINISHED)
@@ -2915,7 +3178,7 @@ lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
2915 3178
2916 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt); 3179 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2917 *((uint32_t *) (pcmd)) = ELS_CMD_ACC; 3180 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2918 pcmd += sizeof (uint16_t); 3181 pcmd += sizeof(uint16_t);
2919 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize); 3182 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
2920 pcmd += sizeof(uint16_t); 3183 pcmd += sizeof(uint16_t);
2921 3184
@@ -2932,9 +3195,10 @@ lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
2932 3195
2933 /* Xmit ELS RPL ACC response tag <ulpIoTag> */ 3196 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
2934 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 3197 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2935 "%d:0120 Xmit ELS RPL ACC response tag x%x xri x%x, " 3198 "%d (%d):0120 Xmit ELS RPL ACC response tag x%x "
2936 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n", 3199 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
2937 phba->brd_no, elsiocb->iotag, 3200 "rpi x%x\n",
3201 phba->brd_no, vport->vpi, elsiocb->iotag,
2938 elsiocb->iocb.ulpContext, ndlp->nlp_DID, 3202 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2939 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); 3203 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2940 3204
@@ -3008,8 +3272,8 @@ lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3008 3272
3009 /* FARP-REQ received from DID <did> */ 3273 /* FARP-REQ received from DID <did> */
3010 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 3274 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
3011 "%d:0601 FARP-REQ received from DID x%x\n", 3275 "%d (%d):0601 FARP-REQ received from DID x%x\n",
3012 phba->brd_no, did); 3276 phba->brd_no, vport->vpi, did);
3013 3277
3014 /* We will only support match on WWPN or WWNN */ 3278 /* We will only support match on WWPN or WWNN */
3015 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) { 3279 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
@@ -3020,14 +3284,14 @@ lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3020 /* If this FARP command is searching for my portname */ 3284 /* If this FARP command is searching for my portname */
3021 if (fp->Mflags & FARP_MATCH_PORT) { 3285 if (fp->Mflags & FARP_MATCH_PORT) {
3022 if (memcmp(&fp->RportName, &vport->fc_portname, 3286 if (memcmp(&fp->RportName, &vport->fc_portname,
3023 sizeof (struct lpfc_name)) == 0) 3287 sizeof(struct lpfc_name)) == 0)
3024 cnt = 1; 3288 cnt = 1;
3025 } 3289 }
3026 3290
3027 /* If this FARP command is searching for my nodename */ 3291 /* If this FARP command is searching for my nodename */
3028 if (fp->Mflags & FARP_MATCH_NODE) { 3292 if (fp->Mflags & FARP_MATCH_NODE) {
3029 if (memcmp(&fp->RnodeName, &vport->fc_nodename, 3293 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
3030 sizeof (struct lpfc_name)) == 0) 3294 sizeof(struct lpfc_name)) == 0)
3031 cnt = 1; 3295 cnt = 1;
3032 } 3296 }
3033 3297
@@ -3068,8 +3332,8 @@ lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3068 cmd = *lp++; 3332 cmd = *lp++;
3069 /* FARP-RSP received from DID <did> */ 3333 /* FARP-RSP received from DID <did> */
3070 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 3334 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
3071 "%d:0600 FARP-RSP received from DID x%x\n", 3335 "%d (%d):0600 FARP-RSP received from DID x%x\n",
3072 phba->brd_no, did); 3336 phba->brd_no, vport->vpi, did);
3073 /* ACCEPT the Farp resp request */ 3337 /* ACCEPT the Farp resp request */
3074 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0); 3338 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
3075 3339
@@ -3090,8 +3354,8 @@ lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3090 3354
3091 /* FAN received */ 3355 /* FAN received */
3092 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 3356 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
3093 "%d:0265 FAN received\n", 3357 "%d (%d):0265 FAN received\n",
3094 phba->brd_no); 3358 phba->brd_no, vport->vpi);
3095 3359
3096 icmd = &cmdiocb->iocb; 3360 icmd = &cmdiocb->iocb;
3097 did = icmd->un.elsreq64.remoteID; 3361 did = icmd->un.elsreq64.remoteID;
@@ -3099,7 +3363,7 @@ lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3099 lp = (uint32_t *)pcmd->virt; 3363 lp = (uint32_t *)pcmd->virt;
3100 3364
3101 cmd = *lp++; 3365 cmd = *lp++;
3102 fp = (FAN *)lp; 3366 fp = (FAN *) lp;
3103 3367
3104 /* FAN received; Fan does not have a reply sequence */ 3368 /* FAN received; Fan does not have a reply sequence */
3105 3369
@@ -3178,10 +3442,15 @@ lpfc_els_timeout(unsigned long ptr)
3178 spin_lock_irqsave(&vport->work_port_lock, iflag); 3442 spin_lock_irqsave(&vport->work_port_lock, iflag);
3179 if ((vport->work_port_events & WORKER_ELS_TMO) == 0) { 3443 if ((vport->work_port_events & WORKER_ELS_TMO) == 0) {
3180 vport->work_port_events |= WORKER_ELS_TMO; 3444 vport->work_port_events |= WORKER_ELS_TMO;
3445 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
3446
3447 spin_lock_irqsave(&phba->hbalock, iflag);
3181 if (phba->work_wait) 3448 if (phba->work_wait)
3182 wake_up(phba->work_wait); 3449 lpfc_worker_wake_up(phba);
3450 spin_unlock_irqrestore(&phba->hbalock, iflag);
3183 } 3451 }
3184 spin_unlock_irqrestore(&vport->work_port_lock, iflag); 3452 else
3453 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
3185 return; 3454 return;
3186} 3455}
3187 3456
@@ -3221,17 +3490,19 @@ lpfc_els_timeout_handler(struct lpfc_vport *vport)
3221 if (pcmd) 3490 if (pcmd)
3222 els_command = *(uint32_t *) (pcmd->virt); 3491 els_command = *(uint32_t *) (pcmd->virt);
3223 3492
3224 if ((els_command == ELS_CMD_FARP) 3493 if (els_command == ELS_CMD_FARP ||
3225 || (els_command == ELS_CMD_FARPR)) { 3494 els_command == ELS_CMD_FARPR ||
3495 els_command == ELS_CMD_FDISC)
3496 continue;
3497
3498 if (vport != piocb->vport)
3226 continue; 3499 continue;
3227 }
3228 3500
3229 if (piocb->drvrTimeout > 0) { 3501 if (piocb->drvrTimeout > 0) {
3230 if (piocb->drvrTimeout >= timeout) { 3502 if (piocb->drvrTimeout >= timeout)
3231 piocb->drvrTimeout -= timeout; 3503 piocb->drvrTimeout -= timeout;
3232 } else { 3504 else
3233 piocb->drvrTimeout = 0; 3505 piocb->drvrTimeout = 0;
3234 }
3235 continue; 3506 continue;
3236 } 3507 }
3237 3508
@@ -3245,11 +3516,10 @@ lpfc_els_timeout_handler(struct lpfc_vport *vport)
3245 remote_ID = ndlp->nlp_DID; 3516 remote_ID = ndlp->nlp_DID;
3246 } 3517 }
3247 3518
3248 lpfc_printf_log(phba, 3519 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
3249 KERN_ERR, 3520 "%d (%d):0127 ELS timeout Data: x%x x%x x%x "
3250 LOG_ELS, 3521 "x%x\n",
3251 "%d:0127 ELS timeout Data: x%x x%x x%x x%x\n", 3522 phba->brd_no, vport->vpi, els_command,
3252 phba->brd_no, els_command,
3253 remote_ID, cmd->ulpCommand, cmd->ulpIoTag); 3523 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
3254 3524
3255 lpfc_sli_issue_abort_iotag(phba, pring, piocb); 3525 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
@@ -3268,6 +3538,11 @@ lpfc_els_flush_cmd(struct lpfc_vport *vport)
3268 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; 3538 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
3269 struct lpfc_iocbq *tmp_iocb, *piocb; 3539 struct lpfc_iocbq *tmp_iocb, *piocb;
3270 IOCB_t *cmd = NULL; 3540 IOCB_t *cmd = NULL;
3541 struct lpfc_dmabuf *pcmd;
3542 uint32_t *elscmd;
3543 uint32_t els_command;
3544
3545 lpfc_fabric_abort_vport(vport);
3271 3546
3272 spin_lock_irq(&phba->hbalock); 3547 spin_lock_irq(&phba->hbalock);
3273 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { 3548 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
@@ -3284,6 +3559,10 @@ lpfc_els_flush_cmd(struct lpfc_vport *vport)
3284 cmd->ulpCommand == CMD_ABORT_XRI_CN) 3559 cmd->ulpCommand == CMD_ABORT_XRI_CN)
3285 continue; 3560 continue;
3286 3561
3562 pcmd = (struct lpfc_dmabuf *) piocb->context2;
3563 elscmd = (uint32_t *) (pcmd->virt);
3564 els_command = *elscmd;
3565
3287 if (piocb->vport != vport) 3566 if (piocb->vport != vport)
3288 continue; 3567 continue;
3289 3568
@@ -3306,7 +3585,7 @@ lpfc_els_flush_cmd(struct lpfc_vport *vport)
3306 while (!list_empty(&completions)) { 3585 while (!list_empty(&completions)) {
3307 piocb = list_get_first(&completions, struct lpfc_iocbq, list); 3586 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
3308 cmd = &piocb->iocb; 3587 cmd = &piocb->iocb;
3309 list_del(&piocb->list); 3588 list_del_init(&piocb->list);
3310 3589
3311 if (!piocb->iocb_cmpl) 3590 if (!piocb->iocb_cmpl)
3312 lpfc_sli_release_iocbq(phba, piocb); 3591 lpfc_sli_release_iocbq(phba, piocb);
@@ -3322,21 +3601,20 @@ lpfc_els_flush_cmd(struct lpfc_vport *vport)
3322 3601
3323static void 3602static void
3324lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, 3603lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3325 struct lpfc_vport *vport, struct lpfc_dmabuf *mp, 3604 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
3326 struct lpfc_iocbq *elsiocb)
3327{ 3605{
3328 struct lpfc_nodelist *ndlp; 3606 struct lpfc_nodelist *ndlp;
3329 struct ls_rjt stat; 3607 struct ls_rjt stat;
3330 uint32_t *lp; 3608 uint32_t *payload;
3331 uint32_t cmd, did, newnode, rjt_err = 0; 3609 uint32_t cmd, did, newnode, rjt_err = 0;
3332 IOCB_t *icmd = &elsiocb->iocb; 3610 IOCB_t *icmd = &elsiocb->iocb;
3333 3611
3334 if (!vport || !mp) 3612 if (vport == NULL || elsiocb->context2 == NULL)
3335 goto dropit; 3613 goto dropit;
3336 3614
3337 newnode = 0; 3615 newnode = 0;
3338 lp = (uint32_t *) mp->virt; 3616 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
3339 cmd = *lp++; 3617 cmd = *payload;
3340 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0) 3618 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
3341 lpfc_post_buffer(phba, pring, 1, 1); 3619 lpfc_post_buffer(phba, pring, 1, 1);
3342 3620
@@ -3347,6 +3625,10 @@ lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3347 if (lpfc_els_chk_latt(vport)) 3625 if (lpfc_els_chk_latt(vport))
3348 goto dropit; 3626 goto dropit;
3349 3627
3628 /* Ignore traffic recevied during vport shutdown. */
3629 if (vport->load_flag & FC_UNLOADING)
3630 goto dropit;
3631
3350 did = icmd->un.rcvels.remoteID; 3632 did = icmd->un.rcvels.remoteID;
3351 ndlp = lpfc_findnode_did(vport, did); 3633 ndlp = lpfc_findnode_did(vport, did);
3352 if (!ndlp) { 3634 if (!ndlp) {
@@ -3367,7 +3649,6 @@ lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3367 if (elsiocb->context1) 3649 if (elsiocb->context1)
3368 lpfc_nlp_put(elsiocb->context1); 3650 lpfc_nlp_put(elsiocb->context1);
3369 elsiocb->context1 = lpfc_nlp_get(ndlp); 3651 elsiocb->context1 = lpfc_nlp_get(ndlp);
3370 elsiocb->context2 = mp;
3371 elsiocb->vport = vport; 3652 elsiocb->vport = vport;
3372 3653
3373 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) { 3654 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
@@ -3375,18 +3656,20 @@ lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3375 } 3656 }
3376 /* ELS command <elsCmd> received from NPORT <did> */ 3657 /* ELS command <elsCmd> received from NPORT <did> */
3377 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 3658 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
3378 "%d:0112 ELS command x%x received from NPORT x%x " 3659 "%d (%d):0112 ELS command x%x received from NPORT x%x "
3379 "Data: x%x\n", phba->brd_no, cmd, did, 3660 "Data: x%x\n", phba->brd_no, vport->vpi, cmd, did,
3380 vport->port_state); 3661 vport->port_state);
3381 3662
3382 switch (cmd) { 3663 switch (cmd) {
3383 case ELS_CMD_PLOGI: 3664 case ELS_CMD_PLOGI:
3384 phba->fc_stat.elsRcvPLOGI++; 3665 phba->fc_stat.elsRcvPLOGI++;
3385 if (vport->port_state < LPFC_DISC_AUTH) { 3666 if ((vport->port_state < LPFC_DISC_AUTH) ||
3386 rjt_err = 1; 3667 ((vport->port_type == LPFC_NPIV_PORT &&
3668 phba->cfg_vport_restrict_login))) {
3669 rjt_err = 2;
3387 break; 3670 break;
3388 } 3671 }
3389 ndlp = lpfc_plogi_confirm_nport(phba, mp, ndlp); 3672 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
3390 lpfc_disc_state_machine(vport, ndlp, elsiocb, 3673 lpfc_disc_state_machine(vport, ndlp, elsiocb,
3391 NLP_EVT_RCV_PLOGI); 3674 NLP_EVT_RCV_PLOGI);
3392 break; 3675 break;
@@ -3482,13 +3765,13 @@ lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3482 break; 3765 break;
3483 default: 3766 default:
3484 /* Unsupported ELS command, reject */ 3767 /* Unsupported ELS command, reject */
3485 rjt_err = 1; 3768 rjt_err = 2;
3486 3769
3487 /* Unknown ELS command <elsCmd> received from NPORT <did> */ 3770 /* Unknown ELS command <elsCmd> received from NPORT <did> */
3488 lpfc_printf_log(phba, KERN_ERR, LOG_ELS, 3771 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
3489 "%d:0115 Unknown ELS command x%x " 3772 "%d (%d):0115 Unknown ELS command x%x "
3490 "received from NPORT x%x\n", 3773 "received from NPORT x%x\n",
3491 phba->brd_no, cmd, did); 3774 phba->brd_no, vport->vpi, cmd, did);
3492 if (newnode) 3775 if (newnode)
3493 lpfc_drop_node(vport, ndlp); 3776 lpfc_drop_node(vport, ndlp);
3494 break; 3777 break;
@@ -3496,96 +3779,742 @@ lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3496 3779
3497 /* check if need to LS_RJT received ELS cmd */ 3780 /* check if need to LS_RJT received ELS cmd */
3498 if (rjt_err) { 3781 if (rjt_err) {
3499 stat.un.b.lsRjtRsvd0 = 0; 3782 memset(&stat, 0, sizeof(stat));
3500 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; 3783 if (rjt_err == 1)
3784 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3785 else
3786 stat.un.b.lsRjtRsnCode = LSRJT_INVALID_CMD;
3501 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE; 3787 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
3502 stat.un.b.vendorUnique = 0;
3503 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp); 3788 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp);
3789 if (newnode)
3790 lpfc_drop_node(vport, ndlp);
3504 } 3791 }
3505 3792
3506 return; 3793 return;
3507 3794
3508dropit: 3795dropit:
3509 lpfc_printf_log(phba, KERN_ERR, LOG_ELS, 3796 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
3510 "%d:0111 Dropping received ELS cmd " 3797 "%d (%d):0111 Dropping received ELS cmd "
3511 "Data: x%x x%x x%x\n", 3798 "Data: x%x x%x x%x\n",
3512 phba->brd_no, 3799 phba->brd_no, vport ? vport->vpi : 0xffff,
3513 icmd->ulpStatus, icmd->un.ulpWord[4], 3800 icmd->ulpStatus, icmd->un.ulpWord[4],
3514 icmd->ulpTimeout); 3801 icmd->ulpTimeout);
3515 phba->fc_stat.elsRcvDrop++; 3802 phba->fc_stat.elsRcvDrop++;
3516} 3803}
3517 3804
3805static struct lpfc_vport *
3806lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
3807{
3808 struct lpfc_vport *vport;
3809
3810 list_for_each_entry(vport, &phba->port_list, listentry) {
3811 if (vport->vpi == vpi)
3812 return vport;
3813 }
3814 return NULL;
3815}
3518 3816
3519void 3817void
3520lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, 3818lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3521 struct lpfc_iocbq *elsiocb) 3819 struct lpfc_iocbq *elsiocb)
3522{ 3820{
3523 struct lpfc_vport *vport = phba->pport; 3821 struct lpfc_vport *vport = phba->pport;
3524 struct lpfc_dmabuf *mp = NULL;
3525 IOCB_t *icmd = &elsiocb->iocb; 3822 IOCB_t *icmd = &elsiocb->iocb;
3526 struct hbq_dmabuf *sp = NULL;
3527 dma_addr_t paddr; 3823 dma_addr_t paddr;
3824 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
3825 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
3528 3826
3529 if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) && 3827 elsiocb->context2 = NULL;
3530 ((icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING)) { 3828 elsiocb->context3 = NULL;
3829
3830 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
3831 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
3832 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
3833 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
3531 phba->fc_stat.NoRcvBuf++; 3834 phba->fc_stat.NoRcvBuf++;
3532 /* Not enough posted buffers; Try posting more buffers */ 3835 /* Not enough posted buffers; Try posting more buffers */
3533 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) 3836 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
3534 lpfc_sli_hbqbuf_fill_hbq(phba);
3535 else
3536 lpfc_post_buffer(phba, pring, 0, 1); 3837 lpfc_post_buffer(phba, pring, 0, 1);
3537 return; 3838 return;
3538 } 3839 }
3539 3840
3540 /* If there are no BDEs associated with this IOCB, 3841 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3541 * there is nothing to do. 3842 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
3542 */ 3843 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
3844 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
3845 vport = phba->pport;
3846 else {
3847 uint16_t vpi = icmd->unsli3.rcvsli3.vpi;
3848 vport = lpfc_find_vport_by_vpid(phba, vpi);
3849 }
3850 }
3851 /* If there are no BDEs associated
3852 * with this IOCB, there is nothing to do.
3853 */
3543 if (icmd->ulpBdeCount == 0) 3854 if (icmd->ulpBdeCount == 0)
3544 return; 3855 return;
3545 3856
3546 /* type of ELS cmd is first 32bit word in packet */ 3857 /* type of ELS cmd is first 32bit word
3858 * in packet
3859 */
3547 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { 3860 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
3548 paddr = getPaddr(icmd->un.cont64[0].addrHigh, 3861 elsiocb->context2 = bdeBuf1;
3549 icmd->un.cont64[0].addrLow);
3550 sp = lpfc_sli_hbqbuf_find(phba, icmd->un.ulpWord[3]);
3551 if (sp)
3552 phba->hbq_buff_count--;
3553 mp = sp ? &sp->dbuf : NULL;
3554 } else { 3862 } else {
3555 paddr = getPaddr(icmd->un.cont64[0].addrHigh, 3863 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
3556 icmd->un.cont64[0].addrLow); 3864 icmd->un.cont64[0].addrLow);
3557 mp = lpfc_sli_ringpostbuf_get(phba, pring, paddr); 3865 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
3866 paddr);
3558 } 3867 }
3559 3868
3560 lpfc_els_unsol_buffer(phba, pring, vport, mp, elsiocb); 3869 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
3561 3870 /*
3871 * The different unsolicited event handlers would tell us
3872 * if they are done with "mp" by setting context2 to NULL.
3873 */
3562 lpfc_nlp_put(elsiocb->context1); 3874 lpfc_nlp_put(elsiocb->context1);
3563 elsiocb->context1 = NULL; 3875 elsiocb->context1 = NULL;
3564 if (elsiocb->context2) { 3876 if (elsiocb->context2) {
3565 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) 3877 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
3566 lpfc_sli_free_hbq(phba, sp); 3878 elsiocb->context2 = NULL;
3567 else {
3568 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3569 kfree(mp);
3570 }
3571 } 3879 }
3572 3880
3573 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */ 3881 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
3574 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) != 0 && 3882 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
3575 icmd->ulpBdeCount == 2) { 3883 icmd->ulpBdeCount == 2) {
3576 sp = lpfc_sli_hbqbuf_find(phba, icmd->un.ulpWord[15]); 3884 elsiocb->context2 = bdeBuf2;
3577 if (sp) 3885 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
3578 phba->hbq_buff_count--;
3579 mp = sp ? &sp->dbuf : NULL;
3580 lpfc_els_unsol_buffer(phba, pring, vport, mp, elsiocb);
3581 /* free mp if we are done with it */ 3886 /* free mp if we are done with it */
3582 if (elsiocb->context2) { 3887 if (elsiocb->context2) {
3583 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) 3888 lpfc_in_buf_free(phba, elsiocb->context2);
3584 lpfc_sli_free_hbq(phba, sp); 3889 elsiocb->context2 = NULL;
3585 else { 3890 }
3586 lpfc_mbuf_free(phba, mp->virt, mp->phys); 3891 }
3587 kfree(mp); 3892}
3893
3894void
3895lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
3896{
3897 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
3898
3899 ndlp = lpfc_findnode_did(vport, NameServer_DID);
3900 if (!ndlp) {
3901 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
3902 if (!ndlp) {
3903 if (phba->fc_topology == TOPOLOGY_LOOP) {
3904 lpfc_disc_start(vport);
3905 return;
3906 }
3907 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3908 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
3909 "%d (%d):0251 NameServer login: no memory\n",
3910 phba->brd_no, vport->vpi);
3911 return;
3912 }
3913 lpfc_nlp_init(vport, ndlp, NameServer_DID);
3914 ndlp->nlp_type |= NLP_FABRIC;
3915 }
3916
3917 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
3918
3919 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
3920 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3921 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
3922 "%d (%d):0252 Cannot issue NameServer login\n",
3923 phba->brd_no, vport->vpi);
3924 return;
3925 }
3926
3927 if (phba->cfg_fdmi_on) {
3928 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
3929 GFP_KERNEL);
3930 if (ndlp_fdmi) {
3931 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
3932 ndlp_fdmi->nlp_type |= NLP_FABRIC;
3933 ndlp_fdmi->nlp_state =
3934 NLP_STE_PLOGI_ISSUE;
3935 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID,
3936 0);
3937 }
3938 }
3939 return;
3940}
3941
3942static void
3943lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3944{
3945 struct lpfc_vport *vport = pmb->vport;
3946 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3947 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3948 MAILBOX_t *mb = &pmb->mb;
3949
3950 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
3951 lpfc_nlp_put(ndlp);
3952
3953 if (mb->mbxStatus) {
3954 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
3955 "%d (%d):0915 Register VPI failed: 0x%x\n",
3956 phba->brd_no, vport->vpi, mb->mbxStatus);
3957
3958 switch (mb->mbxStatus) {
3959 case 0x11: /* unsupported feature */
3960 case 0x9603: /* max_vpi exceeded */
3961 /* giving up on vport registration */
3962 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3963 spin_lock_irq(shost->host_lock);
3964 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
3965 spin_unlock_irq(shost->host_lock);
3966 lpfc_can_disctmo(vport);
3967 break;
3968 default:
3969 /* Try to recover from this error */
3970 lpfc_mbx_unreg_vpi(vport);
3971 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3972 lpfc_initial_fdisc(vport);
3973 break;
3974 }
3975
3976 } else {
3977 if (vport == phba->pport)
3978 lpfc_issue_fabric_reglogin(vport);
3979 else
3980 lpfc_do_scr_ns_plogi(phba, vport);
3981 }
3982 mempool_free(pmb, phba->mbox_mem_pool);
3983 return;
3984}
3985
3986void
3987lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
3988 struct lpfc_nodelist *ndlp)
3989{
3990 LPFC_MBOXQ_t *mbox;
3991
3992 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3993 if (mbox) {
3994 lpfc_reg_vpi(phba, vport->vpi, vport->fc_myDID, mbox);
3995 mbox->vport = vport;
3996 mbox->context2 = lpfc_nlp_get(ndlp);
3997 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
3998 if (lpfc_sli_issue_mbox(phba, mbox,
3999 MBX_NOWAIT | MBX_STOP_IOCB)
4000 == MBX_NOT_FINISHED) {
4001 mempool_free(mbox, phba->mbox_mem_pool);
4002 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
4003
4004 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4005
4006 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
4007 "%d (%d):0253 Register VPI: Cannot send mbox\n",
4008 phba->brd_no, vport->vpi);
4009 }
4010 } else {
4011 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4012
4013 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
4014 "%d (%d):0254 Register VPI: no memory\n",
4015 phba->brd_no, vport->vpi);
4016
4017 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
4018 lpfc_nlp_put(ndlp);
4019 }
4020}
4021
4022static void
4023lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4024 struct lpfc_iocbq *rspiocb)
4025{
4026 struct lpfc_vport *vport = cmdiocb->vport;
4027 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4028 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
4029 struct lpfc_nodelist *np;
4030 struct lpfc_nodelist *next_np;
4031 IOCB_t *irsp = &rspiocb->iocb;
4032 struct lpfc_iocbq *piocb;
4033
4034 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
4035 "%d (%d):0123 FDISC completes. x%x/x%x prevDID: x%x\n",
4036 phba->brd_no, vport->vpi,
4037 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
4038
4039 /* Since all FDISCs are being single threaded, we
4040 * must reset the discovery timer for ALL vports
4041 * waiting to send FDISC when one completes.
4042 */
4043 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
4044 lpfc_set_disctmo(piocb->vport);
4045 }
4046
4047 if (irsp->ulpStatus) {
4048 /* Check for retry */
4049 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
4050 goto out;
4051
4052 /* FDISC failed */
4053 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
4054 "%d (%d):0124 FDISC failed. (%d/%d)\n",
4055 phba->brd_no, vport->vpi,
4056 irsp->ulpStatus, irsp->un.ulpWord[4]);
4057 if (vport->fc_vport->vport_state == FC_VPORT_INITIALIZING)
4058 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4059
4060 lpfc_nlp_put(ndlp);
4061 /* giving up on FDISC. Cancel discovery timer */
4062 lpfc_can_disctmo(vport);
4063 } else {
4064 spin_lock_irq(shost->host_lock);
4065 vport->fc_flag |= FC_FABRIC;
4066 if (vport->phba->fc_topology == TOPOLOGY_LOOP)
4067 vport->fc_flag |= FC_PUBLIC_LOOP;
4068 spin_unlock_irq(shost->host_lock);
4069
4070 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
4071 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
4072 if ((vport->fc_prevDID != vport->fc_myDID) &&
4073 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
4074 /* If our NportID changed, we need to ensure all
4075 * remaining NPORTs get unreg_login'ed so we can
4076 * issue unreg_vpi.
4077 */
4078 list_for_each_entry_safe(np, next_np,
4079 &vport->fc_nodes, nlp_listp) {
4080 if (np->nlp_state != NLP_STE_NPR_NODE
4081 || !(np->nlp_flag & NLP_NPR_ADISC))
4082 continue;
4083 spin_lock_irq(shost->host_lock);
4084 np->nlp_flag &= ~NLP_NPR_ADISC;
4085 spin_unlock_irq(shost->host_lock);
4086 lpfc_unreg_rpi(vport, np);
4087 }
4088 lpfc_mbx_unreg_vpi(vport);
4089 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
4090 }
4091
4092 if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
4093 lpfc_register_new_vport(phba, vport, ndlp);
4094 else
4095 lpfc_do_scr_ns_plogi(phba, vport);
4096
4097 lpfc_nlp_put(ndlp); /* Free Fabric ndlp for vports */
4098 }
4099
4100out:
4101 lpfc_els_free_iocb(phba, cmdiocb);
4102}
4103
4104int
4105lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4106 uint8_t retry)
4107{
4108 struct lpfc_hba *phba = vport->phba;
4109 IOCB_t *icmd;
4110 struct lpfc_iocbq *elsiocb;
4111 struct serv_parm *sp;
4112 uint8_t *pcmd;
4113 uint16_t cmdsize;
4114 int did = ndlp->nlp_DID;
4115 int rc;
4116 int new_ndlp = 0;
4117
4118 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
4119 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
4120 ELS_CMD_FDISC);
4121 if (!elsiocb) {
4122 if (new_ndlp)
4123 mempool_free(ndlp, phba->nlp_mem_pool);
4124 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4125
4126 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
4127 "%d (%d):0255 Issue FDISC: no IOCB\n",
4128 phba->brd_no, vport->vpi);
4129 return 1;
4130 }
4131
4132 icmd = &elsiocb->iocb;
4133 icmd->un.elsreq64.myID = 0;
4134 icmd->un.elsreq64.fl = 1;
4135
4136 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
4137 icmd->ulpCt_h = 1;
4138 icmd->ulpCt_l = 0;
4139
4140 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4141 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
4142 pcmd += sizeof(uint32_t); /* CSP Word 1 */
4143 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
4144 sp = (struct serv_parm *) pcmd;
4145 /* Setup CSPs accordingly for Fabric */
4146 sp->cmn.e_d_tov = 0;
4147 sp->cmn.w2.r_a_tov = 0;
4148 sp->cls1.classValid = 0;
4149 sp->cls2.seqDelivery = 1;
4150 sp->cls3.seqDelivery = 1;
4151
4152 pcmd += sizeof(uint32_t); /* CSP Word 2 */
4153 pcmd += sizeof(uint32_t); /* CSP Word 3 */
4154 pcmd += sizeof(uint32_t); /* CSP Word 4 */
4155 pcmd += sizeof(uint32_t); /* Port Name */
4156 memcpy(pcmd, &vport->fc_portname, 8);
4157 pcmd += sizeof(uint32_t); /* Node Name */
4158 pcmd += sizeof(uint32_t); /* Node Name */
4159 memcpy(pcmd, &vport->fc_nodename, 8);
4160
4161 lpfc_set_disctmo(vport);
4162
4163 phba->fc_stat.elsXmitFDISC++;
4164 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
4165
4166 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
4167 if (rc == IOCB_ERROR) {
4168 lpfc_els_free_iocb(phba, elsiocb);
4169 if (new_ndlp)
4170 mempool_free(ndlp, phba->nlp_mem_pool);
4171 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4172
4173 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
4174 "%d (%d):0256 Issue FDISC: Cannot send IOCB\n",
4175 phba->brd_no, vport->vpi);
4176
4177 return 1;
4178 }
4179 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
4180 vport->port_state = LPFC_FDISC;
4181 return 0;
4182}
4183
4184static void
4185lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4186 struct lpfc_iocbq *rspiocb)
4187{
4188 struct lpfc_vport *vport = cmdiocb->vport;
4189
4190 lpfc_els_free_iocb(phba, cmdiocb);
4191 vport->unreg_vpi_cmpl = VPORT_ERROR;
4192}
4193
4194int
4195lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4196{
4197 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4198 struct lpfc_hba *phba = vport->phba;
4199 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4200 IOCB_t *icmd;
4201 struct lpfc_iocbq *elsiocb;
4202 uint8_t *pcmd;
4203 uint16_t cmdsize;
4204
4205 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
4206 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
4207 ELS_CMD_LOGO);
4208 if (!elsiocb)
4209 return 1;
4210
4211 icmd = &elsiocb->iocb;
4212 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4213 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
4214 pcmd += sizeof(uint32_t);
4215
4216 /* Fill in LOGO payload */
4217 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
4218 pcmd += sizeof(uint32_t);
4219 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
4220
4221 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
4222 spin_lock_irq(shost->host_lock);
4223 ndlp->nlp_flag |= NLP_LOGO_SND;
4224 spin_unlock_irq(shost->host_lock);
4225 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
4226 spin_lock_irq(shost->host_lock);
4227 ndlp->nlp_flag &= ~NLP_LOGO_SND;
4228 spin_unlock_irq(shost->host_lock);
4229 lpfc_els_free_iocb(phba, elsiocb);
4230 return 1;
4231 }
4232 return 0;
4233}
4234
4235void
4236lpfc_fabric_block_timeout(unsigned long ptr)
4237{
4238 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
4239 unsigned long iflags;
4240 uint32_t tmo_posted;
4241 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
4242 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
4243 if (!tmo_posted)
4244 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
4245 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
4246
4247 if (!tmo_posted) {
4248 spin_lock_irqsave(&phba->hbalock, iflags);
4249 if (phba->work_wait)
4250 lpfc_worker_wake_up(phba);
4251 spin_unlock_irqrestore(&phba->hbalock, iflags);
4252 }
4253}
4254
4255static void
4256lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
4257{
4258 struct lpfc_iocbq *iocb;
4259 unsigned long iflags;
4260 int ret;
4261 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4262 IOCB_t *cmd;
4263
4264repeat:
4265 iocb = NULL;
4266 spin_lock_irqsave(&phba->hbalock, iflags);
4267 /* Post any pending iocb to the SLI layer */
4268 if (atomic_read(&phba->fabric_iocb_count) == 0) {
4269 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
4270 list);
4271 if (iocb)
4272 atomic_inc(&phba->fabric_iocb_count);
4273 }
4274 spin_unlock_irqrestore(&phba->hbalock, iflags);
4275 if (iocb) {
4276 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
4277 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
4278 iocb->iocb_flag |= LPFC_IO_FABRIC;
4279
4280 ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
4281
4282 if (ret == IOCB_ERROR) {
4283 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
4284 iocb->fabric_iocb_cmpl = NULL;
4285 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
4286 cmd = &iocb->iocb;
4287 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4288 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4289 iocb->iocb_cmpl(phba, iocb, iocb);
4290
4291 atomic_dec(&phba->fabric_iocb_count);
4292 goto repeat;
4293 }
4294 }
4295
4296 return;
4297}
4298
4299void
4300lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
4301{
4302 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
4303
4304 lpfc_resume_fabric_iocbs(phba);
4305 return;
4306}
4307
4308static void
4309lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
4310{
4311 int blocked;
4312
4313 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
4314 /* Start a timer to unblock fabric
4315 * iocbs after 100ms
4316 */
4317 if (!blocked)
4318 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
4319
4320 return;
4321}
4322
4323static void
4324lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4325 struct lpfc_iocbq *rspiocb)
4326{
4327 struct ls_rjt stat;
4328
4329 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
4330 BUG();
4331
4332 switch (rspiocb->iocb.ulpStatus) {
4333 case IOSTAT_NPORT_RJT:
4334 case IOSTAT_FABRIC_RJT:
4335 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
4336 lpfc_block_fabric_iocbs(phba);
3588 } 4337 }
4338 break;
4339
4340 case IOSTAT_NPORT_BSY:
4341 case IOSTAT_FABRIC_BSY:
4342 lpfc_block_fabric_iocbs(phba);
4343 break;
4344
4345 case IOSTAT_LS_RJT:
4346 stat.un.lsRjtError =
4347 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
4348 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
4349 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
4350 lpfc_block_fabric_iocbs(phba);
4351 break;
4352 }
4353
4354 if (atomic_read(&phba->fabric_iocb_count) == 0)
4355 BUG();
4356
4357 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
4358 cmdiocb->fabric_iocb_cmpl = NULL;
4359 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
4360 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
4361
4362 atomic_dec(&phba->fabric_iocb_count);
4363 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
4364 /* Post any pending iocbs to HBA */
4365 lpfc_resume_fabric_iocbs(phba);
4366 }
4367}
4368
4369int
4370lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
4371{
4372 unsigned long iflags;
4373 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4374 int ready;
4375 int ret;
4376
4377 if (atomic_read(&phba->fabric_iocb_count) > 1)
4378 BUG();
4379
4380 spin_lock_irqsave(&phba->hbalock, iflags);
4381 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
4382 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
4383
4384 spin_unlock_irqrestore(&phba->hbalock, iflags);
4385 if (ready) {
4386 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
4387 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
4388 iocb->iocb_flag |= LPFC_IO_FABRIC;
4389
4390 atomic_inc(&phba->fabric_iocb_count);
4391 ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
4392
4393 if (ret == IOCB_ERROR) {
4394 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
4395 iocb->fabric_iocb_cmpl = NULL;
4396 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
4397 atomic_dec(&phba->fabric_iocb_count);
4398 }
4399 } else {
4400 spin_lock_irqsave(&phba->hbalock, iflags);
4401 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
4402 spin_unlock_irqrestore(&phba->hbalock, iflags);
4403 ret = IOCB_SUCCESS;
4404 }
4405 return ret;
4406}
4407
4408
4409void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
4410{
4411 LIST_HEAD(completions);
4412 struct lpfc_hba *phba = vport->phba;
4413 struct lpfc_iocbq *tmp_iocb, *piocb;
4414 IOCB_t *cmd;
4415
4416 spin_lock_irq(&phba->hbalock);
4417 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
4418 list) {
4419
4420 if (piocb->vport != vport)
4421 continue;
4422
4423 list_move_tail(&piocb->list, &completions);
4424 }
4425 spin_unlock_irq(&phba->hbalock);
4426
4427 while (!list_empty(&completions)) {
4428 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4429 list_del_init(&piocb->list);
4430
4431 cmd = &piocb->iocb;
4432 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4433 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4434 (piocb->iocb_cmpl) (phba, piocb, piocb);
4435 }
4436}
4437
4438void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
4439{
4440 LIST_HEAD(completions);
4441 struct lpfc_hba *phba = ndlp->vport->phba;
4442 struct lpfc_iocbq *tmp_iocb, *piocb;
4443 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4444 IOCB_t *cmd;
4445
4446 spin_lock_irq(&phba->hbalock);
4447 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
4448 list) {
4449 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
4450
4451 list_move_tail(&piocb->list, &completions);
3589 } 4452 }
3590 } 4453 }
4454 spin_unlock_irq(&phba->hbalock);
4455
4456 while (!list_empty(&completions)) {
4457 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4458 list_del_init(&piocb->list);
4459
4460 cmd = &piocb->iocb;
4461 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4462 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4463 (piocb->iocb_cmpl) (phba, piocb, piocb);
4464 }
3591} 4465}
4466
4467void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
4468{
4469 LIST_HEAD(completions);
4470 struct lpfc_iocbq *piocb;
4471 IOCB_t *cmd;
4472
4473 spin_lock_irq(&phba->hbalock);
4474 list_splice_init(&phba->fabric_iocb_list, &completions);
4475 spin_unlock_irq(&phba->hbalock);
4476
4477 while (!list_empty(&completions)) {
4478 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4479 list_del_init(&piocb->list);
4480
4481 cmd = &piocb->iocb;
4482 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4483 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4484 (piocb->iocb_cmpl) (phba, piocb, piocb);
4485 }
4486}
4487
4488
4489void lpfc_fabric_abort_flogi(struct lpfc_hba *phba)
4490{
4491 LIST_HEAD(completions);
4492 struct lpfc_iocbq *tmp_iocb, *piocb;
4493 IOCB_t *cmd;
4494 struct lpfc_nodelist *ndlp;
4495
4496 spin_lock_irq(&phba->hbalock);
4497 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
4498 list) {
4499
4500 cmd = &piocb->iocb;
4501 ndlp = (struct lpfc_nodelist *) piocb->context1;
4502 if (cmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
4503 ndlp != NULL &&
4504 ndlp->nlp_DID == Fabric_DID)
4505 list_move_tail(&piocb->list, &completions);
4506 }
4507 spin_unlock_irq(&phba->hbalock);
4508
4509 while (!list_empty(&completions)) {
4510 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4511 list_del_init(&piocb->list);
4512
4513 cmd = &piocb->iocb;
4514 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4515 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4516 (piocb->iocb_cmpl) (phba, piocb, piocb);
4517 }
4518}
4519
4520