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