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