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