]>
Commit | Line | Data |
---|---|---|
dea3101e JB |
1 | /******************************************************************* |
2 | * This file is part of the Emulex Linux Device Driver for * | |
c44ce173 | 3 | * Fibre Channel Host Bus Adapters. * |
4fede78f | 4 | * Copyright (C) 2004-2010 Emulex. All rights reserved. * |
c44ce173 | 5 | * EMULEX and SLI are trademarks of Emulex. * |
dea3101e JB |
6 | * www.emulex.com * |
7 | * * | |
8 | * This program is free software; you can redistribute it and/or * | |
c44ce173 JSEC |
9 | * modify it under the terms of version 2 of the GNU General * |
10 | * Public License as published by the Free Software Foundation. * | |
11 | * This program is distributed in the hope that it will be useful. * | |
12 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * | |
13 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * | |
14 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * | |
15 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * | |
16 | * TO BE LEGALLY INVALID. See the GNU General Public License for * | |
17 | * more details, a copy of which can be found in the file COPYING * | |
18 | * included with this package. * | |
dea3101e JB |
19 | *******************************************************************/ |
20 | ||
21 | /* | |
09372820 | 22 | * Fibre Channel SCSI LAN Device Driver CT support: FC Generic Services FC-GS |
dea3101e JB |
23 | */ |
24 | ||
25 | #include <linux/blkdev.h> | |
26 | #include <linux/pci.h> | |
27 | #include <linux/interrupt.h> | |
28 | #include <linux/utsname.h> | |
29 | ||
91886523 | 30 | #include <scsi/scsi.h> |
dea3101e JB |
31 | #include <scsi/scsi_device.h> |
32 | #include <scsi/scsi_host.h> | |
f888ba3c | 33 | #include <scsi/scsi_transport_fc.h> |
6a9c52cf | 34 | #include <scsi/fc/fc_fs.h> |
dea3101e | 35 | |
da0436e9 | 36 | #include "lpfc_hw4.h" |
dea3101e JB |
37 | #include "lpfc_hw.h" |
38 | #include "lpfc_sli.h" | |
da0436e9 | 39 | #include "lpfc_sli4.h" |
ea2151b4 | 40 | #include "lpfc_nl.h" |
dea3101e JB |
41 | #include "lpfc_disc.h" |
42 | #include "lpfc_scsi.h" | |
43 | #include "lpfc.h" | |
44 | #include "lpfc_logmsg.h" | |
45 | #include "lpfc_crtn.h" | |
46 | #include "lpfc_version.h" | |
92d7f7b0 | 47 | #include "lpfc_vport.h" |
858c9f6c | 48 | #include "lpfc_debugfs.h" |
dea3101e JB |
49 | |
50 | #define HBA_PORTSPEED_UNKNOWN 0 /* Unknown - transceiver | |
51 | * incapable of reporting */ | |
52 | #define HBA_PORTSPEED_1GBIT 1 /* 1 GBit/sec */ | |
53 | #define HBA_PORTSPEED_2GBIT 2 /* 2 GBit/sec */ | |
54 | #define HBA_PORTSPEED_4GBIT 8 /* 4 GBit/sec */ | |
55 | #define HBA_PORTSPEED_8GBIT 16 /* 8 GBit/sec */ | |
56 | #define HBA_PORTSPEED_10GBIT 4 /* 10 GBit/sec */ | |
57 | #define HBA_PORTSPEED_NOT_NEGOTIATED 5 /* Speed not established */ | |
58 | ||
59 | #define FOURBYTES 4 | |
60 | ||
61 | ||
62 | static char *lpfc_release_version = LPFC_DRIVER_VERSION; | |
63 | ||
ed957684 | 64 | static void |
9c2face6 JS |
65 | lpfc_ct_ignore_hbq_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq, |
66 | struct lpfc_dmabuf *mp, uint32_t size) | |
ed957684 JS |
67 | { |
68 | if (!mp) { | |
9c2face6 | 69 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
97eab634 | 70 | "0146 Ignoring unsolicited CT No HBQ " |
9c2face6 JS |
71 | "status = x%x\n", |
72 | piocbq->iocb.ulpStatus); | |
ed957684 | 73 | } |
9c2face6 JS |
74 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
75 | "0145 Ignoring unsolicted CT HBQ Size:%d " | |
76 | "status = x%x\n", | |
77 | size, piocbq->iocb.ulpStatus); | |
ed957684 JS |
78 | } |
79 | ||
80 | static void | |
9c2face6 JS |
81 | lpfc_ct_unsol_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq, |
82 | struct lpfc_dmabuf *mp, uint32_t size) | |
ed957684 | 83 | { |
9c2face6 | 84 | lpfc_ct_ignore_hbq_buffer(phba, piocbq, mp, size); |
ed957684 JS |
85 | } |
86 | ||
dea3101e | 87 | void |
2e0fef85 JS |
88 | lpfc_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
89 | struct lpfc_iocbq *piocbq) | |
dea3101e | 90 | { |
ed957684 | 91 | struct lpfc_dmabuf *mp = NULL; |
dea3101e | 92 | IOCB_t *icmd = &piocbq->iocb; |
ed957684 JS |
93 | int i; |
94 | struct lpfc_iocbq *iocbq; | |
95 | dma_addr_t paddr; | |
96 | uint32_t size; | |
9c2face6 JS |
97 | struct list_head head; |
98 | struct lpfc_dmabuf *bdeBuf; | |
dea3101e | 99 | |
4fede78f JS |
100 | if (lpfc_bsg_ct_unsol_event(phba, pring, piocbq) == 0) |
101 | return; | |
f1c3b0fc | 102 | |
92d7f7b0 JS |
103 | if (unlikely(icmd->ulpStatus == IOSTAT_NEED_BUFFER)) { |
104 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); | |
105 | } else if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) && | |
106 | ((icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING)) { | |
dea3101e JB |
107 | /* Not enough posted buffers; Try posting more buffers */ |
108 | phba->fc_stat.NoRcvBuf++; | |
92d7f7b0 | 109 | if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) |
495a714c | 110 | lpfc_post_buffer(phba, pring, 2); |
dea3101e JB |
111 | return; |
112 | } | |
113 | ||
114 | /* If there are no BDEs associated with this IOCB, | |
115 | * there is nothing to do. | |
116 | */ | |
117 | if (icmd->ulpBdeCount == 0) | |
118 | return; | |
119 | ||
ed957684 | 120 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
9c2face6 JS |
121 | INIT_LIST_HEAD(&head); |
122 | list_add_tail(&head, &piocbq->list); | |
123 | list_for_each_entry(iocbq, &head, list) { | |
ed957684 | 124 | icmd = &iocbq->iocb; |
9c2face6 | 125 | if (icmd->ulpBdeCount == 0) |
ed957684 | 126 | continue; |
9c2face6 JS |
127 | bdeBuf = iocbq->context2; |
128 | iocbq->context2 = NULL; | |
ed957684 | 129 | size = icmd->un.cont64[0].tus.f.bdeSize; |
9c2face6 JS |
130 | lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf, size); |
131 | lpfc_in_buf_free(phba, bdeBuf); | |
ed957684 | 132 | if (icmd->ulpBdeCount == 2) { |
9c2face6 JS |
133 | bdeBuf = iocbq->context3; |
134 | iocbq->context3 = NULL; | |
135 | size = icmd->unsli3.rcvsli3.bde2.tus.f.bdeSize; | |
136 | lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf, | |
137 | size); | |
138 | lpfc_in_buf_free(phba, bdeBuf); | |
ed957684 | 139 | } |
dea3101e | 140 | } |
9c2face6 | 141 | list_del(&head); |
ed957684 | 142 | } else { |
d7c255b2 JS |
143 | INIT_LIST_HEAD(&head); |
144 | list_add_tail(&head, &piocbq->list); | |
145 | list_for_each_entry(iocbq, &head, list) { | |
ed957684 | 146 | icmd = &iocbq->iocb; |
9c2face6 | 147 | if (icmd->ulpBdeCount == 0) |
d7c255b2 | 148 | lpfc_ct_unsol_buffer(phba, iocbq, NULL, 0); |
ed957684 JS |
149 | for (i = 0; i < icmd->ulpBdeCount; i++) { |
150 | paddr = getPaddr(icmd->un.cont64[i].addrHigh, | |
151 | icmd->un.cont64[i].addrLow); | |
152 | mp = lpfc_sli_ringpostbuf_get(phba, pring, | |
153 | paddr); | |
154 | size = icmd->un.cont64[i].tus.f.bdeSize; | |
d7c255b2 | 155 | lpfc_ct_unsol_buffer(phba, iocbq, mp, size); |
92d7f7b0 | 156 | lpfc_in_buf_free(phba, mp); |
ed957684 | 157 | } |
495a714c | 158 | lpfc_post_buffer(phba, pring, i); |
dea3101e | 159 | } |
d7c255b2 | 160 | list_del(&head); |
dea3101e | 161 | } |
dea3101e JB |
162 | } |
163 | ||
6669f9bb JS |
164 | /** |
165 | * lpfc_sli4_ct_abort_unsol_event - Default handle for sli4 unsol abort | |
166 | * @phba: Pointer to HBA context object. | |
167 | * @pring: Pointer to the driver internal I/O ring. | |
168 | * @piocbq: Pointer to the IOCBQ. | |
169 | * | |
170 | * This function serves as the default handler for the sli4 unsolicited | |
171 | * abort event. It shall be invoked when there is no application interface | |
172 | * registered unsolicited abort handler. This handler does nothing but | |
173 | * just simply releases the dma buffer used by the unsol abort event. | |
174 | **/ | |
175 | void | |
176 | lpfc_sli4_ct_abort_unsol_event(struct lpfc_hba *phba, | |
177 | struct lpfc_sli_ring *pring, | |
178 | struct lpfc_iocbq *piocbq) | |
179 | { | |
180 | IOCB_t *icmd = &piocbq->iocb; | |
181 | struct lpfc_dmabuf *bdeBuf; | |
182 | uint32_t size; | |
183 | ||
184 | /* Forward abort event to any process registered to receive ct event */ | |
4fede78f JS |
185 | if (lpfc_bsg_ct_unsol_event(phba, pring, piocbq) == 0) |
186 | return; | |
6669f9bb JS |
187 | |
188 | /* If there is no BDE associated with IOCB, there is nothing to do */ | |
189 | if (icmd->ulpBdeCount == 0) | |
190 | return; | |
191 | bdeBuf = piocbq->context2; | |
192 | piocbq->context2 = NULL; | |
193 | size = icmd->un.cont64[0].tus.f.bdeSize; | |
194 | lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf, size); | |
195 | lpfc_in_buf_free(phba, bdeBuf); | |
196 | } | |
197 | ||
dea3101e | 198 | static void |
2e0fef85 | 199 | lpfc_free_ct_rsp(struct lpfc_hba *phba, struct lpfc_dmabuf *mlist) |
dea3101e JB |
200 | { |
201 | struct lpfc_dmabuf *mlast, *next_mlast; | |
202 | ||
203 | list_for_each_entry_safe(mlast, next_mlast, &mlist->list, list) { | |
204 | lpfc_mbuf_free(phba, mlast->virt, mlast->phys); | |
205 | list_del(&mlast->list); | |
206 | kfree(mlast); | |
207 | } | |
208 | lpfc_mbuf_free(phba, mlist->virt, mlist->phys); | |
209 | kfree(mlist); | |
210 | return; | |
211 | } | |
212 | ||
213 | static struct lpfc_dmabuf * | |
2e0fef85 | 214 | lpfc_alloc_ct_rsp(struct lpfc_hba *phba, int cmdcode, struct ulp_bde64 *bpl, |
dea3101e JB |
215 | uint32_t size, int *entries) |
216 | { | |
217 | struct lpfc_dmabuf *mlist = NULL; | |
218 | struct lpfc_dmabuf *mp; | |
219 | int cnt, i = 0; | |
220 | ||
09372820 | 221 | /* We get chunks of FCELSSIZE */ |
dea3101e JB |
222 | cnt = size > FCELSSIZE ? FCELSSIZE: size; |
223 | ||
224 | while (size) { | |
225 | /* Allocate buffer for rsp payload */ | |
226 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
227 | if (!mp) { | |
228 | if (mlist) | |
229 | lpfc_free_ct_rsp(phba, mlist); | |
230 | return NULL; | |
231 | } | |
232 | ||
233 | INIT_LIST_HEAD(&mp->list); | |
234 | ||
92d7f7b0 JS |
235 | if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT) || |
236 | cmdcode == be16_to_cpu(SLI_CTNS_GFF_ID)) | |
dea3101e JB |
237 | mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys)); |
238 | else | |
239 | mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys)); | |
240 | ||
241 | if (!mp->virt) { | |
242 | kfree(mp); | |
0b3a82d3 ES |
243 | if (mlist) |
244 | lpfc_free_ct_rsp(phba, mlist); | |
dea3101e JB |
245 | return NULL; |
246 | } | |
247 | ||
248 | /* Queue it to a linked list */ | |
249 | if (!mlist) | |
250 | mlist = mp; | |
251 | else | |
252 | list_add_tail(&mp->list, &mlist->list); | |
253 | ||
34b02dcd | 254 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I; |
dea3101e | 255 | /* build buffer ptr list for IOCB */ |
92d7f7b0 JS |
256 | bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) ); |
257 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) ); | |
dea3101e JB |
258 | bpl->tus.f.bdeSize = (uint16_t) cnt; |
259 | bpl->tus.w = le32_to_cpu(bpl->tus.w); | |
260 | bpl++; | |
261 | ||
262 | i++; | |
263 | size -= cnt; | |
264 | } | |
265 | ||
266 | *entries = i; | |
267 | return mlist; | |
268 | } | |
269 | ||
858c9f6c JS |
270 | int |
271 | lpfc_ct_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *ctiocb) | |
272 | { | |
273 | struct lpfc_dmabuf *buf_ptr; | |
274 | ||
51ef4c26 JS |
275 | if (ctiocb->context_un.ndlp) { |
276 | lpfc_nlp_put(ctiocb->context_un.ndlp); | |
277 | ctiocb->context_un.ndlp = NULL; | |
278 | } | |
858c9f6c JS |
279 | if (ctiocb->context1) { |
280 | buf_ptr = (struct lpfc_dmabuf *) ctiocb->context1; | |
281 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); | |
282 | kfree(buf_ptr); | |
283 | ctiocb->context1 = NULL; | |
284 | } | |
285 | if (ctiocb->context2) { | |
286 | lpfc_free_ct_rsp(phba, (struct lpfc_dmabuf *) ctiocb->context2); | |
287 | ctiocb->context2 = NULL; | |
288 | } | |
289 | ||
290 | if (ctiocb->context3) { | |
291 | buf_ptr = (struct lpfc_dmabuf *) ctiocb->context3; | |
292 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); | |
293 | kfree(buf_ptr); | |
294 | ctiocb->context1 = NULL; | |
295 | } | |
296 | lpfc_sli_release_iocbq(phba, ctiocb); | |
297 | return 0; | |
298 | } | |
299 | ||
dea3101e | 300 | static int |
2e0fef85 | 301 | lpfc_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp, |
dea3101e JB |
302 | struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp, |
303 | void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *, | |
304 | struct lpfc_iocbq *), | |
305 | struct lpfc_nodelist *ndlp, uint32_t usr_flg, uint32_t num_entry, | |
92d7f7b0 | 306 | uint32_t tmo, uint8_t retry) |
dea3101e | 307 | { |
2e0fef85 | 308 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 309 | IOCB_t *icmd; |
0bd4ca25 | 310 | struct lpfc_iocbq *geniocb; |
92d7f7b0 | 311 | int rc; |
dea3101e JB |
312 | |
313 | /* Allocate buffer for command iocb */ | |
0bd4ca25 | 314 | geniocb = lpfc_sli_get_iocbq(phba); |
dea3101e JB |
315 | |
316 | if (geniocb == NULL) | |
317 | return 1; | |
dea3101e JB |
318 | |
319 | icmd = &geniocb->iocb; | |
320 | icmd->un.genreq64.bdl.ulpIoTag32 = 0; | |
321 | icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys); | |
322 | icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys); | |
34b02dcd | 323 | icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; |
dea3101e JB |
324 | icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof (struct ulp_bde64)); |
325 | ||
326 | if (usr_flg) | |
327 | geniocb->context3 = NULL; | |
328 | else | |
329 | geniocb->context3 = (uint8_t *) bmp; | |
330 | ||
331 | /* Save for completion so we can release these resources */ | |
332 | geniocb->context1 = (uint8_t *) inp; | |
333 | geniocb->context2 = (uint8_t *) outp; | |
e47c9093 | 334 | geniocb->context_un.ndlp = lpfc_nlp_get(ndlp); |
dea3101e JB |
335 | |
336 | /* Fill in payload, bp points to frame payload */ | |
337 | icmd->ulpCommand = CMD_GEN_REQUEST64_CR; | |
338 | ||
339 | /* Fill in rest of iocb */ | |
340 | icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA); | |
341 | icmd->un.genreq64.w5.hcsw.Dfctl = 0; | |
6a9c52cf JS |
342 | icmd->un.genreq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CTL; |
343 | icmd->un.genreq64.w5.hcsw.Type = FC_TYPE_CT; | |
dea3101e | 344 | |
c9f8735b JW |
345 | if (!tmo) { |
346 | /* FC spec states we need 3 * ratov for CT requests */ | |
347 | tmo = (3 * phba->fc_ratov); | |
348 | } | |
dea3101e JB |
349 | icmd->ulpTimeout = tmo; |
350 | icmd->ulpBdeCount = 1; | |
351 | icmd->ulpLe = 1; | |
352 | icmd->ulpClass = CLASS3; | |
353 | icmd->ulpContext = ndlp->nlp_rpi; | |
354 | ||
92d7f7b0 JS |
355 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
356 | /* For GEN_REQUEST64_CR, use the RPI */ | |
357 | icmd->ulpCt_h = 0; | |
358 | icmd->ulpCt_l = 0; | |
359 | } | |
360 | ||
dea3101e | 361 | /* Issue GEN REQ IOCB for NPORT <did> */ |
e8b62011 JS |
362 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
363 | "0119 Issue GEN REQ IOCB to NPORT x%x " | |
364 | "Data: x%x x%x\n", | |
365 | ndlp->nlp_DID, icmd->ulpIoTag, | |
366 | vport->port_state); | |
dea3101e JB |
367 | geniocb->iocb_cmpl = cmpl; |
368 | geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT; | |
2e0fef85 | 369 | geniocb->vport = vport; |
92d7f7b0 | 370 | geniocb->retry = retry; |
3772a991 | 371 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, geniocb, 0); |
92d7f7b0 JS |
372 | |
373 | if (rc == IOCB_ERROR) { | |
604a3e30 | 374 | lpfc_sli_release_iocbq(phba, geniocb); |
dea3101e JB |
375 | return 1; |
376 | } | |
dea3101e JB |
377 | |
378 | return 0; | |
379 | } | |
380 | ||
381 | static int | |
2e0fef85 | 382 | lpfc_ct_cmd(struct lpfc_vport *vport, struct lpfc_dmabuf *inmp, |
dea3101e JB |
383 | struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp, |
384 | void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *, | |
385 | struct lpfc_iocbq *), | |
92d7f7b0 | 386 | uint32_t rsp_size, uint8_t retry) |
dea3101e | 387 | { |
2e0fef85 | 388 | struct lpfc_hba *phba = vport->phba; |
dea3101e JB |
389 | struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt; |
390 | struct lpfc_dmabuf *outmp; | |
391 | int cnt = 0, status; | |
392 | int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)-> | |
393 | CommandResponse.bits.CmdRsp; | |
394 | ||
395 | bpl++; /* Skip past ct request */ | |
396 | ||
397 | /* Put buffer(s) for ct rsp in bpl */ | |
398 | outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt); | |
399 | if (!outmp) | |
400 | return -ENOMEM; | |
6a9c52cf JS |
401 | /* |
402 | * Form the CT IOCB. The total number of BDEs in this IOCB | |
403 | * is the single command plus response count from | |
404 | * lpfc_alloc_ct_rsp. | |
405 | */ | |
406 | cnt += 1; | |
2e0fef85 | 407 | status = lpfc_gen_req(vport, bmp, inmp, outmp, cmpl, ndlp, 0, |
6a9c52cf | 408 | cnt, 0, retry); |
dea3101e JB |
409 | if (status) { |
410 | lpfc_free_ct_rsp(phba, outmp); | |
411 | return -ENOMEM; | |
412 | } | |
413 | return 0; | |
414 | } | |
415 | ||
549e55cd | 416 | struct lpfc_vport * |
92d7f7b0 | 417 | lpfc_find_vport_by_did(struct lpfc_hba *phba, uint32_t did) { |
92d7f7b0 | 418 | struct lpfc_vport *vport_curr; |
549e55cd | 419 | unsigned long flags; |
92d7f7b0 | 420 | |
549e55cd | 421 | spin_lock_irqsave(&phba->hbalock, flags); |
92d7f7b0 | 422 | list_for_each_entry(vport_curr, &phba->port_list, listentry) { |
549e55cd JS |
423 | if ((vport_curr->fc_myDID) && (vport_curr->fc_myDID == did)) { |
424 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
92d7f7b0 | 425 | return vport_curr; |
549e55cd | 426 | } |
92d7f7b0 | 427 | } |
549e55cd | 428 | spin_unlock_irqrestore(&phba->hbalock, flags); |
92d7f7b0 JS |
429 | return NULL; |
430 | } | |
431 | ||
dea3101e | 432 | static int |
2e0fef85 | 433 | lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint32_t Size) |
dea3101e | 434 | { |
2e0fef85 | 435 | struct lpfc_hba *phba = vport->phba; |
dea3101e JB |
436 | struct lpfc_sli_ct_request *Response = |
437 | (struct lpfc_sli_ct_request *) mp->virt; | |
438 | struct lpfc_nodelist *ndlp = NULL; | |
439 | struct lpfc_dmabuf *mlast, *next_mp; | |
440 | uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType; | |
2e0fef85 | 441 | uint32_t Did, CTentry; |
dea3101e JB |
442 | int Cnt; |
443 | struct list_head head; | |
444 | ||
2e0fef85 | 445 | lpfc_set_disctmo(vport); |
92d7f7b0 | 446 | vport->num_disc_nodes = 0; |
0ff10d46 | 447 | vport->fc_ns_retry = 0; |
dea3101e | 448 | |
dea3101e JB |
449 | |
450 | list_add_tail(&head, &mp->list); | |
451 | list_for_each_entry_safe(mp, next_mp, &head, list) { | |
452 | mlast = mp; | |
453 | ||
7054a606 JS |
454 | Cnt = Size > FCELSSIZE ? FCELSSIZE : Size; |
455 | ||
dea3101e JB |
456 | Size -= Cnt; |
457 | ||
1dcb58e5 | 458 | if (!ctptr) { |
dea3101e | 459 | ctptr = (uint32_t *) mlast->virt; |
1dcb58e5 | 460 | } else |
dea3101e JB |
461 | Cnt -= 16; /* subtract length of CT header */ |
462 | ||
463 | /* Loop through entire NameServer list of DIDs */ | |
7054a606 | 464 | while (Cnt >= sizeof (uint32_t)) { |
dea3101e JB |
465 | /* Get next DID from NameServer List */ |
466 | CTentry = *ctptr++; | |
467 | Did = ((be32_to_cpu(CTentry)) & Mask_DID); | |
92d7f7b0 | 468 | |
dea3101e | 469 | ndlp = NULL; |
92d7f7b0 JS |
470 | |
471 | /* | |
472 | * Check for rscn processing or not | |
473 | * To conserve rpi's, filter out addresses for other | |
474 | * vports on the same physical HBAs. | |
475 | */ | |
476 | if ((Did != vport->fc_myDID) && | |
477 | ((lpfc_find_vport_by_did(phba, Did) == NULL) || | |
3de2a653 | 478 | vport->cfg_peer_port_login)) { |
92d7f7b0 | 479 | if ((vport->port_type != LPFC_NPIV_PORT) || |
98c9ea5c | 480 | (!(vport->ct_flags & FC_CT_RFF_ID)) || |
3de2a653 | 481 | (!vport->cfg_restrict_login)) { |
92d7f7b0 | 482 | ndlp = lpfc_setup_disc_node(vport, Did); |
58da1ffb | 483 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
858c9f6c JS |
484 | lpfc_debugfs_disc_trc(vport, |
485 | LPFC_DISC_TRC_CT, | |
486 | "Parse GID_FTrsp: " | |
487 | "did:x%x flg:x%x x%x", | |
488 | Did, ndlp->nlp_flag, | |
489 | vport->fc_flag); | |
490 | ||
e8b62011 JS |
491 | lpfc_printf_vlog(vport, |
492 | KERN_INFO, | |
92d7f7b0 | 493 | LOG_DISCOVERY, |
e8b62011 | 494 | "0238 Process " |
92d7f7b0 JS |
495 | "x%x NameServer Rsp" |
496 | "Data: x%x x%x x%x\n", | |
e8b62011 | 497 | Did, ndlp->nlp_flag, |
92d7f7b0 JS |
498 | vport->fc_flag, |
499 | vport->fc_rscn_id_cnt); | |
500 | } else { | |
858c9f6c JS |
501 | lpfc_debugfs_disc_trc(vport, |
502 | LPFC_DISC_TRC_CT, | |
503 | "Skip1 GID_FTrsp: " | |
504 | "did:x%x flg:x%x cnt:%d", | |
505 | Did, vport->fc_flag, | |
506 | vport->fc_rscn_id_cnt); | |
507 | ||
e8b62011 JS |
508 | lpfc_printf_vlog(vport, |
509 | KERN_INFO, | |
92d7f7b0 | 510 | LOG_DISCOVERY, |
e8b62011 | 511 | "0239 Skip x%x " |
92d7f7b0 JS |
512 | "NameServer Rsp Data: " |
513 | "x%x x%x\n", | |
e8b62011 | 514 | Did, vport->fc_flag, |
92d7f7b0 JS |
515 | vport->fc_rscn_id_cnt); |
516 | } | |
517 | ||
518 | } else { | |
519 | if (!(vport->fc_flag & FC_RSCN_MODE) || | |
520 | (lpfc_rscn_payload_check(vport, Did))) { | |
858c9f6c JS |
521 | lpfc_debugfs_disc_trc(vport, |
522 | LPFC_DISC_TRC_CT, | |
523 | "Query GID_FTrsp: " | |
524 | "did:x%x flg:x%x cnt:%d", | |
525 | Did, vport->fc_flag, | |
526 | vport->fc_rscn_id_cnt); | |
527 | ||
0ff10d46 JS |
528 | /* This NPortID was previously |
529 | * a FCP target, * Don't even | |
530 | * bother to send GFF_ID. | |
531 | */ | |
532 | ndlp = lpfc_findnode_did(vport, | |
533 | Did); | |
e47c9093 JS |
534 | if (ndlp && |
535 | NLP_CHK_NODE_ACT(ndlp) | |
536 | && (ndlp->nlp_type & | |
537 | NLP_FCP_TARGET)) | |
0ff10d46 JS |
538 | lpfc_setup_disc_node |
539 | (vport, Did); | |
540 | else if (lpfc_ns_cmd(vport, | |
92d7f7b0 JS |
541 | SLI_CTNS_GFF_ID, |
542 | 0, Did) == 0) | |
543 | vport->num_disc_nodes++; | |
6a9c52cf JS |
544 | else |
545 | lpfc_setup_disc_node | |
546 | (vport, Did); | |
92d7f7b0 JS |
547 | } |
548 | else { | |
858c9f6c JS |
549 | lpfc_debugfs_disc_trc(vport, |
550 | LPFC_DISC_TRC_CT, | |
551 | "Skip2 GID_FTrsp: " | |
552 | "did:x%x flg:x%x cnt:%d", | |
553 | Did, vport->fc_flag, | |
554 | vport->fc_rscn_id_cnt); | |
555 | ||
e8b62011 JS |
556 | lpfc_printf_vlog(vport, |
557 | KERN_INFO, | |
92d7f7b0 | 558 | LOG_DISCOVERY, |
e8b62011 | 559 | "0245 Skip x%x " |
92d7f7b0 JS |
560 | "NameServer Rsp Data: " |
561 | "x%x x%x\n", | |
e8b62011 | 562 | Did, vport->fc_flag, |
92d7f7b0 JS |
563 | vport->fc_rscn_id_cnt); |
564 | } | |
565 | } | |
dea3101e | 566 | } |
dea3101e JB |
567 | if (CTentry & (be32_to_cpu(SLI_CT_LAST_ENTRY))) |
568 | goto nsout1; | |
569 | Cnt -= sizeof (uint32_t); | |
570 | } | |
571 | ctptr = NULL; | |
572 | ||
573 | } | |
574 | ||
575 | nsout1: | |
576 | list_del(&head); | |
dea3101e JB |
577 | return 0; |
578 | } | |
579 | ||
dea3101e | 580 | static void |
2e0fef85 JS |
581 | lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
582 | struct lpfc_iocbq *rspiocb) | |
dea3101e | 583 | { |
2e0fef85 | 584 | struct lpfc_vport *vport = cmdiocb->vport; |
92d7f7b0 | 585 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
dea3101e | 586 | IOCB_t *irsp; |
dea3101e | 587 | struct lpfc_dmabuf *bmp; |
dea3101e | 588 | struct lpfc_dmabuf *outp; |
dea3101e | 589 | struct lpfc_sli_ct_request *CTrsp; |
51ef4c26 | 590 | struct lpfc_nodelist *ndlp; |
58da1ffb | 591 | int rc; |
dea3101e | 592 | |
51ef4c26 JS |
593 | /* First save ndlp, before we overwrite it */ |
594 | ndlp = cmdiocb->context_un.ndlp; | |
595 | ||
dea3101e JB |
596 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
597 | cmdiocb->context_un.rsp_iocb = rspiocb; | |
598 | ||
dea3101e JB |
599 | outp = (struct lpfc_dmabuf *) cmdiocb->context2; |
600 | bmp = (struct lpfc_dmabuf *) cmdiocb->context3; | |
858c9f6c JS |
601 | irsp = &rspiocb->iocb; |
602 | ||
603 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, | |
604 | "GID_FT cmpl: status:x%x/x%x rtry:%d", | |
605 | irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_ns_retry); | |
dea3101e | 606 | |
92d7f7b0 | 607 | /* Don't bother processing response if vport is being torn down. */ |
eada272d JS |
608 | if (vport->load_flag & FC_UNLOADING) { |
609 | if (vport->fc_flag & FC_RSCN_MODE) | |
610 | lpfc_els_flush_rscn(vport); | |
92d7f7b0 | 611 | goto out; |
eada272d | 612 | } |
92d7f7b0 | 613 | |
58da1ffb | 614 | if (lpfc_els_chk_latt(vport)) { |
e8b62011 JS |
615 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
616 | "0216 Link event during NS query\n"); | |
eada272d JS |
617 | if (vport->fc_flag & FC_RSCN_MODE) |
618 | lpfc_els_flush_rscn(vport); | |
858c9f6c JS |
619 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
620 | goto out; | |
621 | } | |
58da1ffb JS |
622 | if (lpfc_error_lost_link(irsp)) { |
623 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, | |
624 | "0226 NS query failed due to link event\n"); | |
eada272d JS |
625 | if (vport->fc_flag & FC_RSCN_MODE) |
626 | lpfc_els_flush_rscn(vport); | |
58da1ffb JS |
627 | goto out; |
628 | } | |
858c9f6c | 629 | if (irsp->ulpStatus) { |
dea3101e | 630 | /* Check for retry */ |
2e0fef85 | 631 | if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) { |
58da1ffb JS |
632 | if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT || |
633 | irsp->un.ulpWord[4] != IOERR_NO_RESOURCES) | |
858c9f6c | 634 | vport->fc_ns_retry++; |
0ff10d46 | 635 | |
58da1ffb JS |
636 | /* CT command is being retried */ |
637 | rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, | |
92d7f7b0 | 638 | vport->fc_ns_retry, 0); |
58da1ffb JS |
639 | if (rc == 0) |
640 | goto out; | |
92d7f7b0 | 641 | } |
eada272d JS |
642 | if (vport->fc_flag & FC_RSCN_MODE) |
643 | lpfc_els_flush_rscn(vport); | |
92d7f7b0 | 644 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
e8b62011 JS |
645 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
646 | "0257 GID_FT Query error: 0x%x 0x%x\n", | |
647 | irsp->ulpStatus, vport->fc_ns_retry); | |
dea3101e JB |
648 | } else { |
649 | /* Good status, continue checking */ | |
650 | CTrsp = (struct lpfc_sli_ct_request *) outp->virt; | |
651 | if (CTrsp->CommandResponse.bits.CmdRsp == | |
652 | be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) { | |
e8b62011 JS |
653 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
654 | "0208 NameServer Rsp Data: x%x\n", | |
655 | vport->fc_flag); | |
2e0fef85 | 656 | lpfc_ns_rsp(vport, outp, |
dea3101e JB |
657 | (uint32_t) (irsp->un.genreq64.bdl.bdeSize)); |
658 | } else if (CTrsp->CommandResponse.bits.CmdRsp == | |
659 | be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) { | |
660 | /* NameServer Rsp Error */ | |
a58cbd52 JS |
661 | if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ) |
662 | && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) { | |
e8b62011 JS |
663 | lpfc_printf_vlog(vport, KERN_INFO, |
664 | LOG_DISCOVERY, | |
665 | "0269 No NameServer Entries " | |
a58cbd52 | 666 | "Data: x%x x%x x%x x%x\n", |
a58cbd52 JS |
667 | CTrsp->CommandResponse.bits.CmdRsp, |
668 | (uint32_t) CTrsp->ReasonCode, | |
669 | (uint32_t) CTrsp->Explanation, | |
670 | vport->fc_flag); | |
671 | ||
672 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, | |
673 | "GID_FT no entry cmd:x%x rsn:x%x exp:x%x", | |
674 | (uint32_t)CTrsp->CommandResponse.bits.CmdRsp, | |
675 | (uint32_t) CTrsp->ReasonCode, | |
676 | (uint32_t) CTrsp->Explanation); | |
e8b62011 JS |
677 | } else { |
678 | lpfc_printf_vlog(vport, KERN_INFO, | |
679 | LOG_DISCOVERY, | |
680 | "0240 NameServer Rsp Error " | |
dea3101e | 681 | "Data: x%x x%x x%x x%x\n", |
dea3101e JB |
682 | CTrsp->CommandResponse.bits.CmdRsp, |
683 | (uint32_t) CTrsp->ReasonCode, | |
684 | (uint32_t) CTrsp->Explanation, | |
2e0fef85 | 685 | vport->fc_flag); |
858c9f6c | 686 | |
a58cbd52 | 687 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, |
858c9f6c JS |
688 | "GID_FT rsp err1 cmd:x%x rsn:x%x exp:x%x", |
689 | (uint32_t)CTrsp->CommandResponse.bits.CmdRsp, | |
690 | (uint32_t) CTrsp->ReasonCode, | |
691 | (uint32_t) CTrsp->Explanation); | |
a58cbd52 JS |
692 | } |
693 | ||
858c9f6c | 694 | |
dea3101e JB |
695 | } else { |
696 | /* NameServer Rsp Error */ | |
e8b62011 JS |
697 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
698 | "0241 NameServer Rsp Error " | |
dea3101e | 699 | "Data: x%x x%x x%x x%x\n", |
dea3101e JB |
700 | CTrsp->CommandResponse.bits.CmdRsp, |
701 | (uint32_t) CTrsp->ReasonCode, | |
702 | (uint32_t) CTrsp->Explanation, | |
2e0fef85 | 703 | vport->fc_flag); |
858c9f6c JS |
704 | |
705 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, | |
706 | "GID_FT rsp err2 cmd:x%x rsn:x%x exp:x%x", | |
707 | (uint32_t)CTrsp->CommandResponse.bits.CmdRsp, | |
708 | (uint32_t) CTrsp->ReasonCode, | |
709 | (uint32_t) CTrsp->Explanation); | |
dea3101e JB |
710 | } |
711 | } | |
712 | /* Link up / RSCN discovery */ | |
92d7f7b0 JS |
713 | if (vport->num_disc_nodes == 0) { |
714 | /* | |
715 | * The driver has cycled through all Nports in the RSCN payload. | |
716 | * Complete the handling by cleaning up and marking the | |
717 | * current driver state. | |
718 | */ | |
719 | if (vport->port_state >= LPFC_DISC_AUTH) { | |
720 | if (vport->fc_flag & FC_RSCN_MODE) { | |
721 | lpfc_els_flush_rscn(vport); | |
722 | spin_lock_irq(shost->host_lock); | |
723 | vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */ | |
724 | spin_unlock_irq(shost->host_lock); | |
725 | } | |
726 | else | |
727 | lpfc_els_flush_rscn(vport); | |
728 | } | |
729 | ||
730 | lpfc_disc_start(vport); | |
731 | } | |
732 | out: | |
51ef4c26 | 733 | cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */ |
858c9f6c | 734 | lpfc_ct_free_iocb(phba, cmdiocb); |
92d7f7b0 JS |
735 | return; |
736 | } | |
737 | ||
311464ec | 738 | static void |
92d7f7b0 JS |
739 | lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
740 | struct lpfc_iocbq *rspiocb) | |
741 | { | |
742 | struct lpfc_vport *vport = cmdiocb->vport; | |
743 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
744 | IOCB_t *irsp = &rspiocb->iocb; | |
92d7f7b0 JS |
745 | struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *) cmdiocb->context1; |
746 | struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *) cmdiocb->context2; | |
747 | struct lpfc_sli_ct_request *CTrsp; | |
0ff10d46 | 748 | int did, rc, retry; |
92d7f7b0 JS |
749 | uint8_t fbits; |
750 | struct lpfc_nodelist *ndlp; | |
751 | ||
752 | did = ((struct lpfc_sli_ct_request *) inp->virt)->un.gff.PortId; | |
753 | did = be32_to_cpu(did); | |
754 | ||
858c9f6c JS |
755 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, |
756 | "GFF_ID cmpl: status:x%x/x%x did:x%x", | |
757 | irsp->ulpStatus, irsp->un.ulpWord[4], did); | |
758 | ||
92d7f7b0 JS |
759 | if (irsp->ulpStatus == IOSTAT_SUCCESS) { |
760 | /* Good status, continue checking */ | |
761 | CTrsp = (struct lpfc_sli_ct_request *) outp->virt; | |
762 | fbits = CTrsp->un.gff_acc.fbits[FCP_TYPE_FEATURE_OFFSET]; | |
763 | ||
764 | if (CTrsp->CommandResponse.bits.CmdRsp == | |
765 | be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) { | |
766 | if ((fbits & FC4_FEATURE_INIT) && | |
767 | !(fbits & FC4_FEATURE_TARGET)) { | |
e8b62011 JS |
768 | lpfc_printf_vlog(vport, KERN_INFO, |
769 | LOG_DISCOVERY, | |
770 | "0270 Skip x%x GFF " | |
771 | "NameServer Rsp Data: (init) " | |
772 | "x%x x%x\n", did, fbits, | |
773 | vport->fc_rscn_id_cnt); | |
92d7f7b0 JS |
774 | goto out; |
775 | } | |
776 | } | |
777 | } | |
858c9f6c | 778 | else { |
0ff10d46 JS |
779 | /* Check for retry */ |
780 | if (cmdiocb->retry < LPFC_MAX_NS_RETRY) { | |
781 | retry = 1; | |
782 | if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) { | |
783 | switch (irsp->un.ulpWord[4]) { | |
784 | case IOERR_NO_RESOURCES: | |
785 | /* We don't increment the retry | |
786 | * count for this case. | |
787 | */ | |
788 | break; | |
789 | case IOERR_LINK_DOWN: | |
790 | case IOERR_SLI_ABORTED: | |
791 | case IOERR_SLI_DOWN: | |
792 | retry = 0; | |
793 | break; | |
794 | default: | |
795 | cmdiocb->retry++; | |
796 | } | |
797 | } | |
798 | else | |
799 | cmdiocb->retry++; | |
800 | ||
801 | if (retry) { | |
802 | /* CT command is being retried */ | |
803 | rc = lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID, | |
804 | cmdiocb->retry, did); | |
805 | if (rc == 0) { | |
806 | /* success */ | |
807 | lpfc_ct_free_iocb(phba, cmdiocb); | |
808 | return; | |
809 | } | |
810 | } | |
811 | } | |
e8b62011 JS |
812 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
813 | "0267 NameServer GFF Rsp " | |
814 | "x%x Error (%d %d) Data: x%x x%x\n", | |
815 | did, irsp->ulpStatus, irsp->un.ulpWord[4], | |
7f5f3d0d | 816 | vport->fc_flag, vport->fc_rscn_id_cnt); |
858c9f6c JS |
817 | } |
818 | ||
92d7f7b0 JS |
819 | /* This is a target port, unregistered port, or the GFF_ID failed */ |
820 | ndlp = lpfc_setup_disc_node(vport, did); | |
58da1ffb | 821 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
e8b62011 JS |
822 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
823 | "0242 Process x%x GFF " | |
824 | "NameServer Rsp Data: x%x x%x x%x\n", | |
825 | did, ndlp->nlp_flag, vport->fc_flag, | |
826 | vport->fc_rscn_id_cnt); | |
92d7f7b0 | 827 | } else { |
e8b62011 JS |
828 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
829 | "0243 Skip x%x GFF " | |
830 | "NameServer Rsp Data: x%x x%x\n", did, | |
831 | vport->fc_flag, vport->fc_rscn_id_cnt); | |
92d7f7b0 | 832 | } |
dea3101e | 833 | out: |
92d7f7b0 JS |
834 | /* Link up / RSCN discovery */ |
835 | if (vport->num_disc_nodes) | |
836 | vport->num_disc_nodes--; | |
837 | if (vport->num_disc_nodes == 0) { | |
838 | /* | |
839 | * The driver has cycled through all Nports in the RSCN payload. | |
840 | * Complete the handling by cleaning up and marking the | |
841 | * current driver state. | |
842 | */ | |
843 | if (vport->port_state >= LPFC_DISC_AUTH) { | |
844 | if (vport->fc_flag & FC_RSCN_MODE) { | |
845 | lpfc_els_flush_rscn(vport); | |
846 | spin_lock_irq(shost->host_lock); | |
847 | vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */ | |
848 | spin_unlock_irq(shost->host_lock); | |
849 | } | |
850 | else | |
851 | lpfc_els_flush_rscn(vport); | |
852 | } | |
853 | lpfc_disc_start(vport); | |
854 | } | |
858c9f6c | 855 | lpfc_ct_free_iocb(phba, cmdiocb); |
dea3101e JB |
856 | return; |
857 | } | |
858 | ||
92d7f7b0 | 859 | |
dea3101e | 860 | static void |
7ee5d43e JS |
861 | lpfc_cmpl_ct(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
862 | struct lpfc_iocbq *rspiocb) | |
dea3101e | 863 | { |
92d7f7b0 | 864 | struct lpfc_vport *vport = cmdiocb->vport; |
dea3101e JB |
865 | struct lpfc_dmabuf *inp; |
866 | struct lpfc_dmabuf *outp; | |
867 | IOCB_t *irsp; | |
868 | struct lpfc_sli_ct_request *CTrsp; | |
51ef4c26 | 869 | struct lpfc_nodelist *ndlp; |
92d7f7b0 JS |
870 | int cmdcode, rc; |
871 | uint8_t retry; | |
858c9f6c | 872 | uint32_t latt; |
dea3101e | 873 | |
51ef4c26 JS |
874 | /* First save ndlp, before we overwrite it */ |
875 | ndlp = cmdiocb->context_un.ndlp; | |
876 | ||
dea3101e JB |
877 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
878 | cmdiocb->context_un.rsp_iocb = rspiocb; | |
879 | ||
880 | inp = (struct lpfc_dmabuf *) cmdiocb->context1; | |
881 | outp = (struct lpfc_dmabuf *) cmdiocb->context2; | |
dea3101e JB |
882 | irsp = &rspiocb->iocb; |
883 | ||
92d7f7b0 JS |
884 | cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)-> |
885 | CommandResponse.bits.CmdRsp); | |
dea3101e JB |
886 | CTrsp = (struct lpfc_sli_ct_request *) outp->virt; |
887 | ||
858c9f6c JS |
888 | latt = lpfc_els_chk_latt(vport); |
889 | ||
890 | /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */ | |
e8b62011 | 891 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
7ee5d43e | 892 | "0209 CT Request completes, latt %d, " |
e8b62011 JS |
893 | "ulpStatus x%x CmdRsp x%x, Context x%x, Tag x%x\n", |
894 | latt, irsp->ulpStatus, | |
895 | CTrsp->CommandResponse.bits.CmdRsp, | |
896 | cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag); | |
dea3101e | 897 | |
858c9f6c JS |
898 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, |
899 | "CT cmd cmpl: status:x%x/x%x cmd:x%x", | |
900 | irsp->ulpStatus, irsp->un.ulpWord[4], cmdcode); | |
901 | ||
92d7f7b0 | 902 | if (irsp->ulpStatus) { |
e8b62011 JS |
903 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
904 | "0268 NS cmd %x Error (%d %d)\n", | |
905 | cmdcode, irsp->ulpStatus, irsp->un.ulpWord[4]); | |
858c9f6c | 906 | |
92d7f7b0 JS |
907 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
908 | ((irsp->un.ulpWord[4] == IOERR_SLI_DOWN) || | |
909 | (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED))) | |
910 | goto out; | |
911 | ||
912 | retry = cmdiocb->retry; | |
913 | if (retry >= LPFC_MAX_NS_RETRY) | |
914 | goto out; | |
915 | ||
916 | retry++; | |
e8b62011 | 917 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
d7c255b2 | 918 | "0250 Retrying NS cmd %x\n", cmdcode); |
92d7f7b0 JS |
919 | rc = lpfc_ns_cmd(vport, cmdcode, retry, 0); |
920 | if (rc == 0) | |
921 | goto out; | |
922 | } | |
923 | ||
924 | out: | |
51ef4c26 | 925 | cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */ |
858c9f6c | 926 | lpfc_ct_free_iocb(phba, cmdiocb); |
dea3101e JB |
927 | return; |
928 | } | |
929 | ||
7ee5d43e JS |
930 | static void |
931 | lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | |
932 | struct lpfc_iocbq *rspiocb) | |
933 | { | |
934 | IOCB_t *irsp = &rspiocb->iocb; | |
935 | struct lpfc_vport *vport = cmdiocb->vport; | |
936 | ||
98c9ea5c JS |
937 | if (irsp->ulpStatus == IOSTAT_SUCCESS) { |
938 | struct lpfc_dmabuf *outp; | |
939 | struct lpfc_sli_ct_request *CTrsp; | |
940 | ||
941 | outp = (struct lpfc_dmabuf *) cmdiocb->context2; | |
942 | CTrsp = (struct lpfc_sli_ct_request *) outp->virt; | |
943 | if (CTrsp->CommandResponse.bits.CmdRsp == | |
944 | be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) | |
945 | vport->ct_flags |= FC_CT_RFT_ID; | |
946 | } | |
7ee5d43e JS |
947 | lpfc_cmpl_ct(phba, cmdiocb, rspiocb); |
948 | return; | |
949 | } | |
950 | ||
dea3101e | 951 | static void |
2e0fef85 JS |
952 | lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
953 | struct lpfc_iocbq *rspiocb) | |
dea3101e | 954 | { |
7ee5d43e JS |
955 | IOCB_t *irsp = &rspiocb->iocb; |
956 | struct lpfc_vport *vport = cmdiocb->vport; | |
957 | ||
98c9ea5c JS |
958 | if (irsp->ulpStatus == IOSTAT_SUCCESS) { |
959 | struct lpfc_dmabuf *outp; | |
960 | struct lpfc_sli_ct_request *CTrsp; | |
961 | ||
962 | outp = (struct lpfc_dmabuf *) cmdiocb->context2; | |
963 | CTrsp = (struct lpfc_sli_ct_request *) outp->virt; | |
964 | if (CTrsp->CommandResponse.bits.CmdRsp == | |
965 | be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) | |
966 | vport->ct_flags |= FC_CT_RNN_ID; | |
967 | } | |
7ee5d43e | 968 | lpfc_cmpl_ct(phba, cmdiocb, rspiocb); |
dea3101e JB |
969 | return; |
970 | } | |
971 | ||
92d7f7b0 JS |
972 | static void |
973 | lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | |
974 | struct lpfc_iocbq *rspiocb) | |
975 | { | |
7ee5d43e JS |
976 | IOCB_t *irsp = &rspiocb->iocb; |
977 | struct lpfc_vport *vport = cmdiocb->vport; | |
978 | ||
98c9ea5c JS |
979 | if (irsp->ulpStatus == IOSTAT_SUCCESS) { |
980 | struct lpfc_dmabuf *outp; | |
981 | struct lpfc_sli_ct_request *CTrsp; | |
982 | ||
983 | outp = (struct lpfc_dmabuf *) cmdiocb->context2; | |
984 | CTrsp = (struct lpfc_sli_ct_request *) outp->virt; | |
985 | if (CTrsp->CommandResponse.bits.CmdRsp == | |
986 | be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) | |
987 | vport->ct_flags |= FC_CT_RSPN_ID; | |
988 | } | |
7ee5d43e | 989 | lpfc_cmpl_ct(phba, cmdiocb, rspiocb); |
92d7f7b0 JS |
990 | return; |
991 | } | |
992 | ||
dea3101e | 993 | static void |
2e0fef85 JS |
994 | lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
995 | struct lpfc_iocbq *rspiocb) | |
dea3101e | 996 | { |
7ee5d43e JS |
997 | IOCB_t *irsp = &rspiocb->iocb; |
998 | struct lpfc_vport *vport = cmdiocb->vport; | |
999 | ||
98c9ea5c JS |
1000 | if (irsp->ulpStatus == IOSTAT_SUCCESS) { |
1001 | struct lpfc_dmabuf *outp; | |
1002 | struct lpfc_sli_ct_request *CTrsp; | |
1003 | ||
1004 | outp = (struct lpfc_dmabuf *) cmdiocb->context2; | |
1005 | CTrsp = (struct lpfc_sli_ct_request *) outp->virt; | |
1006 | if (CTrsp->CommandResponse.bits.CmdRsp == | |
1007 | be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) | |
1008 | vport->ct_flags |= FC_CT_RSNN_NN; | |
1009 | } | |
7ee5d43e JS |
1010 | lpfc_cmpl_ct(phba, cmdiocb, rspiocb); |
1011 | return; | |
1012 | } | |
1013 | ||
1014 | static void | |
1015 | lpfc_cmpl_ct_cmd_da_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | |
1016 | struct lpfc_iocbq *rspiocb) | |
1017 | { | |
1018 | struct lpfc_vport *vport = cmdiocb->vport; | |
1019 | ||
1020 | /* even if it fails we will act as though it succeeded. */ | |
1021 | vport->ct_flags = 0; | |
1022 | lpfc_cmpl_ct(phba, cmdiocb, rspiocb); | |
dea3101e JB |
1023 | return; |
1024 | } | |
1025 | ||
2fb9bd8b | 1026 | static void |
92d7f7b0 JS |
1027 | lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
1028 | struct lpfc_iocbq *rspiocb) | |
2fb9bd8b | 1029 | { |
92d7f7b0 JS |
1030 | IOCB_t *irsp = &rspiocb->iocb; |
1031 | struct lpfc_vport *vport = cmdiocb->vport; | |
1032 | ||
98c9ea5c JS |
1033 | if (irsp->ulpStatus == IOSTAT_SUCCESS) { |
1034 | struct lpfc_dmabuf *outp; | |
1035 | struct lpfc_sli_ct_request *CTrsp; | |
1036 | ||
1037 | outp = (struct lpfc_dmabuf *) cmdiocb->context2; | |
1038 | CTrsp = (struct lpfc_sli_ct_request *) outp->virt; | |
1039 | if (CTrsp->CommandResponse.bits.CmdRsp == | |
1040 | be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) | |
1041 | vport->ct_flags |= FC_CT_RFF_ID; | |
1042 | } | |
7ee5d43e | 1043 | lpfc_cmpl_ct(phba, cmdiocb, rspiocb); |
2fb9bd8b JS |
1044 | return; |
1045 | } | |
1046 | ||
495a714c | 1047 | int |
92d7f7b0 JS |
1048 | lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol, |
1049 | size_t size) | |
1050 | { | |
1051 | int n; | |
1052 | uint8_t *wwn = vport->phba->wwpn; | |
1053 | ||
1054 | n = snprintf(symbol, size, | |
1055 | "Emulex PPN-%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", | |
1056 | wwn[0], wwn[1], wwn[2], wwn[3], | |
1057 | wwn[4], wwn[5], wwn[6], wwn[7]); | |
1058 | ||
1059 | if (vport->port_type == LPFC_PHYSICAL_PORT) | |
1060 | return n; | |
1061 | ||
1062 | if (n < size) | |
1063 | n += snprintf(symbol + n, size - n, " VPort-%d", vport->vpi); | |
1064 | ||
eada272d JS |
1065 | if (n < size && |
1066 | strlen(vport->fc_vport->symbolic_name)) | |
1067 | n += snprintf(symbol + n, size - n, " VName-%s", | |
1068 | vport->fc_vport->symbolic_name); | |
92d7f7b0 JS |
1069 | return n; |
1070 | } | |
1071 | ||
1072 | int | |
1073 | lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol, | |
1074 | size_t size) | |
dea3101e JB |
1075 | { |
1076 | char fwrev[16]; | |
92d7f7b0 | 1077 | int n; |
dea3101e | 1078 | |
92d7f7b0 | 1079 | lpfc_decode_firmware_rev(vport->phba, fwrev, 0); |
dea3101e | 1080 | |
92d7f7b0 JS |
1081 | n = snprintf(symbol, size, "Emulex %s FV%s DV%s", |
1082 | vport->phba->ModelName, fwrev, lpfc_release_version); | |
1083 | return n; | |
dea3101e JB |
1084 | } |
1085 | ||
1086 | /* | |
1087 | * lpfc_ns_cmd | |
1088 | * Description: | |
1089 | * Issue Cmd to NameServer | |
1090 | * SLI_CTNS_GID_FT | |
1091 | * LI_CTNS_RFT_ID | |
1092 | */ | |
1093 | int | |
92d7f7b0 JS |
1094 | lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode, |
1095 | uint8_t retry, uint32_t context) | |
dea3101e | 1096 | { |
92d7f7b0 | 1097 | struct lpfc_nodelist * ndlp; |
2e0fef85 | 1098 | struct lpfc_hba *phba = vport->phba; |
dea3101e JB |
1099 | struct lpfc_dmabuf *mp, *bmp; |
1100 | struct lpfc_sli_ct_request *CtReq; | |
1101 | struct ulp_bde64 *bpl; | |
1102 | void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *, | |
1103 | struct lpfc_iocbq *) = NULL; | |
1104 | uint32_t rsp_size = 1024; | |
92d7f7b0 | 1105 | size_t size; |
858c9f6c | 1106 | int rc = 0; |
92d7f7b0 JS |
1107 | |
1108 | ndlp = lpfc_findnode_did(vport, NameServer_DID); | |
e47c9093 JS |
1109 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) |
1110 | || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) { | |
858c9f6c JS |
1111 | rc=1; |
1112 | goto ns_cmd_exit; | |
1113 | } | |
dea3101e JB |
1114 | |
1115 | /* fill in BDEs for command */ | |
1116 | /* Allocate buffer for command payload */ | |
1117 | mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); | |
858c9f6c JS |
1118 | if (!mp) { |
1119 | rc=2; | |
dea3101e | 1120 | goto ns_cmd_exit; |
858c9f6c | 1121 | } |
dea3101e JB |
1122 | |
1123 | INIT_LIST_HEAD(&mp->list); | |
1124 | mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys)); | |
858c9f6c JS |
1125 | if (!mp->virt) { |
1126 | rc=3; | |
dea3101e | 1127 | goto ns_cmd_free_mp; |
858c9f6c | 1128 | } |
dea3101e JB |
1129 | |
1130 | /* Allocate buffer for Buffer ptr list */ | |
1131 | bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); | |
858c9f6c JS |
1132 | if (!bmp) { |
1133 | rc=4; | |
dea3101e | 1134 | goto ns_cmd_free_mpvirt; |
858c9f6c | 1135 | } |
dea3101e JB |
1136 | |
1137 | INIT_LIST_HEAD(&bmp->list); | |
1138 | bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys)); | |
858c9f6c JS |
1139 | if (!bmp->virt) { |
1140 | rc=5; | |
dea3101e | 1141 | goto ns_cmd_free_bmp; |
858c9f6c | 1142 | } |
dea3101e JB |
1143 | |
1144 | /* NameServer Req */ | |
e8b62011 JS |
1145 | lpfc_printf_vlog(vport, KERN_INFO ,LOG_DISCOVERY, |
1146 | "0236 NameServer Req Data: x%x x%x x%x\n", | |
1147 | cmdcode, vport->fc_flag, vport->fc_rscn_id_cnt); | |
dea3101e JB |
1148 | |
1149 | bpl = (struct ulp_bde64 *) bmp->virt; | |
1150 | memset(bpl, 0, sizeof(struct ulp_bde64)); | |
92d7f7b0 JS |
1151 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) ); |
1152 | bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) ); | |
dea3101e JB |
1153 | bpl->tus.f.bdeFlags = 0; |
1154 | if (cmdcode == SLI_CTNS_GID_FT) | |
1155 | bpl->tus.f.bdeSize = GID_REQUEST_SZ; | |
92d7f7b0 JS |
1156 | else if (cmdcode == SLI_CTNS_GFF_ID) |
1157 | bpl->tus.f.bdeSize = GFF_REQUEST_SZ; | |
dea3101e JB |
1158 | else if (cmdcode == SLI_CTNS_RFT_ID) |
1159 | bpl->tus.f.bdeSize = RFT_REQUEST_SZ; | |
1160 | else if (cmdcode == SLI_CTNS_RNN_ID) | |
1161 | bpl->tus.f.bdeSize = RNN_REQUEST_SZ; | |
92d7f7b0 JS |
1162 | else if (cmdcode == SLI_CTNS_RSPN_ID) |
1163 | bpl->tus.f.bdeSize = RSPN_REQUEST_SZ; | |
dea3101e JB |
1164 | else if (cmdcode == SLI_CTNS_RSNN_NN) |
1165 | bpl->tus.f.bdeSize = RSNN_REQUEST_SZ; | |
7ee5d43e JS |
1166 | else if (cmdcode == SLI_CTNS_DA_ID) |
1167 | bpl->tus.f.bdeSize = DA_ID_REQUEST_SZ; | |
2fb9bd8b JS |
1168 | else if (cmdcode == SLI_CTNS_RFF_ID) |
1169 | bpl->tus.f.bdeSize = RFF_REQUEST_SZ; | |
dea3101e JB |
1170 | else |
1171 | bpl->tus.f.bdeSize = 0; | |
1172 | bpl->tus.w = le32_to_cpu(bpl->tus.w); | |
1173 | ||
1174 | CtReq = (struct lpfc_sli_ct_request *) mp->virt; | |
1175 | memset(CtReq, 0, sizeof (struct lpfc_sli_ct_request)); | |
1176 | CtReq->RevisionId.bits.Revision = SLI_CT_REVISION; | |
1177 | CtReq->RevisionId.bits.InId = 0; | |
1178 | CtReq->FsType = SLI_CT_DIRECTORY_SERVICE; | |
1179 | CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER; | |
1180 | CtReq->CommandResponse.bits.Size = 0; | |
1181 | switch (cmdcode) { | |
1182 | case SLI_CTNS_GID_FT: | |
1183 | CtReq->CommandResponse.bits.CmdRsp = | |
1184 | be16_to_cpu(SLI_CTNS_GID_FT); | |
1185 | CtReq->un.gid.Fc4Type = SLI_CTPT_FCP; | |
92d7f7b0 | 1186 | if (vport->port_state < LPFC_NS_QRY) |
2e0fef85 JS |
1187 | vport->port_state = LPFC_NS_QRY; |
1188 | lpfc_set_disctmo(vport); | |
dea3101e JB |
1189 | cmpl = lpfc_cmpl_ct_cmd_gid_ft; |
1190 | rsp_size = FC_MAX_NS_RSP; | |
1191 | break; | |
1192 | ||
92d7f7b0 JS |
1193 | case SLI_CTNS_GFF_ID: |
1194 | CtReq->CommandResponse.bits.CmdRsp = | |
1195 | be16_to_cpu(SLI_CTNS_GFF_ID); | |
09372820 | 1196 | CtReq->un.gff.PortId = cpu_to_be32(context); |
92d7f7b0 JS |
1197 | cmpl = lpfc_cmpl_ct_cmd_gff_id; |
1198 | break; | |
1199 | ||
dea3101e | 1200 | case SLI_CTNS_RFT_ID: |
7ee5d43e | 1201 | vport->ct_flags &= ~FC_CT_RFT_ID; |
dea3101e JB |
1202 | CtReq->CommandResponse.bits.CmdRsp = |
1203 | be16_to_cpu(SLI_CTNS_RFT_ID); | |
09372820 | 1204 | CtReq->un.rft.PortId = cpu_to_be32(vport->fc_myDID); |
dea3101e JB |
1205 | CtReq->un.rft.fcpReg = 1; |
1206 | cmpl = lpfc_cmpl_ct_cmd_rft_id; | |
1207 | break; | |
1208 | ||
1209 | case SLI_CTNS_RNN_ID: | |
7ee5d43e | 1210 | vport->ct_flags &= ~FC_CT_RNN_ID; |
dea3101e JB |
1211 | CtReq->CommandResponse.bits.CmdRsp = |
1212 | be16_to_cpu(SLI_CTNS_RNN_ID); | |
09372820 | 1213 | CtReq->un.rnn.PortId = cpu_to_be32(vport->fc_myDID); |
2e0fef85 | 1214 | memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename, |
dea3101e JB |
1215 | sizeof (struct lpfc_name)); |
1216 | cmpl = lpfc_cmpl_ct_cmd_rnn_id; | |
1217 | break; | |
1218 | ||
92d7f7b0 | 1219 | case SLI_CTNS_RSPN_ID: |
7ee5d43e | 1220 | vport->ct_flags &= ~FC_CT_RSPN_ID; |
92d7f7b0 JS |
1221 | CtReq->CommandResponse.bits.CmdRsp = |
1222 | be16_to_cpu(SLI_CTNS_RSPN_ID); | |
09372820 | 1223 | CtReq->un.rspn.PortId = cpu_to_be32(vport->fc_myDID); |
92d7f7b0 JS |
1224 | size = sizeof(CtReq->un.rspn.symbname); |
1225 | CtReq->un.rspn.len = | |
1226 | lpfc_vport_symbolic_port_name(vport, | |
1227 | CtReq->un.rspn.symbname, size); | |
1228 | cmpl = lpfc_cmpl_ct_cmd_rspn_id; | |
1229 | break; | |
dea3101e | 1230 | case SLI_CTNS_RSNN_NN: |
7ee5d43e | 1231 | vport->ct_flags &= ~FC_CT_RSNN_NN; |
dea3101e JB |
1232 | CtReq->CommandResponse.bits.CmdRsp = |
1233 | be16_to_cpu(SLI_CTNS_RSNN_NN); | |
2e0fef85 | 1234 | memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename, |
dea3101e | 1235 | sizeof (struct lpfc_name)); |
92d7f7b0 JS |
1236 | size = sizeof(CtReq->un.rsnn.symbname); |
1237 | CtReq->un.rsnn.len = | |
1238 | lpfc_vport_symbolic_node_name(vport, | |
1239 | CtReq->un.rsnn.symbname, size); | |
dea3101e JB |
1240 | cmpl = lpfc_cmpl_ct_cmd_rsnn_nn; |
1241 | break; | |
7ee5d43e JS |
1242 | case SLI_CTNS_DA_ID: |
1243 | /* Implement DA_ID Nameserver request */ | |
1244 | CtReq->CommandResponse.bits.CmdRsp = | |
1245 | be16_to_cpu(SLI_CTNS_DA_ID); | |
09372820 | 1246 | CtReq->un.da_id.port_id = cpu_to_be32(vport->fc_myDID); |
7ee5d43e JS |
1247 | cmpl = lpfc_cmpl_ct_cmd_da_id; |
1248 | break; | |
92d7f7b0 | 1249 | case SLI_CTNS_RFF_ID: |
7ee5d43e | 1250 | vport->ct_flags &= ~FC_CT_RFF_ID; |
92d7f7b0 JS |
1251 | CtReq->CommandResponse.bits.CmdRsp = |
1252 | be16_to_cpu(SLI_CTNS_RFF_ID); | |
a419aef8 | 1253 | CtReq->un.rff.PortId = cpu_to_be32(vport->fc_myDID); |
92d7f7b0 | 1254 | CtReq->un.rff.fbits = FC4_FEATURE_INIT; |
6a9c52cf | 1255 | CtReq->un.rff.type_code = FC_TYPE_FCP; |
92d7f7b0 JS |
1256 | cmpl = lpfc_cmpl_ct_cmd_rff_id; |
1257 | break; | |
dea3101e | 1258 | } |
e47c9093 JS |
1259 | /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count |
1260 | * to hold ndlp reference for the corresponding callback function. | |
1261 | */ | |
858c9f6c | 1262 | if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) { |
dea3101e | 1263 | /* On success, The cmpl function will free the buffers */ |
858c9f6c JS |
1264 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, |
1265 | "Issue CT cmd: cmd:x%x did:x%x", | |
1266 | cmdcode, ndlp->nlp_DID, 0); | |
dea3101e | 1267 | return 0; |
858c9f6c | 1268 | } |
858c9f6c | 1269 | rc=6; |
e47c9093 JS |
1270 | |
1271 | /* Decrement ndlp reference count to release ndlp reference held | |
1272 | * for the failed command's callback function. | |
1273 | */ | |
51ef4c26 | 1274 | lpfc_nlp_put(ndlp); |
e47c9093 | 1275 | |
dea3101e JB |
1276 | lpfc_mbuf_free(phba, bmp->virt, bmp->phys); |
1277 | ns_cmd_free_bmp: | |
1278 | kfree(bmp); | |
1279 | ns_cmd_free_mpvirt: | |
1280 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
1281 | ns_cmd_free_mp: | |
1282 | kfree(mp); | |
1283 | ns_cmd_exit: | |
e8b62011 JS |
1284 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
1285 | "0266 Issue NameServer Req x%x err %d Data: x%x x%x\n", | |
1286 | cmdcode, rc, vport->fc_flag, vport->fc_rscn_id_cnt); | |
dea3101e JB |
1287 | return 1; |
1288 | } | |
1289 | ||
1290 | static void | |
2e0fef85 JS |
1291 | lpfc_cmpl_ct_cmd_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
1292 | struct lpfc_iocbq * rspiocb) | |
dea3101e | 1293 | { |
dea3101e JB |
1294 | struct lpfc_dmabuf *inp = cmdiocb->context1; |
1295 | struct lpfc_dmabuf *outp = cmdiocb->context2; | |
1296 | struct lpfc_sli_ct_request *CTrsp = outp->virt; | |
1297 | struct lpfc_sli_ct_request *CTcmd = inp->virt; | |
1298 | struct lpfc_nodelist *ndlp; | |
1299 | uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp; | |
1300 | uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp; | |
2e0fef85 | 1301 | struct lpfc_vport *vport = cmdiocb->vport; |
858c9f6c JS |
1302 | IOCB_t *irsp = &rspiocb->iocb; |
1303 | uint32_t latt; | |
1304 | ||
1305 | latt = lpfc_els_chk_latt(vport); | |
1306 | ||
1307 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, | |
1308 | "FDMI cmpl: status:x%x/x%x latt:%d", | |
1309 | irsp->ulpStatus, irsp->un.ulpWord[4], latt); | |
1310 | ||
1311 | if (latt || irsp->ulpStatus) { | |
e8b62011 JS |
1312 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
1313 | "0229 FDMI cmd %04x failed, latt = %d " | |
1314 | "ulpStatus: x%x, rid x%x\n", | |
1315 | be16_to_cpu(fdmi_cmd), latt, irsp->ulpStatus, | |
1316 | irsp->un.ulpWord[4]); | |
858c9f6c JS |
1317 | lpfc_ct_free_iocb(phba, cmdiocb); |
1318 | return; | |
1319 | } | |
dea3101e | 1320 | |
2e0fef85 | 1321 | ndlp = lpfc_findnode_did(vport, FDMI_DID); |
e47c9093 JS |
1322 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
1323 | goto fail_out; | |
1324 | ||
dea3101e JB |
1325 | if (fdmi_rsp == be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) { |
1326 | /* FDMI rsp failed */ | |
e8b62011 JS |
1327 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
1328 | "0220 FDMI rsp failed Data: x%x\n", | |
1329 | be16_to_cpu(fdmi_cmd)); | |
dea3101e JB |
1330 | } |
1331 | ||
1332 | switch (be16_to_cpu(fdmi_cmd)) { | |
1333 | case SLI_MGMT_RHBA: | |
2e0fef85 | 1334 | lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA); |
dea3101e JB |
1335 | break; |
1336 | ||
1337 | case SLI_MGMT_RPA: | |
1338 | break; | |
1339 | ||
1340 | case SLI_MGMT_DHBA: | |
2e0fef85 | 1341 | lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT); |
dea3101e JB |
1342 | break; |
1343 | ||
1344 | case SLI_MGMT_DPRT: | |
2e0fef85 | 1345 | lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA); |
dea3101e JB |
1346 | break; |
1347 | } | |
e47c9093 JS |
1348 | |
1349 | fail_out: | |
858c9f6c | 1350 | lpfc_ct_free_iocb(phba, cmdiocb); |
dea3101e JB |
1351 | return; |
1352 | } | |
2e0fef85 | 1353 | |
dea3101e | 1354 | int |
2e0fef85 | 1355 | lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, int cmdcode) |
dea3101e | 1356 | { |
2e0fef85 | 1357 | struct lpfc_hba *phba = vport->phba; |
dea3101e JB |
1358 | struct lpfc_dmabuf *mp, *bmp; |
1359 | struct lpfc_sli_ct_request *CtReq; | |
1360 | struct ulp_bde64 *bpl; | |
1361 | uint32_t size; | |
1362 | REG_HBA *rh; | |
1363 | PORT_ENTRY *pe; | |
1364 | REG_PORT_ATTRIBUTE *pab; | |
1365 | ATTRIBUTE_BLOCK *ab; | |
1366 | ATTRIBUTE_ENTRY *ae; | |
1367 | void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *, | |
1368 | struct lpfc_iocbq *); | |
1369 | ||
1370 | ||
1371 | /* fill in BDEs for command */ | |
1372 | /* Allocate buffer for command payload */ | |
1373 | mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); | |
1374 | if (!mp) | |
1375 | goto fdmi_cmd_exit; | |
1376 | ||
1377 | mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys)); | |
1378 | if (!mp->virt) | |
1379 | goto fdmi_cmd_free_mp; | |
1380 | ||
1381 | /* Allocate buffer for Buffer ptr list */ | |
1382 | bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); | |
1383 | if (!bmp) | |
1384 | goto fdmi_cmd_free_mpvirt; | |
1385 | ||
1386 | bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys)); | |
1387 | if (!bmp->virt) | |
1388 | goto fdmi_cmd_free_bmp; | |
1389 | ||
1390 | INIT_LIST_HEAD(&mp->list); | |
1391 | INIT_LIST_HEAD(&bmp->list); | |
1392 | ||
1393 | /* FDMI request */ | |
e8b62011 JS |
1394 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
1395 | "0218 FDMI Request Data: x%x x%x x%x\n", | |
1396 | vport->fc_flag, vport->port_state, cmdcode); | |
dea3101e JB |
1397 | CtReq = (struct lpfc_sli_ct_request *) mp->virt; |
1398 | ||
1399 | memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request)); | |
1400 | CtReq->RevisionId.bits.Revision = SLI_CT_REVISION; | |
1401 | CtReq->RevisionId.bits.InId = 0; | |
1402 | ||
1403 | CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE; | |
1404 | CtReq->FsSubType = SLI_CT_FDMI_Subtypes; | |
1405 | size = 0; | |
1406 | ||
1407 | switch (cmdcode) { | |
1408 | case SLI_MGMT_RHBA: | |
1409 | { | |
1410 | lpfc_vpd_t *vp = &phba->vpd; | |
1411 | uint32_t i, j, incr; | |
1412 | int len; | |
1413 | ||
1414 | CtReq->CommandResponse.bits.CmdRsp = | |
1415 | be16_to_cpu(SLI_MGMT_RHBA); | |
1416 | CtReq->CommandResponse.bits.Size = 0; | |
1417 | rh = (REG_HBA *) & CtReq->un.PortID; | |
2e0fef85 | 1418 | memcpy(&rh->hi.PortName, &vport->fc_sparam.portName, |
dea3101e JB |
1419 | sizeof (struct lpfc_name)); |
1420 | /* One entry (port) per adapter */ | |
1421 | rh->rpl.EntryCnt = be32_to_cpu(1); | |
2e0fef85 | 1422 | memcpy(&rh->rpl.pe, &vport->fc_sparam.portName, |
dea3101e JB |
1423 | sizeof (struct lpfc_name)); |
1424 | ||
1425 | /* point to the HBA attribute block */ | |
1426 | size = 2 * sizeof (struct lpfc_name) + FOURBYTES; | |
1427 | ab = (ATTRIBUTE_BLOCK *) ((uint8_t *) rh + size); | |
1428 | ab->EntryCnt = 0; | |
1429 | ||
1430 | /* Point to the beginning of the first HBA attribute | |
1431 | entry */ | |
1432 | /* #1 HBA attribute entry */ | |
1433 | size += FOURBYTES; | |
1434 | ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size); | |
1435 | ae->ad.bits.AttrType = be16_to_cpu(NODE_NAME); | |
1436 | ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES | |
1437 | + sizeof (struct lpfc_name)); | |
2e0fef85 | 1438 | memcpy(&ae->un.NodeName, &vport->fc_sparam.nodeName, |
dea3101e JB |
1439 | sizeof (struct lpfc_name)); |
1440 | ab->EntryCnt++; | |
1441 | size += FOURBYTES + sizeof (struct lpfc_name); | |
1442 | ||
1443 | /* #2 HBA attribute entry */ | |
1444 | ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size); | |
1445 | ae->ad.bits.AttrType = be16_to_cpu(MANUFACTURER); | |
1446 | strcpy(ae->un.Manufacturer, "Emulex Corporation"); | |
1447 | len = strlen(ae->un.Manufacturer); | |
1448 | len += (len & 3) ? (4 - (len & 3)) : 4; | |
1449 | ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len); | |
1450 | ab->EntryCnt++; | |
1451 | size += FOURBYTES + len; | |
1452 | ||
1453 | /* #3 HBA attribute entry */ | |
1454 | ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size); | |
1455 | ae->ad.bits.AttrType = be16_to_cpu(SERIAL_NUMBER); | |
1456 | strcpy(ae->un.SerialNumber, phba->SerialNumber); | |
1457 | len = strlen(ae->un.SerialNumber); | |
1458 | len += (len & 3) ? (4 - (len & 3)) : 4; | |
1459 | ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len); | |
1460 | ab->EntryCnt++; | |
1461 | size += FOURBYTES + len; | |
1462 | ||
1463 | /* #4 HBA attribute entry */ | |
1464 | ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size); | |
1465 | ae->ad.bits.AttrType = be16_to_cpu(MODEL); | |
1466 | strcpy(ae->un.Model, phba->ModelName); | |
1467 | len = strlen(ae->un.Model); | |
1468 | len += (len & 3) ? (4 - (len & 3)) : 4; | |
1469 | ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len); | |
1470 | ab->EntryCnt++; | |
1471 | size += FOURBYTES + len; | |
1472 | ||
1473 | /* #5 HBA attribute entry */ | |
1474 | ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size); | |
1475 | ae->ad.bits.AttrType = be16_to_cpu(MODEL_DESCRIPTION); | |
1476 | strcpy(ae->un.ModelDescription, phba->ModelDesc); | |
1477 | len = strlen(ae->un.ModelDescription); | |
1478 | len += (len & 3) ? (4 - (len & 3)) : 4; | |
1479 | ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len); | |
1480 | ab->EntryCnt++; | |
1481 | size += FOURBYTES + len; | |
1482 | ||
1483 | /* #6 HBA attribute entry */ | |
1484 | ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size); | |
1485 | ae->ad.bits.AttrType = be16_to_cpu(HARDWARE_VERSION); | |
1486 | ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 8); | |
1487 | /* Convert JEDEC ID to ascii for hardware version */ | |
1488 | incr = vp->rev.biuRev; | |
1489 | for (i = 0; i < 8; i++) { | |
1490 | j = (incr & 0xf); | |
1491 | if (j <= 9) | |
1492 | ae->un.HardwareVersion[7 - i] = | |
1493 | (char)((uint8_t) 0x30 + | |
1494 | (uint8_t) j); | |
1495 | else | |
1496 | ae->un.HardwareVersion[7 - i] = | |
1497 | (char)((uint8_t) 0x61 + | |
1498 | (uint8_t) (j - 10)); | |
1499 | incr = (incr >> 4); | |
1500 | } | |
1501 | ab->EntryCnt++; | |
1502 | size += FOURBYTES + 8; | |
1503 | ||
1504 | /* #7 HBA attribute entry */ | |
1505 | ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size); | |
1506 | ae->ad.bits.AttrType = be16_to_cpu(DRIVER_VERSION); | |
1507 | strcpy(ae->un.DriverVersion, lpfc_release_version); | |
1508 | len = strlen(ae->un.DriverVersion); | |
1509 | len += (len & 3) ? (4 - (len & 3)) : 4; | |
1510 | ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len); | |
1511 | ab->EntryCnt++; | |
1512 | size += FOURBYTES + len; | |
1513 | ||
1514 | /* #8 HBA attribute entry */ | |
1515 | ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size); | |
1516 | ae->ad.bits.AttrType = be16_to_cpu(OPTION_ROM_VERSION); | |
1517 | strcpy(ae->un.OptionROMVersion, phba->OptionROMVersion); | |
1518 | len = strlen(ae->un.OptionROMVersion); | |
1519 | len += (len & 3) ? (4 - (len & 3)) : 4; | |
1520 | ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len); | |
1521 | ab->EntryCnt++; | |
1522 | size += FOURBYTES + len; | |
1523 | ||
1524 | /* #9 HBA attribute entry */ | |
1525 | ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size); | |
1526 | ae->ad.bits.AttrType = be16_to_cpu(FIRMWARE_VERSION); | |
1527 | lpfc_decode_firmware_rev(phba, ae->un.FirmwareVersion, | |
1528 | 1); | |
1529 | len = strlen(ae->un.FirmwareVersion); | |
1530 | len += (len & 3) ? (4 - (len & 3)) : 4; | |
1531 | ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len); | |
1532 | ab->EntryCnt++; | |
1533 | size += FOURBYTES + len; | |
1534 | ||
1535 | /* #10 HBA attribute entry */ | |
1536 | ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size); | |
1537 | ae->ad.bits.AttrType = be16_to_cpu(OS_NAME_VERSION); | |
1538 | sprintf(ae->un.OsNameVersion, "%s %s %s", | |
2fb9bd8b JS |
1539 | init_utsname()->sysname, |
1540 | init_utsname()->release, | |
96b644bd | 1541 | init_utsname()->version); |
dea3101e JB |
1542 | len = strlen(ae->un.OsNameVersion); |
1543 | len += (len & 3) ? (4 - (len & 3)) : 4; | |
1544 | ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len); | |
1545 | ab->EntryCnt++; | |
1546 | size += FOURBYTES + len; | |
1547 | ||
1548 | /* #11 HBA attribute entry */ | |
1549 | ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size); | |
1550 | ae->ad.bits.AttrType = be16_to_cpu(MAX_CT_PAYLOAD_LEN); | |
1551 | ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4); | |
1552 | ae->un.MaxCTPayloadLen = (65 * 4096); | |
1553 | ab->EntryCnt++; | |
1554 | size += FOURBYTES + 4; | |
1555 | ||
1556 | ab->EntryCnt = be32_to_cpu(ab->EntryCnt); | |
1557 | /* Total size */ | |
1558 | size = GID_REQUEST_SZ - 4 + size; | |
1559 | } | |
1560 | break; | |
1561 | ||
1562 | case SLI_MGMT_RPA: | |
1563 | { | |
1564 | lpfc_vpd_t *vp; | |
1565 | struct serv_parm *hsp; | |
1566 | int len; | |
1567 | ||
1568 | vp = &phba->vpd; | |
1569 | ||
1570 | CtReq->CommandResponse.bits.CmdRsp = | |
1571 | be16_to_cpu(SLI_MGMT_RPA); | |
1572 | CtReq->CommandResponse.bits.Size = 0; | |
1573 | pab = (REG_PORT_ATTRIBUTE *) & CtReq->un.PortID; | |
1574 | size = sizeof (struct lpfc_name) + FOURBYTES; | |
1575 | memcpy((uint8_t *) & pab->PortName, | |
2e0fef85 | 1576 | (uint8_t *) & vport->fc_sparam.portName, |
dea3101e JB |
1577 | sizeof (struct lpfc_name)); |
1578 | pab->ab.EntryCnt = 0; | |
1579 | ||
1580 | /* #1 Port attribute entry */ | |
1581 | ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size); | |
1582 | ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_FC4_TYPES); | |
1583 | ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 32); | |
1584 | ae->un.SupportFC4Types[2] = 1; | |
1585 | ae->un.SupportFC4Types[7] = 1; | |
1586 | pab->ab.EntryCnt++; | |
1587 | size += FOURBYTES + 32; | |
1588 | ||
1589 | /* #2 Port attribute entry */ | |
1590 | ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size); | |
1591 | ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_SPEED); | |
1592 | ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4); | |
74b72a59 JW |
1593 | |
1594 | ae->un.SupportSpeed = 0; | |
1595 | if (phba->lmt & LMT_10Gb) | |
dea3101e | 1596 | ae->un.SupportSpeed = HBA_PORTSPEED_10GBIT; |
74b72a59 JW |
1597 | if (phba->lmt & LMT_8Gb) |
1598 | ae->un.SupportSpeed |= HBA_PORTSPEED_8GBIT; | |
1599 | if (phba->lmt & LMT_4Gb) | |
1600 | ae->un.SupportSpeed |= HBA_PORTSPEED_4GBIT; | |
1601 | if (phba->lmt & LMT_2Gb) | |
1602 | ae->un.SupportSpeed |= HBA_PORTSPEED_2GBIT; | |
1603 | if (phba->lmt & LMT_1Gb) | |
1604 | ae->un.SupportSpeed |= HBA_PORTSPEED_1GBIT; | |
1605 | ||
dea3101e JB |
1606 | pab->ab.EntryCnt++; |
1607 | size += FOURBYTES + 4; | |
1608 | ||
1609 | /* #3 Port attribute entry */ | |
1610 | ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size); | |
1611 | ae->ad.bits.AttrType = be16_to_cpu(PORT_SPEED); | |
1612 | ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4); | |
1613 | switch(phba->fc_linkspeed) { | |
1614 | case LA_1GHZ_LINK: | |
1615 | ae->un.PortSpeed = HBA_PORTSPEED_1GBIT; | |
1616 | break; | |
1617 | case LA_2GHZ_LINK: | |
1618 | ae->un.PortSpeed = HBA_PORTSPEED_2GBIT; | |
1619 | break; | |
1620 | case LA_4GHZ_LINK: | |
1621 | ae->un.PortSpeed = HBA_PORTSPEED_4GBIT; | |
1622 | break; | |
b87eab38 JS |
1623 | case LA_8GHZ_LINK: |
1624 | ae->un.PortSpeed = HBA_PORTSPEED_8GBIT; | |
1625 | break; | |
f4b4c68f JS |
1626 | case LA_10GHZ_LINK: |
1627 | ae->un.PortSpeed = HBA_PORTSPEED_10GBIT; | |
1628 | break; | |
dea3101e JB |
1629 | default: |
1630 | ae->un.PortSpeed = | |
1631 | HBA_PORTSPEED_UNKNOWN; | |
1632 | break; | |
1633 | } | |
1634 | pab->ab.EntryCnt++; | |
1635 | size += FOURBYTES + 4; | |
1636 | ||
1637 | /* #4 Port attribute entry */ | |
1638 | ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size); | |
1639 | ae->ad.bits.AttrType = be16_to_cpu(MAX_FRAME_SIZE); | |
1640 | ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4); | |
2e0fef85 | 1641 | hsp = (struct serv_parm *) & vport->fc_sparam; |
dea3101e JB |
1642 | ae->un.MaxFrameSize = |
1643 | (((uint32_t) hsp->cmn. | |
1644 | bbRcvSizeMsb) << 8) | (uint32_t) hsp->cmn. | |
1645 | bbRcvSizeLsb; | |
1646 | pab->ab.EntryCnt++; | |
1647 | size += FOURBYTES + 4; | |
1648 | ||
1649 | /* #5 Port attribute entry */ | |
1650 | ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size); | |
1651 | ae->ad.bits.AttrType = be16_to_cpu(OS_DEVICE_NAME); | |
1652 | strcpy((char *)ae->un.OsDeviceName, LPFC_DRIVER_NAME); | |
1653 | len = strlen((char *)ae->un.OsDeviceName); | |
1654 | len += (len & 3) ? (4 - (len & 3)) : 4; | |
1655 | ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len); | |
1656 | pab->ab.EntryCnt++; | |
1657 | size += FOURBYTES + len; | |
1658 | ||
3de2a653 | 1659 | if (vport->cfg_fdmi_on == 2) { |
dea3101e JB |
1660 | /* #6 Port attribute entry */ |
1661 | ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + | |
1662 | size); | |
1663 | ae->ad.bits.AttrType = be16_to_cpu(HOST_NAME); | |
1664 | sprintf(ae->un.HostName, "%s", | |
96b644bd | 1665 | init_utsname()->nodename); |
dea3101e JB |
1666 | len = strlen(ae->un.HostName); |
1667 | len += (len & 3) ? (4 - (len & 3)) : 4; | |
1668 | ae->ad.bits.AttrLen = | |
1669 | be16_to_cpu(FOURBYTES + len); | |
1670 | pab->ab.EntryCnt++; | |
1671 | size += FOURBYTES + len; | |
1672 | } | |
1673 | ||
1674 | pab->ab.EntryCnt = be32_to_cpu(pab->ab.EntryCnt); | |
1675 | /* Total size */ | |
1676 | size = GID_REQUEST_SZ - 4 + size; | |
1677 | } | |
1678 | break; | |
1679 | ||
1680 | case SLI_MGMT_DHBA: | |
1681 | CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DHBA); | |
1682 | CtReq->CommandResponse.bits.Size = 0; | |
1683 | pe = (PORT_ENTRY *) & CtReq->un.PortID; | |
1684 | memcpy((uint8_t *) & pe->PortName, | |
2e0fef85 | 1685 | (uint8_t *) & vport->fc_sparam.portName, |
dea3101e JB |
1686 | sizeof (struct lpfc_name)); |
1687 | size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name); | |
1688 | break; | |
1689 | ||
1690 | case SLI_MGMT_DPRT: | |
1691 | CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DPRT); | |
1692 | CtReq->CommandResponse.bits.Size = 0; | |
1693 | pe = (PORT_ENTRY *) & CtReq->un.PortID; | |
1694 | memcpy((uint8_t *) & pe->PortName, | |
2e0fef85 | 1695 | (uint8_t *) & vport->fc_sparam.portName, |
dea3101e JB |
1696 | sizeof (struct lpfc_name)); |
1697 | size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name); | |
1698 | break; | |
1699 | } | |
1700 | ||
1701 | bpl = (struct ulp_bde64 *) bmp->virt; | |
92d7f7b0 JS |
1702 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) ); |
1703 | bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) ); | |
dea3101e JB |
1704 | bpl->tus.f.bdeFlags = 0; |
1705 | bpl->tus.f.bdeSize = size; | |
1706 | bpl->tus.w = le32_to_cpu(bpl->tus.w); | |
1707 | ||
1708 | cmpl = lpfc_cmpl_ct_cmd_fdmi; | |
1709 | ||
e47c9093 JS |
1710 | /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count |
1711 | * to hold ndlp reference for the corresponding callback function. | |
1712 | */ | |
92d7f7b0 | 1713 | if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, FC_MAX_NS_RSP, 0)) |
dea3101e JB |
1714 | return 0; |
1715 | ||
e47c9093 JS |
1716 | /* Decrement ndlp reference count to release ndlp reference held |
1717 | * for the failed command's callback function. | |
1718 | */ | |
51ef4c26 | 1719 | lpfc_nlp_put(ndlp); |
e47c9093 | 1720 | |
dea3101e JB |
1721 | lpfc_mbuf_free(phba, bmp->virt, bmp->phys); |
1722 | fdmi_cmd_free_bmp: | |
1723 | kfree(bmp); | |
1724 | fdmi_cmd_free_mpvirt: | |
1725 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
1726 | fdmi_cmd_free_mp: | |
1727 | kfree(mp); | |
1728 | fdmi_cmd_exit: | |
1729 | /* Issue FDMI request failed */ | |
e8b62011 JS |
1730 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
1731 | "0244 Issue FDMI request failed Data: x%x\n", | |
1732 | cmdcode); | |
dea3101e JB |
1733 | return 1; |
1734 | } | |
1735 | ||
1736 | void | |
1737 | lpfc_fdmi_tmo(unsigned long ptr) | |
1738 | { | |
2e0fef85 JS |
1739 | struct lpfc_vport *vport = (struct lpfc_vport *)ptr; |
1740 | struct lpfc_hba *phba = vport->phba; | |
5e9d9b82 | 1741 | uint32_t tmo_posted; |
dea3101e JB |
1742 | unsigned long iflag; |
1743 | ||
2e0fef85 | 1744 | spin_lock_irqsave(&vport->work_port_lock, iflag); |
5e9d9b82 JS |
1745 | tmo_posted = vport->work_port_events & WORKER_FDMI_TMO; |
1746 | if (!tmo_posted) | |
2e0fef85 | 1747 | vport->work_port_events |= WORKER_FDMI_TMO; |
5e9d9b82 | 1748 | spin_unlock_irqrestore(&vport->work_port_lock, iflag); |
92d7f7b0 | 1749 | |
5e9d9b82 JS |
1750 | if (!tmo_posted) |
1751 | lpfc_worker_wake_up(phba); | |
1752 | return; | |
dea3101e JB |
1753 | } |
1754 | ||
1755 | void | |
2e0fef85 | 1756 | lpfc_fdmi_timeout_handler(struct lpfc_vport *vport) |
dea3101e JB |
1757 | { |
1758 | struct lpfc_nodelist *ndlp; | |
1759 | ||
2e0fef85 | 1760 | ndlp = lpfc_findnode_did(vport, FDMI_DID); |
e47c9093 | 1761 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
2e0fef85 JS |
1762 | if (init_utsname()->nodename[0] != '\0') |
1763 | lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA); | |
1764 | else | |
1765 | mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60); | |
dea3101e | 1766 | } |
dea3101e JB |
1767 | return; |
1768 | } | |
1769 | ||
dea3101e | 1770 | void |
2e0fef85 | 1771 | lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag) |
dea3101e JB |
1772 | { |
1773 | struct lpfc_sli *psli = &phba->sli; | |
1774 | lpfc_vpd_t *vp = &phba->vpd; | |
1775 | uint32_t b1, b2, b3, b4, i, rev; | |
1776 | char c; | |
1777 | uint32_t *ptr, str[4]; | |
1778 | uint8_t *fwname; | |
1779 | ||
f1126688 JS |
1780 | if (phba->sli_rev == LPFC_SLI_REV4) |
1781 | sprintf(fwrevision, "%s", vp->rev.opFwName); | |
1782 | else if (vp->rev.rBit) { | |
f4b4c68f | 1783 | if (psli->sli_flag & LPFC_SLI_ACTIVE) |
dea3101e JB |
1784 | rev = vp->rev.sli2FwRev; |
1785 | else | |
1786 | rev = vp->rev.sli1FwRev; | |
1787 | ||
1788 | b1 = (rev & 0x0000f000) >> 12; | |
1789 | b2 = (rev & 0x00000f00) >> 8; | |
1790 | b3 = (rev & 0x000000c0) >> 6; | |
1791 | b4 = (rev & 0x00000030) >> 4; | |
1792 | ||
1793 | switch (b4) { | |
1794 | case 0: | |
1795 | c = 'N'; | |
1796 | break; | |
1797 | case 1: | |
1798 | c = 'A'; | |
1799 | break; | |
1800 | case 2: | |
1801 | c = 'B'; | |
1802 | break; | |
1803 | default: | |
1804 | c = 0; | |
1805 | break; | |
1806 | } | |
1807 | b4 = (rev & 0x0000000f); | |
1808 | ||
f4b4c68f | 1809 | if (psli->sli_flag & LPFC_SLI_ACTIVE) |
dea3101e JB |
1810 | fwname = vp->rev.sli2FwName; |
1811 | else | |
1812 | fwname = vp->rev.sli1FwName; | |
1813 | ||
1814 | for (i = 0; i < 16; i++) | |
1815 | if (fwname[i] == 0x20) | |
1816 | fwname[i] = 0; | |
1817 | ||
1818 | ptr = (uint32_t*)fwname; | |
1819 | ||
1820 | for (i = 0; i < 3; i++) | |
1821 | str[i] = be32_to_cpu(*ptr++); | |
1822 | ||
1823 | if (c == 0) { | |
1824 | if (flag) | |
1825 | sprintf(fwrevision, "%d.%d%d (%s)", | |
1826 | b1, b2, b3, (char *)str); | |
1827 | else | |
1828 | sprintf(fwrevision, "%d.%d%d", b1, | |
1829 | b2, b3); | |
1830 | } else { | |
1831 | if (flag) | |
1832 | sprintf(fwrevision, "%d.%d%d%c%d (%s)", | |
1833 | b1, b2, b3, c, | |
1834 | b4, (char *)str); | |
1835 | else | |
1836 | sprintf(fwrevision, "%d.%d%d%c%d", | |
1837 | b1, b2, b3, c, b4); | |
1838 | } | |
1839 | } else { | |
1840 | rev = vp->rev.smFwRev; | |
1841 | ||
1842 | b1 = (rev & 0xff000000) >> 24; | |
1843 | b2 = (rev & 0x00f00000) >> 20; | |
1844 | b3 = (rev & 0x000f0000) >> 16; | |
1845 | c = (rev & 0x0000ff00) >> 8; | |
1846 | b4 = (rev & 0x000000ff); | |
1847 | ||
d44a6d2b | 1848 | sprintf(fwrevision, "%d.%d%d%c%d", b1, b2, b3, c, b4); |
dea3101e JB |
1849 | } |
1850 | return; | |
1851 | } |