Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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