]>
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. * |
d080abe0 JS |
4 | * Copyright (C) 2017 Broadcom. All Rights Reserved. The term * |
5 | * “Broadcom” refers to Broadcom Limited and/or its subsidiaries. * | |
50611577 | 6 | * Copyright (C) 2004-2016 Emulex. All rights reserved. * |
c44ce173 | 7 | * EMULEX and SLI are trademarks of Emulex. * |
d080abe0 | 8 | * www.broadcom.com * |
dea3101e JB |
9 | * * |
10 | * This program is free software; you can redistribute it and/or * | |
c44ce173 JSEC |
11 | * modify it under the terms of version 2 of the GNU General * |
12 | * Public License as published by the Free Software Foundation. * | |
13 | * This program is distributed in the hope that it will be useful. * | |
14 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * | |
15 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * | |
16 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * | |
17 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * | |
18 | * TO BE LEGALLY INVALID. See the GNU General Public License for * | |
19 | * more details, a copy of which can be found in the file COPYING * | |
20 | * included with this package. * | |
dea3101e JB |
21 | *******************************************************************/ |
22 | ||
23 | /* | |
09372820 | 24 | * Fibre Channel SCSI LAN Device Driver CT support: FC Generic Services FC-GS |
dea3101e JB |
25 | */ |
26 | ||
27 | #include <linux/blkdev.h> | |
28 | #include <linux/pci.h> | |
29 | #include <linux/interrupt.h> | |
5a0e3ad6 | 30 | #include <linux/slab.h> |
dea3101e JB |
31 | #include <linux/utsname.h> |
32 | ||
91886523 | 33 | #include <scsi/scsi.h> |
dea3101e JB |
34 | #include <scsi/scsi_device.h> |
35 | #include <scsi/scsi_host.h> | |
f888ba3c | 36 | #include <scsi/scsi_transport_fc.h> |
6a9c52cf | 37 | #include <scsi/fc/fc_fs.h> |
dea3101e | 38 | |
da0436e9 | 39 | #include "lpfc_hw4.h" |
dea3101e JB |
40 | #include "lpfc_hw.h" |
41 | #include "lpfc_sli.h" | |
da0436e9 | 42 | #include "lpfc_sli4.h" |
ea2151b4 | 43 | #include "lpfc_nl.h" |
dea3101e | 44 | #include "lpfc_disc.h" |
dea3101e | 45 | #include "lpfc.h" |
a0f2d3ef JS |
46 | #include "lpfc_scsi.h" |
47 | #include "lpfc_nvme.h" | |
dea3101e JB |
48 | #include "lpfc_logmsg.h" |
49 | #include "lpfc_crtn.h" | |
50 | #include "lpfc_version.h" | |
92d7f7b0 | 51 | #include "lpfc_vport.h" |
858c9f6c | 52 | #include "lpfc_debugfs.h" |
dea3101e | 53 | |
a085e87c JS |
54 | /* FDMI Port Speed definitions - FC-GS-7 */ |
55 | #define HBA_PORTSPEED_1GFC 0x00000001 /* 1G FC */ | |
56 | #define HBA_PORTSPEED_2GFC 0x00000002 /* 2G FC */ | |
57 | #define HBA_PORTSPEED_4GFC 0x00000008 /* 4G FC */ | |
58 | #define HBA_PORTSPEED_10GFC 0x00000004 /* 10G FC */ | |
59 | #define HBA_PORTSPEED_8GFC 0x00000010 /* 8G FC */ | |
60 | #define HBA_PORTSPEED_16GFC 0x00000020 /* 16G FC */ | |
61 | #define HBA_PORTSPEED_32GFC 0x00000040 /* 32G FC */ | |
62 | #define HBA_PORTSPEED_20GFC 0x00000080 /* 20G FC */ | |
63 | #define HBA_PORTSPEED_40GFC 0x00000100 /* 40G FC */ | |
64 | #define HBA_PORTSPEED_128GFC 0x00000200 /* 128G FC */ | |
65 | #define HBA_PORTSPEED_64GFC 0x00000400 /* 64G FC */ | |
66 | #define HBA_PORTSPEED_256GFC 0x00000800 /* 256G FC */ | |
67 | #define HBA_PORTSPEED_UNKNOWN 0x00008000 /* Unknown */ | |
68 | #define HBA_PORTSPEED_10GE 0x00010000 /* 10G E */ | |
69 | #define HBA_PORTSPEED_40GE 0x00020000 /* 40G E */ | |
70 | #define HBA_PORTSPEED_100GE 0x00040000 /* 100G E */ | |
71 | #define HBA_PORTSPEED_25GE 0x00080000 /* 25G E */ | |
72 | #define HBA_PORTSPEED_50GE 0x00100000 /* 50G E */ | |
73 | #define HBA_PORTSPEED_400GE 0x00200000 /* 400G E */ | |
dea3101e JB |
74 | |
75 | #define FOURBYTES 4 | |
76 | ||
77 | ||
78 | static char *lpfc_release_version = LPFC_DRIVER_VERSION; | |
79 | ||
ed957684 | 80 | static void |
9c2face6 JS |
81 | lpfc_ct_ignore_hbq_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq, |
82 | struct lpfc_dmabuf *mp, uint32_t size) | |
ed957684 JS |
83 | { |
84 | if (!mp) { | |
9c2face6 | 85 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
97eab634 | 86 | "0146 Ignoring unsolicited CT No HBQ " |
9c2face6 JS |
87 | "status = x%x\n", |
88 | piocbq->iocb.ulpStatus); | |
ed957684 | 89 | } |
9c2face6 JS |
90 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
91 | "0145 Ignoring unsolicted CT HBQ Size:%d " | |
92 | "status = x%x\n", | |
93 | size, piocbq->iocb.ulpStatus); | |
ed957684 JS |
94 | } |
95 | ||
96 | static void | |
9c2face6 JS |
97 | lpfc_ct_unsol_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq, |
98 | struct lpfc_dmabuf *mp, uint32_t size) | |
ed957684 | 99 | { |
9c2face6 | 100 | lpfc_ct_ignore_hbq_buffer(phba, piocbq, mp, size); |
ed957684 JS |
101 | } |
102 | ||
dea3101e | 103 | void |
2e0fef85 JS |
104 | lpfc_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
105 | struct lpfc_iocbq *piocbq) | |
dea3101e | 106 | { |
ed957684 | 107 | struct lpfc_dmabuf *mp = NULL; |
dea3101e | 108 | IOCB_t *icmd = &piocbq->iocb; |
ed957684 JS |
109 | int i; |
110 | struct lpfc_iocbq *iocbq; | |
111 | dma_addr_t paddr; | |
112 | uint32_t size; | |
9c2face6 JS |
113 | struct list_head head; |
114 | struct lpfc_dmabuf *bdeBuf; | |
dea3101e | 115 | |
4fede78f JS |
116 | if (lpfc_bsg_ct_unsol_event(phba, pring, piocbq) == 0) |
117 | return; | |
f1c3b0fc | 118 | |
92d7f7b0 JS |
119 | if (unlikely(icmd->ulpStatus == IOSTAT_NEED_BUFFER)) { |
120 | lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); | |
121 | } else if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) && | |
e3d2b802 JS |
122 | ((icmd->un.ulpWord[4] & IOERR_PARAM_MASK) == |
123 | IOERR_RCV_BUFFER_WAITING)) { | |
dea3101e JB |
124 | /* Not enough posted buffers; Try posting more buffers */ |
125 | phba->fc_stat.NoRcvBuf++; | |
92d7f7b0 | 126 | if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) |
495a714c | 127 | lpfc_post_buffer(phba, pring, 2); |
dea3101e JB |
128 | return; |
129 | } | |
130 | ||
131 | /* If there are no BDEs associated with this IOCB, | |
132 | * there is nothing to do. | |
133 | */ | |
134 | if (icmd->ulpBdeCount == 0) | |
135 | return; | |
136 | ||
ed957684 | 137 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
9c2face6 JS |
138 | INIT_LIST_HEAD(&head); |
139 | list_add_tail(&head, &piocbq->list); | |
140 | list_for_each_entry(iocbq, &head, list) { | |
ed957684 | 141 | icmd = &iocbq->iocb; |
9c2face6 | 142 | if (icmd->ulpBdeCount == 0) |
ed957684 | 143 | continue; |
9c2face6 JS |
144 | bdeBuf = iocbq->context2; |
145 | iocbq->context2 = NULL; | |
ed957684 | 146 | size = icmd->un.cont64[0].tus.f.bdeSize; |
9c2face6 JS |
147 | lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf, size); |
148 | lpfc_in_buf_free(phba, bdeBuf); | |
ed957684 | 149 | if (icmd->ulpBdeCount == 2) { |
9c2face6 JS |
150 | bdeBuf = iocbq->context3; |
151 | iocbq->context3 = NULL; | |
152 | size = icmd->unsli3.rcvsli3.bde2.tus.f.bdeSize; | |
153 | lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf, | |
154 | size); | |
155 | lpfc_in_buf_free(phba, bdeBuf); | |
ed957684 | 156 | } |
dea3101e | 157 | } |
9c2face6 | 158 | list_del(&head); |
ed957684 | 159 | } else { |
d7c255b2 JS |
160 | INIT_LIST_HEAD(&head); |
161 | list_add_tail(&head, &piocbq->list); | |
162 | list_for_each_entry(iocbq, &head, list) { | |
ed957684 | 163 | icmd = &iocbq->iocb; |
9c2face6 | 164 | if (icmd->ulpBdeCount == 0) |
d7c255b2 | 165 | lpfc_ct_unsol_buffer(phba, iocbq, NULL, 0); |
ed957684 JS |
166 | for (i = 0; i < icmd->ulpBdeCount; i++) { |
167 | paddr = getPaddr(icmd->un.cont64[i].addrHigh, | |
168 | icmd->un.cont64[i].addrLow); | |
169 | mp = lpfc_sli_ringpostbuf_get(phba, pring, | |
170 | paddr); | |
171 | size = icmd->un.cont64[i].tus.f.bdeSize; | |
d7c255b2 | 172 | lpfc_ct_unsol_buffer(phba, iocbq, mp, size); |
92d7f7b0 | 173 | lpfc_in_buf_free(phba, mp); |
ed957684 | 174 | } |
495a714c | 175 | lpfc_post_buffer(phba, pring, i); |
dea3101e | 176 | } |
d7c255b2 | 177 | list_del(&head); |
dea3101e | 178 | } |
dea3101e JB |
179 | } |
180 | ||
6669f9bb | 181 | /** |
6dd9e31c | 182 | * lpfc_ct_handle_unsol_abort - ct upper level protocol abort handler |
6669f9bb | 183 | * @phba: Pointer to HBA context object. |
6dd9e31c | 184 | * @dmabuf: pointer to a dmabuf that describes the FC sequence |
6669f9bb | 185 | * |
6dd9e31c JS |
186 | * This function serves as the upper level protocol abort handler for CT |
187 | * protocol. | |
188 | * | |
189 | * Return 1 if abort has been handled, 0 otherwise. | |
6669f9bb | 190 | **/ |
6dd9e31c JS |
191 | int |
192 | lpfc_ct_handle_unsol_abort(struct lpfc_hba *phba, struct hbq_dmabuf *dmabuf) | |
6669f9bb | 193 | { |
6dd9e31c | 194 | int handled; |
6669f9bb | 195 | |
6dd9e31c JS |
196 | /* CT upper level goes through BSG */ |
197 | handled = lpfc_bsg_ct_unsol_abort(phba, dmabuf); | |
6669f9bb | 198 | |
6dd9e31c | 199 | return handled; |
6669f9bb JS |
200 | } |
201 | ||
dea3101e | 202 | static void |
2e0fef85 | 203 | lpfc_free_ct_rsp(struct lpfc_hba *phba, struct lpfc_dmabuf *mlist) |
dea3101e JB |
204 | { |
205 | struct lpfc_dmabuf *mlast, *next_mlast; | |
206 | ||
207 | list_for_each_entry_safe(mlast, next_mlast, &mlist->list, list) { | |
208 | lpfc_mbuf_free(phba, mlast->virt, mlast->phys); | |
209 | list_del(&mlast->list); | |
210 | kfree(mlast); | |
211 | } | |
212 | lpfc_mbuf_free(phba, mlist->virt, mlist->phys); | |
213 | kfree(mlist); | |
214 | return; | |
215 | } | |
216 | ||
217 | static struct lpfc_dmabuf * | |
2e0fef85 | 218 | lpfc_alloc_ct_rsp(struct lpfc_hba *phba, int cmdcode, struct ulp_bde64 *bpl, |
dea3101e JB |
219 | uint32_t size, int *entries) |
220 | { | |
221 | struct lpfc_dmabuf *mlist = NULL; | |
222 | struct lpfc_dmabuf *mp; | |
223 | int cnt, i = 0; | |
224 | ||
09372820 | 225 | /* We get chunks of FCELSSIZE */ |
dea3101e JB |
226 | cnt = size > FCELSSIZE ? FCELSSIZE: size; |
227 | ||
228 | while (size) { | |
229 | /* Allocate buffer for rsp payload */ | |
230 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
231 | if (!mp) { | |
232 | if (mlist) | |
233 | lpfc_free_ct_rsp(phba, mlist); | |
234 | return NULL; | |
235 | } | |
236 | ||
237 | INIT_LIST_HEAD(&mp->list); | |
238 | ||
92d7f7b0 JS |
239 | if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT) || |
240 | cmdcode == be16_to_cpu(SLI_CTNS_GFF_ID)) | |
dea3101e JB |
241 | mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys)); |
242 | else | |
243 | mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys)); | |
244 | ||
245 | if (!mp->virt) { | |
246 | kfree(mp); | |
0b3a82d3 ES |
247 | if (mlist) |
248 | lpfc_free_ct_rsp(phba, mlist); | |
dea3101e JB |
249 | return NULL; |
250 | } | |
251 | ||
252 | /* Queue it to a linked list */ | |
253 | if (!mlist) | |
254 | mlist = mp; | |
255 | else | |
256 | list_add_tail(&mp->list, &mlist->list); | |
257 | ||
34b02dcd | 258 | bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I; |
dea3101e | 259 | /* build buffer ptr list for IOCB */ |
92d7f7b0 JS |
260 | bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) ); |
261 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) ); | |
dea3101e JB |
262 | bpl->tus.f.bdeSize = (uint16_t) cnt; |
263 | bpl->tus.w = le32_to_cpu(bpl->tus.w); | |
264 | bpl++; | |
265 | ||
266 | i++; | |
267 | size -= cnt; | |
268 | } | |
269 | ||
270 | *entries = i; | |
271 | return mlist; | |
272 | } | |
273 | ||
858c9f6c JS |
274 | int |
275 | lpfc_ct_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *ctiocb) | |
276 | { | |
277 | struct lpfc_dmabuf *buf_ptr; | |
278 | ||
51ef4c26 JS |
279 | if (ctiocb->context_un.ndlp) { |
280 | lpfc_nlp_put(ctiocb->context_un.ndlp); | |
281 | ctiocb->context_un.ndlp = NULL; | |
282 | } | |
858c9f6c JS |
283 | if (ctiocb->context1) { |
284 | buf_ptr = (struct lpfc_dmabuf *) ctiocb->context1; | |
285 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); | |
286 | kfree(buf_ptr); | |
287 | ctiocb->context1 = NULL; | |
288 | } | |
289 | if (ctiocb->context2) { | |
290 | lpfc_free_ct_rsp(phba, (struct lpfc_dmabuf *) ctiocb->context2); | |
291 | ctiocb->context2 = NULL; | |
292 | } | |
293 | ||
294 | if (ctiocb->context3) { | |
295 | buf_ptr = (struct lpfc_dmabuf *) ctiocb->context3; | |
296 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); | |
297 | kfree(buf_ptr); | |
1109c944 | 298 | ctiocb->context3 = NULL; |
858c9f6c JS |
299 | } |
300 | lpfc_sli_release_iocbq(phba, ctiocb); | |
301 | return 0; | |
302 | } | |
303 | ||
4258e98e JS |
304 | /** |
305 | * lpfc_gen_req - Build and issue a GEN_REQUEST command to the SLI Layer | |
306 | * @vport: pointer to a host virtual N_Port data structure. | |
307 | * @bmp: Pointer to BPL for SLI command | |
308 | * @inp: Pointer to data buffer for response data. | |
309 | * @outp: Pointer to data buffer that hold the CT command. | |
310 | * @cmpl: completion routine to call when command completes | |
311 | * @ndlp: Destination NPort nodelist entry | |
312 | * | |
313 | * This function as the final part for issuing a CT command. | |
314 | */ | |
dea3101e | 315 | static int |
2e0fef85 | 316 | lpfc_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp, |
dea3101e JB |
317 | struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp, |
318 | void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *, | |
319 | struct lpfc_iocbq *), | |
320 | struct lpfc_nodelist *ndlp, uint32_t usr_flg, uint32_t num_entry, | |
92d7f7b0 | 321 | uint32_t tmo, uint8_t retry) |
dea3101e | 322 | { |
2e0fef85 | 323 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 324 | IOCB_t *icmd; |
0bd4ca25 | 325 | struct lpfc_iocbq *geniocb; |
92d7f7b0 | 326 | int rc; |
dea3101e JB |
327 | |
328 | /* Allocate buffer for command iocb */ | |
0bd4ca25 | 329 | geniocb = lpfc_sli_get_iocbq(phba); |
dea3101e JB |
330 | |
331 | if (geniocb == NULL) | |
332 | return 1; | |
dea3101e JB |
333 | |
334 | icmd = &geniocb->iocb; | |
335 | icmd->un.genreq64.bdl.ulpIoTag32 = 0; | |
336 | icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys); | |
337 | icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys); | |
34b02dcd | 338 | icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64; |
4258e98e | 339 | icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof(struct ulp_bde64)); |
dea3101e JB |
340 | |
341 | if (usr_flg) | |
342 | geniocb->context3 = NULL; | |
343 | else | |
344 | geniocb->context3 = (uint8_t *) bmp; | |
345 | ||
346 | /* Save for completion so we can release these resources */ | |
347 | geniocb->context1 = (uint8_t *) inp; | |
348 | geniocb->context2 = (uint8_t *) outp; | |
e47c9093 | 349 | geniocb->context_un.ndlp = lpfc_nlp_get(ndlp); |
dea3101e JB |
350 | |
351 | /* Fill in payload, bp points to frame payload */ | |
352 | icmd->ulpCommand = CMD_GEN_REQUEST64_CR; | |
353 | ||
354 | /* Fill in rest of iocb */ | |
355 | icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA); | |
356 | icmd->un.genreq64.w5.hcsw.Dfctl = 0; | |
6a9c52cf JS |
357 | icmd->un.genreq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CTL; |
358 | icmd->un.genreq64.w5.hcsw.Type = FC_TYPE_CT; | |
dea3101e | 359 | |
c9f8735b JW |
360 | if (!tmo) { |
361 | /* FC spec states we need 3 * ratov for CT requests */ | |
362 | tmo = (3 * phba->fc_ratov); | |
363 | } | |
dea3101e JB |
364 | icmd->ulpTimeout = tmo; |
365 | icmd->ulpBdeCount = 1; | |
366 | icmd->ulpLe = 1; | |
367 | icmd->ulpClass = CLASS3; | |
368 | icmd->ulpContext = ndlp->nlp_rpi; | |
6d368e53 JS |
369 | if (phba->sli_rev == LPFC_SLI_REV4) |
370 | icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; | |
dea3101e | 371 | |
92d7f7b0 JS |
372 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) { |
373 | /* For GEN_REQUEST64_CR, use the RPI */ | |
374 | icmd->ulpCt_h = 0; | |
375 | icmd->ulpCt_l = 0; | |
376 | } | |
377 | ||
dea3101e | 378 | /* Issue GEN REQ IOCB for NPORT <did> */ |
e8b62011 JS |
379 | lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, |
380 | "0119 Issue GEN REQ IOCB to NPORT x%x " | |
381 | "Data: x%x x%x\n", | |
382 | ndlp->nlp_DID, icmd->ulpIoTag, | |
383 | vport->port_state); | |
dea3101e JB |
384 | geniocb->iocb_cmpl = cmpl; |
385 | geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT; | |
2e0fef85 | 386 | geniocb->vport = vport; |
92d7f7b0 | 387 | geniocb->retry = retry; |
3772a991 | 388 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, geniocb, 0); |
92d7f7b0 JS |
389 | |
390 | if (rc == IOCB_ERROR) { | |
604a3e30 | 391 | lpfc_sli_release_iocbq(phba, geniocb); |
dea3101e JB |
392 | return 1; |
393 | } | |
dea3101e JB |
394 | |
395 | return 0; | |
396 | } | |
397 | ||
4258e98e JS |
398 | /** |
399 | * lpfc_ct_cmd - Build and issue a CT command | |
400 | * @vport: pointer to a host virtual N_Port data structure. | |
401 | * @inmp: Pointer to data buffer for response data. | |
402 | * @bmp: Pointer to BPL for SLI command | |
403 | * @ndlp: Destination NPort nodelist entry | |
404 | * @cmpl: completion routine to call when command completes | |
405 | * | |
406 | * This function is called for issuing a CT command. | |
407 | */ | |
dea3101e | 408 | static int |
2e0fef85 | 409 | lpfc_ct_cmd(struct lpfc_vport *vport, struct lpfc_dmabuf *inmp, |
dea3101e JB |
410 | struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp, |
411 | void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *, | |
412 | struct lpfc_iocbq *), | |
92d7f7b0 | 413 | uint32_t rsp_size, uint8_t retry) |
dea3101e | 414 | { |
2e0fef85 | 415 | struct lpfc_hba *phba = vport->phba; |
dea3101e JB |
416 | struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt; |
417 | struct lpfc_dmabuf *outmp; | |
418 | int cnt = 0, status; | |
419 | int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)-> | |
420 | CommandResponse.bits.CmdRsp; | |
421 | ||
422 | bpl++; /* Skip past ct request */ | |
423 | ||
424 | /* Put buffer(s) for ct rsp in bpl */ | |
425 | outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt); | |
426 | if (!outmp) | |
427 | return -ENOMEM; | |
6a9c52cf JS |
428 | /* |
429 | * Form the CT IOCB. The total number of BDEs in this IOCB | |
430 | * is the single command plus response count from | |
431 | * lpfc_alloc_ct_rsp. | |
432 | */ | |
433 | cnt += 1; | |
2e0fef85 | 434 | status = lpfc_gen_req(vport, bmp, inmp, outmp, cmpl, ndlp, 0, |
6a9c52cf | 435 | cnt, 0, retry); |
dea3101e JB |
436 | if (status) { |
437 | lpfc_free_ct_rsp(phba, outmp); | |
438 | return -ENOMEM; | |
439 | } | |
440 | return 0; | |
441 | } | |
442 | ||
549e55cd | 443 | struct lpfc_vport * |
92d7f7b0 | 444 | lpfc_find_vport_by_did(struct lpfc_hba *phba, uint32_t did) { |
92d7f7b0 | 445 | struct lpfc_vport *vport_curr; |
549e55cd | 446 | unsigned long flags; |
92d7f7b0 | 447 | |
549e55cd | 448 | spin_lock_irqsave(&phba->hbalock, flags); |
92d7f7b0 | 449 | list_for_each_entry(vport_curr, &phba->port_list, listentry) { |
549e55cd JS |
450 | if ((vport_curr->fc_myDID) && (vport_curr->fc_myDID == did)) { |
451 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
92d7f7b0 | 452 | return vport_curr; |
549e55cd | 453 | } |
92d7f7b0 | 454 | } |
549e55cd | 455 | spin_unlock_irqrestore(&phba->hbalock, flags); |
92d7f7b0 JS |
456 | return NULL; |
457 | } | |
458 | ||
a0f2d3ef JS |
459 | static void |
460 | lpfc_prep_node_fc4type(struct lpfc_vport *vport, uint32_t Did, uint8_t fc4_type) | |
461 | { | |
462 | struct lpfc_nodelist *ndlp; | |
463 | ||
464 | if ((vport->port_type != LPFC_NPIV_PORT) || | |
465 | !(vport->ct_flags & FC_CT_RFF_ID) || !vport->cfg_restrict_login) { | |
466 | ||
467 | ndlp = lpfc_setup_disc_node(vport, Did); | |
468 | ||
469 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { | |
bd2cdd5e JS |
470 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, |
471 | "Parse GID_FTrsp: did:x%x flg:x%x x%x", | |
472 | Did, ndlp->nlp_flag, vport->fc_flag); | |
473 | ||
a0f2d3ef JS |
474 | /* By default, the driver expects to support FCP FC4 */ |
475 | if (fc4_type == FC_TYPE_FCP) | |
476 | ndlp->nlp_fc4_type |= NLP_FC4_FCP; | |
477 | ||
478 | if (fc4_type == FC_TYPE_NVME) | |
479 | ndlp->nlp_fc4_type |= NLP_FC4_NVME; | |
480 | ||
481 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, | |
482 | "0238 Process x%06x NameServer Rsp " | |
483 | "Data: x%x x%x x%x x%x\n", Did, | |
484 | ndlp->nlp_flag, ndlp->nlp_fc4_type, | |
485 | vport->fc_flag, | |
486 | vport->fc_rscn_id_cnt); | |
bd2cdd5e JS |
487 | } else { |
488 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, | |
489 | "Skip1 GID_FTrsp: did:x%x flg:x%x cnt:%d", | |
490 | Did, vport->fc_flag, vport->fc_rscn_id_cnt); | |
491 | ||
a0f2d3ef JS |
492 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
493 | "0239 Skip x%06x NameServer Rsp " | |
494 | "Data: x%x x%x\n", Did, | |
495 | vport->fc_flag, | |
496 | vport->fc_rscn_id_cnt); | |
bd2cdd5e | 497 | } |
a0f2d3ef JS |
498 | } else { |
499 | if (!(vport->fc_flag & FC_RSCN_MODE) || | |
500 | lpfc_rscn_payload_check(vport, Did)) { | |
bd2cdd5e JS |
501 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, |
502 | "Query GID_FTrsp: did:x%x flg:x%x cnt:%d", | |
503 | Did, vport->fc_flag, vport->fc_rscn_id_cnt); | |
504 | ||
a0f2d3ef | 505 | /* |
b57ab746 | 506 | * This NPortID was previously a FCP/NVMe target, |
a0f2d3ef JS |
507 | * Don't even bother to send GFF_ID. |
508 | */ | |
509 | ndlp = lpfc_findnode_did(vport, Did); | |
b57ab746 JS |
510 | if (ndlp && NLP_CHK_NODE_ACT(ndlp) && |
511 | (ndlp->nlp_type & | |
512 | (NLP_FCP_TARGET | NLP_NVME_TARGET))) { | |
513 | if (fc4_type == FC_TYPE_FCP) | |
514 | ndlp->nlp_fc4_type |= NLP_FC4_FCP; | |
515 | if (fc4_type == FC_TYPE_NVME) | |
516 | ndlp->nlp_fc4_type |= NLP_FC4_NVME; | |
517 | lpfc_setup_disc_node(vport, Did); | |
518 | } else if (lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID, | |
519 | 0, Did) == 0) | |
520 | vport->num_disc_nodes++; | |
521 | else | |
522 | lpfc_setup_disc_node(vport, Did); | |
bd2cdd5e JS |
523 | } else { |
524 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, | |
525 | "Skip2 GID_FTrsp: did:x%x flg:x%x cnt:%d", | |
526 | Did, vport->fc_flag, vport->fc_rscn_id_cnt); | |
527 | ||
a0f2d3ef JS |
528 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
529 | "0245 Skip x%06x NameServer Rsp " | |
530 | "Data: x%x x%x\n", Did, | |
531 | vport->fc_flag, | |
532 | vport->fc_rscn_id_cnt); | |
bd2cdd5e | 533 | } |
a0f2d3ef JS |
534 | } |
535 | } | |
536 | ||
1c5b12f7 JS |
537 | static void |
538 | lpfc_ns_rsp_audit_did(struct lpfc_vport *vport, uint32_t Did, uint8_t fc4_type) | |
539 | { | |
540 | struct lpfc_hba *phba = vport->phba; | |
541 | struct lpfc_nodelist *ndlp = NULL; | |
542 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
543 | ||
544 | /* | |
545 | * To conserve rpi's, filter out addresses for other | |
546 | * vports on the same physical HBAs. | |
547 | */ | |
548 | if (Did != vport->fc_myDID && | |
549 | (!lpfc_find_vport_by_did(phba, Did) || | |
550 | vport->cfg_peer_port_login)) { | |
551 | if (!phba->nvmet_support) { | |
552 | /* FCPI/NVMEI path. Process Did */ | |
553 | lpfc_prep_node_fc4type(vport, Did, fc4_type); | |
554 | return; | |
555 | } | |
556 | /* NVMET path. NVMET only cares about NVMEI nodes. */ | |
557 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { | |
558 | if (ndlp->nlp_type != NLP_NVME_INITIATOR || | |
559 | ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) | |
560 | continue; | |
561 | spin_lock_irq(shost->host_lock); | |
562 | if (ndlp->nlp_DID == Did) | |
563 | ndlp->nlp_flag &= ~NLP_NVMET_RECOV; | |
564 | else | |
565 | ndlp->nlp_flag |= NLP_NVMET_RECOV; | |
566 | spin_unlock_irq(shost->host_lock); | |
567 | } | |
568 | } | |
569 | } | |
570 | ||
dea3101e | 571 | static int |
a0f2d3ef JS |
572 | lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint8_t fc4_type, |
573 | uint32_t Size) | |
dea3101e JB |
574 | { |
575 | struct lpfc_sli_ct_request *Response = | |
576 | (struct lpfc_sli_ct_request *) mp->virt; | |
dea3101e JB |
577 | struct lpfc_dmabuf *mlast, *next_mp; |
578 | uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType; | |
2e0fef85 | 579 | uint32_t Did, CTentry; |
dea3101e JB |
580 | int Cnt; |
581 | struct list_head head; | |
1c5b12f7 JS |
582 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
583 | struct lpfc_nodelist *ndlp = NULL; | |
dea3101e | 584 | |
2e0fef85 | 585 | lpfc_set_disctmo(vport); |
92d7f7b0 | 586 | vport->num_disc_nodes = 0; |
0ff10d46 | 587 | vport->fc_ns_retry = 0; |
dea3101e | 588 | |
dea3101e JB |
589 | |
590 | list_add_tail(&head, &mp->list); | |
591 | list_for_each_entry_safe(mp, next_mp, &head, list) { | |
592 | mlast = mp; | |
593 | ||
7054a606 JS |
594 | Cnt = Size > FCELSSIZE ? FCELSSIZE : Size; |
595 | ||
dea3101e JB |
596 | Size -= Cnt; |
597 | ||
1dcb58e5 | 598 | if (!ctptr) { |
dea3101e | 599 | ctptr = (uint32_t *) mlast->virt; |
1dcb58e5 | 600 | } else |
dea3101e JB |
601 | Cnt -= 16; /* subtract length of CT header */ |
602 | ||
603 | /* Loop through entire NameServer list of DIDs */ | |
4258e98e | 604 | while (Cnt >= sizeof(uint32_t)) { |
dea3101e JB |
605 | /* Get next DID from NameServer List */ |
606 | CTentry = *ctptr++; | |
607 | Did = ((be32_to_cpu(CTentry)) & Mask_DID); | |
1c5b12f7 | 608 | lpfc_ns_rsp_audit_did(vport, Did, fc4_type); |
76b2c34a | 609 | if (CTentry & (cpu_to_be32(SLI_CT_LAST_ENTRY))) |
dea3101e | 610 | goto nsout1; |
a0f2d3ef | 611 | |
4258e98e | 612 | Cnt -= sizeof(uint32_t); |
dea3101e JB |
613 | } |
614 | ctptr = NULL; | |
615 | ||
616 | } | |
617 | ||
1c5b12f7 JS |
618 | /* All GID_FT entries processed. If the driver is running in |
619 | * in target mode, put impacted nodes into recovery and drop | |
620 | * the RPI to flush outstanding IO. | |
621 | */ | |
622 | if (vport->phba->nvmet_support) { | |
623 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { | |
624 | if (!(ndlp->nlp_flag & NLP_NVMET_RECOV)) | |
625 | continue; | |
626 | lpfc_disc_state_machine(vport, ndlp, NULL, | |
627 | NLP_EVT_DEVICE_RECOVERY); | |
628 | spin_lock_irq(shost->host_lock); | |
629 | ndlp->nlp_flag &= ~NLP_NVMET_RECOV; | |
0d618cf4 | 630 | spin_unlock_irq(shost->host_lock); |
1c5b12f7 JS |
631 | } |
632 | } | |
633 | ||
dea3101e JB |
634 | nsout1: |
635 | list_del(&head); | |
dea3101e JB |
636 | return 0; |
637 | } | |
638 | ||
dea3101e | 639 | static void |
2e0fef85 JS |
640 | lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
641 | struct lpfc_iocbq *rspiocb) | |
dea3101e | 642 | { |
2e0fef85 | 643 | struct lpfc_vport *vport = cmdiocb->vport; |
92d7f7b0 | 644 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
dea3101e | 645 | IOCB_t *irsp; |
dea3101e | 646 | struct lpfc_dmabuf *outp; |
a0f2d3ef | 647 | struct lpfc_dmabuf *inp; |
dea3101e | 648 | struct lpfc_sli_ct_request *CTrsp; |
a0f2d3ef | 649 | struct lpfc_sli_ct_request *CTreq; |
51ef4c26 | 650 | struct lpfc_nodelist *ndlp; |
a0f2d3ef | 651 | int rc, type; |
dea3101e | 652 | |
51ef4c26 JS |
653 | /* First save ndlp, before we overwrite it */ |
654 | ndlp = cmdiocb->context_un.ndlp; | |
655 | ||
dea3101e JB |
656 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
657 | cmdiocb->context_un.rsp_iocb = rspiocb; | |
a0f2d3ef | 658 | inp = (struct lpfc_dmabuf *) cmdiocb->context1; |
dea3101e | 659 | outp = (struct lpfc_dmabuf *) cmdiocb->context2; |
858c9f6c JS |
660 | irsp = &rspiocb->iocb; |
661 | ||
662 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, | |
663 | "GID_FT cmpl: status:x%x/x%x rtry:%d", | |
664 | irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_ns_retry); | |
dea3101e | 665 | |
92d7f7b0 | 666 | /* Don't bother processing response if vport is being torn down. */ |
eada272d JS |
667 | if (vport->load_flag & FC_UNLOADING) { |
668 | if (vport->fc_flag & FC_RSCN_MODE) | |
669 | lpfc_els_flush_rscn(vport); | |
92d7f7b0 | 670 | goto out; |
eada272d | 671 | } |
92d7f7b0 | 672 | |
58da1ffb | 673 | if (lpfc_els_chk_latt(vport)) { |
e8b62011 JS |
674 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
675 | "0216 Link event during NS query\n"); | |
eada272d JS |
676 | if (vport->fc_flag & FC_RSCN_MODE) |
677 | lpfc_els_flush_rscn(vport); | |
858c9f6c JS |
678 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
679 | goto out; | |
680 | } | |
58da1ffb JS |
681 | if (lpfc_error_lost_link(irsp)) { |
682 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, | |
683 | "0226 NS query failed due to link event\n"); | |
eada272d JS |
684 | if (vport->fc_flag & FC_RSCN_MODE) |
685 | lpfc_els_flush_rscn(vport); | |
58da1ffb JS |
686 | goto out; |
687 | } | |
858c9f6c | 688 | if (irsp->ulpStatus) { |
dea3101e | 689 | /* Check for retry */ |
2e0fef85 | 690 | if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) { |
58da1ffb | 691 | if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT || |
edb22f06 | 692 | (irsp->un.ulpWord[4] & IOERR_PARAM_MASK) != |
e3d2b802 | 693 | IOERR_NO_RESOURCES) |
858c9f6c | 694 | vport->fc_ns_retry++; |
0ff10d46 | 695 | |
a0f2d3ef JS |
696 | type = lpfc_get_gidft_type(vport, cmdiocb); |
697 | if (type == 0) | |
698 | goto out; | |
699 | ||
58da1ffb | 700 | /* CT command is being retried */ |
a0f2d3ef | 701 | vport->gidft_inp--; |
58da1ffb | 702 | rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, |
a0f2d3ef | 703 | vport->fc_ns_retry, type); |
58da1ffb JS |
704 | if (rc == 0) |
705 | goto out; | |
92d7f7b0 | 706 | } |
eada272d JS |
707 | if (vport->fc_flag & FC_RSCN_MODE) |
708 | lpfc_els_flush_rscn(vport); | |
92d7f7b0 | 709 | lpfc_vport_set_state(vport, FC_VPORT_FAILED); |
e8b62011 JS |
710 | lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, |
711 | "0257 GID_FT Query error: 0x%x 0x%x\n", | |
712 | irsp->ulpStatus, vport->fc_ns_retry); | |
dea3101e JB |
713 | } else { |
714 | /* Good status, continue checking */ | |
a0f2d3ef | 715 | CTreq = (struct lpfc_sli_ct_request *) inp->virt; |
dea3101e JB |
716 | CTrsp = (struct lpfc_sli_ct_request *) outp->virt; |
717 | if (CTrsp->CommandResponse.bits.CmdRsp == | |
76b2c34a | 718 | cpu_to_be16(SLI_CT_RESPONSE_FS_ACC)) { |
e8b62011 | 719 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
a0f2d3ef JS |
720 | "0208 NameServer Rsp Data: x%x x%x\n", |
721 | vport->fc_flag, | |
722 | CTreq->un.gid.Fc4Type); | |
723 | ||
724 | lpfc_ns_rsp(vport, | |
725 | outp, | |
726 | CTreq->un.gid.Fc4Type, | |
dea3101e JB |
727 | (uint32_t) (irsp->un.genreq64.bdl.bdeSize)); |
728 | } else if (CTrsp->CommandResponse.bits.CmdRsp == | |
729 | be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) { | |
730 | /* NameServer Rsp Error */ | |
a58cbd52 JS |
731 | if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ) |
732 | && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) { | |
e8b62011 JS |
733 | lpfc_printf_vlog(vport, KERN_INFO, |
734 | LOG_DISCOVERY, | |
735 | "0269 No NameServer Entries " | |
a58cbd52 | 736 | "Data: x%x x%x x%x x%x\n", |
a58cbd52 JS |
737 | CTrsp->CommandResponse.bits.CmdRsp, |
738 | (uint32_t) CTrsp->ReasonCode, | |
739 | (uint32_t) CTrsp->Explanation, | |
740 | vport->fc_flag); | |
741 | ||
742 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, | |
743 | "GID_FT no entry cmd:x%x rsn:x%x exp:x%x", | |
744 | (uint32_t)CTrsp->CommandResponse.bits.CmdRsp, | |
745 | (uint32_t) CTrsp->ReasonCode, | |
746 | (uint32_t) CTrsp->Explanation); | |
e8b62011 JS |
747 | } else { |
748 | lpfc_printf_vlog(vport, KERN_INFO, | |
749 | LOG_DISCOVERY, | |
750 | "0240 NameServer Rsp Error " | |
dea3101e | 751 | "Data: x%x x%x x%x x%x\n", |
dea3101e JB |
752 | CTrsp->CommandResponse.bits.CmdRsp, |
753 | (uint32_t) CTrsp->ReasonCode, | |
754 | (uint32_t) CTrsp->Explanation, | |
2e0fef85 | 755 | vport->fc_flag); |
858c9f6c | 756 | |
a58cbd52 | 757 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, |
858c9f6c JS |
758 | "GID_FT rsp err1 cmd:x%x rsn:x%x exp:x%x", |
759 | (uint32_t)CTrsp->CommandResponse.bits.CmdRsp, | |
760 | (uint32_t) CTrsp->ReasonCode, | |
761 | (uint32_t) CTrsp->Explanation); | |
a58cbd52 JS |
762 | } |
763 | ||
858c9f6c | 764 | |
dea3101e JB |
765 | } else { |
766 | /* NameServer Rsp Error */ | |
e8b62011 JS |
767 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
768 | "0241 NameServer Rsp Error " | |
dea3101e | 769 | "Data: x%x x%x x%x x%x\n", |
dea3101e JB |
770 | CTrsp->CommandResponse.bits.CmdRsp, |
771 | (uint32_t) CTrsp->ReasonCode, | |
772 | (uint32_t) CTrsp->Explanation, | |
2e0fef85 | 773 | vport->fc_flag); |
858c9f6c JS |
774 | |
775 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, | |
776 | "GID_FT rsp err2 cmd:x%x rsn:x%x exp:x%x", | |
777 | (uint32_t)CTrsp->CommandResponse.bits.CmdRsp, | |
778 | (uint32_t) CTrsp->ReasonCode, | |
779 | (uint32_t) CTrsp->Explanation); | |
dea3101e | 780 | } |
a0f2d3ef | 781 | vport->gidft_inp--; |
dea3101e JB |
782 | } |
783 | /* Link up / RSCN discovery */ | |
a0f2d3ef JS |
784 | if ((vport->num_disc_nodes == 0) && |
785 | (vport->gidft_inp == 0)) { | |
92d7f7b0 JS |
786 | /* |
787 | * The driver has cycled through all Nports in the RSCN payload. | |
788 | * Complete the handling by cleaning up and marking the | |
789 | * current driver state. | |
790 | */ | |
791 | if (vport->port_state >= LPFC_DISC_AUTH) { | |
792 | if (vport->fc_flag & FC_RSCN_MODE) { | |
793 | lpfc_els_flush_rscn(vport); | |
794 | spin_lock_irq(shost->host_lock); | |
795 | vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */ | |
796 | spin_unlock_irq(shost->host_lock); | |
797 | } | |
798 | else | |
799 | lpfc_els_flush_rscn(vport); | |
800 | } | |
801 | ||
802 | lpfc_disc_start(vport); | |
803 | } | |
804 | out: | |
51ef4c26 | 805 | cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */ |
858c9f6c | 806 | lpfc_ct_free_iocb(phba, cmdiocb); |
92d7f7b0 JS |
807 | return; |
808 | } | |
809 | ||
311464ec | 810 | static void |
92d7f7b0 JS |
811 | lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
812 | struct lpfc_iocbq *rspiocb) | |
813 | { | |
814 | struct lpfc_vport *vport = cmdiocb->vport; | |
815 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
816 | IOCB_t *irsp = &rspiocb->iocb; | |
92d7f7b0 JS |
817 | struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *) cmdiocb->context1; |
818 | struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *) cmdiocb->context2; | |
819 | struct lpfc_sli_ct_request *CTrsp; | |
0ff10d46 | 820 | int did, rc, retry; |
92d7f7b0 JS |
821 | uint8_t fbits; |
822 | struct lpfc_nodelist *ndlp; | |
823 | ||
824 | did = ((struct lpfc_sli_ct_request *) inp->virt)->un.gff.PortId; | |
825 | did = be32_to_cpu(did); | |
826 | ||
858c9f6c JS |
827 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, |
828 | "GFF_ID cmpl: status:x%x/x%x did:x%x", | |
829 | irsp->ulpStatus, irsp->un.ulpWord[4], did); | |
830 | ||
92d7f7b0 JS |
831 | if (irsp->ulpStatus == IOSTAT_SUCCESS) { |
832 | /* Good status, continue checking */ | |
833 | CTrsp = (struct lpfc_sli_ct_request *) outp->virt; | |
834 | fbits = CTrsp->un.gff_acc.fbits[FCP_TYPE_FEATURE_OFFSET]; | |
835 | ||
836 | if (CTrsp->CommandResponse.bits.CmdRsp == | |
837 | be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) { | |
838 | if ((fbits & FC4_FEATURE_INIT) && | |
839 | !(fbits & FC4_FEATURE_TARGET)) { | |
e8b62011 JS |
840 | lpfc_printf_vlog(vport, KERN_INFO, |
841 | LOG_DISCOVERY, | |
842 | "0270 Skip x%x GFF " | |
843 | "NameServer Rsp Data: (init) " | |
844 | "x%x x%x\n", did, fbits, | |
845 | vport->fc_rscn_id_cnt); | |
92d7f7b0 JS |
846 | goto out; |
847 | } | |
848 | } | |
849 | } | |
858c9f6c | 850 | else { |
0ff10d46 JS |
851 | /* Check for retry */ |
852 | if (cmdiocb->retry < LPFC_MAX_NS_RETRY) { | |
853 | retry = 1; | |
854 | if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) { | |
e3d2b802 JS |
855 | switch ((irsp->un.ulpWord[4] & |
856 | IOERR_PARAM_MASK)) { | |
857 | ||
0ff10d46 JS |
858 | case IOERR_NO_RESOURCES: |
859 | /* We don't increment the retry | |
860 | * count for this case. | |
861 | */ | |
862 | break; | |
863 | case IOERR_LINK_DOWN: | |
864 | case IOERR_SLI_ABORTED: | |
865 | case IOERR_SLI_DOWN: | |
866 | retry = 0; | |
867 | break; | |
868 | default: | |
869 | cmdiocb->retry++; | |
870 | } | |
871 | } | |
872 | else | |
873 | cmdiocb->retry++; | |
874 | ||
875 | if (retry) { | |
876 | /* CT command is being retried */ | |
877 | rc = lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID, | |
878 | cmdiocb->retry, did); | |
879 | if (rc == 0) { | |
880 | /* success */ | |
881 | lpfc_ct_free_iocb(phba, cmdiocb); | |
882 | return; | |
883 | } | |
884 | } | |
885 | } | |
e8b62011 JS |
886 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
887 | "0267 NameServer GFF Rsp " | |
888 | "x%x Error (%d %d) Data: x%x x%x\n", | |
889 | did, irsp->ulpStatus, irsp->un.ulpWord[4], | |
7f5f3d0d | 890 | vport->fc_flag, vport->fc_rscn_id_cnt); |
858c9f6c JS |
891 | } |
892 | ||
92d7f7b0 JS |
893 | /* This is a target port, unregistered port, or the GFF_ID failed */ |
894 | ndlp = lpfc_setup_disc_node(vport, did); | |
58da1ffb | 895 | if (ndlp && NLP_CHK_NODE_ACT(ndlp)) { |
e8b62011 JS |
896 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
897 | "0242 Process x%x GFF " | |
898 | "NameServer Rsp Data: x%x x%x x%x\n", | |
899 | did, ndlp->nlp_flag, vport->fc_flag, | |
900 | vport->fc_rscn_id_cnt); | |
92d7f7b0 | 901 | } else { |
e8b62011 JS |
902 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
903 | "0243 Skip x%x GFF " | |
904 | "NameServer Rsp Data: x%x x%x\n", did, | |
905 | vport->fc_flag, vport->fc_rscn_id_cnt); | |
92d7f7b0 | 906 | } |
dea3101e | 907 | out: |
92d7f7b0 JS |
908 | /* Link up / RSCN discovery */ |
909 | if (vport->num_disc_nodes) | |
910 | vport->num_disc_nodes--; | |
911 | if (vport->num_disc_nodes == 0) { | |
912 | /* | |
913 | * The driver has cycled through all Nports in the RSCN payload. | |
914 | * Complete the handling by cleaning up and marking the | |
915 | * current driver state. | |
916 | */ | |
917 | if (vport->port_state >= LPFC_DISC_AUTH) { | |
918 | if (vport->fc_flag & FC_RSCN_MODE) { | |
919 | lpfc_els_flush_rscn(vport); | |
920 | spin_lock_irq(shost->host_lock); | |
921 | vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */ | |
922 | spin_unlock_irq(shost->host_lock); | |
923 | } | |
924 | else | |
925 | lpfc_els_flush_rscn(vport); | |
926 | } | |
927 | lpfc_disc_start(vport); | |
928 | } | |
858c9f6c | 929 | lpfc_ct_free_iocb(phba, cmdiocb); |
dea3101e JB |
930 | return; |
931 | } | |
932 | ||
a0f2d3ef JS |
933 | static void |
934 | lpfc_cmpl_ct_cmd_gft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | |
935 | struct lpfc_iocbq *rspiocb) | |
936 | { | |
937 | struct lpfc_vport *vport = cmdiocb->vport; | |
938 | IOCB_t *irsp = &rspiocb->iocb; | |
939 | struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *)cmdiocb->context1; | |
940 | struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *)cmdiocb->context2; | |
941 | struct lpfc_sli_ct_request *CTrsp; | |
942 | int did; | |
943 | struct lpfc_nodelist *ndlp; | |
944 | uint32_t fc4_data_0, fc4_data_1; | |
945 | ||
946 | did = ((struct lpfc_sli_ct_request *)inp->virt)->un.gft.PortId; | |
947 | did = be32_to_cpu(did); | |
948 | ||
bd2cdd5e JS |
949 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, |
950 | "GFT_ID cmpl: status:x%x/x%x did:x%x", | |
951 | irsp->ulpStatus, irsp->un.ulpWord[4], did); | |
952 | ||
a0f2d3ef JS |
953 | if (irsp->ulpStatus == IOSTAT_SUCCESS) { |
954 | /* Good status, continue checking */ | |
955 | CTrsp = (struct lpfc_sli_ct_request *)outp->virt; | |
956 | fc4_data_0 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[0]); | |
957 | fc4_data_1 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[1]); | |
958 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, | |
959 | "3062 DID x%06x GFT Wd0 x%08x Wd1 x%08x\n", | |
960 | did, fc4_data_0, fc4_data_1); | |
961 | ||
962 | ndlp = lpfc_findnode_did(vport, did); | |
963 | if (ndlp) { | |
964 | /* The bitmask value for FCP and NVME FCP types is | |
965 | * the same because they are 32 bits distant from | |
966 | * each other in word0 and word0. | |
967 | */ | |
968 | if (fc4_data_0 & LPFC_FC4_TYPE_BITMASK) | |
969 | ndlp->nlp_fc4_type |= NLP_FC4_FCP; | |
970 | if (fc4_data_1 & LPFC_FC4_TYPE_BITMASK) | |
971 | ndlp->nlp_fc4_type |= NLP_FC4_NVME; | |
972 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, | |
973 | "3064 Setting ndlp %p, DID x%06x with " | |
974 | "FC4 x%08x, Data: x%08x x%08x\n", | |
975 | ndlp, did, ndlp->nlp_fc4_type, | |
976 | FC_TYPE_FCP, FC_TYPE_NVME); | |
b5ccc7d6 | 977 | ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE; |
e6ef6a77 GS |
978 | |
979 | lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE); | |
980 | lpfc_issue_els_prli(vport, ndlp, 0); | |
a0f2d3ef | 981 | } |
a0f2d3ef JS |
982 | } else |
983 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, | |
984 | "3065 GFT_ID failed x%08x\n", irsp->ulpStatus); | |
985 | ||
986 | lpfc_ct_free_iocb(phba, cmdiocb); | |
987 | } | |
92d7f7b0 | 988 | |
dea3101e | 989 | static void |
7ee5d43e JS |
990 | lpfc_cmpl_ct(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
991 | struct lpfc_iocbq *rspiocb) | |
dea3101e | 992 | { |
92d7f7b0 | 993 | struct lpfc_vport *vport = cmdiocb->vport; |
dea3101e JB |
994 | struct lpfc_dmabuf *inp; |
995 | struct lpfc_dmabuf *outp; | |
996 | IOCB_t *irsp; | |
997 | struct lpfc_sli_ct_request *CTrsp; | |
51ef4c26 | 998 | struct lpfc_nodelist *ndlp; |
92d7f7b0 JS |
999 | int cmdcode, rc; |
1000 | uint8_t retry; | |
858c9f6c | 1001 | uint32_t latt; |
dea3101e | 1002 | |
51ef4c26 JS |
1003 | /* First save ndlp, before we overwrite it */ |
1004 | ndlp = cmdiocb->context_un.ndlp; | |
1005 | ||
dea3101e JB |
1006 | /* we pass cmdiocb to state machine which needs rspiocb as well */ |
1007 | cmdiocb->context_un.rsp_iocb = rspiocb; | |
1008 | ||
1009 | inp = (struct lpfc_dmabuf *) cmdiocb->context1; | |
1010 | outp = (struct lpfc_dmabuf *) cmdiocb->context2; | |
dea3101e JB |
1011 | irsp = &rspiocb->iocb; |
1012 | ||
92d7f7b0 JS |
1013 | cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)-> |
1014 | CommandResponse.bits.CmdRsp); | |
dea3101e JB |
1015 | CTrsp = (struct lpfc_sli_ct_request *) outp->virt; |
1016 | ||
858c9f6c JS |
1017 | latt = lpfc_els_chk_latt(vport); |
1018 | ||
1019 | /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */ | |
e8b62011 | 1020 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
7ee5d43e | 1021 | "0209 CT Request completes, latt %d, " |
e8b62011 JS |
1022 | "ulpStatus x%x CmdRsp x%x, Context x%x, Tag x%x\n", |
1023 | latt, irsp->ulpStatus, | |
1024 | CTrsp->CommandResponse.bits.CmdRsp, | |
1025 | cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag); | |
dea3101e | 1026 | |
858c9f6c JS |
1027 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, |
1028 | "CT cmd cmpl: status:x%x/x%x cmd:x%x", | |
1029 | irsp->ulpStatus, irsp->un.ulpWord[4], cmdcode); | |
1030 | ||
92d7f7b0 | 1031 | if (irsp->ulpStatus) { |
e8b62011 | 1032 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
6e15520d | 1033 | "0268 NS cmd x%x Error (x%x x%x)\n", |
e8b62011 | 1034 | cmdcode, irsp->ulpStatus, irsp->un.ulpWord[4]); |
858c9f6c | 1035 | |
92d7f7b0 | 1036 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
e3d2b802 JS |
1037 | (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == |
1038 | IOERR_SLI_DOWN) || | |
1039 | ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) == | |
1040 | IOERR_SLI_ABORTED))) | |
92d7f7b0 JS |
1041 | goto out; |
1042 | ||
1043 | retry = cmdiocb->retry; | |
1044 | if (retry >= LPFC_MAX_NS_RETRY) | |
1045 | goto out; | |
1046 | ||
1047 | retry++; | |
e8b62011 | 1048 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
d7c255b2 | 1049 | "0250 Retrying NS cmd %x\n", cmdcode); |
92d7f7b0 JS |
1050 | rc = lpfc_ns_cmd(vport, cmdcode, retry, 0); |
1051 | if (rc == 0) | |
1052 | goto out; | |
1053 | } | |
1054 | ||
1055 | out: | |
51ef4c26 | 1056 | cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */ |
858c9f6c | 1057 | lpfc_ct_free_iocb(phba, cmdiocb); |
dea3101e JB |
1058 | return; |
1059 | } | |
1060 | ||
7ee5d43e JS |
1061 | static void |
1062 | lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | |
1063 | struct lpfc_iocbq *rspiocb) | |
1064 | { | |
1065 | IOCB_t *irsp = &rspiocb->iocb; | |
1066 | struct lpfc_vport *vport = cmdiocb->vport; | |
1067 | ||
98c9ea5c JS |
1068 | if (irsp->ulpStatus == IOSTAT_SUCCESS) { |
1069 | struct lpfc_dmabuf *outp; | |
1070 | struct lpfc_sli_ct_request *CTrsp; | |
1071 | ||
1072 | outp = (struct lpfc_dmabuf *) cmdiocb->context2; | |
1073 | CTrsp = (struct lpfc_sli_ct_request *) outp->virt; | |
1074 | if (CTrsp->CommandResponse.bits.CmdRsp == | |
1075 | be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) | |
1076 | vport->ct_flags |= FC_CT_RFT_ID; | |
1077 | } | |
7ee5d43e JS |
1078 | lpfc_cmpl_ct(phba, cmdiocb, rspiocb); |
1079 | return; | |
1080 | } | |
1081 | ||
dea3101e | 1082 | static void |
2e0fef85 JS |
1083 | lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
1084 | struct lpfc_iocbq *rspiocb) | |
dea3101e | 1085 | { |
7ee5d43e JS |
1086 | IOCB_t *irsp = &rspiocb->iocb; |
1087 | struct lpfc_vport *vport = cmdiocb->vport; | |
1088 | ||
98c9ea5c JS |
1089 | if (irsp->ulpStatus == IOSTAT_SUCCESS) { |
1090 | struct lpfc_dmabuf *outp; | |
1091 | struct lpfc_sli_ct_request *CTrsp; | |
1092 | ||
1093 | outp = (struct lpfc_dmabuf *) cmdiocb->context2; | |
1094 | CTrsp = (struct lpfc_sli_ct_request *) outp->virt; | |
1095 | if (CTrsp->CommandResponse.bits.CmdRsp == | |
1096 | be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) | |
1097 | vport->ct_flags |= FC_CT_RNN_ID; | |
1098 | } | |
7ee5d43e | 1099 | lpfc_cmpl_ct(phba, cmdiocb, rspiocb); |
dea3101e JB |
1100 | return; |
1101 | } | |
1102 | ||
92d7f7b0 JS |
1103 | static void |
1104 | lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | |
1105 | struct lpfc_iocbq *rspiocb) | |
1106 | { | |
7ee5d43e JS |
1107 | IOCB_t *irsp = &rspiocb->iocb; |
1108 | struct lpfc_vport *vport = cmdiocb->vport; | |
1109 | ||
98c9ea5c JS |
1110 | if (irsp->ulpStatus == IOSTAT_SUCCESS) { |
1111 | struct lpfc_dmabuf *outp; | |
1112 | struct lpfc_sli_ct_request *CTrsp; | |
1113 | ||
1114 | outp = (struct lpfc_dmabuf *) cmdiocb->context2; | |
1115 | CTrsp = (struct lpfc_sli_ct_request *) outp->virt; | |
1116 | if (CTrsp->CommandResponse.bits.CmdRsp == | |
1117 | be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) | |
1118 | vport->ct_flags |= FC_CT_RSPN_ID; | |
1119 | } | |
7ee5d43e | 1120 | lpfc_cmpl_ct(phba, cmdiocb, rspiocb); |
92d7f7b0 JS |
1121 | return; |
1122 | } | |
1123 | ||
dea3101e | 1124 | static void |
2e0fef85 JS |
1125 | lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
1126 | struct lpfc_iocbq *rspiocb) | |
dea3101e | 1127 | { |
7ee5d43e JS |
1128 | IOCB_t *irsp = &rspiocb->iocb; |
1129 | struct lpfc_vport *vport = cmdiocb->vport; | |
1130 | ||
98c9ea5c JS |
1131 | if (irsp->ulpStatus == IOSTAT_SUCCESS) { |
1132 | struct lpfc_dmabuf *outp; | |
1133 | struct lpfc_sli_ct_request *CTrsp; | |
1134 | ||
1135 | outp = (struct lpfc_dmabuf *) cmdiocb->context2; | |
1136 | CTrsp = (struct lpfc_sli_ct_request *) outp->virt; | |
1137 | if (CTrsp->CommandResponse.bits.CmdRsp == | |
1138 | be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) | |
1139 | vport->ct_flags |= FC_CT_RSNN_NN; | |
1140 | } | |
7ee5d43e JS |
1141 | lpfc_cmpl_ct(phba, cmdiocb, rspiocb); |
1142 | return; | |
1143 | } | |
1144 | ||
1145 | static void | |
1146 | lpfc_cmpl_ct_cmd_da_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | |
1147 | struct lpfc_iocbq *rspiocb) | |
1148 | { | |
1149 | struct lpfc_vport *vport = cmdiocb->vport; | |
1150 | ||
1151 | /* even if it fails we will act as though it succeeded. */ | |
1152 | vport->ct_flags = 0; | |
1153 | lpfc_cmpl_ct(phba, cmdiocb, rspiocb); | |
dea3101e JB |
1154 | return; |
1155 | } | |
1156 | ||
2fb9bd8b | 1157 | static void |
92d7f7b0 JS |
1158 | lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
1159 | struct lpfc_iocbq *rspiocb) | |
2fb9bd8b | 1160 | { |
92d7f7b0 JS |
1161 | IOCB_t *irsp = &rspiocb->iocb; |
1162 | struct lpfc_vport *vport = cmdiocb->vport; | |
1163 | ||
98c9ea5c JS |
1164 | if (irsp->ulpStatus == IOSTAT_SUCCESS) { |
1165 | struct lpfc_dmabuf *outp; | |
1166 | struct lpfc_sli_ct_request *CTrsp; | |
1167 | ||
1168 | outp = (struct lpfc_dmabuf *) cmdiocb->context2; | |
1169 | CTrsp = (struct lpfc_sli_ct_request *) outp->virt; | |
1170 | if (CTrsp->CommandResponse.bits.CmdRsp == | |
1171 | be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) | |
1172 | vport->ct_flags |= FC_CT_RFF_ID; | |
1173 | } | |
7ee5d43e | 1174 | lpfc_cmpl_ct(phba, cmdiocb, rspiocb); |
2fb9bd8b JS |
1175 | return; |
1176 | } | |
1177 | ||
a0f2d3ef JS |
1178 | /* |
1179 | * Although the symbolic port name is thought to be an integer | |
1180 | * as of January 18, 2016, leave it as a string until more of | |
1181 | * the record state becomes defined. | |
1182 | */ | |
495a714c | 1183 | int |
92d7f7b0 JS |
1184 | lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol, |
1185 | size_t size) | |
1186 | { | |
1187 | int n; | |
92d7f7b0 | 1188 | |
a0f2d3ef JS |
1189 | /* |
1190 | * Use the lpfc board number as the Symbolic Port | |
1191 | * Name object. NPIV is not in play so this integer | |
1192 | * value is sufficient and unique per FC-ID. | |
1193 | */ | |
1194 | n = snprintf(symbol, size, "%d", vport->phba->brd_no); | |
92d7f7b0 JS |
1195 | return n; |
1196 | } | |
1197 | ||
a0f2d3ef | 1198 | |
92d7f7b0 JS |
1199 | int |
1200 | lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol, | |
1201 | size_t size) | |
dea3101e | 1202 | { |
6b5151fd | 1203 | char fwrev[FW_REV_STR_SIZE]; |
92d7f7b0 | 1204 | int n; |
dea3101e | 1205 | |
92d7f7b0 | 1206 | lpfc_decode_firmware_rev(vport->phba, fwrev, 0); |
dea3101e | 1207 | |
f0bf5f91 | 1208 | n = snprintf(symbol, size, "Emulex %s", vport->phba->ModelName); |
f0bf5f91 JS |
1209 | if (size < n) |
1210 | return n; | |
f0bf5f91 | 1211 | |
a0f2d3ef | 1212 | n += snprintf(symbol + n, size - n, " FV%s", fwrev); |
f0bf5f91 JS |
1213 | if (size < n) |
1214 | return n; | |
f0bf5f91 | 1215 | |
a0f2d3ef JS |
1216 | n += snprintf(symbol + n, size - n, " DV%s.", |
1217 | lpfc_release_version); | |
f0bf5f91 JS |
1218 | if (size < n) |
1219 | return n; | |
f0bf5f91 | 1220 | |
a0f2d3ef JS |
1221 | n += snprintf(symbol + n, size - n, " HN:%s.", |
1222 | init_utsname()->nodename); | |
f0bf5f91 JS |
1223 | if (size < n) |
1224 | return n; | |
f0bf5f91 | 1225 | |
a0f2d3ef JS |
1226 | /* Note :- OS name is "Linux" */ |
1227 | n += snprintf(symbol + n, size - n, " OS:%s\n", | |
1228 | init_utsname()->sysname); | |
92d7f7b0 | 1229 | return n; |
dea3101e JB |
1230 | } |
1231 | ||
76b2c34a JS |
1232 | static uint32_t |
1233 | lpfc_find_map_node(struct lpfc_vport *vport) | |
1234 | { | |
1235 | struct lpfc_nodelist *ndlp, *next_ndlp; | |
1236 | struct Scsi_Host *shost; | |
1237 | uint32_t cnt = 0; | |
1238 | ||
1239 | shost = lpfc_shost_from_vport(vport); | |
1240 | spin_lock_irq(shost->host_lock); | |
1241 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { | |
1242 | if (ndlp->nlp_type & NLP_FABRIC) | |
1243 | continue; | |
1244 | if ((ndlp->nlp_state == NLP_STE_MAPPED_NODE) || | |
1245 | (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE)) | |
1246 | cnt++; | |
1247 | } | |
1248 | spin_unlock_irq(shost->host_lock); | |
1249 | return cnt; | |
1250 | } | |
1251 | ||
a0f2d3ef JS |
1252 | /* |
1253 | * This routine will return the FC4 Type associated with the CT | |
1254 | * GID_FT command. | |
1255 | */ | |
1256 | int | |
1257 | lpfc_get_gidft_type(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb) | |
1258 | { | |
1259 | struct lpfc_sli_ct_request *CtReq; | |
1260 | struct lpfc_dmabuf *mp; | |
1261 | uint32_t type; | |
1262 | ||
1263 | mp = cmdiocb->context1; | |
1264 | if (mp == NULL) | |
1265 | return 0; | |
1266 | CtReq = (struct lpfc_sli_ct_request *)mp->virt; | |
1267 | type = (uint32_t)CtReq->un.gid.Fc4Type; | |
1268 | if ((type != SLI_CTPT_FCP) && (type != SLI_CTPT_NVME)) | |
1269 | return 0; | |
1270 | return type; | |
1271 | } | |
1272 | ||
dea3101e JB |
1273 | /* |
1274 | * lpfc_ns_cmd | |
1275 | * Description: | |
1276 | * Issue Cmd to NameServer | |
1277 | * SLI_CTNS_GID_FT | |
1278 | * LI_CTNS_RFT_ID | |
1279 | */ | |
1280 | int | |
92d7f7b0 JS |
1281 | lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode, |
1282 | uint8_t retry, uint32_t context) | |
dea3101e | 1283 | { |
92d7f7b0 | 1284 | struct lpfc_nodelist * ndlp; |
2e0fef85 | 1285 | struct lpfc_hba *phba = vport->phba; |
dea3101e JB |
1286 | struct lpfc_dmabuf *mp, *bmp; |
1287 | struct lpfc_sli_ct_request *CtReq; | |
1288 | struct ulp_bde64 *bpl; | |
1289 | void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *, | |
1290 | struct lpfc_iocbq *) = NULL; | |
1291 | uint32_t rsp_size = 1024; | |
92d7f7b0 | 1292 | size_t size; |
858c9f6c | 1293 | int rc = 0; |
92d7f7b0 JS |
1294 | |
1295 | ndlp = lpfc_findnode_did(vport, NameServer_DID); | |
e47c9093 JS |
1296 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) |
1297 | || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) { | |
858c9f6c JS |
1298 | rc=1; |
1299 | goto ns_cmd_exit; | |
1300 | } | |
dea3101e JB |
1301 | |
1302 | /* fill in BDEs for command */ | |
1303 | /* Allocate buffer for command payload */ | |
4258e98e | 1304 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
858c9f6c JS |
1305 | if (!mp) { |
1306 | rc=2; | |
dea3101e | 1307 | goto ns_cmd_exit; |
858c9f6c | 1308 | } |
dea3101e JB |
1309 | |
1310 | INIT_LIST_HEAD(&mp->list); | |
1311 | mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys)); | |
858c9f6c JS |
1312 | if (!mp->virt) { |
1313 | rc=3; | |
dea3101e | 1314 | goto ns_cmd_free_mp; |
858c9f6c | 1315 | } |
dea3101e JB |
1316 | |
1317 | /* Allocate buffer for Buffer ptr list */ | |
4258e98e | 1318 | bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
858c9f6c JS |
1319 | if (!bmp) { |
1320 | rc=4; | |
dea3101e | 1321 | goto ns_cmd_free_mpvirt; |
858c9f6c | 1322 | } |
dea3101e JB |
1323 | |
1324 | INIT_LIST_HEAD(&bmp->list); | |
1325 | bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys)); | |
858c9f6c JS |
1326 | if (!bmp->virt) { |
1327 | rc=5; | |
dea3101e | 1328 | goto ns_cmd_free_bmp; |
858c9f6c | 1329 | } |
dea3101e JB |
1330 | |
1331 | /* NameServer Req */ | |
e8b62011 | 1332 | lpfc_printf_vlog(vport, KERN_INFO ,LOG_DISCOVERY, |
a0f2d3ef JS |
1333 | "0236 NameServer Req Data: x%x x%x x%x x%x\n", |
1334 | cmdcode, vport->fc_flag, vport->fc_rscn_id_cnt, | |
1335 | context); | |
dea3101e JB |
1336 | |
1337 | bpl = (struct ulp_bde64 *) bmp->virt; | |
1338 | memset(bpl, 0, sizeof(struct ulp_bde64)); | |
92d7f7b0 JS |
1339 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) ); |
1340 | bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) ); | |
dea3101e JB |
1341 | bpl->tus.f.bdeFlags = 0; |
1342 | if (cmdcode == SLI_CTNS_GID_FT) | |
1343 | bpl->tus.f.bdeSize = GID_REQUEST_SZ; | |
92d7f7b0 JS |
1344 | else if (cmdcode == SLI_CTNS_GFF_ID) |
1345 | bpl->tus.f.bdeSize = GFF_REQUEST_SZ; | |
a0f2d3ef JS |
1346 | else if (cmdcode == SLI_CTNS_GFT_ID) |
1347 | bpl->tus.f.bdeSize = GFT_REQUEST_SZ; | |
dea3101e JB |
1348 | else if (cmdcode == SLI_CTNS_RFT_ID) |
1349 | bpl->tus.f.bdeSize = RFT_REQUEST_SZ; | |
1350 | else if (cmdcode == SLI_CTNS_RNN_ID) | |
1351 | bpl->tus.f.bdeSize = RNN_REQUEST_SZ; | |
92d7f7b0 JS |
1352 | else if (cmdcode == SLI_CTNS_RSPN_ID) |
1353 | bpl->tus.f.bdeSize = RSPN_REQUEST_SZ; | |
dea3101e JB |
1354 | else if (cmdcode == SLI_CTNS_RSNN_NN) |
1355 | bpl->tus.f.bdeSize = RSNN_REQUEST_SZ; | |
7ee5d43e JS |
1356 | else if (cmdcode == SLI_CTNS_DA_ID) |
1357 | bpl->tus.f.bdeSize = DA_ID_REQUEST_SZ; | |
2fb9bd8b JS |
1358 | else if (cmdcode == SLI_CTNS_RFF_ID) |
1359 | bpl->tus.f.bdeSize = RFF_REQUEST_SZ; | |
dea3101e JB |
1360 | else |
1361 | bpl->tus.f.bdeSize = 0; | |
1362 | bpl->tus.w = le32_to_cpu(bpl->tus.w); | |
1363 | ||
1364 | CtReq = (struct lpfc_sli_ct_request *) mp->virt; | |
4258e98e | 1365 | memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request)); |
dea3101e JB |
1366 | CtReq->RevisionId.bits.Revision = SLI_CT_REVISION; |
1367 | CtReq->RevisionId.bits.InId = 0; | |
1368 | CtReq->FsType = SLI_CT_DIRECTORY_SERVICE; | |
1369 | CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER; | |
1370 | CtReq->CommandResponse.bits.Size = 0; | |
1371 | switch (cmdcode) { | |
1372 | case SLI_CTNS_GID_FT: | |
1373 | CtReq->CommandResponse.bits.CmdRsp = | |
76b2c34a | 1374 | cpu_to_be16(SLI_CTNS_GID_FT); |
a0f2d3ef JS |
1375 | CtReq->un.gid.Fc4Type = context; |
1376 | ||
92d7f7b0 | 1377 | if (vport->port_state < LPFC_NS_QRY) |
2e0fef85 JS |
1378 | vport->port_state = LPFC_NS_QRY; |
1379 | lpfc_set_disctmo(vport); | |
dea3101e JB |
1380 | cmpl = lpfc_cmpl_ct_cmd_gid_ft; |
1381 | rsp_size = FC_MAX_NS_RSP; | |
1382 | break; | |
1383 | ||
92d7f7b0 JS |
1384 | case SLI_CTNS_GFF_ID: |
1385 | CtReq->CommandResponse.bits.CmdRsp = | |
76b2c34a | 1386 | cpu_to_be16(SLI_CTNS_GFF_ID); |
09372820 | 1387 | CtReq->un.gff.PortId = cpu_to_be32(context); |
92d7f7b0 JS |
1388 | cmpl = lpfc_cmpl_ct_cmd_gff_id; |
1389 | break; | |
1390 | ||
a0f2d3ef JS |
1391 | case SLI_CTNS_GFT_ID: |
1392 | CtReq->CommandResponse.bits.CmdRsp = | |
1393 | cpu_to_be16(SLI_CTNS_GFT_ID); | |
1394 | CtReq->un.gft.PortId = cpu_to_be32(context); | |
1395 | cmpl = lpfc_cmpl_ct_cmd_gft_id; | |
1396 | break; | |
1397 | ||
dea3101e | 1398 | case SLI_CTNS_RFT_ID: |
7ee5d43e | 1399 | vport->ct_flags &= ~FC_CT_RFT_ID; |
dea3101e | 1400 | CtReq->CommandResponse.bits.CmdRsp = |
76b2c34a | 1401 | cpu_to_be16(SLI_CTNS_RFT_ID); |
09372820 | 1402 | CtReq->un.rft.PortId = cpu_to_be32(vport->fc_myDID); |
a0f2d3ef JS |
1403 | |
1404 | /* Register FC4 FCP type if enabled. */ | |
1405 | if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || | |
1406 | (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) | |
1407 | CtReq->un.rft.fcpReg = 1; | |
1408 | ||
1409 | /* Register NVME type if enabled. Defined LE and swapped. | |
1410 | * rsvd[0] is used as word1 because of the hard-coded | |
1411 | * word0 usage in the ct_request data structure. | |
1412 | */ | |
1413 | if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || | |
1414 | (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) | |
1415 | CtReq->un.rft.rsvd[0] = cpu_to_be32(0x00000100); | |
1416 | ||
dea3101e JB |
1417 | cmpl = lpfc_cmpl_ct_cmd_rft_id; |
1418 | break; | |
1419 | ||
1420 | case SLI_CTNS_RNN_ID: | |
7ee5d43e | 1421 | vport->ct_flags &= ~FC_CT_RNN_ID; |
dea3101e | 1422 | CtReq->CommandResponse.bits.CmdRsp = |
76b2c34a | 1423 | cpu_to_be16(SLI_CTNS_RNN_ID); |
09372820 | 1424 | CtReq->un.rnn.PortId = cpu_to_be32(vport->fc_myDID); |
2e0fef85 | 1425 | memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename, |
4258e98e | 1426 | sizeof(struct lpfc_name)); |
dea3101e JB |
1427 | cmpl = lpfc_cmpl_ct_cmd_rnn_id; |
1428 | break; | |
1429 | ||
92d7f7b0 | 1430 | case SLI_CTNS_RSPN_ID: |
7ee5d43e | 1431 | vport->ct_flags &= ~FC_CT_RSPN_ID; |
92d7f7b0 | 1432 | CtReq->CommandResponse.bits.CmdRsp = |
76b2c34a | 1433 | cpu_to_be16(SLI_CTNS_RSPN_ID); |
09372820 | 1434 | CtReq->un.rspn.PortId = cpu_to_be32(vport->fc_myDID); |
92d7f7b0 JS |
1435 | size = sizeof(CtReq->un.rspn.symbname); |
1436 | CtReq->un.rspn.len = | |
1437 | lpfc_vport_symbolic_port_name(vport, | |
1438 | CtReq->un.rspn.symbname, size); | |
1439 | cmpl = lpfc_cmpl_ct_cmd_rspn_id; | |
1440 | break; | |
dea3101e | 1441 | case SLI_CTNS_RSNN_NN: |
7ee5d43e | 1442 | vport->ct_flags &= ~FC_CT_RSNN_NN; |
dea3101e | 1443 | CtReq->CommandResponse.bits.CmdRsp = |
76b2c34a | 1444 | cpu_to_be16(SLI_CTNS_RSNN_NN); |
2e0fef85 | 1445 | memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename, |
4258e98e | 1446 | sizeof(struct lpfc_name)); |
92d7f7b0 JS |
1447 | size = sizeof(CtReq->un.rsnn.symbname); |
1448 | CtReq->un.rsnn.len = | |
1449 | lpfc_vport_symbolic_node_name(vport, | |
1450 | CtReq->un.rsnn.symbname, size); | |
dea3101e JB |
1451 | cmpl = lpfc_cmpl_ct_cmd_rsnn_nn; |
1452 | break; | |
7ee5d43e JS |
1453 | case SLI_CTNS_DA_ID: |
1454 | /* Implement DA_ID Nameserver request */ | |
1455 | CtReq->CommandResponse.bits.CmdRsp = | |
76b2c34a | 1456 | cpu_to_be16(SLI_CTNS_DA_ID); |
09372820 | 1457 | CtReq->un.da_id.port_id = cpu_to_be32(vport->fc_myDID); |
7ee5d43e JS |
1458 | cmpl = lpfc_cmpl_ct_cmd_da_id; |
1459 | break; | |
92d7f7b0 | 1460 | case SLI_CTNS_RFF_ID: |
7ee5d43e | 1461 | vport->ct_flags &= ~FC_CT_RFF_ID; |
92d7f7b0 | 1462 | CtReq->CommandResponse.bits.CmdRsp = |
76b2c34a | 1463 | cpu_to_be16(SLI_CTNS_RFF_ID); |
a419aef8 | 1464 | CtReq->un.rff.PortId = cpu_to_be32(vport->fc_myDID); |
92d7f7b0 | 1465 | CtReq->un.rff.fbits = FC4_FEATURE_INIT; |
a0f2d3ef JS |
1466 | |
1467 | /* The driver always supports FC_TYPE_FCP. However, the | |
1468 | * caller can specify NVME (type x28) as well. But only | |
1469 | * these that FC4 type is supported. | |
1470 | */ | |
1471 | if (((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || | |
1472 | (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) && | |
1473 | (context == FC_TYPE_NVME)) { | |
8c258641 JS |
1474 | if ((vport == phba->pport) && phba->nvmet_support) { |
1475 | CtReq->un.rff.fbits = (FC4_FEATURE_TARGET | | |
1476 | FC4_FEATURE_NVME_DISC); | |
d613b6a7 | 1477 | lpfc_nvmet_update_targetport(phba); |
8c258641 JS |
1478 | } else { |
1479 | lpfc_nvme_update_localport(vport); | |
1480 | } | |
a0f2d3ef JS |
1481 | CtReq->un.rff.type_code = context; |
1482 | ||
1483 | } else if (((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) || | |
1484 | (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) && | |
1485 | (context == FC_TYPE_FCP)) | |
1486 | CtReq->un.rff.type_code = context; | |
1487 | ||
1488 | else | |
1489 | goto ns_cmd_free_bmpvirt; | |
1490 | ||
92d7f7b0 JS |
1491 | cmpl = lpfc_cmpl_ct_cmd_rff_id; |
1492 | break; | |
dea3101e | 1493 | } |
e47c9093 JS |
1494 | /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count |
1495 | * to hold ndlp reference for the corresponding callback function. | |
1496 | */ | |
858c9f6c | 1497 | if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) { |
dea3101e | 1498 | /* On success, The cmpl function will free the buffers */ |
858c9f6c JS |
1499 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, |
1500 | "Issue CT cmd: cmd:x%x did:x%x", | |
1501 | cmdcode, ndlp->nlp_DID, 0); | |
dea3101e | 1502 | return 0; |
858c9f6c | 1503 | } |
858c9f6c | 1504 | rc=6; |
e47c9093 JS |
1505 | |
1506 | /* Decrement ndlp reference count to release ndlp reference held | |
1507 | * for the failed command's callback function. | |
1508 | */ | |
51ef4c26 | 1509 | lpfc_nlp_put(ndlp); |
e47c9093 | 1510 | |
a0f2d3ef | 1511 | ns_cmd_free_bmpvirt: |
dea3101e JB |
1512 | lpfc_mbuf_free(phba, bmp->virt, bmp->phys); |
1513 | ns_cmd_free_bmp: | |
1514 | kfree(bmp); | |
1515 | ns_cmd_free_mpvirt: | |
1516 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
1517 | ns_cmd_free_mp: | |
1518 | kfree(mp); | |
1519 | ns_cmd_exit: | |
e8b62011 JS |
1520 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
1521 | "0266 Issue NameServer Req x%x err %d Data: x%x x%x\n", | |
1522 | cmdcode, rc, vport->fc_flag, vport->fc_rscn_id_cnt); | |
dea3101e JB |
1523 | return 1; |
1524 | } | |
1525 | ||
4258e98e JS |
1526 | /** |
1527 | * lpfc_cmpl_ct_disc_fdmi - Handle a discovery FDMI completion | |
1528 | * @phba: Pointer to HBA context object. | |
1529 | * @cmdiocb: Pointer to the command IOCBQ. | |
1530 | * @rspiocb: Pointer to the response IOCBQ. | |
1531 | * | |
1532 | * This function to handle the completion of a driver initiated FDMI | |
1533 | * CT command issued during discovery. | |
1534 | */ | |
dea3101e | 1535 | static void |
4258e98e JS |
1536 | lpfc_cmpl_ct_disc_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
1537 | struct lpfc_iocbq *rspiocb) | |
dea3101e | 1538 | { |
4258e98e | 1539 | struct lpfc_vport *vport = cmdiocb->vport; |
dea3101e JB |
1540 | struct lpfc_dmabuf *inp = cmdiocb->context1; |
1541 | struct lpfc_dmabuf *outp = cmdiocb->context2; | |
dea3101e | 1542 | struct lpfc_sli_ct_request *CTcmd = inp->virt; |
4258e98e | 1543 | struct lpfc_sli_ct_request *CTrsp = outp->virt; |
dea3101e JB |
1544 | uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp; |
1545 | uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp; | |
858c9f6c | 1546 | IOCB_t *irsp = &rspiocb->iocb; |
4258e98e JS |
1547 | struct lpfc_nodelist *ndlp; |
1548 | uint32_t latt, cmd, err; | |
858c9f6c JS |
1549 | |
1550 | latt = lpfc_els_chk_latt(vport); | |
858c9f6c JS |
1551 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT, |
1552 | "FDMI cmpl: status:x%x/x%x latt:%d", | |
1553 | irsp->ulpStatus, irsp->un.ulpWord[4], latt); | |
1554 | ||
1555 | if (latt || irsp->ulpStatus) { | |
4258e98e JS |
1556 | |
1557 | /* Look for a retryable error */ | |
1558 | if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) { | |
1559 | switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) { | |
1560 | case IOERR_SLI_ABORTED: | |
1561 | case IOERR_ABORT_IN_PROGRESS: | |
1562 | case IOERR_SEQUENCE_TIMEOUT: | |
1563 | case IOERR_ILLEGAL_FRAME: | |
1564 | case IOERR_NO_RESOURCES: | |
1565 | case IOERR_ILLEGAL_COMMAND: | |
1566 | cmdiocb->retry++; | |
1567 | if (cmdiocb->retry >= LPFC_FDMI_MAX_RETRY) | |
1568 | break; | |
1569 | ||
1570 | /* Retry the same FDMI command */ | |
1571 | err = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, | |
1572 | cmdiocb, 0); | |
1573 | if (err == IOCB_ERROR) | |
1574 | break; | |
1575 | return; | |
1576 | default: | |
1577 | break; | |
1578 | } | |
1579 | } | |
1580 | ||
e8b62011 JS |
1581 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
1582 | "0229 FDMI cmd %04x failed, latt = %d " | |
1583 | "ulpStatus: x%x, rid x%x\n", | |
1584 | be16_to_cpu(fdmi_cmd), latt, irsp->ulpStatus, | |
1585 | irsp->un.ulpWord[4]); | |
858c9f6c | 1586 | } |
4258e98e | 1587 | lpfc_ct_free_iocb(phba, cmdiocb); |
dea3101e | 1588 | |
2e0fef85 | 1589 | ndlp = lpfc_findnode_did(vport, FDMI_DID); |
e47c9093 | 1590 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
4258e98e | 1591 | return; |
e47c9093 | 1592 | |
4258e98e JS |
1593 | /* Check for a CT LS_RJT response */ |
1594 | cmd = be16_to_cpu(fdmi_cmd); | |
76b2c34a | 1595 | if (fdmi_rsp == cpu_to_be16(SLI_CT_RESPONSE_FS_RJT)) { |
dea3101e | 1596 | /* FDMI rsp failed */ |
e8b62011 | 1597 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
4258e98e JS |
1598 | "0220 FDMI cmd failed FS_RJT Data: x%x", cmd); |
1599 | ||
1600 | /* Should we fallback to FDMI-2 / FDMI-1 ? */ | |
1601 | switch (cmd) { | |
1602 | case SLI_MGMT_RHBA: | |
1603 | if (vport->fdmi_hba_mask == LPFC_FDMI2_HBA_ATTR) { | |
1604 | /* Fallback to FDMI-1 */ | |
1605 | vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR; | |
1606 | vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR; | |
1607 | /* Start over */ | |
1608 | lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0); | |
1609 | } | |
1610 | return; | |
1611 | ||
1612 | case SLI_MGMT_RPRT: | |
1613 | if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) { | |
1614 | /* Fallback to FDMI-1 */ | |
1615 | vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR; | |
1616 | /* Start over */ | |
1617 | lpfc_fdmi_cmd(vport, ndlp, cmd, 0); | |
1618 | } | |
1619 | if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) { | |
1620 | vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR; | |
1621 | /* Retry the same command */ | |
1622 | lpfc_fdmi_cmd(vport, ndlp, cmd, 0); | |
1623 | } | |
1624 | return; | |
1625 | ||
1626 | case SLI_MGMT_RPA: | |
1627 | if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) { | |
1628 | /* Fallback to FDMI-1 */ | |
1629 | vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR; | |
1630 | vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR; | |
1631 | /* Start over */ | |
1632 | lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0); | |
1633 | } | |
1634 | if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) { | |
1635 | vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR; | |
1636 | /* Retry the same command */ | |
1637 | lpfc_fdmi_cmd(vport, ndlp, cmd, 0); | |
1638 | } | |
1639 | return; | |
1640 | } | |
dea3101e JB |
1641 | } |
1642 | ||
4258e98e JS |
1643 | /* |
1644 | * On success, need to cycle thru FDMI registration for discovery | |
1645 | * DHBA -> DPRT -> RHBA -> RPA (physical port) | |
1646 | * DPRT -> RPRT (vports) | |
1647 | */ | |
1648 | switch (cmd) { | |
1649 | case SLI_MGMT_RHBA: | |
1650 | lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA, 0); | |
1651 | break; | |
1652 | ||
1653 | case SLI_MGMT_DHBA: | |
1654 | lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0); | |
1655 | break; | |
1656 | ||
1657 | case SLI_MGMT_DPRT: | |
1658 | if (vport->port_type == LPFC_PHYSICAL_PORT) | |
1659 | lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA, 0); | |
1660 | else | |
1661 | lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT, 0); | |
1662 | break; | |
1663 | } | |
1664 | return; | |
76b2c34a JS |
1665 | } |
1666 | ||
4258e98e JS |
1667 | |
1668 | /** | |
1669 | * lpfc_fdmi_num_disc_check - Check how many mapped NPorts we are connected to | |
1670 | * @vport: pointer to a host virtual N_Port data structure. | |
1671 | * | |
1672 | * Called from hbeat timeout routine to check if the number of discovered | |
1673 | * ports has changed. If so, re-register thar port Attribute. | |
1674 | */ | |
1675 | void | |
1676 | lpfc_fdmi_num_disc_check(struct lpfc_vport *vport) | |
76b2c34a | 1677 | { |
4258e98e | 1678 | struct lpfc_hba *phba = vport->phba; |
76b2c34a | 1679 | struct lpfc_nodelist *ndlp; |
4258e98e | 1680 | uint16_t cnt; |
76b2c34a | 1681 | |
4258e98e JS |
1682 | if (!lpfc_is_link_up(phba)) |
1683 | return; | |
1684 | ||
a03a4219 JS |
1685 | /* Must be connected to a Fabric */ |
1686 | if (!(vport->fc_flag & FC_FABRIC)) | |
1687 | return; | |
1688 | ||
4258e98e JS |
1689 | if (!(vport->fdmi_port_mask & LPFC_FDMI_PORT_ATTR_num_disc)) |
1690 | return; | |
1691 | ||
1692 | cnt = lpfc_find_map_node(vport); | |
1693 | if (cnt == vport->fdmi_num_disc) | |
1694 | return; | |
76b2c34a JS |
1695 | |
1696 | ndlp = lpfc_findnode_did(vport, FDMI_DID); | |
1697 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) | |
1698 | return; | |
1699 | ||
4258e98e JS |
1700 | if (vport->port_type == LPFC_PHYSICAL_PORT) { |
1701 | lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA, | |
1702 | LPFC_FDMI_PORT_ATTR_num_disc); | |
1703 | } else { | |
1704 | lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT, | |
1705 | LPFC_FDMI_PORT_ATTR_num_disc); | |
1706 | } | |
1707 | } | |
dea3101e | 1708 | |
4258e98e | 1709 | /* Routines for all individual HBA attributes */ |
bd4b3e5c | 1710 | static int |
4258e98e JS |
1711 | lpfc_fdmi_hba_attr_wwnn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) |
1712 | { | |
1713 | struct lpfc_fdmi_attr_entry *ae; | |
1714 | uint32_t size; | |
dea3101e | 1715 | |
4258e98e JS |
1716 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; |
1717 | memset(ae, 0, sizeof(struct lpfc_name)); | |
1718 | ||
1719 | memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName, | |
1720 | sizeof(struct lpfc_name)); | |
1721 | size = FOURBYTES + sizeof(struct lpfc_name); | |
1722 | ad->AttrLen = cpu_to_be16(size); | |
1723 | ad->AttrType = cpu_to_be16(RHBA_NODENAME); | |
1724 | return size; | |
1725 | } | |
bd4b3e5c | 1726 | static int |
4258e98e JS |
1727 | lpfc_fdmi_hba_attr_manufacturer(struct lpfc_vport *vport, |
1728 | struct lpfc_fdmi_attr_def *ad) | |
1729 | { | |
1730 | struct lpfc_fdmi_attr_entry *ae; | |
1731 | uint32_t len, size; | |
1732 | ||
1733 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; | |
1734 | memset(ae, 0, 256); | |
1735 | ||
1736 | strncpy(ae->un.AttrString, | |
1737 | "Emulex Corporation", | |
1738 | sizeof(ae->un.AttrString)); | |
1739 | len = strnlen(ae->un.AttrString, | |
1740 | sizeof(ae->un.AttrString)); | |
1741 | len += (len & 3) ? (4 - (len & 3)) : 4; | |
1742 | size = FOURBYTES + len; | |
1743 | ad->AttrLen = cpu_to_be16(size); | |
1744 | ad->AttrType = cpu_to_be16(RHBA_MANUFACTURER); | |
1745 | return size; | |
1746 | } | |
1747 | ||
bd4b3e5c | 1748 | static int |
4258e98e JS |
1749 | lpfc_fdmi_hba_attr_sn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) |
1750 | { | |
1751 | struct lpfc_hba *phba = vport->phba; | |
1752 | struct lpfc_fdmi_attr_entry *ae; | |
1753 | uint32_t len, size; | |
1754 | ||
1755 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; | |
1756 | memset(ae, 0, 256); | |
1757 | ||
1758 | strncpy(ae->un.AttrString, phba->SerialNumber, | |
1759 | sizeof(ae->un.AttrString)); | |
1760 | len = strnlen(ae->un.AttrString, | |
1761 | sizeof(ae->un.AttrString)); | |
1762 | len += (len & 3) ? (4 - (len & 3)) : 4; | |
1763 | size = FOURBYTES + len; | |
1764 | ad->AttrLen = cpu_to_be16(size); | |
1765 | ad->AttrType = cpu_to_be16(RHBA_SERIAL_NUMBER); | |
1766 | return size; | |
1767 | } | |
1768 | ||
bd4b3e5c | 1769 | static int |
4258e98e JS |
1770 | lpfc_fdmi_hba_attr_model(struct lpfc_vport *vport, |
1771 | struct lpfc_fdmi_attr_def *ad) | |
1772 | { | |
1773 | struct lpfc_hba *phba = vport->phba; | |
1774 | struct lpfc_fdmi_attr_entry *ae; | |
1775 | uint32_t len, size; | |
1776 | ||
1777 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; | |
1778 | memset(ae, 0, 256); | |
1779 | ||
1780 | strncpy(ae->un.AttrString, phba->ModelName, | |
1781 | sizeof(ae->un.AttrString)); | |
1782 | len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString)); | |
1783 | len += (len & 3) ? (4 - (len & 3)) : 4; | |
1784 | size = FOURBYTES + len; | |
1785 | ad->AttrLen = cpu_to_be16(size); | |
1786 | ad->AttrType = cpu_to_be16(RHBA_MODEL); | |
1787 | return size; | |
1788 | } | |
1789 | ||
bd4b3e5c | 1790 | static int |
4258e98e JS |
1791 | lpfc_fdmi_hba_attr_description(struct lpfc_vport *vport, |
1792 | struct lpfc_fdmi_attr_def *ad) | |
1793 | { | |
1794 | struct lpfc_hba *phba = vport->phba; | |
1795 | struct lpfc_fdmi_attr_entry *ae; | |
1796 | uint32_t len, size; | |
1797 | ||
1798 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; | |
1799 | memset(ae, 0, 256); | |
1800 | ||
1801 | strncpy(ae->un.AttrString, phba->ModelDesc, | |
1802 | sizeof(ae->un.AttrString)); | |
1803 | len = strnlen(ae->un.AttrString, | |
1804 | sizeof(ae->un.AttrString)); | |
1805 | len += (len & 3) ? (4 - (len & 3)) : 4; | |
1806 | size = FOURBYTES + len; | |
1807 | ad->AttrLen = cpu_to_be16(size); | |
1808 | ad->AttrType = cpu_to_be16(RHBA_MODEL_DESCRIPTION); | |
1809 | return size; | |
1810 | } | |
1811 | ||
bd4b3e5c | 1812 | static int |
4258e98e JS |
1813 | lpfc_fdmi_hba_attr_hdw_ver(struct lpfc_vport *vport, |
1814 | struct lpfc_fdmi_attr_def *ad) | |
1815 | { | |
1816 | struct lpfc_hba *phba = vport->phba; | |
1817 | lpfc_vpd_t *vp = &phba->vpd; | |
1818 | struct lpfc_fdmi_attr_entry *ae; | |
1819 | uint32_t i, j, incr, size; | |
1820 | ||
1821 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; | |
1822 | memset(ae, 0, 256); | |
1823 | ||
1824 | /* Convert JEDEC ID to ascii for hardware version */ | |
1825 | incr = vp->rev.biuRev; | |
1826 | for (i = 0; i < 8; i++) { | |
1827 | j = (incr & 0xf); | |
1828 | if (j <= 9) | |
1829 | ae->un.AttrString[7 - i] = | |
1830 | (char)((uint8_t) 0x30 + | |
1831 | (uint8_t) j); | |
1832 | else | |
1833 | ae->un.AttrString[7 - i] = | |
1834 | (char)((uint8_t) 0x61 + | |
1835 | (uint8_t) (j - 10)); | |
1836 | incr = (incr >> 4); | |
1837 | } | |
1838 | size = FOURBYTES + 8; | |
1839 | ad->AttrLen = cpu_to_be16(size); | |
1840 | ad->AttrType = cpu_to_be16(RHBA_HARDWARE_VERSION); | |
1841 | return size; | |
1842 | } | |
1843 | ||
bd4b3e5c | 1844 | static int |
4258e98e JS |
1845 | lpfc_fdmi_hba_attr_drvr_ver(struct lpfc_vport *vport, |
1846 | struct lpfc_fdmi_attr_def *ad) | |
1847 | { | |
1848 | struct lpfc_fdmi_attr_entry *ae; | |
1849 | uint32_t len, size; | |
1850 | ||
1851 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; | |
1852 | memset(ae, 0, 256); | |
1853 | ||
1854 | strncpy(ae->un.AttrString, lpfc_release_version, | |
1855 | sizeof(ae->un.AttrString)); | |
1856 | len = strnlen(ae->un.AttrString, | |
1857 | sizeof(ae->un.AttrString)); | |
1858 | len += (len & 3) ? (4 - (len & 3)) : 4; | |
1859 | size = FOURBYTES + len; | |
1860 | ad->AttrLen = cpu_to_be16(size); | |
1861 | ad->AttrType = cpu_to_be16(RHBA_DRIVER_VERSION); | |
1862 | return size; | |
1863 | } | |
1864 | ||
bd4b3e5c | 1865 | static int |
4258e98e JS |
1866 | lpfc_fdmi_hba_attr_rom_ver(struct lpfc_vport *vport, |
1867 | struct lpfc_fdmi_attr_def *ad) | |
1868 | { | |
1869 | struct lpfc_hba *phba = vport->phba; | |
1870 | struct lpfc_fdmi_attr_entry *ae; | |
1871 | uint32_t len, size; | |
1872 | ||
1873 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; | |
1874 | memset(ae, 0, 256); | |
1875 | ||
1876 | if (phba->sli_rev == LPFC_SLI_REV4) | |
1877 | lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1); | |
1878 | else | |
1879 | strncpy(ae->un.AttrString, phba->OptionROMVersion, | |
1880 | sizeof(ae->un.AttrString)); | |
1881 | len = strnlen(ae->un.AttrString, | |
1882 | sizeof(ae->un.AttrString)); | |
1883 | len += (len & 3) ? (4 - (len & 3)) : 4; | |
1884 | size = FOURBYTES + len; | |
1885 | ad->AttrLen = cpu_to_be16(size); | |
1886 | ad->AttrType = cpu_to_be16(RHBA_OPTION_ROM_VERSION); | |
1887 | return size; | |
1888 | } | |
1889 | ||
bd4b3e5c | 1890 | static int |
4258e98e JS |
1891 | lpfc_fdmi_hba_attr_fmw_ver(struct lpfc_vport *vport, |
1892 | struct lpfc_fdmi_attr_def *ad) | |
1893 | { | |
1894 | struct lpfc_hba *phba = vport->phba; | |
1895 | struct lpfc_fdmi_attr_entry *ae; | |
1896 | uint32_t len, size; | |
1897 | ||
1898 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; | |
1899 | memset(ae, 0, 256); | |
1900 | ||
1901 | lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1); | |
1902 | len = strnlen(ae->un.AttrString, | |
1903 | sizeof(ae->un.AttrString)); | |
1904 | len += (len & 3) ? (4 - (len & 3)) : 4; | |
1905 | size = FOURBYTES + len; | |
1906 | ad->AttrLen = cpu_to_be16(size); | |
1907 | ad->AttrType = cpu_to_be16(RHBA_FIRMWARE_VERSION); | |
1908 | return size; | |
1909 | } | |
1910 | ||
bd4b3e5c | 1911 | static int |
4258e98e JS |
1912 | lpfc_fdmi_hba_attr_os_ver(struct lpfc_vport *vport, |
1913 | struct lpfc_fdmi_attr_def *ad) | |
1914 | { | |
1915 | struct lpfc_fdmi_attr_entry *ae; | |
1916 | uint32_t len, size; | |
1917 | ||
1918 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; | |
1919 | memset(ae, 0, 256); | |
1920 | ||
1921 | snprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s %s %s", | |
1922 | init_utsname()->sysname, | |
1923 | init_utsname()->release, | |
1924 | init_utsname()->version); | |
1925 | ||
1926 | len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString)); | |
1927 | len += (len & 3) ? (4 - (len & 3)) : 4; | |
1928 | size = FOURBYTES + len; | |
1929 | ad->AttrLen = cpu_to_be16(size); | |
1930 | ad->AttrType = cpu_to_be16(RHBA_OS_NAME_VERSION); | |
1931 | return size; | |
1932 | } | |
1933 | ||
bd4b3e5c | 1934 | static int |
4258e98e JS |
1935 | lpfc_fdmi_hba_attr_ct_len(struct lpfc_vport *vport, |
1936 | struct lpfc_fdmi_attr_def *ad) | |
1937 | { | |
1938 | struct lpfc_fdmi_attr_entry *ae; | |
1939 | uint32_t size; | |
1940 | ||
1941 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; | |
1942 | ||
1943 | ae->un.AttrInt = cpu_to_be32(LPFC_MAX_CT_SIZE); | |
1944 | size = FOURBYTES + sizeof(uint32_t); | |
1945 | ad->AttrLen = cpu_to_be16(size); | |
1946 | ad->AttrType = cpu_to_be16(RHBA_MAX_CT_PAYLOAD_LEN); | |
1947 | return size; | |
1948 | } | |
1949 | ||
bd4b3e5c | 1950 | static int |
4258e98e JS |
1951 | lpfc_fdmi_hba_attr_symbolic_name(struct lpfc_vport *vport, |
1952 | struct lpfc_fdmi_attr_def *ad) | |
1953 | { | |
1954 | struct lpfc_fdmi_attr_entry *ae; | |
1955 | uint32_t len, size; | |
1956 | ||
1957 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; | |
1958 | memset(ae, 0, 256); | |
1959 | ||
1960 | len = lpfc_vport_symbolic_node_name(vport, | |
1961 | ae->un.AttrString, 256); | |
1962 | len += (len & 3) ? (4 - (len & 3)) : 4; | |
1963 | size = FOURBYTES + len; | |
1964 | ad->AttrLen = cpu_to_be16(size); | |
1965 | ad->AttrType = cpu_to_be16(RHBA_SYM_NODENAME); | |
1966 | return size; | |
1967 | } | |
1968 | ||
bd4b3e5c | 1969 | static int |
4258e98e JS |
1970 | lpfc_fdmi_hba_attr_vendor_info(struct lpfc_vport *vport, |
1971 | struct lpfc_fdmi_attr_def *ad) | |
1972 | { | |
1973 | struct lpfc_fdmi_attr_entry *ae; | |
1974 | uint32_t size; | |
1975 | ||
1976 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; | |
1977 | ||
1978 | /* Nothing is defined for this currently */ | |
1979 | ae->un.AttrInt = cpu_to_be32(0); | |
1980 | size = FOURBYTES + sizeof(uint32_t); | |
1981 | ad->AttrLen = cpu_to_be16(size); | |
1982 | ad->AttrType = cpu_to_be16(RHBA_VENDOR_INFO); | |
1983 | return size; | |
1984 | } | |
1985 | ||
bd4b3e5c | 1986 | static int |
4258e98e JS |
1987 | lpfc_fdmi_hba_attr_num_ports(struct lpfc_vport *vport, |
1988 | struct lpfc_fdmi_attr_def *ad) | |
1989 | { | |
1990 | struct lpfc_fdmi_attr_entry *ae; | |
1991 | uint32_t size; | |
1992 | ||
1993 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; | |
1994 | ||
1995 | /* Each driver instance corresponds to a single port */ | |
1996 | ae->un.AttrInt = cpu_to_be32(1); | |
1997 | size = FOURBYTES + sizeof(uint32_t); | |
1998 | ad->AttrLen = cpu_to_be16(size); | |
1999 | ad->AttrType = cpu_to_be16(RHBA_NUM_PORTS); | |
2000 | return size; | |
2001 | } | |
2002 | ||
bd4b3e5c | 2003 | static int |
4258e98e JS |
2004 | lpfc_fdmi_hba_attr_fabric_wwnn(struct lpfc_vport *vport, |
2005 | struct lpfc_fdmi_attr_def *ad) | |
2006 | { | |
2007 | struct lpfc_fdmi_attr_entry *ae; | |
2008 | uint32_t size; | |
2009 | ||
2010 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; | |
2011 | memset(ae, 0, sizeof(struct lpfc_name)); | |
2012 | ||
2013 | memcpy(&ae->un.AttrWWN, &vport->fabric_nodename, | |
2014 | sizeof(struct lpfc_name)); | |
2015 | size = FOURBYTES + sizeof(struct lpfc_name); | |
2016 | ad->AttrLen = cpu_to_be16(size); | |
2017 | ad->AttrType = cpu_to_be16(RHBA_FABRIC_WWNN); | |
2018 | return size; | |
2019 | } | |
2020 | ||
bd4b3e5c | 2021 | static int |
4258e98e JS |
2022 | lpfc_fdmi_hba_attr_bios_ver(struct lpfc_vport *vport, |
2023 | struct lpfc_fdmi_attr_def *ad) | |
2024 | { | |
2025 | struct lpfc_hba *phba = vport->phba; | |
2026 | struct lpfc_fdmi_attr_entry *ae; | |
2027 | uint32_t len, size; | |
2028 | ||
2029 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; | |
2030 | memset(ae, 0, 256); | |
2031 | ||
2032 | lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1); | |
2033 | len = strnlen(ae->un.AttrString, | |
2034 | sizeof(ae->un.AttrString)); | |
2035 | len += (len & 3) ? (4 - (len & 3)) : 4; | |
2036 | size = FOURBYTES + len; | |
2037 | ad->AttrLen = cpu_to_be16(size); | |
2038 | ad->AttrType = cpu_to_be16(RHBA_BIOS_VERSION); | |
2039 | return size; | |
2040 | } | |
2041 | ||
bd4b3e5c | 2042 | static int |
4258e98e JS |
2043 | lpfc_fdmi_hba_attr_bios_state(struct lpfc_vport *vport, |
2044 | struct lpfc_fdmi_attr_def *ad) | |
2045 | { | |
2046 | struct lpfc_fdmi_attr_entry *ae; | |
2047 | uint32_t size; | |
2048 | ||
2049 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; | |
2050 | ||
2051 | /* Driver doesn't have access to this information */ | |
2052 | ae->un.AttrInt = cpu_to_be32(0); | |
2053 | size = FOURBYTES + sizeof(uint32_t); | |
2054 | ad->AttrLen = cpu_to_be16(size); | |
2055 | ad->AttrType = cpu_to_be16(RHBA_BIOS_STATE); | |
2056 | return size; | |
2057 | } | |
2058 | ||
bd4b3e5c | 2059 | static int |
4258e98e JS |
2060 | lpfc_fdmi_hba_attr_vendor_id(struct lpfc_vport *vport, |
2061 | struct lpfc_fdmi_attr_def *ad) | |
2062 | { | |
2063 | struct lpfc_fdmi_attr_entry *ae; | |
2064 | uint32_t len, size; | |
2065 | ||
2066 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; | |
2067 | memset(ae, 0, 256); | |
2068 | ||
2069 | strncpy(ae->un.AttrString, "EMULEX", | |
2070 | sizeof(ae->un.AttrString)); | |
2071 | len = strnlen(ae->un.AttrString, | |
2072 | sizeof(ae->un.AttrString)); | |
2073 | len += (len & 3) ? (4 - (len & 3)) : 4; | |
2074 | size = FOURBYTES + len; | |
2075 | ad->AttrLen = cpu_to_be16(size); | |
2076 | ad->AttrType = cpu_to_be16(RHBA_VENDOR_ID); | |
2077 | return size; | |
2078 | } | |
2079 | ||
2080 | /* Routines for all individual PORT attributes */ | |
bd4b3e5c | 2081 | static int |
4258e98e JS |
2082 | lpfc_fdmi_port_attr_fc4type(struct lpfc_vport *vport, |
2083 | struct lpfc_fdmi_attr_def *ad) | |
2084 | { | |
2085 | struct lpfc_fdmi_attr_entry *ae; | |
2086 | uint32_t size; | |
2087 | ||
2088 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; | |
2089 | memset(ae, 0, 32); | |
2090 | ||
2091 | ae->un.AttrTypes[3] = 0x02; /* Type 1 - ELS */ | |
2092 | ae->un.AttrTypes[2] = 0x01; /* Type 8 - FCP */ | |
82820f0c | 2093 | ae->un.AttrTypes[6] = 0x01; /* Type 40 - NVME */ |
4258e98e JS |
2094 | ae->un.AttrTypes[7] = 0x01; /* Type 32 - CT */ |
2095 | size = FOURBYTES + 32; | |
2096 | ad->AttrLen = cpu_to_be16(size); | |
2097 | ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_FC4_TYPES); | |
2098 | return size; | |
2099 | } | |
2100 | ||
bd4b3e5c | 2101 | static int |
4258e98e JS |
2102 | lpfc_fdmi_port_attr_support_speed(struct lpfc_vport *vport, |
2103 | struct lpfc_fdmi_attr_def *ad) | |
2104 | { | |
2105 | struct lpfc_hba *phba = vport->phba; | |
2106 | struct lpfc_fdmi_attr_entry *ae; | |
2107 | uint32_t size; | |
2108 | ||
2109 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; | |
2110 | ||
2111 | ae->un.AttrInt = 0; | |
a085e87c JS |
2112 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
2113 | if (phba->lmt & LMT_32Gb) | |
2114 | ae->un.AttrInt |= HBA_PORTSPEED_32GFC; | |
2115 | if (phba->lmt & LMT_16Gb) | |
2116 | ae->un.AttrInt |= HBA_PORTSPEED_16GFC; | |
2117 | if (phba->lmt & LMT_10Gb) | |
2118 | ae->un.AttrInt |= HBA_PORTSPEED_10GFC; | |
2119 | if (phba->lmt & LMT_8Gb) | |
2120 | ae->un.AttrInt |= HBA_PORTSPEED_8GFC; | |
2121 | if (phba->lmt & LMT_4Gb) | |
2122 | ae->un.AttrInt |= HBA_PORTSPEED_4GFC; | |
2123 | if (phba->lmt & LMT_2Gb) | |
2124 | ae->un.AttrInt |= HBA_PORTSPEED_2GFC; | |
2125 | if (phba->lmt & LMT_1Gb) | |
2126 | ae->un.AttrInt |= HBA_PORTSPEED_1GFC; | |
2127 | } else { | |
2128 | /* FCoE links support only one speed */ | |
2129 | switch (phba->fc_linkspeed) { | |
2130 | case LPFC_ASYNC_LINK_SPEED_10GBPS: | |
2131 | ae->un.AttrInt = HBA_PORTSPEED_10GE; | |
2132 | break; | |
2133 | case LPFC_ASYNC_LINK_SPEED_25GBPS: | |
2134 | ae->un.AttrInt = HBA_PORTSPEED_25GE; | |
2135 | break; | |
2136 | case LPFC_ASYNC_LINK_SPEED_40GBPS: | |
2137 | ae->un.AttrInt = HBA_PORTSPEED_40GE; | |
2138 | break; | |
2139 | case LPFC_ASYNC_LINK_SPEED_100GBPS: | |
2140 | ae->un.AttrInt = HBA_PORTSPEED_100GE; | |
2141 | break; | |
2142 | } | |
2143 | } | |
4258e98e JS |
2144 | ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt); |
2145 | size = FOURBYTES + sizeof(uint32_t); | |
2146 | ad->AttrLen = cpu_to_be16(size); | |
2147 | ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_SPEED); | |
2148 | return size; | |
2149 | } | |
2150 | ||
bd4b3e5c | 2151 | static int |
4258e98e JS |
2152 | lpfc_fdmi_port_attr_speed(struct lpfc_vport *vport, |
2153 | struct lpfc_fdmi_attr_def *ad) | |
2154 | { | |
2155 | struct lpfc_hba *phba = vport->phba; | |
2156 | struct lpfc_fdmi_attr_entry *ae; | |
2157 | uint32_t size; | |
2158 | ||
2159 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; | |
2160 | ||
a085e87c JS |
2161 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
2162 | switch (phba->fc_linkspeed) { | |
2163 | case LPFC_LINK_SPEED_1GHZ: | |
2164 | ae->un.AttrInt = HBA_PORTSPEED_1GFC; | |
2165 | break; | |
2166 | case LPFC_LINK_SPEED_2GHZ: | |
2167 | ae->un.AttrInt = HBA_PORTSPEED_2GFC; | |
2168 | break; | |
2169 | case LPFC_LINK_SPEED_4GHZ: | |
2170 | ae->un.AttrInt = HBA_PORTSPEED_4GFC; | |
2171 | break; | |
2172 | case LPFC_LINK_SPEED_8GHZ: | |
2173 | ae->un.AttrInt = HBA_PORTSPEED_8GFC; | |
2174 | break; | |
2175 | case LPFC_LINK_SPEED_10GHZ: | |
2176 | ae->un.AttrInt = HBA_PORTSPEED_10GFC; | |
2177 | break; | |
2178 | case LPFC_LINK_SPEED_16GHZ: | |
2179 | ae->un.AttrInt = HBA_PORTSPEED_16GFC; | |
2180 | break; | |
2181 | case LPFC_LINK_SPEED_32GHZ: | |
2182 | ae->un.AttrInt = HBA_PORTSPEED_32GFC; | |
2183 | break; | |
2184 | default: | |
2185 | ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN; | |
2186 | break; | |
2187 | } | |
2188 | } else { | |
2189 | switch (phba->fc_linkspeed) { | |
2190 | case LPFC_ASYNC_LINK_SPEED_10GBPS: | |
2191 | ae->un.AttrInt = HBA_PORTSPEED_10GE; | |
2192 | break; | |
2193 | case LPFC_ASYNC_LINK_SPEED_25GBPS: | |
2194 | ae->un.AttrInt = HBA_PORTSPEED_25GE; | |
2195 | break; | |
2196 | case LPFC_ASYNC_LINK_SPEED_40GBPS: | |
2197 | ae->un.AttrInt = HBA_PORTSPEED_40GE; | |
2198 | break; | |
2199 | case LPFC_ASYNC_LINK_SPEED_100GBPS: | |
2200 | ae->un.AttrInt = HBA_PORTSPEED_100GE; | |
2201 | break; | |
2202 | default: | |
2203 | ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN; | |
2204 | break; | |
2205 | } | |
dea3101e | 2206 | } |
a085e87c | 2207 | |
4258e98e JS |
2208 | ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt); |
2209 | size = FOURBYTES + sizeof(uint32_t); | |
2210 | ad->AttrLen = cpu_to_be16(size); | |
2211 | ad->AttrType = cpu_to_be16(RPRT_PORT_SPEED); | |
2212 | return size; | |
2213 | } | |
2214 | ||
bd4b3e5c | 2215 | static int |
4258e98e JS |
2216 | lpfc_fdmi_port_attr_max_frame(struct lpfc_vport *vport, |
2217 | struct lpfc_fdmi_attr_def *ad) | |
2218 | { | |
2219 | struct serv_parm *hsp; | |
2220 | struct lpfc_fdmi_attr_entry *ae; | |
2221 | uint32_t size; | |
2222 | ||
2223 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; | |
2224 | ||
2225 | hsp = (struct serv_parm *)&vport->fc_sparam; | |
2226 | ae->un.AttrInt = (((uint32_t) hsp->cmn.bbRcvSizeMsb) << 8) | | |
2227 | (uint32_t) hsp->cmn.bbRcvSizeLsb; | |
2228 | ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt); | |
2229 | size = FOURBYTES + sizeof(uint32_t); | |
2230 | ad->AttrLen = cpu_to_be16(size); | |
2231 | ad->AttrType = cpu_to_be16(RPRT_MAX_FRAME_SIZE); | |
2232 | return size; | |
2233 | } | |
2234 | ||
bd4b3e5c | 2235 | static int |
4258e98e JS |
2236 | lpfc_fdmi_port_attr_os_devname(struct lpfc_vport *vport, |
2237 | struct lpfc_fdmi_attr_def *ad) | |
2238 | { | |
2239 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
2240 | struct lpfc_fdmi_attr_entry *ae; | |
2241 | uint32_t len, size; | |
2242 | ||
2243 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; | |
2244 | memset(ae, 0, 256); | |
2245 | ||
2246 | snprintf(ae->un.AttrString, sizeof(ae->un.AttrString), | |
2247 | "/sys/class/scsi_host/host%d", shost->host_no); | |
2248 | len = strnlen((char *)ae->un.AttrString, | |
2249 | sizeof(ae->un.AttrString)); | |
2250 | len += (len & 3) ? (4 - (len & 3)) : 4; | |
2251 | size = FOURBYTES + len; | |
2252 | ad->AttrLen = cpu_to_be16(size); | |
2253 | ad->AttrType = cpu_to_be16(RPRT_OS_DEVICE_NAME); | |
2254 | return size; | |
2255 | } | |
2256 | ||
bd4b3e5c | 2257 | static int |
4258e98e JS |
2258 | lpfc_fdmi_port_attr_host_name(struct lpfc_vport *vport, |
2259 | struct lpfc_fdmi_attr_def *ad) | |
2260 | { | |
2261 | struct lpfc_fdmi_attr_entry *ae; | |
2262 | uint32_t len, size; | |
2263 | ||
2264 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; | |
2265 | memset(ae, 0, 256); | |
2266 | ||
2267 | snprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s", | |
2268 | init_utsname()->nodename); | |
2269 | ||
2270 | len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString)); | |
2271 | len += (len & 3) ? (4 - (len & 3)) : 4; | |
2272 | size = FOURBYTES + len; | |
2273 | ad->AttrLen = cpu_to_be16(size); | |
2274 | ad->AttrType = cpu_to_be16(RPRT_HOST_NAME); | |
2275 | return size; | |
2276 | } | |
2277 | ||
bd4b3e5c | 2278 | static int |
4258e98e JS |
2279 | lpfc_fdmi_port_attr_wwnn(struct lpfc_vport *vport, |
2280 | struct lpfc_fdmi_attr_def *ad) | |
2281 | { | |
2282 | struct lpfc_fdmi_attr_entry *ae; | |
2283 | uint32_t size; | |
2284 | ||
2285 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; | |
2286 | memset(ae, 0, sizeof(struct lpfc_name)); | |
2287 | ||
2288 | memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName, | |
2289 | sizeof(struct lpfc_name)); | |
2290 | size = FOURBYTES + sizeof(struct lpfc_name); | |
2291 | ad->AttrLen = cpu_to_be16(size); | |
2292 | ad->AttrType = cpu_to_be16(RPRT_NODENAME); | |
2293 | return size; | |
2294 | } | |
2295 | ||
bd4b3e5c | 2296 | static int |
4258e98e JS |
2297 | lpfc_fdmi_port_attr_wwpn(struct lpfc_vport *vport, |
2298 | struct lpfc_fdmi_attr_def *ad) | |
2299 | { | |
2300 | struct lpfc_fdmi_attr_entry *ae; | |
2301 | uint32_t size; | |
2302 | ||
2303 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; | |
2304 | memset(ae, 0, sizeof(struct lpfc_name)); | |
2305 | ||
2306 | memcpy(&ae->un.AttrWWN, &vport->fc_sparam.portName, | |
2307 | sizeof(struct lpfc_name)); | |
2308 | size = FOURBYTES + sizeof(struct lpfc_name); | |
2309 | ad->AttrLen = cpu_to_be16(size); | |
2310 | ad->AttrType = cpu_to_be16(RPRT_PORTNAME); | |
2311 | return size; | |
2312 | } | |
2313 | ||
bd4b3e5c | 2314 | static int |
4258e98e JS |
2315 | lpfc_fdmi_port_attr_symbolic_name(struct lpfc_vport *vport, |
2316 | struct lpfc_fdmi_attr_def *ad) | |
2317 | { | |
2318 | struct lpfc_fdmi_attr_entry *ae; | |
2319 | uint32_t len, size; | |
2320 | ||
2321 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; | |
2322 | memset(ae, 0, 256); | |
2323 | ||
2324 | len = lpfc_vport_symbolic_port_name(vport, ae->un.AttrString, 256); | |
2325 | len += (len & 3) ? (4 - (len & 3)) : 4; | |
2326 | size = FOURBYTES + len; | |
2327 | ad->AttrLen = cpu_to_be16(size); | |
2328 | ad->AttrType = cpu_to_be16(RPRT_SYM_PORTNAME); | |
2329 | return size; | |
2330 | } | |
2331 | ||
bd4b3e5c | 2332 | static int |
4258e98e JS |
2333 | lpfc_fdmi_port_attr_port_type(struct lpfc_vport *vport, |
2334 | struct lpfc_fdmi_attr_def *ad) | |
2335 | { | |
2336 | struct lpfc_hba *phba = vport->phba; | |
2337 | struct lpfc_fdmi_attr_entry *ae; | |
2338 | uint32_t size; | |
2339 | ||
2340 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; | |
2341 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) | |
2342 | ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NLPORT); | |
2343 | else | |
2344 | ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NPORT); | |
2345 | size = FOURBYTES + sizeof(uint32_t); | |
2346 | ad->AttrLen = cpu_to_be16(size); | |
2347 | ad->AttrType = cpu_to_be16(RPRT_PORT_TYPE); | |
2348 | return size; | |
2349 | } | |
2350 | ||
bd4b3e5c | 2351 | static int |
4258e98e JS |
2352 | lpfc_fdmi_port_attr_class(struct lpfc_vport *vport, |
2353 | struct lpfc_fdmi_attr_def *ad) | |
2354 | { | |
2355 | struct lpfc_fdmi_attr_entry *ae; | |
2356 | uint32_t size; | |
2357 | ||
2358 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; | |
2359 | ae->un.AttrInt = cpu_to_be32(FC_COS_CLASS2 | FC_COS_CLASS3); | |
2360 | size = FOURBYTES + sizeof(uint32_t); | |
2361 | ad->AttrLen = cpu_to_be16(size); | |
2362 | ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_CLASS); | |
2363 | return size; | |
2364 | } | |
2365 | ||
bd4b3e5c | 2366 | static int |
4258e98e JS |
2367 | lpfc_fdmi_port_attr_fabric_wwpn(struct lpfc_vport *vport, |
2368 | struct lpfc_fdmi_attr_def *ad) | |
2369 | { | |
2370 | struct lpfc_fdmi_attr_entry *ae; | |
2371 | uint32_t size; | |
2372 | ||
2373 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; | |
2374 | memset(ae, 0, sizeof(struct lpfc_name)); | |
2375 | ||
2376 | memcpy(&ae->un.AttrWWN, &vport->fabric_portname, | |
2377 | sizeof(struct lpfc_name)); | |
2378 | size = FOURBYTES + sizeof(struct lpfc_name); | |
2379 | ad->AttrLen = cpu_to_be16(size); | |
2380 | ad->AttrType = cpu_to_be16(RPRT_FABRICNAME); | |
2381 | return size; | |
2382 | } | |
2383 | ||
bd4b3e5c | 2384 | static int |
4258e98e JS |
2385 | lpfc_fdmi_port_attr_active_fc4type(struct lpfc_vport *vport, |
2386 | struct lpfc_fdmi_attr_def *ad) | |
2387 | { | |
2388 | struct lpfc_fdmi_attr_entry *ae; | |
2389 | uint32_t size; | |
2390 | ||
2391 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; | |
2392 | memset(ae, 0, 32); | |
2393 | ||
2394 | ae->un.AttrTypes[3] = 0x02; /* Type 1 - ELS */ | |
2395 | ae->un.AttrTypes[2] = 0x01; /* Type 8 - FCP */ | |
2396 | ae->un.AttrTypes[7] = 0x01; /* Type 32 - CT */ | |
2397 | size = FOURBYTES + 32; | |
2398 | ad->AttrLen = cpu_to_be16(size); | |
2399 | ad->AttrType = cpu_to_be16(RPRT_ACTIVE_FC4_TYPES); | |
2400 | return size; | |
2401 | } | |
2402 | ||
bd4b3e5c | 2403 | static int |
4258e98e JS |
2404 | lpfc_fdmi_port_attr_port_state(struct lpfc_vport *vport, |
2405 | struct lpfc_fdmi_attr_def *ad) | |
2406 | { | |
2407 | struct lpfc_fdmi_attr_entry *ae; | |
2408 | uint32_t size; | |
2409 | ||
2410 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; | |
2411 | /* Link Up - operational */ | |
2412 | ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTSTATE_ONLINE); | |
2413 | size = FOURBYTES + sizeof(uint32_t); | |
2414 | ad->AttrLen = cpu_to_be16(size); | |
2415 | ad->AttrType = cpu_to_be16(RPRT_PORT_STATE); | |
2416 | return size; | |
2417 | } | |
2418 | ||
bd4b3e5c | 2419 | static int |
4258e98e JS |
2420 | lpfc_fdmi_port_attr_num_disc(struct lpfc_vport *vport, |
2421 | struct lpfc_fdmi_attr_def *ad) | |
2422 | { | |
2423 | struct lpfc_fdmi_attr_entry *ae; | |
2424 | uint32_t size; | |
2425 | ||
2426 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; | |
2427 | vport->fdmi_num_disc = lpfc_find_map_node(vport); | |
2428 | ae->un.AttrInt = cpu_to_be32(vport->fdmi_num_disc); | |
2429 | size = FOURBYTES + sizeof(uint32_t); | |
2430 | ad->AttrLen = cpu_to_be16(size); | |
2431 | ad->AttrType = cpu_to_be16(RPRT_DISC_PORT); | |
2432 | return size; | |
2433 | } | |
2434 | ||
bd4b3e5c | 2435 | static int |
4258e98e JS |
2436 | lpfc_fdmi_port_attr_nportid(struct lpfc_vport *vport, |
2437 | struct lpfc_fdmi_attr_def *ad) | |
2438 | { | |
2439 | struct lpfc_fdmi_attr_entry *ae; | |
2440 | uint32_t size; | |
2441 | ||
2442 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; | |
2443 | ae->un.AttrInt = cpu_to_be32(vport->fc_myDID); | |
2444 | size = FOURBYTES + sizeof(uint32_t); | |
2445 | ad->AttrLen = cpu_to_be16(size); | |
2446 | ad->AttrType = cpu_to_be16(RPRT_PORT_ID); | |
2447 | return size; | |
2448 | } | |
2449 | ||
bd4b3e5c | 2450 | static int |
4258e98e JS |
2451 | lpfc_fdmi_smart_attr_service(struct lpfc_vport *vport, |
2452 | struct lpfc_fdmi_attr_def *ad) | |
2453 | { | |
2454 | struct lpfc_fdmi_attr_entry *ae; | |
2455 | uint32_t len, size; | |
2456 | ||
2457 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; | |
2458 | memset(ae, 0, 256); | |
2459 | ||
2460 | strncpy(ae->un.AttrString, "Smart SAN Initiator", | |
2461 | sizeof(ae->un.AttrString)); | |
2462 | len = strnlen(ae->un.AttrString, | |
2463 | sizeof(ae->un.AttrString)); | |
2464 | len += (len & 3) ? (4 - (len & 3)) : 4; | |
2465 | size = FOURBYTES + len; | |
2466 | ad->AttrLen = cpu_to_be16(size); | |
2467 | ad->AttrType = cpu_to_be16(RPRT_SMART_SERVICE); | |
2468 | return size; | |
2469 | } | |
2470 | ||
bd4b3e5c | 2471 | static int |
4258e98e JS |
2472 | lpfc_fdmi_smart_attr_guid(struct lpfc_vport *vport, |
2473 | struct lpfc_fdmi_attr_def *ad) | |
2474 | { | |
2475 | struct lpfc_fdmi_attr_entry *ae; | |
2476 | uint32_t size; | |
2477 | ||
2478 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; | |
2479 | memset(ae, 0, 256); | |
2480 | ||
2481 | memcpy(&ae->un.AttrString, &vport->fc_sparam.nodeName, | |
2482 | sizeof(struct lpfc_name)); | |
2483 | memcpy((((uint8_t *)&ae->un.AttrString) + | |
2484 | sizeof(struct lpfc_name)), | |
2485 | &vport->fc_sparam.portName, sizeof(struct lpfc_name)); | |
2486 | size = FOURBYTES + (2 * sizeof(struct lpfc_name)); | |
2487 | ad->AttrLen = cpu_to_be16(size); | |
2488 | ad->AttrType = cpu_to_be16(RPRT_SMART_GUID); | |
2489 | return size; | |
2490 | } | |
2491 | ||
bd4b3e5c | 2492 | static int |
4258e98e JS |
2493 | lpfc_fdmi_smart_attr_version(struct lpfc_vport *vport, |
2494 | struct lpfc_fdmi_attr_def *ad) | |
2495 | { | |
2496 | struct lpfc_fdmi_attr_entry *ae; | |
2497 | uint32_t len, size; | |
2498 | ||
2499 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; | |
2500 | memset(ae, 0, 256); | |
2501 | ||
56204984 | 2502 | strncpy(ae->un.AttrString, "Smart SAN Version 2.0", |
4258e98e JS |
2503 | sizeof(ae->un.AttrString)); |
2504 | len = strnlen(ae->un.AttrString, | |
2505 | sizeof(ae->un.AttrString)); | |
2506 | len += (len & 3) ? (4 - (len & 3)) : 4; | |
2507 | size = FOURBYTES + len; | |
2508 | ad->AttrLen = cpu_to_be16(size); | |
2509 | ad->AttrType = cpu_to_be16(RPRT_SMART_VERSION); | |
2510 | return size; | |
2511 | } | |
2512 | ||
bd4b3e5c | 2513 | static int |
4258e98e JS |
2514 | lpfc_fdmi_smart_attr_model(struct lpfc_vport *vport, |
2515 | struct lpfc_fdmi_attr_def *ad) | |
2516 | { | |
2517 | struct lpfc_hba *phba = vport->phba; | |
2518 | struct lpfc_fdmi_attr_entry *ae; | |
2519 | uint32_t len, size; | |
2520 | ||
2521 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; | |
2522 | memset(ae, 0, 256); | |
2523 | ||
2524 | strncpy(ae->un.AttrString, phba->ModelName, | |
2525 | sizeof(ae->un.AttrString)); | |
2526 | len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString)); | |
2527 | len += (len & 3) ? (4 - (len & 3)) : 4; | |
2528 | size = FOURBYTES + len; | |
2529 | ad->AttrLen = cpu_to_be16(size); | |
2530 | ad->AttrType = cpu_to_be16(RPRT_SMART_MODEL); | |
2531 | return size; | |
2532 | } | |
2533 | ||
bd4b3e5c | 2534 | static int |
4258e98e JS |
2535 | lpfc_fdmi_smart_attr_port_info(struct lpfc_vport *vport, |
2536 | struct lpfc_fdmi_attr_def *ad) | |
2537 | { | |
2538 | struct lpfc_fdmi_attr_entry *ae; | |
2539 | uint32_t size; | |
2540 | ||
2541 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; | |
2542 | ||
2543 | /* SRIOV (type 3) is not supported */ | |
2544 | if (vport->vpi) | |
2545 | ae->un.AttrInt = cpu_to_be32(2); /* NPIV */ | |
2546 | else | |
2547 | ae->un.AttrInt = cpu_to_be32(1); /* Physical */ | |
2548 | size = FOURBYTES + sizeof(uint32_t); | |
2549 | ad->AttrLen = cpu_to_be16(size); | |
2550 | ad->AttrType = cpu_to_be16(RPRT_SMART_PORT_INFO); | |
2551 | return size; | |
2552 | } | |
2553 | ||
bd4b3e5c | 2554 | static int |
4258e98e JS |
2555 | lpfc_fdmi_smart_attr_qos(struct lpfc_vport *vport, |
2556 | struct lpfc_fdmi_attr_def *ad) | |
2557 | { | |
2558 | struct lpfc_fdmi_attr_entry *ae; | |
2559 | uint32_t size; | |
2560 | ||
2561 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; | |
2562 | ae->un.AttrInt = cpu_to_be32(0); | |
2563 | size = FOURBYTES + sizeof(uint32_t); | |
2564 | ad->AttrLen = cpu_to_be16(size); | |
2565 | ad->AttrType = cpu_to_be16(RPRT_SMART_QOS); | |
2566 | return size; | |
2567 | } | |
2568 | ||
bd4b3e5c | 2569 | static int |
4258e98e JS |
2570 | lpfc_fdmi_smart_attr_security(struct lpfc_vport *vport, |
2571 | struct lpfc_fdmi_attr_def *ad) | |
2572 | { | |
2573 | struct lpfc_fdmi_attr_entry *ae; | |
2574 | uint32_t size; | |
2575 | ||
2576 | ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue; | |
56204984 | 2577 | ae->un.AttrInt = cpu_to_be32(1); |
4258e98e JS |
2578 | size = FOURBYTES + sizeof(uint32_t); |
2579 | ad->AttrLen = cpu_to_be16(size); | |
2580 | ad->AttrType = cpu_to_be16(RPRT_SMART_SECURITY); | |
2581 | return size; | |
dea3101e | 2582 | } |
2e0fef85 | 2583 | |
4258e98e JS |
2584 | /* RHBA attribute jump table */ |
2585 | int (*lpfc_fdmi_hba_action[]) | |
2586 | (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = { | |
2587 | /* Action routine Mask bit Attribute type */ | |
2588 | lpfc_fdmi_hba_attr_wwnn, /* bit0 RHBA_NODENAME */ | |
2589 | lpfc_fdmi_hba_attr_manufacturer, /* bit1 RHBA_MANUFACTURER */ | |
2590 | lpfc_fdmi_hba_attr_sn, /* bit2 RHBA_SERIAL_NUMBER */ | |
2591 | lpfc_fdmi_hba_attr_model, /* bit3 RHBA_MODEL */ | |
2592 | lpfc_fdmi_hba_attr_description, /* bit4 RHBA_MODEL_DESCRIPTION */ | |
2593 | lpfc_fdmi_hba_attr_hdw_ver, /* bit5 RHBA_HARDWARE_VERSION */ | |
2594 | lpfc_fdmi_hba_attr_drvr_ver, /* bit6 RHBA_DRIVER_VERSION */ | |
2595 | lpfc_fdmi_hba_attr_rom_ver, /* bit7 RHBA_OPTION_ROM_VERSION */ | |
2596 | lpfc_fdmi_hba_attr_fmw_ver, /* bit8 RHBA_FIRMWARE_VERSION */ | |
2597 | lpfc_fdmi_hba_attr_os_ver, /* bit9 RHBA_OS_NAME_VERSION */ | |
2598 | lpfc_fdmi_hba_attr_ct_len, /* bit10 RHBA_MAX_CT_PAYLOAD_LEN */ | |
2599 | lpfc_fdmi_hba_attr_symbolic_name, /* bit11 RHBA_SYM_NODENAME */ | |
2600 | lpfc_fdmi_hba_attr_vendor_info, /* bit12 RHBA_VENDOR_INFO */ | |
2601 | lpfc_fdmi_hba_attr_num_ports, /* bit13 RHBA_NUM_PORTS */ | |
2602 | lpfc_fdmi_hba_attr_fabric_wwnn, /* bit14 RHBA_FABRIC_WWNN */ | |
2603 | lpfc_fdmi_hba_attr_bios_ver, /* bit15 RHBA_BIOS_VERSION */ | |
2604 | lpfc_fdmi_hba_attr_bios_state, /* bit16 RHBA_BIOS_STATE */ | |
2605 | lpfc_fdmi_hba_attr_vendor_id, /* bit17 RHBA_VENDOR_ID */ | |
2606 | }; | |
2607 | ||
2608 | /* RPA / RPRT attribute jump table */ | |
2609 | int (*lpfc_fdmi_port_action[]) | |
2610 | (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = { | |
2611 | /* Action routine Mask bit Attribute type */ | |
2612 | lpfc_fdmi_port_attr_fc4type, /* bit0 RPRT_SUPPORT_FC4_TYPES */ | |
2613 | lpfc_fdmi_port_attr_support_speed, /* bit1 RPRT_SUPPORTED_SPEED */ | |
2614 | lpfc_fdmi_port_attr_speed, /* bit2 RPRT_PORT_SPEED */ | |
2615 | lpfc_fdmi_port_attr_max_frame, /* bit3 RPRT_MAX_FRAME_SIZE */ | |
2616 | lpfc_fdmi_port_attr_os_devname, /* bit4 RPRT_OS_DEVICE_NAME */ | |
2617 | lpfc_fdmi_port_attr_host_name, /* bit5 RPRT_HOST_NAME */ | |
2618 | lpfc_fdmi_port_attr_wwnn, /* bit6 RPRT_NODENAME */ | |
2619 | lpfc_fdmi_port_attr_wwpn, /* bit7 RPRT_PORTNAME */ | |
2620 | lpfc_fdmi_port_attr_symbolic_name, /* bit8 RPRT_SYM_PORTNAME */ | |
2621 | lpfc_fdmi_port_attr_port_type, /* bit9 RPRT_PORT_TYPE */ | |
2622 | lpfc_fdmi_port_attr_class, /* bit10 RPRT_SUPPORTED_CLASS */ | |
2623 | lpfc_fdmi_port_attr_fabric_wwpn, /* bit11 RPRT_FABRICNAME */ | |
2624 | lpfc_fdmi_port_attr_active_fc4type, /* bit12 RPRT_ACTIVE_FC4_TYPES */ | |
2625 | lpfc_fdmi_port_attr_port_state, /* bit13 RPRT_PORT_STATE */ | |
2626 | lpfc_fdmi_port_attr_num_disc, /* bit14 RPRT_DISC_PORT */ | |
2627 | lpfc_fdmi_port_attr_nportid, /* bit15 RPRT_PORT_ID */ | |
2628 | lpfc_fdmi_smart_attr_service, /* bit16 RPRT_SMART_SERVICE */ | |
2629 | lpfc_fdmi_smart_attr_guid, /* bit17 RPRT_SMART_GUID */ | |
2630 | lpfc_fdmi_smart_attr_version, /* bit18 RPRT_SMART_VERSION */ | |
2631 | lpfc_fdmi_smart_attr_model, /* bit19 RPRT_SMART_MODEL */ | |
2632 | lpfc_fdmi_smart_attr_port_info, /* bit20 RPRT_SMART_PORT_INFO */ | |
2633 | lpfc_fdmi_smart_attr_qos, /* bit21 RPRT_SMART_QOS */ | |
2634 | lpfc_fdmi_smart_attr_security, /* bit22 RPRT_SMART_SECURITY */ | |
2635 | }; | |
76b2c34a | 2636 | |
4258e98e JS |
2637 | /** |
2638 | * lpfc_fdmi_cmd - Build and send a FDMI cmd to the specified NPort | |
2639 | * @vport: pointer to a host virtual N_Port data structure. | |
2640 | * @ndlp: ndlp to send FDMI cmd to (if NULL use FDMI_DID) | |
2641 | * cmdcode: FDMI command to send | |
2642 | * mask: Mask of HBA or PORT Attributes to send | |
2643 | * | |
2644 | * Builds and sends a FDMI command using the CT subsystem. | |
2645 | */ | |
dea3101e | 2646 | int |
4258e98e JS |
2647 | lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, |
2648 | int cmdcode, uint32_t new_mask) | |
dea3101e | 2649 | { |
2e0fef85 | 2650 | struct lpfc_hba *phba = vport->phba; |
dea3101e JB |
2651 | struct lpfc_dmabuf *mp, *bmp; |
2652 | struct lpfc_sli_ct_request *CtReq; | |
2653 | struct ulp_bde64 *bpl; | |
4258e98e | 2654 | uint32_t bit_pos; |
dea3101e | 2655 | uint32_t size; |
76b2c34a | 2656 | uint32_t rsp_size; |
4258e98e | 2657 | uint32_t mask; |
76b2c34a JS |
2658 | struct lpfc_fdmi_reg_hba *rh; |
2659 | struct lpfc_fdmi_port_entry *pe; | |
2660 | struct lpfc_fdmi_reg_portattr *pab = NULL; | |
2661 | struct lpfc_fdmi_attr_block *ab = NULL; | |
4258e98e JS |
2662 | int (*func)(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad); |
2663 | void (*cmpl)(struct lpfc_hba *, struct lpfc_iocbq *, | |
2664 | struct lpfc_iocbq *); | |
dea3101e | 2665 | |
4258e98e JS |
2666 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) |
2667 | return 0; | |
2668 | ||
2669 | cmpl = lpfc_cmpl_ct_disc_fdmi; /* called from discovery */ | |
dea3101e JB |
2670 | |
2671 | /* fill in BDEs for command */ | |
2672 | /* Allocate buffer for command payload */ | |
76b2c34a | 2673 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
dea3101e JB |
2674 | if (!mp) |
2675 | goto fdmi_cmd_exit; | |
2676 | ||
2677 | mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys)); | |
2678 | if (!mp->virt) | |
2679 | goto fdmi_cmd_free_mp; | |
2680 | ||
2681 | /* Allocate buffer for Buffer ptr list */ | |
76b2c34a | 2682 | bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
dea3101e JB |
2683 | if (!bmp) |
2684 | goto fdmi_cmd_free_mpvirt; | |
2685 | ||
2686 | bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys)); | |
2687 | if (!bmp->virt) | |
2688 | goto fdmi_cmd_free_bmp; | |
2689 | ||
2690 | INIT_LIST_HEAD(&mp->list); | |
2691 | INIT_LIST_HEAD(&bmp->list); | |
2692 | ||
2693 | /* FDMI request */ | |
e8b62011 JS |
2694 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
2695 | "0218 FDMI Request Data: x%x x%x x%x\n", | |
2696 | vport->fc_flag, vport->port_state, cmdcode); | |
76b2c34a | 2697 | CtReq = (struct lpfc_sli_ct_request *)mp->virt; |
dea3101e | 2698 | |
76b2c34a | 2699 | /* First populate the CT_IU preamble */ |
dea3101e JB |
2700 | memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request)); |
2701 | CtReq->RevisionId.bits.Revision = SLI_CT_REVISION; | |
2702 | CtReq->RevisionId.bits.InId = 0; | |
2703 | ||
2704 | CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE; | |
2705 | CtReq->FsSubType = SLI_CT_FDMI_Subtypes; | |
76b2c34a JS |
2706 | |
2707 | CtReq->CommandResponse.bits.CmdRsp = cpu_to_be16(cmdcode); | |
2708 | rsp_size = LPFC_BPL_SIZE; | |
dea3101e JB |
2709 | size = 0; |
2710 | ||
76b2c34a | 2711 | /* Next fill in the specific FDMI cmd information */ |
dea3101e | 2712 | switch (cmdcode) { |
76b2c34a | 2713 | case SLI_MGMT_RHAT: |
dea3101e | 2714 | case SLI_MGMT_RHBA: |
4258e98e JS |
2715 | rh = (struct lpfc_fdmi_reg_hba *)&CtReq->un.PortID; |
2716 | /* HBA Identifier */ | |
2717 | memcpy(&rh->hi.PortName, &phba->pport->fc_sparam.portName, | |
2718 | sizeof(struct lpfc_name)); | |
dea3101e | 2719 | |
4258e98e JS |
2720 | if (cmdcode == SLI_MGMT_RHBA) { |
2721 | /* Registered Port List */ | |
2722 | /* One entry (port) per adapter */ | |
2723 | rh->rpl.EntryCnt = cpu_to_be32(1); | |
2724 | memcpy(&rh->rpl.pe, &phba->pport->fc_sparam.portName, | |
76b2c34a JS |
2725 | sizeof(struct lpfc_name)); |
2726 | ||
4258e98e JS |
2727 | /* point to the HBA attribute block */ |
2728 | size = 2 * sizeof(struct lpfc_name) + | |
2729 | FOURBYTES; | |
2730 | } else { | |
2731 | size = sizeof(struct lpfc_name); | |
2732 | } | |
2733 | ab = (struct lpfc_fdmi_attr_block *)((uint8_t *)rh + size); | |
2734 | ab->EntryCnt = 0; | |
2735 | size += FOURBYTES; | |
2736 | bit_pos = 0; | |
2737 | if (new_mask) | |
2738 | mask = new_mask; | |
2739 | else | |
2740 | mask = vport->fdmi_hba_mask; | |
2741 | ||
2742 | /* Mask will dictate what attributes to build in the request */ | |
2743 | while (mask) { | |
2744 | if (mask & 0x1) { | |
2745 | func = lpfc_fdmi_hba_action[bit_pos]; | |
2746 | size += func(vport, | |
2747 | (struct lpfc_fdmi_attr_def *) | |
2748 | ((uint8_t *)rh + size)); | |
2749 | ab->EntryCnt++; | |
2750 | if ((size + 256) > | |
2751 | (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE)) | |
2752 | goto hba_out; | |
dea3101e | 2753 | } |
4258e98e JS |
2754 | mask = mask >> 1; |
2755 | bit_pos++; | |
dea3101e | 2756 | } |
4258e98e JS |
2757 | hba_out: |
2758 | ab->EntryCnt = cpu_to_be32(ab->EntryCnt); | |
2759 | /* Total size */ | |
2760 | size = GID_REQUEST_SZ - 4 + size; | |
dea3101e JB |
2761 | break; |
2762 | ||
76b2c34a | 2763 | case SLI_MGMT_RPRT: |
dea3101e | 2764 | case SLI_MGMT_RPA: |
4258e98e JS |
2765 | pab = (struct lpfc_fdmi_reg_portattr *)&CtReq->un.PortID; |
2766 | if (cmdcode == SLI_MGMT_RPRT) { | |
2767 | rh = (struct lpfc_fdmi_reg_hba *)pab; | |
2768 | /* HBA Identifier */ | |
2769 | memcpy(&rh->hi.PortName, | |
2770 | &phba->pport->fc_sparam.portName, | |
76b2c34a | 2771 | sizeof(struct lpfc_name)); |
4258e98e JS |
2772 | pab = (struct lpfc_fdmi_reg_portattr *) |
2773 | ((uint8_t *)pab + sizeof(struct lpfc_name)); | |
2774 | } | |
dea3101e | 2775 | |
4258e98e JS |
2776 | memcpy((uint8_t *)&pab->PortName, |
2777 | (uint8_t *)&vport->fc_sparam.portName, | |
2778 | sizeof(struct lpfc_name)); | |
2779 | size += sizeof(struct lpfc_name) + FOURBYTES; | |
2780 | pab->ab.EntryCnt = 0; | |
2781 | bit_pos = 0; | |
2782 | if (new_mask) | |
2783 | mask = new_mask; | |
2784 | else | |
2785 | mask = vport->fdmi_port_mask; | |
2786 | ||
2787 | /* Mask will dictate what attributes to build in the request */ | |
2788 | while (mask) { | |
2789 | if (mask & 0x1) { | |
2790 | func = lpfc_fdmi_port_action[bit_pos]; | |
2791 | size += func(vport, | |
2792 | (struct lpfc_fdmi_attr_def *) | |
2793 | ((uint8_t *)pab + size)); | |
2794 | pab->ab.EntryCnt++; | |
2795 | if ((size + 256) > | |
2796 | (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE)) | |
2797 | goto port_out; | |
2798 | } | |
2799 | mask = mask >> 1; | |
2800 | bit_pos++; | |
dea3101e | 2801 | } |
4258e98e JS |
2802 | port_out: |
2803 | pab->ab.EntryCnt = cpu_to_be32(pab->ab.EntryCnt); | |
2804 | /* Total size */ | |
2805 | if (cmdcode == SLI_MGMT_RPRT) | |
2806 | size += sizeof(struct lpfc_name); | |
2807 | size = GID_REQUEST_SZ - 4 + size; | |
dea3101e JB |
2808 | break; |
2809 | ||
76b2c34a JS |
2810 | case SLI_MGMT_GHAT: |
2811 | case SLI_MGMT_GRPL: | |
2812 | rsp_size = FC_MAX_NS_RSP; | |
dea3101e | 2813 | case SLI_MGMT_DHBA: |
76b2c34a JS |
2814 | case SLI_MGMT_DHAT: |
2815 | pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID; | |
2816 | memcpy((uint8_t *)&pe->PortName, | |
2817 | (uint8_t *)&vport->fc_sparam.portName, | |
2818 | sizeof(struct lpfc_name)); | |
2819 | size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name); | |
dea3101e JB |
2820 | break; |
2821 | ||
76b2c34a JS |
2822 | case SLI_MGMT_GPAT: |
2823 | case SLI_MGMT_GPAS: | |
2824 | rsp_size = FC_MAX_NS_RSP; | |
dea3101e | 2825 | case SLI_MGMT_DPRT: |
76b2c34a JS |
2826 | case SLI_MGMT_DPA: |
2827 | pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID; | |
2828 | memcpy((uint8_t *)&pe->PortName, | |
2829 | (uint8_t *)&vport->fc_sparam.portName, | |
2830 | sizeof(struct lpfc_name)); | |
2831 | size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name); | |
2832 | break; | |
2833 | case SLI_MGMT_GRHL: | |
2834 | size = GID_REQUEST_SZ - 4; | |
dea3101e | 2835 | break; |
76b2c34a JS |
2836 | default: |
2837 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY, | |
2838 | "0298 FDMI cmdcode x%x not supported\n", | |
2839 | cmdcode); | |
2840 | goto fdmi_cmd_free_bmpvirt; | |
dea3101e | 2841 | } |
76b2c34a | 2842 | CtReq->CommandResponse.bits.Size = cpu_to_be16(rsp_size); |
dea3101e | 2843 | |
76b2c34a JS |
2844 | bpl = (struct ulp_bde64 *)bmp->virt; |
2845 | bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys)); | |
2846 | bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys)); | |
dea3101e JB |
2847 | bpl->tus.f.bdeFlags = 0; |
2848 | bpl->tus.f.bdeSize = size; | |
dea3101e | 2849 | |
76b2c34a JS |
2850 | /* |
2851 | * The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count | |
e47c9093 JS |
2852 | * to hold ndlp reference for the corresponding callback function. |
2853 | */ | |
76b2c34a | 2854 | if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, 0)) |
dea3101e JB |
2855 | return 0; |
2856 | ||
76b2c34a JS |
2857 | /* |
2858 | * Decrement ndlp reference count to release ndlp reference held | |
e47c9093 JS |
2859 | * for the failed command's callback function. |
2860 | */ | |
51ef4c26 | 2861 | lpfc_nlp_put(ndlp); |
e47c9093 | 2862 | |
76b2c34a | 2863 | fdmi_cmd_free_bmpvirt: |
dea3101e JB |
2864 | lpfc_mbuf_free(phba, bmp->virt, bmp->phys); |
2865 | fdmi_cmd_free_bmp: | |
2866 | kfree(bmp); | |
2867 | fdmi_cmd_free_mpvirt: | |
2868 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
2869 | fdmi_cmd_free_mp: | |
2870 | kfree(mp); | |
2871 | fdmi_cmd_exit: | |
2872 | /* Issue FDMI request failed */ | |
e8b62011 JS |
2873 | lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, |
2874 | "0244 Issue FDMI request failed Data: x%x\n", | |
2875 | cmdcode); | |
dea3101e JB |
2876 | return 1; |
2877 | } | |
2878 | ||
92494144 JS |
2879 | /** |
2880 | * lpfc_delayed_disc_tmo - Timeout handler for delayed discovery timer. | |
2881 | * @ptr - Context object of the timer. | |
2882 | * | |
2883 | * This function set the WORKER_DELAYED_DISC_TMO flag and wake up | |
2884 | * the worker thread. | |
2885 | **/ | |
2886 | void | |
2887 | lpfc_delayed_disc_tmo(unsigned long ptr) | |
2888 | { | |
2889 | struct lpfc_vport *vport = (struct lpfc_vport *)ptr; | |
2890 | struct lpfc_hba *phba = vport->phba; | |
2891 | uint32_t tmo_posted; | |
2892 | unsigned long iflag; | |
2893 | ||
2894 | spin_lock_irqsave(&vport->work_port_lock, iflag); | |
2895 | tmo_posted = vport->work_port_events & WORKER_DELAYED_DISC_TMO; | |
2896 | if (!tmo_posted) | |
2897 | vport->work_port_events |= WORKER_DELAYED_DISC_TMO; | |
2898 | spin_unlock_irqrestore(&vport->work_port_lock, iflag); | |
2899 | ||
2900 | if (!tmo_posted) | |
2901 | lpfc_worker_wake_up(phba); | |
2902 | return; | |
2903 | } | |
2904 | ||
2905 | /** | |
2906 | * lpfc_delayed_disc_timeout_handler - Function called by worker thread to | |
2907 | * handle delayed discovery. | |
2908 | * @vport: pointer to a host virtual N_Port data structure. | |
2909 | * | |
2910 | * This function start nport discovery of the vport. | |
2911 | **/ | |
2912 | void | |
2913 | lpfc_delayed_disc_timeout_handler(struct lpfc_vport *vport) | |
2914 | { | |
2915 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
2916 | ||
2917 | spin_lock_irq(shost->host_lock); | |
2918 | if (!(vport->fc_flag & FC_DISC_DELAYED)) { | |
2919 | spin_unlock_irq(shost->host_lock); | |
2920 | return; | |
2921 | } | |
2922 | vport->fc_flag &= ~FC_DISC_DELAYED; | |
2923 | spin_unlock_irq(shost->host_lock); | |
2924 | ||
2925 | lpfc_do_scr_ns_plogi(vport->phba, vport); | |
2926 | } | |
2927 | ||
dea3101e | 2928 | void |
2e0fef85 | 2929 | lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag) |
dea3101e JB |
2930 | { |
2931 | struct lpfc_sli *psli = &phba->sli; | |
2932 | lpfc_vpd_t *vp = &phba->vpd; | |
2933 | uint32_t b1, b2, b3, b4, i, rev; | |
2934 | char c; | |
2935 | uint32_t *ptr, str[4]; | |
2936 | uint8_t *fwname; | |
2937 | ||
f1126688 | 2938 | if (phba->sli_rev == LPFC_SLI_REV4) |
6b5151fd | 2939 | snprintf(fwrevision, FW_REV_STR_SIZE, "%s", vp->rev.opFwName); |
f1126688 | 2940 | else if (vp->rev.rBit) { |
f4b4c68f | 2941 | if (psli->sli_flag & LPFC_SLI_ACTIVE) |
dea3101e JB |
2942 | rev = vp->rev.sli2FwRev; |
2943 | else | |
2944 | rev = vp->rev.sli1FwRev; | |
2945 | ||
2946 | b1 = (rev & 0x0000f000) >> 12; | |
2947 | b2 = (rev & 0x00000f00) >> 8; | |
2948 | b3 = (rev & 0x000000c0) >> 6; | |
2949 | b4 = (rev & 0x00000030) >> 4; | |
2950 | ||
2951 | switch (b4) { | |
2952 | case 0: | |
2953 | c = 'N'; | |
2954 | break; | |
2955 | case 1: | |
2956 | c = 'A'; | |
2957 | break; | |
2958 | case 2: | |
2959 | c = 'B'; | |
2960 | break; | |
73d91e50 JS |
2961 | case 3: |
2962 | c = 'X'; | |
2963 | break; | |
dea3101e JB |
2964 | default: |
2965 | c = 0; | |
2966 | break; | |
2967 | } | |
2968 | b4 = (rev & 0x0000000f); | |
2969 | ||
f4b4c68f | 2970 | if (psli->sli_flag & LPFC_SLI_ACTIVE) |
dea3101e JB |
2971 | fwname = vp->rev.sli2FwName; |
2972 | else | |
2973 | fwname = vp->rev.sli1FwName; | |
2974 | ||
2975 | for (i = 0; i < 16; i++) | |
2976 | if (fwname[i] == 0x20) | |
2977 | fwname[i] = 0; | |
2978 | ||
2979 | ptr = (uint32_t*)fwname; | |
2980 | ||
2981 | for (i = 0; i < 3; i++) | |
2982 | str[i] = be32_to_cpu(*ptr++); | |
2983 | ||
2984 | if (c == 0) { | |
2985 | if (flag) | |
2986 | sprintf(fwrevision, "%d.%d%d (%s)", | |
2987 | b1, b2, b3, (char *)str); | |
2988 | else | |
2989 | sprintf(fwrevision, "%d.%d%d", b1, | |
2990 | b2, b3); | |
2991 | } else { | |
2992 | if (flag) | |
2993 | sprintf(fwrevision, "%d.%d%d%c%d (%s)", | |
2994 | b1, b2, b3, c, | |
2995 | b4, (char *)str); | |
2996 | else | |
2997 | sprintf(fwrevision, "%d.%d%d%c%d", | |
2998 | b1, b2, b3, c, b4); | |
2999 | } | |
3000 | } else { | |
3001 | rev = vp->rev.smFwRev; | |
3002 | ||
3003 | b1 = (rev & 0xff000000) >> 24; | |
3004 | b2 = (rev & 0x00f00000) >> 20; | |
3005 | b3 = (rev & 0x000f0000) >> 16; | |
3006 | c = (rev & 0x0000ff00) >> 8; | |
3007 | b4 = (rev & 0x000000ff); | |
3008 | ||
d44a6d2b | 3009 | sprintf(fwrevision, "%d.%d%d%c%d", b1, b2, b3, c, b4); |
dea3101e JB |
3010 | } |
3011 | return; | |
3012 | } |