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