1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#include <linux/blkdev.h>
28#include <linux/pci.h>
29#include <linux/interrupt.h>
30#include <linux/slab.h>
31#include <linux/utsname.h>
32
33#include <scsi/scsi.h>
34#include <scsi/scsi_device.h>
35#include <scsi/scsi_host.h>
36#include <scsi/scsi_transport_fc.h>
37#include <scsi/fc/fc_fs.h>
38
39#include "lpfc_hw4.h"
40#include "lpfc_hw.h"
41#include "lpfc_sli.h"
42#include "lpfc_sli4.h"
43#include "lpfc_nl.h"
44#include "lpfc_disc.h"
45#include "lpfc.h"
46#include "lpfc_scsi.h"
47#include "lpfc_nvme.h"
48#include "lpfc_logmsg.h"
49#include "lpfc_crtn.h"
50#include "lpfc_version.h"
51#include "lpfc_vport.h"
52#include "lpfc_debugfs.h"
53
54
55#define HBA_PORTSPEED_1GFC 0x00000001
56#define HBA_PORTSPEED_2GFC 0x00000002
57#define HBA_PORTSPEED_4GFC 0x00000008
58#define HBA_PORTSPEED_10GFC 0x00000004
59#define HBA_PORTSPEED_8GFC 0x00000010
60#define HBA_PORTSPEED_16GFC 0x00000020
61#define HBA_PORTSPEED_32GFC 0x00000040
62#define HBA_PORTSPEED_20GFC 0x00000080
63#define HBA_PORTSPEED_40GFC 0x00000100
64#define HBA_PORTSPEED_128GFC 0x00000200
65#define HBA_PORTSPEED_64GFC 0x00000400
66#define HBA_PORTSPEED_256GFC 0x00000800
67#define HBA_PORTSPEED_UNKNOWN 0x00008000
68#define HBA_PORTSPEED_10GE 0x00010000
69#define HBA_PORTSPEED_40GE 0x00020000
70#define HBA_PORTSPEED_100GE 0x00040000
71#define HBA_PORTSPEED_25GE 0x00080000
72#define HBA_PORTSPEED_50GE 0x00100000
73#define HBA_PORTSPEED_400GE 0x00200000
74
75#define FOURBYTES 4
76
77
78static char *lpfc_release_version = LPFC_DRIVER_VERSION;
79
80static void
81lpfc_ct_ignore_hbq_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
82 struct lpfc_dmabuf *mp, uint32_t size)
83{
84 if (!mp) {
85 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
86 "0146 Ignoring unsolicited CT No HBQ "
87 "status = x%x\n",
88 piocbq->iocb.ulpStatus);
89 }
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);
94}
95
96static void
97lpfc_ct_unsol_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
98 struct lpfc_dmabuf *mp, uint32_t size)
99{
100 lpfc_ct_ignore_hbq_buffer(phba, piocbq, mp, size);
101}
102
103void
104lpfc_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
105 struct lpfc_iocbq *piocbq)
106{
107 struct lpfc_dmabuf *mp = NULL;
108 IOCB_t *icmd = &piocbq->iocb;
109 int i;
110 struct lpfc_iocbq *iocbq;
111 dma_addr_t paddr;
112 uint32_t size;
113 struct list_head head;
114 struct lpfc_dmabuf *bdeBuf;
115
116 if (lpfc_bsg_ct_unsol_event(phba, pring, piocbq) == 0)
117 return;
118
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) &&
122 ((icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
123 IOERR_RCV_BUFFER_WAITING)) {
124
125 phba->fc_stat.NoRcvBuf++;
126 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
127 lpfc_post_buffer(phba, pring, 2);
128 return;
129 }
130
131
132
133
134 if (icmd->ulpBdeCount == 0)
135 return;
136
137 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
138 INIT_LIST_HEAD(&head);
139 list_add_tail(&head, &piocbq->list);
140 list_for_each_entry(iocbq, &head, list) {
141 icmd = &iocbq->iocb;
142 if (icmd->ulpBdeCount == 0)
143 continue;
144 bdeBuf = iocbq->context2;
145 iocbq->context2 = NULL;
146 size = icmd->un.cont64[0].tus.f.bdeSize;
147 lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf, size);
148 lpfc_in_buf_free(phba, bdeBuf);
149 if (icmd->ulpBdeCount == 2) {
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);
156 }
157 }
158 list_del(&head);
159 } else {
160 INIT_LIST_HEAD(&head);
161 list_add_tail(&head, &piocbq->list);
162 list_for_each_entry(iocbq, &head, list) {
163 icmd = &iocbq->iocb;
164 if (icmd->ulpBdeCount == 0)
165 lpfc_ct_unsol_buffer(phba, iocbq, NULL, 0);
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;
172 lpfc_ct_unsol_buffer(phba, iocbq, mp, size);
173 lpfc_in_buf_free(phba, mp);
174 }
175 lpfc_post_buffer(phba, pring, i);
176 }
177 list_del(&head);
178 }
179}
180
181
182
183
184
185
186
187
188
189
190
191int
192lpfc_ct_handle_unsol_abort(struct lpfc_hba *phba, struct hbq_dmabuf *dmabuf)
193{
194 int handled;
195
196
197 handled = lpfc_bsg_ct_unsol_abort(phba, dmabuf);
198
199 return handled;
200}
201
202static void
203lpfc_free_ct_rsp(struct lpfc_hba *phba, struct lpfc_dmabuf *mlist)
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
217static struct lpfc_dmabuf *
218lpfc_alloc_ct_rsp(struct lpfc_hba *phba, int cmdcode, struct ulp_bde64 *bpl,
219 uint32_t size, int *entries)
220{
221 struct lpfc_dmabuf *mlist = NULL;
222 struct lpfc_dmabuf *mp;
223 int cnt, i = 0;
224
225
226 cnt = size > FCELSSIZE ? FCELSSIZE: size;
227
228 while (size) {
229
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
239 if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT) ||
240 cmdcode == be16_to_cpu(SLI_CTNS_GFF_ID))
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);
247 if (mlist)
248 lpfc_free_ct_rsp(phba, mlist);
249 return NULL;
250 }
251
252
253 if (!mlist)
254 mlist = mp;
255 else
256 list_add_tail(&mp->list, &mlist->list);
257
258 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
259
260 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
261 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
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
274int
275lpfc_ct_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *ctiocb)
276{
277 struct lpfc_dmabuf *buf_ptr;
278
279 if (ctiocb->context_un.ndlp) {
280 lpfc_nlp_put(ctiocb->context_un.ndlp);
281 ctiocb->context_un.ndlp = NULL;
282 }
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);
298 ctiocb->context3 = NULL;
299 }
300 lpfc_sli_release_iocbq(phba, ctiocb);
301 return 0;
302}
303
304
305
306
307
308
309
310
311
312
313
314
315static int
316lpfc_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp,
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,
321 uint32_t tmo, uint8_t retry)
322{
323 struct lpfc_hba *phba = vport->phba;
324 IOCB_t *icmd;
325 struct lpfc_iocbq *geniocb;
326 int rc;
327
328
329 geniocb = lpfc_sli_get_iocbq(phba);
330
331 if (geniocb == NULL)
332 return 1;
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);
338 icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
339 icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof(struct ulp_bde64));
340
341 if (usr_flg)
342 geniocb->context3 = NULL;
343 else
344 geniocb->context3 = (uint8_t *) bmp;
345
346
347 geniocb->context1 = (uint8_t *) inp;
348 geniocb->context2 = (uint8_t *) outp;
349 geniocb->context_un.ndlp = lpfc_nlp_get(ndlp);
350
351
352 icmd->ulpCommand = CMD_GEN_REQUEST64_CR;
353
354
355 icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
356 icmd->un.genreq64.w5.hcsw.Dfctl = 0;
357 icmd->un.genreq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CTL;
358 icmd->un.genreq64.w5.hcsw.Type = FC_TYPE_CT;
359
360 if (!tmo) {
361
362 tmo = (3 * phba->fc_ratov);
363 }
364 icmd->ulpTimeout = tmo;
365 icmd->ulpBdeCount = 1;
366 icmd->ulpLe = 1;
367 icmd->ulpClass = CLASS3;
368 icmd->ulpContext = ndlp->nlp_rpi;
369 if (phba->sli_rev == LPFC_SLI_REV4)
370 icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
371
372 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
373
374 icmd->ulpCt_h = 0;
375 icmd->ulpCt_l = 0;
376 }
377
378
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);
384 geniocb->iocb_cmpl = cmpl;
385 geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
386 geniocb->vport = vport;
387 geniocb->retry = retry;
388 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, geniocb, 0);
389
390 if (rc == IOCB_ERROR) {
391 lpfc_sli_release_iocbq(phba, geniocb);
392 return 1;
393 }
394
395 return 0;
396}
397
398
399
400
401
402
403
404
405
406
407
408static int
409lpfc_ct_cmd(struct lpfc_vport *vport, struct lpfc_dmabuf *inmp,
410 struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
411 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
412 struct lpfc_iocbq *),
413 uint32_t rsp_size, uint8_t retry)
414{
415 struct lpfc_hba *phba = vport->phba;
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++;
423
424
425 outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
426 if (!outmp)
427 return -ENOMEM;
428
429
430
431
432
433 cnt += 1;
434 status = lpfc_gen_req(vport, bmp, inmp, outmp, cmpl, ndlp, 0,
435 cnt, 0, retry);
436 if (status) {
437 lpfc_free_ct_rsp(phba, outmp);
438 return -ENOMEM;
439 }
440 return 0;
441}
442
443struct lpfc_vport *
444lpfc_find_vport_by_did(struct lpfc_hba *phba, uint32_t did) {
445 struct lpfc_vport *vport_curr;
446 unsigned long flags;
447
448 spin_lock_irqsave(&phba->port_list_lock, flags);
449 list_for_each_entry(vport_curr, &phba->port_list, listentry) {
450 if ((vport_curr->fc_myDID) && (vport_curr->fc_myDID == did)) {
451 spin_unlock_irqrestore(&phba->port_list_lock, flags);
452 return vport_curr;
453 }
454 }
455 spin_unlock_irqrestore(&phba->port_list_lock, flags);
456 return NULL;
457}
458
459static void
460lpfc_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)) {
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
474
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);
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
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);
497 }
498 } else {
499 if (!(vport->fc_flag & FC_RSCN_MODE) ||
500 lpfc_rscn_payload_check(vport, Did)) {
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
505
506
507
508
509 ndlp = lpfc_findnode_did(vport, Did);
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);
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
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);
533 }
534 }
535}
536
537static void
538lpfc_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 char *str;
544
545 if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_FT)
546 str = "GID_FT";
547 else
548 str = "GID_PT";
549 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
550 "6430 Process %s rsp for %08x type %x %s %s\n",
551 str, Did, fc4_type,
552 (fc4_type == FC_TYPE_FCP) ? "FCP" : " ",
553 (fc4_type == FC_TYPE_NVME) ? "NVME" : " ");
554
555
556
557
558 if (Did != vport->fc_myDID &&
559 (!lpfc_find_vport_by_did(phba, Did) ||
560 vport->cfg_peer_port_login)) {
561 if (!phba->nvmet_support) {
562
563 lpfc_prep_node_fc4type(vport, Did, fc4_type);
564 return;
565 }
566
567 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
568 if (ndlp->nlp_type != NLP_NVME_INITIATOR ||
569 ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
570 continue;
571 spin_lock_irq(shost->host_lock);
572 if (ndlp->nlp_DID == Did)
573 ndlp->nlp_flag &= ~NLP_NVMET_RECOV;
574 else
575 ndlp->nlp_flag |= NLP_NVMET_RECOV;
576 spin_unlock_irq(shost->host_lock);
577 }
578 }
579}
580
581static int
582lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint8_t fc4_type,
583 uint32_t Size)
584{
585 struct lpfc_sli_ct_request *Response =
586 (struct lpfc_sli_ct_request *) mp->virt;
587 struct lpfc_dmabuf *mlast, *next_mp;
588 uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
589 uint32_t Did, CTentry;
590 int Cnt;
591 struct list_head head;
592 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
593 struct lpfc_nodelist *ndlp = NULL;
594
595 lpfc_set_disctmo(vport);
596 vport->num_disc_nodes = 0;
597 vport->fc_ns_retry = 0;
598
599
600 list_add_tail(&head, &mp->list);
601 list_for_each_entry_safe(mp, next_mp, &head, list) {
602 mlast = mp;
603
604 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
605
606 Size -= Cnt;
607
608 if (!ctptr) {
609 ctptr = (uint32_t *) mlast->virt;
610 } else
611 Cnt -= 16;
612
613
614 while (Cnt >= sizeof(uint32_t)) {
615
616 CTentry = *ctptr++;
617 Did = ((be32_to_cpu(CTentry)) & Mask_DID);
618 lpfc_ns_rsp_audit_did(vport, Did, fc4_type);
619 if (CTentry & (cpu_to_be32(SLI_CT_LAST_ENTRY)))
620 goto nsout1;
621
622 Cnt -= sizeof(uint32_t);
623 }
624 ctptr = NULL;
625
626 }
627
628
629
630
631
632 if (vport->phba->nvmet_support) {
633 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
634 if (!(ndlp->nlp_flag & NLP_NVMET_RECOV))
635 continue;
636 lpfc_disc_state_machine(vport, ndlp, NULL,
637 NLP_EVT_DEVICE_RECOVERY);
638 spin_lock_irq(shost->host_lock);
639 ndlp->nlp_flag &= ~NLP_NVMET_RECOV;
640 spin_unlock_irq(shost->host_lock);
641 }
642 }
643
644nsout1:
645 list_del(&head);
646 return 0;
647}
648
649static void
650lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
651 struct lpfc_iocbq *rspiocb)
652{
653 struct lpfc_vport *vport = cmdiocb->vport;
654 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
655 IOCB_t *irsp;
656 struct lpfc_dmabuf *outp;
657 struct lpfc_dmabuf *inp;
658 struct lpfc_sli_ct_request *CTrsp;
659 struct lpfc_sli_ct_request *CTreq;
660 struct lpfc_nodelist *ndlp;
661 int rc, type;
662
663
664 ndlp = cmdiocb->context_un.ndlp;
665
666
667 cmdiocb->context_un.rsp_iocb = rspiocb;
668 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
669 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
670 irsp = &rspiocb->iocb;
671
672 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
673 "GID_FT cmpl: status:x%x/x%x rtry:%d",
674 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_ns_retry);
675
676
677 if (vport->load_flag & FC_UNLOADING) {
678 if (vport->fc_flag & FC_RSCN_MODE)
679 lpfc_els_flush_rscn(vport);
680 goto out;
681 }
682
683 if (lpfc_els_chk_latt(vport)) {
684 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
685 "0216 Link event during NS query\n");
686 if (vport->fc_flag & FC_RSCN_MODE)
687 lpfc_els_flush_rscn(vport);
688 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
689 goto out;
690 }
691 if (lpfc_error_lost_link(irsp)) {
692 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
693 "0226 NS query failed due to link event\n");
694 if (vport->fc_flag & FC_RSCN_MODE)
695 lpfc_els_flush_rscn(vport);
696 goto out;
697 }
698
699 spin_lock_irq(shost->host_lock);
700 if (vport->fc_flag & FC_RSCN_DEFERRED) {
701 vport->fc_flag &= ~FC_RSCN_DEFERRED;
702 spin_unlock_irq(shost->host_lock);
703
704
705
706
707 vport->gidft_inp--;
708
709
710
711
712
713 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
714 "0151 Process Deferred RSCN Data: x%x x%x\n",
715 vport->fc_flag, vport->fc_rscn_id_cnt);
716 lpfc_els_handle_rscn(vport);
717
718 goto out;
719 }
720 spin_unlock_irq(shost->host_lock);
721
722 if (irsp->ulpStatus) {
723
724 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
725 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
726 (irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
727 IOERR_NO_RESOURCES)
728 vport->fc_ns_retry++;
729
730 type = lpfc_get_gidft_type(vport, cmdiocb);
731 if (type == 0)
732 goto out;
733
734
735 vport->gidft_inp--;
736 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
737 vport->fc_ns_retry, type);
738 if (rc == 0)
739 goto out;
740 }
741 if (vport->fc_flag & FC_RSCN_MODE)
742 lpfc_els_flush_rscn(vport);
743 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
744 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
745 "0257 GID_FT Query error: 0x%x 0x%x\n",
746 irsp->ulpStatus, vport->fc_ns_retry);
747 } else {
748
749 CTreq = (struct lpfc_sli_ct_request *) inp->virt;
750 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
751 if (CTrsp->CommandResponse.bits.CmdRsp ==
752 cpu_to_be16(SLI_CT_RESPONSE_FS_ACC)) {
753 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
754 "0208 NameServer Rsp Data: x%x x%x\n",
755 vport->fc_flag,
756 CTreq->un.gid.Fc4Type);
757
758 lpfc_ns_rsp(vport,
759 outp,
760 CTreq->un.gid.Fc4Type,
761 (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
762 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
763 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
764
765 if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
766 && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
767 lpfc_printf_vlog(vport, KERN_INFO,
768 LOG_DISCOVERY,
769 "0269 No NameServer Entries "
770 "Data: x%x x%x x%x x%x\n",
771 CTrsp->CommandResponse.bits.CmdRsp,
772 (uint32_t) CTrsp->ReasonCode,
773 (uint32_t) CTrsp->Explanation,
774 vport->fc_flag);
775
776 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
777 "GID_FT no entry cmd:x%x rsn:x%x exp:x%x",
778 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
779 (uint32_t) CTrsp->ReasonCode,
780 (uint32_t) CTrsp->Explanation);
781 } else {
782 lpfc_printf_vlog(vport, KERN_INFO,
783 LOG_DISCOVERY,
784 "0240 NameServer Rsp Error "
785 "Data: x%x x%x x%x x%x\n",
786 CTrsp->CommandResponse.bits.CmdRsp,
787 (uint32_t) CTrsp->ReasonCode,
788 (uint32_t) CTrsp->Explanation,
789 vport->fc_flag);
790
791 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
792 "GID_FT rsp err1 cmd:x%x rsn:x%x exp:x%x",
793 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
794 (uint32_t) CTrsp->ReasonCode,
795 (uint32_t) CTrsp->Explanation);
796 }
797
798
799 } else {
800
801 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
802 "0241 NameServer Rsp Error "
803 "Data: x%x x%x x%x x%x\n",
804 CTrsp->CommandResponse.bits.CmdRsp,
805 (uint32_t) CTrsp->ReasonCode,
806 (uint32_t) CTrsp->Explanation,
807 vport->fc_flag);
808
809 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
810 "GID_FT rsp err2 cmd:x%x rsn:x%x exp:x%x",
811 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
812 (uint32_t) CTrsp->ReasonCode,
813 (uint32_t) CTrsp->Explanation);
814 }
815 vport->gidft_inp--;
816 }
817
818 if ((vport->num_disc_nodes == 0) &&
819 (vport->gidft_inp == 0)) {
820
821
822
823
824
825 if (vport->port_state >= LPFC_DISC_AUTH) {
826 if (vport->fc_flag & FC_RSCN_MODE) {
827 lpfc_els_flush_rscn(vport);
828 spin_lock_irq(shost->host_lock);
829 vport->fc_flag |= FC_RSCN_MODE;
830 spin_unlock_irq(shost->host_lock);
831 }
832 else
833 lpfc_els_flush_rscn(vport);
834 }
835
836 lpfc_disc_start(vport);
837 }
838out:
839 cmdiocb->context_un.ndlp = ndlp;
840 lpfc_ct_free_iocb(phba, cmdiocb);
841 return;
842}
843
844static void
845lpfc_cmpl_ct_cmd_gid_pt(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
846 struct lpfc_iocbq *rspiocb)
847{
848 struct lpfc_vport *vport = cmdiocb->vport;
849 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
850 IOCB_t *irsp;
851 struct lpfc_dmabuf *outp;
852 struct lpfc_dmabuf *inp;
853 struct lpfc_sli_ct_request *CTrsp;
854 struct lpfc_sli_ct_request *CTreq;
855 struct lpfc_nodelist *ndlp;
856 int rc;
857
858
859 ndlp = cmdiocb->context_un.ndlp;
860
861
862 cmdiocb->context_un.rsp_iocb = rspiocb;
863 inp = (struct lpfc_dmabuf *)cmdiocb->context1;
864 outp = (struct lpfc_dmabuf *)cmdiocb->context2;
865 irsp = &rspiocb->iocb;
866
867 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
868 "GID_PT cmpl: status:x%x/x%x rtry:%d",
869 irsp->ulpStatus, irsp->un.ulpWord[4],
870 vport->fc_ns_retry);
871
872
873 if (vport->load_flag & FC_UNLOADING) {
874 if (vport->fc_flag & FC_RSCN_MODE)
875 lpfc_els_flush_rscn(vport);
876 goto out;
877 }
878
879 if (lpfc_els_chk_latt(vport)) {
880 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
881 "4108 Link event during NS query\n");
882 if (vport->fc_flag & FC_RSCN_MODE)
883 lpfc_els_flush_rscn(vport);
884 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
885 goto out;
886 }
887 if (lpfc_error_lost_link(irsp)) {
888 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
889 "4166 NS query failed due to link event\n");
890 if (vport->fc_flag & FC_RSCN_MODE)
891 lpfc_els_flush_rscn(vport);
892 goto out;
893 }
894
895 spin_lock_irq(shost->host_lock);
896 if (vport->fc_flag & FC_RSCN_DEFERRED) {
897 vport->fc_flag &= ~FC_RSCN_DEFERRED;
898 spin_unlock_irq(shost->host_lock);
899
900
901
902
903 vport->gidft_inp--;
904
905
906
907
908
909 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
910 "4167 Process Deferred RSCN Data: x%x x%x\n",
911 vport->fc_flag, vport->fc_rscn_id_cnt);
912 lpfc_els_handle_rscn(vport);
913
914 goto out;
915 }
916 spin_unlock_irq(shost->host_lock);
917
918 if (irsp->ulpStatus) {
919
920 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
921 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
922 (irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
923 IOERR_NO_RESOURCES)
924 vport->fc_ns_retry++;
925
926
927 vport->gidft_inp--;
928 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_PT,
929 vport->fc_ns_retry, GID_PT_N_PORT);
930 if (rc == 0)
931 goto out;
932 }
933 if (vport->fc_flag & FC_RSCN_MODE)
934 lpfc_els_flush_rscn(vport);
935 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
936 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
937 "4103 GID_FT Query error: 0x%x 0x%x\n",
938 irsp->ulpStatus, vport->fc_ns_retry);
939 } else {
940
941 CTreq = (struct lpfc_sli_ct_request *)inp->virt;
942 CTrsp = (struct lpfc_sli_ct_request *)outp->virt;
943 if (CTrsp->CommandResponse.bits.CmdRsp ==
944 cpu_to_be16(SLI_CT_RESPONSE_FS_ACC)) {
945 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
946 "4105 NameServer Rsp Data: x%x x%x\n",
947 vport->fc_flag,
948 CTreq->un.gid.Fc4Type);
949
950 lpfc_ns_rsp(vport,
951 outp,
952 CTreq->un.gid.Fc4Type,
953 (uint32_t)(irsp->un.genreq64.bdl.bdeSize));
954 } else if (CTrsp->CommandResponse.bits.CmdRsp ==
955 be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
956
957 if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
958 && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
959 lpfc_printf_vlog(
960 vport, KERN_INFO, LOG_DISCOVERY,
961 "4106 No NameServer Entries "
962 "Data: x%x x%x x%x x%x\n",
963 CTrsp->CommandResponse.bits.CmdRsp,
964 (uint32_t)CTrsp->ReasonCode,
965 (uint32_t)CTrsp->Explanation,
966 vport->fc_flag);
967
968 lpfc_debugfs_disc_trc(
969 vport, LPFC_DISC_TRC_CT,
970 "GID_PT no entry cmd:x%x rsn:x%x exp:x%x",
971 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
972 (uint32_t)CTrsp->ReasonCode,
973 (uint32_t)CTrsp->Explanation);
974 } else {
975 lpfc_printf_vlog(
976 vport, KERN_INFO, LOG_DISCOVERY,
977 "4107 NameServer Rsp Error "
978 "Data: x%x x%x x%x x%x\n",
979 CTrsp->CommandResponse.bits.CmdRsp,
980 (uint32_t)CTrsp->ReasonCode,
981 (uint32_t)CTrsp->Explanation,
982 vport->fc_flag);
983
984 lpfc_debugfs_disc_trc(
985 vport, LPFC_DISC_TRC_CT,
986 "GID_PT rsp err1 cmd:x%x rsn:x%x exp:x%x",
987 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
988 (uint32_t)CTrsp->ReasonCode,
989 (uint32_t)CTrsp->Explanation);
990 }
991 } else {
992
993 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
994 "4109 NameServer Rsp Error "
995 "Data: x%x x%x x%x x%x\n",
996 CTrsp->CommandResponse.bits.CmdRsp,
997 (uint32_t)CTrsp->ReasonCode,
998 (uint32_t)CTrsp->Explanation,
999 vport->fc_flag);
1000
1001 lpfc_debugfs_disc_trc(
1002 vport, LPFC_DISC_TRC_CT,
1003 "GID_PT rsp err2 cmd:x%x rsn:x%x exp:x%x",
1004 (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
1005 (uint32_t)CTrsp->ReasonCode,
1006 (uint32_t)CTrsp->Explanation);
1007 }
1008 vport->gidft_inp--;
1009 }
1010
1011 if ((vport->num_disc_nodes == 0) &&
1012 (vport->gidft_inp == 0)) {
1013
1014
1015
1016
1017
1018 if (vport->port_state >= LPFC_DISC_AUTH) {
1019 if (vport->fc_flag & FC_RSCN_MODE) {
1020 lpfc_els_flush_rscn(vport);
1021 spin_lock_irq(shost->host_lock);
1022 vport->fc_flag |= FC_RSCN_MODE;
1023 spin_unlock_irq(shost->host_lock);
1024 } else {
1025 lpfc_els_flush_rscn(vport);
1026 }
1027 }
1028
1029 lpfc_disc_start(vport);
1030 }
1031out:
1032 cmdiocb->context_un.ndlp = ndlp;
1033 lpfc_ct_free_iocb(phba, cmdiocb);
1034}
1035
1036static void
1037lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1038 struct lpfc_iocbq *rspiocb)
1039{
1040 struct lpfc_vport *vport = cmdiocb->vport;
1041 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1042 IOCB_t *irsp = &rspiocb->iocb;
1043 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *) cmdiocb->context1;
1044 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1045 struct lpfc_sli_ct_request *CTrsp;
1046 int did, rc, retry;
1047 uint8_t fbits;
1048 struct lpfc_nodelist *ndlp;
1049
1050 did = ((struct lpfc_sli_ct_request *) inp->virt)->un.gff.PortId;
1051 did = be32_to_cpu(did);
1052
1053 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1054 "GFF_ID cmpl: status:x%x/x%x did:x%x",
1055 irsp->ulpStatus, irsp->un.ulpWord[4], did);
1056
1057 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1058
1059 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1060 fbits = CTrsp->un.gff_acc.fbits[FCP_TYPE_FEATURE_OFFSET];
1061
1062 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1063 "6431 Process GFF_ID rsp for %08x "
1064 "fbits %02x %s %s\n",
1065 did, fbits,
1066 (fbits & FC4_FEATURE_INIT) ? "Initiator" : " ",
1067 (fbits & FC4_FEATURE_TARGET) ? "Target" : " ");
1068
1069 if (CTrsp->CommandResponse.bits.CmdRsp ==
1070 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
1071 if ((fbits & FC4_FEATURE_INIT) &&
1072 !(fbits & FC4_FEATURE_TARGET)) {
1073 lpfc_printf_vlog(vport, KERN_INFO,
1074 LOG_DISCOVERY,
1075 "0270 Skip x%x GFF "
1076 "NameServer Rsp Data: (init) "
1077 "x%x x%x\n", did, fbits,
1078 vport->fc_rscn_id_cnt);
1079 goto out;
1080 }
1081 }
1082 }
1083 else {
1084
1085 if (cmdiocb->retry < LPFC_MAX_NS_RETRY) {
1086 retry = 1;
1087 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
1088 switch ((irsp->un.ulpWord[4] &
1089 IOERR_PARAM_MASK)) {
1090
1091 case IOERR_NO_RESOURCES:
1092
1093
1094
1095 break;
1096 case IOERR_LINK_DOWN:
1097 case IOERR_SLI_ABORTED:
1098 case IOERR_SLI_DOWN:
1099 retry = 0;
1100 break;
1101 default:
1102 cmdiocb->retry++;
1103 }
1104 }
1105 else
1106 cmdiocb->retry++;
1107
1108 if (retry) {
1109
1110 rc = lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
1111 cmdiocb->retry, did);
1112 if (rc == 0) {
1113
1114 lpfc_ct_free_iocb(phba, cmdiocb);
1115 return;
1116 }
1117 }
1118 }
1119 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1120 "0267 NameServer GFF Rsp "
1121 "x%x Error (%d %d) Data: x%x x%x\n",
1122 did, irsp->ulpStatus, irsp->un.ulpWord[4],
1123 vport->fc_flag, vport->fc_rscn_id_cnt);
1124 }
1125
1126
1127 ndlp = lpfc_setup_disc_node(vport, did);
1128 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
1129 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1130 "0242 Process x%x GFF "
1131 "NameServer Rsp Data: x%x x%x x%x\n",
1132 did, ndlp->nlp_flag, vport->fc_flag,
1133 vport->fc_rscn_id_cnt);
1134 } else {
1135 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1136 "0243 Skip x%x GFF "
1137 "NameServer Rsp Data: x%x x%x\n", did,
1138 vport->fc_flag, vport->fc_rscn_id_cnt);
1139 }
1140out:
1141
1142 if (vport->num_disc_nodes)
1143 vport->num_disc_nodes--;
1144 if (vport->num_disc_nodes == 0) {
1145
1146
1147
1148
1149
1150 if (vport->port_state >= LPFC_DISC_AUTH) {
1151 if (vport->fc_flag & FC_RSCN_MODE) {
1152 lpfc_els_flush_rscn(vport);
1153 spin_lock_irq(shost->host_lock);
1154 vport->fc_flag |= FC_RSCN_MODE;
1155 spin_unlock_irq(shost->host_lock);
1156 }
1157 else
1158 lpfc_els_flush_rscn(vport);
1159 }
1160 lpfc_disc_start(vport);
1161 }
1162 lpfc_ct_free_iocb(phba, cmdiocb);
1163 return;
1164}
1165
1166static void
1167lpfc_cmpl_ct_cmd_gft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1168 struct lpfc_iocbq *rspiocb)
1169{
1170 struct lpfc_vport *vport = cmdiocb->vport;
1171 IOCB_t *irsp = &rspiocb->iocb;
1172 struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *)cmdiocb->context1;
1173 struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *)cmdiocb->context2;
1174 struct lpfc_sli_ct_request *CTrsp;
1175 int did;
1176 struct lpfc_nodelist *ndlp;
1177 uint32_t fc4_data_0, fc4_data_1;
1178
1179 did = ((struct lpfc_sli_ct_request *)inp->virt)->un.gft.PortId;
1180 did = be32_to_cpu(did);
1181
1182 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1183 "GFT_ID cmpl: status:x%x/x%x did:x%x",
1184 irsp->ulpStatus, irsp->un.ulpWord[4], did);
1185
1186 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1187
1188 CTrsp = (struct lpfc_sli_ct_request *)outp->virt;
1189 fc4_data_0 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[0]);
1190 fc4_data_1 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[1]);
1191
1192 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1193 "6432 Process GFT_ID rsp for %08x "
1194 "Data %08x %08x %s %s\n",
1195 did, fc4_data_0, fc4_data_1,
1196 (fc4_data_0 & LPFC_FC4_TYPE_BITMASK) ?
1197 "FCP" : " ",
1198 (fc4_data_1 & LPFC_FC4_TYPE_BITMASK) ?
1199 "NVME" : " ");
1200
1201 ndlp = lpfc_findnode_did(vport, did);
1202 if (ndlp) {
1203
1204
1205
1206
1207 if (fc4_data_0 & LPFC_FC4_TYPE_BITMASK)
1208 ndlp->nlp_fc4_type |= NLP_FC4_FCP;
1209 if (fc4_data_1 & LPFC_FC4_TYPE_BITMASK)
1210 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
1211 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1212 "3064 Setting ndlp %p, DID x%06x with "
1213 "FC4 x%08x, Data: x%08x x%08x\n",
1214 ndlp, did, ndlp->nlp_fc4_type,
1215 FC_TYPE_FCP, FC_TYPE_NVME);
1216 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1217
1218 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1219 lpfc_issue_els_prli(vport, ndlp, 0);
1220 }
1221 } else
1222 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1223 "3065 GFT_ID failed x%08x\n", irsp->ulpStatus);
1224
1225 lpfc_ct_free_iocb(phba, cmdiocb);
1226}
1227
1228static void
1229lpfc_cmpl_ct(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1230 struct lpfc_iocbq *rspiocb)
1231{
1232 struct lpfc_vport *vport = cmdiocb->vport;
1233 struct lpfc_dmabuf *inp;
1234 struct lpfc_dmabuf *outp;
1235 IOCB_t *irsp;
1236 struct lpfc_sli_ct_request *CTrsp;
1237 struct lpfc_nodelist *ndlp;
1238 int cmdcode, rc;
1239 uint8_t retry;
1240 uint32_t latt;
1241
1242
1243 ndlp = cmdiocb->context_un.ndlp;
1244
1245
1246 cmdiocb->context_un.rsp_iocb = rspiocb;
1247
1248 inp = (struct lpfc_dmabuf *) cmdiocb->context1;
1249 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1250 irsp = &rspiocb->iocb;
1251
1252 cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)->
1253 CommandResponse.bits.CmdRsp);
1254 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1255
1256 latt = lpfc_els_chk_latt(vport);
1257
1258
1259 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1260 "0209 CT Request completes, latt %d, "
1261 "ulpStatus x%x CmdRsp x%x, Context x%x, Tag x%x\n",
1262 latt, irsp->ulpStatus,
1263 CTrsp->CommandResponse.bits.CmdRsp,
1264 cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag);
1265
1266 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1267 "CT cmd cmpl: status:x%x/x%x cmd:x%x",
1268 irsp->ulpStatus, irsp->un.ulpWord[4], cmdcode);
1269
1270 if (irsp->ulpStatus) {
1271 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1272 "0268 NS cmd x%x Error (x%x x%x)\n",
1273 cmdcode, irsp->ulpStatus, irsp->un.ulpWord[4]);
1274
1275 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1276 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1277 IOERR_SLI_DOWN) ||
1278 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1279 IOERR_SLI_ABORTED)))
1280 goto out;
1281
1282 retry = cmdiocb->retry;
1283 if (retry >= LPFC_MAX_NS_RETRY)
1284 goto out;
1285
1286 retry++;
1287 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1288 "0250 Retrying NS cmd %x\n", cmdcode);
1289 rc = lpfc_ns_cmd(vport, cmdcode, retry, 0);
1290 if (rc == 0)
1291 goto out;
1292 }
1293
1294out:
1295 cmdiocb->context_un.ndlp = ndlp;
1296 lpfc_ct_free_iocb(phba, cmdiocb);
1297 return;
1298}
1299
1300static void
1301lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1302 struct lpfc_iocbq *rspiocb)
1303{
1304 IOCB_t *irsp = &rspiocb->iocb;
1305 struct lpfc_vport *vport = cmdiocb->vport;
1306
1307 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1308 struct lpfc_dmabuf *outp;
1309 struct lpfc_sli_ct_request *CTrsp;
1310
1311 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1312 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1313 if (CTrsp->CommandResponse.bits.CmdRsp ==
1314 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1315 vport->ct_flags |= FC_CT_RFT_ID;
1316 }
1317 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1318 return;
1319}
1320
1321static void
1322lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1323 struct lpfc_iocbq *rspiocb)
1324{
1325 IOCB_t *irsp = &rspiocb->iocb;
1326 struct lpfc_vport *vport = cmdiocb->vport;
1327
1328 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1329 struct lpfc_dmabuf *outp;
1330 struct lpfc_sli_ct_request *CTrsp;
1331
1332 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1333 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1334 if (CTrsp->CommandResponse.bits.CmdRsp ==
1335 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1336 vport->ct_flags |= FC_CT_RNN_ID;
1337 }
1338 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1339 return;
1340}
1341
1342static void
1343lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1344 struct lpfc_iocbq *rspiocb)
1345{
1346 IOCB_t *irsp = &rspiocb->iocb;
1347 struct lpfc_vport *vport = cmdiocb->vport;
1348
1349 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1350 struct lpfc_dmabuf *outp;
1351 struct lpfc_sli_ct_request *CTrsp;
1352
1353 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1354 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1355 if (CTrsp->CommandResponse.bits.CmdRsp ==
1356 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1357 vport->ct_flags |= FC_CT_RSPN_ID;
1358 }
1359 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1360 return;
1361}
1362
1363static void
1364lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1365 struct lpfc_iocbq *rspiocb)
1366{
1367 IOCB_t *irsp = &rspiocb->iocb;
1368 struct lpfc_vport *vport = cmdiocb->vport;
1369
1370 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1371 struct lpfc_dmabuf *outp;
1372 struct lpfc_sli_ct_request *CTrsp;
1373
1374 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1375 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1376 if (CTrsp->CommandResponse.bits.CmdRsp ==
1377 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1378 vport->ct_flags |= FC_CT_RSNN_NN;
1379 }
1380 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1381 return;
1382}
1383
1384static void
1385lpfc_cmpl_ct_cmd_da_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1386 struct lpfc_iocbq *rspiocb)
1387{
1388 struct lpfc_vport *vport = cmdiocb->vport;
1389
1390
1391 vport->ct_flags = 0;
1392 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1393 return;
1394}
1395
1396static void
1397lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1398 struct lpfc_iocbq *rspiocb)
1399{
1400 IOCB_t *irsp = &rspiocb->iocb;
1401 struct lpfc_vport *vport = cmdiocb->vport;
1402
1403 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
1404 struct lpfc_dmabuf *outp;
1405 struct lpfc_sli_ct_request *CTrsp;
1406
1407 outp = (struct lpfc_dmabuf *) cmdiocb->context2;
1408 CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
1409 if (CTrsp->CommandResponse.bits.CmdRsp ==
1410 be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
1411 vport->ct_flags |= FC_CT_RFF_ID;
1412 }
1413 lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
1414 return;
1415}
1416
1417
1418
1419
1420
1421
1422int
1423lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol,
1424 size_t size)
1425{
1426 int n;
1427
1428
1429
1430
1431
1432
1433 n = scnprintf(symbol, size, "%d", vport->phba->brd_no);
1434 return n;
1435}
1436
1437
1438int
1439lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol,
1440 size_t size)
1441{
1442 char fwrev[FW_REV_STR_SIZE];
1443 int n;
1444
1445 lpfc_decode_firmware_rev(vport->phba, fwrev, 0);
1446
1447 n = scnprintf(symbol, size, "Emulex %s", vport->phba->ModelName);
1448 if (size < n)
1449 return n;
1450
1451 n += scnprintf(symbol + n, size - n, " FV%s", fwrev);
1452 if (size < n)
1453 return n;
1454
1455 n += scnprintf(symbol + n, size - n, " DV%s.",
1456 lpfc_release_version);
1457 if (size < n)
1458 return n;
1459
1460 n += scnprintf(symbol + n, size - n, " HN:%s.",
1461 init_utsname()->nodename);
1462 if (size < n)
1463 return n;
1464
1465
1466 n += scnprintf(symbol + n, size - n, " OS:%s",
1467 init_utsname()->sysname);
1468 return n;
1469}
1470
1471static uint32_t
1472lpfc_find_map_node(struct lpfc_vport *vport)
1473{
1474 struct lpfc_nodelist *ndlp, *next_ndlp;
1475 struct Scsi_Host *shost;
1476 uint32_t cnt = 0;
1477
1478 shost = lpfc_shost_from_vport(vport);
1479 spin_lock_irq(shost->host_lock);
1480 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
1481 if (ndlp->nlp_type & NLP_FABRIC)
1482 continue;
1483 if ((ndlp->nlp_state == NLP_STE_MAPPED_NODE) ||
1484 (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE))
1485 cnt++;
1486 }
1487 spin_unlock_irq(shost->host_lock);
1488 return cnt;
1489}
1490
1491
1492
1493
1494
1495int
1496lpfc_get_gidft_type(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb)
1497{
1498 struct lpfc_sli_ct_request *CtReq;
1499 struct lpfc_dmabuf *mp;
1500 uint32_t type;
1501
1502 mp = cmdiocb->context1;
1503 if (mp == NULL)
1504 return 0;
1505 CtReq = (struct lpfc_sli_ct_request *)mp->virt;
1506 type = (uint32_t)CtReq->un.gid.Fc4Type;
1507 if ((type != SLI_CTPT_FCP) && (type != SLI_CTPT_NVME))
1508 return 0;
1509 return type;
1510}
1511
1512
1513
1514
1515
1516
1517
1518
1519int
1520lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode,
1521 uint8_t retry, uint32_t context)
1522{
1523 struct lpfc_nodelist * ndlp;
1524 struct lpfc_hba *phba = vport->phba;
1525 struct lpfc_dmabuf *mp, *bmp;
1526 struct lpfc_sli_ct_request *CtReq;
1527 struct ulp_bde64 *bpl;
1528 void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
1529 struct lpfc_iocbq *) = NULL;
1530 uint32_t *ptr;
1531 uint32_t rsp_size = 1024;
1532 size_t size;
1533 int rc = 0;
1534
1535 ndlp = lpfc_findnode_did(vport, NameServer_DID);
1536 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)
1537 || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) {
1538 rc=1;
1539 goto ns_cmd_exit;
1540 }
1541
1542
1543
1544 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
1545 if (!mp) {
1546 rc=2;
1547 goto ns_cmd_exit;
1548 }
1549
1550 INIT_LIST_HEAD(&mp->list);
1551 mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
1552 if (!mp->virt) {
1553 rc=3;
1554 goto ns_cmd_free_mp;
1555 }
1556
1557
1558 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
1559 if (!bmp) {
1560 rc=4;
1561 goto ns_cmd_free_mpvirt;
1562 }
1563
1564 INIT_LIST_HEAD(&bmp->list);
1565 bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
1566 if (!bmp->virt) {
1567 rc=5;
1568 goto ns_cmd_free_bmp;
1569 }
1570
1571
1572 lpfc_printf_vlog(vport, KERN_INFO ,LOG_DISCOVERY,
1573 "0236 NameServer Req Data: x%x x%x x%x x%x\n",
1574 cmdcode, vport->fc_flag, vport->fc_rscn_id_cnt,
1575 context);
1576
1577 bpl = (struct ulp_bde64 *) bmp->virt;
1578 memset(bpl, 0, sizeof(struct ulp_bde64));
1579 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
1580 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
1581 bpl->tus.f.bdeFlags = 0;
1582 if (cmdcode == SLI_CTNS_GID_FT)
1583 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
1584 else if (cmdcode == SLI_CTNS_GID_PT)
1585 bpl->tus.f.bdeSize = GID_REQUEST_SZ;
1586 else if (cmdcode == SLI_CTNS_GFF_ID)
1587 bpl->tus.f.bdeSize = GFF_REQUEST_SZ;
1588 else if (cmdcode == SLI_CTNS_GFT_ID)
1589 bpl->tus.f.bdeSize = GFT_REQUEST_SZ;
1590 else if (cmdcode == SLI_CTNS_RFT_ID)
1591 bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
1592 else if (cmdcode == SLI_CTNS_RNN_ID)
1593 bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
1594 else if (cmdcode == SLI_CTNS_RSPN_ID)
1595 bpl->tus.f.bdeSize = RSPN_REQUEST_SZ;
1596 else if (cmdcode == SLI_CTNS_RSNN_NN)
1597 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
1598 else if (cmdcode == SLI_CTNS_DA_ID)
1599 bpl->tus.f.bdeSize = DA_ID_REQUEST_SZ;
1600 else if (cmdcode == SLI_CTNS_RFF_ID)
1601 bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
1602 else
1603 bpl->tus.f.bdeSize = 0;
1604 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1605
1606 CtReq = (struct lpfc_sli_ct_request *) mp->virt;
1607 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
1608 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
1609 CtReq->RevisionId.bits.InId = 0;
1610 CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
1611 CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
1612 CtReq->CommandResponse.bits.Size = 0;
1613 switch (cmdcode) {
1614 case SLI_CTNS_GID_FT:
1615 CtReq->CommandResponse.bits.CmdRsp =
1616 cpu_to_be16(SLI_CTNS_GID_FT);
1617 CtReq->un.gid.Fc4Type = context;
1618
1619 if (vport->port_state < LPFC_NS_QRY)
1620 vport->port_state = LPFC_NS_QRY;
1621 lpfc_set_disctmo(vport);
1622 cmpl = lpfc_cmpl_ct_cmd_gid_ft;
1623 rsp_size = FC_MAX_NS_RSP;
1624 break;
1625
1626 case SLI_CTNS_GID_PT:
1627 CtReq->CommandResponse.bits.CmdRsp =
1628 cpu_to_be16(SLI_CTNS_GID_PT);
1629 CtReq->un.gid.PortType = context;
1630
1631 if (vport->port_state < LPFC_NS_QRY)
1632 vport->port_state = LPFC_NS_QRY;
1633 lpfc_set_disctmo(vport);
1634 cmpl = lpfc_cmpl_ct_cmd_gid_pt;
1635 rsp_size = FC_MAX_NS_RSP;
1636 break;
1637
1638 case SLI_CTNS_GFF_ID:
1639 CtReq->CommandResponse.bits.CmdRsp =
1640 cpu_to_be16(SLI_CTNS_GFF_ID);
1641 CtReq->un.gff.PortId = cpu_to_be32(context);
1642 cmpl = lpfc_cmpl_ct_cmd_gff_id;
1643 break;
1644
1645 case SLI_CTNS_GFT_ID:
1646 CtReq->CommandResponse.bits.CmdRsp =
1647 cpu_to_be16(SLI_CTNS_GFT_ID);
1648 CtReq->un.gft.PortId = cpu_to_be32(context);
1649 cmpl = lpfc_cmpl_ct_cmd_gft_id;
1650 break;
1651
1652 case SLI_CTNS_RFT_ID:
1653 vport->ct_flags &= ~FC_CT_RFT_ID;
1654 CtReq->CommandResponse.bits.CmdRsp =
1655 cpu_to_be16(SLI_CTNS_RFT_ID);
1656 CtReq->un.rft.PortId = cpu_to_be32(vport->fc_myDID);
1657
1658
1659 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH ||
1660 vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP)
1661 CtReq->un.rft.fcpReg = 1;
1662
1663
1664
1665
1666
1667 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH ||
1668 vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
1669 CtReq->un.rft.rsvd[0] =
1670 cpu_to_be32(LPFC_FC4_TYPE_BITMASK);
1671
1672 ptr = (uint32_t *)CtReq;
1673 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1674 "6433 Issue RFT (%s %s): %08x %08x %08x %08x "
1675 "%08x %08x %08x %08x\n",
1676 CtReq->un.rft.fcpReg ? "FCP" : " ",
1677 CtReq->un.rft.rsvd[0] ? "NVME" : " ",
1678 *ptr, *(ptr + 1), *(ptr + 2), *(ptr + 3),
1679 *(ptr + 4), *(ptr + 5),
1680 *(ptr + 6), *(ptr + 7));
1681 cmpl = lpfc_cmpl_ct_cmd_rft_id;
1682 break;
1683
1684 case SLI_CTNS_RNN_ID:
1685 vport->ct_flags &= ~FC_CT_RNN_ID;
1686 CtReq->CommandResponse.bits.CmdRsp =
1687 cpu_to_be16(SLI_CTNS_RNN_ID);
1688 CtReq->un.rnn.PortId = cpu_to_be32(vport->fc_myDID);
1689 memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
1690 sizeof(struct lpfc_name));
1691 cmpl = lpfc_cmpl_ct_cmd_rnn_id;
1692 break;
1693
1694 case SLI_CTNS_RSPN_ID:
1695 vport->ct_flags &= ~FC_CT_RSPN_ID;
1696 CtReq->CommandResponse.bits.CmdRsp =
1697 cpu_to_be16(SLI_CTNS_RSPN_ID);
1698 CtReq->un.rspn.PortId = cpu_to_be32(vport->fc_myDID);
1699 size = sizeof(CtReq->un.rspn.symbname);
1700 CtReq->un.rspn.len =
1701 lpfc_vport_symbolic_port_name(vport,
1702 CtReq->un.rspn.symbname, size);
1703 cmpl = lpfc_cmpl_ct_cmd_rspn_id;
1704 break;
1705 case SLI_CTNS_RSNN_NN:
1706 vport->ct_flags &= ~FC_CT_RSNN_NN;
1707 CtReq->CommandResponse.bits.CmdRsp =
1708 cpu_to_be16(SLI_CTNS_RSNN_NN);
1709 memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
1710 sizeof(struct lpfc_name));
1711 size = sizeof(CtReq->un.rsnn.symbname);
1712 CtReq->un.rsnn.len =
1713 lpfc_vport_symbolic_node_name(vport,
1714 CtReq->un.rsnn.symbname, size);
1715 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
1716 break;
1717 case SLI_CTNS_DA_ID:
1718
1719 CtReq->CommandResponse.bits.CmdRsp =
1720 cpu_to_be16(SLI_CTNS_DA_ID);
1721 CtReq->un.da_id.port_id = cpu_to_be32(vport->fc_myDID);
1722 cmpl = lpfc_cmpl_ct_cmd_da_id;
1723 break;
1724 case SLI_CTNS_RFF_ID:
1725 vport->ct_flags &= ~FC_CT_RFF_ID;
1726 CtReq->CommandResponse.bits.CmdRsp =
1727 cpu_to_be16(SLI_CTNS_RFF_ID);
1728 CtReq->un.rff.PortId = cpu_to_be32(vport->fc_myDID);
1729 CtReq->un.rff.fbits = FC4_FEATURE_INIT;
1730
1731
1732
1733
1734
1735 if (((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1736 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) &&
1737 (context == FC_TYPE_NVME)) {
1738 if ((vport == phba->pport) && phba->nvmet_support) {
1739 CtReq->un.rff.fbits = (FC4_FEATURE_TARGET |
1740 FC4_FEATURE_NVME_DISC);
1741 lpfc_nvmet_update_targetport(phba);
1742 } else {
1743 lpfc_nvme_update_localport(vport);
1744 }
1745 CtReq->un.rff.type_code = context;
1746
1747 } else if (((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1748 (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) &&
1749 (context == FC_TYPE_FCP))
1750 CtReq->un.rff.type_code = context;
1751
1752 else
1753 goto ns_cmd_free_bmpvirt;
1754
1755 ptr = (uint32_t *)CtReq;
1756 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1757 "6434 Issue RFF (%s): %08x %08x %08x %08x "
1758 "%08x %08x %08x %08x\n",
1759 (context == FC_TYPE_NVME) ? "NVME" : "FCP",
1760 *ptr, *(ptr + 1), *(ptr + 2), *(ptr + 3),
1761 *(ptr + 4), *(ptr + 5),
1762 *(ptr + 6), *(ptr + 7));
1763 cmpl = lpfc_cmpl_ct_cmd_rff_id;
1764 break;
1765 }
1766
1767
1768
1769 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) {
1770
1771 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1772 "Issue CT cmd: cmd:x%x did:x%x",
1773 cmdcode, ndlp->nlp_DID, 0);
1774 return 0;
1775 }
1776 rc=6;
1777
1778
1779
1780
1781 lpfc_nlp_put(ndlp);
1782
1783ns_cmd_free_bmpvirt:
1784 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1785ns_cmd_free_bmp:
1786 kfree(bmp);
1787ns_cmd_free_mpvirt:
1788 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1789ns_cmd_free_mp:
1790 kfree(mp);
1791ns_cmd_exit:
1792 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1793 "0266 Issue NameServer Req x%x err %d Data: x%x x%x\n",
1794 cmdcode, rc, vport->fc_flag, vport->fc_rscn_id_cnt);
1795 return 1;
1796}
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807static void
1808lpfc_cmpl_ct_disc_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1809 struct lpfc_iocbq *rspiocb)
1810{
1811 struct lpfc_vport *vport = cmdiocb->vport;
1812 struct lpfc_dmabuf *inp = cmdiocb->context1;
1813 struct lpfc_dmabuf *outp = cmdiocb->context2;
1814 struct lpfc_sli_ct_request *CTcmd = inp->virt;
1815 struct lpfc_sli_ct_request *CTrsp = outp->virt;
1816 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
1817 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
1818 IOCB_t *irsp = &rspiocb->iocb;
1819 struct lpfc_nodelist *ndlp;
1820 uint32_t latt, cmd, err;
1821
1822 latt = lpfc_els_chk_latt(vport);
1823 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
1824 "FDMI cmpl: status:x%x/x%x latt:%d",
1825 irsp->ulpStatus, irsp->un.ulpWord[4], latt);
1826
1827 if (latt || irsp->ulpStatus) {
1828
1829
1830 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
1831 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
1832 case IOERR_SLI_ABORTED:
1833 case IOERR_ABORT_IN_PROGRESS:
1834 case IOERR_SEQUENCE_TIMEOUT:
1835 case IOERR_ILLEGAL_FRAME:
1836 case IOERR_NO_RESOURCES:
1837 case IOERR_ILLEGAL_COMMAND:
1838 cmdiocb->retry++;
1839 if (cmdiocb->retry >= LPFC_FDMI_MAX_RETRY)
1840 break;
1841
1842
1843 err = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING,
1844 cmdiocb, 0);
1845 if (err == IOCB_ERROR)
1846 break;
1847 return;
1848 default:
1849 break;
1850 }
1851 }
1852
1853 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1854 "0229 FDMI cmd %04x failed, latt = %d "
1855 "ulpStatus: x%x, rid x%x\n",
1856 be16_to_cpu(fdmi_cmd), latt, irsp->ulpStatus,
1857 irsp->un.ulpWord[4]);
1858 }
1859 lpfc_ct_free_iocb(phba, cmdiocb);
1860
1861 ndlp = lpfc_findnode_did(vport, FDMI_DID);
1862 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
1863 return;
1864
1865
1866 cmd = be16_to_cpu(fdmi_cmd);
1867 if (fdmi_rsp == cpu_to_be16(SLI_CT_RESPONSE_FS_RJT)) {
1868
1869 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1870 "0220 FDMI cmd failed FS_RJT Data: x%x", cmd);
1871
1872
1873 switch (cmd) {
1874 case SLI_MGMT_RHBA:
1875 if (vport->fdmi_hba_mask == LPFC_FDMI2_HBA_ATTR) {
1876
1877 vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR;
1878 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1879
1880 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
1881 }
1882 return;
1883
1884 case SLI_MGMT_RPRT:
1885 if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) {
1886
1887 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1888
1889 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1890 }
1891 if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) {
1892 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
1893
1894 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1895 }
1896 return;
1897
1898 case SLI_MGMT_RPA:
1899 if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) {
1900
1901 vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR;
1902 vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
1903
1904 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
1905 }
1906 if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) {
1907 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
1908
1909 lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
1910 }
1911 return;
1912 }
1913 }
1914
1915
1916
1917
1918
1919
1920 switch (cmd) {
1921 case SLI_MGMT_RHBA:
1922 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA, 0);
1923 break;
1924
1925 case SLI_MGMT_DHBA:
1926 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
1927 break;
1928
1929 case SLI_MGMT_DPRT:
1930 if (vport->port_type == LPFC_PHYSICAL_PORT)
1931 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA, 0);
1932 else
1933 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT, 0);
1934 break;
1935 }
1936 return;
1937}
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947void
1948lpfc_fdmi_num_disc_check(struct lpfc_vport *vport)
1949{
1950 struct lpfc_hba *phba = vport->phba;
1951 struct lpfc_nodelist *ndlp;
1952 uint16_t cnt;
1953
1954 if (!lpfc_is_link_up(phba))
1955 return;
1956
1957
1958 if (!(vport->fc_flag & FC_FABRIC))
1959 return;
1960
1961 if (!(vport->fdmi_port_mask & LPFC_FDMI_PORT_ATTR_num_disc))
1962 return;
1963
1964 cnt = lpfc_find_map_node(vport);
1965 if (cnt == vport->fdmi_num_disc)
1966 return;
1967
1968 ndlp = lpfc_findnode_did(vport, FDMI_DID);
1969 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
1970 return;
1971
1972 if (vport->port_type == LPFC_PHYSICAL_PORT) {
1973 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA,
1974 LPFC_FDMI_PORT_ATTR_num_disc);
1975 } else {
1976 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT,
1977 LPFC_FDMI_PORT_ATTR_num_disc);
1978 }
1979}
1980
1981
1982static int
1983lpfc_fdmi_hba_attr_wwnn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad)
1984{
1985 struct lpfc_fdmi_attr_entry *ae;
1986 uint32_t size;
1987
1988 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
1989 memset(ae, 0, sizeof(struct lpfc_name));
1990
1991 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName,
1992 sizeof(struct lpfc_name));
1993 size = FOURBYTES + sizeof(struct lpfc_name);
1994 ad->AttrLen = cpu_to_be16(size);
1995 ad->AttrType = cpu_to_be16(RHBA_NODENAME);
1996 return size;
1997}
1998static int
1999lpfc_fdmi_hba_attr_manufacturer(struct lpfc_vport *vport,
2000 struct lpfc_fdmi_attr_def *ad)
2001{
2002 struct lpfc_fdmi_attr_entry *ae;
2003 uint32_t len, size;
2004
2005 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2006 memset(ae, 0, 256);
2007
2008
2009
2010
2011 strncpy(ae->un.AttrString,
2012 "Emulex Corporation",
2013 sizeof(ae->un.AttrString));
2014 len = strnlen(ae->un.AttrString,
2015 sizeof(ae->un.AttrString));
2016 len += (len & 3) ? (4 - (len & 3)) : 4;
2017 size = FOURBYTES + len;
2018 ad->AttrLen = cpu_to_be16(size);
2019 ad->AttrType = cpu_to_be16(RHBA_MANUFACTURER);
2020 return size;
2021}
2022
2023static int
2024lpfc_fdmi_hba_attr_sn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad)
2025{
2026 struct lpfc_hba *phba = vport->phba;
2027 struct lpfc_fdmi_attr_entry *ae;
2028 uint32_t len, size;
2029
2030 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2031 memset(ae, 0, 256);
2032
2033 strncpy(ae->un.AttrString, phba->SerialNumber,
2034 sizeof(ae->un.AttrString));
2035 len = strnlen(ae->un.AttrString,
2036 sizeof(ae->un.AttrString));
2037 len += (len & 3) ? (4 - (len & 3)) : 4;
2038 size = FOURBYTES + len;
2039 ad->AttrLen = cpu_to_be16(size);
2040 ad->AttrType = cpu_to_be16(RHBA_SERIAL_NUMBER);
2041 return size;
2042}
2043
2044static int
2045lpfc_fdmi_hba_attr_model(struct lpfc_vport *vport,
2046 struct lpfc_fdmi_attr_def *ad)
2047{
2048 struct lpfc_hba *phba = vport->phba;
2049 struct lpfc_fdmi_attr_entry *ae;
2050 uint32_t len, size;
2051
2052 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2053 memset(ae, 0, 256);
2054
2055 strncpy(ae->un.AttrString, phba->ModelName,
2056 sizeof(ae->un.AttrString));
2057 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2058 len += (len & 3) ? (4 - (len & 3)) : 4;
2059 size = FOURBYTES + len;
2060 ad->AttrLen = cpu_to_be16(size);
2061 ad->AttrType = cpu_to_be16(RHBA_MODEL);
2062 return size;
2063}
2064
2065static int
2066lpfc_fdmi_hba_attr_description(struct lpfc_vport *vport,
2067 struct lpfc_fdmi_attr_def *ad)
2068{
2069 struct lpfc_hba *phba = vport->phba;
2070 struct lpfc_fdmi_attr_entry *ae;
2071 uint32_t len, size;
2072
2073 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2074 memset(ae, 0, 256);
2075
2076 strncpy(ae->un.AttrString, phba->ModelDesc,
2077 sizeof(ae->un.AttrString));
2078 len = strnlen(ae->un.AttrString,
2079 sizeof(ae->un.AttrString));
2080 len += (len & 3) ? (4 - (len & 3)) : 4;
2081 size = FOURBYTES + len;
2082 ad->AttrLen = cpu_to_be16(size);
2083 ad->AttrType = cpu_to_be16(RHBA_MODEL_DESCRIPTION);
2084 return size;
2085}
2086
2087static int
2088lpfc_fdmi_hba_attr_hdw_ver(struct lpfc_vport *vport,
2089 struct lpfc_fdmi_attr_def *ad)
2090{
2091 struct lpfc_hba *phba = vport->phba;
2092 lpfc_vpd_t *vp = &phba->vpd;
2093 struct lpfc_fdmi_attr_entry *ae;
2094 uint32_t i, j, incr, size;
2095
2096 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2097 memset(ae, 0, 256);
2098
2099
2100 incr = vp->rev.biuRev;
2101 for (i = 0; i < 8; i++) {
2102 j = (incr & 0xf);
2103 if (j <= 9)
2104 ae->un.AttrString[7 - i] =
2105 (char)((uint8_t) 0x30 +
2106 (uint8_t) j);
2107 else
2108 ae->un.AttrString[7 - i] =
2109 (char)((uint8_t) 0x61 +
2110 (uint8_t) (j - 10));
2111 incr = (incr >> 4);
2112 }
2113 size = FOURBYTES + 8;
2114 ad->AttrLen = cpu_to_be16(size);
2115 ad->AttrType = cpu_to_be16(RHBA_HARDWARE_VERSION);
2116 return size;
2117}
2118
2119static int
2120lpfc_fdmi_hba_attr_drvr_ver(struct lpfc_vport *vport,
2121 struct lpfc_fdmi_attr_def *ad)
2122{
2123 struct lpfc_fdmi_attr_entry *ae;
2124 uint32_t len, size;
2125
2126 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2127 memset(ae, 0, 256);
2128
2129 strncpy(ae->un.AttrString, lpfc_release_version,
2130 sizeof(ae->un.AttrString));
2131 len = strnlen(ae->un.AttrString,
2132 sizeof(ae->un.AttrString));
2133 len += (len & 3) ? (4 - (len & 3)) : 4;
2134 size = FOURBYTES + len;
2135 ad->AttrLen = cpu_to_be16(size);
2136 ad->AttrType = cpu_to_be16(RHBA_DRIVER_VERSION);
2137 return size;
2138}
2139
2140static int
2141lpfc_fdmi_hba_attr_rom_ver(struct lpfc_vport *vport,
2142 struct lpfc_fdmi_attr_def *ad)
2143{
2144 struct lpfc_hba *phba = vport->phba;
2145 struct lpfc_fdmi_attr_entry *ae;
2146 uint32_t len, size;
2147
2148 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2149 memset(ae, 0, 256);
2150
2151 if (phba->sli_rev == LPFC_SLI_REV4)
2152 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
2153 else
2154 strncpy(ae->un.AttrString, phba->OptionROMVersion,
2155 sizeof(ae->un.AttrString));
2156 len = strnlen(ae->un.AttrString,
2157 sizeof(ae->un.AttrString));
2158 len += (len & 3) ? (4 - (len & 3)) : 4;
2159 size = FOURBYTES + len;
2160 ad->AttrLen = cpu_to_be16(size);
2161 ad->AttrType = cpu_to_be16(RHBA_OPTION_ROM_VERSION);
2162 return size;
2163}
2164
2165static int
2166lpfc_fdmi_hba_attr_fmw_ver(struct lpfc_vport *vport,
2167 struct lpfc_fdmi_attr_def *ad)
2168{
2169 struct lpfc_hba *phba = vport->phba;
2170 struct lpfc_fdmi_attr_entry *ae;
2171 uint32_t len, size;
2172
2173 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2174 memset(ae, 0, 256);
2175
2176 lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
2177 len = strnlen(ae->un.AttrString,
2178 sizeof(ae->un.AttrString));
2179 len += (len & 3) ? (4 - (len & 3)) : 4;
2180 size = FOURBYTES + len;
2181 ad->AttrLen = cpu_to_be16(size);
2182 ad->AttrType = cpu_to_be16(RHBA_FIRMWARE_VERSION);
2183 return size;
2184}
2185
2186static int
2187lpfc_fdmi_hba_attr_os_ver(struct lpfc_vport *vport,
2188 struct lpfc_fdmi_attr_def *ad)
2189{
2190 struct lpfc_fdmi_attr_entry *ae;
2191 uint32_t len, size;
2192
2193 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2194 memset(ae, 0, 256);
2195
2196 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s %s %s",
2197 init_utsname()->sysname,
2198 init_utsname()->release,
2199 init_utsname()->version);
2200
2201 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2202 len += (len & 3) ? (4 - (len & 3)) : 4;
2203 size = FOURBYTES + len;
2204 ad->AttrLen = cpu_to_be16(size);
2205 ad->AttrType = cpu_to_be16(RHBA_OS_NAME_VERSION);
2206 return size;
2207}
2208
2209static int
2210lpfc_fdmi_hba_attr_ct_len(struct lpfc_vport *vport,
2211 struct lpfc_fdmi_attr_def *ad)
2212{
2213 struct lpfc_fdmi_attr_entry *ae;
2214 uint32_t size;
2215
2216 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2217
2218 ae->un.AttrInt = cpu_to_be32(LPFC_MAX_CT_SIZE);
2219 size = FOURBYTES + sizeof(uint32_t);
2220 ad->AttrLen = cpu_to_be16(size);
2221 ad->AttrType = cpu_to_be16(RHBA_MAX_CT_PAYLOAD_LEN);
2222 return size;
2223}
2224
2225static int
2226lpfc_fdmi_hba_attr_symbolic_name(struct lpfc_vport *vport,
2227 struct lpfc_fdmi_attr_def *ad)
2228{
2229 struct lpfc_fdmi_attr_entry *ae;
2230 uint32_t len, size;
2231
2232 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2233 memset(ae, 0, 256);
2234
2235 len = lpfc_vport_symbolic_node_name(vport,
2236 ae->un.AttrString, 256);
2237 len += (len & 3) ? (4 - (len & 3)) : 4;
2238 size = FOURBYTES + len;
2239 ad->AttrLen = cpu_to_be16(size);
2240 ad->AttrType = cpu_to_be16(RHBA_SYM_NODENAME);
2241 return size;
2242}
2243
2244static int
2245lpfc_fdmi_hba_attr_vendor_info(struct lpfc_vport *vport,
2246 struct lpfc_fdmi_attr_def *ad)
2247{
2248 struct lpfc_fdmi_attr_entry *ae;
2249 uint32_t size;
2250
2251 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2252
2253
2254 ae->un.AttrInt = cpu_to_be32(0);
2255 size = FOURBYTES + sizeof(uint32_t);
2256 ad->AttrLen = cpu_to_be16(size);
2257 ad->AttrType = cpu_to_be16(RHBA_VENDOR_INFO);
2258 return size;
2259}
2260
2261static int
2262lpfc_fdmi_hba_attr_num_ports(struct lpfc_vport *vport,
2263 struct lpfc_fdmi_attr_def *ad)
2264{
2265 struct lpfc_fdmi_attr_entry *ae;
2266 uint32_t size;
2267
2268 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2269
2270
2271 ae->un.AttrInt = cpu_to_be32(1);
2272 size = FOURBYTES + sizeof(uint32_t);
2273 ad->AttrLen = cpu_to_be16(size);
2274 ad->AttrType = cpu_to_be16(RHBA_NUM_PORTS);
2275 return size;
2276}
2277
2278static int
2279lpfc_fdmi_hba_attr_fabric_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->fabric_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(RHBA_FABRIC_WWNN);
2293 return size;
2294}
2295
2296static int
2297lpfc_fdmi_hba_attr_bios_ver(struct lpfc_vport *vport,
2298 struct lpfc_fdmi_attr_def *ad)
2299{
2300 struct lpfc_hba *phba = vport->phba;
2301 struct lpfc_fdmi_attr_entry *ae;
2302 uint32_t len, size;
2303
2304 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2305 memset(ae, 0, 256);
2306
2307 strlcat(ae->un.AttrString, phba->BIOSVersion,
2308 sizeof(ae->un.AttrString));
2309 len = strnlen(ae->un.AttrString,
2310 sizeof(ae->un.AttrString));
2311 len += (len & 3) ? (4 - (len & 3)) : 4;
2312 size = FOURBYTES + len;
2313 ad->AttrLen = cpu_to_be16(size);
2314 ad->AttrType = cpu_to_be16(RHBA_BIOS_VERSION);
2315 return size;
2316}
2317
2318static int
2319lpfc_fdmi_hba_attr_bios_state(struct lpfc_vport *vport,
2320 struct lpfc_fdmi_attr_def *ad)
2321{
2322 struct lpfc_fdmi_attr_entry *ae;
2323 uint32_t size;
2324
2325 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2326
2327
2328 ae->un.AttrInt = cpu_to_be32(0);
2329 size = FOURBYTES + sizeof(uint32_t);
2330 ad->AttrLen = cpu_to_be16(size);
2331 ad->AttrType = cpu_to_be16(RHBA_BIOS_STATE);
2332 return size;
2333}
2334
2335static int
2336lpfc_fdmi_hba_attr_vendor_id(struct lpfc_vport *vport,
2337 struct lpfc_fdmi_attr_def *ad)
2338{
2339 struct lpfc_fdmi_attr_entry *ae;
2340 uint32_t len, size;
2341
2342 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2343 memset(ae, 0, 256);
2344
2345 strncpy(ae->un.AttrString, "EMULEX",
2346 sizeof(ae->un.AttrString));
2347 len = strnlen(ae->un.AttrString,
2348 sizeof(ae->un.AttrString));
2349 len += (len & 3) ? (4 - (len & 3)) : 4;
2350 size = FOURBYTES + len;
2351 ad->AttrLen = cpu_to_be16(size);
2352 ad->AttrType = cpu_to_be16(RHBA_VENDOR_ID);
2353 return size;
2354}
2355
2356
2357static int
2358lpfc_fdmi_port_attr_fc4type(struct lpfc_vport *vport,
2359 struct lpfc_fdmi_attr_def *ad)
2360{
2361 struct lpfc_hba *phba = vport->phba;
2362 struct lpfc_fdmi_attr_entry *ae;
2363 uint32_t size;
2364
2365 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2366 memset(ae, 0, 32);
2367
2368 ae->un.AttrTypes[3] = 0x02;
2369 ae->un.AttrTypes[2] = 0x01;
2370 ae->un.AttrTypes[7] = 0x01;
2371
2372
2373 if ((phba->sli_rev == LPFC_SLI_REV4) && (vport == phba->pport) &&
2374 phba->sli4_hba.pc_sli4_params.nvme)
2375 ae->un.AttrTypes[6] = 0x01;
2376
2377 size = FOURBYTES + 32;
2378 ad->AttrLen = cpu_to_be16(size);
2379 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_FC4_TYPES);
2380 return size;
2381}
2382
2383static int
2384lpfc_fdmi_port_attr_support_speed(struct lpfc_vport *vport,
2385 struct lpfc_fdmi_attr_def *ad)
2386{
2387 struct lpfc_hba *phba = vport->phba;
2388 struct lpfc_fdmi_attr_entry *ae;
2389 uint32_t size;
2390
2391 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2392
2393 ae->un.AttrInt = 0;
2394 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
2395 if (phba->lmt & LMT_128Gb)
2396 ae->un.AttrInt |= HBA_PORTSPEED_128GFC;
2397 if (phba->lmt & LMT_64Gb)
2398 ae->un.AttrInt |= HBA_PORTSPEED_64GFC;
2399 if (phba->lmt & LMT_32Gb)
2400 ae->un.AttrInt |= HBA_PORTSPEED_32GFC;
2401 if (phba->lmt & LMT_16Gb)
2402 ae->un.AttrInt |= HBA_PORTSPEED_16GFC;
2403 if (phba->lmt & LMT_10Gb)
2404 ae->un.AttrInt |= HBA_PORTSPEED_10GFC;
2405 if (phba->lmt & LMT_8Gb)
2406 ae->un.AttrInt |= HBA_PORTSPEED_8GFC;
2407 if (phba->lmt & LMT_4Gb)
2408 ae->un.AttrInt |= HBA_PORTSPEED_4GFC;
2409 if (phba->lmt & LMT_2Gb)
2410 ae->un.AttrInt |= HBA_PORTSPEED_2GFC;
2411 if (phba->lmt & LMT_1Gb)
2412 ae->un.AttrInt |= HBA_PORTSPEED_1GFC;
2413 } else {
2414
2415 switch (phba->fc_linkspeed) {
2416 case LPFC_ASYNC_LINK_SPEED_10GBPS:
2417 ae->un.AttrInt = HBA_PORTSPEED_10GE;
2418 break;
2419 case LPFC_ASYNC_LINK_SPEED_25GBPS:
2420 ae->un.AttrInt = HBA_PORTSPEED_25GE;
2421 break;
2422 case LPFC_ASYNC_LINK_SPEED_40GBPS:
2423 ae->un.AttrInt = HBA_PORTSPEED_40GE;
2424 break;
2425 case LPFC_ASYNC_LINK_SPEED_100GBPS:
2426 ae->un.AttrInt = HBA_PORTSPEED_100GE;
2427 break;
2428 }
2429 }
2430 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2431 size = FOURBYTES + sizeof(uint32_t);
2432 ad->AttrLen = cpu_to_be16(size);
2433 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_SPEED);
2434 return size;
2435}
2436
2437static int
2438lpfc_fdmi_port_attr_speed(struct lpfc_vport *vport,
2439 struct lpfc_fdmi_attr_def *ad)
2440{
2441 struct lpfc_hba *phba = vport->phba;
2442 struct lpfc_fdmi_attr_entry *ae;
2443 uint32_t size;
2444
2445 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2446
2447 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
2448 switch (phba->fc_linkspeed) {
2449 case LPFC_LINK_SPEED_1GHZ:
2450 ae->un.AttrInt = HBA_PORTSPEED_1GFC;
2451 break;
2452 case LPFC_LINK_SPEED_2GHZ:
2453 ae->un.AttrInt = HBA_PORTSPEED_2GFC;
2454 break;
2455 case LPFC_LINK_SPEED_4GHZ:
2456 ae->un.AttrInt = HBA_PORTSPEED_4GFC;
2457 break;
2458 case LPFC_LINK_SPEED_8GHZ:
2459 ae->un.AttrInt = HBA_PORTSPEED_8GFC;
2460 break;
2461 case LPFC_LINK_SPEED_10GHZ:
2462 ae->un.AttrInt = HBA_PORTSPEED_10GFC;
2463 break;
2464 case LPFC_LINK_SPEED_16GHZ:
2465 ae->un.AttrInt = HBA_PORTSPEED_16GFC;
2466 break;
2467 case LPFC_LINK_SPEED_32GHZ:
2468 ae->un.AttrInt = HBA_PORTSPEED_32GFC;
2469 break;
2470 case LPFC_LINK_SPEED_64GHZ:
2471 ae->un.AttrInt = HBA_PORTSPEED_64GFC;
2472 break;
2473 case LPFC_LINK_SPEED_128GHZ:
2474 ae->un.AttrInt = HBA_PORTSPEED_128GFC;
2475 break;
2476 default:
2477 ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN;
2478 break;
2479 }
2480 } else {
2481 switch (phba->fc_linkspeed) {
2482 case LPFC_ASYNC_LINK_SPEED_10GBPS:
2483 ae->un.AttrInt = HBA_PORTSPEED_10GE;
2484 break;
2485 case LPFC_ASYNC_LINK_SPEED_25GBPS:
2486 ae->un.AttrInt = HBA_PORTSPEED_25GE;
2487 break;
2488 case LPFC_ASYNC_LINK_SPEED_40GBPS:
2489 ae->un.AttrInt = HBA_PORTSPEED_40GE;
2490 break;
2491 case LPFC_ASYNC_LINK_SPEED_100GBPS:
2492 ae->un.AttrInt = HBA_PORTSPEED_100GE;
2493 break;
2494 default:
2495 ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN;
2496 break;
2497 }
2498 }
2499
2500 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2501 size = FOURBYTES + sizeof(uint32_t);
2502 ad->AttrLen = cpu_to_be16(size);
2503 ad->AttrType = cpu_to_be16(RPRT_PORT_SPEED);
2504 return size;
2505}
2506
2507static int
2508lpfc_fdmi_port_attr_max_frame(struct lpfc_vport *vport,
2509 struct lpfc_fdmi_attr_def *ad)
2510{
2511 struct serv_parm *hsp;
2512 struct lpfc_fdmi_attr_entry *ae;
2513 uint32_t size;
2514
2515 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2516
2517 hsp = (struct serv_parm *)&vport->fc_sparam;
2518 ae->un.AttrInt = (((uint32_t) hsp->cmn.bbRcvSizeMsb) << 8) |
2519 (uint32_t) hsp->cmn.bbRcvSizeLsb;
2520 ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
2521 size = FOURBYTES + sizeof(uint32_t);
2522 ad->AttrLen = cpu_to_be16(size);
2523 ad->AttrType = cpu_to_be16(RPRT_MAX_FRAME_SIZE);
2524 return size;
2525}
2526
2527static int
2528lpfc_fdmi_port_attr_os_devname(struct lpfc_vport *vport,
2529 struct lpfc_fdmi_attr_def *ad)
2530{
2531 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2532 struct lpfc_fdmi_attr_entry *ae;
2533 uint32_t len, size;
2534
2535 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2536 memset(ae, 0, 256);
2537
2538 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString),
2539 "/sys/class/scsi_host/host%d", shost->host_no);
2540 len = strnlen((char *)ae->un.AttrString,
2541 sizeof(ae->un.AttrString));
2542 len += (len & 3) ? (4 - (len & 3)) : 4;
2543 size = FOURBYTES + len;
2544 ad->AttrLen = cpu_to_be16(size);
2545 ad->AttrType = cpu_to_be16(RPRT_OS_DEVICE_NAME);
2546 return size;
2547}
2548
2549static int
2550lpfc_fdmi_port_attr_host_name(struct lpfc_vport *vport,
2551 struct lpfc_fdmi_attr_def *ad)
2552{
2553 struct lpfc_fdmi_attr_entry *ae;
2554 uint32_t len, size;
2555
2556 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2557 memset(ae, 0, 256);
2558
2559 snprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s",
2560 init_utsname()->nodename);
2561
2562 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2563 len += (len & 3) ? (4 - (len & 3)) : 4;
2564 size = FOURBYTES + len;
2565 ad->AttrLen = cpu_to_be16(size);
2566 ad->AttrType = cpu_to_be16(RPRT_HOST_NAME);
2567 return size;
2568}
2569
2570static int
2571lpfc_fdmi_port_attr_wwnn(struct lpfc_vport *vport,
2572 struct lpfc_fdmi_attr_def *ad)
2573{
2574 struct lpfc_fdmi_attr_entry *ae;
2575 uint32_t size;
2576
2577 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2578 memset(ae, 0, sizeof(struct lpfc_name));
2579
2580 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName,
2581 sizeof(struct lpfc_name));
2582 size = FOURBYTES + sizeof(struct lpfc_name);
2583 ad->AttrLen = cpu_to_be16(size);
2584 ad->AttrType = cpu_to_be16(RPRT_NODENAME);
2585 return size;
2586}
2587
2588static int
2589lpfc_fdmi_port_attr_wwpn(struct lpfc_vport *vport,
2590 struct lpfc_fdmi_attr_def *ad)
2591{
2592 struct lpfc_fdmi_attr_entry *ae;
2593 uint32_t size;
2594
2595 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2596 memset(ae, 0, sizeof(struct lpfc_name));
2597
2598 memcpy(&ae->un.AttrWWN, &vport->fc_sparam.portName,
2599 sizeof(struct lpfc_name));
2600 size = FOURBYTES + sizeof(struct lpfc_name);
2601 ad->AttrLen = cpu_to_be16(size);
2602 ad->AttrType = cpu_to_be16(RPRT_PORTNAME);
2603 return size;
2604}
2605
2606static int
2607lpfc_fdmi_port_attr_symbolic_name(struct lpfc_vport *vport,
2608 struct lpfc_fdmi_attr_def *ad)
2609{
2610 struct lpfc_fdmi_attr_entry *ae;
2611 uint32_t len, size;
2612
2613 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2614 memset(ae, 0, 256);
2615
2616 len = lpfc_vport_symbolic_port_name(vport, ae->un.AttrString, 256);
2617 len += (len & 3) ? (4 - (len & 3)) : 4;
2618 size = FOURBYTES + len;
2619 ad->AttrLen = cpu_to_be16(size);
2620 ad->AttrType = cpu_to_be16(RPRT_SYM_PORTNAME);
2621 return size;
2622}
2623
2624static int
2625lpfc_fdmi_port_attr_port_type(struct lpfc_vport *vport,
2626 struct lpfc_fdmi_attr_def *ad)
2627{
2628 struct lpfc_hba *phba = vport->phba;
2629 struct lpfc_fdmi_attr_entry *ae;
2630 uint32_t size;
2631
2632 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2633 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP)
2634 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NLPORT);
2635 else
2636 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NPORT);
2637 size = FOURBYTES + sizeof(uint32_t);
2638 ad->AttrLen = cpu_to_be16(size);
2639 ad->AttrType = cpu_to_be16(RPRT_PORT_TYPE);
2640 return size;
2641}
2642
2643static int
2644lpfc_fdmi_port_attr_class(struct lpfc_vport *vport,
2645 struct lpfc_fdmi_attr_def *ad)
2646{
2647 struct lpfc_fdmi_attr_entry *ae;
2648 uint32_t size;
2649
2650 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2651 ae->un.AttrInt = cpu_to_be32(FC_COS_CLASS2 | FC_COS_CLASS3);
2652 size = FOURBYTES + sizeof(uint32_t);
2653 ad->AttrLen = cpu_to_be16(size);
2654 ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_CLASS);
2655 return size;
2656}
2657
2658static int
2659lpfc_fdmi_port_attr_fabric_wwpn(struct lpfc_vport *vport,
2660 struct lpfc_fdmi_attr_def *ad)
2661{
2662 struct lpfc_fdmi_attr_entry *ae;
2663 uint32_t size;
2664
2665 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2666 memset(ae, 0, sizeof(struct lpfc_name));
2667
2668 memcpy(&ae->un.AttrWWN, &vport->fabric_portname,
2669 sizeof(struct lpfc_name));
2670 size = FOURBYTES + sizeof(struct lpfc_name);
2671 ad->AttrLen = cpu_to_be16(size);
2672 ad->AttrType = cpu_to_be16(RPRT_FABRICNAME);
2673 return size;
2674}
2675
2676static int
2677lpfc_fdmi_port_attr_active_fc4type(struct lpfc_vport *vport,
2678 struct lpfc_fdmi_attr_def *ad)
2679{
2680 struct lpfc_fdmi_attr_entry *ae;
2681 uint32_t size;
2682
2683 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2684 memset(ae, 0, 32);
2685
2686 ae->un.AttrTypes[3] = 0x02;
2687 ae->un.AttrTypes[2] = 0x01;
2688 ae->un.AttrTypes[7] = 0x01;
2689
2690
2691 if (vport->phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
2692 ae->un.AttrTypes[6] = 0x1;
2693
2694 size = FOURBYTES + 32;
2695 ad->AttrLen = cpu_to_be16(size);
2696 ad->AttrType = cpu_to_be16(RPRT_ACTIVE_FC4_TYPES);
2697 return size;
2698}
2699
2700static int
2701lpfc_fdmi_port_attr_port_state(struct lpfc_vport *vport,
2702 struct lpfc_fdmi_attr_def *ad)
2703{
2704 struct lpfc_fdmi_attr_entry *ae;
2705 uint32_t size;
2706
2707 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2708
2709 ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTSTATE_ONLINE);
2710 size = FOURBYTES + sizeof(uint32_t);
2711 ad->AttrLen = cpu_to_be16(size);
2712 ad->AttrType = cpu_to_be16(RPRT_PORT_STATE);
2713 return size;
2714}
2715
2716static int
2717lpfc_fdmi_port_attr_num_disc(struct lpfc_vport *vport,
2718 struct lpfc_fdmi_attr_def *ad)
2719{
2720 struct lpfc_fdmi_attr_entry *ae;
2721 uint32_t size;
2722
2723 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2724 vport->fdmi_num_disc = lpfc_find_map_node(vport);
2725 ae->un.AttrInt = cpu_to_be32(vport->fdmi_num_disc);
2726 size = FOURBYTES + sizeof(uint32_t);
2727 ad->AttrLen = cpu_to_be16(size);
2728 ad->AttrType = cpu_to_be16(RPRT_DISC_PORT);
2729 return size;
2730}
2731
2732static int
2733lpfc_fdmi_port_attr_nportid(struct lpfc_vport *vport,
2734 struct lpfc_fdmi_attr_def *ad)
2735{
2736 struct lpfc_fdmi_attr_entry *ae;
2737 uint32_t size;
2738
2739 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2740 ae->un.AttrInt = cpu_to_be32(vport->fc_myDID);
2741 size = FOURBYTES + sizeof(uint32_t);
2742 ad->AttrLen = cpu_to_be16(size);
2743 ad->AttrType = cpu_to_be16(RPRT_PORT_ID);
2744 return size;
2745}
2746
2747static int
2748lpfc_fdmi_smart_attr_service(struct lpfc_vport *vport,
2749 struct lpfc_fdmi_attr_def *ad)
2750{
2751 struct lpfc_fdmi_attr_entry *ae;
2752 uint32_t len, size;
2753
2754 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2755 memset(ae, 0, 256);
2756
2757 strncpy(ae->un.AttrString, "Smart SAN Initiator",
2758 sizeof(ae->un.AttrString));
2759 len = strnlen(ae->un.AttrString,
2760 sizeof(ae->un.AttrString));
2761 len += (len & 3) ? (4 - (len & 3)) : 4;
2762 size = FOURBYTES + len;
2763 ad->AttrLen = cpu_to_be16(size);
2764 ad->AttrType = cpu_to_be16(RPRT_SMART_SERVICE);
2765 return size;
2766}
2767
2768static int
2769lpfc_fdmi_smart_attr_guid(struct lpfc_vport *vport,
2770 struct lpfc_fdmi_attr_def *ad)
2771{
2772 struct lpfc_fdmi_attr_entry *ae;
2773 uint32_t size;
2774
2775 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2776 memset(ae, 0, 256);
2777
2778 memcpy(&ae->un.AttrString, &vport->fc_sparam.nodeName,
2779 sizeof(struct lpfc_name));
2780 memcpy((((uint8_t *)&ae->un.AttrString) +
2781 sizeof(struct lpfc_name)),
2782 &vport->fc_sparam.portName, sizeof(struct lpfc_name));
2783 size = FOURBYTES + (2 * sizeof(struct lpfc_name));
2784 ad->AttrLen = cpu_to_be16(size);
2785 ad->AttrType = cpu_to_be16(RPRT_SMART_GUID);
2786 return size;
2787}
2788
2789static int
2790lpfc_fdmi_smart_attr_version(struct lpfc_vport *vport,
2791 struct lpfc_fdmi_attr_def *ad)
2792{
2793 struct lpfc_fdmi_attr_entry *ae;
2794 uint32_t len, size;
2795
2796 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2797 memset(ae, 0, 256);
2798
2799 strncpy(ae->un.AttrString, "Smart SAN Version 2.0",
2800 sizeof(ae->un.AttrString));
2801 len = strnlen(ae->un.AttrString,
2802 sizeof(ae->un.AttrString));
2803 len += (len & 3) ? (4 - (len & 3)) : 4;
2804 size = FOURBYTES + len;
2805 ad->AttrLen = cpu_to_be16(size);
2806 ad->AttrType = cpu_to_be16(RPRT_SMART_VERSION);
2807 return size;
2808}
2809
2810static int
2811lpfc_fdmi_smart_attr_model(struct lpfc_vport *vport,
2812 struct lpfc_fdmi_attr_def *ad)
2813{
2814 struct lpfc_hba *phba = vport->phba;
2815 struct lpfc_fdmi_attr_entry *ae;
2816 uint32_t len, size;
2817
2818 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2819 memset(ae, 0, 256);
2820
2821 strncpy(ae->un.AttrString, phba->ModelName,
2822 sizeof(ae->un.AttrString));
2823 len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
2824 len += (len & 3) ? (4 - (len & 3)) : 4;
2825 size = FOURBYTES + len;
2826 ad->AttrLen = cpu_to_be16(size);
2827 ad->AttrType = cpu_to_be16(RPRT_SMART_MODEL);
2828 return size;
2829}
2830
2831static int
2832lpfc_fdmi_smart_attr_port_info(struct lpfc_vport *vport,
2833 struct lpfc_fdmi_attr_def *ad)
2834{
2835 struct lpfc_fdmi_attr_entry *ae;
2836 uint32_t size;
2837
2838 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2839
2840
2841 if (vport->vpi)
2842 ae->un.AttrInt = cpu_to_be32(2);
2843 else
2844 ae->un.AttrInt = cpu_to_be32(1);
2845 size = FOURBYTES + sizeof(uint32_t);
2846 ad->AttrLen = cpu_to_be16(size);
2847 ad->AttrType = cpu_to_be16(RPRT_SMART_PORT_INFO);
2848 return size;
2849}
2850
2851static int
2852lpfc_fdmi_smart_attr_qos(struct lpfc_vport *vport,
2853 struct lpfc_fdmi_attr_def *ad)
2854{
2855 struct lpfc_fdmi_attr_entry *ae;
2856 uint32_t size;
2857
2858 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2859 ae->un.AttrInt = cpu_to_be32(0);
2860 size = FOURBYTES + sizeof(uint32_t);
2861 ad->AttrLen = cpu_to_be16(size);
2862 ad->AttrType = cpu_to_be16(RPRT_SMART_QOS);
2863 return size;
2864}
2865
2866static int
2867lpfc_fdmi_smart_attr_security(struct lpfc_vport *vport,
2868 struct lpfc_fdmi_attr_def *ad)
2869{
2870 struct lpfc_fdmi_attr_entry *ae;
2871 uint32_t size;
2872
2873 ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2874 ae->un.AttrInt = cpu_to_be32(1);
2875 size = FOURBYTES + sizeof(uint32_t);
2876 ad->AttrLen = cpu_to_be16(size);
2877 ad->AttrType = cpu_to_be16(RPRT_SMART_SECURITY);
2878 return size;
2879}
2880
2881
2882int (*lpfc_fdmi_hba_action[])
2883 (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = {
2884
2885 lpfc_fdmi_hba_attr_wwnn,
2886 lpfc_fdmi_hba_attr_manufacturer,
2887 lpfc_fdmi_hba_attr_sn,
2888 lpfc_fdmi_hba_attr_model,
2889 lpfc_fdmi_hba_attr_description,
2890 lpfc_fdmi_hba_attr_hdw_ver,
2891 lpfc_fdmi_hba_attr_drvr_ver,
2892 lpfc_fdmi_hba_attr_rom_ver,
2893 lpfc_fdmi_hba_attr_fmw_ver,
2894 lpfc_fdmi_hba_attr_os_ver,
2895 lpfc_fdmi_hba_attr_ct_len,
2896 lpfc_fdmi_hba_attr_symbolic_name,
2897 lpfc_fdmi_hba_attr_vendor_info,
2898 lpfc_fdmi_hba_attr_num_ports,
2899 lpfc_fdmi_hba_attr_fabric_wwnn,
2900 lpfc_fdmi_hba_attr_bios_ver,
2901 lpfc_fdmi_hba_attr_bios_state,
2902 lpfc_fdmi_hba_attr_vendor_id,
2903};
2904
2905
2906int (*lpfc_fdmi_port_action[])
2907 (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = {
2908
2909 lpfc_fdmi_port_attr_fc4type,
2910 lpfc_fdmi_port_attr_support_speed,
2911 lpfc_fdmi_port_attr_speed,
2912 lpfc_fdmi_port_attr_max_frame,
2913 lpfc_fdmi_port_attr_os_devname,
2914 lpfc_fdmi_port_attr_host_name,
2915 lpfc_fdmi_port_attr_wwnn,
2916 lpfc_fdmi_port_attr_wwpn,
2917 lpfc_fdmi_port_attr_symbolic_name,
2918 lpfc_fdmi_port_attr_port_type,
2919 lpfc_fdmi_port_attr_class,
2920 lpfc_fdmi_port_attr_fabric_wwpn,
2921 lpfc_fdmi_port_attr_active_fc4type,
2922 lpfc_fdmi_port_attr_port_state,
2923 lpfc_fdmi_port_attr_num_disc,
2924 lpfc_fdmi_port_attr_nportid,
2925 lpfc_fdmi_smart_attr_service,
2926 lpfc_fdmi_smart_attr_guid,
2927 lpfc_fdmi_smart_attr_version,
2928 lpfc_fdmi_smart_attr_model,
2929 lpfc_fdmi_smart_attr_port_info,
2930 lpfc_fdmi_smart_attr_qos,
2931 lpfc_fdmi_smart_attr_security,
2932};
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943int
2944lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2945 int cmdcode, uint32_t new_mask)
2946{
2947 struct lpfc_hba *phba = vport->phba;
2948 struct lpfc_dmabuf *mp, *bmp;
2949 struct lpfc_sli_ct_request *CtReq;
2950 struct ulp_bde64 *bpl;
2951 uint32_t bit_pos;
2952 uint32_t size;
2953 uint32_t rsp_size;
2954 uint32_t mask;
2955 struct lpfc_fdmi_reg_hba *rh;
2956 struct lpfc_fdmi_port_entry *pe;
2957 struct lpfc_fdmi_reg_portattr *pab = NULL;
2958 struct lpfc_fdmi_attr_block *ab = NULL;
2959 int (*func)(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad);
2960 void (*cmpl)(struct lpfc_hba *, struct lpfc_iocbq *,
2961 struct lpfc_iocbq *);
2962
2963 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2964 return 0;
2965
2966 cmpl = lpfc_cmpl_ct_disc_fdmi;
2967
2968
2969
2970 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
2971 if (!mp)
2972 goto fdmi_cmd_exit;
2973
2974 mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
2975 if (!mp->virt)
2976 goto fdmi_cmd_free_mp;
2977
2978
2979 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
2980 if (!bmp)
2981 goto fdmi_cmd_free_mpvirt;
2982
2983 bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
2984 if (!bmp->virt)
2985 goto fdmi_cmd_free_bmp;
2986
2987 INIT_LIST_HEAD(&mp->list);
2988 INIT_LIST_HEAD(&bmp->list);
2989
2990
2991 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2992 "0218 FDMI Request Data: x%x x%x x%x\n",
2993 vport->fc_flag, vport->port_state, cmdcode);
2994 CtReq = (struct lpfc_sli_ct_request *)mp->virt;
2995
2996
2997 memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
2998 CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
2999 CtReq->RevisionId.bits.InId = 0;
3000
3001 CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
3002 CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
3003
3004 CtReq->CommandResponse.bits.CmdRsp = cpu_to_be16(cmdcode);
3005 rsp_size = LPFC_BPL_SIZE;
3006 size = 0;
3007
3008
3009 switch (cmdcode) {
3010 case SLI_MGMT_RHAT:
3011 case SLI_MGMT_RHBA:
3012 rh = (struct lpfc_fdmi_reg_hba *)&CtReq->un.PortID;
3013
3014 memcpy(&rh->hi.PortName, &phba->pport->fc_sparam.portName,
3015 sizeof(struct lpfc_name));
3016
3017 if (cmdcode == SLI_MGMT_RHBA) {
3018
3019
3020 rh->rpl.EntryCnt = cpu_to_be32(1);
3021 memcpy(&rh->rpl.pe, &phba->pport->fc_sparam.portName,
3022 sizeof(struct lpfc_name));
3023
3024
3025 size = 2 * sizeof(struct lpfc_name) +
3026 FOURBYTES;
3027 } else {
3028 size = sizeof(struct lpfc_name);
3029 }
3030 ab = (struct lpfc_fdmi_attr_block *)((uint8_t *)rh + size);
3031 ab->EntryCnt = 0;
3032 size += FOURBYTES;
3033 bit_pos = 0;
3034 if (new_mask)
3035 mask = new_mask;
3036 else
3037 mask = vport->fdmi_hba_mask;
3038
3039
3040 while (mask) {
3041 if (mask & 0x1) {
3042 func = lpfc_fdmi_hba_action[bit_pos];
3043 size += func(vport,
3044 (struct lpfc_fdmi_attr_def *)
3045 ((uint8_t *)rh + size));
3046 ab->EntryCnt++;
3047 if ((size + 256) >
3048 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
3049 goto hba_out;
3050 }
3051 mask = mask >> 1;
3052 bit_pos++;
3053 }
3054hba_out:
3055 ab->EntryCnt = cpu_to_be32(ab->EntryCnt);
3056
3057 size = GID_REQUEST_SZ - 4 + size;
3058 break;
3059
3060 case SLI_MGMT_RPRT:
3061 case SLI_MGMT_RPA:
3062 pab = (struct lpfc_fdmi_reg_portattr *)&CtReq->un.PortID;
3063 if (cmdcode == SLI_MGMT_RPRT) {
3064 rh = (struct lpfc_fdmi_reg_hba *)pab;
3065
3066 memcpy(&rh->hi.PortName,
3067 &phba->pport->fc_sparam.portName,
3068 sizeof(struct lpfc_name));
3069 pab = (struct lpfc_fdmi_reg_portattr *)
3070 ((uint8_t *)pab + sizeof(struct lpfc_name));
3071 }
3072
3073 memcpy((uint8_t *)&pab->PortName,
3074 (uint8_t *)&vport->fc_sparam.portName,
3075 sizeof(struct lpfc_name));
3076 size += sizeof(struct lpfc_name) + FOURBYTES;
3077 pab->ab.EntryCnt = 0;
3078 bit_pos = 0;
3079 if (new_mask)
3080 mask = new_mask;
3081 else
3082 mask = vport->fdmi_port_mask;
3083
3084
3085 while (mask) {
3086 if (mask & 0x1) {
3087 func = lpfc_fdmi_port_action[bit_pos];
3088 size += func(vport,
3089 (struct lpfc_fdmi_attr_def *)
3090 ((uint8_t *)pab + size));
3091 pab->ab.EntryCnt++;
3092 if ((size + 256) >
3093 (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
3094 goto port_out;
3095 }
3096 mask = mask >> 1;
3097 bit_pos++;
3098 }
3099port_out:
3100 pab->ab.EntryCnt = cpu_to_be32(pab->ab.EntryCnt);
3101
3102 if (cmdcode == SLI_MGMT_RPRT)
3103 size += sizeof(struct lpfc_name);
3104 size = GID_REQUEST_SZ - 4 + size;
3105 break;
3106
3107 case SLI_MGMT_GHAT:
3108 case SLI_MGMT_GRPL:
3109 rsp_size = FC_MAX_NS_RSP;
3110
3111 case SLI_MGMT_DHBA:
3112 case SLI_MGMT_DHAT:
3113 pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID;
3114 memcpy((uint8_t *)&pe->PortName,
3115 (uint8_t *)&vport->fc_sparam.portName,
3116 sizeof(struct lpfc_name));
3117 size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
3118 break;
3119
3120 case SLI_MGMT_GPAT:
3121 case SLI_MGMT_GPAS:
3122 rsp_size = FC_MAX_NS_RSP;
3123
3124 case SLI_MGMT_DPRT:
3125 case SLI_MGMT_DPA:
3126 pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID;
3127 memcpy((uint8_t *)&pe->PortName,
3128 (uint8_t *)&vport->fc_sparam.portName,
3129 sizeof(struct lpfc_name));
3130 size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
3131 break;
3132 case SLI_MGMT_GRHL:
3133 size = GID_REQUEST_SZ - 4;
3134 break;
3135 default:
3136 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
3137 "0298 FDMI cmdcode x%x not supported\n",
3138 cmdcode);
3139 goto fdmi_cmd_free_bmpvirt;
3140 }
3141 CtReq->CommandResponse.bits.Size = cpu_to_be16(rsp_size);
3142
3143 bpl = (struct ulp_bde64 *)bmp->virt;
3144 bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys));
3145 bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys));
3146 bpl->tus.f.bdeFlags = 0;
3147 bpl->tus.f.bdeSize = size;
3148
3149
3150
3151
3152
3153 if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, 0))
3154 return 0;
3155
3156
3157
3158
3159
3160 lpfc_nlp_put(ndlp);
3161
3162fdmi_cmd_free_bmpvirt:
3163 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
3164fdmi_cmd_free_bmp:
3165 kfree(bmp);
3166fdmi_cmd_free_mpvirt:
3167 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3168fdmi_cmd_free_mp:
3169 kfree(mp);
3170fdmi_cmd_exit:
3171
3172 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3173 "0244 Issue FDMI request failed Data: x%x\n",
3174 cmdcode);
3175 return 1;
3176}
3177
3178
3179
3180
3181
3182
3183
3184
3185void
3186lpfc_delayed_disc_tmo(struct timer_list *t)
3187{
3188 struct lpfc_vport *vport = from_timer(vport, t, delayed_disc_tmo);
3189 struct lpfc_hba *phba = vport->phba;
3190 uint32_t tmo_posted;
3191 unsigned long iflag;
3192
3193 spin_lock_irqsave(&vport->work_port_lock, iflag);
3194 tmo_posted = vport->work_port_events & WORKER_DELAYED_DISC_TMO;
3195 if (!tmo_posted)
3196 vport->work_port_events |= WORKER_DELAYED_DISC_TMO;
3197 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
3198
3199 if (!tmo_posted)
3200 lpfc_worker_wake_up(phba);
3201 return;
3202}
3203
3204
3205
3206
3207
3208
3209
3210
3211void
3212lpfc_delayed_disc_timeout_handler(struct lpfc_vport *vport)
3213{
3214 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3215
3216 spin_lock_irq(shost->host_lock);
3217 if (!(vport->fc_flag & FC_DISC_DELAYED)) {
3218 spin_unlock_irq(shost->host_lock);
3219 return;
3220 }
3221 vport->fc_flag &= ~FC_DISC_DELAYED;
3222 spin_unlock_irq(shost->host_lock);
3223
3224 lpfc_do_scr_ns_plogi(vport->phba, vport);
3225}
3226
3227void
3228lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
3229{
3230 struct lpfc_sli *psli = &phba->sli;
3231 lpfc_vpd_t *vp = &phba->vpd;
3232 uint32_t b1, b2, b3, b4, i, rev;
3233 char c;
3234 uint32_t *ptr, str[4];
3235 uint8_t *fwname;
3236
3237 if (phba->sli_rev == LPFC_SLI_REV4)
3238 snprintf(fwrevision, FW_REV_STR_SIZE, "%s", vp->rev.opFwName);
3239 else if (vp->rev.rBit) {
3240 if (psli->sli_flag & LPFC_SLI_ACTIVE)
3241 rev = vp->rev.sli2FwRev;
3242 else
3243 rev = vp->rev.sli1FwRev;
3244
3245 b1 = (rev & 0x0000f000) >> 12;
3246 b2 = (rev & 0x00000f00) >> 8;
3247 b3 = (rev & 0x000000c0) >> 6;
3248 b4 = (rev & 0x00000030) >> 4;
3249
3250 switch (b4) {
3251 case 0:
3252 c = 'N';
3253 break;
3254 case 1:
3255 c = 'A';
3256 break;
3257 case 2:
3258 c = 'B';
3259 break;
3260 case 3:
3261 c = 'X';
3262 break;
3263 default:
3264 c = 0;
3265 break;
3266 }
3267 b4 = (rev & 0x0000000f);
3268
3269 if (psli->sli_flag & LPFC_SLI_ACTIVE)
3270 fwname = vp->rev.sli2FwName;
3271 else
3272 fwname = vp->rev.sli1FwName;
3273
3274 for (i = 0; i < 16; i++)
3275 if (fwname[i] == 0x20)
3276 fwname[i] = 0;
3277
3278 ptr = (uint32_t*)fwname;
3279
3280 for (i = 0; i < 3; i++)
3281 str[i] = be32_to_cpu(*ptr++);
3282
3283 if (c == 0) {
3284 if (flag)
3285 sprintf(fwrevision, "%d.%d%d (%s)",
3286 b1, b2, b3, (char *)str);
3287 else
3288 sprintf(fwrevision, "%d.%d%d", b1,
3289 b2, b3);
3290 } else {
3291 if (flag)
3292 sprintf(fwrevision, "%d.%d%d%c%d (%s)",
3293 b1, b2, b3, c,
3294 b4, (char *)str);
3295 else
3296 sprintf(fwrevision, "%d.%d%d%c%d",
3297 b1, b2, b3, c, b4);
3298 }
3299 } else {
3300 rev = vp->rev.smFwRev;
3301
3302 b1 = (rev & 0xff000000) >> 24;
3303 b2 = (rev & 0x00f00000) >> 20;
3304 b3 = (rev & 0x000f0000) >> 16;
3305 c = (rev & 0x0000ff00) >> 8;
3306 b4 = (rev & 0x000000ff);
3307
3308 sprintf(fwrevision, "%d.%d%d%c%d", b1, b2, b3, c, b4);
3309 }
3310 return;
3311}
3312