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