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