1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include <linux/blkdev.h>
25#include <linux/delay.h>
26#include <linux/slab.h>
27#include <linux/pci.h>
28#include <linux/kthread.h>
29#include <linux/interrupt.h>
30#include <linux/lockdep.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_nl.h"
42#include "lpfc_disc.h"
43#include "lpfc_sli.h"
44#include "lpfc_sli4.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_vport.h"
51#include "lpfc_debugfs.h"
52
53
54static uint8_t lpfcAlpaArray[] = {
55 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6,
56 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA,
57 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5,
58 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9,
59 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97,
60 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79,
61 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B,
62 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56,
63 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A,
64 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35,
65 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29,
66 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17,
67 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01
68};
69
70static void lpfc_disc_timeout_handler(struct lpfc_vport *);
71static void lpfc_disc_flush_list(struct lpfc_vport *vport);
72static void lpfc_unregister_fcfi_cmpl(struct lpfc_hba *, LPFC_MBOXQ_t *);
73static int lpfc_fcf_inuse(struct lpfc_hba *);
74static void lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *, LPFC_MBOXQ_t *);
75static void lpfc_check_inactive_vmid(struct lpfc_hba *phba);
76static void lpfc_check_vmid_qfpa_issue(struct lpfc_hba *phba);
77
78static int
79lpfc_valid_xpt_node(struct lpfc_nodelist *ndlp)
80{
81 if (ndlp->nlp_fc4_type ||
82 ndlp->nlp_type & NLP_FABRIC)
83 return 1;
84 return 0;
85}
86
87
88
89
90
91
92static int
93lpfc_rport_invalid(struct fc_rport *rport)
94{
95 struct lpfc_rport_data *rdata;
96 struct lpfc_nodelist *ndlp;
97
98 if (!rport) {
99 pr_err("**** %s: NULL rport, exit.\n", __func__);
100 return -EINVAL;
101 }
102
103 rdata = rport->dd_data;
104 if (!rdata) {
105 pr_err("**** %s: NULL dd_data on rport x%px SID x%x\n",
106 __func__, rport, rport->scsi_target_id);
107 return -EINVAL;
108 }
109
110 ndlp = rdata->pnode;
111 if (!rdata->pnode) {
112 pr_err("**** %s: NULL ndlp on rport x%px SID x%x\n",
113 __func__, rport, rport->scsi_target_id);
114 return -EINVAL;
115 }
116
117 if (!ndlp->vport) {
118 pr_err("**** %s: Null vport on ndlp x%px, DID x%x rport x%px "
119 "SID x%x\n", __func__, ndlp, ndlp->nlp_DID, rport,
120 rport->scsi_target_id);
121 return -EINVAL;
122 }
123 return 0;
124}
125
126void
127lpfc_terminate_rport_io(struct fc_rport *rport)
128{
129 struct lpfc_rport_data *rdata;
130 struct lpfc_nodelist *ndlp;
131 struct lpfc_vport *vport;
132
133 if (lpfc_rport_invalid(rport))
134 return;
135
136 rdata = rport->dd_data;
137 ndlp = rdata->pnode;
138 vport = ndlp->vport;
139 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
140 "rport terminate: sid:x%x did:x%x flg:x%x",
141 ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
142
143 if (ndlp->nlp_sid != NLP_NO_SID)
144 lpfc_sli_abort_iocb(vport, ndlp->nlp_sid, 0, LPFC_CTX_TGT);
145}
146
147
148
149
150void
151lpfc_dev_loss_tmo_callbk(struct fc_rport *rport)
152{
153 struct lpfc_nodelist *ndlp;
154 struct lpfc_vport *vport;
155 struct lpfc_hba *phba;
156 struct lpfc_work_evt *evtp;
157 unsigned long iflags;
158
159 ndlp = ((struct lpfc_rport_data *)rport->dd_data)->pnode;
160 if (!ndlp)
161 return;
162
163 vport = ndlp->vport;
164 phba = vport->phba;
165
166 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
167 "rport devlosscb: sid:x%x did:x%x flg:x%x",
168 ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
169
170 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
171 "3181 dev_loss_callbk x%06x, rport x%px flg x%x "
172 "load_flag x%x refcnt %d\n",
173 ndlp->nlp_DID, ndlp->rport, ndlp->nlp_flag,
174 vport->load_flag, kref_read(&ndlp->kref));
175
176
177
178
179 if (vport->load_flag & FC_UNLOADING) {
180 ((struct lpfc_rport_data *)rport->dd_data)->pnode = NULL;
181 ndlp->rport = NULL;
182
183 ndlp->fc4_xpt_flags &= ~SCSI_XPT_REGD;
184
185
186
187
188 lpfc_nlp_put(ndlp);
189 return;
190 }
191
192 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE)
193 return;
194
195 if (rport->port_name != wwn_to_u64(ndlp->nlp_portname.u.wwn))
196 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
197 "6789 rport name %llx != node port name %llx",
198 rport->port_name,
199 wwn_to_u64(ndlp->nlp_portname.u.wwn));
200
201 evtp = &ndlp->dev_loss_evt;
202
203 if (!list_empty(&evtp->evt_listp)) {
204 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
205 "6790 rport name %llx dev_loss_evt pending\n",
206 rport->port_name);
207 return;
208 }
209
210 spin_lock_irqsave(&ndlp->lock, iflags);
211 ndlp->nlp_flag |= NLP_IN_DEV_LOSS;
212 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
213
214
215
216
217
218 ndlp->fc4_xpt_flags &= ~SCSI_XPT_REGD;
219 ((struct lpfc_rport_data *)rport->dd_data)->pnode = NULL;
220 ndlp->rport = NULL;
221 spin_unlock_irqrestore(&ndlp->lock, iflags);
222
223
224
225
226 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
227
228 spin_lock_irqsave(&phba->hbalock, iflags);
229 if (evtp->evt_arg1) {
230 evtp->evt = LPFC_EVT_DEV_LOSS;
231 list_add_tail(&evtp->evt_listp, &phba->work_list);
232 lpfc_worker_wake_up(phba);
233 }
234 spin_unlock_irqrestore(&phba->hbalock, iflags);
235
236 return;
237}
238
239
240
241
242
243
244
245
246static void lpfc_check_inactive_vmid_one(struct lpfc_vport *vport)
247{
248 u16 keep;
249 u32 difftime = 0, r, bucket;
250 u64 *lta;
251 int cpu;
252 struct lpfc_vmid *vmp;
253
254 write_lock(&vport->vmid_lock);
255
256 if (!vport->cur_vmid_cnt)
257 goto out;
258
259
260 hash_for_each(vport->hash_table, bucket, vmp, hnode) {
261 keep = 0;
262 if (vmp->flag & LPFC_VMID_REGISTERED) {
263
264
265 for_each_possible_cpu(cpu) {
266
267 lta = per_cpu_ptr(vmp->last_io_time, cpu);
268 if (!lta)
269 continue;
270 difftime = (jiffies) - (*lta);
271 if ((vport->vmid_inactivity_timeout *
272 JIFFIES_PER_HR) > difftime) {
273 keep = 1;
274 break;
275 }
276 }
277
278
279
280 if (!keep) {
281
282 vmp->flag = LPFC_VMID_DE_REGISTER;
283 write_unlock(&vport->vmid_lock);
284 if (vport->vmid_priority_tagging)
285 r = lpfc_vmid_uvem(vport, vmp, false);
286 else
287 r = lpfc_vmid_cmd(vport,
288 SLI_CTAS_DAPP_IDENT,
289 vmp);
290
291
292
293 write_lock(&vport->vmid_lock);
294 if (!r) {
295 struct lpfc_vmid *ht = vmp;
296
297 vport->cur_vmid_cnt--;
298 ht->flag = LPFC_VMID_SLOT_FREE;
299 free_percpu(ht->last_io_time);
300 ht->last_io_time = NULL;
301 hash_del(&ht->hnode);
302 }
303 }
304 }
305 }
306 out:
307 write_unlock(&vport->vmid_lock);
308}
309
310
311
312
313
314
315
316
317
318
319
320static void lpfc_check_inactive_vmid(struct lpfc_hba *phba)
321{
322 struct lpfc_vport *vport;
323 struct lpfc_vport **vports;
324 int i;
325
326 vports = lpfc_create_vport_work_array(phba);
327 if (!vports)
328 return;
329
330 for (i = 0; i <= phba->max_vports; i++) {
331 if ((!vports[i]) && (i == 0))
332 vport = phba->pport;
333 else
334 vport = vports[i];
335 if (!vport)
336 break;
337
338 lpfc_check_inactive_vmid_one(vport);
339 }
340 lpfc_destroy_vport_work_array(phba, vports);
341}
342
343
344
345
346
347
348
349
350
351
352
353static int
354lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp)
355{
356 struct lpfc_vport *vport;
357 struct lpfc_hba *phba;
358 uint8_t *name;
359 int warn_on = 0;
360 int fcf_inuse = 0;
361 unsigned long iflags;
362
363 vport = ndlp->vport;
364 name = (uint8_t *)&ndlp->nlp_portname;
365 phba = vport->phba;
366
367 spin_lock_irqsave(&ndlp->lock, iflags);
368 ndlp->nlp_flag &= ~NLP_IN_DEV_LOSS;
369 spin_unlock_irqrestore(&ndlp->lock, iflags);
370
371 if (phba->sli_rev == LPFC_SLI_REV4)
372 fcf_inuse = lpfc_fcf_inuse(phba);
373
374 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
375 "rport devlosstmo:did:x%x type:x%x id:x%x",
376 ndlp->nlp_DID, ndlp->nlp_type, ndlp->nlp_sid);
377
378 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
379 "3182 %s x%06x, nflag x%x xflags x%x refcnt %d\n",
380 __func__, ndlp->nlp_DID, ndlp->nlp_flag,
381 ndlp->fc4_xpt_flags, kref_read(&ndlp->kref));
382
383
384 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
385 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
386 "0284 Devloss timeout Ignored on "
387 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
388 "NPort x%x\n",
389 *name, *(name+1), *(name+2), *(name+3),
390 *(name+4), *(name+5), *(name+6), *(name+7),
391 ndlp->nlp_DID);
392 return fcf_inuse;
393 }
394
395
396 if (ndlp->nlp_type & NLP_FABRIC) {
397 lpfc_nlp_put(ndlp);
398 return fcf_inuse;
399 }
400
401 if (ndlp->nlp_sid != NLP_NO_SID) {
402 warn_on = 1;
403 lpfc_sli_abort_iocb(vport, ndlp->nlp_sid, 0, LPFC_CTX_TGT);
404 }
405
406 if (warn_on) {
407 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
408 "0203 Devloss timeout on "
409 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
410 "NPort x%06x Data: x%x x%x x%x\n",
411 *name, *(name+1), *(name+2), *(name+3),
412 *(name+4), *(name+5), *(name+6), *(name+7),
413 ndlp->nlp_DID, ndlp->nlp_flag,
414 ndlp->nlp_state, ndlp->nlp_rpi);
415 } else {
416 lpfc_printf_vlog(vport, KERN_INFO, LOG_TRACE_EVENT,
417 "0204 Devloss timeout on "
418 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
419 "NPort x%06x Data: x%x x%x x%x\n",
420 *name, *(name+1), *(name+2), *(name+3),
421 *(name+4), *(name+5), *(name+6), *(name+7),
422 ndlp->nlp_DID, ndlp->nlp_flag,
423 ndlp->nlp_state, ndlp->nlp_rpi);
424 }
425
426 if (!(ndlp->fc4_xpt_flags & NVME_XPT_REGD))
427 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
428
429 return fcf_inuse;
430}
431
432static void lpfc_check_vmid_qfpa_issue(struct lpfc_hba *phba)
433{
434 struct lpfc_vport *vport;
435 struct lpfc_vport **vports;
436 int i;
437
438 vports = lpfc_create_vport_work_array(phba);
439 if (!vports)
440 return;
441
442 for (i = 0; i <= phba->max_vports; i++) {
443 if ((!vports[i]) && (i == 0))
444 vport = phba->pport;
445 else
446 vport = vports[i];
447 if (!vport)
448 break;
449
450 if (vport->vmid_flag & LPFC_VMID_ISSUE_QFPA) {
451 if (!lpfc_issue_els_qfpa(vport))
452 vport->vmid_flag &= ~LPFC_VMID_ISSUE_QFPA;
453 }
454 }
455 lpfc_destroy_vport_work_array(phba, vports);
456}
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476static void
477lpfc_sli4_post_dev_loss_tmo_handler(struct lpfc_hba *phba, int fcf_inuse,
478 uint32_t nlp_did)
479{
480
481
482
483 if (!fcf_inuse)
484 return;
485
486 if ((phba->hba_flag & HBA_FIP_SUPPORT) && !lpfc_fcf_inuse(phba)) {
487 spin_lock_irq(&phba->hbalock);
488 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
489 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
490 spin_unlock_irq(&phba->hbalock);
491 return;
492 }
493 phba->hba_flag |= HBA_DEVLOSS_TMO;
494 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
495 "2847 Last remote node (x%x) using "
496 "FCF devloss tmo\n", nlp_did);
497 }
498 if (phba->fcf.fcf_flag & FCF_REDISC_PROG) {
499 spin_unlock_irq(&phba->hbalock);
500 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
501 "2868 Devloss tmo to FCF rediscovery "
502 "in progress\n");
503 return;
504 }
505 if (!(phba->hba_flag & (FCF_TS_INPROG | FCF_RR_INPROG))) {
506 spin_unlock_irq(&phba->hbalock);
507 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
508 "2869 Devloss tmo to idle FIP engine, "
509 "unreg in-use FCF and rescan.\n");
510
511 lpfc_unregister_fcf_rescan(phba);
512 return;
513 }
514 spin_unlock_irq(&phba->hbalock);
515 if (phba->hba_flag & FCF_TS_INPROG)
516 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
517 "2870 FCF table scan in progress\n");
518 if (phba->hba_flag & FCF_RR_INPROG)
519 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
520 "2871 FLOGI roundrobin FCF failover "
521 "in progress\n");
522 }
523 lpfc_unregister_unused_fcf(phba);
524}
525
526
527
528
529
530
531
532
533
534
535
536struct lpfc_fast_path_event *
537lpfc_alloc_fast_evt(struct lpfc_hba *phba) {
538 struct lpfc_fast_path_event *ret;
539
540
541 if (atomic_read(&phba->fast_event_count) > LPFC_MAX_EVT_COUNT)
542 return NULL;
543
544 ret = kzalloc(sizeof(struct lpfc_fast_path_event),
545 GFP_ATOMIC);
546 if (ret) {
547 atomic_inc(&phba->fast_event_count);
548 INIT_LIST_HEAD(&ret->work_evt.evt_listp);
549 ret->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT;
550 }
551 return ret;
552}
553
554
555
556
557
558
559
560
561
562void
563lpfc_free_fast_evt(struct lpfc_hba *phba,
564 struct lpfc_fast_path_event *evt) {
565
566 atomic_dec(&phba->fast_event_count);
567 kfree(evt);
568}
569
570
571
572
573
574
575
576
577
578
579static void
580lpfc_send_fastpath_evt(struct lpfc_hba *phba,
581 struct lpfc_work_evt *evtp)
582{
583 unsigned long evt_category, evt_sub_category;
584 struct lpfc_fast_path_event *fast_evt_data;
585 char *evt_data;
586 uint32_t evt_data_size;
587 struct Scsi_Host *shost;
588
589 fast_evt_data = container_of(evtp, struct lpfc_fast_path_event,
590 work_evt);
591
592 evt_category = (unsigned long) fast_evt_data->un.fabric_evt.event_type;
593 evt_sub_category = (unsigned long) fast_evt_data->un.
594 fabric_evt.subcategory;
595 shost = lpfc_shost_from_vport(fast_evt_data->vport);
596 if (evt_category == FC_REG_FABRIC_EVENT) {
597 if (evt_sub_category == LPFC_EVENT_FCPRDCHKERR) {
598 evt_data = (char *) &fast_evt_data->un.read_check_error;
599 evt_data_size = sizeof(fast_evt_data->un.
600 read_check_error);
601 } else if ((evt_sub_category == LPFC_EVENT_FABRIC_BUSY) ||
602 (evt_sub_category == LPFC_EVENT_PORT_BUSY)) {
603 evt_data = (char *) &fast_evt_data->un.fabric_evt;
604 evt_data_size = sizeof(fast_evt_data->un.fabric_evt);
605 } else {
606 lpfc_free_fast_evt(phba, fast_evt_data);
607 return;
608 }
609 } else if (evt_category == FC_REG_SCSI_EVENT) {
610 switch (evt_sub_category) {
611 case LPFC_EVENT_QFULL:
612 case LPFC_EVENT_DEVBSY:
613 evt_data = (char *) &fast_evt_data->un.scsi_evt;
614 evt_data_size = sizeof(fast_evt_data->un.scsi_evt);
615 break;
616 case LPFC_EVENT_CHECK_COND:
617 evt_data = (char *) &fast_evt_data->un.check_cond_evt;
618 evt_data_size = sizeof(fast_evt_data->un.
619 check_cond_evt);
620 break;
621 case LPFC_EVENT_VARQUEDEPTH:
622 evt_data = (char *) &fast_evt_data->un.queue_depth_evt;
623 evt_data_size = sizeof(fast_evt_data->un.
624 queue_depth_evt);
625 break;
626 default:
627 lpfc_free_fast_evt(phba, fast_evt_data);
628 return;
629 }
630 } else {
631 lpfc_free_fast_evt(phba, fast_evt_data);
632 return;
633 }
634
635 if (phba->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
636 fc_host_post_vendor_event(shost,
637 fc_get_event_number(),
638 evt_data_size,
639 evt_data,
640 LPFC_NL_VENDOR_ID);
641
642 lpfc_free_fast_evt(phba, fast_evt_data);
643 return;
644}
645
646static void
647lpfc_work_list_done(struct lpfc_hba *phba)
648{
649 struct lpfc_work_evt *evtp = NULL;
650 struct lpfc_nodelist *ndlp;
651 int free_evt;
652 int fcf_inuse;
653 uint32_t nlp_did;
654
655 spin_lock_irq(&phba->hbalock);
656 while (!list_empty(&phba->work_list)) {
657 list_remove_head((&phba->work_list), evtp, typeof(*evtp),
658 evt_listp);
659 spin_unlock_irq(&phba->hbalock);
660 free_evt = 1;
661 switch (evtp->evt) {
662 case LPFC_EVT_ELS_RETRY:
663 ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1);
664 lpfc_els_retry_delay_handler(ndlp);
665 free_evt = 0;
666
667
668
669 lpfc_nlp_put(ndlp);
670 break;
671 case LPFC_EVT_DEV_LOSS:
672 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
673 fcf_inuse = lpfc_dev_loss_tmo_handler(ndlp);
674 free_evt = 0;
675
676
677
678 nlp_did = ndlp->nlp_DID;
679 lpfc_nlp_put(ndlp);
680 if (phba->sli_rev == LPFC_SLI_REV4)
681 lpfc_sli4_post_dev_loss_tmo_handler(phba,
682 fcf_inuse,
683 nlp_did);
684 break;
685 case LPFC_EVT_RECOVER_PORT:
686 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
687 lpfc_sli_abts_recover_port(ndlp->vport, ndlp);
688 free_evt = 0;
689
690
691
692 lpfc_nlp_put(ndlp);
693 break;
694 case LPFC_EVT_ONLINE:
695 if (phba->link_state < LPFC_LINK_DOWN)
696 *(int *) (evtp->evt_arg1) = lpfc_online(phba);
697 else
698 *(int *) (evtp->evt_arg1) = 0;
699 complete((struct completion *)(evtp->evt_arg2));
700 break;
701 case LPFC_EVT_OFFLINE_PREP:
702 if (phba->link_state >= LPFC_LINK_DOWN)
703 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
704 *(int *)(evtp->evt_arg1) = 0;
705 complete((struct completion *)(evtp->evt_arg2));
706 break;
707 case LPFC_EVT_OFFLINE:
708 lpfc_offline(phba);
709 lpfc_sli_brdrestart(phba);
710 *(int *)(evtp->evt_arg1) =
711 lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY);
712 lpfc_unblock_mgmt_io(phba);
713 complete((struct completion *)(evtp->evt_arg2));
714 break;
715 case LPFC_EVT_WARM_START:
716 lpfc_offline(phba);
717 lpfc_reset_barrier(phba);
718 lpfc_sli_brdreset(phba);
719 lpfc_hba_down_post(phba);
720 *(int *)(evtp->evt_arg1) =
721 lpfc_sli_brdready(phba, HS_MBRDY);
722 lpfc_unblock_mgmt_io(phba);
723 complete((struct completion *)(evtp->evt_arg2));
724 break;
725 case LPFC_EVT_KILL:
726 lpfc_offline(phba);
727 *(int *)(evtp->evt_arg1)
728 = (phba->pport->stopped)
729 ? 0 : lpfc_sli_brdkill(phba);
730 lpfc_unblock_mgmt_io(phba);
731 complete((struct completion *)(evtp->evt_arg2));
732 break;
733 case LPFC_EVT_FASTPATH_MGMT_EVT:
734 lpfc_send_fastpath_evt(phba, evtp);
735 free_evt = 0;
736 break;
737 case LPFC_EVT_RESET_HBA:
738 if (!(phba->pport->load_flag & FC_UNLOADING))
739 lpfc_reset_hba(phba);
740 break;
741 }
742 if (free_evt)
743 kfree(evtp);
744 spin_lock_irq(&phba->hbalock);
745 }
746 spin_unlock_irq(&phba->hbalock);
747
748}
749
750static void
751lpfc_work_done(struct lpfc_hba *phba)
752{
753 struct lpfc_sli_ring *pring;
754 uint32_t ha_copy, status, control, work_port_events;
755 struct lpfc_vport **vports;
756 struct lpfc_vport *vport;
757 int i;
758
759 spin_lock_irq(&phba->hbalock);
760 ha_copy = phba->work_ha;
761 phba->work_ha = 0;
762 spin_unlock_irq(&phba->hbalock);
763
764
765 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC)
766 lpfc_sli4_post_async_mbox(phba);
767
768 if (ha_copy & HA_ERATT)
769
770 lpfc_handle_eratt(phba);
771
772 if (ha_copy & HA_MBATT)
773 lpfc_sli_handle_mb_event(phba);
774
775 if (ha_copy & HA_LATT)
776 lpfc_handle_latt(phba);
777
778
779 if (lpfc_is_vmid_enabled(phba)) {
780 if (phba->pport->work_port_events &
781 WORKER_CHECK_VMID_ISSUE_QFPA) {
782 lpfc_check_vmid_qfpa_issue(phba);
783 phba->pport->work_port_events &=
784 ~WORKER_CHECK_VMID_ISSUE_QFPA;
785 }
786 if (phba->pport->work_port_events &
787 WORKER_CHECK_INACTIVE_VMID) {
788 lpfc_check_inactive_vmid(phba);
789 phba->pport->work_port_events &=
790 ~WORKER_CHECK_INACTIVE_VMID;
791 }
792 }
793
794
795 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
796 if (phba->hba_flag & HBA_RRQ_ACTIVE)
797 lpfc_handle_rrq_active(phba);
798 if (phba->hba_flag & ELS_XRI_ABORT_EVENT)
799 lpfc_sli4_els_xri_abort_event_proc(phba);
800 if (phba->hba_flag & ASYNC_EVENT)
801 lpfc_sli4_async_event_proc(phba);
802 if (phba->hba_flag & HBA_POST_RECEIVE_BUFFER) {
803 spin_lock_irq(&phba->hbalock);
804 phba->hba_flag &= ~HBA_POST_RECEIVE_BUFFER;
805 spin_unlock_irq(&phba->hbalock);
806 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
807 }
808 if (phba->fcf.fcf_flag & FCF_REDISC_EVT)
809 lpfc_sli4_fcf_redisc_event_proc(phba);
810 }
811
812 vports = lpfc_create_vport_work_array(phba);
813 if (vports != NULL)
814 for (i = 0; i <= phba->max_vports; i++) {
815
816
817
818
819 if (vports[i] == NULL && i == 0)
820 vport = phba->pport;
821 else
822 vport = vports[i];
823 if (vport == NULL)
824 break;
825 spin_lock_irq(&vport->work_port_lock);
826 work_port_events = vport->work_port_events;
827 vport->work_port_events &= ~work_port_events;
828 spin_unlock_irq(&vport->work_port_lock);
829 if (work_port_events & WORKER_DISC_TMO)
830 lpfc_disc_timeout_handler(vport);
831 if (work_port_events & WORKER_ELS_TMO)
832 lpfc_els_timeout_handler(vport);
833 if (work_port_events & WORKER_HB_TMO)
834 lpfc_hb_timeout_handler(phba);
835 if (work_port_events & WORKER_MBOX_TMO)
836 lpfc_mbox_timeout_handler(phba);
837 if (work_port_events & WORKER_FABRIC_BLOCK_TMO)
838 lpfc_unblock_fabric_iocbs(phba);
839 if (work_port_events & WORKER_RAMP_DOWN_QUEUE)
840 lpfc_ramp_down_queue_handler(phba);
841 if (work_port_events & WORKER_DELAYED_DISC_TMO)
842 lpfc_delayed_disc_timeout_handler(vport);
843 }
844 lpfc_destroy_vport_work_array(phba, vports);
845
846 pring = lpfc_phba_elsring(phba);
847 status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
848 status >>= (4*LPFC_ELS_RING);
849 if (pring && (status & HA_RXMASK ||
850 pring->flag & LPFC_DEFERRED_RING_EVENT ||
851 phba->hba_flag & HBA_SP_QUEUE_EVT)) {
852 if (pring->flag & LPFC_STOP_IOCB_EVENT) {
853 pring->flag |= LPFC_DEFERRED_RING_EVENT;
854
855 if (!(phba->hba_flag & HBA_SP_QUEUE_EVT))
856 set_bit(LPFC_DATA_READY, &phba->data_flags);
857 } else {
858
859
860
861 if (phba->link_state >= LPFC_LINK_DOWN ||
862 phba->link_flag & LS_MDS_LOOPBACK) {
863 pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
864 lpfc_sli_handle_slow_ring_event(phba, pring,
865 (status &
866 HA_RXMASK));
867 }
868 }
869 if (phba->sli_rev == LPFC_SLI_REV4)
870 lpfc_drain_txq(phba);
871
872
873
874 if (phba->sli_rev <= LPFC_SLI_REV3) {
875 spin_lock_irq(&phba->hbalock);
876 control = readl(phba->HCregaddr);
877 if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) {
878 lpfc_debugfs_slow_ring_trc(phba,
879 "WRK Enable ring: cntl:x%x hacopy:x%x",
880 control, ha_copy, 0);
881
882 control |= (HC_R0INT_ENA << LPFC_ELS_RING);
883 writel(control, phba->HCregaddr);
884 readl(phba->HCregaddr);
885 } else {
886 lpfc_debugfs_slow_ring_trc(phba,
887 "WRK Ring ok: cntl:x%x hacopy:x%x",
888 control, ha_copy, 0);
889 }
890 spin_unlock_irq(&phba->hbalock);
891 }
892 }
893 lpfc_work_list_done(phba);
894}
895
896int
897lpfc_do_work(void *p)
898{
899 struct lpfc_hba *phba = p;
900 int rc;
901
902 set_user_nice(current, MIN_NICE);
903 current->flags |= PF_NOFREEZE;
904 phba->data_flags = 0;
905
906 while (!kthread_should_stop()) {
907
908 rc = wait_event_interruptible(phba->work_waitq,
909 (test_and_clear_bit(LPFC_DATA_READY,
910 &phba->data_flags)
911 || kthread_should_stop()));
912
913 if (rc) {
914 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
915 "0433 Wakeup on signal: rc=x%x\n", rc);
916 break;
917 }
918
919
920 lpfc_work_done(phba);
921 }
922 phba->worker_thread = NULL;
923 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
924 "0432 Worker thread stopped.\n");
925 return 0;
926}
927
928
929
930
931
932
933int
934lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2,
935 uint32_t evt)
936{
937 struct lpfc_work_evt *evtp;
938 unsigned long flags;
939
940
941
942
943
944 evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC);
945 if (!evtp)
946 return 0;
947
948 evtp->evt_arg1 = arg1;
949 evtp->evt_arg2 = arg2;
950 evtp->evt = evt;
951
952 spin_lock_irqsave(&phba->hbalock, flags);
953 list_add_tail(&evtp->evt_listp, &phba->work_list);
954 spin_unlock_irqrestore(&phba->hbalock, flags);
955
956 lpfc_worker_wake_up(phba);
957
958 return 1;
959}
960
961void
962lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove)
963{
964 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
965 struct lpfc_hba *phba = vport->phba;
966 struct lpfc_nodelist *ndlp, *next_ndlp;
967
968 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
969 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
970 continue;
971
972 if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) ||
973 ((vport->port_type == LPFC_NPIV_PORT) &&
974 ((ndlp->nlp_DID == NameServer_DID) ||
975 (ndlp->nlp_DID == FDMI_DID) ||
976 (ndlp->nlp_DID == Fabric_Cntl_DID))))
977 lpfc_unreg_rpi(vport, ndlp);
978
979
980 if ((phba->sli_rev < LPFC_SLI_REV4) &&
981 (!remove && ndlp->nlp_type & NLP_FABRIC))
982 continue;
983
984
985 if (phba->nvmet_support &&
986 ndlp->nlp_state == NLP_STE_UNMAPPED_NODE)
987 lpfc_nvmet_invalidate_host(phba, ndlp);
988
989 lpfc_disc_state_machine(vport, ndlp, NULL,
990 remove
991 ? NLP_EVT_DEVICE_RM
992 : NLP_EVT_DEVICE_RECOVERY);
993 }
994 if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) {
995 if (phba->sli_rev == LPFC_SLI_REV4)
996 lpfc_sli4_unreg_all_rpis(vport);
997 lpfc_mbx_unreg_vpi(vport);
998 spin_lock_irq(shost->host_lock);
999 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
1000 spin_unlock_irq(shost->host_lock);
1001 }
1002}
1003
1004void
1005lpfc_port_link_failure(struct lpfc_vport *vport)
1006{
1007 lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN);
1008
1009
1010 lpfc_cleanup_rcv_buffers(vport);
1011
1012
1013 lpfc_els_flush_rscn(vport);
1014
1015
1016 lpfc_els_flush_cmd(vport);
1017
1018 lpfc_cleanup_rpis(vport, 0);
1019
1020
1021 lpfc_can_disctmo(vport);
1022}
1023
1024void
1025lpfc_linkdown_port(struct lpfc_vport *vport)
1026{
1027 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1028
1029 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
1030 fc_host_post_event(shost, fc_get_event_number(),
1031 FCH_EVT_LINKDOWN, 0);
1032
1033 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1034 "Link Down: state:x%x rtry:x%x flg:x%x",
1035 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
1036
1037 lpfc_port_link_failure(vport);
1038
1039
1040 spin_lock_irq(shost->host_lock);
1041 vport->fc_flag &= ~FC_DISC_DELAYED;
1042 spin_unlock_irq(shost->host_lock);
1043 del_timer_sync(&vport->delayed_disc_tmo);
1044}
1045
1046int
1047lpfc_linkdown(struct lpfc_hba *phba)
1048{
1049 struct lpfc_vport *vport = phba->pport;
1050 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1051 struct lpfc_vport **vports;
1052 LPFC_MBOXQ_t *mb;
1053 int i;
1054
1055 if (phba->link_state == LPFC_LINK_DOWN)
1056 return 0;
1057
1058
1059 lpfc_scsi_dev_block(phba);
1060
1061 phba->defer_flogi_acc_flag = false;
1062
1063 spin_lock_irq(&phba->hbalock);
1064 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
1065 spin_unlock_irq(&phba->hbalock);
1066 if (phba->link_state > LPFC_LINK_DOWN) {
1067 phba->link_state = LPFC_LINK_DOWN;
1068 if (phba->sli4_hba.conf_trunk) {
1069 phba->trunk_link.link0.state = 0;
1070 phba->trunk_link.link1.state = 0;
1071 phba->trunk_link.link2.state = 0;
1072 phba->trunk_link.link3.state = 0;
1073 phba->sli4_hba.link_state.logical_speed =
1074 LPFC_LINK_SPEED_UNKNOWN;
1075 }
1076 spin_lock_irq(shost->host_lock);
1077 phba->pport->fc_flag &= ~FC_LBIT;
1078 spin_unlock_irq(shost->host_lock);
1079 }
1080 vports = lpfc_create_vport_work_array(phba);
1081 if (vports != NULL) {
1082 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
1083
1084 lpfc_linkdown_port(vports[i]);
1085
1086 vports[i]->fc_myDID = 0;
1087
1088 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1089 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
1090 if (phba->nvmet_support)
1091 lpfc_nvmet_update_targetport(phba);
1092 else
1093 lpfc_nvme_update_localport(vports[i]);
1094 }
1095 }
1096 }
1097 lpfc_destroy_vport_work_array(phba, vports);
1098
1099
1100 if (phba->sli_rev > LPFC_SLI_REV3)
1101 goto skip_unreg_did;
1102
1103 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1104 if (mb) {
1105 lpfc_unreg_did(phba, 0xffff, LPFC_UNREG_ALL_DFLT_RPIS, mb);
1106 mb->vport = vport;
1107 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1108 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
1109 == MBX_NOT_FINISHED) {
1110 mempool_free(mb, phba->mbox_mem_pool);
1111 }
1112 }
1113
1114 skip_unreg_did:
1115
1116 if (phba->pport->fc_flag & FC_PT2PT) {
1117 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1118 if (mb) {
1119 lpfc_config_link(phba, mb);
1120 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1121 mb->vport = vport;
1122 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
1123 == MBX_NOT_FINISHED) {
1124 mempool_free(mb, phba->mbox_mem_pool);
1125 }
1126 }
1127 spin_lock_irq(shost->host_lock);
1128 phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
1129 phba->pport->rcv_flogi_cnt = 0;
1130 spin_unlock_irq(shost->host_lock);
1131 }
1132 return 0;
1133}
1134
1135static void
1136lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport)
1137{
1138 struct lpfc_nodelist *ndlp;
1139
1140 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
1141 ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
1142
1143 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
1144 continue;
1145 if (ndlp->nlp_type & NLP_FABRIC) {
1146
1147
1148
1149 if (ndlp->nlp_DID != Fabric_DID)
1150 lpfc_unreg_rpi(vport, ndlp);
1151 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1152 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
1153
1154
1155
1156 lpfc_unreg_rpi(vport, ndlp);
1157 }
1158 }
1159}
1160
1161static void
1162lpfc_linkup_port(struct lpfc_vport *vport)
1163{
1164 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1165 struct lpfc_hba *phba = vport->phba;
1166
1167 if ((vport->load_flag & FC_UNLOADING) != 0)
1168 return;
1169
1170 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1171 "Link Up: top:x%x speed:x%x flg:x%x",
1172 phba->fc_topology, phba->fc_linkspeed, phba->link_flag);
1173
1174
1175 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1176 (vport != phba->pport))
1177 return;
1178
1179 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
1180 fc_host_post_event(shost, fc_get_event_number(),
1181 FCH_EVT_LINKUP, 0);
1182
1183 spin_lock_irq(shost->host_lock);
1184 vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
1185 FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
1186 vport->fc_flag |= FC_NDISC_ACTIVE;
1187 vport->fc_ns_retry = 0;
1188 spin_unlock_irq(shost->host_lock);
1189
1190 lpfc_linkup_cleanup_nodes(vport);
1191}
1192
1193static int
1194lpfc_linkup(struct lpfc_hba *phba)
1195{
1196 struct lpfc_vport **vports;
1197 int i;
1198 struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
1199
1200 phba->link_state = LPFC_LINK_UP;
1201
1202
1203 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
1204 del_timer_sync(&phba->fabric_block_timer);
1205
1206 vports = lpfc_create_vport_work_array(phba);
1207 if (vports != NULL)
1208 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
1209 lpfc_linkup_port(vports[i]);
1210 lpfc_destroy_vport_work_array(phba, vports);
1211
1212
1213
1214
1215
1216 spin_lock_irq(shost->host_lock);
1217 phba->pport->rcv_flogi_cnt = 0;
1218 spin_unlock_irq(shost->host_lock);
1219
1220
1221 phba->hba_flag &= ~(HBA_FLOGI_ISSUED);
1222 phba->defer_flogi_acc_flag = false;
1223
1224 return 0;
1225}
1226
1227
1228
1229
1230
1231
1232
1233static void
1234lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1235{
1236 struct lpfc_vport *vport = pmb->vport;
1237 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1238 struct lpfc_sli *psli = &phba->sli;
1239 MAILBOX_t *mb = &pmb->u.mb;
1240 uint32_t control;
1241
1242
1243 psli->sli3_ring[LPFC_EXTRA_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
1244 psli->sli3_ring[LPFC_FCP_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
1245
1246
1247 if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
1248
1249 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1250 "0320 CLEAR_LA mbxStatus error x%x hba "
1251 "state x%x\n",
1252 mb->mbxStatus, vport->port_state);
1253 phba->link_state = LPFC_HBA_ERROR;
1254 goto out;
1255 }
1256
1257 if (vport->port_type == LPFC_PHYSICAL_PORT)
1258 phba->link_state = LPFC_HBA_READY;
1259
1260 spin_lock_irq(&phba->hbalock);
1261 psli->sli_flag |= LPFC_PROCESS_LA;
1262 control = readl(phba->HCregaddr);
1263 control |= HC_LAINT_ENA;
1264 writel(control, phba->HCregaddr);
1265 readl(phba->HCregaddr);
1266 spin_unlock_irq(&phba->hbalock);
1267 mempool_free(pmb, phba->mbox_mem_pool);
1268 return;
1269
1270out:
1271
1272 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1273 "0225 Device Discovery completes\n");
1274 mempool_free(pmb, phba->mbox_mem_pool);
1275
1276 spin_lock_irq(shost->host_lock);
1277 vport->fc_flag &= ~FC_ABORT_DISCOVERY;
1278 spin_unlock_irq(shost->host_lock);
1279
1280 lpfc_can_disctmo(vport);
1281
1282
1283
1284 spin_lock_irq(&phba->hbalock);
1285 psli->sli_flag |= LPFC_PROCESS_LA;
1286 control = readl(phba->HCregaddr);
1287 control |= HC_LAINT_ENA;
1288 writel(control, phba->HCregaddr);
1289 readl(phba->HCregaddr);
1290 spin_unlock_irq(&phba->hbalock);
1291
1292 return;
1293}
1294
1295void
1296lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1297{
1298 struct lpfc_vport *vport = pmb->vport;
1299 LPFC_MBOXQ_t *sparam_mb;
1300 struct lpfc_dmabuf *sparam_mp;
1301 u16 status = pmb->u.mb.mbxStatus;
1302 int rc;
1303
1304 mempool_free(pmb, phba->mbox_mem_pool);
1305
1306 if (status)
1307 goto out;
1308
1309
1310 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1311 !(phba->hba_flag & HBA_FCOE_MODE) &&
1312 (phba->link_flag & LS_LOOPBACK_MODE))
1313 return;
1314
1315 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP &&
1316 vport->fc_flag & FC_PUBLIC_LOOP &&
1317 !(vport->fc_flag & FC_LBIT)) {
1318
1319
1320
1321
1322 lpfc_set_disctmo(vport);
1323 return;
1324 }
1325
1326
1327
1328
1329 if (vport->port_state != LPFC_FLOGI) {
1330
1331
1332
1333 if (phba->bbcredit_support && phba->cfg_enable_bbcr &&
1334 !(phba->link_flag & LS_LOOPBACK_MODE)) {
1335 sparam_mb = mempool_alloc(phba->mbox_mem_pool,
1336 GFP_KERNEL);
1337 if (!sparam_mb)
1338 goto sparam_out;
1339
1340 rc = lpfc_read_sparam(phba, sparam_mb, 0);
1341 if (rc) {
1342 mempool_free(sparam_mb, phba->mbox_mem_pool);
1343 goto sparam_out;
1344 }
1345 sparam_mb->vport = vport;
1346 sparam_mb->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
1347 rc = lpfc_sli_issue_mbox(phba, sparam_mb, MBX_NOWAIT);
1348 if (rc == MBX_NOT_FINISHED) {
1349 sparam_mp = (struct lpfc_dmabuf *)
1350 sparam_mb->ctx_buf;
1351 lpfc_mbuf_free(phba, sparam_mp->virt,
1352 sparam_mp->phys);
1353 kfree(sparam_mp);
1354 sparam_mb->ctx_buf = NULL;
1355 mempool_free(sparam_mb, phba->mbox_mem_pool);
1356 goto sparam_out;
1357 }
1358
1359 phba->hba_flag |= HBA_DEFER_FLOGI;
1360 } else {
1361 lpfc_initial_flogi(vport);
1362 }
1363 } else {
1364 if (vport->fc_flag & FC_PT2PT)
1365 lpfc_disc_start(vport);
1366 }
1367 return;
1368
1369out:
1370 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1371 "0306 CONFIG_LINK mbxStatus error x%x HBA state x%x\n",
1372 status, vport->port_state);
1373
1374sparam_out:
1375 lpfc_linkdown(phba);
1376
1377 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1378 "0200 CONFIG_LINK bad hba state x%x\n",
1379 vport->port_state);
1380
1381 lpfc_issue_clear_la(phba, vport);
1382 return;
1383}
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393void
1394lpfc_sli4_clear_fcf_rr_bmask(struct lpfc_hba *phba)
1395{
1396 struct lpfc_fcf_pri *fcf_pri;
1397 struct lpfc_fcf_pri *next_fcf_pri;
1398 memset(phba->fcf.fcf_rr_bmask, 0, sizeof(*phba->fcf.fcf_rr_bmask));
1399 spin_lock_irq(&phba->hbalock);
1400 list_for_each_entry_safe(fcf_pri, next_fcf_pri,
1401 &phba->fcf.fcf_pri_list, list) {
1402 list_del_init(&fcf_pri->list);
1403 fcf_pri->fcf_rec.flag = 0;
1404 }
1405 spin_unlock_irq(&phba->hbalock);
1406}
1407static void
1408lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1409{
1410 struct lpfc_vport *vport = mboxq->vport;
1411
1412 if (mboxq->u.mb.mbxStatus) {
1413 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1414 "2017 REG_FCFI mbxStatus error x%x "
1415 "HBA state x%x\n", mboxq->u.mb.mbxStatus,
1416 vport->port_state);
1417 goto fail_out;
1418 }
1419
1420
1421 phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, &mboxq->u.mqe.un.reg_fcfi);
1422
1423 spin_lock_irq(&phba->hbalock);
1424 phba->fcf.fcf_flag |= FCF_REGISTERED;
1425 spin_unlock_irq(&phba->hbalock);
1426
1427
1428 if ((!(phba->hba_flag & FCF_RR_INPROG)) &&
1429 lpfc_check_pending_fcoe_event(phba, LPFC_UNREG_FCF))
1430 goto fail_out;
1431
1432
1433 spin_lock_irq(&phba->hbalock);
1434 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
1435 phba->hba_flag &= ~FCF_TS_INPROG;
1436 if (vport->port_state != LPFC_FLOGI) {
1437 phba->hba_flag |= FCF_RR_INPROG;
1438 spin_unlock_irq(&phba->hbalock);
1439 lpfc_issue_init_vfi(vport);
1440 goto out;
1441 }
1442 spin_unlock_irq(&phba->hbalock);
1443 goto out;
1444
1445fail_out:
1446 spin_lock_irq(&phba->hbalock);
1447 phba->hba_flag &= ~FCF_RR_INPROG;
1448 spin_unlock_irq(&phba->hbalock);
1449out:
1450 mempool_free(mboxq, phba->mbox_mem_pool);
1451}
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462static uint32_t
1463lpfc_fab_name_match(uint8_t *fab_name, struct fcf_record *new_fcf_record)
1464{
1465 if (fab_name[0] != bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record))
1466 return 0;
1467 if (fab_name[1] != bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record))
1468 return 0;
1469 if (fab_name[2] != bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record))
1470 return 0;
1471 if (fab_name[3] != bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record))
1472 return 0;
1473 if (fab_name[4] != bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record))
1474 return 0;
1475 if (fab_name[5] != bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record))
1476 return 0;
1477 if (fab_name[6] != bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record))
1478 return 0;
1479 if (fab_name[7] != bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record))
1480 return 0;
1481 return 1;
1482}
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493static uint32_t
1494lpfc_sw_name_match(uint8_t *sw_name, struct fcf_record *new_fcf_record)
1495{
1496 if (sw_name[0] != bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record))
1497 return 0;
1498 if (sw_name[1] != bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record))
1499 return 0;
1500 if (sw_name[2] != bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record))
1501 return 0;
1502 if (sw_name[3] != bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record))
1503 return 0;
1504 if (sw_name[4] != bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record))
1505 return 0;
1506 if (sw_name[5] != bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record))
1507 return 0;
1508 if (sw_name[6] != bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record))
1509 return 0;
1510 if (sw_name[7] != bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record))
1511 return 0;
1512 return 1;
1513}
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524static uint32_t
1525lpfc_mac_addr_match(uint8_t *mac_addr, struct fcf_record *new_fcf_record)
1526{
1527 if (mac_addr[0] != bf_get(lpfc_fcf_record_mac_0, new_fcf_record))
1528 return 0;
1529 if (mac_addr[1] != bf_get(lpfc_fcf_record_mac_1, new_fcf_record))
1530 return 0;
1531 if (mac_addr[2] != bf_get(lpfc_fcf_record_mac_2, new_fcf_record))
1532 return 0;
1533 if (mac_addr[3] != bf_get(lpfc_fcf_record_mac_3, new_fcf_record))
1534 return 0;
1535 if (mac_addr[4] != bf_get(lpfc_fcf_record_mac_4, new_fcf_record))
1536 return 0;
1537 if (mac_addr[5] != bf_get(lpfc_fcf_record_mac_5, new_fcf_record))
1538 return 0;
1539 return 1;
1540}
1541
1542static bool
1543lpfc_vlan_id_match(uint16_t curr_vlan_id, uint16_t new_vlan_id)
1544{
1545 return (curr_vlan_id == new_vlan_id);
1546}
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558static void
1559__lpfc_update_fcf_record_pri(struct lpfc_hba *phba, uint16_t fcf_index,
1560 struct fcf_record *new_fcf_record
1561 )
1562{
1563 struct lpfc_fcf_pri *fcf_pri;
1564
1565 fcf_pri = &phba->fcf.fcf_pri[fcf_index];
1566 fcf_pri->fcf_rec.fcf_index = fcf_index;
1567
1568 fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority;
1569
1570}
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580static void
1581lpfc_copy_fcf_record(struct lpfc_fcf_rec *fcf_rec,
1582 struct fcf_record *new_fcf_record)
1583{
1584
1585 fcf_rec->fabric_name[0] =
1586 bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record);
1587 fcf_rec->fabric_name[1] =
1588 bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record);
1589 fcf_rec->fabric_name[2] =
1590 bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record);
1591 fcf_rec->fabric_name[3] =
1592 bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record);
1593 fcf_rec->fabric_name[4] =
1594 bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record);
1595 fcf_rec->fabric_name[5] =
1596 bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record);
1597 fcf_rec->fabric_name[6] =
1598 bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record);
1599 fcf_rec->fabric_name[7] =
1600 bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record);
1601
1602 fcf_rec->mac_addr[0] = bf_get(lpfc_fcf_record_mac_0, new_fcf_record);
1603 fcf_rec->mac_addr[1] = bf_get(lpfc_fcf_record_mac_1, new_fcf_record);
1604 fcf_rec->mac_addr[2] = bf_get(lpfc_fcf_record_mac_2, new_fcf_record);
1605 fcf_rec->mac_addr[3] = bf_get(lpfc_fcf_record_mac_3, new_fcf_record);
1606 fcf_rec->mac_addr[4] = bf_get(lpfc_fcf_record_mac_4, new_fcf_record);
1607 fcf_rec->mac_addr[5] = bf_get(lpfc_fcf_record_mac_5, new_fcf_record);
1608
1609 fcf_rec->fcf_indx = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
1610
1611 fcf_rec->priority = new_fcf_record->fip_priority;
1612
1613 fcf_rec->switch_name[0] =
1614 bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record);
1615 fcf_rec->switch_name[1] =
1616 bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record);
1617 fcf_rec->switch_name[2] =
1618 bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record);
1619 fcf_rec->switch_name[3] =
1620 bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record);
1621 fcf_rec->switch_name[4] =
1622 bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record);
1623 fcf_rec->switch_name[5] =
1624 bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record);
1625 fcf_rec->switch_name[6] =
1626 bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record);
1627 fcf_rec->switch_name[7] =
1628 bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record);
1629}
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644static void
1645__lpfc_update_fcf_record(struct lpfc_hba *phba, struct lpfc_fcf_rec *fcf_rec,
1646 struct fcf_record *new_fcf_record, uint32_t addr_mode,
1647 uint16_t vlan_id, uint32_t flag)
1648{
1649 lockdep_assert_held(&phba->hbalock);
1650
1651
1652 lpfc_copy_fcf_record(fcf_rec, new_fcf_record);
1653
1654 fcf_rec->addr_mode = addr_mode;
1655 fcf_rec->vlan_id = vlan_id;
1656 fcf_rec->flag |= (flag | RECORD_VALID);
1657 __lpfc_update_fcf_record_pri(phba,
1658 bf_get(lpfc_fcf_record_fcf_index, new_fcf_record),
1659 new_fcf_record);
1660}
1661
1662
1663
1664
1665
1666
1667
1668
1669static void
1670lpfc_register_fcf(struct lpfc_hba *phba)
1671{
1672 LPFC_MBOXQ_t *fcf_mbxq;
1673 int rc;
1674
1675 spin_lock_irq(&phba->hbalock);
1676
1677 if (!(phba->fcf.fcf_flag & FCF_AVAILABLE)) {
1678 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1679 spin_unlock_irq(&phba->hbalock);
1680 return;
1681 }
1682
1683
1684 if (phba->fcf.fcf_flag & FCF_REGISTERED) {
1685 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
1686 phba->hba_flag &= ~FCF_TS_INPROG;
1687 if (phba->pport->port_state != LPFC_FLOGI &&
1688 phba->pport->fc_flag & FC_FABRIC) {
1689 phba->hba_flag |= FCF_RR_INPROG;
1690 spin_unlock_irq(&phba->hbalock);
1691 lpfc_initial_flogi(phba->pport);
1692 return;
1693 }
1694 spin_unlock_irq(&phba->hbalock);
1695 return;
1696 }
1697 spin_unlock_irq(&phba->hbalock);
1698
1699 fcf_mbxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1700 if (!fcf_mbxq) {
1701 spin_lock_irq(&phba->hbalock);
1702 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1703 spin_unlock_irq(&phba->hbalock);
1704 return;
1705 }
1706
1707 lpfc_reg_fcfi(phba, fcf_mbxq);
1708 fcf_mbxq->vport = phba->pport;
1709 fcf_mbxq->mbox_cmpl = lpfc_mbx_cmpl_reg_fcfi;
1710 rc = lpfc_sli_issue_mbox(phba, fcf_mbxq, MBX_NOWAIT);
1711 if (rc == MBX_NOT_FINISHED) {
1712 spin_lock_irq(&phba->hbalock);
1713 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1714 spin_unlock_irq(&phba->hbalock);
1715 mempool_free(fcf_mbxq, phba->mbox_mem_pool);
1716 }
1717
1718 return;
1719}
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739static int
1740lpfc_match_fcf_conn_list(struct lpfc_hba *phba,
1741 struct fcf_record *new_fcf_record,
1742 uint32_t *boot_flag, uint32_t *addr_mode,
1743 uint16_t *vlan_id)
1744{
1745 struct lpfc_fcf_conn_entry *conn_entry;
1746 int i, j, fcf_vlan_id = 0;
1747
1748
1749 for (i = 0; i < 512; i++) {
1750 if (new_fcf_record->vlan_bitmap[i]) {
1751 fcf_vlan_id = i * 8;
1752 j = 0;
1753 while (!((new_fcf_record->vlan_bitmap[i] >> j) & 1)) {
1754 j++;
1755 fcf_vlan_id++;
1756 }
1757 break;
1758 }
1759 }
1760
1761
1762 if (!bf_get(lpfc_fcf_record_fcf_avail, new_fcf_record) ||
1763 !bf_get(lpfc_fcf_record_fcf_valid, new_fcf_record) ||
1764 bf_get(lpfc_fcf_record_fcf_sol, new_fcf_record))
1765 return 0;
1766
1767 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
1768 *boot_flag = 0;
1769 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1770 new_fcf_record);
1771 if (phba->valid_vlan)
1772 *vlan_id = phba->vlan_id;
1773 else
1774 *vlan_id = LPFC_FCOE_NULL_VID;
1775 return 1;
1776 }
1777
1778
1779
1780
1781
1782 if (list_empty(&phba->fcf_conn_rec_list)) {
1783 *boot_flag = 0;
1784 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1785 new_fcf_record);
1786
1787
1788
1789
1790
1791 if (*addr_mode & LPFC_FCF_FPMA)
1792 *addr_mode = LPFC_FCF_FPMA;
1793
1794
1795 if (fcf_vlan_id)
1796 *vlan_id = fcf_vlan_id;
1797 else
1798 *vlan_id = LPFC_FCOE_NULL_VID;
1799 return 1;
1800 }
1801
1802 list_for_each_entry(conn_entry,
1803 &phba->fcf_conn_rec_list, list) {
1804 if (!(conn_entry->conn_rec.flags & FCFCNCT_VALID))
1805 continue;
1806
1807 if ((conn_entry->conn_rec.flags & FCFCNCT_FBNM_VALID) &&
1808 !lpfc_fab_name_match(conn_entry->conn_rec.fabric_name,
1809 new_fcf_record))
1810 continue;
1811 if ((conn_entry->conn_rec.flags & FCFCNCT_SWNM_VALID) &&
1812 !lpfc_sw_name_match(conn_entry->conn_rec.switch_name,
1813 new_fcf_record))
1814 continue;
1815 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) {
1816
1817
1818
1819
1820 if (!(new_fcf_record->vlan_bitmap
1821 [conn_entry->conn_rec.vlan_tag / 8] &
1822 (1 << (conn_entry->conn_rec.vlan_tag % 8))))
1823 continue;
1824 }
1825
1826
1827
1828
1829
1830 if (!(bf_get(lpfc_fcf_record_mac_addr_prov, new_fcf_record)
1831 & (LPFC_FCF_FPMA | LPFC_FCF_SPMA)))
1832 continue;
1833
1834
1835
1836
1837
1838 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1839 !(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)) {
1840
1841
1842
1843
1844 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1845 !(bf_get(lpfc_fcf_record_mac_addr_prov,
1846 new_fcf_record) & LPFC_FCF_SPMA))
1847 continue;
1848
1849
1850
1851
1852 if (!(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1853 !(bf_get(lpfc_fcf_record_mac_addr_prov,
1854 new_fcf_record) & LPFC_FCF_FPMA))
1855 continue;
1856 }
1857
1858
1859
1860
1861 if (conn_entry->conn_rec.flags & FCFCNCT_BOOT)
1862 *boot_flag = 1;
1863 else
1864 *boot_flag = 0;
1865
1866
1867
1868
1869
1870
1871 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1872 new_fcf_record);
1873
1874
1875
1876
1877 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1878 (!(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)))
1879 *addr_mode = (conn_entry->conn_rec.flags &
1880 FCFCNCT_AM_SPMA) ?
1881 LPFC_FCF_SPMA : LPFC_FCF_FPMA;
1882
1883
1884
1885
1886 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1887 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
1888 (conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1889 (*addr_mode & LPFC_FCF_SPMA))
1890 *addr_mode = LPFC_FCF_SPMA;
1891 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1892 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
1893 !(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1894 (*addr_mode & LPFC_FCF_FPMA))
1895 *addr_mode = LPFC_FCF_FPMA;
1896
1897
1898 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID)
1899 *vlan_id = conn_entry->conn_rec.vlan_tag;
1900
1901
1902
1903
1904 else if (fcf_vlan_id)
1905 *vlan_id = fcf_vlan_id;
1906 else
1907 *vlan_id = LPFC_FCOE_NULL_VID;
1908
1909 return 1;
1910 }
1911
1912 return 0;
1913}
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924int
1925lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf)
1926{
1927
1928
1929
1930
1931 if ((phba->link_state >= LPFC_LINK_UP) &&
1932 (phba->fcoe_eventtag == phba->fcoe_eventtag_at_fcf_scan))
1933 return 0;
1934
1935 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1936 "2768 Pending link or FCF event during current "
1937 "handling of the previous event: link_state:x%x, "
1938 "evt_tag_at_scan:x%x, evt_tag_current:x%x\n",
1939 phba->link_state, phba->fcoe_eventtag_at_fcf_scan,
1940 phba->fcoe_eventtag);
1941
1942 spin_lock_irq(&phba->hbalock);
1943 phba->fcf.fcf_flag &= ~FCF_AVAILABLE;
1944 spin_unlock_irq(&phba->hbalock);
1945
1946 if (phba->link_state >= LPFC_LINK_UP) {
1947 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
1948 "2780 Restart FCF table scan due to "
1949 "pending FCF event:evt_tag_at_scan:x%x, "
1950 "evt_tag_current:x%x\n",
1951 phba->fcoe_eventtag_at_fcf_scan,
1952 phba->fcoe_eventtag);
1953 lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
1954 } else {
1955
1956
1957
1958
1959 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
1960 "2833 Stop FCF discovery process due to link "
1961 "state change (x%x)\n", phba->link_state);
1962 spin_lock_irq(&phba->hbalock);
1963 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1964 phba->fcf.fcf_flag &= ~(FCF_REDISC_FOV | FCF_DISCOVERY);
1965 spin_unlock_irq(&phba->hbalock);
1966 }
1967
1968
1969 if (unreg_fcf) {
1970 spin_lock_irq(&phba->hbalock);
1971 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
1972 spin_unlock_irq(&phba->hbalock);
1973 lpfc_sli4_unregister_fcf(phba);
1974 }
1975 return 1;
1976}
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993static bool
1994lpfc_sli4_new_fcf_random_select(struct lpfc_hba *phba, uint32_t fcf_cnt)
1995{
1996 uint32_t rand_num;
1997
1998
1999 rand_num = 0xFFFF & prandom_u32();
2000
2001
2002 if ((fcf_cnt * rand_num) < 0xFFFF)
2003 return true;
2004 else
2005 return false;
2006}
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021static struct fcf_record *
2022lpfc_sli4_fcf_rec_mbox_parse(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
2023 uint16_t *next_fcf_index)
2024{
2025 void *virt_addr;
2026 struct lpfc_mbx_sge sge;
2027 struct lpfc_mbx_read_fcf_tbl *read_fcf;
2028 uint32_t shdr_status, shdr_add_status, if_type;
2029 union lpfc_sli4_cfg_shdr *shdr;
2030 struct fcf_record *new_fcf_record;
2031
2032
2033
2034
2035 lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
2036 if (unlikely(!mboxq->sge_array)) {
2037 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2038 "2524 Failed to get the non-embedded SGE "
2039 "virtual address\n");
2040 return NULL;
2041 }
2042 virt_addr = mboxq->sge_array->addr[0];
2043
2044 shdr = (union lpfc_sli4_cfg_shdr *)virt_addr;
2045 lpfc_sli_pcimem_bcopy(shdr, shdr,
2046 sizeof(union lpfc_sli4_cfg_shdr));
2047 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
2048 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
2049 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
2050 if (shdr_status || shdr_add_status) {
2051 if (shdr_status == STATUS_FCF_TABLE_EMPTY ||
2052 if_type == LPFC_SLI_INTF_IF_TYPE_2)
2053 lpfc_printf_log(phba, KERN_ERR,
2054 LOG_TRACE_EVENT,
2055 "2726 READ_FCF_RECORD Indicates empty "
2056 "FCF table.\n");
2057 else
2058 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2059 "2521 READ_FCF_RECORD mailbox failed "
2060 "with status x%x add_status x%x, "
2061 "mbx\n", shdr_status, shdr_add_status);
2062 return NULL;
2063 }
2064
2065
2066 read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
2067 lpfc_sli_pcimem_bcopy(read_fcf, read_fcf,
2068 sizeof(struct lpfc_mbx_read_fcf_tbl));
2069 *next_fcf_index = bf_get(lpfc_mbx_read_fcf_tbl_nxt_vindx, read_fcf);
2070 new_fcf_record = (struct fcf_record *)(virt_addr +
2071 sizeof(struct lpfc_mbx_read_fcf_tbl));
2072 lpfc_sli_pcimem_bcopy(new_fcf_record, new_fcf_record,
2073 offsetof(struct fcf_record, vlan_bitmap));
2074 new_fcf_record->word137 = le32_to_cpu(new_fcf_record->word137);
2075 new_fcf_record->word138 = le32_to_cpu(new_fcf_record->word138);
2076
2077 return new_fcf_record;
2078}
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090static void
2091lpfc_sli4_log_fcf_record_info(struct lpfc_hba *phba,
2092 struct fcf_record *fcf_record,
2093 uint16_t vlan_id,
2094 uint16_t next_fcf_index)
2095{
2096 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2097 "2764 READ_FCF_RECORD:\n"
2098 "\tFCF_Index : x%x\n"
2099 "\tFCF_Avail : x%x\n"
2100 "\tFCF_Valid : x%x\n"
2101 "\tFCF_SOL : x%x\n"
2102 "\tFIP_Priority : x%x\n"
2103 "\tMAC_Provider : x%x\n"
2104 "\tLowest VLANID : x%x\n"
2105 "\tFCF_MAC Addr : x%x:%x:%x:%x:%x:%x\n"
2106 "\tFabric_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
2107 "\tSwitch_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
2108 "\tNext_FCF_Index: x%x\n",
2109 bf_get(lpfc_fcf_record_fcf_index, fcf_record),
2110 bf_get(lpfc_fcf_record_fcf_avail, fcf_record),
2111 bf_get(lpfc_fcf_record_fcf_valid, fcf_record),
2112 bf_get(lpfc_fcf_record_fcf_sol, fcf_record),
2113 fcf_record->fip_priority,
2114 bf_get(lpfc_fcf_record_mac_addr_prov, fcf_record),
2115 vlan_id,
2116 bf_get(lpfc_fcf_record_mac_0, fcf_record),
2117 bf_get(lpfc_fcf_record_mac_1, fcf_record),
2118 bf_get(lpfc_fcf_record_mac_2, fcf_record),
2119 bf_get(lpfc_fcf_record_mac_3, fcf_record),
2120 bf_get(lpfc_fcf_record_mac_4, fcf_record),
2121 bf_get(lpfc_fcf_record_mac_5, fcf_record),
2122 bf_get(lpfc_fcf_record_fab_name_0, fcf_record),
2123 bf_get(lpfc_fcf_record_fab_name_1, fcf_record),
2124 bf_get(lpfc_fcf_record_fab_name_2, fcf_record),
2125 bf_get(lpfc_fcf_record_fab_name_3, fcf_record),
2126 bf_get(lpfc_fcf_record_fab_name_4, fcf_record),
2127 bf_get(lpfc_fcf_record_fab_name_5, fcf_record),
2128 bf_get(lpfc_fcf_record_fab_name_6, fcf_record),
2129 bf_get(lpfc_fcf_record_fab_name_7, fcf_record),
2130 bf_get(lpfc_fcf_record_switch_name_0, fcf_record),
2131 bf_get(lpfc_fcf_record_switch_name_1, fcf_record),
2132 bf_get(lpfc_fcf_record_switch_name_2, fcf_record),
2133 bf_get(lpfc_fcf_record_switch_name_3, fcf_record),
2134 bf_get(lpfc_fcf_record_switch_name_4, fcf_record),
2135 bf_get(lpfc_fcf_record_switch_name_5, fcf_record),
2136 bf_get(lpfc_fcf_record_switch_name_6, fcf_record),
2137 bf_get(lpfc_fcf_record_switch_name_7, fcf_record),
2138 next_fcf_index);
2139}
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154static bool
2155lpfc_sli4_fcf_record_match(struct lpfc_hba *phba,
2156 struct lpfc_fcf_rec *fcf_rec,
2157 struct fcf_record *new_fcf_record,
2158 uint16_t new_vlan_id)
2159{
2160 if (new_vlan_id != LPFC_FCOE_IGNORE_VID)
2161 if (!lpfc_vlan_id_match(fcf_rec->vlan_id, new_vlan_id))
2162 return false;
2163 if (!lpfc_mac_addr_match(fcf_rec->mac_addr, new_fcf_record))
2164 return false;
2165 if (!lpfc_sw_name_match(fcf_rec->switch_name, new_fcf_record))
2166 return false;
2167 if (!lpfc_fab_name_match(fcf_rec->fabric_name, new_fcf_record))
2168 return false;
2169 if (fcf_rec->priority != new_fcf_record->fip_priority)
2170 return false;
2171 return true;
2172}
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185int lpfc_sli4_fcf_rr_next_proc(struct lpfc_vport *vport, uint16_t fcf_index)
2186{
2187 struct lpfc_hba *phba = vport->phba;
2188 int rc;
2189
2190 if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) {
2191 spin_lock_irq(&phba->hbalock);
2192 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
2193 spin_unlock_irq(&phba->hbalock);
2194 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2195 "2872 Devloss tmo with no eligible "
2196 "FCF, unregister in-use FCF (x%x) "
2197 "and rescan FCF table\n",
2198 phba->fcf.current_rec.fcf_indx);
2199 lpfc_unregister_fcf_rescan(phba);
2200 goto stop_flogi_current_fcf;
2201 }
2202
2203 phba->hba_flag &= ~FCF_RR_INPROG;
2204
2205 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
2206 spin_unlock_irq(&phba->hbalock);
2207 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2208 "2865 No FCF available, stop roundrobin FCF "
2209 "failover and change port state:x%x/x%x\n",
2210 phba->pport->port_state, LPFC_VPORT_UNKNOWN);
2211 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
2212
2213 if (!phba->fcf.fcf_redisc_attempted) {
2214 lpfc_unregister_fcf(phba);
2215
2216 rc = lpfc_sli4_redisc_fcf_table(phba);
2217 if (!rc) {
2218 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2219 "3195 Rediscover FCF table\n");
2220 phba->fcf.fcf_redisc_attempted = 1;
2221 lpfc_sli4_clear_fcf_rr_bmask(phba);
2222 } else {
2223 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2224 "3196 Rediscover FCF table "
2225 "failed. Status:x%x\n", rc);
2226 }
2227 } else {
2228 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2229 "3197 Already rediscover FCF table "
2230 "attempted. No more retry\n");
2231 }
2232 goto stop_flogi_current_fcf;
2233 } else {
2234 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_ELS,
2235 "2794 Try FLOGI roundrobin FCF failover to "
2236 "(x%x)\n", fcf_index);
2237 rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba, fcf_index);
2238 if (rc)
2239 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
2240 "2761 FLOGI roundrobin FCF failover "
2241 "failed (rc:x%x) to read FCF (x%x)\n",
2242 rc, phba->fcf.current_rec.fcf_indx);
2243 else
2244 goto stop_flogi_current_fcf;
2245 }
2246 return 0;
2247
2248stop_flogi_current_fcf:
2249 lpfc_can_disctmo(vport);
2250 return 1;
2251}
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262static void lpfc_sli4_fcf_pri_list_del(struct lpfc_hba *phba,
2263 uint16_t fcf_index)
2264{
2265 struct lpfc_fcf_pri *new_fcf_pri;
2266
2267 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2268 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2269 "3058 deleting idx x%x pri x%x flg x%x\n",
2270 fcf_index, new_fcf_pri->fcf_rec.priority,
2271 new_fcf_pri->fcf_rec.flag);
2272 spin_lock_irq(&phba->hbalock);
2273 if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST) {
2274 if (phba->fcf.current_rec.priority ==
2275 new_fcf_pri->fcf_rec.priority)
2276 phba->fcf.eligible_fcf_cnt--;
2277 list_del_init(&new_fcf_pri->list);
2278 new_fcf_pri->fcf_rec.flag &= ~LPFC_FCF_ON_PRI_LIST;
2279 }
2280 spin_unlock_irq(&phba->hbalock);
2281}
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293void
2294lpfc_sli4_set_fcf_flogi_fail(struct lpfc_hba *phba, uint16_t fcf_index)
2295{
2296 struct lpfc_fcf_pri *new_fcf_pri;
2297 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2298 spin_lock_irq(&phba->hbalock);
2299 new_fcf_pri->fcf_rec.flag |= LPFC_FCF_FLOGI_FAILED;
2300 spin_unlock_irq(&phba->hbalock);
2301}
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319static int lpfc_sli4_fcf_pri_list_add(struct lpfc_hba *phba,
2320 uint16_t fcf_index,
2321 struct fcf_record *new_fcf_record)
2322{
2323 uint16_t current_fcf_pri;
2324 uint16_t last_index;
2325 struct lpfc_fcf_pri *fcf_pri;
2326 struct lpfc_fcf_pri *next_fcf_pri;
2327 struct lpfc_fcf_pri *new_fcf_pri;
2328 int ret;
2329
2330 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2331 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2332 "3059 adding idx x%x pri x%x flg x%x\n",
2333 fcf_index, new_fcf_record->fip_priority,
2334 new_fcf_pri->fcf_rec.flag);
2335 spin_lock_irq(&phba->hbalock);
2336 if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST)
2337 list_del_init(&new_fcf_pri->list);
2338 new_fcf_pri->fcf_rec.fcf_index = fcf_index;
2339 new_fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority;
2340 if (list_empty(&phba->fcf.fcf_pri_list)) {
2341 list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list);
2342 ret = lpfc_sli4_fcf_rr_index_set(phba,
2343 new_fcf_pri->fcf_rec.fcf_index);
2344 goto out;
2345 }
2346
2347 last_index = find_first_bit(phba->fcf.fcf_rr_bmask,
2348 LPFC_SLI4_FCF_TBL_INDX_MAX);
2349 if (last_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
2350 ret = 0;
2351 goto out;
2352 }
2353 current_fcf_pri = phba->fcf.fcf_pri[last_index].fcf_rec.priority;
2354 if (new_fcf_pri->fcf_rec.priority <= current_fcf_pri) {
2355 list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list);
2356 if (new_fcf_pri->fcf_rec.priority < current_fcf_pri) {
2357 memset(phba->fcf.fcf_rr_bmask, 0,
2358 sizeof(*phba->fcf.fcf_rr_bmask));
2359
2360 phba->fcf.eligible_fcf_cnt = 1;
2361 } else
2362
2363 phba->fcf.eligible_fcf_cnt++;
2364 ret = lpfc_sli4_fcf_rr_index_set(phba,
2365 new_fcf_pri->fcf_rec.fcf_index);
2366 goto out;
2367 }
2368
2369 list_for_each_entry_safe(fcf_pri, next_fcf_pri,
2370 &phba->fcf.fcf_pri_list, list) {
2371 if (new_fcf_pri->fcf_rec.priority <=
2372 fcf_pri->fcf_rec.priority) {
2373 if (fcf_pri->list.prev == &phba->fcf.fcf_pri_list)
2374 list_add(&new_fcf_pri->list,
2375 &phba->fcf.fcf_pri_list);
2376 else
2377 list_add(&new_fcf_pri->list,
2378 &((struct lpfc_fcf_pri *)
2379 fcf_pri->list.prev)->list);
2380 ret = 0;
2381 goto out;
2382 } else if (fcf_pri->list.next == &phba->fcf.fcf_pri_list
2383 || new_fcf_pri->fcf_rec.priority <
2384 next_fcf_pri->fcf_rec.priority) {
2385 list_add(&new_fcf_pri->list, &fcf_pri->list);
2386 ret = 0;
2387 goto out;
2388 }
2389 if (new_fcf_pri->fcf_rec.priority > fcf_pri->fcf_rec.priority)
2390 continue;
2391
2392 }
2393 ret = 1;
2394out:
2395
2396 new_fcf_pri->fcf_rec.flag = LPFC_FCF_ON_PRI_LIST;
2397 spin_unlock_irq(&phba->hbalock);
2398 return ret;
2399}
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416void
2417lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2418{
2419 struct fcf_record *new_fcf_record;
2420 uint32_t boot_flag, addr_mode;
2421 uint16_t fcf_index, next_fcf_index;
2422 struct lpfc_fcf_rec *fcf_rec = NULL;
2423 uint16_t vlan_id = LPFC_FCOE_NULL_VID;
2424 bool select_new_fcf;
2425 int rc;
2426
2427
2428 if (lpfc_check_pending_fcoe_event(phba, LPFC_SKIP_UNREG_FCF)) {
2429 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2430 return;
2431 }
2432
2433
2434 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2435 &next_fcf_index);
2436 if (!new_fcf_record) {
2437 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2438 "2765 Mailbox command READ_FCF_RECORD "
2439 "failed to retrieve a FCF record.\n");
2440
2441 spin_lock_irq(&phba->hbalock);
2442 phba->hba_flag &= ~FCF_TS_INPROG;
2443 spin_unlock_irq(&phba->hbalock);
2444 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2445 return;
2446 }
2447
2448
2449 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2450 &addr_mode, &vlan_id);
2451
2452
2453 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2454 next_fcf_index);
2455
2456
2457
2458
2459
2460
2461 if (!rc) {
2462 lpfc_sli4_fcf_pri_list_del(phba,
2463 bf_get(lpfc_fcf_record_fcf_index,
2464 new_fcf_record));
2465 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2466 "2781 FCF (x%x) failed connection "
2467 "list check: (x%x/x%x/%x)\n",
2468 bf_get(lpfc_fcf_record_fcf_index,
2469 new_fcf_record),
2470 bf_get(lpfc_fcf_record_fcf_avail,
2471 new_fcf_record),
2472 bf_get(lpfc_fcf_record_fcf_valid,
2473 new_fcf_record),
2474 bf_get(lpfc_fcf_record_fcf_sol,
2475 new_fcf_record));
2476 if ((phba->fcf.fcf_flag & FCF_IN_USE) &&
2477 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
2478 new_fcf_record, LPFC_FCOE_IGNORE_VID)) {
2479 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) !=
2480 phba->fcf.current_rec.fcf_indx) {
2481 lpfc_printf_log(phba, KERN_ERR,
2482 LOG_TRACE_EVENT,
2483 "2862 FCF (x%x) matches property "
2484 "of in-use FCF (x%x)\n",
2485 bf_get(lpfc_fcf_record_fcf_index,
2486 new_fcf_record),
2487 phba->fcf.current_rec.fcf_indx);
2488 goto read_next_fcf;
2489 }
2490
2491
2492
2493
2494
2495
2496 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND) &&
2497 !(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
2498 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2499 "2835 Invalid in-use FCF "
2500 "(x%x), enter FCF failover "
2501 "table scan.\n",
2502 phba->fcf.current_rec.fcf_indx);
2503 spin_lock_irq(&phba->hbalock);
2504 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
2505 spin_unlock_irq(&phba->hbalock);
2506 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2507 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2508 LPFC_FCOE_FCF_GET_FIRST);
2509 return;
2510 }
2511 }
2512 goto read_next_fcf;
2513 } else {
2514 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2515 rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index,
2516 new_fcf_record);
2517 if (rc)
2518 goto read_next_fcf;
2519 }
2520
2521
2522
2523
2524
2525
2526
2527 spin_lock_irq(&phba->hbalock);
2528 if (phba->fcf.fcf_flag & FCF_IN_USE) {
2529 if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV &&
2530 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
2531 new_fcf_record, vlan_id)) {
2532 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) ==
2533 phba->fcf.current_rec.fcf_indx) {
2534 phba->fcf.fcf_flag |= FCF_AVAILABLE;
2535 if (phba->fcf.fcf_flag & FCF_REDISC_PEND)
2536
2537 __lpfc_sli4_stop_fcf_redisc_wait_timer(
2538 phba);
2539 else if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2540
2541 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
2542 spin_unlock_irq(&phba->hbalock);
2543 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2544 "2836 New FCF matches in-use "
2545 "FCF (x%x), port_state:x%x, "
2546 "fc_flag:x%x\n",
2547 phba->fcf.current_rec.fcf_indx,
2548 phba->pport->port_state,
2549 phba->pport->fc_flag);
2550 goto out;
2551 } else
2552 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2553 "2863 New FCF (x%x) matches "
2554 "property of in-use FCF (x%x)\n",
2555 bf_get(lpfc_fcf_record_fcf_index,
2556 new_fcf_record),
2557 phba->fcf.current_rec.fcf_indx);
2558 }
2559
2560
2561
2562
2563
2564
2565
2566 if (!(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
2567 spin_unlock_irq(&phba->hbalock);
2568 goto read_next_fcf;
2569 }
2570 }
2571
2572
2573
2574
2575 if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2576 fcf_rec = &phba->fcf.failover_rec;
2577 else
2578 fcf_rec = &phba->fcf.current_rec;
2579
2580 if (phba->fcf.fcf_flag & FCF_AVAILABLE) {
2581
2582
2583
2584
2585
2586 if (boot_flag && !(fcf_rec->flag & BOOT_ENABLE)) {
2587
2588 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2589 "2837 Update current FCF record "
2590 "(x%x) with new FCF record (x%x)\n",
2591 fcf_rec->fcf_indx,
2592 bf_get(lpfc_fcf_record_fcf_index,
2593 new_fcf_record));
2594 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2595 addr_mode, vlan_id, BOOT_ENABLE);
2596 spin_unlock_irq(&phba->hbalock);
2597 goto read_next_fcf;
2598 }
2599
2600
2601
2602
2603
2604 if (!boot_flag && (fcf_rec->flag & BOOT_ENABLE)) {
2605 spin_unlock_irq(&phba->hbalock);
2606 goto read_next_fcf;
2607 }
2608
2609
2610
2611
2612 if (new_fcf_record->fip_priority < fcf_rec->priority) {
2613
2614 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2615 "2838 Update current FCF record "
2616 "(x%x) with new FCF record (x%x)\n",
2617 fcf_rec->fcf_indx,
2618 bf_get(lpfc_fcf_record_fcf_index,
2619 new_fcf_record));
2620 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2621 addr_mode, vlan_id, 0);
2622
2623 phba->fcf.eligible_fcf_cnt = 1;
2624 } else if (new_fcf_record->fip_priority == fcf_rec->priority) {
2625
2626 phba->fcf.eligible_fcf_cnt++;
2627 select_new_fcf = lpfc_sli4_new_fcf_random_select(phba,
2628 phba->fcf.eligible_fcf_cnt);
2629 if (select_new_fcf) {
2630 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2631 "2839 Update current FCF record "
2632 "(x%x) with new FCF record (x%x)\n",
2633 fcf_rec->fcf_indx,
2634 bf_get(lpfc_fcf_record_fcf_index,
2635 new_fcf_record));
2636
2637 __lpfc_update_fcf_record(phba, fcf_rec,
2638 new_fcf_record,
2639 addr_mode, vlan_id, 0);
2640 }
2641 }
2642 spin_unlock_irq(&phba->hbalock);
2643 goto read_next_fcf;
2644 }
2645
2646
2647
2648
2649 if (fcf_rec) {
2650 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2651 "2840 Update initial FCF candidate "
2652 "with FCF (x%x)\n",
2653 bf_get(lpfc_fcf_record_fcf_index,
2654 new_fcf_record));
2655 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2656 addr_mode, vlan_id, (boot_flag ?
2657 BOOT_ENABLE : 0));
2658 phba->fcf.fcf_flag |= FCF_AVAILABLE;
2659
2660 phba->fcf.eligible_fcf_cnt = 1;
2661 }
2662 spin_unlock_irq(&phba->hbalock);
2663 goto read_next_fcf;
2664
2665read_next_fcf:
2666 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2667 if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0) {
2668 if (phba->fcf.fcf_flag & FCF_REDISC_FOV) {
2669
2670
2671
2672
2673
2674
2675
2676
2677 if (!(phba->fcf.failover_rec.flag & RECORD_VALID)) {
2678 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2679 "2782 No suitable FCF found: "
2680 "(x%x/x%x)\n",
2681 phba->fcoe_eventtag_at_fcf_scan,
2682 bf_get(lpfc_fcf_record_fcf_index,
2683 new_fcf_record));
2684 spin_lock_irq(&phba->hbalock);
2685 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
2686 phba->hba_flag &= ~FCF_TS_INPROG;
2687 spin_unlock_irq(&phba->hbalock);
2688
2689 lpfc_printf_log(phba, KERN_INFO,
2690 LOG_FIP,
2691 "2864 On devloss tmo "
2692 "unreg in-use FCF and "
2693 "rescan FCF table\n");
2694 lpfc_unregister_fcf_rescan(phba);
2695 return;
2696 }
2697
2698
2699
2700 phba->hba_flag &= ~FCF_TS_INPROG;
2701 spin_unlock_irq(&phba->hbalock);
2702 return;
2703 }
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714 lpfc_unregister_fcf(phba);
2715
2716
2717 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2718 "2842 Replace in-use FCF (x%x) "
2719 "with failover FCF (x%x)\n",
2720 phba->fcf.current_rec.fcf_indx,
2721 phba->fcf.failover_rec.fcf_indx);
2722 memcpy(&phba->fcf.current_rec,
2723 &phba->fcf.failover_rec,
2724 sizeof(struct lpfc_fcf_rec));
2725
2726
2727
2728
2729
2730 spin_lock_irq(&phba->hbalock);
2731 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
2732 spin_unlock_irq(&phba->hbalock);
2733
2734 lpfc_register_fcf(phba);
2735 } else {
2736
2737
2738
2739
2740 if ((phba->fcf.fcf_flag & FCF_REDISC_EVT) ||
2741 (phba->fcf.fcf_flag & FCF_REDISC_PEND))
2742 return;
2743
2744 if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV &&
2745 phba->fcf.fcf_flag & FCF_IN_USE) {
2746
2747
2748
2749
2750
2751
2752 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2753 "2841 In-use FCF record (x%x) "
2754 "not reported, entering fast "
2755 "FCF failover mode scanning.\n",
2756 phba->fcf.current_rec.fcf_indx);
2757 spin_lock_irq(&phba->hbalock);
2758 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
2759 spin_unlock_irq(&phba->hbalock);
2760 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2761 LPFC_FCOE_FCF_GET_FIRST);
2762 return;
2763 }
2764
2765 lpfc_register_fcf(phba);
2766 }
2767 } else
2768 lpfc_sli4_fcf_scan_read_fcf_rec(phba, next_fcf_index);
2769 return;
2770
2771out:
2772 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2773 lpfc_register_fcf(phba);
2774
2775 return;
2776}
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793void
2794lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2795{
2796 struct fcf_record *new_fcf_record;
2797 uint32_t boot_flag, addr_mode;
2798 uint16_t next_fcf_index, fcf_index;
2799 uint16_t current_fcf_index;
2800 uint16_t vlan_id;
2801 int rc;
2802
2803
2804 if (phba->link_state < LPFC_LINK_UP) {
2805 spin_lock_irq(&phba->hbalock);
2806 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
2807 phba->hba_flag &= ~FCF_RR_INPROG;
2808 spin_unlock_irq(&phba->hbalock);
2809 goto out;
2810 }
2811
2812
2813 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2814 &next_fcf_index);
2815 if (!new_fcf_record) {
2816 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2817 "2766 Mailbox command READ_FCF_RECORD "
2818 "failed to retrieve a FCF record. "
2819 "hba_flg x%x fcf_flg x%x\n", phba->hba_flag,
2820 phba->fcf.fcf_flag);
2821 lpfc_unregister_fcf_rescan(phba);
2822 goto out;
2823 }
2824
2825
2826 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2827 &addr_mode, &vlan_id);
2828
2829
2830 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2831 next_fcf_index);
2832
2833 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2834 if (!rc) {
2835 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2836 "2848 Remove ineligible FCF (x%x) from "
2837 "from roundrobin bmask\n", fcf_index);
2838
2839 lpfc_sli4_fcf_rr_index_clear(phba, fcf_index);
2840
2841 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
2842 rc = lpfc_sli4_fcf_rr_next_proc(phba->pport, fcf_index);
2843 if (rc)
2844 goto out;
2845 goto error_out;
2846 }
2847
2848 if (fcf_index == phba->fcf.current_rec.fcf_indx) {
2849 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2850 "2760 Perform FLOGI roundrobin FCF failover: "
2851 "FCF (x%x) back to FCF (x%x)\n",
2852 phba->fcf.current_rec.fcf_indx, fcf_index);
2853
2854 msleep(500);
2855 lpfc_issue_init_vfi(phba->pport);
2856 goto out;
2857 }
2858
2859
2860 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2861 "2834 Update current FCF (x%x) with new FCF (x%x)\n",
2862 phba->fcf.failover_rec.fcf_indx, fcf_index);
2863 spin_lock_irq(&phba->hbalock);
2864 __lpfc_update_fcf_record(phba, &phba->fcf.failover_rec,
2865 new_fcf_record, addr_mode, vlan_id,
2866 (boot_flag ? BOOT_ENABLE : 0));
2867 spin_unlock_irq(&phba->hbalock);
2868
2869 current_fcf_index = phba->fcf.current_rec.fcf_indx;
2870
2871
2872 lpfc_unregister_fcf(phba);
2873
2874
2875 memcpy(&phba->fcf.current_rec, &phba->fcf.failover_rec,
2876 sizeof(struct lpfc_fcf_rec));
2877
2878 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2879 "2783 Perform FLOGI roundrobin FCF failover: FCF "
2880 "(x%x) to FCF (x%x)\n", current_fcf_index, fcf_index);
2881
2882error_out:
2883 lpfc_register_fcf(phba);
2884out:
2885 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2886}
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899void
2900lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2901{
2902 struct fcf_record *new_fcf_record;
2903 uint32_t boot_flag, addr_mode;
2904 uint16_t fcf_index, next_fcf_index;
2905 uint16_t vlan_id;
2906 int rc;
2907
2908
2909 if (phba->link_state < LPFC_LINK_UP)
2910 goto out;
2911
2912
2913 if (!(phba->fcf.fcf_flag & FCF_DISCOVERY))
2914 goto out;
2915
2916
2917 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2918 &next_fcf_index);
2919 if (!new_fcf_record) {
2920 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2921 "2767 Mailbox command READ_FCF_RECORD "
2922 "failed to retrieve a FCF record.\n");
2923 goto out;
2924 }
2925
2926
2927 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2928 &addr_mode, &vlan_id);
2929
2930
2931 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2932 next_fcf_index);
2933
2934 if (!rc)
2935 goto out;
2936
2937
2938 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2939
2940 rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index, new_fcf_record);
2941
2942out:
2943 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2944}
2945
2946
2947
2948
2949
2950
2951
2952
2953static void
2954lpfc_init_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2955{
2956 struct lpfc_vport *vport = mboxq->vport;
2957
2958
2959
2960
2961
2962 if (mboxq->u.mb.mbxStatus &&
2963 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
2964 LPFC_SLI_INTF_IF_TYPE_0) &&
2965 mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) {
2966 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2967 "2891 Init VFI mailbox failed 0x%x\n",
2968 mboxq->u.mb.mbxStatus);
2969 mempool_free(mboxq, phba->mbox_mem_pool);
2970 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2971 return;
2972 }
2973
2974 lpfc_initial_flogi(vport);
2975 mempool_free(mboxq, phba->mbox_mem_pool);
2976 return;
2977}
2978
2979
2980
2981
2982
2983
2984
2985
2986void
2987lpfc_issue_init_vfi(struct lpfc_vport *vport)
2988{
2989 LPFC_MBOXQ_t *mboxq;
2990 int rc;
2991 struct lpfc_hba *phba = vport->phba;
2992
2993 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2994 if (!mboxq) {
2995 lpfc_printf_vlog(vport, KERN_ERR,
2996 LOG_TRACE_EVENT, "2892 Failed to allocate "
2997 "init_vfi mailbox\n");
2998 return;
2999 }
3000 lpfc_init_vfi(mboxq, vport);
3001 mboxq->mbox_cmpl = lpfc_init_vfi_cmpl;
3002 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
3003 if (rc == MBX_NOT_FINISHED) {
3004 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3005 "2893 Failed to issue init_vfi mailbox\n");
3006 mempool_free(mboxq, vport->phba->mbox_mem_pool);
3007 }
3008}
3009
3010
3011
3012
3013
3014
3015
3016
3017void
3018lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
3019{
3020 struct lpfc_vport *vport = mboxq->vport;
3021 struct lpfc_nodelist *ndlp;
3022 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3023
3024 if (mboxq->u.mb.mbxStatus) {
3025 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3026 "2609 Init VPI mailbox failed 0x%x\n",
3027 mboxq->u.mb.mbxStatus);
3028 mempool_free(mboxq, phba->mbox_mem_pool);
3029 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3030 return;
3031 }
3032 spin_lock_irq(shost->host_lock);
3033 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
3034 spin_unlock_irq(shost->host_lock);
3035
3036
3037 if ((phba->pport == vport) || (vport->port_state == LPFC_FDISC)) {
3038 ndlp = lpfc_findnode_did(vport, Fabric_DID);
3039 if (!ndlp)
3040 lpfc_printf_vlog(vport, KERN_ERR,
3041 LOG_TRACE_EVENT,
3042 "2731 Cannot find fabric "
3043 "controller node\n");
3044 else
3045 lpfc_register_new_vport(phba, vport, ndlp);
3046 mempool_free(mboxq, phba->mbox_mem_pool);
3047 return;
3048 }
3049
3050 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
3051 lpfc_initial_fdisc(vport);
3052 else {
3053 lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP);
3054 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3055 "2606 No NPIV Fabric support\n");
3056 }
3057 mempool_free(mboxq, phba->mbox_mem_pool);
3058 return;
3059}
3060
3061
3062
3063
3064
3065
3066
3067
3068void
3069lpfc_issue_init_vpi(struct lpfc_vport *vport)
3070{
3071 LPFC_MBOXQ_t *mboxq;
3072 int rc, vpi;
3073
3074 if ((vport->port_type != LPFC_PHYSICAL_PORT) && (!vport->vpi)) {
3075 vpi = lpfc_alloc_vpi(vport->phba);
3076 if (!vpi) {
3077 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3078 "3303 Failed to obtain vport vpi\n");
3079 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3080 return;
3081 }
3082 vport->vpi = vpi;
3083 }
3084
3085 mboxq = mempool_alloc(vport->phba->mbox_mem_pool, GFP_KERNEL);
3086 if (!mboxq) {
3087 lpfc_printf_vlog(vport, KERN_ERR,
3088 LOG_TRACE_EVENT, "2607 Failed to allocate "
3089 "init_vpi mailbox\n");
3090 return;
3091 }
3092 lpfc_init_vpi(vport->phba, mboxq, vport->vpi);
3093 mboxq->vport = vport;
3094 mboxq->mbox_cmpl = lpfc_init_vpi_cmpl;
3095 rc = lpfc_sli_issue_mbox(vport->phba, mboxq, MBX_NOWAIT);
3096 if (rc == MBX_NOT_FINISHED) {
3097 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3098 "2608 Failed to issue init_vpi mailbox\n");
3099 mempool_free(mboxq, vport->phba->mbox_mem_pool);
3100 }
3101}
3102
3103
3104
3105
3106
3107
3108
3109
3110void
3111lpfc_start_fdiscs(struct lpfc_hba *phba)
3112{
3113 struct lpfc_vport **vports;
3114 int i;
3115
3116 vports = lpfc_create_vport_work_array(phba);
3117 if (vports != NULL) {
3118 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3119 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
3120 continue;
3121
3122 if (vports[i]->vpi > phba->max_vpi) {
3123 lpfc_vport_set_state(vports[i],
3124 FC_VPORT_FAILED);
3125 continue;
3126 }
3127 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3128 lpfc_vport_set_state(vports[i],
3129 FC_VPORT_LINKDOWN);
3130 continue;
3131 }
3132 if (vports[i]->fc_flag & FC_VPORT_NEEDS_INIT_VPI) {
3133 lpfc_issue_init_vpi(vports[i]);
3134 continue;
3135 }
3136 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
3137 lpfc_initial_fdisc(vports[i]);
3138 else {
3139 lpfc_vport_set_state(vports[i],
3140 FC_VPORT_NO_FABRIC_SUPP);
3141 lpfc_printf_vlog(vports[i], KERN_ERR,
3142 LOG_TRACE_EVENT,
3143 "0259 No NPIV "
3144 "Fabric support\n");
3145 }
3146 }
3147 }
3148 lpfc_destroy_vport_work_array(phba, vports);
3149}
3150
3151void
3152lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
3153{
3154 struct lpfc_dmabuf *dmabuf = mboxq->ctx_buf;
3155 struct lpfc_vport *vport = mboxq->vport;
3156 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3157
3158
3159
3160
3161
3162 if (mboxq->u.mb.mbxStatus &&
3163 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
3164 LPFC_SLI_INTF_IF_TYPE_0) &&
3165 mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) {
3166 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3167 "2018 REG_VFI mbxStatus error x%x "
3168 "HBA state x%x\n",
3169 mboxq->u.mb.mbxStatus, vport->port_state);
3170 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3171
3172 lpfc_disc_list_loopmap(vport);
3173
3174 lpfc_disc_start(vport);
3175 goto out_free_mem;
3176 }
3177 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3178 goto out_free_mem;
3179 }
3180
3181
3182
3183
3184
3185 if (vport->fc_flag & FC_VFI_REGISTERED)
3186 if (!(phba->sli_rev == LPFC_SLI_REV4 &&
3187 vport->fc_flag & FC_PT2PT))
3188 goto out_free_mem;
3189
3190
3191 spin_lock_irq(shost->host_lock);
3192 vport->vpi_state |= LPFC_VPI_REGISTERED;
3193 vport->fc_flag |= FC_VFI_REGISTERED;
3194 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
3195 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
3196 spin_unlock_irq(shost->host_lock);
3197
3198
3199 if ((phba->sli_rev == LPFC_SLI_REV4) &&
3200 (phba->link_flag & LS_LOOPBACK_MODE)) {
3201 phba->link_state = LPFC_HBA_READY;
3202 goto out_free_mem;
3203 }
3204
3205 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
3206 "3313 cmpl reg vfi port_state:%x fc_flag:%x myDid:%x "
3207 "alpacnt:%d LinkState:%x topology:%x\n",
3208 vport->port_state, vport->fc_flag, vport->fc_myDID,
3209 vport->phba->alpa_map[0],
3210 phba->link_state, phba->fc_topology);
3211
3212 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
3213
3214
3215
3216
3217 if ((vport->fc_flag & FC_PT2PT) ||
3218 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
3219 !(vport->fc_flag & FC_PUBLIC_LOOP))) {
3220
3221
3222 lpfc_disc_list_loopmap(vport);
3223
3224 if (vport->fc_flag & FC_PT2PT)
3225 vport->port_state = LPFC_VPORT_READY;
3226 else
3227 lpfc_disc_start(vport);
3228 } else {
3229 lpfc_start_fdiscs(phba);
3230 lpfc_do_scr_ns_plogi(phba, vport);
3231 }
3232 }
3233
3234out_free_mem:
3235 mempool_free(mboxq, phba->mbox_mem_pool);
3236 if (dmabuf) {
3237 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
3238 kfree(dmabuf);
3239 }
3240 return;
3241}
3242
3243static void
3244lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3245{
3246 MAILBOX_t *mb = &pmb->u.mb;
3247 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
3248 struct lpfc_vport *vport = pmb->vport;
3249 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3250 struct serv_parm *sp = &vport->fc_sparam;
3251 uint32_t ed_tov;
3252
3253
3254 if (mb->mbxStatus) {
3255
3256 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3257 "0319 READ_SPARAM mbxStatus error x%x "
3258 "hba state x%x>\n",
3259 mb->mbxStatus, vport->port_state);
3260 lpfc_linkdown(phba);
3261 goto out;
3262 }
3263
3264 memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt,
3265 sizeof (struct serv_parm));
3266
3267 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
3268 if (sp->cmn.edtovResolution)
3269 ed_tov = (ed_tov + 999999) / 1000000;
3270
3271 phba->fc_edtov = ed_tov;
3272 phba->fc_ratov = (2 * ed_tov) / 1000;
3273 if (phba->fc_ratov < FF_DEF_RATOV) {
3274
3275 phba->fc_ratov = FF_DEF_RATOV;
3276 }
3277
3278 lpfc_update_vport_wwn(vport);
3279 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
3280 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3281 memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn));
3282 memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn));
3283 }
3284
3285 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3286 kfree(mp);
3287 mempool_free(pmb, phba->mbox_mem_pool);
3288
3289
3290
3291
3292 if (phba->hba_flag & HBA_DEFER_FLOGI) {
3293 lpfc_initial_flogi(vport);
3294 phba->hba_flag &= ~HBA_DEFER_FLOGI;
3295 }
3296 return;
3297
3298out:
3299 pmb->ctx_buf = NULL;
3300 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3301 kfree(mp);
3302 lpfc_issue_clear_la(phba, vport);
3303 mempool_free(pmb, phba->mbox_mem_pool);
3304 return;
3305}
3306
3307static void
3308lpfc_mbx_process_link_up(struct lpfc_hba *phba, struct lpfc_mbx_read_top *la)
3309{
3310 struct lpfc_vport *vport = phba->pport;
3311 LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox = NULL;
3312 struct Scsi_Host *shost;
3313 int i;
3314 struct lpfc_dmabuf *mp;
3315 int rc;
3316 struct fcf_record *fcf_record;
3317 uint32_t fc_flags = 0;
3318 unsigned long iflags;
3319
3320 spin_lock_irqsave(&phba->hbalock, iflags);
3321 phba->fc_linkspeed = bf_get(lpfc_mbx_read_top_link_spd, la);
3322
3323 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
3324 switch (bf_get(lpfc_mbx_read_top_link_spd, la)) {
3325 case LPFC_LINK_SPEED_1GHZ:
3326 case LPFC_LINK_SPEED_2GHZ:
3327 case LPFC_LINK_SPEED_4GHZ:
3328 case LPFC_LINK_SPEED_8GHZ:
3329 case LPFC_LINK_SPEED_10GHZ:
3330 case LPFC_LINK_SPEED_16GHZ:
3331 case LPFC_LINK_SPEED_32GHZ:
3332 case LPFC_LINK_SPEED_64GHZ:
3333 case LPFC_LINK_SPEED_128GHZ:
3334 case LPFC_LINK_SPEED_256GHZ:
3335 break;
3336 default:
3337 phba->fc_linkspeed = LPFC_LINK_SPEED_UNKNOWN;
3338 break;
3339 }
3340 }
3341
3342 if (phba->fc_topology &&
3343 phba->fc_topology != bf_get(lpfc_mbx_read_top_topology, la)) {
3344 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
3345 "3314 Toplogy changed was 0x%x is 0x%x\n",
3346 phba->fc_topology,
3347 bf_get(lpfc_mbx_read_top_topology, la));
3348 phba->fc_topology_changed = 1;
3349 }
3350
3351 phba->fc_topology = bf_get(lpfc_mbx_read_top_topology, la);
3352 phba->link_flag &= ~(LS_NPIV_FAB_SUPPORTED | LS_CT_VEN_RPA);
3353
3354 shost = lpfc_shost_from_vport(vport);
3355 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3356 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
3357
3358
3359
3360
3361 if (phba->cfg_enable_npiv && phba->max_vpi)
3362 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3363 "1309 Link Up Event npiv not supported in loop "
3364 "topology\n");
3365
3366 if (bf_get(lpfc_mbx_read_top_il, la))
3367 fc_flags |= FC_LBIT;
3368
3369 vport->fc_myDID = bf_get(lpfc_mbx_read_top_alpa_granted, la);
3370 i = la->lilpBde64.tus.f.bdeSize;
3371
3372 if (i == 0) {
3373 phba->alpa_map[0] = 0;
3374 } else {
3375 if (vport->cfg_log_verbose & LOG_LINK_EVENT) {
3376 int numalpa, j, k;
3377 union {
3378 uint8_t pamap[16];
3379 struct {
3380 uint32_t wd1;
3381 uint32_t wd2;
3382 uint32_t wd3;
3383 uint32_t wd4;
3384 } pa;
3385 } un;
3386 numalpa = phba->alpa_map[0];
3387 j = 0;
3388 while (j < numalpa) {
3389 memset(un.pamap, 0, 16);
3390 for (k = 1; j < numalpa; k++) {
3391 un.pamap[k - 1] =
3392 phba->alpa_map[j + 1];
3393 j++;
3394 if (k == 16)
3395 break;
3396 }
3397
3398 lpfc_printf_log(phba,
3399 KERN_WARNING,
3400 LOG_LINK_EVENT,
3401 "1304 Link Up Event "
3402 "ALPA map Data: x%x "
3403 "x%x x%x x%x\n",
3404 un.pa.wd1, un.pa.wd2,
3405 un.pa.wd3, un.pa.wd4);
3406 }
3407 }
3408 }
3409 } else {
3410 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) {
3411 if (phba->max_vpi && phba->cfg_enable_npiv &&
3412 (phba->sli_rev >= LPFC_SLI_REV3))
3413 phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
3414 }
3415 vport->fc_myDID = phba->fc_pref_DID;
3416 fc_flags |= FC_LBIT;
3417 }
3418 spin_unlock_irqrestore(&phba->hbalock, iflags);
3419
3420 if (fc_flags) {
3421 spin_lock_irqsave(shost->host_lock, iflags);
3422 vport->fc_flag |= fc_flags;
3423 spin_unlock_irqrestore(shost->host_lock, iflags);
3424 }
3425
3426 lpfc_linkup(phba);
3427 sparam_mbox = NULL;
3428
3429 sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3430 if (!sparam_mbox)
3431 goto out;
3432
3433 rc = lpfc_read_sparam(phba, sparam_mbox, 0);
3434 if (rc) {
3435 mempool_free(sparam_mbox, phba->mbox_mem_pool);
3436 goto out;
3437 }
3438 sparam_mbox->vport = vport;
3439 sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
3440 rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT);
3441 if (rc == MBX_NOT_FINISHED) {
3442 mp = (struct lpfc_dmabuf *)sparam_mbox->ctx_buf;
3443 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3444 kfree(mp);
3445 mempool_free(sparam_mbox, phba->mbox_mem_pool);
3446 goto out;
3447 }
3448
3449 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
3450 cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3451 if (!cfglink_mbox)
3452 goto out;
3453 vport->port_state = LPFC_LOCAL_CFG_LINK;
3454 lpfc_config_link(phba, cfglink_mbox);
3455 cfglink_mbox->vport = vport;
3456 cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
3457 rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT);
3458 if (rc == MBX_NOT_FINISHED) {
3459 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
3460 goto out;
3461 }
3462 } else {
3463 vport->port_state = LPFC_VPORT_UNKNOWN;
3464
3465
3466
3467
3468
3469 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
3470 fcf_record = kzalloc(sizeof(struct fcf_record),
3471 GFP_KERNEL);
3472 if (unlikely(!fcf_record)) {
3473 lpfc_printf_log(phba, KERN_ERR,
3474 LOG_TRACE_EVENT,
3475 "2554 Could not allocate memory for "
3476 "fcf record\n");
3477 rc = -ENODEV;
3478 goto out;
3479 }
3480
3481 lpfc_sli4_build_dflt_fcf_record(phba, fcf_record,
3482 LPFC_FCOE_FCF_DEF_INDEX);
3483 rc = lpfc_sli4_add_fcf_record(phba, fcf_record);
3484 if (unlikely(rc)) {
3485 lpfc_printf_log(phba, KERN_ERR,
3486 LOG_TRACE_EVENT,
3487 "2013 Could not manually add FCF "
3488 "record 0, status %d\n", rc);
3489 rc = -ENODEV;
3490 kfree(fcf_record);
3491 goto out;
3492 }
3493 kfree(fcf_record);
3494 }
3495
3496
3497
3498
3499 spin_lock_irqsave(&phba->hbalock, iflags);
3500 if (phba->hba_flag & FCF_TS_INPROG) {
3501 spin_unlock_irqrestore(&phba->hbalock, iflags);
3502 return;
3503 }
3504
3505 phba->fcf.fcf_flag |= FCF_INIT_DISC;
3506 spin_unlock_irqrestore(&phba->hbalock, iflags);
3507 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
3508 "2778 Start FCF table scan at linkup\n");
3509 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
3510 LPFC_FCOE_FCF_GET_FIRST);
3511 if (rc) {
3512 spin_lock_irqsave(&phba->hbalock, iflags);
3513 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
3514 spin_unlock_irqrestore(&phba->hbalock, iflags);
3515 goto out;
3516 }
3517
3518 lpfc_sli4_clear_fcf_rr_bmask(phba);
3519 }
3520
3521
3522 memset(phba->os_host_name, 0, sizeof(phba->os_host_name));
3523 scnprintf(phba->os_host_name, sizeof(phba->os_host_name), "%s",
3524 init_utsname()->nodename);
3525 return;
3526out:
3527 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3528 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3529 "0263 Discovery Mailbox error: state: 0x%x : x%px x%px\n",
3530 vport->port_state, sparam_mbox, cfglink_mbox);
3531 lpfc_issue_clear_la(phba, vport);
3532 return;
3533}
3534
3535static void
3536lpfc_enable_la(struct lpfc_hba *phba)
3537{
3538 uint32_t control;
3539 struct lpfc_sli *psli = &phba->sli;
3540 spin_lock_irq(&phba->hbalock);
3541 psli->sli_flag |= LPFC_PROCESS_LA;
3542 if (phba->sli_rev <= LPFC_SLI_REV3) {
3543 control = readl(phba->HCregaddr);
3544 control |= HC_LAINT_ENA;
3545 writel(control, phba->HCregaddr);
3546 readl(phba->HCregaddr);
3547 }
3548 spin_unlock_irq(&phba->hbalock);
3549}
3550
3551static void
3552lpfc_mbx_issue_link_down(struct lpfc_hba *phba)
3553{
3554 lpfc_linkdown(phba);
3555 lpfc_enable_la(phba);
3556 lpfc_unregister_unused_fcf(phba);
3557
3558}
3559
3560
3561
3562
3563
3564
3565
3566
3567void
3568lpfc_mbx_cmpl_read_topology(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3569{
3570 struct lpfc_vport *vport = pmb->vport;
3571 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3572 struct lpfc_mbx_read_top *la;
3573 struct lpfc_sli_ring *pring;
3574 MAILBOX_t *mb = &pmb->u.mb;
3575 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
3576 uint8_t attn_type;
3577 unsigned long iflags;
3578
3579
3580 pring = lpfc_phba_elsring(phba);
3581 if (pring)
3582 pring->flag &= ~LPFC_STOP_IOCB_EVENT;
3583
3584
3585 if (mb->mbxStatus) {
3586 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
3587 "1307 READ_LA mbox error x%x state x%x\n",
3588 mb->mbxStatus, vport->port_state);
3589 lpfc_mbx_issue_link_down(phba);
3590 phba->link_state = LPFC_HBA_ERROR;
3591 goto lpfc_mbx_cmpl_read_topology_free_mbuf;
3592 }
3593
3594 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
3595 attn_type = bf_get(lpfc_mbx_read_top_att_type, la);
3596
3597 memcpy(&phba->alpa_map[0], mp->virt, 128);
3598
3599 spin_lock_irqsave(shost->host_lock, iflags);
3600 if (bf_get(lpfc_mbx_read_top_pb, la))
3601 vport->fc_flag |= FC_BYPASSED_MODE;
3602 else
3603 vport->fc_flag &= ~FC_BYPASSED_MODE;
3604 spin_unlock_irqrestore(shost->host_lock, iflags);
3605
3606 if (phba->fc_eventTag <= la->eventTag) {
3607 phba->fc_stat.LinkMultiEvent++;
3608 if (attn_type == LPFC_ATT_LINK_UP)
3609 if (phba->fc_eventTag != 0)
3610 lpfc_linkdown(phba);
3611 }
3612
3613 phba->fc_eventTag = la->eventTag;
3614 if (phba->sli_rev < LPFC_SLI_REV4) {
3615 spin_lock_irqsave(&phba->hbalock, iflags);
3616 if (bf_get(lpfc_mbx_read_top_mm, la))
3617 phba->sli.sli_flag |= LPFC_MENLO_MAINT;
3618 else
3619 phba->sli.sli_flag &= ~LPFC_MENLO_MAINT;
3620 spin_unlock_irqrestore(&phba->hbalock, iflags);
3621 }
3622
3623 phba->link_events++;
3624 if ((attn_type == LPFC_ATT_LINK_UP) &&
3625 !(phba->sli.sli_flag & LPFC_MENLO_MAINT)) {
3626 phba->fc_stat.LinkUp++;
3627 if (phba->link_flag & LS_LOOPBACK_MODE) {
3628 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3629 "1306 Link Up Event in loop back mode "
3630 "x%x received Data: x%x x%x x%x x%x\n",
3631 la->eventTag, phba->fc_eventTag,
3632 bf_get(lpfc_mbx_read_top_alpa_granted,
3633 la),
3634 bf_get(lpfc_mbx_read_top_link_spd, la),
3635 phba->alpa_map[0]);
3636 } else {
3637 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3638 "1303 Link Up Event x%x received "
3639 "Data: x%x x%x x%x x%x x%x x%x %d\n",
3640 la->eventTag, phba->fc_eventTag,
3641 bf_get(lpfc_mbx_read_top_alpa_granted,
3642 la),
3643 bf_get(lpfc_mbx_read_top_link_spd, la),
3644 phba->alpa_map[0],
3645 bf_get(lpfc_mbx_read_top_mm, la),
3646 bf_get(lpfc_mbx_read_top_fa, la),
3647 phba->wait_4_mlo_maint_flg);
3648 }
3649 lpfc_mbx_process_link_up(phba, la);
3650
3651 if (phba->cmf_active_mode != LPFC_CFG_OFF)
3652 lpfc_cmf_signal_init(phba);
3653
3654 } else if (attn_type == LPFC_ATT_LINK_DOWN ||
3655 attn_type == LPFC_ATT_UNEXP_WWPN) {
3656 phba->fc_stat.LinkDown++;
3657 if (phba->link_flag & LS_LOOPBACK_MODE)
3658 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3659 "1308 Link Down Event in loop back mode "
3660 "x%x received "
3661 "Data: x%x x%x x%x\n",
3662 la->eventTag, phba->fc_eventTag,
3663 phba->pport->port_state, vport->fc_flag);
3664 else if (attn_type == LPFC_ATT_UNEXP_WWPN)
3665 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3666 "1313 Link Down Unexpected FA WWPN Event x%x "
3667 "received Data: x%x x%x x%x x%x x%x\n",
3668 la->eventTag, phba->fc_eventTag,
3669 phba->pport->port_state, vport->fc_flag,
3670 bf_get(lpfc_mbx_read_top_mm, la),
3671 bf_get(lpfc_mbx_read_top_fa, la));
3672 else
3673 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3674 "1305 Link Down Event x%x received "
3675 "Data: x%x x%x x%x x%x x%x\n",
3676 la->eventTag, phba->fc_eventTag,
3677 phba->pport->port_state, vport->fc_flag,
3678 bf_get(lpfc_mbx_read_top_mm, la),
3679 bf_get(lpfc_mbx_read_top_fa, la));
3680 lpfc_mbx_issue_link_down(phba);
3681 }
3682 if (phba->sli.sli_flag & LPFC_MENLO_MAINT &&
3683 attn_type == LPFC_ATT_LINK_UP) {
3684 if (phba->link_state != LPFC_LINK_DOWN) {
3685 phba->fc_stat.LinkDown++;
3686 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3687 "1312 Link Down Event x%x received "
3688 "Data: x%x x%x x%x\n",
3689 la->eventTag, phba->fc_eventTag,
3690 phba->pport->port_state, vport->fc_flag);
3691 lpfc_mbx_issue_link_down(phba);
3692 } else
3693 lpfc_enable_la(phba);
3694
3695 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3696 "1310 Menlo Maint Mode Link up Event x%x rcvd "
3697 "Data: x%x x%x x%x\n",
3698 la->eventTag, phba->fc_eventTag,
3699 phba->pport->port_state, vport->fc_flag);
3700
3701
3702
3703
3704
3705 if (phba->wait_4_mlo_maint_flg) {
3706 phba->wait_4_mlo_maint_flg = 0;
3707 wake_up_interruptible(&phba->wait_4_mlo_m_q);
3708 }
3709 }
3710
3711 if ((phba->sli_rev < LPFC_SLI_REV4) &&
3712 bf_get(lpfc_mbx_read_top_fa, la)) {
3713 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
3714 lpfc_issue_clear_la(phba, vport);
3715 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
3716 "1311 fa %d\n",
3717 bf_get(lpfc_mbx_read_top_fa, la));
3718 }
3719
3720lpfc_mbx_cmpl_read_topology_free_mbuf:
3721 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3722 kfree(mp);
3723 mempool_free(pmb, phba->mbox_mem_pool);
3724 return;
3725}
3726
3727
3728
3729
3730
3731
3732
3733void
3734lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3735{
3736 struct lpfc_vport *vport = pmb->vport;
3737 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
3738 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
3739
3740 pmb->ctx_buf = NULL;
3741 pmb->ctx_ndlp = NULL;
3742
3743 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI | LOG_NODE | LOG_DISCOVERY,
3744 "0002 rpi:%x DID:%x flg:%x %d x%px\n",
3745 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
3746 kref_read(&ndlp->kref),
3747 ndlp);
3748 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
3749 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
3750
3751 if (ndlp->nlp_flag & NLP_IGNR_REG_CMPL ||
3752 ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) {
3753
3754
3755
3756
3757
3758
3759
3760
3761 spin_lock_irq(&ndlp->lock);
3762 ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
3763 spin_unlock_irq(&ndlp->lock);
3764
3765
3766
3767
3768
3769
3770 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
3771 lpfc_unreg_rpi(vport, ndlp);
3772 }
3773
3774
3775 lpfc_disc_state_machine(vport, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
3776
3777 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3778 kfree(mp);
3779 mempool_free(pmb, phba->mbox_mem_pool);
3780
3781
3782
3783 lpfc_nlp_put(ndlp);
3784
3785 return;
3786}
3787
3788static void
3789lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3790{
3791 MAILBOX_t *mb = &pmb->u.mb;
3792 struct lpfc_vport *vport = pmb->vport;
3793 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3794
3795 switch (mb->mbxStatus) {
3796 case 0x0011:
3797 case 0x0020:
3798 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3799 "0911 cmpl_unreg_vpi, mb status = 0x%x\n",
3800 mb->mbxStatus);
3801 break;
3802
3803 case 0x9700:
3804 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3805 "2798 Unreg_vpi failed vpi 0x%x, mb status = 0x%x\n",
3806 vport->vpi, mb->mbxStatus);
3807 if (!(phba->pport->load_flag & FC_UNLOADING))
3808 lpfc_workq_post_event(phba, NULL, NULL,
3809 LPFC_EVT_RESET_HBA);
3810 }
3811 spin_lock_irq(shost->host_lock);
3812 vport->vpi_state &= ~LPFC_VPI_REGISTERED;
3813 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3814 spin_unlock_irq(shost->host_lock);
3815 vport->unreg_vpi_cmpl = VPORT_OK;
3816 mempool_free(pmb, phba->mbox_mem_pool);
3817 lpfc_cleanup_vports_rrqs(vport, NULL);
3818
3819
3820
3821
3822 if ((vport->load_flag & FC_UNLOADING) && (vport != phba->pport))
3823 scsi_host_put(shost);
3824}
3825
3826int
3827lpfc_mbx_unreg_vpi(struct lpfc_vport *vport)
3828{
3829 struct lpfc_hba *phba = vport->phba;
3830 LPFC_MBOXQ_t *mbox;
3831 int rc;
3832
3833 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3834 if (!mbox)
3835 return 1;
3836
3837 lpfc_unreg_vpi(phba, vport->vpi, mbox);
3838 mbox->vport = vport;
3839 mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi;
3840 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
3841 if (rc == MBX_NOT_FINISHED) {
3842 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3843 "1800 Could not issue unreg_vpi\n");
3844 mempool_free(mbox, phba->mbox_mem_pool);
3845 vport->unreg_vpi_cmpl = VPORT_ERROR;
3846 return rc;
3847 }
3848 return 0;
3849}
3850
3851static void
3852lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3853{
3854 struct lpfc_vport *vport = pmb->vport;
3855 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3856 MAILBOX_t *mb = &pmb->u.mb;
3857
3858 switch (mb->mbxStatus) {
3859 case 0x0011:
3860 case 0x9601:
3861 case 0x9602:
3862 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3863 "0912 cmpl_reg_vpi, mb status = 0x%x\n",
3864 mb->mbxStatus);
3865 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3866 spin_lock_irq(shost->host_lock);
3867 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
3868 spin_unlock_irq(shost->host_lock);
3869 vport->fc_myDID = 0;
3870
3871 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
3872 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
3873 if (phba->nvmet_support)
3874 lpfc_nvmet_update_targetport(phba);
3875 else
3876 lpfc_nvme_update_localport(vport);
3877 }
3878 goto out;
3879 }
3880
3881 spin_lock_irq(shost->host_lock);
3882 vport->vpi_state |= LPFC_VPI_REGISTERED;
3883 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
3884 spin_unlock_irq(shost->host_lock);
3885 vport->num_disc_nodes = 0;
3886
3887 if (vport->fc_npr_cnt)
3888 lpfc_els_disc_plogi(vport);
3889
3890 if (!vport->num_disc_nodes) {
3891 spin_lock_irq(shost->host_lock);
3892 vport->fc_flag &= ~FC_NDISC_ACTIVE;
3893 spin_unlock_irq(shost->host_lock);
3894 lpfc_can_disctmo(vport);
3895 }
3896 vport->port_state = LPFC_VPORT_READY;
3897
3898out:
3899 mempool_free(pmb, phba->mbox_mem_pool);
3900 return;
3901}
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911void
3912lpfc_create_static_vport(struct lpfc_hba *phba)
3913{
3914 LPFC_MBOXQ_t *pmb = NULL;
3915 MAILBOX_t *mb;
3916 struct static_vport_info *vport_info;
3917 int mbx_wait_rc = 0, i;
3918 struct fc_vport_identifiers vport_id;
3919 struct fc_vport *new_fc_vport;
3920 struct Scsi_Host *shost;
3921 struct lpfc_vport *vport;
3922 uint16_t offset = 0;
3923 uint8_t *vport_buff;
3924 struct lpfc_dmabuf *mp;
3925 uint32_t byte_count = 0;
3926
3927 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3928 if (!pmb) {
3929 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3930 "0542 lpfc_create_static_vport failed to"
3931 " allocate mailbox memory\n");
3932 return;
3933 }
3934 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
3935 mb = &pmb->u.mb;
3936
3937 vport_info = kzalloc(sizeof(struct static_vport_info), GFP_KERNEL);
3938 if (!vport_info) {
3939 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3940 "0543 lpfc_create_static_vport failed to"
3941 " allocate vport_info\n");
3942 mempool_free(pmb, phba->mbox_mem_pool);
3943 return;
3944 }
3945
3946 vport_buff = (uint8_t *) vport_info;
3947 do {
3948
3949 if (pmb->ctx_buf) {
3950 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
3951 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3952 kfree(mp);
3953 }
3954 if (lpfc_dump_static_vport(phba, pmb, offset))
3955 goto out;
3956
3957 pmb->vport = phba->pport;
3958 mbx_wait_rc = lpfc_sli_issue_mbox_wait(phba, pmb,
3959 LPFC_MBOX_TMO);
3960
3961 if ((mbx_wait_rc != MBX_SUCCESS) || mb->mbxStatus) {
3962 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3963 "0544 lpfc_create_static_vport failed to"
3964 " issue dump mailbox command ret 0x%x "
3965 "status 0x%x\n",
3966 mbx_wait_rc, mb->mbxStatus);
3967 goto out;
3968 }
3969
3970 if (phba->sli_rev == LPFC_SLI_REV4) {
3971 byte_count = pmb->u.mqe.un.mb_words[5];
3972 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
3973 if (byte_count > sizeof(struct static_vport_info) -
3974 offset)
3975 byte_count = sizeof(struct static_vport_info)
3976 - offset;
3977 memcpy(vport_buff + offset, mp->virt, byte_count);
3978 offset += byte_count;
3979 } else {
3980 if (mb->un.varDmp.word_cnt >
3981 sizeof(struct static_vport_info) - offset)
3982 mb->un.varDmp.word_cnt =
3983 sizeof(struct static_vport_info)
3984 - offset;
3985 byte_count = mb->un.varDmp.word_cnt;
3986 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
3987 vport_buff + offset,
3988 byte_count);
3989
3990 offset += byte_count;
3991 }
3992
3993 } while (byte_count &&
3994 offset < sizeof(struct static_vport_info));
3995
3996
3997 if ((le32_to_cpu(vport_info->signature) != VPORT_INFO_SIG) ||
3998 ((le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK)
3999 != VPORT_INFO_REV)) {
4000 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4001 "0545 lpfc_create_static_vport bad"
4002 " information header 0x%x 0x%x\n",
4003 le32_to_cpu(vport_info->signature),
4004 le32_to_cpu(vport_info->rev) &
4005 VPORT_INFO_REV_MASK);
4006
4007 goto out;
4008 }
4009
4010 shost = lpfc_shost_from_vport(phba->pport);
4011
4012 for (i = 0; i < MAX_STATIC_VPORT_COUNT; i++) {
4013 memset(&vport_id, 0, sizeof(vport_id));
4014 vport_id.port_name = wwn_to_u64(vport_info->vport_list[i].wwpn);
4015 vport_id.node_name = wwn_to_u64(vport_info->vport_list[i].wwnn);
4016 if (!vport_id.port_name || !vport_id.node_name)
4017 continue;
4018
4019 vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR;
4020 vport_id.vport_type = FC_PORTTYPE_NPIV;
4021 vport_id.disable = false;
4022 new_fc_vport = fc_vport_create(shost, 0, &vport_id);
4023
4024 if (!new_fc_vport) {
4025 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4026 "0546 lpfc_create_static_vport failed to"
4027 " create vport\n");
4028 continue;
4029 }
4030
4031 vport = *(struct lpfc_vport **)new_fc_vport->dd_data;
4032 vport->vport_flag |= STATIC_VPORT;
4033 }
4034
4035out:
4036 kfree(vport_info);
4037 if (mbx_wait_rc != MBX_TIMEOUT) {
4038 if (pmb->ctx_buf) {
4039 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
4040 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4041 kfree(mp);
4042 }
4043 mempool_free(pmb, phba->mbox_mem_pool);
4044 }
4045
4046 return;
4047}
4048
4049
4050
4051
4052
4053
4054
4055void
4056lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4057{
4058 struct lpfc_vport *vport = pmb->vport;
4059 MAILBOX_t *mb = &pmb->u.mb;
4060 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
4061 struct lpfc_nodelist *ndlp;
4062 struct Scsi_Host *shost;
4063
4064 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
4065 pmb->ctx_ndlp = NULL;
4066 pmb->ctx_buf = NULL;
4067
4068 if (mb->mbxStatus) {
4069 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4070 "0258 Register Fabric login error: 0x%x\n",
4071 mb->mbxStatus);
4072 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4073 kfree(mp);
4074 mempool_free(pmb, phba->mbox_mem_pool);
4075
4076 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4077
4078 lpfc_disc_list_loopmap(vport);
4079
4080
4081 lpfc_disc_start(vport);
4082
4083
4084
4085 lpfc_nlp_put(ndlp);
4086 return;
4087 }
4088
4089 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4090
4091
4092
4093 lpfc_nlp_put(ndlp);
4094 return;
4095 }
4096
4097 if (phba->sli_rev < LPFC_SLI_REV4)
4098 ndlp->nlp_rpi = mb->un.varWords[0];
4099 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
4100 ndlp->nlp_type |= NLP_FABRIC;
4101 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
4102
4103 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
4104
4105
4106 if (!(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
4107 lpfc_start_fdiscs(phba);
4108 else {
4109 shost = lpfc_shost_from_vport(vport);
4110 spin_lock_irq(shost->host_lock);
4111 vport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG ;
4112 spin_unlock_irq(shost->host_lock);
4113 }
4114 lpfc_do_scr_ns_plogi(phba, vport);
4115 }
4116
4117 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4118 kfree(mp);
4119 mempool_free(pmb, phba->mbox_mem_pool);
4120
4121
4122
4123
4124 lpfc_nlp_put(ndlp);
4125 return;
4126}
4127
4128
4129
4130
4131
4132int
4133lpfc_issue_gidft(struct lpfc_vport *vport)
4134{
4135
4136 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4137 (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) {
4138 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_FCP)) {
4139
4140
4141
4142 lpfc_printf_vlog(vport, KERN_ERR,
4143 LOG_TRACE_EVENT,
4144 "0604 %s FC TYPE %x %s\n",
4145 "Failed to issue GID_FT to ",
4146 FC_TYPE_FCP,
4147 "Finishing discovery.");
4148 return 0;
4149 }
4150 vport->gidft_inp++;
4151 }
4152
4153 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4154 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
4155 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_NVME)) {
4156
4157
4158
4159 lpfc_printf_vlog(vport, KERN_ERR,
4160 LOG_TRACE_EVENT,
4161 "0605 %s FC_TYPE %x %s %d\n",
4162 "Failed to issue GID_FT to ",
4163 FC_TYPE_NVME,
4164 "Finishing discovery: gidftinp ",
4165 vport->gidft_inp);
4166 if (vport->gidft_inp == 0)
4167 return 0;
4168 } else
4169 vport->gidft_inp++;
4170 }
4171 return vport->gidft_inp;
4172}
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184int
4185lpfc_issue_gidpt(struct lpfc_vport *vport)
4186{
4187
4188 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_PT, 0, GID_PT_N_PORT)) {
4189
4190
4191
4192 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4193 "0606 %s Port TYPE %x %s\n",
4194 "Failed to issue GID_PT to ",
4195 GID_PT_N_PORT,
4196 "Finishing discovery.");
4197 return 0;
4198 }
4199 vport->gidft_inp++;
4200 return 1;
4201}
4202
4203
4204
4205
4206
4207
4208
4209void
4210lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4211{
4212 MAILBOX_t *mb = &pmb->u.mb;
4213 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
4214 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
4215 struct lpfc_vport *vport = pmb->vport;
4216 int rc;
4217
4218 pmb->ctx_buf = NULL;
4219 pmb->ctx_ndlp = NULL;
4220 vport->gidft_inp = 0;
4221
4222 if (mb->mbxStatus) {
4223 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4224 "0260 Register NameServer error: 0x%x\n",
4225 mb->mbxStatus);
4226
4227out:
4228
4229
4230
4231 lpfc_nlp_put(ndlp);
4232 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4233 kfree(mp);
4234 mempool_free(pmb, phba->mbox_mem_pool);
4235
4236
4237
4238
4239
4240 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD))) {
4241 spin_lock_irq(&ndlp->lock);
4242 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
4243 spin_unlock_irq(&ndlp->lock);
4244 lpfc_nlp_not_used(ndlp);
4245 }
4246
4247 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4248
4249
4250
4251
4252 lpfc_disc_list_loopmap(vport);
4253
4254
4255 lpfc_disc_start(vport);
4256 return;
4257 }
4258 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4259 return;
4260 }
4261
4262 if (phba->sli_rev < LPFC_SLI_REV4)
4263 ndlp->nlp_rpi = mb->un.varWords[0];
4264 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
4265 ndlp->nlp_type |= NLP_FABRIC;
4266 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
4267 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY,
4268 "0003 rpi:%x DID:%x flg:%x %d x%px\n",
4269 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
4270 kref_read(&ndlp->kref),
4271 ndlp);
4272
4273 if (vport->port_state < LPFC_VPORT_READY) {
4274
4275 lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0);
4276 lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
4277 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4278 lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0);
4279
4280 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4281 (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP))
4282 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, FC_TYPE_FCP);
4283
4284 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4285 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME))
4286 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0,
4287 FC_TYPE_NVME);
4288
4289
4290 lpfc_issue_els_scr(vport, 0);
4291
4292
4293
4294
4295
4296
4297
4298 if (phba->cmf_active_mode != LPFC_CFG_OFF) {
4299 phba->cgn_reg_fpin = phba->cgn_init_reg_fpin;
4300 phba->cgn_reg_signal = phba->cgn_init_reg_signal;
4301 rc = lpfc_issue_els_edc(vport, 0);
4302 lpfc_printf_log(phba, KERN_INFO,
4303 LOG_INIT | LOG_ELS | LOG_DISCOVERY,
4304 "4220 EDC issue error x%x, Data: x%x\n",
4305 rc, phba->cgn_init_reg_signal);
4306 } else {
4307 lpfc_issue_els_rdf(vport, 0);
4308 }
4309 }
4310
4311 vport->fc_ns_retry = 0;
4312 if (lpfc_issue_gidft(vport) == 0)
4313 goto out;
4314
4315
4316
4317
4318
4319
4320
4321
4322 lpfc_nlp_put(ndlp);
4323 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4324 kfree(mp);
4325 mempool_free(pmb, phba->mbox_mem_pool);
4326
4327 return;
4328}
4329
4330
4331
4332
4333
4334
4335void
4336lpfc_mbx_cmpl_fc_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4337{
4338 struct lpfc_vport *vport = pmb->vport;
4339 MAILBOX_t *mb = &pmb->u.mb;
4340 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
4341 struct lpfc_nodelist *ndlp;
4342
4343 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
4344 pmb->ctx_ndlp = NULL;
4345 pmb->ctx_buf = NULL;
4346
4347 if (mb->mbxStatus) {
4348 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4349 "0933 %s: Register FC login error: 0x%x\n",
4350 __func__, mb->mbxStatus);
4351 goto out;
4352 }
4353
4354 if (phba->sli_rev < LPFC_SLI_REV4)
4355 ndlp->nlp_rpi = mb->un.varWords[0];
4356
4357 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4358 "0934 %s: Complete FC x%x RegLogin rpi x%x ste x%x\n",
4359 __func__, ndlp->nlp_DID, ndlp->nlp_rpi,
4360 ndlp->nlp_state);
4361
4362 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
4363 ndlp->nlp_type |= NLP_FABRIC;
4364 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
4365
4366 out:
4367 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4368 kfree(mp);
4369 mempool_free(pmb, phba->mbox_mem_pool);
4370
4371
4372
4373
4374 lpfc_nlp_put(ndlp);
4375}
4376
4377static void
4378lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4379{
4380 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4381 struct fc_rport *rport;
4382 struct lpfc_rport_data *rdata;
4383 struct fc_rport_identifiers rport_ids;
4384 struct lpfc_hba *phba = vport->phba;
4385 unsigned long flags;
4386
4387 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
4388 return;
4389
4390
4391 rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
4392 rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
4393 rport_ids.port_id = ndlp->nlp_DID;
4394 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
4395
4396
4397 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
4398 "rport add: did:x%x flg:x%x type x%x",
4399 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
4400
4401
4402 if (vport->load_flag & FC_UNLOADING)
4403 return;
4404
4405
4406
4407
4408 if (ndlp->rport) {
4409 rdata = ndlp->rport->dd_data;
4410 rdata->pnode = NULL;
4411 }
4412
4413 ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids);
4414 if (!rport) {
4415 dev_printk(KERN_WARNING, &phba->pcidev->dev,
4416 "Warning: fc_remote_port_add failed\n");
4417 return;
4418 }
4419
4420
4421 rport->maxframe_size = ndlp->nlp_maxframe;
4422 rport->supported_classes = ndlp->nlp_class_sup;
4423 rdata = rport->dd_data;
4424 rdata->pnode = lpfc_nlp_get(ndlp);
4425 if (!rdata->pnode) {
4426 dev_warn(&phba->pcidev->dev,
4427 "Warning - node ref failed. Unreg rport\n");
4428 fc_remote_port_delete(rport);
4429 ndlp->rport = NULL;
4430 return;
4431 }
4432
4433 spin_lock_irqsave(&ndlp->lock, flags);
4434 ndlp->fc4_xpt_flags |= SCSI_XPT_REGD;
4435 spin_unlock_irqrestore(&ndlp->lock, flags);
4436
4437 if (ndlp->nlp_type & NLP_FCP_TARGET)
4438 rport_ids.roles |= FC_PORT_ROLE_FCP_TARGET;
4439 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
4440 rport_ids.roles |= FC_PORT_ROLE_FCP_INITIATOR;
4441 if (ndlp->nlp_type & NLP_NVME_INITIATOR)
4442 rport_ids.roles |= FC_PORT_ROLE_NVME_INITIATOR;
4443 if (ndlp->nlp_type & NLP_NVME_TARGET)
4444 rport_ids.roles |= FC_PORT_ROLE_NVME_TARGET;
4445 if (ndlp->nlp_type & NLP_NVME_DISCOVERY)
4446 rport_ids.roles |= FC_PORT_ROLE_NVME_DISCOVERY;
4447
4448 if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
4449 fc_remote_port_rolechg(rport, rport_ids.roles);
4450
4451 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
4452 "3183 %s rport x%px DID x%x, role x%x\n",
4453 __func__, rport, rport->port_id, rport->roles);
4454
4455 if ((rport->scsi_target_id != -1) &&
4456 (rport->scsi_target_id < LPFC_MAX_TARGET)) {
4457 ndlp->nlp_sid = rport->scsi_target_id;
4458 }
4459
4460 return;
4461}
4462
4463static void
4464lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp)
4465{
4466 struct fc_rport *rport = ndlp->rport;
4467 struct lpfc_vport *vport = ndlp->vport;
4468
4469 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
4470 return;
4471
4472 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
4473 "rport delete: did:x%x flg:x%x type x%x",
4474 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
4475
4476 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4477 "3184 rport unregister x%06x, rport x%px "
4478 "xptflg x%x\n",
4479 ndlp->nlp_DID, rport, ndlp->fc4_xpt_flags);
4480
4481 fc_remote_port_delete(rport);
4482 lpfc_nlp_put(ndlp);
4483}
4484
4485static void
4486lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count)
4487{
4488 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4489 unsigned long iflags;
4490
4491 spin_lock_irqsave(shost->host_lock, iflags);
4492 switch (state) {
4493 case NLP_STE_UNUSED_NODE:
4494 vport->fc_unused_cnt += count;
4495 break;
4496 case NLP_STE_PLOGI_ISSUE:
4497 vport->fc_plogi_cnt += count;
4498 break;
4499 case NLP_STE_ADISC_ISSUE:
4500 vport->fc_adisc_cnt += count;
4501 break;
4502 case NLP_STE_REG_LOGIN_ISSUE:
4503 vport->fc_reglogin_cnt += count;
4504 break;
4505 case NLP_STE_PRLI_ISSUE:
4506 vport->fc_prli_cnt += count;
4507 break;
4508 case NLP_STE_UNMAPPED_NODE:
4509 vport->fc_unmap_cnt += count;
4510 break;
4511 case NLP_STE_MAPPED_NODE:
4512 vport->fc_map_cnt += count;
4513 break;
4514 case NLP_STE_NPR_NODE:
4515 if (vport->fc_npr_cnt == 0 && count == -1)
4516 vport->fc_npr_cnt = 0;
4517 else
4518 vport->fc_npr_cnt += count;
4519 break;
4520 }
4521 spin_unlock_irqrestore(shost->host_lock, iflags);
4522}
4523
4524
4525void
4526lpfc_nlp_reg_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4527{
4528
4529 unsigned long iflags;
4530
4531 spin_lock_irqsave(&ndlp->lock, iflags);
4532 if (ndlp->fc4_xpt_flags & NLP_XPT_REGD) {
4533
4534 spin_unlock_irqrestore(&ndlp->lock, iflags);
4535
4536 if (ndlp->fc4_xpt_flags & NVME_XPT_REGD &&
4537 ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY)) {
4538 lpfc_nvme_rescan_port(vport, ndlp);
4539 }
4540 return;
4541 }
4542
4543 ndlp->fc4_xpt_flags |= NLP_XPT_REGD;
4544 spin_unlock_irqrestore(&ndlp->lock, iflags);
4545
4546 if (lpfc_valid_xpt_node(ndlp)) {
4547 vport->phba->nport_event_cnt++;
4548
4549
4550
4551
4552 lpfc_register_remote_port(vport, ndlp);
4553 }
4554
4555
4556 if (!(ndlp->nlp_fc4_type & NLP_FC4_NVME))
4557 return;
4558
4559
4560 if (vport->phba->sli_rev >= LPFC_SLI_REV4 &&
4561 ndlp->nlp_fc4_type & NLP_FC4_NVME) {
4562 if (vport->phba->nvmet_support == 0) {
4563
4564
4565
4566
4567 if (ndlp->nlp_type & NLP_NVME_TARGET) {
4568 vport->phba->nport_event_cnt++;
4569 lpfc_nvme_register_port(vport, ndlp);
4570 }
4571 } else {
4572
4573
4574
4575 lpfc_nlp_get(ndlp);
4576 }
4577 }
4578}
4579
4580
4581void
4582lpfc_nlp_unreg_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4583{
4584 unsigned long iflags;
4585
4586 spin_lock_irqsave(&ndlp->lock, iflags);
4587 if (!(ndlp->fc4_xpt_flags & NLP_XPT_REGD)) {
4588 spin_unlock_irqrestore(&ndlp->lock, iflags);
4589 return;
4590 }
4591
4592 ndlp->fc4_xpt_flags &= ~NLP_XPT_REGD;
4593 spin_unlock_irqrestore(&ndlp->lock, iflags);
4594
4595 if (ndlp->rport &&
4596 ndlp->fc4_xpt_flags & SCSI_XPT_REGD) {
4597 vport->phba->nport_event_cnt++;
4598 lpfc_unregister_remote_port(ndlp);
4599 }
4600
4601 if (ndlp->fc4_xpt_flags & NVME_XPT_REGD) {
4602 vport->phba->nport_event_cnt++;
4603 if (vport->phba->nvmet_support == 0) {
4604
4605 if (ndlp->nlp_type & NLP_NVME_TARGET)
4606 lpfc_nvme_unregister_port(vport, ndlp);
4607 } else {
4608
4609 lpfc_nlp_put(ndlp);
4610 }
4611 }
4612
4613}
4614
4615
4616
4617
4618static void
4619lpfc_handle_adisc_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4620 int new_state)
4621{
4622 switch (new_state) {
4623
4624
4625
4626
4627 case NLP_STE_ADISC_ISSUE:
4628 break;
4629
4630
4631
4632
4633
4634
4635 case NLP_STE_UNMAPPED_NODE:
4636 ndlp->nlp_type |= NLP_FC_NODE;
4637 fallthrough;
4638 case NLP_STE_MAPPED_NODE:
4639 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
4640 lpfc_nlp_reg_node(vport, ndlp);
4641 break;
4642
4643
4644
4645
4646
4647
4648
4649 case NLP_STE_NPR_NODE:
4650 ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
4651 fallthrough;
4652 default:
4653 lpfc_nlp_unreg_node(vport, ndlp);
4654 break;
4655 }
4656
4657}
4658
4659static void
4660lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4661 int old_state, int new_state)
4662{
4663
4664 if (new_state == NLP_STE_ADISC_ISSUE ||
4665 old_state == NLP_STE_ADISC_ISSUE) {
4666 lpfc_handle_adisc_state(vport, ndlp, new_state);
4667 return;
4668 }
4669
4670 if (new_state == NLP_STE_UNMAPPED_NODE) {
4671 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
4672 ndlp->nlp_type |= NLP_FC_NODE;
4673 }
4674 if (new_state == NLP_STE_MAPPED_NODE)
4675 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
4676 if (new_state == NLP_STE_NPR_NODE)
4677 ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
4678
4679
4680 if ((old_state == NLP_STE_MAPPED_NODE ||
4681 old_state == NLP_STE_UNMAPPED_NODE)) {
4682
4683 if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
4684 lpfc_nlp_unreg_node(vport, ndlp);
4685 }
4686
4687 if (new_state == NLP_STE_MAPPED_NODE ||
4688 new_state == NLP_STE_UNMAPPED_NODE)
4689 lpfc_nlp_reg_node(vport, ndlp);
4690
4691 if ((new_state == NLP_STE_MAPPED_NODE) &&
4692 (vport->stat_data_enabled)) {
4693
4694
4695
4696
4697 ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT,
4698 sizeof(struct lpfc_scsicmd_bkt),
4699 GFP_KERNEL);
4700
4701 if (!ndlp->lat_data)
4702 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4703 "0286 lpfc_nlp_state_cleanup failed to "
4704 "allocate statistical data buffer DID "
4705 "0x%x\n", ndlp->nlp_DID);
4706 }
4707
4708
4709
4710
4711
4712
4713 if ((new_state == NLP_STE_MAPPED_NODE) &&
4714 (ndlp->nlp_type & NLP_FCP_TARGET) &&
4715 (!ndlp->rport ||
4716 ndlp->rport->scsi_target_id == -1 ||
4717 ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
4718 spin_lock_irq(&ndlp->lock);
4719 ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
4720 spin_unlock_irq(&ndlp->lock);
4721 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
4722 }
4723}
4724
4725static char *
4726lpfc_nlp_state_name(char *buffer, size_t size, int state)
4727{
4728 static char *states[] = {
4729 [NLP_STE_UNUSED_NODE] = "UNUSED",
4730 [NLP_STE_PLOGI_ISSUE] = "PLOGI",
4731 [NLP_STE_ADISC_ISSUE] = "ADISC",
4732 [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN",
4733 [NLP_STE_PRLI_ISSUE] = "PRLI",
4734 [NLP_STE_LOGO_ISSUE] = "LOGO",
4735 [NLP_STE_UNMAPPED_NODE] = "UNMAPPED",
4736 [NLP_STE_MAPPED_NODE] = "MAPPED",
4737 [NLP_STE_NPR_NODE] = "NPR",
4738 };
4739
4740 if (state < NLP_STE_MAX_STATE && states[state])
4741 strlcpy(buffer, states[state], size);
4742 else
4743 snprintf(buffer, size, "unknown (%d)", state);
4744 return buffer;
4745}
4746
4747void
4748lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4749 int state)
4750{
4751 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4752 int old_state = ndlp->nlp_state;
4753 int node_dropped = ndlp->nlp_flag & NLP_DROPPED;
4754 char name1[16], name2[16];
4755
4756 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4757 "0904 NPort state transition x%06x, %s -> %s\n",
4758 ndlp->nlp_DID,
4759 lpfc_nlp_state_name(name1, sizeof(name1), old_state),
4760 lpfc_nlp_state_name(name2, sizeof(name2), state));
4761
4762 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
4763 "node statechg did:x%x old:%d ste:%d",
4764 ndlp->nlp_DID, old_state, state);
4765
4766 if (node_dropped && old_state == NLP_STE_UNUSED_NODE &&
4767 state != NLP_STE_UNUSED_NODE) {
4768 ndlp->nlp_flag &= ~NLP_DROPPED;
4769 lpfc_nlp_get(ndlp);
4770 }
4771
4772 if (old_state == NLP_STE_NPR_NODE &&
4773 state != NLP_STE_NPR_NODE)
4774 lpfc_cancel_retry_delay_tmo(vport, ndlp);
4775 if (old_state == NLP_STE_UNMAPPED_NODE) {
4776 ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
4777 ndlp->nlp_type &= ~NLP_FC_NODE;
4778 }
4779
4780 if (list_empty(&ndlp->nlp_listp)) {
4781 spin_lock_irq(shost->host_lock);
4782 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
4783 spin_unlock_irq(shost->host_lock);
4784 } else if (old_state)
4785 lpfc_nlp_counters(vport, old_state, -1);
4786
4787 ndlp->nlp_state = state;
4788 lpfc_nlp_counters(vport, state, 1);
4789 lpfc_nlp_state_cleanup(vport, ndlp, old_state, state);
4790}
4791
4792void
4793lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4794{
4795 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4796
4797 if (list_empty(&ndlp->nlp_listp)) {
4798 spin_lock_irq(shost->host_lock);
4799 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
4800 spin_unlock_irq(shost->host_lock);
4801 }
4802}
4803
4804void
4805lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4806{
4807 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4808
4809 lpfc_cancel_retry_delay_tmo(vport, ndlp);
4810 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
4811 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
4812 spin_lock_irq(shost->host_lock);
4813 list_del_init(&ndlp->nlp_listp);
4814 spin_unlock_irq(shost->host_lock);
4815 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
4816 NLP_STE_UNUSED_NODE);
4817}
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833static inline void
4834lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4835 uint32_t did)
4836{
4837 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
4838 INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp);
4839 timer_setup(&ndlp->nlp_delayfunc, lpfc_els_retry_delay, 0);
4840 INIT_LIST_HEAD(&ndlp->recovery_evt.evt_listp);
4841
4842 ndlp->nlp_DID = did;
4843 ndlp->vport = vport;
4844 ndlp->phba = vport->phba;
4845 ndlp->nlp_sid = NLP_NO_SID;
4846 ndlp->nlp_fc4_type = NLP_FC4_NONE;
4847 kref_init(&ndlp->kref);
4848 atomic_set(&ndlp->cmd_pending, 0);
4849 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
4850 ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING;
4851}
4852
4853void
4854lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4855{
4856
4857
4858
4859
4860
4861
4862
4863 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4864 return;
4865 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
4866 ndlp->nlp_flag |= NLP_DROPPED;
4867 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
4868 lpfc_cleanup_vports_rrqs(vport, ndlp);
4869 lpfc_unreg_rpi(vport, ndlp);
4870 }
4871
4872 lpfc_nlp_put(ndlp);
4873 return;
4874}
4875
4876
4877
4878
4879void
4880lpfc_set_disctmo(struct lpfc_vport *vport)
4881{
4882 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4883 struct lpfc_hba *phba = vport->phba;
4884 uint32_t tmo;
4885
4886 if (vport->port_state == LPFC_LOCAL_CFG_LINK) {
4887
4888 tmo = (((phba->fc_edtov + 999) / 1000) + 1);
4889 } else {
4890
4891
4892
4893 tmo = ((phba->fc_ratov * 3) + 3);
4894 }
4895
4896
4897 if (!timer_pending(&vport->fc_disctmo)) {
4898 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4899 "set disc timer: tmo:x%x state:x%x flg:x%x",
4900 tmo, vport->port_state, vport->fc_flag);
4901 }
4902
4903 mod_timer(&vport->fc_disctmo, jiffies + msecs_to_jiffies(1000 * tmo));
4904 spin_lock_irq(shost->host_lock);
4905 vport->fc_flag |= FC_DISC_TMO;
4906 spin_unlock_irq(shost->host_lock);
4907
4908
4909 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4910 "0247 Start Discovery Timer state x%x "
4911 "Data: x%x x%lx x%x x%x\n",
4912 vport->port_state, tmo,
4913 (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt,
4914 vport->fc_adisc_cnt);
4915
4916 return;
4917}
4918
4919
4920
4921
4922int
4923lpfc_can_disctmo(struct lpfc_vport *vport)
4924{
4925 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4926 unsigned long iflags;
4927
4928 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4929 "can disc timer: state:x%x rtry:x%x flg:x%x",
4930 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
4931
4932
4933 if (vport->fc_flag & FC_DISC_TMO) {
4934 spin_lock_irqsave(shost->host_lock, iflags);
4935 vport->fc_flag &= ~FC_DISC_TMO;
4936 spin_unlock_irqrestore(shost->host_lock, iflags);
4937 del_timer_sync(&vport->fc_disctmo);
4938 spin_lock_irqsave(&vport->work_port_lock, iflags);
4939 vport->work_port_events &= ~WORKER_DISC_TMO;
4940 spin_unlock_irqrestore(&vport->work_port_lock, iflags);
4941 }
4942
4943
4944 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4945 "0248 Cancel Discovery Timer state x%x "
4946 "Data: x%x x%x x%x\n",
4947 vport->port_state, vport->fc_flag,
4948 vport->fc_plogi_cnt, vport->fc_adisc_cnt);
4949 return 0;
4950}
4951
4952
4953
4954
4955
4956int
4957lpfc_check_sli_ndlp(struct lpfc_hba *phba,
4958 struct lpfc_sli_ring *pring,
4959 struct lpfc_iocbq *iocb,
4960 struct lpfc_nodelist *ndlp)
4961{
4962 IOCB_t *icmd = &iocb->iocb;
4963 struct lpfc_vport *vport = ndlp->vport;
4964
4965 if (iocb->vport != vport)
4966 return 0;
4967
4968 if (pring->ringno == LPFC_ELS_RING) {
4969 switch (icmd->ulpCommand) {
4970 case CMD_GEN_REQUEST64_CR:
4971 if (iocb->context_un.ndlp == ndlp)
4972 return 1;
4973 fallthrough;
4974 case CMD_ELS_REQUEST64_CR:
4975 if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID)
4976 return 1;
4977 fallthrough;
4978 case CMD_XMIT_ELS_RSP64_CX:
4979 if (iocb->context1 == (uint8_t *) ndlp)
4980 return 1;
4981 }
4982 } else if (pring->ringno == LPFC_FCP_RING) {
4983
4984 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
4985 (ndlp->nlp_flag & NLP_DELAY_TMO)) {
4986 return 0;
4987 }
4988 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
4989 return 1;
4990 }
4991 }
4992 return 0;
4993}
4994
4995static void
4996__lpfc_dequeue_nport_iocbs(struct lpfc_hba *phba,
4997 struct lpfc_nodelist *ndlp, struct lpfc_sli_ring *pring,
4998 struct list_head *dequeue_list)
4999{
5000 struct lpfc_iocbq *iocb, *next_iocb;
5001
5002 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
5003
5004 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))
5005
5006 list_move_tail(&iocb->list, dequeue_list);
5007 }
5008}
5009
5010static void
5011lpfc_sli3_dequeue_nport_iocbs(struct lpfc_hba *phba,
5012 struct lpfc_nodelist *ndlp, struct list_head *dequeue_list)
5013{
5014 struct lpfc_sli *psli = &phba->sli;
5015 uint32_t i;
5016
5017 spin_lock_irq(&phba->hbalock);
5018 for (i = 0; i < psli->num_rings; i++)
5019 __lpfc_dequeue_nport_iocbs(phba, ndlp, &psli->sli3_ring[i],
5020 dequeue_list);
5021 spin_unlock_irq(&phba->hbalock);
5022}
5023
5024static void
5025lpfc_sli4_dequeue_nport_iocbs(struct lpfc_hba *phba,
5026 struct lpfc_nodelist *ndlp, struct list_head *dequeue_list)
5027{
5028 struct lpfc_sli_ring *pring;
5029 struct lpfc_queue *qp = NULL;
5030
5031 spin_lock_irq(&phba->hbalock);
5032 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
5033 pring = qp->pring;
5034 if (!pring)
5035 continue;
5036 spin_lock(&pring->ring_lock);
5037 __lpfc_dequeue_nport_iocbs(phba, ndlp, pring, dequeue_list);
5038 spin_unlock(&pring->ring_lock);
5039 }
5040 spin_unlock_irq(&phba->hbalock);
5041}
5042
5043
5044
5045
5046
5047static int
5048lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
5049{
5050 LIST_HEAD(completions);
5051
5052 lpfc_fabric_abort_nport(ndlp);
5053
5054
5055
5056
5057
5058 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
5059 if (phba->sli_rev != LPFC_SLI_REV4)
5060 lpfc_sli3_dequeue_nport_iocbs(phba, ndlp, &completions);
5061 else
5062 lpfc_sli4_dequeue_nport_iocbs(phba, ndlp, &completions);
5063 }
5064
5065
5066 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5067 IOERR_SLI_ABORTED);
5068
5069 return 0;
5070}
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080static void
5081lpfc_nlp_logo_unreg(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5082{
5083 struct lpfc_vport *vport = pmb->vport;
5084 struct lpfc_nodelist *ndlp;
5085
5086 ndlp = (struct lpfc_nodelist *)(pmb->ctx_ndlp);
5087 if (!ndlp)
5088 return;
5089 lpfc_issue_els_logo(vport, ndlp, 0);
5090 mempool_free(pmb, phba->mbox_mem_pool);
5091
5092
5093 if ((ndlp->nlp_flag & NLP_UNREG_INP) &&
5094 (ndlp->nlp_defer_did != NLP_EVT_NOTHING_PENDING)) {
5095 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5096 "1434 UNREG cmpl deferred logo x%x "
5097 "on NPort x%x Data: x%x x%px\n",
5098 ndlp->nlp_rpi, ndlp->nlp_DID,
5099 ndlp->nlp_defer_did, ndlp);
5100
5101 ndlp->nlp_flag &= ~NLP_UNREG_INP;
5102 ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING;
5103 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
5104 } else {
5105
5106 if (ndlp->nlp_flag & NLP_RELEASE_RPI) {
5107 lpfc_sli4_free_rpi(vport->phba, ndlp->nlp_rpi);
5108 spin_lock_irq(&ndlp->lock);
5109 ndlp->nlp_flag &= ~NLP_RELEASE_RPI;
5110 ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
5111 spin_unlock_irq(&ndlp->lock);
5112 }
5113 spin_lock_irq(&ndlp->lock);
5114 ndlp->nlp_flag &= ~NLP_UNREG_INP;
5115 spin_unlock_irq(&ndlp->lock);
5116 }
5117}
5118
5119
5120
5121
5122
5123
5124static void
5125lpfc_set_unreg_login_mbx_cmpl(struct lpfc_hba *phba, struct lpfc_vport *vport,
5126 struct lpfc_nodelist *ndlp, LPFC_MBOXQ_t *mbox)
5127{
5128 unsigned long iflags;
5129
5130
5131
5132
5133 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
5134 if (!mbox->ctx_ndlp)
5135 return;
5136
5137 if (ndlp->nlp_flag & NLP_ISSUE_LOGO) {
5138 mbox->mbox_cmpl = lpfc_nlp_logo_unreg;
5139
5140 } else if (phba->sli_rev == LPFC_SLI_REV4 &&
5141 (!(vport->load_flag & FC_UNLOADING)) &&
5142 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
5143 LPFC_SLI_INTF_IF_TYPE_2) &&
5144 (kref_read(&ndlp->kref) > 0)) {
5145 mbox->mbox_cmpl = lpfc_sli4_unreg_rpi_cmpl_clr;
5146 } else {
5147 if (vport->load_flag & FC_UNLOADING) {
5148 if (phba->sli_rev == LPFC_SLI_REV4) {
5149 spin_lock_irqsave(&ndlp->lock, iflags);
5150 ndlp->nlp_flag |= NLP_RELEASE_RPI;
5151 spin_unlock_irqrestore(&ndlp->lock, iflags);
5152 }
5153 }
5154 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5155 }
5156}
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167int
5168lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
5169{
5170 struct lpfc_hba *phba = vport->phba;
5171 LPFC_MBOXQ_t *mbox;
5172 int rc, acc_plogi = 1;
5173 uint16_t rpi;
5174
5175 if (ndlp->nlp_flag & NLP_RPI_REGISTERED ||
5176 ndlp->nlp_flag & NLP_REG_LOGIN_SEND) {
5177 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
5178 lpfc_printf_vlog(vport, KERN_INFO,
5179 LOG_NODE | LOG_DISCOVERY,
5180 "3366 RPI x%x needs to be "
5181 "unregistered nlp_flag x%x "
5182 "did x%x\n",
5183 ndlp->nlp_rpi, ndlp->nlp_flag,
5184 ndlp->nlp_DID);
5185
5186
5187
5188
5189 if (ndlp->nlp_flag & NLP_UNREG_INP) {
5190 lpfc_printf_vlog(vport, KERN_INFO,
5191 LOG_NODE | LOG_DISCOVERY,
5192 "1436 unreg_rpi SKIP UNREG x%x on "
5193 "NPort x%x deferred x%x flg x%x "
5194 "Data: x%px\n",
5195 ndlp->nlp_rpi, ndlp->nlp_DID,
5196 ndlp->nlp_defer_did,
5197 ndlp->nlp_flag, ndlp);
5198 goto out;
5199 }
5200
5201 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5202 if (mbox) {
5203
5204 rpi = ndlp->nlp_rpi;
5205 if (phba->sli_rev == LPFC_SLI_REV4)
5206 rpi = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
5207
5208 lpfc_unreg_login(phba, vport->vpi, rpi, mbox);
5209 mbox->vport = vport;
5210 lpfc_set_unreg_login_mbx_cmpl(phba, vport, ndlp, mbox);
5211 if (!mbox->ctx_ndlp) {
5212 mempool_free(mbox, phba->mbox_mem_pool);
5213 return 1;
5214 }
5215
5216 if (mbox->mbox_cmpl == lpfc_sli4_unreg_rpi_cmpl_clr)
5217
5218
5219
5220 acc_plogi = 0;
5221 if (((ndlp->nlp_DID & Fabric_DID_MASK) !=
5222 Fabric_DID_MASK) &&
5223 (!(vport->fc_flag & FC_OFFLINE_MODE)))
5224 ndlp->nlp_flag |= NLP_UNREG_INP;
5225
5226 lpfc_printf_vlog(vport, KERN_INFO,
5227 LOG_NODE | LOG_DISCOVERY,
5228 "1433 unreg_rpi UNREG x%x on "
5229 "NPort x%x deferred flg x%x "
5230 "Data:x%px\n",
5231 ndlp->nlp_rpi, ndlp->nlp_DID,
5232 ndlp->nlp_flag, ndlp);
5233
5234 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5235 if (rc == MBX_NOT_FINISHED) {
5236 mempool_free(mbox, phba->mbox_mem_pool);
5237 acc_plogi = 1;
5238 }
5239 } else {
5240 lpfc_printf_vlog(vport, KERN_INFO,
5241 LOG_NODE | LOG_DISCOVERY,
5242 "1444 Failed to allocate mempool "
5243 "unreg_rpi UNREG x%x, "
5244 "DID x%x, flag x%x, "
5245 "ndlp x%px\n",
5246 ndlp->nlp_rpi, ndlp->nlp_DID,
5247 ndlp->nlp_flag, ndlp);
5248
5249
5250
5251
5252
5253 if (!(vport->load_flag & FC_UNLOADING)) {
5254 ndlp->nlp_flag &= ~NLP_UNREG_INP;
5255 lpfc_issue_els_logo(vport, ndlp, 0);
5256 ndlp->nlp_prev_state = ndlp->nlp_state;
5257 lpfc_nlp_set_state(vport, ndlp,
5258 NLP_STE_NPR_NODE);
5259 }
5260
5261 return 1;
5262 }
5263 lpfc_no_rpi(phba, ndlp);
5264out:
5265 if (phba->sli_rev != LPFC_SLI_REV4)
5266 ndlp->nlp_rpi = 0;
5267 ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
5268 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
5269 if (acc_plogi)
5270 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
5271 return 1;
5272 }
5273 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
5274 return 0;
5275}
5276
5277
5278
5279
5280
5281
5282
5283
5284void
5285lpfc_unreg_hba_rpis(struct lpfc_hba *phba)
5286{
5287 struct lpfc_vport **vports;
5288 struct lpfc_nodelist *ndlp;
5289 struct Scsi_Host *shost;
5290 int i;
5291
5292 vports = lpfc_create_vport_work_array(phba);
5293 if (!vports) {
5294 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5295 "2884 Vport array allocation failed \n");
5296 return;
5297 }
5298 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
5299 shost = lpfc_shost_from_vport(vports[i]);
5300 spin_lock_irq(shost->host_lock);
5301 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
5302 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
5303
5304 spin_unlock_irq(shost->host_lock);
5305 lpfc_unreg_rpi(vports[i], ndlp);
5306 spin_lock_irq(shost->host_lock);
5307 }
5308 }
5309 spin_unlock_irq(shost->host_lock);
5310 }
5311 lpfc_destroy_vport_work_array(phba, vports);
5312}
5313
5314void
5315lpfc_unreg_all_rpis(struct lpfc_vport *vport)
5316{
5317 struct lpfc_hba *phba = vport->phba;
5318 LPFC_MBOXQ_t *mbox;
5319 int rc;
5320
5321 if (phba->sli_rev == LPFC_SLI_REV4) {
5322 lpfc_sli4_unreg_all_rpis(vport);
5323 return;
5324 }
5325
5326 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5327 if (mbox) {
5328 lpfc_unreg_login(phba, vport->vpi, LPFC_UNREG_ALL_RPIS_VPORT,
5329 mbox);
5330 mbox->vport = vport;
5331 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5332 mbox->ctx_ndlp = NULL;
5333 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
5334 if (rc != MBX_TIMEOUT)
5335 mempool_free(mbox, phba->mbox_mem_pool);
5336
5337 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
5338 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
5339 "1836 Could not issue "
5340 "unreg_login(all_rpis) status %d\n",
5341 rc);
5342 }
5343}
5344
5345void
5346lpfc_unreg_default_rpis(struct lpfc_vport *vport)
5347{
5348 struct lpfc_hba *phba = vport->phba;
5349 LPFC_MBOXQ_t *mbox;
5350 int rc;
5351
5352
5353 if (phba->sli_rev > LPFC_SLI_REV3)
5354 return;
5355
5356 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5357 if (mbox) {
5358 lpfc_unreg_did(phba, vport->vpi, LPFC_UNREG_ALL_DFLT_RPIS,
5359 mbox);
5360 mbox->vport = vport;
5361 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5362 mbox->ctx_ndlp = NULL;
5363 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
5364 if (rc != MBX_TIMEOUT)
5365 mempool_free(mbox, phba->mbox_mem_pool);
5366
5367 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
5368 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
5369 "1815 Could not issue "
5370 "unreg_did (default rpis) status %d\n",
5371 rc);
5372 }
5373}
5374
5375
5376
5377
5378
5379static int
5380lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
5381{
5382 struct lpfc_hba *phba = vport->phba;
5383 LPFC_MBOXQ_t *mb, *nextmb;
5384 struct lpfc_dmabuf *mp;
5385
5386
5387 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5388 "0900 Cleanup node for NPort x%x "
5389 "Data: x%x x%x x%x\n",
5390 ndlp->nlp_DID, ndlp->nlp_flag,
5391 ndlp->nlp_state, ndlp->nlp_rpi);
5392 lpfc_dequeue_node(vport, ndlp);
5393
5394
5395
5396
5397 if ((mb = phba->sli.mbox_active)) {
5398 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
5399 !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) &&
5400 (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
5401 mb->ctx_ndlp = NULL;
5402 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5403 }
5404 }
5405
5406 spin_lock_irq(&phba->hbalock);
5407
5408 list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
5409 if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) ||
5410 (mb->mbox_flag & LPFC_MBX_IMED_UNREG) ||
5411 (ndlp != (struct lpfc_nodelist *)mb->ctx_ndlp))
5412 continue;
5413
5414 mb->ctx_ndlp = NULL;
5415 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5416 }
5417
5418 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
5419 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
5420 !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) &&
5421 (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
5422 mp = (struct lpfc_dmabuf *)(mb->ctx_buf);
5423 if (mp) {
5424 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
5425 kfree(mp);
5426 }
5427 list_del(&mb->list);
5428 mempool_free(mb, phba->mbox_mem_pool);
5429
5430
5431
5432
5433 }
5434 }
5435 spin_unlock_irq(&phba->hbalock);
5436
5437 lpfc_els_abort(phba, ndlp);
5438
5439 spin_lock_irq(&ndlp->lock);
5440 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
5441 spin_unlock_irq(&ndlp->lock);
5442
5443 ndlp->nlp_last_elscmd = 0;
5444 del_timer_sync(&ndlp->nlp_delayfunc);
5445
5446 list_del_init(&ndlp->els_retry_evt.evt_listp);
5447 list_del_init(&ndlp->dev_loss_evt.evt_listp);
5448 list_del_init(&ndlp->recovery_evt.evt_listp);
5449 lpfc_cleanup_vports_rrqs(vport, ndlp);
5450
5451 if (phba->sli_rev == LPFC_SLI_REV4)
5452 ndlp->nlp_flag |= NLP_RELEASE_RPI;
5453
5454 return 0;
5455}
5456
5457static int
5458lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5459 uint32_t did)
5460{
5461 D_ID mydid, ndlpdid, matchdid;
5462
5463 if (did == Bcast_DID)
5464 return 0;
5465
5466
5467 if (ndlp->nlp_DID == did)
5468 return 1;
5469
5470
5471 mydid.un.word = vport->fc_myDID;
5472 if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
5473 return 0;
5474 }
5475
5476 matchdid.un.word = did;
5477 ndlpdid.un.word = ndlp->nlp_DID;
5478 if (matchdid.un.b.id == ndlpdid.un.b.id) {
5479 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
5480 (mydid.un.b.area == matchdid.un.b.area)) {
5481
5482
5483
5484
5485
5486
5487
5488
5489 if ((ndlpdid.un.b.domain == 0) &&
5490 (ndlpdid.un.b.area == 0)) {
5491 if (ndlpdid.un.b.id &&
5492 vport->phba->fc_topology ==
5493 LPFC_TOPOLOGY_LOOP)
5494 return 1;
5495 }
5496 return 0;
5497 }
5498
5499 matchdid.un.word = ndlp->nlp_DID;
5500 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
5501 (mydid.un.b.area == ndlpdid.un.b.area)) {
5502 if ((matchdid.un.b.domain == 0) &&
5503 (matchdid.un.b.area == 0)) {
5504 if (matchdid.un.b.id)
5505 return 1;
5506 }
5507 }
5508 }
5509 return 0;
5510}
5511
5512
5513static struct lpfc_nodelist *
5514__lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
5515{
5516 struct lpfc_nodelist *ndlp;
5517 uint32_t data1;
5518
5519 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5520 if (lpfc_matchdid(vport, ndlp, did)) {
5521 data1 = (((uint32_t)ndlp->nlp_state << 24) |
5522 ((uint32_t)ndlp->nlp_xri << 16) |
5523 ((uint32_t)ndlp->nlp_type << 8)
5524 );
5525 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5526 "0929 FIND node DID "
5527 "Data: x%px x%x x%x x%x x%x x%px\n",
5528 ndlp, ndlp->nlp_DID,
5529 ndlp->nlp_flag, data1, ndlp->nlp_rpi,
5530 ndlp->active_rrqs_xri_bitmap);
5531 return ndlp;
5532 }
5533 }
5534
5535
5536 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5537 "0932 FIND node did x%x NOT FOUND.\n", did);
5538 return NULL;
5539}
5540
5541struct lpfc_nodelist *
5542lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
5543{
5544 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5545 struct lpfc_nodelist *ndlp;
5546 unsigned long iflags;
5547
5548 spin_lock_irqsave(shost->host_lock, iflags);
5549 ndlp = __lpfc_findnode_did(vport, did);
5550 spin_unlock_irqrestore(shost->host_lock, iflags);
5551 return ndlp;
5552}
5553
5554struct lpfc_nodelist *
5555lpfc_findnode_mapped(struct lpfc_vport *vport)
5556{
5557 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5558 struct lpfc_nodelist *ndlp;
5559 uint32_t data1;
5560 unsigned long iflags;
5561
5562 spin_lock_irqsave(shost->host_lock, iflags);
5563
5564 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5565 if (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE ||
5566 ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
5567 data1 = (((uint32_t)ndlp->nlp_state << 24) |
5568 ((uint32_t)ndlp->nlp_xri << 16) |
5569 ((uint32_t)ndlp->nlp_type << 8) |
5570 ((uint32_t)ndlp->nlp_rpi & 0xff));
5571 spin_unlock_irqrestore(shost->host_lock, iflags);
5572 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5573 "2025 FIND node DID "
5574 "Data: x%px x%x x%x x%x x%px\n",
5575 ndlp, ndlp->nlp_DID,
5576 ndlp->nlp_flag, data1,
5577 ndlp->active_rrqs_xri_bitmap);
5578 return ndlp;
5579 }
5580 }
5581 spin_unlock_irqrestore(shost->host_lock, iflags);
5582
5583
5584 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5585 "2026 FIND mapped did NOT FOUND.\n");
5586 return NULL;
5587}
5588
5589struct lpfc_nodelist *
5590lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did)
5591{
5592 struct lpfc_nodelist *ndlp;
5593
5594 ndlp = lpfc_findnode_did(vport, did);
5595 if (!ndlp) {
5596 if (vport->phba->nvmet_support)
5597 return NULL;
5598 if ((vport->fc_flag & FC_RSCN_MODE) != 0 &&
5599 lpfc_rscn_payload_check(vport, did) == 0)
5600 return NULL;
5601 ndlp = lpfc_nlp_init(vport, did);
5602 if (!ndlp)
5603 return NULL;
5604 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5605
5606 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5607 "6453 Setup New Node 2B_DISC x%x "
5608 "Data:x%x x%x x%x\n",
5609 ndlp->nlp_DID, ndlp->nlp_flag,
5610 ndlp->nlp_state, vport->fc_flag);
5611
5612 spin_lock_irq(&ndlp->lock);
5613 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
5614 spin_unlock_irq(&ndlp->lock);
5615 return ndlp;
5616 }
5617
5618
5619
5620
5621
5622 if ((vport->fc_flag & FC_RSCN_MODE) &&
5623 !(vport->fc_flag & FC_NDISC_ACTIVE)) {
5624 if (lpfc_rscn_payload_check(vport, did)) {
5625
5626
5627
5628
5629 lpfc_cancel_retry_delay_tmo(vport, ndlp);
5630
5631 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5632 "6455 Setup RSCN Node 2B_DISC x%x "
5633 "Data:x%x x%x x%x\n",
5634 ndlp->nlp_DID, ndlp->nlp_flag,
5635 ndlp->nlp_state, vport->fc_flag);
5636
5637
5638
5639
5640
5641
5642 if (vport->phba->nvmet_support)
5643 return ndlp;
5644
5645
5646
5647
5648 if (ndlp->nlp_flag & NLP_RCV_PLOGI &&
5649 !(ndlp->nlp_type &
5650 (NLP_FCP_TARGET | NLP_NVME_TARGET)))
5651 return NULL;
5652
5653 ndlp->nlp_prev_state = ndlp->nlp_state;
5654 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5655
5656 spin_lock_irq(&ndlp->lock);
5657 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
5658 spin_unlock_irq(&ndlp->lock);
5659 } else {
5660 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5661 "6456 Skip Setup RSCN Node x%x "
5662 "Data:x%x x%x x%x\n",
5663 ndlp->nlp_DID, ndlp->nlp_flag,
5664 ndlp->nlp_state, vport->fc_flag);
5665 ndlp = NULL;
5666 }
5667 } else {
5668 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5669 "6457 Setup Active Node 2B_DISC x%x "
5670 "Data:x%x x%x x%x\n",
5671 ndlp->nlp_DID, ndlp->nlp_flag,
5672 ndlp->nlp_state, vport->fc_flag);
5673
5674
5675
5676
5677
5678 if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE ||
5679 ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
5680 (!vport->phba->nvmet_support &&
5681 ndlp->nlp_flag & NLP_RCV_PLOGI))
5682 return NULL;
5683
5684 if (vport->phba->nvmet_support)
5685 return ndlp;
5686
5687
5688
5689
5690 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5691
5692 spin_lock_irq(&ndlp->lock);
5693 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
5694 spin_unlock_irq(&ndlp->lock);
5695 }
5696 return ndlp;
5697}
5698
5699
5700void
5701lpfc_disc_list_loopmap(struct lpfc_vport *vport)
5702{
5703 struct lpfc_hba *phba = vport->phba;
5704 int j;
5705 uint32_t alpa, index;
5706
5707 if (!lpfc_is_link_up(phba))
5708 return;
5709
5710 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
5711 return;
5712
5713
5714 if (phba->alpa_map[0]) {
5715 for (j = 1; j <= phba->alpa_map[0]; j++) {
5716 alpa = phba->alpa_map[j];
5717 if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0))
5718 continue;
5719 lpfc_setup_disc_node(vport, alpa);
5720 }
5721 } else {
5722
5723 for (j = 0; j < FC_MAXLOOP; j++) {
5724
5725
5726
5727 if (vport->cfg_scan_down)
5728 index = j;
5729 else
5730 index = FC_MAXLOOP - j - 1;
5731 alpa = lpfcAlpaArray[index];
5732 if ((vport->fc_myDID & 0xff) == alpa)
5733 continue;
5734 lpfc_setup_disc_node(vport, alpa);
5735 }
5736 }
5737 return;
5738}
5739
5740
5741void
5742lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport)
5743{
5744 LPFC_MBOXQ_t *mbox;
5745 struct lpfc_sli *psli = &phba->sli;
5746 struct lpfc_sli_ring *extra_ring = &psli->sli3_ring[LPFC_EXTRA_RING];
5747 struct lpfc_sli_ring *fcp_ring = &psli->sli3_ring[LPFC_FCP_RING];
5748 int rc;
5749
5750
5751
5752
5753
5754 if ((phba->link_state >= LPFC_CLEAR_LA) ||
5755 (vport->port_type != LPFC_PHYSICAL_PORT) ||
5756 (phba->sli_rev == LPFC_SLI_REV4))
5757 return;
5758
5759
5760 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) {
5761 phba->link_state = LPFC_CLEAR_LA;
5762 lpfc_clear_la(phba, mbox);
5763 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
5764 mbox->vport = vport;
5765 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5766 if (rc == MBX_NOT_FINISHED) {
5767 mempool_free(mbox, phba->mbox_mem_pool);
5768 lpfc_disc_flush_list(vport);
5769 extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
5770 fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
5771 phba->link_state = LPFC_HBA_ERROR;
5772 }
5773 }
5774}
5775
5776
5777void
5778lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport)
5779{
5780 LPFC_MBOXQ_t *regvpimbox;
5781
5782 regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5783 if (regvpimbox) {
5784 lpfc_reg_vpi(vport, regvpimbox);
5785 regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi;
5786 regvpimbox->vport = vport;
5787 if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT)
5788 == MBX_NOT_FINISHED) {
5789 mempool_free(regvpimbox, phba->mbox_mem_pool);
5790 }
5791 }
5792}
5793
5794
5795void
5796lpfc_disc_start(struct lpfc_vport *vport)
5797{
5798 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5799 struct lpfc_hba *phba = vport->phba;
5800 uint32_t num_sent;
5801 uint32_t clear_la_pending;
5802
5803 if (!lpfc_is_link_up(phba)) {
5804 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
5805 "3315 Link is not up %x\n",
5806 phba->link_state);
5807 return;
5808 }
5809
5810 if (phba->link_state == LPFC_CLEAR_LA)
5811 clear_la_pending = 1;
5812 else
5813 clear_la_pending = 0;
5814
5815 if (vport->port_state < LPFC_VPORT_READY)
5816 vport->port_state = LPFC_DISC_AUTH;
5817
5818 lpfc_set_disctmo(vport);
5819
5820 vport->fc_prevDID = vport->fc_myDID;
5821 vport->num_disc_nodes = 0;
5822
5823
5824 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5825 "0202 Start Discovery port state x%x "
5826 "flg x%x Data: x%x x%x x%x\n",
5827 vport->port_state, vport->fc_flag, vport->fc_plogi_cnt,
5828 vport->fc_adisc_cnt, vport->fc_npr_cnt);
5829
5830
5831 num_sent = lpfc_els_disc_adisc(vport);
5832
5833 if (num_sent)
5834 return;
5835
5836
5837 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
5838 !(vport->fc_flag & FC_PT2PT) &&
5839 !(vport->fc_flag & FC_RSCN_MODE) &&
5840 (phba->sli_rev < LPFC_SLI_REV4)) {
5841 lpfc_issue_clear_la(phba, vport);
5842 lpfc_issue_reg_vpi(phba, vport);
5843 return;
5844 }
5845
5846
5847
5848
5849
5850 if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) {
5851
5852 lpfc_issue_clear_la(phba, vport);
5853
5854 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
5855 vport->num_disc_nodes = 0;
5856
5857 if (vport->fc_npr_cnt)
5858 lpfc_els_disc_plogi(vport);
5859
5860 if (!vport->num_disc_nodes) {
5861 spin_lock_irq(shost->host_lock);
5862 vport->fc_flag &= ~FC_NDISC_ACTIVE;
5863 spin_unlock_irq(shost->host_lock);
5864 lpfc_can_disctmo(vport);
5865 }
5866 }
5867 vport->port_state = LPFC_VPORT_READY;
5868 } else {
5869
5870 num_sent = lpfc_els_disc_plogi(vport);
5871
5872 if (num_sent)
5873 return;
5874
5875 if (vport->fc_flag & FC_RSCN_MODE) {
5876
5877
5878
5879 if ((vport->fc_rscn_id_cnt == 0) &&
5880 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
5881 spin_lock_irq(shost->host_lock);
5882 vport->fc_flag &= ~FC_RSCN_MODE;
5883 spin_unlock_irq(shost->host_lock);
5884 lpfc_can_disctmo(vport);
5885 } else
5886 lpfc_els_handle_rscn(vport);
5887 }
5888 }
5889 return;
5890}
5891
5892
5893
5894
5895
5896static void
5897lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
5898{
5899 LIST_HEAD(completions);
5900 IOCB_t *icmd;
5901 struct lpfc_iocbq *iocb, *next_iocb;
5902 struct lpfc_sli_ring *pring;
5903
5904 pring = lpfc_phba_elsring(phba);
5905 if (unlikely(!pring))
5906 return;
5907
5908
5909
5910
5911 spin_lock_irq(&phba->hbalock);
5912 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
5913 if (iocb->context1 != ndlp) {
5914 continue;
5915 }
5916 icmd = &iocb->iocb;
5917 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
5918 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
5919
5920 list_move_tail(&iocb->list, &completions);
5921 }
5922 }
5923
5924
5925 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
5926 if (iocb->context1 != ndlp) {
5927 continue;
5928 }
5929 icmd = &iocb->iocb;
5930 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR ||
5931 icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) {
5932 lpfc_sli_issue_abort_iotag(phba, pring, iocb, NULL);
5933 }
5934 }
5935 spin_unlock_irq(&phba->hbalock);
5936
5937
5938 lpfc_issue_hb_tmo(phba);
5939
5940
5941 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5942 IOERR_SLI_ABORTED);
5943}
5944
5945static void
5946lpfc_disc_flush_list(struct lpfc_vport *vport)
5947{
5948 struct lpfc_nodelist *ndlp, *next_ndlp;
5949 struct lpfc_hba *phba = vport->phba;
5950
5951 if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) {
5952 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
5953 nlp_listp) {
5954 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
5955 ndlp->nlp_state == NLP_STE_ADISC_ISSUE) {
5956 lpfc_free_tx(phba, ndlp);
5957 }
5958 }
5959 }
5960}
5961
5962void
5963lpfc_cleanup_discovery_resources(struct lpfc_vport *vport)
5964{
5965 lpfc_els_flush_rscn(vport);
5966 lpfc_els_flush_cmd(vport);
5967 lpfc_disc_flush_list(vport);
5968}
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985void
5986lpfc_disc_timeout(struct timer_list *t)
5987{
5988 struct lpfc_vport *vport = from_timer(vport, t, fc_disctmo);
5989 struct lpfc_hba *phba = vport->phba;
5990 uint32_t tmo_posted;
5991 unsigned long flags = 0;
5992
5993 if (unlikely(!phba))
5994 return;
5995
5996 spin_lock_irqsave(&vport->work_port_lock, flags);
5997 tmo_posted = vport->work_port_events & WORKER_DISC_TMO;
5998 if (!tmo_posted)
5999 vport->work_port_events |= WORKER_DISC_TMO;
6000 spin_unlock_irqrestore(&vport->work_port_lock, flags);
6001
6002 if (!tmo_posted)
6003 lpfc_worker_wake_up(phba);
6004 return;
6005}
6006
6007static void
6008lpfc_disc_timeout_handler(struct lpfc_vport *vport)
6009{
6010 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6011 struct lpfc_hba *phba = vport->phba;
6012 struct lpfc_sli *psli = &phba->sli;
6013 struct lpfc_nodelist *ndlp, *next_ndlp;
6014 LPFC_MBOXQ_t *initlinkmbox;
6015 int rc, clrlaerr = 0;
6016
6017 if (!(vport->fc_flag & FC_DISC_TMO))
6018 return;
6019
6020 spin_lock_irq(shost->host_lock);
6021 vport->fc_flag &= ~FC_DISC_TMO;
6022 spin_unlock_irq(shost->host_lock);
6023
6024 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6025 "disc timeout: state:x%x rtry:x%x flg:x%x",
6026 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
6027
6028 switch (vport->port_state) {
6029
6030 case LPFC_LOCAL_CFG_LINK:
6031
6032
6033
6034
6035 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
6036 "0221 FAN timeout\n");
6037
6038
6039 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
6040 nlp_listp) {
6041 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
6042 continue;
6043 if (ndlp->nlp_type & NLP_FABRIC) {
6044
6045 lpfc_drop_node(vport, ndlp);
6046
6047 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
6048
6049
6050
6051 lpfc_unreg_rpi(vport, ndlp);
6052 }
6053 }
6054 if (vport->port_state != LPFC_FLOGI) {
6055 if (phba->sli_rev <= LPFC_SLI_REV3)
6056 lpfc_initial_flogi(vport);
6057 else
6058 lpfc_issue_init_vfi(vport);
6059 return;
6060 }
6061 break;
6062
6063 case LPFC_FDISC:
6064 case LPFC_FLOGI:
6065
6066
6067 lpfc_printf_vlog(vport, KERN_ERR,
6068 LOG_TRACE_EVENT,
6069 "0222 Initial %s timeout\n",
6070 vport->vpi ? "FDISC" : "FLOGI");
6071
6072
6073
6074
6075
6076
6077 lpfc_disc_list_loopmap(vport);
6078
6079
6080 lpfc_disc_start(vport);
6081 break;
6082
6083 case LPFC_FABRIC_CFG_LINK:
6084
6085
6086 lpfc_printf_vlog(vport, KERN_ERR,
6087 LOG_TRACE_EVENT,
6088 "0223 Timeout while waiting for "
6089 "NameServer login\n");
6090
6091 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6092 if (ndlp)
6093 lpfc_els_abort(phba, ndlp);
6094
6095
6096 goto restart_disc;
6097
6098 case LPFC_NS_QRY:
6099
6100 lpfc_printf_vlog(vport, KERN_ERR,
6101 LOG_TRACE_EVENT,
6102 "0224 NameServer Query timeout "
6103 "Data: x%x x%x\n",
6104 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
6105
6106 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
6107
6108 vport->fc_ns_retry++;
6109 vport->gidft_inp = 0;
6110 rc = lpfc_issue_gidft(vport);
6111 if (rc == 0)
6112 break;
6113 }
6114 vport->fc_ns_retry = 0;
6115
6116restart_disc:
6117
6118
6119
6120
6121
6122 if (phba->sli_rev < LPFC_SLI_REV4) {
6123 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
6124 lpfc_issue_reg_vpi(phba, vport);
6125 else {
6126 lpfc_issue_clear_la(phba, vport);
6127 vport->port_state = LPFC_VPORT_READY;
6128 }
6129 }
6130
6131
6132 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6133 if (!initlinkmbox) {
6134 lpfc_printf_vlog(vport, KERN_ERR,
6135 LOG_TRACE_EVENT,
6136 "0206 Device Discovery "
6137 "completion error\n");
6138 phba->link_state = LPFC_HBA_ERROR;
6139 break;
6140 }
6141
6142 lpfc_linkdown(phba);
6143 lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
6144 phba->cfg_link_speed);
6145 initlinkmbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
6146 initlinkmbox->vport = vport;
6147 initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
6148 rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT);
6149 lpfc_set_loopback_flag(phba);
6150 if (rc == MBX_NOT_FINISHED)
6151 mempool_free(initlinkmbox, phba->mbox_mem_pool);
6152
6153 break;
6154
6155 case LPFC_DISC_AUTH:
6156
6157 lpfc_printf_vlog(vport, KERN_ERR,
6158 LOG_TRACE_EVENT,
6159 "0227 Node Authentication timeout\n");
6160 lpfc_disc_flush_list(vport);
6161
6162
6163
6164
6165
6166 if (phba->sli_rev < LPFC_SLI_REV4) {
6167 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
6168 lpfc_issue_reg_vpi(phba, vport);
6169 else {
6170 lpfc_issue_clear_la(phba, vport);
6171 vport->port_state = LPFC_VPORT_READY;
6172 }
6173 }
6174 break;
6175
6176 case LPFC_VPORT_READY:
6177 if (vport->fc_flag & FC_RSCN_MODE) {
6178 lpfc_printf_vlog(vport, KERN_ERR,
6179 LOG_TRACE_EVENT,
6180 "0231 RSCN timeout Data: x%x "
6181 "x%x\n",
6182 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
6183
6184
6185 lpfc_els_flush_cmd(vport);
6186
6187 lpfc_els_flush_rscn(vport);
6188 lpfc_disc_flush_list(vport);
6189 }
6190 break;
6191
6192 default:
6193 lpfc_printf_vlog(vport, KERN_ERR,
6194 LOG_TRACE_EVENT,
6195 "0273 Unexpected discovery timeout, "
6196 "vport State x%x\n", vport->port_state);
6197 break;
6198 }
6199
6200 switch (phba->link_state) {
6201 case LPFC_CLEAR_LA:
6202
6203 lpfc_printf_vlog(vport, KERN_ERR,
6204 LOG_TRACE_EVENT,
6205 "0228 CLEAR LA timeout\n");
6206 clrlaerr = 1;
6207 break;
6208
6209 case LPFC_LINK_UP:
6210 lpfc_issue_clear_la(phba, vport);
6211 fallthrough;
6212 case LPFC_LINK_UNKNOWN:
6213 case LPFC_WARM_START:
6214 case LPFC_INIT_START:
6215 case LPFC_INIT_MBX_CMDS:
6216 case LPFC_LINK_DOWN:
6217 case LPFC_HBA_ERROR:
6218 lpfc_printf_vlog(vport, KERN_ERR,
6219 LOG_TRACE_EVENT,
6220 "0230 Unexpected timeout, hba link "
6221 "state x%x\n", phba->link_state);
6222 clrlaerr = 1;
6223 break;
6224
6225 case LPFC_HBA_READY:
6226 break;
6227 }
6228
6229 if (clrlaerr) {
6230 lpfc_disc_flush_list(vport);
6231 if (phba->sli_rev != LPFC_SLI_REV4) {
6232 psli->sli3_ring[(LPFC_EXTRA_RING)].flag &=
6233 ~LPFC_STOP_IOCB_EVENT;
6234 psli->sli3_ring[LPFC_FCP_RING].flag &=
6235 ~LPFC_STOP_IOCB_EVENT;
6236 }
6237 vport->port_state = LPFC_VPORT_READY;
6238 }
6239 return;
6240}
6241
6242
6243
6244
6245
6246
6247
6248void
6249lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6250{
6251 MAILBOX_t *mb = &pmb->u.mb;
6252 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
6253 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
6254 struct lpfc_vport *vport = pmb->vport;
6255
6256 pmb->ctx_buf = NULL;
6257 pmb->ctx_ndlp = NULL;
6258
6259 if (phba->sli_rev < LPFC_SLI_REV4)
6260 ndlp->nlp_rpi = mb->un.varWords[0];
6261 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
6262 ndlp->nlp_type |= NLP_FABRIC;
6263 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
6264 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY,
6265 "0004 rpi:%x DID:%x flg:%x %d x%px\n",
6266 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
6267 kref_read(&ndlp->kref),
6268 ndlp);
6269
6270
6271
6272
6273
6274
6275 if (vport->port_type == LPFC_PHYSICAL_PORT) {
6276 phba->link_flag &= ~LS_CT_VEN_RPA;
6277 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
6278 } else {
6279 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
6280 }
6281
6282
6283
6284
6285
6286 lpfc_nlp_put(ndlp);
6287 lpfc_mbuf_free(phba, mp->virt, mp->phys);
6288 kfree(mp);
6289 mempool_free(pmb, phba->mbox_mem_pool);
6290
6291 return;
6292}
6293
6294static int
6295lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param)
6296{
6297 uint16_t *rpi = param;
6298
6299 return ndlp->nlp_rpi == *rpi;
6300}
6301
6302static int
6303lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param)
6304{
6305 return memcmp(&ndlp->nlp_portname, param,
6306 sizeof(ndlp->nlp_portname)) == 0;
6307}
6308
6309static struct lpfc_nodelist *
6310__lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
6311{
6312 struct lpfc_nodelist *ndlp;
6313
6314 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
6315 if (filter(ndlp, param)) {
6316 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
6317 "3185 FIND node filter %ps DID "
6318 "ndlp x%px did x%x flg x%x st x%x "
6319 "xri x%x type x%x rpi x%x\n",
6320 filter, ndlp, ndlp->nlp_DID,
6321 ndlp->nlp_flag, ndlp->nlp_state,
6322 ndlp->nlp_xri, ndlp->nlp_type,
6323 ndlp->nlp_rpi);
6324 return ndlp;
6325 }
6326 }
6327 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
6328 "3186 FIND node filter %ps NOT FOUND.\n", filter);
6329 return NULL;
6330}
6331
6332
6333
6334
6335
6336struct lpfc_nodelist *
6337__lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
6338{
6339 return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi);
6340}
6341
6342
6343
6344
6345
6346struct lpfc_nodelist *
6347lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn)
6348{
6349 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6350 struct lpfc_nodelist *ndlp;
6351
6352 spin_lock_irq(shost->host_lock);
6353 ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn);
6354 spin_unlock_irq(shost->host_lock);
6355 return ndlp;
6356}
6357
6358
6359
6360
6361
6362
6363struct lpfc_nodelist *
6364lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
6365{
6366 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6367 struct lpfc_nodelist *ndlp;
6368 unsigned long flags;
6369
6370 spin_lock_irqsave(shost->host_lock, flags);
6371 ndlp = __lpfc_findnode_rpi(vport, rpi);
6372 spin_unlock_irqrestore(shost->host_lock, flags);
6373 return ndlp;
6374}
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389struct lpfc_vport *
6390lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
6391{
6392 struct lpfc_vport *vport;
6393 unsigned long flags;
6394 int i = 0;
6395
6396
6397 if (vpi > 0) {
6398
6399
6400
6401
6402 for (i = 0; i <= phba->max_vpi; i++) {
6403 if (vpi == phba->vpi_ids[i])
6404 break;
6405 }
6406
6407 if (i > phba->max_vpi) {
6408 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6409 "2936 Could not find Vport mapped "
6410 "to vpi %d\n", vpi);
6411 return NULL;
6412 }
6413 }
6414
6415 spin_lock_irqsave(&phba->port_list_lock, flags);
6416 list_for_each_entry(vport, &phba->port_list, listentry) {
6417 if (vport->vpi == i) {
6418 spin_unlock_irqrestore(&phba->port_list_lock, flags);
6419 return vport;
6420 }
6421 }
6422 spin_unlock_irqrestore(&phba->port_list_lock, flags);
6423 return NULL;
6424}
6425
6426struct lpfc_nodelist *
6427lpfc_nlp_init(struct lpfc_vport *vport, uint32_t did)
6428{
6429 struct lpfc_nodelist *ndlp;
6430 int rpi = LPFC_RPI_ALLOC_ERROR;
6431
6432 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
6433 rpi = lpfc_sli4_alloc_rpi(vport->phba);
6434 if (rpi == LPFC_RPI_ALLOC_ERROR)
6435 return NULL;
6436 }
6437
6438 ndlp = mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL);
6439 if (!ndlp) {
6440 if (vport->phba->sli_rev == LPFC_SLI_REV4)
6441 lpfc_sli4_free_rpi(vport->phba, rpi);
6442 return NULL;
6443 }
6444
6445 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
6446
6447 spin_lock_init(&ndlp->lock);
6448
6449 lpfc_initialize_node(vport, ndlp, did);
6450 INIT_LIST_HEAD(&ndlp->nlp_listp);
6451 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
6452 ndlp->nlp_rpi = rpi;
6453 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY,
6454 "0007 Init New ndlp x%px, rpi:x%x DID:%x "
6455 "flg:x%x refcnt:%d\n",
6456 ndlp, ndlp->nlp_rpi, ndlp->nlp_DID,
6457 ndlp->nlp_flag, kref_read(&ndlp->kref));
6458
6459 ndlp->active_rrqs_xri_bitmap =
6460 mempool_alloc(vport->phba->active_rrq_pool,
6461 GFP_KERNEL);
6462 if (ndlp->active_rrqs_xri_bitmap)
6463 memset(ndlp->active_rrqs_xri_bitmap, 0,
6464 ndlp->phba->cfg_rrq_xri_bitmap_sz);
6465 }
6466
6467
6468
6469 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
6470 "node init: did:x%x",
6471 ndlp->nlp_DID, 0, 0);
6472
6473 return ndlp;
6474}
6475
6476
6477
6478
6479static void
6480lpfc_nlp_release(struct kref *kref)
6481{
6482 struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist,
6483 kref);
6484 struct lpfc_vport *vport = ndlp->vport;
6485
6486 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6487 "node release: did:x%x flg:x%x type:x%x",
6488 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
6489
6490 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
6491 "0279 %s: ndlp: x%px did %x refcnt:%d rpi:%x\n",
6492 __func__, ndlp, ndlp->nlp_DID,
6493 kref_read(&ndlp->kref), ndlp->nlp_rpi);
6494
6495
6496 lpfc_cancel_retry_delay_tmo(vport, ndlp);
6497 lpfc_cleanup_node(vport, ndlp);
6498
6499
6500
6501
6502
6503
6504
6505
6506 if (ndlp->nlp_flag & NLP_RELEASE_RPI) {
6507 if (ndlp->nlp_rpi != LPFC_RPI_ALLOC_ERROR &&
6508 !(ndlp->nlp_flag & (NLP_RPI_REGISTERED | NLP_UNREG_INP))) {
6509 lpfc_sli4_free_rpi(vport->phba, ndlp->nlp_rpi);
6510 ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
6511 }
6512 }
6513
6514
6515
6516
6517 ndlp->vport = NULL;
6518 ndlp->nlp_state = NLP_STE_FREED_NODE;
6519 ndlp->nlp_flag = 0;
6520 ndlp->fc4_xpt_flags = 0;
6521
6522
6523 kfree(ndlp->lat_data);
6524 if (ndlp->phba->sli_rev == LPFC_SLI_REV4)
6525 mempool_free(ndlp->active_rrqs_xri_bitmap,
6526 ndlp->phba->active_rrq_pool);
6527 mempool_free(ndlp, ndlp->phba->nlp_mem_pool);
6528}
6529
6530
6531
6532
6533
6534struct lpfc_nodelist *
6535lpfc_nlp_get(struct lpfc_nodelist *ndlp)
6536{
6537 unsigned long flags;
6538
6539 if (ndlp) {
6540 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6541 "node get: did:x%x flg:x%x refcnt:x%x",
6542 ndlp->nlp_DID, ndlp->nlp_flag,
6543 kref_read(&ndlp->kref));
6544
6545
6546
6547
6548
6549 spin_lock_irqsave(&ndlp->lock, flags);
6550 if (!kref_get_unless_zero(&ndlp->kref)) {
6551 spin_unlock_irqrestore(&ndlp->lock, flags);
6552 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
6553 "0276 %s: ndlp:x%px refcnt:%d\n",
6554 __func__, (void *)ndlp, kref_read(&ndlp->kref));
6555 return NULL;
6556 }
6557 spin_unlock_irqrestore(&ndlp->lock, flags);
6558 } else {
6559 WARN_ONCE(!ndlp, "**** %s, get ref on NULL ndlp!", __func__);
6560 }
6561
6562 return ndlp;
6563}
6564
6565
6566
6567
6568int
6569lpfc_nlp_put(struct lpfc_nodelist *ndlp)
6570{
6571 if (ndlp) {
6572 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6573 "node put: did:x%x flg:x%x refcnt:x%x",
6574 ndlp->nlp_DID, ndlp->nlp_flag,
6575 kref_read(&ndlp->kref));
6576 } else {
6577 WARN_ONCE(!ndlp, "**** %s, put ref on NULL ndlp!", __func__);
6578 }
6579
6580 return ndlp ? kref_put(&ndlp->kref, lpfc_nlp_release) : 0;
6581}
6582
6583
6584
6585
6586
6587
6588int
6589lpfc_nlp_not_used(struct lpfc_nodelist *ndlp)
6590{
6591 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6592 "node not used: did:x%x flg:x%x refcnt:x%x",
6593 ndlp->nlp_DID, ndlp->nlp_flag,
6594 kref_read(&ndlp->kref));
6595
6596 if (kref_read(&ndlp->kref) == 1)
6597 if (lpfc_nlp_put(ndlp))
6598 return 1;
6599 return 0;
6600}
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612static int
6613lpfc_fcf_inuse(struct lpfc_hba *phba)
6614{
6615 struct lpfc_vport **vports;
6616 int i, ret = 0;
6617 struct lpfc_nodelist *ndlp;
6618 struct Scsi_Host *shost;
6619
6620 vports = lpfc_create_vport_work_array(phba);
6621
6622
6623 if (!vports)
6624 return 1;
6625
6626 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6627 shost = lpfc_shost_from_vport(vports[i]);
6628 spin_lock_irq(shost->host_lock);
6629
6630
6631
6632
6633
6634
6635 if (!(vports[i]->fc_flag & FC_VPORT_CVL_RCVD)) {
6636 spin_unlock_irq(shost->host_lock);
6637 ret = 1;
6638 goto out;
6639 }
6640 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
6641 if (ndlp->rport &&
6642 (ndlp->rport->roles & FC_RPORT_ROLE_FCP_TARGET)) {
6643 ret = 1;
6644 spin_unlock_irq(shost->host_lock);
6645 goto out;
6646 } else if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
6647 ret = 1;
6648 lpfc_printf_log(phba, KERN_INFO,
6649 LOG_NODE | LOG_DISCOVERY,
6650 "2624 RPI %x DID %x flag %x "
6651 "still logged in\n",
6652 ndlp->nlp_rpi, ndlp->nlp_DID,
6653 ndlp->nlp_flag);
6654 }
6655 }
6656 spin_unlock_irq(shost->host_lock);
6657 }
6658out:
6659 lpfc_destroy_vport_work_array(phba, vports);
6660 return ret;
6661}
6662
6663
6664
6665
6666
6667
6668
6669
6670void
6671lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
6672{
6673 struct lpfc_vport *vport = mboxq->vport;
6674 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6675
6676 if (mboxq->u.mb.mbxStatus) {
6677 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6678 "2555 UNREG_VFI mbxStatus error x%x "
6679 "HBA state x%x\n",
6680 mboxq->u.mb.mbxStatus, vport->port_state);
6681 }
6682 spin_lock_irq(shost->host_lock);
6683 phba->pport->fc_flag &= ~FC_VFI_REGISTERED;
6684 spin_unlock_irq(shost->host_lock);
6685 mempool_free(mboxq, phba->mbox_mem_pool);
6686 return;
6687}
6688
6689
6690
6691
6692
6693
6694
6695
6696static void
6697lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
6698{
6699 struct lpfc_vport *vport = mboxq->vport;
6700
6701 if (mboxq->u.mb.mbxStatus) {
6702 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6703 "2550 UNREG_FCFI mbxStatus error x%x "
6704 "HBA state x%x\n",
6705 mboxq->u.mb.mbxStatus, vport->port_state);
6706 }
6707 mempool_free(mboxq, phba->mbox_mem_pool);
6708 return;
6709}
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719int
6720lpfc_unregister_fcf_prep(struct lpfc_hba *phba)
6721{
6722 struct lpfc_vport **vports;
6723 struct lpfc_nodelist *ndlp;
6724 struct Scsi_Host *shost;
6725 int i = 0, rc;
6726
6727
6728 if (lpfc_fcf_inuse(phba))
6729 lpfc_unreg_hba_rpis(phba);
6730
6731
6732 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
6733
6734
6735 vports = lpfc_create_vport_work_array(phba);
6736 if (vports && (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))
6737 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6738
6739 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
6740 if (ndlp)
6741 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
6742 lpfc_cleanup_pending_mbox(vports[i]);
6743 if (phba->sli_rev == LPFC_SLI_REV4)
6744 lpfc_sli4_unreg_all_rpis(vports[i]);
6745 lpfc_mbx_unreg_vpi(vports[i]);
6746 shost = lpfc_shost_from_vport(vports[i]);
6747 spin_lock_irq(shost->host_lock);
6748 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
6749 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
6750 spin_unlock_irq(shost->host_lock);
6751 }
6752 lpfc_destroy_vport_work_array(phba, vports);
6753 if (i == 0 && (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))) {
6754 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
6755 if (ndlp)
6756 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
6757 lpfc_cleanup_pending_mbox(phba->pport);
6758 if (phba->sli_rev == LPFC_SLI_REV4)
6759 lpfc_sli4_unreg_all_rpis(phba->pport);
6760 lpfc_mbx_unreg_vpi(phba->pport);
6761 shost = lpfc_shost_from_vport(phba->pport);
6762 spin_lock_irq(shost->host_lock);
6763 phba->pport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
6764 phba->pport->vpi_state &= ~LPFC_VPI_REGISTERED;
6765 spin_unlock_irq(shost->host_lock);
6766 }
6767
6768
6769 lpfc_els_flush_all_cmd(phba);
6770
6771
6772 rc = lpfc_issue_unreg_vfi(phba->pport);
6773 return rc;
6774}
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786int
6787lpfc_sli4_unregister_fcf(struct lpfc_hba *phba)
6788{
6789 LPFC_MBOXQ_t *mbox;
6790 int rc;
6791
6792 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6793 if (!mbox) {
6794 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6795 "2551 UNREG_FCFI mbox allocation failed"
6796 "HBA state x%x\n", phba->pport->port_state);
6797 return -ENOMEM;
6798 }
6799 lpfc_unreg_fcfi(mbox, phba->fcf.fcfi);
6800 mbox->vport = phba->pport;
6801 mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl;
6802 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
6803
6804 if (rc == MBX_NOT_FINISHED) {
6805 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6806 "2552 Unregister FCFI command failed rc x%x "
6807 "HBA state x%x\n",
6808 rc, phba->pport->port_state);
6809 return -EINVAL;
6810 }
6811 return 0;
6812}
6813
6814
6815
6816
6817
6818
6819
6820
6821void
6822lpfc_unregister_fcf_rescan(struct lpfc_hba *phba)
6823{
6824 int rc;
6825
6826
6827 rc = lpfc_unregister_fcf_prep(phba);
6828 if (rc) {
6829 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6830 "2748 Failed to prepare for unregistering "
6831 "HBA's FCF record: rc=%d\n", rc);
6832 return;
6833 }
6834
6835
6836 rc = lpfc_sli4_unregister_fcf(phba);
6837 if (rc)
6838 return;
6839
6840 phba->fcf.fcf_flag = 0;
6841 phba->fcf.current_rec.flag = 0;
6842
6843
6844
6845
6846
6847 if ((phba->pport->load_flag & FC_UNLOADING) ||
6848 (phba->link_state < LPFC_LINK_UP))
6849 return;
6850
6851
6852 spin_lock_irq(&phba->hbalock);
6853 phba->fcf.fcf_flag |= FCF_INIT_DISC;
6854 spin_unlock_irq(&phba->hbalock);
6855
6856
6857 lpfc_sli4_clear_fcf_rr_bmask(phba);
6858
6859 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
6860
6861 if (rc) {
6862 spin_lock_irq(&phba->hbalock);
6863 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
6864 spin_unlock_irq(&phba->hbalock);
6865 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6866 "2553 lpfc_unregister_unused_fcf failed "
6867 "to read FCF record HBA state x%x\n",
6868 phba->pport->port_state);
6869 }
6870}
6871
6872
6873
6874
6875
6876
6877
6878
6879void
6880lpfc_unregister_fcf(struct lpfc_hba *phba)
6881{
6882 int rc;
6883
6884
6885 rc = lpfc_unregister_fcf_prep(phba);
6886 if (rc) {
6887 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6888 "2749 Failed to prepare for unregistering "
6889 "HBA's FCF record: rc=%d\n", rc);
6890 return;
6891 }
6892
6893
6894 rc = lpfc_sli4_unregister_fcf(phba);
6895 if (rc)
6896 return;
6897
6898 spin_lock_irq(&phba->hbalock);
6899 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
6900 spin_unlock_irq(&phba->hbalock);
6901}
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911void
6912lpfc_unregister_unused_fcf(struct lpfc_hba *phba)
6913{
6914
6915
6916
6917
6918
6919 spin_lock_irq(&phba->hbalock);
6920 if (!(phba->hba_flag & HBA_FCOE_MODE) ||
6921 !(phba->fcf.fcf_flag & FCF_REGISTERED) ||
6922 !(phba->hba_flag & HBA_FIP_SUPPORT) ||
6923 (phba->fcf.fcf_flag & FCF_DISCOVERY) ||
6924 (phba->pport->port_state == LPFC_FLOGI)) {
6925 spin_unlock_irq(&phba->hbalock);
6926 return;
6927 }
6928 spin_unlock_irq(&phba->hbalock);
6929
6930 if (lpfc_fcf_inuse(phba))
6931 return;
6932
6933 lpfc_unregister_fcf_rescan(phba);
6934}
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944static void
6945lpfc_read_fcf_conn_tbl(struct lpfc_hba *phba,
6946 uint8_t *buff)
6947{
6948 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
6949 struct lpfc_fcf_conn_hdr *conn_hdr;
6950 struct lpfc_fcf_conn_rec *conn_rec;
6951 uint32_t record_count;
6952 int i;
6953
6954
6955 list_for_each_entry_safe(conn_entry, next_conn_entry,
6956 &phba->fcf_conn_rec_list, list) {
6957 list_del_init(&conn_entry->list);
6958 kfree(conn_entry);
6959 }
6960
6961 conn_hdr = (struct lpfc_fcf_conn_hdr *) buff;
6962 record_count = conn_hdr->length * sizeof(uint32_t)/
6963 sizeof(struct lpfc_fcf_conn_rec);
6964
6965 conn_rec = (struct lpfc_fcf_conn_rec *)
6966 (buff + sizeof(struct lpfc_fcf_conn_hdr));
6967
6968 for (i = 0; i < record_count; i++) {
6969 if (!(conn_rec[i].flags & FCFCNCT_VALID))
6970 continue;
6971 conn_entry = kzalloc(sizeof(struct lpfc_fcf_conn_entry),
6972 GFP_KERNEL);
6973 if (!conn_entry) {
6974 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6975 "2566 Failed to allocate connection"
6976 " table entry\n");
6977 return;
6978 }
6979
6980 memcpy(&conn_entry->conn_rec, &conn_rec[i],
6981 sizeof(struct lpfc_fcf_conn_rec));
6982 list_add_tail(&conn_entry->list,
6983 &phba->fcf_conn_rec_list);
6984 }
6985
6986 if (!list_empty(&phba->fcf_conn_rec_list)) {
6987 i = 0;
6988 list_for_each_entry(conn_entry, &phba->fcf_conn_rec_list,
6989 list) {
6990 conn_rec = &conn_entry->conn_rec;
6991 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6992 "3345 FCF connection list rec[%02d]: "
6993 "flags:x%04x, vtag:x%04x, "
6994 "fabric_name:x%02x:%02x:%02x:%02x:"
6995 "%02x:%02x:%02x:%02x, "
6996 "switch_name:x%02x:%02x:%02x:%02x:"
6997 "%02x:%02x:%02x:%02x\n", i++,
6998 conn_rec->flags, conn_rec->vlan_tag,
6999 conn_rec->fabric_name[0],
7000 conn_rec->fabric_name[1],
7001 conn_rec->fabric_name[2],
7002 conn_rec->fabric_name[3],
7003 conn_rec->fabric_name[4],
7004 conn_rec->fabric_name[5],
7005 conn_rec->fabric_name[6],
7006 conn_rec->fabric_name[7],
7007 conn_rec->switch_name[0],
7008 conn_rec->switch_name[1],
7009 conn_rec->switch_name[2],
7010 conn_rec->switch_name[3],
7011 conn_rec->switch_name[4],
7012 conn_rec->switch_name[5],
7013 conn_rec->switch_name[6],
7014 conn_rec->switch_name[7]);
7015 }
7016 }
7017}
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027static void
7028lpfc_read_fcoe_param(struct lpfc_hba *phba,
7029 uint8_t *buff)
7030{
7031 struct lpfc_fip_param_hdr *fcoe_param_hdr;
7032 struct lpfc_fcoe_params *fcoe_param;
7033
7034 fcoe_param_hdr = (struct lpfc_fip_param_hdr *)
7035 buff;
7036 fcoe_param = (struct lpfc_fcoe_params *)
7037 (buff + sizeof(struct lpfc_fip_param_hdr));
7038
7039 if ((fcoe_param_hdr->parm_version != FIPP_VERSION) ||
7040 (fcoe_param_hdr->length != FCOE_PARAM_LENGTH))
7041 return;
7042
7043 if (fcoe_param_hdr->parm_flags & FIPP_VLAN_VALID) {
7044 phba->valid_vlan = 1;
7045 phba->vlan_id = le16_to_cpu(fcoe_param->vlan_tag) &
7046 0xFFF;
7047 }
7048
7049 phba->fc_map[0] = fcoe_param->fc_map[0];
7050 phba->fc_map[1] = fcoe_param->fc_map[1];
7051 phba->fc_map[2] = fcoe_param->fc_map[2];
7052 return;
7053}
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065static uint8_t *
7066lpfc_get_rec_conf23(uint8_t *buff, uint32_t size, uint8_t rec_type)
7067{
7068 uint32_t offset = 0, rec_length;
7069
7070 if ((buff[0] == LPFC_REGION23_LAST_REC) ||
7071 (size < sizeof(uint32_t)))
7072 return NULL;
7073
7074 rec_length = buff[offset + 1];
7075
7076
7077
7078
7079
7080 while ((offset + rec_length * sizeof(uint32_t) + sizeof(uint32_t))
7081 <= size) {
7082 if (buff[offset] == rec_type)
7083 return &buff[offset];
7084
7085 if (buff[offset] == LPFC_REGION23_LAST_REC)
7086 return NULL;
7087
7088 offset += rec_length * sizeof(uint32_t) + sizeof(uint32_t);
7089 rec_length = buff[offset + 1];
7090 }
7091 return NULL;
7092}
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103void
7104lpfc_parse_fcoe_conf(struct lpfc_hba *phba,
7105 uint8_t *buff,
7106 uint32_t size)
7107{
7108 uint32_t offset = 0;
7109 uint8_t *rec_ptr;
7110
7111
7112
7113
7114
7115 if (size < 2*sizeof(uint32_t))
7116 return;
7117
7118
7119 if (memcmp(buff, LPFC_REGION23_SIGNATURE, 4)) {
7120 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7121 "2567 Config region 23 has bad signature\n");
7122 return;
7123 }
7124
7125 offset += 4;
7126
7127
7128 if (buff[offset] != LPFC_REGION23_VERSION) {
7129 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7130 "2568 Config region 23 has bad version\n");
7131 return;
7132 }
7133 offset += 4;
7134
7135
7136 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
7137 size - offset, FCOE_PARAM_TYPE);
7138 if (rec_ptr)
7139 lpfc_read_fcoe_param(phba, rec_ptr);
7140
7141
7142 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
7143 size - offset, FCOE_CONN_TBL_TYPE);
7144 if (rec_ptr)
7145 lpfc_read_fcf_conn_tbl(phba, rec_ptr);
7146
7147}
7148