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