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