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