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