Commit | Line | Data |
---|---|---|
128bddac | 1 | /******************************************************************* |
dea3101e | 2 | * This file is part of the Emulex Linux Device Driver for * |
c44ce173 | 3 | * Fibre Channel Host Bus Adapters. * |
ea4044e4 | 4 | * Copyright (C) 2017-2024 Broadcom. All Rights Reserved. The term * |
4ae2ebde | 5 | * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. * |
50611577 | 6 | * Copyright (C) 2004-2016 Emulex. All rights reserved. * |
c44ce173 | 7 | * EMULEX and SLI are trademarks of Emulex. * |
d080abe0 | 8 | * www.broadcom.com * |
c44ce173 | 9 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
dea3101e | 10 | * * |
11 | * This program is free software; you can redistribute it and/or * | |
c44ce173 JSEC |
12 | * modify it under the terms of version 2 of the GNU General * |
13 | * Public License as published by the Free Software Foundation. * | |
14 | * This program is distributed in the hope that it will be useful. * | |
15 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * | |
16 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * | |
17 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * | |
18 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * | |
19 | * TO BE LEGALLY INVALID. See the GNU General Public License for * | |
20 | * more details, a copy of which can be found in the file COPYING * | |
21 | * included with this package. * | |
dea3101e | 22 | *******************************************************************/ |
23 | ||
dea3101e | 24 | #include <linux/blkdev.h> |
25 | #include <linux/pci.h> | |
5a0e3ad6 | 26 | #include <linux/slab.h> |
dea3101e | 27 | #include <linux/interrupt.h> |
28 | ||
91886523 | 29 | #include <scsi/scsi.h> |
dea3101e | 30 | #include <scsi/scsi_device.h> |
31 | #include <scsi/scsi_host.h> | |
32 | #include <scsi/scsi_transport_fc.h> | |
a0f2d3ef JS |
33 | #include <scsi/fc/fc_fs.h> |
34 | ||
da0436e9 | 35 | #include "lpfc_hw4.h" |
dea3101e | 36 | #include "lpfc_hw.h" |
37 | #include "lpfc_sli.h" | |
da0436e9 | 38 | #include "lpfc_sli4.h" |
ea2151b4 | 39 | #include "lpfc_nl.h" |
dea3101e | 40 | #include "lpfc_disc.h" |
dea3101e | 41 | #include "lpfc.h" |
a0f2d3ef JS |
42 | #include "lpfc_scsi.h" |
43 | #include "lpfc_nvme.h" | |
dea3101e | 44 | #include "lpfc_logmsg.h" |
45 | #include "lpfc_crtn.h" | |
92d7f7b0 | 46 | #include "lpfc_vport.h" |
858c9f6c | 47 | #include "lpfc_debugfs.h" |
dea3101e | 48 | |
49 | ||
bf81e9cd JT |
50 | /* Called to clear RSCN discovery flags when driver is unloading. */ |
51 | static bool | |
52 | lpfc_check_unload_and_clr_rscn(unsigned long *fc_flag) | |
53 | { | |
54 | /* If unloading, then clear the FC_RSCN_DEFERRED flag */ | |
55 | if (test_bit(FC_UNLOADING, fc_flag)) { | |
56 | clear_bit(FC_RSCN_DEFERRED, fc_flag); | |
57 | return false; | |
58 | } | |
59 | return test_bit(FC_RSCN_DEFERRED, fc_flag); | |
60 | } | |
61 | ||
dea3101e | 62 | /* Called to verify a rcv'ed ADISC was intended for us. */ |
63 | static int | |
2e0fef85 JS |
64 | lpfc_check_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
65 | struct lpfc_name *nn, struct lpfc_name *pn) | |
dea3101e | 66 | { |
6b5151fd JS |
67 | /* First, we MUST have a RPI registered */ |
68 | if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED)) | |
69 | return 0; | |
70 | ||
dea3101e | 71 | /* Compare the ADISC rsp WWNN / WWPN matches our internal node |
72 | * table entry for that node. | |
73 | */ | |
2e0fef85 | 74 | if (memcmp(nn, &ndlp->nlp_nodename, sizeof (struct lpfc_name))) |
c9f8735b | 75 | return 0; |
dea3101e | 76 | |
2e0fef85 | 77 | if (memcmp(pn, &ndlp->nlp_portname, sizeof (struct lpfc_name))) |
c9f8735b | 78 | return 0; |
dea3101e | 79 | |
80 | /* we match, return success */ | |
c9f8735b | 81 | return 1; |
dea3101e | 82 | } |
83 | ||
dea3101e | 84 | int |
2e0fef85 | 85 | lpfc_check_sparm(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
341af102 | 86 | struct serv_parm *sp, uint32_t class, int flogi) |
dea3101e | 87 | { |
2e0fef85 | 88 | volatile struct serv_parm *hsp = &vport->fc_sparam; |
2fb70f79 JSEC |
89 | uint16_t hsp_value, ssp_value = 0; |
90 | ||
91 | /* | |
92 | * The receive data field size and buffer-to-buffer receive data field | |
93 | * size entries are 16 bits but are represented as two 8-bit fields in | |
94 | * the driver data structure to account for rsvd bits and other control | |
95 | * bits. Reconstruct and compare the fields as a 16-bit values before | |
96 | * correcting the byte values. | |
97 | */ | |
dea3101e | 98 | if (sp->cls1.classValid) { |
341af102 JS |
99 | if (!flogi) { |
100 | hsp_value = ((hsp->cls1.rcvDataSizeMsb << 8) | | |
101 | hsp->cls1.rcvDataSizeLsb); | |
102 | ssp_value = ((sp->cls1.rcvDataSizeMsb << 8) | | |
103 | sp->cls1.rcvDataSizeLsb); | |
104 | if (!ssp_value) | |
105 | goto bad_service_param; | |
106 | if (ssp_value > hsp_value) { | |
107 | sp->cls1.rcvDataSizeLsb = | |
108 | hsp->cls1.rcvDataSizeLsb; | |
109 | sp->cls1.rcvDataSizeMsb = | |
110 | hsp->cls1.rcvDataSizeMsb; | |
111 | } | |
2fb70f79 | 112 | } |
341af102 | 113 | } else if (class == CLASS1) |
92d7f7b0 | 114 | goto bad_service_param; |
dea3101e | 115 | if (sp->cls2.classValid) { |
341af102 JS |
116 | if (!flogi) { |
117 | hsp_value = ((hsp->cls2.rcvDataSizeMsb << 8) | | |
118 | hsp->cls2.rcvDataSizeLsb); | |
119 | ssp_value = ((sp->cls2.rcvDataSizeMsb << 8) | | |
120 | sp->cls2.rcvDataSizeLsb); | |
121 | if (!ssp_value) | |
122 | goto bad_service_param; | |
123 | if (ssp_value > hsp_value) { | |
124 | sp->cls2.rcvDataSizeLsb = | |
125 | hsp->cls2.rcvDataSizeLsb; | |
126 | sp->cls2.rcvDataSizeMsb = | |
127 | hsp->cls2.rcvDataSizeMsb; | |
128 | } | |
2fb70f79 | 129 | } |
341af102 | 130 | } else if (class == CLASS2) |
92d7f7b0 | 131 | goto bad_service_param; |
dea3101e | 132 | if (sp->cls3.classValid) { |
341af102 JS |
133 | if (!flogi) { |
134 | hsp_value = ((hsp->cls3.rcvDataSizeMsb << 8) | | |
135 | hsp->cls3.rcvDataSizeLsb); | |
136 | ssp_value = ((sp->cls3.rcvDataSizeMsb << 8) | | |
137 | sp->cls3.rcvDataSizeLsb); | |
138 | if (!ssp_value) | |
139 | goto bad_service_param; | |
140 | if (ssp_value > hsp_value) { | |
141 | sp->cls3.rcvDataSizeLsb = | |
142 | hsp->cls3.rcvDataSizeLsb; | |
143 | sp->cls3.rcvDataSizeMsb = | |
144 | hsp->cls3.rcvDataSizeMsb; | |
145 | } | |
2fb70f79 | 146 | } |
341af102 | 147 | } else if (class == CLASS3) |
92d7f7b0 | 148 | goto bad_service_param; |
dea3101e | 149 | |
2fb70f79 JSEC |
150 | /* |
151 | * Preserve the upper four bits of the MSB from the PLOGI response. | |
152 | * These bits contain the Buffer-to-Buffer State Change Number | |
153 | * from the target and need to be passed to the FW. | |
154 | */ | |
155 | hsp_value = (hsp->cmn.bbRcvSizeMsb << 8) | hsp->cmn.bbRcvSizeLsb; | |
156 | ssp_value = (sp->cmn.bbRcvSizeMsb << 8) | sp->cmn.bbRcvSizeLsb; | |
157 | if (ssp_value > hsp_value) { | |
dea3101e | 158 | sp->cmn.bbRcvSizeLsb = hsp->cmn.bbRcvSizeLsb; |
2fb70f79 JSEC |
159 | sp->cmn.bbRcvSizeMsb = (sp->cmn.bbRcvSizeMsb & 0xF0) | |
160 | (hsp->cmn.bbRcvSizeMsb & 0x0F); | |
161 | } | |
dea3101e | 162 | |
dea3101e | 163 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name)); |
164 | memcpy(&ndlp->nlp_portname, &sp->portName, sizeof (struct lpfc_name)); | |
2fb70f79 | 165 | return 1; |
92d7f7b0 | 166 | bad_service_param: |
372c187b | 167 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
e8b62011 JS |
168 | "0207 Device %x " |
169 | "(%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x) sent " | |
170 | "invalid service parameters. Ignoring device.\n", | |
171 | ndlp->nlp_DID, | |
172 | sp->nodeName.u.wwn[0], sp->nodeName.u.wwn[1], | |
173 | sp->nodeName.u.wwn[2], sp->nodeName.u.wwn[3], | |
174 | sp->nodeName.u.wwn[4], sp->nodeName.u.wwn[5], | |
175 | sp->nodeName.u.wwn[6], sp->nodeName.u.wwn[7]); | |
92d7f7b0 | 176 | return 0; |
dea3101e | 177 | } |
178 | ||
179 | static void * | |
2e0fef85 | 180 | lpfc_check_elscmpl_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
92d7f7b0 | 181 | struct lpfc_iocbq *rspiocb) |
dea3101e | 182 | { |
183 | struct lpfc_dmabuf *pcmd, *prsp; | |
184 | uint32_t *lp; | |
185 | void *ptr = NULL; | |
2d1928c5 | 186 | u32 ulp_status = get_job_ulpstatus(phba, rspiocb); |
dea3101e | 187 | |
d51cf5bd | 188 | pcmd = cmdiocb->cmd_dmabuf; |
dea3101e | 189 | |
d51cf5bd | 190 | /* For lpfc_els_abort, cmd_dmabuf could be zero'ed to delay |
dea3101e | 191 | * freeing associated memory till after ABTS completes. |
192 | */ | |
193 | if (pcmd) { | |
194 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, | |
195 | list); | |
196 | if (prsp) { | |
197 | lp = (uint32_t *) prsp->virt; | |
198 | ptr = (void *)((uint8_t *)lp + sizeof(uint32_t)); | |
199 | } | |
2fe165b6 | 200 | } else { |
2d1928c5 JS |
201 | /* Force ulp_status error since we are returning NULL ptr */ |
202 | if (!(ulp_status)) { | |
203 | if (phba->sli_rev == LPFC_SLI_REV4) { | |
204 | bf_set(lpfc_wcqe_c_status, &rspiocb->wcqe_cmpl, | |
205 | IOSTAT_LOCAL_REJECT); | |
206 | rspiocb->wcqe_cmpl.parameter = IOERR_SLI_ABORTED; | |
207 | } else { | |
208 | rspiocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; | |
209 | rspiocb->iocb.un.ulpWord[4] = IOERR_SLI_ABORTED; | |
210 | } | |
dea3101e | 211 | } |
212 | ptr = NULL; | |
213 | } | |
c9f8735b | 214 | return ptr; |
dea3101e | 215 | } |
216 | ||
217 | ||
2a9bf3d0 | 218 | |
dea3101e | 219 | /* |
220 | * Free resources / clean up outstanding I/Os | |
221 | * associated with a LPFC_NODELIST entry. This | |
222 | * routine effectively results in a "software abort". | |
223 | */ | |
7c9fdfb7 | 224 | void |
2e0fef85 | 225 | lpfc_els_abort(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
dea3101e | 226 | { |
2a9bf3d0 | 227 | LIST_HEAD(abort_list); |
bf81e9cd | 228 | LIST_HEAD(drv_cmpl_list); |
895427bd | 229 | struct lpfc_sli_ring *pring; |
dea3101e | 230 | struct lpfc_iocbq *iocb, *next_iocb; |
bf81e9cd | 231 | int retval = 0; |
dea3101e | 232 | |
895427bd JS |
233 | pring = lpfc_phba_elsring(phba); |
234 | ||
7c9fdfb7 | 235 | /* In case of error recovery path, we might have a NULL pring here */ |
1234a6d5 | 236 | if (unlikely(!pring)) |
7c9fdfb7 GP |
237 | return; |
238 | ||
dea3101e | 239 | /* Abort outstanding I/O on NPort <nlp_DID> */ |
e8b62011 | 240 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_DISCOVERY, |
2a9bf3d0 | 241 | "2819 Abort outstanding I/O on NPort x%x " |
e8b62011 JS |
242 | "Data: x%x x%x x%x\n", |
243 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, | |
244 | ndlp->nlp_rpi); | |
0976e1a6 | 245 | /* Clean up all fabric IOs first.*/ |
92d7f7b0 | 246 | lpfc_fabric_abort_nport(ndlp); |
dea3101e | 247 | |
0976e1a6 JS |
248 | /* |
249 | * Lock the ELS ring txcmplq for SLI3/SLI4 and build a local list | |
250 | * of all ELS IOs that need an ABTS. The IOs need to stay on the | |
251 | * txcmplq so that the abort operation completes them successfully. | |
252 | */ | |
2e0fef85 | 253 | spin_lock_irq(&phba->hbalock); |
0976e1a6 JS |
254 | if (phba->sli_rev == LPFC_SLI_REV4) |
255 | spin_lock(&pring->ring_lock); | |
256 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { | |
257 | /* Add to abort_list on on NDLP match. */ | |
2a9bf3d0 JS |
258 | if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) |
259 | list_add_tail(&iocb->dlist, &abort_list); | |
07951076 | 260 | } |
0976e1a6 JS |
261 | if (phba->sli_rev == LPFC_SLI_REV4) |
262 | spin_unlock(&pring->ring_lock); | |
2e0fef85 | 263 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 264 | |
0976e1a6 | 265 | /* Abort the targeted IOs and remove them from the abort list. */ |
2a9bf3d0 | 266 | list_for_each_entry_safe(iocb, next_iocb, &abort_list, dlist) { |
bf81e9cd JT |
267 | spin_lock_irq(&phba->hbalock); |
268 | list_del_init(&iocb->dlist); | |
269 | retval = lpfc_sli_issue_abort_iotag(phba, pring, iocb, NULL); | |
270 | spin_unlock_irq(&phba->hbalock); | |
271 | ||
272 | if (retval && test_bit(FC_UNLOADING, &phba->pport->load_flag)) { | |
273 | list_del_init(&iocb->list); | |
274 | list_add_tail(&iocb->list, &drv_cmpl_list); | |
275 | } | |
2a9bf3d0 | 276 | } |
bf81e9cd JT |
277 | |
278 | lpfc_sli_cancel_iocbs(phba, &drv_cmpl_list, IOSTAT_LOCAL_REJECT, | |
279 | IOERR_SLI_ABORTED); | |
280 | ||
a22d73b6 JS |
281 | /* Make sure HBA is alive */ |
282 | lpfc_issue_hb_tmo(phba); | |
2a9bf3d0 | 283 | |
0976e1a6 JS |
284 | INIT_LIST_HEAD(&abort_list); |
285 | ||
286 | /* Now process the txq */ | |
287 | spin_lock_irq(&phba->hbalock); | |
288 | if (phba->sli_rev == LPFC_SLI_REV4) | |
289 | spin_lock(&pring->ring_lock); | |
290 | ||
291 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { | |
292 | /* Check to see if iocb matches the nport we are looking for */ | |
293 | if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) { | |
294 | list_del_init(&iocb->list); | |
295 | list_add_tail(&iocb->list, &abort_list); | |
296 | } | |
297 | } | |
298 | ||
299 | if (phba->sli_rev == LPFC_SLI_REV4) | |
300 | spin_unlock(&pring->ring_lock); | |
301 | spin_unlock_irq(&phba->hbalock); | |
302 | ||
a257bf90 | 303 | /* Cancel all the IOCBs from the completions list */ |
0976e1a6 JS |
304 | lpfc_sli_cancel_iocbs(phba, &abort_list, |
305 | IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED); | |
2534ba75 | 306 | |
0d2b6b83 | 307 | lpfc_cancel_retry_delay_tmo(phba->pport, ndlp); |
dea3101e | 308 | } |
309 | ||
14375305 | 310 | /* lpfc_defer_plogi_acc - Issue PLOGI ACC after reg_login completes |
359e10f0 | 311 | * @phba: pointer to lpfc hba data structure. |
14375305 | 312 | * @login_mbox: pointer to REG_RPI mailbox object |
359e10f0 | 313 | * |
14375305 | 314 | * The ACC for a rcv'ed PLOGI is deferred until AFTER the REG_RPI completes |
359e10f0 | 315 | */ |
f7cb0d09 | 316 | static void |
14375305 | 317 | lpfc_defer_plogi_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *login_mbox) |
359e10f0 | 318 | { |
359e10f0 JS |
319 | struct lpfc_iocbq *save_iocb; |
320 | struct lpfc_nodelist *ndlp; | |
14375305 JS |
321 | MAILBOX_t *mb = &login_mbox->u.mb; |
322 | ||
359e10f0 JS |
323 | int rc; |
324 | ||
14375305 | 325 | ndlp = login_mbox->ctx_ndlp; |
85d77f91 | 326 | save_iocb = login_mbox->ctx_u.save_iocb; |
359e10f0 | 327 | |
14375305 JS |
328 | if (mb->mbxStatus == MBX_SUCCESS) { |
329 | /* Now that REG_RPI completed successfully, | |
330 | * we can now proceed with sending the PLOGI ACC. | |
331 | */ | |
332 | rc = lpfc_els_rsp_acc(login_mbox->vport, ELS_CMD_PLOGI, | |
333 | save_iocb, ndlp, NULL); | |
334 | if (rc) { | |
335 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, | |
336 | "4576 PLOGI ACC fails pt2pt discovery: " | |
337 | "DID %x Data: %x\n", ndlp->nlp_DID, rc); | |
338 | } | |
359e10f0 JS |
339 | } |
340 | ||
14375305 JS |
341 | /* Now process the REG_RPI cmpl */ |
342 | lpfc_mbx_cmpl_reg_login(phba, login_mbox); | |
343 | ndlp->nlp_flag &= ~NLP_ACC_REGLOGIN; | |
be0709e4 JS |
344 | kfree(save_iocb); |
345 | } | |
346 | ||
dea3101e | 347 | static int |
2e0fef85 | 348 | lpfc_rcv_plogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
92d7f7b0 | 349 | struct lpfc_iocbq *cmdiocb) |
dea3101e | 350 | { |
2e0fef85 | 351 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 352 | struct lpfc_dmabuf *pcmd; |
ed4afe74 | 353 | uint64_t nlp_portwwn = 0; |
dea3101e | 354 | uint32_t *lp; |
2d1928c5 | 355 | union lpfc_wqe128 *wqe; |
dea3101e | 356 | IOCB_t *icmd; |
357 | struct serv_parm *sp; | |
d6de08cc | 358 | uint32_t ed_tov; |
359e10f0 JS |
359 | LPFC_MBOXQ_t *link_mbox; |
360 | LPFC_MBOXQ_t *login_mbox; | |
361 | struct lpfc_iocbq *save_iocb; | |
dea3101e | 362 | struct ls_rjt stat; |
8c258641 | 363 | uint32_t vid, flag; |
14375305 | 364 | int rc; |
2d1928c5 | 365 | u32 remote_did; |
dea3101e | 366 | |
367 | memset(&stat, 0, sizeof (struct ls_rjt)); | |
d51cf5bd | 368 | pcmd = cmdiocb->cmd_dmabuf; |
dea3101e | 369 | lp = (uint32_t *) pcmd->virt; |
370 | sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t)); | |
a8adb832 | 371 | if (wwn_to_u64(sp->portName.u.wwn) == 0) { |
372c187b | 372 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
3bfab8a0 | 373 | "0140 PLOGI Reject: invalid pname\n"); |
a8adb832 JS |
374 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
375 | stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_PNAME; | |
376 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, | |
377 | NULL); | |
378 | return 0; | |
379 | } | |
380 | if (wwn_to_u64(sp->nodeName.u.wwn) == 0) { | |
372c187b | 381 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
3bfab8a0 | 382 | "0141 PLOGI Reject: invalid nname\n"); |
a8adb832 JS |
383 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
384 | stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_NNAME; | |
385 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, | |
386 | NULL); | |
387 | return 0; | |
388 | } | |
ed4afe74 JS |
389 | |
390 | nlp_portwwn = wwn_to_u64(ndlp->nlp_portname.u.wwn); | |
341af102 | 391 | if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0) == 0)) { |
dea3101e | 392 | /* Reject this request because invalid parameters */ |
393 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; | |
394 | stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS; | |
858c9f6c JS |
395 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
396 | NULL); | |
c9f8735b | 397 | return 0; |
dea3101e | 398 | } |
2d1928c5 JS |
399 | |
400 | if (phba->sli_rev == LPFC_SLI_REV4) | |
401 | wqe = &cmdiocb->wqe; | |
402 | else | |
403 | icmd = &cmdiocb->iocb; | |
dea3101e | 404 | |
405 | /* PLOGI chkparm OK */ | |
e8b62011 | 406 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
e74c03c8 | 407 | "0114 PLOGI chkparm OK Data: x%x x%x x%x " |
a645b8c1 | 408 | "x%x x%x x%lx\n", |
e8b62011 | 409 | ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag, |
e74c03c8 JS |
410 | ndlp->nlp_rpi, vport->port_state, |
411 | vport->fc_flag); | |
dea3101e | 412 | |
3de2a653 | 413 | if (vport->cfg_fcp_class == 2 && sp->cls2.classValid) |
dea3101e | 414 | ndlp->nlp_fcp_info |= CLASS2; |
ed957684 | 415 | else |
dea3101e | 416 | ndlp->nlp_fcp_info |= CLASS3; |
2e0fef85 | 417 | |
dea3101e | 418 | ndlp->nlp_class_sup = 0; |
419 | if (sp->cls1.classValid) | |
420 | ndlp->nlp_class_sup |= FC_COS_CLASS1; | |
421 | if (sp->cls2.classValid) | |
422 | ndlp->nlp_class_sup |= FC_COS_CLASS2; | |
423 | if (sp->cls3.classValid) | |
424 | ndlp->nlp_class_sup |= FC_COS_CLASS3; | |
425 | if (sp->cls4.classValid) | |
426 | ndlp->nlp_class_sup |= FC_COS_CLASS4; | |
427 | ndlp->nlp_maxframe = | |
428 | ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb; | |
ed4afe74 | 429 | /* if already logged in, do implicit logout */ |
2fe165b6 | 430 | switch (ndlp->nlp_state) { |
dea3101e | 431 | case NLP_STE_NPR_NODE: |
432 | if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) | |
433 | break; | |
df561f66 | 434 | fallthrough; |
dea3101e | 435 | case NLP_STE_REG_LOGIN_ISSUE: |
436 | case NLP_STE_PRLI_ISSUE: | |
437 | case NLP_STE_UNMAPPED_NODE: | |
438 | case NLP_STE_MAPPED_NODE: | |
1c5b12f7 JS |
439 | /* For initiators, lpfc_plogi_confirm_nport skips fabric did. |
440 | * For target mode, execute implicit logo. | |
441 | * Fabric nodes go into NPR. | |
442 | */ | |
443 | if (!(ndlp->nlp_type & NLP_FABRIC) && | |
444 | !(phba->nvmet_support)) { | |
ecf041fe JS |
445 | /* Clear ndlp info, since follow up PRLI may have |
446 | * updated ndlp information | |
447 | */ | |
448 | ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR); | |
449 | ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR); | |
450 | ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE; | |
451 | ndlp->nlp_nvme_info &= ~NLP_NVME_NSLER; | |
452 | ndlp->nlp_flag &= ~NLP_FIRSTBURST; | |
453 | ||
ed4afe74 JS |
454 | lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, |
455 | ndlp, NULL); | |
456 | return 1; | |
457 | } | |
458 | if (nlp_portwwn != 0 && | |
459 | nlp_portwwn != wwn_to_u64(sp->portName.u.wwn)) | |
b76beac1 | 460 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
ed4afe74 JS |
461 | "0143 PLOGI recv'd from DID: x%x " |
462 | "WWPN changed: old %llx new %llx\n", | |
463 | ndlp->nlp_DID, | |
464 | (unsigned long long)nlp_portwwn, | |
465 | (unsigned long long) | |
466 | wwn_to_u64(sp->portName.u.wwn)); | |
467 | ||
4c2805aa JS |
468 | /* Notify transport of connectivity loss to trigger cleanup. */ |
469 | if (phba->nvmet_support && | |
470 | ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) | |
471 | lpfc_nvmet_invalidate_host(phba, ndlp); | |
472 | ||
ed4afe74 JS |
473 | ndlp->nlp_prev_state = ndlp->nlp_state; |
474 | /* rport needs to be unregistered first */ | |
475 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); | |
476 | break; | |
dea3101e | 477 | } |
478 | ||
9de416ac JS |
479 | ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR); |
480 | ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR); | |
481 | ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE; | |
ecf041fe | 482 | ndlp->nlp_nvme_info &= ~NLP_NVME_NSLER; |
9de416ac JS |
483 | ndlp->nlp_flag &= ~NLP_FIRSTBURST; |
484 | ||
359e10f0 JS |
485 | login_mbox = NULL; |
486 | link_mbox = NULL; | |
487 | save_iocb = NULL; | |
488 | ||
939723a4 | 489 | /* Check for Nport to NPort pt2pt protocol */ |
a645b8c1 JT |
490 | if (test_bit(FC_PT2PT, &vport->fc_flag) && |
491 | !test_bit(FC_PT2PT_PLOGI, &vport->fc_flag)) { | |
dea3101e | 492 | /* rcv'ed PLOGI decides what our NPortId will be */ |
2d1928c5 JS |
493 | if (phba->sli_rev == LPFC_SLI_REV4) { |
494 | vport->fc_myDID = bf_get(els_rsp64_sid, | |
495 | &cmdiocb->wqe.xmit_els_rsp); | |
496 | } else { | |
497 | vport->fc_myDID = icmd->un.rcvels.parmRo; | |
498 | } | |
d6de08cc | 499 | |
9dd83f75 JS |
500 | /* If there is an outstanding FLOGI, abort it now. |
501 | * The remote NPort is not going to ACC our FLOGI | |
502 | * if its already issuing a PLOGI for pt2pt mode. | |
503 | * This indicates our FLOGI was dropped; however, we | |
504 | * must have ACCed the remote NPorts FLOGI to us | |
505 | * to make it here. | |
506 | */ | |
e780c942 | 507 | if (test_bit(HBA_FLOGI_OUTSTANDING, &phba->hba_flag)) |
9dd83f75 JS |
508 | lpfc_els_abort_flogi(phba); |
509 | ||
d6de08cc JS |
510 | ed_tov = be32_to_cpu(sp->cmn.e_d_tov); |
511 | if (sp->cmn.edtovResolution) { | |
512 | /* E_D_TOV ticks are in nanoseconds */ | |
513 | ed_tov = (phba->fc_edtov + 999999) / 1000000; | |
dea3101e | 514 | } |
d6de08cc | 515 | |
939723a4 | 516 | /* |
d6de08cc JS |
517 | * For pt-to-pt, use the larger EDTOV |
518 | * RATOV = 2 * EDTOV | |
939723a4 | 519 | */ |
d6de08cc JS |
520 | if (ed_tov > phba->fc_edtov) |
521 | phba->fc_edtov = ed_tov; | |
522 | phba->fc_ratov = (2 * phba->fc_edtov) / 1000; | |
523 | ||
524 | memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); | |
525 | ||
14375305 JS |
526 | /* Issue CONFIG_LINK for SLI3 or REG_VFI for SLI4, |
527 | * to account for updated TOV's / parameters | |
528 | */ | |
939723a4 JS |
529 | if (phba->sli_rev == LPFC_SLI_REV4) |
530 | lpfc_issue_reg_vfi(vport); | |
d6de08cc | 531 | else { |
359e10f0 JS |
532 | link_mbox = mempool_alloc(phba->mbox_mem_pool, |
533 | GFP_KERNEL); | |
534 | if (!link_mbox) | |
d6de08cc | 535 | goto out; |
359e10f0 | 536 | lpfc_config_link(phba, link_mbox); |
14375305 | 537 | link_mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
359e10f0 | 538 | link_mbox->vport = vport; |
ba3d58a1 JS |
539 | |
540 | /* The default completion handling for CONFIG_LINK | |
541 | * does not require the ndlp so no reference is needed. | |
542 | */ | |
359e10f0 JS |
543 | link_mbox->ctx_ndlp = ndlp; |
544 | ||
14375305 JS |
545 | rc = lpfc_sli_issue_mbox(phba, link_mbox, MBX_NOWAIT); |
546 | if (rc == MBX_NOT_FINISHED) { | |
547 | mempool_free(link_mbox, phba->mbox_mem_pool); | |
d6de08cc | 548 | goto out; |
14375305 | 549 | } |
d6de08cc | 550 | } |
dea3101e | 551 | |
2e0fef85 | 552 | lpfc_can_disctmo(vport); |
dea3101e | 553 | } |
d6de08cc | 554 | |
8c258641 JS |
555 | ndlp->nlp_flag &= ~NLP_SUPPRESS_RSP; |
556 | if ((phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) && | |
557 | sp->cmn.valid_vendor_ver_level) { | |
558 | vid = be32_to_cpu(sp->un.vv.vid); | |
559 | flag = be32_to_cpu(sp->un.vv.flags); | |
560 | if ((vid == LPFC_VV_EMLX_ID) && (flag & LPFC_VV_SUPPRESS_RSP)) | |
561 | ndlp->nlp_flag |= NLP_SUPPRESS_RSP; | |
562 | } | |
563 | ||
359e10f0 JS |
564 | login_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
565 | if (!login_mbox) | |
dea3101e | 566 | goto out; |
567 | ||
14375305 JS |
568 | save_iocb = kzalloc(sizeof(*save_iocb), GFP_KERNEL); |
569 | if (!save_iocb) | |
570 | goto out; | |
571 | ||
572 | /* Save info from cmd IOCB to be used in rsp after all mbox completes */ | |
573 | memcpy((uint8_t *)save_iocb, (uint8_t *)cmdiocb, | |
574 | sizeof(struct lpfc_iocbq)); | |
575 | ||
6b5151fd | 576 | /* Registering an existing RPI behaves differently for SLI3 vs SLI4 */ |
14375305 | 577 | if (phba->sli_rev == LPFC_SLI_REV4) |
6b5151fd JS |
578 | lpfc_unreg_rpi(vport, ndlp); |
579 | ||
14375305 JS |
580 | /* Issue REG_LOGIN first, before ACCing the PLOGI, thus we will |
581 | * always be deferring the ACC. | |
582 | */ | |
2d1928c5 JS |
583 | if (phba->sli_rev == LPFC_SLI_REV4) |
584 | remote_did = bf_get(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest); | |
585 | else | |
586 | remote_did = icmd->un.rcvels.remoteID; | |
587 | rc = lpfc_reg_rpi(phba, vport->vpi, remote_did, | |
359e10f0 JS |
588 | (uint8_t *)sp, login_mbox, ndlp->nlp_rpi); |
589 | if (rc) | |
dea3101e | 590 | goto out; |
dea3101e | 591 | |
359e10f0 | 592 | login_mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login; |
359e10f0 | 593 | login_mbox->vport = vport; |
dea3101e | 594 | |
33ccf8d1 JS |
595 | /* |
596 | * If there is an outstanding PLOGI issued, abort it before | |
597 | * sending ACC rsp for received PLOGI. If pending plogi | |
598 | * is not canceled here, the plogi will be rejected by | |
599 | * remote port and will be retried. On a configuration with | |
600 | * single discovery thread, this will cause a huge delay in | |
601 | * discovery. Also this will cause multiple state machines | |
602 | * running in parallel for this node. | |
feff8b3d | 603 | * This only applies to a fabric environment. |
33ccf8d1 | 604 | */ |
feff8b3d | 605 | if ((ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) && |
a645b8c1 | 606 | test_bit(FC_FABRIC, &vport->fc_flag)) { |
33ccf8d1 | 607 | /* software abort outstanding PLOGI */ |
07951076 | 608 | lpfc_els_abort(phba, ndlp); |
33ccf8d1 JS |
609 | } |
610 | ||
858c9f6c | 611 | if ((vport->port_type == LPFC_NPIV_PORT && |
3de2a653 | 612 | vport->cfg_restrict_login)) { |
858c9f6c | 613 | |
be0709e4 JS |
614 | /* no deferred ACC */ |
615 | kfree(save_iocb); | |
616 | ||
01131e7a JS |
617 | /* This is an NPIV SLI4 instance that does not need to register |
618 | * a default RPI. | |
858c9f6c | 619 | */ |
01131e7a | 620 | if (phba->sli_rev == LPFC_SLI_REV4) { |
ef47575f JS |
621 | lpfc_mbox_rsrc_cleanup(phba, login_mbox, |
622 | MBOX_THD_UNLOCKED); | |
01131e7a JS |
623 | login_mbox = NULL; |
624 | } else { | |
625 | /* In order to preserve RPIs, we want to cleanup | |
626 | * the default RPI the firmware created to rcv | |
627 | * this ELS request. The only way to do this is | |
628 | * to register, then unregister the RPI. | |
629 | */ | |
630 | spin_lock_irq(&ndlp->lock); | |
631 | ndlp->nlp_flag |= (NLP_RM_DFLT_RPI | NLP_ACC_REGLOGIN | | |
632 | NLP_RCV_PLOGI); | |
633 | spin_unlock_irq(&ndlp->lock); | |
634 | } | |
635 | ||
858c9f6c JS |
636 | stat.un.b.lsRjtRsnCode = LSRJT_INVALID_CMD; |
637 | stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE; | |
0a8a86fa | 638 | rc = lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, |
672d1cb4 | 639 | ndlp, login_mbox); |
ef47575f JS |
640 | if (rc && login_mbox) |
641 | lpfc_mbox_rsrc_cleanup(phba, login_mbox, | |
642 | MBOX_THD_UNLOCKED); | |
359e10f0 JS |
643 | return 1; |
644 | } | |
359e10f0 | 645 | |
14375305 JS |
646 | /* So the order here should be: |
647 | * SLI3 pt2pt | |
648 | * Issue CONFIG_LINK mbox | |
649 | * CONFIG_LINK cmpl | |
650 | * SLI4 pt2pt | |
651 | * Issue REG_VFI mbox | |
652 | * REG_VFI cmpl | |
653 | * SLI4 | |
654 | * Issue UNREG RPI mbx | |
655 | * UNREG RPI cmpl | |
656 | * Issue REG_RPI mbox | |
657 | * REG RPI cmpl | |
658 | * Issue PLOGI ACC | |
659 | * PLOGI ACC cmpl | |
660 | */ | |
661 | login_mbox->mbox_cmpl = lpfc_defer_plogi_acc; | |
662 | login_mbox->ctx_ndlp = lpfc_nlp_get(ndlp); | |
ba3d58a1 JS |
663 | if (!login_mbox->ctx_ndlp) |
664 | goto out; | |
665 | ||
85d77f91 | 666 | login_mbox->ctx_u.save_iocb = save_iocb; /* For PLOGI ACC */ |
359e10f0 | 667 | |
14375305 JS |
668 | spin_lock_irq(&ndlp->lock); |
669 | ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI); | |
670 | spin_unlock_irq(&ndlp->lock); | |
671 | ||
672 | /* Start the ball rolling by issuing REG_LOGIN here */ | |
673 | rc = lpfc_sli_issue_mbox(phba, login_mbox, MBX_NOWAIT); | |
ba3d58a1 JS |
674 | if (rc == MBX_NOT_FINISHED) { |
675 | lpfc_nlp_put(ndlp); | |
14375305 | 676 | goto out; |
ba3d58a1 | 677 | } |
14375305 | 678 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE); |
359e10f0 | 679 | |
c9f8735b | 680 | return 1; |
dea3101e | 681 | out: |
be0709e4 | 682 | kfree(save_iocb); |
359e10f0 JS |
683 | if (login_mbox) |
684 | mempool_free(login_mbox, phba->mbox_mem_pool); | |
685 | ||
dea3101e | 686 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; |
687 | stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE; | |
858c9f6c | 688 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
c9f8735b | 689 | return 0; |
dea3101e | 690 | } |
691 | ||
6b5151fd JS |
692 | /** |
693 | * lpfc_mbx_cmpl_resume_rpi - Resume RPI completion routine | |
694 | * @phba: pointer to lpfc hba data structure. | |
695 | * @mboxq: pointer to mailbox object | |
696 | * | |
697 | * This routine is invoked to issue a completion to a rcv'ed | |
698 | * ADISC or PDISC after the paused RPI has been resumed. | |
699 | **/ | |
700 | static void | |
701 | lpfc_mbx_cmpl_resume_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) | |
702 | { | |
703 | struct lpfc_vport *vport; | |
704 | struct lpfc_iocbq *elsiocb; | |
705 | struct lpfc_nodelist *ndlp; | |
706 | uint32_t cmd; | |
707 | ||
85d77f91 | 708 | elsiocb = mboxq->ctx_u.save_iocb; |
18f7fe44 | 709 | ndlp = mboxq->ctx_ndlp; |
6b5151fd JS |
710 | vport = mboxq->vport; |
711 | cmd = elsiocb->drvrTimeout; | |
712 | ||
713 | if (cmd == ELS_CMD_ADISC) { | |
714 | lpfc_els_rsp_adisc_acc(vport, elsiocb, ndlp); | |
715 | } else { | |
716 | lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, elsiocb, | |
717 | ndlp, NULL); | |
718 | } | |
1037e4b4 JS |
719 | |
720 | /* This nlp_put pairs with lpfc_sli4_resume_rpi */ | |
721 | lpfc_nlp_put(ndlp); | |
722 | ||
6b5151fd | 723 | kfree(elsiocb); |
72859909 | 724 | mempool_free(mboxq, phba->mbox_mem_pool); |
6b5151fd JS |
725 | } |
726 | ||
dea3101e | 727 | static int |
2e0fef85 | 728 | lpfc_rcv_padisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
dea3101e | 729 | struct lpfc_iocbq *cmdiocb) |
730 | { | |
cad93a08 | 731 | struct lpfc_hba *phba = vport->phba; |
6b5151fd | 732 | struct lpfc_iocbq *elsiocb; |
dea3101e | 733 | struct lpfc_dmabuf *pcmd; |
2e0fef85 JS |
734 | struct serv_parm *sp; |
735 | struct lpfc_name *pnn, *ppn; | |
dea3101e | 736 | struct ls_rjt stat; |
737 | ADISC *ap; | |
dea3101e | 738 | uint32_t *lp; |
739 | uint32_t cmd; | |
740 | ||
d51cf5bd | 741 | pcmd = cmdiocb->cmd_dmabuf; |
dea3101e | 742 | lp = (uint32_t *) pcmd->virt; |
743 | ||
744 | cmd = *lp++; | |
745 | if (cmd == ELS_CMD_ADISC) { | |
746 | ap = (ADISC *) lp; | |
747 | pnn = (struct lpfc_name *) & ap->nodeName; | |
748 | ppn = (struct lpfc_name *) & ap->portName; | |
749 | } else { | |
750 | sp = (struct serv_parm *) lp; | |
751 | pnn = (struct lpfc_name *) & sp->nodeName; | |
752 | ppn = (struct lpfc_name *) & sp->portName; | |
753 | } | |
754 | ||
cad93a08 JS |
755 | if (get_job_ulpstatus(phba, cmdiocb) == 0 && |
756 | lpfc_check_adisc(vport, ndlp, pnn, ppn)) { | |
6b5151fd JS |
757 | |
758 | /* | |
759 | * As soon as we send ACC, the remote NPort can | |
760 | * start sending us data. Thus, for SLI4 we must | |
761 | * resume the RPI before the ACC goes out. | |
762 | */ | |
763 | if (vport->phba->sli_rev == LPFC_SLI_REV4) { | |
764 | elsiocb = kmalloc(sizeof(struct lpfc_iocbq), | |
765 | GFP_KERNEL); | |
766 | if (elsiocb) { | |
6b5151fd JS |
767 | /* Save info from cmd IOCB used in rsp */ |
768 | memcpy((uint8_t *)elsiocb, (uint8_t *)cmdiocb, | |
769 | sizeof(struct lpfc_iocbq)); | |
770 | ||
771 | /* Save the ELS cmd */ | |
772 | elsiocb->drvrTimeout = cmd; | |
773 | ||
2ae917d4 JT |
774 | if (lpfc_sli4_resume_rpi(ndlp, |
775 | lpfc_mbx_cmpl_resume_rpi, | |
776 | elsiocb)) | |
777 | kfree(elsiocb); | |
6b5151fd JS |
778 | goto out; |
779 | } | |
780 | } | |
781 | ||
dea3101e | 782 | if (cmd == ELS_CMD_ADISC) { |
2e0fef85 | 783 | lpfc_els_rsp_adisc_acc(vport, cmdiocb, ndlp); |
2fe165b6 | 784 | } else { |
6b5151fd JS |
785 | lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, |
786 | ndlp, NULL); | |
dea3101e | 787 | } |
6b5151fd | 788 | out: |
9806c984 DK |
789 | /* If we are authenticated, move to the proper state. |
790 | * It is possible an ADISC arrived and the remote nport | |
791 | * is already in MAPPED or UNMAPPED state. Catch this | |
792 | * condition and don't set the nlp_state again because | |
793 | * it causes an unnecessary transport unregister/register. | |
ab803860 JS |
794 | * |
795 | * Nodes marked for ADISC will move MAPPED or UNMAPPED state | |
796 | * after issuing ADISC | |
9806c984 DK |
797 | */ |
798 | if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET)) { | |
ab803860 JS |
799 | if ((ndlp->nlp_state != NLP_STE_MAPPED_NODE) && |
800 | !(ndlp->nlp_flag & NLP_NPR_ADISC)) | |
9806c984 DK |
801 | lpfc_nlp_set_state(vport, ndlp, |
802 | NLP_STE_MAPPED_NODE); | |
803 | } | |
6b5151fd | 804 | |
c9f8735b | 805 | return 1; |
dea3101e | 806 | } |
807 | /* Reject this request because invalid parameters */ | |
808 | stat.un.b.lsRjtRsvd0 = 0; | |
809 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; | |
810 | stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS; | |
811 | stat.un.b.vendorUnique = 0; | |
858c9f6c | 812 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
dea3101e | 813 | |
dea3101e | 814 | /* 1 sec timeout */ |
256ec0d0 | 815 | mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000)); |
dea3101e | 816 | |
c6adba15 | 817 | spin_lock_irq(&ndlp->lock); |
dea3101e | 818 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
c6adba15 | 819 | spin_unlock_irq(&ndlp->lock); |
5024ab17 JW |
820 | ndlp->nlp_last_elscmd = ELS_CMD_PLOGI; |
821 | ndlp->nlp_prev_state = ndlp->nlp_state; | |
2e0fef85 | 822 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
c9f8735b | 823 | return 0; |
dea3101e | 824 | } |
825 | ||
826 | static int | |
2e0fef85 JS |
827 | lpfc_rcv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
828 | struct lpfc_iocbq *cmdiocb, uint32_t els_cmd) | |
dea3101e | 829 | { |
4b40c59e JS |
830 | struct lpfc_hba *phba = vport->phba; |
831 | struct lpfc_vport **vports; | |
832 | int i, active_vlink_present = 0 ; | |
2e0fef85 JS |
833 | |
834 | /* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */ | |
dea3101e | 835 | /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary |
836 | * PLOGIs during LOGO storms from a device. | |
837 | */ | |
c6adba15 | 838 | spin_lock_irq(&ndlp->lock); |
dea3101e | 839 | ndlp->nlp_flag |= NLP_LOGO_ACC; |
c6adba15 | 840 | spin_unlock_irq(&ndlp->lock); |
82d9a2a2 | 841 | if (els_cmd == ELS_CMD_PRLO) |
51ef4c26 | 842 | lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL); |
82d9a2a2 | 843 | else |
51ef4c26 | 844 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
4c2805aa | 845 | |
fe83e3b9 JS |
846 | /* This clause allows the initiator to ACC the LOGO back to the |
847 | * Fabric Domain Controller. It does deliberately skip all other | |
848 | * steps because some fabrics send RDP requests after logging out | |
849 | * from the initiator. | |
850 | */ | |
851 | if (ndlp->nlp_type & NLP_FABRIC && | |
852 | ((ndlp->nlp_DID & WELL_KNOWN_DID_MASK) != WELL_KNOWN_DID_MASK)) | |
853 | return 0; | |
854 | ||
4c2805aa JS |
855 | /* Notify transport of connectivity loss to trigger cleanup. */ |
856 | if (phba->nvmet_support && | |
857 | ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) | |
858 | lpfc_nvmet_invalidate_host(phba, ndlp); | |
859 | ||
4b40c59e | 860 | if (ndlp->nlp_DID == Fabric_DID) { |
336d6361 | 861 | if (vport->port_state <= LPFC_FDISC || |
a645b8c1 | 862 | test_bit(FC_PT2PT, &vport->fc_flag)) |
4b40c59e | 863 | goto out; |
6fb120a7 | 864 | lpfc_linkdown_port(vport); |
a645b8c1 | 865 | set_bit(FC_VPORT_LOGO_RCVD, &vport->fc_flag); |
4b40c59e JS |
866 | vports = lpfc_create_vport_work_array(phba); |
867 | if (vports) { | |
868 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; | |
869 | i++) { | |
a645b8c1 JT |
870 | if (!test_bit(FC_VPORT_LOGO_RCVD, |
871 | &vports[i]->fc_flag) && | |
872 | vports[i]->port_state > LPFC_FDISC) { | |
4b40c59e JS |
873 | active_vlink_present = 1; |
874 | break; | |
875 | } | |
876 | } | |
877 | lpfc_destroy_vport_work_array(phba, vports); | |
878 | } | |
dea3101e | 879 | |
cc82355a JS |
880 | /* |
881 | * Don't re-instantiate if vport is marked for deletion. | |
882 | * If we are here first then vport_delete is going to wait | |
883 | * for discovery to complete. | |
884 | */ | |
e39811be JT |
885 | if (!test_bit(FC_UNLOADING, &vport->load_flag) && |
886 | active_vlink_present) { | |
4b40c59e JS |
887 | /* |
888 | * If there are other active VLinks present, | |
889 | * re-instantiate the Vlink using FDISC. | |
890 | */ | |
256ec0d0 JS |
891 | mod_timer(&ndlp->nlp_delayfunc, |
892 | jiffies + msecs_to_jiffies(1000)); | |
c6adba15 | 893 | spin_lock_irq(&ndlp->lock); |
4b40c59e | 894 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
c6adba15 | 895 | spin_unlock_irq(&ndlp->lock); |
4b40c59e JS |
896 | ndlp->nlp_last_elscmd = ELS_CMD_FDISC; |
897 | vport->port_state = LPFC_FDISC; | |
898 | } else { | |
a645b8c1 | 899 | clear_bit(FC_LOGO_RCVD_DID_CHNG, &phba->pport->fc_flag); |
4b40c59e JS |
900 | lpfc_retry_pport_discovery(phba); |
901 | } | |
9388da30 JT |
902 | } else { |
903 | lpfc_printf_vlog(vport, KERN_INFO, | |
904 | LOG_NODE | LOG_ELS | LOG_DISCOVERY, | |
905 | "3203 LOGO recover nport x%06x state x%x " | |
a645b8c1 | 906 | "ntype x%x fc_flag x%lx\n", |
9388da30 JT |
907 | ndlp->nlp_DID, ndlp->nlp_state, |
908 | ndlp->nlp_type, vport->fc_flag); | |
909 | ||
910 | /* Special cases for rports that recover post LOGO. */ | |
911 | if ((!(ndlp->nlp_type == NLP_FABRIC) && | |
912 | (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET) || | |
a645b8c1 | 913 | test_bit(FC_PT2PT, &vport->fc_flag))) || |
9388da30 JT |
914 | (ndlp->nlp_state >= NLP_STE_ADISC_ISSUE || |
915 | ndlp->nlp_state <= NLP_STE_PRLI_ISSUE)) { | |
916 | mod_timer(&ndlp->nlp_delayfunc, | |
917 | jiffies + msecs_to_jiffies(1000 * 1)); | |
918 | spin_lock_irq(&ndlp->lock); | |
919 | ndlp->nlp_flag |= NLP_DELAY_TMO; | |
920 | spin_unlock_irq(&ndlp->lock); | |
921 | ndlp->nlp_last_elscmd = ELS_CMD_PLOGI; | |
922 | lpfc_printf_vlog(vport, KERN_INFO, | |
923 | LOG_NODE | LOG_ELS | LOG_DISCOVERY, | |
924 | "3204 Start nlpdelay on DID x%06x " | |
925 | "nflag x%x lastels x%x ref cnt %u", | |
926 | ndlp->nlp_DID, ndlp->nlp_flag, | |
927 | ndlp->nlp_last_elscmd, | |
928 | kref_read(&ndlp->kref)); | |
929 | } | |
c9f8735b | 930 | } |
4b40c59e | 931 | out: |
06145683 JS |
932 | /* Unregister from backend, could have been skipped due to ADISC */ |
933 | lpfc_nlp_unreg_node(vport, ndlp); | |
934 | ||
87af33fe JS |
935 | ndlp->nlp_prev_state = ndlp->nlp_state; |
936 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); | |
dea3101e | 937 | |
c6adba15 | 938 | spin_lock_irq(&ndlp->lock); |
dea3101e | 939 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
c6adba15 | 940 | spin_unlock_irq(&ndlp->lock); |
dea3101e | 941 | /* The driver has to wait until the ACC completes before it continues |
942 | * processing the LOGO. The action will resume in | |
943 | * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an | |
944 | * unreg_login, the driver waits so the ACC does not get aborted. | |
945 | */ | |
c9f8735b | 946 | return 0; |
dea3101e | 947 | } |
948 | ||
b95e29b7 JS |
949 | static uint32_t |
950 | lpfc_rcv_prli_support_check(struct lpfc_vport *vport, | |
951 | struct lpfc_nodelist *ndlp, | |
952 | struct lpfc_iocbq *cmdiocb) | |
953 | { | |
954 | struct ls_rjt stat; | |
955 | uint32_t *payload; | |
956 | uint32_t cmd; | |
12e896c7 | 957 | PRLI *npr; |
b95e29b7 | 958 | |
d51cf5bd | 959 | payload = cmdiocb->cmd_dmabuf->virt; |
b95e29b7 | 960 | cmd = *payload; |
12e896c7 JT |
961 | npr = (PRLI *)((uint8_t *)payload + sizeof(uint32_t)); |
962 | ||
b95e29b7 JS |
963 | if (vport->phba->nvmet_support) { |
964 | /* Must be a NVME PRLI */ | |
12e896c7 | 965 | if (cmd == ELS_CMD_PRLI) |
b95e29b7 JS |
966 | goto out; |
967 | } else { | |
968 | /* Initiator mode. */ | |
969 | if (!vport->nvmei_support && (cmd == ELS_CMD_NVMEPRLI)) | |
970 | goto out; | |
12e896c7 JT |
971 | |
972 | /* NPIV ports will RJT initiator only functions */ | |
973 | if (vport->port_type == LPFC_NPIV_PORT && | |
974 | npr->initiatorFunc && !npr->targetFunc) | |
975 | goto out; | |
b95e29b7 JS |
976 | } |
977 | return 1; | |
978 | out: | |
12e896c7 | 979 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY, |
b95e29b7 | 980 | "6115 Rcv PRLI (%x) check failed: ndlp rpi %d " |
12e896c7 JT |
981 | "state x%x flags x%x port_type: x%x " |
982 | "npr->initfcn: x%x npr->tgtfcn: x%x\n", | |
b95e29b7 | 983 | cmd, ndlp->nlp_rpi, ndlp->nlp_state, |
12e896c7 JT |
984 | ndlp->nlp_flag, vport->port_type, |
985 | npr->initiatorFunc, npr->targetFunc); | |
b95e29b7 JS |
986 | memset(&stat, 0, sizeof(struct ls_rjt)); |
987 | stat.un.b.lsRjtRsnCode = LSRJT_CMD_UNSUPPORTED; | |
988 | stat.un.b.lsRjtRsnCodeExp = LSEXP_REQ_UNSUPPORTED; | |
989 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, | |
990 | ndlp, NULL); | |
991 | return 0; | |
992 | } | |
993 | ||
dea3101e | 994 | static void |
2e0fef85 JS |
995 | lpfc_rcv_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
996 | struct lpfc_iocbq *cmdiocb) | |
dea3101e | 997 | { |
a0f2d3ef | 998 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 999 | struct lpfc_dmabuf *pcmd; |
1000 | uint32_t *lp; | |
1001 | PRLI *npr; | |
1002 | struct fc_rport *rport = ndlp->rport; | |
1003 | u32 roles; | |
1004 | ||
d51cf5bd JS |
1005 | pcmd = cmdiocb->cmd_dmabuf; |
1006 | lp = (uint32_t *)pcmd->virt; | |
1007 | npr = (PRLI *)((uint8_t *)lp + sizeof(uint32_t)); | |
dea3101e | 1008 | |
a0f2d3ef JS |
1009 | if ((npr->prliType == PRLI_FCP_TYPE) || |
1010 | (npr->prliType == PRLI_NVME_TYPE)) { | |
1011 | if (npr->initiatorFunc) { | |
1012 | if (npr->prliType == PRLI_FCP_TYPE) | |
1013 | ndlp->nlp_type |= NLP_FCP_INITIATOR; | |
1014 | if (npr->prliType == PRLI_NVME_TYPE) | |
1015 | ndlp->nlp_type |= NLP_NVME_INITIATOR; | |
1016 | } | |
3cb01c57 | 1017 | if (npr->targetFunc) { |
a0f2d3ef JS |
1018 | if (npr->prliType == PRLI_FCP_TYPE) |
1019 | ndlp->nlp_type |= NLP_FCP_TARGET; | |
1020 | if (npr->prliType == PRLI_NVME_TYPE) | |
1021 | ndlp->nlp_type |= NLP_NVME_TARGET; | |
3cb01c57 JS |
1022 | if (npr->writeXferRdyDis) |
1023 | ndlp->nlp_flag |= NLP_FIRSTBURST; | |
1024 | } | |
0d8af096 JS |
1025 | if (npr->Retry && ndlp->nlp_type & |
1026 | (NLP_FCP_INITIATOR | NLP_FCP_TARGET)) | |
dea3101e | 1027 | ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE; |
8c258641 | 1028 | |
0d8af096 JS |
1029 | if (npr->Retry && phba->nsler && |
1030 | ndlp->nlp_type & (NLP_NVME_INITIATOR | NLP_NVME_TARGET)) | |
1031 | ndlp->nlp_nvme_info |= NLP_NVME_NSLER; | |
1032 | ||
1033 | ||
8c258641 JS |
1034 | /* If this driver is in nvme target mode, set the ndlp's fc4 |
1035 | * type to NVME provided the PRLI response claims NVME FC4 | |
1036 | * type. Target mode does not issue gft_id so doesn't get | |
1037 | * the fc4 type set until now. | |
1038 | */ | |
9de416ac | 1039 | if (phba->nvmet_support && (npr->prliType == PRLI_NVME_TYPE)) { |
8c258641 | 1040 | ndlp->nlp_fc4_type |= NLP_FC4_NVME; |
9de416ac JS |
1041 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
1042 | } | |
07aaefdf JS |
1043 | |
1044 | /* Fabric Controllers send FCP PRLI as an initiator but should | |
1045 | * not get recognized as FCP type and registered with transport. | |
1046 | */ | |
1047 | if (npr->prliType == PRLI_FCP_TYPE && | |
1048 | !(ndlp->nlp_type & NLP_FABRIC)) | |
9de416ac | 1049 | ndlp->nlp_fc4_type |= NLP_FC4_FCP; |
dea3101e | 1050 | } |
1051 | if (rport) { | |
1052 | /* We need to update the rport role values */ | |
1053 | roles = FC_RPORT_ROLE_UNKNOWN; | |
1054 | if (ndlp->nlp_type & NLP_FCP_INITIATOR) | |
1055 | roles |= FC_RPORT_ROLE_FCP_INITIATOR; | |
1056 | if (ndlp->nlp_type & NLP_FCP_TARGET) | |
1057 | roles |= FC_RPORT_ROLE_FCP_TARGET; | |
858c9f6c JS |
1058 | |
1059 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, | |
1060 | "rport rolechg: role:x%x did:x%x flg:x%x", | |
1061 | roles, ndlp->nlp_DID, ndlp->nlp_flag); | |
1062 | ||
f6e84790 | 1063 | if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME) |
a0f2d3ef | 1064 | fc_remote_port_rolechg(rport, roles); |
dea3101e | 1065 | } |
1066 | } | |
1067 | ||
1068 | static uint32_t | |
2e0fef85 | 1069 | lpfc_disc_set_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
dea3101e | 1070 | { |
4042629e | 1071 | if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED)) { |
c6adba15 | 1072 | spin_lock_irq(&ndlp->lock); |
51ef4c26 | 1073 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
c6adba15 | 1074 | spin_unlock_irq(&ndlp->lock); |
51ef4c26 JS |
1075 | return 0; |
1076 | } | |
1077 | ||
a645b8c1 | 1078 | if (!test_bit(FC_PT2PT, &vport->fc_flag)) { |
1b32f6aa | 1079 | /* Check config parameter use-adisc or FCP-2 */ |
a645b8c1 JT |
1080 | if (vport->cfg_use_adisc && |
1081 | (test_bit(FC_RSCN_MODE, &vport->fc_flag) || | |
ffc95493 | 1082 | ((ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) && |
0fd103cc | 1083 | (ndlp->nlp_type & NLP_FCP_TARGET)))) { |
c6adba15 | 1084 | spin_lock_irq(&ndlp->lock); |
1b32f6aa | 1085 | ndlp->nlp_flag |= NLP_NPR_ADISC; |
c6adba15 | 1086 | spin_unlock_irq(&ndlp->lock); |
1b32f6aa JS |
1087 | return 1; |
1088 | } | |
92d7f7b0 | 1089 | } |
30e196ca | 1090 | |
c6adba15 | 1091 | spin_lock_irq(&ndlp->lock); |
92d7f7b0 | 1092 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
c6adba15 | 1093 | spin_unlock_irq(&ndlp->lock); |
92d7f7b0 JS |
1094 | lpfc_unreg_rpi(vport, ndlp); |
1095 | return 0; | |
dea3101e | 1096 | } |
6d368e53 | 1097 | |
78730cfe | 1098 | /** |
25985edc | 1099 | * lpfc_release_rpi - Release a RPI by issuing unreg_login mailbox cmd. |
78730cfe JS |
1100 | * @phba : Pointer to lpfc_hba structure. |
1101 | * @vport: Pointer to lpfc_vport structure. | |
22f8c077 | 1102 | * @ndlp: Pointer to lpfc_nodelist structure. |
78730cfe JS |
1103 | * @rpi : rpi to be release. |
1104 | * | |
1105 | * This function will send a unreg_login mailbox command to the firmware | |
1106 | * to release a rpi. | |
1107 | **/ | |
3999df75 | 1108 | static void |
dea16bda JS |
1109 | lpfc_release_rpi(struct lpfc_hba *phba, struct lpfc_vport *vport, |
1110 | struct lpfc_nodelist *ndlp, uint16_t rpi) | |
78730cfe JS |
1111 | { |
1112 | LPFC_MBOXQ_t *pmb; | |
1113 | int rc; | |
1114 | ||
dea16bda JS |
1115 | /* If there is already an UNREG in progress for this ndlp, |
1116 | * no need to queue up another one. | |
1117 | */ | |
1118 | if (ndlp->nlp_flag & NLP_UNREG_INP) { | |
1119 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, | |
1120 | "1435 release_rpi SKIP UNREG x%x on " | |
1121 | "NPort x%x deferred x%x flg x%x " | |
32350664 | 1122 | "Data: x%px\n", |
dea16bda JS |
1123 | ndlp->nlp_rpi, ndlp->nlp_DID, |
1124 | ndlp->nlp_defer_did, | |
1125 | ndlp->nlp_flag, ndlp); | |
1126 | return; | |
1127 | } | |
1128 | ||
78730cfe JS |
1129 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
1130 | GFP_KERNEL); | |
1131 | if (!pmb) | |
372c187b DK |
1132 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
1133 | "2796 mailbox memory allocation failed \n"); | |
78730cfe JS |
1134 | else { |
1135 | lpfc_unreg_login(phba, vport->vpi, rpi, pmb); | |
1136 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
dea16bda | 1137 | pmb->vport = vport; |
4430f7fd JS |
1138 | pmb->ctx_ndlp = lpfc_nlp_get(ndlp); |
1139 | if (!pmb->ctx_ndlp) { | |
1140 | mempool_free(pmb, phba->mbox_mem_pool); | |
1141 | return; | |
1142 | } | |
dea16bda JS |
1143 | |
1144 | if (((ndlp->nlp_DID & Fabric_DID_MASK) != Fabric_DID_MASK) && | |
a645b8c1 | 1145 | (!test_bit(FC_OFFLINE_MODE, &vport->fc_flag))) |
dea16bda JS |
1146 | ndlp->nlp_flag |= NLP_UNREG_INP; |
1147 | ||
1148 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, | |
1149 | "1437 release_rpi UNREG x%x " | |
1150 | "on NPort x%x flg x%x\n", | |
1151 | ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag); | |
1152 | ||
78730cfe | 1153 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
ba3d58a1 JS |
1154 | if (rc == MBX_NOT_FINISHED) { |
1155 | lpfc_nlp_put(ndlp); | |
78730cfe | 1156 | mempool_free(pmb, phba->mbox_mem_pool); |
ba3d58a1 | 1157 | } |
78730cfe JS |
1158 | } |
1159 | } | |
dea3101e | 1160 | |
1161 | static uint32_t | |
2e0fef85 JS |
1162 | lpfc_disc_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
1163 | void *arg, uint32_t evt) | |
dea3101e | 1164 | { |
78730cfe JS |
1165 | struct lpfc_hba *phba; |
1166 | LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg; | |
78730cfe JS |
1167 | uint16_t rpi; |
1168 | ||
1169 | phba = vport->phba; | |
1170 | /* Release the RPI if reglogin completing */ | |
e39811be JT |
1171 | if (!test_bit(FC_UNLOADING, &phba->pport->load_flag) && |
1172 | evt == NLP_EVT_CMPL_REG_LOGIN && !pmb->u.mb.mbxStatus) { | |
78730cfe | 1173 | rpi = pmb->u.mb.un.varWords[0]; |
dea16bda | 1174 | lpfc_release_rpi(phba, vport, ndlp, rpi); |
78730cfe | 1175 | } |
372c187b | 1176 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
e47c9093 | 1177 | "0271 Illegal State Transition: node x%x " |
e8b62011 JS |
1178 | "event x%x, state x%x Data: x%x x%x\n", |
1179 | ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi, | |
1180 | ndlp->nlp_flag); | |
c9f8735b | 1181 | return ndlp->nlp_state; |
dea3101e | 1182 | } |
1183 | ||
87af33fe JS |
1184 | static uint32_t |
1185 | lpfc_cmpl_plogi_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, | |
1186 | void *arg, uint32_t evt) | |
1187 | { | |
1188 | /* This transition is only legal if we previously | |
1189 | * rcv'ed a PLOGI. Since we don't want 2 discovery threads | |
1190 | * working on the same NPortID, do nothing for this thread | |
1191 | * to stop it. | |
1192 | */ | |
1193 | if (!(ndlp->nlp_flag & NLP_RCV_PLOGI)) { | |
372c187b DK |
1194 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
1195 | "0272 Illegal State Transition: node x%x " | |
1196 | "event x%x, state x%x Data: x%x x%x\n", | |
1197 | ndlp->nlp_DID, evt, ndlp->nlp_state, | |
1198 | ndlp->nlp_rpi, ndlp->nlp_flag); | |
87af33fe JS |
1199 | } |
1200 | return ndlp->nlp_state; | |
1201 | } | |
1202 | ||
dea3101e | 1203 | /* Start of Discovery State Machine routines */ |
1204 | ||
1205 | static uint32_t | |
2e0fef85 JS |
1206 | lpfc_rcv_plogi_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
1207 | void *arg, uint32_t evt) | |
dea3101e | 1208 | { |
1209 | struct lpfc_iocbq *cmdiocb; | |
1210 | ||
1211 | cmdiocb = (struct lpfc_iocbq *) arg; | |
1212 | ||
2e0fef85 | 1213 | if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) { |
c9f8735b | 1214 | return ndlp->nlp_state; |
dea3101e | 1215 | } |
c9f8735b | 1216 | return NLP_STE_FREED_NODE; |
dea3101e | 1217 | } |
1218 | ||
1219 | static uint32_t | |
2e0fef85 JS |
1220 | lpfc_rcv_els_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
1221 | void *arg, uint32_t evt) | |
dea3101e | 1222 | { |
2e0fef85 | 1223 | lpfc_issue_els_logo(vport, ndlp, 0); |
c9f8735b | 1224 | return ndlp->nlp_state; |
dea3101e | 1225 | } |
1226 | ||
1227 | static uint32_t | |
2e0fef85 JS |
1228 | lpfc_rcv_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
1229 | void *arg, uint32_t evt) | |
dea3101e | 1230 | { |
2e0fef85 | 1231 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; |
dea3101e | 1232 | |
c6adba15 | 1233 | spin_lock_irq(&ndlp->lock); |
dea3101e | 1234 | ndlp->nlp_flag |= NLP_LOGO_ACC; |
c6adba15 | 1235 | spin_unlock_irq(&ndlp->lock); |
51ef4c26 | 1236 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
dea3101e | 1237 | |
c9f8735b | 1238 | return ndlp->nlp_state; |
dea3101e | 1239 | } |
1240 | ||
1241 | static uint32_t | |
2e0fef85 JS |
1242 | lpfc_cmpl_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
1243 | void *arg, uint32_t evt) | |
dea3101e | 1244 | { |
c9f8735b | 1245 | return NLP_STE_FREED_NODE; |
dea3101e | 1246 | } |
1247 | ||
1248 | static uint32_t | |
2e0fef85 JS |
1249 | lpfc_device_rm_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
1250 | void *arg, uint32_t evt) | |
dea3101e | 1251 | { |
c9f8735b | 1252 | return NLP_STE_FREED_NODE; |
dea3101e | 1253 | } |
1254 | ||
df9e1b59 JS |
1255 | static uint32_t |
1256 | lpfc_device_recov_unused_node(struct lpfc_vport *vport, | |
1257 | struct lpfc_nodelist *ndlp, | |
1258 | void *arg, uint32_t evt) | |
1259 | { | |
1260 | return ndlp->nlp_state; | |
1261 | } | |
1262 | ||
dea3101e | 1263 | static uint32_t |
2e0fef85 | 1264 | lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
dea3101e | 1265 | void *arg, uint32_t evt) |
1266 | { | |
2e0fef85 | 1267 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 1268 | struct lpfc_iocbq *cmdiocb = arg; |
d51cf5bd | 1269 | struct lpfc_dmabuf *pcmd = cmdiocb->cmd_dmabuf; |
2e0fef85 JS |
1270 | uint32_t *lp = (uint32_t *) pcmd->virt; |
1271 | struct serv_parm *sp = (struct serv_parm *) (lp + 1); | |
dea3101e | 1272 | struct ls_rjt stat; |
1273 | int port_cmp; | |
1274 | ||
dea3101e | 1275 | memset(&stat, 0, sizeof (struct ls_rjt)); |
1276 | ||
1277 | /* For a PLOGI, we only accept if our portname is less | |
1278 | * than the remote portname. | |
1279 | */ | |
1280 | phba->fc_stat.elsLogiCol++; | |
2e0fef85 | 1281 | port_cmp = memcmp(&vport->fc_portname, &sp->portName, |
92d7f7b0 | 1282 | sizeof(struct lpfc_name)); |
dea3101e | 1283 | |
1284 | if (port_cmp >= 0) { | |
1285 | /* Reject this request because the remote node will accept | |
1286 | ours */ | |
1287 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; | |
1288 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS; | |
858c9f6c JS |
1289 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
1290 | NULL); | |
2fe165b6 | 1291 | } else { |
0d2b6b83 JS |
1292 | if (lpfc_rcv_plogi(vport, ndlp, cmdiocb) && |
1293 | (ndlp->nlp_flag & NLP_NPR_2B_DISC) && | |
1294 | (vport->num_disc_nodes)) { | |
c6adba15 | 1295 | spin_lock_irq(&ndlp->lock); |
0d2b6b83 | 1296 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
c6adba15 | 1297 | spin_unlock_irq(&ndlp->lock); |
0d2b6b83 JS |
1298 | /* Check if there are more PLOGIs to be sent */ |
1299 | lpfc_more_plogi(vport); | |
1300 | if (vport->num_disc_nodes == 0) { | |
a645b8c1 | 1301 | clear_bit(FC_NDISC_ACTIVE, &vport->fc_flag); |
0d2b6b83 JS |
1302 | lpfc_can_disctmo(vport); |
1303 | lpfc_end_rscn(vport); | |
1304 | } | |
1305 | } | |
2e0fef85 | 1306 | } /* If our portname was less */ |
dea3101e | 1307 | |
c9f8735b JW |
1308 | return ndlp->nlp_state; |
1309 | } | |
1310 | ||
92d7f7b0 JS |
1311 | static uint32_t |
1312 | lpfc_rcv_prli_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, | |
1313 | void *arg, uint32_t evt) | |
1314 | { | |
1315 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; | |
1316 | struct ls_rjt stat; | |
1317 | ||
1318 | memset(&stat, 0, sizeof (struct ls_rjt)); | |
1319 | stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY; | |
1320 | stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE; | |
858c9f6c | 1321 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
92d7f7b0 JS |
1322 | return ndlp->nlp_state; |
1323 | } | |
1324 | ||
c9f8735b | 1325 | static uint32_t |
2e0fef85 JS |
1326 | lpfc_rcv_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
1327 | void *arg, uint32_t evt) | |
c9f8735b | 1328 | { |
2e0fef85 | 1329 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; |
c9f8735b | 1330 | |
faa832e9 JS |
1331 | /* Retrieve RPI from LOGO IOCB. RPI is used for CMD_ABORT_XRI_CN */ |
1332 | if (vport->phba->sli_rev == LPFC_SLI_REV3) | |
1333 | ndlp->nlp_rpi = cmdiocb->iocb.ulpIoTag; | |
92d7f7b0 | 1334 | /* software abort outstanding PLOGI */ |
2e0fef85 | 1335 | lpfc_els_abort(vport->phba, ndlp); |
c9f8735b | 1336 | |
2e0fef85 | 1337 | lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO); |
c9f8735b | 1338 | return ndlp->nlp_state; |
dea3101e | 1339 | } |
1340 | ||
1341 | static uint32_t | |
2e0fef85 JS |
1342 | lpfc_rcv_els_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
1343 | void *arg, uint32_t evt) | |
dea3101e | 1344 | { |
2e0fef85 JS |
1345 | struct lpfc_hba *phba = vport->phba; |
1346 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; | |
dea3101e | 1347 | |
1348 | /* software abort outstanding PLOGI */ | |
07951076 | 1349 | lpfc_els_abort(phba, ndlp); |
dea3101e | 1350 | |
1351 | if (evt == NLP_EVT_RCV_LOGO) { | |
51ef4c26 | 1352 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
2fe165b6 | 1353 | } else { |
2e0fef85 | 1354 | lpfc_issue_els_logo(vport, ndlp, 0); |
dea3101e | 1355 | } |
1356 | ||
2e0fef85 | 1357 | /* Put ndlp in npr state set plogi timer for 1 sec */ |
256ec0d0 | 1358 | mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000 * 1)); |
c6adba15 | 1359 | spin_lock_irq(&ndlp->lock); |
5024ab17 | 1360 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
c6adba15 | 1361 | spin_unlock_irq(&ndlp->lock); |
5024ab17 JW |
1362 | ndlp->nlp_last_elscmd = ELS_CMD_PLOGI; |
1363 | ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE; | |
2e0fef85 | 1364 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
dea3101e | 1365 | |
c9f8735b | 1366 | return ndlp->nlp_state; |
dea3101e | 1367 | } |
1368 | ||
1369 | static uint32_t | |
2e0fef85 JS |
1370 | lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport, |
1371 | struct lpfc_nodelist *ndlp, | |
1372 | void *arg, | |
dea3101e | 1373 | uint32_t evt) |
1374 | { | |
2e0fef85 JS |
1375 | struct lpfc_hba *phba = vport->phba; |
1376 | struct lpfc_iocbq *cmdiocb, *rspiocb; | |
ef47575f | 1377 | struct lpfc_dmabuf *pcmd, *prsp; |
dea3101e | 1378 | uint32_t *lp; |
8c258641 | 1379 | uint32_t vid, flag; |
dea3101e | 1380 | struct serv_parm *sp; |
d6de08cc | 1381 | uint32_t ed_tov; |
dea3101e | 1382 | LPFC_MBOXQ_t *mbox; |
d6de08cc | 1383 | int rc; |
cad93a08 JS |
1384 | u32 ulp_status; |
1385 | u32 did; | |
dea3101e | 1386 | |
1387 | cmdiocb = (struct lpfc_iocbq *) arg; | |
d51cf5bd | 1388 | rspiocb = cmdiocb->rsp_iocb; |
dea3101e | 1389 | |
cad93a08 JS |
1390 | ulp_status = get_job_ulpstatus(phba, rspiocb); |
1391 | ||
dea3101e | 1392 | if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) { |
5024ab17 | 1393 | /* Recovery from PLOGI collision logic */ |
c9f8735b | 1394 | return ndlp->nlp_state; |
dea3101e | 1395 | } |
1396 | ||
cad93a08 | 1397 | if (ulp_status) |
dea3101e | 1398 | goto out; |
1399 | ||
d51cf5bd | 1400 | pcmd = cmdiocb->cmd_dmabuf; |
dea3101e | 1401 | |
2e0fef85 | 1402 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
a2fc4aef JS |
1403 | if (!prsp) |
1404 | goto out; | |
dea3101e | 1405 | |
2e0fef85 | 1406 | lp = (uint32_t *) prsp->virt; |
dea3101e | 1407 | sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t)); |
58da1ffb JS |
1408 | |
1409 | /* Some switches have FDMI servers returning 0 for WWN */ | |
1410 | if ((ndlp->nlp_DID != FDMI_DID) && | |
1411 | (wwn_to_u64(sp->portName.u.wwn) == 0 || | |
1412 | wwn_to_u64(sp->nodeName.u.wwn) == 0)) { | |
372c187b | 1413 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
a8adb832 JS |
1414 | "0142 PLOGI RSP: Invalid WWN.\n"); |
1415 | goto out; | |
1416 | } | |
341af102 | 1417 | if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0)) |
dea3101e | 1418 | goto out; |
dea3101e | 1419 | /* PLOGI chkparm OK */ |
e8b62011 JS |
1420 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
1421 | "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n", | |
1422 | ndlp->nlp_DID, ndlp->nlp_state, | |
1423 | ndlp->nlp_flag, ndlp->nlp_rpi); | |
3de2a653 | 1424 | if (vport->cfg_fcp_class == 2 && (sp->cls2.classValid)) |
dea3101e | 1425 | ndlp->nlp_fcp_info |= CLASS2; |
2e0fef85 | 1426 | else |
dea3101e | 1427 | ndlp->nlp_fcp_info |= CLASS3; |
2e0fef85 | 1428 | |
dea3101e | 1429 | ndlp->nlp_class_sup = 0; |
1430 | if (sp->cls1.classValid) | |
1431 | ndlp->nlp_class_sup |= FC_COS_CLASS1; | |
1432 | if (sp->cls2.classValid) | |
1433 | ndlp->nlp_class_sup |= FC_COS_CLASS2; | |
1434 | if (sp->cls3.classValid) | |
1435 | ndlp->nlp_class_sup |= FC_COS_CLASS3; | |
1436 | if (sp->cls4.classValid) | |
1437 | ndlp->nlp_class_sup |= FC_COS_CLASS4; | |
1438 | ndlp->nlp_maxframe = | |
2e0fef85 | 1439 | ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb; |
dea3101e | 1440 | |
a645b8c1 JT |
1441 | if (test_bit(FC_PT2PT, &vport->fc_flag) && |
1442 | test_bit(FC_PT2PT_PLOGI, &vport->fc_flag)) { | |
d6de08cc JS |
1443 | ed_tov = be32_to_cpu(sp->cmn.e_d_tov); |
1444 | if (sp->cmn.edtovResolution) { | |
1445 | /* E_D_TOV ticks are in nanoseconds */ | |
1446 | ed_tov = (phba->fc_edtov + 999999) / 1000000; | |
1447 | } | |
1448 | ||
8c258641 JS |
1449 | ndlp->nlp_flag &= ~NLP_SUPPRESS_RSP; |
1450 | if ((phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) && | |
1451 | sp->cmn.valid_vendor_ver_level) { | |
1452 | vid = be32_to_cpu(sp->un.vv.vid); | |
1453 | flag = be32_to_cpu(sp->un.vv.flags); | |
1454 | if ((vid == LPFC_VV_EMLX_ID) && | |
1455 | (flag & LPFC_VV_SUPPRESS_RSP)) | |
1456 | ndlp->nlp_flag |= NLP_SUPPRESS_RSP; | |
1457 | } | |
1458 | ||
d6de08cc JS |
1459 | /* |
1460 | * Use the larger EDTOV | |
1461 | * RATOV = 2 * EDTOV for pt-to-pt | |
1462 | */ | |
1463 | if (ed_tov > phba->fc_edtov) | |
1464 | phba->fc_edtov = ed_tov; | |
1465 | phba->fc_ratov = (2 * phba->fc_edtov) / 1000; | |
1466 | ||
1467 | memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm)); | |
1468 | ||
1469 | /* Issue config_link / reg_vfi to account for updated TOV's */ | |
1470 | if (phba->sli_rev == LPFC_SLI_REV4) { | |
1471 | lpfc_issue_reg_vfi(vport); | |
1472 | } else { | |
01c73bbc JS |
1473 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
1474 | if (!mbox) { | |
372c187b DK |
1475 | lpfc_printf_vlog(vport, KERN_ERR, |
1476 | LOG_TRACE_EVENT, | |
01c73bbc JS |
1477 | "0133 PLOGI: no memory " |
1478 | "for config_link " | |
1479 | "Data: x%x x%x x%x x%x\n", | |
1480 | ndlp->nlp_DID, ndlp->nlp_state, | |
1481 | ndlp->nlp_flag, ndlp->nlp_rpi); | |
1482 | goto out; | |
1483 | } | |
1484 | ||
d6de08cc JS |
1485 | lpfc_config_link(phba, mbox); |
1486 | ||
1487 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
1488 | mbox->vport = vport; | |
1489 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); | |
1490 | if (rc == MBX_NOT_FINISHED) { | |
1491 | mempool_free(mbox, phba->mbox_mem_pool); | |
1492 | goto out; | |
1493 | } | |
1494 | } | |
92d7f7b0 | 1495 | } |
dea3101e | 1496 | |
2e0fef85 JS |
1497 | lpfc_unreg_rpi(vport, ndlp); |
1498 | ||
01c73bbc JS |
1499 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
1500 | if (!mbox) { | |
372c187b | 1501 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
01c73bbc JS |
1502 | "0018 PLOGI: no memory for reg_login " |
1503 | "Data: x%x x%x x%x x%x\n", | |
1504 | ndlp->nlp_DID, ndlp->nlp_state, | |
1505 | ndlp->nlp_flag, ndlp->nlp_rpi); | |
1506 | goto out; | |
1507 | } | |
1508 | ||
cad93a08 JS |
1509 | did = get_job_els_rsp64_did(phba, cmdiocb); |
1510 | ||
1511 | if (lpfc_reg_rpi(phba, vport->vpi, did, | |
4042629e | 1512 | (uint8_t *) sp, mbox, ndlp->nlp_rpi) == 0) { |
2fe165b6 | 1513 | switch (ndlp->nlp_DID) { |
dea3101e | 1514 | case NameServer_DID: |
de0c5b32 | 1515 | mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login; |
fe83e3b9 JS |
1516 | /* Fabric Controller Node needs these parameters. */ |
1517 | memcpy(&ndlp->fc_sparam, sp, sizeof(struct serv_parm)); | |
dea3101e | 1518 | break; |
1519 | case FDMI_DID: | |
de0c5b32 | 1520 | mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login; |
dea3101e | 1521 | break; |
1522 | default: | |
ffc95493 | 1523 | ndlp->nlp_flag |= NLP_REG_LOGIN_SEND; |
de0c5b32 | 1524 | mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login; |
dea3101e | 1525 | } |
4430f7fd | 1526 | |
3e1f0718 | 1527 | mbox->ctx_ndlp = lpfc_nlp_get(ndlp); |
4430f7fd JS |
1528 | if (!mbox->ctx_ndlp) |
1529 | goto out; | |
1530 | ||
2e0fef85 | 1531 | mbox->vport = vport; |
0b727fea | 1532 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
dea3101e | 1533 | != MBX_NOT_FINISHED) { |
2e0fef85 JS |
1534 | lpfc_nlp_set_state(vport, ndlp, |
1535 | NLP_STE_REG_LOGIN_ISSUE); | |
c9f8735b | 1536 | return ndlp->nlp_state; |
dea3101e | 1537 | } |
ffc95493 JS |
1538 | if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND) |
1539 | ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND; | |
fa4066b6 JS |
1540 | /* decrement node reference count to the failed mbox |
1541 | * command | |
1542 | */ | |
329f9bc7 | 1543 | lpfc_nlp_put(ndlp); |
ef47575f | 1544 | lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED); |
372c187b | 1545 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
e8b62011 JS |
1546 | "0134 PLOGI: cannot issue reg_login " |
1547 | "Data: x%x x%x x%x x%x\n", | |
1548 | ndlp->nlp_DID, ndlp->nlp_state, | |
1549 | ndlp->nlp_flag, ndlp->nlp_rpi); | |
dea3101e | 1550 | } else { |
1551 | mempool_free(mbox, phba->mbox_mem_pool); | |
92d7f7b0 | 1552 | |
372c187b | 1553 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
e8b62011 JS |
1554 | "0135 PLOGI: cannot format reg_login " |
1555 | "Data: x%x x%x x%x x%x\n", | |
1556 | ndlp->nlp_DID, ndlp->nlp_state, | |
1557 | ndlp->nlp_flag, ndlp->nlp_rpi); | |
dea3101e | 1558 | } |
1559 | ||
1560 | ||
92d7f7b0 JS |
1561 | out: |
1562 | if (ndlp->nlp_DID == NameServer_DID) { | |
1563 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); | |
372c187b | 1564 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
e8b62011 | 1565 | "0261 Cannot Register NameServer login\n"); |
92d7f7b0 JS |
1566 | } |
1567 | ||
8b455cf3 JS |
1568 | /* |
1569 | ** In case the node reference counter does not go to zero, ensure that | |
1570 | ** the stale state for the node is not processed. | |
1571 | */ | |
1572 | ||
1573 | ndlp->nlp_prev_state = ndlp->nlp_state; | |
1574 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); | |
c9f8735b | 1575 | return NLP_STE_FREED_NODE; |
dea3101e | 1576 | } |
1577 | ||
0ff10d46 JS |
1578 | static uint32_t |
1579 | lpfc_cmpl_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, | |
1580 | void *arg, uint32_t evt) | |
1581 | { | |
1582 | return ndlp->nlp_state; | |
1583 | } | |
1584 | ||
1585 | static uint32_t | |
1586 | lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport *vport, | |
1587 | struct lpfc_nodelist *ndlp, void *arg, uint32_t evt) | |
1588 | { | |
78730cfe JS |
1589 | struct lpfc_hba *phba; |
1590 | LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg; | |
1591 | MAILBOX_t *mb = &pmb->u.mb; | |
1592 | uint16_t rpi; | |
1593 | ||
1594 | phba = vport->phba; | |
1595 | /* Release the RPI */ | |
e39811be JT |
1596 | if (!test_bit(FC_UNLOADING, &phba->pport->load_flag) && |
1597 | !mb->mbxStatus) { | |
78730cfe | 1598 | rpi = pmb->u.mb.un.varWords[0]; |
dea16bda | 1599 | lpfc_release_rpi(phba, vport, ndlp, rpi); |
78730cfe | 1600 | } |
0ff10d46 JS |
1601 | return ndlp->nlp_state; |
1602 | } | |
1603 | ||
dea3101e | 1604 | static uint32_t |
2e0fef85 JS |
1605 | lpfc_device_rm_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
1606 | void *arg, uint32_t evt) | |
dea3101e | 1607 | { |
2e0fef85 | 1608 | if (ndlp->nlp_flag & NLP_NPR_2B_DISC) { |
c6adba15 | 1609 | spin_lock_irq(&ndlp->lock); |
a0f9b48d | 1610 | ndlp->nlp_flag |= NLP_NODEV_REMOVE; |
c6adba15 | 1611 | spin_unlock_irq(&ndlp->lock); |
a0f9b48d | 1612 | return ndlp->nlp_state; |
2e0fef85 | 1613 | } else { |
a0f9b48d | 1614 | /* software abort outstanding PLOGI */ |
2e0fef85 | 1615 | lpfc_els_abort(vport->phba, ndlp); |
dea3101e | 1616 | |
2e0fef85 | 1617 | lpfc_drop_node(vport, ndlp); |
a0f9b48d JS |
1618 | return NLP_STE_FREED_NODE; |
1619 | } | |
dea3101e | 1620 | } |
1621 | ||
1622 | static uint32_t | |
2e0fef85 JS |
1623 | lpfc_device_recov_plogi_issue(struct lpfc_vport *vport, |
1624 | struct lpfc_nodelist *ndlp, | |
1625 | void *arg, | |
1626 | uint32_t evt) | |
dea3101e | 1627 | { |
2e0fef85 JS |
1628 | struct lpfc_hba *phba = vport->phba; |
1629 | ||
bf81e9cd JT |
1630 | /* Don't do anything that disrupts the RSCN unless lpfc is unloading. */ |
1631 | if (lpfc_check_unload_and_clr_rscn(&vport->fc_flag)) | |
92d7f7b0 JS |
1632 | return ndlp->nlp_state; |
1633 | ||
dea3101e | 1634 | /* software abort outstanding PLOGI */ |
07951076 | 1635 | lpfc_els_abort(phba, ndlp); |
dea3101e | 1636 | |
5024ab17 | 1637 | ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE; |
2e0fef85 | 1638 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
c6adba15 | 1639 | spin_lock_irq(&ndlp->lock); |
a0f9b48d | 1640 | ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC); |
c6adba15 | 1641 | spin_unlock_irq(&ndlp->lock); |
dea3101e | 1642 | |
c9f8735b | 1643 | return ndlp->nlp_state; |
dea3101e | 1644 | } |
1645 | ||
1646 | static uint32_t | |
2e0fef85 JS |
1647 | lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
1648 | void *arg, uint32_t evt) | |
dea3101e | 1649 | { |
2e0fef85 | 1650 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 1651 | struct lpfc_iocbq *cmdiocb; |
1652 | ||
1653 | /* software abort outstanding ADISC */ | |
07951076 | 1654 | lpfc_els_abort(phba, ndlp); |
dea3101e | 1655 | |
1656 | cmdiocb = (struct lpfc_iocbq *) arg; | |
1657 | ||
0d2b6b83 JS |
1658 | if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) { |
1659 | if (ndlp->nlp_flag & NLP_NPR_2B_DISC) { | |
c6adba15 | 1660 | spin_lock_irq(&ndlp->lock); |
0d2b6b83 | 1661 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; |
c6adba15 | 1662 | spin_unlock_irq(&ndlp->lock); |
90160e01 | 1663 | if (vport->num_disc_nodes) |
0d2b6b83 | 1664 | lpfc_more_adisc(vport); |
0d2b6b83 JS |
1665 | } |
1666 | return ndlp->nlp_state; | |
1667 | } | |
5024ab17 | 1668 | ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE; |
2e0fef85 JS |
1669 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
1670 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); | |
dea3101e | 1671 | |
c9f8735b | 1672 | return ndlp->nlp_state; |
dea3101e | 1673 | } |
1674 | ||
1675 | static uint32_t | |
2e0fef85 JS |
1676 | lpfc_rcv_prli_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
1677 | void *arg, uint32_t evt) | |
dea3101e | 1678 | { |
2e0fef85 | 1679 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; |
dea3101e | 1680 | |
b95e29b7 JS |
1681 | if (lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb)) |
1682 | lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp); | |
c9f8735b | 1683 | return ndlp->nlp_state; |
dea3101e | 1684 | } |
1685 | ||
1686 | static uint32_t | |
2e0fef85 JS |
1687 | lpfc_rcv_logo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
1688 | void *arg, uint32_t evt) | |
dea3101e | 1689 | { |
2e0fef85 | 1690 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 1691 | struct lpfc_iocbq *cmdiocb; |
1692 | ||
1693 | cmdiocb = (struct lpfc_iocbq *) arg; | |
1694 | ||
1695 | /* software abort outstanding ADISC */ | |
07951076 | 1696 | lpfc_els_abort(phba, ndlp); |
dea3101e | 1697 | |
2e0fef85 | 1698 | lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO); |
c9f8735b | 1699 | return ndlp->nlp_state; |
dea3101e | 1700 | } |
1701 | ||
1702 | static uint32_t | |
2e0fef85 JS |
1703 | lpfc_rcv_padisc_adisc_issue(struct lpfc_vport *vport, |
1704 | struct lpfc_nodelist *ndlp, | |
1705 | void *arg, uint32_t evt) | |
dea3101e | 1706 | { |
1707 | struct lpfc_iocbq *cmdiocb; | |
1708 | ||
1709 | cmdiocb = (struct lpfc_iocbq *) arg; | |
1710 | ||
2e0fef85 | 1711 | lpfc_rcv_padisc(vport, ndlp, cmdiocb); |
c9f8735b | 1712 | return ndlp->nlp_state; |
dea3101e | 1713 | } |
1714 | ||
1715 | static uint32_t | |
2e0fef85 JS |
1716 | lpfc_rcv_prlo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
1717 | void *arg, uint32_t evt) | |
dea3101e | 1718 | { |
1719 | struct lpfc_iocbq *cmdiocb; | |
1720 | ||
1721 | cmdiocb = (struct lpfc_iocbq *) arg; | |
1722 | ||
1723 | /* Treat like rcv logo */ | |
2e0fef85 | 1724 | lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO); |
c9f8735b | 1725 | return ndlp->nlp_state; |
dea3101e | 1726 | } |
1727 | ||
1728 | static uint32_t | |
2e0fef85 JS |
1729 | lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport *vport, |
1730 | struct lpfc_nodelist *ndlp, | |
1731 | void *arg, uint32_t evt) | |
dea3101e | 1732 | { |
2e0fef85 | 1733 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 1734 | struct lpfc_iocbq *cmdiocb, *rspiocb; |
dea3101e | 1735 | ADISC *ap; |
6fb120a7 | 1736 | int rc; |
cad93a08 | 1737 | u32 ulp_status; |
dea3101e | 1738 | |
1739 | cmdiocb = (struct lpfc_iocbq *) arg; | |
d51cf5bd | 1740 | rspiocb = cmdiocb->rsp_iocb; |
dea3101e | 1741 | |
cad93a08 JS |
1742 | ulp_status = get_job_ulpstatus(phba, rspiocb); |
1743 | ||
dea3101e | 1744 | ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb); |
dea3101e | 1745 | |
cad93a08 | 1746 | if ((ulp_status) || |
92d7f7b0 | 1747 | (!lpfc_check_adisc(vport, ndlp, &ap->nodeName, &ap->portName))) { |
dea3101e | 1748 | /* 1 sec timeout */ |
256ec0d0 JS |
1749 | mod_timer(&ndlp->nlp_delayfunc, |
1750 | jiffies + msecs_to_jiffies(1000)); | |
c6adba15 | 1751 | spin_lock_irq(&ndlp->lock); |
dea3101e | 1752 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
c6adba15 | 1753 | spin_unlock_irq(&ndlp->lock); |
5024ab17 | 1754 | ndlp->nlp_last_elscmd = ELS_CMD_PLOGI; |
dea3101e | 1755 | |
5024ab17 | 1756 | ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE; |
2e0fef85 JS |
1757 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
1758 | lpfc_unreg_rpi(vport, ndlp); | |
c9f8735b | 1759 | return ndlp->nlp_state; |
dea3101e | 1760 | } |
5024ab17 | 1761 | |
6fb120a7 | 1762 | if (phba->sli_rev == LPFC_SLI_REV4) { |
6b5151fd | 1763 | rc = lpfc_sli4_resume_rpi(ndlp, NULL, NULL); |
6fb120a7 JS |
1764 | if (rc) { |
1765 | /* Stay in state and retry. */ | |
1766 | ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE; | |
1767 | return ndlp->nlp_state; | |
1768 | } | |
1769 | } | |
1770 | ||
00081c5c DK |
1771 | if (ndlp->nlp_type & NLP_FCP_TARGET) |
1772 | ndlp->nlp_fc4_type |= NLP_FC4_FCP; | |
1773 | ||
1774 | if (ndlp->nlp_type & NLP_NVME_TARGET) | |
1775 | ndlp->nlp_fc4_type |= NLP_FC4_NVME; | |
1776 | ||
1777 | if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET)) { | |
5024ab17 | 1778 | ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE; |
2e0fef85 | 1779 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE); |
2501322e | 1780 | } else { |
5024ab17 | 1781 | ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE; |
2e0fef85 | 1782 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
2501322e | 1783 | } |
6fb120a7 | 1784 | |
c9f8735b | 1785 | return ndlp->nlp_state; |
dea3101e | 1786 | } |
1787 | ||
1788 | static uint32_t | |
2e0fef85 JS |
1789 | lpfc_device_rm_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
1790 | void *arg, uint32_t evt) | |
dea3101e | 1791 | { |
2e0fef85 | 1792 | if (ndlp->nlp_flag & NLP_NPR_2B_DISC) { |
c6adba15 | 1793 | spin_lock_irq(&ndlp->lock); |
a0f9b48d | 1794 | ndlp->nlp_flag |= NLP_NODEV_REMOVE; |
c6adba15 | 1795 | spin_unlock_irq(&ndlp->lock); |
a0f9b48d | 1796 | return ndlp->nlp_state; |
2e0fef85 | 1797 | } else { |
a0f9b48d | 1798 | /* software abort outstanding ADISC */ |
2e0fef85 | 1799 | lpfc_els_abort(vport->phba, ndlp); |
dea3101e | 1800 | |
2e0fef85 | 1801 | lpfc_drop_node(vport, ndlp); |
a0f9b48d JS |
1802 | return NLP_STE_FREED_NODE; |
1803 | } | |
dea3101e | 1804 | } |
1805 | ||
1806 | static uint32_t | |
2e0fef85 JS |
1807 | lpfc_device_recov_adisc_issue(struct lpfc_vport *vport, |
1808 | struct lpfc_nodelist *ndlp, | |
1809 | void *arg, | |
1810 | uint32_t evt) | |
dea3101e | 1811 | { |
2e0fef85 JS |
1812 | struct lpfc_hba *phba = vport->phba; |
1813 | ||
bf81e9cd JT |
1814 | /* Don't do anything that disrupts the RSCN unless lpfc is unloading. */ |
1815 | if (lpfc_check_unload_and_clr_rscn(&vport->fc_flag)) | |
92d7f7b0 JS |
1816 | return ndlp->nlp_state; |
1817 | ||
dea3101e | 1818 | /* software abort outstanding ADISC */ |
07951076 | 1819 | lpfc_els_abort(phba, ndlp); |
dea3101e | 1820 | |
5024ab17 | 1821 | ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE; |
2e0fef85 | 1822 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
c6adba15 | 1823 | spin_lock_irq(&ndlp->lock); |
a0f9b48d | 1824 | ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC); |
c6adba15 | 1825 | spin_unlock_irq(&ndlp->lock); |
92d7f7b0 | 1826 | lpfc_disc_set_adisc(vport, ndlp); |
c9f8735b | 1827 | return ndlp->nlp_state; |
dea3101e | 1828 | } |
1829 | ||
1830 | static uint32_t | |
2e0fef85 JS |
1831 | lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport *vport, |
1832 | struct lpfc_nodelist *ndlp, | |
1833 | void *arg, | |
dea3101e | 1834 | uint32_t evt) |
1835 | { | |
2e0fef85 | 1836 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; |
dea3101e | 1837 | |
2e0fef85 | 1838 | lpfc_rcv_plogi(vport, ndlp, cmdiocb); |
c9f8735b | 1839 | return ndlp->nlp_state; |
dea3101e | 1840 | } |
1841 | ||
1842 | static uint32_t | |
2e0fef85 JS |
1843 | lpfc_rcv_prli_reglogin_issue(struct lpfc_vport *vport, |
1844 | struct lpfc_nodelist *ndlp, | |
1845 | void *arg, | |
dea3101e | 1846 | uint32_t evt) |
1847 | { | |
2e0fef85 | 1848 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; |
8c258641 | 1849 | struct ls_rjt stat; |
dea3101e | 1850 | |
b95e29b7 JS |
1851 | if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb)) { |
1852 | return ndlp->nlp_state; | |
1853 | } | |
8c258641 JS |
1854 | if (vport->phba->nvmet_support) { |
1855 | /* NVME Target mode. Handle and respond to the PRLI and | |
1856 | * transition to UNMAPPED provided the RPI has completed | |
1857 | * registration. | |
1858 | */ | |
1859 | if (ndlp->nlp_flag & NLP_RPI_REGISTERED) { | |
1860 | lpfc_rcv_prli(vport, ndlp, cmdiocb); | |
1861 | lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp); | |
8c258641 JS |
1862 | } else { |
1863 | /* RPI registration has not completed. Reject the PRLI | |
1864 | * to prevent an illegal state transition when the | |
1865 | * rpi registration does complete. | |
1866 | */ | |
8c258641 | 1867 | memset(&stat, 0, sizeof(struct ls_rjt)); |
e06351a0 JS |
1868 | stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY; |
1869 | stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE; | |
8c258641 JS |
1870 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, |
1871 | ndlp, NULL); | |
9de416ac | 1872 | return ndlp->nlp_state; |
8c258641 JS |
1873 | } |
1874 | } else { | |
1875 | /* Initiator mode. */ | |
1876 | lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp); | |
1877 | } | |
c9f8735b | 1878 | return ndlp->nlp_state; |
dea3101e | 1879 | } |
1880 | ||
1881 | static uint32_t | |
2e0fef85 JS |
1882 | lpfc_rcv_logo_reglogin_issue(struct lpfc_vport *vport, |
1883 | struct lpfc_nodelist *ndlp, | |
1884 | void *arg, | |
dea3101e | 1885 | uint32_t evt) |
1886 | { | |
2e0fef85 JS |
1887 | struct lpfc_hba *phba = vport->phba; |
1888 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; | |
7054a606 JS |
1889 | LPFC_MBOXQ_t *mb; |
1890 | LPFC_MBOXQ_t *nextmb; | |
dea3101e | 1891 | |
1892 | cmdiocb = (struct lpfc_iocbq *) arg; | |
1893 | ||
7054a606 JS |
1894 | /* cleanup any ndlp on mbox q waiting for reglogin cmpl */ |
1895 | if ((mb = phba->sli.mbox_active)) { | |
04c68496 | 1896 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) && |
18f7fe44 | 1897 | (ndlp == mb->ctx_ndlp)) { |
de96e9c5 | 1898 | ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND; |
92d7f7b0 | 1899 | lpfc_nlp_put(ndlp); |
3e1f0718 | 1900 | mb->ctx_ndlp = NULL; |
7054a606 JS |
1901 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
1902 | } | |
1903 | } | |
1904 | ||
2e0fef85 | 1905 | spin_lock_irq(&phba->hbalock); |
7054a606 | 1906 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { |
04c68496 | 1907 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) && |
18f7fe44 | 1908 | (ndlp == mb->ctx_ndlp)) { |
de96e9c5 | 1909 | ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND; |
92d7f7b0 | 1910 | lpfc_nlp_put(ndlp); |
7054a606 | 1911 | list_del(&mb->list); |
5ffc266e | 1912 | phba->sli.mboxq_cnt--; |
ef47575f | 1913 | lpfc_mbox_rsrc_cleanup(phba, mb, MBOX_THD_LOCKED); |
7054a606 JS |
1914 | } |
1915 | } | |
2e0fef85 | 1916 | spin_unlock_irq(&phba->hbalock); |
7054a606 | 1917 | |
2e0fef85 | 1918 | lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO); |
c9f8735b | 1919 | return ndlp->nlp_state; |
dea3101e | 1920 | } |
1921 | ||
1922 | static uint32_t | |
2e0fef85 JS |
1923 | lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport *vport, |
1924 | struct lpfc_nodelist *ndlp, | |
1925 | void *arg, | |
dea3101e | 1926 | uint32_t evt) |
1927 | { | |
2e0fef85 | 1928 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; |
dea3101e | 1929 | |
2e0fef85 | 1930 | lpfc_rcv_padisc(vport, ndlp, cmdiocb); |
c9f8735b | 1931 | return ndlp->nlp_state; |
dea3101e | 1932 | } |
1933 | ||
1934 | static uint32_t | |
2e0fef85 JS |
1935 | lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport *vport, |
1936 | struct lpfc_nodelist *ndlp, | |
1937 | void *arg, | |
dea3101e | 1938 | uint32_t evt) |
1939 | { | |
1940 | struct lpfc_iocbq *cmdiocb; | |
1941 | ||
1942 | cmdiocb = (struct lpfc_iocbq *) arg; | |
51ef4c26 | 1943 | lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL); |
c9f8735b | 1944 | return ndlp->nlp_state; |
dea3101e | 1945 | } |
1946 | ||
1947 | static uint32_t | |
2e0fef85 JS |
1948 | lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport *vport, |
1949 | struct lpfc_nodelist *ndlp, | |
1950 | void *arg, | |
1951 | uint32_t evt) | |
dea3101e | 1952 | { |
a0f2d3ef | 1953 | struct lpfc_hba *phba = vport->phba; |
2e0fef85 | 1954 | LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg; |
04c68496 | 1955 | MAILBOX_t *mb = &pmb->u.mb; |
2e0fef85 | 1956 | uint32_t did = mb->un.varWords[1]; |
dea3101e | 1957 | |
dea3101e | 1958 | if (mb->mbxStatus) { |
1959 | /* RegLogin failed */ | |
372c187b DK |
1960 | lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, |
1961 | "0246 RegLogin failed Data: x%x x%x x%x x%x " | |
6d368e53 JS |
1962 | "x%x\n", |
1963 | did, mb->mbxStatus, vport->port_state, | |
1964 | mb->un.varRegLogin.vpi, | |
1965 | mb->un.varRegLogin.rpi); | |
d0e56dad JS |
1966 | /* |
1967 | * If RegLogin failed due to lack of HBA resources do not | |
1968 | * retry discovery. | |
1969 | */ | |
1970 | if (mb->mbxStatus == MBXERR_RPI_FULL) { | |
87af33fe JS |
1971 | ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE; |
1972 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); | |
d0e56dad JS |
1973 | return ndlp->nlp_state; |
1974 | } | |
1975 | ||
2e0fef85 | 1976 | /* Put ndlp in npr state set plogi timer for 1 sec */ |
256ec0d0 JS |
1977 | mod_timer(&ndlp->nlp_delayfunc, |
1978 | jiffies + msecs_to_jiffies(1000 * 1)); | |
c6adba15 | 1979 | spin_lock_irq(&ndlp->lock); |
dea3101e | 1980 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
c6adba15 | 1981 | spin_unlock_irq(&ndlp->lock); |
5024ab17 | 1982 | ndlp->nlp_last_elscmd = ELS_CMD_PLOGI; |
dea3101e | 1983 | |
2e0fef85 | 1984 | lpfc_issue_els_logo(vport, ndlp, 0); |
c9f8735b | 1985 | return ndlp->nlp_state; |
dea3101e | 1986 | } |
1987 | ||
6d368e53 | 1988 | /* SLI4 ports have preallocated logical rpis. */ |
a0f2d3ef | 1989 | if (phba->sli_rev < LPFC_SLI_REV4) |
6d368e53 JS |
1990 | ndlp->nlp_rpi = mb->un.varWords[0]; |
1991 | ||
4042629e | 1992 | ndlp->nlp_flag |= NLP_RPI_REGISTERED; |
dea3101e | 1993 | |
1994 | /* Only if we are not a fabric nport do we issue PRLI */ | |
a0f2d3ef JS |
1995 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
1996 | "3066 RegLogin Complete on x%x x%x x%x\n", | |
1997 | did, ndlp->nlp_type, ndlp->nlp_fc4_type); | |
1998 | if (!(ndlp->nlp_type & NLP_FABRIC) && | |
1999 | (phba->nvmet_support == 0)) { | |
2000 | /* The driver supports FCP and NVME concurrently. If the | |
2001 | * ndlp's nlp_fc4_type is still zero, the driver doesn't | |
2002 | * know what PRLI to send yet. Figure that out now and | |
2003 | * call PRLI depending on the outcome. | |
2004 | */ | |
a645b8c1 | 2005 | if (test_bit(FC_PT2PT, &vport->fc_flag)) { |
a0f2d3ef JS |
2006 | /* If we are pt2pt, there is no Fabric to determine |
2007 | * the FC4 type of the remote nport. So if NVME | |
2008 | * is configured try it. | |
2009 | */ | |
2010 | ndlp->nlp_fc4_type |= NLP_FC4_FCP; | |
a645b8c1 | 2011 | if ((!test_bit(FC_PT2PT_NO_NVME, &vport->fc_flag)) && |
7f4c5a26 JS |
2012 | (vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH || |
2013 | vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) { | |
a0f2d3ef JS |
2014 | ndlp->nlp_fc4_type |= NLP_FC4_NVME; |
2015 | /* We need to update the localport also */ | |
01649561 | 2016 | lpfc_nvme_update_localport(vport); |
a0f2d3ef JS |
2017 | } |
2018 | ||
2877cbff DK |
2019 | } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
2020 | ndlp->nlp_fc4_type |= NLP_FC4_FCP; | |
2021 | ||
a0f2d3ef | 2022 | } else if (ndlp->nlp_fc4_type == 0) { |
7ea92eb4 JS |
2023 | /* If we are only configured for FCP, the driver |
2024 | * should just issue PRLI for FCP. Otherwise issue | |
2025 | * GFT_ID to determine if remote port supports NVME. | |
2026 | */ | |
f6e84790 | 2027 | if (vport->cfg_enable_fc4_type != LPFC_ENABLE_FCP) { |
b27cbd55 BVA |
2028 | lpfc_ns_cmd(vport, SLI_CTNS_GFT_ID, 0, |
2029 | ndlp->nlp_DID); | |
7ea92eb4 JS |
2030 | return ndlp->nlp_state; |
2031 | } | |
2032 | ndlp->nlp_fc4_type = NLP_FC4_FCP; | |
a0f2d3ef JS |
2033 | } |
2034 | ||
5024ab17 | 2035 | ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE; |
2e0fef85 | 2036 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
7f20c1cb JS |
2037 | if (lpfc_issue_els_prli(vport, ndlp, 0)) { |
2038 | lpfc_issue_els_logo(vport, ndlp, 0); | |
2039 | ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE; | |
2040 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); | |
2041 | } | |
dea3101e | 2042 | } else { |
a645b8c1 | 2043 | if (test_bit(FC_PT2PT, &vport->fc_flag) && phba->nvmet_support) |
8c258641 JS |
2044 | phba->targetport->port_id = vport->fc_myDID; |
2045 | ||
2046 | /* Only Fabric ports should transition. NVME target | |
2047 | * must complete PRLI. | |
2048 | */ | |
a0f2d3ef | 2049 | if (ndlp->nlp_type & NLP_FABRIC) { |
07aaefdf | 2050 | ndlp->nlp_fc4_type &= ~NLP_FC4_FCP; |
a0f2d3ef JS |
2051 | ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE; |
2052 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); | |
2053 | } | |
dea3101e | 2054 | } |
c9f8735b | 2055 | return ndlp->nlp_state; |
dea3101e | 2056 | } |
2057 | ||
2058 | static uint32_t | |
2e0fef85 JS |
2059 | lpfc_device_rm_reglogin_issue(struct lpfc_vport *vport, |
2060 | struct lpfc_nodelist *ndlp, | |
2061 | void *arg, | |
dea3101e | 2062 | uint32_t evt) |
2063 | { | |
2e0fef85 | 2064 | if (ndlp->nlp_flag & NLP_NPR_2B_DISC) { |
c6adba15 | 2065 | spin_lock_irq(&ndlp->lock); |
a0f9b48d | 2066 | ndlp->nlp_flag |= NLP_NODEV_REMOVE; |
c6adba15 | 2067 | spin_unlock_irq(&ndlp->lock); |
a0f9b48d | 2068 | return ndlp->nlp_state; |
2e0fef85 JS |
2069 | } else { |
2070 | lpfc_drop_node(vport, ndlp); | |
a0f9b48d JS |
2071 | return NLP_STE_FREED_NODE; |
2072 | } | |
dea3101e | 2073 | } |
2074 | ||
2075 | static uint32_t | |
2e0fef85 JS |
2076 | lpfc_device_recov_reglogin_issue(struct lpfc_vport *vport, |
2077 | struct lpfc_nodelist *ndlp, | |
2078 | void *arg, | |
2079 | uint32_t evt) | |
dea3101e | 2080 | { |
bf81e9cd JT |
2081 | /* Don't do anything that disrupts the RSCN unless lpfc is unloading. */ |
2082 | if (lpfc_check_unload_and_clr_rscn(&vport->fc_flag)) | |
92d7f7b0 JS |
2083 | return ndlp->nlp_state; |
2084 | ||
5024ab17 | 2085 | ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE; |
2e0fef85 | 2086 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
c6adba15 | 2087 | spin_lock_irq(&ndlp->lock); |
a0f2d3ef | 2088 | |
8c258641 JS |
2089 | /* If we are a target we won't immediately transition into PRLI, |
2090 | * so if REG_LOGIN already completed we don't need to ignore it. | |
2091 | */ | |
2092 | if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED) || | |
2093 | !vport->phba->nvmet_support) | |
2094 | ndlp->nlp_flag |= NLP_IGNR_REG_CMPL; | |
2095 | ||
a0f9b48d | 2096 | ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC); |
c6adba15 | 2097 | spin_unlock_irq(&ndlp->lock); |
92d7f7b0 | 2098 | lpfc_disc_set_adisc(vport, ndlp); |
c9f8735b | 2099 | return ndlp->nlp_state; |
dea3101e | 2100 | } |
2101 | ||
2102 | static uint32_t | |
2e0fef85 JS |
2103 | lpfc_rcv_plogi_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
2104 | void *arg, uint32_t evt) | |
dea3101e | 2105 | { |
2106 | struct lpfc_iocbq *cmdiocb; | |
2107 | ||
2108 | cmdiocb = (struct lpfc_iocbq *) arg; | |
2109 | ||
2e0fef85 | 2110 | lpfc_rcv_plogi(vport, ndlp, cmdiocb); |
c9f8735b | 2111 | return ndlp->nlp_state; |
dea3101e | 2112 | } |
2113 | ||
2114 | static uint32_t | |
2e0fef85 JS |
2115 | lpfc_rcv_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
2116 | void *arg, uint32_t evt) | |
dea3101e | 2117 | { |
2e0fef85 | 2118 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; |
dea3101e | 2119 | |
b95e29b7 JS |
2120 | if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb)) |
2121 | return ndlp->nlp_state; | |
ecf041fe | 2122 | lpfc_rcv_prli(vport, ndlp, cmdiocb); |
2e0fef85 | 2123 | lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp); |
c9f8735b | 2124 | return ndlp->nlp_state; |
dea3101e | 2125 | } |
2126 | ||
2127 | static uint32_t | |
2e0fef85 JS |
2128 | lpfc_rcv_logo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
2129 | void *arg, uint32_t evt) | |
dea3101e | 2130 | { |
2e0fef85 | 2131 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; |
dea3101e | 2132 | |
2133 | /* Software abort outstanding PRLI before sending acc */ | |
2e0fef85 | 2134 | lpfc_els_abort(vport->phba, ndlp); |
dea3101e | 2135 | |
2e0fef85 | 2136 | lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO); |
c9f8735b | 2137 | return ndlp->nlp_state; |
dea3101e | 2138 | } |
2139 | ||
2140 | static uint32_t | |
2e0fef85 JS |
2141 | lpfc_rcv_padisc_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
2142 | void *arg, uint32_t evt) | |
dea3101e | 2143 | { |
2e0fef85 | 2144 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; |
dea3101e | 2145 | |
2e0fef85 | 2146 | lpfc_rcv_padisc(vport, ndlp, cmdiocb); |
c9f8735b | 2147 | return ndlp->nlp_state; |
dea3101e | 2148 | } |
2149 | ||
2150 | /* This routine is envoked when we rcv a PRLO request from a nport | |
2151 | * we are logged into. We should send back a PRLO rsp setting the | |
2152 | * appropriate bits. | |
2153 | * NEXT STATE = PRLI_ISSUE | |
2154 | */ | |
2155 | static uint32_t | |
2e0fef85 JS |
2156 | lpfc_rcv_prlo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
2157 | void *arg, uint32_t evt) | |
dea3101e | 2158 | { |
2e0fef85 | 2159 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; |
dea3101e | 2160 | |
51ef4c26 | 2161 | lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL); |
c9f8735b | 2162 | return ndlp->nlp_state; |
dea3101e | 2163 | } |
2164 | ||
2165 | static uint32_t | |
2e0fef85 JS |
2166 | lpfc_cmpl_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
2167 | void *arg, uint32_t evt) | |
dea3101e | 2168 | { |
2169 | struct lpfc_iocbq *cmdiocb, *rspiocb; | |
2e0fef85 | 2170 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 2171 | PRLI *npr; |
a0f2d3ef JS |
2172 | struct lpfc_nvme_prli *nvpr; |
2173 | void *temp_ptr; | |
cad93a08 | 2174 | u32 ulp_status; |
04c32001 | 2175 | bool acc_imode_sps = false; |
dea3101e | 2176 | |
2177 | cmdiocb = (struct lpfc_iocbq *) arg; | |
d51cf5bd | 2178 | rspiocb = cmdiocb->rsp_iocb; |
a0f2d3ef | 2179 | |
cad93a08 JS |
2180 | ulp_status = get_job_ulpstatus(phba, rspiocb); |
2181 | ||
a0f2d3ef JS |
2182 | /* A solicited PRLI is either FCP or NVME. The PRLI cmd/rsp |
2183 | * format is different so NULL the two PRLI types so that the | |
2184 | * driver correctly gets the correct context. | |
2185 | */ | |
2186 | npr = NULL; | |
2187 | nvpr = NULL; | |
2188 | temp_ptr = lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb); | |
a680a929 | 2189 | if (cmdiocb->cmd_flag & LPFC_PRLI_FCP_REQ) |
a0f2d3ef | 2190 | npr = (PRLI *) temp_ptr; |
a680a929 | 2191 | else if (cmdiocb->cmd_flag & LPFC_PRLI_NVME_REQ) |
a0f2d3ef | 2192 | nvpr = (struct lpfc_nvme_prli *) temp_ptr; |
dea3101e | 2193 | |
cad93a08 | 2194 | if (ulp_status) { |
858c9f6c | 2195 | if ((vport->port_type == LPFC_NPIV_PORT) && |
3de2a653 | 2196 | vport->cfg_restrict_login) { |
858c9f6c JS |
2197 | goto out; |
2198 | } | |
a0f2d3ef | 2199 | |
118c0415 JS |
2200 | /* Adjust the nlp_type accordingly if the PRLI failed */ |
2201 | if (npr) | |
8db1c2b3 | 2202 | ndlp->nlp_fc4_type &= ~NLP_FC4_FCP; |
118c0415 JS |
2203 | if (nvpr) |
2204 | ndlp->nlp_fc4_type &= ~NLP_FC4_NVME; | |
8db1c2b3 | 2205 | |
118c0415 JS |
2206 | /* We can't set the DSM state till BOTH PRLIs complete */ |
2207 | goto out_err; | |
dea3101e | 2208 | } |
2209 | ||
04c32001 JT |
2210 | if (npr && npr->prliType == PRLI_FCP_TYPE) { |
2211 | lpfc_printf_vlog(vport, KERN_INFO, | |
2212 | LOG_ELS | LOG_NODE | LOG_DISCOVERY, | |
2213 | "6028 FCP NPR PRLI Cmpl Init %d Target %d " | |
2214 | "EIP %d AccCode x%x\n", | |
2215 | npr->initiatorFunc, npr->targetFunc, | |
2216 | npr->estabImagePair, npr->acceptRspCode); | |
2217 | ||
2218 | if (npr->acceptRspCode == PRLI_INV_SRV_PARM) { | |
2219 | /* Strict initiators don't establish an image pair. */ | |
2220 | if (npr->initiatorFunc && !npr->targetFunc && | |
2221 | !npr->estabImagePair) | |
2222 | acc_imode_sps = true; | |
3cb01c57 | 2223 | } |
a0f2d3ef | 2224 | |
04c32001 JT |
2225 | if (npr->acceptRspCode == PRLI_REQ_EXECUTED || acc_imode_sps) { |
2226 | if (npr->initiatorFunc) | |
2227 | ndlp->nlp_type |= NLP_FCP_INITIATOR; | |
2228 | if (npr->targetFunc) { | |
2229 | ndlp->nlp_type |= NLP_FCP_TARGET; | |
2230 | if (npr->writeXferRdyDis) | |
2231 | ndlp->nlp_flag |= NLP_FIRSTBURST; | |
2232 | } | |
2233 | if (npr->Retry) | |
2234 | ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE; | |
2235 | } | |
a0f2d3ef JS |
2236 | } else if (nvpr && |
2237 | (bf_get_be32(prli_acc_rsp_code, nvpr) == | |
2238 | PRLI_REQ_EXECUTED) && | |
2239 | (bf_get_be32(prli_type_code, nvpr) == | |
2240 | PRLI_NVME_TYPE)) { | |
2241 | ||
2242 | /* Complete setting up the remote ndlp personality. */ | |
2243 | if (bf_get_be32(prli_init, nvpr)) | |
2244 | ndlp->nlp_type |= NLP_NVME_INITIATOR; | |
2245 | ||
69641627 JS |
2246 | if (phba->nsler && bf_get_be32(prli_nsler, nvpr) && |
2247 | bf_get_be32(prli_conf, nvpr)) | |
2248 | ||
0d8af096 JS |
2249 | ndlp->nlp_nvme_info |= NLP_NVME_NSLER; |
2250 | else | |
2251 | ndlp->nlp_nvme_info &= ~NLP_NVME_NSLER; | |
2252 | ||
a0f2d3ef JS |
2253 | /* Target driver cannot solicit NVME FB. */ |
2254 | if (bf_get_be32(prli_tgt, nvpr)) { | |
dc53a618 JS |
2255 | /* Complete the nvme target roles. The transport |
2256 | * needs to know if the rport is capable of | |
2257 | * discovery in addition to its role. | |
2258 | */ | |
a0f2d3ef | 2259 | ndlp->nlp_type |= NLP_NVME_TARGET; |
dc53a618 JS |
2260 | if (bf_get_be32(prli_disc, nvpr)) |
2261 | ndlp->nlp_type |= NLP_NVME_DISCOVERY; | |
0709263a JS |
2262 | |
2263 | /* | |
2264 | * If prli_fba is set, the Target supports FirstBurst. | |
2265 | * If prli_fb_sz is 0, the FirstBurst size is unlimited, | |
2266 | * otherwise it defines the actual size supported by | |
2267 | * the NVME Target. | |
2268 | */ | |
a0f2d3ef | 2269 | if ((bf_get_be32(prli_fba, nvpr) == 1) && |
a0f2d3ef JS |
2270 | (phba->cfg_nvme_enable_fb) && |
2271 | (!phba->nvmet_support)) { | |
2272 | /* Both sides support FB. The target's first | |
2273 | * burst size is a 512 byte encoded value. | |
2274 | */ | |
2275 | ndlp->nlp_flag |= NLP_FIRSTBURST; | |
2276 | ndlp->nvme_fb_size = bf_get_be32(prli_fb_sz, | |
2277 | nvpr); | |
0709263a JS |
2278 | |
2279 | /* Expressed in units of 512 bytes */ | |
2280 | if (ndlp->nvme_fb_size) | |
2281 | ndlp->nvme_fb_size <<= | |
2282 | LPFC_NVME_FB_SHIFT; | |
2283 | else | |
2284 | ndlp->nvme_fb_size = LPFC_NVME_MAX_FB; | |
a0f2d3ef JS |
2285 | } |
2286 | } | |
2287 | ||
a0f2d3ef JS |
2288 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC, |
2289 | "6029 NVME PRLI Cmpl w1 x%08x " | |
2290 | "w4 x%08x w5 x%08x flag x%x, " | |
2291 | "fcp_info x%x nlp_type x%x\n", | |
2292 | be32_to_cpu(nvpr->word1), | |
2293 | be32_to_cpu(nvpr->word4), | |
2294 | be32_to_cpu(nvpr->word5), | |
2295 | ndlp->nlp_flag, ndlp->nlp_fcp_info, | |
2296 | ndlp->nlp_type); | |
dea3101e | 2297 | } |
92d7f7b0 JS |
2298 | if (!(ndlp->nlp_type & NLP_FCP_TARGET) && |
2299 | (vport->port_type == LPFC_NPIV_PORT) && | |
3de2a653 | 2300 | vport->cfg_restrict_login) { |
858c9f6c | 2301 | out: |
c6adba15 | 2302 | spin_lock_irq(&ndlp->lock); |
92d7f7b0 | 2303 | ndlp->nlp_flag |= NLP_TARGET_REMOVE; |
c6adba15 | 2304 | spin_unlock_irq(&ndlp->lock); |
92d7f7b0 JS |
2305 | lpfc_issue_els_logo(vport, ndlp, 0); |
2306 | ||
2307 | ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE; | |
87af33fe | 2308 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
92d7f7b0 JS |
2309 | return ndlp->nlp_state; |
2310 | } | |
dea3101e | 2311 | |
a0f2d3ef JS |
2312 | out_err: |
2313 | /* The ndlp state cannot move to MAPPED or UNMAPPED before all PRLIs | |
2314 | * are complete. | |
2315 | */ | |
2316 | if (ndlp->fc4_prli_sent == 0) { | |
2317 | ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE; | |
2318 | if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET)) | |
2319 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE); | |
9de416ac JS |
2320 | else if (ndlp->nlp_type & |
2321 | (NLP_FCP_INITIATOR | NLP_NVME_INITIATOR)) | |
a0f2d3ef JS |
2322 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
2323 | } else | |
2324 | lpfc_printf_vlog(vport, | |
2325 | KERN_INFO, LOG_ELS, | |
2326 | "3067 PRLI's still outstanding " | |
2327 | "on x%06x - count %d, Pend Node Mode " | |
2328 | "transition...\n", | |
2329 | ndlp->nlp_DID, ndlp->fc4_prli_sent); | |
2330 | ||
c9f8735b | 2331 | return ndlp->nlp_state; |
dea3101e | 2332 | } |
2333 | ||
2334 | /*! lpfc_device_rm_prli_issue | |
92d7f7b0 JS |
2335 | * |
2336 | * \pre | |
2337 | * \post | |
2338 | * \param phba | |
2339 | * \param ndlp | |
2340 | * \param arg | |
2341 | * \param evt | |
2342 | * \return uint32_t | |
2343 | * | |
2344 | * \b Description: | |
2345 | * This routine is envoked when we a request to remove a nport we are in the | |
2346 | * process of PRLIing. We should software abort outstanding prli, unreg | |
2347 | * login, send a logout. We will change node state to UNUSED_NODE, put it | |
2348 | * on plogi list so it can be freed when LOGO completes. | |
2349 | * | |
2350 | */ | |
2351 | ||
dea3101e | 2352 | static uint32_t |
2e0fef85 JS |
2353 | lpfc_device_rm_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
2354 | void *arg, uint32_t evt) | |
dea3101e | 2355 | { |
2e0fef85 | 2356 | if (ndlp->nlp_flag & NLP_NPR_2B_DISC) { |
c6adba15 | 2357 | spin_lock_irq(&ndlp->lock); |
a0f9b48d | 2358 | ndlp->nlp_flag |= NLP_NODEV_REMOVE; |
c6adba15 | 2359 | spin_unlock_irq(&ndlp->lock); |
a0f9b48d | 2360 | return ndlp->nlp_state; |
2e0fef85 | 2361 | } else { |
a0f9b48d | 2362 | /* software abort outstanding PLOGI */ |
2e0fef85 | 2363 | lpfc_els_abort(vport->phba, ndlp); |
dea3101e | 2364 | |
2e0fef85 | 2365 | lpfc_drop_node(vport, ndlp); |
a0f9b48d JS |
2366 | return NLP_STE_FREED_NODE; |
2367 | } | |
dea3101e | 2368 | } |
2369 | ||
2370 | ||
2371 | /*! lpfc_device_recov_prli_issue | |
92d7f7b0 JS |
2372 | * |
2373 | * \pre | |
2374 | * \post | |
2375 | * \param phba | |
2376 | * \param ndlp | |
2377 | * \param arg | |
2378 | * \param evt | |
2379 | * \return uint32_t | |
2380 | * | |
2381 | * \b Description: | |
2382 | * The routine is envoked when the state of a device is unknown, like | |
2383 | * during a link down. We should remove the nodelist entry from the | |
2384 | * unmapped list, issue a UNREG_LOGIN, do a software abort of the | |
2385 | * outstanding PRLI command, then free the node entry. | |
2386 | */ | |
dea3101e | 2387 | static uint32_t |
2e0fef85 JS |
2388 | lpfc_device_recov_prli_issue(struct lpfc_vport *vport, |
2389 | struct lpfc_nodelist *ndlp, | |
2390 | void *arg, | |
2391 | uint32_t evt) | |
dea3101e | 2392 | { |
2e0fef85 JS |
2393 | struct lpfc_hba *phba = vport->phba; |
2394 | ||
bf81e9cd JT |
2395 | /* Don't do anything that disrupts the RSCN unless lpfc is unloading. */ |
2396 | if (lpfc_check_unload_and_clr_rscn(&vport->fc_flag)) | |
92d7f7b0 JS |
2397 | return ndlp->nlp_state; |
2398 | ||
dea3101e | 2399 | /* software abort outstanding PRLI */ |
07951076 | 2400 | lpfc_els_abort(phba, ndlp); |
dea3101e | 2401 | |
5024ab17 | 2402 | ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE; |
2e0fef85 | 2403 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
c6adba15 | 2404 | spin_lock_irq(&ndlp->lock); |
a0f9b48d | 2405 | ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC); |
c6adba15 | 2406 | spin_unlock_irq(&ndlp->lock); |
92d7f7b0 | 2407 | lpfc_disc_set_adisc(vport, ndlp); |
c9f8735b | 2408 | return ndlp->nlp_state; |
dea3101e | 2409 | } |
2410 | ||
086a345f JS |
2411 | static uint32_t |
2412 | lpfc_rcv_plogi_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, | |
2413 | void *arg, uint32_t evt) | |
2414 | { | |
2415 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg; | |
2416 | struct ls_rjt stat; | |
2417 | ||
2418 | memset(&stat, 0, sizeof(struct ls_rjt)); | |
2419 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; | |
2420 | stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE; | |
2421 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); | |
2422 | return ndlp->nlp_state; | |
2423 | } | |
2424 | ||
2425 | static uint32_t | |
2426 | lpfc_rcv_prli_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, | |
2427 | void *arg, uint32_t evt) | |
2428 | { | |
2429 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg; | |
2430 | struct ls_rjt stat; | |
2431 | ||
2432 | memset(&stat, 0, sizeof(struct ls_rjt)); | |
2433 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; | |
2434 | stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE; | |
2435 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); | |
2436 | return ndlp->nlp_state; | |
2437 | } | |
2438 | ||
2439 | static uint32_t | |
2440 | lpfc_rcv_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, | |
2441 | void *arg, uint32_t evt) | |
2442 | { | |
086a345f JS |
2443 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg; |
2444 | ||
c6adba15 | 2445 | spin_lock_irq(&ndlp->lock); |
7c5e518c | 2446 | ndlp->nlp_flag |= NLP_LOGO_ACC; |
c6adba15 | 2447 | spin_unlock_irq(&ndlp->lock); |
086a345f JS |
2448 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
2449 | return ndlp->nlp_state; | |
2450 | } | |
2451 | ||
2452 | static uint32_t | |
2453 | lpfc_rcv_padisc_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, | |
2454 | void *arg, uint32_t evt) | |
2455 | { | |
2456 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg; | |
2457 | struct ls_rjt stat; | |
2458 | ||
2459 | memset(&stat, 0, sizeof(struct ls_rjt)); | |
2460 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; | |
2461 | stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE; | |
2462 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); | |
2463 | return ndlp->nlp_state; | |
2464 | } | |
2465 | ||
2466 | static uint32_t | |
2467 | lpfc_rcv_prlo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, | |
2468 | void *arg, uint32_t evt) | |
2469 | { | |
2470 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)arg; | |
2471 | struct ls_rjt stat; | |
2472 | ||
2473 | memset(&stat, 0, sizeof(struct ls_rjt)); | |
2474 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; | |
2475 | stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE; | |
2476 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); | |
2477 | return ndlp->nlp_state; | |
2478 | } | |
2479 | ||
2480 | static uint32_t | |
2481 | lpfc_cmpl_logo_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, | |
2482 | void *arg, uint32_t evt) | |
2483 | { | |
086a345f JS |
2484 | ndlp->nlp_prev_state = NLP_STE_LOGO_ISSUE; |
2485 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); | |
c6adba15 | 2486 | spin_lock_irq(&ndlp->lock); |
086a345f | 2487 | ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC); |
c6adba15 | 2488 | spin_unlock_irq(&ndlp->lock); |
086a345f JS |
2489 | lpfc_disc_set_adisc(vport, ndlp); |
2490 | return ndlp->nlp_state; | |
2491 | } | |
2492 | ||
2493 | static uint32_t | |
2494 | lpfc_device_rm_logo_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, | |
2495 | void *arg, uint32_t evt) | |
2496 | { | |
2497 | /* | |
d2aa4876 DK |
2498 | * DevLoss has timed out and is calling for Device Remove. |
2499 | * In this case, abort the LOGO and cleanup the ndlp | |
086a345f | 2500 | */ |
d2aa4876 DK |
2501 | |
2502 | lpfc_unreg_rpi(vport, ndlp); | |
2503 | /* software abort outstanding PLOGI */ | |
2504 | lpfc_els_abort(vport->phba, ndlp); | |
2505 | lpfc_drop_node(vport, ndlp); | |
2506 | return NLP_STE_FREED_NODE; | |
086a345f JS |
2507 | } |
2508 | ||
2509 | static uint32_t | |
2510 | lpfc_device_recov_logo_issue(struct lpfc_vport *vport, | |
2511 | struct lpfc_nodelist *ndlp, | |
2512 | void *arg, uint32_t evt) | |
2513 | { | |
2514 | /* | |
2515 | * Device Recovery events have no meaning for a node with a LOGO | |
2516 | * outstanding. The LOGO has to complete first and handle the | |
2517 | * node from that point. | |
2518 | */ | |
2519 | return ndlp->nlp_state; | |
2520 | } | |
2521 | ||
dea3101e | 2522 | static uint32_t |
2e0fef85 JS |
2523 | lpfc_rcv_plogi_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
2524 | void *arg, uint32_t evt) | |
dea3101e | 2525 | { |
2e0fef85 | 2526 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; |
dea3101e | 2527 | |
2e0fef85 | 2528 | lpfc_rcv_plogi(vport, ndlp, cmdiocb); |
c9f8735b | 2529 | return ndlp->nlp_state; |
dea3101e | 2530 | } |
2531 | ||
2532 | static uint32_t | |
2e0fef85 JS |
2533 | lpfc_rcv_prli_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
2534 | void *arg, uint32_t evt) | |
dea3101e | 2535 | { |
2e0fef85 | 2536 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; |
dea3101e | 2537 | |
b95e29b7 JS |
2538 | if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb)) |
2539 | return ndlp->nlp_state; | |
2540 | ||
2e0fef85 JS |
2541 | lpfc_rcv_prli(vport, ndlp, cmdiocb); |
2542 | lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp); | |
c9f8735b | 2543 | return ndlp->nlp_state; |
dea3101e | 2544 | } |
2545 | ||
2546 | static uint32_t | |
2e0fef85 JS |
2547 | lpfc_rcv_logo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
2548 | void *arg, uint32_t evt) | |
dea3101e | 2549 | { |
2e0fef85 | 2550 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; |
dea3101e | 2551 | |
2e0fef85 | 2552 | lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO); |
c9f8735b | 2553 | return ndlp->nlp_state; |
dea3101e | 2554 | } |
2555 | ||
2556 | static uint32_t | |
2e0fef85 JS |
2557 | lpfc_rcv_padisc_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
2558 | void *arg, uint32_t evt) | |
dea3101e | 2559 | { |
2e0fef85 | 2560 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; |
dea3101e | 2561 | |
2e0fef85 | 2562 | lpfc_rcv_padisc(vport, ndlp, cmdiocb); |
c9f8735b | 2563 | return ndlp->nlp_state; |
dea3101e | 2564 | } |
2565 | ||
2566 | static uint32_t | |
2e0fef85 JS |
2567 | lpfc_rcv_prlo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
2568 | void *arg, uint32_t evt) | |
dea3101e | 2569 | { |
2e0fef85 | 2570 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; |
dea3101e | 2571 | |
51ef4c26 | 2572 | lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL); |
c9f8735b | 2573 | return ndlp->nlp_state; |
dea3101e | 2574 | } |
2575 | ||
debbc1e2 JS |
2576 | static uint32_t |
2577 | lpfc_device_rm_unmap_node(struct lpfc_vport *vport, | |
2578 | struct lpfc_nodelist *ndlp, | |
2579 | void *arg, | |
2580 | uint32_t evt) | |
2581 | { | |
2582 | lpfc_drop_node(vport, ndlp); | |
2583 | return NLP_STE_FREED_NODE; | |
2584 | } | |
2585 | ||
dea3101e | 2586 | static uint32_t |
2e0fef85 JS |
2587 | lpfc_device_recov_unmap_node(struct lpfc_vport *vport, |
2588 | struct lpfc_nodelist *ndlp, | |
2589 | void *arg, | |
2590 | uint32_t evt) | |
dea3101e | 2591 | { |
5024ab17 | 2592 | ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE; |
2e0fef85 | 2593 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
c6adba15 | 2594 | spin_lock_irq(&ndlp->lock); |
a0f9b48d | 2595 | ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC); |
01a8aed6 | 2596 | ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME); |
c6adba15 | 2597 | spin_unlock_irq(&ndlp->lock); |
2e0fef85 | 2598 | lpfc_disc_set_adisc(vport, ndlp); |
dea3101e | 2599 | |
c9f8735b | 2600 | return ndlp->nlp_state; |
dea3101e | 2601 | } |
2602 | ||
2603 | static uint32_t | |
2e0fef85 JS |
2604 | lpfc_rcv_plogi_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
2605 | void *arg, uint32_t evt) | |
dea3101e | 2606 | { |
2e0fef85 | 2607 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; |
dea3101e | 2608 | |
2e0fef85 | 2609 | lpfc_rcv_plogi(vport, ndlp, cmdiocb); |
c9f8735b | 2610 | return ndlp->nlp_state; |
dea3101e | 2611 | } |
2612 | ||
2613 | static uint32_t | |
2e0fef85 JS |
2614 | lpfc_rcv_prli_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
2615 | void *arg, uint32_t evt) | |
dea3101e | 2616 | { |
2e0fef85 | 2617 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; |
dea3101e | 2618 | |
b95e29b7 JS |
2619 | if (!lpfc_rcv_prli_support_check(vport, ndlp, cmdiocb)) |
2620 | return ndlp->nlp_state; | |
2e0fef85 | 2621 | lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp); |
c9f8735b | 2622 | return ndlp->nlp_state; |
dea3101e | 2623 | } |
2624 | ||
2625 | static uint32_t | |
2e0fef85 JS |
2626 | lpfc_rcv_logo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
2627 | void *arg, uint32_t evt) | |
dea3101e | 2628 | { |
2e0fef85 | 2629 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; |
dea3101e | 2630 | |
2e0fef85 | 2631 | lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO); |
c9f8735b | 2632 | return ndlp->nlp_state; |
dea3101e | 2633 | } |
2634 | ||
2635 | static uint32_t | |
2e0fef85 JS |
2636 | lpfc_rcv_padisc_mapped_node(struct lpfc_vport *vport, |
2637 | struct lpfc_nodelist *ndlp, | |
2638 | void *arg, uint32_t evt) | |
dea3101e | 2639 | { |
2e0fef85 | 2640 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; |
dea3101e | 2641 | |
2e0fef85 | 2642 | lpfc_rcv_padisc(vport, ndlp, cmdiocb); |
c9f8735b | 2643 | return ndlp->nlp_state; |
dea3101e | 2644 | } |
2645 | ||
2646 | static uint32_t | |
2e0fef85 JS |
2647 | lpfc_rcv_prlo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
2648 | void *arg, uint32_t evt) | |
dea3101e | 2649 | { |
2e0fef85 | 2650 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; |
dea3101e | 2651 | |
2652 | /* flush the target */ | |
078c68b8 | 2653 | lpfc_sli_abort_iocb(vport, ndlp->nlp_sid, 0, LPFC_CTX_TGT); |
dea3101e | 2654 | |
1f0f7679 JT |
2655 | /* Send PRLO_ACC */ |
2656 | spin_lock_irq(&ndlp->lock); | |
2657 | ndlp->nlp_flag |= NLP_LOGO_ACC; | |
2658 | spin_unlock_irq(&ndlp->lock); | |
2659 | lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL); | |
2660 | ||
2661 | /* Save ELS_CMD_PRLO as the last elscmd and then set to NPR. | |
2662 | * lpfc_cmpl_els_logo_acc is expected to restart discovery. | |
2663 | */ | |
2664 | ndlp->nlp_last_elscmd = ELS_CMD_PRLO; | |
2665 | ndlp->nlp_prev_state = ndlp->nlp_state; | |
2666 | ||
2667 | lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_ELS | LOG_DISCOVERY, | |
2668 | "3422 DID x%06x nflag x%x lastels x%x ref cnt %u\n", | |
2669 | ndlp->nlp_DID, ndlp->nlp_flag, | |
2670 | ndlp->nlp_last_elscmd, | |
2671 | kref_read(&ndlp->kref)); | |
2672 | ||
2673 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); | |
2674 | ||
c9f8735b | 2675 | return ndlp->nlp_state; |
dea3101e | 2676 | } |
2677 | ||
2678 | static uint32_t | |
2e0fef85 JS |
2679 | lpfc_device_recov_mapped_node(struct lpfc_vport *vport, |
2680 | struct lpfc_nodelist *ndlp, | |
2681 | void *arg, | |
2682 | uint32_t evt) | |
dea3101e | 2683 | { |
06145683 JS |
2684 | lpfc_disc_set_adisc(vport, ndlp); |
2685 | ||
5024ab17 | 2686 | ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE; |
2e0fef85 | 2687 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
c6adba15 | 2688 | spin_lock_irq(&ndlp->lock); |
a0f9b48d | 2689 | ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC); |
01a8aed6 | 2690 | ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME); |
c6adba15 | 2691 | spin_unlock_irq(&ndlp->lock); |
c9f8735b | 2692 | return ndlp->nlp_state; |
dea3101e | 2693 | } |
2694 | ||
2695 | static uint32_t | |
2e0fef85 JS |
2696 | lpfc_rcv_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
2697 | void *arg, uint32_t evt) | |
dea3101e | 2698 | { |
2e0fef85 | 2699 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; |
dea3101e | 2700 | |
2701 | /* Ignore PLOGI if we have an outstanding LOGO */ | |
0d2b6b83 | 2702 | if (ndlp->nlp_flag & (NLP_LOGO_SND | NLP_LOGO_ACC)) |
c9f8735b | 2703 | return ndlp->nlp_state; |
2e0fef85 | 2704 | if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) { |
0d2b6b83 | 2705 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
c6adba15 | 2706 | spin_lock_irq(&ndlp->lock); |
0d2b6b83 | 2707 | ndlp->nlp_flag &= ~(NLP_NPR_ADISC | NLP_NPR_2B_DISC); |
c6adba15 | 2708 | spin_unlock_irq(&ndlp->lock); |
0d2b6b83 JS |
2709 | } else if (!(ndlp->nlp_flag & NLP_NPR_2B_DISC)) { |
2710 | /* send PLOGI immediately, move to PLOGI issue state */ | |
2711 | if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) { | |
2712 | ndlp->nlp_prev_state = NLP_STE_NPR_NODE; | |
2713 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); | |
2714 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); | |
2715 | } | |
dea3101e | 2716 | } |
c9f8735b | 2717 | return ndlp->nlp_state; |
dea3101e | 2718 | } |
2719 | ||
2720 | static uint32_t | |
2e0fef85 JS |
2721 | lpfc_rcv_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
2722 | void *arg, uint32_t evt) | |
dea3101e | 2723 | { |
2e0fef85 JS |
2724 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; |
2725 | struct ls_rjt stat; | |
dea3101e | 2726 | |
2727 | memset(&stat, 0, sizeof (struct ls_rjt)); | |
2728 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; | |
2729 | stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE; | |
858c9f6c | 2730 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
dea3101e | 2731 | |
2732 | if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) { | |
ab803860 JS |
2733 | /* |
2734 | * ADISC nodes will be handled in regular discovery path after | |
2735 | * receiving response from NS. | |
2736 | * | |
2737 | * For other nodes, Send PLOGI to trigger an implicit LOGO. | |
2738 | */ | |
2739 | if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) { | |
5024ab17 | 2740 | ndlp->nlp_prev_state = NLP_STE_NPR_NODE; |
2e0fef85 JS |
2741 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
2742 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); | |
dea3101e | 2743 | } |
2744 | } | |
c9f8735b | 2745 | return ndlp->nlp_state; |
dea3101e | 2746 | } |
2747 | ||
2748 | static uint32_t | |
2e0fef85 JS |
2749 | lpfc_rcv_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
2750 | void *arg, uint32_t evt) | |
dea3101e | 2751 | { |
2e0fef85 | 2752 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; |
dea3101e | 2753 | |
2e0fef85 | 2754 | lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO); |
c9f8735b | 2755 | return ndlp->nlp_state; |
dea3101e | 2756 | } |
2757 | ||
2758 | static uint32_t | |
2e0fef85 JS |
2759 | lpfc_rcv_padisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
2760 | void *arg, uint32_t evt) | |
dea3101e | 2761 | { |
2e0fef85 | 2762 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; |
dea3101e | 2763 | |
2e0fef85 | 2764 | lpfc_rcv_padisc(vport, ndlp, cmdiocb); |
33ccf8d1 JS |
2765 | /* |
2766 | * Do not start discovery if discovery is about to start | |
2767 | * or discovery in progress for this node. Starting discovery | |
2768 | * here will affect the counting of discovery threads. | |
2769 | */ | |
2fb9bd8b | 2770 | if (!(ndlp->nlp_flag & NLP_DELAY_TMO) && |
92d7f7b0 | 2771 | !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) { |
ab803860 JS |
2772 | /* |
2773 | * ADISC nodes will be handled in regular discovery path after | |
2774 | * receiving response from NS. | |
2775 | * | |
2776 | * For other nodes, Send PLOGI to trigger an implicit LOGO. | |
2777 | */ | |
2778 | if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) { | |
5024ab17 | 2779 | ndlp->nlp_prev_state = NLP_STE_NPR_NODE; |
2e0fef85 JS |
2780 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
2781 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); | |
dea3101e | 2782 | } |
2783 | } | |
c9f8735b | 2784 | return ndlp->nlp_state; |
dea3101e | 2785 | } |
2786 | ||
2787 | static uint32_t | |
2e0fef85 JS |
2788 | lpfc_rcv_prlo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
2789 | void *arg, uint32_t evt) | |
dea3101e | 2790 | { |
2e0fef85 | 2791 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; |
dea3101e | 2792 | |
c6adba15 | 2793 | spin_lock_irq(&ndlp->lock); |
c9f8735b | 2794 | ndlp->nlp_flag |= NLP_LOGO_ACC; |
c6adba15 | 2795 | spin_unlock_irq(&ndlp->lock); |
c9f8735b | 2796 | |
51ef4c26 | 2797 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
dea3101e | 2798 | |
2e0fef85 | 2799 | if ((ndlp->nlp_flag & NLP_DELAY_TMO) == 0) { |
256ec0d0 JS |
2800 | mod_timer(&ndlp->nlp_delayfunc, |
2801 | jiffies + msecs_to_jiffies(1000 * 1)); | |
c6adba15 | 2802 | spin_lock_irq(&ndlp->lock); |
c9f8735b JW |
2803 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
2804 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; | |
c6adba15 | 2805 | spin_unlock_irq(&ndlp->lock); |
5024ab17 | 2806 | ndlp->nlp_last_elscmd = ELS_CMD_PLOGI; |
c9f8735b | 2807 | } else { |
c6adba15 | 2808 | spin_lock_irq(&ndlp->lock); |
c9f8735b | 2809 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
c6adba15 | 2810 | spin_unlock_irq(&ndlp->lock); |
dea3101e | 2811 | } |
c9f8735b JW |
2812 | return ndlp->nlp_state; |
2813 | } | |
dea3101e | 2814 | |
c9f8735b | 2815 | static uint32_t |
2e0fef85 JS |
2816 | lpfc_cmpl_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
2817 | void *arg, uint32_t evt) | |
c9f8735b | 2818 | { |
cad93a08 | 2819 | struct lpfc_hba *phba = vport->phba; |
c9f8735b | 2820 | struct lpfc_iocbq *cmdiocb, *rspiocb; |
cad93a08 | 2821 | u32 ulp_status; |
c9f8735b JW |
2822 | |
2823 | cmdiocb = (struct lpfc_iocbq *) arg; | |
d51cf5bd | 2824 | rspiocb = cmdiocb->rsp_iocb; |
a0f9b48d | 2825 | |
cad93a08 JS |
2826 | ulp_status = get_job_ulpstatus(phba, rspiocb); |
2827 | ||
2828 | if (ulp_status) | |
a0f9b48d | 2829 | return NLP_STE_FREED_NODE; |
cad93a08 | 2830 | |
c9f8735b JW |
2831 | return ndlp->nlp_state; |
2832 | } | |
2833 | ||
2834 | static uint32_t | |
2e0fef85 JS |
2835 | lpfc_cmpl_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
2836 | void *arg, uint32_t evt) | |
c9f8735b | 2837 | { |
cad93a08 | 2838 | struct lpfc_hba *phba = vport->phba; |
c9f8735b | 2839 | struct lpfc_iocbq *cmdiocb, *rspiocb; |
cad93a08 | 2840 | u32 ulp_status; |
c9f8735b JW |
2841 | |
2842 | cmdiocb = (struct lpfc_iocbq *) arg; | |
d51cf5bd | 2843 | rspiocb = cmdiocb->rsp_iocb; |
a0f9b48d | 2844 | |
cad93a08 JS |
2845 | ulp_status = get_job_ulpstatus(phba, rspiocb); |
2846 | ||
2847 | if (ulp_status && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) { | |
2e0fef85 | 2848 | lpfc_drop_node(vport, ndlp); |
a0f9b48d JS |
2849 | return NLP_STE_FREED_NODE; |
2850 | } | |
c9f8735b | 2851 | return ndlp->nlp_state; |
dea3101e | 2852 | } |
2853 | ||
2854 | static uint32_t | |
2e0fef85 JS |
2855 | lpfc_cmpl_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
2856 | void *arg, uint32_t evt) | |
dea3101e | 2857 | { |
086a345f | 2858 | /* For the fabric port just clear the fc flags. */ |
d7c255b2 | 2859 | if (ndlp->nlp_DID == Fabric_DID) { |
a645b8c1 JT |
2860 | clear_bit(FC_FABRIC, &vport->fc_flag); |
2861 | clear_bit(FC_PUBLIC_LOOP, &vport->fc_flag); | |
d7c255b2 | 2862 | } |
2e0fef85 | 2863 | lpfc_unreg_rpi(vport, ndlp); |
c9f8735b JW |
2864 | return ndlp->nlp_state; |
2865 | } | |
2866 | ||
2867 | static uint32_t | |
2e0fef85 JS |
2868 | lpfc_cmpl_adisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
2869 | void *arg, uint32_t evt) | |
c9f8735b | 2870 | { |
cad93a08 | 2871 | struct lpfc_hba *phba = vport->phba; |
c9f8735b | 2872 | struct lpfc_iocbq *cmdiocb, *rspiocb; |
cad93a08 | 2873 | u32 ulp_status; |
c9f8735b JW |
2874 | |
2875 | cmdiocb = (struct lpfc_iocbq *) arg; | |
d51cf5bd | 2876 | rspiocb = cmdiocb->rsp_iocb; |
a0f9b48d | 2877 | |
cad93a08 JS |
2878 | ulp_status = get_job_ulpstatus(phba, rspiocb); |
2879 | ||
2880 | if (ulp_status && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) { | |
2e0fef85 | 2881 | lpfc_drop_node(vport, ndlp); |
a0f9b48d JS |
2882 | return NLP_STE_FREED_NODE; |
2883 | } | |
c9f8735b | 2884 | return ndlp->nlp_state; |
dea3101e | 2885 | } |
2886 | ||
2887 | static uint32_t | |
2e0fef85 JS |
2888 | lpfc_cmpl_reglogin_npr_node(struct lpfc_vport *vport, |
2889 | struct lpfc_nodelist *ndlp, | |
2890 | void *arg, uint32_t evt) | |
dea3101e | 2891 | { |
2e0fef85 | 2892 | LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg; |
04c68496 | 2893 | MAILBOX_t *mb = &pmb->u.mb; |
dea3101e | 2894 | |
04c68496 | 2895 | if (!mb->mbxStatus) { |
6d368e53 JS |
2896 | /* SLI4 ports have preallocated logical rpis. */ |
2897 | if (vport->phba->sli_rev < LPFC_SLI_REV4) | |
2898 | ndlp->nlp_rpi = mb->un.varWords[0]; | |
4042629e | 2899 | ndlp->nlp_flag |= NLP_RPI_REGISTERED; |
4b7789b7 JS |
2900 | if (ndlp->nlp_flag & NLP_LOGO_ACC) { |
2901 | lpfc_unreg_rpi(vport, ndlp); | |
2902 | } | |
04c68496 | 2903 | } else { |
a0f9b48d | 2904 | if (ndlp->nlp_flag & NLP_NODEV_REMOVE) { |
2e0fef85 | 2905 | lpfc_drop_node(vport, ndlp); |
a0f9b48d JS |
2906 | return NLP_STE_FREED_NODE; |
2907 | } | |
2908 | } | |
c9f8735b | 2909 | return ndlp->nlp_state; |
dea3101e | 2910 | } |
2911 | ||
2912 | static uint32_t | |
2e0fef85 JS |
2913 | lpfc_device_rm_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
2914 | void *arg, uint32_t evt) | |
dea3101e | 2915 | { |
a0f9b48d | 2916 | if (ndlp->nlp_flag & NLP_NPR_2B_DISC) { |
c6adba15 | 2917 | spin_lock_irq(&ndlp->lock); |
a0f9b48d | 2918 | ndlp->nlp_flag |= NLP_NODEV_REMOVE; |
c6adba15 | 2919 | spin_unlock_irq(&ndlp->lock); |
a0f9b48d JS |
2920 | return ndlp->nlp_state; |
2921 | } | |
2e0fef85 | 2922 | lpfc_drop_node(vport, ndlp); |
c9f8735b | 2923 | return NLP_STE_FREED_NODE; |
dea3101e | 2924 | } |
2925 | ||
2926 | static uint32_t | |
2e0fef85 JS |
2927 | lpfc_device_recov_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
2928 | void *arg, uint32_t evt) | |
dea3101e | 2929 | { |
bf81e9cd JT |
2930 | /* Don't do anything that disrupts the RSCN unless lpfc is unloading. */ |
2931 | if (lpfc_check_unload_and_clr_rscn(&vport->fc_flag)) | |
92d7f7b0 JS |
2932 | return ndlp->nlp_state; |
2933 | ||
eaf15d5b | 2934 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
c6adba15 | 2935 | spin_lock_irq(&ndlp->lock); |
a0f9b48d | 2936 | ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC); |
01a8aed6 | 2937 | ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME); |
c6adba15 | 2938 | spin_unlock_irq(&ndlp->lock); |
c9f8735b | 2939 | return ndlp->nlp_state; |
dea3101e | 2940 | } |
2941 | ||
2942 | ||
2943 | /* This next section defines the NPort Discovery State Machine */ | |
2944 | ||
2945 | /* There are 4 different double linked lists nodelist entries can reside on. | |
2946 | * The plogi list and adisc list are used when Link Up discovery or RSCN | |
2947 | * processing is needed. Each list holds the nodes that we will send PLOGI | |
2948 | * or ADISC on. These lists will keep track of what nodes will be effected | |
2949 | * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up). | |
2950 | * The unmapped_list will contain all nodes that we have successfully logged | |
2951 | * into at the Fibre Channel level. The mapped_list will contain all nodes | |
2952 | * that are mapped FCP targets. | |
2953 | */ | |
2954 | /* | |
2955 | * The bind list is a list of undiscovered (potentially non-existent) nodes | |
2956 | * that we have saved binding information on. This information is used when | |
2957 | * nodes transition from the unmapped to the mapped list. | |
2958 | */ | |
2959 | /* For UNUSED_NODE state, the node has just been allocated . | |
2960 | * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on | |
2961 | * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list | |
2962 | * and put on the unmapped list. For ADISC processing, the node is taken off | |
2963 | * the ADISC list and placed on either the mapped or unmapped list (depending | |
2964 | * on its previous state). Once on the unmapped list, a PRLI is issued and the | |
2965 | * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is | |
2966 | * changed to UNMAPPED_NODE. If the completion indicates a mapped | |
2967 | * node, the node is taken off the unmapped list. The binding list is checked | |
2968 | * for a valid binding, or a binding is automatically assigned. If binding | |
2969 | * assignment is unsuccessful, the node is left on the unmapped list. If | |
2970 | * binding assignment is successful, the associated binding list entry (if | |
2971 | * any) is removed, and the node is placed on the mapped list. | |
2972 | */ | |
2973 | /* | |
2974 | * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped | |
c01f3208 | 2975 | * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers |
dea3101e | 2976 | * expire, all effected nodes will receive a DEVICE_RM event. |
2977 | */ | |
2978 | /* | |
2979 | * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists | |
2980 | * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap | |
2981 | * check, additional nodes may be added or removed (via DEVICE_RM) to / from | |
2982 | * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated, | |
2983 | * we will first process the ADISC list. 32 entries are processed initially and | |
2984 | * ADISC is initited for each one. Completions / Events for each node are | |
2985 | * funnelled thru the state machine. As each node finishes ADISC processing, it | |
2986 | * starts ADISC for any nodes waiting for ADISC processing. If no nodes are | |
2987 | * waiting, and the ADISC list count is identically 0, then we are done. For | |
2988 | * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we | |
2989 | * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI | |
2990 | * list. 32 entries are processed initially and PLOGI is initited for each one. | |
2991 | * Completions / Events for each node are funnelled thru the state machine. As | |
2992 | * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting | |
2993 | * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is | |
2994 | * indentically 0, then we are done. We have now completed discovery / RSCN | |
2995 | * handling. Upon completion, ALL nodes should be on either the mapped or | |
2996 | * unmapped lists. | |
2997 | */ | |
2998 | ||
2999 | static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT]) | |
2e0fef85 | 3000 | (struct lpfc_vport *, struct lpfc_nodelist *, void *, uint32_t) = { |
dea3101e | 3001 | /* Action routine Event Current State */ |
3002 | lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */ | |
3003 | lpfc_rcv_els_unused_node, /* RCV_PRLI */ | |
3004 | lpfc_rcv_logo_unused_node, /* RCV_LOGO */ | |
3005 | lpfc_rcv_els_unused_node, /* RCV_ADISC */ | |
3006 | lpfc_rcv_els_unused_node, /* RCV_PDISC */ | |
3007 | lpfc_rcv_els_unused_node, /* RCV_PRLO */ | |
3008 | lpfc_disc_illegal, /* CMPL_PLOGI */ | |
3009 | lpfc_disc_illegal, /* CMPL_PRLI */ | |
3010 | lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */ | |
3011 | lpfc_disc_illegal, /* CMPL_ADISC */ | |
3012 | lpfc_disc_illegal, /* CMPL_REG_LOGIN */ | |
3013 | lpfc_device_rm_unused_node, /* DEVICE_RM */ | |
df9e1b59 | 3014 | lpfc_device_recov_unused_node, /* DEVICE_RECOVERY */ |
dea3101e | 3015 | |
3016 | lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */ | |
92d7f7b0 | 3017 | lpfc_rcv_prli_plogi_issue, /* RCV_PRLI */ |
c9f8735b | 3018 | lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */ |
dea3101e | 3019 | lpfc_rcv_els_plogi_issue, /* RCV_ADISC */ |
3020 | lpfc_rcv_els_plogi_issue, /* RCV_PDISC */ | |
3021 | lpfc_rcv_els_plogi_issue, /* RCV_PRLO */ | |
3022 | lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */ | |
3023 | lpfc_disc_illegal, /* CMPL_PRLI */ | |
0ff10d46 | 3024 | lpfc_cmpl_logo_plogi_issue, /* CMPL_LOGO */ |
dea3101e | 3025 | lpfc_disc_illegal, /* CMPL_ADISC */ |
0ff10d46 | 3026 | lpfc_cmpl_reglogin_plogi_issue,/* CMPL_REG_LOGIN */ |
dea3101e | 3027 | lpfc_device_rm_plogi_issue, /* DEVICE_RM */ |
3028 | lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */ | |
3029 | ||
3030 | lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */ | |
3031 | lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */ | |
3032 | lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */ | |
3033 | lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */ | |
3034 | lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */ | |
3035 | lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */ | |
3036 | lpfc_disc_illegal, /* CMPL_PLOGI */ | |
3037 | lpfc_disc_illegal, /* CMPL_PRLI */ | |
3038 | lpfc_disc_illegal, /* CMPL_LOGO */ | |
3039 | lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */ | |
3040 | lpfc_disc_illegal, /* CMPL_REG_LOGIN */ | |
3041 | lpfc_device_rm_adisc_issue, /* DEVICE_RM */ | |
3042 | lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */ | |
3043 | ||
3044 | lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */ | |
3045 | lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */ | |
3046 | lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */ | |
3047 | lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */ | |
3048 | lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */ | |
3049 | lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */ | |
87af33fe | 3050 | lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */ |
dea3101e | 3051 | lpfc_disc_illegal, /* CMPL_PRLI */ |
3052 | lpfc_disc_illegal, /* CMPL_LOGO */ | |
3053 | lpfc_disc_illegal, /* CMPL_ADISC */ | |
3054 | lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */ | |
3055 | lpfc_device_rm_reglogin_issue, /* DEVICE_RM */ | |
3056 | lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */ | |
3057 | ||
3058 | lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */ | |
3059 | lpfc_rcv_prli_prli_issue, /* RCV_PRLI */ | |
3060 | lpfc_rcv_logo_prli_issue, /* RCV_LOGO */ | |
3061 | lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */ | |
3062 | lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */ | |
3063 | lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */ | |
87af33fe | 3064 | lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */ |
dea3101e | 3065 | lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */ |
3066 | lpfc_disc_illegal, /* CMPL_LOGO */ | |
3067 | lpfc_disc_illegal, /* CMPL_ADISC */ | |
3068 | lpfc_disc_illegal, /* CMPL_REG_LOGIN */ | |
3069 | lpfc_device_rm_prli_issue, /* DEVICE_RM */ | |
3070 | lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */ | |
3071 | ||
086a345f JS |
3072 | lpfc_rcv_plogi_logo_issue, /* RCV_PLOGI LOGO_ISSUE */ |
3073 | lpfc_rcv_prli_logo_issue, /* RCV_PRLI */ | |
3074 | lpfc_rcv_logo_logo_issue, /* RCV_LOGO */ | |
3075 | lpfc_rcv_padisc_logo_issue, /* RCV_ADISC */ | |
3076 | lpfc_rcv_padisc_logo_issue, /* RCV_PDISC */ | |
3077 | lpfc_rcv_prlo_logo_issue, /* RCV_PRLO */ | |
3078 | lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */ | |
3079 | lpfc_disc_illegal, /* CMPL_PRLI */ | |
3080 | lpfc_cmpl_logo_logo_issue, /* CMPL_LOGO */ | |
3081 | lpfc_disc_illegal, /* CMPL_ADISC */ | |
3082 | lpfc_disc_illegal, /* CMPL_REG_LOGIN */ | |
3083 | lpfc_device_rm_logo_issue, /* DEVICE_RM */ | |
3084 | lpfc_device_recov_logo_issue, /* DEVICE_RECOVERY */ | |
3085 | ||
dea3101e | 3086 | lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */ |
3087 | lpfc_rcv_prli_unmap_node, /* RCV_PRLI */ | |
3088 | lpfc_rcv_logo_unmap_node, /* RCV_LOGO */ | |
3089 | lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */ | |
3090 | lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */ | |
3091 | lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */ | |
3092 | lpfc_disc_illegal, /* CMPL_PLOGI */ | |
3093 | lpfc_disc_illegal, /* CMPL_PRLI */ | |
3094 | lpfc_disc_illegal, /* CMPL_LOGO */ | |
3095 | lpfc_disc_illegal, /* CMPL_ADISC */ | |
3096 | lpfc_disc_illegal, /* CMPL_REG_LOGIN */ | |
debbc1e2 | 3097 | lpfc_device_rm_unmap_node, /* DEVICE_RM */ |
dea3101e | 3098 | lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */ |
3099 | ||
3100 | lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */ | |
3101 | lpfc_rcv_prli_mapped_node, /* RCV_PRLI */ | |
3102 | lpfc_rcv_logo_mapped_node, /* RCV_LOGO */ | |
3103 | lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */ | |
3104 | lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */ | |
3105 | lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */ | |
3106 | lpfc_disc_illegal, /* CMPL_PLOGI */ | |
3107 | lpfc_disc_illegal, /* CMPL_PRLI */ | |
3108 | lpfc_disc_illegal, /* CMPL_LOGO */ | |
3109 | lpfc_disc_illegal, /* CMPL_ADISC */ | |
3110 | lpfc_disc_illegal, /* CMPL_REG_LOGIN */ | |
3111 | lpfc_disc_illegal, /* DEVICE_RM */ | |
3112 | lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */ | |
3113 | ||
3114 | lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */ | |
3115 | lpfc_rcv_prli_npr_node, /* RCV_PRLI */ | |
3116 | lpfc_rcv_logo_npr_node, /* RCV_LOGO */ | |
3117 | lpfc_rcv_padisc_npr_node, /* RCV_ADISC */ | |
3118 | lpfc_rcv_padisc_npr_node, /* RCV_PDISC */ | |
3119 | lpfc_rcv_prlo_npr_node, /* RCV_PRLO */ | |
c9f8735b JW |
3120 | lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */ |
3121 | lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */ | |
dea3101e | 3122 | lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */ |
c9f8735b | 3123 | lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */ |
dea3101e | 3124 | lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */ |
3125 | lpfc_device_rm_npr_node, /* DEVICE_RM */ | |
3126 | lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */ | |
3127 | }; | |
3128 | ||
3129 | int | |
2e0fef85 JS |
3130 | lpfc_disc_state_machine(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
3131 | void *arg, uint32_t evt) | |
dea3101e | 3132 | { |
3133 | uint32_t cur_state, rc; | |
2e0fef85 | 3134 | uint32_t(*func) (struct lpfc_vport *, struct lpfc_nodelist *, void *, |
dea3101e | 3135 | uint32_t); |
e47c9093 | 3136 | uint32_t got_ndlp = 0; |
26d824ca | 3137 | uint32_t data1; |
e47c9093 JS |
3138 | |
3139 | if (lpfc_nlp_get(ndlp)) | |
3140 | got_ndlp = 1; | |
dea3101e | 3141 | |
dea3101e | 3142 | cur_state = ndlp->nlp_state; |
3143 | ||
26d824ca JS |
3144 | data1 = (((uint32_t)ndlp->nlp_fc4_type << 16) | |
3145 | ((uint32_t)ndlp->nlp_type)); | |
dea3101e | 3146 | /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */ |
e8b62011 JS |
3147 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
3148 | "0211 DSM in event x%x on NPort x%x in " | |
dea16bda JS |
3149 | "state %d rpi x%x Data: x%x x%x\n", |
3150 | evt, ndlp->nlp_DID, cur_state, ndlp->nlp_rpi, | |
26d824ca | 3151 | ndlp->nlp_flag, data1); |
dea3101e | 3152 | |
858c9f6c JS |
3153 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM, |
3154 | "DSM in: evt:%d ste:%d did:x%x", | |
3155 | evt, cur_state, ndlp->nlp_DID); | |
3156 | ||
dea3101e | 3157 | func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt]; |
2e0fef85 | 3158 | rc = (func) (vport, ndlp, arg, evt); |
dea3101e | 3159 | |
3160 | /* DSM out state <rc> on NPort <nlp_DID> */ | |
e47c9093 | 3161 | if (got_ndlp) { |
26d824ca JS |
3162 | data1 = (((uint32_t)ndlp->nlp_fc4_type << 16) | |
3163 | ((uint32_t)ndlp->nlp_type)); | |
e47c9093 | 3164 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
dea16bda | 3165 | "0212 DSM out state %d on NPort x%x " |
26d824ca JS |
3166 | "rpi x%x Data: x%x x%x\n", |
3167 | rc, ndlp->nlp_DID, ndlp->nlp_rpi, ndlp->nlp_flag, | |
3168 | data1); | |
dea3101e | 3169 | |
e47c9093 JS |
3170 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM, |
3171 | "DSM out: ste:%d did:x%x flg:x%x", | |
3172 | rc, ndlp->nlp_DID, ndlp->nlp_flag); | |
3173 | /* Decrement the ndlp reference count held for this function */ | |
3174 | lpfc_nlp_put(ndlp); | |
3175 | } else { | |
3176 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, | |
d7c255b2 | 3177 | "0213 DSM out state %d on NPort free\n", rc); |
858c9f6c | 3178 | |
e47c9093 JS |
3179 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM, |
3180 | "DSM out: ste:%d did:x%x flg:x%x", | |
3181 | rc, 0, 0); | |
3182 | } | |
dea3101e | 3183 | |
c9f8735b | 3184 | return rc; |
dea3101e | 3185 | } |