]>
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. * |
e47c9093 | 4 | * Copyright (C) 2004-2008 Emulex. All rights reserved. * |
c44ce173 | 5 | * EMULEX and SLI are trademarks of Emulex. * |
dea3101e | 6 | * www.emulex.com * |
c44ce173 | 7 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
dea3101e JB |
8 | * * |
9 | * This program is free software; you can redistribute it and/or * | |
c44ce173 JSEC |
10 | * modify it under the terms of version 2 of the GNU General * |
11 | * Public License as published by the Free Software Foundation. * | |
12 | * This program is distributed in the hope that it will be useful. * | |
13 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * | |
14 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * | |
15 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * | |
16 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * | |
17 | * TO BE LEGALLY INVALID. See the GNU General Public License for * | |
18 | * more details, a copy of which can be found in the file COPYING * | |
19 | * included with this package. * | |
dea3101e JB |
20 | *******************************************************************/ |
21 | ||
dea3101e JB |
22 | #include <linux/blkdev.h> |
23 | #include <linux/pci.h> | |
24 | #include <linux/interrupt.h> | |
25 | ||
91886523 | 26 | #include <scsi/scsi.h> |
dea3101e JB |
27 | #include <scsi/scsi_device.h> |
28 | #include <scsi/scsi_host.h> | |
29 | #include <scsi/scsi_transport_fc.h> | |
30 | ||
31 | #include "lpfc_hw.h" | |
32 | #include "lpfc_sli.h" | |
33 | #include "lpfc_disc.h" | |
34 | #include "lpfc_scsi.h" | |
35 | #include "lpfc.h" | |
36 | #include "lpfc_logmsg.h" | |
37 | #include "lpfc_crtn.h" | |
92d7f7b0 | 38 | #include "lpfc_vport.h" |
858c9f6c | 39 | #include "lpfc_debugfs.h" |
dea3101e JB |
40 | |
41 | ||
42 | /* Called to verify a rcv'ed ADISC was intended for us. */ | |
43 | static int | |
2e0fef85 JS |
44 | lpfc_check_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
45 | struct lpfc_name *nn, struct lpfc_name *pn) | |
dea3101e JB |
46 | { |
47 | /* Compare the ADISC rsp WWNN / WWPN matches our internal node | |
48 | * table entry for that node. | |
49 | */ | |
2e0fef85 | 50 | if (memcmp(nn, &ndlp->nlp_nodename, sizeof (struct lpfc_name))) |
c9f8735b | 51 | return 0; |
dea3101e | 52 | |
2e0fef85 | 53 | if (memcmp(pn, &ndlp->nlp_portname, sizeof (struct lpfc_name))) |
c9f8735b | 54 | return 0; |
dea3101e JB |
55 | |
56 | /* we match, return success */ | |
c9f8735b | 57 | return 1; |
dea3101e JB |
58 | } |
59 | ||
dea3101e | 60 | int |
2e0fef85 JS |
61 | lpfc_check_sparm(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
62 | struct serv_parm * sp, uint32_t class) | |
dea3101e | 63 | { |
2e0fef85 | 64 | volatile struct serv_parm *hsp = &vport->fc_sparam; |
2fb70f79 JSEC |
65 | uint16_t hsp_value, ssp_value = 0; |
66 | ||
67 | /* | |
68 | * The receive data field size and buffer-to-buffer receive data field | |
69 | * size entries are 16 bits but are represented as two 8-bit fields in | |
70 | * the driver data structure to account for rsvd bits and other control | |
71 | * bits. Reconstruct and compare the fields as a 16-bit values before | |
72 | * correcting the byte values. | |
73 | */ | |
dea3101e | 74 | if (sp->cls1.classValid) { |
2fb70f79 JSEC |
75 | hsp_value = (hsp->cls1.rcvDataSizeMsb << 8) | |
76 | hsp->cls1.rcvDataSizeLsb; | |
77 | ssp_value = (sp->cls1.rcvDataSizeMsb << 8) | | |
78 | sp->cls1.rcvDataSizeLsb; | |
92d7f7b0 JS |
79 | if (!ssp_value) |
80 | goto bad_service_param; | |
2fb70f79 | 81 | if (ssp_value > hsp_value) { |
dea3101e | 82 | sp->cls1.rcvDataSizeLsb = hsp->cls1.rcvDataSizeLsb; |
2fb70f79 JSEC |
83 | sp->cls1.rcvDataSizeMsb = hsp->cls1.rcvDataSizeMsb; |
84 | } | |
dea3101e | 85 | } else if (class == CLASS1) { |
92d7f7b0 | 86 | goto bad_service_param; |
dea3101e JB |
87 | } |
88 | ||
89 | if (sp->cls2.classValid) { | |
2fb70f79 JSEC |
90 | hsp_value = (hsp->cls2.rcvDataSizeMsb << 8) | |
91 | hsp->cls2.rcvDataSizeLsb; | |
92 | ssp_value = (sp->cls2.rcvDataSizeMsb << 8) | | |
93 | sp->cls2.rcvDataSizeLsb; | |
92d7f7b0 JS |
94 | if (!ssp_value) |
95 | goto bad_service_param; | |
2fb70f79 | 96 | if (ssp_value > hsp_value) { |
dea3101e | 97 | sp->cls2.rcvDataSizeLsb = hsp->cls2.rcvDataSizeLsb; |
2fb70f79 JSEC |
98 | sp->cls2.rcvDataSizeMsb = hsp->cls2.rcvDataSizeMsb; |
99 | } | |
dea3101e | 100 | } else if (class == CLASS2) { |
92d7f7b0 | 101 | goto bad_service_param; |
dea3101e JB |
102 | } |
103 | ||
104 | if (sp->cls3.classValid) { | |
2fb70f79 JSEC |
105 | hsp_value = (hsp->cls3.rcvDataSizeMsb << 8) | |
106 | hsp->cls3.rcvDataSizeLsb; | |
107 | ssp_value = (sp->cls3.rcvDataSizeMsb << 8) | | |
108 | sp->cls3.rcvDataSizeLsb; | |
92d7f7b0 JS |
109 | if (!ssp_value) |
110 | goto bad_service_param; | |
2fb70f79 | 111 | if (ssp_value > hsp_value) { |
dea3101e | 112 | sp->cls3.rcvDataSizeLsb = hsp->cls3.rcvDataSizeLsb; |
2fb70f79 JSEC |
113 | sp->cls3.rcvDataSizeMsb = hsp->cls3.rcvDataSizeMsb; |
114 | } | |
dea3101e | 115 | } else if (class == CLASS3) { |
92d7f7b0 | 116 | goto bad_service_param; |
dea3101e JB |
117 | } |
118 | ||
2fb70f79 JSEC |
119 | /* |
120 | * Preserve the upper four bits of the MSB from the PLOGI response. | |
121 | * These bits contain the Buffer-to-Buffer State Change Number | |
122 | * from the target and need to be passed to the FW. | |
123 | */ | |
124 | hsp_value = (hsp->cmn.bbRcvSizeMsb << 8) | hsp->cmn.bbRcvSizeLsb; | |
125 | ssp_value = (sp->cmn.bbRcvSizeMsb << 8) | sp->cmn.bbRcvSizeLsb; | |
126 | if (ssp_value > hsp_value) { | |
dea3101e | 127 | sp->cmn.bbRcvSizeLsb = hsp->cmn.bbRcvSizeLsb; |
2fb70f79 JSEC |
128 | sp->cmn.bbRcvSizeMsb = (sp->cmn.bbRcvSizeMsb & 0xF0) | |
129 | (hsp->cmn.bbRcvSizeMsb & 0x0F); | |
130 | } | |
dea3101e | 131 | |
dea3101e JB |
132 | memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name)); |
133 | memcpy(&ndlp->nlp_portname, &sp->portName, sizeof (struct lpfc_name)); | |
2fb70f79 | 134 | return 1; |
92d7f7b0 | 135 | bad_service_param: |
e8b62011 JS |
136 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
137 | "0207 Device %x " | |
138 | "(%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x) sent " | |
139 | "invalid service parameters. Ignoring device.\n", | |
140 | ndlp->nlp_DID, | |
141 | sp->nodeName.u.wwn[0], sp->nodeName.u.wwn[1], | |
142 | sp->nodeName.u.wwn[2], sp->nodeName.u.wwn[3], | |
143 | sp->nodeName.u.wwn[4], sp->nodeName.u.wwn[5], | |
144 | sp->nodeName.u.wwn[6], sp->nodeName.u.wwn[7]); | |
92d7f7b0 | 145 | return 0; |
dea3101e JB |
146 | } |
147 | ||
148 | static void * | |
2e0fef85 | 149 | lpfc_check_elscmpl_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
92d7f7b0 | 150 | struct lpfc_iocbq *rspiocb) |
dea3101e JB |
151 | { |
152 | struct lpfc_dmabuf *pcmd, *prsp; | |
153 | uint32_t *lp; | |
154 | void *ptr = NULL; | |
155 | IOCB_t *irsp; | |
156 | ||
157 | irsp = &rspiocb->iocb; | |
158 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; | |
159 | ||
160 | /* For lpfc_els_abort, context2 could be zero'ed to delay | |
161 | * freeing associated memory till after ABTS completes. | |
162 | */ | |
163 | if (pcmd) { | |
164 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, | |
165 | list); | |
166 | if (prsp) { | |
167 | lp = (uint32_t *) prsp->virt; | |
168 | ptr = (void *)((uint8_t *)lp + sizeof(uint32_t)); | |
169 | } | |
2fe165b6 | 170 | } else { |
dea3101e JB |
171 | /* Force ulpStatus error since we are returning NULL ptr */ |
172 | if (!(irsp->ulpStatus)) { | |
173 | irsp->ulpStatus = IOSTAT_LOCAL_REJECT; | |
174 | irsp->un.ulpWord[4] = IOERR_SLI_ABORTED; | |
175 | } | |
176 | ptr = NULL; | |
177 | } | |
c9f8735b | 178 | return ptr; |
dea3101e JB |
179 | } |
180 | ||
181 | ||
182 | /* | |
183 | * Free resources / clean up outstanding I/Os | |
184 | * associated with a LPFC_NODELIST entry. This | |
185 | * routine effectively results in a "software abort". | |
186 | */ | |
187 | int | |
2e0fef85 | 188 | lpfc_els_abort(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp) |
dea3101e | 189 | { |
2534ba75 | 190 | LIST_HEAD(completions); |
2e0fef85 JS |
191 | struct lpfc_sli *psli = &phba->sli; |
192 | struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING]; | |
dea3101e | 193 | struct lpfc_iocbq *iocb, *next_iocb; |
2534ba75 | 194 | IOCB_t *cmd; |
dea3101e JB |
195 | |
196 | /* Abort outstanding I/O on NPort <nlp_DID> */ | |
e8b62011 JS |
197 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_DISCOVERY, |
198 | "0205 Abort outstanding I/O on NPort x%x " | |
199 | "Data: x%x x%x x%x\n", | |
200 | ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state, | |
201 | ndlp->nlp_rpi); | |
92d7f7b0 JS |
202 | |
203 | lpfc_fabric_abort_nport(ndlp); | |
dea3101e | 204 | |
dea3101e | 205 | /* First check the txq */ |
2e0fef85 | 206 | spin_lock_irq(&phba->hbalock); |
2534ba75 | 207 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
858c9f6c | 208 | /* Check to see if iocb matches the nport we are looking for */ |
2534ba75 | 209 | if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) { |
858c9f6c | 210 | /* It matches, so deque and call compl with anp error */ |
2534ba75 JS |
211 | list_move_tail(&iocb->list, &completions); |
212 | pring->txq_cnt--; | |
dea3101e | 213 | } |
2534ba75 | 214 | } |
dea3101e | 215 | |
dea3101e | 216 | /* Next check the txcmplq */ |
07951076 | 217 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { |
858c9f6c | 218 | /* Check to see if iocb matches the nport we are looking for */ |
92d7f7b0 | 219 | if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) { |
07951076 | 220 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); |
92d7f7b0 | 221 | } |
07951076 | 222 | } |
2e0fef85 | 223 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 224 | |
2534ba75 JS |
225 | while (!list_empty(&completions)) { |
226 | iocb = list_get_first(&completions, struct lpfc_iocbq, list); | |
227 | cmd = &iocb->iocb; | |
92d7f7b0 | 228 | list_del_init(&iocb->list); |
2534ba75 | 229 | |
2e0fef85 JS |
230 | if (!iocb->iocb_cmpl) |
231 | lpfc_sli_release_iocbq(phba, iocb); | |
232 | else { | |
2534ba75 JS |
233 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
234 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; | |
235 | (iocb->iocb_cmpl) (phba, iocb, iocb); | |
2e0fef85 | 236 | } |
2534ba75 JS |
237 | } |
238 | ||
dea3101e | 239 | /* If we are delaying issuing an ELS command, cancel it */ |
fdcebe28 | 240 | if (ndlp->nlp_flag & NLP_DELAY_TMO) |
2e0fef85 | 241 | lpfc_cancel_retry_delay_tmo(phba->pport, ndlp); |
c9f8735b | 242 | return 0; |
dea3101e JB |
243 | } |
244 | ||
245 | static int | |
2e0fef85 | 246 | lpfc_rcv_plogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
92d7f7b0 | 247 | struct lpfc_iocbq *cmdiocb) |
dea3101e | 248 | { |
2e0fef85 JS |
249 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
250 | struct lpfc_hba *phba = vport->phba; | |
dea3101e | 251 | struct lpfc_dmabuf *pcmd; |
e47c9093 | 252 | struct lpfc_work_evt *evtp; |
dea3101e JB |
253 | uint32_t *lp; |
254 | IOCB_t *icmd; | |
255 | struct serv_parm *sp; | |
256 | LPFC_MBOXQ_t *mbox; | |
257 | struct ls_rjt stat; | |
258 | int rc; | |
259 | ||
260 | memset(&stat, 0, sizeof (struct ls_rjt)); | |
2e0fef85 | 261 | if (vport->port_state <= LPFC_FLOGI) { |
dea3101e JB |
262 | /* Before responding to PLOGI, check for pt2pt mode. |
263 | * If we are pt2pt, with an outstanding FLOGI, abort | |
264 | * the FLOGI and resend it first. | |
265 | */ | |
2e0fef85 | 266 | if (vport->fc_flag & FC_PT2PT) { |
92d7f7b0 | 267 | lpfc_els_abort_flogi(phba); |
2e0fef85 | 268 | if (!(vport->fc_flag & FC_PT2PT_PLOGI)) { |
dea3101e JB |
269 | /* If the other side is supposed to initiate |
270 | * the PLOGI anyway, just ACC it now and | |
271 | * move on with discovery. | |
272 | */ | |
273 | phba->fc_edtov = FF_DEF_EDTOV; | |
274 | phba->fc_ratov = FF_DEF_RATOV; | |
275 | /* Start discovery - this should just do | |
276 | CLEAR_LA */ | |
2e0fef85 | 277 | lpfc_disc_start(vport); |
ed957684 | 278 | } else |
2e0fef85 | 279 | lpfc_initial_flogi(vport); |
2fe165b6 | 280 | } else { |
dea3101e JB |
281 | stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY; |
282 | stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE; | |
2e0fef85 | 283 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, |
858c9f6c | 284 | ndlp, NULL); |
dea3101e JB |
285 | return 0; |
286 | } | |
287 | } | |
288 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; | |
289 | lp = (uint32_t *) pcmd->virt; | |
290 | sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t)); | |
a8adb832 JS |
291 | if (wwn_to_u64(sp->portName.u.wwn) == 0) { |
292 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | |
293 | "0140 PLOGI Reject: invalid nname\n"); | |
294 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; | |
295 | stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_PNAME; | |
296 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, | |
297 | NULL); | |
298 | return 0; | |
299 | } | |
300 | if (wwn_to_u64(sp->nodeName.u.wwn) == 0) { | |
301 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | |
302 | "0141 PLOGI Reject: invalid pname\n"); | |
303 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; | |
304 | stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_NNAME; | |
305 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, | |
306 | NULL); | |
307 | return 0; | |
308 | } | |
2e0fef85 | 309 | if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3) == 0)) { |
dea3101e JB |
310 | /* Reject this request because invalid parameters */ |
311 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; | |
312 | stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS; | |
858c9f6c JS |
313 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
314 | NULL); | |
c9f8735b | 315 | return 0; |
dea3101e JB |
316 | } |
317 | icmd = &cmdiocb->iocb; | |
318 | ||
319 | /* PLOGI chkparm OK */ | |
e8b62011 JS |
320 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
321 | "0114 PLOGI chkparm OK Data: x%x x%x x%x x%x\n", | |
322 | ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag, | |
323 | ndlp->nlp_rpi); | |
dea3101e | 324 | |
3de2a653 | 325 | if (vport->cfg_fcp_class == 2 && sp->cls2.classValid) |
dea3101e | 326 | ndlp->nlp_fcp_info |= CLASS2; |
ed957684 | 327 | else |
dea3101e | 328 | ndlp->nlp_fcp_info |= CLASS3; |
2e0fef85 | 329 | |
dea3101e JB |
330 | ndlp->nlp_class_sup = 0; |
331 | if (sp->cls1.classValid) | |
332 | ndlp->nlp_class_sup |= FC_COS_CLASS1; | |
333 | if (sp->cls2.classValid) | |
334 | ndlp->nlp_class_sup |= FC_COS_CLASS2; | |
335 | if (sp->cls3.classValid) | |
336 | ndlp->nlp_class_sup |= FC_COS_CLASS3; | |
337 | if (sp->cls4.classValid) | |
338 | ndlp->nlp_class_sup |= FC_COS_CLASS4; | |
339 | ndlp->nlp_maxframe = | |
340 | ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb; | |
341 | ||
342 | /* no need to reg_login if we are already in one of these states */ | |
2fe165b6 | 343 | switch (ndlp->nlp_state) { |
dea3101e JB |
344 | case NLP_STE_NPR_NODE: |
345 | if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) | |
346 | break; | |
347 | case NLP_STE_REG_LOGIN_ISSUE: | |
348 | case NLP_STE_PRLI_ISSUE: | |
349 | case NLP_STE_UNMAPPED_NODE: | |
350 | case NLP_STE_MAPPED_NODE: | |
51ef4c26 | 351 | lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL); |
c9f8735b | 352 | return 1; |
dea3101e JB |
353 | } |
354 | ||
92d7f7b0 JS |
355 | if ((vport->fc_flag & FC_PT2PT) && |
356 | !(vport->fc_flag & FC_PT2PT_PLOGI)) { | |
dea3101e | 357 | /* rcv'ed PLOGI decides what our NPortId will be */ |
2e0fef85 | 358 | vport->fc_myDID = icmd->un.rcvels.parmRo; |
dea3101e JB |
359 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
360 | if (mbox == NULL) | |
361 | goto out; | |
362 | lpfc_config_link(phba, mbox); | |
363 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
ed957684 | 364 | mbox->vport = vport; |
0b727fea | 365 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
dea3101e | 366 | if (rc == MBX_NOT_FINISHED) { |
92d7f7b0 | 367 | mempool_free(mbox, phba->mbox_mem_pool); |
dea3101e JB |
368 | goto out; |
369 | } | |
370 | ||
2e0fef85 | 371 | lpfc_can_disctmo(vport); |
dea3101e JB |
372 | } |
373 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
2e0fef85 | 374 | if (!mbox) |
dea3101e JB |
375 | goto out; |
376 | ||
92d7f7b0 JS |
377 | rc = lpfc_reg_login(phba, vport->vpi, icmd->un.rcvels.remoteID, |
378 | (uint8_t *) sp, mbox, 0); | |
2e0fef85 JS |
379 | if (rc) { |
380 | mempool_free(mbox, phba->mbox_mem_pool); | |
dea3101e JB |
381 | goto out; |
382 | } | |
383 | ||
384 | /* ACC PLOGI rsp command needs to execute first, | |
385 | * queue this mbox command to be processed later. | |
386 | */ | |
387 | mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login; | |
329f9bc7 JS |
388 | /* |
389 | * mbox->context2 = lpfc_nlp_get(ndlp) deferred until mailbox | |
390 | * command issued in lpfc_cmpl_els_acc(). | |
391 | */ | |
2e0fef85 JS |
392 | mbox->vport = vport; |
393 | spin_lock_irq(shost->host_lock); | |
5024ab17 | 394 | ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI); |
2e0fef85 | 395 | spin_unlock_irq(shost->host_lock); |
dea3101e | 396 | |
33ccf8d1 JS |
397 | /* |
398 | * If there is an outstanding PLOGI issued, abort it before | |
399 | * sending ACC rsp for received PLOGI. If pending plogi | |
400 | * is not canceled here, the plogi will be rejected by | |
401 | * remote port and will be retried. On a configuration with | |
402 | * single discovery thread, this will cause a huge delay in | |
403 | * discovery. Also this will cause multiple state machines | |
404 | * running in parallel for this node. | |
405 | */ | |
406 | if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) { | |
407 | /* software abort outstanding PLOGI */ | |
07951076 | 408 | lpfc_els_abort(phba, ndlp); |
33ccf8d1 JS |
409 | } |
410 | ||
858c9f6c | 411 | if ((vport->port_type == LPFC_NPIV_PORT && |
3de2a653 | 412 | vport->cfg_restrict_login)) { |
858c9f6c JS |
413 | |
414 | /* In order to preserve RPIs, we want to cleanup | |
415 | * the default RPI the firmware created to rcv | |
416 | * this ELS request. The only way to do this is | |
417 | * to register, then unregister the RPI. | |
418 | */ | |
419 | spin_lock_irq(shost->host_lock); | |
420 | ndlp->nlp_flag |= NLP_RM_DFLT_RPI; | |
421 | spin_unlock_irq(shost->host_lock); | |
422 | stat.un.b.lsRjtRsnCode = LSRJT_INVALID_CMD; | |
423 | stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE; | |
424 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, | |
425 | ndlp, mbox); | |
426 | return 1; | |
427 | } | |
87af33fe JS |
428 | |
429 | /* If the remote NPort logs into us, before we can initiate | |
430 | * discovery to them, cleanup the NPort from discovery accordingly. | |
431 | */ | |
432 | if (ndlp->nlp_state == NLP_STE_NPR_NODE) { | |
433 | spin_lock_irq(shost->host_lock); | |
434 | ndlp->nlp_flag &= ~NLP_DELAY_TMO; | |
435 | spin_unlock_irq(shost->host_lock); | |
436 | del_timer_sync(&ndlp->nlp_delayfunc); | |
437 | ndlp->nlp_last_elscmd = 0; | |
438 | ||
e47c9093 | 439 | if (!list_empty(&ndlp->els_retry_evt.evt_listp)) { |
87af33fe | 440 | list_del_init(&ndlp->els_retry_evt.evt_listp); |
e47c9093 JS |
441 | /* Decrement ndlp reference count held for the |
442 | * delayed retry | |
443 | */ | |
444 | evtp = &ndlp->els_retry_evt; | |
445 | lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1); | |
446 | } | |
87af33fe JS |
447 | |
448 | if (ndlp->nlp_flag & NLP_NPR_2B_DISC) { | |
449 | spin_lock_irq(shost->host_lock); | |
450 | ndlp->nlp_flag &= ~NLP_NPR_2B_DISC; | |
451 | spin_unlock_irq(shost->host_lock); | |
0ff10d46 JS |
452 | |
453 | if ((ndlp->nlp_flag & NLP_ADISC_SND) && | |
454 | (vport->num_disc_nodes)) { | |
455 | /* Check to see if there are more | |
456 | * ADISCs to be sent | |
457 | */ | |
458 | lpfc_more_adisc(vport); | |
459 | ||
460 | if ((vport->num_disc_nodes == 0) && | |
461 | (vport->fc_npr_cnt)) | |
462 | lpfc_els_disc_plogi(vport); | |
463 | ||
464 | if (vport->num_disc_nodes == 0) { | |
465 | spin_lock_irq(shost->host_lock); | |
466 | vport->fc_flag &= ~FC_NDISC_ACTIVE; | |
467 | spin_unlock_irq(shost->host_lock); | |
468 | lpfc_can_disctmo(vport); | |
469 | lpfc_end_rscn(vport); | |
470 | } | |
471 | } | |
472 | else if (vport->num_disc_nodes) { | |
87af33fe JS |
473 | /* Check to see if there are more |
474 | * PLOGIs to be sent | |
475 | */ | |
476 | lpfc_more_plogi(vport); | |
477 | ||
478 | if (vport->num_disc_nodes == 0) { | |
479 | spin_lock_irq(shost->host_lock); | |
480 | vport->fc_flag &= ~FC_NDISC_ACTIVE; | |
481 | spin_unlock_irq(shost->host_lock); | |
482 | lpfc_can_disctmo(vport); | |
483 | lpfc_end_rscn(vport); | |
484 | } | |
485 | } | |
486 | } | |
487 | } | |
488 | ||
51ef4c26 | 489 | lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox); |
c9f8735b | 490 | return 1; |
dea3101e JB |
491 | |
492 | out: | |
493 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; | |
494 | stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE; | |
858c9f6c | 495 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
c9f8735b | 496 | return 0; |
dea3101e JB |
497 | } |
498 | ||
499 | static int | |
2e0fef85 | 500 | lpfc_rcv_padisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
dea3101e JB |
501 | struct lpfc_iocbq *cmdiocb) |
502 | { | |
2e0fef85 | 503 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
dea3101e | 504 | struct lpfc_dmabuf *pcmd; |
2e0fef85 JS |
505 | struct serv_parm *sp; |
506 | struct lpfc_name *pnn, *ppn; | |
dea3101e JB |
507 | struct ls_rjt stat; |
508 | ADISC *ap; | |
509 | IOCB_t *icmd; | |
510 | uint32_t *lp; | |
511 | uint32_t cmd; | |
512 | ||
513 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; | |
514 | lp = (uint32_t *) pcmd->virt; | |
515 | ||
516 | cmd = *lp++; | |
517 | if (cmd == ELS_CMD_ADISC) { | |
518 | ap = (ADISC *) lp; | |
519 | pnn = (struct lpfc_name *) & ap->nodeName; | |
520 | ppn = (struct lpfc_name *) & ap->portName; | |
521 | } else { | |
522 | sp = (struct serv_parm *) lp; | |
523 | pnn = (struct lpfc_name *) & sp->nodeName; | |
524 | ppn = (struct lpfc_name *) & sp->portName; | |
525 | } | |
526 | ||
527 | icmd = &cmdiocb->iocb; | |
2e0fef85 | 528 | if (icmd->ulpStatus == 0 && lpfc_check_adisc(vport, ndlp, pnn, ppn)) { |
dea3101e | 529 | if (cmd == ELS_CMD_ADISC) { |
2e0fef85 | 530 | lpfc_els_rsp_adisc_acc(vport, cmdiocb, ndlp); |
2fe165b6 | 531 | } else { |
2e0fef85 | 532 | lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, |
51ef4c26 | 533 | NULL); |
dea3101e | 534 | } |
c9f8735b | 535 | return 1; |
dea3101e JB |
536 | } |
537 | /* Reject this request because invalid parameters */ | |
538 | stat.un.b.lsRjtRsvd0 = 0; | |
539 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; | |
540 | stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS; | |
541 | stat.un.b.vendorUnique = 0; | |
858c9f6c | 542 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
dea3101e | 543 | |
dea3101e JB |
544 | /* 1 sec timeout */ |
545 | mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ); | |
546 | ||
2e0fef85 | 547 | spin_lock_irq(shost->host_lock); |
dea3101e | 548 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
2e0fef85 | 549 | spin_unlock_irq(shost->host_lock); |
5024ab17 JW |
550 | ndlp->nlp_last_elscmd = ELS_CMD_PLOGI; |
551 | ndlp->nlp_prev_state = ndlp->nlp_state; | |
2e0fef85 | 552 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
c9f8735b | 553 | return 0; |
dea3101e JB |
554 | } |
555 | ||
556 | static int | |
2e0fef85 JS |
557 | lpfc_rcv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
558 | struct lpfc_iocbq *cmdiocb, uint32_t els_cmd) | |
dea3101e | 559 | { |
2e0fef85 JS |
560 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
561 | ||
562 | /* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */ | |
dea3101e JB |
563 | /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary |
564 | * PLOGIs during LOGO storms from a device. | |
565 | */ | |
2e0fef85 | 566 | spin_lock_irq(shost->host_lock); |
dea3101e | 567 | ndlp->nlp_flag |= NLP_LOGO_ACC; |
2e0fef85 | 568 | spin_unlock_irq(shost->host_lock); |
82d9a2a2 | 569 | if (els_cmd == ELS_CMD_PRLO) |
51ef4c26 | 570 | lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL); |
82d9a2a2 | 571 | else |
51ef4c26 | 572 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
dea3101e | 573 | |
c9f8735b | 574 | if (!(ndlp->nlp_type & NLP_FABRIC) || |
92d7f7b0 | 575 | (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) { |
dea3101e | 576 | /* Only try to re-login if this is NOT a Fabric Node */ |
dea3101e | 577 | mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1); |
2e0fef85 | 578 | spin_lock_irq(shost->host_lock); |
dea3101e | 579 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
2e0fef85 | 580 | spin_unlock_irq(shost->host_lock); |
dea3101e | 581 | |
5024ab17 | 582 | ndlp->nlp_last_elscmd = ELS_CMD_PLOGI; |
c9f8735b | 583 | } |
87af33fe JS |
584 | ndlp->nlp_prev_state = ndlp->nlp_state; |
585 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); | |
dea3101e | 586 | |
2e0fef85 | 587 | spin_lock_irq(shost->host_lock); |
dea3101e | 588 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
2e0fef85 | 589 | spin_unlock_irq(shost->host_lock); |
dea3101e JB |
590 | /* The driver has to wait until the ACC completes before it continues |
591 | * processing the LOGO. The action will resume in | |
592 | * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an | |
593 | * unreg_login, the driver waits so the ACC does not get aborted. | |
594 | */ | |
c9f8735b | 595 | return 0; |
dea3101e JB |
596 | } |
597 | ||
598 | static void | |
2e0fef85 JS |
599 | lpfc_rcv_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
600 | struct lpfc_iocbq *cmdiocb) | |
dea3101e JB |
601 | { |
602 | struct lpfc_dmabuf *pcmd; | |
603 | uint32_t *lp; | |
604 | PRLI *npr; | |
605 | struct fc_rport *rport = ndlp->rport; | |
606 | u32 roles; | |
607 | ||
608 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; | |
609 | lp = (uint32_t *) pcmd->virt; | |
610 | npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t)); | |
611 | ||
612 | ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR); | |
613 | ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE; | |
92d7f7b0 | 614 | if (npr->prliType == PRLI_FCP_TYPE) { |
dea3101e JB |
615 | if (npr->initiatorFunc) |
616 | ndlp->nlp_type |= NLP_FCP_INITIATOR; | |
617 | if (npr->targetFunc) | |
618 | ndlp->nlp_type |= NLP_FCP_TARGET; | |
619 | if (npr->Retry) | |
620 | ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE; | |
621 | } | |
622 | if (rport) { | |
623 | /* We need to update the rport role values */ | |
624 | roles = FC_RPORT_ROLE_UNKNOWN; | |
625 | if (ndlp->nlp_type & NLP_FCP_INITIATOR) | |
626 | roles |= FC_RPORT_ROLE_FCP_INITIATOR; | |
627 | if (ndlp->nlp_type & NLP_FCP_TARGET) | |
628 | roles |= FC_RPORT_ROLE_FCP_TARGET; | |
858c9f6c JS |
629 | |
630 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT, | |
631 | "rport rolechg: role:x%x did:x%x flg:x%x", | |
632 | roles, ndlp->nlp_DID, ndlp->nlp_flag); | |
633 | ||
dea3101e JB |
634 | fc_remote_port_rolechg(rport, roles); |
635 | } | |
636 | } | |
637 | ||
638 | static uint32_t | |
2e0fef85 | 639 | lpfc_disc_set_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
dea3101e | 640 | { |
2e0fef85 | 641 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
2e0fef85 | 642 | |
51ef4c26 JS |
643 | if (!ndlp->nlp_rpi) { |
644 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; | |
645 | return 0; | |
646 | } | |
647 | ||
dea3101e | 648 | /* Check config parameter use-adisc or FCP-2 */ |
3de2a653 | 649 | if ((vport->cfg_use_adisc && (vport->fc_flag & FC_RSCN_MODE)) || |
92d7f7b0 JS |
650 | ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) { |
651 | spin_lock_irq(shost->host_lock); | |
652 | ndlp->nlp_flag |= NLP_NPR_ADISC; | |
653 | spin_unlock_irq(shost->host_lock); | |
654 | return 1; | |
655 | } | |
656 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; | |
657 | lpfc_unreg_rpi(vport, ndlp); | |
658 | return 0; | |
dea3101e JB |
659 | } |
660 | ||
661 | static uint32_t | |
2e0fef85 JS |
662 | lpfc_disc_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
663 | void *arg, uint32_t evt) | |
dea3101e | 664 | { |
e8b62011 | 665 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
e47c9093 | 666 | "0271 Illegal State Transition: node x%x " |
e8b62011 JS |
667 | "event x%x, state x%x Data: x%x x%x\n", |
668 | ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi, | |
669 | ndlp->nlp_flag); | |
c9f8735b | 670 | return ndlp->nlp_state; |
dea3101e JB |
671 | } |
672 | ||
87af33fe JS |
673 | static uint32_t |
674 | lpfc_cmpl_plogi_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, | |
675 | void *arg, uint32_t evt) | |
676 | { | |
677 | /* This transition is only legal if we previously | |
678 | * rcv'ed a PLOGI. Since we don't want 2 discovery threads | |
679 | * working on the same NPortID, do nothing for this thread | |
680 | * to stop it. | |
681 | */ | |
682 | if (!(ndlp->nlp_flag & NLP_RCV_PLOGI)) { | |
683 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, | |
e47c9093 | 684 | "0272 Illegal State Transition: node x%x " |
87af33fe JS |
685 | "event x%x, state x%x Data: x%x x%x\n", |
686 | ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi, | |
687 | ndlp->nlp_flag); | |
688 | } | |
689 | return ndlp->nlp_state; | |
690 | } | |
691 | ||
dea3101e JB |
692 | /* Start of Discovery State Machine routines */ |
693 | ||
694 | static uint32_t | |
2e0fef85 JS |
695 | lpfc_rcv_plogi_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
696 | void *arg, uint32_t evt) | |
dea3101e JB |
697 | { |
698 | struct lpfc_iocbq *cmdiocb; | |
699 | ||
700 | cmdiocb = (struct lpfc_iocbq *) arg; | |
701 | ||
2e0fef85 | 702 | if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) { |
c9f8735b | 703 | return ndlp->nlp_state; |
dea3101e | 704 | } |
c9f8735b | 705 | return NLP_STE_FREED_NODE; |
dea3101e JB |
706 | } |
707 | ||
708 | static uint32_t | |
2e0fef85 JS |
709 | lpfc_rcv_els_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
710 | void *arg, uint32_t evt) | |
dea3101e | 711 | { |
2e0fef85 | 712 | lpfc_issue_els_logo(vport, ndlp, 0); |
c9f8735b | 713 | return ndlp->nlp_state; |
dea3101e JB |
714 | } |
715 | ||
716 | static uint32_t | |
2e0fef85 JS |
717 | lpfc_rcv_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
718 | void *arg, uint32_t evt) | |
dea3101e | 719 | { |
2e0fef85 JS |
720 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
721 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; | |
dea3101e | 722 | |
2e0fef85 | 723 | spin_lock_irq(shost->host_lock); |
dea3101e | 724 | ndlp->nlp_flag |= NLP_LOGO_ACC; |
2e0fef85 | 725 | spin_unlock_irq(shost->host_lock); |
51ef4c26 | 726 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
dea3101e | 727 | |
c9f8735b | 728 | return ndlp->nlp_state; |
dea3101e JB |
729 | } |
730 | ||
731 | static uint32_t | |
2e0fef85 JS |
732 | lpfc_cmpl_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
733 | void *arg, uint32_t evt) | |
dea3101e | 734 | { |
c9f8735b | 735 | return NLP_STE_FREED_NODE; |
dea3101e JB |
736 | } |
737 | ||
738 | static uint32_t | |
2e0fef85 JS |
739 | lpfc_device_rm_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
740 | void *arg, uint32_t evt) | |
dea3101e | 741 | { |
c9f8735b | 742 | return NLP_STE_FREED_NODE; |
dea3101e JB |
743 | } |
744 | ||
745 | static uint32_t | |
2e0fef85 | 746 | lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
dea3101e JB |
747 | void *arg, uint32_t evt) |
748 | { | |
2e0fef85 | 749 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 750 | struct lpfc_iocbq *cmdiocb = arg; |
2e0fef85 JS |
751 | struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; |
752 | uint32_t *lp = (uint32_t *) pcmd->virt; | |
753 | struct serv_parm *sp = (struct serv_parm *) (lp + 1); | |
dea3101e JB |
754 | struct ls_rjt stat; |
755 | int port_cmp; | |
756 | ||
dea3101e JB |
757 | memset(&stat, 0, sizeof (struct ls_rjt)); |
758 | ||
759 | /* For a PLOGI, we only accept if our portname is less | |
760 | * than the remote portname. | |
761 | */ | |
762 | phba->fc_stat.elsLogiCol++; | |
2e0fef85 | 763 | port_cmp = memcmp(&vport->fc_portname, &sp->portName, |
92d7f7b0 | 764 | sizeof(struct lpfc_name)); |
dea3101e JB |
765 | |
766 | if (port_cmp >= 0) { | |
767 | /* Reject this request because the remote node will accept | |
768 | ours */ | |
769 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; | |
770 | stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS; | |
858c9f6c JS |
771 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, |
772 | NULL); | |
2fe165b6 | 773 | } else { |
2e0fef85 JS |
774 | lpfc_rcv_plogi(vport, ndlp, cmdiocb); |
775 | } /* If our portname was less */ | |
dea3101e | 776 | |
c9f8735b JW |
777 | return ndlp->nlp_state; |
778 | } | |
779 | ||
92d7f7b0 JS |
780 | static uint32_t |
781 | lpfc_rcv_prli_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, | |
782 | void *arg, uint32_t evt) | |
783 | { | |
784 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; | |
785 | struct ls_rjt stat; | |
786 | ||
787 | memset(&stat, 0, sizeof (struct ls_rjt)); | |
788 | stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY; | |
789 | stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE; | |
858c9f6c | 790 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
92d7f7b0 JS |
791 | return ndlp->nlp_state; |
792 | } | |
793 | ||
c9f8735b | 794 | static uint32_t |
2e0fef85 JS |
795 | lpfc_rcv_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
796 | void *arg, uint32_t evt) | |
c9f8735b | 797 | { |
2e0fef85 | 798 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; |
c9f8735b | 799 | |
92d7f7b0 | 800 | /* software abort outstanding PLOGI */ |
2e0fef85 | 801 | lpfc_els_abort(vport->phba, ndlp); |
c9f8735b | 802 | |
2e0fef85 | 803 | lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO); |
c9f8735b | 804 | return ndlp->nlp_state; |
dea3101e JB |
805 | } |
806 | ||
807 | static uint32_t | |
2e0fef85 JS |
808 | lpfc_rcv_els_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
809 | void *arg, uint32_t evt) | |
dea3101e | 810 | { |
2e0fef85 JS |
811 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
812 | struct lpfc_hba *phba = vport->phba; | |
813 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; | |
dea3101e JB |
814 | |
815 | /* software abort outstanding PLOGI */ | |
07951076 | 816 | lpfc_els_abort(phba, ndlp); |
dea3101e JB |
817 | |
818 | if (evt == NLP_EVT_RCV_LOGO) { | |
51ef4c26 | 819 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
2fe165b6 | 820 | } else { |
2e0fef85 | 821 | lpfc_issue_els_logo(vport, ndlp, 0); |
dea3101e JB |
822 | } |
823 | ||
2e0fef85 | 824 | /* Put ndlp in npr state set plogi timer for 1 sec */ |
5024ab17 | 825 | mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1); |
2e0fef85 | 826 | spin_lock_irq(shost->host_lock); |
5024ab17 | 827 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
2e0fef85 | 828 | spin_unlock_irq(shost->host_lock); |
5024ab17 JW |
829 | ndlp->nlp_last_elscmd = ELS_CMD_PLOGI; |
830 | ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE; | |
2e0fef85 | 831 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
dea3101e | 832 | |
c9f8735b | 833 | return ndlp->nlp_state; |
dea3101e JB |
834 | } |
835 | ||
836 | static uint32_t | |
2e0fef85 JS |
837 | lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport, |
838 | struct lpfc_nodelist *ndlp, | |
839 | void *arg, | |
dea3101e JB |
840 | uint32_t evt) |
841 | { | |
2e0fef85 | 842 | struct lpfc_hba *phba = vport->phba; |
0ff10d46 | 843 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
2e0fef85 | 844 | struct lpfc_iocbq *cmdiocb, *rspiocb; |
14691150 | 845 | struct lpfc_dmabuf *pcmd, *prsp, *mp; |
dea3101e JB |
846 | uint32_t *lp; |
847 | IOCB_t *irsp; | |
848 | struct serv_parm *sp; | |
849 | LPFC_MBOXQ_t *mbox; | |
850 | ||
851 | cmdiocb = (struct lpfc_iocbq *) arg; | |
852 | rspiocb = cmdiocb->context_un.rsp_iocb; | |
853 | ||
854 | if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) { | |
5024ab17 | 855 | /* Recovery from PLOGI collision logic */ |
c9f8735b | 856 | return ndlp->nlp_state; |
dea3101e JB |
857 | } |
858 | ||
859 | irsp = &rspiocb->iocb; | |
860 | ||
861 | if (irsp->ulpStatus) | |
862 | goto out; | |
863 | ||
864 | pcmd = (struct lpfc_dmabuf *) cmdiocb->context2; | |
865 | ||
2e0fef85 | 866 | prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list); |
dea3101e | 867 | |
2e0fef85 | 868 | lp = (uint32_t *) prsp->virt; |
dea3101e | 869 | sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t)); |
a8adb832 JS |
870 | if (wwn_to_u64(sp->portName.u.wwn) == 0 || |
871 | wwn_to_u64(sp->nodeName.u.wwn) == 0) { | |
872 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, | |
873 | "0142 PLOGI RSP: Invalid WWN.\n"); | |
874 | goto out; | |
875 | } | |
2e0fef85 | 876 | if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3)) |
dea3101e | 877 | goto out; |
dea3101e | 878 | /* PLOGI chkparm OK */ |
e8b62011 JS |
879 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
880 | "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n", | |
881 | ndlp->nlp_DID, ndlp->nlp_state, | |
882 | ndlp->nlp_flag, ndlp->nlp_rpi); | |
3de2a653 | 883 | if (vport->cfg_fcp_class == 2 && (sp->cls2.classValid)) |
dea3101e | 884 | ndlp->nlp_fcp_info |= CLASS2; |
2e0fef85 | 885 | else |
dea3101e | 886 | ndlp->nlp_fcp_info |= CLASS3; |
2e0fef85 | 887 | |
dea3101e JB |
888 | ndlp->nlp_class_sup = 0; |
889 | if (sp->cls1.classValid) | |
890 | ndlp->nlp_class_sup |= FC_COS_CLASS1; | |
891 | if (sp->cls2.classValid) | |
892 | ndlp->nlp_class_sup |= FC_COS_CLASS2; | |
893 | if (sp->cls3.classValid) | |
894 | ndlp->nlp_class_sup |= FC_COS_CLASS3; | |
895 | if (sp->cls4.classValid) | |
896 | ndlp->nlp_class_sup |= FC_COS_CLASS4; | |
897 | ndlp->nlp_maxframe = | |
2e0fef85 | 898 | ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb; |
dea3101e | 899 | |
2e0fef85 | 900 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
92d7f7b0 | 901 | if (!mbox) { |
e8b62011 JS |
902 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
903 | "0133 PLOGI: no memory for reg_login " | |
92d7f7b0 | 904 | "Data: x%x x%x x%x x%x\n", |
92d7f7b0 JS |
905 | ndlp->nlp_DID, ndlp->nlp_state, |
906 | ndlp->nlp_flag, ndlp->nlp_rpi); | |
dea3101e | 907 | goto out; |
92d7f7b0 | 908 | } |
dea3101e | 909 | |
2e0fef85 JS |
910 | lpfc_unreg_rpi(vport, ndlp); |
911 | ||
92d7f7b0 JS |
912 | if (lpfc_reg_login(phba, vport->vpi, irsp->un.elsreq64.remoteID, |
913 | (uint8_t *) sp, mbox, 0) == 0) { | |
2fe165b6 | 914 | switch (ndlp->nlp_DID) { |
dea3101e | 915 | case NameServer_DID: |
de0c5b32 | 916 | mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login; |
dea3101e JB |
917 | break; |
918 | case FDMI_DID: | |
de0c5b32 | 919 | mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login; |
dea3101e JB |
920 | break; |
921 | default: | |
de0c5b32 | 922 | mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login; |
dea3101e | 923 | } |
329f9bc7 | 924 | mbox->context2 = lpfc_nlp_get(ndlp); |
2e0fef85 | 925 | mbox->vport = vport; |
0b727fea | 926 | if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) |
dea3101e | 927 | != MBX_NOT_FINISHED) { |
2e0fef85 JS |
928 | lpfc_nlp_set_state(vport, ndlp, |
929 | NLP_STE_REG_LOGIN_ISSUE); | |
c9f8735b | 930 | return ndlp->nlp_state; |
dea3101e | 931 | } |
fa4066b6 JS |
932 | /* decrement node reference count to the failed mbox |
933 | * command | |
934 | */ | |
329f9bc7 | 935 | lpfc_nlp_put(ndlp); |
92d7f7b0 | 936 | mp = (struct lpfc_dmabuf *) mbox->context1; |
14691150 JS |
937 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
938 | kfree(mp); | |
dea3101e | 939 | mempool_free(mbox, phba->mbox_mem_pool); |
92d7f7b0 | 940 | |
e8b62011 JS |
941 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
942 | "0134 PLOGI: cannot issue reg_login " | |
943 | "Data: x%x x%x x%x x%x\n", | |
944 | ndlp->nlp_DID, ndlp->nlp_state, | |
945 | ndlp->nlp_flag, ndlp->nlp_rpi); | |
dea3101e JB |
946 | } else { |
947 | mempool_free(mbox, phba->mbox_mem_pool); | |
92d7f7b0 | 948 | |
e8b62011 JS |
949 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
950 | "0135 PLOGI: cannot format reg_login " | |
951 | "Data: x%x x%x x%x x%x\n", | |
952 | ndlp->nlp_DID, ndlp->nlp_state, | |
953 | ndlp->nlp_flag, ndlp->nlp_rpi); | |
dea3101e JB |
954 | } |
955 | ||
956 | ||
92d7f7b0 JS |
957 | out: |
958 | if (ndlp->nlp_DID == NameServer_DID) { | |
959 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); | |
e8b62011 JS |
960 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
961 | "0261 Cannot Register NameServer login\n"); | |
92d7f7b0 JS |
962 | } |
963 | ||
0ff10d46 | 964 | spin_lock_irq(shost->host_lock); |
a8adb832 | 965 | ndlp->nlp_flag |= NLP_DEFER_RM; |
0ff10d46 | 966 | spin_unlock_irq(shost->host_lock); |
c9f8735b | 967 | return NLP_STE_FREED_NODE; |
dea3101e JB |
968 | } |
969 | ||
0ff10d46 JS |
970 | static uint32_t |
971 | lpfc_cmpl_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, | |
972 | void *arg, uint32_t evt) | |
973 | { | |
974 | return ndlp->nlp_state; | |
975 | } | |
976 | ||
977 | static uint32_t | |
978 | lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport *vport, | |
979 | struct lpfc_nodelist *ndlp, void *arg, uint32_t evt) | |
980 | { | |
981 | return ndlp->nlp_state; | |
982 | } | |
983 | ||
dea3101e | 984 | static uint32_t |
2e0fef85 JS |
985 | lpfc_device_rm_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
986 | void *arg, uint32_t evt) | |
dea3101e | 987 | { |
2e0fef85 JS |
988 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
989 | ||
990 | if (ndlp->nlp_flag & NLP_NPR_2B_DISC) { | |
991 | spin_lock_irq(shost->host_lock); | |
a0f9b48d | 992 | ndlp->nlp_flag |= NLP_NODEV_REMOVE; |
2e0fef85 | 993 | spin_unlock_irq(shost->host_lock); |
a0f9b48d | 994 | return ndlp->nlp_state; |
2e0fef85 | 995 | } else { |
a0f9b48d | 996 | /* software abort outstanding PLOGI */ |
2e0fef85 | 997 | lpfc_els_abort(vport->phba, ndlp); |
dea3101e | 998 | |
2e0fef85 | 999 | lpfc_drop_node(vport, ndlp); |
a0f9b48d JS |
1000 | return NLP_STE_FREED_NODE; |
1001 | } | |
dea3101e JB |
1002 | } |
1003 | ||
1004 | static uint32_t | |
2e0fef85 JS |
1005 | lpfc_device_recov_plogi_issue(struct lpfc_vport *vport, |
1006 | struct lpfc_nodelist *ndlp, | |
1007 | void *arg, | |
1008 | uint32_t evt) | |
dea3101e | 1009 | { |
2e0fef85 JS |
1010 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
1011 | struct lpfc_hba *phba = vport->phba; | |
1012 | ||
92d7f7b0 JS |
1013 | /* Don't do anything that will mess up processing of the |
1014 | * previous RSCN. | |
1015 | */ | |
1016 | if (vport->fc_flag & FC_RSCN_DEFERRED) | |
1017 | return ndlp->nlp_state; | |
1018 | ||
dea3101e | 1019 | /* software abort outstanding PLOGI */ |
07951076 | 1020 | lpfc_els_abort(phba, ndlp); |
dea3101e | 1021 | |
5024ab17 | 1022 | ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE; |
2e0fef85 | 1023 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
92d7f7b0 | 1024 | spin_lock_irq(shost->host_lock); |
a0f9b48d | 1025 | ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC); |
2e0fef85 | 1026 | spin_unlock_irq(shost->host_lock); |
dea3101e | 1027 | |
c9f8735b | 1028 | return ndlp->nlp_state; |
dea3101e JB |
1029 | } |
1030 | ||
1031 | static uint32_t | |
2e0fef85 JS |
1032 | lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
1033 | void *arg, uint32_t evt) | |
dea3101e | 1034 | { |
2e0fef85 | 1035 | struct lpfc_hba *phba = vport->phba; |
dea3101e JB |
1036 | struct lpfc_iocbq *cmdiocb; |
1037 | ||
1038 | /* software abort outstanding ADISC */ | |
07951076 | 1039 | lpfc_els_abort(phba, ndlp); |
dea3101e JB |
1040 | |
1041 | cmdiocb = (struct lpfc_iocbq *) arg; | |
1042 | ||
2e0fef85 | 1043 | if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) |
c9f8735b | 1044 | return ndlp->nlp_state; |
2e0fef85 | 1045 | |
5024ab17 | 1046 | ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE; |
2e0fef85 JS |
1047 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); |
1048 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); | |
dea3101e | 1049 | |
c9f8735b | 1050 | return ndlp->nlp_state; |
dea3101e JB |
1051 | } |
1052 | ||
1053 | static uint32_t | |
2e0fef85 JS |
1054 | lpfc_rcv_prli_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
1055 | void *arg, uint32_t evt) | |
dea3101e | 1056 | { |
2e0fef85 | 1057 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; |
dea3101e | 1058 | |
2e0fef85 | 1059 | lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp); |
c9f8735b | 1060 | return ndlp->nlp_state; |
dea3101e JB |
1061 | } |
1062 | ||
1063 | static uint32_t | |
2e0fef85 JS |
1064 | lpfc_rcv_logo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
1065 | void *arg, uint32_t evt) | |
dea3101e | 1066 | { |
2e0fef85 | 1067 | struct lpfc_hba *phba = vport->phba; |
dea3101e JB |
1068 | struct lpfc_iocbq *cmdiocb; |
1069 | ||
1070 | cmdiocb = (struct lpfc_iocbq *) arg; | |
1071 | ||
1072 | /* software abort outstanding ADISC */ | |
07951076 | 1073 | lpfc_els_abort(phba, ndlp); |
dea3101e | 1074 | |
2e0fef85 | 1075 | lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO); |
c9f8735b | 1076 | return ndlp->nlp_state; |
dea3101e JB |
1077 | } |
1078 | ||
1079 | static uint32_t | |
2e0fef85 JS |
1080 | lpfc_rcv_padisc_adisc_issue(struct lpfc_vport *vport, |
1081 | struct lpfc_nodelist *ndlp, | |
1082 | void *arg, uint32_t evt) | |
dea3101e JB |
1083 | { |
1084 | struct lpfc_iocbq *cmdiocb; | |
1085 | ||
1086 | cmdiocb = (struct lpfc_iocbq *) arg; | |
1087 | ||
2e0fef85 | 1088 | lpfc_rcv_padisc(vport, ndlp, cmdiocb); |
c9f8735b | 1089 | return ndlp->nlp_state; |
dea3101e JB |
1090 | } |
1091 | ||
1092 | static uint32_t | |
2e0fef85 JS |
1093 | lpfc_rcv_prlo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
1094 | void *arg, uint32_t evt) | |
dea3101e JB |
1095 | { |
1096 | struct lpfc_iocbq *cmdiocb; | |
1097 | ||
1098 | cmdiocb = (struct lpfc_iocbq *) arg; | |
1099 | ||
1100 | /* Treat like rcv logo */ | |
2e0fef85 | 1101 | lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO); |
c9f8735b | 1102 | return ndlp->nlp_state; |
dea3101e JB |
1103 | } |
1104 | ||
1105 | static uint32_t | |
2e0fef85 JS |
1106 | lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport *vport, |
1107 | struct lpfc_nodelist *ndlp, | |
1108 | void *arg, uint32_t evt) | |
dea3101e | 1109 | { |
2e0fef85 JS |
1110 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
1111 | struct lpfc_hba *phba = vport->phba; | |
dea3101e JB |
1112 | struct lpfc_iocbq *cmdiocb, *rspiocb; |
1113 | IOCB_t *irsp; | |
1114 | ADISC *ap; | |
1115 | ||
1116 | cmdiocb = (struct lpfc_iocbq *) arg; | |
1117 | rspiocb = cmdiocb->context_un.rsp_iocb; | |
1118 | ||
1119 | ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb); | |
1120 | irsp = &rspiocb->iocb; | |
1121 | ||
1122 | if ((irsp->ulpStatus) || | |
92d7f7b0 | 1123 | (!lpfc_check_adisc(vport, ndlp, &ap->nodeName, &ap->portName))) { |
dea3101e JB |
1124 | /* 1 sec timeout */ |
1125 | mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ); | |
2e0fef85 | 1126 | spin_lock_irq(shost->host_lock); |
dea3101e | 1127 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
2e0fef85 | 1128 | spin_unlock_irq(shost->host_lock); |
5024ab17 | 1129 | ndlp->nlp_last_elscmd = ELS_CMD_PLOGI; |
dea3101e | 1130 | |
2e0fef85 JS |
1131 | memset(&ndlp->nlp_nodename, 0, sizeof(struct lpfc_name)); |
1132 | memset(&ndlp->nlp_portname, 0, sizeof(struct lpfc_name)); | |
dea3101e | 1133 | |
5024ab17 | 1134 | ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE; |
2e0fef85 JS |
1135 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
1136 | lpfc_unreg_rpi(vport, ndlp); | |
c9f8735b | 1137 | return ndlp->nlp_state; |
dea3101e | 1138 | } |
5024ab17 | 1139 | |
2501322e | 1140 | if (ndlp->nlp_type & NLP_FCP_TARGET) { |
5024ab17 | 1141 | ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE; |
2e0fef85 | 1142 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE); |
2501322e | 1143 | } else { |
5024ab17 | 1144 | ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE; |
2e0fef85 | 1145 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
2501322e | 1146 | } |
c9f8735b | 1147 | return ndlp->nlp_state; |
dea3101e JB |
1148 | } |
1149 | ||
1150 | static uint32_t | |
2e0fef85 JS |
1151 | lpfc_device_rm_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
1152 | void *arg, uint32_t evt) | |
dea3101e | 1153 | { |
2e0fef85 JS |
1154 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
1155 | ||
1156 | if (ndlp->nlp_flag & NLP_NPR_2B_DISC) { | |
1157 | spin_lock_irq(shost->host_lock); | |
a0f9b48d | 1158 | ndlp->nlp_flag |= NLP_NODEV_REMOVE; |
2e0fef85 | 1159 | spin_unlock_irq(shost->host_lock); |
a0f9b48d | 1160 | return ndlp->nlp_state; |
2e0fef85 | 1161 | } else { |
a0f9b48d | 1162 | /* software abort outstanding ADISC */ |
2e0fef85 | 1163 | lpfc_els_abort(vport->phba, ndlp); |
dea3101e | 1164 | |
2e0fef85 | 1165 | lpfc_drop_node(vport, ndlp); |
a0f9b48d JS |
1166 | return NLP_STE_FREED_NODE; |
1167 | } | |
dea3101e JB |
1168 | } |
1169 | ||
1170 | static uint32_t | |
2e0fef85 JS |
1171 | lpfc_device_recov_adisc_issue(struct lpfc_vport *vport, |
1172 | struct lpfc_nodelist *ndlp, | |
1173 | void *arg, | |
1174 | uint32_t evt) | |
dea3101e | 1175 | { |
2e0fef85 JS |
1176 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
1177 | struct lpfc_hba *phba = vport->phba; | |
1178 | ||
92d7f7b0 JS |
1179 | /* Don't do anything that will mess up processing of the |
1180 | * previous RSCN. | |
1181 | */ | |
1182 | if (vport->fc_flag & FC_RSCN_DEFERRED) | |
1183 | return ndlp->nlp_state; | |
1184 | ||
dea3101e | 1185 | /* software abort outstanding ADISC */ |
07951076 | 1186 | lpfc_els_abort(phba, ndlp); |
dea3101e | 1187 | |
5024ab17 | 1188 | ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE; |
2e0fef85 JS |
1189 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
1190 | spin_lock_irq(shost->host_lock); | |
a0f9b48d | 1191 | ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC); |
2e0fef85 | 1192 | spin_unlock_irq(shost->host_lock); |
92d7f7b0 | 1193 | lpfc_disc_set_adisc(vport, ndlp); |
c9f8735b | 1194 | return ndlp->nlp_state; |
dea3101e JB |
1195 | } |
1196 | ||
1197 | static uint32_t | |
2e0fef85 JS |
1198 | lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport *vport, |
1199 | struct lpfc_nodelist *ndlp, | |
1200 | void *arg, | |
dea3101e JB |
1201 | uint32_t evt) |
1202 | { | |
2e0fef85 | 1203 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; |
dea3101e | 1204 | |
2e0fef85 | 1205 | lpfc_rcv_plogi(vport, ndlp, cmdiocb); |
c9f8735b | 1206 | return ndlp->nlp_state; |
dea3101e JB |
1207 | } |
1208 | ||
1209 | static uint32_t | |
2e0fef85 JS |
1210 | lpfc_rcv_prli_reglogin_issue(struct lpfc_vport *vport, |
1211 | struct lpfc_nodelist *ndlp, | |
1212 | void *arg, | |
dea3101e JB |
1213 | uint32_t evt) |
1214 | { | |
2e0fef85 | 1215 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; |
dea3101e | 1216 | |
2e0fef85 | 1217 | lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp); |
c9f8735b | 1218 | return ndlp->nlp_state; |
dea3101e JB |
1219 | } |
1220 | ||
1221 | static uint32_t | |
2e0fef85 JS |
1222 | lpfc_rcv_logo_reglogin_issue(struct lpfc_vport *vport, |
1223 | struct lpfc_nodelist *ndlp, | |
1224 | void *arg, | |
dea3101e JB |
1225 | uint32_t evt) |
1226 | { | |
2e0fef85 JS |
1227 | struct lpfc_hba *phba = vport->phba; |
1228 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; | |
7054a606 JS |
1229 | LPFC_MBOXQ_t *mb; |
1230 | LPFC_MBOXQ_t *nextmb; | |
1231 | struct lpfc_dmabuf *mp; | |
dea3101e JB |
1232 | |
1233 | cmdiocb = (struct lpfc_iocbq *) arg; | |
1234 | ||
7054a606 JS |
1235 | /* cleanup any ndlp on mbox q waiting for reglogin cmpl */ |
1236 | if ((mb = phba->sli.mbox_active)) { | |
1237 | if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) && | |
1238 | (ndlp == (struct lpfc_nodelist *) mb->context2)) { | |
92d7f7b0 | 1239 | lpfc_nlp_put(ndlp); |
7054a606 JS |
1240 | mb->context2 = NULL; |
1241 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
1242 | } | |
1243 | } | |
1244 | ||
2e0fef85 | 1245 | spin_lock_irq(&phba->hbalock); |
7054a606 JS |
1246 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { |
1247 | if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) && | |
1248 | (ndlp == (struct lpfc_nodelist *) mb->context2)) { | |
1249 | mp = (struct lpfc_dmabuf *) (mb->context1); | |
1250 | if (mp) { | |
98c9ea5c | 1251 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); |
7054a606 JS |
1252 | kfree(mp); |
1253 | } | |
92d7f7b0 | 1254 | lpfc_nlp_put(ndlp); |
7054a606 JS |
1255 | list_del(&mb->list); |
1256 | mempool_free(mb, phba->mbox_mem_pool); | |
1257 | } | |
1258 | } | |
2e0fef85 | 1259 | spin_unlock_irq(&phba->hbalock); |
7054a606 | 1260 | |
2e0fef85 | 1261 | lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO); |
c9f8735b | 1262 | return ndlp->nlp_state; |
dea3101e JB |
1263 | } |
1264 | ||
1265 | static uint32_t | |
2e0fef85 JS |
1266 | lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport *vport, |
1267 | struct lpfc_nodelist *ndlp, | |
1268 | void *arg, | |
dea3101e JB |
1269 | uint32_t evt) |
1270 | { | |
2e0fef85 | 1271 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; |
dea3101e | 1272 | |
2e0fef85 | 1273 | lpfc_rcv_padisc(vport, ndlp, cmdiocb); |
c9f8735b | 1274 | return ndlp->nlp_state; |
dea3101e JB |
1275 | } |
1276 | ||
1277 | static uint32_t | |
2e0fef85 JS |
1278 | lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport *vport, |
1279 | struct lpfc_nodelist *ndlp, | |
1280 | void *arg, | |
dea3101e JB |
1281 | uint32_t evt) |
1282 | { | |
1283 | struct lpfc_iocbq *cmdiocb; | |
1284 | ||
1285 | cmdiocb = (struct lpfc_iocbq *) arg; | |
51ef4c26 | 1286 | lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL); |
c9f8735b | 1287 | return ndlp->nlp_state; |
dea3101e JB |
1288 | } |
1289 | ||
1290 | static uint32_t | |
2e0fef85 JS |
1291 | lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport *vport, |
1292 | struct lpfc_nodelist *ndlp, | |
1293 | void *arg, | |
1294 | uint32_t evt) | |
dea3101e | 1295 | { |
2e0fef85 | 1296 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
2e0fef85 JS |
1297 | LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg; |
1298 | MAILBOX_t *mb = &pmb->mb; | |
1299 | uint32_t did = mb->un.varWords[1]; | |
dea3101e | 1300 | |
dea3101e JB |
1301 | if (mb->mbxStatus) { |
1302 | /* RegLogin failed */ | |
e8b62011 JS |
1303 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
1304 | "0246 RegLogin failed Data: x%x x%x x%x\n", | |
2e0fef85 | 1305 | did, mb->mbxStatus, vport->port_state); |
d0e56dad JS |
1306 | /* |
1307 | * If RegLogin failed due to lack of HBA resources do not | |
1308 | * retry discovery. | |
1309 | */ | |
1310 | if (mb->mbxStatus == MBXERR_RPI_FULL) { | |
87af33fe JS |
1311 | ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE; |
1312 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); | |
d0e56dad JS |
1313 | return ndlp->nlp_state; |
1314 | } | |
1315 | ||
2e0fef85 | 1316 | /* Put ndlp in npr state set plogi timer for 1 sec */ |
dea3101e | 1317 | mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1); |
2e0fef85 | 1318 | spin_lock_irq(shost->host_lock); |
dea3101e | 1319 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
2e0fef85 | 1320 | spin_unlock_irq(shost->host_lock); |
5024ab17 | 1321 | ndlp->nlp_last_elscmd = ELS_CMD_PLOGI; |
dea3101e | 1322 | |
2e0fef85 | 1323 | lpfc_issue_els_logo(vport, ndlp, 0); |
5024ab17 | 1324 | ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE; |
2e0fef85 | 1325 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
c9f8735b | 1326 | return ndlp->nlp_state; |
dea3101e JB |
1327 | } |
1328 | ||
dea3101e | 1329 | ndlp->nlp_rpi = mb->un.varWords[0]; |
dea3101e JB |
1330 | |
1331 | /* Only if we are not a fabric nport do we issue PRLI */ | |
1332 | if (!(ndlp->nlp_type & NLP_FABRIC)) { | |
5024ab17 | 1333 | ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE; |
2e0fef85 JS |
1334 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); |
1335 | lpfc_issue_els_prli(vport, ndlp, 0); | |
dea3101e | 1336 | } else { |
5024ab17 | 1337 | ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE; |
2e0fef85 | 1338 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
dea3101e | 1339 | } |
c9f8735b | 1340 | return ndlp->nlp_state; |
dea3101e JB |
1341 | } |
1342 | ||
1343 | static uint32_t | |
2e0fef85 JS |
1344 | lpfc_device_rm_reglogin_issue(struct lpfc_vport *vport, |
1345 | struct lpfc_nodelist *ndlp, | |
1346 | void *arg, | |
dea3101e JB |
1347 | uint32_t evt) |
1348 | { | |
2e0fef85 JS |
1349 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
1350 | ||
1351 | if (ndlp->nlp_flag & NLP_NPR_2B_DISC) { | |
1352 | spin_lock_irq(shost->host_lock); | |
a0f9b48d | 1353 | ndlp->nlp_flag |= NLP_NODEV_REMOVE; |
2e0fef85 | 1354 | spin_unlock_irq(shost->host_lock); |
a0f9b48d | 1355 | return ndlp->nlp_state; |
2e0fef85 JS |
1356 | } else { |
1357 | lpfc_drop_node(vport, ndlp); | |
a0f9b48d JS |
1358 | return NLP_STE_FREED_NODE; |
1359 | } | |
dea3101e JB |
1360 | } |
1361 | ||
1362 | static uint32_t | |
2e0fef85 JS |
1363 | lpfc_device_recov_reglogin_issue(struct lpfc_vport *vport, |
1364 | struct lpfc_nodelist *ndlp, | |
1365 | void *arg, | |
1366 | uint32_t evt) | |
dea3101e | 1367 | { |
2e0fef85 JS |
1368 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
1369 | ||
92d7f7b0 JS |
1370 | /* Don't do anything that will mess up processing of the |
1371 | * previous RSCN. | |
1372 | */ | |
1373 | if (vport->fc_flag & FC_RSCN_DEFERRED) | |
1374 | return ndlp->nlp_state; | |
1375 | ||
5024ab17 | 1376 | ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE; |
2e0fef85 JS |
1377 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
1378 | spin_lock_irq(shost->host_lock); | |
a0f9b48d | 1379 | ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC); |
2e0fef85 | 1380 | spin_unlock_irq(shost->host_lock); |
92d7f7b0 | 1381 | lpfc_disc_set_adisc(vport, ndlp); |
c9f8735b | 1382 | return ndlp->nlp_state; |
dea3101e JB |
1383 | } |
1384 | ||
1385 | static uint32_t | |
2e0fef85 JS |
1386 | lpfc_rcv_plogi_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
1387 | void *arg, uint32_t evt) | |
dea3101e JB |
1388 | { |
1389 | struct lpfc_iocbq *cmdiocb; | |
1390 | ||
1391 | cmdiocb = (struct lpfc_iocbq *) arg; | |
1392 | ||
2e0fef85 | 1393 | lpfc_rcv_plogi(vport, ndlp, cmdiocb); |
c9f8735b | 1394 | return ndlp->nlp_state; |
dea3101e JB |
1395 | } |
1396 | ||
1397 | static uint32_t | |
2e0fef85 JS |
1398 | lpfc_rcv_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
1399 | void *arg, uint32_t evt) | |
dea3101e | 1400 | { |
2e0fef85 | 1401 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; |
dea3101e | 1402 | |
2e0fef85 | 1403 | lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp); |
c9f8735b | 1404 | return ndlp->nlp_state; |
dea3101e JB |
1405 | } |
1406 | ||
1407 | static uint32_t | |
2e0fef85 JS |
1408 | lpfc_rcv_logo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
1409 | void *arg, uint32_t evt) | |
dea3101e | 1410 | { |
2e0fef85 | 1411 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; |
dea3101e JB |
1412 | |
1413 | /* Software abort outstanding PRLI before sending acc */ | |
2e0fef85 | 1414 | lpfc_els_abort(vport->phba, ndlp); |
dea3101e | 1415 | |
2e0fef85 | 1416 | lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO); |
c9f8735b | 1417 | return ndlp->nlp_state; |
dea3101e JB |
1418 | } |
1419 | ||
1420 | static uint32_t | |
2e0fef85 JS |
1421 | lpfc_rcv_padisc_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
1422 | void *arg, uint32_t evt) | |
dea3101e | 1423 | { |
2e0fef85 | 1424 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; |
dea3101e | 1425 | |
2e0fef85 | 1426 | lpfc_rcv_padisc(vport, ndlp, cmdiocb); |
c9f8735b | 1427 | return ndlp->nlp_state; |
dea3101e JB |
1428 | } |
1429 | ||
1430 | /* This routine is envoked when we rcv a PRLO request from a nport | |
1431 | * we are logged into. We should send back a PRLO rsp setting the | |
1432 | * appropriate bits. | |
1433 | * NEXT STATE = PRLI_ISSUE | |
1434 | */ | |
1435 | static uint32_t | |
2e0fef85 JS |
1436 | lpfc_rcv_prlo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
1437 | void *arg, uint32_t evt) | |
dea3101e | 1438 | { |
2e0fef85 | 1439 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; |
dea3101e | 1440 | |
51ef4c26 | 1441 | lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL); |
c9f8735b | 1442 | return ndlp->nlp_state; |
dea3101e JB |
1443 | } |
1444 | ||
1445 | static uint32_t | |
2e0fef85 JS |
1446 | lpfc_cmpl_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
1447 | void *arg, uint32_t evt) | |
dea3101e | 1448 | { |
92d7f7b0 | 1449 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
dea3101e | 1450 | struct lpfc_iocbq *cmdiocb, *rspiocb; |
2e0fef85 | 1451 | struct lpfc_hba *phba = vport->phba; |
dea3101e JB |
1452 | IOCB_t *irsp; |
1453 | PRLI *npr; | |
1454 | ||
1455 | cmdiocb = (struct lpfc_iocbq *) arg; | |
1456 | rspiocb = cmdiocb->context_un.rsp_iocb; | |
1457 | npr = (PRLI *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb); | |
1458 | ||
1459 | irsp = &rspiocb->iocb; | |
1460 | if (irsp->ulpStatus) { | |
858c9f6c | 1461 | if ((vport->port_type == LPFC_NPIV_PORT) && |
3de2a653 | 1462 | vport->cfg_restrict_login) { |
858c9f6c JS |
1463 | goto out; |
1464 | } | |
5024ab17 | 1465 | ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE; |
2e0fef85 | 1466 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); |
c9f8735b | 1467 | return ndlp->nlp_state; |
dea3101e JB |
1468 | } |
1469 | ||
1470 | /* Check out PRLI rsp */ | |
1471 | ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR); | |
1472 | ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE; | |
1473 | if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) && | |
1474 | (npr->prliType == PRLI_FCP_TYPE)) { | |
1475 | if (npr->initiatorFunc) | |
1476 | ndlp->nlp_type |= NLP_FCP_INITIATOR; | |
1477 | if (npr->targetFunc) | |
1478 | ndlp->nlp_type |= NLP_FCP_TARGET; | |
1479 | if (npr->Retry) | |
1480 | ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE; | |
1481 | } | |
92d7f7b0 JS |
1482 | if (!(ndlp->nlp_type & NLP_FCP_TARGET) && |
1483 | (vport->port_type == LPFC_NPIV_PORT) && | |
3de2a653 | 1484 | vport->cfg_restrict_login) { |
858c9f6c | 1485 | out: |
92d7f7b0 JS |
1486 | spin_lock_irq(shost->host_lock); |
1487 | ndlp->nlp_flag |= NLP_TARGET_REMOVE; | |
1488 | spin_unlock_irq(shost->host_lock); | |
1489 | lpfc_issue_els_logo(vport, ndlp, 0); | |
1490 | ||
1491 | ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE; | |
87af33fe | 1492 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
92d7f7b0 JS |
1493 | return ndlp->nlp_state; |
1494 | } | |
dea3101e | 1495 | |
5024ab17 | 1496 | ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE; |
92d7f7b0 JS |
1497 | if (ndlp->nlp_type & NLP_FCP_TARGET) |
1498 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE); | |
1499 | else | |
1500 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); | |
c9f8735b | 1501 | return ndlp->nlp_state; |
dea3101e JB |
1502 | } |
1503 | ||
1504 | /*! lpfc_device_rm_prli_issue | |
92d7f7b0 JS |
1505 | * |
1506 | * \pre | |
1507 | * \post | |
1508 | * \param phba | |
1509 | * \param ndlp | |
1510 | * \param arg | |
1511 | * \param evt | |
1512 | * \return uint32_t | |
1513 | * | |
1514 | * \b Description: | |
1515 | * This routine is envoked when we a request to remove a nport we are in the | |
1516 | * process of PRLIing. We should software abort outstanding prli, unreg | |
1517 | * login, send a logout. We will change node state to UNUSED_NODE, put it | |
1518 | * on plogi list so it can be freed when LOGO completes. | |
1519 | * | |
1520 | */ | |
1521 | ||
dea3101e | 1522 | static uint32_t |
2e0fef85 JS |
1523 | lpfc_device_rm_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
1524 | void *arg, uint32_t evt) | |
dea3101e | 1525 | { |
2e0fef85 JS |
1526 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
1527 | ||
1528 | if (ndlp->nlp_flag & NLP_NPR_2B_DISC) { | |
1529 | spin_lock_irq(shost->host_lock); | |
a0f9b48d | 1530 | ndlp->nlp_flag |= NLP_NODEV_REMOVE; |
2e0fef85 | 1531 | spin_unlock_irq(shost->host_lock); |
a0f9b48d | 1532 | return ndlp->nlp_state; |
2e0fef85 | 1533 | } else { |
a0f9b48d | 1534 | /* software abort outstanding PLOGI */ |
2e0fef85 | 1535 | lpfc_els_abort(vport->phba, ndlp); |
dea3101e | 1536 | |
2e0fef85 | 1537 | lpfc_drop_node(vport, ndlp); |
a0f9b48d JS |
1538 | return NLP_STE_FREED_NODE; |
1539 | } | |
dea3101e JB |
1540 | } |
1541 | ||
1542 | ||
1543 | /*! lpfc_device_recov_prli_issue | |
92d7f7b0 JS |
1544 | * |
1545 | * \pre | |
1546 | * \post | |
1547 | * \param phba | |
1548 | * \param ndlp | |
1549 | * \param arg | |
1550 | * \param evt | |
1551 | * \return uint32_t | |
1552 | * | |
1553 | * \b Description: | |
1554 | * The routine is envoked when the state of a device is unknown, like | |
1555 | * during a link down. We should remove the nodelist entry from the | |
1556 | * unmapped list, issue a UNREG_LOGIN, do a software abort of the | |
1557 | * outstanding PRLI command, then free the node entry. | |
1558 | */ | |
dea3101e | 1559 | static uint32_t |
2e0fef85 JS |
1560 | lpfc_device_recov_prli_issue(struct lpfc_vport *vport, |
1561 | struct lpfc_nodelist *ndlp, | |
1562 | void *arg, | |
1563 | uint32_t evt) | |
dea3101e | 1564 | { |
2e0fef85 JS |
1565 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
1566 | struct lpfc_hba *phba = vport->phba; | |
1567 | ||
92d7f7b0 JS |
1568 | /* Don't do anything that will mess up processing of the |
1569 | * previous RSCN. | |
1570 | */ | |
1571 | if (vport->fc_flag & FC_RSCN_DEFERRED) | |
1572 | return ndlp->nlp_state; | |
1573 | ||
dea3101e | 1574 | /* software abort outstanding PRLI */ |
07951076 | 1575 | lpfc_els_abort(phba, ndlp); |
dea3101e | 1576 | |
5024ab17 | 1577 | ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE; |
2e0fef85 JS |
1578 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
1579 | spin_lock_irq(shost->host_lock); | |
a0f9b48d | 1580 | ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC); |
2e0fef85 | 1581 | spin_unlock_irq(shost->host_lock); |
92d7f7b0 | 1582 | lpfc_disc_set_adisc(vport, ndlp); |
c9f8735b | 1583 | return ndlp->nlp_state; |
dea3101e JB |
1584 | } |
1585 | ||
1586 | static uint32_t | |
2e0fef85 JS |
1587 | lpfc_rcv_plogi_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
1588 | void *arg, uint32_t evt) | |
dea3101e | 1589 | { |
2e0fef85 | 1590 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; |
dea3101e | 1591 | |
2e0fef85 | 1592 | lpfc_rcv_plogi(vport, ndlp, cmdiocb); |
c9f8735b | 1593 | return ndlp->nlp_state; |
dea3101e JB |
1594 | } |
1595 | ||
1596 | static uint32_t | |
2e0fef85 JS |
1597 | lpfc_rcv_prli_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
1598 | void *arg, uint32_t evt) | |
dea3101e | 1599 | { |
2e0fef85 | 1600 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; |
dea3101e | 1601 | |
2e0fef85 JS |
1602 | lpfc_rcv_prli(vport, ndlp, cmdiocb); |
1603 | lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp); | |
c9f8735b | 1604 | return ndlp->nlp_state; |
dea3101e JB |
1605 | } |
1606 | ||
1607 | static uint32_t | |
2e0fef85 JS |
1608 | lpfc_rcv_logo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
1609 | void *arg, uint32_t evt) | |
dea3101e | 1610 | { |
2e0fef85 | 1611 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; |
dea3101e | 1612 | |
2e0fef85 | 1613 | lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO); |
c9f8735b | 1614 | return ndlp->nlp_state; |
dea3101e JB |
1615 | } |
1616 | ||
1617 | static uint32_t | |
2e0fef85 JS |
1618 | lpfc_rcv_padisc_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
1619 | void *arg, uint32_t evt) | |
dea3101e | 1620 | { |
2e0fef85 | 1621 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; |
dea3101e | 1622 | |
2e0fef85 | 1623 | lpfc_rcv_padisc(vport, ndlp, cmdiocb); |
c9f8735b | 1624 | return ndlp->nlp_state; |
dea3101e JB |
1625 | } |
1626 | ||
1627 | static uint32_t | |
2e0fef85 JS |
1628 | lpfc_rcv_prlo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
1629 | void *arg, uint32_t evt) | |
dea3101e | 1630 | { |
2e0fef85 | 1631 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; |
dea3101e | 1632 | |
51ef4c26 | 1633 | lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL); |
c9f8735b | 1634 | return ndlp->nlp_state; |
dea3101e JB |
1635 | } |
1636 | ||
1637 | static uint32_t | |
2e0fef85 JS |
1638 | lpfc_device_recov_unmap_node(struct lpfc_vport *vport, |
1639 | struct lpfc_nodelist *ndlp, | |
1640 | void *arg, | |
1641 | uint32_t evt) | |
dea3101e | 1642 | { |
2e0fef85 JS |
1643 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
1644 | ||
5024ab17 | 1645 | ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE; |
2e0fef85 JS |
1646 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
1647 | spin_lock_irq(shost->host_lock); | |
a0f9b48d | 1648 | ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC); |
2e0fef85 JS |
1649 | spin_unlock_irq(shost->host_lock); |
1650 | lpfc_disc_set_adisc(vport, ndlp); | |
dea3101e | 1651 | |
c9f8735b | 1652 | return ndlp->nlp_state; |
dea3101e JB |
1653 | } |
1654 | ||
1655 | static uint32_t | |
2e0fef85 JS |
1656 | lpfc_rcv_plogi_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
1657 | void *arg, uint32_t evt) | |
dea3101e | 1658 | { |
2e0fef85 | 1659 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; |
dea3101e | 1660 | |
2e0fef85 | 1661 | lpfc_rcv_plogi(vport, ndlp, cmdiocb); |
c9f8735b | 1662 | return ndlp->nlp_state; |
dea3101e JB |
1663 | } |
1664 | ||
1665 | static uint32_t | |
2e0fef85 JS |
1666 | lpfc_rcv_prli_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
1667 | void *arg, uint32_t evt) | |
dea3101e | 1668 | { |
2e0fef85 | 1669 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; |
dea3101e | 1670 | |
2e0fef85 | 1671 | lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp); |
c9f8735b | 1672 | return ndlp->nlp_state; |
dea3101e JB |
1673 | } |
1674 | ||
1675 | static uint32_t | |
2e0fef85 JS |
1676 | lpfc_rcv_logo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
1677 | void *arg, uint32_t evt) | |
dea3101e | 1678 | { |
2e0fef85 | 1679 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; |
dea3101e | 1680 | |
2e0fef85 | 1681 | lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO); |
c9f8735b | 1682 | return ndlp->nlp_state; |
dea3101e JB |
1683 | } |
1684 | ||
1685 | static uint32_t | |
2e0fef85 JS |
1686 | lpfc_rcv_padisc_mapped_node(struct lpfc_vport *vport, |
1687 | struct lpfc_nodelist *ndlp, | |
1688 | void *arg, uint32_t evt) | |
dea3101e | 1689 | { |
2e0fef85 | 1690 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; |
dea3101e | 1691 | |
2e0fef85 | 1692 | lpfc_rcv_padisc(vport, ndlp, cmdiocb); |
c9f8735b | 1693 | return ndlp->nlp_state; |
dea3101e JB |
1694 | } |
1695 | ||
1696 | static uint32_t | |
2e0fef85 JS |
1697 | lpfc_rcv_prlo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
1698 | void *arg, uint32_t evt) | |
dea3101e | 1699 | { |
2e0fef85 JS |
1700 | struct lpfc_hba *phba = vport->phba; |
1701 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; | |
dea3101e JB |
1702 | |
1703 | /* flush the target */ | |
51ef4c26 JS |
1704 | lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring], |
1705 | ndlp->nlp_sid, 0, LPFC_CTX_TGT); | |
dea3101e JB |
1706 | |
1707 | /* Treat like rcv logo */ | |
2e0fef85 | 1708 | lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO); |
c9f8735b | 1709 | return ndlp->nlp_state; |
dea3101e JB |
1710 | } |
1711 | ||
1712 | static uint32_t | |
2e0fef85 JS |
1713 | lpfc_device_recov_mapped_node(struct lpfc_vport *vport, |
1714 | struct lpfc_nodelist *ndlp, | |
1715 | void *arg, | |
1716 | uint32_t evt) | |
dea3101e | 1717 | { |
2e0fef85 JS |
1718 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
1719 | ||
5024ab17 | 1720 | ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE; |
2e0fef85 JS |
1721 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); |
1722 | spin_lock_irq(shost->host_lock); | |
a0f9b48d | 1723 | ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC); |
2e0fef85 JS |
1724 | spin_unlock_irq(shost->host_lock); |
1725 | lpfc_disc_set_adisc(vport, ndlp); | |
c9f8735b | 1726 | return ndlp->nlp_state; |
dea3101e JB |
1727 | } |
1728 | ||
1729 | static uint32_t | |
2e0fef85 JS |
1730 | lpfc_rcv_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
1731 | void *arg, uint32_t evt) | |
dea3101e | 1732 | { |
2e0fef85 JS |
1733 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
1734 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; | |
dea3101e JB |
1735 | |
1736 | /* Ignore PLOGI if we have an outstanding LOGO */ | |
858c9f6c | 1737 | if (ndlp->nlp_flag & (NLP_LOGO_SND | NLP_LOGO_ACC)) { |
c9f8735b | 1738 | return ndlp->nlp_state; |
dea3101e JB |
1739 | } |
1740 | ||
2e0fef85 JS |
1741 | if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) { |
1742 | spin_lock_irq(shost->host_lock); | |
fdcebe28 | 1743 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
2e0fef85 | 1744 | spin_unlock_irq(shost->host_lock); |
c9f8735b | 1745 | return ndlp->nlp_state; |
dea3101e JB |
1746 | } |
1747 | ||
1748 | /* send PLOGI immediately, move to PLOGI issue state */ | |
1749 | if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) { | |
488d1469 | 1750 | ndlp->nlp_prev_state = NLP_STE_NPR_NODE; |
2e0fef85 JS |
1751 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
1752 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); | |
dea3101e | 1753 | } |
488d1469 | 1754 | |
c9f8735b | 1755 | return ndlp->nlp_state; |
dea3101e JB |
1756 | } |
1757 | ||
1758 | static uint32_t | |
2e0fef85 JS |
1759 | lpfc_rcv_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
1760 | void *arg, uint32_t evt) | |
dea3101e | 1761 | { |
2e0fef85 JS |
1762 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
1763 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; | |
1764 | struct ls_rjt stat; | |
dea3101e JB |
1765 | |
1766 | memset(&stat, 0, sizeof (struct ls_rjt)); | |
1767 | stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; | |
1768 | stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE; | |
858c9f6c | 1769 | lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL); |
dea3101e JB |
1770 | |
1771 | if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) { | |
1772 | if (ndlp->nlp_flag & NLP_NPR_ADISC) { | |
2e0fef85 | 1773 | spin_lock_irq(shost->host_lock); |
c9f8735b | 1774 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
5024ab17 | 1775 | ndlp->nlp_prev_state = NLP_STE_NPR_NODE; |
2e0fef85 JS |
1776 | spin_unlock_irq(shost->host_lock); |
1777 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); | |
1778 | lpfc_issue_els_adisc(vport, ndlp, 0); | |
dea3101e | 1779 | } else { |
5024ab17 | 1780 | ndlp->nlp_prev_state = NLP_STE_NPR_NODE; |
2e0fef85 JS |
1781 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
1782 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); | |
dea3101e JB |
1783 | } |
1784 | } | |
c9f8735b | 1785 | return ndlp->nlp_state; |
dea3101e JB |
1786 | } |
1787 | ||
1788 | static uint32_t | |
2e0fef85 JS |
1789 | lpfc_rcv_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
1790 | void *arg, uint32_t evt) | |
dea3101e | 1791 | { |
2e0fef85 | 1792 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; |
dea3101e | 1793 | |
2e0fef85 | 1794 | lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO); |
c9f8735b | 1795 | return ndlp->nlp_state; |
dea3101e JB |
1796 | } |
1797 | ||
1798 | static uint32_t | |
2e0fef85 JS |
1799 | lpfc_rcv_padisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
1800 | void *arg, uint32_t evt) | |
dea3101e | 1801 | { |
2e0fef85 | 1802 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; |
dea3101e | 1803 | |
2e0fef85 | 1804 | lpfc_rcv_padisc(vport, ndlp, cmdiocb); |
dea3101e | 1805 | |
33ccf8d1 JS |
1806 | /* |
1807 | * Do not start discovery if discovery is about to start | |
1808 | * or discovery in progress for this node. Starting discovery | |
1809 | * here will affect the counting of discovery threads. | |
1810 | */ | |
2fb9bd8b | 1811 | if (!(ndlp->nlp_flag & NLP_DELAY_TMO) && |
92d7f7b0 | 1812 | !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) { |
dea3101e | 1813 | if (ndlp->nlp_flag & NLP_NPR_ADISC) { |
92d7f7b0 | 1814 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
5024ab17 | 1815 | ndlp->nlp_prev_state = NLP_STE_NPR_NODE; |
2e0fef85 JS |
1816 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE); |
1817 | lpfc_issue_els_adisc(vport, ndlp, 0); | |
dea3101e | 1818 | } else { |
5024ab17 | 1819 | ndlp->nlp_prev_state = NLP_STE_NPR_NODE; |
2e0fef85 JS |
1820 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE); |
1821 | lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0); | |
dea3101e JB |
1822 | } |
1823 | } | |
c9f8735b | 1824 | return ndlp->nlp_state; |
dea3101e JB |
1825 | } |
1826 | ||
1827 | static uint32_t | |
2e0fef85 JS |
1828 | lpfc_rcv_prlo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
1829 | void *arg, uint32_t evt) | |
dea3101e | 1830 | { |
2e0fef85 JS |
1831 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
1832 | struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; | |
dea3101e | 1833 | |
2e0fef85 | 1834 | spin_lock_irq(shost->host_lock); |
c9f8735b | 1835 | ndlp->nlp_flag |= NLP_LOGO_ACC; |
2e0fef85 | 1836 | spin_unlock_irq(shost->host_lock); |
c9f8735b | 1837 | |
51ef4c26 | 1838 | lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL); |
dea3101e | 1839 | |
2e0fef85 | 1840 | if ((ndlp->nlp_flag & NLP_DELAY_TMO) == 0) { |
c9f8735b | 1841 | mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1); |
2e0fef85 | 1842 | spin_lock_irq(shost->host_lock); |
c9f8735b JW |
1843 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
1844 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; | |
2e0fef85 | 1845 | spin_unlock_irq(shost->host_lock); |
5024ab17 | 1846 | ndlp->nlp_last_elscmd = ELS_CMD_PLOGI; |
c9f8735b | 1847 | } else { |
2e0fef85 | 1848 | spin_lock_irq(shost->host_lock); |
c9f8735b | 1849 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
2e0fef85 | 1850 | spin_unlock_irq(shost->host_lock); |
dea3101e | 1851 | } |
c9f8735b JW |
1852 | return ndlp->nlp_state; |
1853 | } | |
dea3101e | 1854 | |
c9f8735b | 1855 | static uint32_t |
2e0fef85 JS |
1856 | lpfc_cmpl_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
1857 | void *arg, uint32_t evt) | |
c9f8735b JW |
1858 | { |
1859 | struct lpfc_iocbq *cmdiocb, *rspiocb; | |
a0f9b48d | 1860 | IOCB_t *irsp; |
c9f8735b JW |
1861 | |
1862 | cmdiocb = (struct lpfc_iocbq *) arg; | |
1863 | rspiocb = cmdiocb->context_un.rsp_iocb; | |
a0f9b48d JS |
1864 | |
1865 | irsp = &rspiocb->iocb; | |
1866 | if (irsp->ulpStatus) { | |
a8adb832 | 1867 | ndlp->nlp_flag |= NLP_DEFER_RM; |
a0f9b48d JS |
1868 | return NLP_STE_FREED_NODE; |
1869 | } | |
c9f8735b JW |
1870 | return ndlp->nlp_state; |
1871 | } | |
1872 | ||
1873 | static uint32_t | |
2e0fef85 JS |
1874 | lpfc_cmpl_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
1875 | void *arg, uint32_t evt) | |
c9f8735b JW |
1876 | { |
1877 | struct lpfc_iocbq *cmdiocb, *rspiocb; | |
a0f9b48d | 1878 | IOCB_t *irsp; |
c9f8735b JW |
1879 | |
1880 | cmdiocb = (struct lpfc_iocbq *) arg; | |
1881 | rspiocb = cmdiocb->context_un.rsp_iocb; | |
a0f9b48d JS |
1882 | |
1883 | irsp = &rspiocb->iocb; | |
1884 | if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) { | |
2e0fef85 | 1885 | lpfc_drop_node(vport, ndlp); |
a0f9b48d JS |
1886 | return NLP_STE_FREED_NODE; |
1887 | } | |
c9f8735b | 1888 | return ndlp->nlp_state; |
dea3101e JB |
1889 | } |
1890 | ||
1891 | static uint32_t | |
2e0fef85 JS |
1892 | lpfc_cmpl_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
1893 | void *arg, uint32_t evt) | |
dea3101e | 1894 | { |
2e0fef85 | 1895 | lpfc_unreg_rpi(vport, ndlp); |
dea3101e | 1896 | /* This routine does nothing, just return the current state */ |
c9f8735b JW |
1897 | return ndlp->nlp_state; |
1898 | } | |
1899 | ||
1900 | static uint32_t | |
2e0fef85 JS |
1901 | lpfc_cmpl_adisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
1902 | void *arg, uint32_t evt) | |
c9f8735b JW |
1903 | { |
1904 | struct lpfc_iocbq *cmdiocb, *rspiocb; | |
a0f9b48d | 1905 | IOCB_t *irsp; |
c9f8735b JW |
1906 | |
1907 | cmdiocb = (struct lpfc_iocbq *) arg; | |
1908 | rspiocb = cmdiocb->context_un.rsp_iocb; | |
a0f9b48d JS |
1909 | |
1910 | irsp = &rspiocb->iocb; | |
1911 | if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) { | |
2e0fef85 | 1912 | lpfc_drop_node(vport, ndlp); |
a0f9b48d JS |
1913 | return NLP_STE_FREED_NODE; |
1914 | } | |
c9f8735b | 1915 | return ndlp->nlp_state; |
dea3101e JB |
1916 | } |
1917 | ||
1918 | static uint32_t | |
2e0fef85 JS |
1919 | lpfc_cmpl_reglogin_npr_node(struct lpfc_vport *vport, |
1920 | struct lpfc_nodelist *ndlp, | |
1921 | void *arg, uint32_t evt) | |
dea3101e | 1922 | { |
2e0fef85 JS |
1923 | LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg; |
1924 | MAILBOX_t *mb = &pmb->mb; | |
dea3101e | 1925 | |
c9f8735b JW |
1926 | if (!mb->mbxStatus) |
1927 | ndlp->nlp_rpi = mb->un.varWords[0]; | |
a0f9b48d JS |
1928 | else { |
1929 | if (ndlp->nlp_flag & NLP_NODEV_REMOVE) { | |
2e0fef85 | 1930 | lpfc_drop_node(vport, ndlp); |
a0f9b48d JS |
1931 | return NLP_STE_FREED_NODE; |
1932 | } | |
1933 | } | |
c9f8735b | 1934 | return ndlp->nlp_state; |
dea3101e JB |
1935 | } |
1936 | ||
1937 | static uint32_t | |
2e0fef85 JS |
1938 | lpfc_device_rm_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
1939 | void *arg, uint32_t evt) | |
dea3101e | 1940 | { |
2e0fef85 JS |
1941 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
1942 | ||
a0f9b48d | 1943 | if (ndlp->nlp_flag & NLP_NPR_2B_DISC) { |
2e0fef85 | 1944 | spin_lock_irq(shost->host_lock); |
a0f9b48d | 1945 | ndlp->nlp_flag |= NLP_NODEV_REMOVE; |
2e0fef85 | 1946 | spin_unlock_irq(shost->host_lock); |
a0f9b48d JS |
1947 | return ndlp->nlp_state; |
1948 | } | |
2e0fef85 | 1949 | lpfc_drop_node(vport, ndlp); |
c9f8735b | 1950 | return NLP_STE_FREED_NODE; |
dea3101e JB |
1951 | } |
1952 | ||
1953 | static uint32_t | |
2e0fef85 JS |
1954 | lpfc_device_recov_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
1955 | void *arg, uint32_t evt) | |
dea3101e | 1956 | { |
2e0fef85 JS |
1957 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
1958 | ||
92d7f7b0 JS |
1959 | /* Don't do anything that will mess up processing of the |
1960 | * previous RSCN. | |
1961 | */ | |
1962 | if (vport->fc_flag & FC_RSCN_DEFERRED) | |
1963 | return ndlp->nlp_state; | |
1964 | ||
2e0fef85 | 1965 | spin_lock_irq(shost->host_lock); |
a0f9b48d | 1966 | ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC); |
2e0fef85 | 1967 | spin_unlock_irq(shost->host_lock); |
6ad42535 | 1968 | if (ndlp->nlp_flag & NLP_DELAY_TMO) { |
2e0fef85 | 1969 | lpfc_cancel_retry_delay_tmo(vport, ndlp); |
6ad42535 | 1970 | } |
c9f8735b | 1971 | return ndlp->nlp_state; |
dea3101e JB |
1972 | } |
1973 | ||
1974 | ||
1975 | /* This next section defines the NPort Discovery State Machine */ | |
1976 | ||
1977 | /* There are 4 different double linked lists nodelist entries can reside on. | |
1978 | * The plogi list and adisc list are used when Link Up discovery or RSCN | |
1979 | * processing is needed. Each list holds the nodes that we will send PLOGI | |
1980 | * or ADISC on. These lists will keep track of what nodes will be effected | |
1981 | * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up). | |
1982 | * The unmapped_list will contain all nodes that we have successfully logged | |
1983 | * into at the Fibre Channel level. The mapped_list will contain all nodes | |
1984 | * that are mapped FCP targets. | |
1985 | */ | |
1986 | /* | |
1987 | * The bind list is a list of undiscovered (potentially non-existent) nodes | |
1988 | * that we have saved binding information on. This information is used when | |
1989 | * nodes transition from the unmapped to the mapped list. | |
1990 | */ | |
1991 | /* For UNUSED_NODE state, the node has just been allocated . | |
1992 | * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on | |
1993 | * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list | |
1994 | * and put on the unmapped list. For ADISC processing, the node is taken off | |
1995 | * the ADISC list and placed on either the mapped or unmapped list (depending | |
1996 | * on its previous state). Once on the unmapped list, a PRLI is issued and the | |
1997 | * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is | |
1998 | * changed to UNMAPPED_NODE. If the completion indicates a mapped | |
1999 | * node, the node is taken off the unmapped list. The binding list is checked | |
2000 | * for a valid binding, or a binding is automatically assigned. If binding | |
2001 | * assignment is unsuccessful, the node is left on the unmapped list. If | |
2002 | * binding assignment is successful, the associated binding list entry (if | |
2003 | * any) is removed, and the node is placed on the mapped list. | |
2004 | */ | |
2005 | /* | |
2006 | * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped | |
c01f3208 | 2007 | * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers |
dea3101e JB |
2008 | * expire, all effected nodes will receive a DEVICE_RM event. |
2009 | */ | |
2010 | /* | |
2011 | * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists | |
2012 | * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap | |
2013 | * check, additional nodes may be added or removed (via DEVICE_RM) to / from | |
2014 | * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated, | |
2015 | * we will first process the ADISC list. 32 entries are processed initially and | |
2016 | * ADISC is initited for each one. Completions / Events for each node are | |
2017 | * funnelled thru the state machine. As each node finishes ADISC processing, it | |
2018 | * starts ADISC for any nodes waiting for ADISC processing. If no nodes are | |
2019 | * waiting, and the ADISC list count is identically 0, then we are done. For | |
2020 | * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we | |
2021 | * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI | |
2022 | * list. 32 entries are processed initially and PLOGI is initited for each one. | |
2023 | * Completions / Events for each node are funnelled thru the state machine. As | |
2024 | * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting | |
2025 | * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is | |
2026 | * indentically 0, then we are done. We have now completed discovery / RSCN | |
2027 | * handling. Upon completion, ALL nodes should be on either the mapped or | |
2028 | * unmapped lists. | |
2029 | */ | |
2030 | ||
2031 | static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT]) | |
2e0fef85 | 2032 | (struct lpfc_vport *, struct lpfc_nodelist *, void *, uint32_t) = { |
dea3101e JB |
2033 | /* Action routine Event Current State */ |
2034 | lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */ | |
2035 | lpfc_rcv_els_unused_node, /* RCV_PRLI */ | |
2036 | lpfc_rcv_logo_unused_node, /* RCV_LOGO */ | |
2037 | lpfc_rcv_els_unused_node, /* RCV_ADISC */ | |
2038 | lpfc_rcv_els_unused_node, /* RCV_PDISC */ | |
2039 | lpfc_rcv_els_unused_node, /* RCV_PRLO */ | |
2040 | lpfc_disc_illegal, /* CMPL_PLOGI */ | |
2041 | lpfc_disc_illegal, /* CMPL_PRLI */ | |
2042 | lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */ | |
2043 | lpfc_disc_illegal, /* CMPL_ADISC */ | |
2044 | lpfc_disc_illegal, /* CMPL_REG_LOGIN */ | |
2045 | lpfc_device_rm_unused_node, /* DEVICE_RM */ | |
2046 | lpfc_disc_illegal, /* DEVICE_RECOVERY */ | |
2047 | ||
2048 | lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */ | |
92d7f7b0 | 2049 | lpfc_rcv_prli_plogi_issue, /* RCV_PRLI */ |
c9f8735b | 2050 | lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */ |
dea3101e JB |
2051 | lpfc_rcv_els_plogi_issue, /* RCV_ADISC */ |
2052 | lpfc_rcv_els_plogi_issue, /* RCV_PDISC */ | |
2053 | lpfc_rcv_els_plogi_issue, /* RCV_PRLO */ | |
2054 | lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */ | |
2055 | lpfc_disc_illegal, /* CMPL_PRLI */ | |
0ff10d46 | 2056 | lpfc_cmpl_logo_plogi_issue, /* CMPL_LOGO */ |
dea3101e | 2057 | lpfc_disc_illegal, /* CMPL_ADISC */ |
0ff10d46 | 2058 | lpfc_cmpl_reglogin_plogi_issue,/* CMPL_REG_LOGIN */ |
dea3101e JB |
2059 | lpfc_device_rm_plogi_issue, /* DEVICE_RM */ |
2060 | lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */ | |
2061 | ||
2062 | lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */ | |
2063 | lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */ | |
2064 | lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */ | |
2065 | lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */ | |
2066 | lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */ | |
2067 | lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */ | |
2068 | lpfc_disc_illegal, /* CMPL_PLOGI */ | |
2069 | lpfc_disc_illegal, /* CMPL_PRLI */ | |
2070 | lpfc_disc_illegal, /* CMPL_LOGO */ | |
2071 | lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */ | |
2072 | lpfc_disc_illegal, /* CMPL_REG_LOGIN */ | |
2073 | lpfc_device_rm_adisc_issue, /* DEVICE_RM */ | |
2074 | lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */ | |
2075 | ||
2076 | lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */ | |
2077 | lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */ | |
2078 | lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */ | |
2079 | lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */ | |
2080 | lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */ | |
2081 | lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */ | |
87af33fe | 2082 | lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */ |
dea3101e JB |
2083 | lpfc_disc_illegal, /* CMPL_PRLI */ |
2084 | lpfc_disc_illegal, /* CMPL_LOGO */ | |
2085 | lpfc_disc_illegal, /* CMPL_ADISC */ | |
2086 | lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */ | |
2087 | lpfc_device_rm_reglogin_issue, /* DEVICE_RM */ | |
2088 | lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */ | |
2089 | ||
2090 | lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */ | |
2091 | lpfc_rcv_prli_prli_issue, /* RCV_PRLI */ | |
2092 | lpfc_rcv_logo_prli_issue, /* RCV_LOGO */ | |
2093 | lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */ | |
2094 | lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */ | |
2095 | lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */ | |
87af33fe | 2096 | lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */ |
dea3101e JB |
2097 | lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */ |
2098 | lpfc_disc_illegal, /* CMPL_LOGO */ | |
2099 | lpfc_disc_illegal, /* CMPL_ADISC */ | |
2100 | lpfc_disc_illegal, /* CMPL_REG_LOGIN */ | |
2101 | lpfc_device_rm_prli_issue, /* DEVICE_RM */ | |
2102 | lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */ | |
2103 | ||
2104 | lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */ | |
2105 | lpfc_rcv_prli_unmap_node, /* RCV_PRLI */ | |
2106 | lpfc_rcv_logo_unmap_node, /* RCV_LOGO */ | |
2107 | lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */ | |
2108 | lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */ | |
2109 | lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */ | |
2110 | lpfc_disc_illegal, /* CMPL_PLOGI */ | |
2111 | lpfc_disc_illegal, /* CMPL_PRLI */ | |
2112 | lpfc_disc_illegal, /* CMPL_LOGO */ | |
2113 | lpfc_disc_illegal, /* CMPL_ADISC */ | |
2114 | lpfc_disc_illegal, /* CMPL_REG_LOGIN */ | |
2115 | lpfc_disc_illegal, /* DEVICE_RM */ | |
2116 | lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */ | |
2117 | ||
2118 | lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */ | |
2119 | lpfc_rcv_prli_mapped_node, /* RCV_PRLI */ | |
2120 | lpfc_rcv_logo_mapped_node, /* RCV_LOGO */ | |
2121 | lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */ | |
2122 | lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */ | |
2123 | lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */ | |
2124 | lpfc_disc_illegal, /* CMPL_PLOGI */ | |
2125 | lpfc_disc_illegal, /* CMPL_PRLI */ | |
2126 | lpfc_disc_illegal, /* CMPL_LOGO */ | |
2127 | lpfc_disc_illegal, /* CMPL_ADISC */ | |
2128 | lpfc_disc_illegal, /* CMPL_REG_LOGIN */ | |
2129 | lpfc_disc_illegal, /* DEVICE_RM */ | |
2130 | lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */ | |
2131 | ||
2132 | lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */ | |
2133 | lpfc_rcv_prli_npr_node, /* RCV_PRLI */ | |
2134 | lpfc_rcv_logo_npr_node, /* RCV_LOGO */ | |
2135 | lpfc_rcv_padisc_npr_node, /* RCV_ADISC */ | |
2136 | lpfc_rcv_padisc_npr_node, /* RCV_PDISC */ | |
2137 | lpfc_rcv_prlo_npr_node, /* RCV_PRLO */ | |
c9f8735b JW |
2138 | lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */ |
2139 | lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */ | |
dea3101e | 2140 | lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */ |
c9f8735b | 2141 | lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */ |
dea3101e JB |
2142 | lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */ |
2143 | lpfc_device_rm_npr_node, /* DEVICE_RM */ | |
2144 | lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */ | |
2145 | }; | |
2146 | ||
2147 | int | |
2e0fef85 JS |
2148 | lpfc_disc_state_machine(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
2149 | void *arg, uint32_t evt) | |
dea3101e JB |
2150 | { |
2151 | uint32_t cur_state, rc; | |
2e0fef85 | 2152 | uint32_t(*func) (struct lpfc_vport *, struct lpfc_nodelist *, void *, |
dea3101e | 2153 | uint32_t); |
e47c9093 JS |
2154 | uint32_t got_ndlp = 0; |
2155 | ||
2156 | if (lpfc_nlp_get(ndlp)) | |
2157 | got_ndlp = 1; | |
dea3101e | 2158 | |
dea3101e JB |
2159 | cur_state = ndlp->nlp_state; |
2160 | ||
2161 | /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */ | |
e8b62011 JS |
2162 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
2163 | "0211 DSM in event x%x on NPort x%x in " | |
2164 | "state %d Data: x%x\n", | |
2165 | evt, ndlp->nlp_DID, cur_state, ndlp->nlp_flag); | |
dea3101e | 2166 | |
858c9f6c JS |
2167 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM, |
2168 | "DSM in: evt:%d ste:%d did:x%x", | |
2169 | evt, cur_state, ndlp->nlp_DID); | |
2170 | ||
dea3101e | 2171 | func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt]; |
2e0fef85 | 2172 | rc = (func) (vport, ndlp, arg, evt); |
dea3101e JB |
2173 | |
2174 | /* DSM out state <rc> on NPort <nlp_DID> */ | |
e47c9093 JS |
2175 | if (got_ndlp) { |
2176 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, | |
e8b62011 JS |
2177 | "0212 DSM out state %d on NPort x%x Data: x%x\n", |
2178 | rc, ndlp->nlp_DID, ndlp->nlp_flag); | |
dea3101e | 2179 | |
e47c9093 JS |
2180 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM, |
2181 | "DSM out: ste:%d did:x%x flg:x%x", | |
2182 | rc, ndlp->nlp_DID, ndlp->nlp_flag); | |
2183 | /* Decrement the ndlp reference count held for this function */ | |
2184 | lpfc_nlp_put(ndlp); | |
2185 | } else { | |
2186 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, | |
2187 | "0212 DSM out state %d on NPort free\n", rc); | |
858c9f6c | 2188 | |
e47c9093 JS |
2189 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM, |
2190 | "DSM out: ste:%d did:x%x flg:x%x", | |
2191 | rc, 0, 0); | |
2192 | } | |
dea3101e | 2193 | |
c9f8735b | 2194 | return rc; |
dea3101e | 2195 | } |